diff --git a/test/language/module-code/source-phase-import/import-source-binding-name-2.js b/test/language/module-code/source-phase-import/import-source-binding-name-2.js deleted file mode 100644 index 9bc061ba0b3..00000000000 --- a/test/language/module-code/source-phase-import/import-source-binding-name-2.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2024 Chengzhong Wu. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -description: > - ImportBinding in ImportDeclaration may be 'source' and 'from' -esid: sec-modules -info: | - ImportDeclaration: - import source ImportedBinding FromClause ; - -negative: - phase: resolution - type: SyntaxError -features: [source-phase-imports] -flags: [module] ----*/ - -$DONOTEVALUATE(); - -import "../resources/ensure-linking-error_FIXTURE.js"; - -import source source from ''; -import source from from ''; diff --git a/test/language/module-code/source-phase-import/import-source-binding-name-2_FIXTURE.js b/test/language/module-code/source-phase-import/import-source-binding-name-2_FIXTURE.js new file mode 100644 index 00000000000..306bf0a5cd7 --- /dev/null +++ b/test/language/module-code/source-phase-import/import-source-binding-name-2_FIXTURE.js @@ -0,0 +1,18 @@ +// Copyright (C) 2024 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// ImportBinding in ImportDeclaration may be 'source' and 'from' +// This test is verified with `import-source.js` in the same directory that +// this file does not raise SyntaxError. Note that a SyntaxError could also +// be raised when the imported module does not have a source phase +// representation (see sec-source-text-module-record-initialize-environment, 7.c.ii). +// +// esid: sec-modules +// info: | +// ImportDeclaration: +// import source ImportedBinding FromClause ; + +import "../resources/ensure-linking-error_FIXTURE.js"; + +import source source from ''; +import source from from ''; diff --git a/test/language/module-code/source-phase-import/import-source-binding-name.js b/test/language/module-code/source-phase-import/import-source-binding-name.js deleted file mode 100644 index e75446f3687..00000000000 --- a/test/language/module-code/source-phase-import/import-source-binding-name.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2024 Chengzhong Wu. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -description: > - ImportBinding in ImportDeclaration may be 'source' and 'from' -esid: sec-modules -info: | - ImportDeclaration: - import source ImportedBinding FromClause ; - -negative: - phase: resolution - type: SyntaxError -features: [source-phase-imports] -flags: [module] ----*/ - -$DONOTEVALUATE(); - -import "../resources/ensure-linking-error_FIXTURE.js"; - -import source from ''; -import from from ''; diff --git a/test/language/module-code/source-phase-import/import-source-binding-name_FIXTURE.js b/test/language/module-code/source-phase-import/import-source-binding-name_FIXTURE.js new file mode 100644 index 00000000000..ca1e7a51298 --- /dev/null +++ b/test/language/module-code/source-phase-import/import-source-binding-name_FIXTURE.js @@ -0,0 +1,18 @@ +// Copyright (C) 2024 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// ImportBinding in ImportDeclaration may be 'source' and 'from' +// This test is verified with `import-source.js` in the same directory that +// this file does not raise SyntaxError. Note that a SyntaxError could also +// be raised when the imported module does not have a source phase +// representation (see sec-source-text-module-record-initialize-environment, 7.c.ii). +// +// esid: sec-modules +// info: +// ImportDeclaration: +// import source ImportedBinding FromClause ; + +import "../resources/ensure-linking-error_FIXTURE.js"; + +import source from ''; +import from from ''; diff --git a/test/language/module-code/source-phase-import/import-source-newlines.js b/test/language/module-code/source-phase-import/import-source-newlines.js deleted file mode 100644 index a5aa505186f..00000000000 --- a/test/language/module-code/source-phase-import/import-source-newlines.js +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2024 Chengzhong Wu. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -description: > - import source in ImportDeclaration may include line terminators -esid: sec-modules -info: | - ImportDeclaration: - import source ImportedBinding FromClause ; - - This test uses all four LineFeed characters in order to completely verify the - grammar. - - 16.2.1.7.2 GetModuleSource ( ) - Source Text Module Record provides a GetModuleSource implementation that always returns an abrupt completion indicating that a source phase import is not available. -negative: - phase: resolution - type: SyntaxError -features: [source-phase-imports] -flags: [module] ----*/ - -$DONOTEVALUATE(); - -import "../resources/ensure-linking-error_FIXTURE.js"; - -import - -

source - -

y from ''; diff --git a/test/language/module-code/source-phase-import/import-source-newlines_FIXTURE.js b/test/language/module-code/source-phase-import/import-source-newlines_FIXTURE.js new file mode 100644 index 00000000000..3678d48fcff --- /dev/null +++ b/test/language/module-code/source-phase-import/import-source-newlines_FIXTURE.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// import source in ImportDeclaration may include line terminators +// This test is verified with `import-source.js` in the same directory that +// this file does not raise SyntaxError. Note that a SyntaxError could also +// be raised when the imported module does not have a source phase +// representation (see sec-source-text-module-record-initialize-environment, 7.c.ii). +// +// esid: sec-modules +// info: | +// ImportDeclaration: +// import source ImportedBinding FromClause ; +// +// This test uses all four LineFeed characters in order to completely verify the +// grammar. +// +// 16.2.1.7.2 GetModuleSource ( ) +// Source Text Module Record provides a GetModuleSource implementation that always returns an abrupt completion indicating that a source phase import is not available. + +import "../resources/ensure-linking-error_FIXTURE.js"; + +import + +

source + +

y from ''; diff --git a/test/language/module-code/source-phase-import/import-source.js b/test/language/module-code/source-phase-import/import-source.js new file mode 100644 index 00000000000..48fa601ba16 --- /dev/null +++ b/test/language/module-code/source-phase-import/import-source.js @@ -0,0 +1,33 @@ +// Copyright (C) 2025 Bloomberg LP. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Verify that ImportDeclaration can be correctly parsed. +esid: sec-modules +features: [source-phase-imports] +flags: [async] +includes: [asyncHelpers.js] +---*/ + +function assertImportSourceResolutionFailure(specifier) { + // Import the module and assert that the promise is rejected with a host + // defined error during the resolution phase. + // Note that this is not a `import.source`. + return import(specifier).then( + () => { + throw new Test262Error(`${specifier}: Promise should be rejected`); + }, + error => { + if (error instanceof SyntaxError) { + throw new Test262Error(`${specifier}: Promise should be rejected with a non-SyntaxError`); + } + } + ); +} + +asyncTest(async function () { + await assertImportSourceResolutionFailure('./import-source-binding-name_FIXTURE.js'); + await assertImportSourceResolutionFailure('./import-source-binding-name-2_FIXTURE.js'); + await assertImportSourceResolutionFailure('./import-source-newlines_FIXTURE.js'); +});