1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 | var _traverse = require("@babel/traverse");
|
---|
8 | var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
---|
9 | var _default = exports.default = (0, _helperPluginUtils.declare)(({
|
---|
10 | types: t,
|
---|
11 | assertVersion
|
---|
12 | }) => {
|
---|
13 | assertVersion(7);
|
---|
14 | const containsClassExpressionVisitor = {
|
---|
15 | ClassExpression(path, state) {
|
---|
16 | state.found = true;
|
---|
17 | path.stop();
|
---|
18 | },
|
---|
19 | Function(path) {
|
---|
20 | path.skip();
|
---|
21 | }
|
---|
22 | };
|
---|
23 | const containsYieldOrAwaitVisitor = _traverse.visitors.environmentVisitor({
|
---|
24 | YieldExpression(path, state) {
|
---|
25 | state.yield = true;
|
---|
26 | if (state.await) path.stop();
|
---|
27 | },
|
---|
28 | AwaitExpression(path, state) {
|
---|
29 | state.await = true;
|
---|
30 | if (state.yield) path.stop();
|
---|
31 | }
|
---|
32 | });
|
---|
33 | function containsClassExpression(path) {
|
---|
34 | if (t.isClassExpression(path.node)) return true;
|
---|
35 | if (t.isFunction(path.node)) return false;
|
---|
36 | const state = {
|
---|
37 | found: false
|
---|
38 | };
|
---|
39 | path.traverse(containsClassExpressionVisitor, state);
|
---|
40 | return state.found;
|
---|
41 | }
|
---|
42 | function wrap(path) {
|
---|
43 | const context = {
|
---|
44 | yield: t.isYieldExpression(path.node),
|
---|
45 | await: t.isAwaitExpression(path.node)
|
---|
46 | };
|
---|
47 | path.traverse(containsYieldOrAwaitVisitor, context);
|
---|
48 | let replacement;
|
---|
49 | if (context.yield) {
|
---|
50 | const fn = t.functionExpression(null, [], t.blockStatement([t.returnStatement(path.node)]), true, context.await);
|
---|
51 | replacement = t.yieldExpression(t.callExpression(t.memberExpression(fn, t.identifier("call")), [t.thisExpression(), t.identifier("arguments")]), true);
|
---|
52 | } else {
|
---|
53 | const fn = t.arrowFunctionExpression([], path.node, context.await);
|
---|
54 | replacement = t.callExpression(fn, []);
|
---|
55 | if (context.await) replacement = t.awaitExpression(replacement);
|
---|
56 | }
|
---|
57 | path.replaceWith(replacement);
|
---|
58 | }
|
---|
59 | return {
|
---|
60 | name: "bugfix-firefox-class-in-computed-class-key",
|
---|
61 | visitor: {
|
---|
62 | Class(path) {
|
---|
63 | const hasPrivateElement = path.node.body.body.some(node => t.isPrivate(node));
|
---|
64 | if (!hasPrivateElement) return;
|
---|
65 | for (const elem of path.get("body.body")) {
|
---|
66 | if ("computed" in elem.node && elem.node.computed && containsClassExpression(elem.get("key"))) {
|
---|
67 | wrap(elem.get("key"));
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|
72 | };
|
---|
73 | });
|
---|
74 |
|
---|
75 | //# sourceMappingURL=index.js.map
|
---|