Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

legendecas
Copy link
Member

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a 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";

Comment on lines +11 to +13
// 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() {}
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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).

Copy link
Member Author

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.

src/dynamic-import/import-source-script-code-valid.case Outdated Show resolved Hide resolved
test/language/module-code/abstract-module-source/length.js Outdated Show resolved Hide resolved
@nicolo-ribaudo
Copy link
Member

cc @guybedford

@legendecas legendecas force-pushed the module-source branch 2 times, most recently from 8b8f8ce to c97be5d Compare January 9, 2024 08:02
Copy link

@guybedford guybedford left a 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𝔽.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants