Initial commit

This commit is contained in:
schihei committed 2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 files changed
+5280367

No files matched your search

@@ -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
@@ -0,0 +1 @@
{"version":3,"names":["_traverse","require","_helperPluginUtils","_default","exports","default","declare","types","t","assertVersion","containsClassExpressionVisitor","ClassExpression","path","state","found","stop","Function","skip","containsYieldOrAwaitVisitor","visitors","environmentVisitor","YieldExpression","yield","await","AwaitExpression","containsClassExpression","isClassExpression","node","isFunction","traverse","wrap","context","isYieldExpression","isAwaitExpression","replacement","fn","functionExpression","blockStatement","returnStatement","yieldExpression","callExpression","memberExpression","identifier","thisExpression","arrowFunctionExpression","awaitExpression","replaceWith","name","visitor","Class","hasPrivateElement","body","some","isPrivate","elem","get","computed"],"sources":["../src/index.ts"],"sourcesContent":["import type { types as t, NodePath, Visitor } from \"@babel/core\";\nimport { visitors } from \"@babel/traverse\";\nimport { declare } from \"@babel/helper-plugin-utils\";\n\nexport default declare(({ types: t, assertVersion }) => {\n assertVersion(REQUIRED_VERSION(7));\n\n const containsClassExpressionVisitor: Visitor<{ found: boolean }> = {\n ClassExpression(path, state) {\n state.found = true;\n path.stop();\n },\n Function(path) {\n path.skip();\n },\n };\n\n const containsYieldOrAwaitVisitor = visitors.environmentVisitor<{\n yield: boolean;\n await: boolean;\n }>({\n YieldExpression(path, state) {\n state.yield = true;\n if (state.await) path.stop();\n },\n AwaitExpression(path, state) {\n state.await = true;\n if (state.yield) path.stop();\n },\n });\n\n function containsClassExpression(path: NodePath<t.Node>) {\n if (t.isClassExpression(path.node)) return true;\n if (t.isFunction(path.node)) return false;\n const state = { found: false };\n path.traverse(containsClassExpressionVisitor, state);\n return state.found;\n }\n\n function wrap(path: NodePath<t.Expression>) {\n const context = {\n yield: t.isYieldExpression(path.node),\n await: t.isAwaitExpression(path.node),\n };\n path.traverse(containsYieldOrAwaitVisitor, context);\n\n let replacement;\n\n if (context.yield) {\n const fn = t.functionExpression(\n null,\n [],\n t.blockStatement([t.returnStatement(path.node)]),\n /* generator */ true,\n /* async */ context.await,\n );\n\n replacement = t.yieldExpression(\n t.callExpression(t.memberExpression(fn, t.identifier(\"call\")), [\n t.thisExpression(),\n // NOTE: In some context arguments is invalid (it might not be defined\n // in the top-level scope, or it's a syntax error in static class blocks).\n // However, `yield` is also invalid in those contexts, so we can safely\n // inject a reference to arguments.\n t.identifier(\"arguments\"),\n ]),\n true,\n );\n } else {\n const fn = t.arrowFunctionExpression([], path.node, context.await);\n\n replacement = t.callExpression(fn, []);\n if (context.await) replacement = t.awaitExpression(replacement);\n }\n\n path.replaceWith(replacement);\n }\n\n return {\n name: \"bugfix-firefox-class-in-computed-class-key\",\n\n visitor: {\n Class(path) {\n const hasPrivateElement = path.node.body.body.some(node =>\n t.isPrivate(node),\n );\n if (!hasPrivateElement) return;\n\n for (const elem of path.get(\"body.body\")) {\n if (\n \"computed\" in elem.node &&\n elem.node.computed &&\n containsClassExpression(elem.get(\"key\"))\n ) {\n wrap(\n // @ts-expect-error .key also includes t.PrivateName\n elem.get(\"key\") satisfies NodePath<t.Expression>,\n );\n }\n }\n },\n },\n };\n});\n"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAAqD,IAAAE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEtC,IAAAC,0BAAO,EAAC,CAAC;EAAEC,KAAK,EAAEC,CAAC;EAAEC;AAAc,CAAC,KAAK;EACtDA,aAAa,CAAkB,CAAE,CAAC;EAElC,MAAMC,8BAA2D,GAAG;IAClEC,eAAeA,CAACC,IAAI,EAAEC,KAAK,EAAE;MAC3BA,KAAK,CAACC,KAAK,GAAG,IAAI;MAClBF,IAAI,CAACG,IAAI,CAAC,CAAC;IACb,CAAC;IACDC,QAAQA,CAACJ,IAAI,EAAE;MACbA,IAAI,CAACK,IAAI,CAAC,CAAC;IACb;EACF,CAAC;EAED,MAAMC,2BAA2B,GAAGC,kBAAQ,CAACC,kBAAkB,CAG5D;IACDC,eAAeA,CAACT,IAAI,EAAEC,KAAK,EAAE;MAC3BA,KAAK,CAACS,KAAK,GAAG,IAAI;MAClB,IAAIT,KAAK,CAACU,KAAK,EAAEX,IAAI,CAACG,IAAI,CAAC,CAAC;IAC9B,CAAC;I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