mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 20:28:58 +00:00
refactor: clean up some usages of with_labels (#3854)
This commit is contained in:
parent
13754cbd3d
commit
d6437fec0b
3 changed files with 114 additions and 131 deletions
|
|
@ -16,12 +16,12 @@ pub fn overlong_source() -> OxcDiagnostic {
|
|||
|
||||
#[cold]
|
||||
pub fn flow(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Flow is not supported").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Flow is not supported").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn unexpected_token(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unexpected token").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Unexpected token").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
|
|
@ -32,64 +32,64 @@ pub fn expect_token(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
|
|||
|
||||
#[cold]
|
||||
pub fn invalid_escape_sequence(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Invalid escape sequence").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Invalid escape sequence").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn unicode_escape_sequence(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Invalid Unicode escape sequence").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Invalid Unicode escape sequence").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn invalid_character(x0: char, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Invalid Character `{x0}`")).with_labels([span1.into()])
|
||||
OxcDiagnostic::error(format!("Invalid Character `{x0}`")).with_label(span1)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn invalid_number_end(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Invalid characters after number").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Invalid characters after number").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn unterminated_multi_line_comment(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unterminated multiline comment").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Unterminated multiline comment").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn unterminated_string(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unterminated string").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Unterminated string").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn reg_exp_flag(x0: char, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Unexpected flag {x0} in regular expression literal"))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn reg_exp_flag_twice(x0: char, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Flag {x0} is mentioned twice in regular expression literal"))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn unexpected_end(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unexpected end of file").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Unexpected end of file").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn unterminated_reg_exp(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unterminated regular expression").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Unterminated regular expression").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn invalid_number(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Invalid Number {x0}")).with_labels([span1.into()])
|
||||
OxcDiagnostic::error(format!("Invalid Number {x0}")).with_label(span1)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn escaped_keyword(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Keywords cannot contain escape characters").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Keywords cannot contain escape characters").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
|
|
@ -98,42 +98,41 @@ pub fn auto_semicolon_insertion(span0: Span) -> OxcDiagnostic {
|
|||
"Expected a semicolon or an implicit semicolon after a statement, but found none",
|
||||
)
|
||||
.with_help("Try insert a semicolon here")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn lineterminator_before_arrow(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Line terminator not permitted before arrow").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Line terminator not permitted before arrow").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn invalid_destrucuring_declaration(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Missing initializer in destructuring declaration")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Missing initializer in destructuring declaration").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn missinginitializer_in_const(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Missing initializer in const declaration").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Missing initializer in const declaration").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn lexical_declaration_single_statement(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Lexical declaration cannot appear in a single-statement context")
|
||||
.with_help("Wrap this declaration in a block statement")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn async_function_declaration(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Async functions can only be declared at the top level or inside a block")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn generator_function_declaration(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Generators can only be declared at the top level or inside a block")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
|
|
@ -141,158 +140,151 @@ pub fn await_expression(span0: Span) -> OxcDiagnostic {
|
|||
OxcDiagnostic::error(
|
||||
"`await` is only allowed within async functions and at the top levels of modules",
|
||||
)
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn yield_expression(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A 'yield' expression is only allowed in a generator body.")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn class_declaration(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Invalid class declaration")
|
||||
.with_help("Classes can only be declared at top level or inside a block")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn binding_rest_element_last(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A rest element must be last in a destructuring pattern")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("A rest element must be last in a destructuring pattern").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn rest_parameter_last(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A rest parameter must be last in a parameter list")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("A rest parameter must be last in a parameter list").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn spread_last_element(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Spread must be last element").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Spread must be last element").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn binding_rest_element_trailing_comma(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unexpected trailing comma after rest element").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Unexpected trailing comma after rest element").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn invalid_binding_rest_element(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Invalid rest element")
|
||||
.with_help("Expected identifier in rest element")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn a_rest_parameter_cannot_be_optional(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A rest parameter cannot be optional").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("A rest parameter cannot be optional").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn invalid_assignment(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Cannot assign to this expression").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Cannot assign to this expression").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn new_optional_chain(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Optional chaining cannot appear in the callee of new expressions")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn for_loop_async_of(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("The left-hand side of a `for...of` statement may not be `async`")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn for_await(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("await can only be used in conjunction with `for...of` statements")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn new_dynamic_import(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Cannot use new with dynamic import").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Cannot use new with dynamic import").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn private_name_constructor(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Classes can't have an element named '#constructor'")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Classes can't have an element named '#constructor'").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn static_prototype(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Classes may not have a static property named prototype")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Classes may not have a static property named prototype").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn constructor_getter_setter(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Constructor can't have get/set modifier").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Constructor can't have get/set modifier").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn constructor_async(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Constructor can't be an async method").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Constructor can't be an async method").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn identifier_async(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Cannot use `{x0}` as an identifier in an async context"))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn identifier_generator(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Cannot use `{x0}` as an identifier in a generator context"))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn constructor_generator(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Constructor can't be a generator").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Constructor can't be a generator").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn field_constructor(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Classes can't have a field named 'constructor'")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Classes can't have a field named 'constructor'").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn export_lone_surrogate(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("An export name cannot include a unicode lone surrogate")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("An export name cannot include a unicode lone surrogate").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn export_named_string(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
|
||||
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()])
|
||||
.with_label(span2)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn export_reserved_word(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
|
||||
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()])
|
||||
.with_label(span2)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn template_literal(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Bad escape sequence in untagged template literal")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Bad escape sequence in untagged template literal").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn empty_parenthesized_expression(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Empty parenthesized expression").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Empty parenthesized expression").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
|
|
@ -306,74 +298,72 @@ pub fn illegal_newline(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
|
|||
#[cold]
|
||||
pub fn optional_chain_tagged_template(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Tagged template expressions are not permitted in an optional chain")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn ts_constructor_this_parameter(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("TS2681: A constructor cannot have a `this` parameter.")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("TS2681: A constructor cannot have a `this` parameter.").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn ts_arrow_function_this_parameter(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("TS2730: An arrow function cannot have a `this` parameter.")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn unexpected_super(span0: Span) -> OxcDiagnostic {
|
||||
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()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn expect_function_name(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Expected function name")
|
||||
.with_help("Function name is required in function declaration or named export")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn expect_catch_finally(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Missing catch or finally clause").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Missing catch or finally clause").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn a_set_accessor_cannot_have_a_return_type_annotation(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("TS1095: A 'set' accessor cannot have a return type annotation")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn return_statement_only_in_function_body(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("TS1108: A 'return' statement can only be used within a function body")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn jsx_expressions_may_not_use_the_comma_operator(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("TS18007: JSX expressions may not use the comma operator.")
|
||||
.with_help("Did you mean to write an array?")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn line_terminator_before_using_declaration(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Line terminator not permitted before using declaration.")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn await_in_using_declaration(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Await is not allowed in using declarations.").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Await is not allowed in using declarations.").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn invalid_identifier_in_using_declaration(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Using declarations may not have binding patterns.")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Using declarations may not have binding patterns.").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
|
|
@ -381,7 +371,7 @@ pub fn await_using_declaration_not_allowed_in_for_in_statement(span0: Span) -> O
|
|||
OxcDiagnostic::error(
|
||||
"The left-hand side of a for...in statement cannot be an await using declaration.",
|
||||
)
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
|
|
@ -389,18 +379,18 @@ pub fn using_declaration_not_allowed_in_for_in_statement(span0: Span) -> OxcDiag
|
|||
OxcDiagnostic::error(
|
||||
"The left-hand side of a for...in statement cannot be an using declaration.",
|
||||
)
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn using_declarations_must_be_initialized(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Using declarations must have an initializer.").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Using declarations must have an initializer.").with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
pub fn static_constructor(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("TS1089: `static` modifier cannot appear on a constructor declaration.")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ pub fn check_duplicate_class_elements(ctx: &SemanticBuilder<'_>) {
|
|||
}
|
||||
|
||||
fn undefined_export(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Export '{x0}' is not defined")).with_labels([span1.into()])
|
||||
OxcDiagnostic::error(format!("Export '{x0}' is not defined")).with_label(span1)
|
||||
}
|
||||
|
||||
fn duplicate_export(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
|
||||
|
|
@ -108,12 +108,11 @@ pub fn check_module_record(ctx: &SemanticBuilder<'_>) {
|
|||
}
|
||||
|
||||
fn class_static_block_await(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Cannot use await in class static initialization block")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Cannot use await in class static initialization block").with_label(span0)
|
||||
}
|
||||
|
||||
fn reserved_keyword(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("The keyword '{x0}' is reserved")).with_labels([span1.into()])
|
||||
OxcDiagnostic::error(format!("The keyword '{x0}' is reserved")).with_label(span1)
|
||||
}
|
||||
|
||||
pub const STRICT_MODE_NAMES: Set<&'static str> = phf_set! {
|
||||
|
|
@ -151,15 +150,14 @@ pub fn check_identifier<'a>(name: &str, span: Span, node: &AstNode<'a>, ctx: &Se
|
|||
}
|
||||
|
||||
fn unexpected_identifier_assign(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Cannot assign to '{x0}' in strict mode"))
|
||||
.with_labels([span1.into()])
|
||||
OxcDiagnostic::error(format!("Cannot assign to '{x0}' in strict mode")).with_label(span1)
|
||||
}
|
||||
|
||||
fn invalid_let_declaration(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!(
|
||||
"`let` cannot be declared as a variable name inside of a `{x0}` declaration"
|
||||
))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
pub fn check_binding_identifier<'a>(
|
||||
|
|
@ -191,7 +189,7 @@ pub fn check_binding_identifier<'a>(
|
|||
}
|
||||
|
||||
fn unexpected_arguments(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("'arguments' is not allowed in {x0}")).with_labels([span1.into()])
|
||||
OxcDiagnostic::error(format!("'arguments' is not allowed in {x0}")).with_label(span1)
|
||||
}
|
||||
|
||||
pub fn check_identifier_reference<'a>(
|
||||
|
|
@ -237,7 +235,7 @@ pub fn check_identifier_reference<'a>(
|
|||
|
||||
fn private_not_in_class(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Private identifier '#{x0}' is not allowed outside class bodies"))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
pub fn check_private_identifier_outside_class(
|
||||
|
|
@ -251,7 +249,7 @@ pub fn check_private_identifier_outside_class(
|
|||
|
||||
fn private_field_undeclared(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Private field '{x0}' must be declared in an enclosing class"))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
fn check_private_identifier(ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -273,13 +271,13 @@ fn check_private_identifier(ctx: &SemanticBuilder<'_>) {
|
|||
fn legacy_octal(span0: Span) -> OxcDiagnostic {
|
||||
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()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
fn leading_zero_decimal(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Decimals with leading zeros are not allowed in strict mode")
|
||||
.with_help("remove the leading zero")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_number_literal(lit: &NumericLiteral, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -312,7 +310,7 @@ pub fn check_number_literal(lit: &NumericLiteral, ctx: &SemanticBuilder<'_>) {
|
|||
fn non_octal_decimal_escape_sequence(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Invalid escape sequence")
|
||||
.with_help("\\8 and \\9 are not allowed in strict mode")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_string_literal(lit: &StringLiteral, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -349,7 +347,7 @@ fn illegal_use_strict(span0: Span) -> OxcDiagnostic {
|
|||
OxcDiagnostic::error(
|
||||
"Illegal 'use strict' directive in function with non-simple parameter list",
|
||||
)
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
// It is a Syntax Error if FunctionBodyContainsUseStrict of AsyncFunctionBody is true and IsSimpleParameterList of FormalParameters is false.
|
||||
|
|
@ -376,11 +374,11 @@ fn top_level(x0: &str, span1: Span) -> OxcDiagnostic {
|
|||
OxcDiagnostic::error(format!(
|
||||
"'{x0}' declaration can only be used at the top level of a module"
|
||||
))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
fn module_code(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("Cannot use {x0} outside a module")).with_labels([span1.into()])
|
||||
OxcDiagnostic::error(format!("Cannot use {x0} outside a module")).with_label(span1)
|
||||
}
|
||||
|
||||
pub fn check_module_declaration<'a>(
|
||||
|
|
@ -421,23 +419,21 @@ pub fn check_module_declaration<'a>(
|
|||
fn new_target(span0: Span) -> OxcDiagnostic {
|
||||
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()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
fn new_target_property(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("The only valid meta property for new is new.target")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("The only valid meta property for new is new.target").with_label(span0)
|
||||
}
|
||||
|
||||
fn import_meta(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unexpected import.meta expression")
|
||||
.with_help("import.meta is only allowed in module code")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
fn import_meta_property(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("The only valid meta property for import is import.meta")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("The only valid meta property for import is import.meta").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_meta_property<'a>(prop: &MetaProperty, node: &AstNode<'a>, ctx: &SemanticBuilder<'a>) {
|
||||
|
|
@ -481,13 +477,13 @@ fn function_declaration_strict(span0: Span) -> OxcDiagnostic {
|
|||
.with_help(
|
||||
"In strict mode code, functions can only be declared at top level or inside a block",
|
||||
)
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
fn function_declaration_non_strict(span0: Span) -> OxcDiagnostic {
|
||||
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()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_function_declaration<'a>(
|
||||
|
|
@ -509,7 +505,7 @@ fn reg_exp_flag_u_and_v(span0: Span) -> OxcDiagnostic {
|
|||
OxcDiagnostic::error(
|
||||
"The 'u' and 'v' regular expression flags cannot be enabled at the same time",
|
||||
)
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_regexp_literal(lit: &RegExpLiteral, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -520,7 +516,7 @@ pub fn check_regexp_literal(lit: &RegExpLiteral, ctx: &SemanticBuilder<'_>) {
|
|||
}
|
||||
|
||||
fn with_statement(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("'with' statements are not allowed").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("'with' statements are not allowed").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_with_statement(stmt: &WithStatement, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -543,11 +539,11 @@ pub fn check_switch_statement<'a>(stmt: &SwitchStatement<'a>, ctx: &SemanticBuil
|
|||
}
|
||||
|
||||
fn invalid_label_jump_target(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Jump target cannot cross function boundary.").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Jump target cannot cross function boundary.").with_label(span0)
|
||||
}
|
||||
|
||||
fn invalid_label_target(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Use of undefined label").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Use of undefined label").with_label(span0)
|
||||
}
|
||||
|
||||
fn invalid_label_non_iteration(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
|
||||
|
|
@ -583,7 +579,7 @@ fn check_label(label: &LabelIdentifier, ctx: &SemanticBuilder, is_continue: bool
|
|||
fn invalid_break(span0: Span) -> OxcDiagnostic {
|
||||
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()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_break_statement<'a>(
|
||||
|
|
@ -615,7 +611,7 @@ pub fn check_break_statement<'a>(
|
|||
fn invalid_continue(span0: Span) -> OxcDiagnostic {
|
||||
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()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_continue_statement<'a>(
|
||||
|
|
@ -657,12 +653,12 @@ fn multiple_declaration_in_for_loop_head(x0: &str, span1: Span) -> OxcDiagnostic
|
|||
OxcDiagnostic::error(format!(
|
||||
"Only a single declaration is allowed in a `for...{x0}` statement"
|
||||
))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
fn unexpected_initializer_in_for_loop_head(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error(format!("{x0} loop variable declaration may not have an initializer"))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
pub fn check_for_statement_left<'a>(
|
||||
|
|
@ -708,7 +704,7 @@ fn duplicate_constructor(span0: Span, span1: Span) -> OxcDiagnostic {
|
|||
}
|
||||
|
||||
fn require_class_name(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A class name is required.").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("A class name is required.").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_class(class: &Class, node: &AstNode<'_>, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -744,12 +740,11 @@ pub fn check_class(class: &Class, node: &AstNode<'_>, ctx: &SemanticBuilder<'_>)
|
|||
}
|
||||
|
||||
fn setter_with_parameters(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A 'set' accessor must have exactly one parameter.")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("A 'set' accessor must have exactly one parameter.").with_label(span0)
|
||||
}
|
||||
|
||||
fn setter_with_rest_parameter(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A 'set' accessor cannot have rest parameter.").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("A 'set' accessor cannot have rest parameter.").with_label(span0)
|
||||
}
|
||||
|
||||
fn check_setter(function: &Function<'_>, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -766,8 +761,7 @@ fn check_setter(function: &Function<'_>, ctx: &SemanticBuilder<'_>) {
|
|||
}
|
||||
|
||||
fn getter_parameters(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A 'get' accessor must not have any formal parameters.")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("A 'get' accessor must not have any formal parameters.").with_label(span0)
|
||||
}
|
||||
|
||||
fn check_getter(function: &Function<'_>, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -795,12 +789,12 @@ fn super_without_derived_class(span0: Span, span1: Span) -> OxcDiagnostic {
|
|||
|
||||
fn unexpected_super_call(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Super calls are not permitted outside constructors or in nested functions inside constructors.")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
fn unexpected_super_reference(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("'super' can only be referenced in members of derived classes or object literal expressions.")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_super<'a>(sup: &Super, node: &AstNode<'a>, ctx: &SemanticBuilder<'a>) {
|
||||
|
|
@ -891,7 +885,7 @@ pub fn check_super<'a>(sup: &Super, node: &AstNode<'a>, ctx: &SemanticBuilder<'a
|
|||
fn cover_initialized_name(span0: Span) -> OxcDiagnostic {
|
||||
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()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_object_property(prop: &ObjectProperty, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -911,7 +905,7 @@ pub fn check_object_property(prop: &ObjectProperty, ctx: &SemanticBuilder<'_>) {
|
|||
}
|
||||
|
||||
fn a_rest_parameter_cannot_have_an_initializer(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A rest parameter cannot have an initializer").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("A rest parameter cannot have an initializer").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_formal_parameters<'a>(
|
||||
|
|
@ -937,7 +931,7 @@ pub fn check_array_pattern(pattern: &ArrayPattern, ctx: &SemanticBuilder<'_>) {
|
|||
}
|
||||
|
||||
fn assignment_is_not_simple(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Invalid left-hand side in assignment").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Invalid left-hand side in assignment").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_assignment_expression(assign_expr: &AssignmentExpression, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -973,7 +967,7 @@ pub fn check_object_expression(obj_expr: &ObjectExpression, ctx: &SemanticBuilde
|
|||
fn unexpected_exponential(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unexpected exponentiation expression")
|
||||
.with_help(format!("Wrap {x0} expression in parentheses to enforce operator precedence"))
|
||||
.with_labels([span1.into()])
|
||||
.with_label(span1)
|
||||
}
|
||||
|
||||
pub fn check_binary_expression(binary_expr: &BinaryExpression, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -996,7 +990,7 @@ pub fn check_binary_expression(binary_expr: &BinaryExpression, ctx: &SemanticBui
|
|||
fn mixed_coalesce(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Logical expressions and coalesce expressions cannot be mixed")
|
||||
.with_help("Wrap either expression by parentheses")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_logical_expression(logical_expr: &LogicalExpression, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -1021,7 +1015,7 @@ pub fn check_logical_expression(logical_expr: &LogicalExpression, ctx: &Semantic
|
|||
}
|
||||
|
||||
fn super_private(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Private fields cannot be accessed on super").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Private fields cannot be accessed on super").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_member_expression(member_expr: &MemberExpression, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -1034,12 +1028,11 @@ pub fn check_member_expression(member_expr: &MemberExpression, ctx: &SemanticBui
|
|||
}
|
||||
|
||||
fn delete_of_unqualified(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Delete of an unqualified identifier in strict mode.")
|
||||
.with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Delete of an unqualified identifier in strict mode.").with_label(span0)
|
||||
}
|
||||
|
||||
fn delete_private_field(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Private fields can not be deleted").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Private fields can not be deleted").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_unary_expression<'a>(
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
|
|||
use crate::{builder::SemanticBuilder, diagnostics::redeclaration};
|
||||
|
||||
fn empty_type_parameter_list(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Type parameter list cannot be empty.").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Type parameter list cannot be empty.").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_ts_type_parameter_declaration(
|
||||
|
|
@ -21,7 +21,7 @@ pub fn check_ts_type_parameter_declaration(
|
|||
}
|
||||
|
||||
fn unexpected_optional(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unexpected `?` operator").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Unexpected `?` operator").with_label(span0)
|
||||
}
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
pub fn check_variable_declarator(decl: &VariableDeclarator, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -35,12 +35,12 @@ pub fn check_variable_declarator(decl: &VariableDeclarator, ctx: &SemanticBuilde
|
|||
|
||||
fn required_parameter_after_optional_parameter(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A required parameter cannot follow an optional parameter.")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
fn parameter_property_outside_constructor(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("A parameter property is only allowed in a constructor implementation.")
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_formal_parameters(params: &FormalParameters, ctx: &SemanticBuilder<'_>) {
|
||||
|
|
@ -80,7 +80,7 @@ fn unexpected_assignment(span0: Span) -> OxcDiagnostic {
|
|||
OxcDiagnostic::error(
|
||||
"The left-hand side of an assignment expression must be a variable or a property access.",
|
||||
)
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_simple_assignment_target<'a>(
|
||||
|
|
@ -100,7 +100,7 @@ pub fn check_simple_assignment_target<'a>(
|
|||
}
|
||||
|
||||
fn unexpected_type_annotation(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Unexpected type annotation").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Unexpected type annotation").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_array_pattern<'a>(pattern: &ArrayPattern<'a>, ctx: &SemanticBuilder<'a>) {
|
||||
|
|
@ -117,7 +117,7 @@ fn not_allowed_namespace_declaration(span0: Span) -> OxcDiagnostic {
|
|||
OxcDiagnostic::error(
|
||||
"A namespace declaration is only allowed at the top level of a namespace or module.",
|
||||
)
|
||||
.with_labels([span0.into()])
|
||||
.with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_ts_module_declaration<'a>(decl: &TSModuleDeclaration<'a>, ctx: &SemanticBuilder<'a>) {
|
||||
|
|
@ -140,7 +140,7 @@ pub fn check_ts_module_declaration<'a>(decl: &TSModuleDeclaration<'a>, ctx: &Sem
|
|||
}
|
||||
|
||||
fn enum_member_must_have_initializer(span0: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::error("Enum member must have initializer.").with_labels([span0.into()])
|
||||
OxcDiagnostic::error("Enum member must have initializer.").with_label(span0)
|
||||
}
|
||||
|
||||
pub fn check_ts_enum_declaration<'a>(decl: &TSEnumDeclaration<'a>, ctx: &SemanticBuilder<'a>) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue