Skip to content

Commit 38aa9d6

Browse files
nodejs-github-bottargos
authored andcommittedOct 2, 2024
deps: update acorn to 8.12.1
PR-URL: #53465 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 0309b05 commit 38aa9d6

File tree

8 files changed

+239
-86
lines changed

8 files changed

+239
-86
lines changed
 

‎deps/acorn/acorn/CHANGELOG.md

+30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
## 8.12.1 (2024-07-03)
2+
3+
### Bug fixes
4+
5+
Fix a regression that caused Acorn to no longer run on Node versions <8.10.
6+
7+
## 8.12.0 (2024-06-14)
8+
9+
### New features
10+
11+
Support ES2025 duplicate capture group names in regular expressions.
12+
13+
### Bug fixes
14+
15+
Include `VariableDeclarator` in the `AnyNode` type so that walker objects can refer to it without getting a type error.
16+
17+
Properly raise a parse error for invalid `for`/`of` statements using `async` as binding name.
18+
19+
Properly recognize \"use strict\" when preceded by a string with an escaped newline.
20+
21+
Mark the `Parser` constructor as protected, not private, so plugins can extend it without type errors.
22+
23+
Fix a bug where some invalid `delete` expressions were let through when the operand was parenthesized and `preserveParens` was enabled.
24+
25+
Properly normalize line endings in raw strings of invalid template tokens.
26+
27+
Properly track line numbers for escaped newlines in strings.
28+
29+
Fix a bug that broke line number accounting after a template literal with invalid escape sequences.
30+
131
## 8.11.3 (2023-12-29)
232

333
### Bug fixes

‎deps/acorn/acorn/README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ Options are provided by in a second argument, which should be an
5050
object containing any of these fields (only `ecmaVersion` is
5151
required):
5252

53-
- **ecmaVersion**: Indicates the ECMAScript version to parse. Must be
54-
either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10 (2019),
55-
11 (2020), 12 (2021), 13 (2022), 14 (2023), or `"latest"` (the
56-
latest the library supports). This influences support for strict
57-
mode, the set of reserved words, and support for new syntax
58-
features.
53+
- **ecmaVersion**: Indicates the ECMAScript version to parse. Can be a
54+
number, either in year (`2022`) or plain version number (`6`) form,
55+
or `"latest"` (the latest the library supports). This influences
56+
support for strict mode, the set of reserved words, and support for
57+
new syntax features.
5958

6059
**NOTE**: Only 'stage 4' (finalized) ECMAScript features are being
6160
implemented by Acorn. Other proposed new features must be

‎deps/acorn/acorn/dist/acorn.d.mts

+8-9
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ export type ModuleDeclaration =
562562
| ExportDefaultDeclaration
563563
| ExportAllDeclaration
564564

565-
export type AnyNode = Statement | Expression | Declaration | ModuleDeclaration | Literal | Program | SwitchCase | CatchClause | Property | Super | SpreadElement | TemplateElement | AssignmentProperty | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | MetaProperty | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier | AnonymousFunctionDeclaration | AnonymousClassDeclaration | PropertyDefinition | PrivateIdentifier | StaticBlock
565+
export type AnyNode = Statement | Expression | Declaration | ModuleDeclaration | Literal | Program | SwitchCase | CatchClause | Property | Super | SpreadElement | TemplateElement | AssignmentProperty | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | MetaProperty | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier | AnonymousFunctionDeclaration | AnonymousClassDeclaration | PropertyDefinition | PrivateIdentifier | StaticBlock | VariableDeclarator
566566

567567
export function parse(input: string, options: Options): Program
568568

@@ -573,16 +573,15 @@ export function tokenizer(input: string, options: Options): {
573573
[Symbol.iterator](): Iterator<Token>
574574
}
575575

576-
export type ecmaVersion = 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | "latest"
576+
export type ecmaVersion = 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025 | "latest"
577577

