@samitouri / QOS-React-1 / commits / 8042970ea4

[rust] Scaffolding for semantic analysis

Joe Savona committed Aug 1, 2023 at 15:55 UTC 8042970ea4e13954bfad4bc5c2df6eaa9e2ccb36
10 files changed +220 -2
compiler/forget/Cargo.lock
+8
@@ -562,6 +562,14 @@ dependencies = [
562 "thiserror",
563 ]
564
565 +[[package]]
566 +name = "forget_semantic_analysis"
567 +version = "0.1.0"
568 +dependencies = [
569 + "forget_estree",
570 + "forget_utils",
571 +]
572 +
573 [[package]]
574 name = "forget_ssa"
575 version = "0.1.0"
compiler/forget/crates/forget_estree/src/generated.rs
+101 -1
@@ -3,7 +3,7 @@
3 use std::num::NonZeroU32;
4 use serde::ser::{Serializer, SerializeMap};
5 use serde::{Serialize, Deserialize};
6 -use crate::{JsValue, Binding, SourceRange, Number};
6 +use crate::{JsValue, Binding, SourceRange, Number, ESTreeNode};
7 #[derive(Serialize, Deserialize, Clone, Debug)]
8 #[serde(deny_unknown_fields)]
9 pub struct SourceLocation {
@@ -68,6 +68,7 @@ pub struct Identifier {
68 #[serde(default)]
69 pub range: Option<SourceRange>,
70 }
71 +impl ESTreeNode for Identifier {}
72 impl Serialize for Identifier {
73 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
74 where
@@ -96,6 +97,7 @@ pub struct Literal {
97 #[serde(default)]
98 pub range: Option<SourceRange>,
99 }
100 +impl ESTreeNode for Literal {}
101 impl Serialize for Literal {
102 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
103 where
@@ -120,6 +122,7 @@ pub struct NumericLiteral {
122 #[serde(default)]
123 pub range: Option<SourceRange>,
124 }
125 +impl ESTreeNode for NumericLiteral {}
126 impl Serialize for NumericLiteral {
127 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
128 where
@@ -141,6 +144,7 @@ pub struct BooleanLiteral {
144 #[serde(default)]
145 pub range: Option<SourceRange>,
146 }
147 +impl ESTreeNode for BooleanLiteral {}
148 impl Serialize for BooleanLiteral {
149 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
150 where
@@ -161,6 +165,7 @@ pub struct NullLiteral {
165 #[serde(default)]
166 pub range: Option<SourceRange>,
167 }
168 +impl ESTreeNode for NullLiteral {}
169 impl Serialize for NullLiteral {
170 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
171 where
@@ -181,6 +186,7 @@ pub struct StringLiteral {
186 #[serde(default)]
187 pub range: Option<SourceRange>,
188 }
189 +impl ESTreeNode for StringLiteral {}
190 impl Serialize for StringLiteral {
191 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
192 where
@@ -203,6 +209,7 @@ pub struct RegExpLiteral {
209 #[serde(default)]
210 pub range: Option<SourceRange>,
211 }
212 +impl ESTreeNode for RegExpLiteral {}
213 impl Serialize for RegExpLiteral {
214 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
215 where
@@ -228,6 +235,7 @@ pub struct Program {
235 #[serde(default)]
236 pub range: Option<SourceRange>,
237 }
238 +impl ESTreeNode for Program {}
239 impl Serialize for Program {
240 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
241 where
@@ -252,6 +260,7 @@ pub struct ExpressionStatement {
260 #[serde(default)]
261 pub range: Option<SourceRange>,
262 }
263 +impl ESTreeNode for ExpressionStatement {}
264 impl Serialize for ExpressionStatement {
265 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
266 where
@@ -274,6 +283,7 @@ pub struct BlockStatement {
283 #[serde(default)]
284 pub range: Option<SourceRange>,
285 }
286 +impl ESTreeNode for BlockStatement {}
287 impl Serialize for BlockStatement {
288 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
289 where
@@ -294,6 +304,7 @@ pub struct EmptyStatement {
304 #[serde(default)]
305 pub range: Option<SourceRange>,
306 }
307 +impl ESTreeNode for EmptyStatement {}
308 impl Serialize for EmptyStatement {
309 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
310 where
@@ -313,6 +324,7 @@ pub struct DebuggerStatement {
324 #[serde(default)]
325 pub range: Option<SourceRange>,
326 }
327 +impl ESTreeNode for DebuggerStatement {}
328 impl Serialize for DebuggerStatement {
329 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
330 where
@@ -334,6 +346,7 @@ pub struct WithStatement {
346 #[serde(default)]
347 pub range: Option<SourceRange>,
348 }
349 +impl ESTreeNode for WithStatement {}
350 impl Serialize for WithStatement {
351 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
352 where
@@ -356,6 +369,7 @@ pub struct ReturnStatement {
369 #[serde(default)]
370 pub range: Option<SourceRange>,
371 }
372 +impl ESTreeNode for ReturnStatement {}
373 impl Serialize for ReturnStatement {
374 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
375 where
@@ -378,6 +392,7 @@ pub struct LabeledStatement {
392 #[serde(default)]
393 pub range: Option<SourceRange>,
394 }
395 +impl ESTreeNode for LabeledStatement {}
396 impl Serialize for LabeledStatement {
397 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
398 where
@@ -400,6 +415,7 @@ pub struct BreakStatement {
415 #[serde(default)]
416 pub range: Option<SourceRange>,
417 }
418 +impl ESTreeNode for BreakStatement {}
419 impl Serialize for BreakStatement {
420 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
421 where
@@ -421,6 +437,7 @@ pub struct ContinueStatement {
437 #[serde(default)]
438 pub range: Option<SourceRange>,
439 }
440 +impl ESTreeNode for ContinueStatement {}
441 impl Serialize for ContinueStatement {
442 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
443 where
@@ -444,6 +461,7 @@ pub struct IfStatement {
461 #[serde(default)]
462 pub range: Option<SourceRange>,
463 }
464 +impl ESTreeNode for IfStatement {}
465 impl Serialize for IfStatement {
466 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
467 where
@@ -468,6 +486,7 @@ pub struct SwitchStatement {
486 #[serde(default)]
487 pub range: Option<SourceRange>,
488 }
489 +impl ESTreeNode for SwitchStatement {}
490 impl Serialize for SwitchStatement {
491 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
492 where
@@ -491,6 +510,7 @@ pub struct SwitchCase {
510 #[serde(default)]
511 pub range: Option<SourceRange>,
512 }
513 +impl ESTreeNode for SwitchCase {}
514 impl Serialize for SwitchCase {
515 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
516 where
@@ -513,6 +533,7 @@ pub struct ThrowStatement {
533 #[serde(default)]
534 pub range: Option<SourceRange>,
535 }
536 +impl ESTreeNode for ThrowStatement {}
537 impl Serialize for ThrowStatement {
538 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
539 where
@@ -536,6 +557,7 @@ pub struct TryStatement {
557 #[serde(default)]
558 pub range: Option<SourceRange>,
559 }
560 +impl ESTreeNode for TryStatement {}
561 impl Serialize for TryStatement {
562 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
563 where
@@ -560,6 +582,7 @@ pub struct CatchClause {
582 #[serde(default)]
583 pub range: Option<SourceRange>,
584 }
585 +impl ESTreeNode for CatchClause {}
586 impl Serialize for CatchClause {
587 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
588 where
@@ -583,6 +606,7 @@ pub struct WhileStatement {
606 #[serde(default)]
607 pub range: Option<SourceRange>,
608 }
609 +impl ESTreeNode for WhileStatement {}
610 impl Serialize for WhileStatement {
611 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
612 where
@@ -606,6 +630,7 @@ pub struct DoWhileStatement {
630 #[serde(default)]
631 pub range: Option<SourceRange>,
632 }
633 +impl ESTreeNode for DoWhileStatement {}
634 impl Serialize for DoWhileStatement {
635 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
636 where
@@ -631,6 +656,7 @@ pub struct ForStatement {
656 #[serde(default)]
657 pub range: Option<SourceRange>,
658 }
659 +impl ESTreeNode for ForStatement {}
660 impl Serialize for ForStatement {
661 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
662 where
@@ -657,6 +683,7 @@ pub struct ForInStatement {
683 #[serde(default)]
684 pub range: Option<SourceRange>,
685 }
686 +impl ESTreeNode for ForInStatement {}
687 impl Serialize for ForInStatement {
688 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
689 where
@@ -685,6 +712,7 @@ pub struct ForOfStatement {
712 #[serde(default)]
713 pub range: Option<SourceRange>,
714 }
715 +impl ESTreeNode for ForOfStatement {}
716 impl Serialize for ForOfStatement {
717 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
718 where
@@ -710,6 +738,7 @@ pub struct FunctionDeclaration {
738 #[serde(default)]
739 pub range: Option<SourceRange>,
740 }
741 +impl ESTreeNode for FunctionDeclaration {}
742 impl Serialize for FunctionDeclaration {
743 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
744 where
@@ -735,6 +764,7 @@ pub struct ClassDeclaration {
764 #[serde(default)]
765 pub range: Option<SourceRange>,
766 }
767 +impl ESTreeNode for ClassDeclaration {}
768 impl Serialize for ClassDeclaration {
769 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
770 where
@@ -760,6 +790,7 @@ pub struct ClassExpression {
790 #[serde(default)]
791 pub range: Option<SourceRange>,
792 }
793 +impl ESTreeNode for ClassExpression {}
794 impl Serialize for ClassExpression {
795 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
796 where
@@ -784,6 +815,7 @@ pub struct ClassBody {
815 #[serde(default)]
816 pub range: Option<SourceRange>,
817 }
818 +impl ESTreeNode for ClassBody {}
819 impl Serialize for ClassBody {
820 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
821 where
@@ -811,6 +843,7 @@ pub struct MethodDefinition {
843 #[serde(default)]
844 pub range: Option<SourceRange>,
845 }
846 +impl ESTreeNode for MethodDefinition {}
847 impl Serialize for MethodDefinition {
848 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
849 where
@@ -837,6 +870,7 @@ pub struct VariableDeclaration {
870 #[serde(default)]
871 pub range: Option<SourceRange>,
872 }
873 +impl ESTreeNode for VariableDeclaration {}
874 impl Serialize for VariableDeclaration {
875 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
876 where
@@ -860,6 +894,7 @@ pub struct VariableDeclarator {
894 #[serde(default)]
895 pub range: Option<SourceRange>,
896 }
897 +impl ESTreeNode for VariableDeclarator {}
898 impl Serialize for VariableDeclarator {
899 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
900 where
@@ -881,6 +916,7 @@ pub struct ThisExpression {
916 #[serde(default)]
917 pub range: Option<SourceRange>,
918 }
919 +impl ESTreeNode for ThisExpression {}
920 impl Serialize for ThisExpression {
921 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
922 where
@@ -901,6 +937,7 @@ pub struct ArrayExpression {
937 #[serde(default)]
938 pub range: Option<SourceRange>,
939 }
940 +impl ESTreeNode for ArrayExpression {}
941 impl Serialize for ArrayExpression {
942 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
943 where
@@ -922,6 +959,7 @@ pub struct ObjectExpression {
959 #[serde(default)]
960 pub range: Option<SourceRange>,
961 }
962 +impl ESTreeNode for ObjectExpression {}
963 impl Serialize for ObjectExpression {
964 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
965 where
@@ -951,6 +989,7 @@ pub struct Property {
989 #[serde(default)]
990 pub range: Option<SourceRange>,
991 }
992 +impl ESTreeNode for Property {}
993 impl Serialize for Property {
994 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
995 where
@@ -978,6 +1017,7 @@ pub struct FunctionExpression {
1017 #[serde(default)]
1018 pub range: Option<SourceRange>,
1019 }
1020 +impl ESTreeNode for FunctionExpression {}
1021 impl Serialize for FunctionExpression {
1022 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1023 where
@@ -1005,6 +1045,7 @@ pub struct ArrowFunctionExpression {
1045 #[serde(default)]
1046 pub range: Option<SourceRange>,
1047 }
1048 +impl ESTreeNode for ArrowFunctionExpression {}
1049 impl Serialize for ArrowFunctionExpression {
1050 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1051 where
@@ -1032,6 +1073,7 @@ pub struct UnaryExpression {
1073 #[serde(default)]
1074 pub range: Option<SourceRange>,
1075 }
1076 +impl ESTreeNode for UnaryExpression {}
1077 impl Serialize for UnaryExpression {
1078 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1079 where
@@ -1057,6 +1099,7 @@ pub struct UpdateExpression {
1099 #[serde(default)]
1100 pub range: Option<SourceRange>,
1101 }
1102 +impl ESTreeNode for UpdateExpression {}
1103 impl Serialize for UpdateExpression {
1104 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1105 where
@@ -1082,6 +1125,7 @@ pub struct BinaryExpression {
1125 #[serde(default)]
1126 pub range: Option<SourceRange>,
1127 }
1128 +impl ESTreeNode for BinaryExpression {}
1129 impl Serialize for BinaryExpression {
1130 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1131 where
@@ -1107,6 +1151,7 @@ pub struct AssignmentExpression {
1151 #[serde(default)]
1152 pub range: Option<SourceRange>,
1153 }
1154 +impl ESTreeNode for AssignmentExpression {}
1155 impl Serialize for AssignmentExpression {
1156 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1157 where
@@ -1132,6 +1177,7 @@ pub struct LogicalExpression {
1177 #[serde(default)]
1178 pub range: Option<SourceRange>,
1179 }
1180 +impl ESTreeNode for LogicalExpression {}
1181 impl Serialize for LogicalExpression {
1182 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1183 where
@@ -1158,6 +1204,7 @@ pub struct MemberExpression {
1204 #[serde(default)]
1205 pub range: Option<SourceRange>,
1206 }
1207 +impl ESTreeNode for MemberExpression {}
1208 impl Serialize for MemberExpression {
1209 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1210 where
@@ -1183,6 +1230,7 @@ pub struct ConditionalExpression {
1230 #[serde(default)]
1231 pub range: Option<SourceRange>,
1232 }
1233 +impl ESTreeNode for ConditionalExpression {}
1234 impl Serialize for ConditionalExpression {
1235 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1236 where
@@ -1207,6 +1255,7 @@ pub struct CallExpression {
1255 #[serde(default)]
1256 pub range: Option<SourceRange>,
1257 }
1258 +impl ESTreeNode for CallExpression {}
1259 impl Serialize for CallExpression {
1260 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1261 where
@@ -1230,6 +1279,7 @@ pub struct NewExpression {
1279 #[serde(default)]
1280 pub range: Option<SourceRange>,
1281 }
1282 +impl ESTreeNode for NewExpression {}
1283 impl Serialize for NewExpression {
1284 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1285 where
@@ -1252,6 +1302,7 @@ pub struct SequenceExpression {
1302 #[serde(default)]
1303 pub range: Option<SourceRange>,
1304 }
1305 +impl ESTreeNode for SequenceExpression {}
1306 impl Serialize for SequenceExpression {
1307 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1308 where
@@ -1272,6 +1323,7 @@ pub struct Super {
1323 #[serde(default)]
1324 pub range: Option<SourceRange>,
1325 }
1326 +impl ESTreeNode for Super {}
1327 impl Serialize for Super {
1328 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1329 where
@@ -1292,6 +1344,7 @@ pub struct SpreadElement {
1344 #[serde(default)]
1345 pub range: Option<SourceRange>,
1346 }
1347 +impl ESTreeNode for SpreadElement {}
1348 impl Serialize for SpreadElement {
1349 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1350 where
@@ -1316,6 +1369,7 @@ pub struct YieldExpression {
1369 #[serde(default)]
1370 pub range: Option<SourceRange>,
1371 }
1372 +impl ESTreeNode for YieldExpression {}
1373 impl Serialize for YieldExpression {
1374 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1375 where
@@ -1339,6 +1393,7 @@ pub struct ImportDeclaration {
1393 #[serde(default)]
1394 pub range: Option<SourceRange>,
1395 }
1396 +impl ESTreeNode for ImportDeclaration {}
1397 impl Serialize for ImportDeclaration {
1398 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1399 where
@@ -1362,6 +1417,7 @@ pub struct ImportSpecifier {
1417 #[serde(default)]
1418 pub range: Option<SourceRange>,
1419 }
1420 +impl ESTreeNode for ImportSpecifier {}
1421 impl Serialize for ImportSpecifier {
1422 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1423 where
@@ -1384,6 +1440,7 @@ pub struct ImportDefaultSpecifier {
1440 #[serde(default)]
1441 pub range: Option<SourceRange>,
1442 }
1443 +impl ESTreeNode for ImportDefaultSpecifier {}
1444 impl Serialize for ImportDefaultSpecifier {
1445 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1446 where
@@ -1405,6 +1462,7 @@ pub struct ImportNamespaceSpecifier {
1462 #[serde(default)]
1463 pub range: Option<SourceRange>,
1464 }
1465 +impl ESTreeNode for ImportNamespaceSpecifier {}
1466 impl Serialize for ImportNamespaceSpecifier {
1467 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1468 where
@@ -1428,6 +1486,7 @@ pub struct ExportNamedDeclaration {
1486 #[serde(default)]
1487 pub range: Option<SourceRange>,
1488 }
1489 +impl ESTreeNode for ExportNamedDeclaration {}
1490 impl Serialize for ExportNamedDeclaration {
1491 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1492 where
@@ -1451,6 +1510,7 @@ pub struct ExportSpecifier {
1510 #[serde(default)]
1511 pub range: Option<SourceRange>,
1512 }
1513 +impl ESTreeNode for ExportSpecifier {}
1514 impl Serialize for ExportSpecifier {
1515 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1516 where
@@ -1472,6 +1532,7 @@ pub struct ExportDefaultDeclaration {
1532 #[serde(default)]
1533 pub range: Option<SourceRange>,
1534 }
1535 +impl ESTreeNode for ExportDefaultDeclaration {}
1536 impl Serialize for ExportDefaultDeclaration {
1537 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1538 where
@@ -1495,6 +1556,7 @@ pub struct ExportAllDeclaration {
1556 #[serde(default)]
1557 pub range: Option<SourceRange>,
1558 }
1559 +impl ESTreeNode for ExportAllDeclaration {}
1560 impl Serialize for ExportAllDeclaration {
1561 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1562 where
@@ -1520,6 +1582,7 @@ pub struct JSXIdentifier {
1582 #[serde(default)]
1583 pub range: Option<SourceRange>,
1584 }
1585 +impl ESTreeNode for JSXIdentifier {}
1586 impl Serialize for JSXIdentifier {
1587 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1588 where
@@ -1542,6 +1605,7 @@ pub struct JSXNamespacedName {
1605 #[serde(default)]
1606 pub range: Option<SourceRange>,
1607 }
1608 +impl ESTreeNode for JSXNamespacedName {}
1609 impl Serialize for JSXNamespacedName {
1610 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1611 where
@@ -1565,6 +1629,7 @@ pub struct JSXMemberExpression {
1629 #[serde(default)]
1630 pub range: Option<SourceRange>,
1631 }
1632 +impl ESTreeNode for JSXMemberExpression {}
1633 impl Serialize for JSXMemberExpression {
1634 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1635 where
@@ -1586,6 +1651,7 @@ pub struct JSXEmptyExpression {
1651 #[serde(default)]
1652 pub range: Option<SourceRange>,
1653 }
1654 +impl ESTreeNode for JSXEmptyExpression {}
1655 impl Serialize for JSXEmptyExpression {
1656 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1657 where
@@ -1606,6 +1672,7 @@ pub struct JSXExpressionContainer {
1672 #[serde(default)]
1673 pub range: Option<SourceRange>,
1674 }
1675 +impl ESTreeNode for JSXExpressionContainer {}
1676 impl Serialize for JSXExpressionContainer {
1677 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1678 where
@@ -1627,6 +1694,7 @@ pub struct JSXSpreadChild {
1694 #[serde(default)]
1695 pub range: Option<SourceRange>,
1696 }
1697 +impl ESTreeNode for JSXSpreadChild {}
1698 impl Serialize for JSXSpreadChild {
1699 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1700 where
@@ -1651,6 +1719,7 @@ pub struct JSXOpeningElement {
1719 #[serde(default)]
1720 pub range: Option<SourceRange>,
1721 }
1722 +impl ESTreeNode for JSXOpeningElement {}
1723 impl Serialize for JSXOpeningElement {
1724 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1725 where
@@ -1674,6 +1743,7 @@ pub struct JSXClosingElement {
1743 #[serde(default)]
1744 pub range: Option<SourceRange>,
1745 }
1746 +impl ESTreeNode for JSXClosingElement {}
1747 impl Serialize for JSXClosingElement {
1748 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1749 where
@@ -1696,6 +1766,7 @@ pub struct JSXAttribute {
1766 #[serde(default)]
1767 pub range: Option<SourceRange>,
1768 }
1769 +impl ESTreeNode for JSXAttribute {}
1770 impl Serialize for JSXAttribute {
1771 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1772 where
@@ -1718,6 +1789,7 @@ pub struct JSXSpreadAttribute {
1789 #[serde(default)]
1790 pub range: Option<SourceRange>,
1791 }
1792 +impl ESTreeNode for JSXSpreadAttribute {}
1793 impl Serialize for JSXSpreadAttribute {
1794 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1795 where
@@ -1740,6 +1812,7 @@ pub struct JSXText {
1812 #[serde(default)]
1813 pub range: Option<SourceRange>,
1814 }
1815 +impl ESTreeNode for JSXText {}
1816 impl Serialize for JSXText {
1817 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1818 where
@@ -1763,6 +1836,7 @@ pub struct JSXStringLiteral {
1836 #[serde(default)]
1837 pub range: Option<SourceRange>,
1838 }
1839 +impl ESTreeNode for JSXStringLiteral {}
1840 impl Serialize for JSXStringLiteral {
1841 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1842 where
@@ -1789,6 +1863,7 @@ pub struct JSXElement {
1863 #[serde(default)]
1864 pub range: Option<SourceRange>,
1865 }
1866 +impl ESTreeNode for JSXElement {}
1867 impl Serialize for JSXElement {
1868 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1869 where
@@ -1816,6 +1891,7 @@ pub struct JSXFragment {
1891 #[serde(default)]
1892 pub range: Option<SourceRange>,
1893 }
1894 +impl ESTreeNode for JSXFragment {}
1895 impl Serialize for JSXFragment {
1896 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1897 where
@@ -1838,6 +1914,7 @@ pub struct JSXOpeningFragment {
1914 #[serde(default)]
1915 pub range: Option<SourceRange>,
1916 }
1917 +impl ESTreeNode for JSXOpeningFragment {}
1918 impl Serialize for JSXOpeningFragment {
1919 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1920 where
@@ -1857,6 +1934,7 @@ pub struct JSXClosingFragment {
1934 #[serde(default)]
1935 pub range: Option<SourceRange>,
1936 }
1937 +impl ESTreeNode for JSXClosingFragment {}
1938 impl Serialize for JSXClosingFragment {
1939 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1940 where
@@ -1877,6 +1955,7 @@ pub struct ArrayPattern {
1955 #[serde(default)]
1956 pub range: Option<SourceRange>,
1957 }
1958 +impl ESTreeNode for ArrayPattern {}
1959 impl Serialize for ArrayPattern {
1960 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1961 where
@@ -1898,6 +1977,7 @@ pub struct ObjectPattern {
1977 #[serde(default)]
1978 pub range: Option<SourceRange>,
1979 }
1980 +impl ESTreeNode for ObjectPattern {}
1981 impl Serialize for ObjectPattern {
1982 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1983 where
@@ -1922,6 +2002,7 @@ pub struct AssignmentProperty {
2002 #[serde(default)]
2003 pub range: Option<SourceRange>,
2004 }
2005 +impl ESTreeNode for AssignmentProperty {}
2006 impl Serialize for AssignmentProperty {
2007 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2008 where
@@ -1946,6 +2027,7 @@ pub struct RestElement {
2027 #[serde(default)]
2028 pub range: Option<SourceRange>,
2029 }
2030 +impl ESTreeNode for RestElement {}
2031 impl Serialize for RestElement {
2032 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2033 where
@@ -1968,6 +2050,7 @@ pub struct AssignmentPattern {
2050 #[serde(default)]
2051 pub range: Option<SourceRange>,
2052 }
2053 +impl ESTreeNode for AssignmentPattern {}
2054 impl Serialize for AssignmentPattern {
2055 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2056 where
@@ -1991,6 +2074,7 @@ pub struct TemplateLiteral {
2074 #[serde(default)]
2075 pub range: Option<SourceRange>,
2076 }
2077 +impl ESTreeNode for TemplateLiteral {}
2078 impl Serialize for TemplateLiteral {
2079 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2080 where
@@ -2014,6 +2098,7 @@ pub struct TemplateElement {
2098 #[serde(default)]
2099 pub range: Option<SourceRange>,
2100 }
2101 +impl ESTreeNode for TemplateElement {}
2102 impl Serialize for TemplateElement {
2103 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2104 where
@@ -2037,6 +2122,7 @@ pub struct TaggedTemplateExpression {
2122 #[serde(default)]
2123 pub range: Option<SourceRange>,
2124 }
2125 +impl ESTreeNode for TaggedTemplateExpression {}
2126 impl Serialize for TaggedTemplateExpression {
2127 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2128 where
@@ -2060,6 +2146,7 @@ pub struct MetaProperty {
2146 #[serde(default)]
2147 pub range: Option<SourceRange>,
2148 }
2149 +impl ESTreeNode for MetaProperty {}
2150 impl Serialize for MetaProperty {
2151 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2152 where
@@ -2082,6 +2169,7 @@ pub struct AwaitExpression {
2169 #[serde(default)]
2170 pub range: Option<SourceRange>,
2171 }
2172 +impl ESTreeNode for AwaitExpression {}
2173 impl Serialize for AwaitExpression {
2174 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2175 where
@@ -2103,6 +2191,7 @@ pub struct ChainExpression {
2191 #[serde(default)]
2192 pub range: Option<SourceRange>,
2193 }
2194 +impl ESTreeNode for ChainExpression {}
2195 impl Serialize for ChainExpression {
2196 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2197 where
@@ -2130,6 +2219,7 @@ pub struct OptionalMemberExpression {
2219 #[serde(default)]
2220 pub range: Option<SourceRange>,
2221 }
2222 +impl ESTreeNode for OptionalMemberExpression {}
2223 impl Serialize for OptionalMemberExpression {
2224 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2225 where
@@ -2158,6 +2248,7 @@ pub struct OptionalCallExpression {
2248 #[serde(default)]
2249 pub range: Option<SourceRange>,
2250 }
2251 +impl ESTreeNode for OptionalCallExpression {}
2252 impl Serialize for OptionalCallExpression {
2253 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2254 where
@@ -2181,6 +2272,7 @@ pub struct ImportExpression {
2272 #[serde(default)]
2273 pub range: Option<SourceRange>,
2274 }
2275 +impl ESTreeNode for ImportExpression {}
2276 impl Serialize for ImportExpression {
2277 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2278 where
@@ -2208,6 +2300,7 @@ pub struct ClassProperty {
2300 #[serde(default)]
2301 pub range: Option<SourceRange>,
2302 }
2303 +impl ESTreeNode for ClassProperty {}
2304 impl Serialize for ClassProperty {
2305 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2306 where
@@ -2236,6 +2329,7 @@ pub struct ClassPrivateProperty {
2329 #[serde(default)]
2330 pub range: Option<SourceRange>,
2331 }
2332 +impl ESTreeNode for ClassPrivateProperty {}
2333 impl Serialize for ClassPrivateProperty {
2334 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2335 where
@@ -2259,6 +2353,7 @@ pub struct PrivateName {
2353 #[serde(default)]
2354 pub range: Option<SourceRange>,
2355 }
2356 +impl ESTreeNode for PrivateName {}
2357 impl Serialize for PrivateName {
2358 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2359 where
@@ -2280,6 +2375,7 @@ pub struct PrivateIdentifier {
2375 #[serde(default)]
2376 pub range: Option<SourceRange>,
2377 }
2378 +impl ESTreeNode for PrivateIdentifier {}
2379 impl Serialize for PrivateIdentifier {
2380 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2381 where
@@ -2301,6 +2397,7 @@ pub struct StaticBlock {
2397 #[serde(default)]
2398 pub range: Option<SourceRange>,
2399 }
2400 +impl ESTreeNode for StaticBlock {}
2401 impl Serialize for StaticBlock {
2402 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2403 where
@@ -2323,6 +2420,7 @@ pub struct CoverTypedIdentifier {
2420 #[serde(default)]
2421 pub range: Option<SourceRange>,
2422 }
2423 +impl ESTreeNode for CoverTypedIdentifier {}
2424 impl Serialize for CoverTypedIdentifier {
2425 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2426 where
@@ -2344,6 +2442,7 @@ pub struct TSTypeAnnotation {
2442 #[serde(default)]
2443 pub range: Option<SourceRange>,
2444 }
2445 +impl ESTreeNode for TSTypeAnnotation {}
2446 impl Serialize for TSTypeAnnotation {
2447 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2448 where
@@ -2363,6 +2462,7 @@ pub struct TSTypeAliasDeclaration {
2462 #[serde(default)]
2463 pub range: Option<SourceRange>,
2464 }
2465 +impl ESTreeNode for TSTypeAliasDeclaration {}
2466 impl Serialize for TSTypeAliasDeclaration {
2467 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2468 where
compiler/forget/crates/forget_estree/src/generated_extensions.rs
+3
@@ -1,6 +1,9 @@
1 // Manual extensions to generated types
2 use crate::{Pattern, SourceRange, SourceType};
3
4 +/// Sentinel trait to distinguish AST *node* types
5 +pub trait ESTreeNode {}
6 +
7 impl Default for SourceType {
8 fn default() -> Self {
9 Self::Script
compiler/forget/crates/forget_estree/src/lib.rs
+1
@@ -7,6 +7,7 @@ mod visit;
7
8 pub use binding::{Binding, BindingId};
9 pub use generated::*;
10 +pub use generated_extensions::ESTreeNode;
11 pub use js_value::{JsValue, Number};
12 pub use range::SourceRange;
13 pub use visit::*;
compiler/forget/crates/forget_estree_codegen/src/codegen.rs
+3 -1
@@ -74,7 +74,7 @@ impl Grammar {
74 use std::num::NonZeroU32;
75 use serde::ser::{Serializer, SerializeMap};
76 use serde::{Serialize,Deserialize};
77 - use crate::{JsValue, Binding, SourceRange, Number};
77 + use crate::{JsValue, Binding, SourceRange, Number, ESTreeNode};
78
79 #(#objects)*
80
@@ -221,6 +221,8 @@ impl Node {
221 pub range: Option<SourceRange>,
222 }
223
224 + impl ESTreeNode for #name {}
225 +
226 impl Serialize for #name {
227 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
228 where
compiler/forget/crates/forget_semantic_analysis/Cargo.toml new
+16
@@ -0,0 +1,16 @@
1 +[package]
2 +name = "forget_semantic_analysis"
3 +version = "0.1.0"
4 +authors.workspace = true
5 +description.workspace = true
6 +edition.workspace = true
7 +homepage.workspace = true
8 +keywords.workspace = true
9 +license.workspace = true
10 +repository.workspace = true
11 +
12 +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13 +
14 +[dependencies]
15 +forget_estree = { workspace = true }
16 +forget_utils = { workspace = true }
\ No newline at end of file
compiler/forget/crates/forget_semantic_analysis/README.md new
+6
@@ -0,0 +1,6 @@
1 +# forget_semantic_analysis
2 +
3 +Implements semantic analysis of JavaScript name resolution and scope information over the `forget_estree` AST. Eventually this
4 +analysis will be extended to cover Flow and TypeScript in addition to the core JS and JSX language.
5 +
6 +NOTE: this analsyis *assumes strict mode* and does not support legacy non-strict semantics.
\ No newline at end of file
compiler/forget/crates/forget_semantic_analysis/src/lib.rs new
+52
@@ -0,0 +1,52 @@
1 +use std::collections::HashMap;
2 +
3 +use forget_estree::{ESTreeNode, Identifier, Program};
4 +use forget_utils::PointerAddress;
5 +
6 +pub fn analyze<'ast>(ast: &'ast Program) -> SemanticAnalysis {
7 + todo!("Actually analyze code")
8 +}
9 +
10 +#[derive(Default, Debug)]
11 +pub struct SemanticAnalysis {
12 + scopes: HashMap<AstNode, Scope>,
13 + references: HashMap<AstNode, Reference>,
14 +}
15 +
16 +impl SemanticAnalysis {
17 + pub(crate) fn new() -> Self {
18 + Default::default()
19 + }
20 +
21 + fn scope<T: ESTreeNode>(&self, node: &T) -> Option<&Scope> {
22 + self.scopes.get(&node.into())
23 + }
24 +
25 + fn reference(&self, identifier: &Identifier) -> Option<&Reference> {
26 + self.references.get(&identifier.into())
27 + }
28 +}
29 +
30 +#[derive(Debug)]
31 +pub struct Scope {}
32 +
33 +#[derive(Debug)]
34 +pub struct Reference {}
35 +
36 +#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
37 +struct AstNode(PointerAddress);
38 +
39 +impl AstNode {
40 + fn new<T: ESTreeNode>(node: &T) -> Self {
41 + Self(PointerAddress::new(node))
42 + }
43 +}
44 +
45 +impl<T> From<&T> for AstNode
46 +where
47 + T: ESTreeNode,
48 +{
49 + fn from(value: &T) -> Self {
50 + Self::new(value)
51 + }
52 +}
compiler/forget/crates/forget_utils/src/lib.rs
+2
@@ -1,3 +1,5 @@
1 mod ensure_sufficient_stack;
2 +mod pointer_address;
3
4 pub use ensure_sufficient_stack::*;
5 +pub use pointer_address::PointerAddress;
compiler/forget/crates/forget_utils/src/pointer_address.rs new
+28
@@ -0,0 +1,28 @@
1 +/*
2 + * Copyright (c) Meta Platforms, Inc. and affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + */
7 +
8 +/// A wrapper type that allows comparing pointer equality of references. Two
9 +/// `PointerAddress` values are equal if they point to the same memory location.
10 +///
11 +/// This type is _sound_, but misuse can easily lead to logical bugs if the memory
12 +/// of one PointerAddress could have been freed and reused for a subsequent
13 +/// PointerAddress.
14 +#[derive(Hash, Eq, PartialEq, Clone, Copy)]
15 +pub struct PointerAddress(usize);
16 +
17 +impl PointerAddress {
18 + pub fn new<T>(ptr: &T) -> Self {
19 + let ptr_address: usize = unsafe { std::mem::transmute(ptr) };
20 + Self(ptr_address)
21 + }
22 +}
23 +
24 +impl std::fmt::Debug for PointerAddress {
25 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 + f.write_fmt(format_args!("{:#X}", self.0))
27 + }
28 +}