summaryrefslogtreecommitdiff
path: root/node_modules/@babel/plugin-bugfix-firefox-class-in-computed-class-key/lib/index.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
commitefbc2ffe6a1ee5ec38a4396305561d6515d0943e (patch)
tree2b4c94f18f2c792dfda813050755d5c0273fae22 /node_modules/@babel/plugin-bugfix-firefox-class-in-computed-class-key/lib/index.js
parent43acceb75957c880a5ba5a31aae221394a36d5f6 (diff)
node fixes, updates
Diffstat (limited to 'node_modules/@babel/plugin-bugfix-firefox-class-in-computed-class-key/lib/index.js')
-rw-r--r--node_modules/@babel/plugin-bugfix-firefox-class-in-computed-class-key/lib/index.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/node_modules/@babel/plugin-bugfix-firefox-class-in-computed-class-key/lib/index.js b/node_modules/@babel/plugin-bugfix-firefox-class-in-computed-class-key/lib/index.js
new file mode 100644
index 00000000..6c63b100
--- /dev/null
+++ b/node_modules/@babel/plugin-bugfix-firefox-class-in-computed-class-key/lib/index.js
@@ -0,0 +1,75 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = void 0;
+var _traverse = require("@babel/traverse");
+var _helperPluginUtils = require("@babel/helper-plugin-utils");
+var _default = exports.default = (0, _helperPluginUtils.declare)(({
+ types: t,
+ assertVersion
+}) => {
+ assertVersion(7);
+ const containsClassExpressionVisitor = {
+ ClassExpression(path, state) {
+ state.found = true;
+ path.stop();
+ },
+ Function(path) {
+ path.skip();
+ }
+ };
+ const containsYieldOrAwaitVisitor = _traverse.visitors.environmentVisitor({
+ YieldExpression(path, state) {
+ state.yield = true;
+ if (state.await) path.stop();
+ },
+ AwaitExpression(path, state) {
+ state.await = true;
+ if (state.yield) path.stop();
+ }
+ });
+ function containsClassExpression(path) {
+ if (t.isClassExpression(path.node)) return true;
+ if (t.isFunction(path.node)) return false;
+ const state = {
+ found: false
+ };
+ path.traverse(containsClassExpressionVisitor, state);
+ return state.found;
+ }
+ function wrap(path) {
+ const context = {
+ yield: t.isYieldExpression(path.node),
+ await: t.isAwaitExpression(path.node)
+ };
+ path.traverse(containsYieldOrAwaitVisitor, context);
+ let replacement;
+ if (context.yield) {
+ const fn = t.functionExpression(null, [], t.blockStatement([t.returnStatement(path.node)]), true, context.await);
+ replacement = t.yieldExpression(t.callExpression(t.memberExpression(fn, t.identifier("call")), [t.thisExpression(), t.identifier("arguments")]), true);
+ } else {
+ const fn = t.arrowFunctionExpression([], path.node, context.await);
+ replacement = t.callExpression(fn, []);
+ if (context.await) replacement = t.awaitExpression(replacement);
+ }
+ path.replaceWith(replacement);
+ }
+ return {
+ name: "bugfix-firefox-class-in-computed-class-key",
+ visitor: {
+ Class(path) {
+ const hasPrivateElement = path.node.body.body.some(node => t.isPrivate(node));
+ if (!hasPrivateElement) return;
+ for (const elem of path.get("body.body")) {
+ if ("computed" in elem.node && elem.node.computed && containsClassExpression(elem.get("key"))) {
+ wrap(elem.get("key"));
+ }
+ }
+ }
+ }
+ };
+});
+
+//# sourceMappingURL=index.js.map