578578
export interface Options {
579579
/**
580-
* `ecmaVersion` indicates the ECMAScript version to parse. Must be
581-
* either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
582-
* (2019), 11 (2020), 12 (2021), 13 (2022), 14 (2023), or `"latest"`
583-
* (the latest version the library supports). This influences
584-
* support for strict mode, the set of reserved words, and support
585-
* for new syntax features.
580+
* `ecmaVersion` indicates the ECMAScript version to parse. Can be a
581+
* number, either in year (`2022`) or plain version number (`6`) form,
582+
* or `"latest"` (the latest the library supports). This influences
583+
* support for strict mode, the set of reserved words, and support for
584+
* new syntax features.
586585
*/
587586
ecmaVersion: ecmaVersion
588587

@@ -733,7 +732,7 @@ export class Parser {
733732
options: Options
734733
input: string
735734

736-
private constructor(options: Options, input: string, startPos?: number)
735+
protected constructor(options: Options, input: string, startPos?: number)
737736
parse(): Program
738737

739738
static parse(input: string, options: Options): Program

‎deps/acorn/acorn/dist/acorn.d.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ export type ModuleDeclaration =
562562
| ExportDefaultDeclaration
563563
| ExportAllDeclaration
564564

565-
export type AnyNode = Statement | Expression | Declaration | ModuleDeclaration | Literal | Program | SwitchCase | CatchClause | Property | Super | SpreadElement | TemplateElement | AssignmentProperty | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | MetaProperty | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier | AnonymousFunctionDeclaration | AnonymousClassDeclaration | PropertyDefinition | PrivateIdentifier | StaticBlock
565+
export type AnyNode = Statement | Expression | Declaration | ModuleDeclaration | Literal | Program | SwitchCase | CatchClause | Property | Super | SpreadElement | TemplateElement | AssignmentProperty | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | MetaProperty | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier | AnonymousFunctionDeclaration | AnonymousClassDeclaration | PropertyDefinition | PrivateIdentifier | StaticBlock | VariableDeclarator
566566

567567
export function parse(input: string, options: Options): Program
568568

@@ -573,16 +573,15 @@ export function tokenizer(input: string, options: Options): {
573573
[Symbol.iterator](): Iterator<Token>
574574
}
575575

576-
export type ecmaVersion = 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | "latest"
576+
export type ecmaVersion = 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025 | "latest"
577577

578578
export interface Options {
579579
/**
580-
* `ecmaVersion` indicates the ECMAScript version to parse. Must be
581-
* either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10
582-
* (2019), 11 (2020), 12 (2021), 13 (2022), 14 (2023), or `"latest"`
583-
* (the latest version the library supports). This influences
584-
* support for strict mode, the set of reserved words, and support
585-
* for new syntax features.
580+
* `ecmaVersion` indicates the ECMAScript version to parse. Can be a
581+
* number, either in year (`2022`) or plain version number (`6`) form,
582+
* or `"latest"` (the latest the library supports). This influences
583+
* support for strict mode, the set of reserved words, and support for
584+
* new syntax features.
586585
*/
587586
ecmaVersion: ecmaVersion
588587

@@ -733,7 +732,7 @@ export class Parser {
733732
options: Options
734733
input: string
735734

736-
private constructor(options: Options, input: string, startPos?: number)
735+
protected constructor(options: Options, input: string, startPos?: number)
737736
parse(): Program
738737

739738
static parse(input: string, options: Options): Program

‎deps/acorn/acorn/dist/acorn.js

+92-29
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@
667667

668668
// ## Parser utilities
669669

670-
var literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/;
670+
var literal = /^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;
671671
pp$9.strictDirective = function(start) {
672672
if (this.options.ecmaVersion < 5) { return false }
673673
for (;;) {
@@ -853,7 +853,7 @@
853853
// Statement) is allowed here. If context is not empty then only a Statement
854854
// is allowed. However, `let [` is an explicit negative lookahead for
855855
// ExpressionStatement, so special-case it first.
856-
if (nextCh === 91 || nextCh === 92) { return true } // '[', '/'
856+
if (nextCh === 91 || nextCh === 92) { return true } // '[', '\'
857857
if (context) { return false }
858858

859859
if (nextCh === 123 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true } // '{', astral
@@ -1046,13 +1046,19 @@
10461046
return this.parseFor(node, init$1)
10471047
}
10481048
var startsWithLet = this.isContextual("let"), isForOf = false;
1049+
var containsEsc = this.containsEsc;
10491050
var refDestructuringErrors = new DestructuringErrors;
1050-
var init = this.parseExpression(awaitAt > -1 ? "await" : true, refDestructuringErrors);
1051+
var initPos = this.start;
1052+
var init = awaitAt > -1
1053+
? this.parseExprSubscripts(refDestructuringErrors, "await")
1054+
: this.parseExpression(true, refDestructuringErrors);
10511055
if (this.type === types$1._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
1052-
if (this.options.ecmaVersion >= 9) {
1053-
if (this.type === types$1._in) {
1054-
if (awaitAt > -1) { this.unexpected(awaitAt); }
1055-
} else { node.await = awaitAt > -1; }
1056+
if (awaitAt > -1) { // implies `ecmaVersion >= 9` (see declaration of awaitAt)
1057+
if (this.type === types$1._in) { this.unexpected(awaitAt); }
1058+
node.await = true;
1059+
} else if (isForOf && this.options.ecmaVersion >= 8) {
1060+
if (init.start === initPos && !containsEsc && init.type === "Identifier" && init.name === "async") { this.unexpected(); }
1061+
else if (this.options.ecmaVersion >= 9) { node.await = false; }
10561062
}
10571063
if (startsWithLet && isForOf) { this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); }
10581064
this.toAssignable(init, false, refDestructuringErrors);
@@ -2665,8 +2671,7 @@
26652671
node.argument = this.parseMaybeUnary(null, true, update, forInit);
26662672
this.checkExpressionErrors(refDestructuringErrors, true);
26672673
if (update) { this.checkLValSimple(node.argument); }
2668-
else if (this.strict && node.operator === "delete" &&
2669-
node.argument.type === "Identifier")
2674+
else if (this.strict && node.operator === "delete" && isLocalVariableAccess(node.argument))
26702675
{ this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
26712676
else if (node.operator === "delete" && isPrivateFieldAccess(node.argument))
26722677
{ this.raiseRecoverable(node.start, "Private fields can not be deleted"); }
@@ -2701,10 +2706,18 @@
27012706
}
27022707
};
27032708

2709+
function isLocalVariableAccess(node) {
2710+
return (
2711+
node.type === "Identifier" ||
2712+
node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression)
2713+
)
2714+
}
2715+
27042716
function isPrivateFieldAccess(node) {
27052717
return (
27062718
node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" ||
2707-
node.type === "ChainExpression" && isPrivateFieldAccess(node.expression)
2719+
node.type === "ChainExpression" && isPrivateFieldAccess(node.expression) ||
2720+
node.type === "ParenthesizedExpression" && isPrivateFieldAccess(node.expression)
27082721
)
27092722
}
27102723

@@ -3131,7 +3144,7 @@
31313144
this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
31323145
}
31333146
elem.value = {
3134-
raw: this.value,
3147+
raw: this.value.replace(/\r\n?/g, "\n"),
31353148
cooked: null
31363149
};
31373150
} else {
@@ -3806,6 +3819,30 @@
38063819

38073820
var pp$1 = Parser.prototype;
38083821

3822+
// Track disjunction structure to determine whether a duplicate
3823+
// capture group name is allowed because it is in a separate branch.
3824+
var BranchID = function BranchID(parent, base) {
3825+
// Parent disjunction branch
3826+
this.parent = parent;
3827+
// Identifies this set of sibling branches
3828+
this.base = base || this;
3829+
};
3830+
3831+
BranchID.prototype.separatedFrom = function separatedFrom (alt) {
3832+
// A branch is separate from another branch if they or any of
3833+
// their parents are siblings in a given disjunction
3834+
for (var self = this; self; self = self.parent) {
3835+
for (var other = alt; other; other = other.parent) {
3836+
if (self.base === other.base && self !== other) { return true }
3837+
}
3838+
}
3839+
return false
3840+
};
3841+
3842+
BranchID.prototype.sibling = function sibling () {
3843+
return new BranchID(this.parent, this.base)
3844+
};
3845+
38093846
var RegExpValidationState = function RegExpValidationState(parser) {
38103847
this.parser = parser;
38113848
this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "") + (parser.options.ecmaVersion >= 13 ? "d" : "") + (parser.options.ecmaVersion >= 15 ? "v" : "");
@@ -3822,8 +3859,9 @@
38223859
this.lastAssertionIsQuantifiable = false;
38233860
this.numCapturingParens = 0;
38243861
this.maxBackReference = 0;
3825-
this.groupNames = [];
3862+
this.groupNames = Object.create(null);
38263863
this.backReferenceNames = [];
3864+
this.branchID = null;
38273865
};
38283866

38293867
RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
@@ -3955,6 +3993,11 @@
39553993
}
39563994
};
39573995

