前端 uni-app 重写: 9页面 H5

This commit is contained in:
zhiqui
2026-11-15 15:09:37 +08:00
parent 513b53672e
commit ea7c2529e9
24104 changed files with 3667749 additions and 0 deletions
@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
# @babel/plugin-transform-block-scoping
> Compile ES2015 block scoping (const and let) to ES5
See our website [@babel/plugin-transform-block-scoping](https://babeljs.io/docs/babel-plugin-transform-block-scoping) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/plugin-transform-block-scoping
```
or using yarn:
```sh
yarn add @babel/plugin-transform-block-scoping --dev
```
@@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.annexB33FunctionsVisitor = void 0;
exports.isVarScope = isVarScope;
var _core = require("@babel/core");
const annexB33FunctionsVisitor = exports.annexB33FunctionsVisitor = Object.assign({
VariableDeclaration(path) {
if (isStrict(path)) return;
if (path.node.kind !== "var") return;
const varScope = path.scope.getFunctionParent() || path.scope.getProgramParent();
varScope.path.traverse(functionsToVarVisitor, {
names: Object.keys(path.getBindingIdentifiers())
});
}
}, {
BlockStatement(path) {
if (isStrict(path)) return;
if (_core.types.isFunction(path.parent, {
body: path.node
})) return;
transformStatementList(path.get("body"));
},
SwitchCase(path) {
if (isStrict(path)) return;
transformStatementList(path.get("consequent"));
}
});
function transformStatementList(paths) {
outer: for (const path of paths) {
if (!path.isFunctionDeclaration()) continue;
if (path.node.async || path.node.generator) return;
const {
scope
} = path.parentPath;
if (isVarScope(scope)) return;
const {
name
} = path.node.id;
let currScope = scope;
do {
if (currScope.parent.hasOwnBinding(name)) continue outer;
currScope = currScope.parent;
} while (!isVarScope(currScope));
maybeTransformBlockScopedFunction(path);
}
}
function maybeTransformBlockScopedFunction(path) {
const {
node,
parentPath: {
scope
}
} = path;
const {
id
} = node;
scope.removeOwnBinding(id.name);
node.id = null;
const varNode = _core.types.variableDeclaration("var", [_core.types.variableDeclarator(id, _core.types.toExpression(node))]);
varNode._blockHoist = 2;
const [varPath] = path.replaceWith(varNode);
scope.registerDeclaration(varPath);
}
const functionsToVarVisitor = {
Scope(path, {
names
}) {
for (const name of names) {
const binding = path.scope.getOwnBinding(name);
if ((binding == null ? void 0 : binding.kind) === "hoisted") {
maybeTransformBlockScopedFunction(binding.path);
}
}
},
"Expression|Declaration"(path) {
path.skip();
}
};
function isVarScope(scope) {
return scope.path.isFunctionParent() || scope.path.isProgram();
}
function isStrict(path) {
return !!path.find(({
node
}) => {
var _node$directives;
if (_core.types.isProgram(node)) {
if (node.sourceType === "module") return true;
} else if (_core.types.isClass(node)) {
return true;
} else if (!_core.types.isBlockStatement(node)) {
return false;
}
return (_node$directives = node.directives) == null ? void 0 : _node$directives.some(directive => directive.value.value === "use strict");
});
}
//# sourceMappingURL=annex-B_3_3.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,204 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _core = require("@babel/core");
var _loop = require("./loop.js");
var _validation = require("./validation.js");
var _annexB_3_ = require("./annex-B_3_3.js");
var _default = exports.default = (0, _helperPluginUtils.declare)((api, opts) => {
api.assertVersion(7);
const {
throwIfClosureRequired = false,
tdz: tdzEnabled = false
} = opts;
if (typeof throwIfClosureRequired !== "boolean") {
throw new Error(`.throwIfClosureRequired must be a boolean, or undefined`);
}
if (typeof tdzEnabled !== "boolean") {
throw new Error(`.tdz must be a boolean, or undefined`);
}
return {
name: "transform-block-scoping",
visitor: _core.traverse.visitors.merge([_annexB_3_.annexB33FunctionsVisitor, {
Loop(path, state) {
const isForStatement = path.isForStatement();
const headPath = isForStatement ? path.get("init") : path.isForXStatement() ? path.get("left") : null;
let needsBodyWrap = false;
const markNeedsBodyWrap = () => {
if (throwIfClosureRequired) {
throw path.buildCodeFrameError("Compiling let/const in this block would add a closure " + "(throwIfClosureRequired).");
}
needsBodyWrap = true;
};
if (path.isForStatement()) (0, _loop.moveCapturingTestAndUpdateIntoBody)(path);
const body = path.get("body");
let bodyScope;
if (body.isBlockStatement()) {
bodyScope = body.scope;
}
const bindings = (0, _loop.getLoopBodyBindings)(path);
for (const binding of bindings) {
const {
capturedInClosure
} = (0, _loop.getUsageInBody)(binding, path);
if (capturedInClosure) markNeedsBodyWrap();
}
const captured = [];
const updatedBindingsUsages = new Map();
if (headPath && isBlockScoped(headPath)) {
const names = Object.keys(headPath.getBindingIdentifiers());
const headScope = headPath.scope;
for (let name of names) {
var _bodyScope;
if ((_bodyScope = bodyScope) != null && _bodyScope.hasOwnBinding(name)) continue;
let binding = headScope.getOwnBinding(name);
if (!binding) {
headScope.crawl();
binding = headScope.getOwnBinding(name);
}
const {
usages,
capturedInClosure,
hasConstantViolations,
capturedInHeadClosure,
headUsages
} = (0, _loop.getUsageInBody)(binding, path);
if (headScope.parent.hasBinding(name) || headScope.parent.hasGlobal(name)) {
const newName = headScope.generateUid(name);
headScope.rename(name, newName);
name = newName;
}
if (capturedInHeadClosure && binding.constantViolations.length) {
const headName = headScope.generateUid(name);
const declarationIds = binding.path.get("id").getBindingIdentifierPaths(true)[name];
for (const usage of [...declarationIds, ...headUsages]) {
usage.replaceWith(_core.types.identifier(headName));
}
headPath.pushContainer("declarations", _core.types.variableDeclarator(_core.types.identifier(name), _core.types.identifier(headName)));
headScope.crawl();
}
if (capturedInClosure) {
markNeedsBodyWrap();
captured.push(name);
}
if (isForStatement && hasConstantViolations) {
updatedBindingsUsages.set(name, usages);
}
}
}
if (needsBodyWrap) {
const varPath = (0, _loop.wrapLoopBody)(path, captured, updatedBindingsUsages);
if (headPath != null && headPath.isVariableDeclaration()) {
transformBlockScopedVariable(headPath, state, tdzEnabled);
}
varPath.get("declarations.0.init").unwrapFunctionEnvironment();
}
},
VariableDeclaration(path, state) {
transformBlockScopedVariable(path, state, tdzEnabled);
},
ClassDeclaration(path) {
const {
id
} = path.node;
if (!id) return;
const {
scope
} = path.parentPath;
if (!(0, _annexB_3_.isVarScope)(scope) && scope.parent.hasBinding(id.name, {
noUids: true
})) {
path.scope.rename(id.name);
}
}
}])
};
});
const conflictingFunctionsVisitor = {
Scope(path, {
names
}) {
for (const name of names) {
const binding = path.scope.getOwnBinding(name);
if ((binding == null ? void 0 : binding.kind) === "hoisted") {
path.scope.rename(name);
}
}
},
"Expression|Declaration"(path) {
path.skip();
}
};
function transformBlockScopedVariable(path, state, tdzEnabled) {
if (!isBlockScoped(path)) return;
const dynamicTDZNames = (0, _validation.validateUsage)(path, state, tdzEnabled);
path.node.kind = "var";
const bindingNames = Object.keys(path.getBindingIdentifiers());
for (const name of bindingNames) {
const binding = path.scope.getOwnBinding(name);
if (!binding) continue;
binding.kind = "var";
}
const isLoopBodyDeclaration = isInLoop(path) && !(0, _loop.isVarInLoopHead)(path);
const isNestedForStatementInit = (0, _loop.isVarInForStatementInit)(path) && isInLoop(path.parentPath);
const shouldInitLoopDeclaration = isLoopBodyDeclaration || isNestedForStatementInit;
if (shouldInitLoopDeclaration || dynamicTDZNames.length > 0) {
for (const decl of path.node.declarations) {
var _decl$init;
(_decl$init = decl.init) != null ? _decl$init : decl.init = path.scope.buildUndefinedNode();
}
}
const blockScope = path.scope;
const varScope = blockScope.getFunctionParent() || blockScope.getProgramParent();
if (varScope !== blockScope) {
for (const name of bindingNames) {
let newName = name;
if (blockScope.parent.hasBinding(name, {
noUids: true
}) || blockScope.parent.hasGlobal(name)) {
newName = blockScope.generateUid(name);
blockScope.rename(name, newName);
}
blockScope.moveBindingTo(newName, varScope);
}
}
blockScope.path.traverse(conflictingFunctionsVisitor, {
names: bindingNames
});
for (const name of dynamicTDZNames) {
path.scope.push({
id: _core.types.identifier(name),
init: state.addHelper("temporalUndefined")
});
}
}
function isLetOrConst(kind) {
return kind === "let" || kind === "const";
}
function isInLoop(path) {
if (!path.parentPath) return false;
if (path.parentPath.isLoop()) return true;
if (path.parentPath.isFunctionParent()) return false;
return isInLoop(path.parentPath);
}
function isBlockScoped(path) {
const {
node
} = path;
if (!_core.types.isVariableDeclaration(node)) return false;
const {
kind
} = node;
if (kind === "using" || kind === "await using") {
throw path.buildCodeFrameError(`The ${kind} declaration should be first transformed by \`@babel/plugin-transform-explicit-resource-management\`.`);
} else if (!isLetOrConst(kind)) {
return false;
}
return true;
}
//# sourceMappingURL=index.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,423 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getLoopBodyBindings = getLoopBodyBindings;
exports.getUsageInBody = getUsageInBody;
exports.isVarInForStatementInit = isVarInForStatementInit;
exports.isVarInLoopHead = isVarInLoopHead;
exports.moveCapturingTestAndUpdateIntoBody = moveCapturingTestAndUpdateIntoBody;
exports.wrapLoopBody = wrapLoopBody;
var _core = require("@babel/core");
const collectLoopBodyBindingsVisitor = {
"Expression|Declaration"(path) {
path.skip();
},
Loop(path, state) {
path.skip();
if (!path.isForStatement()) return;
const init = path.get("init");
if (!init.isVariableDeclaration() || init.node.kind === "var") return;
for (const name of Object.keys(init.getBindingIdentifiers())) {
const binding = path.scope.getOwnBinding(name);
if (!binding) continue;
const capturedInHeadClosure = [...binding.referencePaths, ...binding.constantViolations].some(ref => {
const {
inHead,
inClosure
} = relativeLoopLocation(ref, path);
return inHead && inClosure;
});
if (capturedInHeadClosure) state.blockScoped.push(binding);
}
},
Scope(path, state) {
if (path.isFunctionParent()) path.skip();
const {
bindings
} = path.scope;
for (const name of Object.keys(bindings)) {
const binding = bindings[name];
if (binding.kind === "let" || binding.kind === "const" || binding.kind === "hoisted") {
state.blockScoped.push(binding);
}
}
}
};
function getLoopBodyBindings(loopPath) {
const state = {
blockScoped: []
};
loopPath.traverse(collectLoopBodyBindingsVisitor, state);
return state.blockScoped;
}
function getUsageInBody(binding, loopPath) {
const seen = new WeakSet();
let capturedInClosure = false;
let capturedInHeadClosure = false;
const headUsages = [];
const constantViolations = [];
for (const path of binding.constantViolations) {
var _id$getBindingIdentif;
const {
inBody,
inHead,
inClosure
} = relativeLoopLocation(path, loopPath);
const id = path.isUpdateExpression() ? path.get("argument") : path.isAssignmentExpression() ? path.get("left") : null;
if (id) seen.add(id.node);
const ids = (_id$getBindingIdentif = id == null ? void 0 : id.getBindingIdentifierPaths(true)[binding.identifier.name]) != null ? _id$getBindingIdentif : [];
if (inHead) {
capturedInHeadClosure || (capturedInHeadClosure = inClosure);
headUsages.push(...ids);
continue;
}
if (!inBody) continue;
capturedInClosure || (capturedInClosure = inClosure);
constantViolations.push(...ids);
}
const references = filterMap(binding.referencePaths, path => {
if (seen.has(path.node)) return null;
const {
inBody,
inHead,
inClosure
} = relativeLoopLocation(path, loopPath);
if (inHead) {
capturedInHeadClosure || (capturedInHeadClosure = inClosure);
headUsages.push(path);
return null;
}
if (!inBody) return null;
capturedInClosure || (capturedInClosure = inClosure);
return path;
});
return {
capturedInClosure,
hasConstantViolations: constantViolations.length > 0,
usages: references.concat(constantViolations),
capturedInHeadClosure,
headUsages
};
}
function moveCapturingTestAndUpdateIntoBody(loopPath) {
const init = loopPath.get("init");
if (!init.isVariableDeclaration() || init.node.kind !== "let") return;
let testCaptures = false;
let updateCaptures = false;
for (const name of Object.keys(init.getBindingIdentifiers())) {
const binding = loopPath.scope.getOwnBinding(name);
if (!(binding != null && binding.constantViolations.length)) continue;
for (const ref of [...binding.referencePaths, ...binding.constantViolations]) {
const {
inTest,
inUpdate,
inClosure
} = relativeLoopLocation(ref, loopPath);
testCaptures || (testCaptures = inTest && inClosure);
updateCaptures || (updateCaptures = inUpdate && inClosure);
}
}
if (!testCaptures && !updateCaptures) return;
makeAnnexBAssignmentsExplicit(loopPath);
const {
node
} = loopPath;
const bodyStmts = [];
if (updateCaptures && node.update) {
const first = loopPath.scope.generateUid("first");
init.node.declarations.push(_core.types.variableDeclarator(_core.types.identifier(first), _core.types.booleanLiteral(true)));
bodyStmts.push(_core.types.ifStatement(_core.types.unaryExpression("!", _core.types.identifier(first)), _core.types.expressionStatement(node.update)));
node.update = _core.types.assignmentExpression("=", _core.types.identifier(first), _core.types.booleanLiteral(false));
}
if (node.test) {
bodyStmts.push(_core.types.ifStatement(_core.types.unaryExpression("!", node.test), _core.types.breakStatement()));
node.test = null;
}
if (!_core.types.isEmptyStatement(node.body)) bodyStmts.push(node.body);
node.body = _core.types.blockStatement(bodyStmts);
loopPath.scope.crawl();
}
function makeAnnexBAssignmentsExplicit(loopPath) {
const declarations = [];
loopPath.get("body").traverse({
Function(path) {
if (path.isFunctionDeclaration() && (path.parentPath.isBlockStatement() || path.parentPath.isSwitchCase()) && path.node.id && !path.node.generator && !path.node.async && !path.isInStrictMode() && !hasLexicalConflict(loopPath, path.node.id.name)) {
declarations.push(path);
}
path.skip();
}
});
if (declarations.length === 0) return;
const names = new Set();
const renamed = new Map();
for (const path of declarations) {
const name = path.node.id.name;
names.add(name);
const declScope = path.scope.parent;
if (!renamed.has(declScope)) renamed.set(declScope, new Set());
if (!renamed.get(declScope).has(name)) {
renamed.get(declScope).add(name);
declScope.rename(name);
}
path.insertAfter(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.identifier(name), _core.types.cloneNode(path.node.id))));
}
const body = _core.types.toBlock(loopPath.node.body);
body.body.unshift(_core.types.variableDeclaration("var", Array.from(names, name => _core.types.variableDeclarator(_core.types.identifier(name)))));
loopPath.node.body = body;
}
function hasLexicalConflict(loopPath, name) {
const binding = loopPath.scope.getBinding(name);
return !!binding && binding.kind !== "var" && binding.kind !== "hoisted";
}
function relativeLoopLocation(path, loopPath) {
const bodyPath = loopPath.get("body");
const headPath = loopPath.isForStatement() ? loopPath.get("init") : null;
const testPath = loopPath.isForStatement() ? loopPath.get("test") : null;
const updatePath = loopPath.isForStatement() ? loopPath.get("update") : null;
let inClosure = false;
for (let currPath = path; currPath; currPath = currPath.parentPath) {
if (currPath.isFunction() || currPath.isClass() || currPath.isMethod()) {
inClosure = true;
}
const location = {
inBody: false,
inHead: false,
inTest: false,
inUpdate: false,
inClosure
};
if (currPath === bodyPath) {
return Object.assign({}, location, {
inBody: true
});
} else if (headPath && currPath === headPath) {
return Object.assign({}, location, {
inHead: true
});
} else if (testPath != null && testPath.node && currPath === testPath) {
return Object.assign({}, location, {
inTest: true
});
} else if (updatePath != null && updatePath.node && currPath === updatePath) {
return Object.assign({}, location, {
inUpdate: true
});
} else if (currPath === loopPath) {
return location;
}
}
throw new Error("Internal Babel error: path is not in loop. Please report this as a bug.");
}
const collectCompletionsAndVarsVisitor = {
Function(path) {
path.skip();
},
LabeledStatement: {
enter({
node
}, state) {
state.labelsStack.push(node.label.name);
},
exit({
node
}, state) {
const popped = state.labelsStack.pop();
if (popped !== node.label.name) {
throw new Error("Assertion failure. Please report this bug to Babel.");
}
}
},
Loop: {
enter(_, state) {
state.labellessContinueTargets++;
state.labellessBreakTargets++;
},
exit(_, state) {
state.labellessContinueTargets--;
state.labellessBreakTargets--;
}
},
SwitchStatement: {
enter(_, state) {
state.labellessBreakTargets++;
},
exit(_, state) {
state.labellessBreakTargets--;
}
},
"BreakStatement|ContinueStatement"(path, state) {
const {
label
} = path.node;
if (label) {
if (state.labelsStack.includes(label.name)) return;
} else if (path.isBreakStatement() ? state.labellessBreakTargets > 0 : state.labellessContinueTargets > 0) {
return;
}
state.breaksContinues.push(path);
},
ReturnStatement(path, state) {
state.returns.push(path);
},
VariableDeclaration(path, state) {
if (path.parent === state.loopNode && isVarInLoopHead(path)) return;
if (path.node.kind === "var") state.vars.push(path);
}
};
function wrapLoopBody(loopPath, captured, updatedBindingsUsages) {
const loopNode = loopPath.node;
const state = {
breaksContinues: [],
returns: [],
labelsStack: [],
labellessBreakTargets: 0,
labellessContinueTargets: 0,
vars: [],
loopNode
};
loopPath.traverse(collectCompletionsAndVarsVisitor, state);
const callArgs = [];
const closureParams = [];
const updater = [];
for (const [name, updatedUsage] of updatedBindingsUsages) {
callArgs.push(_core.types.identifier(name));
const innerName = loopPath.scope.generateUid(name);
closureParams.push(_core.types.identifier(innerName));
updater.push(_core.types.assignmentExpression("=", _core.types.identifier(name), _core.types.identifier(innerName)));
for (const path of updatedUsage) path.replaceWith(_core.types.identifier(innerName));
}
for (const name of captured) {
if (updatedBindingsUsages.has(name)) continue;
callArgs.push(_core.types.identifier(name));
closureParams.push(_core.types.identifier(name));
}
const id = loopPath.scope.generateUid("loop");
const fn = _core.types.functionExpression(null, closureParams, _core.types.blockStatement([]));
let call = _core.types.callExpression(_core.types.identifier(id), callArgs);
const fnParent = loopPath.findParent(p => p.isFunctionParent());
if (fnParent) {
const {
async = false,
generator = false
} = fnParent.node;
fn.async = async;
fn.generator = generator;
if (generator) call = _core.types.yieldExpression(call, true);else if (async) call = _core.types.awaitExpression(call);
}
const updaterNode = updater.length > 0 ? _core.types.expressionStatement(_core.types.sequenceExpression(updater)) : null;
const [varPath] = loopPath.insertBefore(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(id), fn)]));
const bodyStmts = [];
const varNames = [];
for (const varPath of state.vars) {
const assign = [];
for (const decl of varPath.node.declarations) {
varNames.push(...Object.keys(_core.types.getBindingIdentifiers(decl.id)));
if (decl.init) {
assign.push(_core.types.assignmentExpression("=", decl.id, decl.init));
} else if (_core.types.isForXStatement(varPath.parent, {
left: varPath.node
})) {
assign.push(decl.id);
}
}
if (assign.length > 0) {
const replacement = assign.length === 1 ? assign[0] : _core.types.sequenceExpression(assign);
varPath.replaceWith(replacement);
} else {
varPath.remove();
}
}
if (varNames.length) {
varPath.pushContainer("declarations", varNames.map(name => _core.types.variableDeclarator(_core.types.identifier(name))));
}
const labelNum = state.breaksContinues.length;
const returnNum = state.returns.length;
if (labelNum + returnNum === 0) {
bodyStmts.push(_core.types.expressionStatement(call));
} else if (labelNum === 1 && returnNum === 0) {
for (const path of state.breaksContinues) {
const {
node
} = path;
const {
type,
label
} = node;
let name = type === "BreakStatement" ? "break" : "continue";
if (label) name += " " + label.name;
path.replaceWith(_core.types.addComment(_core.types.returnStatement(_core.types.numericLiteral(1)), "trailing", " " + name, true));
if (updaterNode) path.insertBefore(_core.types.cloneNode(updaterNode));
bodyStmts.push(_core.template.statement.ast`
if (${call}) ${node}
`);
}
} else {
const completionId = loopPath.scope.generateUid("ret");
if (varPath.isVariableDeclaration()) {
varPath.pushContainer("declarations", [_core.types.variableDeclarator(_core.types.identifier(completionId))]);
bodyStmts.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.identifier(completionId), call)));
} else {
bodyStmts.push(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(completionId), call)]));
}
const injected = [];
for (const path of state.breaksContinues) {
const {
node
} = path;
const {
type,
label
} = node;
let name = type === "BreakStatement" ? "break" : "continue";
if (label) name += " " + label.name;
let i = injected.indexOf(name);
const hasInjected = i !== -1;
if (!hasInjected) {
injected.push(name);
i = injected.length - 1;
}
path.replaceWith(_core.types.addComment(_core.types.returnStatement(_core.types.numericLiteral(i)), "trailing", " " + name, true));
if (updaterNode) path.insertBefore(_core.types.cloneNode(updaterNode));
if (hasInjected) continue;
bodyStmts.push(_core.template.statement.ast`
if (${_core.types.identifier(completionId)} === ${_core.types.numericLiteral(i)}) ${node}
`);
}
if (returnNum) {
for (const path of state.returns) {
const arg = path.node.argument || path.scope.buildUndefinedNode();
path.replaceWith(_core.template.statement.ast`
return { v: ${arg} };
`);
}
bodyStmts.push(_core.template.statement.ast`
if (${_core.types.identifier(completionId)}) return ${_core.types.identifier(completionId)}.v;
`);
}
}
const loopBlockBody = _core.types.toBlock(loopNode.body);
loopNode.body = _core.types.blockStatement(bodyStmts);
fn.body = loopBlockBody;
if (updaterNode) loopBlockBody.body.push(updaterNode);
return varPath;
}
function isVarInLoopHead(path) {
if (_core.types.isForStatement(path.parent)) return path.key === "init";
if (_core.types.isForXStatement(path.parent)) return path.key === "left";
return false;
}
function isVarInForStatementInit(path) {
return path.parentPath.isForStatement() && path.key === "init";
}
function filterMap(list, fn) {
const result = [];
for (const item of list) {
const mapped = fn(item);
if (mapped) result.push(mapped);
}
return result;
}
//# sourceMappingURL=loop.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,133 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateUsage = validateUsage;
var _core = require("@babel/core");
function validateUsage(path, state, tdzEnabled) {
const dynamicTDZNames = [];
for (const name of Object.keys(path.getBindingIdentifiers())) {
const binding = path.scope.getBinding(name);
if (!binding) continue;
if (tdzEnabled) {
if (injectTDZChecks(binding, state)) dynamicTDZNames.push(name);
}
if (path.node.kind === "const") {
disallowConstantViolations(name, binding, state);
}
}
return dynamicTDZNames;
}
function disallowConstantViolations(name, binding, state) {
for (const violation of binding.constantViolations) {
const readOnlyError = state.addHelper("readOnlyError");
const throwNode = _core.types.callExpression(readOnlyError, [_core.types.stringLiteral(name)]);
if (violation.isAssignmentExpression()) {
const {
operator,
left,
right
} = violation.node;
if (operator === "=") {
const exprs = [right];
exprs.push(throwNode);
violation.replaceWith(_core.types.sequenceExpression(exprs));
} else if (["&&=", "||=", "??="].includes(operator)) {
violation.replaceWith(_core.types.logicalExpression(operator.slice(0, -1), left, _core.types.sequenceExpression([right, throwNode])));
} else {
violation.replaceWith(_core.types.sequenceExpression([_core.types.binaryExpression(operator.slice(0, -1), left, right), throwNode]));
}
} else if (violation.isUpdateExpression()) {
violation.replaceWith(_core.types.sequenceExpression([_core.types.unaryExpression("+", violation.get("argument").node), throwNode]));
} else if (violation.isForXStatement()) {
violation.ensureBlock();
violation.get("left").replaceWith(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(violation.scope.generateUidIdentifier(name))]));
violation.node.body.body.unshift(_core.types.expressionStatement(throwNode));
}
}
}
function getTDZStatus(refPath, bindingPath) {
const executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath);
if (executionStatus === "before") {
return "outside";
} else if (executionStatus === "after") {
return "inside";
} else {
return "maybe";
}
}
const skipTDZChecks = new WeakSet();
function buildTDZAssert(status, node, state) {
if (status === "maybe") {
const clone = _core.types.cloneNode(node);
skipTDZChecks.add(clone);
return _core.types.callExpression(state.addHelper("temporalRef"), [clone, _core.types.stringLiteral(node.name)]);
} else {
return _core.types.callExpression(state.addHelper("tdz"), [_core.types.stringLiteral(node.name)]);
}
}
function getTDZReplacement(path, state, id = path.node) {
var _path$scope$getBindin;
if (skipTDZChecks.has(id)) return;
skipTDZChecks.add(id);
const bindingPath = (_path$scope$getBindin = path.scope.getBinding(id.name)) == null ? void 0 : _path$scope$getBindin.path;
if (!bindingPath || bindingPath.isFunctionDeclaration()) return;
const status = getTDZStatus(path, bindingPath);
if (status === "outside") return;
if (status === "maybe") {
bindingPath.parent._tdzThis = true;
}
return {
status,
node: buildTDZAssert(status, id, state)
};
}
function injectTDZChecks(binding, state) {
const allUsages = new Set(binding.referencePaths);
binding.constantViolations.forEach(allUsages.add, allUsages);
let dynamicTdz = false;
for (const path of binding.constantViolations) {
const {
node
} = path;
if (skipTDZChecks.has(node)) continue;
skipTDZChecks.add(node);
if (path.isUpdateExpression()) {
const arg = path.get("argument");
const replacement = getTDZReplacement(path, state, arg.node);
if (!replacement) continue;
if (replacement.status === "maybe") {
dynamicTdz = true;
path.insertBefore(replacement.node);
} else {
path.replaceWith(replacement.node);
}
} else if (path.isAssignmentExpression()) {
const nodes = [];
const ids = path.getBindingIdentifiers();
for (const name of Object.keys(ids)) {
const replacement = getTDZReplacement(path, state, ids[name]);
if (replacement) {
nodes.push(_core.types.expressionStatement(replacement.node));
if (replacement.status === "inside") break;
if (replacement.status === "maybe") dynamicTdz = true;
}
}
if (nodes.length > 0) path.insertBefore(nodes);
}
}
for (const path of binding.referencePaths) {
if (path.parentPath.isUpdateExpression()) continue;
if (path.parentPath.isForXStatement({
left: path.node
})) continue;
const replacement = getTDZReplacement(path, state);
if (!replacement) continue;
if (replacement.status === "maybe") dynamicTdz = true;
path.replaceWith(replacement.node);
}
return dynamicTdz;
}
//# sourceMappingURL=validation.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,35 @@
{
"name": "@babel/plugin-transform-block-scoping",
"version": "7.29.13",
"description": "Compile ES2015 block scoping (const and let) to ES5",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-plugin-transform-block-scoping"
},
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-block-scoping",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "./lib/index.js",
"dependencies": {
"@babel/helper-plugin-utils": "^7.29.7"
},
"keywords": [
"babel-plugin"
],
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.29.13",
"@babel/helper-plugin-test-runner": "^7.29.7",
"@babel/traverse": "^7.29.13"
},
"engines": {
"node": ">=6.9.0"
},
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
}