-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: doc & validate source values for formats
PR-URL: #32202 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com>
- Loading branch information
1 parent
19d9e20
commit cd4985c
Showing
5 changed files
with
150 additions
and
13 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
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
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,50 @@ | ||
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/string-sources.mjs | ||
import { mustCall, mustNotCall } from '../common/index.mjs'; | ||
import assert from 'assert'; | ||
|
||
import('test:Array').then( | ||
mustNotCall('Should not accept Arrays'), | ||
mustCall((e) => { | ||
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE'); | ||
}) | ||
); | ||
import('test:ArrayBuffer').then( | ||
mustCall(), | ||
mustNotCall('Should accept ArrayBuffers'), | ||
); | ||
import('test:null').then( | ||
mustNotCall('Should not accept null'), | ||
mustCall((e) => { | ||
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE'); | ||
}) | ||
); | ||
import('test:Object').then( | ||
mustNotCall('Should not stringify or valueOf Objects'), | ||
mustCall((e) => { | ||
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE'); | ||
}) | ||
); | ||
import('test:SharedArrayBuffer').then( | ||
mustCall(), | ||
mustNotCall('Should accept SharedArrayBuffers'), | ||
); | ||
import('test:string').then( | ||
mustCall(), | ||
mustNotCall('Should accept strings'), | ||
); | ||
import('test:String').then( | ||
mustNotCall('Should not accept wrapper Strings'), | ||
mustCall((e) => { | ||
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE'); | ||
}) | ||
); | ||
import('test:Uint8Array').then( | ||
mustCall(), | ||
mustNotCall('Should accept Uint8Arrays'), | ||
); | ||
import('test:undefined').then( | ||
mustNotCall('Should not accept undefined'), | ||
mustCall((e) => { | ||
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE'); | ||
}) | ||
); |
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,30 @@ | ||
const SOURCES = { | ||
__proto__: null, | ||
'test:Array': ['1', '2'], // both `1,2` and `12` are valid ESM | ||
'test:ArrayBuffer': new ArrayBuffer(0), | ||
'test:null': null, | ||
'test:Object': {}, | ||
'test:SharedArrayBuffer': new SharedArrayBuffer(0), | ||
'test:string': '', | ||
'test:String': new String(''), | ||
'test:Uint8Array': new Uint8Array(0), | ||
'test:undefined': undefined, | ||
} | ||
export function resolve(specifier, context, defaultFn) { | ||
if (specifier.startsWith('test:')) { | ||
return { url: specifier }; | ||
} | ||
return defaultFn(specifier, context); | ||
} | ||
export function getFormat(href, context, defaultFn) { | ||
if (href.startsWith('test:')) { | ||
return { format: 'module' }; | ||
} | ||
return defaultFn(href, context); | ||
} | ||
export function getSource(href, context, defaultFn) { | ||
if (href.startsWith('test:')) { | ||
return { source: SOURCES[href] }; | ||
} | ||
return defaultFn(href, context); | ||
} |
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