Fix unicode handling in generated function names (#14047)
This commit is contained in:
parent
ad17fe1cce
commit
d6ff91d560
@ -172,6 +172,7 @@ function visit(node, name, scope) {
|
|||||||
/**
|
/**
|
||||||
* @param {NodePath} param0
|
* @param {NodePath} param0
|
||||||
* @param {Boolean} localBinding whether a name could shadow a self-reference (e.g. converting arrow function)
|
* @param {Boolean} localBinding whether a name could shadow a self-reference (e.g. converting arrow function)
|
||||||
|
* @param {Boolean} supportUnicodeId whether a target support unicodeId or not
|
||||||
*/
|
*/
|
||||||
export default function (
|
export default function (
|
||||||
{
|
{
|
||||||
@ -181,6 +182,7 @@ export default function (
|
|||||||
id,
|
id,
|
||||||
}: { node: any; parent?: any; scope: any; id?: any },
|
}: { node: any; parent?: any; scope: any; id?: any },
|
||||||
localBinding = false,
|
localBinding = false,
|
||||||
|
supportUnicodeId = false,
|
||||||
) {
|
) {
|
||||||
// has an `id` so we don't need to infer one
|
// has an `id` so we don't need to infer one
|
||||||
if (node.id) return;
|
if (node.id) return;
|
||||||
@ -227,6 +229,10 @@ export default function (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!supportUnicodeId && isFunction(node) && /[\uD800-\uDFFF]/.test(name)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
name = toBindingIdentifierName(name);
|
name = toBindingIdentifierName(name);
|
||||||
id = identifier(name);
|
id = identifier(name);
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
"babel-plugin"
|
"babel-plugin"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@babel/helper-compilation-targets": "workspace:^",
|
||||||
"@babel/helper-function-name": "workspace:^",
|
"@babel/helper-function-name": "workspace:^",
|
||||||
"@babel/helper-plugin-utils": "workspace:^"
|
"@babel/helper-plugin-utils": "workspace:^"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
|
import { isRequired } from "@babel/helper-compilation-targets";
|
||||||
import { declare } from "@babel/helper-plugin-utils";
|
import { declare } from "@babel/helper-plugin-utils";
|
||||||
import nameFunction from "@babel/helper-function-name";
|
import nameFunction from "@babel/helper-function-name";
|
||||||
|
|
||||||
export default declare(api => {
|
export default declare(api => {
|
||||||
api.assertVersion(7);
|
api.assertVersion(7);
|
||||||
|
const supportUnicodeId = !isRequired(
|
||||||
|
"transform-unicode-escapes",
|
||||||
|
api.targets(),
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "transform-function-name",
|
name: "transform-function-name",
|
||||||
@ -20,7 +25,7 @@ export default declare(api => {
|
|||||||
ObjectProperty(path) {
|
ObjectProperty(path) {
|
||||||
const value = path.get("value");
|
const value = path.get("value");
|
||||||
if (value.isFunction()) {
|
if (value.isFunction()) {
|
||||||
const newNode = nameFunction(value);
|
const newNode = nameFunction(value, false, supportUnicodeId);
|
||||||
if (newNode) value.replaceWith(newNode);
|
if (newNode) value.replaceWith(newNode);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
var o = {
|
||||||
|
"\uD835\uDC9C"() {}
|
||||||
|
};
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-function-name", "transform-shorthand-properties"],
|
||||||
|
"targets": { "firefox": 52 }
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
var o = {
|
||||||
|
"\uD835\uDC9C": function () {}
|
||||||
|
};
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
var o = {
|
||||||
|
"\uD835\uDC9C"() {}
|
||||||
|
};
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-function-name", "transform-shorthand-properties"],
|
||||||
|
"targets": { "firefox": 60 }
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
var o = {
|
||||||
|
"\uD835\uDC9C": function 𝒜() {}
|
||||||
|
};
|
||||||
@ -2437,6 +2437,7 @@ __metadata:
|
|||||||
resolution: "@babel/plugin-transform-function-name@workspace:packages/babel-plugin-transform-function-name"
|
resolution: "@babel/plugin-transform-function-name@workspace:packages/babel-plugin-transform-function-name"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/core": "workspace:^"
|
"@babel/core": "workspace:^"
|
||||||
|
"@babel/helper-compilation-targets": "workspace:^"
|
||||||
"@babel/helper-function-name": "workspace:^"
|
"@babel/helper-function-name": "workspace:^"
|
||||||
"@babel/helper-plugin-test-runner": "workspace:^"
|
"@babel/helper-plugin-test-runner": "workspace:^"
|
||||||
"@babel/helper-plugin-utils": "workspace:^"
|
"@babel/helper-plugin-utils": "workspace:^"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user