1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@babel/plugin-transform-object-super/lib/index.js

68 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
2024-01-16 21:26:16 +08:00
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _helperReplaceSupers = require("@babel/helper-replace-supers");
var _core = require("@babel/core");
2023-12-18 13:12:25 +08:00
function replacePropertySuper(path, getObjectRef, file) {
2024-01-16 21:26:16 +08:00
const replaceSupers = new _helperReplaceSupers.default({
2023-12-18 13:12:25 +08:00
getObjectRef: getObjectRef,
methodPath: path,
file: file
});
replaceSupers.replace();
}
2024-01-16 21:26:16 +08:00
var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
2023-12-18 13:12:25 +08:00
api.assertVersion(7);
2024-01-16 21:26:16 +08:00
const newLets = new Set();
2023-12-18 13:12:25 +08:00
return {
name: "transform-object-super",
visitor: {
2024-01-16 21:26:16 +08:00
Loop: {
exit(path) {
newLets.forEach(v => {
if (v.scopePath === path) {
path.scope.push({
id: v.id,
kind: "let"
});
path.scope.crawl();
path.requeue();
newLets.delete(v);
}
});
}
},
2023-12-18 13:12:25 +08:00
ObjectExpression(path, state) {
let objectRef;
const getObjectRef = () => objectRef = objectRef || path.scope.generateUidIdentifier("obj");
path.get("properties").forEach(propPath => {
if (!propPath.isMethod()) return;
2024-01-16 21:26:16 +08:00
replacePropertySuper(propPath, getObjectRef, state.file);
2023-12-18 13:12:25 +08:00
});
if (objectRef) {
2024-01-16 21:26:16 +08:00
const scopePath = path.findParent(p => p.isFunction() || p.isProgram() || p.isLoop());
const useLet = scopePath.isLoop();
if (useLet) {
newLets.add({
scopePath,
id: _core.types.cloneNode(objectRef)
});
} else {
path.scope.push({
id: _core.types.cloneNode(objectRef),
kind: "var"
});
}
path.replaceWith(_core.types.assignmentExpression("=", _core.types.cloneNode(objectRef), path.node));
2023-12-18 13:12:25 +08:00
}
}
}
};
});
2024-01-16 21:26:16 +08:00
//# sourceMappingURL=index.js.map