From f06956efd2dc4bf77244a9fcce2b883a00b925af Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 21 Dec 2023 22:46:53 +0800 Subject: updated node modules --- .../plugin-transform-object-super/lib/index.js | 35 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'node_modules/@babel/plugin-transform-object-super/lib/index.js') diff --git a/node_modules/@babel/plugin-transform-object-super/lib/index.js b/node_modules/@babel/plugin-transform-object-super/lib/index.js index 59dad106..345090db 100644 --- a/node_modules/@babel/plugin-transform-object-super/lib/index.js +++ b/node_modules/@babel/plugin-transform-object-super/lib/index.js @@ -15,11 +15,27 @@ function replacePropertySuper(path, getObjectRef, file) { }); replaceSupers.replace(); } -var _default = (0, _helperPluginUtils.declare)(api => { +var _default = exports.default = (0, _helperPluginUtils.declare)(api => { api.assertVersion(7); + const newLets = new Set(); return { name: "transform-object-super", visitor: { + 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); + } + }); + } + }, ObjectExpression(path, state) { let objectRef; const getObjectRef = () => objectRef = objectRef || path.scope.generateUidIdentifier("obj"); @@ -28,15 +44,24 @@ var _default = (0, _helperPluginUtils.declare)(api => { replacePropertySuper(propPath, getObjectRef, state.file); }); if (objectRef) { - path.scope.push({ - id: _core.types.cloneNode(objectRef) - }); + 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)); } } } }; }); -exports.default = _default; //# sourceMappingURL=index.js.map -- cgit v1.2.3