mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-09-11 14:46:37 +03:00
Upgrade Flow and fix new warnings (#2526)
Summary: Release note: Update to Flow v80 Fix new class of warnings. Pull Request resolved: https://github.com/facebook/prepack/pull/2526 Differential Revision: D9621986 Pulled By: hermanventer fbshipit-source-id: 365b73a0aaa68b0f509a1931345d8100ca52c94b
This commit is contained in:
parent
ade7b71211
commit
ebab0a7015
@ -106,7 +106,7 @@
|
||||
"eslint-plugin-flowtype": "^2.40.0",
|
||||
"eslint-plugin-header": "^1.0.0",
|
||||
"eslint-plugin-prettier": "^2.1.2",
|
||||
"flow-bin": "^0.79.1",
|
||||
"flow-bin": "^0.80.0",
|
||||
"flow-typed": "^2.3.0",
|
||||
"graceful-fs": "^4.1.11",
|
||||
"invariant": "^2.2.0",
|
||||
|
@ -226,7 +226,7 @@ while (args.length) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!inputFilename) {
|
||||
if (inputFilename === undefined) {
|
||||
console.error("Missing input file.");
|
||||
process.exit(1);
|
||||
} else {
|
||||
|
@ -160,13 +160,13 @@ class PrepackDebugSession extends DebugSession {
|
||||
response: DebugProtocol.SetBreakpointsResponse,
|
||||
args: DebugProtocol.SetBreakpointsArguments
|
||||
): void {
|
||||
if (!args.source.path || !args.breakpoints) return;
|
||||
if (args.source.path === undefined || args.breakpoints === undefined) return;
|
||||
let filePath = args.source.path;
|
||||
let breakpointInfos = [];
|
||||
for (const breakpoint of args.breakpoints) {
|
||||
let line = breakpoint.line;
|
||||
let column = 0;
|
||||
if (breakpoint.column) {
|
||||
if (breakpoint.column !== undefined) {
|
||||
column = breakpoint.column;
|
||||
}
|
||||
let breakpointInfo: Breakpoint = {
|
||||
|
@ -22,7 +22,7 @@ export class BreakpointManager {
|
||||
_breakpointMaps: Map<string, PerFileBreakpointMap>;
|
||||
|
||||
getStoppableBreakpoint(ast: BabelNode): void | Breakpoint {
|
||||
if (ast.loc && ast.loc.source) {
|
||||
if (ast.loc && ast.loc.source !== null) {
|
||||
let location = ast.loc;
|
||||
let filePath = location.source;
|
||||
if (filePath === null) return;
|
||||
|
@ -91,7 +91,7 @@ export class DebugServer {
|
||||
let reason = this._stopEventManager.getDebuggeeStopReason(ast, stoppables);
|
||||
if (reason) {
|
||||
let location = ast.loc;
|
||||
invariant(location && location.source);
|
||||
invariant(location && location.source !== null);
|
||||
let absolutePath = this._sourceMapManager.relativeToAbsolute(location.source);
|
||||
this._channel.sendStoppedResponse(reason, absolutePath, location.start.line, location.start.column);
|
||||
this.waitForRun(location);
|
||||
@ -190,7 +190,7 @@ export class DebugServer {
|
||||
for (let i = this._realm.contextStack.length - 1; i >= 0; i--) {
|
||||
let frame = this._realm.contextStack[i];
|
||||
let functionName = "(anonymous function)";
|
||||
if (frame.function && frame.function.__originalName) {
|
||||
if (frame.function && frame.function.__originalName !== undefined) {
|
||||
functionName = frame.function.__originalName;
|
||||
}
|
||||
|
||||
@ -214,7 +214,7 @@ export class DebugServer {
|
||||
let fileName = "unknown";
|
||||
let line = 0;
|
||||
let column = 0;
|
||||
if (loc && loc.source) {
|
||||
if (loc && loc.source !== null) {
|
||||
fileName = loc.source;
|
||||
line = loc.start.line;
|
||||
column = loc.start.column;
|
||||
@ -257,7 +257,9 @@ export class DebugServer {
|
||||
return "Global";
|
||||
} else if (envRec instanceof DeclarativeEnvironmentRecord) {
|
||||
if (envRec instanceof FunctionEnvironmentRecord) {
|
||||
return "Local: " + (envRec.$FunctionObject.__originalName || "anonymous function");
|
||||
let name = envRec.$FunctionObject.__originalName;
|
||||
if (name === undefined) name = "anonymous function";
|
||||
return "Local: " + name;
|
||||
} else {
|
||||
return "Block";
|
||||
}
|
||||
@ -288,7 +290,7 @@ export class DebugServer {
|
||||
Returns whether there are more nodes in the ast.
|
||||
*/
|
||||
_checkAndUpdateLastExecuted(ast: BabelNode): boolean {
|
||||
if (ast.loc && ast.loc.source) {
|
||||
if (ast.loc && ast.loc.source !== null) {
|
||||
let filePath = ast.loc.source;
|
||||
let line = ast.loc.start.line;
|
||||
let column = ast.loc.start.column;
|
||||
@ -320,7 +322,7 @@ export class DebugServer {
|
||||
|
||||
// Displays Prepack error message, then waits for user to run the program to continue (similar to a breakpoint).
|
||||
handlePrepackError(diagnostic: CompilerDiagnostic): void {
|
||||
invariant(diagnostic.location && diagnostic.location.source);
|
||||
invariant(diagnostic.location && diagnostic.location.source !== null);
|
||||
// The following constructs the message and stop-instruction that is sent to the UI to actually stop the execution.
|
||||
let location = diagnostic.location;
|
||||
let absoluteSource = "";
|
||||
|
@ -36,7 +36,7 @@ export class Stepper {
|
||||
let filePath = loc.source;
|
||||
let line = loc.start.line;
|
||||
let column = loc.start.column;
|
||||
if (!filePath) return false;
|
||||
if (filePath === null) return false;
|
||||
if (this._stepStartData) {
|
||||
if (
|
||||
filePath === this._stepStartData.filePath &&
|
||||
|
@ -39,7 +39,7 @@ export class SteppingManager {
|
||||
}
|
||||
|
||||
_processStepIn(loc: BabelNodeSourceLocation): void {
|
||||
invariant(loc && loc.source);
|
||||
invariant(loc && loc.source !== null);
|
||||
if (!this._keepOldSteppers) {
|
||||
this._steppers = [];
|
||||
}
|
||||
@ -49,7 +49,7 @@ export class SteppingManager {
|
||||
}
|
||||
|
||||
_processStepOver(loc: BabelNodeSourceLocation): void {
|
||||
invariant(loc && loc.source);
|
||||
invariant(loc && loc.source !== null);
|
||||
if (!this._keepOldSteppers) {
|
||||
this._steppers = [];
|
||||
}
|
||||
@ -59,7 +59,7 @@ export class SteppingManager {
|
||||
}
|
||||
|
||||
_processStepOut(loc: BabelNodeSourceLocation): void {
|
||||
invariant(loc && loc.source);
|
||||
invariant(loc && loc.source !== null);
|
||||
if (!this._keepOldSteppers) {
|
||||
this._steppers = [];
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ export class VariableManager {
|
||||
}
|
||||
|
||||
_getAbstractValueDisplay(value: AbstractValue): string {
|
||||
if (value.intrinsicName && !value.intrinsicName.startsWith("_")) {
|
||||
if (value.intrinsicName !== undefined && !value.intrinsicName.startsWith("_")) {
|
||||
return value.intrinsicName;
|
||||
}
|
||||
return "Abstract " + value.types.getType().name;
|
||||
|
@ -27,7 +27,7 @@ export default function(
|
||||
// 1. If BindingIdentifieropt is not present, let className be undefined.
|
||||
let className;
|
||||
// 2. Else, let className be StringValue of BindingIdentifier.
|
||||
if (ast.id) {
|
||||
if (ast.id != null) {
|
||||
className = ast.id.name;
|
||||
}
|
||||
// 3. Let value be the result of ClassDefinitionEvaluation of ClassTail with argument className.
|
||||
@ -36,7 +36,7 @@ export default function(
|
||||
// 4. ReturnIfAbrupt(value).
|
||||
|
||||
// 5. If className is not undefined, then
|
||||
if (className) {
|
||||
if (className !== undefined) {
|
||||
// a. Let hasNameProperty be HasOwnProperty(value, "name").
|
||||
let hasNameProperty = HasOwnProperty(realm, value, "name");
|
||||
|
||||
|
@ -29,7 +29,7 @@ export default function(
|
||||
// ECMA262 14.1.21
|
||||
|
||||
if (ast.id) {
|
||||
if (ast.generator) {
|
||||
if (ast.generator === true) {
|
||||
// 1. If the function code for this GeneratorExpression is strict mode code, let strict be true. Otherwise let strict be false.
|
||||
let strict = strictCode || IsStrict(ast.body);
|
||||
|
||||
@ -117,7 +117,7 @@ export default function(
|
||||
return closure;
|
||||
}
|
||||
} else {
|
||||
if (ast.generator) {
|
||||
if (ast.generator === true) {
|
||||
// 1. If the function code for this GeneratorExpression is strict mode code, let strict be true. Otherwise let strict be false.
|
||||
let strict = strictCode || IsStrict(ast.body);
|
||||
|
||||
|
@ -36,7 +36,7 @@ export default function(
|
||||
let baseValue = Environment.GetValue(realm, baseReference);
|
||||
|
||||
let propertyNameValue;
|
||||
if (ast.computed) {
|
||||
if (ast.computed === true) {
|
||||
// 3. Let propertyNameReference be the result of evaluating Expression.
|
||||
let propertyNameReference = env.evaluate(ast.property, strictCode);
|
||||
|
||||
|
@ -24,6 +24,6 @@ export default function(
|
||||
return RegExpCreate(
|
||||
realm,
|
||||
new StringValue(realm, ast.pattern),
|
||||
ast.flags ? new StringValue(realm, ast.flags) : undefined
|
||||
ast.flags !== undefined ? new StringValue(realm, ast.flags) : undefined
|
||||
);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ export default function SuperProperty(
|
||||
realm: Realm
|
||||
): Reference {
|
||||
// SuperProperty : super [ Expression ]
|
||||
if (ast.computed) {
|
||||
if (ast.computed === true) {
|
||||
// 1. Let propertyNameReference be the result of evaluating Expression.
|
||||
let propertyNameReference = env.evaluate(ast.property, strictCode);
|
||||
|
||||
|
@ -66,7 +66,7 @@ export default function(
|
||||
}
|
||||
}
|
||||
Properties.PutValue(realm, expr, newAbstractValue);
|
||||
if (ast.prefix) {
|
||||
if (ast.prefix === true) {
|
||||
return newAbstractValue;
|
||||
} else {
|
||||
return oldExpr;
|
||||
@ -74,7 +74,7 @@ export default function(
|
||||
}
|
||||
let oldValue = To.ToNumber(realm, oldExpr);
|
||||
|
||||
if (ast.prefix) {
|
||||
if (ast.prefix === true) {
|
||||
if (ast.operator === "++") {
|
||||
// ECMA262 12.4.6.1
|
||||
|
||||
|
@ -65,7 +65,7 @@ export function describeLocation(
|
||||
if (!locString) {
|
||||
if (loc) {
|
||||
locString = `${loc.start.line}:${loc.start.column + 1}`;
|
||||
if (loc.source) locString = `${loc.source}:${locString}`;
|
||||
if (loc.source !== null) locString = `${loc.source}:${locString}`;
|
||||
} else {
|
||||
locString = (loc ? loc.source : undefined) || "unknown";
|
||||
if (!displayName) return undefined;
|
||||
|
@ -541,7 +541,7 @@ export default function(realm: Realm): ObjectValue {
|
||||
kind: "JSON.parse(...)",
|
||||
});
|
||||
unfiltered.values = new ValuesDomain(new Set([parseResult]));
|
||||
invariant(unfiltered.intrinsicName);
|
||||
invariant(unfiltered.intrinsicName !== undefined);
|
||||
invariant(realm.generator);
|
||||
realm.rebuildNestedProperties(unfiltered, unfiltered.intrinsicName);
|
||||
} else {
|
||||
|
@ -1127,7 +1127,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
|
||||
|
||||
// ECMA262 22.2.3.23
|
||||
obj.defineNativeMethod("set", 1, (context, [overloaded, offset]) => {
|
||||
if (!overloaded.$TypedArrayName) {
|
||||
if (overloaded.$TypedArrayName === undefined) {
|
||||
let array = overloaded;
|
||||
|
||||
// 1. Assert: array is any ECMAScript language value other than an Object with a [[TypedArrayName]] internal slot. If it is such an Object, the definition in 22.2.3.23.2 applies.
|
||||
|
@ -90,7 +90,7 @@ export class ResidualHeapGraphGenerator extends ResidualHeapVisitor {
|
||||
|
||||
_getValueId(val: Value): number {
|
||||
let id = this._valueIds.get(val);
|
||||
if (!id) {
|
||||
if (id === undefined) {
|
||||
this._valueIds.set(val, ++this._idSeed);
|
||||
id = this._idSeed;
|
||||
}
|
||||
@ -113,7 +113,7 @@ export class ResidualHeapGraphGenerator extends ResidualHeapVisitor {
|
||||
// TODO: does not use ref count yet, figure out how to best visualize it later.
|
||||
const serializedId = this._valueIdentifiers.getIdentifier(val);
|
||||
invariant(serializedId);
|
||||
return val.__originalName ? `${serializedId.name}(${val.__originalName})` : serializedId.name;
|
||||
return val.__originalName !== undefined ? `${serializedId.name}(${val.__originalName})` : serializedId.name;
|
||||
}
|
||||
|
||||
_generateDotGraphData(nodes: Set<Value>, edges: Array<Edge>): string {
|
||||
|
@ -86,7 +86,7 @@ export class ResidualHeapValueIdentifiers {
|
||||
let valToRefCount = this.valToRefCount;
|
||||
invariant(valToRefCount !== undefined);
|
||||
let refCount = valToRefCount.get(val);
|
||||
if (refCount) {
|
||||
if (refCount !== undefined) {
|
||||
refCount++;
|
||||
} else {
|
||||
refCount = 1;
|
||||
|
@ -146,7 +146,7 @@ export function verboseToDisplayJson(obj: {}, depth: number): DisplayResult {
|
||||
let prop = obj[key];
|
||||
if (!prop) continue;
|
||||
let value = valueOfProp(prop);
|
||||
if (value && value !== "[object Object]") result[key] = value;
|
||||
if (value !== undefined && value !== "[object Object]") result[key] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -164,7 +164,7 @@ export function createModelledFunctionCall(
|
||||
let argModel = typeof argModelInput === "string" ? (JSON.parse(argModelInput): ArgModel) : argModelInput;
|
||||
invariant(funcValue instanceof ECMAScriptSourceFunctionValue);
|
||||
let params = funcValue.$FormalParameters;
|
||||
if (numArgs && numArgs > 0 && params) {
|
||||
if (numArgs !== undefined && numArgs > 0 && params) {
|
||||
for (let parameterId of params) {
|
||||
if (t.isIdentifier(parameterId)) {
|
||||
// $FlowFixMe: Flow strict file does not allow for casting
|
||||
|
@ -23,7 +23,7 @@ export class DebugReproManagerImplementation {
|
||||
if (configArgs.sourcemaps) {
|
||||
this._sourceMapNames = [];
|
||||
configArgs.sourcemaps.forEach(m => {
|
||||
if (m.sourceMapFilename) this._sourceMapNames.push(m.sourceMapFilename);
|
||||
if (m.sourceMapFilename !== undefined) this._sourceMapNames.push(m.sourceMapFilename);
|
||||
});
|
||||
}
|
||||
this._usedSourceFiles = new Set();
|
||||
|
@ -171,7 +171,12 @@ export class HeapInspector {
|
||||
let targetDescriptor = this.getTargetIntegrityDescriptor(val);
|
||||
|
||||
if (IsArray(this.realm, val)) {
|
||||
if (key === "length" && desc.writable === targetDescriptor.writable && !desc.enumerable && !desc.configurable) {
|
||||
if (
|
||||
key === "length" &&
|
||||
desc.writable === targetDescriptor.writable &&
|
||||
desc.enumerable !== true &&
|
||||
desc.configurable !== true
|
||||
) {
|
||||
// length property has the correct descriptor values
|
||||
return true;
|
||||
}
|
||||
@ -183,8 +188,8 @@ export class HeapInspector {
|
||||
}
|
||||
// length property will be inferred already by the amount of parameters
|
||||
return (
|
||||
!desc.writable &&
|
||||
!desc.enumerable &&
|
||||
desc.writable !== true &&
|
||||
desc.enumerable !== true &&
|
||||
desc.configurable === targetDescriptor.configurable &&
|
||||
val.hasDefaultLength()
|
||||
);
|
||||
@ -202,7 +207,7 @@ export class HeapInspector {
|
||||
!this.realm.isCompatibleWith("mobile") &&
|
||||
(desc.value instanceof AbstractValue ||
|
||||
(desc.value instanceof ConcreteValue &&
|
||||
val.__originalName &&
|
||||
val.__originalName !== undefined &&
|
||||
val.__originalName !== "" &&
|
||||
To.ToString(this.realm, desc.value) !== val.__originalName))
|
||||
)
|
||||
@ -217,7 +222,7 @@ export class HeapInspector {
|
||||
if (
|
||||
!val.$Strict &&
|
||||
desc.writable === (!val.$Strict && targetDescriptor.writable) &&
|
||||
!desc.enumerable &&
|
||||
desc.enumerable !== true &&
|
||||
desc.configurable === targetDescriptor.configurable &&
|
||||
desc.value instanceof UndefinedValue &&
|
||||
val.$FunctionKind === "normal"
|
||||
@ -228,8 +233,8 @@ export class HeapInspector {
|
||||
// ignore the `prototype` property when it's the right one
|
||||
if (key === "prototype") {
|
||||
if (
|
||||
!desc.configurable &&
|
||||
!desc.enumerable &&
|
||||
desc.configurable !== true &&
|
||||
desc.enumerable !== true &&
|
||||
desc.writable === targetDescriptor.writable &&
|
||||
desc.value instanceof ObjectValue &&
|
||||
desc.value.originalConstructor === val
|
||||
@ -244,8 +249,8 @@ export class HeapInspector {
|
||||
if (
|
||||
key === "lastIndex" &&
|
||||
desc.writable === targetDescriptor.writable &&
|
||||
!desc.enumerable &&
|
||||
!desc.configurable
|
||||
desc.enumerable !== true &&
|
||||
desc.configurable !== true
|
||||
) {
|
||||
// length property has the correct descriptor values
|
||||
let v = desc.value;
|
||||
@ -260,7 +265,7 @@ export class HeapInspector {
|
||||
if (key === "constructor") {
|
||||
if (
|
||||
desc.configurable === targetDescriptor.configurable &&
|
||||
!desc.enumerable &&
|
||||
desc.enumerable !== true &&
|
||||
desc.writable === targetDescriptor.writable &&
|
||||
desc.value === val.originalConstructor
|
||||
)
|
||||
|
@ -59,7 +59,7 @@ export class SourceMapManager {
|
||||
let originalSourcePaths = [];
|
||||
let mapPaths = [];
|
||||
for (let map of sourceMaps) {
|
||||
invariant(map.sourceMapContents); // Checked above.
|
||||
invariant(map.sourceMapContents !== undefined); // Checked above.
|
||||
let parsed = JSON.parse(map.sourceMapContents);
|
||||
// Two formats for sourcemaps exist.
|
||||
if ("sections" in parsed) {
|
||||
|
@ -517,7 +517,7 @@ class ObjectValueLeakingVisitor {
|
||||
(val.kind === "widened numeric property" || // TODO: Widened properties needs to be havocable.
|
||||
val.kind.startsWith("abstractCounted"));
|
||||
invariant(
|
||||
whitelistedKind || val.intrinsicName || val.args.length > 0,
|
||||
whitelistedKind !== undefined || val.intrinsicName !== undefined || val.args.length > 0,
|
||||
"Havoced unknown object requires havocable arguments"
|
||||
);
|
||||
|
||||
|
@ -232,7 +232,7 @@ export default class ArrayValue extends ObjectValue {
|
||||
}
|
||||
|
||||
static isIntrinsicAndHasWidenedNumericProperty(obj: Value): boolean {
|
||||
if (obj instanceof ArrayValue && obj.intrinsicName) {
|
||||
if (obj instanceof ArrayValue && obj.intrinsicName !== undefined) {
|
||||
const prop = obj.unknownProperty;
|
||||
if (prop !== undefined && prop.descriptor !== undefined) {
|
||||
const desc = prop.descriptor.throwIfNotConcrete(obj.$Realm);
|
||||
|
@ -106,7 +106,7 @@ export default class IntegerIndexedExotic extends ObjectValue {
|
||||
if (numericIndex < 0) return false;
|
||||
|
||||
// vi. If numericIndex ≥ O.[[ArrayLength]], return false.
|
||||
invariant(O.$ArrayLength);
|
||||
invariant(O.$ArrayLength !== undefined);
|
||||
if (numericIndex >= O.$ArrayLength) return false;
|
||||
|
||||
// vii. Return true.
|
||||
|
@ -4172,9 +4172,9 @@ flat-cache@^1.2.1:
|
||||
graceful-fs "^4.1.2"
|
||||
write "^0.2.1"
|
||||
|
||||
flow-bin@^0.79.1:
|
||||
version "0.79.1"
|
||||
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.79.1.tgz#01c9f427baa6556753fa878c192d42e1ecb764b6"
|
||||
flow-bin@^0.80.0:
|
||||
version "0.80.0"
|
||||
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.80.0.tgz#04cc1ee626a6f50786f78170c92ebe1745235403"
|
||||
|
||||
flow-typed@^2.3.0:
|
||||
version "2.3.0"
|
||||
|
Loading…
Reference in New Issue
Block a user