Skip to content

fix: report n for no-substitution template dynamic imports#201

Merged
guybedford merged 2 commits into
guybedford:mainfrom
BridgeAR:BridgeAR/2026-06-16-dynamic-import-template
Jun 21, 2026
Merged

fix: report n for no-substitution template dynamic imports#201
guybedford merged 2 commits into
guybedford:mainfrom
BridgeAR:BridgeAR/2026-06-16-dynamic-import-template

Conversation

@BridgeAR

Copy link
Copy Markdown
Contributor

Summary

A dynamic import whose specifier is a no-substitution template literal
(import(`./x.js`)) returned n: undefined, while the quoted forms
returned the specifier. A template with no ${...} is a constant string, so it
now records a safe specifier the same as a quoted one; an interpolated template
has no constant value and still returns undefined. This surfaces with minified
Rolldown bundles, which rewrite dynamic-import specifiers to template literals.

src/lexer.c and the lexer.js fallback are updated together. readString
tolerates raw line breaks for a backtick quote, since template literals permit
them and string literals do not.

Drive-by

  • The lexer.js fallback recorded the specifier start before skipping leading
    whitespace/comments, so import(/* c */ "x") mis-decoded n; it now records
    the start after, matching the C lexer.

Test plan

  • chomp test (WASM + ASM): new Dynamic import …template specifier cases
    in test/_unit.cjs (quoted vs no-substitution vs interpolated, escapes,
    attributes, multi-line)

Fixes #198

A dynamic import whose specifier is a no-substitution template literal
(import(`./x.js`)) returned n: undefined, while the quoted forms returned the
specifier. A template with no ${...} is a constant string, so it now records a
safe specifier the same as a quoted one; an interpolated template has no
constant value and still returns undefined. This surfaces with minified
Rolldown bundles, which rewrite dynamic-import specifiers to template literals.

readString tolerates raw line breaks for a backtick quote, since template
literals permit them and string literals do not.

Drive-by fix:

* The JS fallback recorded the specifier start before skipping leading
  whitespace/comments, so import(/* c */ "x") mis-decoded n; it now records the
  start after, matching the C lexer.

Fixes guybedford#198
@BridgeAR BridgeAR marked this pull request as ready for review June 16, 2026 12:47
The asm.js wrapper decodes the dynamic-import specifier with its own
readString copy, which still rejected raw line breaks. A multi-line
no-substitution template threw a parse error on the asm.js build while
WASM and the JS fallback decoded it. Apply the same backtick exception.
@guybedford guybedford merged commit 0259739 into guybedford:main Jun 21, 2026
1 check passed
mergify Bot added a commit to ArcadeData/arcadedb that referenced this pull request Jul 5, 2026
…2.3.0 in /studio [skip ci]

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

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

> 2.2.0
> -----
>
> What's Changed
> --------------
>
> * build(deps-dev): update dev dependencies to latest by [`@​BridgeAR`](https://github.com/BridgeAR) in [guybedford/es-module-lexer#200](https://redirect.github.com/guybedford/es-module-lexer/pull/200)
> * fix: report n for no-substitution template dynamic imports by [`@​BridgeAR`](https://github.com/BridgeAR) in [guybedford/es-module-lexer#201](https://redirect.github.com/guybedford/es-module-lexer/pull/201)
> * Automatic asm.js dictionary extraction and clang toolchain update by [`@​guybedford`](https://github.com/guybedford) in [guybedford/es-module-lexer#203](https://redirect.github.com/guybedford/es-module-lexer/pull/203)
> * fix: don't treat a method named `import` with 2+ args as a dynamic import by [`@​soberm`](https://github.com/soberm) in [guybedford/es-module-lexer#207](https://redirect.github.com/guybedford/es-module-lexer/pull/207)
> * fix: detect every binding in export var/let/const declarations by [`@​BridgeAR`](https://github.com/BridgeAR) in [guybedford/es-module-lexer#199](https://redirect.github.com/guybedford/es-module-lexer/pull/199)
> * feat: expose export statement start position as ss by [`@​BridgeAR`](https://github.com/BridgeAR) in [guybedford/es-module-lexer#206](https://redirect.github.com/guybedford/es-module-lexer/pull/206)
>
> New Contributors
> ----------------
>
> * [`@​BridgeAR`](https://github.com/BridgeAR) made their first contribution in [guybedford/es-module-lexer#200](https://redirect.github.com/guybedford/es-module-lexer/pull/200)
> * [`@​soberm`](https://github.com/soberm) made their first contribution in [guybedford/es-module-lexer#207](https://redirect.github.com/guybedford/es-module-lexer/pull/207)
>
> **Full Changelog**: <guybedford/es-module-lexer@2.1.0...2.2.0>


Commits

* [`dbac1c3`](guybedford/es-module-lexer@dbac1c3) 2.3.0
* [`f3c972d`](guybedford/es-module-lexer@f3c972d) fix: allow wasm memory growth in the minimal build, document it in the readme...
* [`e9b611e`](guybedford/es-module-lexer@e9b611e) fix: allow wasm memory growth for sources over ~4MB ([#217](https://redirect.github.com/guybedford/es-module-lexer/issues/217))
* [`6c90425`](guybedford/es-module-lexer@6c90425) feat: add minimal build for es-module-shims (es-module-lexer/minimal) ([#211](https://redirect.github.com/guybedford/es-module-lexer/issues/211))
* [`70010fb`](guybedford/es-module-lexer@70010fb) docs: correct stale limitations and gzip size in README ([#212](https://redirect.github.com/guybedford/es-module-lexer/issues/212))
* [`1f19494`](guybedford/es-module-lexer@1f19494) 2.2.0
* [`d61e97a`](guybedford/es-module-lexer@d61e97a) feat: expose export statement start position as ss ([#206](https://redirect.github.com/guybedford/es-module-lexer/issues/206))
* [`064d0db`](guybedford/es-module-lexer@064d0db) fix: detect every binding in export var/let/const declarations ([#199](https://redirect.github.com/guybedford/es-module-lexer/issues/199))
* [`99b5226`](guybedford/es-module-lexer@99b5226) fix: don't treat a method named `import` with 2+ args as a dynamic import ([#207](https://redirect.github.com/guybedford/es-module-lexer/issues/207))
* [`fa1ade6`](guybedford/es-module-lexer@fa1ade6) build: update to upstream emsdk toolchain and derive asm.js dictionary from t...
* Additional commits viewable in [compare view](guybedford/es-module-lexer@2.1.0...2.3.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.1.0&new-version=2.3.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.

n is undefined for no-substitution template-literal dynamic imports

2 participants