-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: check --experimental-require-module separately from detection
Previously we assumed if `--experimental-detect-module` is true, then `--experimental-require-module` is true, which isn't the case, as the two can be enabled/disabled separately. This patch fixes the checks so `--no-experimental-require-module` is still effective when `--experimental-detect-module` is enabled. Drive-by: make the assertion messages more informative and remove obsolete TODO about allowing TLA in entrypoints handled by require(esm). PR-URL: #55250 Backport-PR-URL: #55217 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Refs: #52697
- Loading branch information
1 parent
d8c34ce
commit fcdd616
Showing
3 changed files
with
34 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
19 changes: 19 additions & 0 deletions
19
test/es-module/test-disable-require-module-with-detection.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Flags: --no-experimental-require-module | ||
'use strict'; | ||
|
||
// Tests that --experimental-require-module is not implied by --experimental-detect-module | ||
// and is checked independently. | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
// Check that require() still throws SyntaxError for an ambiguous module that's detected to be ESM. | ||
// TODO(joyeecheung): now that --experimental-detect-module is unflagged, it makes more sense | ||
// to either throw ERR_REQUIRE_ESM for require() of detected ESM instead, or add a hint about the | ||
// use of require(esm) to the SyntaxError. | ||
|
||
assert.throws( | ||
() => require('../fixtures/es-modules/loose.js'), | ||
{ | ||
name: 'SyntaxError', | ||
message: /Unexpected token 'export'/ | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// This file can be run or imported only if `--experimental-default-type=module` is set. | ||
// This file can be run or imported only if `--experimental-default-type=module` is set | ||
// or `--experimental-detect-module` is not disabled. If it's loaded by | ||
// require(), then `--experimental-require-module` must not be disabled. | ||
export default 'module'; | ||
console.log('executed'); |