mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
Remove V8 flag for import assertions, enabling support for the syntax; require the import assertion syntax for imports of JSON. Support import assertions in user loaders. Use both resolved module URL and import assertion type as the key for caching modules. Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: https://github.com/nodejs/node/pull/40250 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
// Flags: --experimental-json-modules
|
|
import '../common/index.mjs';
|
|
import { rejects } from 'assert';
|
|
|
|
const jsModuleDataUrl = 'data:text/javascript,export{}';
|
|
const jsonModuleDataUrl = 'data:application/json,""';
|
|
|
|
await rejects(
|
|
// This rejects because of the unsupported MIME type, not because of the
|
|
// unsupported assertion.
|
|
import('data:text/css,', { assert: { type: 'css' } }),
|
|
{ code: 'ERR_INVALID_MODULE_SPECIFIER' }
|
|
);
|
|
|
|
await rejects(
|
|
import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}assert{type:"json"}`),
|
|
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
|
|
);
|
|
|
|
await rejects(
|
|
import(jsModuleDataUrl, { assert: { type: 'json' } }),
|
|
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
|
|
);
|
|
|
|
await rejects(
|
|
import(import.meta.url, { assert: { type: 'unsupported' } }),
|
|
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }
|
|
);
|
|
|
|
await rejects(
|
|
import(jsonModuleDataUrl),
|
|
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
|
|
);
|
|
|
|
await rejects(
|
|
import(jsonModuleDataUrl, { assert: {} }),
|
|
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
|
|
);
|
|
|
|
await rejects(
|
|
import(jsonModuleDataUrl, { assert: { foo: 'bar' } }),
|
|
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
|
|
);
|
|
|
|
await rejects(
|
|
import(jsonModuleDataUrl, { assert: { type: 'unsupported' }}),
|
|
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }
|
|
);
|