Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
nicolo-ribaudo committed Mar 16, 2024
commit 4c227bde6d3bac5fb9b52b58f00748a56d7f5c0b
9 changes: 3 additions & 6 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -796,19 +796,16 @@ static ExitCode ProcessGlobalArgsInternal(std::vector<std::string>* args,
return ExitCode::kInvalidCommandLineArgument2;
}

// TODO(aduh95): remove this when the harmony-import-assertions flag
// is removed in V8.
if (std::find(v8_args.begin(), v8_args.end(),
"--no-harmony-import-assertions") == v8_args.end()) {
v8_args.emplace_back("--harmony-import-assertions");
}
// TODO(aduh95): remove this when the harmony-import-attributes flag
// is removed in V8.
if (std::find(v8_args.begin(),
v8_args.end(),
"--no-harmony-import-attributes") == v8_args.end()) {
v8_args.emplace_back("--harmony-import-attributes");
}
// TODO(nicolo-ribaudo): remove this once V8 doesn't enable it by default
// anymore.
v8_args.emplace_back("--no-harmony-import-assertions");

auto env_opts = per_process::cli_options->per_isolate->per_env;
if (std::find(v8_args.begin(), v8_args.end(),
Expand Down
10 changes: 10 additions & 0 deletions test/es-module/test-esm-import-attributes-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ async function test() {
import(jsonModuleDataUrl, { with: { type: 'unsupported' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
);

await rejects(
import(jsonModuleDataUrl, { assert: { type: 'json' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
);

await rejects(
import(`data:text/javascript,import${JSON.stringify(jsonModuleDataUrl)}assert{type:"json"}`),
SyntaxError
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently throws "unexpected token 'assert" -- I submitted a patch to V8 to make the error explicitly recommend to use 'with' instead: https://chromium-review.googlesource.com/c/v8/v8/+/5376260

);
}

test().then(common.mustCall());
10 changes: 10 additions & 0 deletions test/es-module/test-esm-import-attributes-errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ await rejects(
import(jsonModuleDataUrl, { with: { type: 'unsupported' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
);

await rejects(
import(jsonModuleDataUrl, { assert: { type: 'json' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
);

await rejects(
import(`data:text/javascript,import${JSON.stringify(jsonModuleDataUrl)}assert{type:"json"}`),
SyntaxError
);