16
IdentifierId,
17
InstructionKind,
18
JsxAttribute,
19
+ ObjectMethod,
20
ObjectPropertyKey,
21
Pattern,
22
Place,
119
#declarations: Set<IdentifierId> = new Set();
120
temp: Temporaries = new Map();
121
errors: CompilerError = new CompilerError();
122
+ objectMethods: Map<IdentifierId, ObjectMethod> = new Map();
123
+
124
constructor(env: Environment, fnName: string) {
125
this.env = env;
126
this.fnName = fnName;
710
}
711
} else if (instr.value.kind === "Debugger") {
712
return t.debuggerStatement();
713
+ } else if (instr.value.kind === "ObjectMethod") {
714
+ CompilerError.invariant(instr.lvalue, {
715
+ reason: "Expected object methods to have a temp lvalue",
716
+ loc: null,
717
+ suggestions: null,
718
+ });
719
+ cx.objectMethods.set(instr.lvalue.identifier.id, instr.value);
720
+ return null;
721
} else {
722
const value = codegenInstructionValue(cx, instr.value);
723
const statement = codegenInstruction(cx, instr, value);
980
for (const property of instrValue.properties) {
981
if (property.kind === "ObjectProperty") {
982
const key = codegenObjectPropertyKey(property.key);
972
- const value = codegenPlace(cx, property.place);
973
- properties.push(
974
- t.objectProperty(
975
- key,
976
- value,
977
- false,
978
- value.type === "Identifier" && value.name === property.key.name
979
- )
980
- );
983
+
984
+ switch (property.type) {
985
+ case "property": {
986
+ const value = codegenPlace(cx, property.place);
987
+ properties.push(
988
+ t.objectProperty(
989
+ key,
990
+ value,
991
+ false,
992
+ value.type === "Identifier" &&
993
+ value.name === property.key.name
994
+ )
995
+ );
996
+ break;
997
+ }
998
+ case "method": {
999
+ const method = cx.objectMethods.get(property.place.identifier.id);
1000
+ CompilerError.invariant(method, {
1001
+ reason: "Expected ObjectMethod instruction",
1002
+ loc: null,
1003
+ suggestions: null,
1004
+ });
1005
+ const loweredFunc = method.loweredFunc;
1006
+ const reactiveFunction = buildReactiveFunction(loweredFunc.func);
1007
+ pruneUnusedLabels(reactiveFunction);
1008
+ pruneUnusedLValues(reactiveFunction);
1009
+ renameVariables(reactiveFunction);
1010
+ const fn = codegenReactiveFunction(reactiveFunction).unwrap();
1011
+
1012
+ properties.push(
1013
+ t.objectMethod(
1014
+ "method",
1015
+ key,
1016
+ fn.params,
1017
+ fn.body,
1018
+ false,
1019
+ fn.generator,
1020
+ fn.async
1021
+ )
1022
+ );
1023
+ break;
1024
+ }
1025
+ default:
1026
+ assertExhaustive(
1027
+ property.type,
1028
+ `Unexpected property type: ${property.type}`
1029
+ );
1030
+ }
1031
} else {
1032
properties.push(t.spreadElement(codegenPlace(cx, property.place)));
1033
}
1346
case "DeclareContext":
1347
case "Destructure":
1348
case "StoreLocal":
1349
+ case "ObjectMethod":
1350
case "StoreContext": {
1351
CompilerError.invariant(false, {
1352
reason: `Unexpected ${instrValue.kind} in codegenInstructionValue`,