3996+
function hasProp(obj) {
3997+
for (var _ in obj) { return true }
3998+
return false
3999+
}
4000+
39584001
/**
39594002
* Validate the pattern part of a given RegExpLiteral.
39604003
*
@@ -3969,7 +4012,7 @@
39694012
// |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
39704013
// exception if _P_ did not conform to the grammar, if any elements of _P_
39714014
// were not matched by the parse, or if any Early Error conditions exist.
3972-
if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
4015+
if (!state.switchN && this.options.ecmaVersion >= 9 && hasProp(state.groupNames)) {
39734016
state.switchN = true;
39744017
this.regexp_pattern(state);
39754018
}
@@ -3983,8 +4026,9 @@
39834026
state.lastAssertionIsQuantifiable = false;
39844027
state.numCapturingParens = 0;
39854028
state.maxBackReference = 0;
3986-
state.groupNames.length = 0;
4029+
state.groupNames = Object.create(null);
39874030
state.backReferenceNames.length = 0;
4031+
state.branchID = null;
39884032

39894033
this.regexp_disjunction(state);
39904034

@@ -4003,18 +4047,22 @@
40034047
for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
40044048
var name = list[i];
40054049

4006-
if (state.groupNames.indexOf(name) === -1) {
4050+
if (!state.groupNames[name]) {
40074051
state.raise("Invalid named capture referenced");
40084052
}
40094053
}
40104054
};
40114055

40124056
// https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
40134057
pp$1.regexp_disjunction = function(state) {
4058+
var trackDisjunction = this.options.ecmaVersion >= 16;
4059+
if (trackDisjunction) { state.branchID = new BranchID(state.branchID, null); }
40144060
this.regexp_alternative(state);
40154061
while (state.eat(0x7C /* | */)) {
4062+
if (trackDisjunction) { state.branchID = state.branchID.sibling(); }
40164063
this.regexp_alternative(state);
40174064
}
4065+
if (trackDisjunction) { state.branchID = state.branchID.parent; }
40184066

