| 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 | {
|
|---|
| 40 | path.traverse(containsClassExpressionVisitor, state);
|
|---|
| 41 | }
|
|---|
| 42 | return state.found;
|
|---|
| 43 | }
|
|---|
| 44 | function wrap(path) {
|
|---|
| 45 | const context = {
|
|---|
| 46 | yield: t.isYieldExpression(path.node),
|
|---|
| 47 | await: t.isAwaitExpression(path.node)
|
|---|
| 48 | };
|
|---|
| 49 | {
|
|---|
| 50 | path.traverse(containsYieldOrAwaitVisitor, context);
|
|---|
| 51 | }
|
|---|
| 52 | let replacement;
|
|---|
| 53 | if (context.yield) {
|
|---|
| 54 | const fn = t.functionExpression(null, [], t.blockStatement([t.returnStatement(path.node)]), true, context.await);
|
|---|
| 55 | replacement = t.yieldExpression(t.callExpression(t.memberExpression(fn, t.identifier("call")), [t.thisExpression(), t.identifier("arguments")]), true);
|
|---|
| 56 | } else {
|
|---|
| 57 | const fn = t.arrowFunctionExpression([], path.node, context.await);
|
|---|
| 58 | replacement = t.callExpression(fn, []);
|
|---|
| 59 | if (context.await) replacement = t.awaitExpression(replacement);
|
|---|
| 60 | }
|
|---|
| 61 | path.replaceWith(replacement);
|
|---|
| 62 | }
|
|---|
| 63 | return {
|
|---|
| 64 | name: "bugfix-firefox-class-in-computed-class-key",
|
|---|
| 65 | visitor: {
|
|---|
| 66 | Class(path) {
|
|---|
| 67 | const hasPrivateElement = path.node.body.body.some(node => t.isPrivate(node));
|
|---|
| 68 | if (!hasPrivateElement) return;
|
|---|
| 69 | for (const elem of path.get("body.body")) {
|
|---|
| 70 | if ("computed" in elem.node && elem.node.computed && containsClassExpression(elem.get("key"))) {
|
|---|
| 71 | wrap(elem.get("key"));
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 | };
|
|---|
| 77 | });
|
|---|
| 78 |
|
|---|
| 79 | //# sourceMappingURL=index.js.map
|
|---|