Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 36 additions & 0 deletions crates/oxc_semantic/src/checker/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ pub fn check_duplicate_class_elements(ctx: &SemanticBuilder<'_>) {
});
}

#[cold]
fn class_static_block_await(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Cannot use await in class static initialization block").with_label(span)
}

#[cold]
fn reserved_keyword(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("The keyword '{x0}' is reserved")).with_label(span1)
}
Expand Down Expand Up @@ -144,10 +146,12 @@ fn is_current_node_ambient_binding(symbol_id: Option<SymbolId>, ctx: &SemanticBu
}
}

#[cold]
fn unexpected_identifier_assign(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("Cannot assign to '{x0}' in strict mode")).with_label(span1)
}

#[cold]
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"
Expand Down Expand Up @@ -225,6 +229,7 @@ pub fn check_binding_identifier(ident: &BindingIdentifier, ctx: &SemanticBuilder
}
}

#[cold]
fn unexpected_arguments(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("'arguments' is not allowed in {x0}"))
.with_label(span1)
Expand Down Expand Up @@ -292,6 +297,7 @@ pub fn check_identifier_reference(ident: &IdentifierReference, ctx: &SemanticBui
}
}

#[cold]
fn private_not_in_class(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("Private identifier '#{x0}' is not allowed outside class bodies"))
.with_label(span1)
Expand All @@ -306,6 +312,7 @@ pub fn check_private_identifier_outside_class(
}
}

#[cold]
fn private_field_undeclared(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("Private field '{x0}' must be declared in an enclosing class"))
.with_label(span1)
Expand All @@ -323,12 +330,14 @@ fn check_private_identifier(ctx: &SemanticBuilder<'_>) {
}
}

#[cold]
fn legacy_octal(span: 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_label(span)
}

#[cold]
fn leading_zero_decimal(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Decimals with leading zeros are not allowed in strict mode")
.with_help("remove the leading zero")
Expand Down Expand Up @@ -364,6 +373,7 @@ pub fn check_number_literal(lit: &NumericLiteral, ctx: &SemanticBuilder<'_>) {
}
}

#[cold]
fn non_octal_decimal_escape_sequence(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Invalid escape sequence")
.with_help("\\8 and \\9 are not allowed in strict mode")
Expand Down Expand Up @@ -400,6 +410,7 @@ pub fn check_string_literal(lit: &StringLiteral, ctx: &SemanticBuilder<'_>) {
}
}

#[cold]
fn illegal_use_strict(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error(
"Illegal 'use strict' directive in function with non-simple parameter list",
Expand Down Expand Up @@ -430,13 +441,15 @@ pub fn check_directive(directive: &Directive, ctx: &SemanticBuilder<'_>) {
}
}

#[cold]
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_label(span1)
}

#[cold]
fn module_code(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("Cannot use {x0} outside a module")).with_label(span1)
}
Expand Down Expand Up @@ -476,12 +489,14 @@ pub fn check_module_declaration(decl: &ModuleDeclarationKind, ctx: &SemanticBuil
}
}

#[cold]
fn new_target(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Unexpected new.target expression")
.with_help("new.target is only allowed in constructors and functions invoked using the `new` operator")
.with_label(span)
}

#[cold]
fn import_meta(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Unexpected import.meta expression")
.with_help("import.meta is only allowed in module code")
Expand Down Expand Up @@ -518,6 +533,7 @@ pub fn check_meta_property(prop: &MetaProperty, ctx: &SemanticBuilder<'_>) {
}
}

#[cold]
fn function_declaration_strict(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Invalid function declaration")
.with_help(
Expand All @@ -526,6 +542,7 @@ fn function_declaration_strict(span: Span) -> OxcDiagnostic {
.with_label(span)
}

#[cold]
fn function_declaration_non_strict(span: 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")
Expand Down Expand Up @@ -684,6 +701,7 @@ pub fn check_class_redeclaration(class: &Class, ctx: &SemanticBuilder<'_>) {
}
}

#[cold]
fn with_statement(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("'with' statements are not allowed").with_label(span)
}
Expand All @@ -707,14 +725,17 @@ pub fn check_switch_statement<'a>(stmt: &SwitchStatement<'a>, ctx: &SemanticBuil
}
}

