1753
});
1754
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1755
}
1756
- if (expr.node.prefix) {
1757
- builder.errors.push({
1758
- reason: `(BuildHIR::lowerExpression) Handle prefix UpdateExpression`,
1759
- severity: ErrorSeverity.Todo,
1760
- loc: exprPath.node.loc ?? null,
1761
- suggestions: null,
1762
- });
1763
- return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1764
- }
1765
- const primitiveTemp = lowerValueToTemporary(builder, {
1766
- kind: "Primitive",
1767
- value: 1,
1768
- loc: expr.node.loc ?? GeneratedSource,
1769
- });
1770
- const temp = buildTemporaryPlace(
1771
- builder,
1772
- expr.node.loc ?? GeneratedSource
1773
- );
1774
- const identifier = lowerIdentifierForAssignment(
1756
+ const lvalue = lowerIdentifierForAssignment(
1757
builder,
1758
argument.node.loc ?? GeneratedSource,
1759
InstructionKind.Reassign,
1778
- argument as NodePath<t.Identifier>
1760
+ argument
1761
);
1780
- if (identifier === null) {
1762
+ if (lvalue === null) {
1763
+ // lowerIdentifierForAssignment should have already reported an error if it returned null,
1764
+ // we check here just in case
1765
+ if (!builder.errors.hasErrors()) {
1766
+ builder.errors.push({
1767
+ reason: `(BuildHIR::lowerExpression) Found an invalid UpdateExpression without a previously reported error`,
1768
+ severity: ErrorSeverity.Invariant,
1769
+ loc: exprLoc,
1770
+ suggestions: null,
1771
+ });
1772
+ }
1773
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
1774
}
1783
- builder.push({
1784
- id: makeInstructionId(0),
1785
- lvalue: { ...temp },
1786
- value: {
1787
- kind: "BinaryExpression",
1788
- operator: expr.node.operator === "++" ? "+" : "-",
1789
- left: { ...identifier },
1790
- right: { ...primitiveTemp },
1775
+ const value = lowerIdentifier(builder, argument);
1776
+ if (expr.node.prefix) {
1777
+ return {
1778
+ kind: "PrefixUpdate",
1779
+ lvalue,
1780
+ operation: expr.node.operator,
1781
+ value,
1782
loc: exprLoc,
1792
- },
1793
- loc: exprLoc,
1794
- });
1795
- lowerValueToTemporary(builder, {
1796
- kind: getStoreKind(builder, argument),
1797
- lvalue: { place: { ...identifier }, kind: InstructionKind.Reassign },
1798
- value: { ...temp },
1799
- loc: exprLoc,
1800
- });
1801
- return {
1802
- kind: "LoadLocal",
1803
- place: { ...identifier },
1804
- loc: exprLoc,
1805
- };
1783
+ };
1784
+ } else {
1785
+ return {
1786
+ kind: "PostfixUpdate",
1787
+ lvalue,
1788
+ operation: expr.node.operator,
1789
+ value,
1790
+ loc: exprLoc,
1791
+ };
1792
+ }
1793
}
1794
case "RegExpLiteral": {
1795
let expr = exprPath as NodePath<t.RegExpLiteral>;