@samitouri / QOS-React-2 / commits / 6c425f6b36

Remove codeframe/nodepath options from CompilerError

These were effectively unused since we almost always passed in null when creating errors, so remove them and instead pass in a `loc` explicitly. The downside is that we no longer will see Babel codeframes in our test fixtures, which doesn't seem like a huge loss

Lauren Tan committed Jun 22, 2023 at 10:18 UTC 6c425f6b369bfc6b31a9d7931b358ec3c42f30b1
15 files changed +117 -380
compiler/forget/apps/playground/lib/forgetMonacoDiagnostics.ts
+1 -1
@@ -30,7 +30,7 @@ function mapForgetDiagnosticToMonacoMarker(
30 detail: CompilerErrorDetail,
31 monaco: Monaco
32 ): editor.IMarkerData | null {
33 - if (detail.loc == null) {
33 + if (detail.loc == null || typeof detail.loc === "symbol") {
34 return null;
35 }
36 const severity = mapForgetSeverityToMonaco(detail.severity, monaco);
compiler/forget/packages/babel-plugin-react-forget/src/CompilerError.ts
+7 -68
@@ -5,8 +5,6 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import type { Node, NodePath } from "@babel/traverse";
9 -import type { SourceLocation as BabelSourceLocation } from "@babel/types";
8 import type { SourceLocation } from "./HIR";
9 import type { ExtractClassProperties } from "./Utils/types";
10 import { assertExhaustive } from "./Utils/utils";
@@ -31,60 +29,10 @@ export type CompilerErrorOptions = {
29 reason: string;
30 description?: string | null | undefined;
31 severity: ErrorSeverity;
34 - nodePath: AnyNodePath | null;
32 + loc: SourceLocation | null;
33 };
36 -type AnyNodePath = NodePath<Node | null | undefined>;
37 -type CompilerErrorKind = typeof InvalidInputError | typeof TodoError;
34 type CompilerErrorDetailOptions = ExtractClassProperties<CompilerErrorDetail>;
35
40 -function mapSeverityToErrorCtor(severity: ErrorSeverity): CompilerErrorKind {
41 - switch (severity) {
42 - case ErrorSeverity.InvalidInput:
43 - return InvalidInputError;
44 - case ErrorSeverity.Todo:
45 - return TodoError;
46 - case ErrorSeverity.Invariant:
47 - return InvariantError;
48 - default:
49 - assertExhaustive(severity, `Unhandled severity level: ${severity}`);
50 - }
51 -}
52 -class InvalidInputError extends Error {
53 - constructor(message: string) {
54 - super(message);
55 - this.name = `${ErrorSeverity.InvalidInput}Error`;
56 - }
57 -}
58 -class TodoError extends Error {
59 - constructor(message: string) {
60 - super(message);
61 - this.name = `${ErrorSeverity.Todo}Error`;
62 - }
63 -}
64 -class InvariantError extends Error {
65 - constructor(message: string) {
66 - super(message);
67 - this.name = `${ErrorSeverity.Invariant}Error`;
68 - }
69 -}
70 -
71 -export function tryPrintCodeFrame(
72 - options: CompilerErrorOptions
73 -): string | null {
74 - if (options.nodePath == null) return null;
75 - try {
76 - return options.nodePath
77 - .buildCodeFrameError(
78 - options.reason +
79 - (options.description != null ? `. ${options.description}` : ""),
80 - mapSeverityToErrorCtor(options.severity)
81 - )
82 - .toString();
83 - } catch {
84 - return null;
85 - }
86 -}
87 -
36 /**
37 * Each bailout or invariant in HIR lowering creates an {@link CompilerErrorDetail}, which is then
38 * aggregated into a single {@link CompilerError} later.
@@ -93,26 +41,21 @@ export class CompilerErrorDetail {
41 reason: string;
42 description: string | null;
43 severity: ErrorSeverity;
96 - codeframe: string | null;
97 - loc: BabelSourceLocation | null;
44 + loc: SourceLocation | null;
45
46 constructor(options: CompilerErrorDetailOptions) {
47 this.reason = options.reason;
48 this.description = options.description;
49 this.severity = options.severity;
103 - this.codeframe = options.codeframe;
50 this.loc = options.loc;
51 }
52
53 printErrorMessage(): string {
108 - if (this.codeframe != null) {
109 - return this.codeframe;
110 - }
54 const buffer = [`${this.severity}: ${this.reason}`];
55 if (this.description !== null) {
56 buffer.push(`. ${this.description}`);
57 }
115 - if (this.loc != null) {
58 + if (this.loc != null && typeof this.loc !== "symbol") {
59 buffer.push(` (${this.loc.start.line}:${this.loc.end.line})`);
60 }
61 return buffer.join("");
@@ -134,9 +77,8 @@ export class CompilerError extends Error {
77 const errors = new CompilerError();
78 errors.pushErrorDetail(
79 new CompilerErrorDetail({
137 - codeframe: null,
80 description,
139 - loc: typeof loc === "symbol" ? null : loc,
81 + loc,
82 reason,
83 severity: ErrorSeverity.Invariant,
84 })
@@ -152,9 +94,8 @@ export class CompilerError extends Error {
94 const errors = new CompilerError();
95 errors.pushErrorDetail(
96 new CompilerErrorDetail({
155 - codeframe: null,
97 description,
157 - loc: typeof loc === "symbol" ? null : loc,
98 + loc,
99 reason,
100 severity: ErrorSeverity.Todo,
101 })
@@ -170,9 +111,8 @@ export class CompilerError extends Error {
111 const errors = new CompilerError();
112 errors.pushErrorDetail(
113 new CompilerErrorDetail({
173 - codeframe: null,
114 description,
175 - loc: typeof loc === "symbol" ? null : loc,
115 + loc,
116 reason,
117 severity: ErrorSeverity.InvalidInput,
118 })
@@ -200,8 +140,7 @@ export class CompilerError extends Error {
140 reason: options.reason,
141 description: options.description ?? null,
142 severity: options.severity,
203 - codeframe: tryPrintCodeFrame(options),
204 - loc: options.nodePath?.node?.loc ?? null,
143 + loc: typeof options.loc === "symbol" ? null : options.loc,
144 });
145 return this.pushErrorDetail(detail);
146 }
compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
-4
@@ -213,7 +213,6 @@ export function compileProgram(
213 reason,
214 description: violation.value.trim(),
215 severity: ErrorSeverity.InvalidInput,
216 - codeframe: null,
216 loc: violation.loc ?? null,
217 })
218 );
@@ -359,7 +358,6 @@ function buildFunctionDeclaration(
358 "ArrowFunctionExpression was not declared in a variable declaration",
359 severity: ErrorSeverity.Todo,
360 description: `Handle ${fn.parentPath.type}`,
362 - codeframe: null,
361 loc: fn.node.loc ?? null,
362 });
363 }
@@ -370,7 +368,6 @@ function buildFunctionDeclaration(
368 reason: "ArrowFunctionExpression was not a single declaration",
369 severity: ErrorSeverity.Todo,
370 description: `Handle ${variableDeclarator.parentPath.type}`,
373 - codeframe: null,
371 loc: fn.node.loc ?? null,
372 });
373 }
@@ -382,7 +379,6 @@ function buildFunctionDeclaration(
379 reason: "ArrowFunctionExpression was not an identifier",
380 severity: ErrorSeverity.Todo,
381 description: `Handle ${id.type}`,
385 - codeframe: null,
382 loc: fn.node.loc ?? null,
383 });
384 }
compiler/forget/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts
+54 -54
@@ -88,7 +88,7 @@ export function lower(
88 builder.errors.push({
89 reason: `(BuildHIR::lower) Could not find binding for param '${param.node.name}'`,
90 severity: ErrorSeverity.Invariant,
91 - nodePath: param,
91 + loc: param.node.loc ?? null,
92 });
93 return;
94 }
@@ -122,7 +122,7 @@ export function lower(
122 builder.errors.push({
123 reason: `(BuildHIR::lower) Handle ${param.node.type} params`,
124 severity: ErrorSeverity.Todo,
125 - nodePath: param,
125 + loc: param.node.loc ?? null,
126 });
127 }
128 });
@@ -143,7 +143,7 @@ export function lower(
143 builder.errors.push({
144 reason: `(BuildHIR::lower) Unexpected function body kind: ${body.type}}`,
145 severity: ErrorSeverity.InvalidInput,
146 - nodePath: body,
146 + loc: body.node.loc ?? null,
147 });
148 }
149
@@ -320,7 +320,7 @@ function lowerStatement(
320 reason:
321 "(BuildHIR::lowerStatement) Handle non-variable initialization in ForStatement",
322 severity: ErrorSeverity.Todo,
323 - nodePath: stmt,
323 + loc: stmt.node.loc ?? null,
324 });
325 return {
326 kind: "unsupported",
@@ -391,7 +391,7 @@ function lowerStatement(
391 builder.errors.push({
392 reason: `(BuildHIR::lowerStatement) Handle empty test in ForStatement`,
393 severity: ErrorSeverity.Todo,
394 - nodePath: stmt,
394 + loc: stmt.node.loc ?? null,
395 });
396 } else {
397 builder.terminateWithContinuation(
@@ -540,7 +540,7 @@ function lowerStatement(
540 reason:
541 "(BuildHIR::lowerStatement) Expected at most one `default` branch in SwitchStatement, this code should have failed to parse",
542 severity: ErrorSeverity.InvalidInput,
543 - nodePath: case_,
543 + loc: case_.node.loc ?? null,
544 });
545 break;
546 }
@@ -614,7 +614,7 @@ function lowerStatement(
614 builder.errors.push({
615 reason: `(BuildHIR::lowerStatement) Handle ${nodeKind} kinds in VariableDeclaration`,
616 severity: ErrorSeverity.Todo,
617 - nodePath: stmt,
617 + loc: stmt.node.loc ?? null,
618 });
619 return;
620 }
@@ -641,7 +641,7 @@ function lowerStatement(
641 builder.errors.push({
642 reason: `(BuildHIR::lowerAssignment) Could not find binding for declaration.`,
643 severity: ErrorSeverity.Invariant,
644 - nodePath: id,
644 + loc: id.node.loc ?? null,
645 });
646 } else {
647 const place: Place = {
@@ -655,7 +655,7 @@ function lowerStatement(
655 builder.errors.push({
656 reason: `(BuildHIR::lowerAssignment) Invalid declaration kind (const) for variable later reassigned.`,
657 severity: ErrorSeverity.InvalidInput,
658 - nodePath: id,
658 + loc: id.node.loc ?? null,
659 });
660 }
661 lowerValueToTemporary(builder, {
@@ -681,7 +681,7 @@ function lowerStatement(
681 builder.errors.push({
682 reason: `(BuildHIR::lowerStatement) Expected variable declaration to be an identifier if no initializer was provided.`,
683 severity: ErrorSeverity.InvalidInput,
684 - nodePath: stmt,
684 + loc: stmt.node.loc ?? null,
685 });
686 }
687 }
@@ -865,7 +865,7 @@ function lowerStatement(
865 builder.errors.push({
866 reason: `(BuildHIR::lowerStatement) Handle ${left.type} inits in ForOfStatement`,
867 severity: ErrorSeverity.Todo,
868 - nodePath: left,
868 + loc: left.node.loc ?? null,
869 });
870 return;
871 }
@@ -932,7 +932,7 @@ function lowerStatement(
932 builder.errors.push({
933 reason: `(BuildHIR::lowerStatement) Handle ${stmtPath.type} statements`,
934 severity: ErrorSeverity.Todo,
935 - nodePath: stmtPath,
935 + loc: stmtPath.node.loc ?? null,
936 });
937 lowerValueToTemporary(builder, {
938 kind: "UnsupportedNode",
@@ -1004,7 +1004,7 @@ function lowerExpression(
1004 builder.errors.push({
1005 reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
1006 severity: ErrorSeverity.InvalidInput,
1007 - nodePath: propertyPath,
1007 + loc: propertyPath.node.loc ?? null,
1008 });
1009 continue;
1010 }
@@ -1013,7 +1013,7 @@ function lowerExpression(
1013 builder.errors.push({
1014 reason: `(BuildHIR::lowerExpression) Handle ${valuePath.type} values in ObjectExpression`,
1015 severity: ErrorSeverity.Todo,
1016 - nodePath: valuePath,
1016 + loc: valuePath.node.loc ?? null,
1017 });
1018 continue;
1019 }
@@ -1036,7 +1036,7 @@ function lowerExpression(
1036 builder.errors.push({
1037 reason: `(BuildHIR::lowerExpression) Handle ${propertyPath.type} properties in ObjectExpression`,
1038 severity: ErrorSeverity.Todo,
1039 - nodePath: propertyPath,
1039 + loc: propertyPath.node.loc ?? null,
1040 });
1041 continue;
1042 }
@@ -1055,7 +1055,7 @@ function lowerExpression(
1055 builder.errors.push({
1056 reason: `(BuildHIR::lowerExpression) Handle ${element.type} elements in ArrayExpression`,
1057 severity: ErrorSeverity.Todo,
1058 - nodePath: element,
1058 + loc: null,
1059 });
1060 continue;
1061 } else if (element.isExpression()) {
@@ -1070,7 +1070,7 @@ function lowerExpression(
1070 builder.errors.push({
1071 reason: `(BuildHIR::lowerExpression) Handle ${element.type} elements in ArrayExpression`,
1072 severity: ErrorSeverity.Todo,
1073 - nodePath: element,
1073 + loc: element.node.loc ?? null,
1074 });
1075 continue;
1076 }
@@ -1088,7 +1088,7 @@ function lowerExpression(
1088 builder.errors.push({
1089 reason: `(BuildHIR::lowerExpression) Expected Expression, got ${calleePath.type} in NewExpression (v8 intrinsics not supported): ${calleePath.type}`,
1090 severity: ErrorSeverity.InvalidInput,
1091 - nodePath: calleePath,
1091 + loc: calleePath.node.loc ?? null,
1092 });
1093 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1094 }
@@ -1113,7 +1113,7 @@ function lowerExpression(
1113 builder.errors.push({
1114 reason: `(BuildHIR::lowerExpression) Expected Expression, got ${calleePath.type} in CallExpression (v8 intrinsics not supported)`,
1115 severity: ErrorSeverity.InvalidInput,
1116 - nodePath: calleePath,
1116 + loc: calleePath.node.loc ?? null,
1117 });
1118 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1119 }
@@ -1146,7 +1146,7 @@ function lowerExpression(
1146 builder.errors.push({
1147 reason: `(BuildHIR::lowerExpression) Expected Expression, got ${leftPath.type} lval in BinaryExpression`,
1148 severity: ErrorSeverity.InvalidInput,
1149 - nodePath: leftPath,
1149 + loc: leftPath.node.loc ?? null,
1150 });
1151 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1152 }
@@ -1177,7 +1177,7 @@ function lowerExpression(
1177 builder.errors.push({
1178 reason: `(BuildHIR::lowerExpression) Expected SequenceExpression to have at least one expression`,
1179 severity: ErrorSeverity.InvalidInput,
1180 - nodePath: expr,
1180 + loc: expr.node.loc ?? null,
1181 });
1182 } else {
1183 lowerValueToTemporary(builder, {
@@ -1388,7 +1388,7 @@ function lowerExpression(
1388 builder.errors.push({
1389 reason: `(BuildHIR::lowerExpression) Handle ${operator} operators in AssignmentExpression`,
1390 severity: ErrorSeverity.Todo,
1391 - nodePath: expr.get("operator"),
1391 + loc: expr.node.loc ?? null,
1392 });
1393 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1394 }
@@ -1460,7 +1460,7 @@ function lowerExpression(
1460 builder.errors.push({
1461 reason: `(BuildHIR::lowerExpression) Expected Identifier or MemberExpression, got ${expr.type} lval in AssignmentExpression`,
1462 severity: ErrorSeverity.InvalidInput,
1463 - nodePath: expr,
1463 + loc: expr.node.loc ?? null,
1464 });
1465 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1466 }
@@ -1501,7 +1501,7 @@ function lowerExpression(
1501 builder.errors.push({
1502 reason: `(BuildHIR::lowerExpression) Handle ${attribute.type} attributes in JSXElement`,
1503 severity: ErrorSeverity.Todo,
1504 - nodePath: attribute,
1504 + loc: attribute.node.loc ?? null,
1505 });
1506 continue;
1507 }
@@ -1513,7 +1513,7 @@ function lowerExpression(
1513 builder.errors.push({
1514 reason: `(BuildHIR::lowerExpression) Unexpected colon in attribute name '${name}'`,
1515 severity: ErrorSeverity.Todo,
1516 - nodePath: namePath,
1516 + loc: namePath.node.loc ?? null,
1517 });
1518 }
1519 } else {
@@ -1531,7 +1531,7 @@ function lowerExpression(
1531 builder.errors.push({
1532 reason: `(BuildHIR::lowerExpression) Handle ${valueExpr.type} attribute values in JSXElement`,
1533 severity: ErrorSeverity.Todo,
1534 - nodePath: valueExpr,
1534 + loc: valueExpr.node?.loc ?? null,
1535 });
1536 continue;
1537 }
@@ -1540,7 +1540,7 @@ function lowerExpression(
1540 builder.errors.push({
1541 reason: `(BuildHIR::lowerExpression) Handle ${expression.type} expressions in JSXExpressionContainer within JSXElement`,
1542 severity: ErrorSeverity.Todo,
1543 - nodePath: valueExpr,
1543 + loc: valueExpr.node.loc ?? null,
1544 });
1545 continue;
1546 }
@@ -1582,7 +1582,7 @@ function lowerExpression(
1582 reason:
1583 "(BuildHIR::lowerExpression) Handle tagged template with interpolations",
1584 severity: ErrorSeverity.Todo,
1585 - nodePath: exprPath,
1585 + loc: exprPath.node.loc ?? null,
1586 });
1587 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1588 }
@@ -1596,7 +1596,7 @@ function lowerExpression(
1596 reason:
1597 "(BuildHIR::lowerExpression) Handle tagged template where cooked value is different from raw value",
1598 severity: ErrorSeverity.Todo,
1599 - nodePath: exprPath,
1599 + loc: exprPath.node.loc ?? null,
1600 });
1601 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1602 }
@@ -1617,7 +1617,7 @@ function lowerExpression(
1617 builder.errors.push({
1618 reason: `(BuildHIR::lowerExpression) Unexpected quasi and subexpression lengths in TemplateLiteral.`,
1619 severity: ErrorSeverity.InvalidInput,
1620 - nodePath: exprPath,
1620 + loc: exprPath.node.loc ?? null,
1621 });
1622 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1623 }
@@ -1626,7 +1626,7 @@ function lowerExpression(
1626 builder.errors.push({
1627 reason: `(BuildHIR::lowerAssignment) Handle TSType in TemplateLiteral.`,
1628 severity: ErrorSeverity.Todo,
1629 - nodePath: exprPath,
1629 + loc: exprPath.node.loc ?? null,
1630 });
1631 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1632 }
@@ -1667,7 +1667,7 @@ function lowerExpression(
1667 builder.errors.push({
1668 reason: `(BuildHIR::lowerExpression) delete on a non-member expression has no semantic meaning`,
1669 severity: ErrorSeverity.InvalidInput,
1670 - nodePath: expr,
1670 + loc: expr.node.loc ?? null,
1671 });
1672 return { kind: "UnsupportedNode", node: expr.node, loc: exprLoc };
1673 }
@@ -1704,7 +1704,7 @@ function lowerExpression(
1704 builder.errors.push({
1705 reason: `(BuildHIR::lowerExpression) Handle UpdateExpression with ${argument.type} argument`,
1706 severity: ErrorSeverity.Todo,
1707 - nodePath: exprPath,
1707 + loc: exprPath.node.loc ?? null,
1708 });
1709 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1710 }
@@ -1712,7 +1712,7 @@ function lowerExpression(
1712 builder.errors.push({
1713 reason: `(BuildHIR::lowerExpression) Handle prefix UpdateExpression`,
1714 severity: ErrorSeverity.Todo,
1715 - nodePath: exprPath,
1715 + loc: exprPath.node.loc ?? null,
1716 });
1717 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1718 }
@@ -1766,7 +1766,7 @@ function lowerExpression(
1766 builder.errors.push({
1767 reason: `(BuildHIR::lowerExpression) Handle ${exprPath.type} expressions`,
1768 severity: ErrorSeverity.Todo,
1769 - nodePath: exprPath,
1769 + loc: exprPath.node.loc ?? null,
1770 });
1771 return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1772 }
@@ -2039,7 +2039,7 @@ function lowerReorderableExpression(
2039 builder.errors.push({
2040 reason: `(BuildHIR::node.lowerReorderableExpression) Expression type '${expr.type}' cannot be safely reordered`,
2041 severity: ErrorSeverity.Todo,
2042 - nodePath: expr,
2042 + loc: expr.node.loc ?? null,
2043 });
2044 }
2045 return lowerExpressionToTemporary(builder, expr);
@@ -2130,7 +2130,7 @@ function lowerArguments(
2130 builder.errors.push({
2131 reason: `(BuildHIR::lowerExpression) Handle ${argPath.type} arguments in CallExpression`,
2132 severity: ErrorSeverity.Todo,
2133 - nodePath: argPath,
2133 + loc: argPath.node.loc ?? null,
2134 });
2135 }
2136 }
@@ -2159,7 +2159,7 @@ function lowerMemberExpression(
2159 builder.errors.push({
2160 reason: `(BuildHIR::lowerMemberExpression) Handle ${propertyNode.type} property`,
2161 severity: ErrorSeverity.Todo,
2162 - nodePath: propertyNode,
2162 + loc: propertyNode.node.loc ?? null,
2163 });
2164 return {
2165 object,
@@ -2179,7 +2179,7 @@ function lowerMemberExpression(
2179 builder.errors.push({
2180 reason: `(BuildHIR::lowerMemberExpression) Expected Expression, got ${propertyNode.type} property`,
2181 severity: ErrorSeverity.InvalidInput,
2182 - nodePath: propertyNode,
2182 + loc: propertyNode.node.loc ?? null,
2183 });
2184 return {
2185 object,
@@ -2235,7 +2235,7 @@ function lowerJsxElementName(
2235 builder.errors.push({
2236 reason: `(BuildHIR::lowerJsxElementName) Expected JSXNamespacedName to have no colons in the namespace or name, got '${namespace}' : '${name}'`,
2237 severity: ErrorSeverity.InvalidInput,
2238 - nodePath: exprPath,
2238 + loc: exprPath.node.loc ?? null,
2239 });
2240 }
2241 const place = lowerValueToTemporary(builder, {
@@ -2248,7 +2248,7 @@ function lowerJsxElementName(
2248 builder.errors.push({
2249 reason: `(BuildHIR::lowerJsxElementName) Handle ${exprPath.type} tags`,
2250 severity: ErrorSeverity.Todo,
2251 - nodePath: exprPath,
2251 + loc: exprPath.node.loc ?? null,
2252 });
2253 return lowerValueToTemporary(builder, {
2254 kind: "UnsupportedNode",
@@ -2321,7 +2321,7 @@ function lowerJsxElement(
2321 builder.errors.push({
2322 reason: `(BuildHIR::lowerJsxElement) Expected refinement to work, got: ${exprPath.type}`,
2323 severity: ErrorSeverity.InvalidInput,
2324 - nodePath: exprPath,
2324 + loc: exprPath.node.loc ?? null,
2325 });
2326 }
2327 const place = lowerValueToTemporary(builder, {
@@ -2474,14 +2474,14 @@ function lowerIdentifierForAssignment(
2474 builder.errors.push({
2475 reason: `(BuildHIR::lowerAssignment) Assigning to an identifier defined outside the function scope is not supported.`,
2476 severity: ErrorSeverity.InvalidInput,
2477 - nodePath: path,
2477 + loc: path.node.loc ?? null,
2478 });
2479 } else {
2480 // Else its an internal error bc we couldn't find the binding
2481 builder.errors.push({
2482 reason: `(BuildHIR::lowerAssignment) Could not find binding for declaration.`,
2483 severity: ErrorSeverity.Invariant,
2484 - nodePath: path,
2484 + loc: path.node.loc ?? null,
2485 });
2486 }
2487 return null;
@@ -2523,7 +2523,7 @@ function lowerAssignment(
2523 builder.errors.push({
2524 reason: `(BuildHIR::lowerAssignment) Invalid declaration kind (const) for variable later reassigned.`,
2525 severity: ErrorSeverity.InvalidInput,
2526 - nodePath: lvalue,
2526 + loc: lvalue.node.loc ?? null,
2527 });
2528 }
2529 lowerValueToTemporary(builder, {
@@ -2566,7 +2566,7 @@ function lowerAssignment(
2566 builder.errors.push({
2567 reason: `(BuildHIR::lowerAssignment) Handle ${property.type} properties in MemberExpression`,
2568 severity: ErrorSeverity.Todo,
2569 - nodePath: property,
2569 + loc: property.node.loc ?? null,
2570 });
2571 return { kind: "UnsupportedNode", node: lvalueNode, loc };
2572 }
@@ -2584,7 +2584,7 @@ function lowerAssignment(
2584 reason:
2585 "(BuildHIR::lowerAssignment) Expected private name to appear as a non-computed property",
2586 severity: ErrorSeverity.InvalidInput,
2587 - nodePath: property,
2587 + loc: property.node.loc ?? null,
2588 });
2589 return { kind: "UnsupportedNode", node: lvalueNode, loc };
2590 }
@@ -2616,7 +2616,7 @@ function lowerAssignment(
2616 builder.errors.push({
2617 reason: `(BuildHIR::lowerAssignment) Handle ${argument.node.type} rest element in ArrayPattern`,
2618 severity: ErrorSeverity.Todo,
2619 - nodePath: element,
2619 + loc: element.node.loc ?? null,
2620 });
2621 continue;
2622 }
@@ -2683,7 +2683,7 @@ function lowerAssignment(
2683 builder.errors.push({
2684 reason: `(BuildHIR::lowerAssignment) Handle ${argument.node.type} rest element in ArrayPattern`,
2685 severity: ErrorSeverity.Todo,
2686 - nodePath: argument,
2686 + loc: argument.node.loc ?? null,
2687 });
2688 continue;
2689 }
@@ -2706,7 +2706,7 @@ function lowerAssignment(
2706 builder.errors.push({
2707 reason: `(BuildHIR::lowerAssignment) Handle ${property.type} properties in ObjectPattern`,
2708 severity: ErrorSeverity.Todo,
2709 - nodePath: property,
2709 + loc: property.node.loc ?? null,
2710 });
2711 continue;
2712 }
@@ -2714,7 +2714,7 @@ function lowerAssignment(
2714 builder.errors.push({
2715 reason: `(BuildHIR::lowerAssignment) Handle computed properties in ObjectPattern`,
2716 severity: ErrorSeverity.Todo,
2717 - nodePath: property,
2717 + loc: property.node.loc ?? null,
2718 });
2719 continue;
2720 }
@@ -2723,7 +2723,7 @@ function lowerAssignment(
2723 builder.errors.push({
2724 reason: `(BuildHIR::lowerAssignment) Handle ${key.type} keys in ObjectPattern`,
2725 severity: ErrorSeverity.Todo,
2726 - nodePath: key,
2726 + loc: key.node.loc ?? null,
2727 });
2728 continue;
2729 }
@@ -2732,7 +2732,7 @@ function lowerAssignment(
2732 builder.errors.push({
2733 reason: `(BuildHIR::lowerAssignment) Expected object property value to be an LVal, got: ${element.type}`,
2734 severity: ErrorSeverity.InvalidInput,
2735 - nodePath: element,
2735 + loc: element.node.loc ?? null,
2736 });
2737 continue;
2738 }
@@ -2867,7 +2867,7 @@ function lowerAssignment(
2867 builder.errors.push({
2868 reason: `(BuildHIR::lowerAssignment) Handle ${lvaluePath.type} assignments`,
2869 severity: ErrorSeverity.Todo,
2870 - nodePath: lvaluePath,
2870 + loc: lvaluePath.node.loc ?? null,
2871 });
2872 return { kind: "UnsupportedNode", node: lvalueNode, loc };
2873 }
compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+2 -2
@@ -1039,14 +1039,14 @@ function codegenInstructionValue(
1039 (declarator.id as t.Identifier).name
1040 }'`,
1041 severity: ErrorSeverity.Todo,
1042 - nodePath: null,
1042 + loc: declarator.loc ?? null,
1043 });
1044 return t.stringLiteral(`TODO handle ${declarator.id}`);
1045 } else {
1046 cx.errors.push({
1047 reason: `(CodegenReactiveFunction::codegenInstructionValue) Handle conversion of ${stmt.type} to expression`,
1048 severity: ErrorSeverity.Todo,
1049 - nodePath: null,
1049 + loc: stmt.loc ?? null,
1050 });
1051 return t.stringLiteral(`TODO handle ${stmt.type}`);
1052 }
compiler/forget/packages/babel-plugin-react-forget/src/Validation/ValidateFrozenLambdas.ts
-1
@@ -133,7 +133,6 @@ function validateOperand(
133 const lambda = state.lambdas.get(operandId);
134 if (lambda !== undefined) {
135 return new CompilerErrorDetail({
136 - codeframe: null,
136 description: null,
137 loc: typeof operand.loc !== "symbol" ? operand.loc : null,
138 reason:
compiler/forget/packages/babel-plugin-react-forget/src/Validation/ValidateHooksUsage.ts
-1
@@ -26,7 +26,6 @@ export function validateHooksUsage(fn: HIRFunction): void {
26 const pushError = (place: Place): void => {
27 errors.pushErrorDetail(
28 new CompilerErrorDetail({
29 - codeframe: null,
29 description: null,
30 reason:
31 "Hooks may not be referenced as normal values, they must be called. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)",
compiler/forget/packages/babel-plugin-react-forget/src/Validation/ValidateNoRefAccesInRender.ts
-2
@@ -104,7 +104,6 @@ function validateNonRefValue(error: CompilerError, operand: Place): void {
104 if (isRefValueType(operand.identifier)) {
105 error.pushErrorDetail(
106 new CompilerErrorDetail({
107 - codeframe: null,
107 description: `Cannot access ref value at ${printPlace(operand)}`,
108 loc: typeof operand.loc !== "symbol" ? operand.loc : null,
109 reason:
@@ -120,7 +119,6 @@ function validateNonRefObject(error: CompilerError, operand: Place): void {
119 if (isUseRefType(operand.identifier)) {
120 error.pushErrorDetail(
121 new CompilerErrorDetail({
123 - codeframe: null,
122 description: `Cannot access ref object at ${printPlace(operand)}`,
123 loc: typeof operand.loc !== "symbol" ? operand.loc : null,
124 reason:
compiler/forget/packages/babel-plugin-react-forget/src/Validation/ValidateUnconditionalHooks.ts
+1 -2
@@ -93,11 +93,10 @@ export function validateUnconditionalHooks(
93 // and walk upward to determine whether each error location was due to a loop, if, etc.
94 errors.pushErrorDetail(
95 new CompilerErrorDetail({
96 - codeframe: null,
96 description: null,
97 reason:
98 "Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)",
100 - loc: typeof loc !== "symbol" ? loc : null,
99 + loc,
100 severity: ErrorSeverity.InvalidInput,
101 })
102 );
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error._todo.computed-lval-in-destructure.expect.md
+1 -8
@@ -15,14 +15,7 @@ function Component(props) {
15 ## Error
16
17 ```
18 -[ReactForget] TodoError: (BuildHIR::lowerAssignment) Handle computed properties in ObjectPattern
19 - 1 | function Component(props) {
20 - 2 | const computedKey = props.key;
21 -> 3 | const { [computedKey]: x } = props.val;
22 - | ^^^^^^^^^^^^^^^^
23 - 4 |
24 - 5 | return x;
25 - 6 | }
18 +[ReactForget] Todo: (BuildHIR::lowerAssignment) Handle computed properties in ObjectPattern (3:3)
19 ```
20
21
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-destructure-assignment-to-global.expect.md
+1 -7
@@ -13,13 +13,7 @@ function useFoo(props) {
13 ## Error
14
15 ```
16 -[ReactForget] InvalidInputError: (BuildHIR::lowerAssignment) Assigning to an identifier defined outside the function scope is not supported.
17 - 1 | function useFoo(props) {
18 -> 2 | [x] = props;
19 - | ^
20 - 3 | return { x };
21 - 4 | }
22 - 5 |
16 +[ReactForget] InvalidInput: (BuildHIR::lowerAssignment) Assigning to an identifier defined outside the function scope is not supported. (2:2)
17 ```
18
19
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-destructure-to-local-global-variables.expect.md
+1 -8
@@ -15,14 +15,7 @@ function Component(props) {
15 ## Error
16
17 ```
18 -[ReactForget] InvalidInputError: (BuildHIR::lowerAssignment) Assigning to an identifier defined outside the function scope is not supported.
19 - 1 | function Component(props) {
20 - 2 | let a;
21 -> 3 | [a, b] = props.value;
22 - | ^
23 - 4 |
24 - 5 | return [a, b];
25 - 6 | }
18 +[ReactForget] InvalidInput: (BuildHIR::lowerAssignment) Assigning to an identifier defined outside the function scope is not supported. (3:3)
19 ```
20
21
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-kitchensink.expect.md
+47 -213
@@ -83,219 +83,53 @@ let moduleLocal = false;
83 ## Error
84
85 ```
86 -[ReactForget] TodoError: (BuildHIR::lower) Handle RestElement params
87 -> 1 | function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
88 - | ^^^^^^^
89 - 2 | let i = 0;
90 - 3 | var x = [];
91 - 4 |
92 -
93 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle var kinds in VariableDeclaration
94 - 1 | function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
95 - 2 | let i = 0;
96 -> 3 | var x = [];
97 - | ^^^^^^^^^^^
98 - 4 |
99 - 5 | class Bar {
100 - 6 | #secretSauce = 42;
101 -
102 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle ClassDeclaration statements
103 - 3 | var x = [];
104 - 4 |
105 -> 5 | class Bar {
106 - | ^
107 - 6 | #secretSauce = 42;
108 - 7 | constructor() {
109 - 8 | console.log(this.#secretSauce);
110 -
111 -[ReactForget] TodoError: (BuildHIR::lowerExpression) Handle ObjectMethod properties in ObjectExpression
112 - 10 | }
113 - 11 |
114 -> 12 | const g = { b() {}, c: () => {} };
115 - | ^^^^^^
116 - 13 | const { z, aa = "aa" } = useCustom();
117 - 14 |
118 - 15 | <Button haha={1}></Button>;
119 -
120 -[ReactForget] TodoError: (BuildHIR::lower) Handle RestElement params
121 - 16 | <Button>{/** empty */}</Button>;
122 - 17 |
123 -> 18 | const j = function bar([quz, qux], ...args) {};
124 - | ^^^^^^^
125 - 19 |
126 - 20 | for (; i < 3; i += 1) {
127 - 21 | x.push(i);
128 -
129 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle non-variable initialization in ForStatement
130 - 18 | const j = function bar([quz, qux], ...args) {};
131 - 19 |
132 -> 20 | for (; i < 3; i += 1) {
133 - | ^
134 - 21 | x.push(i);
135 - 22 | }
136 - 23 | for (; i < 3; ) {
137 -
138 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle non-variable initialization in ForStatement
139 - 21 | x.push(i);
140 - 22 | }
141 -> 23 | for (; i < 3; ) {
142 - | ^
143 - 24 | break;
144 - 25 | }
145 - 26 | for (;;) {
146 -
147 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle non-variable initialization in ForStatement
148 - 24 | break;
149 - 25 | }
150 -> 26 | for (;;) {
151 - | ^
152 - 27 | break;
153 - 28 | }
154 - 29 |
155 -
156 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle empty test in ForStatement
157 - 24 | break;
158 - 25 | }
159 -> 26 | for (;;) {
160 - | ^
161 - 27 | break;
162 - 28 | }
163 - 29 |
164 -
165 -[ReactForget] TodoError: (BuildHIR::lowerExpression) Handle tagged template with interpolations
166 - 28 | }
167 - 29 |
168 -> 30 | graphql`
169 - | ^
170 - 31 | ${g}
171 - 32 | `;
172 - 33 |
173 -
174 -[ReactForget] TodoError: (BuildHIR::lowerExpression) Handle tagged template where cooked value is different from raw value
175 - 32 | `;
176 - 33 |
177 -> 34 | graphql`\\t\n`;
178 - | ^^^^^^^^^^^^^^
179 - 35 |
180 - 36 | for (c of [1, 2]) {
181 - 37 | }
182 -
183 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle Identifier inits in ForOfStatement
184 - 34 | graphql`\\t\n`;
185 - 35 |
186 -> 36 | for (c of [1, 2]) {
187 - | ^
188 - 37 | }
189 - 38 | for ([v] of [[1], [2]]) {
190 - 39 | }
191 -
192 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle ArrayPattern inits in ForOfStatement
193 - 36 | for (c of [1, 2]) {
194 - 37 | }
195 -> 38 | for ([v] of [[1], [2]]) {
196 - | ^^^
197 - 39 | }
198 - 40 | for ({ v } of [{ v: 1 }, { v: 2 }]) {
199 - 41 | }
200 -
201 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle ObjectPattern inits in ForOfStatement
202 - 38 | for ([v] of [[1], [2]]) {
203 - 39 | }
204 -> 40 | for ({ v } of [{ v: 1 }, { v: 2 }]) {
205 - | ^^^^^
206 - 41 | }
207 - 42 |
208 - 43 | for (let x in { a: 1 }) {
209 -
210 -[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle ForInStatement statements
211 - 41 | }
212 - 42 |
213 -> 43 | for (let x in { a: 1 }) {
214 - | ^
215 - 44 | }
216 - 45 |
217 - 46 | let updateIdentifier = 0;
218 -
219 -[ReactForget] TodoError: (BuildHIR::lowerExpression) Handle prefix UpdateExpression
220 - 45 |
221 - 46 | let updateIdentifier = 0;
222 -> 47 | --updateIdentifier;
223 - | ^^^^^^^^^^^^^^^^^^
224 - 48 | ++updateIdentifier;
225 - 49 | updateIdentifier.y++;
226 - 50 | updateIdentifier.y--;
227 -
228 -[ReactForget] TodoError: (BuildHIR::lowerExpression) Handle prefix UpdateExpression
229 - 46 | let updateIdentifier = 0;
230 - 47 | --updateIdentifier;
231 -> 48 | ++updateIdentifier;
232 - | ^^^^^^^^^^^^^^^^^^
233 - 49 | updateIdentifier.y++;
234 - 50 | updateIdentifier.y--;
235 - 51 |
236 -
237 -[ReactForget] TodoError: (BuildHIR::lowerExpression) Handle UpdateExpression with MemberExpression argument
238 - 47 | --updateIdentifier;
239 - 48 | ++updateIdentifier;
240 -> 49 | updateIdentifier.y++;
241 - | ^^^^^^^^^^^^^^^^^^^^
242 - 50 | updateIdentifier.y--;
243 - 51 |
244 - 52 | switch (i) {
245 -
246 -[ReactForget] TodoError: (BuildHIR::lowerExpression) Handle UpdateExpression with MemberExpression argument
247 - 48 | ++updateIdentifier;
248 - 49 | updateIdentifier.y++;
249 -> 50 | updateIdentifier.y--;
250 - | ^^^^^^^^^^^^^^^^^^^^
251 - 51 |
252 - 52 | switch (i) {
253 - 53 | case 1 + 1: {
254 -
255 -[ReactForget] TodoError: (BuildHIR::node.lowerReorderableExpression) Expression type 'MemberExpression' cannot be safely reordered
256 - 55 | case foo(): {
257 - 56 | }
258 -> 57 | case x.y: {
259 - | ^^^
260 - 58 | }
261 - 59 | default: {
262 - 60 | }
263 -
264 -[ReactForget] TodoError: (BuildHIR::node.lowerReorderableExpression) Expression type 'CallExpression' cannot be safely reordered
265 - 53 | case 1 + 1: {
266 - 54 | }
267 -> 55 | case foo(): {
268 - | ^^^^^
269 - 56 | }
270 - 57 | case x.y: {
271 - 58 | }
272 -
273 -[ReactForget] TodoError: (BuildHIR::node.lowerReorderableExpression) Expression type 'BinaryExpression' cannot be safely reordered
274 - 51 |
275 - 52 | switch (i) {
276 -> 53 | case 1 + 1: {
277 - | ^^^^^
278 - 54 | }
279 - 55 | case foo(): {
280 - 56 | }
281 -
282 -[ReactForget] InvalidInputError: (BuildHIR::lowerAssignment) Assigning to an identifier defined outside the function scope is not supported.
283 - 62 |
284 - 63 | // Cannot assign to globals
285 -> 64 | someUnknownGlobal = true;
286 - | ^^^^^^^^^^^^^^^^^
287 - 65 | moduleLocal = true;
288 - 66 |
289 - 67 | function component(a) {
290 -
291 -[ReactForget] InvalidInputError: (BuildHIR::lowerAssignment) Assigning to an identifier defined outside the function scope is not supported.
292 - 63 | // Cannot assign to globals
293 - 64 | someUnknownGlobal = true;
294 -> 65 | moduleLocal = true;
295 - | ^^^^^^^^^^^
296 - 66 |
297 - 67 | function component(a) {
298 - 68 | // Add support for function declarations once we support `var` hoisting.
86 +[ReactForget] Todo: (BuildHIR::lower) Handle RestElement params (1:1)
87 +
88 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle var kinds in VariableDeclaration (3:3)
89 +
90 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle ClassDeclaration statements (5:10)
91 +
92 +[ReactForget] Todo: (BuildHIR::lowerExpression) Handle ObjectMethod properties in ObjectExpression (12:12)
93 +
94 +[ReactForget] Todo: (BuildHIR::lower) Handle RestElement params (18:18)
95 +
96 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle non-variable initialization in ForStatement (20:22)
97 +
98 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle non-variable initialization in ForStatement (23:25)
99 +
100 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle non-variable initialization in ForStatement (26:28)
101 +
102 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle empty test in ForStatement (26:28)
103 +
104 +[ReactForget] Todo: (BuildHIR::lowerExpression) Handle tagged template with interpolations (30:32)
105 +
106 +[ReactForget] Todo: (BuildHIR::lowerExpression) Handle tagged template where cooked value is different from raw value (34:34)
107 +
108 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle Identifier inits in ForOfStatement (36:36)
109 +
110 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle ArrayPattern inits in ForOfStatement (38:38)
111 +
112 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle ObjectPattern inits in ForOfStatement (40:40)
113 +
114 +[ReactForget] Todo: (BuildHIR::lowerStatement) Handle ForInStatement statements (43:44)
115 +
116 +[ReactForget] Todo: (BuildHIR::lowerExpression) Handle prefix UpdateExpression (47:47)
117 +
118 +[ReactForget] Todo: (BuildHIR::lowerExpression) Handle prefix UpdateExpression (48:48)
119 +
120 +[ReactForget] Todo: (BuildHIR::lowerExpression) Handle UpdateExpression with MemberExpression argument (49:49)
121 +
122 +[ReactForget] Todo: (BuildHIR::lowerExpression) Handle UpdateExpression with MemberExpression argument (50:50)
123 +
124 +[ReactForget] Todo: (BuildHIR::node.lowerReorderableExpression) Expression type 'MemberExpression' cannot be safely reordered (57:57)
125 +
126 +[ReactForget] Todo: (BuildHIR::node.lowerReorderableExpression) Expression type 'CallExpression' cannot be safely reordered (55:55)
127 +
128 +[ReactForget] Todo: (BuildHIR::node.lowerReorderableExpression) Expression type 'BinaryExpression' cannot be safely reordered (53:53)
129 +
130 +[ReactForget] InvalidInput: (BuildHIR::lowerAssignment) Assigning to an identifier defined outside the function scope is not supported. (64:64)
131 +
132 +[ReactForget] InvalidInput: (BuildHIR::lowerAssignment) Assigning to an identifier defined outside the function scope is not supported. (65:65)
133 ```
134
135
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.useMemo-callback-generator.expect.md
+1 -8
@@ -18,14 +18,7 @@ function component(a, b) {
18 ## Error
19
20 ```
21 -[ReactForget] TodoError: (BuildHIR::lowerExpression) Handle YieldExpression expressions
22 - 4 | // add support for generators in the future.
23 - 5 | let x = useMemo(function* () {
24 -> 6 | yield a;
25 - | ^^^^^^^
26 - 7 | }, []);
27 - 8 | return x;
28 - 9 | }
21 +[ReactForget] Todo: (BuildHIR::lowerExpression) Handle YieldExpression expressions (6:6)
22 ```
23
24
\ No newline at end of file
compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts
+1 -1
@@ -61,7 +61,7 @@ const rule: Rule.RuleModule = {
61 } catch (err) {
62 if (isReactForgetCompilerError(err) && Array.isArray(err.details)) {
63 for (const detail of err.details) {
64 - if (detail.loc != null) {
64 + if (detail.loc != null && typeof detail.loc !== "symbol") {
65 context.report({
66 message: detail.toString(),
67 loc: detail.loc,