Fix unicode handling in generated function names (#14047)

This commit is contained in:
Sneh Khatri
2021-12-21 02:33:35 +05:30
committed by GitHub
parent ad17fe1cce
commit d6ff91d560
10 changed files with 34 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
"babel-plugin"
],
"dependencies": {
"@babel/helper-compilation-targets": "workspace:^",
"@babel/helper-function-name": "workspace:^",
"@babel/helper-plugin-utils": "workspace:^"
},

View File

@@ -1,8 +1,13 @@
import { isRequired } from "@babel/helper-compilation-targets";
import { declare } from "@babel/helper-plugin-utils";
import nameFunction from "@babel/helper-function-name";
export default declare(api => {
api.assertVersion(7);
const supportUnicodeId = !isRequired(
"transform-unicode-escapes",
api.targets(),
);
return {
name: "transform-function-name",
@@ -20,7 +25,7 @@ export default declare(api => {
ObjectProperty(path) {
const value = path.get("value");
if (value.isFunction()) {
const newNode = nameFunction(value);
const newNode = nameFunction(value, false, supportUnicodeId);
if (newNode) value.replaceWith(newNode);
}
},

View File

@@ -0,0 +1,3 @@
var o = {
"\uD835\uDC9C"() {}
};

View File

@@ -0,0 +1,4 @@
{
"plugins": ["transform-function-name", "transform-shorthand-properties"],
"targets": { "firefox": 52 }
}

View File

@@ -0,0 +1,3 @@
var o = {
"\uD835\uDC9C": function () {}
};

View File

@@ -0,0 +1,3 @@
var o = {
"\uD835\uDC9C"() {}
};

View File

@@ -0,0 +1,4 @@
{
"plugins": ["transform-function-name", "transform-shorthand-properties"],
"targets": { "firefox": 60 }
}

View File

@@ -0,0 +1,3 @@
var o = {
"\uD835\uDC9C": function 𝒜() {}
};