40194067
// Make the same message as V8.
40204068
if (this.regexp_eatQuantifier(state, true)) {
@@ -4027,8 +4075,7 @@
40274075

40284076
// https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
40294077
pp$1.regexp_alternative = function(state) {
4030-
while (state.pos < state.source.length && this.regexp_eatTerm(state))
4031-
{ }
4078+
while (state.pos < state.source.length && this.regexp_eatTerm(state)) {}
40324079
};
40334080

40344081
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
@@ -4266,14 +4313,26 @@
42664313
// `?` GroupName
42674314
pp$1.regexp_groupSpecifier = function(state) {
42684315
if (state.eat(0x3F /* ? */)) {
4269-
if (this.regexp_eatGroupName(state)) {
4270-
if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
4316+
if (!this.regexp_eatGroupName(state)) { state.raise("Invalid group"); }
4317+
var trackDisjunction = this.options.ecmaVersion >= 16;
4318+
var known = state.groupNames[state.lastStringValue];
4319+
if (known) {
4320+
if (trackDisjunction) {
4321+
for (var i = 0, list = known; i < list.length; i += 1) {
4322+
var altID = list[i];
4323+
4324+
if (!altID.separatedFrom(state.branchID))
4325+
{ state.raise("Duplicate capture group name"); }
4326+
}
4327+
} else {
42714328
state.raise("Duplicate capture group name");
42724329
}
4273-
state.groupNames.push(state.lastStringValue);
4274-
return
42754330
}
4276-
state.raise("Invalid group");
4331+
if (trackDisjunction) {
4332+
(known || (state.groupNames[state.lastStringValue] = [])).push(state.branchID);
4333+
} else {
4334+
state.groupNames[state.lastStringValue] = true;
4335+
}
42774336
}
42784337
};
42794338

@@ -5778,15 +5837,18 @@
57785837
break
57795838

57805839
case "$":
5781-
if (this.input[this.pos + 1] !== "{") {
5782-
break
5783-
}
5784-
5785-
// falls through
5840+
if (this.input[this.pos + 1] !== "{") { break }
5841+
// fall through
57865842
case "`":
57875843
return this.finishToken(types$1.invalidTemplate, this.input.slice(this.start, this.pos))
57885844

5789-
// no default
5845+
case "\r":
5846+
if (this.input[this.pos + 1] === "\n") { ++this.pos; }
5847+
// fall through
5848+
case "\n": case "\u2028": case "\u2029":
5849+
++this.curLine;
5850+
this.lineStart = this.pos + 1;
5851+
break
57905852
}
57915853
}
57925854
this.raise(this.start, "Unterminated template");
@@ -5849,6 +5911,7 @@
58495911
if (isNewLine(ch)) {
58505912
// Unicode new line characters after \ get removed from output in both
58515913
// template literals and strings
5914+
if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
58525915
return ""
58535916
}
58545917
return String.fromCharCode(ch)
@@ -5927,7 +5990,7 @@
59275990
// [walk]: util/walk.js
59285991

