[79a0317] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = void 0;
|
---|
| 7 | var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
---|
| 8 | var _helperReplaceSupers = require("@babel/helper-replace-supers");
|
---|
| 9 | var _core = require("@babel/core");
|
---|
| 10 | function replacePropertySuper(path, getObjectRef, file) {
|
---|
| 11 | const replaceSupers = new _helperReplaceSupers.default({
|
---|
| 12 | getObjectRef: getObjectRef,
|
---|
| 13 | methodPath: path,
|
---|
| 14 | file: file
|
---|
| 15 | });
|
---|
| 16 | replaceSupers.replace();
|
---|
| 17 | }
|
---|
| 18 | var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
|
---|
| 19 | api.assertVersion(7);
|
---|
| 20 | const newLets = new Set();
|
---|
| 21 | return {
|
---|
| 22 | name: "transform-object-super",
|
---|
| 23 | visitor: {
|
---|
| 24 | Loop: {
|
---|
| 25 | exit(path) {
|
---|
| 26 | newLets.forEach(v => {
|
---|
| 27 | if (v.scopePath === path) {
|
---|
| 28 | path.scope.push({
|
---|
| 29 | id: v.id,
|
---|
| 30 | kind: "let"
|
---|
| 31 | });
|
---|
| 32 | path.scope.crawl();
|
---|
| 33 | path.requeue();
|
---|
| 34 | newLets.delete(v);
|
---|
| 35 | }
|
---|
| 36 | });
|
---|
| 37 | }
|
---|
| 38 | },
|
---|
| 39 | ObjectExpression(path, state) {
|
---|
| 40 | let objectRef;
|
---|
| 41 | const getObjectRef = () => objectRef = objectRef || path.scope.generateUidIdentifier("obj");
|
---|
| 42 | path.get("properties").forEach(propPath => {
|
---|
| 43 | if (!propPath.isMethod()) return;
|
---|
| 44 | replacePropertySuper(propPath, getObjectRef, state.file);
|
---|
| 45 | });
|
---|
| 46 | if (objectRef) {
|
---|
| 47 | const scopePath = path.findParent(p => p.isFunction() || p.isProgram() || p.isLoop());
|
---|
| 48 | const useLet = scopePath.isLoop();
|
---|
| 49 | if (useLet) {
|
---|
| 50 | newLets.add({
|
---|
| 51 | scopePath,
|
---|
| 52 | id: _core.types.cloneNode(objectRef)
|
---|
| 53 | });
|
---|
| 54 | } else {
|
---|
| 55 | path.scope.push({
|
---|
| 56 | id: _core.types.cloneNode(objectRef),
|
---|
| 57 | kind: "var"
|
---|
| 58 | });
|
---|
| 59 | }
|
---|
| 60 | path.replaceWith(_core.types.assignmentExpression("=", _core.types.cloneNode(objectRef), path.node));
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | };
|
---|
| 65 | });
|
---|
| 66 |
|
---|
| 67 | //# sourceMappingURL=index.js.map
|
---|