@samitouri / QOS-React-2 / commits / 34914796b2

[rust][sema] Set root scope kind based on program source type

Rather than always create a Global scope and then immediately add a Module child node, we now set the kind of the root scope to global (for scripts) or module (for modules) based on the program node.

Joe Savona committed Aug 15, 2023 at 12:24 UTC 34914796b247b8fd2912fe90ebd301ad7b2fdb74
7 files changed +526 -580
compiler/forget/crates/forget_semantic_analysis/src/analyzer.rs
+6 -14
@@ -2,7 +2,7 @@ use forget_diagnostics::Diagnostic;
2 use forget_estree::{
3 AssignmentOperator, AssignmentPropertyOrRestElement, AssignmentTarget, Expression,
4 ExpressionOrSuper, ForInInit, ForInit, FunctionBody, Identifier, ImportDeclarationSpecifier,
5 - IntoFunction, JSXElementName, Pattern, Program, SourceRange, SourceType, Statement,
5 + IntoFunction, JSXElementName, Pattern, Program, SourceRange, Statement,
6 VariableDeclarationKind, Visitor,
7 };
8
@@ -12,7 +12,7 @@ use crate::{
12 };
13
14 pub fn analyze(ast: &Program) -> ScopeManager {
15 - let mut analyzer = Analyzer::new();
15 + let mut analyzer = Analyzer::new(ast);
16 analyzer.visit_program(ast);
17 analyzer.manager
18 }
@@ -24,8 +24,8 @@ struct Analyzer {
24 }
25
26 impl Analyzer {
27 - fn new() -> Self {
28 - let manager = ScopeManager::new();
27 + fn new(program: &Program) -> Self {
28 + let manager = ScopeManager::new(program.source_type);
29 let current = manager.root_id();
30 let labels = Default::default();
31 Self {
@@ -643,16 +643,8 @@ impl Visitor for Analyzer {
643 }
644
645 fn visit_program(&mut self, ast: &forget_estree::Program) {
646 - if ast.source_type == SourceType::Module {
647 - self.enter(ScopeKind::Module, |visitor| {
648 - for item in &ast.body {
649 - visitor.visit_module_item(item);
650 - }
651 - });
652 - } else {
653 - for item in &ast.body {
654 - self.visit_module_item(item);
655 - }
646 + for item in &ast.body {
647 + self.visit_module_item(item);
648 }
649 let scope = self.manager.mut_scope(self.current);
650 let unresolved = std::mem::take(&mut scope.unresolved);
compiler/forget/crates/forget_semantic_analysis/src/scope_manager.rs
+7 -3
@@ -1,6 +1,6 @@
1 use forget_diagnostics::Diagnostic;
2 use forget_estree::{
3 - BreakStatement, ContinueStatement, ESTreeNode, LabeledStatement, SourceRange,
3 + BreakStatement, ContinueStatement, ESTreeNode, LabeledStatement, SourceRange, SourceType,
4 VariableDeclarationKind,
5 };
6 use forget_utils::PointerAddress;
@@ -33,13 +33,17 @@ impl std::fmt::Debug for ScopeManager {
33 }
34
35 impl ScopeManager {
36 - pub(crate) fn new() -> Self {
36 + pub(crate) fn new(source_type: SourceType) -> Self {
37 let root_id = ScopeId(0);
38 + let root_kind = match source_type {
39 + SourceType::Module => ScopeKind::Module,
40 + SourceType::Script => ScopeKind::Global,
41 + };
42 Self {
43 root: root_id,
44 scopes: vec![Scope {
45 id: root_id,
42 - kind: ScopeKind::Global,
46 + kind: root_kind,
47 parent: None,
48 declarations: Default::default(),
49 references: Default::default(),
compiler/forget/crates/forget_semantic_analysis/tests/snapshots/analysis_test__fixtures@function-hoisting.js.snap
+85 -95
@@ -33,19 +33,38 @@ Scope {
33 id: ScopeId(
34 0,
35 ),
36 - kind: Global,
37 - declarations: {},
36 + kind: Module,
37 + declarations: {
38 + "Component": Declaration {
39 + id: DeclarationId(
40 + 0,
41 + ),
42 + kind: FunctionDeclaration,
43 + scope: ScopeId(
44 + 0,
45 + ),
46 + },
47 + },
48 references: [],
49 children: [
50 Scope {
51 id: ScopeId(
52 1,
53 ),
44 - kind: Module,
54 + kind: Function,
55 declarations: {
46 - "Component": Declaration {
56 + "props": Declaration {
57 id: DeclarationId(
48 - 0,
58 + 1,
59 + ),
60 + kind: FunctionDeclaration,
61 + scope: ScopeId(
62 + 1,
63 + ),
64 + },
65 + "foo": Declaration {
66 + id: DeclarationId(
67 + 2,
68 ),
69 kind: FunctionDeclaration,
70 scope: ScopeId(
@@ -53,61 +72,42 @@ Scope {
72 ),
73 },
74 },
56 - references: [],
75 + references: [
76 + Reference {
77 + id: ReferenceId(
78 + 1,
79 + ),
80 + kind: Read,
81 + declaration: DeclarationId(
82 + 2,
83 + ),
84 + declaration (name): "foo",
85 + scope: ScopeId(
86 + 1,
87 + ),
88 + },
89 + Reference {
90 + id: ReferenceId(
91 + 2,
92 + ),
93 + kind: Read,
94 + declaration: DeclarationId(
95 + 1,
96 + ),
97 + declaration (name): "props",
98 + scope: ScopeId(
99 + 1,
100 + ),
101 + },
102 + ],
103 children: [
104 Scope {
105 id: ScopeId(
106 2,
107 ),
62 - kind: Function,
63 - declarations: {
64 - "props": Declaration {
65 - id: DeclarationId(
66 - 1,
67 - ),
68 - kind: FunctionDeclaration,
69 - scope: ScopeId(
70 - 2,
71 - ),
72 - },
73 - "foo": Declaration {
74 - id: DeclarationId(
75 - 2,
76 - ),
77 - kind: FunctionDeclaration,
78 - scope: ScopeId(
79 - 2,
80 - ),
81 - },
82 - },
83 - references: [
84 - Reference {
85 - id: ReferenceId(
86 - 1,
87 - ),
88 - kind: Read,
89 - declaration: DeclarationId(
90 - 2,
91 - ),
92 - declaration (name): "foo",
93 - scope: ScopeId(
94 - 2,
95 - ),
96 - },
97 - Reference {
98 - id: ReferenceId(
99 - 2,
100 - ),
101 - kind: Read,
102 - declaration: DeclarationId(
103 - 1,
104 - ),
105 - declaration (name): "props",
106 - scope: ScopeId(
107 - 2,
108 - ),
109 - },
110 - ],
108 + kind: Block,
109 + declarations: {},
110 + references: [],
111 children: [
112 Scope {
113 id: ScopeId(
@@ -145,43 +145,53 @@ Scope {
145 id: ScopeId(
146 7,
147 ),
148 - kind: Block,
148 + kind: Function,
149 declarations: {},
150 - references: [],
150 + references: [
151 + Reference {
152 + id: ReferenceId(
153 + 0,
154 + ),
155 + kind: Read,
156 + declaration: DeclarationId(
157 + 1,
158 + ),
159 + declaration (name): "props",
160 + scope: ScopeId(
161 + 7,
162 + ),
163 + },
164 + ],
165 children: [
166 Scope {
167 id: ScopeId(
168 8,
169 ),
156 - kind: Function,
157 - declarations: {},
158 - references: [
159 - Reference {
160 - id: ReferenceId(
161 - 0,
162 - ),
163 - kind: Read,
164 - declaration: DeclarationId(
165 - 1,
170 + kind: Block,
171 + declarations: {
172 + "_": Declaration {
173 + id: DeclarationId(
174 + 3,
175 ),
167 - declaration (name): "props",
176 + kind: Const,
177 scope: ScopeId(
178 8,
179 ),
180 },
172 - ],
181 + },
182 + references: [],
183 children: [
184 Scope {
185 id: ScopeId(
186 9,
187 ),
178 - kind: Block,
188 + kind: Function,
189 declarations: {
180 - "_": Declaration {
190 + "bar": Declaration {
191 id: DeclarationId(
182 - 3,
192 + 4,
193 ),
184 - kind: Const,
194 + kind: FunctionDeclaration,
195 scope: ScopeId(
196 9,
197 ),
@@ -194,29 +204,9 @@ Scope {
204 10,
205 ),
206 kind: Function,
197 - declarations: {
198 - "bar": Declaration {
199 - id: DeclarationId(
200 - 4,
201 - ),
202 - kind: FunctionDeclaration,
203 - scope: ScopeId(
204 - 10,
205 - ),
206 - },
207 - },
207 + declarations: {},
208 references: [],
209 - children: [
210 - Scope {
211 - id: ScopeId(
212 - 11,
213 - ),
214 - kind: Function,
215 - declarations: {},
216 - references: [],
217 - children: [],
218 - },
219 - ],
209 + children: [],
210 },
211 ],
212 },
compiler/forget/crates/forget_semantic_analysis/tests/snapshots/analysis_test__fixtures@globals-and-imports.js.snap
+170 -180
@@ -28,225 +28,215 @@ Scope {
28 id: ScopeId(
29 0,
30 ),
31 - kind: Global,
32 - declarations: {},
31 + kind: Module,
32 + declarations: {
33 + "Foo": Declaration {
34 + id: DeclarationId(
35 + 0,
36 + ),
37 + kind: Import,
38 + scope: ScopeId(
39 + 0,
40 + ),
41 + },
42 + "Bar": Declaration {
43 + id: DeclarationId(
44 + 1,
45 + ),
46 + kind: Import,
47 + scope: ScopeId(
48 + 0,
49 + ),
50 + },
51 + "Baz": Declaration {
52 + id: DeclarationId(
53 + 2,
54 + ),
55 + kind: Import,
56 + scope: ScopeId(
57 + 0,
58 + ),
59 + },
60 + "Component": Declaration {
61 + id: DeclarationId(
62 + 3,
63 + ),
64 + kind: FunctionDeclaration,
65 + scope: ScopeId(
66 + 0,
67 + ),
68 + },
69 + },
70 references: [],
71 children: [
72 Scope {
73 id: ScopeId(
74 1,
75 ),
39 - kind: Module,
76 + kind: Function,
77 declarations: {
41 - "Foo": Declaration {
78 + "props": Declaration {
79 id: DeclarationId(
43 - 0,
80 + 4,
81 ),
45 - kind: Import,
82 + kind: FunctionDeclaration,
83 scope: ScopeId(
84 1,
85 ),
86 },
50 - "Bar": Declaration {
87 + "g": Declaration {
88 id: DeclarationId(
89 + 5,
90 + ),
91 + kind: Let,
92 + scope: ScopeId(
93 1,
94 ),
54 - kind: Import,
95 + },
96 + "y": Declaration {
97 + id: DeclarationId(
98 + 6,
99 + ),
100 + kind: Let,
101 scope: ScopeId(
102 1,
103 ),
104 },
59 - "Baz": Declaration {
105 + "s": Declaration {
106 id: DeclarationId(
61 - 2,
107 + 7,
108 ),
63 - kind: Import,
109 + kind: Let,
110 scope: ScopeId(
111 1,
112 ),
113 },
68 - "Component": Declaration {
114 + "b": Declaration {
115 id: DeclarationId(
70 - 3,
116 + 8,
117 ),
72 - kind: FunctionDeclaration,
118 + kind: Let,
119 + scope: ScopeId(
120 + 1,
121 + ),
122 + },
123 + "n": Declaration {
124 + id: DeclarationId(
125 + 9,
126 + ),
127 + kind: Let,
128 + scope: ScopeId(
129 + 1,
130 + ),
131 + },
132 + "x": Declaration {
133 + id: DeclarationId(
134 + 10,
135 + ),
136 + kind: Let,
137 scope: ScopeId(
138 1,
139 ),
140 },
141 },
78 - references: [],
142 + references: [
143 + Reference {
144 + id: ReferenceId(
145 + 0,
146 + ),
147 + kind: Read,
148 + declaration: DeclarationId(
149 + 4,
150 + ),
151 + declaration (name): "props",
152 + scope: ScopeId(
153 + 1,
154 + ),
155 + },
156 + Reference {
157 + id: ReferenceId(
158 + 1,
159 + ),
160 + kind: Read,
161 + declaration: DeclarationId(
162 + 4,
163 + ),
164 + declaration (name): "props",
165 + scope: ScopeId(
166 + 1,
167 + ),
168 + },
169 + Reference {
170 + id: ReferenceId(
171 + 2,
172 + ),
173 + kind: Read,
174 + declaration: DeclarationId(
175 + 4,
176 + ),
177 + declaration (name): "props",
178 + scope: ScopeId(
179 + 1,
180 + ),
181 + },
182 + Reference {
183 + id: ReferenceId(
184 + 3,
185 + ),
186 + kind: Read,
187 + declaration: DeclarationId(
188 + 0,
189 + ),
190 + declaration (name): "Foo",
191 + scope: ScopeId(
192 + 1,
193 + ),
194 + },
195 + Reference {
196 + id: ReferenceId(
197 + 4,
198 + ),
199 + kind: Read,
200 + declaration: DeclarationId(
201 + 1,
202 + ),
203 + declaration (name): "Bar",
204 + scope: ScopeId(
205 + 1,
206 + ),
207 + },
208 + Reference {
209 + id: ReferenceId(
210 + 5,
211 + ),
212 + kind: Read,
213 + declaration: DeclarationId(
214 + 2,
215 + ),
216 + declaration (name): "Baz",
217 + scope: ScopeId(
218 + 1,
219 + ),
220 + },
221 + ],
222 children: [
223 Scope {
224 id: ScopeId(
225 2,
226 ),
227 kind: Function,
85 - declarations: {
86 - "props": Declaration {
87 - id: DeclarationId(
88 - 4,
89 - ),
90 - kind: FunctionDeclaration,
91 - scope: ScopeId(
92 - 2,
93 - ),
94 - },
95 - "g": Declaration {
96 - id: DeclarationId(
97 - 5,
98 - ),
99 - kind: Let,
100 - scope: ScopeId(
101 - 2,
102 - ),
103 - },
104 - "y": Declaration {
105 - id: DeclarationId(
106 - 6,
107 - ),
108 - kind: Let,
109 - scope: ScopeId(
110 - 2,
111 - ),
112 - },
113 - "s": Declaration {
114 - id: DeclarationId(
115 - 7,
116 - ),
117 - kind: Let,
118 - scope: ScopeId(
119 - 2,
120 - ),
121 - },
122 - "b": Declaration {
123 - id: DeclarationId(
124 - 8,
125 - ),
126 - kind: Let,
127 - scope: ScopeId(
128 - 2,
129 - ),
130 - },
131 - "n": Declaration {
132 - id: DeclarationId(
133 - 9,
134 - ),
135 - kind: Let,
136 - scope: ScopeId(
137 - 2,
138 - ),
139 - },
140 - "x": Declaration {
141 - id: DeclarationId(
142 - 10,
143 - ),
144 - kind: Let,
145 - scope: ScopeId(
146 - 2,
147 - ),
148 - },
149 - },
150 - references: [
151 - Reference {
152 - id: ReferenceId(
153 - 0,
154 - ),
155 - kind: Read,
156 - declaration: DeclarationId(
157 - 4,
158 - ),
159 - declaration (name): "props",
160 - scope: ScopeId(
161 - 2,
162 - ),
163 - },
164 - Reference {
165 - id: ReferenceId(
166 - 1,
167 - ),
168 - kind: Read,
169 - declaration: DeclarationId(
170 - 4,
171 - ),
172 - declaration (name): "props",
173 - scope: ScopeId(
174 - 2,
175 - ),
176 - },
177 - Reference {
178 - id: ReferenceId(
179 - 2,
180 - ),
181 - kind: Read,
182 - declaration: DeclarationId(
183 - 4,
184 - ),
185 - declaration (name): "props",
186 - scope: ScopeId(
187 - 2,
188 - ),
189 - },
190 - Reference {
191 - id: ReferenceId(
192 - 3,
193 - ),
194 - kind: Read,
195 - declaration: DeclarationId(
196 - 0,
197 - ),
198 - declaration (name): "Foo",
199 - scope: ScopeId(
200 - 2,
201 - ),
202 - },
203 - Reference {
204 - id: ReferenceId(
205 - 4,
206 - ),
207 - kind: Read,
208 - declaration: DeclarationId(
209 - 1,
210 - ),
211 - declaration (name): "Bar",
212 - scope: ScopeId(
213 - 2,
214 - ),
215 - },
216 - Reference {
217 - id: ReferenceId(
218 - 5,
219 - ),
220 - kind: Read,
221 - declaration: DeclarationId(
222 - 2,
223 - ),
224 - declaration (name): "Baz",
225 - scope: ScopeId(
226 - 2,
227 - ),
228 - },
229 - ],
230 - children: [
231 - Scope {
232 - id: ScopeId(
233 - 3,
234 - ),
235 - kind: Function,
236 - declarations: {},
237 - references: [],
238 - children: [],
239 - },
240 - Scope {
241 - id: ScopeId(
242 - 4,
243 - ),
244 - kind: Function,
245 - declarations: {},
246 - references: [],
247 - children: [],
248 - },
249 - ],
228 + declarations: {},
229 + references: [],
230 + children: [],
231 + },
232 + Scope {
233 + id: ScopeId(
234 + 3,
235 + ),
236 + kind: Function,
237 + declarations: {},
238 + references: [],
239 + children: [],
240 },
241 ],
242 },
compiler/forget/crates/forget_semantic_analysis/tests/snapshots/analysis_test__fixtures@labels.js.snap
+94 -104
@@ -24,63 +24,100 @@ Scope {
24 id: ScopeId(
25 0,
26 ),
27 - kind: Global,
28 - declarations: {},
27 + kind: Module,
28 + declarations: {
29 + "Component": Declaration {
30 + id: DeclarationId(
31 + 0,
32 + ),
33 + kind: FunctionDeclaration,
34 + scope: ScopeId(
35 + 0,
36 + ),
37 + },
38 + },
39 references: [],
40 children: [
41 Scope {
42 id: ScopeId(
43 1,
44 ),
35 - kind: Module,
45 + kind: Function,
46 declarations: {
37 - "Component": Declaration {
47 + "props": Declaration {
48 id: DeclarationId(
39 - 0,
49 + 1,
50 ),
51 kind: FunctionDeclaration,
52 scope: ScopeId(
53 1,
54 ),
55 },
56 + "y": Declaration {
57 + id: DeclarationId(
58 + 2,
59 + ),
60 + kind: Let,
61 + scope: ScopeId(
62 + 1,
63 + ),
64 + },
65 },
47 - references: [],
66 + references: [
67 + Reference {
68 + id: ReferenceId(
69 + 6,
70 + ),
71 + kind: Read,
72 + declaration: DeclarationId(
73 + 1,
74 + ),
75 + declaration (name): "props",
76 + scope: ScopeId(
77 + 1,
78 + ),
79 + },
80 + ],
81 children: [
82 Scope {
83 id: ScopeId(
84 2,
85 ),
53 - kind: Function,
86 + kind: For,
87 declarations: {
55 - "props": Declaration {
88 + "x": Declaration {
89 id: DeclarationId(
57 - 1,
90 + 3,
91 ),
59 - kind: FunctionDeclaration,
92 + kind: Let,
93 scope: ScopeId(
94 2,
95 ),
96 },
64 - "y": Declaration {
65 - id: DeclarationId(
66 - 2,
97 + },
98 + references: [
99 + Reference {
100 + id: ReferenceId(
101 + 4,
102 ),
68 - kind: Let,
103 + kind: Read,
104 + declaration: DeclarationId(
105 + 3,
106 + ),
107 + declaration (name): "x",
108 scope: ScopeId(
109 2,
110 ),
111 },
73 - },
74 - references: [
112 Reference {
113 id: ReferenceId(
77 - 6,
114 + 5,
115 ),
116 kind: Read,
117 declaration: DeclarationId(
81 - 1,
118 + 3,
119 ),
83 - declaration (name): "props",
120 + declaration (name): "x",
121 scope: ScopeId(
122 2,
123 ),
@@ -91,22 +128,38 @@ Scope {
128 id: ScopeId(
129 3,
130 ),
94 - kind: For,
95 - declarations: {
96 - "x": Declaration {
97 - id: DeclarationId(
131 + kind: Block,
132 + declarations: {},
133 + references: [
134 + Reference {
135 + id: ReferenceId(
136 + 0,
137 + ),
138 + kind: Read,
139 + declaration: DeclarationId(
140 3,
141 ),
100 - kind: Let,
142 + declaration (name): "x",
143 scope: ScopeId(
144 3,
145 ),
146 },
105 - },
106 - references: [
147 Reference {
148 id: ReferenceId(
109 - 4,
149 + 1,
150 + ),
151 + kind: Write,
152 + declaration: DeclarationId(
153 + 2,
154 + ),
155 + declaration (name): "y",
156 + scope: ScopeId(
157 + 3,
158 + ),
159 + },
160 + Reference {
161 + id: ReferenceId(
162 + 2,
163 ),
164 kind: Read,
165 declaration: DeclarationId(
@@ -119,13 +172,13 @@ Scope {
172 },
173 Reference {
174 id: ReferenceId(
122 - 5,
175 + 3,
176 ),
177 kind: Read,
178 declaration: DeclarationId(
126 - 3,
179 + 2,
180 ),
128 - declaration (name): "x",
181 + declaration (name): "y",
182 scope: ScopeId(
183 3,
184 ),
@@ -138,85 +191,22 @@ Scope {
191 ),
192 kind: Block,
193 declarations: {},
141 - references: [
142 - Reference {
143 - id: ReferenceId(
144 - 0,
145 - ),
146 - kind: Read,
147 - declaration: DeclarationId(
148 - 3,
149 - ),
150 - declaration (name): "x",
151 - scope: ScopeId(
152 - 4,
153 - ),
154 - },
155 - Reference {
156 - id: ReferenceId(
157 - 1,
158 - ),
159 - kind: Write,
160 - declaration: DeclarationId(
161 - 2,
162 - ),
163 - declaration (name): "y",
164 - scope: ScopeId(
165 - 4,
166 - ),
167 - },
168 - Reference {
169 - id: ReferenceId(
170 - 2,
171 - ),
172 - kind: Read,
173 - declaration: DeclarationId(
174 - 3,
175 - ),
176 - declaration (name): "x",
177 - scope: ScopeId(
178 - 4,
179 - ),
180 - },
181 - Reference {
182 - id: ReferenceId(
183 - 3,
184 - ),
185 - kind: Read,
186 - declaration: DeclarationId(
187 - 2,
188 - ),
189 - declaration (name): "y",
190 - scope: ScopeId(
191 - 4,
192 - ),
193 - },
194 - ],
195 - children: [
196 - Scope {
197 - id: ScopeId(
198 - 5,
199 - ),
200 - kind: Block,
201 - declarations: {},
202 - references: [],
203 - children: [],
204 - },
205 - ],
194 + references: [],
195 + children: [],
196 },
197 ],
198 },
209 - Scope {
210 - id: ScopeId(
211 - 6,
212 - ),
213 - kind: Block,
214 - declarations: {},
215 - references: [],
216 - children: [],
217 - },
199 ],
200 },
201 + Scope {
202 + id: ScopeId(
203 + 5,
204 + ),
205 + kind: Block,
206 + declarations: {},
207 + references: [],
208 + children: [],
209 + },
210 ],
211 },
212 ],
compiler/forget/crates/forget_semantic_analysis/tests/snapshots/analysis_test__fixtures@let-const-hoisting.js.snap
+49 -59
@@ -19,25 +19,53 @@ Scope {
19 id: ScopeId(
20 0,
21 ),
22 - kind: Global,
23 - declarations: {},
22 + kind: Module,
23 + declarations: {
24 + "Component": Declaration {
25 + id: DeclarationId(
26 + 0,
27 + ),
28 + kind: FunctionDeclaration,
29 + scope: ScopeId(
30 + 0,
31 + ),
32 + },
33 + },
34 references: [],
35 children: [
36 Scope {
37 id: ScopeId(
38 1,
39 ),
30 - kind: Module,
40 + kind: Function,
41 declarations: {
32 - "Component": Declaration {
42 + "foo": Declaration {
43 id: DeclarationId(
34 - 0,
44 + 1,
45 ),
46 kind: FunctionDeclaration,
47 scope: ScopeId(
48 1,
49 ),
50 },
51 + "a": Declaration {
52 + id: DeclarationId(
53 + 2,
54 + ),
55 + kind: Let,
56 + scope: ScopeId(
57 + 1,
58 + ),
59 + },
60 + "b": Declaration {
61 + id: DeclarationId(
62 + 3,
63 + ),
64 + kind: Const,
65 + scope: ScopeId(
66 + 1,
67 + ),
68 + },
69 },
70 references: [],
71 children: [
@@ -46,74 +74,36 @@ Scope {
74 2,
75 ),
76 kind: Function,
49 - declarations: {
50 - "foo": Declaration {
51 - id: DeclarationId(
52 - 1,
77 + declarations: {},
78 + references: [
79 + Reference {
80 + id: ReferenceId(
81 + 0,
82 ),
54 - kind: FunctionDeclaration,
55 - scope: ScopeId(
83 + kind: Read,
84 + declaration: DeclarationId(
85 2,
86 ),
58 - },
59 - "a": Declaration {
60 - id: DeclarationId(
61 - 2,
62 - ),
63 - kind: Let,
87 + declaration (name): "a",
88 scope: ScopeId(
89 2,
90 ),
91 },
68 - "b": Declaration {
69 - id: DeclarationId(
92 + Reference {
93 + id: ReferenceId(
94 + 1,
95 + ),
96 + kind: Read,
97 + declaration: DeclarationId(
98 3,
99 ),
72 - kind: Const,
100 + declaration (name): "b",
101 scope: ScopeId(
102 2,
103 ),
104 },
77 - },
78 - references: [],
79 - children: [
80 - Scope {
81 - id: ScopeId(
82 - 3,
83 - ),
84 - kind: Function,
85 - declarations: {},
86 - references: [
87 - Reference {
88 - id: ReferenceId(
89 - 0,
90 - ),
91 - kind: Read,
92 - declaration: DeclarationId(
93 - 2,
94 - ),
95 - declaration (name): "a",
96 - scope: ScopeId(
97 - 3,
98 - ),
99 - },
100 - Reference {
101 - id: ReferenceId(
102 - 1,
103 - ),
104 - kind: Read,
105 - declaration: DeclarationId(
106 - 3,
107 - ),
108 - declaration (name): "b",
109 - scope: ScopeId(
110 - 3,
111 - ),
112 - },
113 - ],
114 - children: [],
115 - },
105 ],
106 + children: [],
107 },
108 ],
109 },
compiler/forget/crates/forget_semantic_analysis/tests/snapshots/analysis_test__fixtures@simple-function.js.snap
+115 -125
@@ -20,27 +20,69 @@ Scope {
20 id: ScopeId(
21 0,
22 ),
23 - kind: Global,
24 - declarations: {},
23 + kind: Module,
24 + declarations: {
25 + "Component": Declaration {
26 + id: DeclarationId(
27 + 0,
28 + ),
29 + kind: FunctionDeclaration,
30 + scope: ScopeId(
31 + 0,
32 + ),
33 + },
34 + },
35 references: [],
36 children: [
37 Scope {
38 id: ScopeId(
39 1,
40 ),
31 - kind: Module,
41 + kind: Function,
42 declarations: {
33 - "Component": Declaration {
43 + "a": Declaration {
44 id: DeclarationId(
35 - 0,
45 + 1,
46 ),
47 kind: FunctionDeclaration,
48 scope: ScopeId(
49 1,
50 ),
51 },
52 + "b": Declaration {
53 + id: DeclarationId(
54 + 2,
55 + ),
56 + kind: Let,
57 + scope: ScopeId(
58 + 1,
59 + ),
60 + },
61 + "foo": Declaration {
62 + id: DeclarationId(
63 + 3,
64 + ),
65 + kind: Const,
66 + scope: ScopeId(
67 + 1,
68 + ),
69 + },
70 },
43 - references: [],
71 + references: [
72 + Reference {
73 + id: ReferenceId(
74 + 4,
75 + ),
76 + kind: Read,
77 + declaration: DeclarationId(
78 + 3,
79 + ),
80 + declaration (name): "foo",
81 + scope: ScopeId(
82 + 1,
83 + ),
84 + },
85 + ],
86 children: [
87 Scope {
88 id: ScopeId(
@@ -48,49 +90,17 @@ Scope {
90 ),
91 kind: Function,
92 declarations: {
51 - "a": Declaration {
93 + "foo_": Declaration {
94 id: DeclarationId(
53 - 1,
95 + 4,
96 ),
97 kind: FunctionDeclaration,
98 scope: ScopeId(
99 2,
100 ),
101 },
60 - "b": Declaration {
61 - id: DeclarationId(
62 - 2,
63 - ),
64 - kind: Let,
65 - scope: ScopeId(
66 - 2,
67 - ),
68 - },
69 - "foo": Declaration {
70 - id: DeclarationId(
71 - 3,
72 - ),
73 - kind: Const,
74 - scope: ScopeId(
75 - 2,
76 - ),
77 - },
102 },
79 - references: [
80 - Reference {
81 - id: ReferenceId(
82 - 4,
83 - ),
84 - kind: Read,
85 - declaration: DeclarationId(
86 - 3,
87 - ),
88 - declaration (name): "foo",
89 - scope: ScopeId(
90 - 2,
91 - ),
92 - },
93 - ],
103 + references: [],
104 children: [
105 Scope {
106 id: ScopeId(
@@ -98,100 +108,80 @@ Scope {
108 ),
109 kind: Function,
110 declarations: {
101 - "foo_": Declaration {
111 + "c": Declaration {
112 id: DeclarationId(
103 - 4,
113 + 5,
114 ),
115 kind: FunctionDeclaration,
116 scope: ScopeId(
117 3,
118 ),
119 },
120 + "d": Declaration {
121 + id: DeclarationId(
122 + 6,
123 + ),
124 + kind: Let,
125 + scope: ScopeId(
126 + 3,
127 + ),
128 + },
129 },
111 - references: [],
112 - children: [
113 - Scope {
114 - id: ScopeId(
115 - 4,
116 - ),
117 - kind: Function,
118 - declarations: {
119 - "c": Declaration {
120 - id: DeclarationId(
121 - 5,
122 - ),
123 - kind: FunctionDeclaration,
124 - scope: ScopeId(
125 - 4,
126 - ),
127 - },
128 - "d": Declaration {
129 - id: DeclarationId(
130 - 6,
131 - ),
132 - kind: Let,
133 - scope: ScopeId(
134 - 4,
135 - ),
136 - },
137 - },
138 - references: [
139 - Reference {
140 - id: ReferenceId(
141 - 0,
142 - ),
143 - kind: Read,
144 - declaration: DeclarationId(
145 - 1,
146 - ),
147 - declaration (name): "a",
148 - scope: ScopeId(
149 - 4,
150 - ),
151 - },
152 - Reference {
153 - id: ReferenceId(
154 - 1,
155 - ),
156 - kind: Read,
157 - declaration: DeclarationId(
158 - 2,
159 - ),
160 - declaration (name): "b",
161 - scope: ScopeId(
162 - 4,
163 - ),
164 - },
165 - Reference {
166 - id: ReferenceId(
167 - 2,
168 - ),
169 - kind: Read,
170 - declaration: DeclarationId(
171 - 5,
172 - ),
173 - declaration (name): "c",
174 - scope: ScopeId(
175 - 4,
176 - ),
177 - },
178 - Reference {
179 - id: ReferenceId(
180 - 3,
181 - ),
182 - kind: Read,
183 - declaration: DeclarationId(
184 - 6,
185 - ),
186 - declaration (name): "d",
187 - scope: ScopeId(
188 - 4,
189 - ),
190 - },
191 - ],
192 - children: [],
130 + references: [
131 + Reference {
132 + id: ReferenceId(
133 + 0,
134 + ),
135 + kind: Read,
136 + declaration: DeclarationId(
137 + 1,
138 + ),
139 + declaration (name): "a",
140 + scope: ScopeId(
141 + 3,
142 + ),
143 + },
144 + Reference {
145 + id: ReferenceId(
146 + 1,
147 + ),
148 + kind: Read,
149 + declaration: DeclarationId(
150 + 2,
151 + ),
152 + declaration (name): "b",
153 + scope: ScopeId(
154 + 3,
155 + ),
156 + },
157 + Reference {
158 + id: ReferenceId(
159 + 2,
160 + ),
161 + kind: Read,
162 + declaration: DeclarationId(
163 + 5,
164 + ),
165 + declaration (name): "c",
166 + scope: ScopeId(
167 + 3,
168 + ),
169 + },
170 + Reference {
171 + id: ReferenceId(
172 + 3,
173 + ),
174 + kind: Read,
175 + declaration: DeclarationId(
176 + 6,
177 + ),
178 + declaration (name): "d",
179 + scope: ScopeId(
180 + 3,
181 + ),
182 },
183 ],
184 + children: [],
185 },
186 ],
187 },