Repository navigation
Record the source location of import() calls - #1755
Merged
Merged
Conversation
The parser emitted OP_import with no OP_source_loc before it, so the pc of an import() call, and of an await directly after it, mapped to the last location recorded before the call. Save the position of the import keyword and emit it right before OP_import, as quickjs-ng#1473 did for the for-of iterator close. gen/test_fib.c is regenerated because examples/test_fib.js uses await import(). Fixes: quickjs-ng#1752 Co-Authored-By: Claude Opus 5.5 <[email protected]>
bnoordhuis
reviewed
Sep 25, 2026
bnoordhuis
left a comment
Contributor
There was a problem hiding this comment.
LGTM modulo a comment about a comment.
Comment on lines
+3
to
+10
| /* A stack frame in a function that calls import() must point at the | ||
| import() call, not at the start of the statement, an earlier call in the | ||
| same function or the function itself. import() can run user code | ||
| synchronously, such as a getter on the options object, which captures the | ||
| frame while import() executes. It can also reject without a stack, for | ||
| example on a bad options argument, and the TypeError then gets its stack | ||
| when the await rethrows it. */ | ||
|
|
Contributor
There was a problem hiding this comment.
Suggested change
| /* A stack frame in a function that calls import() must point at the | |
| import() call, not at the start of the statement, an earlier call in the | |
| same function or the function itself. import() can run user code | |
| synchronously, such as a getter on the options object, which captures the | |
| frame while import() executes. It can also reject without a stack, for | |
| example on a bad options argument, and the TypeError then gets its stack | |
| when the await rethrows it. */ |
Superfluous LLM comment, please remove.
Contributor
Author
There was a problem hiding this comment.
Thanks, removed, and shifted the expected line numbers to match.
The expected line numbers move up by eight to match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
bnoordhuis
approved these changes
Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The parser emitted OP_import with no OP_source_loc before it, so the pc of an import() call mapped to the last location recorded before it. The pc of an await directly after it mapped to the same place. That location could be the start of the statement, an earlier call, or the function itself.
Two kinds of errors showed it. The first is code that import() runs synchronously, such as the specifier's toString() or a getter on the options object. It captures the caller's frame at the import() call. The second is when import() rejects without running user code, for example because the options argument or its
withproperty is not an object, or an attribute value is not a string. That TypeError has no stack until the caller's await rethrows it.This change saves the position of the
importkeyword and emits it right before OP_import. It follows the same pattern as the for-of iterator close fix in #1473.import.metais not affected.examples/test_fib.js uses
await import(), somake codegennow adds a pc2line entry to gen/test_fib.c. The regenerated file is included so the codegen check stays clean.The new test, tests/test_dynamic_import_line_numbers.js, covers four cases:
await.Testing:
make testpasses with the change applied. Without the quickjs.c change the new test fails withgot |11,1|, expected |13,21|.Fixes: #1752