59295992

5930-
var version = "8.11.3";
5993+
var version = "8.12.1";
59315994

59325995
Parser.acorn = {
59335996
Parser: Parser,

‎deps/acorn/acorn/dist/acorn.mjs

+92-29
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ var pp$9 = Parser.prototype;
661661

662662
// ## Parser utilities
663663

664-
var literal = /^(?:'((?:\\.|[^'\\])*?)'|"((?:\\.|[^"\\])*?)")/;
664+
var literal = /^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;
665665
pp$9.strictDirective = function(start) {
666666
if (this.options.ecmaVersion < 5) { return false }
667667
for (;;) {
@@ -847,7 +847,7 @@ pp$8.isLet = function(context) {
847847
// Statement) is allowed here. If context is not empty then only a Statement
848848
// is allowed. However, `let [` is an explicit negative lookahead for
849849
// ExpressionStatement, so special-case it first.
850-
if (nextCh === 91 || nextCh === 92) { return true } // '[', '/'
850+
if (nextCh === 91 || nextCh === 92) { return true } // '[', '\'
851851
if (context) { return false }
852852

853853
if (nextCh === 123 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true } // '{', astral
@@ -1040,13 +1040,19 @@ pp$8.parseForStatement = function(node) {
10401040
return this.parseFor(node, init$1)
10411041
}
10421042
var startsWithLet = this.isContextual("let"), isForOf = false;
1043+
var containsEsc = this.containsEsc;
10431044
var refDestructuringErrors = new DestructuringErrors;
1044-
var init = this.parseExpression(awaitAt > -1 ? "await" : true, refDestructuringErrors);
1045+
var initPos = this.start;
1046+
var init = awaitAt > -1
1047+
? this.parseExprSubscripts(refDestructuringErrors, "await")
1048+
: this.parseExpression(true, refDestructuringErrors);
10451049
if (this.type === types$1._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
1046-
if (this.options.ecmaVersion >= 9) {
1047-
if (this.type === types$1._in) {
1048-
if (awaitAt > -1) { this.unexpected(awaitAt); }
1049-
} else { node.await = awaitAt > -1; }
1050+
if (awaitAt > -1) { // implies `ecmaVersion >= 9` (see declaration of awaitAt)
1051+
if (this.type === types$1._in) { this.unexpected(awaitAt); }
1052+
node.await = true;
1053+
} else if (isForOf && this.options.ecmaVersion >= 8) {
1054+
if (init.start === initPos && !containsEsc && init.type === "Identifier" && init.name === "async") { this.unexpected(); }
1055+
else if (this.options.ecmaVersion >= 9) { node.await = false; }
10501056
}
10511057
if (startsWithLet && isForOf) { this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); }
10521058
this.toAssignable(init, false, refDestructuringErrors);
@@ -2659,8 +2665,7 @@ pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forIni
26592665
node.argument = this.parseMaybeUnary(null, true, update, forInit);
26602666
this.checkExpressionErrors(refDestructuringErrors, true);
26612667
if (update) { this.checkLValSimple(node.argument); }
2662-
else if (this.strict && node.operator === "delete" &&
2663-
node.argument.type === "Identifier")
2668+
else if (this.strict && node.operator === "delete" && isLocalVariableAccess(node.argument))
26642669
{ this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
26652670
else if (node.operator === "delete" && isPrivateFieldAccess(node.argument))
26662671
{ this.raiseRecoverable(node.start, "Private fields can not be deleted"); }
@@ -2695,10 +2700,18 @@ pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forIni
26952700
}
26962701
};
26972702

2703+
function isLocalVariableAccess(node) {
2704+
return (
2705+
node.type === "Identifier" ||
2706+
node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression)
2707+
)
2708+
}
2709+
26982710
function isPrivateFieldAccess(node) {
26992711
return (
27002712
node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" ||
2701-
node.type === "ChainExpression" && isPrivateFieldAccess(node.expression)
2713+
node.type === "ChainExpression" && isPrivateFieldAccess(node.expression) ||
2714+
node.type === "ParenthesizedExpression" && isPrivateFieldAccess(node.expression)
27022715
)
27032716
}
27042717

@@ -3125,7 +3138,7 @@ pp$5.parseTemplateElement = function(ref) {
31253138
this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
31263139
}
31273140
elem.value = {
3128-
raw: this.value,
3141+
raw: this.value.replace(/\r\n?/g, "\n"),
31293142
cooked: null
31303143
};
31313144
} else {
@@ -3800,6 +3813,30 @@ for (var i = 0, list = [9, 10, 11, 12, 13, 14]; i < list.length; i += 1) {
38003813

38013814
var pp$1 = Parser.prototype;
38023815

3816+
// Track disjunction structure to determine whether a duplicate
3817+
// capture group name is allowed because it is in a separate branch.
3818+
var BranchID = function BranchID(parent, base) {
3819+
// Parent disjunction branch
3820+
this.parent = parent;
3821+
// Identifies this set of sibling branches
3822+
this.base = base || this;
3823+
};
3824+
3825+
BranchID.prototype.separatedFrom = function separatedFrom (alt) {
3826+
// A branch is separate from another branch if they or any of
3827+
// their parents are siblings in a given disjunction
3828+
for (var self = this; self; self = self.parent) {
3829+
for (var other = alt; other; other = other.parent) {
3830+
if (self.base === other.base && self !== other) { return true }
3831+
}
3832+
}
3833+
return false
3834+
};
3835+
3836+
BranchID.prototype.sibling = function sibling () {
3837+
return new BranchID(this.parent, this.base)
3838+
};
3839+
38033840
var RegExpValidationState = function RegExpValidationState(parser) {
38043841
this.parser = parser;
38053842
this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "") + (parser.options.ecmaVersion >= 13 ? "d" : "") + (parser.options.ecmaVersion >= 15 ? "v" : "");
@@ -3816,8 +3853,9 @@ var RegExpValidationState = function RegExpValidationState(parser) {
38163853
this.lastAssertionIsQuantifiable = false;
38173854
this.numCapturingParens = 0;
38183855
this.maxBackReference = 0;
3819-
this.groupNames = [];
3856+
this.groupNames = Object.create(null);
38203857
this.backReferenceNames = [];
3858+
this.branchID = null;
38213859
};
38223860

38233861
RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
@@ -3949,6 +3987,11 @@ pp$1.validateRegExpFlags = function(state) {
39493987
}
39503988
};
39513989

3990+
function hasProp(obj) {
3991+
for (var _ in obj) { return true }
3992+
return false
3993+
}
3994+
39523995
/**
39533996
* Validate the pattern part of a given RegExpLiteral.
39543997
*
@@ -3963,7 +4006,7 @@ pp$1.validateRegExpPattern = function(state) {
39634006
// |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
39644007
// exception if _P_ did not conform to the grammar, if any elements of _P_
39654008
// were not matched by the parse, or if any Early Error conditions exist.
3966-
if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
4009+
if (!state.switchN && this.options.ecmaVersion >= 9 && hasProp(state.groupNames)) {
39674010
state.switchN = true;
39684011
this.regexp_pattern(state);
39694012
}
@@ -3977,8 +4020,9 @@ pp$1.regexp_pattern = function(state) {
39774020
state.lastAssertionIsQuantifiable = false;
39784021
state.numCapturingParens = 0;
39794022
state.maxBackReference = 0;
3980-
state.groupNames.length = 0;
4023+
state.groupNames = Object.create(null);
39814024
state.backReferenceNames.length = 0;
4025+
state.branchID = null;
39824026

39834027
this.regexp_disjunction(state);
39844028

@@ -3997,18 +4041,22 @@ pp$1.regexp_pattern = function(state) {
39974041
for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
39984042
var name = list[i];
39994043

4000-
if (state.groupNames.indexOf(name) === -1) {
4044+
if (!state.groupNames[name]) {
40014045
state.raise("Invalid named capture referenced");
40024046
}
40034047
}
40044048
};
40054049

40064050
// https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
40074051
pp$1.regexp_disjunction = function(state) {
4052+
var trackDisjunction = this.options.ecmaVersion >= 16;
4053+
if (trackDisjunction) { state.branchID = new BranchID(state.branchID, null); }
40084054
this.regexp_alternative(state);
40094055
while (state.eat(0x7C /* | */)) {
4056+
if (trackDisjunction) { state.branchID = state.branchID.sibling(); }
40104057
this.regexp_alternative(state);
40114058
}
4059+
if (trackDisjunction) { state.branchID = state.branchID.parent; }
40124060

