Skip to content

Commit 462d735

Browse files
esm: drop support for import assertions
This patch removes support for the `assert` keyword for import attributes. It was an old variant of the proposal that was only shipped in V8 and no other engine, and that has then been replaced by the `with` keyword. Chrome is planning to remove support for `assert` in version 126, which will be released in June. Node.js already supports the `with` keyword for import attributes, and this patch does not change that.
1 parent ba06c5c commit 462d735

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/node.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -796,19 +796,15 @@ static ExitCode ProcessGlobalArgsInternal(std::vector<std::string>* args,
796796
return ExitCode::kInvalidCommandLineArgument2;
797797
}
798798

799-
// TODO(aduh95): remove this when the harmony-import-assertions flag
800-
// is removed in V8.
801-
if (std::find(v8_args.begin(), v8_args.end(),
802-
"--no-harmony-import-assertions") == v8_args.end()) {
803-
v8_args.emplace_back("--harmony-import-assertions");
804-
}
805799
// TODO(aduh95): remove this when the harmony-import-attributes flag
806800
// is removed in V8.
807801
if (std::find(v8_args.begin(),
808802
v8_args.end(),
809803
"--no-harmony-import-attributes") == v8_args.end()) {
810804
v8_args.emplace_back("--harmony-import-attributes");
811805
}
806+
// TODO(nicolo-ribaudo): remove this once V8 doesn't enable it by default anymore.
807+
v8_args.emplace_back("--no-harmony-import-assertions");
812808

813809
auto env_opts = per_process::cli_options->per_isolate->per_env;
814810
if (std::find(v8_args.begin(), v8_args.end(),

test/es-module/test-esm-import-attributes-errors.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ async function test() {
5555
import(jsonModuleDataUrl, { with: { type: 'unsupported' } }),
5656
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
5757
);
58+
59+
await rejects(
60+
import(jsonModuleDataUrl, { assert: { type: 'json' } }),
61+
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
62+
);
63+
64+
await rejects(
65+
import(`data:text/javascript,import${JSON.stringify(jsonModuleDataUrl)}assert{type:"json"}`),
66+
SyntaxError
67+
);
5868
}
5969

6070
test().then(common.mustCall());

test/es-module/test-esm-import-attributes-errors.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ await rejects(
5050
import(jsonModuleDataUrl, { with: { type: 'unsupported' } }),
5151
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
5252
);
53+
54+
await rejects(
55+
import(jsonModuleDataUrl, { assert: { type: 'json' } }),
56+
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
57+
);
58+
59+
await rejects(
60+
import(`data:text/javascript,import${JSON.stringify(jsonModuleDataUrl)}assert{type:"json"}`),
61+
SyntaxError
62+
);

0 commit comments

Comments
 (0)