mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(semantic): incorrect semantic check for label has same name (#5041)
fix: #5036 --------- Co-authored-by: Boshen <boshenc@gmail.com>
This commit is contained in:
parent
d5de97d6fe
commit
ad2be97078
8 changed files with 76 additions and 10 deletions
|
|
@ -649,7 +649,18 @@ fn label_redeclaration(x0: &str, span1: Span, span2: Span) -> OxcDiagnostic {
|
|||
pub fn check_labeled_statement(ctx: &SemanticBuilder) {
|
||||
ctx.label_builder.labels.iter().for_each(|labels| {
|
||||
let mut defined = FxHashMap::default();
|
||||
//only need to care about the monotone increasing depth of the array
|
||||
let mut increase_depth = vec![];
|
||||
for labeled in labels {
|
||||
increase_depth.push(labeled);
|
||||
// have to traverse because HashMap can only delete one by one
|
||||
while increase_depth.len() > 2
|
||||
&& increase_depth.iter().rev().nth(1).unwrap().depth
|
||||
>= increase_depth.iter().next_back().unwrap().depth
|
||||
{
|
||||
defined.remove(increase_depth[increase_depth.len() - 2].name);
|
||||
increase_depth.remove(increase_depth.len() - 2);
|
||||
}
|
||||
if let Some(span) = defined.get(labeled.name) {
|
||||
ctx.error(label_redeclaration(labeled.name, *span, labeled.span));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub struct Label<'a> {
|
|||
pub span: Span,
|
||||
used: bool,
|
||||
/// depth is the number of nested labeled statements
|
||||
depth: usize,
|
||||
pub depth: usize,
|
||||
/// is accessible means that the label is accessible from the current position
|
||||
is_accessible: bool,
|
||||
/// is_inside_function_or_static_block means that the label is inside a function or static block
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
codegen_misc Summary:
|
||||
AST Parsed : 25/25 (100.00%)
|
||||
Positive Passed: 25/25 (100.00%)
|
||||
AST Parsed : 26/26 (100.00%)
|
||||
Positive Passed: 26/26 (100.00%)
|
||||
|
|
|
|||
3
tasks/coverage/misc/fail/oxc-5036.js
Normal file
3
tasks/coverage/misc/fail/oxc-5036.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Test: {
|
||||
Test: console.log('Test');
|
||||
}
|
||||
41
tasks/coverage/misc/pass/oxc-5036.js
Normal file
41
tasks/coverage/misc/pass/oxc-5036.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
Parent: {
|
||||
Child1: {
|
||||
Child2: console.log("Child1");
|
||||
Child2: console.log("Child2");
|
||||
}
|
||||
Child1: {
|
||||
Child2: console.log("Child3");
|
||||
Child2: console.log("Child4");
|
||||
}
|
||||
Child2: {
|
||||
Child1: console.log("Child5");
|
||||
Child1: console.log("Child6");
|
||||
}
|
||||
}
|
||||
|
||||
Parent: {
|
||||
Child1: {
|
||||
Child2: console.log("Child7");
|
||||
Child2: console.log("Child8");
|
||||
}
|
||||
}
|
||||
|
||||
Parent: {
|
||||
Child1: {
|
||||
Child12: {
|
||||
Child3: {
|
||||
Child4: {
|
||||
Child5: console.log("Child9");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Child1: console.log("Child10");
|
||||
Child2: console.log("Child11");
|
||||
Child1: {
|
||||
Child2: {
|
||||
Child3: console.log("Child12");
|
||||
}
|
||||
}
|
||||
Child3: console.log("Child13");
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
parser_misc Summary:
|
||||
AST Parsed : 25/25 (100.00%)
|
||||
Positive Passed: 25/25 (100.00%)
|
||||
Negative Passed: 14/14 (100.00%)
|
||||
AST Parsed : 26/26 (100.00%)
|
||||
Positive Passed: 26/26 (100.00%)
|
||||
Negative Passed: 15/15 (100.00%)
|
||||
|
||||
× Unexpected token
|
||||
╭─[misc/fail/oxc-169.js:2:1]
|
||||
|
|
@ -219,6 +219,17 @@ Negative Passed: 14/14 (100.00%)
|
|||
· ─────────────
|
||||
╰────
|
||||
|
||||
× Label `Test` has already been declared
|
||||
╭─[misc/fail/oxc-5036.js:1:1]
|
||||
1 │ Test: {
|
||||
· ──┬─
|
||||
· ╰── `Test` has already been declared here
|
||||
2 │ Test: console.log('Test');
|
||||
· ──┬─
|
||||
· ╰── It can not be redeclared here
|
||||
3 │ }
|
||||
╰────
|
||||
|
||||
× The keyword 'let' is reserved
|
||||
╭─[misc/fail/oxc.js:1:1]
|
||||
1 │ let.a = 1;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
semantic_misc Summary:
|
||||
AST Parsed : 25/25 (100.00%)
|
||||
Positive Passed: 16/25 (64.00%)
|
||||
AST Parsed : 26/26 (100.00%)
|
||||
Positive Passed: 17/26 (65.38%)
|
||||
tasks/coverage/misc/pass/oxc-1288.ts
|
||||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(0): ["from"]
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
transformer_misc Summary:
|
||||
AST Parsed : 25/25 (100.00%)
|
||||
Positive Passed: 25/25 (100.00%)
|
||||
AST Parsed : 26/26 (100.00%)
|
||||
Positive Passed: 26/26 (100.00%)
|
||||
|
|
|
|||
Loading…
Reference in a new issue