Some shallow cleanup of the operation descriptor. (#2471)

Summary:
Release notes: None
Pull Request resolved: https://github.com/facebook/prepack/pull/2471

Differential Revision: D9482778

Pulled By: NTillmann

fbshipit-source-id: 1eea1f3f0e6ddc383a2f214bfd53f5a99b7c1c4e
This commit is contained in:
Nikolai Tillmann 2018-08-23 11:51:17 -07:00 committed by Facebook Github Bot
parent 01edb5044b
commit 6299ab8272
9 changed files with 154 additions and 149 deletions

View File

@ -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<BabelNodeDecorator>;
@ -1065,7 +1065,7 @@ declare module "@babel/types" {
declare function arrayPattern(elements: Array<BabelNodeExpression>, typeAnnotation: any, decorators?: Array<BabelNodeDecorator>): BabelNodeArrayPattern;
declare function arrayTypeAnnotation(elementType: any): BabelNodeArrayTypeAnnotation;
declare function arrowFunctionExpression(params: Array<BabelNodeLVal>, 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<BabelNodeObjectMethod | BabelNodeObjectProperty | BabelNodeSpreadElement>): BabelNodeObjectExpression;
declare function objectMethod(kind: BabelNodeObjectMethodKind, key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, params: Array<BabelNodeLVal>, 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<BabelNodeLVal>, body: BabelNodeBlockStatement, computed?: boolean, async?: boolean, decorators?: any, generator?: boolean, returnType?: any, typeParameters?: any): BabelNodeObjectMethod;
declare function objectPattern(properties: Array<BabelNodeRestProperty | BabelNodeProperty>, typeAnnotation: any, decorators?: Array<BabelNodeDecorator>): BabelNodeObjectPattern;
declare function objectProperty(key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, value: BabelNodeExpression, computed?: boolean, shorthand?: boolean, decorators: ?Array<BabelNodeDecorator>): 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<BabelNodeDecorator>;
@ -2438,7 +2438,7 @@ declare module "babel-types" {
declare function arrayPattern(elements: Array<BabelNodeExpression>, typeAnnotation: any, decorators?: Array<BabelNodeDecorator>): BabelNodeArrayPattern;
declare function arrayTypeAnnotation(elementType: any): BabelNodeArrayTypeAnnotation;
declare function arrowFunctionExpression(params: Array<BabelNodeLVal>, 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<BabelNodeObjectMethod | BabelNodeObjectProperty | BabelNodeSpreadElement>): BabelNodeObjectExpression;
declare function objectMethod(kind: BabelNodeObjectMethodKind, key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, params: Array<BabelNodeLVal>, 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<BabelNodeLVal>, body: BabelNodeBlockStatement, computed?: boolean, async?: boolean, decorators?: any, generator?: boolean, returnType?: any, typeParameters?: any): BabelNodeObjectMethod;
declare function objectPattern(properties: Array<BabelNodeRestProperty | BabelNodeProperty>, typeAnnotation: any, decorators?: Array<BabelNodeDecorator>): BabelNodeObjectPattern;
declare function objectProperty(key: BabelNodeExpression | BabelNodeIdentifier | BabelNodeLiteral, value: BabelNodeExpression, computed?: boolean, shorthand?: boolean, decorators: ?Array<BabelNodeDecorator>): BabelNodeObjectProperty;
declare function objectTypeAnnotation(properties: any, indexers: any, callProperties: any): BabelNodeObjectTypeAnnotation;

View File

@ -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());
}

View File

@ -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 {

View File

@ -302,7 +302,7 @@ export function computeBinary(
realm,
resultType,
[lval, rval],
createOperationDescriptor("BINARY_EXPRESSION", { op }),
createOperationDescriptor("BINARY_EXPRESSION", { binaryOperator: op }),
{ isPure: true }
),
TypesDomain.topVal,

View File

@ -50,7 +50,7 @@ export default function(
realm,
NumberValue,
[oldExpr],
createOperationDescriptor("UPDATE_INCREMENTOR", { op })
createOperationDescriptor("UPDATE_INCREMENTOR", { incrementor: op })
),
TypesDomain.topVal,
ValuesDomain.topVal

View File

@ -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,
}

View File

@ -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<BabelNodeExpression>) {
_serializeAssumeCall({ }: OperationDescriptorData, [c, s]: Array<BabelNodeExpression>) {
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<BabelNodeExpression>) {
_serializeWidenPropertyAssignment({ }: OperationDescriptorData, [o, propName, v]: Array<BabelNodeExpression>) {
return t.assignmentExpression("=", memberExpressionHelper(o, propName), v);
}
_serializeWidenAbstractProperty(data: OperationDescriptorData, [o, p]: Array<BabelNodeExpression>) {
_serializeWidenAbstractProperty({ }: OperationDescriptorData, [o, p]: Array<BabelNodeExpression>) {
return memberExpressionHelper(o, p);
}
_serializeWidenProperty(data: OperationDescriptorData, [o, propName]: Array<BabelNodeExpression>) {
_serializeWidenProperty({ }: OperationDescriptorData, [o, propName]: Array<BabelNodeExpression>) {
return memberExpressionHelper(o, propName);
}
@ -364,7 +362,7 @@ export class ResidualOperationSerializer {
: memberExpressionHelper(o, P);
}
_serializeAbstractObjectGetProtoOf(data: OperationDescriptorData, [p]: Array<BabelNodeExpression>) {
_serializeAbstractObjectGetProtoOf({ }: OperationDescriptorData, [p]: Array<BabelNodeExpression>) {
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<BabelNodeExpression>) {
_serializeCannotBecomeObject({ }: OperationDescriptorData, [n]: Array<BabelNodeExpression>) {
let callFunc = t.identifier("global.__cannotBecomeObject");
return t.callExpression(callFunc, [n]);
}
_serializeResidualCall(data: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
_serializeResidualCall({ }: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
return t.callExpression(nodes[0], ((nodes.slice(1): any): Array<BabelNodeExpression | BabelNodeSpreadElement>));
}
_serializeModulesRequires(data: OperationDescriptorData, [propName]: Array<BabelNodeExpression>) {
_serializeModulesRequires({ }: OperationDescriptorData, [propName]: Array<BabelNodeExpression>) {
return t.callExpression(t.identifier("require"), [propName]);
}
_serializeConcreteModel(data: OperationDescriptorData, [valueNode, propName]: Array<BabelNodeExpression>) {
_serializeConcreteModel({ }: OperationDescriptorData, [valueNode, propName]: Array<BabelNodeExpression>) {
let propString = ((propName: any): BabelNodeStringLiteral).value;
return t.expressionStatement(
t.assignmentExpression("=", this.preludeGenerator.globalReference(propString, false), valueNode)
);
}
_serializeConsoleLog(data: OperationDescriptorData, [propName, ...nodes]: Array<BabelNodeExpression>) {
_serializeConsoleLog({ }: OperationDescriptorData, [propName, ...nodes]: Array<BabelNodeExpression>) {
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<BabelNodeExpression>
) {
return t.binaryExpression("!==", memberExpressionHelper(objectNode, propName), valueNode);
}
_serializeFullInvariantFunction(data: OperationDescriptorData, [propName, objectNode]: Array<BabelNodeExpression>) {
_serializeFullInvariantFunction({ }: OperationDescriptorData, [propName, objectNode]: Array<BabelNodeExpression>) {
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<BabelNodeExpression>) {
_serializeInvariantAppend({ }: OperationDescriptorData, [propName, objectNode]: Array<BabelNodeExpression>) {
return memberExpressionHelper(objectNode, propName);
}
@ -491,13 +489,13 @@ export class ResidualOperationSerializer {
return n;
}
_serializeUpdateIncrementor({ op }: OperationDescriptorData, [oldValNode]: Array<BabelNodeExpression>) {
invariant(op !== undefined);
return t.binaryExpression(op, oldValNode, t.numericLiteral(1));
_serializeUpdateIncrementor({ incrementor }: OperationDescriptorData, [oldValNode]: Array<BabelNodeExpression>) {
invariant(incrementor !== undefined);
return t.binaryExpression(incrementor, oldValNode, t.numericLiteral(1));
}
_serializeDerivedAbstractInvariant(
data: OperationDescriptorData,
{ }: OperationDescriptorData,
[typeOfStringNode, typeofNode]: Array<BabelNodeExpression>
) {
let typeofString = ((typeOfStringNode: any): BabelNodeStringLiteral).value;
@ -539,7 +537,7 @@ export class ResidualOperationSerializer {
}
_serializeReactRelayMockContainer(
data: OperationDescriptorData,
{ }: OperationDescriptorData,
[reactRelayIdent, propName, ...otherArgs]: Array<BabelNodeExpression>
) {
let propString = ((propName: any): BabelNodeStringLiteral).value;
@ -587,14 +585,17 @@ export class ResidualOperationSerializer {
}
_serializeLogicalPropertyAssignment(
{ binding: _binding, value }: OperationDescriptorData,
{ propertyBinding, value }: OperationDescriptorData,
[o, n]: Array<BabelNodeExpression>
) {
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<BabelNodeExpression>) {
_serializeReactNativeStringLiteral({ }: OperationDescriptorData, [propName]: Array<BabelNodeExpression>) {
return propName;
}
_serializeReactCreateContextProvider(data: OperationDescriptorData, [consumerNode]: Array<BabelNodeExpression>) {
_serializeReactCreateContextProvider({ }: OperationDescriptorData, [consumerNode]: Array<BabelNodeExpression>) {
return t.memberExpression(consumerNode, t.identifier("Provider"));
}
_serializeReactTemporalFunc(data: OperationDescriptorData, [renderNode, ..._args]: Array<BabelNodeExpression>) {
_serializeReactTemporalFunc({ }: OperationDescriptorData, [renderNode, ..._args]: Array<BabelNodeExpression>) {
return t.callExpression(renderNode, ((_args: any): Array<any>));
}
_serializeCallAbstractFunc(data: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
_serializeCallAbstractFunc({ }: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
let fun_args = ((nodes.slice(1): any): Array<BabelNodeExpression | BabelNodeSpreadElement>);
return t.callExpression(nodes[0], fun_args);
}
_serializeCallAbstractFuncThis(data: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
_serializeCallAbstractFuncThis({ }: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
let fun_args = ((nodes.slice(1): any): Array<BabelNodeExpression | BabelNodeSpreadElement>);
return t.callExpression(t.memberExpression(nodes[0], t.identifier("call")), fun_args);
}
_serializeDirectCallWithArgList(data: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
_serializeDirectCallWithArgList({ }: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
let fun_args = nodes.slice(1);
return t.callExpression(nodes[0], ((fun_args: any): Array<BabelNodeExpression | BabelNodeSpreadElement>));
}
_serializeObjectProtoHasOwnProperty(
data: OperationDescriptorData,
{ }: OperationDescriptorData,
[methodNode, objectNode, nameNode]: Array<BabelNodeExpression>
) {
return t.callExpression(t.memberExpression(methodNode, t.identifier("call")), [objectNode, nameNode]);
}
_serializeRebuiltObject(data: OperationDescriptorData, [node, propName]: Array<BabelNodeExpression>) {
_serializeRebuiltObject({ }: OperationDescriptorData, [node, propName]: Array<BabelNodeExpression>) {
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<BabelNodeExpression>) {
_serializeGlobalDelete({ }: OperationDescriptorData, [propName]: Array<BabelNodeExpression>) {
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<BabelNodeExpression>) {
_serializeFBMocksMagicGlobalFunction({ }: OperationDescriptorData, [propName, ...args]: Array<BabelNodeExpression>) {
let propString = ((propName: any): BabelNodeStringLiteral).value;
return t.callExpression(t.identifier(propString), ((args: any): Array<any>));
}
_serializeFBMocksBootloaderLoadModules(data: OperationDescriptorData, args: Array<BabelNodeExpression>) {
_serializeFBMocksBootloaderLoadModules({ }: OperationDescriptorData, args: Array<BabelNodeExpression>) {
return t.callExpression(
t.memberExpression(t.identifier("Bootloader"), t.identifier("loadModules")),
((args: any): Array<any>)
);
}
_serializeUnknownArrayGetPartial(data: OperationDescriptorData, [o, p]: Array<BabelNodeExpression>) {
_serializeUnknownArrayGetPartial({ }: OperationDescriptorData, [o, p]: Array<BabelNodeExpression>) {
return memberExpressionHelper(o, p);
}
_serializeObjectGetPartial(data: OperationDescriptorData, [o, p]: Array<BabelNodeExpression>) {
_serializeObjectGetPartial({ }: OperationDescriptorData, [o, p]: Array<BabelNodeExpression>) {
return memberExpressionHelper(o, p);
}
_serializeAbstractObjectGetPartial(data: OperationDescriptorData, [o, p]: Array<BabelNodeExpression>) {
_serializeAbstractObjectGetPartial({ }: OperationDescriptorData, [o, p]: Array<BabelNodeExpression>) {
return memberExpressionHelper(o, p);
}
_serializeObjectSetPartial(
data: OperationDescriptorData,
{ }: OperationDescriptorData,
[objectNode, keyNode, valueNode]: Array<BabelNodeExpression>
) {
return t.expressionStatement(t.assignmentExpression("=", memberExpressionHelper(objectNode, keyNode), valueNode));
}
_serializeIdentifier(data: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
invariant(typeof data.id === "string");
return t.identifier(data.id);
_serializeIdentifier({ id }: OperationDescriptorData, nodes: Array<BabelNodeExpression>) {
invariant(id !== undefined);
return t.identifier(id);
}
_serializeCoerceToString(data: OperationDescriptorData, [p]: Array<BabelNodeExpression>) {
_serializeCoerceToString({ }: OperationDescriptorData, [p]: Array<BabelNodeExpression>) {
return t.binaryExpression("+", t.stringLiteral(""), p);
}
_serializeBabelHelpersObjectWithoutProperties(
data: OperationDescriptorData,
{ }: OperationDescriptorData,
[methodNode, objNode, propRemoveNode]: Array<BabelNodeExpression>
) {
return t.callExpression(methodNode, [objNode, propRemoveNode]);
}
_serializeReactDefaultPropsHelper(data: OperationDescriptorData, [methodNode, ..._args]: Array<BabelNodeExpression>) {
_serializeReactDefaultPropsHelper({ }: OperationDescriptorData, [methodNode, ..._args]: Array<BabelNodeExpression>) {
return t.callExpression(methodNode, ((_args: any): Array<any>));
}
_serializeUnknownArrayMethodCall(data: OperationDescriptorData, [methodNode, ..._args]: Array<BabelNodeExpression>) {
_serializeUnknownArrayMethodCall({ }: OperationDescriptorData, [methodNode, ..._args]: Array<BabelNodeExpression>) {
return t.callExpression(methodNode, ((_args: any): Array<any>));
}
_serializeUnknownArrayLength(data: OperationDescriptorData, [o]: Array<BabelNodeExpression>) {
_serializeUnknownArrayLength({ }: OperationDescriptorData, [o]: Array<BabelNodeExpression>) {
return t.memberExpression(o, t.identifier("length"), false);
}
_serializeUnknownArrayMethodPropertyCall(
data: OperationDescriptorData,
{ }: OperationDescriptorData,
[objNode, propName, ..._args]: Array<BabelNodeExpression>
) {
let propString = ((propName: any): BabelNodeStringLiteral).value;
return t.callExpression(t.memberExpression(objNode, t.identifier(propString)), ((_args: any): Array<any>));
}
_serializeThrow(data: OperationDescriptorData, [argument]: Array<BabelNodeExpression>) {
_serializeThrow({ }: OperationDescriptorData, [argument]: Array<BabelNodeExpression>) {
return t.throwStatement(argument);
}
@ -771,11 +772,11 @@ export class ResidualOperationSerializer {
return t.templateLiteral(((quasis: any): Array<any>), valueNodes);
}
_serializeReactRenderValueHelper(data: OperationDescriptorData, [helperNode, valueNode]: Array<BabelNodeExpression>) {
_serializeReactRenderValueHelper({ }: OperationDescriptorData, [helperNode, valueNode]: Array<BabelNodeExpression>) {
return t.callExpression(helperNode, [valueNode]);
}
_serializePropertyDelete(data: OperationDescriptorData, [objectNode, propName]: Array<BabelNodeExpression>) {
_serializePropertyDelete({ }: OperationDescriptorData, [objectNode, propName]: Array<BabelNodeExpression>) {
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<BabelNodeExpression>) {
let { usesThis } = data;
_serializeForFunctionCall({ usesThis }: OperationDescriptorData, [func, thisExpr]: Array<BabelNodeExpression>) {
return usesThis
? t.callExpression(t.memberExpression(func, t.identifier("call")), [thisExpr])
: t.callExpression(func, []);
}
_serializeNewExpression(
data: OperationDescriptorData,
{ }: OperationDescriptorData,
[constructorNode, ...argListNodes]: Array<BabelNodeExpression>
) {
return t.newExpression(constructorNode, argListNodes);
@ -814,7 +814,7 @@ export class ResidualOperationSerializer {
}
_serializeObjectProtoGetOwnPropertyDescriptor(
data: OperationDescriptorData,
{ }: OperationDescriptorData,
[funcNode, ...args]: Array<BabelNodeExpression>
) {
return t.callExpression(funcNode, ((args: any): Array<BabelNodeExpression | BabelNodeSpreadElement>));
@ -869,46 +869,46 @@ export class ResidualOperationSerializer {
);
}
_serializeGlobalAssignment(data: OperationDescriptorData, [valueNode, propName]: Array<BabelNodeExpression>) {
_serializeGlobalAssignment({ }: OperationDescriptorData, [valueNode, propName]: Array<BabelNodeExpression>) {
let propString = ((propName: any): BabelNodeStringLiteral).value;
return t.expressionStatement(
t.assignmentExpression("=", this.preludeGenerator.globalReference(propString, false), valueNode)
);
}
_serializeSingleArg(data: OperationDescriptorData, [o]: Array<BabelNodeExpression>) {
_serializeSingleArg({ }: OperationDescriptorData, [o]: Array<BabelNodeExpression>) {
return o;
}
_serializeAbstractProperty(data: OperationDescriptorData, [o, propName]: Array<BabelNodeExpression>) {
_serializeAbstractProperty({ }: OperationDescriptorData, [o, propName]: Array<BabelNodeExpression>) {
return memberExpressionHelper(o, propName);
}
_serializeUnaryExpression({ op, prefix }: OperationDescriptorData, [x, y]: Array<BabelNodeExpression>) {
invariant(op !== undefined);
return t.unaryExpression(op, x, prefix);
_serializeUnaryExpression({ unaryOperator, prefix }: OperationDescriptorData, [x, y]: Array<BabelNodeExpression>) {
invariant(unaryOperator !== undefined);
return t.unaryExpression(unaryOperator, x, prefix);
}
_serializeBinaryExpression({ op }: OperationDescriptorData, [x, y]: Array<BabelNodeExpression>) {
invariant(op !== undefined);
return t.binaryExpression(op, x, y);
_serializeBinaryExpression({ binaryOperator }: OperationDescriptorData, [x, y]: Array<BabelNodeExpression>) {
invariant(binaryOperator !== undefined);
return t.binaryExpression(binaryOperator, x, y);
}
_serializeLogicalExpression({ op }: OperationDescriptorData, [x, y]: Array<BabelNodeExpression>) {
invariant(op !== undefined);
return t.logicalExpression(op, x, y);
_serializeLogicalExpression({ logicalOperator }: OperationDescriptorData, [x, y]: Array<BabelNodeExpression>) {
invariant(logicalOperator !== undefined);
return t.logicalExpression(logicalOperator, x, y);
}
_serializeConditionalExpression(data: OperationDescriptorData, [c, x, y]: Array<BabelNodeExpression>) {
_serializeConditionalExpression({ }: OperationDescriptorData, [c, x, y]: Array<BabelNodeExpression>) {
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<BabelNodeExpression>) {
_serializeObjectAssign({ }: OperationDescriptorData, [targetNode, ...sourceNodes]: Array<BabelNodeExpression>) {
return t.callExpression(this.preludeGenerator.memoizeReference("Object.assign"), [targetNode, ...sourceNodes]);
}
}

View File

@ -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<Value>,
desc?: Descriptor,
generator?: Generator,
generators?: Array<Generator>,
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<any>,
state?: "MISSING" | "PRESENT" | "DEFINED",
thisArg?: BaseValue | Value,
template?: PreludeGenerator => ({}) => BabelNodeExpression,
typeComparisons?: Set<typeof Value>,
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<Value>, // used by FULL_INVARIANT_ABSTRACT
desc?: Descriptor, // used by DEFINE_PROPERTY
generator?: Generator, // used by DO_WHILE
generators?: Array<Generator>, // 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<any>, // 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<typeof Value>, // 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<Value>,
// 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<Generator>,
isPure?: boolean,
mutatesOnly?: Array<Value>,
@ -275,12 +281,12 @@ export class TemporalOperationEntry extends GeneratorEntry {
invariant(this.args.includes(arg));
}
}
invariant(this.operationDescriptor !== undefined);
}
declared: void | AbstractValue | ObjectValue;
args: Array<Value>;
// 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<Generator>;
isPure: void | boolean;
mutatesOnly: void | Array<Value>;
@ -328,7 +334,6 @@ 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") {
@ -345,7 +350,7 @@ export class TemporalOperationEntry extends GeneratorEntry {
}
context.emit(node);
context.processValues(valuesToProcess);
}
if (this.declared !== undefined) context.declare(this.declared);
}
}

View File

@ -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,