Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: treat non-strings as separate argument in console.assert() #49722

Merged
merged 6 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,12 @@

assert(expression, ...args) {
if (!expression) {
args[0] = `Assertion failed${args.length === 0 ? '' : `: ${args[0]}`}`;
// https://console.spec.whatwg.org/#assert step 4.2:
if (typeof args[0] === "string") {

Check failure on line 436 in lib/internal/console/constructor.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Strings must use singlequote
args[0] = `Assertion failed: ${args[0]}`

Check failure on line 437 in lib/internal/console/constructor.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
} else {
ArrayPrototypeUnshift(args, "Assertion failed")

Check failure on line 439 in lib/internal/console/constructor.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Strings must use singlequote

Check failure on line 439 in lib/internal/console/constructor.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// https://console.spec.whatwg.org/#assert step 4.2:
if (typeof args[0] === "string") {
args[0] = `Assertion failed: ${args[0]}`
} else {
ArrayPrototypeUnshift(args, "Assertion failed")
}
let baseMessage = 'Assertion failed';
if (args.length > 0) {
baseMessage += ':';
}
ArrayPrototypeUnshift(args, "Assertion failed");

That way it's always consistent and I would not add the documentation reference as it might change it's location without the comment being updated.

// The arguments will be formatted in warn() again
ReflectApply(this.warn, this, args);
}
Expand Down