mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(semantic): ? on variable declaration type annotations is a syntax error (#5956)
Closes #5955
This commit is contained in:
parent
05f592b834
commit
f1551d64bc
9 changed files with 57 additions and 10 deletions
|
|
@ -52,7 +52,7 @@ fn unexpected_optional(span: Span) -> OxcDiagnostic {
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
pub fn check_variable_declarator(decl: &VariableDeclarator, ctx: &SemanticBuilder<'_>) {
|
pub fn check_variable_declarator(decl: &VariableDeclarator, ctx: &SemanticBuilder<'_>) {
|
||||||
if decl.id.optional {
|
if decl.id.optional {
|
||||||
let start = decl.id.span().end;
|
let start = decl.id.span().start;
|
||||||
let Some(offset) = ctx.source_text[start as usize..].find('?') else { return };
|
let Some(offset) = ctx.source_text[start as usize..].find('?') else { return };
|
||||||
let offset = start + offset as u32;
|
let offset = start + offset as u32;
|
||||||
ctx.error(unexpected_optional(Span::new(offset, offset)));
|
ctx.error(unexpected_optional(Span::new(offset, offset)));
|
||||||
|
|
|
||||||
2
tasks/coverage/misc/fail/oxc-5955-1.ts
Normal file
2
tasks/coverage/misc/fail/oxc-5955-1.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
const x?: number = 1;
|
||||||
|
|
||||||
4
tasks/coverage/misc/fail/oxc-5955-2.ts
Normal file
4
tasks/coverage/misc/fail/oxc-5955-2.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
interface B {
|
||||||
|
e()?: number;
|
||||||
|
}
|
||||||
3
tasks/coverage/misc/fail/oxc-5955-3.ts
Normal file
3
tasks/coverage/misc/fail/oxc-5955-3.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
class A {
|
||||||
|
[key: string]?: number;
|
||||||
|
}
|
||||||
7
tasks/coverage/misc/pass/oxc-5955.ts
Normal file
7
tasks/coverage/misc/pass/oxc-5955.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
const a = (b?: number) => b;
|
||||||
|
class B {
|
||||||
|
c?: number = 1;
|
||||||
|
}
|
||||||
|
interface C {
|
||||||
|
d?: number;
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
codegen_misc Summary:
|
codegen_misc Summary:
|
||||||
AST Parsed : 29/29 (100.00%)
|
AST Parsed : 30/30 (100.00%)
|
||||||
Positive Passed: 29/29 (100.00%)
|
Positive Passed: 30/30 (100.00%)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
parser_misc Summary:
|
parser_misc Summary:
|
||||||
AST Parsed : 29/29 (100.00%)
|
AST Parsed : 30/30 (100.00%)
|
||||||
Positive Passed: 29/29 (100.00%)
|
Positive Passed: 30/30 (100.00%)
|
||||||
Negative Passed: 17/17 (100.00%)
|
Negative Passed: 20/20 (100.00%)
|
||||||
|
|
||||||
× Unexpected token
|
× Unexpected token
|
||||||
╭─[misc/fail/oxc-169.js:2:1]
|
╭─[misc/fail/oxc-169.js:2:1]
|
||||||
|
|
@ -244,6 +244,29 @@ Negative Passed: 17/17 (100.00%)
|
||||||
· ───────
|
· ───────
|
||||||
╰────
|
╰────
|
||||||
|
|
||||||
|
× Unexpected `?` operator
|
||||||
|
╭─[misc/fail/oxc-5955-1.ts:1:8]
|
||||||
|
1 │ const x?: number = 1;
|
||||||
|
· ▲
|
||||||
|
2 │
|
||||||
|
╰────
|
||||||
|
|
||||||
|
× Unexpected token
|
||||||
|
╭─[misc/fail/oxc-5955-2.ts:3:8]
|
||||||
|
2 │ interface B {
|
||||||
|
3 │ e()?: number;
|
||||||
|
· ─
|
||||||
|
4 │ }
|
||||||
|
╰────
|
||||||
|
|
||||||
|
× Unexpected token
|
||||||
|
╭─[misc/fail/oxc-5955-3.ts:2:18]
|
||||||
|
1 │ class A {
|
||||||
|
2 │ [key: string]?: number;
|
||||||
|
· ─
|
||||||
|
3 │ }
|
||||||
|
╰────
|
||||||
|
|
||||||
× The keyword 'let' is reserved
|
× The keyword 'let' is reserved
|
||||||
╭─[misc/fail/oxc.js:3:1]
|
╭─[misc/fail/oxc.js:3:1]
|
||||||
2 │
|
2 │
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
semantic_misc Summary:
|
semantic_misc Summary:
|
||||||
AST Parsed : 29/29 (100.00%)
|
AST Parsed : 30/30 (100.00%)
|
||||||
Positive Passed: 17/29 (58.62%)
|
Positive Passed: 17/30 (56.67%)
|
||||||
tasks/coverage/misc/pass/babel-16776-m.js
|
tasks/coverage/misc/pass/babel-16776-m.js
|
||||||
semantic error: Symbol flags mismatch:
|
semantic error: Symbol flags mismatch:
|
||||||
after transform: SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
|
after transform: SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
|
||||||
|
|
@ -176,6 +176,14 @@ Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
rebuilt : ScopeId(0): [ScopeId(1)]
|
rebuilt : ScopeId(0): [ScopeId(1)]
|
||||||
|
|
||||||
|
tasks/coverage/misc/pass/oxc-5955.ts
|
||||||
|
semantic error: Bindings mismatch:
|
||||||
|
after transform: ScopeId(0): ["B", "C", "a"]
|
||||||
|
rebuilt : ScopeId(0): ["B", "a"]
|
||||||
|
Scope children mismatch:
|
||||||
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3)]
|
||||||
|
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
|
|
||||||
tasks/coverage/misc/pass/swc-7187.ts
|
tasks/coverage/misc/pass/swc-7187.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Bindings mismatch:
|
||||||
after transform: ScopeId(0): ["K"]
|
after transform: ScopeId(0): ["K"]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
transformer_misc Summary:
|
transformer_misc Summary:
|
||||||
AST Parsed : 29/29 (100.00%)
|
AST Parsed : 30/30 (100.00%)
|
||||||
Positive Passed: 29/29 (100.00%)
|
Positive Passed: 30/30 (100.00%)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue