Skip to content

Commit

Permalink
deps: update acorn to 8.12.1
Browse files Browse the repository at this point in the history
PR-URL: #53465
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
nodejs-github-bot authored and targos committed Aug 14, 2024
1 parent 6bcbfcd commit ef9a950
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 86 deletions.
30 changes: 30 additions & 0 deletions deps/acorn/acorn/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
## 8.12.1 (2024-07-03)

### Bug fixes

Fix a regression that caused Acorn to no longer run on Node versions <8.10.

## 8.12.0 (2024-06-14)

### New features

Support ES2025 duplicate capture group names in regular expressions.

### Bug fixes

Include `VariableDeclarator` in the `AnyNode` type so that walker objects can refer to it without getting a type error.

Properly raise a parse error for invalid `for`/`of` statements using `async` as binding name.

Properly recognize \"use strict\" when preceded by a string with an escaped newline.

Mark the `Parser` constructor as protected, not private, so plugins can extend it without type errors.

Fix a bug where some invalid `delete` expressions were let through when the operand was parenthesized and `preserveParens` was enabled.

Properly normalize line endings in raw strings of invalid template tokens.

Properly track line numbers for escaped newlines in strings.

Fix a bug that broke line number accounting after a template literal with invalid escape sequences.

## 8.11.3 (2023-12-29)

### Bug fixes
Expand Down
11 changes: 5 additions & 6 deletions deps/acorn/acorn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ Options are provided by in a second argument, which should be an
object containing any of these fields (only `ecmaVersion` is
required):

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

**NOTE**: Only 'stage 4' (finalized) ECMAScript features are being
implemented by Acorn. Other proposed new features must be
Expand Down
17 changes: 8 additions & 9 deletions deps/acorn/acorn/dist/acorn.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export type ModuleDeclaration =
| ExportDefaultDeclaration
| ExportAllDeclaration

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
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

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

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

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"
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"

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

Expand Down Expand Up @@ -733,7 +732,7 @@ export class Parser {
options: Options
input: string

private constructor(options: Options, input: string, startPos?: number)
protected constructor(options: Options, input: string, startPos?: number)
parse(): Program

static parse(input: string, options: Options): Program
Expand Down
17 changes: 8 additions & 9 deletions deps/acorn/acorn/dist/acorn.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export type ModuleDeclaration =
| ExportDefaultDeclaration
| ExportAllDeclaration

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
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

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

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

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"
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"

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

Expand Down Expand Up @@ -733,7 +732,7 @@ export class Parser {
options: Options
input: string

private constructor(options: Options, input: string, startPos?: number)
protected constructor(options: Options, input: string, startPos?: number)
parse(): Program

static parse(input: string, options: Options): Program
Expand Down
121 changes: 92 additions & 29 deletions deps/acorn/acorn/dist/acorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@

// ## Parser utilities

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

if (nextCh === 123 || nextCh > 0xd7ff && nextCh < 0xdc00) { return true } // '{', astral
Expand Down Expand Up @@ -1046,13 +1046,19 @@
return this.parseFor(node, init$1)
}
var startsWithLet = this.isContextual("let"), isForOf = false;
var containsEsc = this.containsEsc;
var refDestructuringErrors = new DestructuringErrors;
var init = this.parseExpression(awaitAt > -1 ? "await" : true, refDestructuringErrors);
var initPos = this.start;
var init = awaitAt > -1
? this.parseExprSubscripts(refDestructuringErrors, "await")
: this.parseExpression(true, refDestructuringErrors);
if (this.type === types$1._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
if (this.options.ecmaVersion >= 9) {
if (this.type === types$1._in) {
if (awaitAt > -1) { this.unexpected(awaitAt); }
} else { node.await = awaitAt > -1; }
if (awaitAt > -1) { // implies `ecmaVersion >= 9` (see declaration of awaitAt)
if (this.type === types$1._in) { this.unexpected(awaitAt); }
node.await = true;
} else if (isForOf && this.options.ecmaVersion >= 8) {
if (init.start === initPos && !containsEsc && init.type === "Identifier" && init.name === "async") { this.unexpected(); }
else if (this.options.ecmaVersion >= 9) { node.await = false; }
}
if (startsWithLet && isForOf) { this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); }
this.toAssignable(init, false, refDestructuringErrors);
Expand Down Expand Up @@ -2665,8 +2671,7 @@
node.argument = this.parseMaybeUnary(null, true, update, forInit);
this.checkExpressionErrors(refDestructuringErrors, true);
if (update) { this.checkLValSimple(node.argument); }
else if (this.strict && node.operator === "delete" &&
node.argument.type === "Identifier")
else if (this.strict && node.operator === "delete" && isLocalVariableAccess(node.argument))
{ this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
else if (node.operator === "delete" && isPrivateFieldAccess(node.argument))
{ this.raiseRecoverable(node.start, "Private fields can not be deleted"); }
Expand Down Expand Up @@ -2701,10 +2706,18 @@
}
};

function isLocalVariableAccess(node) {
return (
node.type === "Identifier" ||
node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression)
)
}

function isPrivateFieldAccess(node) {
return (
node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" ||
node.type === "ChainExpression" && isPrivateFieldAccess(node.expression)
node.type === "ChainExpression" && isPrivateFieldAccess(node.expression) ||
node.type === "ParenthesizedExpression" && isPrivateFieldAccess(node.expression)
)
}

Expand Down Expand Up @@ -3131,7 +3144,7 @@
this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
}
elem.value = {
raw: this.value,
raw: this.value.replace(/\r\n?/g, "\n"),
cooked: null
};
} else {
Expand Down Expand Up @@ -3806,6 +3819,30 @@

var pp$1 = Parser.prototype;

// Track disjunction structure to determine whether a duplicate
// capture group name is allowed because it is in a separate branch.
var BranchID = function BranchID(parent, base) {
// Parent disjunction branch
this.parent = parent;
// Identifies this set of sibling branches
this.base = base || this;
};

BranchID.prototype.separatedFrom = function separatedFrom (alt) {
// A branch is separate from another branch if they or any of
// their parents are siblings in a given disjunction
for (var self = this; self; self = self.parent) {
for (var other = alt; other; other = other.parent) {
if (self.base === other.base && self !== other) { return true }
}
}
return false
};

BranchID.prototype.sibling = function sibling () {
return new BranchID(this.parent, this.base)
};

var RegExpValidationState = function RegExpValidationState(parser) {
this.parser = parser;
this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "") + (parser.options.ecmaVersion >= 13 ? "d" : "") + (parser.options.ecmaVersion >= 15 ? "v" : "");
Expand All @@ -3822,8 +3859,9 @@
this.lastAssertionIsQuantifiable = false;
this.numCapturingParens = 0;
this.maxBackReference = 0;
this.groupNames = [];
this.groupNames = Object.create(null);
this.backReferenceNames = [];
this.branchID = null;
};

RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
Expand Down Expand Up @@ -3955,6 +3993,11 @@
}
};

function hasProp(obj) {
for (var _ in obj) { return true }
return false
}

/**
* Validate the pattern part of a given RegExpLiteral.
*
Expand All @@ -3969,7 +4012,7 @@
// |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
// exception if _P_ did not conform to the grammar, if any elements of _P_
// were not matched by the parse, or if any Early Error conditions exist.
if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
if (!state.switchN && this.options.ecmaVersion >= 9 && hasProp(state.groupNames)) {
state.switchN = true;
this.regexp_pattern(state);
}
Expand All @@ -3983,8 +4026,9 @@
state.lastAssertionIsQuantifiable = false;
state.numCapturingParens = 0;
state.maxBackReference = 0;
state.groupNames.length = 0;
state.groupNames = Object.create(null);
state.backReferenceNames.length = 0;
state.branchID = null;

this.regexp_disjunction(state);

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

if (state.groupNames.indexOf(name) === -1) {
if (!state.groupNames[name]) {
state.raise("Invalid named capture referenced");
}
}
};

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

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

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

// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
Expand Down Expand Up @@ -4266,14 +4313,26 @@
// `?` GroupName
pp$1.regexp_groupSpecifier = function(state) {
if (state.eat(0x3F /* ? */)) {
if (this.regexp_eatGroupName(state)) {
if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
if (!this.regexp_eatGroupName(state)) { state.raise("Invalid group"); }
var trackDisjunction = this.options.ecmaVersion >= 16;
var known = state.groupNames[state.lastStringValue];
if (known) {
if (trackDisjunction) {
for (var i = 0, list = known; i < list.length; i += 1) {
var altID = list[i];

if (!altID.separatedFrom(state.branchID))
{ state.raise("Duplicate capture group name"); }
}
} else {
state.raise("Duplicate capture group name");
}
state.groupNames.push(state.lastStringValue);
return
}
state.raise("Invalid group");
if (trackDisjunction) {
(known || (state.groupNames[state.lastStringValue] = [])).push(state.branchID);
} else {
state.groupNames[state.lastStringValue] = true;
}
}
};

Expand Down Expand Up @@ -5778,15 +5837,18 @@
break

case "$":
if (this.input[this.pos + 1] !== "{") {
break
}

// falls through
if (this.input[this.pos + 1] !== "{") { break }
// fall through
case "`":
return this.finishToken(types$1.invalidTemplate, this.input.slice(this.start, this.pos))

// no default
case "\r":
if (this.input[this.pos + 1] === "\n") { ++this.pos; }
// fall through
case "\n": case "\u2028": case "\u2029":
++this.curLine;
this.lineStart = this.pos + 1;
break
}
}
this.raise(this.start, "Unterminated template");
Expand Down Expand Up @@ -5849,6 +5911,7 @@
if (isNewLine(ch)) {
// Unicode new line characters after \ get removed from output in both
// template literals and strings
if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
return ""
}
return String.fromCharCode(ch)
Expand Down Expand Up @@ -5927,7 +5990,7 @@
// [walk]: util/walk.js


var version = "8.11.3";
var version = "8.12.1";

Parser.acorn = {
Parser: Parser,
Expand Down
Loading

0 comments on commit ef9a950

Please sign in to comment.