refactor(diagnostics): s/OxcDiagnostic::new/OxcDiagnostic::error

This commit is contained in:
Boshen 2024-05-12 01:08:54 +08:00
parent 09f34fc942
commit 312f74bb63
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
5 changed files with 127 additions and 127 deletions

View file

@ -91,7 +91,7 @@ impl Diagnostic for OxcDiagnostic {
impl OxcDiagnostic {
#[must_use]
pub fn new<T: Into<String>>(message: T) -> Self {
pub fn error<T: Into<String>>(message: T) -> Self {
Self {
inner: Box::new(OxcDiagnosticInner {
message: message.into(),

View file

@ -73,7 +73,7 @@ fn print_errors(source_text: &str, errors: Vec<OxcDiagnostic>) {
// · ─────────
// ╰────
fn no_debugger(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("`debugger` statement is not allowed").with_labels([span0.into()])
OxcDiagnostic::error("`debugger` statement is not allowed").with_labels([span0.into()])
}
// This prints:
@ -85,7 +85,7 @@ fn no_debugger(span0: Span) -> OxcDiagnostic {
// · ╰── Empty object binding pattern
// ╰────
fn no_empty_pattern(s0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new("empty destructuring pattern is not allowed").with_labels([
OxcDiagnostic::error("empty destructuring pattern is not allowed").with_labels([
LabeledSpan::new_with_span(Some(format!("Empty {s0} binding pattern")), span1),
])
}

View file

@ -3,7 +3,7 @@ use oxc_span::Span;
#[cold]
pub fn redeclaration(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Identifier `{x0}` has already been declared")).with_labels([
OxcDiagnostic::error(format!("Identifier `{x0}` has already been declared")).with_labels([
LabeledSpan::new_with_span(Some(format!("`{x0}` has already been declared here")), span1),
LabeledSpan::new_with_span(Some("It can not be redeclared here".to_string()), span2),
])
@ -11,90 +11,90 @@ pub fn redeclaration(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
#[cold]
pub fn overlong_source() -> OxcDiagnostic {
OxcDiagnostic::new("Source length exceeds 4 GiB limit")
OxcDiagnostic::error("Source length exceeds 4 GiB limit")
}
#[cold]
pub fn flow(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Flow is not supported").with_labels([span0.into()])
OxcDiagnostic::error("Flow is not supported").with_labels([span0.into()])
}
#[cold]
pub fn unexpected_token(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unexpected token").with_labels([span0.into()])
OxcDiagnostic::error("Unexpected token").with_labels([span0.into()])
}
#[cold]
pub fn expect_token(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Expected `{x0}` but found `{x1}`"))
OxcDiagnostic::error(format!("Expected `{x0}` but found `{x1}`"))
.with_labels([LabeledSpan::new_with_span(Some(format!("`{x0}` expected")), span2)])
}
#[cold]
pub fn invalid_escape_sequence(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid escape sequence").with_labels([span0.into()])
OxcDiagnostic::error("Invalid escape sequence").with_labels([span0.into()])
}
#[cold]
pub fn unicode_escape_sequence(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid Unicode escape sequence").with_labels([span0.into()])
OxcDiagnostic::error("Invalid Unicode escape sequence").with_labels([span0.into()])
}
#[cold]
pub fn invalid_character(x0: char, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Invalid Character `{x0}`")).with_labels([span1.into()])
OxcDiagnostic::error(format!("Invalid Character `{x0}`")).with_labels([span1.into()])
}
#[cold]
pub fn invalid_number_end(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid characters after number").with_labels([span0.into()])
OxcDiagnostic::error("Invalid characters after number").with_labels([span0.into()])
}
#[cold]
pub fn unterminated_multi_line_comment(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unterminated multiline comment").with_labels([span0.into()])
OxcDiagnostic::error("Unterminated multiline comment").with_labels([span0.into()])
}
#[cold]
pub fn unterminated_string(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unterminated string").with_labels([span0.into()])
OxcDiagnostic::error("Unterminated string").with_labels([span0.into()])
}
#[cold]
pub fn reg_exp_flag(x0: char, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Unexpected flag {x0} in regular expression literal"))
OxcDiagnostic::error(format!("Unexpected flag {x0} in regular expression literal"))
.with_labels([span1.into()])
}
#[cold]
pub fn reg_exp_flag_twice(x0: char, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Flag {x0} is mentioned twice in regular expression literal"))
OxcDiagnostic::error(format!("Flag {x0} is mentioned twice in regular expression literal"))
.with_labels([span1.into()])
}
#[cold]
pub fn unexpected_end(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unexpected end of file").with_labels([span0.into()])
OxcDiagnostic::error("Unexpected end of file").with_labels([span0.into()])
}
#[cold]
pub fn unterminated_reg_exp(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unterminated regular expression").with_labels([span0.into()])
OxcDiagnostic::error("Unterminated regular expression").with_labels([span0.into()])
}
#[cold]
pub fn invalid_number(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Invalid Number {x0}")).with_labels([span1.into()])
OxcDiagnostic::error(format!("Invalid Number {x0}")).with_labels([span1.into()])
}
#[cold]
pub fn escaped_keyword(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Keywords cannot contain escape characters").with_labels([span0.into()])
OxcDiagnostic::error("Keywords cannot contain escape characters").with_labels([span0.into()])
}
#[cold]
pub fn auto_semicolon_insertion(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new(
OxcDiagnostic::error(
"Expected a semicolon or an implicit semicolon after a statement, but found none",
)
.with_help("Try insert a semicolon here")
@ -103,42 +103,42 @@ pub fn auto_semicolon_insertion(span0: Span) -> OxcDiagnostic {
#[cold]
pub fn lineterminator_before_arrow(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Line terminator not permitted before arrow").with_labels([span0.into()])
OxcDiagnostic::error("Line terminator not permitted before arrow").with_labels([span0.into()])
}
#[cold]
pub fn invalid_destrucuring_declaration(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Missing initializer in destructuring declaration")
OxcDiagnostic::error("Missing initializer in destructuring declaration")
.with_labels([span0.into()])
}
#[cold]
pub fn missinginitializer_in_const(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Missing initializer in const declaration").with_labels([span0.into()])
OxcDiagnostic::error("Missing initializer in const declaration").with_labels([span0.into()])
}
#[cold]
pub fn lexical_declaration_single_statement(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Lexical declaration cannot appear in a single-statement context")
OxcDiagnostic::error("Lexical declaration cannot appear in a single-statement context")
.with_help("Wrap this declaration in a block statement")
.with_labels([span0.into()])
}
#[cold]
pub fn async_function_declaration(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Async functions can only be declared at the top level or inside a block")
OxcDiagnostic::error("Async functions can only be declared at the top level or inside a block")
.with_labels([span0.into()])
}
#[cold]
pub fn generator_function_declaration(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Generators can only be declared at the top level or inside a block")
OxcDiagnostic::error("Generators can only be declared at the top level or inside a block")
.with_labels([span0.into()])
}
#[cold]
pub fn await_expression(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new(
OxcDiagnostic::error(
"`await` is only allowed within async functions and at the top levels of modules",
)
.with_labels([span0.into()])
@ -146,157 +146,157 @@ pub fn await_expression(span0: Span) -> OxcDiagnostic {
#[cold]
pub fn yield_expression(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A 'yield' expression is only allowed in a generator body.")
OxcDiagnostic::error("A 'yield' expression is only allowed in a generator body.")
.with_labels([span0.into()])
}
#[cold]
pub fn class_declaration(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid class declaration")
OxcDiagnostic::error("Invalid class declaration")
.with_help("Classes can only be declared at top level or inside a block")
.with_labels([span0.into()])
}
#[cold]
pub fn binding_rest_element_last(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A rest element must be last in a destructuring pattern")
OxcDiagnostic::error("A rest element must be last in a destructuring pattern")
.with_labels([span0.into()])
}
#[cold]
pub fn rest_parameter_last(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A rest parameter must be last in a parameter list")
OxcDiagnostic::error("A rest parameter must be last in a parameter list")
.with_labels([span0.into()])
}
#[cold]
pub fn spread_last_element(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Spread must be last element").with_labels([span0.into()])
OxcDiagnostic::error("Spread must be last element").with_labels([span0.into()])
}
#[cold]
pub fn binding_rest_element_trailing_comma(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unexpected trailing comma after rest element").with_labels([span0.into()])
OxcDiagnostic::error("Unexpected trailing comma after rest element").with_labels([span0.into()])
}
#[cold]
pub fn invalid_binding_rest_element(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid rest element")
OxcDiagnostic::error("Invalid rest element")
.with_help("Expected identifier in rest element")
.with_labels([span0.into()])
}
#[cold]
pub fn a_rest_parameter_cannot_be_optional(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A rest parameter cannot be optional").with_labels([span0.into()])
OxcDiagnostic::error("A rest parameter cannot be optional").with_labels([span0.into()])
}
#[cold]
pub fn invalid_assignment(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Cannot assign to this expression").with_labels([span0.into()])
OxcDiagnostic::error("Cannot assign to this expression").with_labels([span0.into()])
}
#[cold]
pub fn new_optional_chain(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Optional chaining cannot appear in the callee of new expressions")
OxcDiagnostic::error("Optional chaining cannot appear in the callee of new expressions")
.with_labels([span0.into()])
}
#[cold]
pub fn for_loop_async_of(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("The left-hand side of a `for...of` statement may not be `async`")
OxcDiagnostic::error("The left-hand side of a `for...of` statement may not be `async`")
.with_labels([span0.into()])
}
#[cold]
pub fn for_await(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("await can only be used in conjunction with `for...of` statements")
OxcDiagnostic::error("await can only be used in conjunction with `for...of` statements")
.with_labels([span0.into()])
}
#[cold]
pub fn new_dynamic_import(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Cannot use new with dynamic import").with_labels([span0.into()])
OxcDiagnostic::error("Cannot use new with dynamic import").with_labels([span0.into()])
}
#[cold]
pub fn private_name_constructor(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Classes can't have an element named '#constructor'")
OxcDiagnostic::error("Classes can't have an element named '#constructor'")
.with_labels([span0.into()])
}
#[cold]
pub fn static_prototype(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Classes may not have a static property named prototype")
OxcDiagnostic::error("Classes may not have a static property named prototype")
.with_labels([span0.into()])
}
#[cold]
pub fn constructor_getter_setter(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Constructor can't have get/set modifier").with_labels([span0.into()])
OxcDiagnostic::error("Constructor can't have get/set modifier").with_labels([span0.into()])
}
#[cold]
pub fn constructor_async(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Constructor can't be an async method").with_labels([span0.into()])
OxcDiagnostic::error("Constructor can't be an async method").with_labels([span0.into()])
}
#[cold]
pub fn identifier_async(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Cannot use `{x0}` as an identifier in an async context"))
OxcDiagnostic::error(format!("Cannot use `{x0}` as an identifier in an async context"))
.with_labels([span1.into()])
}
#[cold]
pub fn identifier_generator(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Cannot use `{x0}` as an identifier in a generator context"))
OxcDiagnostic::error(format!("Cannot use `{x0}` as an identifier in a generator context"))
.with_labels([span1.into()])
}
#[cold]
pub fn constructor_generator(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Constructor can't be a generator").with_labels([span0.into()])
OxcDiagnostic::error("Constructor can't be a generator").with_labels([span0.into()])
}
#[cold]
pub fn field_constructor(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Classes can't have a field named 'constructor'").with_labels([span0.into()])
OxcDiagnostic::error("Classes can't have a field named 'constructor'").with_labels([span0.into()])
}
#[cold]
pub fn export_lone_surrogate(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("An export name cannot include a unicode lone surrogate")
OxcDiagnostic::error("An export name cannot include a unicode lone surrogate")
.with_labels([span0.into()])
}
#[cold]
pub fn export_named_string(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A string literal cannot be used as an exported binding without `from`")
OxcDiagnostic::error("A string literal cannot be used as an exported binding without `from`")
.with_help(format!("Did you mean `export {{ {x0} as {x1} }} from 'some-module'`?"))
.with_labels([span2.into()])
}
#[cold]
pub fn export_reserved_word(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A reserved word cannot be used as an exported binding without `from`")
OxcDiagnostic::error("A reserved word cannot be used as an exported binding without `from`")
.with_help(format!("Did you mean `export {{ {x0} as {x1} }} from 'some-module'`?"))
.with_labels([span2.into()])
}
#[cold]
pub fn template_literal(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Bad escape sequence in untagged template literal")
OxcDiagnostic::error("Bad escape sequence in untagged template literal")
.with_labels([span0.into()])
}
#[cold]
pub fn empty_parenthesized_expression(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Empty parenthesized expression").with_labels([span0.into()])
OxcDiagnostic::error("Empty parenthesized expression").with_labels([span0.into()])
}
#[cold]
pub fn illegal_newline(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Illegal newline after {x0}")).with_labels([
OxcDiagnostic::error(format!("Illegal newline after {x0}")).with_labels([
LabeledSpan::new_with_span(Some(format!("{x0} starts here")), span1),
LabeledSpan::new_with_span(Some("A newline is not expected here".to_string()), span2),
])
@ -304,80 +304,80 @@ pub fn illegal_newline(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
#[cold]
pub fn optional_chain_tagged_template(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Tagged template expressions are not permitted in an optional chain")
OxcDiagnostic::error("Tagged template expressions are not permitted in an optional chain")
.with_labels([span0.into()])
}
#[cold]
pub fn ts_constructor_this_parameter(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("TS2681: A constructor cannot have a `this` parameter.")
OxcDiagnostic::error("TS2681: A constructor cannot have a `this` parameter.")
.with_labels([span0.into()])
}
#[cold]
pub fn ts_arrow_function_this_parameter(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("TS2730: An arrow function cannot have a `this` parameter.")
OxcDiagnostic::error("TS2730: An arrow function cannot have a `this` parameter.")
.with_labels([span0.into()])
}
#[cold]
pub fn unexpected_super(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("'super' can only be used with function calls or in property accesses")
OxcDiagnostic::error("'super' can only be used with function calls or in property accesses")
.with_help("replace with `super()` or `super.prop` or `super[prop]`")
.with_labels([span0.into()])
}
#[cold]
pub fn expect_function_name(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Expected function name")
OxcDiagnostic::error("Expected function name")
.with_help("Function name is required in function declaration or named export")
.with_labels([span0.into()])
}
#[cold]
pub fn expect_catch_finally(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Missing catch or finally clause").with_labels([span0.into()])
OxcDiagnostic::error("Missing catch or finally clause").with_labels([span0.into()])
}
#[cold]
pub fn a_set_accessor_cannot_have_a_return_type_annotation(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("TS1095: A 'set' accessor cannot have a return type annotation")
OxcDiagnostic::error("TS1095: A 'set' accessor cannot have a return type annotation")
.with_labels([span0.into()])
}
#[cold]
pub fn return_statement_only_in_function_body(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("TS1108: A 'return' statement can only be used within a function body")
OxcDiagnostic::error("TS1108: A 'return' statement can only be used within a function body")
.with_labels([span0.into()])
}
#[cold]
pub fn jsx_expressions_may_not_use_the_comma_operator(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("TS18007: JSX expressions may not use the comma operator.")
OxcDiagnostic::error("TS18007: JSX expressions may not use the comma operator.")
.with_help("Did you mean to write an array?")
.with_labels([span0.into()])
}
#[cold]
pub fn line_terminator_before_using_declaration(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Line terminator not permitted before using declaration.")
OxcDiagnostic::error("Line terminator not permitted before using declaration.")
.with_labels([span0.into()])
}
#[cold]
pub fn await_in_using_declaration(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Await is not allowed in using declarations.").with_labels([span0.into()])
OxcDiagnostic::error("Await is not allowed in using declarations.").with_labels([span0.into()])
}
#[cold]
pub fn invalid_identifier_in_using_declaration(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Using declarations may not have binding patterns.")
OxcDiagnostic::error("Using declarations may not have binding patterns.")
.with_labels([span0.into()])
}
#[cold]
pub fn await_using_declaration_not_allowed_in_for_in_statement(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new(
OxcDiagnostic::error(
"The left-hand side of a for...in statement cannot be an await using declaration.",
)
.with_labels([span0.into()])
@ -385,22 +385,22 @@ pub fn await_using_declaration_not_allowed_in_for_in_statement(span0: Span) -> O
#[cold]
pub fn using_declaration_not_allowed_in_for_in_statement(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("The left-hand side of a for...in statement cannot be an using declaration.")
OxcDiagnostic::error("The left-hand side of a for...in statement cannot be an using declaration.")
.with_labels([span0.into()])
}
#[cold]
pub fn using_declarations_must_be_initialized(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Using declarations must have an initializer.").with_labels([span0.into()])
OxcDiagnostic::error("Using declarations must have an initializer.").with_labels([span0.into()])
}
#[cold]
pub fn static_constructor(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("TS1089: `static` modifier cannot appear on a constructor declaration.")
OxcDiagnostic::error("TS1089: `static` modifier cannot appear on a constructor declaration.")
.with_labels([span0.into()])
}
#[cold]
pub fn no_line_break_is_allowed_before_arrow(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("No line break is allowed before '=>'.").with_labels([span0.into()])
OxcDiagnostic::error("No line break is allowed before '=>'.").with_labels([span0.into()])
}

View file

@ -139,11 +139,11 @@ fn check_duplicate_class_elements(ctx: &SemanticBuilder<'_>) {
}
fn undefined_export(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Export '{x0}' is not defined")).with_labels([span1.into()])
OxcDiagnostic::error(format!("Export '{x0}' is not defined")).with_labels([span1.into()])
}
fn duplicate_export(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Duplicated export '{x0}'")).with_labels([
OxcDiagnostic::error(format!("Duplicated export '{x0}'")).with_labels([
LabeledSpan::new_with_span(Some("Export has already been declared here".into()), span1),
LabeledSpan::new_with_span(Some("It cannot be redeclared here".into()), span2),
])
@ -194,12 +194,12 @@ fn check_module_record(ctx: &SemanticBuilder<'_>) {
}
fn class_static_block_await(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Cannot use await in class static initialization block")
OxcDiagnostic::error("Cannot use await in class static initialization block")
.with_labels([span0.into()])
}
fn reserved_keyword(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("The keyword '{x0}' is reserved")).with_labels([span1.into()])
OxcDiagnostic::error(format!("The keyword '{x0}' is reserved")).with_labels([span1.into()])
}
pub const STRICT_MODE_NAMES: Set<&'static str> = phf_set! {
@ -237,12 +237,12 @@ fn check_identifier<'a>(name: &Atom, span: Span, node: &AstNode<'a>, ctx: &Seman
}
fn unexpected_identifier_assign(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Cannot assign to '{x0}' in strict mode"))
OxcDiagnostic::error(format!("Cannot assign to '{x0}' in strict mode"))
.with_labels([span1.into()])
}
fn invalid_let_declaration(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!(
OxcDiagnostic::error(format!(
"`let` cannot be declared as a variable name inside of a `{x0}` declaration"
))
.with_labels([span1.into()])
@ -277,7 +277,7 @@ fn check_binding_identifier<'a>(
}
fn unexpected_arguments(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("'arguments' is not allowed in {x0}")).with_labels([span1.into()])
OxcDiagnostic::error(format!("'arguments' is not allowed in {x0}")).with_labels([span1.into()])
}
fn check_identifier_reference<'a>(
@ -322,7 +322,7 @@ fn check_identifier_reference<'a>(
}
fn private_not_in_class(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Private identifier '#{x0}' is not allowed outside class bodies"))
OxcDiagnostic::error(format!("Private identifier '#{x0}' is not allowed outside class bodies"))
.with_labels([span1.into()])
}
@ -333,7 +333,7 @@ fn check_private_identifier_outside_class(ident: &PrivateIdentifier, ctx: &Seman
}
fn private_field_undeclared(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Private field '{x0}' must be declared in an enclosing class"))
OxcDiagnostic::error(format!("Private field '{x0}' must be declared in an enclosing class"))
.with_labels([span1.into()])
}
@ -354,13 +354,13 @@ fn check_private_identifier(ctx: &SemanticBuilder<'_>) {
}
fn legacy_octal(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("'0'-prefixed octal literals and octal escape sequences are deprecated")
OxcDiagnostic::error("'0'-prefixed octal literals and octal escape sequences are deprecated")
.with_help("for octal literals use the '0o' prefix instead")
.with_labels([span0.into()])
}
fn leading_zero_decimal(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Decimals with leading zeros are not allowed in strict mode")
OxcDiagnostic::error("Decimals with leading zeros are not allowed in strict mode")
.with_help("remove the leading zero")
.with_labels([span0.into()])
}
@ -393,7 +393,7 @@ fn check_number_literal(lit: &NumericLiteral, ctx: &SemanticBuilder<'_>) {
}
fn non_octal_decimal_escape_sequence(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid escape sequence")
OxcDiagnostic::error("Invalid escape sequence")
.with_help("\\8 and \\9 are not allowed in strict mode")
.with_labels([span0.into()])
}
@ -429,7 +429,7 @@ fn check_string_literal(lit: &StringLiteral, ctx: &SemanticBuilder<'_>) {
}
fn illegal_use_strict(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Illegal 'use strict' directive in function with non-simple parameter list")
OxcDiagnostic::error("Illegal 'use strict' directive in function with non-simple parameter list")
.with_labels([span0.into()])
}
@ -454,12 +454,12 @@ fn check_directive(directive: &Directive, ctx: &SemanticBuilder<'_>) {
}
fn top_level(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("'{x0}' declaration can only be used at the top level of a module"))
OxcDiagnostic::error(format!("'{x0}' declaration can only be used at the top level of a module"))
.with_labels([span1.into()])
}
fn module_code(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Cannot use {x0} outside a module")).with_labels([span1.into()])
OxcDiagnostic::error(format!("Cannot use {x0} outside a module")).with_labels([span1.into()])
}
fn check_module_declaration<'a>(
@ -498,24 +498,24 @@ fn check_module_declaration<'a>(
}
fn new_target(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unexpected new.target expression")
OxcDiagnostic::error("Unexpected new.target expression")
.with_help("new.target is only allowed in constructors and functions invoked using thew `new` operator")
.with_labels([span0.into()])
}
fn new_target_property(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("The only valid meta property for new is new.target")
OxcDiagnostic::error("The only valid meta property for new is new.target")
.with_labels([span0.into()])
}
fn import_meta(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unexpected import.meta expression")
OxcDiagnostic::error("Unexpected import.meta expression")
.with_help("import.meta is only allowed in module code")
.with_labels([span0.into()])
}
fn import_meta_property(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("The only valid meta property for import is import.meta")
OxcDiagnostic::error("The only valid meta property for import is import.meta")
.with_labels([span0.into()])
}
@ -556,7 +556,7 @@ fn check_meta_property<'a>(prop: &MetaProperty, node: &AstNode<'a>, ctx: &Semant
}
fn function_declaration_strict(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid function declaration")
OxcDiagnostic::error("Invalid function declaration")
.with_help(
"In strict mode code, functions can only be declared at top level or inside a block",
)
@ -564,7 +564,7 @@ fn function_declaration_strict(span0: Span) -> OxcDiagnostic {
}
fn function_declaration_non_strict(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid function declaration")
OxcDiagnostic::error("Invalid function declaration")
.with_help("In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement")
.with_labels([span0.into()])
}
@ -585,7 +585,7 @@ fn check_function_declaration<'a>(
}
fn reg_exp_flag_u_and_v(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new(
OxcDiagnostic::error(
"The 'u' and 'v' regular expression flags cannot be enabled at the same time",
)
.with_labels([span0.into()])
@ -599,7 +599,7 @@ fn check_regexp_literal(lit: &RegExpLiteral, ctx: &SemanticBuilder<'_>) {
}
fn with_statement(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("'with' statements are not allowed").with_labels([span0.into()])
OxcDiagnostic::error("'with' statements are not allowed").with_labels([span0.into()])
}
fn check_with_statement(stmt: &WithStatement, ctx: &SemanticBuilder<'_>) {
@ -622,15 +622,15 @@ fn check_switch_statement<'a>(stmt: &SwitchStatement<'a>, ctx: &SemanticBuilder<
}
fn invalid_label_jump_target(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Jump target cannot cross function boundary.").with_labels([span0.into()])
OxcDiagnostic::error("Jump target cannot cross function boundary.").with_labels([span0.into()])
}
fn invalid_label_target(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Use of undefined label").with_labels([span0.into()])
OxcDiagnostic::error("Use of undefined label").with_labels([span0.into()])
}
fn invalid_label_non_iteration(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("A `{x0}` statement can only jump to a label of an enclosing `for`, `while` or `do while` statement."))
OxcDiagnostic::error(format!("A `{x0}` statement can only jump to a label of an enclosing `for`, `while` or `do while` statement."))
.with_labels([LabeledSpan::new_with_span(Some("This is an non-iteration statement".into()), span1), LabeledSpan::new_with_span(Some("for this label".into()), span2)])
}
@ -660,7 +660,7 @@ fn check_label(label: &LabelIdentifier, ctx: &SemanticBuilder, is_continue: bool
}
fn invalid_break(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Illegal break statement")
OxcDiagnostic::error("Illegal break statement")
.with_help("A `break` statement can only be used within an enclosing iteration or switch statement.")
.with_labels([span0.into()])
}
@ -688,7 +688,7 @@ fn check_break_statement<'a>(stmt: &BreakStatement, node: &AstNode<'a>, ctx: &Se
}
fn invalid_continue(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Illegal continue statement: no surrounding iteration statement")
OxcDiagnostic::error("Illegal continue statement: no surrounding iteration statement")
.with_help("A `continue` statement can only be used within an enclosing `for`, `while` or `do while` ")
.with_labels([span0.into()])
}
@ -729,12 +729,12 @@ fn check_labeled_statement(ctx: &SemanticBuilder) {
}
fn multiple_declaration_in_for_loop_head(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("Only a single declaration is allowed in a `for...{x0}` statement"))
OxcDiagnostic::error(format!("Only a single declaration is allowed in a `for...{x0}` statement"))
.with_labels([span1.into()])
}
fn unexpected_initializer_in_for_loop_head(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("{x0} loop variable declaration may not have an initializer"))
OxcDiagnostic::error(format!("{x0} loop variable declaration may not have an initializer"))
.with_labels([span1.into()])
}
@ -771,7 +771,7 @@ fn check_for_statement_left<'a>(
}
fn duplicate_constructor(span0: Span, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Multiple constructor implementations are not allowed.").with_labels([
OxcDiagnostic::error("Multiple constructor implementations are not allowed.").with_labels([
LabeledSpan::new_with_span(
Some("constructor has already been declared here".into()),
span0,
@ -781,7 +781,7 @@ fn duplicate_constructor(span0: Span, span1: Span) -> OxcDiagnostic {
}
fn require_class_name(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A class name is required.").with_labels([span0.into()])
OxcDiagnostic::error("A class name is required.").with_labels([span0.into()])
}
fn check_class(class: &Class, node: &AstNode<'_>, ctx: &SemanticBuilder<'_>) {
@ -817,12 +817,12 @@ fn check_class(class: &Class, node: &AstNode<'_>, ctx: &SemanticBuilder<'_>) {
}
fn setter_with_parameters(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A 'set' accessor must have exactly one parameter.")
OxcDiagnostic::error("A 'set' accessor must have exactly one parameter.")
.with_labels([span0.into()])
}
fn setter_with_rest_parameter(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A 'set' accessor cannot have rest parameter.").with_labels([span0.into()])
OxcDiagnostic::error("A 'set' accessor cannot have rest parameter.").with_labels([span0.into()])
}
fn check_setter(function: &Function<'_>, ctx: &SemanticBuilder<'_>) {
@ -839,7 +839,7 @@ fn check_setter(function: &Function<'_>, ctx: &SemanticBuilder<'_>) {
}
fn getter_parameters(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A 'get' accessor must not have any formal parameters.")
OxcDiagnostic::error("A 'get' accessor must not have any formal parameters.")
.with_labels([span0.into()])
}
@ -858,7 +858,7 @@ fn check_method_definition(method: &MethodDefinition<'_>, ctx: &SemanticBuilder<
}
fn super_without_derived_class(span0: Span, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new("'super' can only be referenced in a derived class.")
OxcDiagnostic::error("'super' can only be referenced in a derived class.")
.with_help("either remove this super, or extend the class")
.with_labels([
span0.into(),
@ -867,12 +867,12 @@ fn super_without_derived_class(span0: Span, span1: Span) -> OxcDiagnostic {
}
fn unexpected_super_call(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Super calls are not permitted outside constructors or in nested functions inside constructors.")
OxcDiagnostic::error("Super calls are not permitted outside constructors or in nested functions inside constructors.")
.with_labels([span0.into()])
}
fn unexpected_super_reference(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("'super' can only be referenced in members of derived classes or object literal expressions.")
OxcDiagnostic::error("'super' can only be referenced in members of derived classes or object literal expressions.")
.with_labels([span0.into()])
}
@ -962,7 +962,7 @@ fn check_super<'a>(sup: &Super, node: &AstNode<'a>, ctx: &SemanticBuilder<'a>) {
}
fn cover_initialized_name(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid assignment in object literal")
OxcDiagnostic::error("Invalid assignment in object literal")
.with_help("Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.")
.with_labels([span0.into()])
}
@ -984,7 +984,7 @@ fn check_object_property(prop: &ObjectProperty, ctx: &SemanticBuilder<'_>) {
}
fn a_rest_parameter_cannot_have_an_initializer(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A rest parameter cannot have an initializer").with_labels([span0.into()])
OxcDiagnostic::error("A rest parameter cannot have an initializer").with_labels([span0.into()])
}
fn check_formal_parameters<'a>(
@ -1010,7 +1010,7 @@ fn check_array_pattern(pattern: &ArrayPattern, ctx: &SemanticBuilder<'_>) {
}
fn assignment_is_not_simple(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Invalid left-hand side in assignment").with_labels([span0.into()])
OxcDiagnostic::error("Invalid left-hand side in assignment").with_labels([span0.into()])
}
fn check_assignment_expression(assign_expr: &AssignmentExpression, ctx: &SemanticBuilder<'_>) {
@ -1044,7 +1044,7 @@ fn check_object_expression(obj_expr: &ObjectExpression, ctx: &SemanticBuilder<'_
}
fn unexpected_exponential(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unexpected exponentiation expression")
OxcDiagnostic::error("Unexpected exponentiation expression")
.with_help(format!("Wrap {x0} expression in parentheses to enforce operator precedence"))
.with_labels([span1.into()])
}
@ -1067,7 +1067,7 @@ fn check_binary_expression(binary_expr: &BinaryExpression, ctx: &SemanticBuilder
}
fn mixed_coalesce(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Logical expressions and coalesce expressions cannot be mixed")
OxcDiagnostic::error("Logical expressions and coalesce expressions cannot be mixed")
.with_help("Wrap either expression by parentheses")
.with_labels([span0.into()])
}
@ -1094,7 +1094,7 @@ fn check_logical_expression(logical_expr: &LogicalExpression, ctx: &SemanticBuil
}
fn super_private(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Private fields cannot be accessed on super").with_labels([span0.into()])
OxcDiagnostic::error("Private fields cannot be accessed on super").with_labels([span0.into()])
}
fn check_member_expression(member_expr: &MemberExpression, ctx: &SemanticBuilder<'_>) {
@ -1107,12 +1107,12 @@ fn check_member_expression(member_expr: &MemberExpression, ctx: &SemanticBuilder
}
fn delete_of_unqualified(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Delete of an unqualified identifier in strict mode.")
OxcDiagnostic::error("Delete of an unqualified identifier in strict mode.")
.with_labels([span0.into()])
}
fn delete_private_field(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Private fields can not be deleted").with_labels([span0.into()])
OxcDiagnostic::error("Private fields can not be deleted").with_labels([span0.into()])
}
fn check_unary_expression<'a>(
@ -1148,7 +1148,7 @@ fn is_in_formal_parameters<'a>(node: &AstNode<'a>, ctx: &SemanticBuilder<'a>) ->
}
fn await_or_yield_in_parameter(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::new(format!("{x0} expression not allowed in formal parameter")).with_labels([
OxcDiagnostic::error(format!("{x0} expression not allowed in formal parameter")).with_labels([
LabeledSpan::new_with_span(
Some(format!("{x0} expression not allowed in formal parameter")),
span1,

View file

@ -29,7 +29,7 @@ impl EarlyErrorTypeScript {
}
fn empty_type_parameter_list(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Type parameter list cannot be empty.").with_labels([span0.into()])
OxcDiagnostic::error("Type parameter list cannot be empty.").with_labels([span0.into()])
}
fn check_ts_type_parameter_declaration(
@ -42,7 +42,7 @@ fn check_ts_type_parameter_declaration(
}
fn unexpected_optional(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unexpected `?` operator").with_labels([span0.into()])
OxcDiagnostic::error("Unexpected `?` operator").with_labels([span0.into()])
}
#[allow(clippy::cast_possible_truncation)]
@ -56,12 +56,12 @@ fn check_variable_declarator(decl: &VariableDeclarator, ctx: &SemanticBuilder<'_
}
fn required_parameter_after_optional_parameter(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A required parameter cannot follow an optional parameter.")
OxcDiagnostic::error("A required parameter cannot follow an optional parameter.")
.with_labels([span0.into()])
}
fn parameter_property_outside_constructor(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("A parameter property is only allowed in a constructor implementation.")
OxcDiagnostic::error("A parameter property is only allowed in a constructor implementation.")
.with_labels([span0.into()])
}
@ -99,7 +99,7 @@ fn check_duplicate_bound_names<'a, T: BoundNames<'a>>(bound_names: &T, ctx: &Sem
}
fn unexpected_assignment(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new(
OxcDiagnostic::error(
"The left-hand side of an assignment expression must be a variable or a property access.",
)
.with_labels([span0.into()])
@ -122,7 +122,7 @@ fn check_simple_assignment_target<'a>(
}
fn unexpected_type_annotation(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Unexpected type annotation").with_labels([span0.into()])
OxcDiagnostic::error("Unexpected type annotation").with_labels([span0.into()])
}
fn check_array_pattern<'a>(pattern: &ArrayPattern<'a>, ctx: &SemanticBuilder<'a>) {
@ -136,7 +136,7 @@ fn check_array_pattern<'a>(pattern: &ArrayPattern<'a>, ctx: &SemanticBuilder<'a>
}
fn not_allowed_namespace_declaration(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new(
OxcDiagnostic::error(
"A namespace declaration is only allowed at the top level of a namespace or module.",
)
.with_labels([span0.into()])
@ -162,7 +162,7 @@ fn check_ts_module_declaration<'a>(decl: &TSModuleDeclaration<'a>, ctx: &Semanti
}
fn enum_member_must_have_initializer(span0: Span) -> OxcDiagnostic {
OxcDiagnostic::new("Enum member must have initializer.").with_labels([span0.into()])
OxcDiagnostic::error("Enum member must have initializer.").with_labels([span0.into()])
}
fn check_ts_enum_declaration(decl: &TSEnumDeclaration<'_>, ctx: &SemanticBuilder<'_>) {