New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for Source Phase Imports #3980
base: main
Are you sure you want to change the base?
Conversation
ed0bf1c
to
7d7fb72
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add a test to verify that the import source
declaration syntax is supported:
// test.js
import source x from "x";
import "./ensure-linking-error_FIXTURE.js";
throws in the resolution
phase and not in the parse
phase (e.g. https://github.com/tc39/test262/blob/main/INTERPRETING.md#negative)
where that fixture file is https://github.com/tc39/test262/blob/main/test/language/module-code/import-attributes/ensure-linking-error_FIXTURE.js
--
We should also test that Source Text Module Records do not have a source representation:
assertRejects(import("./a-js-file_FIXTURE.js"), ReferenceError);
// negative:
// - phase: resolution
// - type: ReferenceError
import source s from "./a-js-file_FIXTURE.js";
...ns/dynamic-import/usage/nested-arrow-assignment-expression-import-source-returns-thenable.js
Outdated
Show resolved
Hide resolved
// This is still valid in script code, and should not be valid for module code | ||
// https://tc39.github.io/ecma262/#sec-scripts-static-semantics-lexicallydeclarednames | ||
var smoosh; function smoosh() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we need this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used to ensure that this file is been parsed as a script rather than a module. The file verifies that an import.source()
call can be used in script code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shuold be enough to not specify flags: [module]
and the test will be pared as a script (by defaults tests are run as both strict and non-strict scripts, and this can be changed by specifying the noStrict
/onlyStrict
/module
flags: https://github.com/tc39/test262/blob/main/INTERPRETING.md#flags).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is adapted from https://github.com/tc39/test262/blob/main/src/dynamic-import/script-code-valid.case. I believe the intention here is to disallow this file to be accidentally parsed as a module code and pass the test as a false positive.
cc @guybedford |
8b8f8ce
to
c97be5d
Compare
c97be5d
to
139d854
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciated for your patience with the review. Finally had a look through and it's seeming really thorough to me.
Perhaps we should move abstract-module-source
and its prototype tests to test/built-ins?
The invalid and valid tests could also include a test that import.source
cannot be assigned. See some of the import.meta tests for examples. We could also ensure import.source.x
, typeof import.source
etc remains invalid.
I would note that we are still aiming to specify import.source for ECMAScript SourceText module records, so that reducing the number of tests that would need to change / be removed when that happens would be useful. Rather than the suite of these failures in the catch tests I think just a few would suffice if they will be changed anyway.
Finally for the static import syntax tests, it might be beneficial to also include some of the valid cases of the source
and from
identifier names being imported for the source
import phase per the various discussions we had around these syntax cases.
info: | | ||
28.1.1.1 %AbstractModuleSource% ( ) | ||
|
||
The "length" property of this function is +0𝔽. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean 0
not 0F
in the comment?
Add tests for Source Phase Imports, ecma262 PR.