diff --git a/flow-typed/npm/babel-types_vx.x.x.js b/flow-typed/npm/babel-types_vx.x.x.js index c77621941..516ca95c7 100644 --- a/flow-typed/npm/babel-types_vx.x.x.js +++ b/flow-typed/npm/babel-types_vx.x.x.js @@ -17,9 +17,9 @@ declare module "@babel/types" { - declare type BabelNodeObjectMethodKind = "get" | "set" | "method"; - declare type BabelNodeLogicalOperator = "||" | "&&"; - declare type BabelNodeAssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&="; + declare type BabelObjectMethodKind = "get" | "set" | "method"; + declare type BabelLogicalOperator = "||" | "&&"; + declare type BabelAssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&="; declare type BabelBinaryOperator = "+" | "-" | "/" | "%" | "*" | "**" | "&" | "|" | ">>" | ">>>" | "<<" | "^" | "==" | "===" | "!=" | "!==" | "in" | "instanceof" | ">" | "<" | ">=" | "<="; declare type BabelUnaryOperator = "void" | "delete" | "!" | "+" | "-" | "++" | "--" | "~" | "typeof"; declare type BabelUpdateOperator = "++" | "--"; @@ -206,7 +206,7 @@ declare module "@babel/types" { declare class BabelNodeAssignmentExpression extends BabelNode { type: "AssignmentExpression"; - operator: BabelNodeAssignmentOperator; + operator: BabelAssignmentOperator; left: BabelNodeLVal; right: BabelNodeExpression; } @@ -373,7 +373,7 @@ declare module "@babel/types" { declare class BabelNodeLogicalExpression extends BabelNode { type: "LogicalExpression"; - operator: BabelNodeLogicalOperator; + operator: BabelLogicalOperator; left: BabelNodeExpression; right: BabelNodeExpression; } @@ -405,7 +405,7 @@ declare module "@babel/types" { declare class BabelNodeObjectMethod extends BabelNode { type: "ObjectMethod"; - kind: BabelNodeObjectMethodKind; + kind: BabelObjectMethodKind; computed: boolean; key: BabelNodeExpression; decorators: Array; @@ -1065,7 +1065,7 @@ declare module "@babel/types" { declare function arrayPattern(elements: Array, typeAnnotation: any, decorators?: Array): BabelNodeArrayPattern; declare function arrayTypeAnnotation(elementType: any): BabelNodeArrayTypeAnnotation; declare function arrowFunctionExpression(params: Array, body: BabelNodeBlockStatement | BabelNodeExpression, async?: boolean, returnType?: any, typeParameters?: any): BabelNodeArrowFunctionExpression; - declare function assignmentExpression(operator: BabelNodeAssignmentOperator, left: BabelNodeLVal, right: BabelNodeExpression): BabelNodeAssignmentExpression; + declare function assignmentExpression(operator: BabelAssignmentOperator, left: BabelNodeLVal, right: BabelNodeExpression): BabelNodeAssignmentExpression; declare function assignmentPattern(left: BabelNodeIdentifier, right: BabelNodeExpression, decorators?: any): BabelNodeAssignmentPattern; declare function awaitExpression(argument: BabelNodeExpression): BabelNodeAwaitExpression; declare function binaryExpression(operator: BabelBinaryOperator, left: BabelNodeExpression, right: BabelNodeExpression): BabelNodeBinaryExpression; @@ -1139,7 +1139,7 @@ declare module "@babel/types" { declare function jSXSpreadAttribute(argument: BabelNodeExpression): BabelNodeJSXSpreadAttribute; declare function jSXText(value: string): BabelNodeJSXText; declare function labeledStatement(label: BabelNodeIdentifier, body: BabelNodeStatement): BabelNodeLabeledStatement; - declare function logicalExpression(operator: BabelNodeLogicalOperator, left: BabelNodeExpression, right: BabelNodeExpression): BabelNodeLogicalExpression; + declare function logicalExpression(operator: BabelLogicalOperator, left: BabelNodeExpression, right: BabelNodeExpression): BabelNodeLogicalExpression; declare function memberExpression(object: BabelNodeExpression, property: BabelNodeExpression | BabelNodeIdentifier, computed?: boolean): BabelNodeMemberExpression; declare function metaProperty(meta: string, property: string): BabelNodeMetaProperty; declare function mixedTypeAnnotation(): BabelNodeMixedTypeAnnotation; @@ -1152,7 +1152,7 @@ declare module "@babel/types" { declare function numericLiteral(value: number): BabelNodeNumericLiteral; declare function numericLiteralTypeAnnotation(): BabelNodeNumericLiteralTypeAnnotation; declare function objectExpression(properties: Array): BabelNodeObjectExpression; - declare function objectMethod(kind: BabelNodeObjectMethodKind, key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, params: Array, body: BabelNodeBlockStatement, computed?: boolean, async?: boolean, decorators?: any, generator?: boolean, returnType?: any, typeParameters?: any): BabelNodeObjectMethod; + declare function objectMethod(kind: BabelObjectMethodKind, key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, params: Array, body: BabelNodeBlockStatement, computed?: boolean, async?: boolean, decorators?: any, generator?: boolean, returnType?: any, typeParameters?: any): BabelNodeObjectMethod; declare function objectPattern(properties: Array, typeAnnotation: any, decorators?: Array): BabelNodeObjectPattern; declare function objectProperty(key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, value: BabelNodeExpression, computed?: boolean, shorthand?: boolean, decorators: ?Array): BabelNodeObjectProperty; declare function objectTypeAnnotation(properties: any, indexers: any, callProperties: any): BabelNodeObjectTypeAnnotation; @@ -1390,9 +1390,9 @@ declare module "@babel/types" { } declare module "babel-types" { - declare type BabelNodeObjectMethodKind = "get" | "set" | "method"; - declare type BabelNodeLogicalOperator = "||" | "&&"; - declare type BabelNodeAssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&="; + declare type BabelObjectMethodKind = "get" | "set" | "method"; + declare type BabelLogicalOperator = "||" | "&&"; + declare type BabelAssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&="; declare type BabelBinaryOperator = "+" | "-" | "/" | "%" | "*" | "**" | "&" | "|" | ">>" | ">>>" | "<<" | "^" | "==" | "===" | "!=" | "!==" | "in" | "instanceof" | ">" | "<" | ">=" | "<="; declare type BabelUnaryOperator = "void" | "delete" | "!" | "+" | "-" | "++" | "--" | "~" | "typeof"; declare type BabelUpdateOperator = "++" | "--"; @@ -1579,7 +1579,7 @@ declare module "babel-types" { declare class BabelNodeAssignmentExpression extends BabelNode { type: "AssignmentExpression"; - operator: BabelNodeAssignmentOperator; + operator: BabelAssignmentOperator; left: BabelNodeLVal; right: BabelNodeExpression; } @@ -1746,7 +1746,7 @@ declare module "babel-types" { declare class BabelNodeLogicalExpression extends BabelNode { type: "LogicalExpression"; - operator: BabelNodeLogicalOperator; + operator: BabelLogicalOperator; left: BabelNodeExpression; right: BabelNodeExpression; } @@ -1778,7 +1778,7 @@ declare module "babel-types" { declare class BabelNodeObjectMethod extends BabelNode { type: "ObjectMethod"; - kind: BabelNodeObjectMethodKind; + kind: BabelObjectMethodKind; computed: boolean; key: BabelNodeExpression; decorators: Array; @@ -2438,7 +2438,7 @@ declare module "babel-types" { declare function arrayPattern(elements: Array, typeAnnotation: any, decorators?: Array): BabelNodeArrayPattern; declare function arrayTypeAnnotation(elementType: any): BabelNodeArrayTypeAnnotation; declare function arrowFunctionExpression(params: Array, body: BabelNodeBlockStatement | BabelNodeExpression, async?: boolean, returnType?: any, typeParameters?: any): BabelNodeArrowFunctionExpression; - declare function assignmentExpression(operator: BabelNodeAssignmentOperator, left: BabelNodeLVal, right: BabelNodeExpression): BabelNodeAssignmentExpression; + declare function assignmentExpression(operator: BabelAssignmentOperator, left: BabelNodeLVal, right: BabelNodeExpression): BabelNodeAssignmentExpression; declare function assignmentPattern(left: BabelNodeIdentifier, right: BabelNodeExpression, decorators?: any): BabelNodeAssignmentPattern; declare function awaitExpression(argument: BabelNodeExpression): BabelNodeAwaitExpression; declare function binaryExpression(operator: BabelBinaryOperator, left: BabelNodeExpression, right: BabelNodeExpression): BabelNodeBinaryExpression; @@ -2512,7 +2512,7 @@ declare module "babel-types" { declare function jSXSpreadAttribute(argument: BabelNodeExpression): BabelNodeJSXSpreadAttribute; declare function jSXText(value: string): BabelNodeJSXText; declare function labeledStatement(label: BabelNodeIdentifier, body: BabelNodeStatement): BabelNodeLabeledStatement; - declare function logicalExpression(operator: BabelNodeLogicalOperator, left: BabelNodeExpression, right: BabelNodeExpression): BabelNodeLogicalExpression; + declare function logicalExpression(operator: BabelLogicalOperator, left: BabelNodeExpression, right: BabelNodeExpression): BabelNodeLogicalExpression; declare function memberExpression(object: BabelNodeExpression, property: BabelNodeExpression | BabelNodeIdentifier, computed?: boolean): BabelNodeMemberExpression; declare function metaProperty(meta: string, property: string): BabelNodeMetaProperty; declare function mixedTypeAnnotation(): BabelNodeMixedTypeAnnotation; @@ -2525,7 +2525,7 @@ declare module "babel-types" { declare function numericLiteral(value: number): BabelNodeNumericLiteral; declare function numericLiteralTypeAnnotation(): BabelNodeNumericLiteralTypeAnnotation; declare function objectExpression(properties: Array): BabelNodeObjectExpression; - declare function objectMethod(kind: BabelNodeObjectMethodKind, key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, params: Array, body: BabelNodeBlockStatement, computed?: boolean, async?: boolean, decorators?: any, generator?: boolean, returnType?: any, typeParameters?: any): BabelNodeObjectMethod; + declare function objectMethod(kind: BabelObjectMethodKind, key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, params: Array, body: BabelNodeBlockStatement, computed?: boolean, async?: boolean, decorators?: any, generator?: boolean, returnType?: any, typeParameters?: any): BabelNodeObjectMethod; declare function objectPattern(properties: Array, typeAnnotation: any, decorators?: Array): BabelNodeObjectPattern; declare function objectProperty(key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, value: BabelNodeExpression, computed?: boolean, shorthand?: boolean, decorators: ?Array): BabelNodeObjectProperty; declare function objectTypeAnnotation(properties: any, indexers: any, callProperties: any): BabelNodeObjectTypeAnnotation; diff --git a/src/domains/TypesDomain.js b/src/domains/TypesDomain.js index 6b13ab1e9..16e6d5b29 100644 --- a/src/domains/TypesDomain.js +++ b/src/domains/TypesDomain.js @@ -10,7 +10,7 @@ /* @flow strict-local */ import invariant from "../invariant.js"; -import type { BabelBinaryOperator, BabelNodeLogicalOperator, BabelUnaryOperator } from "@babel/types"; +import type { BabelBinaryOperator, BabelLogicalOperator, BabelUnaryOperator } from "@babel/types"; import { AbstractValue, BooleanValue, @@ -130,7 +130,7 @@ export default class TypesDomain { return TypesDomain.topVal; } - static logicalOp(op: BabelNodeLogicalOperator, left: TypesDomain, right: TypesDomain): TypesDomain { + static logicalOp(op: BabelLogicalOperator, left: TypesDomain, right: TypesDomain): TypesDomain { return left.joinWith(right.getType()); } diff --git a/src/domains/ValuesDomain.js b/src/domains/ValuesDomain.js index 458dd59b6..dbf7b3ad0 100644 --- a/src/domains/ValuesDomain.js +++ b/src/domains/ValuesDomain.js @@ -9,7 +9,7 @@ /* @flow strict-local */ -import type { BabelBinaryOperator, BabelNodeLogicalOperator, BabelUnaryOperator } from "@babel/types"; +import type { BabelBinaryOperator, BabelLogicalOperator, BabelUnaryOperator } from "@babel/types"; import { AbruptCompletion } from "../completions.js"; import { FatalError } from "../errors.js"; import invariant from "../invariant.js"; @@ -307,7 +307,7 @@ export default class ValuesDomain { invariant(false, "unimplemented " + op); } - static logicalOp(realm: Realm, op: BabelNodeLogicalOperator, left: ValuesDomain, right: ValuesDomain): ValuesDomain { + static logicalOp(realm: Realm, op: BabelLogicalOperator, left: ValuesDomain, right: ValuesDomain): ValuesDomain { let leftElements = left._elements; let rightElements = right._elements; // Return top if left and/or right are top or if the size of the value set would get to be quite large. @@ -342,7 +342,7 @@ export default class ValuesDomain { // If that is not the desired behavior, mark the realm as read-only for the duration of the call. static computeLogical( realm: Realm, - op: BabelNodeLogicalOperator, + op: BabelLogicalOperator, lval: ConcreteValue, rval: ConcreteValue ): ConcreteValue { diff --git a/src/evaluators/BinaryExpression.js b/src/evaluators/BinaryExpression.js index a7c9916d0..d6ee68837 100644 --- a/src/evaluators/BinaryExpression.js +++ b/src/evaluators/BinaryExpression.js @@ -302,7 +302,7 @@ export function computeBinary( realm, resultType, [lval, rval], - createOperationDescriptor("BINARY_EXPRESSION", { op }), + createOperationDescriptor("BINARY_EXPRESSION", { binaryOperator: op }), { isPure: true } ), TypesDomain.topVal, diff --git a/src/evaluators/UpdateExpression.js b/src/evaluators/UpdateExpression.js index e8d5e6e7e..be7f5879f 100644 --- a/src/evaluators/UpdateExpression.js +++ b/src/evaluators/UpdateExpression.js @@ -50,7 +50,7 @@ export default function( realm, NumberValue, [oldExpr], - createOperationDescriptor("UPDATE_INCREMENTOR", { op }) + createOperationDescriptor("UPDATE_INCREMENTOR", { incrementor: op }) ), TypesDomain.topVal, ValuesDomain.topVal diff --git a/src/realm.js b/src/realm.js index 342871d88..170e2e6ab 100644 --- a/src/realm.js +++ b/src/realm.js @@ -1062,7 +1062,7 @@ export class Realm { value.types, value.values, [key.object, value], - createOperationDescriptor("LOGICAL_PROPERTY_ASSIGNMENT", { binding: key, value }), + createOperationDescriptor("LOGICAL_PROPERTY_ASSIGNMENT", { propertyBinding: key, value }), { skipInvariant: true, } diff --git a/src/serializer/ResidualOperationSerializer.js b/src/serializer/ResidualOperationSerializer.js index 8c9deb920..f8b2d93df 100644 --- a/src/serializer/ResidualOperationSerializer.js +++ b/src/serializer/ResidualOperationSerializer.js @@ -25,7 +25,6 @@ import { voidExpression, } from "../utils/babelhelpers.js"; import invariant from "../invariant.js"; -import { type Binding } from "../environment.js"; import * as t from "@babel/types"; import { AbstractValue, EmptyValue, ObjectValue, Value } from "../values/index.js"; import type { @@ -35,7 +34,6 @@ import type { BabelNodeStringLiteral, } from "@babel/types"; import { Utils } from "../singletons.js"; -import type { PropertyBinding } from "../types.js"; const labels = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -338,7 +336,7 @@ export class ResidualOperationSerializer { return babelNode; } - _serializeAssumeCall(data: OperationDescriptorData, [c, s]: Array) { + _serializeAssumeCall({ }: OperationDescriptorData, [c, s]: Array) { let errorLiteral = s.type === "StringLiteral" ? s : t.stringLiteral("Assumption violated"); return t.ifStatement( t.unaryExpression("!", c), @@ -346,15 +344,15 @@ export class ResidualOperationSerializer { ); } - _serializeWidenPropertyAssignment(data: OperationDescriptorData, [o, propName, v]: Array) { + _serializeWidenPropertyAssignment({ }: OperationDescriptorData, [o, propName, v]: Array) { return t.assignmentExpression("=", memberExpressionHelper(o, propName), v); } - _serializeWidenAbstractProperty(data: OperationDescriptorData, [o, p]: Array) { + _serializeWidenAbstractProperty({ }: OperationDescriptorData, [o, p]: Array) { return memberExpressionHelper(o, p); } - _serializeWidenProperty(data: OperationDescriptorData, [o, propName]: Array) { + _serializeWidenProperty({ }: OperationDescriptorData, [o, propName]: Array) { return memberExpressionHelper(o, propName); } @@ -364,7 +362,7 @@ export class ResidualOperationSerializer { : memberExpressionHelper(o, P); } - _serializeAbstractObjectGetProtoOf(data: OperationDescriptorData, [p]: Array) { + _serializeAbstractObjectGetProtoOf({ }: OperationDescriptorData, [p]: Array) { invariant(this.realm.preludeGenerator !== undefined); let getPrototypeOf = this.realm.preludeGenerator.memoizeReference("Object.getPrototypeOf"); return this.realm.isCompatibleWith(this.realm.MOBILE_JSC_VERSION) || this.realm.isCompatibleWith("mobile") @@ -372,27 +370,27 @@ export class ResidualOperationSerializer { : t.callExpression(getPrototypeOf, [p]); } - _serializeCannotBecomeObject(data: OperationDescriptorData, [n]: Array) { + _serializeCannotBecomeObject({ }: OperationDescriptorData, [n]: Array) { let callFunc = t.identifier("global.__cannotBecomeObject"); return t.callExpression(callFunc, [n]); } - _serializeResidualCall(data: OperationDescriptorData, nodes: Array) { + _serializeResidualCall({ }: OperationDescriptorData, nodes: Array) { return t.callExpression(nodes[0], ((nodes.slice(1): any): Array)); } - _serializeModulesRequires(data: OperationDescriptorData, [propName]: Array) { + _serializeModulesRequires({ }: OperationDescriptorData, [propName]: Array) { return t.callExpression(t.identifier("require"), [propName]); } - _serializeConcreteModel(data: OperationDescriptorData, [valueNode, propName]: Array) { + _serializeConcreteModel({ }: OperationDescriptorData, [valueNode, propName]: Array) { let propString = ((propName: any): BabelNodeStringLiteral).value; return t.expressionStatement( t.assignmentExpression("=", this.preludeGenerator.globalReference(propString, false), valueNode) ); } - _serializeConsoleLog(data: OperationDescriptorData, [propName, ...nodes]: Array) { + _serializeConsoleLog({ }: OperationDescriptorData, [propName, ...nodes]: Array) { let propString = ((propName: any): BabelNodeStringLiteral).value; return t.expressionStatement( t.callExpression(t.memberExpression(t.identifier("console"), t.identifier(propString)), [...nodes]) @@ -431,13 +429,13 @@ export class ResidualOperationSerializer { } _serializeFullInvariant( - data: OperationDescriptorData, + { }: OperationDescriptorData, [propName, objectNode, valueNode]: Array ) { return t.binaryExpression("!==", memberExpressionHelper(objectNode, propName), valueNode); } - _serializeFullInvariantFunction(data: OperationDescriptorData, [propName, objectNode]: Array) { + _serializeFullInvariantFunction({ }: OperationDescriptorData, [propName, objectNode]: Array) { return t.binaryExpression( "!==", t.unaryExpression("typeof", memberExpressionHelper(objectNode, propName), true), @@ -466,7 +464,7 @@ export class ResidualOperationSerializer { return checks.reduce((expr, newCondition) => t.logicalExpression("&&", expr, newCondition)); } - _serializeInvariantAppend(data: OperationDescriptorData, [propName, objectNode]: Array) { + _serializeInvariantAppend({ }: OperationDescriptorData, [propName, objectNode]: Array) { return memberExpressionHelper(objectNode, propName); } @@ -491,13 +489,13 @@ export class ResidualOperationSerializer { return n; } - _serializeUpdateIncrementor({ op }: OperationDescriptorData, [oldValNode]: Array) { - invariant(op !== undefined); - return t.binaryExpression(op, oldValNode, t.numericLiteral(1)); + _serializeUpdateIncrementor({ incrementor }: OperationDescriptorData, [oldValNode]: Array) { + invariant(incrementor !== undefined); + return t.binaryExpression(incrementor, oldValNode, t.numericLiteral(1)); } _serializeDerivedAbstractInvariant( - data: OperationDescriptorData, + { }: OperationDescriptorData, [typeOfStringNode, typeofNode]: Array ) { let typeofString = ((typeOfStringNode: any): BabelNodeStringLiteral).value; @@ -539,7 +537,7 @@ export class ResidualOperationSerializer { } _serializeReactRelayMockContainer( - data: OperationDescriptorData, + { }: OperationDescriptorData, [reactRelayIdent, propName, ...otherArgs]: Array ) { let propString = ((propName: any): BabelNodeStringLiteral).value; @@ -587,14 +585,17 @@ export class ResidualOperationSerializer { } _serializeLogicalPropertyAssignment( - { binding: _binding, value }: OperationDescriptorData, + { propertyBinding, value }: OperationDescriptorData, [o, n]: Array ) { invariant(value instanceof Value); - invariant(_binding !== undefined); - let binding = ((_binding: any): PropertyBinding); - if (typeof binding.key === "string" && value.mightHaveBeenDeleted() && isSelfReferential(value, binding.pathNode)) { - let inTest = t.binaryExpression("in", t.stringLiteral(binding.key), o); + invariant(propertyBinding !== undefined); + if ( + typeof propertyBinding.key === "string" && + value.mightHaveBeenDeleted() && + isSelfReferential(value, propertyBinding.pathNode) + ) { + let inTest = t.binaryExpression("in", t.stringLiteral(propertyBinding.key), o); let addEmpty = t.conditionalExpression(inTest, n, emptyExpression); n = t.logicalExpression("||", n, addEmpty); } @@ -613,48 +614,48 @@ export class ResidualOperationSerializer { return t.expressionStatement(t.assignmentExpression("=", (id: any), v)); } - _serializeReactNativeStringLiteral(data: OperationDescriptorData, [propName]: Array) { + _serializeReactNativeStringLiteral({ }: OperationDescriptorData, [propName]: Array) { return propName; } - _serializeReactCreateContextProvider(data: OperationDescriptorData, [consumerNode]: Array) { + _serializeReactCreateContextProvider({ }: OperationDescriptorData, [consumerNode]: Array) { return t.memberExpression(consumerNode, t.identifier("Provider")); } - _serializeReactTemporalFunc(data: OperationDescriptorData, [renderNode, ..._args]: Array) { + _serializeReactTemporalFunc({ }: OperationDescriptorData, [renderNode, ..._args]: Array) { return t.callExpression(renderNode, ((_args: any): Array)); } - _serializeCallAbstractFunc(data: OperationDescriptorData, nodes: Array) { + _serializeCallAbstractFunc({ }: OperationDescriptorData, nodes: Array) { let fun_args = ((nodes.slice(1): any): Array); return t.callExpression(nodes[0], fun_args); } - _serializeCallAbstractFuncThis(data: OperationDescriptorData, nodes: Array) { + _serializeCallAbstractFuncThis({ }: OperationDescriptorData, nodes: Array) { let fun_args = ((nodes.slice(1): any): Array); return t.callExpression(t.memberExpression(nodes[0], t.identifier("call")), fun_args); } - _serializeDirectCallWithArgList(data: OperationDescriptorData, nodes: Array) { + _serializeDirectCallWithArgList({ }: OperationDescriptorData, nodes: Array) { let fun_args = nodes.slice(1); return t.callExpression(nodes[0], ((fun_args: any): Array)); } _serializeObjectProtoHasOwnProperty( - data: OperationDescriptorData, + { }: OperationDescriptorData, [methodNode, objectNode, nameNode]: Array ) { return t.callExpression(t.memberExpression(methodNode, t.identifier("call")), [objectNode, nameNode]); } - _serializeRebuiltObject(data: OperationDescriptorData, [node, propName]: Array) { + _serializeRebuiltObject({ }: OperationDescriptorData, [node, propName]: Array) { let propString = ((propName: any): BabelNodeStringLiteral).value; return t.isValidIdentifier(propString) ? t.memberExpression(node, t.identifier(propString), false) : t.memberExpression(node, propName, true); } - _serializeGlobalDelete(data: OperationDescriptorData, [propName]: Array) { + _serializeGlobalDelete({ }: OperationDescriptorData, [propName]: Array) { let propString = ((propName: any): BabelNodeStringLiteral).value; return t.expressionStatement(t.unaryExpression("delete", this.preludeGenerator.globalReference(propString, false))); } @@ -671,74 +672,74 @@ export class ResidualOperationSerializer { return context.emitDefinePropertyBody(object, propString, desc); } - _serializeFBMocksMagicGlobalFunction(data: OperationDescriptorData, [propName, ...args]: Array) { + _serializeFBMocksMagicGlobalFunction({ }: OperationDescriptorData, [propName, ...args]: Array) { let propString = ((propName: any): BabelNodeStringLiteral).value; return t.callExpression(t.identifier(propString), ((args: any): Array)); } - _serializeFBMocksBootloaderLoadModules(data: OperationDescriptorData, args: Array) { + _serializeFBMocksBootloaderLoadModules({ }: OperationDescriptorData, args: Array) { return t.callExpression( t.memberExpression(t.identifier("Bootloader"), t.identifier("loadModules")), ((args: any): Array) ); } - _serializeUnknownArrayGetPartial(data: OperationDescriptorData, [o, p]: Array) { + _serializeUnknownArrayGetPartial({ }: OperationDescriptorData, [o, p]: Array) { return memberExpressionHelper(o, p); } - _serializeObjectGetPartial(data: OperationDescriptorData, [o, p]: Array) { + _serializeObjectGetPartial({ }: OperationDescriptorData, [o, p]: Array) { return memberExpressionHelper(o, p); } - _serializeAbstractObjectGetPartial(data: OperationDescriptorData, [o, p]: Array) { + _serializeAbstractObjectGetPartial({ }: OperationDescriptorData, [o, p]: Array) { return memberExpressionHelper(o, p); } _serializeObjectSetPartial( - data: OperationDescriptorData, + { }: OperationDescriptorData, [objectNode, keyNode, valueNode]: Array ) { return t.expressionStatement(t.assignmentExpression("=", memberExpressionHelper(objectNode, keyNode), valueNode)); } - _serializeIdentifier(data: OperationDescriptorData, nodes: Array) { - invariant(typeof data.id === "string"); - return t.identifier(data.id); + _serializeIdentifier({ id }: OperationDescriptorData, nodes: Array) { + invariant(id !== undefined); + return t.identifier(id); } - _serializeCoerceToString(data: OperationDescriptorData, [p]: Array) { + _serializeCoerceToString({ }: OperationDescriptorData, [p]: Array) { return t.binaryExpression("+", t.stringLiteral(""), p); } _serializeBabelHelpersObjectWithoutProperties( - data: OperationDescriptorData, + { }: OperationDescriptorData, [methodNode, objNode, propRemoveNode]: Array ) { return t.callExpression(methodNode, [objNode, propRemoveNode]); } - _serializeReactDefaultPropsHelper(data: OperationDescriptorData, [methodNode, ..._args]: Array) { + _serializeReactDefaultPropsHelper({ }: OperationDescriptorData, [methodNode, ..._args]: Array) { return t.callExpression(methodNode, ((_args: any): Array)); } - _serializeUnknownArrayMethodCall(data: OperationDescriptorData, [methodNode, ..._args]: Array) { + _serializeUnknownArrayMethodCall({ }: OperationDescriptorData, [methodNode, ..._args]: Array) { return t.callExpression(methodNode, ((_args: any): Array)); } - _serializeUnknownArrayLength(data: OperationDescriptorData, [o]: Array) { + _serializeUnknownArrayLength({ }: OperationDescriptorData, [o]: Array) { return t.memberExpression(o, t.identifier("length"), false); } _serializeUnknownArrayMethodPropertyCall( - data: OperationDescriptorData, + { }: OperationDescriptorData, [objNode, propName, ..._args]: Array ) { let propString = ((propName: any): BabelNodeStringLiteral).value; return t.callExpression(t.memberExpression(objNode, t.identifier(propString)), ((_args: any): Array)); } - _serializeThrow(data: OperationDescriptorData, [argument]: Array) { + _serializeThrow({ }: OperationDescriptorData, [argument]: Array) { return t.throwStatement(argument); } @@ -771,11 +772,11 @@ export class ResidualOperationSerializer { return t.templateLiteral(((quasis: any): Array), valueNodes); } - _serializeReactRenderValueHelper(data: OperationDescriptorData, [helperNode, valueNode]: Array) { + _serializeReactRenderValueHelper({ }: OperationDescriptorData, [helperNode, valueNode]: Array) { return t.callExpression(helperNode, [valueNode]); } - _serializePropertyDelete(data: OperationDescriptorData, [objectNode, propName]: Array) { + _serializePropertyDelete({ }: OperationDescriptorData, [objectNode, propName]: Array) { return t.expressionStatement(t.unaryExpression("delete", memberExpressionHelper(objectNode, propName))); } @@ -786,18 +787,17 @@ export class ResidualOperationSerializer { ) { invariant(binding !== undefined); invariant(context !== undefined); - return context.serializeBinding(((binding: any): Binding)); + return context.serializeBinding(binding); } - _serializeForFunctionCall(data: OperationDescriptorData, [func, thisExpr]: Array) { - let { usesThis } = data; + _serializeForFunctionCall({ usesThis }: OperationDescriptorData, [func, thisExpr]: Array) { return usesThis ? t.callExpression(t.memberExpression(func, t.identifier("call")), [thisExpr]) : t.callExpression(func, []); } _serializeNewExpression( - data: OperationDescriptorData, + { }: OperationDescriptorData, [constructorNode, ...argListNodes]: Array ) { return t.newExpression(constructorNode, argListNodes); @@ -814,7 +814,7 @@ export class ResidualOperationSerializer { } _serializeObjectProtoGetOwnPropertyDescriptor( - data: OperationDescriptorData, + { }: OperationDescriptorData, [funcNode, ...args]: Array ) { return t.callExpression(funcNode, ((args: any): Array)); @@ -869,46 +869,46 @@ export class ResidualOperationSerializer { ); } - _serializeGlobalAssignment(data: OperationDescriptorData, [valueNode, propName]: Array) { + _serializeGlobalAssignment({ }: OperationDescriptorData, [valueNode, propName]: Array) { let propString = ((propName: any): BabelNodeStringLiteral).value; return t.expressionStatement( t.assignmentExpression("=", this.preludeGenerator.globalReference(propString, false), valueNode) ); } - _serializeSingleArg(data: OperationDescriptorData, [o]: Array) { + _serializeSingleArg({ }: OperationDescriptorData, [o]: Array) { return o; } - _serializeAbstractProperty(data: OperationDescriptorData, [o, propName]: Array) { + _serializeAbstractProperty({ }: OperationDescriptorData, [o, propName]: Array) { return memberExpressionHelper(o, propName); } - _serializeUnaryExpression({ op, prefix }: OperationDescriptorData, [x, y]: Array) { - invariant(op !== undefined); - return t.unaryExpression(op, x, prefix); + _serializeUnaryExpression({ unaryOperator, prefix }: OperationDescriptorData, [x, y]: Array) { + invariant(unaryOperator !== undefined); + return t.unaryExpression(unaryOperator, x, prefix); } - _serializeBinaryExpression({ op }: OperationDescriptorData, [x, y]: Array) { - invariant(op !== undefined); - return t.binaryExpression(op, x, y); + _serializeBinaryExpression({ binaryOperator }: OperationDescriptorData, [x, y]: Array) { + invariant(binaryOperator !== undefined); + return t.binaryExpression(binaryOperator, x, y); } - _serializeLogicalExpression({ op }: OperationDescriptorData, [x, y]: Array) { - invariant(op !== undefined); - return t.logicalExpression(op, x, y); + _serializeLogicalExpression({ logicalOperator }: OperationDescriptorData, [x, y]: Array) { + invariant(logicalOperator !== undefined); + return t.logicalExpression(logicalOperator, x, y); } - _serializeConditionalExpression(data: OperationDescriptorData, [c, x, y]: Array) { + _serializeConditionalExpression({ }: OperationDescriptorData, [c, x, y]: Array) { return t.conditionalExpression(c, x, y); } _serializeDerivedOperationDescriptor( - data: OperationDescriptorData, + { id }: OperationDescriptorData, babelNode: BabelNodeExpression ): BabelNodeStatement { - invariant(typeof data.id === "string"); - return t.variableDeclaration("var", [t.variableDeclarator(t.identifier(data.id), babelNode)]); + invariant(id !== undefined); + return t.variableDeclaration("var", [t.variableDeclarator(t.identifier(id), babelNode)]); } _serializeVoidOperationDescriptor(babelNode: BabelNodeExpression) { @@ -923,7 +923,7 @@ export class ResidualOperationSerializer { return template(this.preludeGenerator)(generatorArgs); } - _serializeObjectAssign(data: OperationDescriptorData, [targetNode, ...sourceNodes]: Array) { + _serializeObjectAssign({ }: OperationDescriptorData, [targetNode, ...sourceNodes]: Array) { return t.callExpression(this.preludeGenerator.memoizeReference("Object.assign"), [targetNode, ...sourceNodes]); } } diff --git a/src/utils/generator.js b/src/utils/generator.js index 93708f044..41540cab1 100644 --- a/src/utils/generator.js +++ b/src/utils/generator.js @@ -47,6 +47,9 @@ import type { BabelNodeVariableDeclaration, BabelNodeBlockStatement, BabelNodeLVal, + BabelUnaryOperator, + BabelBinaryOperator, + BabelLogicalOperator, } from "@babel/types"; import { concretize, Join, Utils } from "../singletons.js"; import type { SerializerOptions } from "../options.js"; @@ -138,30 +141,34 @@ export type OperationDescriptor = { // TODO: gradually remove all these, currently it's a random bag of values // that should be in args or in other places rather than here. export type OperationDescriptorData = { - appendLastToInvariantOperationDescriptor?: OperationDescriptor, - binding?: Binding | PropertyBinding, - boundName?: BabelNodeIdentifier, - callTemplate?: () => BabelNodeExpression, - concreteComparisons?: Array, - desc?: Descriptor, - generator?: Generator, - generators?: Array, - id?: string, - lh?: BabelNodeVariableDeclaration, - op?: any, // TODO: This is a union of Babel operators, refactor to not use "any" at some point - prefix?: boolean, - path?: Value, - propertyGetter?: SupportedGraphQLGetters, - propRef?: ReferenceName | AbstractValue, - object?: ObjectValue, - quasis?: Array, - state?: "MISSING" | "PRESENT" | "DEFINED", - thisArg?: BaseValue | Value, - template?: PreludeGenerator => ({}) => BabelNodeExpression, - typeComparisons?: Set, - usesThis?: boolean, - value?: Value, - violationConditionOperationDescriptor?: OperationDescriptor, + appendLastToInvariantOperationDescriptor?: OperationDescriptor, // used by INVARIANT + binding?: Binding, // used by GET_BINDING + propertyBinding?: PropertyBinding, // used by LOGICAL_PROPERTY_ASSIGNMENT + boundName?: BabelNodeIdentifier, // used by FOR_IN + callTemplate?: () => BabelNodeExpression, // used by EMIT_CALL and EMIT_CALL_AND_CAPTURE_RESULT + concreteComparisons?: Array, // used by FULL_INVARIANT_ABSTRACT + desc?: Descriptor, // used by DEFINE_PROPERTY + generator?: Generator, // used by DO_WHILE + generators?: Array, // used by JOIN_GENERATORS + id?: string, // used by IDENTIFIER and DERIVED + lh?: BabelNodeVariableDeclaration, // used by FOR_IN + unaryOperator?: BabelUnaryOperator, // used by UNARY_EXPRESSION + binaryOperator?: BabelBinaryOperator, // used by BINARY_EXPRESSION + logicalOperator?: BabelLogicalOperator, // used by LOGICAL_EXPRESSION + incrementor?: "+" | "-", // used by UPDATE_INCREMENTOR + prefix?: boolean, // used by UNARY_EXPRESSION + path?: Value, // used by PROPERTY_ASSIGNMENT, CONDITIONAL_PROPERTY_ASSIGNMENT + propertyGetter?: SupportedGraphQLGetters, // used by ABSTRACT_OBJECT_GET + propRef?: ReferenceName | AbstractValue, // used by CALL_BAILOUT, and then only if string + object?: ObjectValue, // used by DEFINE_PROPERTY + quasis?: Array, // used by REACT_SSR_TEMPLATE_LITERAL + state?: "MISSING" | "PRESENT" | "DEFINED", // used by PROPERTY_INVARIANT + thisArg?: BaseValue | Value, // used by CALL_BAILOUT + template?: PreludeGenerator => ({}) => BabelNodeExpression, // used by ABSTRACT_FROM_TEMPLATE + typeComparisons?: Set, // used by FULL_INVARIANT_ABSTRACT + usesThis?: boolean, // used by FOR_STATEMENT_FUNC + value?: Value, // used by DO_WHILE, CONDITIONAL_PROPERTY_ASSIGNMENT, LOGICAL_PROPERTY_ASSIGNMENT, LOCAL_ASSIGNMENT, CONDITIONAL_THROW, EMIT_PROPERTY_ASSIGNMENT + violationConditionOperationDescriptor?: OperationDescriptor, // used by INVARIANT }; export type OperationDescriptorKind = "DERIVED" | "VOID"; @@ -258,8 +265,7 @@ export class GeneratorEntry { export type TemporalOperationEntryArgs = { declared?: AbstractValue | ObjectValue, args: Array, - // If we're just trying to add roots for the serializer to notice, we don't need an operationDescriptor. - operationDescriptor?: OperationDescriptor, + operationDescriptor: OperationDescriptor, dependencies?: Array, isPure?: boolean, mutatesOnly?: Array, @@ -275,12 +281,12 @@ export class TemporalOperationEntry extends GeneratorEntry { invariant(this.args.includes(arg)); } } + invariant(this.operationDescriptor !== undefined); } declared: void | AbstractValue | ObjectValue; args: Array; - // If we're just trying to add roots for the serializer to notice, we don't need an operationDescriptor. - operationDescriptor: void | OperationDescriptor; + operationDescriptor: OperationDescriptor; dependencies: void | Array; isPure: void | boolean; mutatesOnly: void | Array; @@ -328,24 +334,23 @@ export class TemporalOperationEntry extends GeneratorEntry { } if (!omit) { let nodes = this.args.map((boundArg, i) => context.serializeValue(boundArg)); - if (this.operationDescriptor !== undefined) { - let valuesToProcess = new Set(); - let node = context.serializeOperationDescriptor(this.operationDescriptor, nodes, context, valuesToProcess); - if (node.type === "BlockStatement") { - let block: BabelNodeBlockStatement = (node: any); - let statements = block.body; - if (statements.length === 0) return; - if (statements.length === 1) { - node = statements[0]; - } + let valuesToProcess = new Set(); + let node = context.serializeOperationDescriptor(this.operationDescriptor, nodes, context, valuesToProcess); + if (node.type === "BlockStatement") { + let block: BabelNodeBlockStatement = (node: any); + let statements = block.body; + if (statements.length === 0) return; + if (statements.length === 1) { + node = statements[0]; } - let declared = this.declared; - if (declared !== undefined && context.options.debugScopes) { - context.emit(context.serializeDebugScopeComment(declared)); - } - context.emit(node); - context.processValues(valuesToProcess); } + let declared = this.declared; + if (declared !== undefined && context.options.debugScopes) { + context.emit(context.serializeDebugScopeComment(declared)); + } + context.emit(node); + context.processValues(valuesToProcess); + if (this.declared !== undefined) context.declare(this.declared); } } diff --git a/src/values/AbstractValue.js b/src/values/AbstractValue.js index d12cf7973..c370a14f7 100644 --- a/src/values/AbstractValue.js +++ b/src/values/AbstractValue.js @@ -12,7 +12,7 @@ import type { BabelBinaryOperator, BabelNodeExpression, - BabelNodeLogicalOperator, + BabelLogicalOperator, BabelNodeSourceLocation, BabelUnaryOperator, } from "@babel/types"; @@ -637,7 +637,7 @@ export default class AbstractValue extends Value { ? ValuesDomain.topVal : ValuesDomain.binaryOp(realm, op, leftValues, rightValues); let [hash, args] = kind === undefined ? hashBinary(op, left, right) : hashCall(kind, left, right); - let operationDescriptor = createOperationDescriptor("BINARY_EXPRESSION", { op }); + let operationDescriptor = createOperationDescriptor("BINARY_EXPRESSION", { binaryOperator: op }); let result = new AbstractValue(realm, resultTypes, resultValues, hash, args, operationDescriptor); result.kind = kind || op; result.expressionLocation = loc; @@ -649,7 +649,7 @@ export default class AbstractValue extends Value { static createFromLogicalOp( realm: Realm, - op: BabelNodeLogicalOperator, + op: BabelLogicalOperator, left: Value, right: Value, loc?: ?BabelNodeSourceLocation, @@ -682,7 +682,7 @@ export default class AbstractValue extends Value { let Constructor = Value.isTypeCompatibleWith(resultTypes.getType(), ObjectValue) ? AbstractObjectValue : AbstractValue; - let operationDescriptor = createOperationDescriptor("LOGICAL_EXPRESSION", { op }); + let operationDescriptor = createOperationDescriptor("LOGICAL_EXPRESSION", { logicalOperator: op }); let result = new Constructor(realm, resultTypes, resultValues, hash, args, operationDescriptor); result.kind = op; result.expressionLocation = loc; @@ -736,7 +736,7 @@ export default class AbstractValue extends Value { invariant(op !== "delete" && op !== "++" && op !== "--"); // The operation must be pure let resultTypes = TypesDomain.unaryOp(op, new TypesDomain(operand.getType())); let resultValues = ValuesDomain.unaryOp(realm, op, operand.values); - let operationDescriptor = createOperationDescriptor("UNARY_EXPRESSION", { op, prefix }); + let operationDescriptor = createOperationDescriptor("UNARY_EXPRESSION", { unaryOperator: op, prefix }); let result = new AbstractValue( realm, resultTypes,