diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-12-21 22:46:53 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-12-21 22:46:53 +0800 |
| commit | f06956efd2dc4bf77244a9fcce2b883a00b925af (patch) | |
| tree | 0123cb73ce67f1f4b17e1d6cbabff076ee44e31b /node_modules/@babel/plugin-transform-object-super/lib/index.js | |
| parent | 8d980c13970c15b6d2312b6fc4ac51698dd0d220 (diff) | |
updated node modules
Diffstat (limited to 'node_modules/@babel/plugin-transform-object-super/lib/index.js')
| -rw-r--r-- | node_modules/@babel/plugin-transform-object-super/lib/index.js | 35 |
1 files changed, 30 insertions, 5 deletions
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 |
