Skip to content

fix: forward the sourcename through the pre-init parse path - #236

Merged
guybedford merged 1 commit into
guybedford:mainfrom
hdimer:fix-preinit-sourcename
Aug 17, 2026
Merged

guybedford merged 1 commit into
guybedford:mainfrom
hdimer:fix-preinit-sourcename

Conversation

@hdimer

@hdimer hdimer commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

When parse() is called before init resolves, it recurses as parse(source) and drops name, which then falls back to its '@' default. The README documents the second argument (parse(source, 'optional-sourcename')) and it documents calling parse before init ("either await init, or call parse asynchronously"), but the two don't compose:

parse('import{', 'my-file.js')
// after awaiting init:  Parse error my-file.js:1:11
// before awaiting init: Parse error @:1:11

So anyone lexing a batch of files on the async path gets every error labelled @.

The fix is to pass name through the recursion. Only the wasm builds have this branch — src/lexer.asm.js and the plain JS build parse synchronously from the first call.

The test goes in the Invalid syntax suite behind the WASM gate. It imports a second module instance via a query string, since the suite's own instance has already awaited init and can't reach the branch. Verified it fails with Parse error @:1:11 without the fix. test:wasm and test:minimal:wasm pass (150 each).

I left the as unknown as cast on that line alone deliberately — that's #155 and it needs a breaking type change, which didn't belong in the same diff.

Disclosure: I used an AI assistant while working on this. I reproduced the bug, reviewed the change, and ran the test suite myself.

`parse(source, name)` called before `init` resolves recursed as
`parse(source)`, so `name` fell back to its `'@'` default and a
caller-supplied sourcename was dropped from the parse error message.

Calling parse asynchronously is a documented path, and so is the second
argument, so the two are usable together but did not compose:

    parse('import{', 'my-file.js')   // awaited init:  Parse error my-file.js:1:11
                                     // pre-init:      Parse error @:1:11

Only the wasm builds have this branch. The test picks up a second,
uninitialized module instance so it can reach it from inside the suite,
which has already awaited init.
@hdimer
hdimer marked this pull request as ready for review August 16, 2026 03:52

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@guybedford
guybedford merged commit 08ee1be into guybedford:main Aug 17, 2026
1 check passed
mergify Bot added a commit to ArcadeData/arcadedb that referenced this pull request Aug 23, 2026
…2.3.2 in /studio [skip ci]

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

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

> 2.3.2
> -----
>
> What's Changed
> --------------
>
> * perf(lexer): skip identifier and number runs by [`@​BridgeAR`](https://github.com/BridgeAR) in [guybedford/es-module-lexer#227](https://redirect.github.com/guybedford/es-module-lexer/pull/227)
> * fix: annotate asm.js integer return type by [`@​Justineo`](https://github.com/Justineo) in [guybedford/es-module-lexer#230](https://redirect.github.com/guybedford/es-module-lexer/pull/230)
> * Add side effects to package.json by [`@​denisx`](https://github.com/denisx) in [guybedford/es-module-lexer#183](https://redirect.github.com/guybedford/es-module-lexer/pull/183)
> * fix: forward the sourcename through the pre-init parse path by [`@​hdimer`](https://github.com/hdimer) in [guybedford/es-module-lexer#236](https://redirect.github.com/guybedford/es-module-lexer/pull/236)
>
> New Contributors
> ----------------
>
> * [`@​Justineo`](https://github.com/Justineo) made their first contribution in [guybedford/es-module-lexer#230](https://redirect.github.com/guybedford/es-module-lexer/pull/230)
> * [`@​denisx`](https://github.com/denisx) made their first contribution in [guybedford/es-module-lexer#183](https://redirect.github.com/guybedford/es-module-lexer/pull/183)
> * [`@​hdimer`](https://github.com/hdimer) made their first contribution in [guybedford/es-module-lexer#236](https://redirect.github.com/guybedford/es-module-lexer/pull/236)
>
> **Full Changelog**: <guybedford/es-module-lexer@2.3.1...2.3.2>


Commits

* [`08ee1be`](guybedford/es-module-lexer@08ee1be) fix: forward the sourcename through the pre-init parse path ([#236](https://redirect.github.com/guybedford/es-module-lexer/issues/236))
* [`5a824a1`](guybedford/es-module-lexer@5a824a1) Update package.json ([#183](https://redirect.github.com/guybedford/es-module-lexer/issues/183))
* [`8274d03`](guybedford/es-module-lexer@8274d03) fix: annotate asm.js integer return type ([#230](https://redirect.github.com/guybedford/es-module-lexer/issues/230))
* [`2abc49e`](guybedford/es-module-lexer@2abc49e) perf(lexer): skip identifier and number runs ([#227](https://redirect.github.com/guybedford/es-module-lexer/issues/227))
* See full diff in [compare view](guybedford/es-module-lexer@2.3.1...2.3.2)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=es-module-lexer&package-manager=npm\_and\_yarn&previous-version=2.3.1&new-version=2.3.2)](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.

3 participants