Skip to content

fix: handle new of conflict cases#195

Merged
guybedford merged 1 commit into
mainfrom
parse-case
Apr 25, 2026
Merged

fix: handle new of conflict cases#195
guybedford merged 1 commit into
mainfrom
parse-case

Conversation

@guybedford

@guybedford guybedford commented Dec 7, 2025

Copy link
Copy Markdown
Owner

Resolves #188of as an identifier on the LHS of / inside a for header was being mis-parsed as the for-of contextual keyword, causing the / to be treated as the start of a regex.

Approach

Inside for (...), of is the for-of contextual keyword only if it follows a binding. In valid JS a binding always ends with one of:

  • An identifier-tail char (alphanumeric, _, $)
  • ] (array destructuring)
  • } (object destructuring)
  • ) (parenthesized binding)

Anything else means of is just an identifier and the following / is division. New isForOfBinding helper scans backward through whitespace from the char before of and checks that terminator.

Cases now covered

C-style for, of as identifier (the / is division):

for (i = of / 2;;) break       // = before of
for (; of / 2;) break           // ; before of
for (;; of / 2) break           // ; before of
for (i + of / 2;;) break        // any binary operator
for (i, of / 2;;) break         // comma
for (i < of / 2;;) break
for (i | of / 2;;) break
for (i ? of / 2 : 0;;) break
for ((of) / 2;;) break          // parenthesized identifier

For-of with regex iterable (the /regex/ is still recognized as a regex):

for (i of /regex/) break
for (let x of /regex/) break
for ([a] of /regex/) break
for ({a} of /regex/) break
for ((x) of /regex/) break
for(let t of/[0-9]+/g.exec(e)){}     // existing test, no space before /
for ([x]of /regex/) break             // no space between ] and of
for (i  of /regex/) break             // multiple spaces
for (i\tof /regex/) break             // tab
for (i\nof /regex/) break             // newline

Disambiguate `of` as identifier vs for-of contextual keyword inside
`for (...)` by checking whether `of` actually follows a binding (the
only place the for-of keyword can appear). In valid JS a binding always
ends with an identifier-tail char, ']', '}', or ')' — anything else
means `of` is just an identifier and the following `/` is division,
not the start of a regex.

Adds isForOfBinding which scans backward through whitespace from the
char before `of` and checks that terminator. This is more robust than
the previous fixed-offset exclusion list (which only excluded ';' and
'=', missing '+', '-', '*', ',', '<', '|', '&', '?', etc.) and also
handles tab/newline whitespace and the no-space-before-of cases like
`for ([x]of /regex/)`.

Fixes #188.
@guybedford guybedford merged commit cc29c5b into main Apr 25, 2026
1 check passed
@guybedford guybedford deleted the parse-case branch April 25, 2026 21:23
mergify Bot added a commit to ArcadeData/arcadedb that referenced this pull request Apr 26, 2026
…2.1.0 in /studio [skip ci]

Bumps [es-module-lexer](https://github.com/guybedford/es-module-lexer) from 2.0.0 to 2.1.0.
Release notes

*Sourced from [es-module-lexer's releases](https://github.com/guybedford/es-module-lexer/releases).*

> 2.1.0
> -----
>
> What's Changed
> --------------
>
> * Always exclude dyn import attributes from specifier range by [`@​nicolo-ribaudo`](https://github.com/nicolo-ribaudo) in [guybedford/es-module-lexer#197](https://redirect.github.com/guybedford/es-module-lexer/pull/197)
> * fix: handle new of conflict cases by [`@​guybedford`](https://github.com/guybedford) in [guybedford/es-module-lexer#195](https://redirect.github.com/guybedford/es-module-lexer/pull/195)
>
> New Contributors
> ----------------
>
> * [`@​nicolo-ribaudo`](https://github.com/nicolo-ribaudo) made their first contribution in [guybedford/es-module-lexer#197](https://redirect.github.com/guybedford/es-module-lexer/pull/197)
>
> **Full Changelog**: <guybedford/es-module-lexer@2.0.0...2.1.0>


Commits

* [`5fb11e1`](guybedford/es-module-lexer@5fb11e1) 2.1.0
* [`cc29c5b`](guybedford/es-module-lexer@cc29c5b) fix: handle new of conflict cases ([#195](https://redirect.github.com/guybedford/es-module-lexer/issues/195))
* [`4a35138`](guybedford/es-module-lexer@4a35138) Always exclude dyn import attributes from specifier range ([#197](https://redirect.github.com/guybedford/es-module-lexer/issues/197))
* See full diff in [compare view](guybedford/es-module-lexer@2.0.0...2.1.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=es-module-lexer&package-manager=npm\_and\_yarn&previous-version=2.0.0&new-version=2.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
tae898 pushed a commit to humemai/arcadedb-embedded-python that referenced this pull request Jun 28, 2026
…2.1.0 in /studio [skip ci]

Bumps [es-module-lexer](https://github.com/guybedford/es-module-lexer) from 2.0.0 to 2.1.0.
Release notes

*Sourced from [es-module-lexer's releases](https://github.com/guybedford/es-module-lexer/releases).*

> 2.1.0
> -----
>
> What's Changed
> --------------
>
> * Always exclude dyn import attributes from specifier range by [`@​nicolo-ribaudo`](https://github.com/nicolo-ribaudo) in [guybedford/es-module-lexer#197](https://redirect.github.com/guybedford/es-module-lexer/pull/197)
> * fix: handle new of conflict cases by [`@​guybedford`](https://github.com/guybedford) in [guybedford/es-module-lexer#195](https://redirect.github.com/guybedford/es-module-lexer/pull/195)
>
> New Contributors
> ----------------
>
> * [`@​nicolo-ribaudo`](https://github.com/nicolo-ribaudo) made their first contribution in [guybedford/es-module-lexer#197](https://redirect.github.com/guybedford/es-module-lexer/pull/197)
>
> **Full Changelog**: <guybedford/es-module-lexer@2.0.0...2.1.0>


Commits

* [`5fb11e1`](guybedford/es-module-lexer@5fb11e1) 2.1.0
* [`cc29c5b`](guybedford/es-module-lexer@cc29c5b) fix: handle new of conflict cases ([ArcadeData#195](https://redirect.github.com/guybedford/es-module-lexer/issues/195))
* [`4a35138`](guybedford/es-module-lexer@4a35138) Always exclude dyn import attributes from specifier range ([ArcadeData#197](https://redirect.github.com/guybedford/es-module-lexer/issues/197))
* See full diff in [compare view](guybedford/es-module-lexer@2.0.0...2.1.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=es-module-lexer&package-manager=npm\_and\_yarn&previous-version=2.0.0&new-version=2.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse error in for statement when identifier of is divided

1 participant