summaryrefslogtreecommitdiff
path: root/node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:31:11 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:31:11 +0800
commitaa773172311dcada759dfbaac485f4bc6e00bc21 (patch)
treeca6d9a5eff3ab8f689f9acb4f0df791d9486813d /node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name
parentc5a5384e846f242e901e859fe600d695d8990a9a (diff)
added babel
Diffstat (limited to 'node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name')
-rw-r--r--node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js b/node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
new file mode 100644
index 00000000..f6873283
--- /dev/null
+++ b/node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
@@ -0,0 +1,31 @@
+/**
+ * Edge 16 & 17 do not infer function.name from variable assignment.
+ * All other `function.name` behavior works fine, so we can skip most of @babel/transform-function-name.
+ * @see https://kangax.github.io/compat-table/es6/#test-function_name_property_variables_(function)
+ *
+ * Note: contrary to various Github issues, Edge 16+ *does* correctly infer the name of Arrow Functions.
+ * The variable declarator name inference issue only affects function expressions, so that's all we fix here.
+ *
+ * A Note on Minification: Terser undoes this transform *by default* unless `keep_fnames` is set to true.
+ * There is by design - if Function.name is critical to your application, you must configure
+ * your minifier to preserve function names.
+ */
+
+export default ({ types: t }) => ({
+ name: "transform-edge-function-name",
+ visitor: {
+ FunctionExpression: {
+ exit(path) {
+ if (!path.node.id && t.isIdentifier(path.parent.id)) {
+ const id = t.cloneNode(path.parent.id);
+ const binding = path.scope.getBinding(id.name);
+ // if the binding gets reassigned anywhere, rename it
+ if (binding?.constantViolations.length) {
+ path.scope.rename(id.name);
+ }
+ path.node.id = id;
+ }
+ },
+ },
+ },
+});