Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mert authored and mert committed Dec 10, 2024
1 parent 9099572 commit b76fdb4
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1816,23 +1816,24 @@ bool ShouldRetryAsESM(Realm* realm,
Utf8Value message_value(isolate, message);
auto message_view = message_value.ToStringView();

for (const auto& error_message : throws_only_in_cjs_error_messages) {
for (const auto& error_message : throws_only_in_cjs_error_messages) {
if (message_view.find(error_message) != std::string_view::npos &&
error_message.find("await is only valid in async functions and "
"the top level bodies of modules") != std::string_view::npos) {

const char* error_text =
"Top-level await is not supported in CommonJS modules. "
"To use top-level await, add \"type\": \"module\" to your package.json "
"or rename the file to use the .mjs extension. Alternatively, wrap "
"the await expression in an async function.";

isolate->ThrowException(v8::Exception::SyntaxError(
String::NewFromUtf8(isolate, error_text).ToLocalChecked()));

return true;
"the top level bodies of modules") !=
std::string_view::npos) {
const char* error_text =
"Top-level await is not supported in CommonJS modules. "
"To use top-level await, add \"type\": \"module\" to your "
"package.json "
"or rename the file to use the .mjs extension. Alternatively, wrap "
"the await expression in an async function.";

isolate->ThrowException(v8::Exception::SyntaxError(
String::NewFromUtf8(isolate, error_text).ToLocalChecked()));

return true;
}
}
}

// These indicates that the file contains syntaxes that are only valid in
// ESM. So it must be true.
Expand Down

0 comments on commit b76fdb4

Please sign in to comment.