Skip to content

Commit

Permalink
Use object.entries and object.assign for older environments
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 9, 2016
1 parent f979d99 commit d3af3dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"lodash": "^4.16.4",
"object-is": "^1.0.1",
"object.assign": "^4.0.4",
"object.entries": "^1.0.3",
"object.values": "^1.0.3",
"uuid": "^2.0.3"
},
Expand Down
6 changes: 4 additions & 2 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import isEqual from 'lodash/isEqual';
import React from 'react';
import is from 'object-is';
import uuid from 'uuid';
import entries from 'object.entries';
import assign from 'object.assign';
import functionName from 'function.prototype.name';
import {
isDOMComponent,
Expand Down Expand Up @@ -175,7 +177,7 @@ export function splitSelector(selector) {
// step 1: make a map of all quoted strings with a uuid
const quotedSegments = selector.split(/[^" ]+|("[^"]*")|.*/g)
.filter(Boolean)
.reduce((obj, match) => ({ ...obj, [match]: uuid.v4() }), {});
.reduce((obj, match) => assign({}, obj, { [match]: uuid.v4() }), {});

return selector
// step 2: replace all quoted strings with the uuid, so we don't have to properly parse them
Expand All @@ -185,7 +187,7 @@ export function splitSelector(selector) {
// step 4: restore the quoted strings by swapping back the uuid's for the original segments
.map((selectorSegment) => {
let restoredSegment = selectorSegment;
Object.entries(quotedSegments).forEach(([k, v]) => {
entries(quotedSegments).forEach(([k, v]) => {
restoredSegment = restoredSegment.replace(v, k);
});
return restoredSegment;
Expand Down

0 comments on commit d3af3dc

Please sign in to comment.