Skip to content

Parse error in for statement when identifier of is divided #188

Description

@quiqueg

Similar to #173 and #177.

Steps to reproduce

  1. for statement which contains:
    • of as an identifier on the left side of a binary expression, whose operator is /

Minimal source code

for (i = of / 2;;) break
for (; of / 2;) break
for (;; of / 2) break

Also affects for..of and for..in statements

However, these are both pathological examples: while they are valid JavaScript, of / 2 would have to produce an iterable for these to execute without error.

for (i of of / 2) break
for (i in of / 2) break

Full repro

import { init, parse } from 'es-module-lexer';
(async () => {
  await init;
  parse('for (i = of / 2;;) {}');
})();
Error: Parse error @:1:22
    at parse (file:///app/node_modules/.pnpm/es-module-lexer@1.7.0/node_modules/es-module-lexer/dist/lexer.js:2:682)
    at file:///app/index.mjs:4:3 {
  idx: 21
}

Affected versions

Reproducible in versions 1.5.1 through 1.7.0.


Like #177, we unfortunately have this code in our minified Vite output and so our CI/CD broke. I somehow managed to find it in our 8MB minified JS file 🫠

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions