mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(semantic): report unexpected type annotation in ArrayPattern (#2309)
This commit is contained in:
parent
73ec4df61c
commit
f53c54ced9
2 changed files with 35 additions and 4 deletions
|
|
@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Reference in a new issue