mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[rust][sema] Test for function hoisting
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
function Component(props) {
|
||||
foo();
|
||||
if (props) {
|
||||
{
|
||||
for (;;) {
|
||||
while (true) {
|
||||
do {
|
||||
function foo() {
|
||||
bar();
|
||||
if (props) {
|
||||
const _ = function bar() {};
|
||||
}
|
||||
}
|
||||
break;
|
||||
} while (true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
---
|
||||
source: crates/forget_semantic_analysis/tests/analysis_test.rs
|
||||
expression: "format!(\"Input:\\n{input}\\n\\nAnalysis:\\n{output}\")"
|
||||
input_file: crates/forget_semantic_analysis/tests/fixtures/function-hoisting.js
|
||||
---
|
||||
Input:
|
||||
function Component(props) {
|
||||
foo();
|
||||
if (props) {
|
||||
{
|
||||
for (;;) {
|
||||
while (true) {
|
||||
do {
|
||||
function foo() {
|
||||
bar();
|
||||
if (props) {
|
||||
const _ = function bar() {};
|
||||
}
|
||||
}
|
||||
break;
|
||||
} while (true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Analysis:
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
0,
|
||||
),
|
||||
kind: Global,
|
||||
declarations: {},
|
||||
references: [],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
1,
|
||||
),
|
||||
kind: Module,
|
||||
declarations: {
|
||||
"Component": Declaration {
|
||||
id: DeclarationId(
|
||||
0,
|
||||
),
|
||||
kind: FunctionDeclaration,
|
||||
scope: ScopeId(
|
||||
1,
|
||||
),
|
||||
},
|
||||
},
|
||||
references: [],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
2,
|
||||
),
|
||||
kind: Function,
|
||||
declarations: {
|
||||
"props": Declaration {
|
||||
id: DeclarationId(
|
||||
1,
|
||||
),
|
||||
kind: FunctionDeclaration,
|
||||
scope: ScopeId(
|
||||
2,
|
||||
),
|
||||
},
|
||||
"foo": Declaration {
|
||||
id: DeclarationId(
|
||||
2,
|
||||
),
|
||||
kind: FunctionDeclaration,
|
||||
scope: ScopeId(
|
||||
2,
|
||||
),
|
||||
},
|
||||
},
|
||||
references: [
|
||||
Reference {
|
||||
id: ReferenceId(
|
||||
1,
|
||||
),
|
||||
kind: Read,
|
||||
declaration: DeclarationId(
|
||||
2,
|
||||
),
|
||||
declaration (name): "foo",
|
||||
scope: ScopeId(
|
||||
2,
|
||||
),
|
||||
},
|
||||
Reference {
|
||||
id: ReferenceId(
|
||||
2,
|
||||
),
|
||||
kind: Read,
|
||||
declaration: DeclarationId(
|
||||
1,
|
||||
),
|
||||
declaration (name): "props",
|
||||
scope: ScopeId(
|
||||
2,
|
||||
),
|
||||
},
|
||||
],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
3,
|
||||
),
|
||||
kind: Block,
|
||||
declarations: {},
|
||||
references: [],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
4,
|
||||
),
|
||||
kind: Block,
|
||||
declarations: {},
|
||||
references: [],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
5,
|
||||
),
|
||||
kind: Block,
|
||||
declarations: {},
|
||||
references: [],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
6,
|
||||
),
|
||||
kind: Block,
|
||||
declarations: {},
|
||||
references: [],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
7,
|
||||
),
|
||||
kind: Block,
|
||||
declarations: {},
|
||||
references: [],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
8,
|
||||
),
|
||||
kind: Function,
|
||||
declarations: {},
|
||||
references: [
|
||||
Reference {
|
||||
id: ReferenceId(
|
||||
0,
|
||||
),
|
||||
kind: Read,
|
||||
declaration: DeclarationId(
|
||||
1,
|
||||
),
|
||||
declaration (name): "props",
|
||||
scope: ScopeId(
|
||||
8,
|
||||
),
|
||||
},
|
||||
],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
9,
|
||||
),
|
||||
kind: Block,
|
||||
declarations: {
|
||||
"_": Declaration {
|
||||
id: DeclarationId(
|
||||
3,
|
||||
),
|
||||
kind: Const,
|
||||
scope: ScopeId(
|
||||
9,
|
||||
),
|
||||
},
|
||||
},
|
||||
references: [],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
10,
|
||||
),
|
||||
kind: Function,
|
||||
declarations: {
|
||||
"bar": Declaration {
|
||||
id: DeclarationId(
|
||||
4,
|
||||
),
|
||||
kind: FunctionDeclaration,
|
||||
scope: ScopeId(
|
||||
10,
|
||||
),
|
||||
},
|
||||
},
|
||||
references: [],
|
||||
children: [
|
||||
Scope {
|
||||
id: ScopeId(
|
||||
11,
|
||||
),
|
||||
kind: Function,
|
||||
declarations: {},
|
||||
references: [],
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
Diagnostic(
|
||||
DiagnosticData {
|
||||
message: "Undefined variable",
|
||||
span: Some(
|
||||
SourceSpan {
|
||||
offset: SourceOffset(
|
||||
0,
|
||||
),
|
||||
length: 1,
|
||||
},
|
||||
),
|
||||
related_information: [],
|
||||
severity: InvalidSyntax,
|
||||
data: [],
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user