Remove source phase resolution time negative error types (#4194)

This commit is contained in:
Chengzhong Wu 2025-02-18 15:11:31 +00:00 committed by GitHub
parent 43c45f3b37
commit 74788df072
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 96 additions and 77 deletions

View File

@ -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 '<do not resolve>';
import source from from '<do not resolve>';

View File

@ -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 '<do not resolve>';
import source from from '<do not resolve>';

View File

@ -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 '<do not resolve>';
import from from '<do not resolve>';

View File

@ -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 '<do not resolve>';
import from from '<do not resolve>';

View File

@ -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 '<do not resolve>';

View File

@ -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 '<do not resolve>';

View File

@ -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');
});