#[cold]
fn invalid_label_jump_target(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Jump target cannot cross function boundary.").with_label(span)
}

#[cold]
fn invalid_label_target(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Use of undefined label").with_label(span)
}

#[cold]
fn invalid_label_non_iteration(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("A `{x0}` statement can only jump to a label of an enclosing `for`, `while` or `do while` statement."))
.with_labels([
Expand All @@ -723,6 +744,7 @@ fn invalid_label_non_iteration(x0: &str, span1: Span, span2: Span) -> OxcDiagnos
])
}

#[cold]
fn invalid_break(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Illegal break statement")
.with_help("A `break` statement can only be used within an enclosing iteration or switch statement.")
Expand Down Expand Up @@ -765,6 +787,7 @@ pub fn check_break_statement(stmt: &BreakStatement, ctx: &SemanticBuilder<'_>) {
}
}

#[cold]
fn invalid_continue(span: 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` ")
Expand Down Expand Up @@ -814,6 +837,7 @@ pub fn check_continue_statement(stmt: &ContinueStatement, ctx: &SemanticBuilder<
}
}

#[cold]
fn label_redeclaration(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("Label `{x0}` has already been declared")).with_labels([
span1.label(format!("`{x0}` has already been declared here")),
Expand Down Expand Up @@ -841,13 +865,15 @@ pub fn check_labeled_statement(stmt: &LabeledStatement, ctx: &SemanticBuilder<'_
}
}

#[cold]
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_label(span1)
}

#[cold]
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_label(span1)
Expand Down Expand Up @@ -884,13 +910,15 @@ pub fn check_for_statement_left(
}
}

#[cold]
fn duplicate_constructor(span: Span, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Multiple constructor implementations are not allowed.").with_labels([
LabeledSpan::new_with_span(Some("constructor has already been declared here".into()), span),
LabeledSpan::new_with_span(Some("it cannot be redeclared here".into()), span1),
])
}

#[cold]
fn require_class_name(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("A class name is required.").with_label(span)
}
Expand Down Expand Up @@ -930,6 +958,7 @@ pub fn check_class(class: &Class, ctx: &SemanticBuilder<'_>) {
}
}

#[cold]
fn super_without_derived_class(span: Span, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::error("'super' can only be referenced in a derived class.")
.with_help("either remove this super, or extend the class")
Expand All @@ -939,11 +968,13 @@ fn super_without_derived_class(span: Span, span1: Span) -> OxcDiagnostic {
])
}

#[cold]
fn unexpected_super_call(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Super calls are not permitted outside constructors or in nested functions inside constructors.")
.with_label(span)
}

#[cold]
fn unexpected_super_reference(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("'super' can only be referenced in members of derived classes or object literal expressions.")
.with_label(span)
Expand Down Expand Up @@ -1212,6 +1243,7 @@ fn get_class_details(
(Some(scope_id), class_id)
}

#[cold]
fn assignment_is_not_simple(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Invalid left-hand side in assignment").with_label(span)
}
Expand Down Expand Up @@ -1254,6 +1286,7 @@ pub fn check_object_expression(obj_expr: &ObjectExpression, ctx: &SemanticBuilde
}
}

#[cold]
fn super_private(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Private fields cannot be accessed on super").with_label(span)
}
Expand All @@ -1268,10 +1301,12 @@ pub fn check_private_field_expression(
}
}

#[cold]
fn delete_of_unqualified(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Delete of an unqualified identifier in strict mode.").with_label(span)
}

#[cold]
fn delete_private_field(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("The operand of a 'delete' operator cannot be a private identifier.")
.with_label(span)
Expand Down Expand Up @@ -1310,6 +1345,7 @@ fn is_in_formal_parameters(ctx: &SemanticBuilder<'_>) -> bool {
false
}

#[cold]
fn await_or_yield_in_parameter(x0: &str, span1: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("{x0} expression not allowed in formal parameter"))
.with_label(span1.label(format!("{x0} expression not allowed in formal parameter")))
Expand Down
Loading
Loading