This commit is contained in:
2023-08-11 10:45:20 +08:00
commit 161ca982f3
31850 changed files with 2706500 additions and 0 deletions

View File

@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _helperReplaceSupers = require("@babel/helper-replace-supers");
var _core = require("@babel/core");
function replacePropertySuper(path, getObjectRef, file) {
const replaceSupers = new _helperReplaceSupers.default({
getObjectRef: getObjectRef,
methodPath: path,
file: file
});
replaceSupers.replace();
}
var _default = (0, _helperPluginUtils.declare)(api => {
api.assertVersion(7);
return {
name: "transform-object-super",
visitor: {
ObjectExpression(path, state) {
let objectRef;
const getObjectRef = () => objectRef = objectRef || path.scope.generateUidIdentifier("obj");
path.get("properties").forEach(propPath => {
if (!propPath.isMethod()) return;
replacePropertySuper(propPath, getObjectRef, state.file);
});
if (objectRef) {
path.scope.push({
id: _core.types.cloneNode(objectRef)
});
path.replaceWith(_core.types.assignmentExpression("=", _core.types.cloneNode(objectRef), path.node));
}
}
}
};
});
exports.default = _default;
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"names":["_helperPluginUtils","require","_helperReplaceSupers","_core","replacePropertySuper","path","getObjectRef","file","replaceSupers","ReplaceSupers","methodPath","replace","_default","declare","api","assertVersion","name","visitor","ObjectExpression","state","objectRef","scope","generateUidIdentifier","get","forEach","propPath","isMethod","push","id","t","cloneNode","replaceWith","assignmentExpression","node","exports","default"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport ReplaceSupers from \"@babel/helper-replace-supers\";\nimport { types as t, type File } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\n\nfunction replacePropertySuper(\n path: NodePath<t.ObjectMethod>,\n getObjectRef: () => t.Identifier,\n file: File,\n) {\n // @ts-expect-error todo(flow->ts):\n const replaceSupers = new ReplaceSupers({\n getObjectRef: getObjectRef,\n methodPath: path,\n file: file,\n });\n\n replaceSupers.replace();\n}\n\nexport default declare(api => {\n api.assertVersion(7);\n\n return {\n name: \"transform-object-super\",\n\n visitor: {\n ObjectExpression(path, state) {\n let objectRef: t.Identifier;\n const getObjectRef = () =>\n (objectRef = objectRef || path.scope.generateUidIdentifier(\"obj\"));\n\n path.get(\"properties\").forEach(propPath => {\n if (!propPath.isMethod()) return;\n\n replacePropertySuper(propPath, getObjectRef, state.file);\n });\n\n if (objectRef) {\n path.scope.push({ id: t.cloneNode(objectRef) });\n path.replaceWith(\n t.assignmentExpression(\"=\", t.cloneNode(objectRef), path.node),\n );\n }\n },\n },\n };\n});\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAGA,SAASG,oBAAoBA,CAC3BC,IAA8B,EAC9BC,YAAgC,EAChCC,IAAU,EACV;EAEA,MAAMC,aAAa,GAAG,IAAIC,4BAAa,CAAC;IACtCH,YAAY,EAAEA,YAAY;IAC1BI,UAAU,EAAEL,IAAI;IAChBE,IAAI,EAAEA;EACR,CAAC,CAAC;EAEFC,aAAa,CAACG,OAAO,CAAC,CAAC;AACzB;AAAC,IAAAC,QAAA,GAEc,IAAAC,0BAAO,EAACC,GAAG,IAAI;EAC5BA,GAAG,CAACC,aAAa,CAAC,CAAC,CAAC;EAEpB,OAAO;IACLC,IAAI,EAAE,wBAAwB;IAE9BC,OAAO,EAAE;MACPC,gBAAgBA,CAACb,IAAI,EAAEc,KAAK,EAAE;QAC5B,IAAIC,SAAuB;QAC3B,MAAMd,YAAY,GAAGA,CAAA,KAClBc,SAAS,GAAGA,SAAS,IAAIf,IAAI,CAACgB,KAAK,CAACC,qBAAqB,CAAC,KAAK,CAAE;QAEpEjB,IAAI,CAACkB,GAAG,CAAC,YAAY,CAAC,CAACC,OAAO,CAACC,QAAQ,IAAI;UACzC,IAAI,CAACA,QAAQ,CAACC,QAAQ,CAAC,CAAC,EAAE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