Skip to content

Commit 25c79f3

Browse files
nicolo-ribaudomarco-ippolito
authored andcommitted
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. PR-URL: #52104 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
1 parent 4a6ca7a commit 25c79f3

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/node.cc

+3-6
Original file line numberDiff line numberDiff line change
@@ -800,19 +800,16 @@ static ExitCode ProcessGlobalArgsInternal(std::vector<std::string>* args,
800800
return ExitCode::kInvalidCommandLineArgument2;
801801
}
802802

803-
// TODO(aduh95): remove this when the harmony-import-assertions flag
804-
// is removed in V8.
805-
if (std::find(v8_args.begin(), v8_args.end(),
806-
"--no-harmony-import-assertions") == v8_args.end()) {
807-
v8_args.emplace_back("--harmony-import-assertions");
808-
}
809803
// TODO(aduh95): remove this when the harmony-import-attributes flag
810804
// is removed in V8.
811805
if (std::find(v8_args.begin(),
812806
v8_args.end(),
813807
"--no-harmony-import-attributes") == v8_args.end()) {
814808
v8_args.emplace_back("--harmony-import-attributes");
815809
}
810+
// TODO(nicolo-ribaudo): remove this once V8 doesn't enable it by default
811+
// anymore.
812+
v8_args.emplace_back("--no-harmony-import-assertions");
816813

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

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

+10
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

+10
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)