@samitouri / QOS-React-2 / commits / 4c0122f4cf

[rust] Small improvements plus snapshot testing for estree

Joe Savona committed Jul 6, 2023 at 09:24 UTC 4c0122f4cf5b636f0073aab50de93115d6588591
12 files changed +3856 -23
compiler/forget/Cargo.lock
+194 -9
@@ -24,6 +24,15 @@ dependencies = [
24 "version_check",
25 ]
26
27 +[[package]]
28 +name = "aho-corasick"
29 +version = "0.7.20"
30 +source = "registry+https://github.com/rust-lang/crates.io-index"
31 +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
32 +dependencies = [
33 + "memchr",
34 +]
35 +
36 [[package]]
37 name = "aho-corasick"
38 version = "1.0.2"
@@ -90,6 +99,16 @@ version = "2.3.2"
99 source = "registry+https://github.com/rust-lang/crates.io-index"
100 checksum = "6dbe3c979c178231552ecba20214a8272df4e09f232a87aef4320cf06539aded"
101
102 +[[package]]
103 +name = "bstr"
104 +version = "1.5.0"
105 +source = "registry+https://github.com/rust-lang/crates.io-index"
106 +checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5"
107 +dependencies = [
108 + "memchr",
109 + "serde",
110 +]
111 +
112 [[package]]
113 name = "bumpalo"
114 version = "3.13.0"
@@ -108,6 +127,18 @@ version = "1.0.0"
127 source = "registry+https://github.com/rust-lang/crates.io-index"
128 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
129
130 +[[package]]
131 +name = "console"
132 +version = "0.15.7"
133 +source = "registry+https://github.com/rust-lang/crates.io-index"
134 +checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8"
135 +dependencies = [
136 + "encode_unicode",
137 + "lazy_static",
138 + "libc",
139 + "windows-sys",
140 +]
141 +
142 [[package]]
143 name = "data-encoding"
144 version = "2.4.0"
@@ -129,6 +160,12 @@ dependencies = [
160 "stable_deref_trait",
161 ]
162
163 +[[package]]
164 +name = "encode_unicode"
165 +version = "0.3.6"
166 +source = "registry+https://github.com/rust-lang/crates.io-index"
167 +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
168 +
169 [[package]]
170 name = "enum-iterator"
171 version = "1.4.1"
@@ -155,8 +192,10 @@ version = "0.1.0"
192 dependencies = [
193 "bumpalo",
194 "elsa",
195 + "insta",
196 "serde",
197 "serde_json",
198 + "static_assertions",
199 ]
200
201 [[package]]
@@ -168,6 +207,12 @@ dependencies = [
207 "swc_ecma_ast",
208 ]
209
210 +[[package]]
211 +name = "fnv"
212 +version = "1.0.7"
213 +source = "registry+https://github.com/rust-lang/crates.io-index"
214 +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
215 +
216 [[package]]
217 name = "form_urlencoded"
218 version = "1.2.0"
@@ -212,6 +257,19 @@ dependencies = [
257 "syn 1.0.109",
258 ]
259
260 +[[package]]
261 +name = "globset"
262 +version = "0.4.10"
263 +source = "registry+https://github.com/rust-lang/crates.io-index"
264 +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc"
265 +dependencies = [
266 + "aho-corasick 0.7.20",
267 + "bstr",
268 + "fnv",
269 + "log",
270 + "regex",
271 +]
272 +
273 [[package]]
274 name = "hashbrown"
275 version = "0.12.3"
@@ -262,6 +320,21 @@ dependencies = [
320 "hashbrown",
321 ]
322
323 +[[package]]
324 +name = "insta"
325 +version = "1.30.0"
326 +source = "registry+https://github.com/rust-lang/crates.io-index"
327 +checksum = "28491f7753051e5704d4d0ae7860d45fae3238d7d235bc4289dcd45c48d3cec3"
328 +dependencies = [
329 + "console",
330 + "globset",
331 + "lazy_static",
332 + "linked-hash-map",
333 + "similar",
334 + "walkdir",
335 + "yaml-rust",
336 +]
337 +
338 [[package]]
339 name = "is-macro"
340 version = "0.3.0"
@@ -366,6 +439,12 @@ version = "0.2.146"
439 source = "registry+https://github.com/rust-lang/crates.io-index"
440 checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b"
441
442 +[[package]]
443 +name = "linked-hash-map"
444 +version = "0.5.6"
445 +source = "registry+https://github.com/rust-lang/crates.io-index"
446 +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
447 +
448 [[package]]
449 name = "lock_api"
450 version = "0.4.10"
@@ -376,6 +455,12 @@ dependencies = [
455 "scopeguard",
456 ]
457
458 +[[package]]
459 +name = "log"
460 +version = "0.4.19"
461 +source = "registry+https://github.com/rust-lang/crates.io-index"
462 +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
463 +
464 [[package]]
465 name = "memchr"
466 version = "2.5.0"
@@ -455,7 +540,7 @@ dependencies = [
540 "libc",
541 "redox_syscall",
542 "smallvec",
458 - "windows-targets",
543 + "windows-targets 0.48.0",
544 ]
545
546 [[package]]
@@ -639,7 +724,7 @@ version = "1.8.4"
724 source = "registry+https://github.com/rust-lang/crates.io-index"
725 checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
726 dependencies = [
642 - "aho-corasick",
727 + "aho-corasick 1.0.2",
728 "memchr",
729 "regex-syntax",
730 ]
@@ -677,6 +762,15 @@ version = "1.0.13"
762 source = "registry+https://github.com/rust-lang/crates.io-index"
763 checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
764
765 +[[package]]
766 +name = "same-file"
767 +version = "1.0.6"
768 +source = "registry+https://github.com/rust-lang/crates.io-index"
769 +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
770 +dependencies = [
771 + "winapi-util",
772 +]
773 +
774 [[package]]
775 name = "scoped-tls"
776 version = "1.0.1"
@@ -735,6 +829,12 @@ dependencies = [
829 "serde",
830 ]
831
832 +[[package]]
833 +name = "similar"
834 +version = "2.2.1"
835 +source = "registry+https://github.com/rust-lang/crates.io-index"
836 +checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf"
837 +
838 [[package]]
839 name = "siphasher"
840 version = "0.3.10"
@@ -1249,6 +1349,16 @@ version = "0.9.4"
1349 source = "registry+https://github.com/rust-lang/crates.io-index"
1350 checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
1351
1352 +[[package]]
1353 +name = "walkdir"
1354 +version = "2.3.3"
1355 +source = "registry+https://github.com/rust-lang/crates.io-index"
1356 +checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698"
1357 +dependencies = [
1358 + "same-file",
1359 + "winapi-util",
1360 +]
1361 +
1362 [[package]]
1363 name = "wasi"
1364 version = "0.11.0+wasi-snapshot-preview1"
@@ -1286,59 +1396,134 @@ version = "0.4.0"
1396 source = "registry+https://github.com/rust-lang/crates.io-index"
1397 checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
1398
1399 +[[package]]
1400 +name = "windows-sys"
1401 +version = "0.45.0"
1402 +source = "registry+https://github.com/rust-lang/crates.io-index"
1403 +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
1404 +dependencies = [
1405 + "windows-targets 0.42.2",
1406 +]
1407 +
1408 +[[package]]
1409 +name = "windows-targets"
1410 +version = "0.42.2"
1411 +source = "registry+https://github.com/rust-lang/crates.io-index"
1412 +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
1413 +dependencies = [
1414 + "windows_aarch64_gnullvm 0.42.2",
1415 + "windows_aarch64_msvc 0.42.2",
1416 + "windows_i686_gnu 0.42.2",
1417 + "windows_i686_msvc 0.42.2",
1418 + "windows_x86_64_gnu 0.42.2",
1419 + "windows_x86_64_gnullvm 0.42.2",
1420 + "windows_x86_64_msvc 0.42.2",
1421 +]
1422 +
1423 [[package]]
1424 name = "windows-targets"
1425 version = "0.48.0"
1426 source = "registry+https://github.com/rust-lang/crates.io-index"
1427 checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
1428 dependencies = [
1295 - "windows_aarch64_gnullvm",
1296 - "windows_aarch64_msvc",
1297 - "windows_i686_gnu",
1298 - "windows_i686_msvc",
1299 - "windows_x86_64_gnu",
1300 - "windows_x86_64_gnullvm",
1301 - "windows_x86_64_msvc",
1429 + "windows_aarch64_gnullvm 0.48.0",
1430 + "windows_aarch64_msvc 0.48.0",
1431 + "windows_i686_gnu 0.48.0",
1432 + "windows_i686_msvc 0.48.0",
1433 + "windows_x86_64_gnu 0.48.0",
1434 + "windows_x86_64_gnullvm 0.48.0",
1435 + "windows_x86_64_msvc 0.48.0",
1436 ]
1437
1438 +[[package]]
1439 +name = "windows_aarch64_gnullvm"
1440 +version = "0.42.2"
1441 +source = "registry+https://github.com/rust-lang/crates.io-index"
1442 +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
1443 +
1444 [[package]]
1445 name = "windows_aarch64_gnullvm"
1446 version = "0.48.0"
1447 source = "registry+https://github.com/rust-lang/crates.io-index"
1448 checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
1449
1450 +[[package]]
1451 +name = "windows_aarch64_msvc"
1452 +version = "0.42.2"
1453 +source = "registry+https://github.com/rust-lang/crates.io-index"
1454 +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
1455 +
1456 [[package]]
1457 name = "windows_aarch64_msvc"
1458 version = "0.48.0"
1459 source = "registry+https://github.com/rust-lang/crates.io-index"
1460 checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
1461
1462 +[[package]]
1463 +name = "windows_i686_gnu"
1464 +version = "0.42.2"
1465 +source = "registry+https://github.com/rust-lang/crates.io-index"
1466 +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
1467 +
1468 [[package]]
1469 name = "windows_i686_gnu"
1470 version = "0.48.0"
1471 source = "registry+https://github.com/rust-lang/crates.io-index"
1472 checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
1473
1474 +[[package]]
1475 +name = "windows_i686_msvc"
1476 +version = "0.42.2"
1477 +source = "registry+https://github.com/rust-lang/crates.io-index"
1478 +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
1479 +
1480 [[package]]
1481 name = "windows_i686_msvc"
1482 version = "0.48.0"
1483 source = "registry+https://github.com/rust-lang/crates.io-index"
1484 checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
1485
1486 +[[package]]
1487 +name = "windows_x86_64_gnu"
1488 +version = "0.42.2"
1489 +source = "registry+https://github.com/rust-lang/crates.io-index"
1490 +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
1491 +
1492 [[package]]
1493 name = "windows_x86_64_gnu"
1494 version = "0.48.0"
1495 source = "registry+https://github.com/rust-lang/crates.io-index"
1496 checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
1497
1498 +[[package]]
1499 +name = "windows_x86_64_gnullvm"
1500 +version = "0.42.2"
1501 +source = "registry+https://github.com/rust-lang/crates.io-index"
1502 +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
1503 +
1504 [[package]]
1505 name = "windows_x86_64_gnullvm"
1506 version = "0.48.0"
1507 source = "registry+https://github.com/rust-lang/crates.io-index"
1508 checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
1509
1510 +[[package]]
1511 +name = "windows_x86_64_msvc"
1512 +version = "0.42.2"
1513 +source = "registry+https://github.com/rust-lang/crates.io-index"
1514 +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
1515 +
1516 [[package]]
1517 name = "windows_x86_64_msvc"
1518 version = "0.48.0"
1519 source = "registry+https://github.com/rust-lang/crates.io-index"
1520 checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
1521 +
1522 +[[package]]
1523 +name = "yaml-rust"
1524 +version = "0.4.5"
1525 +source = "registry+https://github.com/rust-lang/crates.io-index"
1526 +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
1527 +dependencies = [
1528 + "linked-hash-map",
1529 +]
compiler/forget/crates/estree/Cargo.toml
+13
@@ -8,5 +8,18 @@ edition = "2021"
8 [dependencies]
9 bumpalo = { version = "3.13.0", features = ["boxed", "collections"] }
10 elsa = "1.8.1"
11 +insta = { version = "1.30.0", features = ["glob"] }
12 serde = { version = "1.0.164", features = ["derive"] }
13 serde_json = "1.0.99"
14 +static_assertions = "1.1.0"
15 +
16 +
17 +# Make insta run faster by compiling with release mode optimizations
18 +# https://docs.rs/insta/latest/insta/#optional-faster-runs
19 +[profile.dev.package.insta]
20 +opt-level = 3
21 +
22 +# Make insta diffing libary faster by compiling with release mode optimizations
23 +# https://docs.rs/insta/latest/insta/#optional-faster-runs
24 +[profile.dev.package.similar]
25 +opt-level = 3
\ No newline at end of file
compiler/forget/crates/estree/src/fixtures/for-statement.json new
+528
@@ -0,0 +1,528 @@
1 +{
2 + "type": "Program",
3 + "loc": {
4 + "source": null,
5 + "start": {
6 + "line": 1,
7 + "column": 0
8 + },
9 + "end": {
10 + "line": 7,
11 + "column": 1
12 + }
13 + },
14 + "body": [
15 + {
16 + "type": "FunctionDeclaration",
17 + "loc": {
18 + "source": null,
19 + "start": {
20 + "line": 1,
21 + "column": 0
22 + },
23 + "end": {
24 + "line": 7,
25 + "column": 1
26 + }
27 + },
28 + "id": {
29 + "type": "Identifier",
30 + "loc": {
31 + "source": null,
32 + "start": {
33 + "line": 1,
34 + "column": 9
35 + },
36 + "end": {
37 + "line": 1,
38 + "column": 18
39 + }
40 + },
41 + "name": "Component",
42 + "typeAnnotation": null,
43 + "optional": false,
44 + "range": [
45 + 9,
46 + 18
47 + ]
48 + },
49 + "params": [
50 + {
51 + "type": "Identifier",
52 + "loc": {
53 + "source": null,
54 + "start": {
55 + "line": 1,
56 + "column": 19
57 + },
58 + "end": {
59 + "line": 1,
60 + "column": 24
61 + }
62 + },
63 + "name": "props",
64 + "typeAnnotation": null,
65 + "optional": false,
66 + "range": [
67 + 19,
68 + 24
69 + ]
70 + }
71 + ],
72 + "body": {
73 + "type": "BlockStatement",
74 + "loc": {
75 + "source": null,
76 + "start": {
77 + "line": 1,
78 + "column": 26
79 + },
80 + "end": {
81 + "line": 7,
82 + "column": 1
83 + }
84 + },
85 + "body": [
86 + {
87 + "type": "VariableDeclaration",
88 + "loc": {
89 + "source": null,
90 + "start": {
91 + "line": 2,
92 + "column": 2
93 + },
94 + "end": {
95 + "line": 2,
96 + "column": 12
97 + }
98 + },
99 + "kind": "let",
100 + "declarations": [
101 + {
102 + "type": "VariableDeclarator",
103 + "loc": {
104 + "source": null,
105 + "start": {
106 + "line": 2,
107 + "column": 6
108 + },
109 + "end": {
110 + "line": 2,
111 + "column": 11
112 + }
113 + },
114 + "init": {
115 + "type": "Literal",
116 + "loc": {
117 + "source": null,
118 + "start": {
119 + "line": 2,
120 + "column": 10
121 + },
122 + "end": {
123 + "line": 2,
124 + "column": 11
125 + }
126 + },
127 + "value": 0,
128 + "range": [
129 + 38,
130 + 39
131 + ],
132 + "raw": "0"
133 + },
134 + "id": {
135 + "type": "Identifier",
136 + "loc": {
137 + "source": null,
138 + "start": {
139 + "line": 2,
140 + "column": 6
141 + },
142 + "end": {
143 + "line": 2,
144 + "column": 7
145 + }
146 + },
147 + "name": "x",
148 + "typeAnnotation": null,
149 + "optional": false,
150 + "range": [
151 + 34,
152 + 35
153 + ]
154 + },
155 + "range": [
156 + 34,
157 + 39
158 + ]
159 + }
160 + ],
161 + "range": [
162 + 30,
163 + 40
164 + ]
165 + },
166 + {
167 + "type": "ForStatement",
168 + "loc": {
169 + "source": null,
170 + "start": {
171 + "line": 3,
172 + "column": 2
173 + },
174 + "end": {
175 + "line": 5,
176 + "column": 3
177 + }
178 + },
179 + "init": {
180 + "type": "VariableDeclaration",
181 + "loc": {
182 + "source": null,
183 + "start": {
184 + "line": 3,
185 + "column": 7
186 + },
187 + "end": {
188 + "line": 3,
189 + "column": 16
190 + }
191 + },
192 + "kind": "let",
193 + "declarations": [
194 + {
195 + "type": "VariableDeclarator",
196 + "loc": {
197 + "source": null,
198 + "start": {
199 + "line": 3,
200 + "column": 11
201 + },
202 + "end": {
203 + "line": 3,
204 + "column": 16
205 + }
206 + },
207 + "init": {
208 + "type": "Literal",
209 + "loc": {
210 + "source": null,
211 + "start": {
212 + "line": 3,
213 + "column": 15
214 + },
215 + "end": {
216 + "line": 3,
217 + "column": 16
218 + }
219 + },
220 + "value": 0,
221 + "range": [
222 + 56,
223 + 57
224 + ],
225 + "raw": "0"
226 + },
227 + "id": {
228 + "type": "Identifier",
229 + "loc": {
230 + "source": null,
231 + "start": {
232 + "line": 3,
233 + "column": 11
234 + },
235 + "end": {
236 + "line": 3,
237 + "column": 12
238 + }
239 + },
240 + "name": "i",
241 + "typeAnnotation": null,
242 + "optional": false,
243 + "range": [
244 + 52,
245 + 53
246 + ]
247 + },
248 + "range": [
249 + 52,
250 + 57
251 + ]
252 + }
253 + ],
254 + "range": [
255 + 48,
256 + 57
257 + ]
258 + },
259 + "test": {
260 + "type": "BinaryExpression",
261 + "loc": {
262 + "source": null,
263 + "start": {
264 + "line": 3,
265 + "column": 18
266 + },
267 + "end": {
268 + "line": 3,
269 + "column": 24
270 + }
271 + },
272 + "left": {
273 + "type": "Identifier",
274 + "loc": {
275 + "source": null,
276 + "start": {
277 + "line": 3,
278 + "column": 18
279 + },
280 + "end": {
281 + "line": 3,
282 + "column": 19
283 + }
284 + },
285 + "name": "i",
286 + "typeAnnotation": null,
287 + "optional": false,
288 + "range": [
289 + 59,
290 + 60
291 + ]
292 + },
293 + "right": {
294 + "type": "Literal",
295 + "loc": {
296 + "source": null,
297 + "start": {
298 + "line": 3,
299 + "column": 22
300 + },
301 + "end": {
302 + "line": 3,
303 + "column": 24
304 + }
305 + },
306 + "value": 10,
307 + "range": [
308 + 63,
309 + 65
310 + ],
311 + "raw": "10"
312 + },
313 + "operator": "<",
314 + "range": [
315 + 59,
316 + 65
317 + ]
318 + },
319 + "update": {
320 + "type": "UpdateExpression",
321 + "loc": {
322 + "source": null,
323 + "start": {
324 + "line": 3,
325 + "column": 26
326 + },
327 + "end": {
328 + "line": 3,
329 + "column": 29
330 + }
331 + },
332 + "operator": "++",
333 + "argument": {
334 + "type": "Identifier",
335 + "loc": {
336 + "source": null,
337 + "start": {
338 + "line": 3,
339 + "column": 26
340 + },
341 + "end": {
342 + "line": 3,
343 + "column": 27
344 + }
345 + },
346 + "name": "i",
347 + "typeAnnotation": null,
348 + "optional": false,
349 + "range": [
350 + 67,
351 + 68
352 + ]
353 + },
354 + "prefix": false,
355 + "range": [
356 + 67,
357 + 70
358 + ]
359 + },
360 + "body": {
361 + "type": "BlockStatement",
362 + "loc": {
363 + "source": null,
364 + "start": {
365 + "line": 3,
366 + "column": 31
367 + },
368 + "end": {
369 + "line": 5,
370 + "column": 3
371 + }
372 + },
373 + "body": [
374 + {
375 + "type": "ExpressionStatement",
376 + "loc": {
377 + "source": null,
378 + "start": {
379 + "line": 4,
380 + "column": 4
381 + },
382 + "end": {
383 + "line": 4,
384 + "column": 11
385 + }
386 + },
387 + "expression": {
388 + "type": "AssignmentExpression",
389 + "loc": {
390 + "source": null,
391 + "start": {
392 + "line": 4,
393 + "column": 4
394 + },
395 + "end": {
396 + "line": 4,
397 + "column": 10
398 + }
399 + },
400 + "operator": "+=",
401 + "left": {
402 + "type": "Identifier",
403 + "loc": {
404 + "source": null,
405 + "start": {
406 + "line": 4,
407 + "column": 4
408 + },
409 + "end": {
410 + "line": 4,
411 + "column": 5
412 + }
413 + },
414 + "name": "x",
415 + "typeAnnotation": null,
416 + "optional": false,
417 + "range": [
418 + 78,
419 + 79
420 + ]
421 + },
422 + "right": {
423 + "type": "Identifier",
424 + "loc": {
425 + "source": null,
426 + "start": {
427 + "line": 4,
428 + "column": 9
429 + },
430 + "end": {
431 + "line": 4,
432 + "column": 10
433 + }
434 + },
435 + "name": "i",
436 + "typeAnnotation": null,
437 + "optional": false,
438 + "range": [
439 + 83,
440 + 84
441 + ]
442 + },
443 + "range": [
444 + 78,
445 + 84
446 + ]
447 + },
448 + "directive": null,
449 + "range": [
450 + 78,
451 + 85
452 + ]
453 + }
454 + ],
455 + "range": [
456 + 72,
457 + 89
458 + ]
459 + },
460 + "range": [
461 + 43,
462 + 89
463 + ]
464 + },
465 + {
466 + "type": "ReturnStatement",
467 + "loc": {
468 + "source": null,
469 + "start": {
470 + "line": 6,
471 + "column": 2
472 + },
473 + "end": {
474 + "line": 6,
475 + "column": 11
476 + }
477 + },
478 + "argument": {
479 + "type": "Identifier",
480 + "loc": {
481 + "source": null,
482 + "start": {
483 + "line": 6,
484 + "column": 9
485 + },
486 + "end": {
487 + "line": 6,
488 + "column": 10
489 + }
490 + },
491 + "name": "x",
492 + "typeAnnotation": null,
493 + "optional": false,
494 + "range": [
495 + 99,
496 + 100
497 + ]
498 + },
499 + "range": [
500 + 92,
501 + 101
502 + ]
503 + }
504 + ],
505 + "range": [
506 + 26,
507 + 103
508 + ]
509 + },
510 + "typeParameters": null,
511 + "returnType": null,
512 + "predicate": null,
513 + "generator": false,
514 + "async": false,
515 + "range": [
516 + 0,
517 + 103
518 + ]
519 + }
520 + ],
521 + "comments": [],
522 + "interpreter": null,
523 + "range": [
524 + 0,
525 + 103
526 + ],
527 + "sourceType": "script"
528 + }
\ No newline at end of file
compiler/forget/crates/estree/src/fixtures/import.json new
+104
@@ -0,0 +1,104 @@
1 +{
2 + "type": "Program",
3 + "loc": {
4 + "source": null,
5 + "start": {
6 + "line": 1,
7 + "column": 0
8 + },
9 + "end": {
10 + "line": 1,
11 + "column": 26
12 + }
13 + },
14 + "body": [
15 + {
16 + "type": "ImportDeclaration",
17 + "loc": {
18 + "source": null,
19 + "start": {
20 + "line": 1,
21 + "column": 0
22 + },
23 + "end": {
24 + "line": 1,
25 + "column": 26
26 + }
27 + },
28 + "specifiers": [
29 + {
30 + "type": "ImportDefaultSpecifier",
31 + "loc": {
32 + "source": null,
33 + "start": {
34 + "line": 1,
35 + "column": 7
36 + },
37 + "end": {
38 + "line": 1,
39 + "column": 12
40 + }
41 + },
42 + "local": {
43 + "type": "Identifier",
44 + "loc": {
45 + "source": null,
46 + "start": {
47 + "line": 1,
48 + "column": 7
49 + },
50 + "end": {
51 + "line": 1,
52 + "column": 12
53 + }
54 + },
55 + "name": "React",
56 + "typeAnnotation": null,
57 + "optional": false,
58 + "range": [
59 + 7,
60 + 12
61 + ]
62 + },
63 + "range": [
64 + 7,
65 + 12
66 + ]
67 + }
68 + ],
69 + "source": {
70 + "type": "Literal",
71 + "loc": {
72 + "source": null,
73 + "start": {
74 + "line": 1,
75 + "column": 18
76 + },
77 + "end": {
78 + "line": 1,
79 + "column": 25
80 + }
81 + },
82 + "value": "react",
83 + "range": [
84 + 18,
85 + 25
86 + ],
87 + "raw": "'react'"
88 + },
89 + "attributes": [],
90 + "importKind": "value",
91 + "range": [
92 + 0,
93 + 26
94 + ]
95 + }
96 + ],
97 + "comments": [],
98 + "interpreter": null,
99 + "range": [
100 + 0,
101 + 26
102 + ],
103 + "sourceType": "module"
104 + }
\ No newline at end of file
compiler/forget/crates/estree/src/fixtures/simple.json new
+189
@@ -0,0 +1,189 @@
1 +{
2 + "type": "Program",
3 + "loc": {
4 + "source": null,
5 + "start": {
6 + "line": 1,
7 + "column": 0
8 + },
9 + "end": {
10 + "line": 3,
11 + "column": 1
12 + }
13 + },
14 + "range": [
15 + 0,
16 + 51
17 + ],
18 + "body": [
19 + {
20 + "type": "FunctionDeclaration",
21 + "loc": {
22 + "source": null,
23 + "start": {
24 + "line": 1,
25 + "column": 0
26 + },
27 + "end": {
28 + "line": 3,
29 + "column": 1
30 + }
31 + },
32 + "range": [
33 + 0,
34 + 51
35 + ],
36 + "id": {
37 + "type": "Identifier",
38 + "loc": {
39 + "source": null,
40 + "start": {
41 + "line": 1,
42 + "column": 9
43 + },
44 + "end": {
45 + "line": 1,
46 + "column": 18
47 + }
48 + },
49 + "range": [
50 + 9,
51 + 18
52 + ],
53 + "name": "Component",
54 + "typeAnnotation": null,
55 + "optional": false
56 + },
57 + "params": [
58 + {
59 + "type": "Identifier",
60 + "loc": {
61 + "source": null,
62 + "start": {
63 + "line": 1,
64 + "column": 19
65 + },
66 + "end": {
67 + "line": 1,
68 + "column": 24
69 + }
70 + },
71 + "range": [
72 + 19,
73 + 24
74 + ],
75 + "name": "props",
76 + "typeAnnotation": null,
77 + "optional": false
78 + }
79 + ],
80 + "body": {
81 + "type": "BlockStatement",
82 + "loc": {
83 + "source": null,
84 + "start": {
85 + "line": 1,
86 + "column": 26
87 + },
88 + "end": {
89 + "line": 3,
90 + "column": 1
91 + }
92 + },
93 + "range": [
94 + 26,
95 + 51
96 + ],
97 + "body": [
98 + {
99 + "type": "ReturnStatement",
100 + "loc": {
101 + "source": null,
102 + "start": {
103 + "line": 2,
104 + "column": 2
105 + },
106 + "end": {
107 + "line": 2,
108 + "column": 21
109 + }
110 + },
111 + "range": [
112 + 30,
113 + 49
114 + ],
115 + "argument": {
116 + "type": "MemberExpression",
117 + "loc": {
118 + "source": null,
119 + "start": {
120 + "line": 2,
121 + "column": 9
122 + },
123 + "end": {
124 + "line": 2,
125 + "column": 20
126 + }
127 + },
128 + "range": [
129 + 37,
130 + 48
131 + ],
132 + "object": {
133 + "type": "Identifier",
134 + "loc": {
135 + "source": null,
136 + "start": {
137 + "line": 2,
138 + "column": 9
139 + },
140 + "end": {
141 + "line": 2,
142 + "column": 14
143 + }
144 + },
145 + "range": [
146 + 37,
147 + 42
148 + ],
149 + "name": "props",
150 + "typeAnnotation": null,
151 + "optional": false
152 + },
153 + "property": {
154 + "type": "Identifier",
155 + "loc": {
156 + "source": null,
157 + "start": {
158 + "line": 2,
159 + "column": 15
160 + },
161 + "end": {
162 + "line": 2,
163 + "column": 20
164 + }
165 + },
166 + "range": [
167 + 43,
168 + 48
169 + ],
170 + "name": "value",
171 + "typeAnnotation": null,
172 + "optional": false
173 + },
174 + "computed": false
175 + }
176 + }
177 + ]
178 + },
179 + "async": false,
180 + "generator": false,
181 + "predicate": null,
182 + "expression": false,
183 + "returnType": null,
184 + "typeParameters": null
185 + }
186 + ],
187 + "comments": [],
188 + "errors": []
189 + }
\ No newline at end of file
compiler/forget/crates/estree/src/fixtures/test.json new
+351
@@ -0,0 +1,351 @@
1 +{
2 + "type": "Program",
3 + "loc": {
4 + "source": null,
5 + "start": {
6 + "line": 2,
7 + "column": 0
8 + },
9 + "end": {
10 + "line": 4,
11 + "column": 1
12 + }
13 + },
14 + "body": [
15 + {
16 + "type": "FunctionDeclaration",
17 + "loc": {
18 + "source": null,
19 + "start": {
20 + "line": 2,
21 + "column": 0
22 + },
23 + "end": {
24 + "line": 4,
25 + "column": 1
26 + }
27 + },
28 + "id": {
29 + "type": "Identifier",
30 + "loc": {
31 + "source": null,
32 + "start": {
33 + "line": 2,
34 + "column": 9
35 + },
36 + "end": {
37 + "line": 2,
38 + "column": 12
39 + }
40 + },
41 + "name": "foo",
42 + "typeAnnotation": null,
43 + "optional": false,
44 + "range": [
45 + 10,
46 + 13
47 + ]
48 + },
49 + "params": [],
50 + "body": {
51 + "type": "BlockStatement",
52 + "loc": {
53 + "source": null,
54 + "start": {
55 + "line": 2,
56 + "column": 15
57 + },
58 + "end": {
59 + "line": 4,
60 + "column": 1
61 + }
62 + },
63 + "body": [
64 + {
65 + "type": "ReturnStatement",
66 + "loc": {
67 + "source": null,
68 + "start": {
69 + "line": 3,
70 + "column": 2
71 + },
72 + "end": {
73 + "line": 3,
74 + "column": 36
75 + }
76 + },
77 + "argument": {
78 + "type": "JSXElement",
79 + "loc": {
80 + "source": null,
81 + "start": {
82 + "line": 3,
83 + "column": 9
84 + },
85 + "end": {
86 + "line": 3,
87 + "column": 36
88 + }
89 + },
90 + "openingElement": {
91 + "type": "JSXOpeningElement",
92 + "loc": {
93 + "source": null,
94 + "start": {
95 + "line": 3,
96 + "column": 9
97 + },
98 + "end": {
99 + "line": 3,
100 + "column": 26
101 + }
102 + },
103 + "name": {
104 + "type": "JSXMemberExpression",
105 + "loc": {
106 + "source": null,
107 + "start": {
108 + "line": 3,
109 + "column": 10
110 + },
111 + "end": {
112 + "line": 3,
113 + "column": 17
114 + }
115 + },
116 + "object": {
117 + "type": "JSXIdentifier",
118 + "loc": {
119 + "source": null,
120 + "start": {
121 + "line": 3,
122 + "column": 10
123 + },
124 + "end": {
125 + "line": 3,
126 + "column": 13
127 + }
128 + },
129 + "name": "Foo",
130 + "range": [
131 + 28,
132 + 31
133 + ]
134 + },
135 + "property": {
136 + "type": "JSXIdentifier",
137 + "loc": {
138 + "source": null,
139 + "start": {
140 + "line": 3,
141 + "column": 14
142 + },
143 + "end": {
144 + "line": 3,
145 + "column": 17
146 + }
147 + },
148 + "name": "Bar",
149 + "range": [
150 + 32,
151 + 35
152 + ]
153 + },
154 + "range": [
155 + 28,
156 + 35
157 + ]
158 + },
159 + "attributes": [
160 + {
161 + "type": "JSXAttribute",
162 + "loc": {
163 + "source": null,
164 + "start": {
165 + "line": 3,
166 + "column": 18
167 + },
168 + "end": {
169 + "line": 3,
170 + "column": 24
171 + }
172 + },
173 + "name": {
174 + "type": "JSXIdentifier",
175 + "loc": {
176 + "source": null,
177 + "start": {
178 + "line": 3,
179 + "column": 18
180 + },
181 + "end": {
182 + "line": 3,
183 + "column": 19
184 + }
185 + },
186 + "name": "a",
187 + "range": [
188 + 36,
189 + 37
190 + ]
191 + },
192 + "value": {
193 + "type": "JSXExpressionContainer",
194 + "loc": {
195 + "source": null,
196 + "start": {
197 + "line": 3,
198 + "column": 20
199 + },
200 + "end": {
201 + "line": 3,
202 + "column": 24
203 + }
204 + },
205 + "expression": {
206 + "type": "Literal",
207 + "loc": {
208 + "source": null,
209 + "start": {
210 + "line": 3,
211 + "column": 21
212 + },
213 + "end": {
214 + "line": 3,
215 + "column": 23
216 + }
217 + },
218 + "value": 10,
219 + "range": [
220 + 39,
221 + 41
222 + ],
223 + "raw": "10"
224 + },
225 + "range": [
226 + 38,
227 + 42
228 + ]
229 + },
230 + "range": [
231 + 36,
232 + 42
233 + ]
234 + }
235 + ],
236 + "selfClosing": false,
237 + "range": [
238 + 27,
239 + 44
240 + ]
241 + },
242 + "children": [],
243 + "closingElement": {
244 + "type": "JSXClosingElement",
245 + "loc": {
246 + "source": null,
247 + "start": {
248 + "line": 3,
249 + "column": 26
250 + },
251 + "end": {
252 + "line": 3,
253 + "column": 36
254 + }
255 + },
256 + "name": {
257 + "type": "JSXMemberExpression",
258 + "loc": {
259 + "source": null,
260 + "start": {
261 + "line": 3,
262 + "column": 28
263 + },
264 + "end": {
265 + "line": 3,
266 + "column": 35
267 + }
268 + },
269 + "object": {
270 + "type": "JSXIdentifier",
271 + "loc": {
272 + "source": null,
273 + "start": {
274 + "line": 3,
275 + "column": 28
276 + },
277 + "end": {
278 + "line": 3,
279 + "column": 31
280 + }
281 + },
282 + "name": "Foo",
283 + "range": [
284 + 46,
285 + 49
286 + ]
287 + },
288 + "property": {
289 + "type": "JSXIdentifier",
290 + "loc": {
291 + "source": null,
292 + "start": {
293 + "line": 3,
294 + "column": 32
295 + },
296 + "end": {
297 + "line": 3,
298 + "column": 35
299 + }
300 + },
301 + "name": "Bar",
302 + "range": [
303 + 50,
304 + 53
305 + ]
306 + },
307 + "range": [
308 + 46,
309 + 53
310 + ]
311 + },
312 + "range": [
313 + 44,
314 + 54
315 + ]
316 + },
317 + "range": [
318 + 27,
319 + 54
320 + ]
321 + },
322 + "range": [
323 + 20,
324 + 54
325 + ]
326 + }
327 + ],
328 + "range": [
329 + 16,
330 + 56
331 + ]
332 + },
333 + "typeParameters": null,
334 + "returnType": null,
335 + "predicate": null,
336 + "generator": false,
337 + "async": false,
338 + "range": [
339 + 1,
340 + 56
341 + ]
342 + }
343 + ],
344 + "comments": [],
345 + "interpreter": null,
346 + "range": [
347 + 1,
348 + 56
349 + ],
350 + "sourceType": "script"
351 + }
\ No newline at end of file
compiler/forget/crates/estree/src/import.json new
+104
@@ -0,0 +1,104 @@
1 +{
2 + "type": "Program",
3 + "loc": {
4 + "source": null,
5 + "start": {
6 + "line": 1,
7 + "column": 0
8 + },
9 + "end": {
10 + "line": 1,
11 + "column": 26
12 + }
13 + },
14 + "body": [
15 + {
16 + "type": "ImportDeclaration",
17 + "loc": {
18 + "source": null,
19 + "start": {
20 + "line": 1,
21 + "column": 0
22 + },
23 + "end": {
24 + "line": 1,
25 + "column": 26
26 + }
27 + },
28 + "specifiers": [
29 + {
30 + "type": "ImportDefaultSpecifier",
31 + "loc": {
32 + "source": null,
33 + "start": {
34 + "line": 1,
35 + "column": 7
36 + },
37 + "end": {
38 + "line": 1,
39 + "column": 12
40 + }
41 + },
42 + "local": {
43 + "type": "Identifier",
44 + "loc": {
45 + "source": null,
46 + "start": {
47 + "line": 1,
48 + "column": 7
49 + },
50 + "end": {
51 + "line": 1,
52 + "column": 12
53 + }
54 + },
55 + "name": "React",
56 + "typeAnnotation": null,
57 + "optional": false,
58 + "range": [
59 + 7,
60 + 12
61 + ]
62 + },
63 + "range": [
64 + 7,
65 + 12
66 + ]
67 + }
68 + ],
69 + "source": {
70 + "type": "Literal",
71 + "loc": {
72 + "source": null,
73 + "start": {
74 + "line": 1,
75 + "column": 18
76 + },
77 + "end": {
78 + "line": 1,
79 + "column": 25
80 + }
81 + },
82 + "value": "react",
83 + "range": [
84 + 18,
85 + 25
86 + ],
87 + "raw": "'react'"
88 + },
89 + "attributes": [],
90 + "importKind": "value",
91 + "range": [
92 + 0,
93 + 26
94 + ]
95 + }
96 + ],
97 + "comments": [],
98 + "interpreter": null,
99 + "range": [
100 + 0,
101 + 26
102 + ],
103 + "sourceType": "module"
104 + }
\ No newline at end of file
compiler/forget/crates/estree/src/lib.rs
+54 -14
@@ -1,5 +1,6 @@
1 use serde::{Deserialize, Serialize};
2 -use std::num::{NonZeroU32, NonZeroUsize};
2 +use static_assertions::assert_eq_size;
3 +use std::num::NonZeroU32;
4
5 #[derive(Serialize, Deserialize, Debug)]
6 pub struct SourceLocation {
@@ -13,20 +14,25 @@ pub struct SourceLocation {
14 #[derive(Serialize, Deserialize, Debug)]
15 pub struct Position {
16 /// >= 1
16 - pub line: NonZeroUsize,
17 + pub line: NonZeroU32,
18 /// >= 0
19 pub column: u32,
20 }
21 +assert_eq_size!(Option<Position>, u64);
22
23 #[derive(Serialize, Deserialize, Debug)]
24 pub struct SourceRange {
25 pub start: u32,
26 + // end is exclusive so it can always be non-zero. This allows
27 + // Option<SourceRange> to not take any additional bytes.
28 pub end: NonZeroU32,
29 }
30 +assert_eq_size!(Option<SourceRange>, u64);
31
32 #[derive(Serialize, Deserialize, Debug)]
33 pub struct Program {
34 /// sourceType
35 + #[serde(rename = "sourceType")]
36 #[serde(default)]
37 pub source_type: SourceType,
38
@@ -36,6 +42,7 @@ pub struct Program {
42 pub comments: Option<Vec<Comment>>,
43
44 pub loc: Option<SourceLocation>,
45 +
46 #[serde(default)]
47 pub range: Option<SourceRange>,
48 }
@@ -73,26 +80,20 @@ pub enum CommentType {
80 #[derive(Serialize, Deserialize, Debug)]
81 #[serde(untagged)]
82 pub enum ModuleItem {
76 - Directive(Box<Directive>),
83 Statement(Box<Statement>),
84 ImportDeclaration(Box<ImportDeclaration>),
85 +}
86 +
87 +#[derive(Serialize, Deserialize, Debug)]
88 +#[serde(tag = "type")]
89 +pub enum ImportExportDeclaration {
90 + ImportDeclaration(Box<ImportDeclaration>),
91 // TODO:
92 // ExportNamedDeclaration(Box<ExportNamedDeclaration>),
93 // ExportDefaultDeclaration(Box<ExportDefaultDeclaration>),
94 // ExportAllDeclaration(Box<ExportAllDeclaration>),
95 }
96
85 -#[derive(Serialize, Deserialize, Debug)]
86 -pub struct Directive {
87 - /// type = "ExpressionStatement"
88 - pub type_: String,
89 - pub expression: Literal,
90 - pub directive: String,
91 - pub loc: Option<SourceLocation>,
92 - #[serde(default)]
93 - pub range: Option<SourceRange>,
94 -}
95 -
97 #[derive(Serialize, Deserialize, Debug)]
98 pub struct ImportDeclaration {
99 pub specifiers: Vec<ImportSpecifiers>,
@@ -106,12 +107,27 @@ pub struct ImportDeclaration {
107 #[serde(tag = "type")]
108 pub enum ImportSpecifiers {
109 ImportSpecifier(Box<ImportSpecifier>),
110 + ImportDefaultSpecifier(Box<ImportDefaultSpecifier>),
111 }
112
113 #[derive(Serialize, Deserialize, Debug)]
114 pub struct ImportSpecifier {
115 pub imported: Identifier,
116 +
117 + pub local: Identifier,
118 +
119 pub loc: Option<SourceLocation>,
120 +
121 + #[serde(default)]
122 + pub range: Option<SourceRange>,
123 +}
124 +
125 +#[derive(Serialize, Deserialize, Debug)]
126 +pub struct ImportDefaultSpecifier {
127 + pub local: Identifier,
128 +
129 + pub loc: Option<SourceLocation>,
130 +
131 #[serde(default)]
132 pub range: Option<SourceRange>,
133 }
@@ -142,6 +158,8 @@ pub enum Statement {
158 WhileStatement(Box<WhileStatement>),
159 WithStatement(Box<WithStatement>),
160 }
161 +// Prevent unboxed variants from increasing the size
162 +assert_eq_size!(Statement, u128);
163
164 #[derive(Serialize, Deserialize, Debug)]
165 pub struct BlockStatement {
@@ -467,6 +485,8 @@ pub enum ExpressionLike {
485 JSXOpeningElement(Box<JSXOpeningElement>),
486 JSXText(Box<JSXText>),
487 }
488 +// Prevent unboxed variants from increasing the size
489 +assert_eq_size!(ExpressionLike, u128);
490
491 #[derive(Serialize, Deserialize, Debug)]
492 pub struct ArrayExpression {
@@ -1223,6 +1243,7 @@ pub struct JSXText {
1243 #[cfg(test)]
1244 mod tests {
1245 use super::*;
1246 + use insta::{assert_snapshot, glob};
1247 use serde_json;
1248
1249 #[test]
@@ -1255,6 +1276,15 @@ mod tests {
1276 println!("serialized:\n{}", serialized);
1277 }
1278
1279 + #[test]
1280 + fn import() {
1281 + let source = include_str!("import.json");
1282 + let ast: Program = serde_json::from_str(&source).unwrap();
1283 + println!("deserialized:\n{:#?}", ast);
1284 + let serialized = serde_json::to_string_pretty(&ast).unwrap();
1285 + println!("serialized:\n{}", serialized);
1286 + }
1287 +
1288 #[test]
1289 fn test() {
1290 let source = include_str!("test.json");
@@ -1263,4 +1293,14 @@ mod tests {
1293 let serialized = serde_json::to_string_pretty(&ast).unwrap();
1294 println!("serialized:\n{}", serialized);
1295 }
1296 +
1297 + #[test]
1298 + fn fixtures() {
1299 + glob!("fixtures/**.json", |path| {
1300 + let input = std::fs::read_to_string(path).unwrap();
1301 + let ast: Program = serde_json::from_str(&input).unwrap();
1302 + let serialized = serde_json::to_string_pretty(&ast).unwrap();
1303 + assert_snapshot!(format!("Input:\n{input}\n\nOutput:\n{serialized}"));
1304 + });
1305 + }
1306 }
compiler/forget/crates/estree/src/snapshots/estree__tests__fixtures@for-statement.json.snap new
+1038
@@ -0,0 +1,1038 @@
1 +---
2 +source: crates/estree/src/lib.rs
3 +expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{serialized}\")"
4 +input_file: crates/estree/src/fixtures/for-statement.json
5 +---
6 +Input:
7 +{
8 + "type": "Program",
9 + "loc": {
10 + "source": null,
11 + "start": {
12 + "line": 1,
13 + "column": 0
14 + },
15 + "end": {
16 + "line": 7,
17 + "column": 1
18 + }
19 + },
20 + "body": [
21 + {
22 + "type": "FunctionDeclaration",
23 + "loc": {
24 + "source": null,
25 + "start": {
26 + "line": 1,
27 + "column": 0
28 + },
29 + "end": {
30 + "line": 7,
31 + "column": 1
32 + }
33 + },
34 + "id": {
35 + "type": "Identifier",
36 + "loc": {
37 + "source": null,
38 + "start": {
39 + "line": 1,
40 + "column": 9
41 + },
42 + "end": {
43 + "line": 1,
44 + "column": 18
45 + }
46 + },
47 + "name": "Component",
48 + "typeAnnotation": null,
49 + "optional": false,
50 + "range": [
51 + 9,
52 + 18
53 + ]
54 + },
55 + "params": [
56 + {
57 + "type": "Identifier",
58 + "loc": {
59 + "source": null,
60 + "start": {
61 + "line": 1,
62 + "column": 19
63 + },
64 + "end": {
65 + "line": 1,
66 + "column": 24
67 + }
68 + },
69 + "name": "props",
70 + "typeAnnotation": null,
71 + "optional": false,
72 + "range": [
73 + 19,
74 + 24
75 + ]
76 + }
77 + ],
78 + "body": {
79 + "type": "BlockStatement",
80 + "loc": {
81 + "source": null,
82 + "start": {
83 + "line": 1,
84 + "column": 26
85 + },
86 + "end": {
87 + "line": 7,
88 + "column": 1
89 + }
90 + },
91 + "body": [
92 + {
93 + "type": "VariableDeclaration",
94 + "loc": {
95 + "source": null,
96 + "start": {
97 + "line": 2,
98 + "column": 2
99 + },
100 + "end": {
101 + "line": 2,
102 + "column": 12
103 + }
104 + },
105 + "kind": "let",
106 + "declarations": [
107 + {
108 + "type": "VariableDeclarator",
109 + "loc": {
110 + "source": null,
111 + "start": {
112 + "line": 2,
113 + "column": 6
114 + },
115 + "end": {
116 + "line": 2,
117 + "column": 11
118 + }
119 + },
120 + "init": {
121 + "type": "Literal",
122 + "loc": {
123 + "source": null,
124 + "start": {
125 + "line": 2,
126 + "column": 10
127 + },
128 + "end": {
129 + "line": 2,
130 + "column": 11
131 + }
132 + },
133 + "value": 0,
134 + "range": [
135 + 38,
136 + 39
137 + ],
138 + "raw": "0"
139 + },
140 + "id": {
141 + "type": "Identifier",
142 + "loc": {
143 + "source": null,
144 + "start": {
145 + "line": 2,
146 + "column": 6
147 + },
148 + "end": {
149 + "line": 2,
150 + "column": 7
151 + }
152 + },
153 + "name": "x",
154 + "typeAnnotation": null,
155 + "optional": false,
156 + "range": [
157 + 34,
158 + 35
159 + ]
160 + },
161 + "range": [
162 + 34,
163 + 39
164 + ]
165 + }
166 + ],
167 + "range": [
168 + 30,
169 + 40
170 + ]
171 + },
172 + {
173 + "type": "ForStatement",
174 + "loc": {
175 + "source": null,
176 + "start": {
177 + "line": 3,
178 + "column": 2
179 + },
180 + "end": {
181 + "line": 5,
182 + "column": 3
183 + }
184 + },
185 + "init": {
186 + "type": "VariableDeclaration",
187 + "loc": {
188 + "source": null,
189 + "start": {
190 + "line": 3,
191 + "column": 7
192 + },
193 + "end": {
194 + "line": 3,
195 + "column": 16
196 + }
197 + },
198 + "kind": "let",
199 + "declarations": [
200 + {
201 + "type": "VariableDeclarator",
202 + "loc": {
203 + "source": null,
204 + "start": {
205 + "line": 3,
206 + "column": 11
207 + },
208 + "end": {
209 + "line": 3,
210 + "column": 16
211 + }
212 + },
213 + "init": {
214 + "type": "Literal",
215 + "loc": {
216 + "source": null,
217 + "start": {
218 + "line": 3,
219 + "column": 15
220 + },
221 + "end": {
222 + "line": 3,
223 + "column": 16
224 + }
225 + },
226 + "value": 0,
227 + "range": [
228 + 56,
229 + 57
230 + ],
231 + "raw": "0"
232 + },
233 + "id": {
234 + "type": "Identifier",
235 + "loc": {
236 + "source": null,
237 + "start": {
238 + "line": 3,
239 + "column": 11
240 + },
241 + "end": {
242 + "line": 3,
243 + "column": 12
244 + }
245 + },
246 + "name": "i",
247 + "typeAnnotation": null,
248 + "optional": false,
249 + "range": [
250 + 52,
251 + 53
252 + ]
253 + },
254 + "range": [
255 + 52,
256 + 57
257 + ]
258 + }
259 + ],
260 + "range": [
261 + 48,
262 + 57
263 + ]
264 + },
265 + "test": {
266 + "type": "BinaryExpression",
267 + "loc": {
268 + "source": null,
269 + "start": {
270 + "line": 3,
271 + "column": 18
272 + },
273 + "end": {
274 + "line": 3,
275 + "column": 24
276 + }
277 + },
278 + "left": {
279 + "type": "Identifier",
280 + "loc": {
281 + "source": null,
282 + "start": {
283 + "line": 3,
284 + "column": 18
285 + },
286 + "end": {
287 + "line": 3,
288 + "column": 19
289 + }
290 + },
291 + "name": "i",
292 + "typeAnnotation": null,
293 + "optional": false,
294 + "range": [
295 + 59,
296 + 60
297 + ]
298 + },
299 + "right": {
300 + "type": "Literal",
301 + "loc": {
302 + "source": null,
303 + "start": {
304 + "line": 3,
305 + "column": 22
306 + },
307 + "end": {
308 + "line": 3,
309 + "column": 24
310 + }
311 + },
312 + "value": 10,
313 + "range": [
314 + 63,
315 + 65
316 + ],
317 + "raw": "10"
318 + },
319 + "operator": "<",
320 + "range": [
321 + 59,
322 + 65
323 + ]
324 + },
325 + "update": {
326 + "type": "UpdateExpression",
327 + "loc": {
328 + "source": null,
329 + "start": {
330 + "line": 3,
331 + "column": 26
332 + },
333 + "end": {
334 + "line": 3,
335 + "column": 29
336 + }
337 + },
338 + "operator": "++",
339 + "argument": {
340 + "type": "Identifier",
341 + "loc": {
342 + "source": null,
343 + "start": {
344 + "line": 3,
345 + "column": 26
346 + },
347 + "end": {
348 + "line": 3,
349 + "column": 27
350 + }
351 + },
352 + "name": "i",
353 + "typeAnnotation": null,
354 + "optional": false,
355 + "range": [
356 + 67,
357 + 68
358 + ]
359 + },
360 + "prefix": false,
361 + "range": [
362 + 67,
363 + 70
364 + ]
365 + },
366 + "body": {
367 + "type": "BlockStatement",
368 + "loc": {
369 + "source": null,
370 + "start": {
371 + "line": 3,
372 + "column": 31
373 + },
374 + "end": {
375 + "line": 5,
376 + "column": 3
377 + }
378 + },
379 + "body": [
380 + {
381 + "type": "ExpressionStatement",
382 + "loc": {
383 + "source": null,
384 + "start": {
385 + "line": 4,
386 + "column": 4
387 + },
388 + "end": {
389 + "line": 4,
390 + "column": 11
391 + }
392 + },
393 + "expression": {
394 + "type": "AssignmentExpression",
395 + "loc": {
396 + "source": null,
397 + "start": {
398 + "line": 4,
399 + "column": 4
400 + },
401 + "end": {
402 + "line": 4,
403 + "column": 10
404 + }
405 + },
406 + "operator": "+=",
407 + "left": {
408 + "type": "Identifier",
409 + "loc": {
410 + "source": null,
411 + "start": {
412 + "line": 4,
413 + "column": 4
414 + },
415 + "end": {
416 + "line": 4,
417 + "column": 5
418 + }
419 + },
420 + "name": "x",
421 + "typeAnnotation": null,
422 + "optional": false,
423 + "range": [
424 + 78,
425 + 79
426 + ]
427 + },
428 + "right": {
429 + "type": "Identifier",
430 + "loc": {
431 + "source": null,
432 + "start": {
433 + "line": 4,
434 + "column": 9
435 + },
436 + "end": {
437 + "line": 4,
438 + "column": 10
439 + }
440 + },
441 + "name": "i",
442 + "typeAnnotation": null,
443 + "optional": false,
444 + "range": [
445 + 83,
446 + 84
447 + ]
448 + },
449 + "range": [
450 + 78,
451 + 84
452 + ]
453 + },
454 + "directive": null,
455 + "range": [
456 + 78,
457 + 85
458 + ]
459 + }
460 + ],
461 + "range": [
462 + 72,
463 + 89
464 + ]
465 + },
466 + "range": [
467 + 43,
468 + 89
469 + ]
470 + },
471 + {
472 + "type": "ReturnStatement",
473 + "loc": {
474 + "source": null,
475 + "start": {
476 + "line": 6,
477 + "column": 2
478 + },
479 + "end": {
480 + "line": 6,
481 + "column": 11
482 + }
483 + },
484 + "argument": {
485 + "type": "Identifier",
486 + "loc": {
487 + "source": null,
488 + "start": {
489 + "line": 6,
490 + "column": 9
491 + },
492 + "end": {
493 + "line": 6,
494 + "column": 10
495 + }
496 + },
497 + "name": "x",
498 + "typeAnnotation": null,
499 + "optional": false,
500 + "range": [
501 + 99,
502 + 100
503 + ]
504 + },
505 + "range": [
506 + 92,
507 + 101
508 + ]
509 + }
510 + ],
511 + "range": [
512 + 26,
513 + 103
514 + ]
515 + },
516 + "typeParameters": null,
517 + "returnType": null,
518 + "predicate": null,
519 + "generator": false,
520 + "async": false,
521 + "range": [
522 + 0,
523 + 103
524 + ]
525 + }
526 + ],
527 + "comments": [],
528 + "interpreter": null,
529 + "range": [
530 + 0,
531 + 103
532 + ],
533 + "sourceType": "script"
534 + }
535 +
536 +Output:
537 +{
538 + "sourceType": "script",
539 + "body": [
540 + {
541 + "type": "FunctionDeclaration",
542 + "id": {
543 + "name": "Component",
544 + "loc": {
545 + "source": null,
546 + "start": {
547 + "line": 1,
548 + "column": 9
549 + },
550 + "end": {
551 + "line": 1,
552 + "column": 18
553 + }
554 + },
555 + "range": {
556 + "start": 9,
557 + "end": 18
558 + }
559 + },
560 + "params": [
561 + {
562 + "type": "Identifier",
563 + "name": "props",
564 + "loc": {
565 + "source": null,
566 + "start": {
567 + "line": 1,
568 + "column": 19
569 + },
570 + "end": {
571 + "line": 1,
572 + "column": 24
573 + }
574 + },
575 + "range": {
576 + "start": 19,
577 + "end": 24
578 + }
579 + }
580 + ],
581 + "generator": false,
582 + "async": false,
583 + "body": {
584 + "type": "BlockStatement",
585 + "body": [
586 + {
587 + "type": "VariableDeclaration",
588 + "declarations": [
589 + {
590 + "id": {
591 + "type": "Identifier",
592 + "name": "x",
593 + "loc": {
594 + "source": null,
595 + "start": {
596 + "line": 2,
597 + "column": 6
598 + },
599 + "end": {
600 + "line": 2,
601 + "column": 7
602 + }
603 + },
604 + "range": {
605 + "start": 34,
606 + "end": 35
607 + }
608 + },
609 + "init": {
610 + "type": "Literal",
611 + "value": 0,
612 + "raw": "0",
613 + "loc": {
614 + "source": null,
615 + "start": {
616 + "line": 2,
617 + "column": 10
618 + },
619 + "end": {
620 + "line": 2,
621 + "column": 11
622 + }
623 + },
624 + "range": {
625 + "start": 38,
626 + "end": 39
627 + }
628 + },
629 + "loc": {
630 + "source": null,
631 + "start": {
632 + "line": 2,
633 + "column": 6
634 + },
635 + "end": {
636 + "line": 2,
637 + "column": 11
638 + }
639 + },
640 + "range": {
641 + "start": 34,
642 + "end": 39
643 + }
644 + }
645 + ],
646 + "kind": "let",
647 + "loc": {
648 + "source": null,
649 + "start": {
650 + "line": 2,
651 + "column": 2
652 + },
653 + "end": {
654 + "line": 2,
655 + "column": 12
656 + }
657 + },
658 + "range": {
659 + "start": 30,
660 + "end": 40
661 + }
662 + },
663 + {
664 + "type": "ForStatement",
665 + "init": {
666 + "type": "VariableDeclaration",
667 + "declarations": [
668 + {
669 + "id": {
670 + "type": "Identifier",
671 + "name": "i",
672 + "loc": {
673 + "source": null,
674 + "start": {
675 + "line": 3,
676 + "column": 11
677 + },
678 + "end": {
679 + "line": 3,
680 + "column": 12
681 + }
682 + },
683 + "range": {
684 + "start": 52,
685 + "end": 53
686 + }
687 + },
688 + "init": {
689 + "type": "Literal",
690 + "value": 0,
691 + "raw": "0",
692 + "loc": {
693 + "source": null,
694 + "start": {
695 + "line": 3,
696 + "column": 15
697 + },
698 + "end": {
699 + "line": 3,
700 + "column": 16
701 + }
702 + },
703 + "range": {
704 + "start": 56,
705 + "end": 57
706 + }
707 + },
708 + "loc": {
709 + "source": null,
710 + "start": {
711 + "line": 3,
712 + "column": 11
713 + },
714 + "end": {
715 + "line": 3,
716 + "column": 16
717 + }
718 + },
719 + "range": {
720 + "start": 52,
721 + "end": 57
722 + }
723 + }
724 + ],
725 + "kind": "let",
726 + "loc": {
727 + "source": null,
728 + "start": {
729 + "line": 3,
730 + "column": 7
731 + },
732 + "end": {
733 + "line": 3,
734 + "column": 16
735 + }
736 + },
737 + "range": {
738 + "start": 48,
739 + "end": 57
740 + }
741 + },
742 + "test": {
743 + "type": "BinaryExpression",
744 + "operator": "<",
745 + "left": {
746 + "type": "Identifier",
747 + "name": "i",
748 + "loc": {
749 + "source": null,
750 + "start": {
751 + "line": 3,
752 + "column": 18
753 + },
754 + "end": {
755 + "line": 3,
756 + "column": 19
757 + }
758 + },
759 + "range": {
760 + "start": 59,
761 + "end": 60
762 + }
763 + },
764 + "right": {
765 + "type": "Literal",
766 + "value": 10,
767 + "raw": "10",
768 + "loc": {
769 + "source": null,
770 + "start": {
771 + "line": 3,
772 + "column": 22
773 + },
774 + "end": {
775 + "line": 3,
776 + "column": 24
777 + }
778 + },
779 + "range": {
780 + "start": 63,
781 + "end": 65
782 + }
783 + },
784 + "loc": {
785 + "source": null,
786 + "start": {
787 + "line": 3,
788 + "column": 18
789 + },
790 + "end": {
791 + "line": 3,
792 + "column": 24
793 + }
794 + },
795 + "range": {
796 + "start": 59,
797 + "end": 65
798 + }
799 + },
800 + "update": {
801 + "type": "UpdateExpression",
802 + "operator": "++",
803 + "argument": {
804 + "type": "Identifier",
805 + "name": "i",
806 + "loc": {
807 + "source": null,
808 + "start": {
809 + "line": 3,
810 + "column": 26
811 + },
812 + "end": {
813 + "line": 3,
814 + "column": 27
815 + }
816 + },
817 + "range": {
818 + "start": 67,
819 + "end": 68
820 + }
821 + },
822 + "prefix": false,
823 + "loc": {
824 + "source": null,
825 + "start": {
826 + "line": 3,
827 + "column": 26
828 + },
829 + "end": {
830 + "line": 3,
831 + "column": 29
832 + }
833 + },
834 + "range": {
835 + "start": 67,
836 + "end": 70
837 + }
838 + },
839 + "body": {
840 + "type": "BlockStatement",
841 + "body": [
842 + {
843 + "type": "ExpressionStatement",
844 + "expression": {
845 + "type": "AssignmentExpression",
846 + "operator": "+=",
847 + "left": {
848 + "type": "Identifier",
849 + "name": "x",
850 + "loc": {
851 + "source": null,
852 + "start": {
853 + "line": 4,
854 + "column": 4
855 + },
856 + "end": {
857 + "line": 4,
858 + "column": 5
859 + }
860 + },
861 + "range": {
862 + "start": 78,
863 + "end": 79
864 + }
865 + },
866 + "right": {
867 + "type": "Identifier",
868 + "name": "i",
869 + "loc": {
870 + "source": null,
871 + "start": {
872 + "line": 4,
873 + "column": 9
874 + },
875 + "end": {
876 + "line": 4,
877 + "column": 10
878 + }
879 + },
880 + "range": {
881 + "start": 83,
882 + "end": 84
883 + }
884 + },
885 + "loc": {
886 + "source": null,
887 + "start": {
888 + "line": 4,
889 + "column": 4
890 + },
891 + "end": {
892 + "line": 4,
893 + "column": 10
894 + }
895 + },
896 + "range": {
897 + "start": 78,
898 + "end": 84
899 + }
900 + },
901 + "directive": null,
902 + "loc": {
903 + "source": null,
904 + "start": {
905 + "line": 4,
906 + "column": 4
907 + },
908 + "end": {
909 + "line": 4,
910 + "column": 11
911 + }
912 + },
913 + "range": {
914 + "start": 78,
915 + "end": 85
916 + }
917 + }
918 + ],
919 + "loc": {
920 + "source": null,
921 + "start": {
922 + "line": 3,
923 + "column": 31
924 + },
925 + "end": {
926 + "line": 5,
927 + "column": 3
928 + }
929 + },
930 + "range": {
931 + "start": 72,
932 + "end": 89
933 + }
934 + },
935 + "loc": {
936 + "source": null,
937 + "start": {
938 + "line": 3,
939 + "column": 2
940 + },
941 + "end": {
942 + "line": 5,
943 + "column": 3
944 + }
945 + },
946 + "range": {
947 + "start": 43,
948 + "end": 89
949 + }
950 + },
951 + {
952 + "type": "ReturnStatement",
953 + "argument": {
954 + "type": "Identifier",
955 + "name": "x",
956 + "loc": {
957 + "source": null,
958 + "start": {
959 + "line": 6,
960 + "column": 9
961 + },
962 + "end": {
963 + "line": 6,
964 + "column": 10
965 + }
966 + },
967 + "range": {
968 + "start": 99,
969 + "end": 100
970 + }
971 + },
972 + "loc": {
973 + "source": null,
974 + "start": {
975 + "line": 6,
976 + "column": 2
977 + },
978 + "end": {
979 + "line": 6,
980 + "column": 11
981 + }
982 + },
983 + "range": {
984 + "start": 92,
985 + "end": 101
986 + }
987 + }
988 + ],
989 + "loc": {
990 + "source": null,
991 + "start": {
992 + "line": 1,
993 + "column": 26
994 + },
995 + "end": {
996 + "line": 7,
997 + "column": 1
998 + }
999 + },
1000 + "range": {
1001 + "start": 26,
1002 + "end": 103
1003 + }
1004 + },
1005 + "loc": {
1006 + "source": null,
1007 + "start": {
1008 + "line": 1,
1009 + "column": 0
1010 + },
1011 + "end": {
1012 + "line": 7,
1013 + "column": 1
1014 + }
1015 + },
1016 + "range": {
1017 + "start": 0,
1018 + "end": 103
1019 + }
1020 + }
1021 + ],
1022 + "comments": [],
1023 + "loc": {
1024 + "source": null,
1025 + "start": {
1026 + "line": 1,
1027 + "column": 0
1028 + },
1029 + "end": {
1030 + "line": 7,
1031 + "column": 1
1032 + }
1033 + },
1034 + "range": {
1035 + "start": 0,
1036 + "end": 103
1037 + }
1038 +}
compiler/forget/crates/estree/src/snapshots/estree__tests__fixtures@import.json.snap new
+207
@@ -0,0 +1,207 @@
1 +---
2 +source: crates/estree/src/lib.rs
3 +expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{serialized}\")"
4 +input_file: crates/estree/src/fixtures/import.json
5 +---
6 +Input:
7 +{
8 + "type": "Program",
9 + "loc": {
10 + "source": null,
11 + "start": {
12 + "line": 1,
13 + "column": 0
14 + },
15 + "end": {
16 + "line": 1,
17 + "column": 26
18 + }
19 + },
20 + "body": [
21 + {
22 + "type": "ImportDeclaration",
23 + "loc": {
24 + "source": null,
25 + "start": {
26 + "line": 1,
27 + "column": 0
28 + },
29 + "end": {
30 + "line": 1,
31 + "column": 26
32 + }
33 + },
34 + "specifiers": [
35 + {
36 + "type": "ImportDefaultSpecifier",
37 + "loc": {
38 + "source": null,
39 + "start": {
40 + "line": 1,
41 + "column": 7
42 + },
43 + "end": {
44 + "line": 1,
45 + "column": 12
46 + }
47 + },
48 + "local": {
49 + "type": "Identifier",
50 + "loc": {
51 + "source": null,
52 + "start": {
53 + "line": 1,
54 + "column": 7
55 + },
56 + "end": {
57 + "line": 1,
58 + "column": 12
59 + }
60 + },
61 + "name": "React",
62 + "typeAnnotation": null,
63 + "optional": false,
64 + "range": [
65 + 7,
66 + 12
67 + ]
68 + },
69 + "range": [
70 + 7,
71 + 12
72 + ]
73 + }
74 + ],
75 + "source": {
76 + "type": "Literal",
77 + "loc": {
78 + "source": null,
79 + "start": {
80 + "line": 1,
81 + "column": 18
82 + },
83 + "end": {
84 + "line": 1,
85 + "column": 25
86 + }
87 + },
88 + "value": "react",
89 + "range": [
90 + 18,
91 + 25
92 + ],
93 + "raw": "'react'"
94 + },
95 + "attributes": [],
96 + "importKind": "value",
97 + "range": [
98 + 0,
99 + 26
100 + ]
101 + }
102 + ],
103 + "comments": [],
104 + "interpreter": null,
105 + "range": [
106 + 0,
107 + 26
108 + ],
109 + "sourceType": "module"
110 + }
111 +
112 +Output:
113 +{
114 + "sourceType": "module",
115 + "body": [
116 + {
117 + "specifiers": [
118 + {
119 + "type": "ImportDefaultSpecifier",
120 + "local": {
121 + "name": "React",
122 + "loc": {
123 + "source": null,
124 + "start": {
125 + "line": 1,
126 + "column": 7
127 + },
128 + "end": {
129 + "line": 1,
130 + "column": 12
131 + }
132 + },
133 + "range": {
134 + "start": 7,
135 + "end": 12
136 + }
137 + },
138 + "loc": {
139 + "source": null,
140 + "start": {
141 + "line": 1,
142 + "column": 7
143 + },
144 + "end": {
145 + "line": 1,
146 + "column": 12
147 + }
148 + },
149 + "range": {
150 + "start": 7,
151 + "end": 12
152 + }
153 + }
154 + ],
155 + "source": {
156 + "value": "react",
157 + "raw": "'react'",
158 + "loc": {
159 + "source": null,
160 + "start": {
161 + "line": 1,
162 + "column": 18
163 + },
164 + "end": {
165 + "line": 1,
166 + "column": 25
167 + }
168 + },
169 + "range": {
170 + "start": 18,
171 + "end": 25
172 + }
173 + },
174 + "loc": {
175 + "source": null,
176 + "start": {
177 + "line": 1,
178 + "column": 0
179 + },
180 + "end": {
181 + "line": 1,
182 + "column": 26
183 + }
184 + },
185 + "range": {
186 + "start": 0,
187 + "end": 26
188 + }
189 + }
190 + ],
191 + "comments": [],
192 + "loc": {
193 + "source": null,
194 + "start": {
195 + "line": 1,
196 + "column": 0
197 + },
198 + "end": {
199 + "line": 1,
200 + "column": 26
201 + }
202 + },
203 + "range": {
204 + "start": 0,
205 + "end": 26
206 + }
207 +}
compiler/forget/crates/estree/src/snapshots/estree__tests__fixtures@simple.json.snap new
+373
@@ -0,0 +1,373 @@
1 +---
2 +source: crates/estree/src/lib.rs
3 +expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{serialized}\")"
4 +input_file: crates/estree/src/fixtures/simple.json
5 +---
6 +Input:
7 +{
8 + "type": "Program",
9 + "loc": {
10 + "source": null,
11 + "start": {
12 + "line": 1,
13 + "column": 0
14 + },
15 + "end": {
16 + "line": 3,
17 + "column": 1
18 + }
19 + },
20 + "range": [
21 + 0,
22 + 51
23 + ],
24 + "body": [
25 + {
26 + "type": "FunctionDeclaration",
27 + "loc": {
28 + "source": null,
29 + "start": {
30 + "line": 1,
31 + "column": 0
32 + },
33 + "end": {
34 + "line": 3,
35 + "column": 1
36 + }
37 + },
38 + "range": [
39 + 0,
40 + 51
41 + ],
42 + "id": {
43 + "type": "Identifier",
44 + "loc": {
45 + "source": null,
46 + "start": {
47 + "line": 1,
48 + "column": 9
49 + },
50 + "end": {
51 + "line": 1,
52 + "column": 18
53 + }
54 + },
55 + "range": [
56 + 9,
57 + 18
58 + ],
59 + "name": "Component",
60 + "typeAnnotation": null,
61 + "optional": false
62 + },
63 + "params": [
64 + {
65 + "type": "Identifier",
66 + "loc": {
67 + "source": null,
68 + "start": {
69 + "line": 1,
70 + "column": 19
71 + },
72 + "end": {
73 + "line": 1,
74 + "column": 24
75 + }
76 + },
77 + "range": [
78 + 19,
79 + 24
80 + ],
81 + "name": "props",
82 + "typeAnnotation": null,
83 + "optional": false
84 + }
85 + ],
86 + "body": {
87 + "type": "BlockStatement",
88 + "loc": {
89 + "source": null,
90 + "start": {
91 + "line": 1,
92 + "column": 26
93 + },
94 + "end": {
95 + "line": 3,
96 + "column": 1
97 + }
98 + },
99 + "range": [
100 + 26,
101 + 51
102 + ],
103 + "body": [
104 + {
105 + "type": "ReturnStatement",
106 + "loc": {
107 + "source": null,
108 + "start": {
109 + "line": 2,
110 + "column": 2
111 + },
112 + "end": {
113 + "line": 2,
114 + "column": 21
115 + }
116 + },
117 + "range": [
118 + 30,
119 + 49
120 + ],
121 + "argument": {
122 + "type": "MemberExpression",
123 + "loc": {
124 + "source": null,
125 + "start": {
126 + "line": 2,
127 + "column": 9
128 + },
129 + "end": {
130 + "line": 2,
131 + "column": 20
132 + }
133 + },
134 + "range": [
135 + 37,
136 + 48
137 + ],
138 + "object": {
139 + "type": "Identifier",
140 + "loc": {
141 + "source": null,
142 + "start": {
143 + "line": 2,
144 + "column": 9
145 + },
146 + "end": {
147 + "line": 2,
148 + "column": 14
149 + }
150 + },
151 + "range": [
152 + 37,
153 + 42
154 + ],
155 + "name": "props",
156 + "typeAnnotation": null,
157 + "optional": false
158 + },
159 + "property": {
160 + "type": "Identifier",
161 + "loc": {
162 + "source": null,
163 + "start": {
164 + "line": 2,
165 + "column": 15
166 + },
167 + "end": {
168 + "line": 2,
169 + "column": 20
170 + }
171 + },
172 + "range": [
173 + 43,
174 + 48
175 + ],
176 + "name": "value",
177 + "typeAnnotation": null,
178 + "optional": false
179 + },
180 + "computed": false
181 + }
182 + }
183 + ]
184 + },
185 + "async": false,
186 + "generator": false,
187 + "predicate": null,
188 + "expression": false,
189 + "returnType": null,
190 + "typeParameters": null
191 + }
192 + ],
193 + "comments": [],
194 + "errors": []
195 + }
196 +
197 +Output:
198 +{
199 + "sourceType": "module",
200 + "body": [
201 + {
202 + "type": "FunctionDeclaration",
203 + "id": {
204 + "name": "Component",
205 + "loc": {
206 + "source": null,
207 + "start": {
208 + "line": 1,
209 + "column": 9
210 + },
211 + "end": {
212 + "line": 1,
213 + "column": 18
214 + }
215 + },
216 + "range": {
217 + "start": 9,
218 + "end": 18
219 + }
220 + },
221 + "params": [
222 + {
223 + "type": "Identifier",
224 + "name": "props",
225 + "loc": {
226 + "source": null,
227 + "start": {
228 + "line": 1,
229 + "column": 19
230 + },
231 + "end": {
232 + "line": 1,
233 + "column": 24
234 + }
235 + },
236 + "range": {
237 + "start": 19,
238 + "end": 24
239 + }
240 + }
241 + ],
242 + "generator": false,
243 + "async": false,
244 + "body": {
245 + "type": "BlockStatement",
246 + "body": [
247 + {
248 + "type": "ReturnStatement",
249 + "argument": {
250 + "type": "MemberExpression",
251 + "object": {
252 + "type": "Identifier",
253 + "name": "props",
254 + "loc": {
255 + "source": null,
256 + "start": {
257 + "line": 2,
258 + "column": 9
259 + },
260 + "end": {
261 + "line": 2,
262 + "column": 14
263 + }
264 + },
265 + "range": {
266 + "start": 37,
267 + "end": 42
268 + }
269 + },
270 + "property": {
271 + "type": "Identifier",
272 + "name": "value",
273 + "loc": {
274 + "source": null,
275 + "start": {
276 + "line": 2,
277 + "column": 15
278 + },
279 + "end": {
280 + "line": 2,
281 + "column": 20
282 + }
283 + },
284 + "range": {
285 + "start": 43,
286 + "end": 48
287 + }
288 + },
289 + "computed": false,
290 + "optional": false,
291 + "loc": {
292 + "source": null,
293 + "start": {
294 + "line": 2,
295 + "column": 9
296 + },
297 + "end": {
298 + "line": 2,
299 + "column": 20
300 + }
301 + },
302 + "range": {
303 + "start": 37,
304 + "end": 48
305 + }
306 + },
307 + "loc": {
308 + "source": null,
309 + "start": {
310 + "line": 2,
311 + "column": 2
312 + },
313 + "end": {
314 + "line": 2,
315 + "column": 21
316 + }
317 + },
318 + "range": {
319 + "start": 30,
320 + "end": 49
321 + }
322 + }
323 + ],
324 + "loc": {
325 + "source": null,
326 + "start": {
327 + "line": 1,
328 + "column": 26
329 + },
330 + "end": {
331 + "line": 3,
332 + "column": 1
333 + }
334 + },
335 + "range": {
336 + "start": 26,
337 + "end": 51
338 + }
339 + },
340 + "loc": {
341 + "source": null,
342 + "start": {
343 + "line": 1,
344 + "column": 0
345 + },
346 + "end": {
347 + "line": 3,
348 + "column": 1
349 + }
350 + },
351 + "range": {
352 + "start": 0,
353 + "end": 51
354 + }
355 + }
356 + ],
357 + "comments": [],
358 + "loc": {
359 + "source": null,
360 + "start": {
361 + "line": 1,
362 + "column": 0
363 + },
364 + "end": {
365 + "line": 3,
366 + "column": 1
367 + }
368 + },
369 + "range": {
370 + "start": 0,
371 + "end": 51
372 + }
373 +}
compiler/forget/crates/estree/src/snapshots/estree__tests__fixtures@test.json.snap new
+701
@@ -0,0 +1,701 @@
1 +---
2 +source: crates/estree/src/lib.rs
3 +expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{serialized}\")"
4 +input_file: crates/estree/src/fixtures/test.json
5 +---
6 +Input:
7 +{
8 + "type": "Program",
9 + "loc": {
10 + "source": null,
11 + "start": {
12 + "line": 2,
13 + "column": 0
14 + },
15 + "end": {
16 + "line": 4,
17 + "column": 1
18 + }
19 + },
20 + "body": [
21 + {
22 + "type": "FunctionDeclaration",
23 + "loc": {
24 + "source": null,
25 + "start": {
26 + "line": 2,
27 + "column": 0
28 + },
29 + "end": {
30 + "line": 4,
31 + "column": 1
32 + }
33 + },
34 + "id": {
35 + "type": "Identifier",
36 + "loc": {
37 + "source": null,
38 + "start": {
39 + "line": 2,
40 + "column": 9
41 + },
42 + "end": {
43 + "line": 2,
44 + "column": 12
45 + }
46 + },
47 + "name": "foo",
48 + "typeAnnotation": null,
49 + "optional": false,
50 + "range": [
51 + 10,
52 + 13
53 + ]
54 + },
55 + "params": [],
56 + "body": {
57 + "type": "BlockStatement",
58 + "loc": {
59 + "source": null,
60 + "start": {
61 + "line": 2,
62 + "column": 15
63 + },
64 + "end": {
65 + "line": 4,
66 + "column": 1
67 + }
68 + },
69 + "body": [
70 + {
71 + "type": "ReturnStatement",
72 + "loc": {
73 + "source": null,
74 + "start": {
75 + "line": 3,
76 + "column": 2
77 + },
78 + "end": {
79 + "line": 3,
80 + "column": 36
81 + }
82 + },
83 + "argument": {
84 + "type": "JSXElement",
85 + "loc": {
86 + "source": null,
87 + "start": {
88 + "line": 3,
89 + "column": 9
90 + },
91 + "end": {
92 + "line": 3,
93 + "column": 36
94 + }
95 + },
96 + "openingElement": {
97 + "type": "JSXOpeningElement",
98 + "loc": {
99 + "source": null,
100 + "start": {
101 + "line": 3,
102 + "column": 9
103 + },
104 + "end": {
105 + "line": 3,
106 + "column": 26
107 + }
108 + },
109 + "name": {
110 + "type": "JSXMemberExpression",
111 + "loc": {
112 + "source": null,
113 + "start": {
114 + "line": 3,
115 + "column": 10
116 + },
117 + "end": {
118 + "line": 3,
119 + "column": 17
120 + }
121 + },
122 + "object": {
123 + "type": "JSXIdentifier",
124 + "loc": {
125 + "source": null,
126 + "start": {
127 + "line": 3,
128 + "column": 10
129 + },
130 + "end": {
131 + "line": 3,
132 + "column": 13
133 + }
134 + },
135 + "name": "Foo",
136 + "range": [
137 + 28,
138 + 31
139 + ]
140 + },
141 + "property": {
142 + "type": "JSXIdentifier",
143 + "loc": {
144 + "source": null,
145 + "start": {
146 + "line": 3,
147 + "column": 14
148 + },
149 + "end": {
150 + "line": 3,
151 + "column": 17
152 + }
153 + },
154 + "name": "Bar",
155 + "range": [
156 + 32,
157 + 35
158 + ]
159 + },
160 + "range": [
161 + 28,
162 + 35
163 + ]
164 + },
165 + "attributes": [
166 + {
167 + "type": "JSXAttribute",
168 + "loc": {
169 + "source": null,
170 + "start": {
171 + "line": 3,
172 + "column": 18
173 + },
174 + "end": {
175 + "line": 3,
176 + "column": 24
177 + }
178 + },
179 + "name": {
180 + "type": "JSXIdentifier",
181 + "loc": {
182 + "source": null,
183 + "start": {
184 + "line": 3,
185 + "column": 18
186 + },
187 + "end": {
188 + "line": 3,
189 + "column": 19
190 + }
191 + },
192 + "name": "a",
193 + "range": [
194 + 36,
195 + 37
196 + ]
197 + },
198 + "value": {
199 + "type": "JSXExpressionContainer",
200 + "loc": {
201 + "source": null,
202 + "start": {
203 + "line": 3,
204 + "column": 20
205 + },
206 + "end": {
207 + "line": 3,
208 + "column": 24
209 + }
210 + },
211 + "expression": {
212 + "type": "Literal",
213 + "loc": {
214 + "source": null,
215 + "start": {
216 + "line": 3,
217 + "column": 21
218 + },
219 + "end": {
220 + "line": 3,
221 + "column": 23
222 + }
223 + },
224 + "value": 10,
225 + "range": [
226 + 39,
227 + 41
228 + ],
229 + "raw": "10"
230 + },
231 + "range": [
232 + 38,
233 + 42
234 + ]
235 + },
236 + "range": [
237 + 36,
238 + 42
239 + ]
240 + }
241 + ],
242 + "selfClosing": false,
243 + "range": [
244 + 27,
245 + 44
246 + ]
247 + },
248 + "children": [],
249 + "closingElement": {
250 + "type": "JSXClosingElement",
251 + "loc": {
252 + "source": null,
253 + "start": {
254 + "line": 3,
255 + "column": 26
256 + },
257 + "end": {
258 + "line": 3,
259 + "column": 36
260 + }
261 + },
262 + "name": {
263 + "type": "JSXMemberExpression",
264 + "loc": {
265 + "source": null,
266 + "start": {
267 + "line": 3,
268 + "column": 28
269 + },
270 + "end": {
271 + "line": 3,
272 + "column": 35
273 + }
274 + },
275 + "object": {
276 + "type": "JSXIdentifier",
277 + "loc": {
278 + "source": null,
279 + "start": {
280 + "line": 3,
281 + "column": 28
282 + },
283 + "end": {
284 + "line": 3,
285 + "column": 31
286 + }
287 + },
288 + "name": "Foo",
289 + "range": [
290 + 46,
291 + 49
292 + ]
293 + },
294 + "property": {
295 + "type": "JSXIdentifier",
296 + "loc": {
297 + "source": null,
298 + "start": {
299 + "line": 3,
300 + "column": 32
301 + },
302 + "end": {
303 + "line": 3,
304 + "column": 35
305 + }
306 + },
307 + "name": "Bar",
308 + "range": [
309 + 50,
310 + 53
311 + ]
312 + },
313 + "range": [
314 + 46,
315 + 53
316 + ]
317 + },
318 + "range": [
319 + 44,
320 + 54
321 + ]
322 + },
323 + "range": [
324 + 27,
325 + 54
326 + ]
327 + },
328 + "range": [
329 + 20,
330 + 54
331 + ]
332 + }
333 + ],
334 + "range": [
335 + 16,
336 + 56
337 + ]
338 + },
339 + "typeParameters": null,
340 + "returnType": null,
341 + "predicate": null,
342 + "generator": false,
343 + "async": false,
344 + "range": [
345 + 1,
346 + 56
347 + ]
348 + }
349 + ],
350 + "comments": [],
351 + "interpreter": null,
352 + "range": [
353 + 1,
354 + 56
355 + ],
356 + "sourceType": "script"
357 + }
358 +
359 +Output:
360 +{
361 + "sourceType": "script",
362 + "body": [
363 + {
364 + "type": "FunctionDeclaration",
365 + "id": {
366 + "name": "foo",
367 + "loc": {
368 + "source": null,
369 + "start": {
370 + "line": 2,
371 + "column": 9
372 + },
373 + "end": {
374 + "line": 2,
375 + "column": 12
376 + }
377 + },
378 + "range": {
379 + "start": 10,
380 + "end": 13
381 + }
382 + },
383 + "params": [],
384 + "generator": false,
385 + "async": false,
386 + "body": {
387 + "type": "BlockStatement",
388 + "body": [
389 + {
390 + "type": "ReturnStatement",
391 + "argument": {
392 + "type": "JSXElement",
393 + "openingElement": {
394 + "type": "JSXOpeningElement",
395 + "name": {
396 + "type": "JSXMemberExpression",
397 + "object": {
398 + "type": "JSXIdentifier",
399 + "name": "Foo",
400 + "loc": {
401 + "source": null,
402 + "start": {
403 + "line": 3,
404 + "column": 10
405 + },
406 + "end": {
407 + "line": 3,
408 + "column": 13
409 + }
410 + },
411 + "range": {
412 + "start": 28,
413 + "end": 31
414 + }
415 + },
416 + "property": {
417 + "type": "JSXIdentifier",
418 + "name": "Bar",
419 + "loc": {
420 + "source": null,
421 + "start": {
422 + "line": 3,
423 + "column": 14
424 + },
425 + "end": {
426 + "line": 3,
427 + "column": 17
428 + }
429 + },
430 + "range": {
431 + "start": 32,
432 + "end": 35
433 + }
434 + },
435 + "loc": {
436 + "source": null,
437 + "start": {
438 + "line": 3,
439 + "column": 10
440 + },
441 + "end": {
442 + "line": 3,
443 + "column": 17
444 + }
445 + },
446 + "range": {
447 + "start": 28,
448 + "end": 35
449 + }
450 + },
451 + "attributes": [
452 + {
453 + "name": {
454 + "type": "JSXIdentifier",
455 + "name": "a",
456 + "loc": {
457 + "source": null,
458 + "start": {
459 + "line": 3,
460 + "column": 18
461 + },
462 + "end": {
463 + "line": 3,
464 + "column": 19
465 + }
466 + },
467 + "range": {
468 + "start": 36,
469 + "end": 37
470 + }
471 + },
472 + "value": {
473 + "type": "JSXExpressionContainer",
474 + "expression": {
475 + "type": "Literal",
476 + "value": 10,
477 + "raw": "10",
478 + "loc": {
479 + "source": null,
480 + "start": {
481 + "line": 3,
482 + "column": 21
483 + },
484 + "end": {
485 + "line": 3,
486 + "column": 23
487 + }
488 + },
489 + "range": {
490 + "start": 39,
491 + "end": 41
492 + }
493 + },
494 + "loc": {
495 + "source": null,
496 + "start": {
497 + "line": 3,
498 + "column": 20
499 + },
500 + "end": {
501 + "line": 3,
502 + "column": 24
503 + }
504 + },
505 + "range": {
506 + "start": 38,
507 + "end": 42
508 + }
509 + },
510 + "loc": {
511 + "source": null,
512 + "start": {
513 + "line": 3,
514 + "column": 18
515 + },
516 + "end": {
517 + "line": 3,
518 + "column": 24
519 + }
520 + },
521 + "range": {
522 + "start": 36,
523 + "end": 42
524 + }
525 + }
526 + ],
527 + "selfClosing": false,
528 + "loc": {
529 + "source": null,
530 + "start": {
531 + "line": 3,
532 + "column": 9
533 + },
534 + "end": {
535 + "line": 3,
536 + "column": 26
537 + }
538 + },
539 + "range": {
540 + "start": 27,
541 + "end": 44
542 + }
543 + },
544 + "children": [],
545 + "closingElement": {
546 + "type": "JSXClosingElement",
547 + "name": {
548 + "type": "JSXMemberExpression",
549 + "object": {
550 + "type": "JSXIdentifier",
551 + "name": "Foo",
552 + "loc": {
553 + "source": null,
554 + "start": {
555 + "line": 3,
556 + "column": 28
557 + },
558 + "end": {
559 + "line": 3,
560 + "column": 31
561 + }
562 + },
563 + "range": {
564 + "start": 46,
565 + "end": 49
566 + }
567 + },
568 + "property": {
569 + "type": "JSXIdentifier",
570 + "name": "Bar",
571 + "loc": {
572 + "source": null,
573 + "start": {
574 + "line": 3,
575 + "column": 32
576 + },
577 + "end": {
578 + "line": 3,
579 + "column": 35
580 + }
581 + },
582 + "range": {
583 + "start": 50,
584 + "end": 53
585 + }
586 + },
587 + "loc": {
588 + "source": null,
589 + "start": {
590 + "line": 3,
591 + "column": 28
592 + },
593 + "end": {
594 + "line": 3,
595 + "column": 35
596 + }
597 + },
598 + "range": {
599 + "start": 46,
600 + "end": 53
601 + }
602 + },
603 + "loc": {
604 + "source": null,
605 + "start": {
606 + "line": 3,
607 + "column": 26
608 + },
609 + "end": {
610 + "line": 3,
611 + "column": 36
612 + }
613 + },
614 + "range": {
615 + "start": 44,
616 + "end": 54
617 + }
618 + },
619 + "loc": {
620 + "source": null,
621 + "start": {
622 + "line": 3,
623 + "column": 9
624 + },
625 + "end": {
626 + "line": 3,
627 + "column": 36
628 + }
629 + },
630 + "range": {
631 + "start": 27,
632 + "end": 54
633 + }
634 + },
635 + "loc": {
636 + "source": null,
637 + "start": {
638 + "line": 3,
639 + "column": 2
640 + },
641 + "end": {
642 + "line": 3,
643 + "column": 36
644 + }
645 + },
646 + "range": {
647 + "start": 20,
648 + "end": 54
649 + }
650 + }
651 + ],
652 + "loc": {
653 + "source": null,
654 + "start": {
655 + "line": 2,
656 + "column": 15
657 + },
658 + "end": {
659 + "line": 4,
660 + "column": 1
661 + }
662 + },
663 + "range": {
664 + "start": 16,
665 + "end": 56
666 + }
667 + },
668 + "loc": {
669 + "source": null,
670 + "start": {
671 + "line": 2,
672 + "column": 0
673 + },
674 + "end": {
675 + "line": 4,
676 + "column": 1
677 + }
678 + },
679 + "range": {
680 + "start": 1,
681 + "end": 56
682 + }
683 + }
684 + ],
685 + "comments": [],
686 + "loc": {
687 + "source": null,
688 + "start": {
689 + "line": 2,
690 + "column": 0
691 + },
692 + "end": {
693 + "line": 4,
694 + "column": 1
695 + }
696 + },
697 + "range": {
698 + "start": 1,
699 + "end": 56
700 + }
701 +}