diff --git a/compiler/forget/crates/forget_semantic_analysis/tests/fixtures/function-hoisting.js b/compiler/forget/crates/forget_semantic_analysis/tests/fixtures/function-hoisting.js new file mode 100644 index 0000000000..d081238b50 --- /dev/null +++ b/compiler/forget/crates/forget_semantic_analysis/tests/fixtures/function-hoisting.js @@ -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; + } + } + } +} diff --git a/compiler/forget/crates/forget_semantic_analysis/tests/snapshots/analysis_test__fixtures@function-hoisting.js.snap b/compiler/forget/crates/forget_semantic_analysis/tests/snapshots/analysis_test__fixtures@function-hoisting.js.snap new file mode 100644 index 0000000000..72ca147b5f --- /dev/null +++ b/compiler/forget/crates/forget_semantic_analysis/tests/snapshots/analysis_test__fixtures@function-hoisting.js.snap @@ -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: [], + }, +) +