Skip to content

Commit

Permalink
fix: property names minification - removal of quotes
Browse files Browse the repository at this point in the history
+ t.valueToNode(<objectExpressionNode>) returns an object expression
node and again but with a few other effects - it removes the quotes from
property names for some unicode which is not supported in Safari and a
few other older browsers. So we bail here and let propertyLiterals
plugin handle the conversion of StringLiterals to Identifiers.
+ Fix #627
+ Fix #706
  • Loading branch information
boopathi committed Nov 18, 2017
1 parent 7aa580c commit be6cfdc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/babel-plugin-minify-constant-folding/src/index.js
Expand Up @@ -160,6 +160,15 @@ module.exports = babel => {
}
}

// this will convert object to object but
// t.valueToNode has other effects where property name
// is not treated for the respective environment.
// So we bail here for objects and let other plugins
// take care of converting String literal to Identifier
if (typeof res.value === "object") {
return;
}

const node = t.valueToNode(res.value);
node[seen] = true;
path.replaceWith(node);
Expand Down
11 changes: 11 additions & 0 deletions packages/babel-preset-minify/__tests__/preset-tests.js
Expand Up @@ -142,4 +142,15 @@ describe("preset", () => {
})();
`
);

thePlugin(
"should fix unicode",
`
function foo() {
module.exports = {
"\uD835\uDCB6": "ascr"
};
}
`
);
});

0 comments on commit be6cfdc

Please sign in to comment.