diff --git a/crates/oxc_semantic/src/checker/typescript.rs b/crates/oxc_semantic/src/checker/typescript.rs index 4d4a1001a..ab2fe522c 100644 --- a/crates/oxc_semantic/src/checker/typescript.rs +++ b/crates/oxc_semantic/src/checker/typescript.rs @@ -20,6 +20,7 @@ impl EarlyErrorTypeScript { AstKind::VariableDeclarator(decl) => check_variable_declarator(decl, ctx), AstKind::SimpleAssignmentTarget(target) => check_simple_assignment_target(target, ctx), AstKind::FormalParameters(params) => check_formal_parameters(params, ctx), + AstKind::ArrayPattern(pattern) => check_array_pattern(pattern, ctx), _ => {} } } @@ -101,3 +102,18 @@ fn check_simple_assignment_target<'a>( } } } + +fn check_array_pattern<'a>(pattern: &ArrayPattern<'a>, ctx: &SemanticBuilder<'a>) { + #[derive(Debug, Error, Diagnostic)] + #[error("Unexpected type annotation")] + #[diagnostic()] + struct UnexpectedTypeAnnotation(#[label] Span); + + for element in &pattern.elements { + let _ = element.as_ref().map(|element| { + if let Some(type_annotation) = &element.type_annotation { + ctx.error(UnexpectedTypeAnnotation(type_annotation.span)); + } + }); + } +} diff --git a/tasks/coverage/parser_babel.snap b/tasks/coverage/parser_babel.snap index b0a4c11f7..3d33445ba 100644 --- a/tasks/coverage/parser_babel.snap +++ b/tasks/coverage/parser_babel.snap @@ -1,7 +1,7 @@ parser_babel Summary: AST Parsed : 2090/2096 (99.71%) Positive Passed: 2086/2096 (99.52%) -Negative Passed: 1355/1500 (90.33%) +Negative Passed: 1358/1500 (90.53%) Expect Syntax Error: "annex-b/disabled/1.1-html-comments-close/input.js" Expect Syntax Error: "annex-b/disabled/3.1-sloppy-labeled-functions/input.js" Expect Syntax Error: "annex-b/disabled/3.1-sloppy-labeled-functions-if-body/input.js" @@ -138,9 +138,6 @@ Expect Syntax Error: "typescript/types/const-type-parameters-invalid-babel-7/inp Expect Syntax Error: "typescript/types/import-type-declaration-error/input.ts" Expect Syntax Error: "typescript/types/import-type-dynamic-errors/input.ts" Expect Syntax Error: "typescript/types/intrinsic-keyword-error/input.ts" -Expect Syntax Error: "typescript/types/no-annotation-in-destructuring/input.ts" -Expect Syntax Error: "typescript/types/no-optional-in-destructuring/input.ts" -Expect Syntax Error: "typescript/types/no-optional-in-destructuring-in-params/input.ts" Expect Syntax Error: "typescript/types/read-only-1/input.ts" Expect Syntax Error: "typescript/types/read-only-2/input.ts" Expect Syntax Error: "typescript/types/read-only-3/input.ts" @@ -10416,6 +10413,24 @@ Expect to Parse: "typescript/types/const-type-parameters-babel-7/input.ts" · ─ ╰──── + × Unexpected type annotation + ╭─[typescript/types/no-annotation-in-destructuring/input.ts:1:7] + 1 │ let [a: number] = b; + · ──────── + ╰──── + + × Unexpected type annotation + ╭─[typescript/types/no-optional-in-destructuring/input.ts:1:7] + 1 │ let [a: number] = b; + · ──────── + ╰──── + + × Unexpected type annotation + ╭─[typescript/types/no-optional-in-destructuring-in-params/input.ts:1:14] + 1 │ function f([a: number]) {} + · ──────── + ╰──── + × Expected `,` but found `:` ╭─[typescript/types/tuple-invalid-label-1/input.ts:1:14] 1 │ type T = [x.y: A];