This commit is contained in:
2026-08-14 16:03:47 +01:00
parent fd53e3f4fb
commit dfdc3b2840
2463 changed files with 186456 additions and 111315 deletions
+57 -13
View File
@@ -15,7 +15,7 @@ let source, pos, end,
name;
function addImport (ss, s, e, d) {
const impt = { ss, se: d === -2 ? e : d === -1 ? e + 1 : 0, s, e, d, a: -1, n: undefined };
const impt = { ss, se: d === -2 ? e : d === -1 ? e + 1 : 0, s, e, d, a: -1, n: undefined, at: null };
imports.push(impt);
return impt;
}
@@ -141,6 +141,23 @@ export function parse (_source, _name) {
curDynamicImport = null;
}
break;
case 91/*[*/:
openTokenPosStack[openTokenDepth++] = lastTokenPos;
break;
case 93/*]*/:
if (openTokenDepth === 0)
syntaxError();
openTokenDepth--;
break;
case 44/*,*/:
if (curDynamicImport && curDynamicImport.e === 0 && curDynamicImport.d === openTokenPosStack[openTokenDepth - 1]) {
curDynamicImport.e = lastTokenPos + 1;
pos++;
commentWhitespace(true);
curDynamicImport.a = pos;
pos--;
}
break;
case 123/*{*/:
// dynamic import followed by { is not a dynamic import (so remove)
// this is a sneaky way to get around { import () {} } v { import () }
@@ -191,6 +208,7 @@ export function parse (_source, _name) {
!(lastToken === 46/*.*/ && (source.charCodeAt(lastTokenPos - 1) >= 48/*0*/ && source.charCodeAt(lastTokenPos - 1) <= 57/*9*/)) &&
!(lastToken === 43/*+*/ && source.charCodeAt(lastTokenPos - 1) === 43/*+*/) && !(lastToken === 45/*-*/ && source.charCodeAt(lastTokenPos - 1) === 45/*-*/) ||
lastToken === 41/*)*/ && isParenKeyword(openTokenPosStack[openTokenDepth]) ||
openTokenDepth > 0 && lastToken === 102/*f*/ && source.charCodeAt(lastTokenPos - 1) === 111/*o*/ && isForOfBinding(lastTokenPos - 2) && isForParen(openTokenPosStack[openTokenDepth - 1]) ||
lastToken === 125/*}*/ && (isExpressionTerminator(openTokenPosStack[openTokenDepth]) || openClassPosStack[openTokenDepth]) ||
lastToken === 47/*/*/ && lastSlashWasDivision ||
isExpressionKeyword(lastTokenPos) ||
@@ -608,58 +626,68 @@ function readImportString (ss, ch) {
readName(impt);
pos++;
ch = commentWhitespace(false);
if (ch !== 97/*a*/ || !source.startsWith('ssert', pos + 1)) {
if (ch !== 119/*w*/ || !source.startsWith('ith', pos + 1)) {
pos--;
return;
}
const assertIndex = pos;
const attrIndex = pos;
pos += 6;
pos += 4;
ch = commentWhitespace(true);
if (ch !== 123/*{*/) {
pos = assertIndex;
pos = attrIndex;
return;
}
const assertStart = pos;
const attrStart = pos;
const attrs = [];
do {
pos++;
ch = commentWhitespace(true);
let key, keyStart, keyEnd;
if (ch === 39/*'*/ || ch === 34/*"*/) {
keyStart = pos;
stringLiteral(ch);
keyEnd = pos + 1;
key = readString(keyStart, ch);
pos++;
ch = commentWhitespace(true);
}
else {
keyStart = pos;
ch = readToWsOrPunctuator(ch);
keyEnd = pos;
key = source.slice(keyStart, keyEnd);
}
if (ch !== 58/*:*/) {
pos = assertIndex;
pos = attrIndex;
return;
}
pos++;
ch = commentWhitespace(true);
let value, valueStart;
if (ch === 39/*'*/ || ch === 34/*"*/) {
valueStart = pos;
stringLiteral(ch);
value = readString(valueStart, ch);
}
else {
pos = assertIndex;
pos = attrIndex;
return;
}
attrs.push([key, value]);
pos++;
ch = commentWhitespace(true);
if (ch === 44/*,*/) {
pos++;
ch = commentWhitespace(true);
if (ch === 125/*}*/)
break;
continue;
}
if (ch === 125/*}*/)
break;
pos = assertIndex;
pos = attrIndex;
return;
} while (true);
impt.a = assertStart;
impt.a = attrStart;
impt.at = attrs;
impt.se = pos + 1;
}
@@ -885,6 +913,22 @@ function isParenKeyword (curPos) {
source.charCodeAt(curPos - 1) === 105/*i*/ && source.charCodeAt(curPos) === 102/*f*/;
}
function isForParen (curPos) {
return source.charCodeAt(curPos) === 114/*r*/ && source.startsWith('fo', curPos - 2);
}
// In valid JS, the for-of `of` keyword always follows a binding,
// which ends with an identifier-tail char, ']', '}', or ')'.
function isForOfBinding (pos) {
const ch = source.charCodeAt(pos);
if (!isBrOrWs(ch) && ch !== 93/*]*/ && ch !== 125/*}*/ && ch !== 41/*)*/)
return false;
while (pos > 0 && isBrOrWs(source.charCodeAt(pos)))
pos--;
const c = source.charCodeAt(pos);
return c === 93/*]*/ || c === 125/*}*/ || c === 41/*)*/ || !isPunctuator(c);
}
function isPunctuator (ch) {
// 23 possible punctuator endings: !%&()*+,-./:;<=>?[]^{}|~
return ch === 33/*!*/ || ch === 37/*%*/ || ch === 38/*&*/ ||