Skip to content

Commit

Permalink
fix: property names minification - removal of quotes (babel#730)
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 babel#627
+ Fix babel#706
  • Loading branch information
boopathi authored Nov 18, 2017
1 parent e51ed59 commit 04e4679
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,15 @@ describe("preset", () => {
})();
`
);

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

0 comments on commit 04e4679

Please sign in to comment.