40134061
// Make the same message as V8.
40144062
if (this.regexp_eatQuantifier(state, true)) {
@@ -4021,8 +4069,7 @@ pp$1.regexp_disjunction = function(state) {
40214069

40224070
// https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
40234071
pp$1.regexp_alternative = function(state) {
4024-
while (state.pos < state.source.length && this.regexp_eatTerm(state))
4025-
{ }
4072+
while (state.pos < state.source.length && this.regexp_eatTerm(state)) {}
40264073
};
40274074

40284075
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
@@ -4260,14 +4307,26 @@ pp$1.regexp_eatExtendedPatternCharacter = function(state) {
42604307
// `?` GroupName
42614308
pp$1.regexp_groupSpecifier = function(state) {
42624309
if (state.eat(0x3F /* ? */)) {
4263-
if (this.regexp_eatGroupName(state)) {
4264-
if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
4310+
if (!this.regexp_eatGroupName(state)) { state.raise("Invalid group"); }
4311+
var trackDisjunction = this.options.ecmaVersion >= 16;
4312+
var known = state.groupNames[state.lastStringValue];
4313+
if (known) {
4314+
if (trackDisjunction) {
4315+
for (var i = 0, list = known; i < list.length; i += 1) {
4316+
var altID = list[i];
4317+
4318+
if (!altID.separatedFrom(state.branchID))
4319+
{ state.raise("Duplicate capture group name"); }
4320+
}
4321+
} else {
42654322
state.raise("Duplicate capture group name");
42664323
}
4267-
state.groupNames.push(state.lastStringValue);
4268-
return
42694324
}
4270-
state.raise("Invalid group");
4325+
if (trackDisjunction) {
4326+
(known || (state.groupNames[state.lastStringValue] = [])).push(state.branchID);
4327+
} else {
4328+
state.groupNames[state.lastStringValue] = true;
4329+
}
42714330
}
42724331
};
42734332

@@ -5772,15 +5831,18 @@ pp.readInvalidTemplateToken = function() {
57725831
break
57735832

57745833
case "$":
5775-
if (this.input[this.pos + 1] !== "{") {
5776-
break
5777-
}
5778-
5779-
// falls through
5834+
if (this.input[this.pos + 1] !== "{") { break }
5835+
// fall through
57805836
case "`":
57815837
return this.finishToken(types$1.invalidTemplate, this.input.slice(this.start, this.pos))
57825838

5783-
// no default
5839+
case "\r":
5840+
if (this.input[this.pos + 1] === "\n") { ++this.pos; }
5841+
// fall through
5842+
case "\n": case "\u2028": case "\u2029":
5843+
++this.curLine;
5844+
this.lineStart = this.pos + 1;
5845+
break
57845846
}
57855847
}
57865848
this.raise(this.start, "Unterminated template");
@@ -5843,6 +5905,7 @@ pp.readEscapedChar = function(inTemplate) {
58435905
if (isNewLine(ch)) {
58445906
// Unicode new line characters after \ get removed from output in both
58455907
// template literals and strings
5908+
if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
58465909
return ""
58475910
}
58485911
return String.fromCharCode(ch)
@@ -5921,7 +5984,7 @@ pp.readWord = function() {
59215984
// [walk]: util/walk.js
59225985

59235986

5924-
var version = "8.11.3";
5987+
var version = "8.12.1";
59255988

59265989
Parser.acorn = {
59275990
Parser: Parser,

‎deps/acorn/acorn/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"./package.json": "./package.json"
1818
},
19-
"version": "8.11.3",
19+
"version": "8.12.1",
2020
"engines": {
2121
"node": ">=0.4.0"
2222
},
@@ -38,13 +38,13 @@
3838
],
3939
"repository": {
4040
"type": "git",
41-
"url": "https://github.com/acornjs/acorn.git"
41+
"url": "git+https://github.com/acornjs/acorn.git"
4242
},
4343
"license": "MIT",
4444
"scripts": {
4545
"prepare": "cd ..; npm run build:main"
4646
},
4747
"bin": {
48-
"acorn": "./bin/acorn"
48+
"acorn": "bin/acorn"
4949
}
5050
}

‎src/acorn_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Refer to tools/dep_updaters/update-acorn.sh
33
#ifndef SRC_ACORN_VERSION_H_
44
#define SRC_ACORN_VERSION_H_
5-
#define ACORN_VERSION "8.11.3"
5+
#define ACORN_VERSION "8.12.1"
66
#endif // SRC_ACORN_VERSION_H_

0 commit comments

Comments
 (0)
Please sign in to comment.