diff --git a/packages/babel-plugin-minify-constant-folding/src/index.js b/packages/babel-plugin-minify-constant-folding/src/index.js index 02fd8c9c1..4a9965200 100644 --- a/packages/babel-plugin-minify-constant-folding/src/index.js +++ b/packages/babel-plugin-minify-constant-folding/src/index.js @@ -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); diff --git a/packages/babel-preset-minify/__tests__/preset-tests.js b/packages/babel-preset-minify/__tests__/preset-tests.js index 4f7bf2c54..56e733249 100644 --- a/packages/babel-preset-minify/__tests__/preset-tests.js +++ b/packages/babel-preset-minify/__tests__/preset-tests.js @@ -142,4 +142,15 @@ describe("preset", () => { })(); ` ); + + thePlugin( + "should fix unicode", + ` + function foo() { + module.exports = { + "\uD835\uDCB6": "ascr" + }; + } + ` + ); });