diff --git a/index.js b/index.js index b8c33665..93e04786 100644 --- a/index.js +++ b/index.js @@ -49,6 +49,7 @@ module.exports = { }); } + opts.originalText = text; ast.tokens = []; const printer = new Printer(opts); diff --git a/src/printer.js b/src/printer.js index a4f7e960..080e888c 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1600,7 +1600,6 @@ function printStatementSequence(path, options, print) { let inClassBody = namedTypes.ClassBody && namedTypes.ClassBody.check(path.getParentNode()); let printed = []; - let prevAddSpacing = false; path.map(function(stmtPath, i) { var stmt = stmtPath.getValue(); @@ -1617,23 +1616,16 @@ function printStatementSequence(path, options, print) { return; } - const addSpacing = shouldAddSpacing(stmt); const stmtPrinted = print(stmtPath); const parts = []; - if (!prevAddSpacing && addSpacing && !isFirstStatement(stmtPath)) { - parts.push(hardline); - } - parts.push(stmtPrinted); - if (addSpacing && !isLastStatement(stmtPath)) { + if (shouldAddSpacing(stmt, options) && !isLastStatement(stmtPath)) { parts.push(hardline); } printed.push(concat(parts)); - - prevAddSpacing = addSpacing; }); return join(hardline, printed); @@ -2073,12 +2065,28 @@ function nodeStr(str, options) { } } -function shouldAddSpacing(node) { - return node.type === "IfStatement" || node.type === "ForStatement" || - node.type === "ForInStatement" || - node.type === "ForOfStatement" || - node.type === "ExpressionStatement" || - node.type === "FunctionDeclaration"; +function shouldAddSpacing(node, options) { + const text = options.originalText; + const length = text.length; + let cursor = node.end + 1; + // Look forward and see if there is a blank line after this code by + // scanning up to the next non-indentation character. + while(cursor < length) { + const c = text.charAt(cursor); + // Skip any indentation characters (this will detect lines with + // spaces or tabs as blank) + if(c !== " " && c !== "\t") { + // If the next character is a newline, this line is blank so we + // should add a blank line. + if(c === "\n" || c === "\r") { + return true; + } + return false; + } + cursor++; + } + + return false; } function isFirstStatement(path) { diff --git a/src/printer2.js b/src/printer2.js deleted file mode 100644 index 27233e0f..00000000 --- a/src/printer2.js +++ /dev/null @@ -1,1980 +0,0 @@ -var assert = require("assert"); -var sourceMap = require("source-map"); -var printComments = require("./comments").printComments; -var pp = require("./pp"); -var fromString = pp.fromString; -var concat = pp.concat; -var isEmpty = pp.isEmpty; -var join = pp.join; -var line = pp.line; -var hardline = pp.hardline; -var softline = pp.softline; -var literalline = pp.literalline; -var group = pp.group; -var multilineGroup = pp.multilineGroup; -var indent = pp.indent; -var getFirstString = pp.getFirstString; -var hasHardLine = pp.hasHardLine; -var conditionalGroup = pp.conditionalGroup; -var normalizeOptions = require("./options").normalize; -var types = require("ast-types"); -var namedTypes = types.namedTypes; -var isString = types.builtInTypes.string; -var isObject = types.builtInTypes.object; -var FastPath = require("./fast-path"); -var util = require("./util"); - -function PrintResult(code, sourceMap) { - assert.ok(this instanceof PrintResult); - - isString.assert(code); - - this.code = code; - - if (sourceMap) { - isObject.assert(sourceMap); - - this.map = sourceMap; - } -} - -var PRp = PrintResult.prototype; -var warnedAboutToString = false; - -PRp.toString = function() { - if (!warnedAboutToString) { - console.warn( - "Deprecation warning: recast.print now returns an object with " + - "a .code property. You appear to be treating the object as a " + - "string, which might still work but is strongly discouraged." - ); - - warnedAboutToString = true; - } - - return this.code; -}; - -var emptyPrintResult = new PrintResult(""); - -function Printer(originalOptions) { - assert.ok(this instanceof Printer); - - var explicitTabWidth = originalOptions && originalOptions.tabWidth; - var options = normalizeOptions(originalOptions); - - assert.notStrictEqual(options, originalOptions); - - // It's common for client code to pass the same options into both - // recast.parse and recast.print, but the Printer doesn't need (and - // can be confused by) options.sourceFileName, so we null it out. - options.sourceFileName = null; - - function printWithComments(path) { - assert.ok(path instanceof FastPath); - - return printComments(path, print); - } - - function print(path, includeComments) { - if (includeComments) - return printWithComments(path); - - assert.ok(path instanceof FastPath); - - if (!explicitTabWidth) { - var oldTabWidth = options.tabWidth; - var loc = path.getNode().loc; - - if (loc && loc.lines && loc.lines.guessTabWidth) { - options.tabWidth = loc.lines.guessTabWidth(); - - var lines = maybeReprint(path); - - options.tabWidth = oldTabWidth; - - return lines; - } - } - - return maybeReprint(path); - } - - function maybeReprint(path) { - // TODO: remove this function entirely as we don't ever keep the - // previous formatting - return printRootGenerically(path); - } - - // Print the root node generically, but then resume reprinting its - // children non-generically. - function printRootGenerically(path, includeComments) { - return (includeComments ? printComments( - path, - printRootGenerically - ) : genericPrint(path, options, printWithComments)); - } - - // Print the entire AST generically. - function printGenerically(path) { - // return genericPrint(path, options, printGenerically); - return printComments(path, p => genericPrint(p, options, printGenerically)); - } - - this.print = function(ast) { - if (!ast) { - return emptyPrintResult; - } - - var lines = print(FastPath.from(ast), true); - return new PrintResult( - lines.toString(options), - util.composeSourceMaps( - options.inputSourceMap, - lines.getSourceMap(options.sourceMapName, options.sourceRoot) - ) - ); - }; - - this.printGenerically = function(ast) { - if (!ast) { - return emptyPrintResult; - } - - var path = FastPath.from(ast); - var oldReuseWhitespace = options.reuseWhitespace; - - // Do not reuse whitespace (or anything else, for that matter) - // when printing generically. - options.reuseWhitespace = false; - - var res = printGenerically(path); - var pr = new PrintResult(pp.print(options.printWidth, res)); - - options.reuseWhitespace = oldReuseWhitespace; - - return pr; - }; -} - -exports.Printer = Printer; - -function maybeAddParens(path, lines) { - return (path.needsParens() ? concat([ "(", lines, ")" ]) : lines); -} - -function genericPrint(path, options, printPath) { - assert.ok(path instanceof FastPath); - - var node = path.getValue(); - var parts = []; - var needsParens = false; - var linesWithoutParens = genericPrintNoParens(path, options, printPath); - - if (!node || isEmpty(linesWithoutParens)) { - return linesWithoutParens; - } - - if ( - node.decorators && node.decorators.length > 0 && - // If the parent node is an export declaration, it will be - // responsible for printing node.decorators. - !util.getParentExportDeclaration(path) - ) { - path.each( - function(decoratorPath) { - parts.push(printPath(decoratorPath), line); - }, - "decorators" - ); - } else - if ( - util.isExportDeclaration(node) && node.declaration && - node.declaration.decorators - ) { - // Export declarations are responsible for printing any decorators - // that logically apply to node.declaration. - path.each( - function(decoratorPath) { - parts.push(printPath(decoratorPath), line); - }, - "declaration", - "decorators" - ); - } else { - // Nodes with decorators can't have parentheses, so we can avoid - // computing path.needsParens() except in this case. - needsParens = path.needsParens(); - } - - if (needsParens) { - parts.unshift("("); - } - - parts.push(linesWithoutParens); - - if (needsParens) { - parts.push(")"); - } - - return concat(parts); -} - -function genericPrintNoParens(path, options, print) { - var n = path.getValue(); - - if (!n) { - return fromString(""); - } - - if (typeof n === "string") { - return fromString(n, options); - } - - // TODO: For some reason NumericLiteralTypeAnnotation is not - // printable so this throws, but I think that's a bug in ast-types. - // This assert isn't very useful though. - // namedTypes.Printable.assert(n); - var parts = []; - switch (n.type) { - case "File": - return path.call(print, "program"); - case "Program": - - // Babel 6 - if (n.directives) { - path.each( - function(childPath) { - parts.push(print(childPath), ";", hardline); - }, - "directives" - ); - } - - parts.push(path.call( - function(bodyPath) { - return printStatementSequence(bodyPath, options, print); - }, - "body" - )); - - // Make sure the file always ends with a newline - parts.push(hardline); - - return concat(parts); - // Babel extension. - case "Noop": - case "EmptyStatement": - return fromString(""); - case "ExpressionStatement": - return concat([ path.call(print, "expression"), ";" ]); - case // Babel extension. - "ParenthesizedExpression": - return concat([ "(", path.call(print, "expression"), ")" ]); - case "AssignmentExpression": - return group( - concat([ - path.call(print, "left"), - " ", - n.operator, - " ", - path.call(print, "right") - ]) - ); - case "BinaryExpression": - case "LogicalExpression": - return group( - concat([ - path.call(print, "left"), - " ", - n.operator, - indent(options.tabWidth, concat([ line, path.call(print, "right") ])) - ]) - ); - case "AssignmentPattern": - return concat([ - path.call(print, "left"), - " = ", - path.call(print, "right") - ]); - case "MemberExpression": - - parts.push(path.call(print, "object")); - - var property = path.call(print, "property"); - - if (n.computed) { - parts.push("[", property, "]"); - } else { - parts.push(".", property); - } - - return concat(parts); - case "MetaProperty": - return concat([ - path.call(print, "meta"), - ".", - path.call(print, "property") - ]); - case "BindExpression": - - if (n.object) { - parts.push(path.call(print, "object")); - } - - parts.push("::", path.call(print, "callee")); - - return concat(parts); - case "Path": - return fromString(".").join(n.body); - case "Identifier": - return concat([ - n.name, - (n.optional ? "?" : ""), - path.call(print, "typeAnnotation") - ]); - case "SpreadElement": - case "SpreadElementPattern": - // Babel 6 for ObjectPattern - case "RestProperty": - case "SpreadProperty": - case "SpreadPropertyPattern": - case "RestElement": - return concat([ "...", path.call(print, "argument") ]); - case "FunctionDeclaration": - case "FunctionExpression": - - if (n.async) - parts.push("async "); - - parts.push("function"); - - if (n.generator) - parts.push("*"); - - if (n.id) { - parts.push(" ", path.call(print, "id")); - } - - parts.push( - path.call(print, "typeParameters"), - printFunctionParams(path, print, options), - printReturnType(path, print), - " ", - path.call(print, "body") - ); - - return group(concat(parts)); - case "ArrowFunctionExpression": - - if (n.async) - parts.push("async "); - - if (n.typeParameters) { - parts.push(path.call(print, "typeParameters")); - } - - if ( - !options.arrowParensAlways && n.params.length === 1 && !n.rest && - n.params[0].type === "Identifier" && - !n.params[0].typeAnnotation && - !n.predicate && - !n.returnType - ) { - parts.push(path.call(print, "params", 0)); - } else { - parts.push( - printFunctionParams(path, print, options), - printReturnType(path, print) - ); - } - - parts.push(" => ", path.call(print, "body")); - - return group(concat(parts)); - case "MethodDefinition": - - if (n.static) { - parts.push("static "); - } - - parts.push(printMethod(path, options, print)); - - return concat(parts); - case "YieldExpression": - - parts.push("yield"); - - if (n.delegate) - parts.push("*"); - - if (n.argument) - parts.push(" ", path.call(print, "argument")); - - return concat(parts); - case "AwaitExpression": - - parts.push("await"); - - if (n.all) - parts.push("*"); - - if (n.argument) - parts.push(" ", path.call(print, "argument")); - - return concat(parts); - case "ModuleDeclaration": - - parts.push("module", path.call(print, "id")); - - if (n.source) { - assert.ok(!n.body); - - parts.push("from", path.call(print, "source")); - } else { - parts.push(path.call(print, "body")); - } - - return fromString(" ").join(parts); - case "ImportSpecifier": - - if (n.imported) { - parts.push(path.call(print, "imported")); - - if (n.local && n.local.name !== n.imported.name) { - parts.push(" as ", path.call(print, "local")); - } - } else - if (n.id) { - parts.push(path.call(print, "id")); - - if (n.name) { - parts.push(" as ", path.call(print, "name")); - } - } - - return concat(parts); - case "ExportSpecifier": - - if (n.local) { - parts.push(path.call(print, "local")); - - if (n.exported && n.exported.name !== n.local.name) { - parts.push(" as ", path.call(print, "exported")); - } - } else - if (n.id) { - parts.push(path.call(print, "id")); - - if (n.name) { - parts.push(" as ", path.call(print, "name")); - } - } - - return concat(parts); - case "ExportBatchSpecifier": - return fromString("*"); - case "ImportNamespaceSpecifier": - - parts.push("* as "); - - if (n.local) { - parts.push(path.call(print, "local")); - } else - if (n.id) { - parts.push(path.call(print, "id")); - } - - return concat(parts); - case "ImportDefaultSpecifier": - - if (n.local) { - return path.call(print, "local"); - } - - return path.call(print, "id"); - case "ExportDeclaration": - case "ExportDefaultDeclaration": - case "ExportNamedDeclaration": - return printExportDeclaration(path, options, print); - case "ExportAllDeclaration": - - parts.push("export *"); - - if (n.exported) { - parts.push(" as ", path.call(print, "exported")); - } - - parts.push(" from ", path.call(print, "source")); - - return concat(parts); - case "ExportNamespaceSpecifier": - return concat([ "* as ", path.call(print, "exported") ]); - case "ExportDefaultSpecifier": - return path.call(print, "exported"); - case "ImportDeclaration": - - parts.push("import "); - - if (n.importKind && n.importKind !== "value") { - parts.push(n.importKind + " "); - } - - if (n.specifiers && n.specifiers.length > 0) { - var foundImportSpecifier = false; - - path.each( - function(specifierPath) { - var i = specifierPath.getName(); - - if (i > 0) { - parts.push(", "); - } - - var value = specifierPath.getValue(); - - if ( - namedTypes.ImportDefaultSpecifier.check(value) || - namedTypes.ImportNamespaceSpecifier.check(value) - ) { - assert.strictEqual(foundImportSpecifier, false); - } else { - namedTypes.ImportSpecifier.assert(value); - - if (!foundImportSpecifier) { - foundImportSpecifier = true; - - parts.push((options.objectCurlySpacing ? "{ " : "{")); - } - } - - parts.push(print(specifierPath)); - }, - "specifiers" - ); - - if (foundImportSpecifier) { - parts.push((options.objectCurlySpacing ? " }" : "}")); - } - - parts.push(" from "); - } - - parts.push(path.call(print, "source"), ";"); - - return concat(parts); - case "BlockStatement": - var naked = path.call( - function(bodyPath) { - return printStatementSequence(bodyPath, options, print); - }, - "body" - ); - - // If there are no contents, return a simple block - if (!getFirstString(naked)) { - return "{}"; - } - - parts.push("{"); - - // Babel 6 - if (n.directives) { - path.each( - function(childPath) { - parts.push( - indent( - options.tabWidth, - concat([ line, print(childPath), ";", line ]) - ) - ); - }, - "directives" - ); - } - - parts.push(indent(options.tabWidth, concat([ hardline, naked ]))); - - parts.push(hardline, "}"); - - return concat(parts); - case "ReturnStatement": - - parts.push("return"); - - var arg = path.call(print, "argument"); - - if (n.argument) { - if ( - namedTypes.JSXElement && namedTypes.JSXElement.check(n.argument) && - hasHardLine(arg) - ) { - parts.push( - " (", - indent(options.tabWidth, concat([ hardline, arg ])), - hardline, - ")" - ); - } else { - parts.push(" ", arg); - } - } - - parts.push(";"); - - return concat(parts); - case "CallExpression": - return concat([ - path.call(print, "callee"), - printArgumentsList(path, options, print) - ]); - case "ObjectExpression": - case "ObjectPattern": - case "ObjectTypeAnnotation": - var allowBreak = false; - var isTypeAnnotation = n.type === "ObjectTypeAnnotation"; - // Leave this here because we *might* want to make this - // configurable later -- flow accepts ";" for type separators - var separator = (isTypeAnnotation ? "," : ","); - var fields = []; - var leftBrace = (n.exact ? "{|" : "{"); - var rightBrace = (n.exact ? "|}" : "}"); - - if (isTypeAnnotation) { - fields.push("indexers", "callProperties"); - } - - fields.push("properties"); - - var i = 0; - var props = []; - - fields.forEach(function(field) { - path.each( - function(childPath) { - props.push(group(print(childPath))); - }, - field - ); - }); - - if (props.length === 0) { - return "{}"; - } else { - return multilineGroup( - concat([ - leftBrace, - indent( - options.tabWidth, - concat([ - (options.bracketSpacing ? line : softline), - join(concat([ separator, line ]), props) - ]) - ), - (options.bracketSpacing ? line : softline), - rightBrace, - path.call(print, "typeAnnotation") - ]) - ); - } - - case "PropertyPattern": - return concat([ - path.call(print, "key"), - ": ", - path.call(print, "pattern") - ]); - // Babel 6 - case "ObjectProperty": - case // Non-standard AST node type. - "Property": - - if (n.method || n.kind === "get" || n.kind === "set") { - return printMethod(path, options, print); - } - - if (n.computed) { - parts.push("[", path.call(print, "key"), "]"); - } else { - parts.push(path.call(print, (n.shorthand ? "value" : "key"))); - } - - if (!n.shorthand) { - parts.push(": ", path.call(print, "value")); - } - - return concat(parts); - case // Babel 6 - "ClassMethod": - - if (n.static) { - parts.push("static "); - } - - parts = parts.concat(printObjectMethod(path, options, print)); - - return concat(parts); - case // Babel 6 - "ObjectMethod": - return printObjectMethod(path, options, print); - case "Decorator": - return concat([ "@", path.call(print, "expression") ]); - case "ArrayExpression": - case "ArrayPattern": - - if (n.elements.length === 0) { - parts.push("[]"); - } else { - parts.push( - multilineGroup( - concat([ - "[", - indent( - options.tabWidth, - concat([ - line, - join(concat([ ",", line ]), path.map(print, "elements")) - ]) - ), - line, - "]" - ]) - ) - ); - } - - if (n.typeAnnotation) - parts.push(path.call(print, "typeAnnotation")); - - return concat(parts); - case "SequenceExpression": - return join(", ", path.map(print, "expressions")); - case "ThisExpression": - return fromString("this"); - case "Super": - return fromString("super"); - case // Babel 6 Literal split - "NullLiteral": - return fromString("null"); - case // Babel 6 Literal split - "RegExpLiteral": - return fromString(n.extra.raw); - // Babel 6 Literal split - case "BooleanLiteral": - // Babel 6 Literal split - case "NumericLiteral": - // Babel 6 Literal split - case "StringLiteral": - case "Literal": - - if (typeof n.value !== "string") - return fromString(n.value, options); - - return nodeStr(n.value, options); - case // Babel 6 - "Directive": - return path.call(print, "value"); - case // Babel 6 - "DirectiveLiteral": - return fromString(nodeStr(n.value, options)); - case "ModuleSpecifier": - - if (n.local) { - throw new Error("The ESTree ModuleSpecifier type should be abstract"); - } - - // The Esprima ModuleSpecifier type is just a string-valued - // Literal identifying the imported-from module. - return fromString(nodeStr(n.value, options), options); - case "UnaryExpression": - - parts.push(n.operator); - - if (/[a-z]$/.test(n.operator)) - parts.push(" "); - - parts.push(path.call(print, "argument")); - - return concat(parts); - case "UpdateExpression": - - parts.push(path.call(print, "argument"), n.operator); - - if (n.prefix) - parts.reverse(); - - return concat(parts); - case "ConditionalExpression": - return concat([ - "(", - path.call(print, "test"), - " ? ", - path.call(print, "consequent"), - " : ", - path.call(print, "alternate"), - ")" - ]); - case "NewExpression": - - parts.push("new ", path.call(print, "callee")); - - var args = n.arguments; - - if (args) { - parts.push(printArgumentsList(path, options, print)); - } - - return concat(parts); - case "VariableDeclaration": - var printed = path.map( - function(childPath) { - return print(childPath); - }, - "declarations" - ); - - parts = [ - n.kind, - " ", - printed[0], - indent( - options.tabWidth, - concat(printed.slice(1).map(p => concat([ ",", line, p ]))) - ) - ]; - - // We generally want to terminate all variable declarations with a - // semicolon, except when they are children of for loops. - var parentNode = path.getParentNode(); - - if ( - !namedTypes.ForStatement.check(parentNode) && - !namedTypes.ForInStatement.check(parentNode) && - !(namedTypes.ForOfStatement && - namedTypes.ForOfStatement.check(parentNode)) && - !(namedTypes.ForAwaitStatement && - namedTypes.ForAwaitStatement.check(parentNode)) - ) { - parts.push(";"); - } - - return multilineGroup(concat(parts)); - case "VariableDeclarator": - return (n.init ? concat([ - path.call(print, "id"), - " = ", - path.call(print, "init") - ]) : path.call(print, "id")); - case "WithStatement": - return concat([ - "with (", - path.call(print, "object"), - ") ", - path.call(print, "body") - ]); - // var con = adjustClause(path.call(print, "consequent"), options), - // parts = ["if (", path.call(print, "test"), ")", con]; - // if (n.alternate) - // parts.push( - // endsWithBrace(con) ? " else" : "\nelse", - // adjustClause(path.call(print, "alternate"), options)); - // return concat(parts); - case "IfStatement": - const con = adjustClause(path.call(print, "consequent"), options); - - parts = [ - "if (", - group( - concat([ - indent( - options.tabWidth, - concat([ softline, path.call(print, "test") ]) - ), - softline - ]) - ), - ")", - con - ]; - - if (n.alternate) { - const hasBraces = getFirstString(con) === "{"; - - parts.push( - (hasBraces ? " else" : "\nelse"), - adjustClause(path.call(print, "alternate"), options) - ); - } - - return concat(parts); - case "ForStatement": - // TODO Get the for (;;) case right. - return concat([ - "for (", - group( - concat([ - indent( - options.tabWidth, - concat([ - softline, - path.call(print, "init"), - ";", - line, - path.call(print, "test"), - ";", - line, - path.call(print, "update") - ]) - ), - softline - ]) - ), - ")", - adjustClause(path.call(print, "body"), options) - ]); - case "WhileStatement": - return concat([ - "while (", - path.call(print, "test"), - ")", - adjustClause(path.call(print, "body"), options) - ]); - case "ForInStatement": - // Note: esprima can't actually parse "for each (". - return concat([ - (n.each ? "for each (" : "for ("), - path.call(print, "left"), - " in ", - path.call(print, "right"), - ")", - adjustClause(path.call(print, "body"), options) - ]); - case "ForOfStatement": - return concat([ - "for (", - path.call(print, "left"), - " of ", - path.call(print, "right"), - ")", - adjustClause(path.call(print, "body"), options) - ]); - case "ForAwaitStatement": - return concat([ - "for await (", - path.call(print, "left"), - " of ", - path.call(print, "right"), - ")", - adjustClause(path.call(print, "body"), options) - ]); - case "DoWhileStatement": - var clause = adjustClause(path.call(print, "body"), options); - var doBody = concat([ "do", clause ]); - var parts = [ doBody ]; - const hasBraces = getFirstString(clause) === "{"; - - if (hasBraces) - parts.push(" while"); -else - parts.push(concat([ line, "while" ])); - - parts.push(" (", path.call(print, "test"), ");"); - - return concat(parts); - case "DoExpression": - var statements = path.call( - function(bodyPath) { - return printStatementSequence(bodyPath, options, print); - }, - "body" - ); - return concat([ "do {\n", statements.indent(options.tabWidth), "\n}" ]); - case "BreakStatement": - - parts.push("break"); - - if (n.label) - parts.push(" ", path.call(print, "label")); - - parts.push(";"); - - return concat(parts); - case "ContinueStatement": - - parts.push("continue"); - - if (n.label) - parts.push(" ", path.call(print, "label")); - - parts.push(";"); - - return concat(parts); - case "LabeledStatement": - return concat([ - path.call(print, "label"), - ":", - hardline, - path.call(print, "body") - ]); - case "TryStatement": - - parts.push("try ", path.call(print, "block")); - - if (n.handler) { - parts.push(" ", path.call(print, "handler")); - } else - if (n.handlers) { - path.each( - function(handlerPath) { - parts.push(" ", print(handlerPath)); - }, - "handlers" - ); - } - - if (n.finalizer) { - parts.push(" finally ", path.call(print, "finalizer")); - } - - return concat(parts); - case "CatchClause": - - parts.push("catch (", path.call(print, "param")); - - if (n.guard) - // Note: esprima does not recognize conditional catch clauses. - parts.push(" if ", path.call(print, "guard")); - - parts.push(") ", path.call(print, "body")); - - return concat(parts); - case "ThrowStatement": - return concat([ "throw ", path.call(print, "argument"), ";" ]); - // Note: ignoring n.lexical because it has no printing consequences. - case "SwitchStatement": - return concat([ - "switch (", - path.call(print, "discriminant"), - ") {", - hardline, - join(hardline, path.map(print, "cases")), - hardline, - "}" - ]); - case "SwitchCase": - - if (n.test) - parts.push("case ", path.call(print, "test"), ":"); -else - parts.push("default:"); - - if (n.consequent.length > 0) { - parts.push(indent(options.tabWidth, concat([ - hardline, - path.call( - function(consequentPath) { - return printStatementSequence(consequentPath, options, print); - }, - "consequent" - ) - ]))); - } - - return concat(parts); - // JSX extensions below. - case "DebuggerStatement": - return fromString("debugger;"); - case "JSXAttribute": - - parts.push(path.call(print, "name")); - - if (n.value) - parts.push("=", path.call(print, "value")); - - return concat(parts); - case "JSXIdentifier": - return fromString(n.name, options); - case "JSXNamespacedName": - return fromString( - ":" - ).join([ path.call(print, "namespace"), path.call(print, "name") ]); - case "JSXMemberExpression": - return fromString( - "." - ).join([ path.call(print, "object"), path.call(print, "property") ]); - case "JSXSpreadAttribute": - return concat([ "{...", path.call(print, "argument"), "}" ]); - case "JSXExpressionContainer": - return concat([ "{", path.call(print, "expression"), "}" ]); - case "JSXElement": - var openingLines = path.call(print, "openingElement"); - - if (n.openingElement.selfClosing) { - assert.ok(!n.closingElement); - - return openingLines; - } - - var children = []; - - path.map( - function(childPath) { - var child = childPath.getValue(); - - if ( - namedTypes.Literal.check(child) && typeof child.value === "string" - ) { - if (/\S/.test(child.value)) { - const beginBreak = child.value.match(/^\s*\n/); - const endBreak = child.value.match(/\n\s*$/); - - children.push( - (beginBreak ? hardline : ""), - child.value.replace(/^\s+|\s+$/g, ""), - (endBreak ? hardline : "") - ); - } else - if (/\n/.test(child.value)) { - children.push(hardline); - } - } else { - children.push(print(childPath)); - } - }, - "children" - ); - - var mostChildren = children.slice(0, -1); - var closingLines = path.call(print, "closingElement"); - return concat([ - openingLines, - indent(options.tabWidth, concat(mostChildren)), - util.getLast(children) || "", - closingLines - ]); - case "JSXOpeningElement": - return group( - concat([ - "<", - path.call(print, "name"), - concat(path.map(attr => concat([ " ", print(attr) ]), "attributes")), - (n.selfClosing ? "/>" : ">") - ]) - ); - case "JSXClosingElement": - return concat([ "" ]); - case "JSXText": - throw new Error("JSXTest should be handled by JSXElement"); - case "JSXEmptyExpression": - return ""; - case "TypeAnnotatedIdentifier": - return concat([ - path.call(print, "annotation"), - " ", - path.call(print, "identifier") - ]); - case "ClassBody": - - if (n.body.length === 0) { - return fromString("{}"); - } - - return concat([ - "{", - indent(options.tabWidth, concat([ - hardline, - path.call( - function(bodyPath) { - return printStatementSequence(bodyPath, options, print); - }, - "body" - ) - ])), - hardline, - "}" - ]); - case "ClassPropertyDefinition": - - parts.push("static ", path.call(print, "definition")); - - if (!namedTypes.MethodDefinition.check(n.definition)) - parts.push(";"); - - return concat(parts); - case "ClassProperty": - - if (n.static) - parts.push("static "); - - var key = path.call(print, "key"); - - if (n.computed) { - key = concat([ "[", key, "]" ]); - } else - if (n.variance === "plus") { - key = concat([ "+", key ]); - } else - if (n.variance === "minus") { - key = concat([ "-", key ]); - } - - parts.push(key); - - if (n.typeAnnotation) - parts.push(path.call(print, "typeAnnotation")); - - if (n.value) - parts.push(" = ", path.call(print, "value")); - - parts.push(";"); - - return concat(parts); - case "ClassDeclaration": - case "ClassExpression": - return concat(printClass(path, print)); - case "TemplateElement": - return join(literalline, n.value.raw.split("\n")); - case "TemplateLiteral": - var expressions = path.map(print, "expressions"); - - parts.push("`"); - - path.each( - function(childPath) { - var i = childPath.getName(); - - parts.push(print(childPath)); - - if (i < expressions.length) { - parts.push("${", expressions[i], "}"); - } - }, - "quasis" - ); - - parts.push("`"); - - return concat(parts); - // These types are unprintable because they serve as abstract - // supertypes for other (printable) types. - case "TaggedTemplateExpression": - return concat([ path.call(print, "tag"), path.call(print, "quasi") ]); - case "Node": - case "Printable": - case "SourceLocation": - case "Position": - case "Statement": - case "Function": - case "Pattern": - case "Expression": - case "Declaration": - case "Specifier": - case "NamedSpecifier": - // Supertype of Block and Line. - case "Comment": - // Flow - case "MemberTypeAnnotation": - case // Flow - "Type": - throw new Error("unprintable type: " + JSON.stringify(n.type)); - // Babel block comment. - case "CommentBlock": - case // Esprima block comment. - "Block": - return concat([ "/*", fromString(n.value, options), "*/" ]); - // Babel line comment. - case "CommentLine": - case // Esprima line comment. - "Line": - return concat([ "//", fromString(n.value, options) ]); - // Type Annotations for Facebook Flow, typically stripped out or - // transformed away before printing. - case "TypeAnnotation": - - if (n.typeAnnotation) { - if (n.typeAnnotation.type !== "FunctionTypeAnnotation") { - parts.push(": "); - } - - parts.push(path.call(print, "typeAnnotation")); - - return concat(parts); - } - - return ""; - case "TupleTypeAnnotation": - return concat([ "[", join(", ", path.map(print, "types")), "]" ]); - case "ExistentialTypeParam": - case "ExistsTypeAnnotation": - return fromString("*", options); - case "EmptyTypeAnnotation": - return fromString("empty", options); - case "AnyTypeAnnotation": - return fromString("any", options); - case "MixedTypeAnnotation": - return fromString("mixed", options); - case "ArrayTypeAnnotation": - return concat([ path.call(print, "elementType"), "[]" ]); - case "BooleanTypeAnnotation": - return fromString("boolean", options); - case "NumericLiteralTypeAnnotation": - case "BooleanLiteralTypeAnnotation": - return "" + n.value; - case "DeclareClass": - return printFlowDeclaration(path, printClass(path, print)); - case "DeclareFunction": - return printFlowDeclaration(path, [ - "function ", - path.call(print, "id"), - (n.predicate ? " " : ""), - path.call(print, "predicate"), - ";" - ]); - case "DeclareModule": - return printFlowDeclaration(path, [ - "module ", - path.call(print, "id"), - " ", - path.call(print, "body") - ]); - case "DeclareModuleExports": - return printFlowDeclaration(path, [ - "module.exports", - path.call(print, "typeAnnotation"), - ";" - ]); - case "DeclareVariable": - return printFlowDeclaration(path, [ "var ", path.call(print, "id"), ";" ]); - case "DeclareExportAllDeclaration": - return concat([ "declare export * from ", path.call(print, "source") ]); - case "DeclareExportDeclaration": - return concat([ "declare ", printExportDeclaration(path, options, print) ]); - case "FunctionTypeAnnotation": - // FunctionTypeAnnotation is ambiguous: - // declare function foo(a: B): void; OR - // var A: (a: B) => void; - var parent = path.getParentNode(0); - var isArrowFunctionTypeAnnotation = !(!parent.variance && - !parent.optional && - namedTypes.ObjectTypeProperty.check(parent) || - namedTypes.ObjectTypeCallProperty.check(parent) || - namedTypes.DeclareFunction.check(path.getParentNode(2))); - var needsColon = isArrowFunctionTypeAnnotation && - namedTypes.TypeAnnotation.check(parent); - - if (needsColon) { - parts.push(": "); - } - - parts.push(path.call(print, "typeParameters")); - - parts.push(printFunctionParams(path, print, options)); - - // The returnType is not wrapped in a TypeAnnotation, so the colon - // needs to be added separately. - if (n.returnType || n.predicate) { - parts.push( - (isArrowFunctionTypeAnnotation ? " => " : ": "), - path.call(print, "returnType"), - path.call(print, "predicate") - ); - } - - return group(concat(parts)); - case "FunctionTypeParam": - return concat([ - path.call(print, "name"), - (n.optional ? "?" : ""), - ": ", - path.call(print, "typeAnnotation") - ]); - case "GenericTypeAnnotation": - return concat([ - path.call(print, "id"), - path.call(print, "typeParameters") - ]); - case "DeclareInterface": - - parts.push("declare "); - - case "InterfaceDeclaration": - - parts.push( - fromString("interface ", options), - path.call(print, "id"), - path.call(print, "typeParameters"), - " " - ); - - if (n["extends"].length > 0) { - parts.push("extends ", join(", ", path.map(print, "extends"))); - } - - parts.push(" ", path.call(print, "body")); - - return concat(parts); - case "ClassImplements": - case "InterfaceExtends": - return concat([ - path.call(print, "id"), - path.call(print, "typeParameters") - ]); - case "IntersectionTypeAnnotation": - return join(" & ", path.map(print, "types")); - case "NullableTypeAnnotation": - return concat([ "?", path.call(print, "typeAnnotation") ]); - case "NullLiteralTypeAnnotation": - return fromString("null", options); - case "ThisTypeAnnotation": - return fromString("this", options); - case "NumberTypeAnnotation": - return fromString("number", options); - case "ObjectTypeCallProperty": - - if (n.static) { - parts.push("static "); - } - - parts.push(path.call(print, "value")); - - return concat(parts); - case "ObjectTypeIndexer": - var variance = (n.variance === "plus" ? "+" : (n.variance === - "minus" ? "-" : "")); - return concat([ - variance, - "[", - path.call(print, "id"), - ": ", - path.call(print, "key"), - "]: ", - path.call(print, "value") - ]); - case "ObjectTypeProperty": - var variance = (n.variance === "plus" ? "+" : (n.variance === - "minus" ? "-" : "")); - // TODO: This is a bad hack and we need a better way to know - // when to emit an arrow function or not. - var isFunction = !n.variance && !n.optional && - n.value.type === "FunctionTypeAnnotation"; - return concat([ - (n.static ? "static " : ""), - variance, - path.call(print, "key"), - (n.optional ? "?" : ""), - (isFunction ? "" : ": "), - path.call(print, "value") - ]); - case "QualifiedTypeIdentifier": - return concat([ - path.call(print, "qualification"), - ".", - path.call(print, "id") - ]); - case "StringLiteralTypeAnnotation": - return fromString(nodeStr(n.value, options), options); - case "NumberLiteralTypeAnnotation": - - assert.strictEqual(typeof n.value, "number"); - - return fromString("" + n.value, options); - case "StringTypeAnnotation": - return fromString("string", options); - case "DeclareTypeAlias": - case "TypeAlias": - { - const parent = path.getParentNode(1); - - if ( - n.type === "DeclareTypeAlias" || - parent && parent.type === "DeclareModule" - ) { - parts.push("declare "); - } - - parts.push( - "type ", - path.call(print, "id"), - path.call(print, "typeParameters"), - " = ", - path.call(print, "right"), - ";" - ); - - return concat(parts); - } - case "TypeCastExpression": - return concat([ - "(", - path.call(print, "expression"), - path.call(print, "typeAnnotation"), - ")" - ]); - case "TypeParameterDeclaration": - case "TypeParameterInstantiation": - return concat([ "<", join(", ", path.map(print, "params")), ">" ]); - case "TypeParameter": - switch (n.variance) { - case "plus": - - parts.push("+"); - - break; - case "minus": - - parts.push("-"); - - break; - default: - } - - parts.push(path.call(print, "name")); - - if (n.bound) { - parts.push(path.call(print, "bound")); - } - - if (n["default"]) { - parts.push("=", path.call(print, "default")); - } - - return concat(parts); - case "TypeofTypeAnnotation": - return concat([ - fromString("typeof ", options), - path.call(print, "argument") - ]); - case "UnionTypeAnnotation": - return join(" | ", path.map(print, "types")); - case "VoidTypeAnnotation": - return "void"; - case "NullTypeAnnotation": - return "null"; - case "InferredPredicate": - return "%checks"; - // Unhandled types below. If encountered, nodes of these types should - // be either left alone or desugared into AST types that are fully - // supported by the pretty-printer. - case "DeclaredPredicate": - return concat([ "%checks(", path.call(print, "value"), ")" ]); - // TODO - case "ClassHeritage": - // TODO - case "ComprehensionBlock": - // TODO - case "ComprehensionExpression": - // TODO - case "Glob": - // TODO - case "GeneratorExpression": - // TODO - case "LetStatement": - // TODO - case "LetExpression": - // TODO - case "GraphExpression": - // TODO - // XML types that nobody cares about or needs to print. - case "GraphIndexExpression": - case "XMLDefaultDeclaration": - case "XMLAnyName": - case "XMLQualifiedIdentifier": - case "XMLFunctionQualifiedIdentifier": - case "XMLAttributeSelector": - case "XMLFilterExpression": - case "XML": - case "XMLElement": - case "XMLList": - case "XMLEscape": - case "XMLText": - case "XMLStartTag": - case "XMLEndTag": - case "XMLPointTag": - case "XMLName": - case "XMLAttribute": - case "XMLCdata": - case "XMLComment": - case "XMLProcessingInstruction": - default: - debugger; - throw new Error("unknown type: " + JSON.stringify(n.type)); - } - return p; -} - -function printStatementSequence(path, options, print) { - let inClassBody = namedTypes.ClassBody && - namedTypes.ClassBody.check(path.getParentNode()); - let printed = []; - let prevAddSpacing = false; - - path.map(function(stmtPath, i) { - var stmt = stmtPath.getValue(); - - // Just in case the AST has been modified to contain falsy - // "statements," it's safer simply to skip them. - if (!stmt) { - return; - } - - // Skip printing EmptyStatement nodes to avoid leaving stray - // semicolons lying around. - if (stmt.type === "EmptyStatement") { - return; - } - - const addSpacing = shouldAddSpacing(stmt); - const stmtPrinted = print(stmtPath); - const parts = []; - - if (!prevAddSpacing && addSpacing && !isFirstStatement(stmtPath)) { - parts.push(hardline); - } - - parts.push(stmtPrinted); - - if (addSpacing && !isLastStatement(stmtPath)) { - parts.push(hardline); - } - - printed.push(concat(parts)); - - prevAddSpacing = addSpacing; - }); - - return join(hardline, printed); -} - -function printMethod(path, options, print) { - var node = path.getNode(); - var kind = node.kind; - var parts = []; - - if (node.type === "ObjectMethod" || node.type === "ClassMethod") { - node.value = node; - } else { - namedTypes.FunctionExpression.assert(node.value); - } - - if (node.value.async) { - parts.push("async "); - } - - if (!kind || kind === "init" || kind === "method" || kind === "constructor") { - if (node.value.generator) { - parts.push("*"); - } - } else { - assert.ok(kind === "get" || kind === "set"); - - parts.push(kind, " "); - } - - var key = path.call(print, "key"); - - if (node.computed) { - key = concat([ "[", key, "]" ]); - } - - parts.push( - key, - path.call(print, "value", "typeParameters"), - path.call( - function(valuePath) { - return printFunctionParams(valuePath, print, options); - }, - "value" - ), - path.call(p => printReturnType(p, print), "value"), - " ", - path.call(print, "value", "body") - ); - - return group(concat(parts)); -} - -function printArgumentsList(path, options, print) { - var printed = path.map(print, "arguments"); - var trailingComma = util.isTrailingCommaEnabled(options, "parameters"); - var args; - - if (printed.length === 0) { - return "()"; - } - - const lastArg = util.getLast(path.getValue().arguments); - // This is just an optimization; I think we could return the - // conditional group for all function calls, but it's more expensive - // so only do it for specific forms. - const groupLastArg = lastArg.type === "ObjectExpression" || - lastArg.type === "ArrayExpression" || - lastArg.type === "FunctionExpression" || - lastArg.type === "ArrowFunctionExpression" || - lastArg.type === "CallExpression" || - lastArg.type === "NewExpression"; - - if (groupLastArg) { - const shouldBreak = printed.slice(0, -1).some(hasHardLine); - return conditionalGroup( - [ - concat([ "(", join(concat([ ", " ]), printed), ")" ]), - concat([ - "(", - join(concat([ ",", line ]), printed.slice(0, -1)), - (printed.length > 1 ? ", " : ""), - group(util.getLast(printed), {shouldBreak: true}), - ")" - ]), - group( - concat([ - "(", - indent( - options.tabWidth, - concat([ line, join(concat([ ",", line ]), printed) ]) - ), - line, - ")" - ]), - {shouldBreak: true} - ) - ], - {shouldBreak} - ); - } - - const shouldBreak = printed.some(hasHardLine); - return group( - concat([ - "(", - indent( - options.tabWidth, - concat([ softline, join(concat([ ",", line ]), printed) ]) - ), - softline, - ")" - ]), - {shouldBreak} - ); -} - -function printFunctionParams(path, print, options) { - var fun = path.getValue(); - // namedTypes.Function.assert(fun); - var printed = path.map(print, "params"); - - if (fun.defaults) { - path.each( - function(defExprPath) { - var i = defExprPath.getName(); - var p = printed[i]; - - if (p && defExprPath.getValue()) { - printed[i] = concat([ p, " = ", print(defExprPath) ]); - } - }, - "defaults" - ); - } - - if (fun.rest) { - printed.push(concat([ "...", path.call(print, "rest") ])); - } - - return concat([ - "(", - indent( - options.tabWidth, - concat([ softline, join(concat([ ",", line ]), printed) ]) - ), - softline, - ")" - ]); -} - -function printObjectMethod(path, options, print) { - var objMethod = path.getValue(); - var parts = []; - - if (objMethod.async) - parts.push("async "); - - if (objMethod.generator) - parts.push("*"); - - if ( - objMethod.method || objMethod.kind === "get" || objMethod.kind === "set" - ) { - return printMethod(path, options, print); - } - - var key = path.call(print, "key"); - - if (objMethod.computed) { - parts.push("[", key, "]"); - } else { - parts.push(key); - } - - parts.push( - printFunctionParams(path, print), - printReturnType(path, print), - " ", - path.call(print, "body") - ); - - return group(concat(parts)); -} - -function printReturnType(path, print) { - const n = path.getValue(); - const parts = [ path.call(print, "returnType") ]; - - if (n.predicate) { - // The return type will already add the colon, but otherwise we - // need to do it ourselves - parts.push((n.returnType ? " " : ": "), path.call(print, "predicate")); - } - - return concat(parts); -} - -function printExportDeclaration(path, options, print) { - var decl = path.getValue(); - var parts = [ "export " ]; - var shouldPrintSpaces = options.objectCurlySpacing; - - namedTypes.Declaration.assert(decl); - - if (decl["default"] || decl.type === "ExportDefaultDeclaration") { - parts.push("default "); - } - - if (decl.declaration) { - parts.push(path.call(print, "declaration")); - } else - if (decl.specifiers && decl.specifiers.length > 0) { - if ( - decl.specifiers.length === 1 && - decl.specifiers[0].type === "ExportBatchSpecifier" - ) { - parts.push("*"); - } else { - parts.push( - (decl.exportKind === "type" ? "type " : ""), - (shouldPrintSpaces ? "{ " : "{"), - join(", ", path.map(print, "specifiers")), - (shouldPrintSpaces ? " }" : "}") - ); - } - - if (decl.source) { - parts.push(" from ", path.call(print, "source")); - } - } - - return concat(parts); -} - -function printFlowDeclaration(path, parts) { - var parentExportDecl = util.getParentExportDeclaration(path); - - if (parentExportDecl) { - assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration"); - } else { - // If the parent node has type DeclareExportDeclaration, then it - // will be responsible for printing the "declare" token. Otherwise - // it needs to be printed with this non-exported declaration node. - parts.unshift("declare "); - } - - return concat(parts); -} - -function printClass(path, print) { - const n = path.getValue(); - const parts = [ "class" ]; - - if (n.id) { - parts.push(" ", path.call(print, "id"), path.call(print, "typeParameters")); - } - - if (n.superClass) { - parts.push( - " extends ", - path.call(print, "superClass"), - path.call(print, "superTypeParameters") - ); - } else - if (n.extends && n.extends.length > 0) { - parts.push(" extends ", join(", ", path.map(print, "extends"))); - } - - if (n["implements"] && n["implements"].length > 0) { - parts.push( - " implements ", - fromString(", ").join(path.map(print, "implements")) - ); - } - - parts.push(" ", path.call(print, "body")); - - return parts; -} - -function adjustClause(clause, options) { - if (getFirstString(clause) === "{") { - return concat([ " ", clause ]); - } - - return indent(options.tabWidth, concat([ hardline, clause ])); -} - -function lastNonSpaceCharacter(lines) { - var pos = lines.lastPos(); - do { - var ch = lines.charAt(pos); - - if (/\S/.test(ch)) - return ch; - } while (lines.prevPos(pos)); -} - -function swapQuotes(str) { - return str.replace(/['"]/g, function(m) { - return (m === "\"" ? "'" : "\""); - }); -} - -function nodeStr(str, options) { - isString.assert(str); - - switch (options.quote) { - case "single": - return swapQuotes(JSON.stringify(swapQuotes(str))); - case "double": - default: - return JSON.stringify(str); - } -} - -function shouldAddSpacing(node) { - return node.type === "IfStatement" || node.type === "ForStatement" || - node.type === "ForInStatement" || - node.type === "ForOfStatement" || - node.type === "ExpressionStatement" || - node.type === "FunctionDeclaration"; -} - -function isFirstStatement(path) { - const parent = path.getParentNode(); - const node = path.getValue(); - const body = parent.body; - return body && body[0] === node; -} - -function isLastStatement(path) { - const parent = path.getParentNode(); - const node = path.getValue(); - const body = parent.body; - return body && body[body.length - 1] === node; -} diff --git a/tests/abnormal/__snapshots__/jsfmt.spec.js.snap b/tests/abnormal/__snapshots__/jsfmt.spec.js.snap index 76e876bc..8b18630e 100644 --- a/tests/abnormal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/abnormal/__snapshots__/jsfmt.spec.js.snap @@ -12,7 +12,6 @@ function foo() { break; } } - function bar() { L: do { @@ -31,13 +30,10 @@ function foo() { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function bar(x: number) {} - function foo() { var x = null; - if (x == null) return; - bar(x); } " diff --git a/tests/annot/__snapshots__/jsfmt.spec.js.snap b/tests/annot/__snapshots__/jsfmt.spec.js.snap index 4f7cee99..f759c082 100644 --- a/tests/annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/annot/__snapshots__/jsfmt.spec.js.snap @@ -73,7 +73,6 @@ function barfoo(n : number | null | void) : ?number { return n; } function foo(str: string, i: number): string { return str; } - var bar: (str: number, i: number) => string = foo; var qux = function(str: string, i: number): number { return foo(str, i); @@ -94,11 +93,9 @@ var array_of_tuple: [number, string][] = [ [ 0, \"foo\" ], [ 1, \"bar\" ] ]; var array_of_tuple_parens: [number, string][] = array_of_tuple; type ObjType = { \"bar-foo\": string, \"foo-bar\": number }; var test_obj: ObjType = { \"bar-foo\": \"23\" }; - function param_anno(n: number): void { n = \"hey\"; } - function param_anno2( batchRequests: Array<{ method: string, path: string, params: ?Object }> ): void { @@ -110,14 +107,11 @@ function param_anno2( }; }); } - var toz: null = 3; var zer: null = null; - function foobar(n: ?number): number | null | void { return n; } - function barfoo(n: number | null | void): ?number { return n; } @@ -146,20 +140,15 @@ function foo() { // ok (no confusion across scopes) // looked up above let myClassInstance: MyClass = null; - function bar(): MyClass { return null; } - class MyClass {} - function foo() { let myClassInstance: MyClass = mk(); - function mk() { return new MyClass(); } - class MyClass {} } " @@ -171,7 +160,6 @@ exports[`test issue-530.js 1`] = ` module.exports = foo; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo(...args: any) {} - module.exports = foo; " `; @@ -212,11 +200,9 @@ function bar(y: MyObj): string { * leading to an error. */ type MyObj = Object; - function foo(x: { [key: string]: mixed }) { bar(x); } - function bar(y: MyObj): string { return y.foo; } @@ -228,7 +214,6 @@ exports[`test other.js 1`] = ` module.exports = (C: any); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class C {} - module.exports = (C: any); " `; @@ -266,7 +251,6 @@ declare class Map { insertWith(fn: Merge, k: K, v: V): Map } declare function foldr(fn: (a: A, b: B) => B, b: B, as: A[]): B; - function insertMany( merge: Merge, vs: [K, V][], @@ -275,10 +259,8 @@ function insertMany( function f([ k, v ]: [K, V], m: Map): Map { return m.insertWith(merge, k, v); } - return foldr(f, m, vs); } - class Foo { bar() { return function(a: A, b: B, c: C): void { @@ -294,7 +276,6 @@ exports[`test test.js 1`] = ` ((0: C): string); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var C = require(\"./other\"); - ((0: C): string); " `; diff --git a/tests/any/__snapshots__/jsfmt.spec.js.snap b/tests/any/__snapshots__/jsfmt.spec.js.snap index 11056fc3..8c9272d1 100644 --- a/tests/any/__snapshots__/jsfmt.spec.js.snap +++ b/tests/any/__snapshots__/jsfmt.spec.js.snap @@ -13,15 +13,12 @@ var z:string = qux(0); function foo(x: any): any { return x; } - function bar(x: any): mixed { return x; } - function qux(x: mixed): any { return x; } - var x: string = foo(0); var y: string = bar(0); var z: string = qux(0); @@ -71,19 +68,15 @@ var w:string = baz(0); function foo(x: $FlowFixMe): $FlowFixMe { return x; } - function bar(x: $FlowFixMe): mixed { return x; } - function qux(x: $FlowFixMe): $FlowFixMe { return x; } - function baz(x: $FlowFixMe): $FlowFixMe { return x; } - var x: string = foo(0); var y: string = bar(0); var z: string = qux(0); @@ -124,19 +117,15 @@ var w:string = baz(0); function foo(x: $FlowIssue): $FlowIssue { return x; } - function bar(x: $FlowIssue): mixed { return x; } - function qux(x: $FlowIssue): $FlowIssue { return x; } - function baz(x: $FlowIssue): $FlowIssue { return x; } - var x: string = foo(0); var y: string = bar(0); var z: string = qux(0); @@ -187,22 +176,17 @@ declare class C { bar(n1: number, n2: number): number, bar(s1: string, s2: string): string } - function foo(c: C, x: any): string { let y = x.y; return c.bar(0, y); } - var any_fun1 = require(\"./nonflowfile\"); - function bar1(x: mixed) { if (any_fun1(x)) { (x: boolean); } } - var any_fun2 = require(\"./anyexportflowfile\"); - function bar2(x: mixed) { if (any_fun2(x)) { (x: boolean); @@ -232,7 +216,6 @@ function foo(o: ?AsyncRequest) { * annotation - without it, the body of the if will be unreachable */ type AsyncRequest = any; - function foo(o: ?AsyncRequest) { if (o) { var n: number = o; diff --git a/tests/arith/__snapshots__/jsfmt.spec.js.snap b/tests/arith/__snapshots__/jsfmt.spec.js.snap index 57189a5a..c5a6a2e7 100644 --- a/tests/arith/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arith/__snapshots__/jsfmt.spec.js.snap @@ -133,113 +133,71 @@ let tests = [ // error, string ~> empty // error, string ~> empty function num(x: number) {} - function str(x: string) {} - function foo() { var x = 0; var y = \"...\"; var z = {}; - num(x + x); - num(x + y); - str(x + y); - str(x + x); - str(z + y); } - function bar0(x: ?number, y: number) { num(x + y); } - function bar1(x: number, y: ?number) { num(x + y); } - function bar2(x?: number, y: number) { num(x + y); } - function bar3(x: number, y?: number) { num(x + y); } - function bar4(x?: ?number, y: number) { num(x + y); } - function bar5(x: number, y?: ?number) { num(x + y); } - num(null + null); - num(undefined + undefined); - num(null + 1); - num(1 + null); - num(undefined + 1); - num(1 + undefined); - num(null + true); - num(true + null); - num(undefined + true); - num(true + undefined); - str(\"foo\" + true); - str(true + \"foo\"); - str(\"foo\" + null); - str(null + \"foo\"); - str(\"foo\" + undefined); - str(undefined + \"foo\"); - let tests = [ function(x: mixed, y: mixed) { x + y; - x + 0; - 0 + x; - x + \"\"; - \"\" + x; - x + {}; - ({}) + x; }, function() { (1 + {}: number); - ({} + 1: number); - (\"1\" + {}: string); - ({} + \"1\": string); }, function(x: any, y: number, z: string) { (x + y: string); - (y + x: string); - (x + z: empty); - (z + x: empty); } ]; @@ -262,17 +220,11 @@ y **= 2; // error /* @flow */ // error let x: number = 2 ** 3; - x **= 4; - let y: string = \"123\"; - y **= 2; - 1 + 2 ** 3 + 4; - 2 ** 2; - (-2) ** 2; " `; @@ -295,19 +247,15 @@ function f(a: A, b: B): B {return b + a; } // error function f(a: A): A { return a + a; } - function f(a: A, b: B): A { return a + b; } - function f(a: A, b: B): A { return b + a; } - function f(a: A, b: B): B { return a + b; } - function f(a: A, b: B): B { return b + a; } @@ -331,17 +279,11 @@ y *= 2; // error /* @flow */ // error function num(x: number) {} - num(null * 1); - num(1 * null); - let x: number = 2 * 3; - x *= 4; - let y: string = \"123\"; - y *= 2; " `; @@ -393,47 +335,27 @@ let tests = [ // error // error 1 < 2; - 1 < \"foo\"; - \"foo\" < 1; - \"foo\" < \"bar\"; - 1 < { foo: 1 }; - ({ foo: 1 }) < 1; - ({ foo: 1 }) < { foo: 1 }; - \"foo\" < { foo: 1 }; - ({ foo: 1 }) < \"foo\"; - var x = (null: ?number); - 1 < x; - x < 1; - null < null; - undefined < null; - null < undefined; - undefined < undefined; - NaN < 1; - 1 < NaN; - NaN < NaN; - let tests = [ function(x: any, y: number, z: string) { x > y; - x > z; } ]; diff --git a/tests/array-filter/__snapshots__/jsfmt.spec.js.snap b/tests/array-filter/__snapshots__/jsfmt.spec.js.snap index bc4a52c2..55c9ec1e 100644 --- a/tests/array-filter/__snapshots__/jsfmt.spec.js.snap +++ b/tests/array-filter/__snapshots__/jsfmt.spec.js.snap @@ -13,7 +13,6 @@ function filterOutSmall (arr: Array): Array { function filterOutVoids(arr: Array): Array { return arr.filter(Boolean); } - function filterOutSmall(arr: Array): Array { return arr.filter(num => num && num > 10); } @@ -47,9 +46,7 @@ function filterItems(items: Array): Array { } }).filter(Boolean); } - const filteredItems = filterItems([ \"foo\", \"b\", 1, 2 ]); - console.log(filteredItems); " `; diff --git a/tests/array_spread/__snapshots__/jsfmt.spec.js.snap b/tests/array_spread/__snapshots__/jsfmt.spec.js.snap index aa3e6754..c902ddba 100644 --- a/tests/array_spread/__snapshots__/jsfmt.spec.js.snap +++ b/tests/array_spread/__snapshots__/jsfmt.spec.js.snap @@ -11,11 +11,8 @@ var y: Array = [\'3\', ...x]; var A = [ 1, 2, 3 ]; var B = [ ...A ]; var C = [ 1, 2, 3 ]; - B.sort((a, b) => a - b); - C.sort((a, b) => a - b); - var x: Array = [ \"1\", \"2\" ]; var y: Array = [ \"3\", ...x ]; " diff --git a/tests/arraylib/__snapshots__/jsfmt.spec.js.snap b/tests/arraylib/__snapshots__/jsfmt.spec.js.snap index 176c0a9e..d9048ff0 100644 --- a/tests/arraylib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arraylib/__snapshots__/jsfmt.spec.js.snap @@ -67,11 +67,9 @@ function from_test() { // error, string ~> number // error, string ~> number function foo(x: string) {} - var a = [ 0 ]; var b = a.map(function(x) { foo(x); - return \"\" + x; }); var c: number = a[0]; @@ -88,31 +86,25 @@ var k: Array = h.concat(h); var l: Array = h.concat(1, 2, 3); var m: Array = h.concat(\"a\", \"b\", \"c\"); var n: Array = h.concat(\"a\", \"b\", \"c\"); - function reduce_test() { [ 0, 1, 2, 3, 4 ].reduce(function(previousValue, currentValue, index, array) { return previousValue + currentValue + array[index]; }); - [ 0, 1, 2, 3, 4 ].reduce( function(previousValue, currentValue, index, array) { return previousValue + currentValue + array[index]; }, 10 ); - var total = [ 0, 1, 2, 3 ].reduce(function(a, b) { return a + b; }); var flattened = [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ].reduce(function(a, b) { return a.concat(b); }); - [ \"\" ].reduce((acc, str) => acc * str.length); - [ \"\" ].reduceRight((acc, str) => acc * str.length); } - function from_test() { var a: Array = Array.from([ 1, 2, 3 ], function(val, index) { return index % 2 ? \"foo\" : String(val); diff --git a/tests/arrays/__snapshots__/jsfmt.spec.js.snap b/tests/arrays/__snapshots__/jsfmt.spec.js.snap index 2fcd08df..8ca259f3 100644 --- a/tests/arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrays/__snapshots__/jsfmt.spec.js.snap @@ -43,19 +43,12 @@ module.exports = \"arrays\"; // for literals, composite element type is union of individuals // note: test both tuple and non-tuple inferred literals function foo(x: string) {} - var a = []; - a[0] = 1; - a[1] = \"...\"; - foo(a[1]); - var y; - a.forEach(x => y = x); - var alittle: Array = [ 0, 1, 2, 3, null ]; var abig: Array = [ 0, 1, 2, 3, 4, 5, 6, 8, null ]; var abig2: Array<{ x: number, y: number }> = [ @@ -77,7 +70,6 @@ var abig2: Array<{ x: number, y: number }> = [ { x: 0, y: 0, c: 1 }, { x: 0, y: 0, c: \"hey\" } ]; - module.exports = \"arrays\"; " `; @@ -96,9 +88,7 @@ arr[day] = 0; // error: number ~> string var arr = []; var day = new Date(); - arr[day] = 0; - (arr[day]: string); " `; diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap index f4f32e3d..e584d2ee 100644 --- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap @@ -19,9 +19,7 @@ var ident = (x: T): T => x; var add = (x: number, y: number): number => x + y; var bad = (x: number): string => x; var ident = (x: T): T => x; - (ident(1): number); - (ident(\"hi\"): number); " `; @@ -44,9 +42,7 @@ function selectBestEffortImageForWidth( images: Array ): Image { var maxPixelWidth = maxWidth; - images = images.sort((a, b) => a.width - b.width + \"\"); - return images.find(image => image.width >= maxPixelWidth) || images[images.length - 1]; } diff --git a/tests/async/__snapshots__/jsfmt.spec.js.snap b/tests/async/__snapshots__/jsfmt.spec.js.snap index 4e4ae9d5..ff7d0b2e 100644 --- a/tests/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async/__snapshots__/jsfmt.spec.js.snap @@ -71,25 +71,20 @@ var objf : () => Promise = obj.f; async function f0(): Promise { return 1; } - async function f1(): Promise { return 1; } - async function f2(p: Promise): Promise { var x: number = await p; var y: number = await 1; return x + y; } - async function f3(p: Promise): Promise { return await p; } - async function f4(p: Promise): Promise { return await p; } - var f5: () => Promise = async () => await 1; class C { async m() { @@ -134,7 +129,6 @@ class C {} var P: Promise> = new Promise(function(resolve, reject) { resolve(C); }); - async function foo() { class Bar extends (await P) {} return Bar; @@ -169,9 +163,7 @@ var async = 3; var y = { async }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ async function f() {} - async function ft(a: T) {} - class C { async m() {} async mt(a: T) {} @@ -185,9 +177,7 @@ var o = { async m() {} }; var ot = { async m(a: T) {} }; var oz = { async async() {} }; var x = { async: 5 }; - console.log(x.async); - var async = 3; var y = { async }; " @@ -224,14 +214,11 @@ async function foo3(): Promise { async function foo1(): Promise { return; } - async function foo2(): Promise { return undefined; } - async function foo3(): Promise { function bar() {} - return bar(); } " @@ -324,35 +311,29 @@ function test1() { async function foo() { return 42; } - async function bar() { var a = await foo(); var b: number = a; var c: string = a; } } - function test2() { async function voidoid1() { console.log(\"HEY\"); } - var voidoid2: () => Promise = voidoid1; var voidoid3: () => void = voidoid1; } - function test3() { async function voidoid4(): Promise { console.log(\"HEY\"); } } - function test4() { async function voidoid5(): void { console.log(\"HEY\"); } } - function test5() { async function voidoid6(): Promise { console.log(\"HEY\"); @@ -412,11 +393,9 @@ async function baz() { async function foo() { return 42; } - async function bar() { return foo(); } - async function baz() { var a = await bar(); var b: number = a; @@ -454,11 +433,9 @@ var y = { await }; async function f() { await 1; } - async function ft(a: T) { await 1; } - class C { async m() { await 1; @@ -498,9 +475,7 @@ var oz = { } }; var x = { await: 5 }; - console.log(x.await); - var await = 3; var y = { await }; " diff --git a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap index 0b44f0a3..92ce089a 100644 --- a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap @@ -33,31 +33,24 @@ async function* delegate_next() { async function* inner() { var x: void = yield; } - yield* inner(); } - delegate_next().next(0); - async function* delegate_yield() { async function* inner() { yield 0; } - yield* inner(); } - async () => { for await (const x of delegate_yield()) { (x: void); } }; - async function* delegate_return() { async function* inner() { return 0; } - var x: void = yield* inner(); } " @@ -93,7 +86,6 @@ async function f() { // error: string ~> void interface File { readLine(): Promise, close(): void, EOF: boolean } declare function fileOpen(path: string): Promise; - async function* readLines(path) { let file: File = await fileOpen(path); try { @@ -104,7 +96,6 @@ async function* readLines(path) { file.close(); } } - async function f() { for await (const line of readLines(\"/path/to/file\")) { (line: void); @@ -144,11 +135,9 @@ refuse_return().return(\"string\").then(result => { // yielding or returning internally. // error: number | void ~> string declare var gen: AsyncGenerator; - gen.return(0).then(result => { (result.value: void); }); - async function* refuse_return() { try { yield 1; @@ -156,7 +145,6 @@ async function* refuse_return() { return 0; } } - refuse_return().return(\"string\").then(result => { if (result.done) { (result.value: string); @@ -208,7 +196,6 @@ async function* catch_return() { return e; } } - async () => { catch_return().throw(\"\").then(({ value }) => { if (value !== undefined) { @@ -216,17 +203,14 @@ async () => { } }); }; - async function* yield_return() { try { yield 0; - return; } catch (e) { yield e; } } - async () => { yield_return().throw(\"\").then(({ value }) => { if (value !== undefined) { diff --git a/tests/autocomplete/__snapshots__/jsfmt.spec.js.snap b/tests/autocomplete/__snapshots__/jsfmt.spec.js.snap index c78433ce..c39735c8 100644 --- a/tests/autocomplete/__snapshots__/jsfmt.spec.js.snap +++ b/tests/autocomplete/__snapshots__/jsfmt.spec.js.snap @@ -19,7 +19,6 @@ declare var mergeInto: $Facebookism$MergeInto; declare var mixin: $Facebookism$Mixin; declare var objectGetPrototypeOf: Object$GetPrototypeOf; declare var objectAssign: Object$Assign; - m; " `; diff --git a/tests/binary/__snapshots__/jsfmt.spec.js.snap b/tests/binary/__snapshots__/jsfmt.spec.js.snap index e88f1790..5b8ba242 100644 --- a/tests/binary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/binary/__snapshots__/jsfmt.spec.js.snap @@ -78,55 +78,39 @@ let tests = [ let tests = [ function() { \"foo\" in {}; - \"foo\" in { foo: null }; - 0 in {}; - 0 in { \"0\": null }; }, function() { \"foo\" in []; - 0 in []; - \"length\" in []; }, function() { \"foo\" in new String(\"bar\"); - \"foo\" in new Number(123); }, function() { \"foo\" in 123; - \"foo\" in \"bar\"; - \"foo\" in void 0; - \"foo\" in null; }, function() { null in {}; - void 0 in {}; - ({}) in {}; - [] in {}; - false in []; }, function() { if (\"foo\" in 123) {} - if (!\"foo\" in {}) {} - if (!(\"foo\" in {})) {} }, function(x: Object, y: mixed) { \"foo\" in x; - \"foo\" in y; } ]; diff --git a/tests/binding/__snapshots__/jsfmt.spec.js.snap b/tests/binding/__snapshots__/jsfmt.spec.js.snap index 15d58ddb..fb51cf02 100644 --- a/tests/binding/__snapshots__/jsfmt.spec.js.snap +++ b/tests/binding/__snapshots__/jsfmt.spec.js.snap @@ -33,40 +33,23 @@ for (const { baz } of bazzes) { // error: string ~> number // error: string ~> number const x = 0; - x++; - x--; - x += 0; - x -= 0; - x /= 0; - x %= 0; - x <<= 0; - x >>= 0; - x >>>= 0; - x |= 0; - x ^= 0; - x &= 0; - const { foo } = { foo: \"foo\" }; const [ bar ] = [ \"bar\" ]; - (foo: number); - (bar: number); - declare var bazzes: { baz: string }[]; - for (const { baz } of bazzes) { (baz: number); } @@ -328,155 +311,120 @@ function type_type() { type A = number; type A = number; } - function type_class() { type A = number; class A {} } - function type_let() { type A = number; let A = 0; } - function type_const() { type A = number; const A = 0; } - function type_var() { type A = number; var A = 0; } - function type_reassign() { type A = number; - A = 42; } - function class_type() { class A {} type A = number; } - function class_class() { class A {} class A {} } - function class_let() { class A {} let A = 0; } - function class_const() { class A {} const A = 0; } - function class_var() { class A {} var A = 0; } - function let_type() { let A = 0; type A = number; } - function let_class() { let A = 0; class A {} } - function let_let() { let A = 0; let A = 0; } - function let_const() { let A = 0; const A = 0; } - function let_var() { let A = 0; var A = 0; } - function const_type() { const A = 0; type A = number; } - function const_class() { const A = 0; class A {} } - function const_let() { const A = 0; let A = 0; } - function const_const() { const A = 0; const A = 0; } - function const_var() { const A = 0; var A = 0; } - function const_reassign() { const A = 0; - A = 42; } - function var_type() { var A = 0; type A = number; } - function var_class() { var A = 0; class A {} } - function var_let() { var A = 0; let A = 0; } - function var_const() { var A = 0; const A = 0; } - function var_var() { var A = 0; var A = 0; } - function function_toplevel() { function a() {} - function a() {} - } - function function_block() { { function a() {} - function a() {} - } } - function var_shadow_nested_scope() { { let x = 0; @@ -485,7 +433,6 @@ function var_shadow_nested_scope() { } } } - function type_shadow_nested_scope() { { let x = 0; @@ -494,9 +441,7 @@ function type_shadow_nested_scope() { } } } - function fn_params_name_clash(x, x) {} - function fn_params_clash_fn_binding(x, y) { let x = 0; var y = 0; @@ -650,7 +595,6 @@ function block_scope() { var b = \"\"; } } - function switch_scope(x: string) { let a: number = 0; var b: number = 0; @@ -664,13 +608,10 @@ function switch_scope(x: string) { break; } } - function switch_scope2(x: number) { switch (x) { case 0: - a = \"\"; - break; case 1: var b = a; @@ -679,18 +620,14 @@ function switch_scope2(x: number) { let a = \"\"; break; case 3: - a = \"\"; - break; case 4: var c: string = a; break; } - a = \"\"; } - function try_scope() { let a: number = 0; try { @@ -701,57 +638,41 @@ function try_scope() { let a = \"\"; } } - function for_scope_let() { let a: number = 0; - for (let a = \"\"; ; ) {} } - function for_scope_var() { var a: number = 0; - for (var a = \"\"; ; ) {} } - function for_in_scope_let(o: Object) { let a: number = 0; - for (let a in o) {} } - function for_in_scope_var(o: Object) { var a: number = 0; - for (var a in o) {} } - function for_of_scope_let(xs: string[]) { let a: number = 0; - for (let a of xs) {} } - function for_of_scope_var(xs: string[]) { var a: number = 0; - for (var a of xs) {} } - function default_param_1() { function f(x: () => string = f): number { return 0; } } - function default_param_2() { let a = \"\"; - function f0(x = () => a): number { let a = 0; return x(); } - function f1(x = b): number { let b = 0; return x; @@ -906,25 +827,19 @@ f(a); // ok, a: number (not ?number) // ok, a: number (not ?number) type T1 = T2; type T2 = number; - function f0() { var v = x * c; let x = 0; const c = 0; } - function f1(b) { x = 10; - let x = 0; - if (b) { y = 10; - let y = 0; } } - function f2() { { var v = x * c; @@ -932,57 +847,44 @@ function f2() { let x = 0; const c = 0; } - function f3() { var s: string = foo(); { var n: number = foo(); - function foo() { return 0; } } var s2: string = foo(); - function foo() { return \"\"; } } - function f4() { function g() { return x + c; } - let x = 0; const c = 0; } - function f5() { function g() { return x; } - g(); - let x = 0; const c = 0; } - var x: C; var y = new C(); class C {} var z: C = new C(); var a: number; - function f(n: number) { return n; } - f(a); - a = 10; - f(a); " `; diff --git a/tests/bom/__snapshots__/jsfmt.spec.js.snap b/tests/bom/__snapshots__/jsfmt.spec.js.snap index 0b4c785d..47e0dd90 100644 --- a/tests/bom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/bom/__snapshots__/jsfmt.spec.js.snap @@ -125,89 +125,50 @@ for (let [x, y]: [number, number] of a.entries()) {} // incorrect // incorrect // incorrect const a: FormData = new FormData(); - new FormData(\"\"); - new FormData(document.createElement(\"input\")); - new FormData(document.createElement(\"form\")); - const b: boolean = a.has(\"foo\"); const c: ?(string | File) = a.get(\"foo\"); const d: string = a.get(\"foo\"); const e: Blob = a.get(\"foo\"); const f: ?(string | File | Blob) = a.get(\"foo\"); - a.get(2); - const a1: Array = a.getAll(\"foo\"); const a2: Array = a.getAll(\"foo\"); const a3: Array = a.getAll(\"foo\"); - a.getAll(23); - a.set(\"foo\", \"bar\"); - a.set(\"foo\", {}); - a.set(2, \"bar\"); - a.set(\"foo\", \"bar\", \"baz\"); - a.set(\"bar\", new File([], \"q\")); - a.set(\"bar\", new File([], \"q\"), \"x\"); - a.set(\"bar\", new File([], \"q\"), 2); - a.set(\"bar\", new Blob()); - a.set(\"bar\", new Blob(), \"x\"); - a.set(\"bar\", new Blob(), 2); - a.append(\"foo\", \"bar\"); - a.append(\"foo\", {}); - a.append(2, \"bar\"); - a.append(\"foo\", \"bar\", \"baz\"); - a.append(\"foo\", \"bar\"); - a.append(\"bar\", new File([], \"q\")); - a.append(\"bar\", new File([], \"q\"), \"x\"); - a.append(\"bar\", new File([], \"q\"), 2); - a.append(\"bar\", new Blob()); - a.append(\"bar\", new Blob(), \"x\"); - a.append(\"bar\", new Blob(), 2); - a.delete(\"xx\"); - a.delete(3); - for (let x: string of a.keys()) {} - for (let x: number of a.keys()) {} - for (let x: string | File of a.values()) {} - for (let x: string | File | Blob of a.values()) {} - for (let [ x, y ]: [string, string | File] of a.entries()) {} - for (let [ x, y ]: [string, string | File | Blob] of a.entries()) {} - for (let [ x, y ]: [number, string] of a.entries()) {} - for (let [ x, y ]: [string, number] of a.entries()) {} - for (let [ x, y ]: [number, number] of a.entries()) {} " `; @@ -270,39 +231,22 @@ function callback( ): void { return; } - const o: MutationObserver = new MutationObserver(callback); - new MutationObserver((arr: Array) => true); - new MutationObserver(() => {}); - new MutationObserver(); - new MutationObserver(42); - new MutationObserver((n: number) => {}); - const div = document.createElement(\"div\"); - o.observe(div, { attributes: true, attributeFilter: [ \"style\" ] }); - o.observe(div, { characterData: true, invalid: true }); - o.observe(); - o.observe(\"invalid\"); - o.observe(div); - o.observe(div, {}); - o.observe(div, { subtree: true }); - o.observe(div, { attributes: true, attributeFilter: true }); - o.takeRecords(); - o.disconnect(); " `; diff --git a/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap b/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap index ab76bc6a..47e63d98 100644 --- a/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap @@ -5,9 +5,7 @@ foo(0, \"\"); function bar(x:X, y:Y): number { return y*0; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo(x: X, y: Y): void {} - foo(0, \"\"); - function bar(x: X, y: Y): number { return y * 0; } @@ -56,7 +54,6 @@ function foo(x: T): T { var y: string = x; return x; } - class C { bar(x: U): T { return x; @@ -67,13 +64,10 @@ class C { return x; } } - function example(o: T): T { o.x = 0; - return o; } - var obj1: { x: number, y: string } = example({ x: 0, y: \"\" }); var obj2: { x: number } = example({ x: 0 }); var c: C = new C(); diff --git a/tests/break/__snapshots__/jsfmt.spec.js.snap b/tests/break/__snapshots__/jsfmt.spec.js.snap index 73e262b3..9b5dff29 100644 --- a/tests/break/__snapshots__/jsfmt.spec.js.snap +++ b/tests/break/__snapshots__/jsfmt.spec.js.snap @@ -87,27 +87,20 @@ function foo(b) { while (b) { if (x == null) { z = \"\"; - break; } - var y: number = x; } var w: number = z; } - function bar(b) { var x = b ? null : false; - if (x == null) return; - switch (\"\") { case 0: var y: number = x; - x = \"\"; - case 1: var z: number = x; break; @@ -115,18 +108,14 @@ function bar(b) { } var w: number = x; } - function bar2(b) { var x = b ? null : false; - if (x == null) return; - switch (\"\") { case 0: { let y: number = x; - x = \"\"; } case 1: @@ -138,36 +127,27 @@ function bar2(b) { } var w: number = x; } - function qux(b) { var z = 0; while (b) { var y: number = z; - if (b) { z = \"\"; - continue; } - z = 0; } var w: number = z; } - function test_const() { let st: string = \"abc\"; - for (let i = 1; i < 100; i++) { const fooRes: ?string = \"HEY\"; - if (!fooRes) { break; } - st = fooRes; } - return st; } " diff --git a/tests/builtin_uses/__snapshots__/jsfmt.spec.js.snap b/tests/builtin_uses/__snapshots__/jsfmt.spec.js.snap index a6ab2556..fead4428 100644 --- a/tests/builtin_uses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/builtin_uses/__snapshots__/jsfmt.spec.js.snap @@ -4,9 +4,7 @@ exports[`test test.js 1`] = ` module.exports = o; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var o = Object.freeze({ foo: 0 }); - (o.foo: string); - module.exports = o; " `; @@ -16,7 +14,6 @@ exports[`test test2.js 1`] = ` (o.foo: string); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var o = require(\"./test\"); - (o.foo: string); " `; diff --git a/tests/builtins/__snapshots__/jsfmt.spec.js.snap b/tests/builtins/__snapshots__/jsfmt.spec.js.snap index a0044943..520a4943 100644 --- a/tests/builtins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/builtins/__snapshots__/jsfmt.spec.js.snap @@ -26,24 +26,19 @@ var b = a.map(function(x) { }); var c: string = b[0]; var array = []; - function f() { array = array.map(function() { return \"...\"; }); - var x: number = array[0]; } - var Foo = require(\"./genericfoo\"); var foo = new Foo(); - function g() { var foo1 = foo.map(function() { return \"...\"; }); var x: number = foo1.get(); - foo = foo1; } " @@ -73,7 +68,6 @@ class Foo { return this.x; } } - module.exports = Foo; " `; diff --git a/tests/call_properties/__snapshots__/jsfmt.spec.js.snap b/tests/call_properties/__snapshots__/jsfmt.spec.js.snap index f3d5cc58..935c0342 100644 --- a/tests/call_properties/__snapshots__/jsfmt.spec.js.snap +++ b/tests/call_properties/__snapshots__/jsfmt.spec.js.snap @@ -39,23 +39,18 @@ function f(): number { function a(f: { (): string }, g: { (x: number): string }): string { return f() + g(123); } - function b(f: { (): string }): number { return f(); } - function c(f: { (x: number): number }): number { return f(\"hello\"); } - function d(f: { (x: number): number }): number { return f(); } - function e(f: {}): number { return f(); } - function f(): number { var x = {}; return x(); @@ -167,27 +162,21 @@ function g(x: {}): Function { function a(x: { (z: number): string }): (z: number) => string { return x; } - function b(x: { (z: number): string }): (z: number) => number { return x; } - function c(x: { (z: number): string }): (z: string) => string { return x; } - function d(x: { (z: number): string }): () => string { return x; } - function e(x: {}): () => string { return x; } - function f(x: { (z: number): string }): Function { return x; } - function g(x: {}): Function { return x; } @@ -226,18 +215,15 @@ function e(x: { (): string; (x: number): string }): () => number { function a(f: { (): string, (x: number): string }): string { return f() + f(123); } - var b: { (): string, (x: number): string } = function(x?: number): string { return \"hi\"; }; var c: { (): string, (x: number): string } = function(x: number): string { return \"hi\"; }; - function d(x: { (): string, (x: number): string }): () => string { return x; } - function e(x: { (): string, (x: number): string }): () => number { return x; } @@ -262,9 +248,7 @@ var c : { myProp: number } = f; var a: { someProp: number } = function() {}; var b: { apply: Function } = function() {}; var f = function() {}; - f.myProp = 123; - var c: { myProp: number } = f; " `; diff --git a/tests/callable/__snapshots__/jsfmt.spec.js.snap b/tests/callable/__snapshots__/jsfmt.spec.js.snap index 99eb523a..8a12d5db 100644 --- a/tests/callable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/callable/__snapshots__/jsfmt.spec.js.snap @@ -11,11 +11,9 @@ function f(x) { (f: F); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ type F = { (x: string): number, p?: string }; - function f(x) { return x.length; } - (f: F); " `; @@ -49,27 +47,17 @@ callable.call(null, 0); // error, number ~> string // error, number ~> string // error, number ~> string var x = Boolean(4); - function foo(fn: (value: any) => boolean) {} - foo(Boolean); - var dict: { [k: string]: any } = {}; - dict(); - interface ICall { (x: string): void } declare var icall: ICall; - icall(0); - icall.call(null, 0); - type Callable = { (x: string): void }; declare var callable: Callable; - callable(0); - callable.call(null, 0); " `; diff --git a/tests/class_statics/__snapshots__/jsfmt.spec.js.snap b/tests/class_statics/__snapshots__/jsfmt.spec.js.snap index f4c16f89..bdb7351e 100644 --- a/tests/class_statics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_statics/__snapshots__/jsfmt.spec.js.snap @@ -80,25 +80,17 @@ class A { static foo(x: number) {} static bar(y: string) {} } - A.qux = function(x: string) {}; - class B extends A { static x: string; static foo(x: string) {} static main() { B.x = 0; - B.x = \"\"; - B.foo(0); - B.foo(\"\"); - B.y = 0; - B.bar(0); - B.qux(0); } static create(): A { @@ -118,25 +110,19 @@ class C { class D extends C { static main() { D.foo(0); - D.bar(0); } } var d: C<*> = D.create(); - (new A(): typeof A); - (B: typeof A); - class E { static x: number; static foo(): string { this.bar(); - return this.x; } } - module.exports = { A: A, B: B, C: C, D: D, E: E }; " `; diff --git a/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap b/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap index 2524c13c..180e09de 100644 --- a/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap @@ -8,7 +8,6 @@ module.exports = { A, B }; /* @flow */ class A {} class B {} - module.exports = { A, B }; " `; @@ -66,19 +65,14 @@ foo(new D, { f_: 0 }); class C { x: X; } - function foo(c: C, x: X) {} - type O = { f: number }; - foo((new C(): C), { f_: 0 }); - class D extends C { bar() { this.x; } } - foo(new D(), { f_: 0 }); " `; diff --git a/tests/class_type/__snapshots__/jsfmt.spec.js.snap b/tests/class_type/__snapshots__/jsfmt.spec.js.snap index 820819e9..341b3c27 100644 --- a/tests/class_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_type/__snapshots__/jsfmt.spec.js.snap @@ -14,15 +14,12 @@ function bar(x: Class): B { // OK // error (too few args) class A {} - function foo(x: Class): A { return new x(); } - class B { constructor(_: any) {} } - function bar(x: Class): B { return new x(); } @@ -52,15 +49,10 @@ declare function check(cls: $Type, inst: X): void; class A {} class B extends A {} class C {} - check(B, new A()); - check(A, new B()); - check(C, new A()); - check(C, new B()); - check(B, new C()); " `; diff --git a/tests/classes/__snapshots__/jsfmt.spec.js.snap b/tests/classes/__snapshots__/jsfmt.spec.js.snap index fe4c99da..1c99c586 100644 --- a/tests/classes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/classes/__snapshots__/jsfmt.spec.js.snap @@ -8,7 +8,6 @@ module.exports = A; class A { foo(x: number): void {} } - module.exports = A; " `; @@ -27,9 +26,7 @@ module.exports = B; var A = require(\"./A\"); class B extends A {} let b = new B(); - (b.foo: number); - module.exports = B; " `; @@ -52,9 +49,7 @@ class C extends B { foo(x: string): void {} } let c = new C(); - (c.foo: number); - module.exports = C; " `; @@ -66,7 +61,6 @@ new E().x ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class D {} class E {} - new E().x; " `; @@ -128,21 +122,13 @@ class TestClass { c: ?string; } var x = new TestClass(); - x.a; - x.b; - x.c; - x.d; - var y: Foo = x; - y.b; - y.d; - class Test2Superclass { a: number; c: ?number; @@ -259,15 +245,10 @@ declare var o: {p:number}; class C { static p: string; } - C.p = \"hi\"; - (C: { p: string }); - (C: { p: number }); - declare var o: { p: number }; - (o: Class); " `; diff --git a/tests/closure/__snapshots__/jsfmt.spec.js.snap b/tests/closure/__snapshots__/jsfmt.spec.js.snap index c5b2ee34..2dfec3fe 100644 --- a/tests/closure/__snapshots__/jsfmt.spec.js.snap +++ b/tests/closure/__snapshots__/jsfmt.spec.js.snap @@ -105,45 +105,28 @@ function local_meth() { // error // shouldn\'t pollute linear refinement function takes_string(_: string) {} - var global_x = \"hello\"; - function global_f() {} - function global_g() { global_x = 42; } - global_f(); - takes_string(global_x); - global_g(); - takes_string(global_x); - global_x = 42; - function local_func() { var local_x = \"hello\"; - function local_f() {} - function local_g() { local_x = 42; } - local_f(); - takes_string(local_x); - local_g(); - takes_string(local_x); - local_x = 42; } - var global_y = \"hello\"; var global_o = { f: function() {}, @@ -151,17 +134,11 @@ var global_o = { global_y = 42; } }; - global_o.f(); - takes_string(global_y); - global_o.g(); - takes_string(global_y); - global_y = 42; - function local_meth() { var local_y = \"hello\"; var local_o = { @@ -170,15 +147,10 @@ function local_meth() { local_y = 42; } }; - local_o.f(); - takes_string(local_y); - local_o.g(); - takes_string(local_y); - local_y = 42; } " @@ -206,15 +178,12 @@ function example(b: bool): number { // error, string ~/~> number (return type anno) TODO function example(b: boolean): number { var x = 0; - function f() { x = \"\"; } - if (b) { f(); } - return x; } " @@ -285,30 +254,23 @@ call_me(); // error // in a galaxy far far away var call_me: () => void = () => {}; - function g(x: ?number) { const const_x = x; - if (const_x) { call_me = () => { var y: number = const_x; }; } - var var_x = x; - if (var_x) { call_me = () => { var y: number = var_x; }; } - var_x = null; } - function h(x: number | string | boolean) { const const_x = x; - if (typeof const_x == \"number\") { call_me = () => { var y: number = const_x; @@ -322,9 +284,7 @@ function h(x: number | string | boolean) { var y: boolean = const_x; }; } - var var_x = x; - if (typeof var_x == \"number\") { call_me = () => { var y: number = var_x; @@ -339,7 +299,6 @@ function h(x: number | string | boolean) { }; } } - call_me(); " `; diff --git a/tests/commonjs/__snapshots__/jsfmt.spec.js.snap b/tests/commonjs/__snapshots__/jsfmt.spec.js.snap index 671e7cb5..3fa8065b 100644 --- a/tests/commonjs/__snapshots__/jsfmt.spec.js.snap +++ b/tests/commonjs/__snapshots__/jsfmt.spec.js.snap @@ -5,7 +5,6 @@ function f(x:string) { } module.exports = f; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function f(x: string) {} - module.exports = f; " `; @@ -17,7 +16,6 @@ var f = require(\'./Abs\'); f(0); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var f = require(\"./Abs\"); - f(0); " `; diff --git a/tests/computed_props/__snapshots__/jsfmt.spec.js.snap b/tests/computed_props/__snapshots__/jsfmt.spec.js.snap index 615127ba..ce1cfa12 100644 --- a/tests/computed_props/__snapshots__/jsfmt.spec.js.snap +++ b/tests/computed_props/__snapshots__/jsfmt.spec.js.snap @@ -32,11 +32,8 @@ var ColorIdToNumber = { [ColorId.GREEN]: ColorNumber.GREEN, [ColorId.BLUE]: ColorNumber.BLUE }; - (ColorIdToNumber[ColorId.RED]: \"ffffff\"); - ColorIdToNumber.XXX; - module.exports = { ColorId, ColorNumber }; " `; @@ -60,9 +57,7 @@ var ColorIdToNumber = { [ColorId.GREEN]: ColorNumber.GREEN, [ColorId.BLUE]: ColorNumber.BLUE }; - (ColorIdToNumber[ColorId.GREEN]: \"ffffff\"); - module.exports = ColorIdToNumber; " `; @@ -76,7 +71,6 @@ var ColorIdToNumber = require(\'./test2\'); // oops var { ColorId } = require(\"./test\"); var ColorIdToNumber = require(\"./test2\"); - (ColorIdToNumber[ColorId.BLUE]: \"ffffff\"); " `; @@ -99,7 +93,6 @@ module.exports = { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var hello = require(\"./test4\"); var dummy = require(\"./test\"); - module.exports = { ...dummy, [hello]: \"world\", ...dummy }; " `; @@ -110,7 +103,6 @@ exports[`test test6.js 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // oops var o = require(\"./test5\"); - (o.hello: \"nothing\"); " `; diff --git a/tests/conditional/__snapshots__/jsfmt.spec.js.snap b/tests/conditional/__snapshots__/jsfmt.spec.js.snap index b2fb3b7c..a9955eca 100644 --- a/tests/conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/conditional/__snapshots__/jsfmt.spec.js.snap @@ -32,18 +32,15 @@ function a(): number { var x: ?string = null; return x ? 1 : 0; } - function b(): number { var x: ?number = null; return x != null ? x : 0; } - function c(): number { var x = false; var temp = x ? 1 : x; return temp ? temp : 0; } - function d(): string { var x: ?number = null; return x != null ? x : x != null; diff --git a/tests/config_all_weak/__snapshots__/jsfmt.spec.js.snap b/tests/config_all_weak/__snapshots__/jsfmt.spec.js.snap index 1fba561f..67a13971 100644 --- a/tests/config_all_weak/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_all_weak/__snapshots__/jsfmt.spec.js.snap @@ -4,7 +4,6 @@ exports[`test no_at_flow.js 1`] = ` x.length; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x; - x.length; " `; diff --git a/tests/config_file_extensions/__snapshots__/jsfmt.spec.js.snap b/tests/config_file_extensions/__snapshots__/jsfmt.spec.js.snap index 9c34a8d4..f0084118 100644 --- a/tests/config_file_extensions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_file_extensions/__snapshots__/jsfmt.spec.js.snap @@ -19,7 +19,6 @@ function foo(x) { var a: number = \"asdf\"; return x * 10; } - foo(\"Hello, world!\"); " `; diff --git a/tests/config_module_system_node_resolve_dirname/__snapshots__/jsfmt.spec.js.snap b/tests/config_module_system_node_resolve_dirname/__snapshots__/jsfmt.spec.js.snap index 316b7875..6fa40e88 100644 --- a/tests/config_module_system_node_resolve_dirname/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_module_system_node_resolve_dirname/__snapshots__/jsfmt.spec.js.snap @@ -9,9 +9,7 @@ import {name} from \"testproj\"; // @flow // Error: Resolve from node_modules first! import {name} from \"testproj\"; - (name: \"node_modules/testproj\"); - (name: \"custom_resolve_dir/testproj\"); " `; diff --git a/tests/config_module_system_node_resolve_dirname/subdir/__snapshots__/jsfmt.spec.js.snap b/tests/config_module_system_node_resolve_dirname/subdir/__snapshots__/jsfmt.spec.js.snap index b258d151..86ce5276 100644 --- a/tests/config_module_system_node_resolve_dirname/subdir/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_module_system_node_resolve_dirname/subdir/__snapshots__/jsfmt.spec.js.snap @@ -9,9 +9,7 @@ import {name} from \"testproj2\"; // @flow // Error: Resolve from sibling \'custom_resolve_dir\' first! import {name} from \"testproj2\"; - (name: \"node_modules/testproj2\"); - (name: \"subdir/custom_resolve_dir/testproj2\"); " `; diff --git a/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap b/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap index b09693c9..5eeef88d 100644 --- a/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap @@ -48,15 +48,12 @@ class A { return \"some string\"; } } - A._sProperty = 48; - class B extends A { _property1: string; static _sProperty: string; constructor() { super(); - this._property1 = \"another string\"; } _method1(): string { @@ -66,7 +63,6 @@ class B extends A { return 23; } } - B._sProperty = \"B._sProperty string\"; " `; @@ -84,7 +80,6 @@ module.exports = new C; class C { _p: string; } - module.exports = new C(); " `; diff --git a/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap b/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap index 2a216b3b..69d00c9c 100644 --- a/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap @@ -48,15 +48,12 @@ class A { return \"some string\"; } } - A._sProperty = 48; - class B extends A { _property1: string; static _sProperty: string; constructor() { super(); - this._property1 = \"another string\"; } _method1(): string { @@ -66,7 +63,6 @@ class B extends A { return 23; } } - B._sProperty = \"B._sProperty string\"; " `; diff --git a/tests/const_params/__snapshots__/jsfmt.spec.js.snap b/tests/const_params/__snapshots__/jsfmt.spec.js.snap index 036e585a..24fef60f 100644 --- a/tests/const_params/__snapshots__/jsfmt.spec.js.snap +++ b/tests/const_params/__snapshots__/jsfmt.spec.js.snap @@ -52,7 +52,6 @@ function durable_refi(x: ?number) { function cannot_reassign(x: string) { x = \"hey\"; } - function durable_refi(x: ?number) { if (x) { return () => { diff --git a/tests/constructor/__snapshots__/jsfmt.spec.js.snap b/tests/constructor/__snapshots__/jsfmt.spec.js.snap index 21cf3452..666897f0 100644 --- a/tests/constructor/__snapshots__/jsfmt.spec.js.snap +++ b/tests/constructor/__snapshots__/jsfmt.spec.js.snap @@ -15,7 +15,6 @@ class C { class D { constructor(): number {} } - module.exports = C; " `; diff --git a/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap b/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap index 42ebc809..7033255d 100644 --- a/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap +++ b/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap @@ -32,24 +32,19 @@ exports.Foo2 = (Foo: Class); function Foo() { this.x = 0; } - Foo.y = 0; - Foo.prototype = { m() { return 0; } }; - exports.Foo = Foo; - interface IFooPrototype { m(): number } interface IFoo extends IFooPrototype { static (): void, x: boolean, static y: boolean } - exports.Foo2 = (Foo: Class); " `; diff --git a/tests/contents/ignore/__snapshots__/jsfmt.spec.js.snap b/tests/contents/ignore/__snapshots__/jsfmt.spec.js.snap index c503ca73..19942181 100644 --- a/tests/contents/ignore/__snapshots__/jsfmt.spec.js.snap +++ b/tests/contents/ignore/__snapshots__/jsfmt.spec.js.snap @@ -10,9 +10,7 @@ var xxx = 0; xxx ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require(\"./dummy\"); - var xxx = 0; - xxx; " `; diff --git a/tests/contents/no_flow/__snapshots__/jsfmt.spec.js.snap b/tests/contents/no_flow/__snapshots__/jsfmt.spec.js.snap index c503ca73..19942181 100644 --- a/tests/contents/no_flow/__snapshots__/jsfmt.spec.js.snap +++ b/tests/contents/no_flow/__snapshots__/jsfmt.spec.js.snap @@ -10,9 +10,7 @@ var xxx = 0; xxx ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require(\"./dummy\"); - var xxx = 0; - xxx; " `; diff --git a/tests/core_tests/__snapshots__/jsfmt.spec.js.snap b/tests/core_tests/__snapshots__/jsfmt.spec.js.snap index e6fd84cd..7b43343f 100644 --- a/tests/core_tests/__snapshots__/jsfmt.spec.js.snap +++ b/tests/core_tests/__snapshots__/jsfmt.spec.js.snap @@ -51,28 +51,18 @@ let tests = [ let tests = [ function() { new Boolean(); - new Boolean(0); - new Boolean(-0); - new Boolean(null); - new Boolean(false); - new Boolean(NaN); - new Boolean(undefined); - new Boolean(\"\"); }, function() { true.toString(); - let x: boolean = false; - x.toString(); - new Boolean(true).toString(); }, function() { @@ -80,19 +70,12 @@ let tests = [ }, function() { Boolean(); - Boolean(0); - Boolean(-0); - Boolean(null); - Boolean(false); - Boolean(NaN); - Boolean(undefined); - Boolean(\"\"); } ]; @@ -146,7 +129,6 @@ function* generator(): Iterable<[string, number]> { yield [ \"foo\", 123 ]; } } - let tests = [ function() { let w = new Map(); @@ -163,7 +145,6 @@ let tests = [ }, function(x: Map) { (x.get(\"foo\"): boolean); - x.get(123); } ]; @@ -214,33 +195,22 @@ let tests = [ let tests = [ function() { new RegExp(\"foo\"); - new RegExp(/foo/); - new RegExp(\"foo\", \"i\"); - new RegExp(\"foo\", \"ig\"); - new RegExp(/foo/, \"i\"); - new RegExp(/foo/g, \"i\"); }, function() { RegExp(\"foo\"); - RegExp(/foo/); - RegExp(\"foo\", \"i\"); - RegExp(\"foo\", \"ig\"); - RegExp(/foo/, \"i\"); - RegExp(/foo/g, \"i\"); }, function() { RegExp(\"foo\", \"z\"); - new RegExp(\"foo\", \"z\"); } ]; @@ -291,43 +261,29 @@ let ws5 = new WeakSet(numbers()); // error, must be objects let ws = new WeakSet(); let obj: Object = {}; let dict: { foo: string } = { foo: \"bar\" }; - ws.add(window); - ws.add(obj); - ws.add(dict); - ws.has(window); - ws.has(obj); - ws.has(dict); - ws.delete(window); - ws.delete(obj); - ws.delete(dict); - let ws2 = new WeakSet([ obj, dict ]); let ws3 = new WeakSet([ 1, 2, 3 ]); - function* generator(): Iterable<{ foo: string }> { while (true) { yield { foo: \"bar\" }; } } - let ws4 = new WeakSet(generator()); - function* numbers(): Iterable { let i = 0; while (true) { yield i++; } } - let ws5 = new WeakSet(numbers()); " `; diff --git a/tests/covariance/__snapshots__/jsfmt.spec.js.snap b/tests/covariance/__snapshots__/jsfmt.spec.js.snap index b680c9a3..6ee94bc9 100644 --- a/tests/covariance/__snapshots__/jsfmt.spec.js.snap +++ b/tests/covariance/__snapshots__/jsfmt.spec.js.snap @@ -89,9 +89,7 @@ n.x = [0]; type CovArrayVerbose = Array; var b: CovArrayVerbose = []; var y: CovArrayVerbose = b; - y[0] = \"\"; - class NVerbose { x: CovArrayVerbose; foo(): CovArrayVerbose { @@ -99,11 +97,8 @@ class NVerbose { } } var nv: NVerbose = new NVerbose(); - nv.x = [ 0 ]; - (nv.x[0]: string); - (nv.foo()[0]: string); " `; diff --git a/tests/coverage/__snapshots__/jsfmt.spec.js.snap b/tests/coverage/__snapshots__/jsfmt.spec.js.snap index 9ec8e4b3..f9dfe473 100644 --- a/tests/coverage/__snapshots__/jsfmt.spec.js.snap +++ b/tests/coverage/__snapshots__/jsfmt.spec.js.snap @@ -36,7 +36,6 @@ exports[`test no_pragma.js 1`] = ` (x: string); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ let x = 0; - (x: string); " `; diff --git a/tests/cycle/__snapshots__/jsfmt.spec.js.snap b/tests/cycle/__snapshots__/jsfmt.spec.js.snap index bd0d5c48..f652eb51 100644 --- a/tests/cycle/__snapshots__/jsfmt.spec.js.snap +++ b/tests/cycle/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,6 @@ module.exports = A; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var B = require(\"./B\"); class A extends B {} - module.exports = A; " `; @@ -21,7 +20,6 @@ module.exports = B; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //class B extends A { } var A = require(\"./A\"); - module.exports = B; " `; diff --git a/tests/date/__snapshots__/jsfmt.spec.js.snap b/tests/date/__snapshots__/jsfmt.spec.js.snap index 9421de8c..e4ac978b 100644 --- a/tests/date/__snapshots__/jsfmt.spec.js.snap +++ b/tests/date/__snapshots__/jsfmt.spec.js.snap @@ -34,41 +34,23 @@ new Date(2015, 6, 18, 11, 55, 42, 999, \'hahaha\'); var d = new Date(0); var x: string = d.getTime(); var y: number = d; - new Date(); - new Date(1234567890); - new Date(\"2015/06/18\"); - new Date(2015, 6); - new Date(2015, 6, 18); - new Date(2015, 6, 18, 11); - new Date(2015, 6, 18, 11, 55); - new Date(2015, 6, 18, 11, 55, 42); - new Date(2015, 6, 18, 11, 55, 42, 999); - new Date({}); - new Date(2015, \"6\"); - new Date(2015, 6, \"18\"); - new Date(2015, 6, 18, \"11\"); - new Date(2015, 6, 18, 11, \"55\"); - new Date(2015, 6, 18, 11, 55, \"42\"); - new Date(2015, 6, 18, 11, 55, 42, \"999\"); - new Date(\"2015\", 6); - new Date(2015, 6, 18, 11, 55, 42, 999, \"hahaha\"); " `; diff --git a/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap index 593fee81..284cf97a 100644 --- a/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap @@ -68,15 +68,10 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var Implicit = require(\"ImplicitProvidesModule\"); - (Implicit.fun(): string); - var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\"); - (ExplicitSameName.fun(): string); - var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\"); - (ExplicitDifferentName.fun(): string); " `; diff --git a/tests/declaration_files_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap index 39dd1e86..43a7dfa3 100644 --- a/tests/declaration_files_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap @@ -20,11 +20,8 @@ var docblock = require(\"qux/docblock\"); var min = require(\"d3/min.js\"); var corge = require(\"qux/corge\"); var unreachable = require(\"annotation\"); - (docblock.fun(): string); - (min.fun(): string); - (corge.fun(): string); " `; diff --git a/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap index 412a0f72..0a3ea919 100644 --- a/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap @@ -25,7 +25,6 @@ module.exports.fun = (): Implementation => new Implementation; * @flow */ class Implementation {} - module.exports.fun = (): Implementation => new Implementation(); " `; @@ -44,7 +43,6 @@ module.exports.fun = (): Implementation => new Implementation; * @flow */ class Implementation {} - module.exports.fun = (): Implementation => new Implementation(); " `; @@ -63,7 +61,6 @@ module.exports.fun = (): Implementation => new Implementation; * @flow */ class Implementation {} - module.exports.fun = (): Implementation => new Implementation(); " `; @@ -93,15 +90,10 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\'); // Error: Either Implementation ~> boolean or Declaration ~> boolean // Error: Either Implementation ~> boolean or Declaration ~> boolean var Implicit = require(\"ImplicitProvidesModule\"); - (Implicit.fun(): boolean); - var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\"); - (ExplicitSameName.fun(): boolean); - var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\"); - (ExplicitDifferentName.fun(): boolean); " `; diff --git a/tests/declaration_files_incremental_haste/external/_d3/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_incremental_haste/external/_d3/__snapshots__/jsfmt.spec.js.snap index 6556366e..02bbf30a 100644 --- a/tests/declaration_files_incremental_haste/external/_d3/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_haste/external/_d3/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test min.js 1`] = ` module.exports.fun = (): Implementation => new Implementation; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class Implementation {} - module.exports.fun = (): Implementation => new Implementation(); " `; diff --git a/tests/declaration_files_incremental_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_incremental_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap index 1a9f2a6e..1642bb7e 100644 --- a/tests/declaration_files_incremental_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap @@ -16,11 +16,8 @@ var corge = require(\'qux/corge\'); var docblock = require(\"qux/docblock\"); var min = require(\"d3/min.js\"); var corge = require(\"qux/corge\"); - (docblock.fun(): boolean); - (min.fun(): boolean); - (corge.fun(): boolean); " `; diff --git a/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap index 5c5cd641..1e0dbe29 100644 --- a/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap @@ -70,51 +70,28 @@ var F = require(\'package_with_dir_main\'); // Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean var B1 = require(\"B\"); - (B1.fun(): boolean); - var B2 = require(\"B.js\"); - (B2.fun(): boolean); - var C = require(\"package_with_full_main\"); - (C.fun(): boolean); - var D = require(\"package_with_partial_main\"); - (D.fun(): boolean); - var E = require(\"package_with_no_package_json\"); - (E.fun(): boolean); - var F = require(\"package_with_dir_main\"); - (F.fun(): boolean); - var B1 = require(\"B\"); - (B1.fun(): boolean); - var B2 = require(\"B.js\"); - (B2.fun(): boolean); - var C = require(\"package_with_full_main\"); - (C.fun(): boolean); - var D = require(\"package_with_partial_main\"); - (D.fun(): boolean); - var E = require(\"package_with_no_package_json\"); - (E.fun(): boolean); - var F = require(\"package_with_dir_main\"); - (F.fun(): boolean); " `; @@ -126,7 +103,6 @@ exports[`test test_relative.js 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Error: either Implementation ~> boolean or Definition ~> boolean import {foo} from \"./A\"; - (foo(): boolean); " `; diff --git a/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap index 5baccdd1..777cf1f1 100644 --- a/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap @@ -50,27 +50,16 @@ var F = require(\'package_with_dir_main\'); // Error number ~> string // Error number ~> string var B1 = require(\"B\"); - (B1.fun(): string); - var B2 = require(\"B.js\"); - (B2.fun(): string); - var C = require(\"package_with_full_main\"); - (C.fun(): string); - var D = require(\"package_with_partial_main\"); - (D.fun(): string); - var E = require(\"package_with_no_package_json\"); - (E.fun(): string); - var F = require(\"package_with_dir_main\"); - (F.fun(): string); " `; @@ -97,17 +86,11 @@ var CJS = require(\'./CJS.js\'); // Error number ~> string // Error: string ~> number var A1 = require(\"./A\"); - (A1.fun(): string); - var A2 = require(\"./A.js\"); - (A2.fun(): string); - var CJS = require(\"./CJS.js\"); - (CJS: string); - (CJS: number); " `; diff --git a/tests/declare_class/__snapshots__/jsfmt.spec.js.snap b/tests/declare_class/__snapshots__/jsfmt.spec.js.snap index 241ad005..254d373a 100644 --- a/tests/declare_class/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_class/__snapshots__/jsfmt.spec.js.snap @@ -12,13 +12,9 @@ C.foo(\"\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error, it\'s a string declare class C { static x: number, static foo(x: number): void } - C.x = \"\"; - C.foo(\"\"); - (C.name: string); - (C.name: number); " `; diff --git a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap index b99fd957..c83406e6 100644 --- a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap @@ -64,7 +64,6 @@ class Test extends Base { return 2; } } - module.exports = Test; " `; @@ -114,13 +113,9 @@ exports.numberValue5 = 5; * @flow */ exports.numberValue1 = 1; - exports.numberValue2 = 2; - exports.numberValue3 = 3; - exports.numberValue4 = 4; - exports.numberValue5 = 5; " `; @@ -493,13 +488,9 @@ exports.stringValue = \"str\"; * @flow */ exports.numberValue1 = 42; - exports.numberValue2 = 42; - exports.numberValue3 = 42; - exports.numberValue4 = 42; - exports.stringValue = \"str\"; " `; @@ -990,33 +981,24 @@ var d2: string = numVal1; import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\"; var e1: number = CJS_Clobb_Lit.numberValue3; var e2: string = CJS_Clobb_Lit.numberValue3; - CJS_Clobb_Lit.doesntExist; - import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\"; var f1: number = CJS_Clobb_Lit_NS.numberValue4; var f2: number = CJS_Clobb_Lit_NS.default.numberValue4; - CJS_Clobb_Lit_NS.default.default; - var f3: string = CJS_Clobb_Lit_NS.numberValue4; var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; import {doesntExist2} from \"CommonJS_Clobbering_Class\"; import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\"; import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\"; - new CJS_Clobb_Class(); - new CJS_Clobb_Class().doesntExist; - var h1: number = CJS_Clobb_Class.staticNumber2(); var h2: string = CJS_Clobb_Class.staticNumber2(); var h3: number = new CJS_Clobb_Class().instNumber1(); var h4: string = new CJS_Clobb_Class().instNumber1(); import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\"; - new CJS_Clobb_Class_NS(); - var i1: number = CJS_Clobb_Class_NS.staticNumber3(); var i2: number = new CJS_Clobb_Class_NS.default().instNumber2(); var i3: string = new CJS_Clobb_Class_NS.default().instNumber2(); @@ -1030,9 +1012,7 @@ var k2: string = numVal3; import * as CJS_Named from \"CommonJS_Named\"; var l1: number = CJS_Named.numberValue1; var l2: string = CJS_Named.numberValue1; - CJS_Named.doesntExist; - import * as CJS_Named_NS from \"CommonJS_Named\"; var m1: number = CJS_Named_NS.numberValue4; var m2: string = CJS_Named_NS.default.numberValue4; @@ -1082,9 +1062,7 @@ var ab2: string = numberValue2_renamed; import {numberValue1 as numberValue5} from \"ES6_ExportAllFrom_Intermediary1\"; var ac1: number = numberValue5; var ac2: string = numberValue5; - require(\"ES6_Default_AnonFunction2\").doesntExist; - var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default; var ad1: number = ES6_Def_AnonFunc2(); var ad2: string = ES6_Def_AnonFunc2(); diff --git a/tests/declare_fun/__snapshots__/jsfmt.spec.js.snap b/tests/declare_fun/__snapshots__/jsfmt.spec.js.snap index f9611c54..b43e39d7 100644 --- a/tests/declare_fun/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_fun/__snapshots__/jsfmt.spec.js.snap @@ -13,11 +13,8 @@ declare function foo(x: X): X; declare function foo(x: number): string; declare function foo(x: string): number; declare function foo(x: X): X; - (foo(0): string); - (foo(\"hello\"): number); - (foo(false): void); " `; diff --git a/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap b/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap index 432fdcd1..1bcc4dda 100644 --- a/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap @@ -36,28 +36,17 @@ import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\"; // Error: number ~> string // Error: number ~> string import declare_module_exports from \"declare_module_exports\"; - (declare_module_exports: number); - (declare_module_exports: string); - import {str} from \"declare_m_e_with_other_value_declares\"; import type {str2} from \"declare_m_e_with_other_type_declares\"; - (\"asdf\": str2); - (42: str2); - import DEPRECATED__declare_var_exports from \"DEPRECATED__declare_var_exports\"; - (DEPRECATED__declare_var_exports: number); - (DEPRECATED__declare_var_exports: string); - import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\"; - (declare_m_e_with_declare_var_e: number); - (declare_m_e_with_declare_var_e: string); " `; diff --git a/tests/declare_type/__snapshots__/jsfmt.spec.js.snap b/tests/declare_type/__snapshots__/jsfmt.spec.js.snap index c0383703..509d3fd0 100644 --- a/tests/declare_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_type/__snapshots__/jsfmt.spec.js.snap @@ -54,13 +54,9 @@ import type {toz} from \"ModuleAliasFoo\"; var k4: toz = foo(k1); import blah from \"foo\"; import type {Foo, Bar, Id} from \"foo\"; - blah(0, 0); - ({ toz: 3 }: Foo); - (3: Bar); - (\"lol\": Id); " `; diff --git a/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap b/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap index c7510e63..e2983148 100644 --- a/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap +++ b/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap @@ -55,13 +55,10 @@ class Variance<+Out, -In> { } class A {} class B extends A {} - function subtyping(v1: Variance, v2: Variance) { (v1: Variance); - (v2: Variance); } - class PropVariance<+Out, -In> { inv1: Out; inv2: In; diff --git a/tests/demo/1/__snapshots__/jsfmt.spec.js.snap b/tests/demo/1/__snapshots__/jsfmt.spec.js.snap index 4b03d887..eaf0b237 100644 --- a/tests/demo/1/__snapshots__/jsfmt.spec.js.snap +++ b/tests/demo/1/__snapshots__/jsfmt.spec.js.snap @@ -13,9 +13,7 @@ f(x); function f(x) { return 42 / x; } - var x = null; - f(x); " `; diff --git a/tests/demo/2/__snapshots__/jsfmt.spec.js.snap b/tests/demo/2/__snapshots__/jsfmt.spec.js.snap index e4017d9c..d62a8fbb 100644 --- a/tests/demo/2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/demo/2/__snapshots__/jsfmt.spec.js.snap @@ -33,15 +33,11 @@ class A { return callback(this.getX()); } } - function callback(x: string) { return x.length; } - var a = new A(42); - a.onLoad(callback); - module.exports = A; " `; diff --git a/tests/deps/__snapshots__/jsfmt.spec.js.snap b/tests/deps/__snapshots__/jsfmt.spec.js.snap index 42e4f837..70f5644e 100644 --- a/tests/deps/__snapshots__/jsfmt.spec.js.snap +++ b/tests/deps/__snapshots__/jsfmt.spec.js.snap @@ -19,11 +19,8 @@ require(\'./F\'); require(\'./G\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require(\"./D\"); - require(\"./E\"); - require(\"./F\"); - require(\"./G\"); " `; diff --git a/tests/destructuring/__snapshots__/jsfmt.spec.js.snap b/tests/destructuring/__snapshots__/jsfmt.spec.js.snap index de1f7def..8d854f33 100644 --- a/tests/destructuring/__snapshots__/jsfmt.spec.js.snap +++ b/tests/destructuring/__snapshots__/jsfmt.spec.js.snap @@ -23,15 +23,10 @@ let [ a, ...ys ] = xs; let [ b, ...zs ] = ys; let c = zs[0]; let d = zs[1]; - (a: void); - (b: void); - (c: void); - (d: void); - let [ ...e ] = 0; " `; @@ -51,16 +46,11 @@ var { [\"key\"]: val3, ...spread } = { key: \"val\" }; // ok (gasp!) by existing StrT -> ElemT rule // error (gasp!) in general we don\'t know if a computed prop should be excluded from spread var { [\"key\"]: val1 } = { key: \"val\" }; - (val1: void); - var key: string = \"key\"; var { [key]: val2 } = { key: \"val\" }; - (val2: void); - var { [\"key\"]: val3, ...spread } = { key: \"val\" }; - (spread.key: void); " `; @@ -193,75 +183,45 @@ function default_expr_scope({a, b = a}) {} function obj_prop_fun({ p: { q = 0 } = { q: true } } = { p: { q: \"\" } }) { (q: void); } - obj_prop_fun(); - obj_prop_fun({}); - obj_prop_fun({ p: {} }); - obj_prop_fun({ p: { q: null } }); - function obj_prop_var(o = { p: { q: \"\" } }) { var { p: { q = 0 } = { q: true } } = o; - (q: void); } - obj_prop_var(); - obj_prop_var({}); - obj_prop_var({ p: {} }); - obj_prop_var({ p: { q: null } }); - function obj_rest( { p: { q, ...o } = { q: 0, r: 0 } } = { p: { q: 0, r: \"\" } } ) { (o.r: void); } - obj_rest(); - obj_rest({}); - obj_rest({ p: {} }); - obj_rest({ p: { q: 0, r: null } }); - function obj_prop_annot({ p = true }: { p: string } = { p: 0 }) { (p: void); } - var { p = true }: { p: string } = { p: 0 }; - (p: void); - function obj_prop_err({ x: { y } } = null) {} - function obj_rest_err({ ...o } = 0) {} - function arr_elem_err([ x ] = null) {} - function arr_rest_err([ ...a ] = null) {} - function gen(x: T, { p = x }: { p: T }): T { return p; } - obj_prop_fun(({}: { p?: { q?: null } })); - obj_prop_var(({}: { p?: { q?: null } })); - function obj_prop_opt({ p }: { p?: string } = { p: 0 }) {} - function obj_prop_maybe({ p }: { p: ?string } = { p: 0 }) {} - function obj_prop_union({ p }: { p: number | string } = { p: true }) {} - function obj_prop_union2({ p }: { p: number } | { p: string } = { p: true }) {} - function default_expr_scope({ a, b = a }) {} " `; @@ -350,66 +310,41 @@ var cp2_err: string = others.childprop2; // Error: number ~> string declare var a: string; declare var b: string; declare var c: string; - [ { a1: a, b }, c ] = [ { a1: 0, b: 1 }, 2 ]; - var { m } = { m: 0 }; - ({ m } = { m: m }); - var obj; - ({ n: obj.x } = { n: 3 }); - [ obj.x ] = [ \"foo\" ]; - function foo({ p, z: [ r ] }) { a = p; - b = z; - c = r; } - foo({ p: 0, z: [ 1, 2 ] }); - [ a, , b, ...c ] = [ 0, 1, true, 3 ]; - function bar({ x, ...z }) { var o: { x: string, y: number } = z; } - bar({ x: \"\", y: 0 }); - var spread = { y: \"\" }; var extend: { x: number, y: string, z: boolean } = { x: 0, ...spread }; - function qux(_: { a: number }) {} - qux({ a: \"\" }); - function corge({ b }: { b: string }) {} - corge({ b: 0 }); - var { n }: { n: number } = { n: \"\" }; - function test() { var { foo } = { bar: 123 }; var { bar, baz } = { bar: 123 }; } - function test() { var x = { foo: \"abc\", bar: 123 }; var { foo, ...rest } = x; - (x.baz: string); - (rest.baz: string); } - module.exports = corge; - class Base { baseprop1: number; baseprop2: number; @@ -463,7 +398,6 @@ exports[`test eager.js 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error, property \`x\` can not be accessed on \`null\` var x; - ({ x } = null); " `; @@ -516,43 +450,27 @@ function arr_rest_pattern([ _, ...a ] : ArrRest) { // a: [X] // a: [X] // a: [X] function obj_pattern({ prop }: { prop: X }) {} - type Prop = { prop: X }; - function obj_pattern2({ prop }: Prop) {} - function arr_pattern([ elem ]: X[]) {} - type Elem = X[]; - function arr_pattern2([ elem ]: Elem) {} - function tup_pattern([ proj ]: [X]) {} - type Proj = [X]; - function tup_pattern2([ proj ]: Proj) {} - function rest_antipattern(...t: T) {} - function rest_pattern(...r: X[]) {} - function obj_rest_pattern({ _, ...o }: { _: any, x: X }) { o.x; } - type ObjRest = { _: any, x: X }; - function obj_rest_pattern({ _, ...o }: ObjRest) { o.x; } - function arr_rest_pattern([ _, ...a ]: [any, X]) { a[0]; } - type ArrRest = [any, X]; - function arr_rest_pattern([ _, ...a ]: ArrRest) { a[0]; } @@ -588,14 +506,11 @@ var { x: o } = o; let foo = (i: number) => [ i ]; const bar = (i: number) => { [ i ] = foo(i); - return [ i ]; }; - foo = (i: number) => { return bar(i); }; - declare var o; var { x: o } = o; " @@ -611,11 +526,8 @@ var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" }; // error: string ~> void // ok var { \"key\": val } = { key: \"val\" }; - (val: void); - var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" }; - (with_dash: \"motivating example\"); " `; @@ -633,7 +545,6 @@ function bar() { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var { x } = { x: { foo: \"foo\" } }; - function bar() { x.bar; } diff --git a/tests/dictionary/__snapshots__/jsfmt.spec.js.snap b/tests/dictionary/__snapshots__/jsfmt.spec.js.snap index 0f0a3f5d..41fa7c36 100644 --- a/tests/dictionary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dictionary/__snapshots__/jsfmt.spec.js.snap @@ -38,10 +38,8 @@ function foo0( x: Array<{ [key: string]: mixed }> ): Array<{ [key: string]: mixed }> { x[0].fooBar = \"foobar\"; - return x; } - function foo2( x: { [key: string]: number } ): { [key: string]: number, +toString: () => string } { @@ -504,231 +502,167 @@ class B extends A {} class C extends B {} class X {} class Y {} - function set_prop_to_string_key(o: { [k: string]: any }) { o.prop = \"ok\"; } - function unsound_dict_has_every_key(o: { [k: string]: X }) { (o.p: X); - (o[\"p\"]: X); } - function set_prop_covariant(o: { [k: string]: B }) { o.p = new A(); - o.p = new B(); - o.p = new C(); } - function get_prop_contravariant(o: { [k: string]: B }) { (o.p: A); - (o.p: B); - (o.p: C); } - function add_prop_to_nonstring_key_dot(o: { [k: number]: any }) { o.prop = \"err\"; } - function add_prop_to_nonstring_key_bracket(o: { [k: number]: any }) { o[0] = \"ok\"; } - function mix_with_declared_props(o: { [k: number]: X, p: Y }, x: X, y: Y) { (o[0]: X); - (o.p: Y); - o[0] = x; - o.p = y; } - function object_prototype( o: { [k: string]: number } ): { [k: string]: number, +toString: () => string } { (o.toString(): boolean); - return o; } - function unsound_string_conversion_alias_declared_prop( o: { [k: number]: any, \"0\": X } ) { o[0] = \"not-x\"; } - function unification_dict_values_invariant(x: Array<{ [k: string]: B }>) { let a: Array<{ [k: string]: A }> = x; - a[0].p = new A(); - let b: Array<{ [k: string]: B }> = x; let c: Array<{ [k: string]: C }> = x; - (x[0].p: C); } - function subtype_dict_values_invariant(x: { [k: string]: B }) { let a: { [k: string]: A } = x; - a.p = new A(); - let b: { [k: string]: B } = x; let c: { [k: string]: C } = x; - (x.p: C); } - function subtype_dict_values_fresh_exception() { let a: { [k: string]: A } = { a: new A(), b: new B(), c: new C() }; let b: { [k: string]: B } = { a: new A(), b: new B(), c: new C() }; let c: { [k: string]: C } = { a: new A(), b: new B(), c: new C() }; } - function unification_dict_keys_invariant(x: Array<{ [k: B]: any }>) { let a: Array<{ [k: A]: any }> = x; let b: Array<{ [k: B]: any }> = x; let c: Array<{ [k: C]: any }> = x; } - function subtype_dict_keys_invariant(x: { [k: B]: any }) { let a: { [k: A]: any } = x; let b: { [k: B]: any } = x; let c: { [k: C]: any } = x; } - function unification_mix_with_declared_props_invariant_l( x: Array<{ [k: string]: B }> ) { let a: Array<{ [k: string]: B, p: A }> = x; - a[0].p = new A(); - let b: Array<{ [k: string]: B, p: B }> = x; let c: Array<{ [k: string]: B, p: C }> = x; - (x[0].p: C); } - function unification_mix_with_declared_props_invariant_r( xa: Array<{ [k: string]: A, p: B }>, xb: Array<{ [k: string]: B, p: B }>, xc: Array<{ [k: string]: C, p: B }> ) { let a: Array<{ [k: string]: A }> = xa; - a[0].p = new A(); - let b: Array<{ [k: string]: B }> = xb; let c: Array<{ [k: string]: C }> = xc; - (xc[0].p: C); } - function subtype_mix_with_declared_props_invariant_l(x: { [k: string]: B }) { let a: { [k: string]: B, p: A } = x; - a.p = new A(); - let b: { [k: string]: B, p: B } = x; let c: { [k: string]: B, p: C } = x; - (x.p: C); } - function subtype_mix_with_declared_props_invariant_r( xa: { [k: string]: A, p: B }, xb: { [k: string]: B, p: B }, xc: { [k: string]: C, p: B } ) { let a: { [k: string]: A } = xa; - a.p = new A(); - let b: { [k: string]: B } = xb; let c: { [k: string]: C } = xc; - (xc.p: C); } - function unification_dict_to_obj( x: Array<{ [k: string]: X }> ): Array<{ p: X }> { return x; } - function unification_obj_to_dict( x: Array<{ p: X }> ): Array<{ [k: string]: X }> { return x; } - function subtype_dict_to_obj(x: { [k: string]: B }) { let a: { p: A } = x; - a.p = new A(); - let b: { p: B } = x; let c: { p: C } = x; - (x.p: C); } - function subtype_obj_to_dict(x: { p: B }) { let a: { [k: string]: A } = x; - a.p = new A(); - let b: { [k: string]: B } = x; let c: { [k: string]: C } = x; - (x.p: C); } - function subtype_obj_to_mixed(x: { p: B, x: X }) { let a: { [k: string]: A, x: X } = x; let b: { [k: string]: B, x: X } = x; let c: { [k: string]: C, x: X } = x; } - function unification_dict_to_mixed(x: Array<{ [k: string]: B }>) { let a: Array<{ [k: string]: B, p: A }> = x; let b: Array<{ [k: string]: B, p: B }> = x; let c: Array<{ [k: string]: B, p: C }> = x; } - function subtype_dict_to_mixed(x: { [k: string]: B }) { let a: { [k: string]: B, p: A } = x; let b: { [k: string]: B, p: B } = x; let c: { [k: string]: B, p: C } = x; } - function subtype_dict_to_optional_a(x: { [k: string]: B }) { let a: { p?: A } = x; } - function subtype_dict_to_optional_b(x: { [k: string]: B }) { let b: { p?: B } = x; } - function subtype_dict_to_optional_c(x: { [k: string]: B }) { let c: { p?: C } = x; } - function subtype_optional_a_to_dict(x: { p?: A }): { [k: string]: B } { return x; } - function subtype_optional_b_to_dict(x: { p?: B }): { [k: string]: B } { return x; } - function subtype_optional_c_to_dict(x: { p?: C }): { [k: string]: B } { return x; } @@ -814,52 +748,41 @@ var z: { [key: number]: string } = x; var a: { [key: string]: ?string } = {}; var b: { [key: string]: string } = a; var c: { [key: string]: ?string } = b; - function foo0( x: Array<{ [key: string]: number }> ): Array<{ [key: string]: string }> { return x; } - function foo1( x: Array<{ [key: string]: number }> ): Array<{ [key: string]: number, fooBar: string }> { return x; } - function foo2( x: Array<{ [key: string]: mixed }> ): Array<{ [key: string]: mixed, fooBar: string }> { x[0].fooBar = 123; - return x; } - function foo3(x: { [key: string]: number }): { foo: number } { return x; } - function foo4( x: { [key: string]: number } ): { [key: string]: number, foo: string } { return x; } - function foo5(x: Array<{ [key: string]: number }>): Array<{ foo: number }> { return x; } - function foo6(x: Array<{ foo: number }>): Array<{ [key: string]: number }> { return x; } - function foo7(x: { [key: string]: number, bar: string }) { (x.bar: string); } - function foo8(x: { [key: string]: number }) { (x.foo: string); - (x.foo: number); } " @@ -938,7 +861,6 @@ var o: { foo: QueryFunction } = { return params.count; } }; - module.exports = o; " `; @@ -952,7 +874,6 @@ o.foo = function (params) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error, number ~/~ string var o = require(\"./test\"); - o.foo = function(params) { return params.count; }; diff --git a/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap b/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap index 1000ce23..1a7513cb 100644 --- a/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap +++ b/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap @@ -224,7 +224,6 @@ export function emitExpression(node: TypedNode) : t.Expression { import * as t from \"./jsAst\"; const b = t.builders; import type {TypedNode} from \"./ast\"; - function getBinaryOp( op: \"plus\" | \"minus\" | \"divide\" | \"multiply\" ): \"+\" | \"-\" | \"*\" | \"/\" { @@ -241,7 +240,6 @@ function getBinaryOp( throw new Error(\"Invalid binary operator: \" + op); } } - export function emitExpression(node: TypedNode): t.Expression { switch (node.exprNodeType) { case \"string_literal\": diff --git a/tests/docblock_flow/__snapshots__/jsfmt.spec.js.snap b/tests/docblock_flow/__snapshots__/jsfmt.spec.js.snap index 72a3f339..205f3c27 100644 --- a/tests/docblock_flow/__snapshots__/jsfmt.spec.js.snap +++ b/tests/docblock_flow/__snapshots__/jsfmt.spec.js.snap @@ -102,7 +102,6 @@ exports[`test use_strict_with_flow.js 1`] = ` /* @flow */ // error \"use strict\"; - (\"\": void); " `; diff --git a/tests/dom/__snapshots__/jsfmt.spec.js.snap b/tests/dom/__snapshots__/jsfmt.spec.js.snap index 0f29690f..8a6c0d46 100644 --- a/tests/dom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dom/__snapshots__/jsfmt.spec.js.snap @@ -44,7 +44,6 @@ let tests = [ let tests = [ function(document: Document) { const event = document.createEvent(\"CustomEvent\"); - event.initCustomEvent(\"butts\", true, false, { nice: 42 }); } ]; @@ -69,11 +68,8 @@ let tests = [ let tests = [ function(document: Document) { (document.createElement(\"canvas\"): HTMLCanvasElement); - (document.createElement(\"link\"): HTMLLinkElement); - (document.createElement(\"option\"): HTMLOptionElement); - (document.createElement(\"select\"): HTMLSelectElement); } ]; @@ -106,21 +102,13 @@ let tests = [ let tests = [ function(element: Element) { element.scrollIntoView(); - element.scrollIntoView(false); - element.scrollIntoView({}); - element.scrollIntoView({ behavior: \"smooth\", block: \"end\" }); - element.scrollIntoView({ block: \"end\" }); - element.scrollIntoView({ behavior: \"smooth\" }); - element.scrollIntoView({ behavior: \"invalid\" }); - element.scrollIntoView({ block: \"invalid\" }); - element.scrollIntoView(1); } ]; @@ -173,21 +161,13 @@ let tests = [ let tests = [ function(element: HTMLElement) { element.scrollIntoView(); - element.scrollIntoView(false); - element.scrollIntoView({}); - element.scrollIntoView({ behavior: \"smooth\", block: \"end\" }); - element.scrollIntoView({ block: \"end\" }); - element.scrollIntoView({ behavior: \"smooth\" }); - element.scrollIntoView({ behavior: \"invalid\" }); - element.scrollIntoView({ block: \"invalid\" }); - element.scrollIntoView(1); } ]; @@ -215,13 +195,9 @@ let tests = [ let tests = [ function(el: HTMLInputElement) { el.setRangeText(\"foo\"); - el.setRangeText(\"foo\", 123); - el.setRangeText(\"foo\", 123, 234); - el.setRangeText(\"foo\", 123, 234, \"select\"); - el.setRangeText(\"foo\", 123, 234, \"bogus\"); } ]; @@ -326,16 +302,12 @@ let listener: EventListener = function(event: Event): void {}; let tests = [ function() { let target = new EventTarget(); - (target.attachEvent(\"foo\", listener): void); - (target.attachEvent && target.attachEvent(\"foo\", listener): void); }, function() { let target = new EventTarget(); - (target.detachEvent(\"foo\", listener): void); - (target.detachEvent && target.detachEvent(\"foo\", listener): void); }, function() { @@ -368,11 +340,8 @@ let tests = [ let tests = [ function() { let path = new Path2D(); - (path.arcTo(0, 0, 0, 0, 10): void); - (path.arcTo(0, 0, 0, 0, 10, 20, 5): void); - (path.arcTo(0, 0, 0, 0, 10, \"20\", 5): void); } ]; @@ -726,12 +695,10 @@ let tests = [ }, function() { document.createNodeIterator(document.body); - document.createNodeIterator({}); }, function() { document.createTreeWalker(document.body); - document.createTreeWalker({}); }, function() { @@ -893,17 +860,13 @@ let tests = [ -1, node => NodeFilter.FILTER_ACCEPT ); - document.createNodeIterator(document.body, -1, node => \"accept\"); - document.createNodeIterator(document.body, -1, { accept: node => NodeFilter.FILTER_ACCEPT }); - document.createNodeIterator(document.body, -1, { accept: node => \"accept\" }); - document.createNodeIterator(document.body, -1, {}); }, function() { @@ -912,15 +875,11 @@ let tests = [ -1, node => NodeFilter.FILTER_ACCEPT ); - document.createTreeWalker(document.body, -1, node => \"accept\"); - document.createTreeWalker(document.body, -1, { accept: node => NodeFilter.FILTER_ACCEPT }); - document.createTreeWalker(document.body, -1, { accept: node => \"accept\" }); - document.createTreeWalker(document.body, -1, {}); } ]; diff --git a/tests/dump-types/__snapshots__/jsfmt.spec.js.snap b/tests/dump-types/__snapshots__/jsfmt.spec.js.snap index 8baf70ee..21ac10bf 100644 --- a/tests/dump-types/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dump-types/__snapshots__/jsfmt.spec.js.snap @@ -7,11 +7,8 @@ module.exports = num; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var num = 42; - function bar() {} - bar(); - module.exports = num; " `; @@ -42,35 +39,25 @@ const idxResult = idx(obj, obj => obj.a.b.c.d); // @flow // test deduping of inferred types var num = require(\"./import\"); - function foo(x) {} - foo(0); - var a: string = num; - function unannotated(x) { return x; } - const nullToUndefined = val => val === null ? undefined : val; - function f0(x: ?Object) { return nullToUndefined(x); } - function f1(x: ?Object) { return nullToUndefined(x); } - function f2(x: ?string) { return nullToUndefined(x); } - function f3(x: ?string) { return nullToUndefined(x); } - declare var idx: $Facebookism$Idx; declare var obj: { a?: { b: ?{ c: null | { d: number } } } }; const idxResult = idx(obj, obj => obj.a.b.c.d); diff --git a/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap b/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap index 8eb108bc..05b08534 100644 --- a/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap +++ b/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap @@ -39,34 +39,26 @@ class C1 { m() {} m() {} } - new C1().m(); - class C2 { get m() { return 42; } m() {} } - new C2().m(); - class C3 { set m(x) {} m() {} } - new C3().m(); - class C4 { get m() { return 42; } set m(x: number) {} } - new C4().m = new C4().m - 42; - class C5 { m() {} get m() { @@ -74,7 +66,6 @@ class C5 { } set m(x: number) {} } - new C5().m = new C5().m - 42; " `; diff --git a/tests/encaps/__snapshots__/jsfmt.spec.js.snap b/tests/encaps/__snapshots__/jsfmt.spec.js.snap index a09e17e1..425186a3 100644 --- a/tests/encaps/__snapshots__/jsfmt.spec.js.snap +++ b/tests/encaps/__snapshots__/jsfmt.spec.js.snap @@ -23,20 +23,15 @@ var s3 = tag2 \`la la la\`; class A {} var a = new A(); var s1 = \`l\${a.x}r\`; - function tag(strings, ...values) { var x: number = strings[0]; return x; } - var s2 = tag\`l\${42}r\`; - function tag2(strings, ...values) { return { foo: \"\" }; } - var s3 = tag2\`la la la\`; - (s3.foo: number); " `; diff --git a/tests/enumerror/__snapshots__/jsfmt.spec.js.snap b/tests/enumerror/__snapshots__/jsfmt.spec.js.snap index 17e60f71..5c22163c 100644 --- a/tests/enumerror/__snapshots__/jsfmt.spec.js.snap +++ b/tests/enumerror/__snapshots__/jsfmt.spec.js.snap @@ -34,24 +34,17 @@ function isActive( ): boolean { return ad.state === \"ACTIVE\"; } - isActive({ state: \"PAUSE\" }); - var MyStates = { PAUSED: \"PAUSED\", ACTIVE: \"ACTIVE\", DELETED: \"DELETED\" }; - function isActive2(ad: { state: $Keys }): boolean { return ad.state === MyStates.ACTIVE; } - isActive2({ state: \"PAUSE\" }); - type Keys = $Keys<{ x: any, y: any }>; type Union = \"x\" | \"y\"; - function keys2union(s: Keys): Union { return s; } - function union2keys(s: Union): Keys { return s; } diff --git a/tests/equals/__snapshots__/jsfmt.spec.js.snap b/tests/equals/__snapshots__/jsfmt.spec.js.snap index dd104c69..8830a42a 100644 --- a/tests/equals/__snapshots__/jsfmt.spec.js.snap +++ b/tests/equals/__snapshots__/jsfmt.spec.js.snap @@ -16,21 +16,13 @@ var x = (null : ?number); // error // error 1 == 1; - \"foo\" == \"bar\"; - 1 == null; - null == 1; - 1 == \"\"; - \"\" == 1; - var x = (null: ?number); - x == 1; - 1 == x; " `; diff --git a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap index 7875553d..1e9ebc18 100644 --- a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap @@ -64,7 +64,6 @@ class Test extends Base { return 2; } } - module.exports = Test; " `; @@ -132,13 +131,9 @@ exports.numberValue5 = 5; * @flow */ exports.numberValue1 = 1; - exports.numberValue2 = 2; - exports.numberValue3 = 3; - exports.numberValue4 = 4; - exports.numberValue5 = 5; " `; @@ -244,7 +239,6 @@ export default class Foo { return 42; } } - new Foo(); " `; @@ -588,13 +582,9 @@ exports.stringValue = \"str\"; * @flow */ exports.numberValue1 = 42; - exports.numberValue2 = 42; - exports.numberValue3 = 42; - exports.numberValue4 = 42; - exports.stringValue = \"str\"; " `; @@ -1100,33 +1090,24 @@ var d2: string = numVal1; import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\"; var e1: number = CJS_Clobb_Lit.numberValue3; var e2: string = CJS_Clobb_Lit.numberValue3; - CJS_Clobb_Lit.doesntExist; - import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\"; var f1: number = CJS_Clobb_Lit_NS.numberValue4; var f2: number = CJS_Clobb_Lit_NS.default.numberValue4; - CJS_Clobb_Lit_NS.default.default; - var f3: string = CJS_Clobb_Lit_NS.numberValue4; var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; import {doesntExist2} from \"CommonJS_Clobbering_Class\"; import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\"; import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\"; - new CJS_Clobb_Class(); - new CJS_Clobb_Class().doesntExist; - var h1: number = CJS_Clobb_Class.staticNumber2(); var h2: string = CJS_Clobb_Class.staticNumber2(); var h3: number = new CJS_Clobb_Class().instNumber1(); var h4: string = new CJS_Clobb_Class().instNumber1(); import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\"; - new CJS_Clobb_Class_NS(); - var i1: number = CJS_Clobb_Class_NS.staticNumber3(); var i2: number = new CJS_Clobb_Class_NS.default().instNumber2(); var i3: string = new CJS_Clobb_Class_NS.default().instNumber2(); @@ -1140,9 +1121,7 @@ var k2: string = numVal3; import * as CJS_Named from \"CommonJS_Named\"; var l1: number = CJS_Named.numberValue1; var l2: string = CJS_Named.numberValue1; - CJS_Named.doesntExist; - import * as CJS_Named_NS from \"CommonJS_Named\"; var m1: number = CJS_Named_NS.numberValue4; var m2: string = CJS_Named_NS.default.numberValue4; @@ -1201,9 +1180,7 @@ var ab2: string = numberValue2_renamed; import {numberValue1 as numberValue5} from \"ES6_ExportAllFrom_Intermediary1\"; var ac1: number = numberValue5; var ac2: string = numberValue5; - require(\"ES6_Default_AnonFunction2\").doesntExist; - var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default; var ad1: number = ES6_Def_AnonFunc2(); var ad2: string = ES6_Def_AnonFunc2(); @@ -1356,48 +1333,27 @@ function testRequires() { // CommonJS module that clobbers module.exports with a frozen object // Error: frozen import * as DefaultA from \"A\"; - DefaultA.numberValue1 = 123; - import * as ES6_Named1 from \"ES6_Named1\"; - ES6_Named1.varDeclNumber1 = 123; - import * as CommonJS_Star from \"CommonJS_Clobbering_Lit\"; - CommonJS_Star.numberValue1 = 123; - CommonJS_Star.default.numberValue1 = 123; - import CommonJS_Clobbering_Lit from \"CommonJS_Clobbering_Lit\"; - CommonJS_Clobbering_Lit.numberValue1 = 123; - import * as CommonJS_Frozen_Star from \"CommonJS_Clobbering_Frozen\"; - CommonJS_Frozen_Star.numberValue1 = 123; - CommonJS_Frozen_Star.default.numberValue1 = 123; - import CommonJS_Clobbering_Frozen from \"CommonJS_Clobbering_Frozen\"; - CommonJS_Clobbering_Frozen.numberValue1 = 123; - function testRequires() { var DefaultA = require(\"A\"); - DefaultA.numberValue1 = 123; - var ES6_Named1 = require(\"ES6_Named1\"); - ES6_Named1.numberValue = 123; - var CommonJS_Star = require(\"CommonJS_Clobbering_Lit\"); - CommonJS_Star.numberValue1 = 123; - var CommonJS_Frozen_Star = require(\"CommonJS_Clobbering_Frozen\"); - CommonJS_Frozen_Star.numberValue1 = 123; } " diff --git a/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap b/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap index acef56d3..1b9d8aa8 100644 --- a/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap +++ b/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap @@ -58,63 +58,36 @@ import {exports as nope} from \"ES\"; // Error: Not an export // Error: Not an export import {num1, str1} from \"CJS_Named\"; import CJS_Named from \"CJS_Named\"; - (num1: number); - (num1: string); - (str1: string); - (str1: number); - (CJS_Named: { num1: number, str1: string }); - (CJS_Named: number); - import {num2} from \"CJS_Clobbered\"; import {numExport} from \"CJS_Clobbered\"; - (numExport: number); - (numExport: string); - import type {numType} from \"CJS_Clobbered\"; - (42: numType); - (\"asdf\": numType); - import {strHidden} from \"ES\"; import {str3} from \"ES\"; - (str3: string); - (str3: number); - import {num3} from \"ES\"; - (num3: number); - (num3: string); - import {C} from \"ES\"; import type {C as CType} from \"ES\"; - (new C(): C); - (42: C); - (new C(): CType); - (42: CType); - import {T} from \"ES\"; import type {T as T2} from \"ES\"; - (42: T2); - (\"asdf\": T2); - import {exports as nope} from \"ES\"; " `; diff --git a/tests/export_default/__snapshots__/jsfmt.spec.js.snap b/tests/export_default/__snapshots__/jsfmt.spec.js.snap index 7fb847c6..2ca98135 100644 --- a/tests/export_default/__snapshots__/jsfmt.spec.js.snap +++ b/tests/export_default/__snapshots__/jsfmt.spec.js.snap @@ -18,15 +18,10 @@ N.z = Q(N.z); // declaration of Q redirects to module M var M = require(\"M\"); var N = require(\"N\"); - N.x = M(N.x); - var P = require(\"./P\"); - N.y = P(N.y); - var Q = require(\"Q\"); - N.z = Q(N.z); " `; diff --git a/tests/export_type/__snapshots__/jsfmt.spec.js.snap b/tests/export_type/__snapshots__/jsfmt.spec.js.snap index cee975ea..839a4136 100644 --- a/tests/export_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/export_type/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,6 @@ module.exports = {} /* @flow */ export type talias4 = number; export interface IFoo { prop: number } - module.exports = {}; " `; diff --git a/tests/extensions/__snapshots__/jsfmt.spec.js.snap b/tests/extensions/__snapshots__/jsfmt.spec.js.snap index 74ca1755..524d171e 100644 --- a/tests/extensions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/extensions/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test foo.js 1`] = ` imp(1337); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var imp = require(\"./bar\"); - imp(1337); " `; diff --git a/tests/facebook_fbt_none/__snapshots__/jsfmt.spec.js.snap b/tests/facebook_fbt_none/__snapshots__/jsfmt.spec.js.snap index 7259d28d..8b22529f 100644 --- a/tests/facebook_fbt_none/__snapshots__/jsfmt.spec.js.snap +++ b/tests/facebook_fbt_none/__snapshots__/jsfmt.spec.js.snap @@ -7,9 +7,7 @@ var React = require(\'react\'); // @flow // Error: ReactElement ~> number var React = require(\"react\"); - (: React.Element<*>); - (: number); " `; diff --git a/tests/facebook_fbt_some/__snapshots__/jsfmt.spec.js.snap b/tests/facebook_fbt_some/__snapshots__/jsfmt.spec.js.snap index 6986e7b2..01fa23f9 100644 --- a/tests/facebook_fbt_some/__snapshots__/jsfmt.spec.js.snap +++ b/tests/facebook_fbt_some/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,6 @@ exports[`test main.js 1`] = ` // @flow // Error (the libdef in this test marks fbt as number) (: number); - (: string); " `; diff --git a/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap b/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap index 6bbe6737..c918f25f 100644 --- a/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap +++ b/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test Bar.js 1`] = ` module.exports = Bar; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var Bar = { x: 0 }; - module.exports = Bar; " `; @@ -63,9 +62,7 @@ let tests = [ }, function(copyProperties: Object$Assign) { let result = {}; - result.baz = false; - (copyProperties(result, { foo: \"a\" }, { bar: 123 }): { foo: string, bar: number, baz: boolean }); @@ -74,17 +71,14 @@ let tests = [ const copyProperties = require(\"copyProperties\"); let x = { foo: \"a\" }; let y = { bar: 123 }; - (copyProperties({}, x, y): { foo: string, bar: number }); }, function(copyProperties: Object$Assign) { copyProperties(); - (copyProperties({ foo: \"a\" }): { foo: number }); }, function(copyProperties: Object$Assign) { function x(cb: Function) {} - x(copyProperties); } ]; @@ -112,14 +106,11 @@ let tests = [ let tests = [ function() { let x: ?string = null; - invariant(x, \"truthy only\"); }, function(invariant: Function) { let x: ?string = null; - invariant(x); - (x: string); } ]; @@ -200,17 +191,13 @@ let tests = [ }, function(mergeInto: $Facebookism$MergeInto) { let result = {}; - result.baz = false; - (mergeInto(result, { foo: \"a\" }, { bar: 123 }): void); - (result: { foo: string, bar: number, baz: boolean }); }, function() { const mergeInto = require(\"mergeInto\"); let result: { foo?: string, bar?: number, baz: boolean } = { baz: false }; - (mergeInto(result, { foo: \"a\" }, { bar: 123 }): void); }, function(mergeInto: $Facebookism$MergeInto) { @@ -218,7 +205,6 @@ let tests = [ }, function(mergeInto: $Facebookism$MergeInto) { function x(cb: Function) {} - x(mergeInto); } ]; @@ -241,7 +227,6 @@ var mixin = require(\"mixin\"); class Foo extends mixin(Bar) { m() { var x: string = this.x; - this.y = \"\"; } } diff --git a/tests/fetch/__snapshots__/jsfmt.spec.js.snap b/tests/fetch/__snapshots__/jsfmt.spec.js.snap index bef18507..162ff450 100644 --- a/tests/fetch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/fetch/__snapshots__/jsfmt.spec.js.snap @@ -98,31 +98,21 @@ const b = new Headers([ \"Content-Type\", \"image/jpeg\" ]); const c = new Headers({ \"Content-Type\", \"image/jpeg\" }); const d = new Headers(c); const e: Headers = new Headers(); - e.append(\"Content-Type\", \"image/jpeg\"); - e.append(\"Content-Type\"); - e.append({ \"Content-Type\", \"image/jpeg\" }); - e.set(\"Content-Type\", \"image/jpeg\"); - e.set(\"Content-Type\"); - e.set({ \"Content-Type\", \"image/jpeg\" }); - const f: Headers = e.append(\"Content-Type\", \"image/jpeg\"); const g: string = e.get(\"Content-Type\"); const h: number = e.get(\"Content-Type\"); - for (let v of e) { const [ i, j ]: [string, string] = v; } - for (let v of e.entries()) { const [ i, j ]: [string, string] = v; } - e.getAll(\"content-type\").forEach((v: string) => {}); " `; @@ -229,13 +219,9 @@ const k: Request = new Request(\"http://example.org\", { cache: \"default\" }); var l: boolean = h.bodyUsed; - h.text().then((t: string) => t); - h.text().then((t: Buffer) => t); - h.arrayBuffer().then((ab: ArrayBuffer) => ab); - h.arrayBuffer().then((ab: Buffer) => ab); " `; @@ -325,13 +311,9 @@ const i: Response = new Response({ }); const ok: boolean = h.ok; const status: number = h.status; - h.text().then((t: string) => t); - h.text().then((t: Buffer) => t); - h.arrayBuffer().then((ab: ArrayBuffer) => ab); - h.arrayBuffer().then((ab: Buffer) => ab); " `; @@ -389,31 +371,21 @@ const b = new URLSearchParams([ \"key1\", \"value1\" ]); const c = new URLSearchParams({ \"key1\", \"value1\" }); const d = new URLSearchParams(c); const e: URLSearchParams = new URLSearchParams(); - e.append(\"key1\", \"value1\"); - e.append(\"key1\"); - e.append({ \"key1\", \"value1\" }); - e.set(\"key1\", \"value1\"); - e.set(\"key1\"); - e.set({ \"key1\", \"value1\" }); - const f: URLSearchParams = e.append(\"key1\", \"value1\"); const g: string = e.get(\"key1\"); const h: number = e.get(\"key1\"); - for (let v of e) { const [ i, j ]: [string, string] = v; } - for (let v of e.entries()) { const [ i, j ]: [string, string] = v; } - e.getAll(\"key1\").forEach((v: string) => {}); " `; diff --git a/tests/find-module/__snapshots__/jsfmt.spec.js.snap b/tests/find-module/__snapshots__/jsfmt.spec.js.snap index 8a762fae..3a5cd026 100644 --- a/tests/find-module/__snapshots__/jsfmt.spec.js.snap +++ b/tests/find-module/__snapshots__/jsfmt.spec.js.snap @@ -12,9 +12,7 @@ exports[`test test.js 1`] = ` import x from \'./req\'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"./req\"); - (x: string); - import x from \"./req\"; " `; diff --git a/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap b/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap index e1b5fa3e..f04e7e95 100644 --- a/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap +++ b/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap @@ -34,15 +34,12 @@ module.exports = {fn: fix}; function eq(x: number, y: number) { return true; } - function sub(x: number, y: number) { return 0; } - function mul(x: number, y: number) { return 0; } - function fix(fold) { var delta = function(delta) { return fold(function(x) { @@ -52,23 +49,18 @@ function fix(fold) { }; return delta(delta); } - function mk_factorial() { return fix(function(factorial) { return function(n) { if (eq(n, 1)) { return 1; } - return mul(factorial(sub(n, 1)), n); }; }); } - var factorial = mk_factorial(); - factorial(\"...\"); - module.exports = { fn: fix }; " `; @@ -101,30 +93,22 @@ function Y(f) { function g(x) { return f(x(x)); } - g(g); } - function func1(f) { function fix_f(x: number): number { return f(x); } - return fix_f; } - function func2(f) { function fix_f(x: string): string { return f(x); } - return fix_f; } - Y(func1); - Y(func2); - module.exports = Y; " `; diff --git a/tests/for/__snapshots__/jsfmt.spec.js.snap b/tests/for/__snapshots__/jsfmt.spec.js.snap index 6475c32b..4fa368cb 100644 --- a/tests/for/__snapshots__/jsfmt.spec.js.snap +++ b/tests/for/__snapshots__/jsfmt.spec.js.snap @@ -50,38 +50,28 @@ function corge(x: boolean) { /* @flow */ function foo(x: boolean) { var max = 10; - for (var ii = 0; ii < max; ii++) { if (x) { continue; } - return; } - console.log(\"this is still reachable\"); } - function bar(x: boolean) { var max = 0; - for (var ii = 0; ii < max; ii++) { return; } - console.log(\"this is still reachable\"); } - function baz(x: boolean) { var max = 0; - for (var ii = 0; ii < max; ii++) { continue; } - console.log(\"this is still reachable\"); } - function bliffl(x: boolean) { var max = 10; loop1: @@ -90,20 +80,15 @@ function bliffl(x: boolean) { for (var jj = 0; jj < max; jj++) { break loop1; } - console.log(\"this is still reachable\"); } - console.log(\"this is still reachable\"); } - function corge(x: boolean) { var max = 0; - for (var ii = 0; ii < max; ii++) { break; } - console.log(\"this is still reachable\"); } " @@ -155,34 +140,26 @@ function corge(x: boolean) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo(x: boolean) { var obj = { a: 1, b: 2 }; - for (var prop in obj) { if (x) { continue; } - return; } - console.log(\"this is still reachable\"); } - function bar(x: boolean) { for (var prop in {}) { return; } - console.log(\"this is still reachable\"); } - function baz(x: boolean) { for (var prop in {}) { continue; } - console.log(\"this is still reachable\"); } - function bliffl(x: boolean) { var obj = { a: 1, b: 2 }; loop1: @@ -191,18 +168,14 @@ function bliffl(x: boolean) { for (var prop2 in obj) { break loop1; } - console.log(\"this is still reachable\"); } - console.log(\"this is still reachable\"); } - function corge(x: boolean) { for (var prop in {}) { break; } - console.log(\"this is still reachable\"); } " @@ -254,34 +227,26 @@ function corge(x: boolean) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo(x: boolean) { var arr = [ 1, 2, 3 ]; - for (var elem of arr) { if (x) { continue; } - return; } - console.log(\"this is still reachable\"); } - function bar(x: boolean) { for (var elem of []) { return; } - console.log(\"this is still reachable\"); } - function baz(x: boolean) { for (var elem of []) { continue; } - console.log(\"this is still reachable\"); } - function bliffl(x: boolean) { var arr = [ 1, 2, 3 ]; loop1: @@ -290,18 +255,14 @@ function bliffl(x: boolean) { for (var elem of arr) { break loop1; } - console.log(\"this is still reachable\"); } - console.log(\"this is still reachable\"); } - function corge(x: boolean) { for (var elem of []) { break; } - console.log(\"this is still reachable\"); } " diff --git a/tests/forof/__snapshots__/jsfmt.spec.js.snap b/tests/forof/__snapshots__/jsfmt.spec.js.snap index ef70b0ae..0652bf64 100644 --- a/tests/forof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/forof/__snapshots__/jsfmt.spec.js.snap @@ -69,47 +69,38 @@ function testArray(arr: Array): void { (x: string); } } - function testIterable1(iterable: Iterable): void { for (var x of iterable) { (x: string); } } - function testIterable2(iterable: Iterable<*>): void { for (var x of iterable) { (x: string); } } - function testString(str: string): void { for (var x of str) { (x: number); } } - function testMap1(map: Map): void { for (var elem of map) { (elem: [string, number]); - (elem: number); } } - function testMap2(map: Map<*, *>): void { for (var elem of map) { (elem: [number, string]); - (elem: number); } } - function testSet1(set: Set): void { for (var x of set) { (x: number); } } - function testSet2(set: Set<*>): void { for (var x of set) { (x: number); diff --git a/tests/function/__snapshots__/jsfmt.spec.js.snap b/tests/function/__snapshots__/jsfmt.spec.js.snap index ff8bdb28..0b2326b9 100644 --- a/tests/function/__snapshots__/jsfmt.spec.js.snap +++ b/tests/function/__snapshots__/jsfmt.spec.js.snap @@ -69,39 +69,24 @@ function test2(): number { return 0; } function test(a: string, b: number): number { return this.length; } - test.apply(\"\", [ \"\", 0 ]); - test.apply(0, [ \"\", 0 ]); - test.apply(\"\", [ \"\" ]); - test.apply(\"\", [ \"\", \"\" ]); - test.apply(\"\", [ 0, 0 ]); - function f(args) { test.apply(\"\", args); } - f([ \"\", 0 ]); - f([ \"\", \"\" ]); - f([ 0, 0 ]); - test.apply(\"\", \"not array\"); - (test.call.apply(test, [ 0, 123, \"foo\" ]): void); - (test.bind.apply(test, [ 0, 123 ]): (b: number) => number); - function test2(): number { return 0; } - (test2.apply(): number); - (test2.apply(\"\"): number); " `; @@ -123,9 +108,7 @@ let tests = [ let tests = [ function(x: (a: string, b: string) => void) { let y = x.bind(x, \"foo\"); - y(\"bar\"); - y(123); } ]; @@ -191,35 +174,22 @@ function test2(): number { return 0; } function test(a: string, b: number): number { return this.length; } - test.call(\"\", \"\", 0); - test.call(0, \"\", 0); - test.call(\"\", \"\"); - test.call(\"\", \"\", \"\"); - test.call(\"\", 0, 0); - function f(args) { test.call(\"\", args[0], args[1]); } - f([ \"\", 0 ]); - f([ \"\", \"\" ]); - f([ 0, 0 ]); - (test.apply.call(test, 0, [ 0, \"foo\" ]): number); - function test2(): number { return 0; } - (test2.call(): number); - (test2.call(\"\"): number); " `; @@ -322,74 +292,47 @@ var b: Function = function(a: number, b: number): number { }; class C {} var c: Function = C; - function good(x: Function, MyThing: Function): number { var o: Object = x; - x.foo = 123; - x[\"foo\"] = 456; - x(); - ; - var { ...something } = x; - Object.assign(x, { hi: \"there\" }); - Object.keys(x); - return x.bar + x[\"bar\"] + x.lala(); } - function bad(x: Function, y: Object): void { var a: number = x; var b: string = x; var c: Function = y; } - let tests = [ function(y: () => void, z: Function) { function x() {} - (x.length: void); - (y.length: void); - (z.length: void); - (x.name: void); - (y.name: void); - (z.name: void); }, function(y: () => void, z: Function) { function x() {} - x.length = \"foo\"; - y.length = \"foo\"; - z.length = \"foo\"; - x.name = 123; - y.name = 123; - z.name = 123; - (z.foo: number); - (z.foo: string); } ]; var d: Function = () => 1; var e = (d.bind(1): Function)(); - (e: number); - (e: string); " `; @@ -421,15 +364,12 @@ function rest_t>(...xs: T): U { function rest_array(...xs: Array): T { return xs[0]; } - function rest_tuple(...xs: [T]): T { return xs[0]; } - function rest_any(...xs: any): any { return xs[0]; } - function rest_t>(...xs: T): U { return xs[0]; } diff --git a/tests/funrec/__snapshots__/jsfmt.spec.js.snap b/tests/funrec/__snapshots__/jsfmt.spec.js.snap index 1399f943..575d958b 100644 --- a/tests/funrec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/funrec/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,6 @@ function foo() { function bar(x) { return x; } - function foo() { return function bound() { return bar(bound); diff --git a/tests/generators/__snapshots__/jsfmt.spec.js.snap b/tests/generators/__snapshots__/jsfmt.spec.js.snap index 3e7a5823..da258ffe 100644 --- a/tests/generators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/generators/__snapshots__/jsfmt.spec.js.snap @@ -151,18 +151,14 @@ for (var x of examples.delegate_yield_iterable([])) { class GeneratorExamples { *stmt_yield(): Generator { yield 0; - yield \"\"; } *stmt_next(): Generator { var a = yield; - if (a) { (a: number); } - var b = yield; - if (b) { (b: string); } @@ -179,7 +175,6 @@ class GeneratorExamples { } *widen_next() { var x = yield 0; - if (typeof x === \"number\") {} else if (typeof x === \"boolean\") {} else { @@ -188,30 +183,25 @@ class GeneratorExamples { } *widen_yield() { yield 0; - yield \"\"; - yield true; } *delegate_next_generator() { function* inner() { var x: number = yield; } - yield* inner(); } *delegate_yield_generator() { function* inner() { yield \"\"; } - yield* inner(); } *delegate_return_generator() { function* inner() { return \"\"; } - var x: number = yield* inner(); } *delegate_next_iterable(xs: Array) { @@ -234,25 +224,18 @@ class GeneratorExamples { } } var examples = new GeneratorExamples(); - for (var x of examples.infer_stmt()) { (x: string); } - var infer_stmt_next = examples.infer_stmt().next(0).value; - if (typeof infer_stmt_next === \"undefined\") {} else if (typeof infer_stmt_next === \"number\") {} else { (infer_stmt_next: boolean); } - examples.widen_next().next(0); - examples.widen_next().next(\"\"); - examples.widen_next().next(true); - for (var x of examples.widen_yield()) { if (typeof x === \"number\") {} else if (typeof x === \"boolean\") {} @@ -260,15 +243,11 @@ for (var x of examples.widen_yield()) { (x: string); } } - examples.delegate_next_generator().next(\"\"); - for (var x of examples.delegate_yield_generator()) { (x: number); } - examples.delegate_next_iterable([]).next(\"\"); - for (var x of examples.delegate_yield_iterable([])) { (x: string); } @@ -309,13 +288,10 @@ class GeneratorExamples { } } var examples = new GeneratorExamples(); - for (var x of examples.infer_stmt()) { (x: string); } - var infer_stmt_next = examples.infer_stmt().next(0).value; - if (typeof infer_stmt_next === \"undefined\") {} else if (typeof infer_stmt_next === \"number\") {} else { @@ -476,73 +452,53 @@ if (multiple_return_result.done) { // error: number|string ~> void function* stmt_yield(): Generator { yield 0; - yield \"\"; } - function* stmt_next(): Generator { var a = yield; - if (a) { (a: number); } - var b = yield; - if (b) { (b: string); } } - function* stmt_return_ok(): Generator { return 0; } - function* stmt_return_err(): Generator { return \"\"; } - function* infer_stmt() { var x: boolean = yield 0; return \"\"; } - for (var x of infer_stmt()) { (x: string); } - var infer_stmt_next = infer_stmt().next(0).value; - if (typeof infer_stmt_next === \"undefined\") {} else if (typeof infer_stmt_next === \"number\") {} else { (infer_stmt_next: boolean); } - function* widen_next() { var x = yield 0; - if (typeof x === \"number\") {} else if (typeof x === \"boolean\") {} else { (x: string); } } - widen_next().next(0); - widen_next().next(\"\"); - widen_next().next(true); - function* widen_yield() { yield 0; - yield \"\"; - yield true; } - for (var x of widen_yield()) { if (typeof x === \"number\") {} else if (typeof x === \"boolean\") {} @@ -550,67 +506,50 @@ for (var x of widen_yield()) { (x: string); } } - function* delegate_next_generator() { function* inner() { var x: number = yield; } - yield* inner(); } - delegate_next_generator().next(\"\"); - function* delegate_yield_generator() { function* inner() { yield \"\"; } - yield* inner(); } - for (var x of delegate_yield_generator()) { (x: number); } - function* delegate_return_generator() { function* inner() { return \"\"; } - var x: number = yield* inner(); } - function* delegate_next_iterable(xs: Array) { yield* xs; } - delegate_next_iterable([]).next(\"\"); - function* delegate_yield_iterable(xs: Array) { yield* xs; } - for (var x of delegate_yield_iterable([])) { (x: string); } - function* delegate_return_iterable(xs: Array) { var x: void = yield* xs; } - function* generic_yield(y: Y): Generator { yield y; } - function* generic_return(r: R): Generator { return r; } - function* generic_next(): Generator { return yield undefined; } - function* multiple_return(b) { if (b) { return 0; @@ -618,9 +557,7 @@ function* multiple_return(b) { return \"foo\"; } } - let multiple_return_result = multiple_return().next(); - if (multiple_return_result.done) { (multiple_return_result.value: void); } @@ -658,10 +595,8 @@ if (refuse_return_result.done) { // error: number | void ~> string function test1(gen: Generator) { var ret = gen.return(0); - (ret.value: void); } - function* refuse_return() { try { yield 1; @@ -669,10 +604,8 @@ function* refuse_return() { return 0; } } - var refuse_return_gen = refuse_return(); var refuse_return_result = refuse_return_gen.return(\"string\"); - if (refuse_return_result.done) { (refuse_return_result.value: string); } @@ -715,25 +648,19 @@ function* catch_return() { return e; } } - var catch_return_value = catch_return().throw(\"\").value; - if (catch_return_value !== undefined) { (catch_return_value: string); } - function* yield_return() { try { yield 0; - return; } catch (e) { yield e; } } - var yield_return_value = yield_return().throw(\"\").value; - if (yield_return_value !== undefined) { (yield_return_value: string); } diff --git a/tests/generics/__snapshots__/jsfmt.spec.js.snap b/tests/generics/__snapshots__/jsfmt.spec.js.snap index b9e80fcd..d9d39010 100644 --- a/tests/generics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/generics/__snapshots__/jsfmt.spec.js.snap @@ -63,9 +63,7 @@ class D { x: T; m(z: S, u: T, v): S { this.x = u; - v.u = u; - return z; } } @@ -77,7 +75,6 @@ var n: number = o.u; class E extends C { set(x: X): X { this.x = x; - return this.get(); } } @@ -92,9 +89,7 @@ class H extends G> { } } var h1 = new H(); - h1.foo([ \"...\" ]); - var h2: F>>> = h1; var obj: Object = {}; var fn: Function = function() { diff --git a/tests/geolocation/__snapshots__/jsfmt.spec.js.snap b/tests/geolocation/__snapshots__/jsfmt.spec.js.snap index 2be6e37c..aec7076c 100644 --- a/tests/geolocation/__snapshots__/jsfmt.spec.js.snap +++ b/tests/geolocation/__snapshots__/jsfmt.spec.js.snap @@ -38,7 +38,6 @@ var id = geolocation.watchPosition( } } ); - geolocation.clearWatch(id); " `; diff --git a/tests/get-def/__snapshots__/jsfmt.spec.js.snap b/tests/get-def/__snapshots__/jsfmt.spec.js.snap index 7adcec9d..77a9b62c 100644 --- a/tests/get-def/__snapshots__/jsfmt.spec.js.snap +++ b/tests/get-def/__snapshots__/jsfmt.spec.js.snap @@ -19,15 +19,11 @@ lib.bar(); // t123456 // D123456 var lib = require(\"./library\"); - function add(a: number, b: number): number { return a + b; } - var re = /^keynote (talk){2} (lightning){3,5} (talk){2} closing partytime!!!/; - add(lib.iTakeAString(42), 7); - lib.bar(); " `; @@ -47,17 +43,11 @@ things; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import thing from \"./helpers/exports_default.js\"; - thing; - import {foo, bar as baz} from \"./helpers/exports_named.js\"; - foo; - baz; - import * as things from \"./helpers/exports_named.js\"; - things; " `; diff --git a/tests/get-def2/__snapshots__/jsfmt.spec.js.snap b/tests/get-def2/__snapshots__/jsfmt.spec.js.snap index 8cdeb84a..6f0c1417 100644 --- a/tests/get-def2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/get-def2/__snapshots__/jsfmt.spec.js.snap @@ -6,7 +6,6 @@ module.exports = {ParentFoo}; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var ParentFoo = { foo: \"bar\" }; - module.exports = { ParentFoo }; " `; @@ -46,25 +45,15 @@ import type {Foo} from \'./types\'; // Follows non-destructured property access of \`require(\'Parent\')\` var Parent = require(\"./Parent\"); let ParentFoo; - ({ ParentFoo } = Parent); - ParentFoo; - let ParentFoo2; - ParentFoo2 = Parent; - ParentFoo2; - let ParentFoo3 = Parent; - ParentFoo3; - let foo = require(\"./Parent\").ParentFoo.foo; - foo; - import type {Foo} from \"./types\"; " `; @@ -116,9 +105,7 @@ class C extends React.Component { props: { x: string }; } let msg = \"hello\"; - ; -
; " `; diff --git a/tests/get-imports-and-importers/__snapshots__/jsfmt.spec.js.snap b/tests/get-imports-and-importers/__snapshots__/jsfmt.spec.js.snap index d74194a8..2a1fec9b 100644 --- a/tests/get-imports-and-importers/__snapshots__/jsfmt.spec.js.snap +++ b/tests/get-imports-and-importers/__snapshots__/jsfmt.spec.js.snap @@ -28,7 +28,6 @@ require(\'b\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow require(\"./a.js\"); - require(\"b\"); " `; diff --git a/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap b/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap index 94def9a4..a2aad7e4 100644 --- a/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap +++ b/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap @@ -113,18 +113,12 @@ var testGetterNoError1: number = foo.goodGetterNoAnnotation; var testGetterNoError2: number = foo.goodGetterWithAnnotation; var testGetterWithError1: string = foo.goodGetterNoAnnotation; var testGetterWithError2: string = foo.goodGetterWithAnnotation; - foo.goodSetterNoAnnotation = 123; - foo.goodSetterWithAnnotation = 123; - foo.goodSetterNoAnnotation = \"hello\"; - foo.goodSetterWithAnnotation = \"hello\"; - var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter; var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter; - foo.propOverriddenWithSetter = 123; " `; @@ -252,19 +246,12 @@ var testGetterNoError1: number = obj.goodGetterNoAnnotation; var testGetterNoError2: number = obj.goodGetterWithAnnotation; var testGetterWithError1: string = obj.goodGetterNoAnnotation; var testGetterWithError2: string = obj.goodGetterWithAnnotation; - obj.goodSetterNoAnnotation = 123; - obj.goodSetterWithAnnotation = 123; - obj.goodSetterNoAnnotation = \"hello\"; - obj.goodSetterWithAnnotation = \"hello\"; - var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter; - obj.exampleOfOrderOfGetterAndSetter = new C(); - var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered; " `; @@ -405,52 +392,42 @@ class Base { this.x = value; } } - (class extends Base { get x(): B { return b; } }); - (class extends Base { set x(value: B): void {} }); - (class extends Base { get x(): C { return c; } set x(value: A): void {} }); - (class extends Base { set pos(value: B): void {} }); - (class extends Base { get pos(): C { return c; } }); - (class extends Base { get neg(): B { return b; } }); - (class extends Base { set neg(value: A): void {} }); - (class extends Base { get: C; }); - (class extends Base { set: A; }); - (class extends Base { getset: B; }); diff --git a/tests/ignore_package/__snapshots__/jsfmt.spec.js.snap b/tests/ignore_package/__snapshots__/jsfmt.spec.js.snap index a4577d6f..de3a76b7 100644 --- a/tests/ignore_package/__snapshots__/jsfmt.spec.js.snap +++ b/tests/ignore_package/__snapshots__/jsfmt.spec.js.snap @@ -22,11 +22,9 @@ module.exports = foo; \'Required module not found\'. */ var _ = require(\"underscore\"); - function foo(): string { return _.foo(); } - module.exports = foo; " `; diff --git a/tests/immutable_methods/__snapshots__/jsfmt.spec.js.snap b/tests/immutable_methods/__snapshots__/jsfmt.spec.js.snap index c51f2ab8..c2bc11be 100644 --- a/tests/immutable_methods/__snapshots__/jsfmt.spec.js.snap +++ b/tests/immutable_methods/__snapshots__/jsfmt.spec.js.snap @@ -21,7 +21,6 @@ class B extends A { } class C extends A {} var a: A = new B(); - a.foo = function(): C { return new C(); }; diff --git a/tests/import_type/__snapshots__/jsfmt.spec.js.snap b/tests/import_type/__snapshots__/jsfmt.spec.js.snap index 3f7f37df..cd09a084 100644 --- a/tests/import_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import_type/__snapshots__/jsfmt.spec.js.snap @@ -23,7 +23,6 @@ class ClassFoo3 { return new ClassFoo3(); } } - module.exports = ClassFoo3; " `; @@ -61,21 +60,15 @@ class ClassFoo4 { } } class ClassFoo5 {} - function givesAFoo4(): ClassFoo4 { return new ClassFoo4(); } - function givesAFoo5(): ClassFoo5 { return new ClassFoo5(); } - exports.ClassFoo4 = ClassFoo4; - exports.ClassFoo5 = ClassFoo5; - exports.foo4Inst = new ClassFoo4(); - exports.foo5Inst = new ClassFoo5(); " `; @@ -301,29 +294,21 @@ import type ClassFoo1 from \"./ExportDefault_Class\"; import {foo1Inst} from \"./ExportDefault_Class\"; var a1: ClassFoo1 = foo1Inst; var a2: number = foo1Inst; - new ClassFoo1(); - import type {ClassFoo2} from \"./ExportNamed_Class\"; import {foo2Inst} from \"./ExportNamed_Class\"; var b1: ClassFoo2 = foo2Inst; var b2: number = foo2Inst; - new ClassFoo2(); - import type ClassFoo3T from \"./ExportCJSDefault_Class\"; import ClassFoo3 from \"./ExportCJSDefault_Class\"; var c1: ClassFoo3T = new ClassFoo3(); - new ClassFoo3T(); - import type {ClassFoo4, ClassFoo5} from \"./ExportCJSNamed_Class\"; import {foo4Inst, foo5Inst} from \"./ExportCJSNamed_Class\"; var d1: ClassFoo4 = foo4Inst; var d2: number = foo4Inst; - new ClassFoo4(); - var d3: typeof ClassFoo5 = foo5Inst; import type {AliasFoo3} from \"./ExportNamed_Alias\"; import {givesAFoo3Obj} from \"./ExportNamed_Alias\"; @@ -332,7 +317,6 @@ var e2: number = givesAFoo3Obj(); var e3: typeof AliasFoo3 = givesAFoo3Obj(); import type {numValue} from \"./ExportsANumber\"; import type ClassFoo6 from \"./issue-359\"; - function foo() { ClassFoo6; } diff --git a/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap b/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap index 6ca9d03b..f38d2cdf 100644 --- a/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap @@ -23,7 +23,6 @@ class ClassFoo3 { return new ClassFoo3(); } } - module.exports = ClassFoo3; " `; @@ -51,7 +50,6 @@ exports.ClassFoo4 = ClassFoo4; * @flow */ class ClassFoo4 {} - exports.ClassFoo4 = ClassFoo4; " `; @@ -332,16 +330,12 @@ import typeof ClassFoo1T from \"./ExportDefault_Class\"; import ClassFoo1 from \"./ExportDefault_Class\"; var a1: ClassFoo1T = ClassFoo1; var a2: ClassFoo1T = new ClassFoo1(); - new ClassFoo1T(); - import typeof {ClassFoo2 as ClassFoo2T} from \"./ExportNamed_Class\"; import {ClassFoo2} from \"./ExportNamed_Class\"; var b1: ClassFoo2T = ClassFoo2; var b2: ClassFoo2T = new ClassFoo2(); - new ClassFoo2T(); - import typeof ClassFoo3T from \"./ExportCJSDefault_Class\"; import ClassFoo3 from \"./ExportCJSDefault_Class\"; var c1: ClassFoo3T = ClassFoo3; diff --git a/tests/incremental_basic/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_basic/__snapshots__/jsfmt.spec.js.snap index 8856a065..a0eb1b11 100644 --- a/tests/incremental_basic/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_basic/__snapshots__/jsfmt.spec.js.snap @@ -5,7 +5,6 @@ module.exports = a; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var a: string = 0; - module.exports = a; " `; @@ -19,7 +18,6 @@ module.exports = b; // @flow var a = require(\"./a\"); var b: number = a; - module.exports = b; " `; @@ -33,7 +31,6 @@ module.exports = c; // @flow var b = require(\"./b\"); var c: string = b; - module.exports = c; " `; diff --git a/tests/incremental_basic/tmp1/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_basic/tmp1/__snapshots__/jsfmt.spec.js.snap index b7674dd7..11d82fe8 100644 --- a/tests/incremental_basic/tmp1/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_basic/tmp1/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,6 @@ module.exports = b; // @flow var a = require(\"./a\"); var b = a; - module.exports = b; " `; diff --git a/tests/incremental_basic/tmp2/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_basic/tmp2/__snapshots__/jsfmt.spec.js.snap index 8ad3c26a..5e716253 100644 --- a/tests/incremental_basic/tmp2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_basic/tmp2/__snapshots__/jsfmt.spec.js.snap @@ -5,7 +5,6 @@ module.exports = a; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var a = 0; - module.exports = a; " `; diff --git a/tests/incremental_basic/tmp3/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_basic/tmp3/__snapshots__/jsfmt.spec.js.snap index 7dc23dfc..b56a5d3b 100644 --- a/tests/incremental_basic/tmp3/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_basic/tmp3/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,6 @@ module.exports = b; // @flow var a = require(\"./a\"); var b: number = a; - module.exports = b; " `; diff --git a/tests/incremental_cycle/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_cycle/__snapshots__/jsfmt.spec.js.snap index bde85b2e..47f24548 100644 --- a/tests/incremental_cycle/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_cycle/__snapshots__/jsfmt.spec.js.snap @@ -13,7 +13,6 @@ class A { b: number; c: string; } - module.exports = A; " `; @@ -35,7 +34,6 @@ import type C from \"./C\"; class B extends A { c: C; } - module.exports = B; " `; @@ -57,7 +55,6 @@ import type B from \"./B\"; class C extends A { b: B; } - module.exports = C; " `; diff --git a/tests/incremental_cycle/tmp1/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_cycle/tmp1/__snapshots__/jsfmt.spec.js.snap index 4f33f2e6..17dfcbbb 100644 --- a/tests/incremental_cycle/tmp1/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_cycle/tmp1/__snapshots__/jsfmt.spec.js.snap @@ -29,7 +29,6 @@ import type {B} from \"./B\"; class C extends A { b: B; } - module.exports = C; " `; diff --git a/tests/incremental_delete/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_delete/__snapshots__/jsfmt.spec.js.snap index 3f9e10d8..85093731 100644 --- a/tests/incremental_delete/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_delete/__snapshots__/jsfmt.spec.js.snap @@ -5,7 +5,6 @@ module.exports = a; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var a: string = 0; - module.exports = a; " `; @@ -19,7 +18,6 @@ module.exports = b; // @flow var a = require(\"./a\"); var b: number = a; - module.exports = b; " `; @@ -33,7 +31,6 @@ module.exports = c; // @flow var b = require(\"./b\"); var c: string = b; - module.exports = c; " `; diff --git a/tests/incremental_mixed_naming_cycle/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_mixed_naming_cycle/__snapshots__/jsfmt.spec.js.snap index dece80a4..3d5a61e0 100644 --- a/tests/incremental_mixed_naming_cycle/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_mixed_naming_cycle/__snapshots__/jsfmt.spec.js.snap @@ -14,9 +14,7 @@ module.exports = \'A\'; * @flow */ (require(\"./b\"): void); - (require(\"C\"): void); - module.exports = \"A\"; " `; @@ -37,9 +35,7 @@ module.exports = \'B\'; * @flow */ (require(\"A\"): void); - (require(\"D\"): void); - module.exports = \"B\"; " `; @@ -60,9 +56,7 @@ module.exports = \'C\'; * @flow */ require(\"Root\"); - (require(\"./b\"): void); - module.exports = \"C\"; " `; @@ -82,7 +76,6 @@ module.exports = \'D\'; * @flow */ (require(\"./b\"): void); - module.exports = \"D\"; " `; diff --git a/tests/indexer/__snapshots__/jsfmt.spec.js.snap b/tests/indexer/__snapshots__/jsfmt.spec.js.snap index db47e463..a10443ae 100644 --- a/tests/indexer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/indexer/__snapshots__/jsfmt.spec.js.snap @@ -50,31 +50,24 @@ function foo7(): {[key: string]: number; foo: number} { function foo0(): {} { return { foo: \"bar\" }; } - function foo1(): { [key: string]: string } { return { foo: \"bar\" }; } - function foo2(): { [key: number]: string } { return { foo: \"bar\" }; } - function foo3(): { [key: string]: number } { return { foo: \"bar\" }; } - function foo4(): { [key: number]: number } { return { foo: \"bar\" }; } - function foo5(): { [key: string]: number, foo: string } { return { foo: \"bar\" }; } - function foo6(): { [key: number]: number, foo: string } { return { foo: \"bar\" }; } - function foo7(): { [key: string]: number, foo: number } { return { foo: \"bar\" }; } diff --git a/tests/init/__snapshots__/jsfmt.spec.js.snap b/tests/init/__snapshots__/jsfmt.spec.js.snap index ace31a70..1689ae65 100644 --- a/tests/init/__snapshots__/jsfmt.spec.js.snap +++ b/tests/init/__snapshots__/jsfmt.spec.js.snap @@ -60,47 +60,36 @@ function _if(b: () => boolean) { if (b()) { var f = function() {}; } - f(); } - function _while(b: () => boolean) { while (b()) { var f = function() {}; } - f(); } - function _do_while(b: () => boolean) { do { var f = function() {}; } while (b()); - f(); } - function _for(n: number) { for (var i = 0; i < n; i++) { var f = function() {}; } - f(); } - function _for_in(obj: Object) { for (var p in obj) { var f = function() {}; } - f(); } - function _for_of(arr: Array) { for (var x of arr) { var f = function() {}; } - f(); } " @@ -432,24 +421,19 @@ function for_in_post_init() { // error function linear_deferred_init() { var x: number; - x = 0; - var y: number = x; } - function linear_pre_init() { var x: number; var y: number = x; } - function if_scoped_init(b) { if (b) { var x: number = 0; var y: number = x; } } - function if_else_partial_init(b) { if (b) { var x: number = 0; @@ -457,93 +441,68 @@ function if_else_partial_init(b) { var y: number = x; } } - function if_pre_init(b) { var y: number = x; - if (b) { var x: number = 0; } } - function if_partial_post_init(b) { if (b) { var x: number = 0; } - var y: number = x; } - function if_post_init(b) { if (b) { var x: number = 0; } else { var x: number = 1; } - var y: number = x; } - function if_partial_post_init(b) { var x: number; - if (b) { x = 0; } - var y: number = x; } - function if_post_init(b) { var x: number; - if (b) { x = 0; } else { x = 1; } - var y: number = x; } - function switch_partial_post_init(i) { var x: number; switch (i) { case 0: - x = 0; - break; case 1: - x = 1; - break; } var y: number = x; } - function switch_post_init(i) { var x: number; switch (i) { case 0: - x = 0; - break; case 1: - x = 1; - break; default: - x = 2; - } var y: number = x; } - function switch_scoped_init_1(i) { switch (i) { case 0: @@ -551,7 +510,6 @@ function switch_scoped_init_1(i) { var y: number = x; } } - function switch_scoped_init_2(i) { var y: number = x; switch (i) { @@ -559,7 +517,6 @@ function switch_scoped_init_2(i) { var x: number = 0; } } - function switch_scoped_init_3(i) { switch (i) { case 0: @@ -567,7 +524,6 @@ function switch_scoped_init_3(i) { } var y: number = x; } - function switch_scoped_init_4(i) { switch (i) { case 0: @@ -576,115 +532,94 @@ function switch_scoped_init_4(i) { var y: number = x; } } - function while_scoped_init(b) { while (b) { var x: number = 0; var y: number = x; } } - function while_pre_init(b) { var y: number = x; while (b) { var x: number = 0; } } - function while_post_init(b) { while (b) { var x: number = 0; } var y: number = x; } - function do_while_scoped_init(b) { do { var x: number = 0; var y: number = x; } while (b); } - function do_while_pre_init(b) { var y: number = x; do { var x: number = 0; } while (b); } - function do_while_post_init(b) { do { var x: number = 0; } while (b); var y: number = x; } - function for_scoped_init(b) { for (; b; ) { var x: number = 0; var y: number = x; } } - function for_pre_init(b) { var y: number = x; - for (; b; ) { var x: number = 0; } } - function for_post_init(b) { for (; b; ) { var x: number = 0; } - var y: number = x; } - function for_in_scoped_init() { for (var p in { a: 1, b: 2 }) { var x: number = 0; var y: number = x; } } - function for_in_pre_init() { var y: number = x; - for (var p in { a: 1, b: 2 }) { var x: number = 0; } } - function for_in_post_init() { for (var p in { a: 1, b: 2 }) { var x: number = 0; } - var y: number = x; } - function for_of_scoped_init() { for (var x of [ 1, 2, 3 ]) { var x: number = 0; var y: number = x; } } - function for_in_pre_init() { var y: number = x; - for (var x of [ 1, 2, 3 ]) { var x: number = 0; } } - function for_in_post_init() { for (var x of [ 1, 2, 3 ]) { var x: number = 0; } - var y: number = x; } " @@ -886,86 +821,61 @@ function sub_closure_init_reference() { // TDZ (...even though this is weird...) function linear_deferred_init() { let x: number; - x = 0; - let y: number = x; } - function linear_pre_init() { let x: number; let y: ?number = x; let z: number = x; - x = 0; - let w: number = x; } - function self_init() { let x = x; } - function if_partial_post_init(b) { let x: number; - if (b) { x = 0; } - var y: number = x; } - function if_post_init(b) { let x: number; - if (b) { x = 0; } else { x = 1; } - var y: number = x; } - function switch_partial_post_init(i) { let x: number; switch (i) { case 0: - x = 0; - break; case 1: - x = 1; - break; } var y: number = x; } - function switch_post_init(i) { let x: number; switch (i) { case 0: - x = 0; - break; case 1: - x = 1; - break; default: - x = 2; - } var y: number = x; } - function switch_scoped_init_2(i) { switch (i) { case 0: @@ -974,7 +884,6 @@ function switch_scoped_init_2(i) { let y: number = x; } } - function while_post_init(b) { let x: number; while (b) { @@ -982,7 +891,6 @@ function while_post_init(b) { } var y: number = x; } - function do_while_post_init(b) { let x: number; do { @@ -990,55 +898,42 @@ function do_while_post_init(b) { } while (b); var y: number = x; } - function for_in_post_init() { var x: number; - for (var p in {}) { x = 0; } - var y: number = x; } - function for_of_post_init() { var x: number; - for (var x of []) { x = 0; } - var y: number = x; } - function switch_post_init2(i): number { let bar; switch (i) { case 1: - bar = 3; - break; default: throw new Error(\"Invalid state\"); } return bar; } - function switch_post_init2(i): number { let bar; switch (i) { case 1: - bar = 3; - break; default: throw new Error(\"Invalid state\"); } return bar; } - function sub_closure_init_reference() { let x = function() { return x; diff --git a/tests/instanceof/__snapshots__/jsfmt.spec.js.snap b/tests/instanceof/__snapshots__/jsfmt.spec.js.snap index f46fff4f..2acb79b4 100644 --- a/tests/instanceof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/instanceof/__snapshots__/jsfmt.spec.js.snap @@ -103,81 +103,63 @@ class X1 { class X2 { foo: string; } - function x(b) { return b ? new X1() : new X2(); } - function consumer1(b) { var g = x(b); - if (g instanceof X2) g.foo = \"1337\"; else g.foo = 1337; } - function consumer2(b) { var g = x(b); - if (g instanceof X1) g.foo = \"1337\"; } - class Y1 { bar: X1; } class Y2 { bar: X2; } - function y(b) { return b ? new Y1() : new Y2(); } - function consumer3(b) { var g = y(b); - if (g.bar instanceof X2) g.bar.foo = \"1337\"; else g.bar.foo = 1337; } - function consumer4(b) { var g = y(b); - if (g.bar instanceof X1) g.bar.foo = \"1337\"; } - class Z1 { baz: Y1; } class Z2 { baz: Y2; } - function z(b) { return b ? new Z1() : new Z2(); } - function consumer5(b) { var g = z(b); - if (g.baz.bar instanceof X2) g.baz.bar.foo = \"1337\"; else g.baz.bar.foo = 1337; } - function consumer6(b) { var g = z(b); - if (g.baz.bar instanceof X1) g.baz.bar.foo = \"1337\"; } - class C { m() { if (this instanceof D) @@ -190,11 +172,9 @@ class D extends C { s: string; constructor() { super(); - this.s = \"yup\"; } } - function foo0(x: Array | number) { if (x instanceof Array) { x[0] = 123; @@ -202,7 +182,6 @@ function foo0(x: Array | number) { x++; } } - function foo1(x: Array | number) { if (x instanceof Array) { x++; diff --git a/tests/interface/__snapshots__/jsfmt.spec.js.snap b/tests/interface/__snapshots__/jsfmt.spec.js.snap index 326a3a07..9b3cbfb6 100644 --- a/tests/interface/__snapshots__/jsfmt.spec.js.snap +++ b/tests/interface/__snapshots__/jsfmt.spec.js.snap @@ -48,10 +48,8 @@ declare class C { x: number } var x: string = new C().x; interface I { x: number } var i = new I(); - function testInterfaceName(o: I) { (o.name: string); - (o.constructor.name: string); } " @@ -93,11 +91,8 @@ interface I_ { x: number } interface J extends I, I_ {} interface K extends J {} var k: K = { x: \"\", y: \"\" }; - (k.x: string); - (k.y: string); - declare class C { x: number } declare class D extends C, Other {} interface A { y: Y } @@ -105,11 +100,8 @@ interface A_ { x: X } interface B extends A, A_ { z: Z } interface E extends B {} var e: E = { x: \"\", y: \"\", z: \"\" }; - (e.x: string); - (e.y: string); - (e.z: string); " `; @@ -132,22 +124,15 @@ function bar(m: M) { m.x; m.y; m.z; } // OK import type {J} from \"./import\"; interface K {} interface L extends J, K { y: string } - function foo(l: L) { l.x; - l.y; - l.z; } - type M = { y: string } & J & { z: boolean }; - function bar(m: M) { m.x; - m.y; - m.z; } " @@ -168,10 +153,8 @@ function foo(k: K) { interface I { x: number, y: string } interface J { y: number } interface K extends I, J { x: string } - function foo(k: K) { (k.x: number); - (k.y: number); } " @@ -191,11 +174,8 @@ new C().bar((x: string) => { }); // error, number ~/~> string // error, property \`foo\` not found function // error, number ~/~> string interface I { foo(x: number): void } - (function foo(x: number) {}: I); - declare class C { bar(i: I): void, bar(f: (x: number) => void): void } - new C().bar((x: string) => {}); " `; diff --git a/tests/intersection/__snapshots__/jsfmt.spec.js.snap b/tests/intersection/__snapshots__/jsfmt.spec.js.snap index b5c30ac0..95269c1d 100644 --- a/tests/intersection/__snapshots__/jsfmt.spec.js.snap +++ b/tests/intersection/__snapshots__/jsfmt.spec.js.snap @@ -10,7 +10,6 @@ function bar(x: Error & {type:number}): number { function foo(x: $All): number { return x.type; } - function bar(x: Error & { type: number }): number { return x.type; } @@ -83,12 +82,10 @@ type DuplexStreamOptions = ReadableStreamOptions & readableObjectMode?: boolean, writableObjectMode?: boolean }; - function hasObjectMode_bad(options: DuplexStreamOptions): boolean { return options.objectMode || options.readableObjectMode || options.writableObjectMode; } - function hasObjectMode_ok(options: DuplexStreamOptions): boolean { return !!(options.objectMode || options.readableObjectMode || options.writableObjectMode); @@ -150,9 +147,7 @@ type F = (_: ObjA) => void; type G = (_: ObjB) => void; type FG = (_: ObjA | ObjB) => void; declare var fun1: F & G; - (fun1: FG); - var fun2: FG = fun1; declare var f: ((_: number) => void) & ((_: string) => void); var g: (_: number | string) => void = f; diff --git a/tests/issues-11/__snapshots__/jsfmt.spec.js.snap b/tests/issues-11/__snapshots__/jsfmt.spec.js.snap index c3dbf1e2..31d0b8f3 100644 --- a/tests/issues-11/__snapshots__/jsfmt.spec.js.snap +++ b/tests/issues-11/__snapshots__/jsfmt.spec.js.snap @@ -5,7 +5,6 @@ exports.y = \"\"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ exports.x = 1; - exports.y = \"\"; " `; diff --git a/tests/iter/__snapshots__/jsfmt.spec.js.snap b/tests/iter/__snapshots__/jsfmt.spec.js.snap index 9184c88b..ea2a952a 100644 --- a/tests/iter/__snapshots__/jsfmt.spec.js.snap +++ b/tests/iter/__snapshots__/jsfmt.spec.js.snap @@ -44,43 +44,31 @@ for (var y in this) { // regression test to make sure \`in this\` doesn\'t fatal. it\'s currently // allowed, even though we can\'t actually enumerate all the keys on \`this\`. var a = [ true, false ]; - function foo(x) {} - for (var i = 0; i < 3; i++) { foo(a[i]); } - for (var k in a) { foo(a[k]); } - var b = (null: ?{ [key: string]: string }); - for (var j in b) { foo(b[j]); } - var c; - for (var m in c = b) { foo(c[m]); } - var d; - for (var n in d = a) { foo(d[n]); } - for (var x in undefined) { foo(x); } - for (var x in null) { foo(x); } - for (var y in this) {} " `; diff --git a/tests/iterable/__snapshots__/jsfmt.spec.js.snap b/tests/iterable/__snapshots__/jsfmt.spec.js.snap index 0baa6595..7de68aa0 100644 --- a/tests/iterable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/iterable/__snapshots__/jsfmt.spec.js.snap @@ -63,7 +63,6 @@ function miss_the_cache(x: Array): Iterable { return x; function fill_the_cache(x: Array): Iterable { return x; } - function miss_the_cache(x: Array): Iterable { return x; } @@ -89,9 +88,7 @@ function foo(strs: Iterable): void { console.log(s); } } - var m: Map = new Map(); - foo(m.keys()); " `; @@ -138,7 +135,6 @@ function makeIterator(coin_flip: () => boolean): Iterator { }, next(): IteratorResult { var done = coin_flip(); - if (!done) { return { done, value: \"still going...\" }; } else { @@ -147,7 +143,6 @@ function makeIterator(coin_flip: () => boolean): Iterator { } }; } - function makeIterator(coin_flip: () => boolean): Iterator { return { \"@@iterator\"() { @@ -155,7 +150,6 @@ function makeIterator(coin_flip: () => boolean): Iterator { }, next(): IteratorResult { var done = coin_flip(); - if (done) { return { done, value: \"still going...\" }; } else { @@ -189,15 +183,12 @@ function mapTest4(map: Map): Iterable { function mapTest1(map: Map): Iterable<[string, number]> { return map; } - function mapTest2(map: Map): Iterable<[K, V]> { return map; } - function mapTest3(map: Map): Iterable<*> { return map; } - function mapTest4(map: Map): Iterable { return map; } @@ -226,15 +217,12 @@ function setTest4(set: Set): Iterable { function setTest1(set: Set): Iterable { return set; } - function setTest2(set: Set): Iterable { return set; } - function setTest3(set: Set): Iterable<*> { return set; } - function setTest4(set: Set): Iterable { return set; } @@ -267,7 +255,6 @@ exports[`test variance.js 1`] = ` // ok, Iterable<+T> // ok, Iterator<+T> (([]: Array): Iterable); - (([]: Array).values(): Iterable); " `; diff --git a/tests/jsx_intrinsics.builtin/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_intrinsics.builtin/__snapshots__/jsfmt.spec.js.snap index fca6f91a..654f05bb 100644 --- a/tests/jsx_intrinsics.builtin/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx_intrinsics.builtin/__snapshots__/jsfmt.spec.js.snap @@ -74,17 +74,11 @@ var React = require(\"react\"); var Div = \"div\"; var Bad = \"bad\"; var Str: string = \"str\"; -
; - ; - ; - React.createElement(\"div\", {}); - React.createElement(\"bad\", {}); -
; " `; diff --git a/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap index c19c607f..f2adad66 100644 --- a/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap @@ -27,11 +27,8 @@ class CustomComponent extends React.Component { } var a: React.Element<{ prop: string }> = ; var b: React.Element<{ prop1: string }> = ; -
; -
; - var c: React.Element<{ id: string }> =
; var d: React.Element<{ id: number }> =
; " @@ -70,19 +67,12 @@ var React = require(\"react\"); var Div = \"div\"; var Bad = \"bad\"; var Str: string = \"str\"; -
; - ; - ; - React.createElement(\"div\", {}); - React.createElement(\"bad\", {}); - React.createElement(Str, {}); -
; " `; diff --git a/tests/keys/__snapshots__/jsfmt.spec.js.snap b/tests/keys/__snapshots__/jsfmt.spec.js.snap index 0d03db13..5429c131 100644 --- a/tests/keys/__snapshots__/jsfmt.spec.js.snap +++ b/tests/keys/__snapshots__/jsfmt.spec.js.snap @@ -65,57 +65,38 @@ function testKeysOfOtherObj(str: string, lit: \'hi\') { // Error: number -> keys of ObjLit function testKeysOfObject(str: string, lit: \"hi\") { (str: $Keys); - if (str) { (str: $Keys); } - (\"hi\": $Keys); - (123: $Keys); } - type StrDict = { [key: string]: mixed }; - function testKeysOfStrDict(str: string, lit: \"hi\") { (str: $Keys); - if (str) { (str: $Keys); } - (\"hi\": $Keys); - (123: $Keys); } - type StrLitDict = { [key: \"hi\"]: mixed }; - function testKeysOfStrLitDict(str: string, lit: \"hi\") { (str: $Keys); - if (str) { (str: $Keys); } - (\"hi\": $Keys); - (\"bye\": $Keys); - (123: $Keys); } - type ObjLit = { hi: mixed }; - function testKeysOfOtherObj(str: string, lit: \"hi\") { (str: $Keys); - if (str) { (str: $Keys); } - (\"hi\": $Keys); - (123: $Keys); } " diff --git a/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap b/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap index 30f050e0..78425ba0 100644 --- a/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap @@ -80,15 +80,10 @@ class C { return \"hello\"; } } - (new C().foo(): boolean); - (new C().x: boolean); - (new C().bar: boolean); - (new C().qux: boolean); - const o = { foo(): number { return 0; @@ -107,13 +102,9 @@ const o = { return \"hello\"; } }; - (o.foo(): boolean); - (o.x: boolean); - (o.bar: boolean); - (o.qux(): boolean); " `; diff --git a/tests/lib/__snapshots__/jsfmt.spec.js.snap b/tests/lib/__snapshots__/jsfmt.spec.js.snap index 68c393e8..06d844c4 100644 --- a/tests/lib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/lib/__snapshots__/jsfmt.spec.js.snap @@ -16,11 +16,8 @@ var y: string = Number.MAX_VALUE; var z: number = new TypeError().name; var w: string = parseInt(\"...\"); var a = new Map(); - a.delete(\"foobar\"); - var b = undefined; - if (undefined) {} " `; diff --git a/tests/libconfig/__snapshots__/jsfmt.spec.js.snap b/tests/libconfig/__snapshots__/jsfmt.spec.js.snap index 228bf3a0..7fd71f3a 100644 --- a/tests/libconfig/__snapshots__/jsfmt.spec.js.snap +++ b/tests/libconfig/__snapshots__/jsfmt.spec.js.snap @@ -17,7 +17,6 @@ exports[`test libtest.js 1`] = ` bar(123); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ foo(123); - bar(123); " `; diff --git a/tests/libdef_ignored_module/__snapshots__/jsfmt.spec.js.snap b/tests/libdef_ignored_module/__snapshots__/jsfmt.spec.js.snap index a1a70c83..6bc3f2f4 100644 --- a/tests/libdef_ignored_module/__snapshots__/jsfmt.spec.js.snap +++ b/tests/libdef_ignored_module/__snapshots__/jsfmt.spec.js.snap @@ -8,7 +8,6 @@ import foo from \"foo\"; /* @flow */ // error number ~> string import foo from \"foo\"; - (foo.bar: string); " `; diff --git a/tests/librec/__snapshots__/jsfmt.spec.js.snap b/tests/librec/__snapshots__/jsfmt.spec.js.snap index 7916eed2..9d7c8b78 100644 --- a/tests/librec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/librec/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test libtest.js 1`] = ` bar(123); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ foo(123); - bar(123); " `; diff --git a/tests/literal/__snapshots__/jsfmt.spec.js.snap b/tests/literal/__snapshots__/jsfmt.spec.js.snap index a81ba272..3b821102 100644 --- a/tests/literal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/literal/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,6 @@ exports[`test enum.js 1`] = ` module.exports = APIKeys; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var APIKeys = { AGE: \"age\", NAME: \"name\" }; - module.exports = APIKeys; " `; @@ -44,25 +43,15 @@ var red:string = tuple[indices.red]; // error: tuple[0] is a number // error: object.name is a string // error: tuple[0] is a number var APIKeys = require(\"./enum\"); - function foo(x: $Keys) {} - foo(\"AGE\"); - foo(\"LOCATION\"); - function bar(x: $Keys<{ age: number }>) {} - bar(APIKeys.AGE); - bar(APIKeys.NAME); - var object = {}; - object[APIKeys.AGE] = 123; - object[APIKeys.NAME] = \"FOO\"; - var age: number = object[APIKeys.AGE]; var name: number = object[APIKeys.NAME]; var indices = { red: 0, green: 1, blue: 2 }; @@ -101,26 +90,20 @@ function test4(flip_times: number): number { function test1(x: number): number { return -x; } - function test2(x: string): number { return -x; } - function test3(x: number, flip_times: number): number { for (var i = 0; i < flip_times; i++) { x = -x; } - return x; } - function test4(flip_times: number): number { var x = 1; - for (var i = 0; i < flip_times; i++) { x = -x; } - return x; } " diff --git a/tests/locals/__snapshots__/jsfmt.spec.js.snap b/tests/locals/__snapshots__/jsfmt.spec.js.snap index f3581136..38f06e4e 100644 --- a/tests/locals/__snapshots__/jsfmt.spec.js.snap +++ b/tests/locals/__snapshots__/jsfmt.spec.js.snap @@ -78,80 +78,54 @@ function switch_scope(x: mixed) { switch (x) { case \"foo\": let a; - a = 0; - b = 0; - } - (a: string); - (b: string); } - function try_scope_finally() { let a; let b; try { a = \"\"; - b = \"\"; } finally { let a; - a = 0; - b = 0; } - (a: string); - (b: string); } - function for_scope() { let a = \"\"; let b = \"\"; - for (let a; ; ) { a = 0; - b = 0; } - (a: string); - (b: string); } - function for_in_scope(o: Object) { let a = 0; let b = 0; - for (let a in o) { a = \"\"; - b = \"\"; } - (a: number); - (b: number); } - function for_of_scope(xs: number[]) { let a = \"\"; let b = \"\"; - for (let a of xs) { a = 0; - b = 0; } - (a: string); - (b: string); } " @@ -186,26 +160,20 @@ function foo0(b: bool): number { // error: string ~> number var x: string = 0; var x: number = 1; - function foo(p: boolean) {} - function sorry(really: boolean) { if (really) { var x: number | string = 1337; } else { var x: boolean = true; } - foo(x); } - function foo0(b: boolean): number { var x = 0; - if (b) { var x = \"\"; } - return x; } " diff --git a/tests/logical/__snapshots__/jsfmt.spec.js.snap b/tests/logical/__snapshots__/jsfmt.spec.js.snap index c03bdba3..77d9ffa3 100644 --- a/tests/logical/__snapshots__/jsfmt.spec.js.snap +++ b/tests/logical/__snapshots__/jsfmt.spec.js.snap @@ -735,228 +735,174 @@ function logical1a(): number { var x = false; return x && \"123\"; } - function logical1b(): string { var x = true; return x && \"123\"; } - function logical2a(): number { return false && \"123\"; } - function logical2b(): number { return 0 && \"123\"; } - function logical2c(): string { return \"\" && 123; } - function logical2d(): string { return true && \"123\"; } - function logical2e(): number { return \"foo\" && 123; } - function logical2f(): string { return 123 && \"foo\"; } - function logical2g(): string { return [ 1, 2, 3 ] && \"foo\"; } - function logical2h(x: { a: number }): string { return x && \"foo\"; } - function logical2i(x: Object): string { return x && \"foo\"; } - function logical2j(x: (a: number) => number): string { return x && \"foo\"; } - function logical2k(x: Function): string { return x && \"foo\"; } - function logical3a(): string { var x: ?number = null; return x != null && x > 10; } - function logical3b(): number { var x: ?number = null; return x != null && x; } - function logical3c(): ?number { var x: ?number = null; return x != undefined && x; } - function logical4(x: boolean): string { return x && \"123\"; } - function logical5a(): number { var x = false; return x || 0; } - function logical5b(): number { var x: ?number = null; return x || 0; } - function logical5c(): string { var x = true; return x || 0; } - function logical6a(): string { return false || \"123\"; } - function logical6b(): string { return 0 || \"123\"; } - function logical6c(): number { return \"\" || 123; } - function logical6d(): number { return true || \"123\"; } - function logical6e(): string { return \"foo\" || 123; } - function logical6f(): number { return 123 || \"foo\"; } - function logical7a(): number { var x: ?number = null; return x != null && x || 0; } - function logical7b(x: boolean, y: number): number { return x && y || 0; } - function logical7c(x: string): number { return x && 1 || 0; } - function logical7d(x: number): string { return x && \"foo\" || \"bar\"; } - function logical7e(x: number): string { return false && x || \"bar\"; } - function logical8a(): number { var x = false; return (x || 0) && \"foo\"; } - function logical8b(): string { var x = false; return (x || 1) && \"foo\"; } - function logical8c(): string { var x = true; return (x || 1) && \"foo\"; } - function logical8d(): number { var x = false; return x || 0 && \"foo\"; } - function logical8e(): string { var x = false; return x || 1 && \"foo\"; } - function logical8f(): string { var x = true; return x || 1 && \"foo\"; } - function logical9a(x: number, y: string): number | string { return x || y || false; } - function logical9b(x: number, y: string): number | string { return false || x || y; } - function logical9c(x: number, y: boolean): string { return \"a\" || x || y; } - function logical10a(x: number, y: string): number | string { return x && y && false; } - function logical10b(x: number, y: string): Array { return false && x && y; } - function logical10c(x: number, y: string): Array { return x && false && y; } - function logical11a(): number { var y = 1; - for (var x = 0; x < 5; x++) { y = y || true; } - return y; } - function logical11b(y: number): number { for (var x = 0; x < 5; x++) { y = y || true; } - return y; } - function logical12a(): number { var y = 1; var z = true; - for (var x = 0; x < 5; x++) { y = z && y; - z = false; } - return y; } - function logical12b(y: number): number { for (var x = 0; x < 5; x++) { y = y && true; } - return y; } - function logical13(x: number): Array<{ x: string }> { return [ { x: x && \"bar\" }, @@ -969,7 +915,6 @@ function logical13(x: number): Array<{ x: string }> { { x: \"foo\" && \"bar\" } ]; } - function logical14(x: number): Array<{ x: string }> { return [ { x: x || \"bar\" }, @@ -982,67 +927,51 @@ function logical14(x: number): Array<{ x: string }> { { x: \"foo\" || \"bar\" } ]; } - function logical15a(x: number): number { return 5 + (x || 7); } - function logical15b(x: number): number { return (x || 7) + 5; } - function logical15c(x: number): number { return 5 + (x && 7); } - function logical15d(x: number): number { return (x && 7) + 5; } - function logical16a(x: number): boolean { return 5 < (x || 7); } - function logical16b(x: number): boolean { return (x || 7) < 5; } - function logical16c(x: number): boolean { return 5 < (x && 7); } - function logical16d(x: number): boolean { return (x && 7) < 5; } - function logical17a(x: number): boolean { return 5 == (x || 7); } - function logical17b(x: number): boolean { return (x || 7) == 5; } - function logical17c(x: number): boolean { return 5 == (x && 7); } - function logical17d(x: number): boolean { return (x && 7) == 5; } - function logical18a(x: number, y: number): number { return x - 1 || y - 1; } - function logical18b(x: { a: number }, y: { b: number }): number { return x.a - 1 || y.b - 1; } - function logical19a(x: { y: string, z: boolean }): boolean { return x.y && x.z; } - function logical19b(x: { y: string, z: boolean }): boolean { return x.y || x.z; } diff --git a/tests/loners/__snapshots__/jsfmt.spec.js.snap b/tests/loners/__snapshots__/jsfmt.spec.js.snap index 3cbf1f9b..37c7f72b 100644 --- a/tests/loners/__snapshots__/jsfmt.spec.js.snap +++ b/tests/loners/__snapshots__/jsfmt.spec.js.snap @@ -13,13 +13,10 @@ module.exports = export_f; var o = { x: 5, y: \"jello\" }; var z = o.z; var export_o: { x: number } = o; - function f(u, v?): number { return u; } - var export_f: (u: number) => number = f; - module.exports = export_f; " `; diff --git a/tests/method_properties/__snapshots__/jsfmt.spec.js.snap b/tests/method_properties/__snapshots__/jsfmt.spec.js.snap index b2f42ad6..652cb90f 100644 --- a/tests/method_properties/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method_properties/__snapshots__/jsfmt.spec.js.snap @@ -43,22 +43,15 @@ class C { this.constructor.x; } } - C.x; - new C().foo.x; - C.bar.x; - import {Foo} from \"./exports_optional_prop\"; const foo = new Foo(); - (foo.bar(): string); - function f(x) { (x.bar(): string); } - f(foo); " `; diff --git a/tests/misc/__snapshots__/jsfmt.spec.js.snap b/tests/misc/__snapshots__/jsfmt.spec.js.snap index fe6dc1a0..eec2e231 100644 --- a/tests/misc/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/__snapshots__/jsfmt.spec.js.snap @@ -17,19 +17,12 @@ f(A.x); // A.x is now a string, by def assign /* @providesModule A */ // A.x is now a string, by def assign module.exports = {}; - var A = { x: true, ...{} }; - module.exports.cls = A; - function f(x: boolean) {} - module.exports.fn = f; - A.y = \"?\"; - A.x = A.y; - f(A.x); " `; @@ -53,19 +46,14 @@ module.exports = B; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule B */ var A = require(\"A\").cls; - function B() { this.b = \"...\"; } - function f(): number { return this.b; } - B.prototype.s = 0; - B.prototype.fn = f; - module.exports = B; " `; @@ -89,17 +77,12 @@ module.exports = C; /* @providesModule C */ var B = require(\"B\"); var f = require(\"A\").fn; - function C() { var o = new B(); - f(o.b); - f(o.s); - o.fn(); } - module.exports = C; " `; @@ -122,19 +105,13 @@ module.exports = \"D for dummy\"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule D */ var f = require(\"A\").fn; - function g(): string { return this.i; } - var o = { fn: g, ...{} }; - o.i = true; - var i = o.fn(); - f(i); - module.exports = \"D for dummy\"; " `; @@ -153,12 +130,9 @@ module.exports = {obj: o}; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule E */ function h(x: number) {} - var proto = { fn: h }; var o = Object.create(proto); - o.fn(false); - module.exports = { obj: o }; " `; @@ -174,9 +148,7 @@ function foo(x: Array): string { function fn2(x) { return x.length * 4; } - fn2({ length: \"hi\" }); - function foo(x: Array): string { return x.length; } @@ -193,15 +165,10 @@ b.length = \"duck\"; b.length(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var a = { length: \"duck\" }; - a.length = 123; - a.length(); - var b = [ 123 ]; - b.length = \"duck\"; - b.length(); " `; diff --git a/tests/missing_annotation/__snapshots__/jsfmt.spec.js.snap b/tests/missing_annotation/__snapshots__/jsfmt.spec.js.snap index e5eaab89..8825ef9d 100644 --- a/tests/missing_annotation/__snapshots__/jsfmt.spec.js.snap +++ b/tests/missing_annotation/__snapshots__/jsfmt.spec.js.snap @@ -132,7 +132,6 @@ var Bar = { c: Foo.c(\"bar\"), d: Foo.d(\"bar\") }; - module.exports = Foo, Bar; " `; diff --git a/tests/modified_lib/__snapshots__/jsfmt.spec.js.snap b/tests/modified_lib/__snapshots__/jsfmt.spec.js.snap index c3571c62..2c17a143 100644 --- a/tests/modified_lib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/modified_lib/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,6 @@ bar(5); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import {bar} from \"foo\"; - bar(5); " `; diff --git a/tests/module_not_found_errors/src/__snapshots__/jsfmt.spec.js.snap b/tests/module_not_found_errors/src/__snapshots__/jsfmt.spec.js.snap index e8727e80..f0bdd78a 100644 --- a/tests/module_not_found_errors/src/__snapshots__/jsfmt.spec.js.snap +++ b/tests/module_not_found_errors/src/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,6 @@ require(\'module_outside_of_root\'); // node_modules/module_outside_of_root/ sits outside of the Flow project root. // Flow should give a descriptive error about this require(\"module_completely_absent\"); - require(\"module_outside_of_root\"); " `; diff --git a/tests/modules/__snapshots__/jsfmt.spec.js.snap b/tests/modules/__snapshots__/jsfmt.spec.js.snap index 53e26311..e604d943 100644 --- a/tests/modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/modules/__snapshots__/jsfmt.spec.js.snap @@ -20,7 +20,6 @@ f(\"...\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var f = require(\"./lib\"); - f(\"...\"); " `; @@ -40,13 +39,10 @@ module.exports = f; //function f(x) { g(x); return x; } //function f(x:number) { g(x); return x; } function g(x: string) {} - function f(x: number): number { g(x); - return x; } - module.exports = f; " `; diff --git a/tests/more_annot/__snapshots__/jsfmt.spec.js.snap b/tests/more_annot/__snapshots__/jsfmt.spec.js.snap index 21c5dd02..3d7a75d5 100644 --- a/tests/more_annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_annot/__snapshots__/jsfmt.spec.js.snap @@ -23,9 +23,7 @@ module.exports = o3; var o1 = { x: 0, y: \"\" }; var o2 = { z: o1 }; var o3 = {}; - o3.w = o2; - module.exports = o3; " `; @@ -41,9 +39,7 @@ var o2: Foo = new Foo(); function Foo() { this.x = 0; } - Foo.prototype.m = function() {}; - var o1: { x: number, m(): void } = new Foo(); var o2: Foo = new Foo(); " diff --git a/tests/more_classes/__snapshots__/jsfmt.spec.js.snap b/tests/more_classes/__snapshots__/jsfmt.spec.js.snap index 7a280679..721db0ca 100644 --- a/tests/more_classes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_classes/__snapshots__/jsfmt.spec.js.snap @@ -27,16 +27,13 @@ class Bar { self: Bar; constructor(y: number) { this.y = y; - this.self = this; } bar(z: string, u: string): string { new Qux().w = \"?\"; - return z; } } - module.exports = Bar; " `; @@ -79,19 +76,15 @@ class Foo extends Qux { } foo(y: string, z): number { this.x = y; - var u = new Foo(\"...\").qux(); var v = new Bar(y); - v.self = v; - return v.bar(z, u); } fooqux(x: string) { this.x; } } - module.exports = Foo; " `; @@ -118,7 +111,6 @@ class Qux { } fooqux(x: number) {} } - module.exports = Qux; " `; diff --git a/tests/more_generics/__snapshots__/jsfmt.spec.js.snap b/tests/more_generics/__snapshots__/jsfmt.spec.js.snap index 7213dac9..45b91272 100644 --- a/tests/more_generics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_generics/__snapshots__/jsfmt.spec.js.snap @@ -41,38 +41,28 @@ function foo8(x:U,y):U { var foo1 = function(x: T): T { return x; }; - function foo2(x: T): S { return x; } - var foo3 = function(x: T): T { return foo3(x); }; - function foo4(x: T): S { return foo4(x); } - var x = []; - function foo5(): Array { return x; } - var foo6 = function(x: R): R { return foo1(x); }; - function foo7(x: R): R { return foo5(); } - function foo8(x: U, y): U { var z = foo8(x, x); - y(); - return x; } " diff --git a/tests/more_path/__snapshots__/jsfmt.spec.js.snap b/tests/more_path/__snapshots__/jsfmt.spec.js.snap index 3bda194e..c99ae1ae 100644 --- a/tests/more_path/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_path/__snapshots__/jsfmt.spec.js.snap @@ -63,71 +63,51 @@ module.exports = true; //f(x); //f(y); function f(x: number) {} - function g() { return 42 || \"hello\"; } - var x = g(); - if (typeof x === \"string\") { x = 0; } - f(x); - class A {} - function h() { return 42 || new A(); } - var y = h(); - if (y instanceof A) { y = 0; } - function bar() { return true; } - class C { qux() {} } - function foo() { var c = \"...\"; - c = new C(); - if (bar()) { c.qux(); } } - function goofy() { var x = g(); - if (typeof x == \"function\") { x(); } else {} } - function goofy2() { var o = { x: 0 }; - if (typeof o.x == \"function\") { o.x(); } - var y = o.x; - if (typeof y == \"function\") { y(); } else {} } - module.exports = true; " `; @@ -148,15 +128,11 @@ module.exports = FlowSA; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule FlowSA */ function check(x: string) {} - function FlowSA() { var x = 0; - x = \"...\"; - check(x); } - module.exports = FlowSA; " `; @@ -218,41 +194,31 @@ class B extends A { class C extends B { c() {} } - function bar(x: B) { if (x instanceof A) { x.a(); - x.c(); } else { x++; } } - function foo(x: A) { if (x instanceof C) { x.a(); - x.b(); - x.c(); - x.d(); } else { x.a(); - x.c(); } } - class D { d() {} } - function baz(x: D) { if (x instanceof A) {} } - module.exports = \"sigma\"; " `; @@ -280,12 +246,10 @@ class BaseClass { class ChildClass extends BaseClass { childProp: string; } - function test(obj: BaseClass): string { if (obj instanceof ChildClass) { return obj.childProp_TYPO; } - return obj.baseProp; } " diff --git a/tests/namespace/__snapshots__/jsfmt.spec.js.snap b/tests/namespace/__snapshots__/jsfmt.spec.js.snap index 0342dae1..7d6b4a42 100644 --- a/tests/namespace/__snapshots__/jsfmt.spec.js.snap +++ b/tests/namespace/__snapshots__/jsfmt.spec.js.snap @@ -32,16 +32,13 @@ module.exports = { foo: (\"\": number) }; type T = (x: number) => void; var f: T = function(x: string): void {}; type Map = (x: X) => Y; - function bar(x: U, f: Map): V { return f(x); } - var y: number = bar(0, x => \"\"); type Seq = number | Array; var s1: Seq = [ 0, [ 0 ] ]; var s2: Seq = [ [ \"\" ] ]; - module.exports = { foo: (\"\": number) }; " `; diff --git a/tests/node_modules_with_symlinks/root/__snapshots__/jsfmt.spec.js.snap b/tests/node_modules_with_symlinks/root/__snapshots__/jsfmt.spec.js.snap index df899f28..20acb26b 100644 --- a/tests/node_modules_with_symlinks/root/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_modules_with_symlinks/root/__snapshots__/jsfmt.spec.js.snap @@ -6,9 +6,7 @@ console.log(y); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"symlink_lib\"); var y = require(\"symlink_lib_outside_root\"); - console.log(x); - console.log(y); " `; diff --git a/tests/node_tests/assert/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/assert/__snapshots__/jsfmt.spec.js.snap index 9ef8d717..35b84c3b 100644 --- a/tests/node_tests/assert/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/assert/__snapshots__/jsfmt.spec.js.snap @@ -9,9 +9,7 @@ assert.ok(true) // ok // ok // ok var assert = require(\"assert\"); - assert(true); - assert.ok(true); " `; diff --git a/tests/node_tests/basic/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic/__snapshots__/jsfmt.spec.js.snap index c2fb53b3..da8e1cb6 100644 --- a/tests/node_tests/basic/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic/__snapshots__/jsfmt.spec.js.snap @@ -10,7 +10,6 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"./bar.js\"); - console.log(x); " `; diff --git a/tests/node_tests/basic_file/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic_file/__snapshots__/jsfmt.spec.js.snap index 2d694c58..d1b67587 100644 --- a/tests/node_tests/basic_file/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic_file/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,6 @@ console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bar.js does not work var x = require(\"./bar\"); - console.log(x); " `; diff --git a/tests/node_tests/basic_node_modules/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic_node_modules/__snapshots__/jsfmt.spec.js.snap index 781fee3c..4caf098a 100644 --- a/tests/node_tests/basic_node_modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic_node_modules/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar.js\"); - console.log(x); " `; diff --git a/tests/node_tests/basic_node_modules_with_path/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic_node_modules_with_path/__snapshots__/jsfmt.spec.js.snap index 7f860b9b..68209ae1 100644 --- a/tests/node_tests/basic_node_modules_with_path/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic_node_modules_with_path/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib/bar\"); - console.log(x); " `; diff --git a/tests/node_tests/basic_package/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic_package/__snapshots__/jsfmt.spec.js.snap index db75331d..bdc2306d 100644 --- a/tests/node_tests/basic_package/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic_package/__snapshots__/jsfmt.spec.js.snap @@ -4,7 +4,6 @@ console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // \'bar_lib\' does not work! var x = require(\"./bar_lib\"); - console.log(x); " `; diff --git a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap index cc05c500..0467c352 100644 --- a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap @@ -70,90 +70,58 @@ let bool: boolean = false; let buffer: Buffer = new Buffer(0); let num: number = 0; let maybeNum: ?number; - buffer.length; - buffer.buffer; - buffer.byteOffset; - buffer.byteLength; - buffer[1]; - buffer.copyWithin(0, 0); - buffer.copyWithin(0, 0, 0); - const it1: Iterator<[number, number]> = buffer.entries(); - bool = buffer.every((element: number) => false); - bool = buffer.every((element: number) => false, buffer); - buffer = buffer.fill(1); - buffer = buffer.fill(1, 0, 0); - buffer = buffer.fill(\"a\"); - buffer = buffer.fill(\"a\", 0, 0); - buffer = buffer.fill(\"a\", 0, 0, \"utf8\"); - buffer = buffer.fill(\"a\", \"utf8\"); - maybeNum = buffer.find(( element: number, index: number, array: Uint8Array ) => false); - maybeNum = buffer.find( (element: number, index: number, array: Uint8Array) => false, buffer ); - num = buffer.findIndex(( element: number, index: number, array: Uint8Array ) => false); - num = buffer.findIndex( (element: number, index: number, array: Uint8Array) => false, buffer ); - buffer.forEach((value: number) => console.log(value), buffer); - buffer.forEach( (value: number, index: number, array: Uint8Array) => console.log(value), buffer ); - bool = buffer.includes(3); - bool = buffer.includes(3, 4); - num = buffer.indexOf(3); - num = buffer.indexOf(3, 4); - buffer = Buffer.from([ 98, 117, 102, 102, 101, 114 ]); - const typedArray = new Uint8Array([ 52 ]); - buffer = Buffer.from( typedArray.buffer, typedArray.byteOffset, typedArray.byteLength ); - buffer = Buffer.from(new Buffer(0)); - buffer = Buffer.from(\"foo\", \"utf8\"); - buffer = Buffer.from([ 98, 117, 102, 102, 101, 114 ], (a: number) => a + 1, {}); " `; diff --git a/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap index c0c564b7..604ace3e 100644 --- a/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap @@ -21,13 +21,10 @@ exec(\'ls\', {maxBuffer: 100}, function(error, stdout, stderr) { // options only. // options + callback. var exec = require(\"child_process\").exec; - exec(\"ls\", function(error, stdout, stderr) { console.info(stdout); }); - exec(\"ls\", { timeout: 250 }); - exec(\"ls\", { maxBuffer: 100 }, function(error, stdout, stderr) { console.info(stdout); }); @@ -71,21 +68,15 @@ execFile(\'ls\', [\'-l\'], {timeout: 250}, function(error, stdout, stderr) { // args + options. // Put it all together. var execFile = require(\"child_process\").execFile; - execFile(\"ls\", [ \"-lh\" ]); - execFile(\"ls\", function(error, stdout, stderr) { console.info(stdout); }); - execFile(\"wc\", { timeout: 250 }); - execFile(\"ls\", [ \"-l\" ], function(error, stdout, stderr) { console.info(stdout); }); - execFile(\"ls\", [ \"-l\" ], { timeout: 250 }); - execFile(\"ls\", [ \"-l\" ], { timeout: 250 }, function(error, stdout, stderr) { console.info(stdout); }); @@ -112,17 +103,11 @@ var execSync = require(\'child_process\').execSync; // error, no signatures match // error, no signatures match var execSync = require(\"child_process\").execSync; - (execSync(\"ls\"): Buffer); - (execSync(\"ls\", { encoding: \"buffer\" }): Buffer); - (execSync(\"ls\", { encoding: \"utf8\" }): string); - execSync(\"ls\", { timeout: \"250\" }); - execSync(\"ls\", { stdio: \"inherit\" }); - execSync(\"ls\", { stdio: [ \"inherit\" ] }); " `; @@ -165,31 +150,23 @@ wc.stderr.pipe(process.stderr); var child_process = require(\"child_process\"); var ls = child_process.spawn(\"ls\"); var wc = child_process.spawn(\"wc\", [ \"-l\" ]); - child_process.spawn(\"echo\", [ \"-n\", \"\\\"Testing...\\\"\" ], { env: { TEST: \"foo\" } }); - child_process.spawn(\"echo\", { env: { FOO: 2 } }); - ls.stdout.on(\"data\", function(data) { wc.stdin.write(data); }); - ls.stderr.on(\"data\", function(data) { console.warn(data); }); - ls.on(\"close\", function(code) { if (code !== 0) { console.warn(\"\`ls\` exited with code %s\", code); } - wc.stdin.end(); }); - wc.stdout.pipe(process.stdout); - wc.stderr.pipe(process.stderr); " `; diff --git a/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap index 3b99d34a..6d556856 100644 --- a/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap @@ -52,40 +52,25 @@ const crypto = require(\"crypto\"); let tests = [ function() { const hmac = crypto.createHmac(\"sha256\", \"a secret\"); - hmac.on(\"readable\", () => { (hmac.read(): ?(string | Buffer)); - (hmac.read(): number); }); - hmac.write(\"some data to hash\"); - hmac.write(123); - hmac.end(); }, function(buf: Buffer) { const hmac = crypto.createHmac(\"sha256\", \"a secret\"); - hmac.update(\"some data to hash\"); - hmac.update(\"foo\", \"utf8\"); - hmac.update(\"foo\", \"bogus\"); - hmac.update(buf); - hmac.update(buf, \"utf8\"); - (hmac.update(\"some data to hash\").update(buf).digest(): Buffer); - (hmac.digest(\"hex\"): string); - (hmac.digest(): Buffer); - (hmac.digest(\"hex\"): void); - (hmac.digest(): void); } ]; diff --git a/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap index f999e49f..baae31ed 100644 --- a/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap @@ -40,37 +40,25 @@ fs.readFile(\"file.exp\", {}, (_, data) => { // error // error var fs = require(\"fs\"); - fs.readFile(\"file.exp\", (_, data) => { (data: Buffer); }); - fs.readFile(\"file.exp\", \"blah\", (_, data) => { (data: string); }); - fs.readFile(\"file.exp\", { encoding: \"blah\" }, (_, data) => { (data: string); }); - fs.readFile(\"file.exp\", {}, (_, data) => { (data: Buffer); }); - (fs.readFileSync(\"file.exp\"): Buffer); - (fs.readFileSync(\"file.exp\"): string); - (fs.readFileSync(\"file.exp\", \"blah\"): string); - (fs.readFileSync(\"file.exp\", \"blah\"): Buffer); - (fs.readFileSync(\"file.exp\", { encoding: \"blah\" }): string); - (fs.readFileSync(\"file.exp\", { encoding: \"blah\" }): Buffer); - (fs.readFileSync(\"file.exp\", {}): Buffer); - (fs.readFileSync(\"file.exp\", {}): string); " `; diff --git a/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap index 62b8fcae..722a7156 100644 --- a/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap @@ -37,37 +37,21 @@ let data4 = require(\'./json_array\'); // error, should be null // ok let data = require(\"./package/index.json\"); - (data.foo: void); - (data.foo.bar: void); - (data.abc: boolean); - let data2 = require(\"./package\"); - (data2.baz: void); - let data3 = require(\"./package2\"); - (data3.foo: void); - let data4 = require(\"./json_array\"); - (data4: Array); - (data4: void); - (require(\"./json_string\"): void); - (require(\"./json_number\"): void); - (require(\"./json_true\"): void); - (require(\"./json_false\"): void); - (require(\"./json_null\"): void); - (require(\"./json_negative_number\"): -1); " `; diff --git a/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap index d288f48b..bccf9dff 100644 --- a/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap @@ -21,21 +21,13 @@ var u3 = os.userInfo({encoding: \'buffer\'}); // error var os = require(\"os\"); var u1 = os.userInfo(); - (u1.username: string); - (u1.username: Buffer); - var u2 = os.userInfo({ encoding: \"utf8\" }); - (u2.username: string); - (u2.username: Buffer); - var u3 = os.userInfo({ encoding: \"buffer\" }); - (u3.username: string); - (u3.username: Buffer); " `; diff --git a/tests/node_tests/package_file/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/package_file/__snapshots__/jsfmt.spec.js.snap index 869132ca..b71f83ab 100644 --- a/tests/node_tests/package_file/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/package_file/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,6 @@ console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // \'bar_lib\' does not work! var x: string = require(\"./bar_lib\"); - console.log(x); " `; diff --git a/tests/node_tests/package_file_node_modules/foo/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/package_file_node_modules/foo/__snapshots__/jsfmt.spec.js.snap index 56acd783..5604ee51 100644 --- a/tests/node_tests/package_file_node_modules/foo/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/package_file_node_modules/foo/__snapshots__/jsfmt.spec.js.snap @@ -4,7 +4,6 @@ console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // \'bar_lib\' does not work! var x: string = require(\"bar_lib\"); - console.log(x); " `; diff --git a/tests/node_tests/path_node_modules/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/path_node_modules/__snapshots__/jsfmt.spec.js.snap index 6da9a82e..51bc929a 100644 --- a/tests/node_tests/path_node_modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/path_node_modules/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib/src/lib/bar\"); - console.log(x); " `; diff --git a/tests/node_tests/path_node_modules_with_short_main/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/path_node_modules_with_short_main/__snapshots__/jsfmt.spec.js.snap index 3ed654b1..d2e4c58f 100644 --- a/tests/node_tests/path_node_modules_with_short_main/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/path_node_modules_with_short_main/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib\"); - console.log(x); " `; diff --git a/tests/node_tests/path_node_modules_without_main/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/path_node_modules_without_main/__snapshots__/jsfmt.spec.js.snap index 3ed654b1..d2e4c58f 100644 --- a/tests/node_tests/path_node_modules_without_main/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/path_node_modules_without_main/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib\"); - console.log(x); " `; diff --git a/tests/node_tests/path_package/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/path_package/__snapshots__/jsfmt.spec.js.snap index 0d81ff4d..e77df483 100644 --- a/tests/node_tests/path_package/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/path_package/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib/src/lib\"); - console.log(x); " `; diff --git a/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap index c8c6576d..1cf3b543 100644 --- a/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap @@ -39,34 +39,21 @@ var fs = require(\"fs\"); var stream = require(\"stream\"); var ls = child_process.spawn(\"ls\"); var data = \"foo\"; - ls.stdin.write(data); - ls.stdin.write(data, \"utf-8\"); - ls.stdin.write(data, () => {}); - ls.stdin.write(data, \"utf-8\", () => {}); - ls.stdin.end(); - ls.stdin.end(data); - ls.stdin.end(data, \"utf-8\"); - ls.stdin.end(data, () => {}); - ls.stdin.end(data, \"utf-8\", () => {}); - var ws = fs.createWriteStream(\"/dev/null\"); - ls.stdout.pipe(ws).end(); - class MyReadStream extends stream.Readable {} class MyWriteStream extends stream.Writable {} class MyDuplex extends stream.Duplex {} class MyTransform extends stream.Duplex {} - new MyReadStream() .pipe(new MyDuplex()) .pipe(new MyTransform()) diff --git a/tests/node_tests/timers/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/timers/__snapshots__/jsfmt.spec.js.snap index 569e8e36..862e8381 100644 --- a/tests/node_tests/timers/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/timers/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,6 @@ setImmediate(setImmediateCallback); function setImmediateCallback(): number { return 0; } - setImmediate(setImmediateCallback); " `; diff --git a/tests/node_tests/url/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/url/__snapshots__/jsfmt.spec.js.snap index a08c91e9..f335f9ef 100644 --- a/tests/node_tests/url/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/url/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,6 @@ exports[`test url.js 1`] = ` url.format(url.parse(\'https://example.com/foo\')); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ const url = require(\"url\"); - url.format(url.parse(\"https://example.com/foo\")); " `; diff --git a/tests/nullable/__snapshots__/jsfmt.spec.js.snap b/tests/nullable/__snapshots__/jsfmt.spec.js.snap index 65812309..8d38dc75 100644 --- a/tests/nullable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/nullable/__snapshots__/jsfmt.spec.js.snap @@ -10,7 +10,6 @@ exports[`test maybe.js 1`] = ` // ok // error (only num ~> string) ((\"foo\": ??string): ?string); - ((123: ??number): ?string); " `; @@ -41,33 +40,23 @@ var array_of_nullable: Array = [null, 3]; function foo(): string { return null; } - function bar(): ?string { return null; } - function qux(x: string) {} - function corge(x: number) {} - var x = bar(); - if (x != null) qux(x); - if (x != null) corge(x); - function grault() { x = null; } - if (x != null) { grault(); - qux(x); } - var array_of_nullable: Array = [ null, 3 ]; " `; @@ -82,15 +71,10 @@ function fn(data: ?{}) {} fn({some: \'literal\'}); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo(x: ?string) {} - function bar(x: ?number) {} - foo(\"hmm\"); - bar(\"hmm\"); - function fn(data: ?{}) {} - fn({ some: \"literal\" }); " `; diff --git a/tests/object-method/__snapshots__/jsfmt.spec.js.snap b/tests/object-method/__snapshots__/jsfmt.spec.js.snap index a9b5fb4f..ebb2518e 100644 --- a/tests/object-method/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object-method/__snapshots__/jsfmt.spec.js.snap @@ -4,7 +4,6 @@ exports[`test id.js 1`] = ` module.exports = id; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare function id(_: X): X; - module.exports = id; " `; @@ -19,7 +18,6 @@ function subtypeCheck(x: Interface): ObjectType { return x; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ interface Interface { m(): void } import type {ObjectType} from \"./test\"; - function subtypeCheck(x: Interface): ObjectType { return x; } @@ -43,11 +41,9 @@ module.exports = id( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ const id = require(\"./id\"); export type ObjectType = { +m: () => void }; - function methodCaller(x: ObjectType) { x.m(); } - module.exports = id(methodCaller); " `; @@ -77,12 +73,9 @@ b.f(); // error, property \`p\` not found function f() { return this.p; } - var a = { p: 0, f }; var b = { f }; - a.f(); - b.f(); " `; @@ -116,19 +109,14 @@ qux({ f: foo }); // error, since \`this\` is used non-trivially in \`foo\` function foo() { this.m(); } - function bar(f: () => void) { f(); - ({ f }).f(); } - bar(foo); - function qux(o: { f(): void }) { o.f(); } - qux({ f: foo }); " `; diff --git a/tests/object_annot/__snapshots__/jsfmt.spec.js.snap b/tests/object_annot/__snapshots__/jsfmt.spec.js.snap index 73b5e962..173c7a7b 100644 --- a/tests/object_annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_annot/__snapshots__/jsfmt.spec.js.snap @@ -12,7 +12,6 @@ function bar(x: Object): Array { function foo(x: Array): Array { return x.sort((a, b) => a.foo - b.foo); } - function bar(x: Object): Array { return Object.keys(x); } diff --git a/tests/object_api/__snapshots__/jsfmt.spec.js.snap b/tests/object_api/__snapshots__/jsfmt.spec.js.snap index 40e61c33..72b9db44 100644 --- a/tests/object_api/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_api/__snapshots__/jsfmt.spec.js.snap @@ -19,9 +19,7 @@ module.exports = b; // works here var a = require(\"./a\"); var b = Object.assign({ bar() {}, ...{} }, a); - b.a(); - module.exports = b; " `; @@ -34,9 +32,7 @@ c.a(); c.foo();~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var c = require(\"./b\"); - c.a(); - c.foo(); " `; @@ -64,9 +60,7 @@ var export_ = Object.assign({}, { }); var decl_export_: { foo: any, bar: any } = Object.assign({}, export_); let anyObj: Object = {}; - Object.assign(anyObj, anyObj); - module.exports = export_; " `; @@ -98,16 +92,11 @@ declare var o: O; class C { foo: string; } - (Object.create(C.prototype): C); - (Object.create(new C()): C); - ({ foo: \"foo\" }: C); - type O = { foo: string }; declare var o: O; - (o: C); " `; @@ -131,7 +120,6 @@ class Bar extends Foo {} let tests = [ function() { const x = new Bar(); - (Object.getPrototypeOf(x): Foo); } ]; @@ -182,39 +170,27 @@ class Bar extends Foo { // only own enumerable props // error: bar_prop ~> error var sealed = { one: \"one\", two: \"two\" }; - (Object.keys(sealed): Array<\"one\" | \"two\">); - (Object.keys(sealed): void); - var unsealed = {}; - Object.keys(unsealed).forEach(k => { (k: number); }); - var dict: { [k: number]: string } = {}; - Object.keys(dict).forEach(k => { (k: number); }); - var any: Object = {}; - (Object.keys(any): Array); - class Foo { prop: string; foo() {} } - (Object.keys(new Foo()): Array<\"error\">); - class Bar extends Foo { bar_prop: string; bar() {} } - (Object.keys(new Bar()): Array<\"error\">); " `; @@ -469,13 +445,9 @@ var k : Object = a.constructor; // constructor // function takesABool(x: boolean) {} - function takesAString(x: string) {} - function takesANumber(x: number) {} - function takesAnObject(x: Object) {} - class Foo {} var a = { foo: \"bar\" }; var b = { foo: \"bar\", ...{} }; @@ -488,131 +460,80 @@ var c = { var d: { [key: string]: string } = { foo: \"bar\" }; var x = new Date(); var y = new Foo(); - takesAString(a.toString()); - d.toString(); - var aToString: () => string = a.toString; var aToString2 = a.toString; - takesAString(aToString2()); - b.toString = function(): string { return \"foo\"; }; - c.toString = function(): number { return 123; }; - var cToString: () => number = c.toString; var xToString: number = x.toString; var xToString2: () => number = x.toString; - takesAString(x.toString()); - var yToString: number = y.toString; - takesAString(y.toString()); - (123).toString(); - (123).toString; - (123).toString = function() {}; - (123).toString(2); - (123).toString(\"foo\"); - (123).toString(null); - takesABool(a.hasOwnProperty(\"foo\")); - var aHasOwnProperty: (prop: string) => boolean = a.hasOwnProperty; var aHasOwnProperty2 = a.hasOwnProperty; - takesABool(aHasOwnProperty2(\"bar\")); - b.hasOwnProperty = function() { return false; }; - var xHasOwnProperty: number = x.hasOwnProperty; var xHasOwnProperty2: (prop: string) => number = x.hasOwnProperty; - takesABool(x.hasOwnProperty(\"foo\")); - var yHasOwnProperty: number = y.hasOwnProperty; - takesABool(y.hasOwnProperty(\"foo\")); - takesABool(a.propertyIsEnumerable(\"foo\")); - var aPropertyIsEnumerable: (prop: string) => boolean = a.propertyIsEnumerable; var aPropertyIsEnumerable2 = a.propertyIsEnumerable; - takesABool(aPropertyIsEnumerable2(\"bar\")); - b.propertyIsEnumerable = function() { return false; }; - var xPropertyIsEnumerable: number = x.propertyIsEnumerable; var xPropertyIsEnumerable2: (prop: string) => number = x.propertyIsEnumerable; - takesABool(x.propertyIsEnumerable(\"foo\")); - var yPropertyIsEnumerable: number = y.propertyIsEnumerable; - takesABool(y.propertyIsEnumerable(\"foo\")); - takesAnObject(a.valueOf()); - var aValueOf: () => Object = a.valueOf; var aValueOf2 = a.valueOf; - takesAnObject(aValueOf2()); - b.valueOf = function() { return {}; }; - var xValueOf: number = x.valueOf; - takesANumber(x.valueOf()); - var yValueOf: number = y.valueOf; - takesAnObject(y.valueOf()); - var strValueOf: string = \"foo\".valueOf(); var numValueOf: number = (123).valueOf(); var boolValueOf: boolean = true.valueOf(); - takesAString(a.toLocaleString()); - var aToLocaleString: () => string = a.toLocaleString; var aToLocaleString2 = a.toLocaleString; - takesAString(aToLocaleString2()); - b.toLocaleString = function() { return \"derp\"; }; - var xToLocaleString: number = x.toLocaleString; var xToLocaleString2: () => number = x.toLocaleString; - takesAString(x.toLocaleString()); - var yToLocaleString: number = y.toLocaleString; - takesAString(y.toLocaleString()); - var k: Object = a.constructor; - (123).constructor; " `; diff --git a/tests/object_assign/__snapshots__/jsfmt.spec.js.snap b/tests/object_assign/__snapshots__/jsfmt.spec.js.snap index 2f03f748..ab008521 100644 --- a/tests/object_assign/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_assign/__snapshots__/jsfmt.spec.js.snap @@ -47,7 +47,6 @@ var Good = Object.assign({}, MyEventEmitter.prototype, { } }); var good: number = Good.foo(); - module.exports = { Bad: Bad, Good: Good }; " `; @@ -101,7 +100,6 @@ exports[`test apply.js 1`] = ` a: number, b: string }); - (Object.assign({}, ...[ { a: 1 }, { b: \"foo\" } ]): { a: number, b: string }); " `; @@ -115,9 +113,7 @@ Object.assign({a: \"foo\"}, 123); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ Object.assign(\"123\", { a: \"foo\" }); - Object.assign(123, { a: \"foo\" }); - Object.assign({ a: \"foo\" }, 123); " `; @@ -157,9 +153,7 @@ class MyReactThing extends React.Component { return this.props.foo; } } - ; - ; " `; diff --git a/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap b/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap index 5bf527a3..f9cd104d 100644 --- a/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap @@ -29,26 +29,16 @@ var xx : { x: number } = Object.freeze({ x: \"error\" }) // error // error var foo = Object.freeze({ bar: \"12345\" }); - foo.bar = \"23456\"; - Object.assign(foo, { bar: \"12345\" }); - var baz = { baz: 12345 }; var bliffl = Object.freeze({ bar: \"12345\", ...baz }); - bliffl.bar = \"23456\"; - bliffl.baz = 3456; - bliffl.corge; - bliffl.constructor = baz; - bliffl.toString = function() {}; - baz.baz = 0; - var x: number = Object.freeze(123); var xx: { x: number } = Object.freeze({ x: \"error\" }); " diff --git a/tests/object_is/__snapshots__/jsfmt.spec.js.snap b/tests/object_is/__snapshots__/jsfmt.spec.js.snap index 21d8110f..46b60832 100644 --- a/tests/object_is/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_is/__snapshots__/jsfmt.spec.js.snap @@ -23,34 +23,20 @@ var c: boolean = Object.is(\'a\'); var d: boolean = Object.is(\'a\', \'b\', \'c\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Object.is(1, 1); - Object.is(1, 2); - Object.is(1, {}); - Object.is(1, NaN); - Object.is(0, 0); - Object.is(0, -0); - Object.is(NaN, NaN); - Object.is({}, {}); - var emptyObject = {}; var emptyArray = []; - Object.is(emptyObject, emptyObject); - Object.is(emptyArray, emptyArray); - Object.is(emptyObject, emptyArray); - var squared = x => x * x; - Object.is(squared, squared); - var a: boolean = Object.is(\"a\", \"a\"); var b: string = Object.is(\"a\", \"a\"); var c: boolean = Object.is(\"a\"); diff --git a/tests/objects/__snapshots__/jsfmt.spec.js.snap b/tests/objects/__snapshots__/jsfmt.spec.js.snap index d0536eff..bd87fb09 100644 --- a/tests/objects/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objects/__snapshots__/jsfmt.spec.js.snap @@ -23,31 +23,18 @@ var z = Object(123); // error (next line makes this not match any signatures) // error // error (next line makes this not match any signatures) (Object({ foo: \"bar\" }): { foo: string }); - (Object(\"123\"): String); - (Object(123): Number); - (Object(true): Boolean); - (Object(null): {}); - (Object(undefined): {}); - (Object(void 0): {}); - (Object(undefined): Number); - var x = Object(null); - x.foo = \"bar\"; - var y = Object(\"123\"); - (y.charAt(0): string); - var z = Object(123); - (z.charAt(0): string); " `; @@ -86,31 +73,18 @@ y[\'bar\'] = \'abc\'; // error, property not found // error, property not found // error, prototype method is not a string var x: { \"123\": string, bar: string } = { \"123\": \"val\", bar: \"bar\" }; - (x.foo: string); - (x[\"foo\"]: string); - (x[123]: boolean); - (x.bar: boolean); - (x[\"123\"]: boolean); - x[\"123\"] = false; - x[123] = false; - x[\"foo\" + \"bar\"] = \"derp\"; - (x[\`foo\`]: string); - var y: { foo: string } = { foo: \"bar\" }; - y[\"foo\"] = 123; - y[\"bar\"] = \"abc\"; - (y[\"hasOwnProperty\"]: string); " `; @@ -160,20 +134,14 @@ function assign_then_widen() { // error: subsequent assignment might make glob.x a number // ok, by lvalue\'s given type var glob: { x: string } = { x: \"hey\" }; - function assign_then_alias() { var obj: { x: string | number }; - obj = { x: \"hey\" }; - glob = obj; } - function assign_then_widen() { var obj: { x: string | number }; - obj = { x: \"hey\" }; - obj.x = 10; } " diff --git a/tests/objmap/__snapshots__/jsfmt.spec.js.snap b/tests/objmap/__snapshots__/jsfmt.spec.js.snap index 8bb77647..36d1cec6 100644 --- a/tests/objmap/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objmap/__snapshots__/jsfmt.spec.js.snap @@ -25,14 +25,10 @@ promiseAllByKey({ declare function promiseAllByKey(o: O): Promise<$ObjMap>; declare function keyMirror(o: O): $ObjMapi(k: K) => K>; var o = keyMirror({ FOO: null, BAR: null }); - (o.FOO: \"FOO\"); - (o.FOO: \"BAR\"); - promiseAllByKey({ foo: Promise.resolve(0), bar: \"bar\" }).then(o => { (o.foo: string); - (o.bar: \"bar\"); }); " diff --git a/tests/optional/__snapshots__/jsfmt.spec.js.snap b/tests/optional/__snapshots__/jsfmt.spec.js.snap index bb7ef332..fc738e9b 100644 --- a/tests/optional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/optional/__snapshots__/jsfmt.spec.js.snap @@ -4,7 +4,6 @@ exports[`test client_optional.js 1`] = ` qux(0); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var qux = require(\"./optional\"); - qux(0); " `; @@ -28,7 +27,6 @@ class C { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function x(x: T = 0) {} - class C { x(x: T = 0) {} } @@ -107,43 +105,36 @@ function optionalNullable1(x: { y?: ?number }) { x.y++; } } - function optionalNullable2(x: { y?: ?number }) { if (x.y !== undefined && x.y !== null) { x.y++; } } - function optionalNullable3(x: { y?: ?number }) { if (!(x.y !== null && x.y !== undefined)) { x.y++; } } - function optionalNullable4(x: { y?: ?number }) { if (!(x.y !== undefined && x.y !== null)) { x.y++; } } - function optionalNullable5(x: { y?: ?number }) { if (x.y === null || x.y === undefined) { x.y++; } } - function optionalNullable6(x: { y?: ?number }) { if (x.y === undefined || x.y === null) { x.y++; } } - function optionalNullable7(x: { y?: ?number }) { if (!(x.y === null || x.y === undefined)) { x.y++; } } - function optionalNullable8(x: { y?: ?number }) { if (!(x.y === undefined || x.y === null)) { x.y++; @@ -169,23 +160,15 @@ module.exports = qux; function bar(x?, y?) { x * 0; } - bar(0); - var foo: (x?: number) => void = bar; - foo(); - function qux(x = \"hello\", ...y): string { foo(x); - return y[0]; } - qux(0, 0); - qux(0, ...[ \"\", 42 ]); - module.exports = qux; " `; @@ -232,53 +215,40 @@ function foo(x?: string): string { if (x == null) { return \"foo\"; } - return x; } - function bar(obj: { x?: string }): string { if (obj.x == null) { return \"foo\"; } - return obj.x; } - function baz(bar?) { if (!bar) { return 1; } - return bar.duck; } - function testOptionalNullable(x?: ?string): string { if (x == null) { return \"foo\"; } - return x; } - function testOptionalNullableDefault(x?: ?string = \"hi\"): string { if (x == null) { return \"foo\"; } - return x; } - function testOptionalNullableProperty(obj: { x?: ?string }): string { if (obj.x == null) { return \"foo\"; } - return obj.x; } - function testOptionalNullableFlowingToNullable(x?: ?string): ?string { var f = function(y: ?string) {}; - f(x); } " @@ -311,13 +281,10 @@ bar(undefined); // ok // ok // ok function foo(x?: number) {} - foo(undefined); - function bar(x = \"bar\"): string { return x; } - bar(undefined); " `; @@ -346,13 +313,9 @@ foo(123, true); // ERROR boolean ~> string function foo(x?: number, ...y: Array): [?number, Array] { return [ x, y ]; } - foo(); - foo(123), foo(123, \"hello\"); - foo(true); - foo(123, true); " `; @@ -369,11 +332,9 @@ function bar() { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x; - function foo(bar? = undefined) { x = bar; } - function bar() { return x.duck; } @@ -392,11 +353,9 @@ function bar() { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x; - function foo(bar?) { x = bar; } - function bar() { return x.duck; } diff --git a/tests/optional_props/__snapshots__/jsfmt.spec.js.snap b/tests/optional_props/__snapshots__/jsfmt.spec.js.snap index d40483dc..c8372b5c 100644 --- a/tests/optional_props/__snapshots__/jsfmt.spec.js.snap +++ b/tests/optional_props/__snapshots__/jsfmt.spec.js.snap @@ -19,15 +19,10 @@ var x: {} = { foo: 0 }; var y: { foo?: string } = x; var z: string = y.foo || \"\"; var o = {}; - y = o; - o.foo = 0; - function bar(config: { foo?: number }) {} - bar({}); - bar({ foo: \"\" }); " `; @@ -56,17 +51,11 @@ var f: { foo?: ?string } = { foo: null }; // Also fine // This is fine // Also fine var a: { foo?: string } = {}; - a.foo = undefined; - a.foo = null; - var b: { foo?: ?string } = {}; - b.foo = undefined; - b.foo = null; - var c: { foo?: string } = { foo: undefined }; var d: { foo?: string } = { foo: null }; var e: { foo?: ?string } = { foo: undefined }; @@ -174,16 +163,12 @@ class A { // annotation will be processed before the flow involving the // access. Here we lose the race and get an error on the write. var x: { a: number, b?: number } = { a: 0 }; - x = { a: 0 }; - x.b = 1; - class A { x: { a: number, b?: string }; foo() { this.x = { a: 123 }; - this.x.b = \"hello\"; } } @@ -207,7 +192,6 @@ class A { o: O; foo() { this.o.x = { a: 123 }; - this.o.x.b = \"hello\"; } } diff --git a/tests/overload/__snapshots__/jsfmt.spec.js.snap b/tests/overload/__snapshots__/jsfmt.spec.js.snap index 21ac6d47..0c5f378d 100644 --- a/tests/overload/__snapshots__/jsfmt.spec.js.snap +++ b/tests/overload/__snapshots__/jsfmt.spec.js.snap @@ -92,21 +92,13 @@ declare class C { bar(x: { a: string }): string } var a = new C(); - a.foo(0); - a.foo(\"hey\"); - a.foo(true); - a.bar({ a: 0 }); - a.bar({ a: \"hey\" }); - a.bar({ a: true }); - declare var x: { a: boolean } & { b: string }; - a.bar(x); " `; @@ -120,7 +112,6 @@ exports[`test test.js 1`] = ` // matches one of the overloads of set function foo() { var output = new FakeUint8Array(); - output.set(new FakeUint8Array(), 0); } " @@ -139,9 +130,7 @@ var foo = new Foo; // error declare class Foo { bar(x: \"hmm\"): number, bar(x: string): string } var foo = new Foo(); - (foo.bar(\"hmm\"): number); - (foo.bar(\"hmmm\"): number); " `; @@ -180,20 +169,15 @@ h(x_h.p); // ok declare function f(x: string): void; declare function f(x: number): void; declare var x_f: string | number; - f(x_f); - declare function g(x: null): void; declare function g(x: void): void; declare function g(x: string): void; declare var x_g: ?string; - g(x_g); - declare function h(x: void): void; declare function h(x: string): void; declare var x_h: { p?: string }; - h(x_h.p); " `; @@ -207,7 +191,6 @@ var x2:string = foo([\"\"])[0]; function foo(x: $Either, U>): Array { return []; } - var x1: number = foo(0)[0]; var x2: string = foo([ \"\" ])[0]; " diff --git a/tests/path/__snapshots__/jsfmt.spec.js.snap b/tests/path/__snapshots__/jsfmt.spec.js.snap index 7bf50bc1..2de635b6 100644 --- a/tests/path/__snapshots__/jsfmt.spec.js.snap +++ b/tests/path/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,6 @@ var z:number = x; var x = 1; while (typeof x == \"number\" || typeof x == \"string\") { x = x + 1; - if (true) x = \"\"; } diff --git a/tests/plsummit/__snapshots__/jsfmt.spec.js.snap b/tests/plsummit/__snapshots__/jsfmt.spec.js.snap index c41b3d2a..a20611cb 100644 --- a/tests/plsummit/__snapshots__/jsfmt.spec.js.snap +++ b/tests/plsummit/__snapshots__/jsfmt.spec.js.snap @@ -7,9 +7,7 @@ n * s.length; function foo(x) { return [ x, x > 0, \"number \" + x ]; } - var [ n, b, s ] = foo(42); - n * s.length; " `; @@ -28,7 +26,6 @@ class C { this.x = x; } } - module.exports = C; " `; @@ -41,10 +38,8 @@ function foo(x: X): X { r = x; return x; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var r: number = 0; - function foo(x: X): X { r = x; - return x; } " @@ -78,11 +73,9 @@ function foo() { var x = 0; var y = x; } - function bar(x: ?string): number { if (x == null) x = \"\"; - return x.length; } " @@ -106,27 +99,20 @@ var y: number = o2.bar(); function C() { this.x = 0; } - C.prototype.foo = function() { return this.x; }; - var c = new C(); var x: string = c.foo(); - function foo() { return this.y; } - function bar() { return this.foo(); } - var o = { y: \"\", foo: foo, bar: bar }; var o2 = { y: 0, foo: foo, bar: bar }; - o.bar(); - var y: number = o2.bar(); " `; diff --git a/tests/poly/__snapshots__/jsfmt.spec.js.snap b/tests/poly/__snapshots__/jsfmt.spec.js.snap index a4456d10..8393a1d1 100644 --- a/tests/poly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/poly/__snapshots__/jsfmt.spec.js.snap @@ -16,15 +16,11 @@ function bar(): A<*> { // error, * can\'t be {} and {x: string} at the same time // ok but unsafe, caller may assume any type arg // error, * can\'t be {} and {x: string} at the same time class A {} - new A(); - class B extends A {} - function foo(b): A { return b ? (new A(): A) : (new A(): A); } - function bar(): A<*> { return (new A(): A<{}>) || (new A(): A<{ x: string }>); } @@ -67,13 +63,9 @@ class C { } } var a: C<*> = new C(); - a.meth(new Middle()); - a.meth(new Child()); - a.meth(42); - a.meth(new Base()); " `; @@ -110,7 +102,6 @@ type Box = { }; declare var bool: Box; declare function unbox(box: Box): A; - unbox(bool); " `; @@ -141,11 +132,9 @@ class Foo { this.x = x; } } - function bar(foo: Foo, y: S): Foo { return new Foo(y); } - var P = { bar: bar }; declare var Q: { bar(foo: Foo, y: S): Foo }; var foo = new Foo(0); diff --git a/tests/poly_class_export/__snapshots__/jsfmt.spec.js.snap b/tests/poly_class_export/__snapshots__/jsfmt.spec.js.snap index 76725074..a34a5433 100644 --- a/tests/poly_class_export/__snapshots__/jsfmt.spec.js.snap +++ b/tests/poly_class_export/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,6 @@ module.exports = A; class A { x: T; } - module.exports = A; " `; @@ -36,7 +35,6 @@ class B extends A { super(); } } - module.exports = new B(); " `; diff --git a/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap index ce0c36c3..01ac8ec8 100644 --- a/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap @@ -21,9 +21,7 @@ declare function my_filter>( ): Array<$Refine>; declare var arr: Array; const barr = my_filter(arr, is_string); - (barr: Array); - function is_string(x): %checks { return typeof x === \"string\"; } @@ -63,9 +61,7 @@ type C = { kind: \"C\", y: boolean }; type D = { kind: \"D\", x: boolean }; type E = { kind: \"E\", y: boolean }; declare var ab: Array; - (my_filter(ab, (x): %checks => x.kind === \"A\"): Array); - (my_filter(ab, (x): %checks => x.kind !== \"A\"): Array); " `; @@ -141,9 +137,7 @@ function is_string_and_number(x, y): %checks { declare function refine>(v: T, cb: P): $Refine; declare var a: mixed; var b = refine(a, is_string); - (b: string); - declare function refine_fst>( v: T, w: T, @@ -152,15 +146,11 @@ declare function refine_fst>( declare var c: mixed; declare var d: mixed; var e = refine2(c, d, is_string_and_number); - (e: string); - declare function refine2>(v: T, w: T, cb: P): $Refine; - function is_string(x): boolean %checks { return typeof x === \"string\"; } - function is_string_and_number(x, y): %checks { return typeof x === \"string\" && typeof y === \"number\"; } @@ -200,18 +190,13 @@ declare function my_filter>( ): Array<$Refine>; declare var a: Array; const b = my_filter(a, is_string); - (b: Array); - declare var c: Array; const d = my_filter(c, is_string_regular); - (d: Array); - function is_string(x): boolean %checks { return typeof x === \"string\"; } - function is_string_regular(x): boolean { return typeof x === \"string\"; } @@ -251,9 +236,7 @@ type C = { kind: \"C\", y: boolean }; type D = { kind: \"D\", x: boolean }; type E = { kind: \"E\", y: boolean }; declare var ab: Array; - (my_filter(ab, (x): %checks => x.kind === \"A\"): Array); - (my_filter(ab, (x): %checks => x.kind !== \"A\"): Array); " `; @@ -316,9 +299,7 @@ function is_string_and_number(x, y): %checks { declare function refine>(v: T, cb: P): $Refine; declare var a: mixed; var b = refine(a, is_string); - (b: string); - declare var c: mixed; declare var d: mixed; declare var e: mixed; @@ -329,25 +310,18 @@ declare function refine3>( cb: P ): $Refine; var e = refine3(c, d, e, is_string_and_number); - (e: string); - function is_string_and_number(x, y): %checks { return typeof x === \"string\" && typeof y === \"number\"; } - var e = refine(a, is_string_regular); - (e: number); - function is_string(x): %checks { return typeof x === \"string\"; } - function is_string_regular(x) { return typeof x === \"string\"; } - function is_string_and_number(x, y): %checks { return typeof x === \"string\" && typeof y === \"number\"; } diff --git a/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap index 8c53d33b..3139419a 100644 --- a/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap @@ -59,11 +59,9 @@ class C { } declare var m: Function; const o = { a: 1 }; - if (m.bind(o)) { o.a; } - class D { m: Function; n() { @@ -72,7 +70,6 @@ class D { } declare var m: Function; const x = \"\"; - if (m.bind(this)(x)) {} " `; @@ -102,10 +99,8 @@ function foo(x: number | string | Array): number { declare function f1(x: mixed): boolean %checks(typeof x === \"string\"); declare function f2(x: mixed): boolean %checks(Array.isArray(x)); declare var cond: boolean; - function foo(x: number | string | Array): number { var f = cond ? f1 : f2; - if (f(x)) { return x.length; } else { @@ -144,7 +139,6 @@ function foo(x: string | Array): string { // guarantees that \`x\` here is an Array declare function is_string(x: mixed): boolean %checks(typeof x === \"string\"); declare function is_number(x: mixed): boolean %checks(typeof x === \"number\"); - function foo(x: string | Array): string { if (is_string(x)) { return x; @@ -186,23 +180,16 @@ function foo(x: mixed) { return 1; } declare function r(x: string): number; var s = \"a\"; var n = r(s) || 1; - (n: number); - var x = \"\"; - if (x = r(s) || 1) { (x: number); } - declare var dollars: mixed; - function foo(x: mixed) { return 1; } - foo(dollars) || 0; - Number(dollars) || 0; " `; @@ -238,14 +225,11 @@ function f(_this: { m: ?Meeting }): string { // - preserving \`havoc\` semantics type Meeting = { organizer: ?Invitee, es: Array }; type Invitee = { fbid: number }; - function f(_this: { m: ?Meeting }): string { if (!_this.m) { return \"0\"; } - if (_this.m.es.some(a => a.fbid === 0)) {} - return \"3\"; } " @@ -298,12 +282,10 @@ function foo(s: Array): string { // Sanity check: // - we should still be getting an error at the second return statement declare function pred(x: T): boolean; - function foo(s: Array): string { if (pred(s)) { return \"1\"; } - return 1; } " @@ -334,16 +316,13 @@ function foo(s: Array): string { // Sanity check: // - invalid calls at predicate positions declare function pred(x: T): boolean; - function foo(s: Array): string { if (1(s)) { return \"1\"; } - if ((pred + 1)(\"s\")) { return \"1\"; } - return \"1\"; } " @@ -372,7 +351,6 @@ function bar(x: string | Array): string { // error: both string and Array can flow to x declare function is_string(x: mixed): boolean %checks(typeof x === \"string\"); declare function is_number(x: mixed): boolean %checks(typeof x === \"number\"); - function bar(x: string | Array): string { if (is_number(x)) { return x; @@ -401,7 +379,6 @@ declare function foo( input: mixed, types: string | Array ): boolean %checks(typeof input === \"string\" || Array.isArray(input)); - foo(3, 3); " `; @@ -430,12 +407,10 @@ function foo(x: string | Array): string { function pred(x: mixed): boolean %checks(typeof x === \"string\") { return typeof x === \"string\"; } - function foo(x: string | Array): string { if (pred(x)) { return x; } - return \"1\"; } " diff --git a/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap index 780e4e56..8f85dd8f 100644 --- a/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap @@ -33,18 +33,14 @@ function bak(z: string | number): number { function check(y): %checks(typeof y === \"string\") { return typeof y === \"number\"; } - declare var y: number | boolean; - if (check(y)) { (y: number); } - function indirect_is_number(y): %checks { var y = 1; return typeof y === \"number\"; } - function bak(z: string | number): number { if (indirect_is_number(z)) { return z; @@ -76,7 +72,6 @@ function foo(x: string | Array): string { function multi_param(w, x, y, z): %checks { return typeof z === \"string\"; } - function foo(x: string | Array): string { if (multi_param(\"1\", \"2\", x, \"3\")) { return x; @@ -110,17 +105,14 @@ function dotAccess(head, create) { // @flow declare var key: string; declare var obj: { page: ?Object }; - if (dotAccess(obj)) { (obj.page: Object); } - function dotAccess(head, create) { const path = \"path.location\"; const stack = path.split(\".\"); do { const key = stack.shift(); - head = head[key] || create && (head[key] = {}); } while (stack.length && head); return head; @@ -151,11 +143,9 @@ function foo(x: string | Array): string { // Sanity check: this should fail, because the preficate function // checks \`y\` instead of \`x\`. declare var y: mixed; - function err(x): %checks { return typeof y === \"string\"; } - function foo(x: string | Array): string { if (err(x)) { return x; @@ -253,15 +243,12 @@ declare function from_two_strings(x: string, y: string): void; function is_string(y): %checks { return typeof y === \"string\"; } - function is_bool(y): %checks { return typeof y === \"boolean\"; } - function is_number(y): %checks { return typeof y === \"number\"; } - function foo(x: string | Array): string { if (is_string(x)) { return x; @@ -269,7 +256,6 @@ function foo(x: string | Array): string { return x.join(); } } - function bar(z: { f: string | Array }): string { if (is_string(z.f)) { return z.f; @@ -277,11 +263,9 @@ function bar(z: { f: string | Array }): string { return z.f.join(); } } - function is_number_or_bool(y): %checks { return is_number(y) || is_bool(y); } - function baz(z: string | number): number { if (is_number_or_bool(z)) { return z; @@ -289,11 +273,9 @@ function baz(z: string | number): number { return z.length; } } - function multi_param(w, x, y, z): %checks { return typeof z === \"string\"; } - function foo(x: string | Array): string { if (multi_param(\"1\", \"2\", \"3\", x)) { return x; @@ -301,17 +283,14 @@ function foo(x: string | Array): string { return x.join(); } } - function foo(a, b) { if (two_strings(a, b)) { from_two_strings(a, b); } } - function two_strings(x, y): %checks { return is_string(x) && is_string(y); } - declare function from_two_strings(x: string, y: string): void; " `; @@ -354,7 +333,6 @@ function foo(x: string | Array): string { return x.join(); } } - function is_string(x): %checks { return typeof x === \"string\"; } diff --git a/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap index 16757c5a..a0ef58a3 100644 --- a/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap @@ -54,7 +54,6 @@ var a2 = (x: mixed): %checks (x !== null) => x !== null; function f5(x: mixed): %checks(x !== null) { return x !== null; } - var a2 = (x: mixed): %checks(x !== null) => x !== null; " `; @@ -92,28 +91,20 @@ declare function f(x: mixed): checks declare function f1(x: mixed): boolean; declare function f3(x: mixed): boolean %checks(x !== null); declare function f4(x: mixed): boolean %checks(x !== null); - function f7(x: mixed): %checks { return x !== null; } - var a0 = (x: mixed) => x !== null; var a1 = (x: mixed): %checks => x !== null; - (x): %checks => x !== null; - const insert_a_really_big_predicated_arrow_function_name_here = ( x ): %checks => x !== null; declare var x; - x; - checks => 123; - type checks = any; declare function f(x: mixed): checks; - typeof x === null; " `; diff --git a/tests/private/__snapshots__/jsfmt.spec.js.snap b/tests/private/__snapshots__/jsfmt.spec.js.snap index 805c600d..fbef504c 100644 --- a/tests/private/__snapshots__/jsfmt.spec.js.snap +++ b/tests/private/__snapshots__/jsfmt.spec.js.snap @@ -20,9 +20,7 @@ class A { __x: number; constructor() { this.x = 0; - this._x = \"\"; - this.__x = 0; } } diff --git a/tests/promises/__snapshots__/jsfmt.spec.js.snap b/tests/promises/__snapshots__/jsfmt.spec.js.snap index 530fc733..00a1adbd 100644 --- a/tests/promises/__snapshots__/jsfmt.spec.js.snap +++ b/tests/promises/__snapshots__/jsfmt.spec.js.snap @@ -55,31 +55,21 @@ function tes2(val: Map>) { // Promise.all supports iterables declare var pstr: Promise; declare var pnum: Promise; - Promise.all([ pstr, pnum, true ]).then(xs => { let [ a, b, c ] = xs; - (a: number); - (b: boolean); - (c: string); - xs.forEach(x => { (x: void); }); }); - Promise.all(); - Promise.all(0); - (Promise.all: Function); - function test(val: Iterable>) { const r: Promise> = Promise.all(val); } - function tes2(val: Map>) { const r: Promise> = Promise.all(val.values()); } @@ -113,7 +103,6 @@ async function testAll() { const y: Promise> = Promise.all(x); const z: Array = await y; } - async function testRace() { const x: Array> = []; const y: Promise = Promise.race(x); @@ -430,12 +419,10 @@ new Promise(function(resolve, reject) { var a: number = num; var b: string = num; }); - new Promise((resolve, reject) => resolve(0)).then(function(num) { var a: number = num; var b: string = num; }); - new Promise(function(resolve, reject) { resolve(new Promise(function(resolve, reject) { resolve(0); @@ -444,7 +431,6 @@ new Promise(function(resolve, reject) { var a: number = num; var b: string = num; }); - new Promise(function(resolve, reject) { resolve(new Promise(function(resolve, reject) { resolve(new Promise(function(resolve, reject) { @@ -455,7 +441,6 @@ new Promise(function(resolve, reject) { var a: number = num; var b: string = num; }); - new Promise(function(resolve, reject) { if (Math.random()) { resolve(42); @@ -468,17 +453,14 @@ new Promise(function(resolve, reject) { } else { var b: number = numOrStr; } - var c: string = numOrStr; }); - new Promise(function(resolve, reject) { reject(0); }).catch(function(num) { var a: number = num; var b: string = num; }); - new Promise(function(resolve, reject) { reject(new Promise(function(resolve, reject) { reject(0); @@ -487,7 +469,6 @@ new Promise(function(resolve, reject) { var a: Promise = num; var b: number = num; }); - new Promise(function(resolve, reject) { if (Math.random()) { reject(42); @@ -500,35 +481,28 @@ new Promise(function(resolve, reject) { } else { var b: number = numOrStr; } - var c: string = numOrStr; }); - Promise.resolve(0).then(function(num) { var a: number = num; var b: string = num; }); - Promise.resolve(Promise.resolve(0)).then(function(num) { var a: number = num; var b: string = num; }); - Promise.resolve(Promise.resolve(Promise.resolve(0))).then(function(num) { var a: number = num; var b: string = num; }); - Promise.reject(0).catch(function(num) { var a: number = num; var b: string = num; }); - Promise.reject(Promise.resolve(0)).then(function(num) { var a: Promise = num; var b: number = num; }); - Promise .resolve(0) .then(function(num) { @@ -538,7 +512,6 @@ Promise var a: string = str; var b: number = str; }); - Promise .resolve(0) .then(function(num) { @@ -548,7 +521,6 @@ Promise var a: string = str; var b: number = str; }); - Promise .resolve(0) .then(function(num) { @@ -558,7 +530,6 @@ Promise var a: string = str; var b: number = str; }); - Promise .resolve(0) .then(function(num) { @@ -568,7 +539,6 @@ Promise var a: string = str; var b: number = str; }); - Promise .reject(0) .catch(function(num) { @@ -578,7 +548,6 @@ Promise var a: string = str; var b: number = str; }); - Promise .reject(0) .catch(function(num) { @@ -588,7 +557,6 @@ Promise var a: string = str; var b: number = str; }); - Promise .reject(0) .catch(function(num) { @@ -598,7 +566,6 @@ Promise var a: string = str; var b: number = str; }); - Promise .resolve(0) .catch(function(err) {}) @@ -669,7 +636,6 @@ async function baz(): Promise { // error: \`Promise\` in return expr is the local binding // error: return type anno is a ref to the local binding class Promise {} - async function foo(x: boolean) { if (x) { return { bar: \"baz\" }; @@ -677,19 +643,14 @@ async function foo(x: boolean) { return null; } } - async function run() { console.log(await foo(true)); - console.log(await foo(false)); } - run(); - async function bar() { return Promise.resolve(0); } - async function baz(): Promise { return 0; } @@ -707,7 +668,6 @@ exports[`test resolve_void.js 1`] = ` // error // error (Promise.resolve(): Promise); - (Promise.resolve(undefined): Promise); " `; diff --git a/tests/pure_component/__snapshots__/jsfmt.spec.js.snap b/tests/pure_component/__snapshots__/jsfmt.spec.js.snap index af656e82..8c898746 100644 --- a/tests/pure_component/__snapshots__/jsfmt.spec.js.snap +++ b/tests/pure_component/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,6 @@ var React = require(\"react\"); class C extends React.PureComponent { props: { x: number }; } - ; " `; diff --git a/tests/react/__snapshots__/jsfmt.spec.js.snap b/tests/react/__snapshots__/jsfmt.spec.js.snap index ffeecb47..41f8cc68 100644 --- a/tests/react/__snapshots__/jsfmt.spec.js.snap +++ b/tests/react/__snapshots__/jsfmt.spec.js.snap @@ -20,7 +20,6 @@ var AudienceInsightsContainer = React.createClass({ return ; } }); - module.exports = AudienceInsightsContainer; " `; diff --git a/tests/react_functional/__snapshots__/jsfmt.spec.js.snap b/tests/react_functional/__snapshots__/jsfmt.spec.js.snap index 3eaf4daa..24592167 100644 --- a/tests/react_functional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/react_functional/__snapshots__/jsfmt.spec.js.snap @@ -20,21 +20,13 @@ var Z = 0; // ok // error, expected React component import React from \"react\"; - function F(props: { foo: string }) {} - ; - ; - ; - function G(props: { foo: string | numner }) {} - ; - var Z = 0; - ; " `; diff --git a/tests/react_modules/__snapshots__/jsfmt.spec.js.snap b/tests/react_modules/__snapshots__/jsfmt.spec.js.snap index 06a72f33..061e9dcf 100644 --- a/tests/react_modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/react_modules/__snapshots__/jsfmt.spec.js.snap @@ -45,7 +45,6 @@ var Callsite = React.createClass({ ); } }); - module.exports = Callsite; " `; @@ -74,7 +73,6 @@ var Hello = React.createClass({ return
{this.props.name}
; } }); - module.exports = Hello; " `; @@ -127,7 +125,6 @@ class Callsite extends React.Component { ); } } - module.exports = Callsite; " `; @@ -159,7 +156,6 @@ class Hello extends React.Component<{}, Props, void> { return
{this.props.name}
; } } - module.exports = Hello; " `; diff --git a/tests/rec/__snapshots__/jsfmt.spec.js.snap b/tests/rec/__snapshots__/jsfmt.spec.js.snap index 58fec505..23e1dcda 100644 --- a/tests/rec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/rec/__snapshots__/jsfmt.spec.js.snap @@ -22,23 +22,17 @@ function identity
(val: A): Functor { /* @flow */ type F = { foo(x: A): F }; declare function foo(x: any): F; - ({ foo }: F); - function bar(y: F): F { return y; } - function bar1(y: F): F { return y; } - function bar2(y: F): F { return y; } - type Functor = { map(f: (val: A) => B): Functor }; - function identity(val: A): Functor { return { map(f: (_: typeof val) => B): Functor { @@ -65,7 +59,6 @@ type Task = { next: (input: value) => Task ): Task }; - function id(x: Task): Task { return x; } @@ -105,19 +98,12 @@ class P { } type Pstar = X | Pstar>; var p: P = new P(); - (p.x: string); - var pstar: Pstar = 0; - (pstar: number); - pstar = p; - (pstar.x: string); - pstar = (new P(): P>); - (pstar.x: string); " `; @@ -167,31 +153,24 @@ class C extends B { } // Both S> and S<*> expand to { y: { y: ... }}. // error: number ~/~ string var a = []; - function bar() { a = a.concat([]); } - class A { x: A>; } var a_ = new A(); - function foo0() { a_ = a_.x; } - type T = { y: S }; type S = T>; - function foo1(b: S<*>) { b = b.y; } - class D {} class B extends D {} class C extends B {} - ((new C(): C): D); " `; @@ -221,14 +200,11 @@ function bar(x: P): () => P { // () => P = () => () => { x: P } type I = () => I>; type J = () => J>; - function foo(x: I): J { return x; } - type Q = { x: X }; type P = () => Q>; - function bar(x: P): () => P { return x; } @@ -257,7 +233,6 @@ function flatten(arrArg: NestedArray) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ type NestedArray = Array>; - function flatten(arrArg: NestedArray) { let arr = arrArg; while (true) { diff --git a/tests/recheck/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/__snapshots__/jsfmt.spec.js.snap index cadb75bc..ecdb2395 100644 --- a/tests/recheck/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/__snapshots__/jsfmt.spec.js.snap @@ -11,9 +11,7 @@ module.exports = foo; function foo(x: number): string { return 5; } - foo(0); - module.exports = foo; " `; @@ -27,7 +25,6 @@ module.exports = foo(\"\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow const foo = require(\"./a1\"); - module.exports = foo(\"\"); " `; @@ -41,7 +38,6 @@ const five = require(\'./a2\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow const five = require(\"./a2\"); - (five + five: string); " `; @@ -61,7 +57,6 @@ class C { class E { x: C; } - module.exports = { C, E }; " `; @@ -79,19 +74,15 @@ module.exports = { C, D }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import {C, E} from \"./b0\"; - function foo() { return C; } - function bar() { return E; } - let X = foo(); class F extends X {} class D extends F {} - module.exports = { C, D }; " `; @@ -115,7 +106,6 @@ import { C, D } from \"./b2\"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import {C, D} from \"./b2\"; - (new D(): C); " `; @@ -156,7 +146,6 @@ bar({ x: 0 }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import {bar} from \"./c2\"; - bar({ x: 0 }); " `; @@ -222,7 +211,6 @@ const f = (): Action => { return { type: \"FOO\" }; }; import {LIFE} from \"./e1\"; - (LIFE: 42); " `; @@ -245,7 +233,6 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: T; - module.exports = { a, b, c }; " `; @@ -258,7 +245,6 @@ var { a, b, c } = require(\'./f1\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var { a, b, c } = require(\"./f1\"); - (c: { x: number }); " `; @@ -285,7 +271,6 @@ module.exports = { D }; // @flow import {C} from \"./g1\"; class D extends C {} - module.exports = { D }; " `; @@ -301,7 +286,6 @@ import { D } from \'./g2\'; // @flow import {C} from \"./g1\"; import {D} from \"./g2\"; - (new D(): C); " `; diff --git a/tests/recheck/tmp1a/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp1a/__snapshots__/jsfmt.spec.js.snap index 6b838f34..66ae79e5 100644 --- a/tests/recheck/tmp1a/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp1a/__snapshots__/jsfmt.spec.js.snap @@ -11,9 +11,7 @@ module.exports = foo; function foo(x: number): number { return 5; } - foo(0); - module.exports = foo; " `; diff --git a/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap index b28ad5d1..179bc75d 100644 --- a/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap @@ -11,19 +11,15 @@ module.exports = { C, D }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import {C, E} from \"./b0\"; - function foo() { return C; } - function bar() { return E; } - let X = bar(); class F extends X {} class D extends F {} - module.exports = { C, D }; " `; diff --git a/tests/recheck/tmp1e/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp1e/__snapshots__/jsfmt.spec.js.snap index bf0ffa70..c47943ef 100644 --- a/tests/recheck/tmp1e/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp1e/__snapshots__/jsfmt.spec.js.snap @@ -17,7 +17,6 @@ const f = (): Action => { return { type: \"QUX\" }; }; import {LIFE} from \"./e1\"; - (LIFE: 42); " `; diff --git a/tests/recheck/tmp1f/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp1f/__snapshots__/jsfmt.spec.js.snap index 8fc7eff8..67d680d1 100644 --- a/tests/recheck/tmp1f/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp1f/__snapshots__/jsfmt.spec.js.snap @@ -16,7 +16,6 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: S; - module.exports = { a, b, c }; " `; diff --git a/tests/recheck/tmp2a/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp2a/__snapshots__/jsfmt.spec.js.snap index d04b23f4..53e7ab99 100644 --- a/tests/recheck/tmp2a/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp2a/__snapshots__/jsfmt.spec.js.snap @@ -11,9 +11,7 @@ module.exports = foo; function foo(x: number): number { return 5; } - foo(\"\"); - module.exports = foo; " `; diff --git a/tests/recheck/tmp2b/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp2b/__snapshots__/jsfmt.spec.js.snap index 5c9820b9..66607eac 100644 --- a/tests/recheck/tmp2b/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp2b/__snapshots__/jsfmt.spec.js.snap @@ -13,7 +13,6 @@ class C { class E extends C { x: C; } - module.exports = { C, E }; " `; diff --git a/tests/recheck/tmp2f/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp2f/__snapshots__/jsfmt.spec.js.snap index 66d9e0ad..a0e8a11d 100644 --- a/tests/recheck/tmp2f/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp2f/__snapshots__/jsfmt.spec.js.snap @@ -16,7 +16,6 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: T; - module.exports = { a, b, c }; " `; diff --git a/tests/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap index 5cc14fef..75120088 100644 --- a/tests/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap @@ -33,7 +33,6 @@ const f = (): Action => { return { type: \"QUX\" }; }; import {LIFE} from \"./e1\"; - (LIFE: 0); " `; diff --git a/tests/recheck/tmp3f/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp3f/__snapshots__/jsfmt.spec.js.snap index aa5165df..a5b3f715 100644 --- a/tests/recheck/tmp3f/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp3f/__snapshots__/jsfmt.spec.js.snap @@ -16,7 +16,6 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: T; - module.exports = { a, b, c: a }; " `; diff --git a/tests/recheck/tmp4f/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp4f/__snapshots__/jsfmt.spec.js.snap index 287d23f1..d65ea4c7 100644 --- a/tests/recheck/tmp4f/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp4f/__snapshots__/jsfmt.spec.js.snap @@ -16,7 +16,6 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: T; - module.exports = { a, b, c: b }; " `; diff --git a/tests/record/__snapshots__/jsfmt.spec.js.snap b/tests/record/__snapshots__/jsfmt.spec.js.snap index 19a3c59e..3c34fd98 100644 --- a/tests/record/__snapshots__/jsfmt.spec.js.snap +++ b/tests/record/__snapshots__/jsfmt.spec.js.snap @@ -37,21 +37,14 @@ var o3: {[key: AnyKey]: number} = { foo: 0 }; // error: qux not found type Key1 = \"foo\" | \"bar\"; var o1: { [key: Key1]: number } = { foo: 0, bar: \"\" }; - o1.foo; - o1.qux; - o1.toString(); - type R = { foo: any, bar: any }; type Key2 = $Keys; var o2: { [key: Key2]: number } = { foo: 0 }; - o2.bar; - o2.qux; - class C { x: $Subtype<{ [key: $Keys]: any }>; } diff --git a/tests/refi/__snapshots__/jsfmt.spec.js.snap b/tests/refi/__snapshots__/jsfmt.spec.js.snap index c1f28f89..b36a96bb 100644 --- a/tests/refi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/refi/__snapshots__/jsfmt.spec.js.snap @@ -103,7 +103,6 @@ var tests = [ function() { if (x == null) return; - var y: string = x; }, function() { @@ -114,7 +113,6 @@ var tests = [ }, function() { if (x != null) {} - var y: string = x; }, function() { @@ -413,14 +411,12 @@ var tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p != null) { var y: string = x.p; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p == null) {} else { var y: string = x.p; @@ -428,15 +424,12 @@ var tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p == null) return; - var y: string = x.p; }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (!(x.p != null)) {} else { var y: string = x.p; @@ -444,32 +437,25 @@ var tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p != null) { alert(\"\"); - var y: string = x.p; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p != null) { x.p = null; - var y: string = x.p; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p != null) {} - var y: string = x.p; }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p != null) {} else { var y: string = x.p; @@ -485,7 +471,6 @@ var tests = [ }, function() { var x: { p: string | string[] } = { p: [ \"xxx\" ] }; - if (Array.isArray(x.p)) { var y: string[] = x.p; } else { @@ -494,163 +479,127 @@ var tests = [ }, function() { var x: { y: ?string } = { y: null }; - if (!x.y) { x.y = \"foo\"; } - (x.y: string); }, function() { var x: { y: ?string } = { y: null }; - if (x.y) {} else { x.y = \"foo\"; } - (x.y: string); }, function() { var x: { y: ?string } = { y: null }; - if (!x.y) { x.y = 123; } - (x.y: string); }, function() { var x: { y: ?string } = { y: null }; - if (x.y) { x.y = \"foo\"; } else { x.y = \"bar\"; } - (x.y: string); }, function() { var x: { y: string | number | boolean } = { y: false }; - if (typeof x.y == \"number\") { x.y = \"foo\"; } - (x.y: string); }, function() { var x: { y: string | number | boolean } = { y: false }; - if (typeof x.y == \"number\") { x.y = \"foo\"; } else if (typeof x.y == \"boolean\") { x.y = \"bar\"; } - (x.y: boolean); }, function() { var x: { y: ?string } = { y: null }; - if (!x.y) { x.y = \"foo\"; } - if (x.y) { x.y = null; } - (x.y: string); }, function() { var x: { y: string | number | boolean } = { y: false }; - if (typeof x.y == \"number\") { x.y = \"foo\"; } - if (typeof x.y == \"string\") { x.y = false; } - (x.y: string); }, function() { var x: { y: string | number | boolean } = { y: false }; - if (typeof x.y == \"number\") { x.y = \"foo\"; } - if (typeof x.y == \"string\") { x.y = 123; } - (x.y: string); }, function() { var x: { y: ?string } = { y: null }; var z: string = \"foo\"; - if (x.y) { x.y = z; } else { x.y = z; } - (x.y: string); }, function(x: string) { if (x === \"a\") {} - (x: \"b\"); }, function(x: mixed) { if (typeof x.bar === \"string\") {} - (x: string & number); }, function() { let x: { foo: ?string } = { foo: null }; - if (!x.foo) { if (false) {} - x.foo = \"foo\"; } - (x.foo: string); }, function() { let x: { foo: ?string } = { foo: null }; - if (!x.foo) { while (false) {} - x.foo = \"foo\"; } - (x.foo: string); }, function() { let x: { foo: ?string } = { foo: null }; - if (!x.foo) { for (var i = 0; i < 0; i++) {} - x.foo = \"foo\"; } - (x.foo: string); }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p != null) { var { p } = x; - (p: string); } } @@ -709,46 +658,34 @@ function try_scope_catch(x: string | number) { function block_scope(x: string | number) { { let x; - x = \"\"; } - (x: string); } - function switch_scope(x: string | number) { switch (x) { default: let x; - x = \"\"; - } - (x: string); } - function try_scope(x: string | number) { try { let x; - x = \"\"; } catch (e) { x = \"\"; } - (x: string); } - function try_scope_catch(x: string | number) { try { x = \"\"; } catch (e) { let x; - x = \"\"; } - (x: string); } " @@ -859,14 +796,12 @@ var paths = [ }, function() { var x: ?string = \"xxx\"; - if (x != null) { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - if (x == null) {} else { var y: string = x; @@ -874,15 +809,12 @@ var paths = [ }, function() { var x: ?string = \"xxx\"; - if (x == null) return; - var y: string = x; }, function() { var x: ?string = \"xxx\"; - if (!(x != null)) {} else { var y: string = x; @@ -890,23 +822,18 @@ var paths = [ }, function() { var x: ?string = \"xxx\"; - if (x != null) { alert(\"\"); - var y: string = x; } }, function() { var x: ?string = \"xxx\"; - if (x != null) {} - var y: string = x; }, function() { var x: ?string = \"xxx\"; - if (x != null) {} else { var y: string = x; @@ -922,7 +849,6 @@ var paths = [ }, function() { var x: string | string[] = [ \"xxx\" ]; - if (Array.isArray(x)) { var y: string[] = x; } else { @@ -931,11 +857,9 @@ var paths = [ }, function() { var x: ?string = null; - if (!x) { x = \"xxx\"; } - var y: string = x; } ]; @@ -1121,35 +1045,30 @@ class D extends C { var null_tests = [ function() { var x: ?string = \"xxx\"; - if (x != null) { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - if (null != x) { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p != null) { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q != null) { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - if (x == null) {} else { var y: string = x; @@ -1157,7 +1076,6 @@ var null_tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p == null) {} else { var y: string = x.p; @@ -1165,7 +1083,6 @@ var null_tests = [ }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q == null) {} else { var y: string = x.p.q; @@ -1173,28 +1090,24 @@ var null_tests = [ }, function() { var x: ?string = \"xxx\"; - if (x !== null) { var y: string | void = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p !== null) { var y: string | void = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q !== null) { var y: string | void = x.p.q; } }, function() { var x: ?string = \"xxx\"; - if (x === null) {} else { var y: string | void = x; @@ -1202,7 +1115,6 @@ var null_tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p === null) {} else { var y: string | void = x.p; @@ -1210,7 +1122,6 @@ var null_tests = [ }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q === null) {} else { var y: string | void = x.p.q; @@ -1228,7 +1139,6 @@ class C { ensure1(): string { if (this.p == null) return \"\"; - return this.p; } ensure2(): string | void { @@ -1240,7 +1150,6 @@ class C { ensure3(): string | void { if (this.p === null) return \"\"; - return this.p; } } @@ -1260,10 +1169,8 @@ class D extends C { ensure103(): string { if (super.p != null) { alert(\"\"); - return super.p; } - return \"\"; } } @@ -1363,50 +1270,39 @@ function foo(a, b, c) { return; } } - function exhaustion1(x): number { var foo; switch (x) { case 0: case 1: - foo = 3; - break; default: throw new Error(\"Invalid state\"); } return foo; } - function exhaustion2(x, y): number { var foo; switch (x) { case 0: - if (y) { break; } - case 1: - foo = 3; - break; default: throw new Error(\"Invalid state\"); } return foo; } - function exhaustion3(x): number { let foo = null; switch (x) { case 0: case 1: - foo = 3; - break; default: throw new Error(\"Invalid state\"); @@ -1569,35 +1465,30 @@ class A { var null_tests = [ function() { var x: ?string = \"xxx\"; - if (typeof x == \"string\") { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - if (\"string\" == typeof x) { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (typeof x.p == \"string\") { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (typeof x.p.q == \"string\") { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - if (typeof x != \"string\") {} else { var y: string = x; @@ -1605,7 +1496,6 @@ var null_tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (typeof x.p != \"string\") {} else { var y: string = x.p; @@ -1613,7 +1503,6 @@ var null_tests = [ }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (typeof x.p.q != \"string\") {} else { var y: string = x.p.q; @@ -1621,28 +1510,24 @@ var null_tests = [ }, function() { var x: ?string = \"xxx\"; - if (typeof x === \"string\") { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (typeof x.p === \"string\") { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (typeof x.p.q === \"string\") { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - if (typeof x !== \"string\") {} else { var y: string = x; @@ -1650,7 +1535,6 @@ var null_tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (typeof x.p !== \"string\") {} else { var y: string = x.p; @@ -1658,7 +1542,6 @@ var null_tests = [ }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (typeof x.p.q !== \"string\") {} else { var y: string = x.p.q; @@ -1785,35 +1668,30 @@ class A { var undef_tests = [ function() { var x: ?string = \"xxx\"; - if (x !== undefined && x !== null) { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - if (undefined !== x && x !== null) { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p !== undefined && x.p !== null) { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q !== undefined && x.p.q !== null) { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - if (x === undefined || x === null) {} else { var y: string = x; @@ -1821,7 +1699,6 @@ var undef_tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p === undefined || x.p === null) {} else { var y: string = x.p; @@ -1829,7 +1706,6 @@ var undef_tests = [ }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q === undefined || x.p.q === null) {} else { var y: string = x.p.q; @@ -1944,35 +1820,30 @@ class A { var void_tests = [ function() { var x: ?string = \"xxx\"; - if (x !== void 0 && x !== null) { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - if (void 0 !== x && x !== null) { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p !== void 0 && x.p !== null) { var y: string | void = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q !== void 0 && x.p.q !== null) { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - if (x === void 0 || x === null) {} else { var y: string = x; @@ -1980,7 +1851,6 @@ var void_tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p === void 0 || x.p === null) {} else { var y: string = x.p; @@ -1988,7 +1858,6 @@ var void_tests = [ }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q === void 0 || x.p.q === null) {} else { var y: string = x.p.q; diff --git a/tests/refinements/__snapshots__/jsfmt.spec.js.snap b/tests/refinements/__snapshots__/jsfmt.spec.js.snap index c6edf4e6..b335d4a3 100644 --- a/tests/refinements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/refinements/__snapshots__/jsfmt.spec.js.snap @@ -37,26 +37,21 @@ function bar2(x : Bar) { // x.parent might be null function foo(x: ?number) { var y; - if (y = x) { var z = y * 1000; } } - type Bar = { parent: ?Bar, doStuff(): void }; - function bar0(x: Bar) { while (x = x.parent) { x.doStuff(); } } - function bar1(x: ?Bar) { while (x = x.parent) { x.doStuff(); } } - function bar2(x: Bar) { var y = x; while (y = y.parent) { @@ -142,14 +137,11 @@ function foo(x: ?boolean) { if (x === false) { return; } - if (x === true) { return; } - x[0]; } - function bar(x: ?boolean) { if (x !== true) { if (x !== false) { @@ -157,30 +149,25 @@ function bar(x: ?boolean) { } } } - function baz(x: ?boolean) { if (100 * false) { return; } - if (false * 100) { return; } } - let tests = [ function(x: { done: true, result: string } | { done: false }) { if (x.done === true) { return x.result; } - return x.result; }, function(x: { done: true, result: string } | { done: false }) { if (true === x.done) { return x.result; } - return x.result; } ]; @@ -210,15 +197,12 @@ function testLiteralProperty(a: A) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow type A = { \"b_c\": ?string }; - function stuff(str: string) {} - function testProperty(a: A) { if (a.b_c) { stuff(a.b_c); } } - function testLiteralProperty(a: A) { if (a[\"b_c\"]) { stuff(a[\"b_c\"]); @@ -298,32 +282,26 @@ type Name = { kind: \"Name\", value: string, type: void }; type ListType = { kind: \"ListType\", type: Type }; type NonNullType = { kind: \"NonNullType\", type: Name | ListType | BadType }; type BadType = {}; - function getTypeASTName(typeAST: Type): string { if (!typeAST.type) throw new Error(\"Must be wrapping type\"); - return getTypeASTName(typeAST.type); } - let tests = [ function(x: { done: true, result: string } | { done: false }) { if (x.done) { return x.result; } - return x.result; }, function(x: { done: true, result: string } | { foo: string }) { if (x.done) { return x.result; } - return x.result; }, function() { type T = { foo: Object, bar: string } | { baz: string, quux: string }; - function testAlwaysTruthyProp(t: T) { if (t.foo) { (t.bar: string); @@ -331,7 +309,6 @@ let tests = [ (t.quux: string); } } - function testSometimesTruthyProp(t: T) { if (t.bar) { (t.foo: Object); @@ -391,12 +368,10 @@ let tests = [ let tests = [ function(x: string, y: number) { if (x == y) {} - if (x === y) {} }, function(x: string) { if (x == undefined) {} - if (x == void 0) {} }, function(x: string) { @@ -404,7 +379,6 @@ let tests = [ }, function(x: { y: \"foo\" } | { y: \"bar\" }) { if (x.y == 123) {} - if (x.y === 123) {} } ]; @@ -429,15 +403,12 @@ function foo2(x: ?Class): string { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare class Foo { foo: string } - function foo0(x: ?string): string { return x && x || \"\"; } - function foo1(x: ?Foo): string { return x && x.foo || \"\"; } - function foo2(x: ?Class): string { return x && new x().foo || \"\"; } @@ -505,23 +476,18 @@ function bar(x:Object) { // also treated as \`any\`, so allowed function foo(x: { y?: () => void }) { x.y(); - if (x.hasOwnProperty(\"y\")) { x.y(); } - if (x.hasOwnProperty(\"z\")) { x.z(); } } - function bar(x: Object) { x.y(); - if (x.hasOwnProperty(\"y\")) { x.y(); } - if (x.hasOwnProperty(\"z\")) { x.z(); } @@ -651,97 +617,68 @@ function def_assign_setprop_nohavoc(obj: Obj, obj2: Obj2) { // doesn\'t clear refi of .p // still ok type Obj = { p: number | string }; - function f() {} - function def_assign_function_havoc(obj: Obj) { obj.p = 10; - f(); - var x: number = obj.p; } - function def_assign_setprop_havoc(obj: Obj, obj2: Obj) { obj.p = 10; - obj2.p = \"hey\"; - var x: number = obj.p; } - function def_assign_index_havoc(obj: Obj, obj2: Obj) { obj.p = 10; - obj2[\"p\"] = \"hey\"; - var x: number = obj.p; } - function def_assign_within_if(b: boolean, obj: Obj) { if (b) { obj.p = 10; - var x: number = obj.p; } - var y: number = obj.p; } - function def_assign_within_while(b: boolean, obj: Obj) { while (b) { obj.p = 10; - var x: number = obj.p; } var y: number = obj.p; } - function def_assign_within_do(b: boolean, obj: Obj) { do { obj.p = 10; - var x: number = obj.p; } while (b); var y: number = obj.p; } - function def_assign_within_try(b: boolean, obj: Obj) { obj.p = 10; - try { f(); - obj.p = \"hey\"; } catch (e) { f(); - obj.p = \"hey\"; } finally { var y: number = obj.p; - obj.p = 42; } var z: string = obj.p; } - function def_assign_within_for(b: boolean, obj: Obj) { for (; b; ) { obj.p = 10; - var x: number = obj.p; } - var z: number = obj.p; } - type Obj2 = { q: number | string }; - function def_assign_setprop_nohavoc(obj: Obj, obj2: Obj2) { obj.p = 10; - obj2.q = \"hey\"; - var x: number = obj.p; } " @@ -828,17 +765,14 @@ function foo1(o: { x: number }) { o.x; } } - function foo2(o: { x: number }) { if (o.p2) { o.p2.x; } } - function foo3(o: { x: number }) { o.p3.x; } - function foo4(o: $Exact<{ x: number }>) { if (o.p4) { o.p4.x; @@ -846,38 +780,27 @@ function foo4(o: $Exact<{ x: number }>) { o.p4.x; } } - function foo5() { const o = {}; - _foo5(); - if (o.p) { o.p(); } - function _foo5() { o.p = function() {}; } } - function foo6(o: mixed) { if (o.bar) {} } - function foo7(o: mixed) { if (typeof o.bar === \"string\") {} - if (o && typeof o.bar === \"string\") {} - if (o != null && typeof o.bar === \"string\") {} - if (o !== null && o !== undefined && typeof o.bar === \"string\") {} } - function foo8(o: { p: mixed }) { if (o.p && o.p.q) {} - if (o.p && o.p.q && o.p.q.r) {} } " @@ -1030,133 +953,105 @@ function arr0(x: mixed) { // error, mixed // error function takesNumber(x: number) {} - function takesString(x: string) {} - function num(x: mixed) { if (typeof x === \"number\") { takesString(x); - (!x: false); } - if (typeof x === \"number\" && x) { (!x: false); } - if (x && typeof x === \"number\") { (!x: false); } } - function str(x: mixed) { if (typeof x === \"string\") { takesNumber(x); - (!x: false); } - if (typeof x === \"string\" && x) { (!x: false); } - if (x && typeof x === \"string\") { (!x: false); } } - function bool(x: mixed) { if (typeof x === \"boolean\") { takesString(x); - (x: true); } - if (typeof x === \"boolean\" && x) { (x: true); } - if (x && typeof x === \"boolean\") { (x: true); } } - function fun(x: mixed) { if (typeof x === \"function\") { takesString(x); } } - function obj0(x: mixed) { if (typeof x === \"object\") { takesString(x); } } - function obj1(x: mixed) { if (Array.isArray(x)) { takesString(x); } } - function undef(x: mixed) { if (typeof x === \"undefined\") { takesString(x); } } - function null_(x: mixed) { if (x === null) { takesString(x); } } - function maybe(x: mixed) { if (x == null) { takesString(x); } } - function true_(x: mixed) { if (x === true) { takesString(x); } } - function false_(x: mixed) { if (x === false) { takesString(x); } } - function obj2(x: mixed) { if (typeof x === \"object\") { (x: { [key: string]: mixed } | null); - if (x !== null) { (x[\"foo\"]: string); } } } - function obj2(x: mixed) { if (typeof x === \"object\" && x) { (x: Object); } - if (x && typeof x === \"object\") { (x: Object); } - if (x != null && typeof x === \"object\") { (x: Object); } - if (x !== null && typeof x === \"object\") { (x: Object); } } - function arr0(x: mixed) { if (Array.isArray(x)) { takesString(x[0]); @@ -1241,23 +1136,19 @@ function foo(x: ?boolean) { x++; } } - function bar(x: ?number) { if (!x) { x[0]; } } - function baz(x: ?number) { if (x === null || x === undefined) { return; } - if (!x) { x[0]; } } - class TestClass {} let tests = [ function() { @@ -1305,7 +1196,6 @@ function null_bogus_comparison() { if (100 * null) { return; } - if (null * 100) { return; } @@ -1456,54 +1346,45 @@ let tests = [ if (x === 0) { (x: void); } - (x: 0); }, function(x: number) { if (x !== 0) { (x: 0); } - (x: void); }, function(x: 1): 0 { if (x === 0) { return x; } - return 0; }, function(x: 0): number { if (x === 1) { return x; } - return x; }, function(x: 0) { if (x !== 1) { (x: 0); } - (x: 0); }, function(x: 0): number { if (x === 0) { return x; } - return x; }, function(x: 0 | 1) { if (x === 0) { (x: 0); - (x: void); } - if (x === 1) { (x: 1); - (x: void); } }, @@ -1511,7 +1392,6 @@ let tests = [ if (x.foo === 0) { return x.foo; } - return x.foo; }, function(x: { kind: 0, foo: number } | { kind: 1, bar: number }): number { @@ -1531,7 +1411,6 @@ let tests = [ if (n !== 0 && n !== 1 && n !== 2) { throw new Error(\"Wrong number passed\"); } - return n; }, function(s: number): ?Mode { @@ -1544,15 +1423,11 @@ let tests = [ function(mode: Mode) { switch (mode) { case 0: - (mode: 0); - break; case 1: case 2: - (mode: 1 | 2); - break; } }, @@ -1659,94 +1534,71 @@ function a(x: { [key: string]: ?string }, y: string): string { if (x[y]) { return x[y]; } - return \"\"; } - function b(x: { y: { [key: string]: ?string } }, z: string): string { if (x.y[z]) { return x.y[z]; } - return \"\"; } - function c(x: { [key: string]: ?string }, y: { z: string }): string { if (x[y.z]) { return x[y.z]; } - return \"\"; } - function d(x: { y: { [key: string]: ?string } }, a: { b: string }): string { if (x.y[a.b]) { return x.y[a.b]; } - return \"\"; } - function a_array(x: Array, y: number): string { if (x[y]) { return x[y]; } - return \"\"; } - function b_array(x: { y: Array }, z: number): string { if (x.y[z]) { return x.y[z]; } - return \"\"; } - function c_array(x: Array, y: { z: number }): string { if (x[y.z]) { return x[y.z]; } - return \"\"; } - function d_array(x: { y: Array }, a: { b: number }): string { if (x.y[a.b]) { return x.y[a.b]; } - return \"\"; } - function e_array(x: Array): string { if (x[0]) { return x[0]; } - return \"\"; } - function c2(x: { [key: string]: ?string }, y: { z: string }): string { if (x[y.z]) { y.z = \"HEY\"; - return x[y.z]; } - return \"\"; } - function c3( x: { [key: string]: ?string }, y: { z: string, a: string } ): string { if (x[y.z]) { y.a = \"HEY\"; - return x[y.z]; } - return \"\"; } " @@ -1850,42 +1702,33 @@ function foo(b) { var x = b ? 0 : null; while (typeof x == \"string\" || typeof x == \"number\") { var y: string = x; - x = false; } var z: string = x; } - function bar(b) { var x = b ? 0 : null; do { var y: string = x; - x = false; } while (x === null); var z: string = x; } - function maybe_throw() {} - function qux() { var x = 0; try { maybe_throw(); - x = \"hello\"; } catch (e) { maybe_throw(); - x = \"hello\"; } finally { var y: number = x; - x = 42; } var z: string = x; } - function corge(b) { for ( var x = b ? 0 : null; @@ -1894,27 +1737,21 @@ function corge(b) { ) { var y: string = x; } - var z: string = x; } - function waldo() { var o = {}; var x = false; - for (x in o) { x = 0; } - var z: number = x; } - function global_in_conditional0(x: number) { if (x != 0) { if (BAZ) {} } } - function global_in_conditional2(x: number) { for (var i = 0; i < 100; i++) { if (BAZ) {} @@ -2079,54 +1916,45 @@ let tests = [ if (x === \"foo\") { (x: void); } - (x: \"foo\"); }, function(x: string) { if (x !== \"foo\") { (x: \"foo\"); } - (x: void); }, function(x: \"bar\"): \"foo\" { if (x === \"foo\") { return x; } - return \"foo\"; }, function(x: \"foo\"): string { if (x === \"bar\") { return x; } - return x; }, function(x: \"foo\") { if (x !== \"bar\") { (x: \"foo\"); } - (x: \"foo\"); }, function(x: \"foo\"): string { if (x === \"foo\") { return x; } - return x; }, function(x: \"foo\" | \"bar\") { if (x === \"foo\") { (x: \"foo\"); - (x: void); } - if (x === \"bar\") { (x: \"bar\"); - (x: void); } }, @@ -2134,7 +1962,6 @@ let tests = [ if (x.foo === \"foo\") { return x.foo; } - return x.foo; }, function( @@ -2154,11 +1981,9 @@ let tests = [ }, function(str: string): Mode { var ch = str[0]; - if (ch !== \"a\" && ch !== \"b\" && ch !== \"c\") { throw new Error(\"Wrong string passed\"); } - return ch; }, function(s: string): ?Mode { @@ -2171,15 +1996,11 @@ let tests = [ function(mode: Mode) { switch (mode) { case \"a\": - (mode: \"a\"); - break; case \"b\": case \"c\": - (mode: \"b\" | \"c\"); - break; } }, @@ -2194,11 +2015,9 @@ let tests = [ if (x === \`foo\`) { return x; } - if (\`foo\` === x) { return x; } - return \"foo\"; } ]; @@ -2248,7 +2067,6 @@ class B { if (super.prop) { return super.prop; } - return \"B\"; } } @@ -2257,7 +2075,6 @@ class C extends A { if (super.prop) { return super.prop; } - return \"C\"; } } @@ -2337,7 +2154,6 @@ function foo(text: string | number): string { return \"wat\"; } } - function bar(text: string | number): string { switch (typeof text) { case \"string\": @@ -2346,7 +2162,6 @@ function bar(text: string | number): string { return text++ + \"\"; } } - function baz1(text: string | number): string { switch (typeof text) { case \"number\": @@ -2356,7 +2171,6 @@ function baz1(text: string | number): string { return \"wat\"; } } - function baz2(text: string | number): string { switch (typeof text) { case \"string\": @@ -2366,7 +2180,6 @@ function baz2(text: string | number): string { return \"wat\"; } } - function corge(text: string | number | Array): string { switch (typeof text) { case \"object\": @@ -2692,7 +2505,6 @@ let tests = [ type Type = Name | ListType; type Name = { kind: \"Name\", value: string }; type ListType = { kind: \"ListType\", name: string }; - function getTypeASTName(typeAST: Type): string { if (typeAST.kind === \"Name\") { return typeAST.value; @@ -2700,44 +2512,35 @@ function getTypeASTName(typeAST: Type): string { return typeAST.name; } } - import type {ASTNode} from \"./ast_node\"; var Node = require(\"./node1\"); - function foo(x: ASTNode) { if (x.kind === Node) { return x.prop1.charAt(0); } - return null; } - type Apple = { kind: \"Fruit\", taste: \"Bad\" }; type Orange = { kind: \"Fruit\", taste: \"Good\" }; type Broccoli = { kind: \"Veg\", taste: \"Bad\", raw: \"No\" }; type Carrot = { kind: \"Veg\", taste: \"Good\", raw: \"Maybe\" }; type Breakfast = Apple | Orange | Broccoli | Carrot; - function bar(x: Breakfast) { if (x.kind === \"Fruit\") { (x.taste: \"Good\"); } else (x.raw: \"No\"); } - function qux(x: Breakfast) { if (x.taste === \"Good\") { (x.raw: \"Yes\" | \"No\"); } } - function list(n) { if (n > 0) return { kind: \"cons\", next: list(n - 1) }; - return { kind: \"nil\" }; } - function length(l) { switch (l.kind) { case \"cons\": @@ -2746,19 +2549,15 @@ function length(l) { return 0; } } - function check(n) { if (n >= 0) return n === length(list(n)); - return true; } - var EnumKind = { A: 1, B: 2, C: 3 }; type A = { kind: 1, A: number }; type B = { kind: 2, B: number }; type C = { kind: 3, C: number }; - function kind(x: A | B | C): number { switch (x.kind) { case EnumKind.A: @@ -2769,19 +2568,15 @@ function kind(x: A | B | C): number { return x.A; } } - kind({ kind: EnumKind.A, A: 1 }); - type Citizen = { citizen: true }; type NonCitizen = { citizen: false, nationality: string }; - function nationality(x: Citizen | NonCitizen) { if (x.citizen) return \"Shire\"; else return x.nationality; } - let tests = [ function test7(x: A) { if (x.kindTypo === 1) { @@ -2790,12 +2585,10 @@ let tests = [ }, function test8(x: { foo: { bar: 1 } }) { if (x.foo.bar === 1) {} - if (x.fooTypo.bar === 1) {} }, function(x: A) { if (x.kind === null.toString()) {} - if ({ kind: 1 }.kind === null.toString()) {} }, function( @@ -2808,49 +2601,33 @@ let tests = [ t: () => void ) { if (x.length === 0) {} - if (x.legnth === 0) { (x.legnth: number); - (x.legnth: string); } - if (y.length === 0) {} - if (y.legnth === 0) { (y.legnth: number); - (y.legnth: string); } - if (z.toString === 0) {} - if (z.toStirng === 0) { (z.toStirng: number); - (z.toStirng: string); } - if (q.valueOf === 0) {} - if (q.valeuOf === 0) { (q.valeuOf: number); - (q.valeuOf: string); } - if (r.toStirng === 0) { (r.toStirng: empty); } - if (s.call === 0) {} - if (s.calll === 0) { (t.calll: empty); } - if (t.call === 0) {} - if (t.calll === 0) { (t.calll: empty); } @@ -2859,23 +2636,18 @@ let tests = [ if (x.str === \"str\") { (x.str: \"not str\"); } - if (x.num === 123) { (x.num: 456); } - if (x.bool === true) { (x.bool: false); } - if (x.badStr === \"bad\") { (x.badStr: empty); } - if (x.badNum === 123) { (x.badNum: empty); } - if (x.badBool === true) { (x.badBool: empty); } @@ -2883,63 +2655,48 @@ let tests = [ function(x: { foo: 123, y: string } | { foo: \"foo\", z: string }) { if (x.foo === 123) { (x.y: string); - x.z; } else { (x.z: string); - x.y; } - if (x.foo === \"foo\") { (x.z: string); - x.y; } else { (x.y: string); - x.z; } }, function(x: { foo: number, y: string } | { foo: \"foo\", z: string }) { if (x.foo === 123) { (x.y: string); - x.z; } else { x.y; - x.z; } - if (x.foo === \"foo\") { (x.z: string); - x.y; } else { (x.y: string); - x.z; } }, function(x: { foo: number, y: string } | { foo: string, z: string }) { if (x.foo === 123) { (x.y: string); - x.z; } else { x.y; - x.z; } - if (x.foo === \"foo\") { (x.z: string); - x.y; } else { x.y; - x.z; } }, @@ -2949,7 +2706,6 @@ let tests = [ ) { if (x.foo === num) { x.y; - x.z; } } @@ -2986,18 +2742,13 @@ function handleStatus(status: Success | Error) { import {SUCCESS, ERROR} from \"./constants\"; type Success = { type: typeof SUCCESS, message: string }; type Error = { type: typeof ERROR, error: string }; - function handleStatus(status: Success | Error) { switch (status.type) { case SUCCESS: - console.log(\`Successful: \${status.message}\`); - break; default: - console.log(\`Errored: \${status.error}\`); - } } " @@ -3086,63 +2837,48 @@ function foo(x: boolean | number) { x[0]; } } - function bar(): number { var x = null; - if (typeof x === \"object\") { return x; } - return 0; } - function fn0() { if (typeof BAZ !== \"undefined\" && typeof BAZ.stuff === \"function\") { BAZ.stuff(123); } - BAZ.stuff(123); } - function fn1() { BAZ.stuff; - if (typeof BAZ !== \"undefined\" && typeof BAZ.stuff === \"function\") { BAZ.stuff(123); - BAZ.stuff(123); } } - function anyfun(x: number | Function): number { if (typeof x === \"function\") { return 0; } - return x; } - function anyobj(x: number | Object): number { if (typeof x === \"object\") { return 0; } - return x; } - function testInvalidValue(x: mixed) { if (typeof x === \"foo\") { return 0; } } - function testTemplateLiteral(x: string | number) { if (typeof x === \`string\`) { return x.length; } } - function testInvalidTemplateLiteral(x: string | number) { if (typeof x === \`foo\`) { return 0; @@ -3242,78 +2978,65 @@ function undef_var(x: ?number) { var y = x * 1000; } } - function undef_var_rev(x: ?number) { if (x === null || x === undefined) {} else { var y = x * 1000; } } - function undef_prop(x: { x: ?number }) { if (x.x !== null && x.x !== undefined) { var y = x.x * 1000; } } - function undef_prop_rev(x: { x: ?number }) { if (x.x === null || x.x === undefined) {} else { var y = x.x * 1000; } } - function undef_var_fail(x: ?number) { if (x !== undefined) { var y = x * 1000; } } - function undef_var_fail_rev(x: ?number) { if (x === undefined) {} else { var y = x * 1000; } } - function undef_prop_fail(x: { x: ?number }) { if (x.x !== undefined) { var y = x.x * 1000; } } - function undef_prop_fail_rev(x: { x: ?number }) { if (x.x === undefined) {} else { var y = x.x * 1000; } } - function undef_unreachable(x: number) { if (x === undefined) { var y = x * 1000; } - if (x == undefined) { var z = x * 1000; } } - function undef_var_nonstrict(x: ?number, y: ?number) { if (x != undefined) { var a = x * 1000; } - if (y == undefined) { var b = y * 1000; } } - function undef_bogus_comparison() { if (100 * undefined) { return; } - if (undefined * 100) { return; } @@ -3349,19 +3072,16 @@ function baz(x: ?thing) { // error on number // error on number type thing = number | boolean; - function foo(x: thing) { if (x === true) { x[0]; } } - function bar(x: thing) { if (x !== true && x !== false) { x[0]; } } - function baz(x: ?thing) { if (x && x !== true) { x[0]; @@ -3473,92 +3193,77 @@ function void_var(x: ?number) { var y = x * 1000; } } - function void_var_rev(x: ?number) { if (x === null || x === void 0) {} else { var y = x * 1000; } } - function void_pro(x: { x: ?number }) { if (x.x !== null && x.x !== void 0) { var y = x.x * 1000; } } - function void_pro_rev(x: { x: ?number }) { if (x.x === null || x.x === void 0) {} else { var y = x.x * 1000; } } - function void_var_fail(x: ?number) { if (x !== void 0) { var y = x * 1000; } } - function void_var_fail_rev(x: ?number) { if (x === void 0) {} else { var y = x * 1000; } } - function void_pro_fail(x: { x: ?number }) { if (x.x !== void 0) { var y = x.x * 1000; } } - function void_pro_fail_rev(x: { x: ?number }) { if (x.x === void 0) {} else { var y = x.x * 1000; } } - function void_var_side_effect(x: ?number) { if (x !== null && x !== void (x * 1000)) { var y = x * 1000; } } - function void_var_side_effect_rev(x: ?number) { if (x === null || x === void (x * 1000)) {} else { var y = x * 1000; } } - function void_prop_side_effect(x: { x: ?number }) { if (x.x !== null && x.x !== void (x.x * 1000)) { var y = x.x * 1000; } } - function void_prop_side_effect_rev(x: { x: ?number }) { if (x.x === null || x.x === void (x.x * 1000)) {} else { var y = x.x * 1000; } } - function void_bogus_comparison() { if (100 * void 0) { return; } - if (void 0 * 100) { return; } } - function void_redefined_undefined(x: ?number) { var undefined = \"foo\"; - if (x !== null && x !== void 0) { var y = x * 1000; } diff --git a/tests/replace/__snapshots__/jsfmt.spec.js.snap b/tests/replace/__snapshots__/jsfmt.spec.js.snap index 9a21d5fb..172688df 100644 --- a/tests/replace/__snapshots__/jsfmt.spec.js.snap +++ b/tests/replace/__snapshots__/jsfmt.spec.js.snap @@ -6,9 +6,7 @@ function foo(x) { } foo(\"\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var a = 0; - function foo(x) {} - foo(\"\"); " `; diff --git a/tests/require/__snapshots__/jsfmt.spec.js.snap b/tests/require/__snapshots__/jsfmt.spec.js.snap index fbda0f7f..2ff20ad5 100644 --- a/tests/require/__snapshots__/jsfmt.spec.js.snap +++ b/tests/require/__snapshots__/jsfmt.spec.js.snap @@ -33,7 +33,6 @@ exports = {stringValue: \'\'}; // value will affect the exports object but re-binding it makes it useless and // does not affect the exports value. module.exports = { numberValue: 42 }; - exports = { stringValue: \"\" }; " `; @@ -76,7 +75,6 @@ require(\"not a module name\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow function require() {} - require(\"not a module name\"); " `; @@ -144,38 +142,22 @@ require.call(null, \"DoesNotExist\"); // error: but only if they have no expressions // require.call is allowed but circumverts Flow\'s static analysis function takesANumber(num: number): void {} - function takesAString(str: string): void {} - var A = require(\"A\"); - takesANumber(A.numberValue); - takesAString(A.numberValue); - var B = require(\"./B\"); - takesANumber(B.numberValue); - takesAString(B.numberValue); - require(\"C\"); - require(\"./D\"); - var E = require(\"./E\"); var e_1: number = E.numberValue; - E.stringValue; - var a = \"./E\"; - require(a); - require(\`./E\`); - require(\`\${\"./E\"}\`); - require.call(null, \"DoesNotExist\"); " `; diff --git a/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap b/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap index 63dcea77..e80f22f7 100644 --- a/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap @@ -80,14 +80,10 @@ requireLazy([ \"A\", \"B\" ], function(A, B) { var num4: number = B.stringValueB; var str4: string = B.numberValueB; }); - var notA: Object = A; var notB: Object = B; - requireLazy(); - requireLazy([ nope ], function() {}); - requireLazy([ \"A\" ]); " `; diff --git a/tests/return/__snapshots__/jsfmt.spec.js.snap b/tests/return/__snapshots__/jsfmt.spec.js.snap index aad213d6..8179ff20 100644 --- a/tests/return/__snapshots__/jsfmt.spec.js.snap +++ b/tests/return/__snapshots__/jsfmt.spec.js.snap @@ -47,35 +47,28 @@ class C { return x; } } - function f(x): number { if (x > 1) { return 42; } } - function g(x): ?number { if (x > 1) { return 42; } } - function h(x): number { if (x > 1) { return 42; } - return; } - function i(x): ?number { if (x > 1) { return 42; } - return; } - module.exports = C; " `; @@ -105,7 +98,6 @@ function f(b) { return \"nope\"; } } - (f(true): void); " `; diff --git a/tests/return_new/__snapshots__/jsfmt.spec.js.snap b/tests/return_new/__snapshots__/jsfmt.spec.js.snap index bb6b08df..e2b52572 100644 --- a/tests/return_new/__snapshots__/jsfmt.spec.js.snap +++ b/tests/return_new/__snapshots__/jsfmt.spec.js.snap @@ -19,24 +19,17 @@ var a: A = new B(); // OK (returns new A) function Foo() { return {}; } - var foo: number = new Foo(); - function Bar() { return 0; } - var bar: number = new Bar(); - function Qux() {} - var qux: number = new Qux(); class A {} - function B() { return new A(); } - var a: A = new B(); " `; @@ -59,11 +52,8 @@ module.exports = D; // error, new D is an object, D not in proto chain declare class D { constructor(): { x: number }, y: any } var d = new D(); - d.x = \"\"; - (new D(): D); - module.exports = D; " `; diff --git a/tests/seal/__snapshots__/jsfmt.spec.js.snap b/tests/seal/__snapshots__/jsfmt.spec.js.snap index c1fabc24..a6fc1d18 100644 --- a/tests/seal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/seal/__snapshots__/jsfmt.spec.js.snap @@ -6,7 +6,6 @@ imp({ name: \"imp\" }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var imp = require(\"./obj_annot\"); - imp({ name: \"imp\" }); " `; @@ -26,9 +25,7 @@ module.exports = foo; function foo(param: { name: string }): number { return param.id; } - foo({ name: \"test\" }); - module.exports = foo; " `; diff --git a/tests/sealed/__snapshots__/jsfmt.spec.js.snap b/tests/sealed/__snapshots__/jsfmt.spec.js.snap index 01fd8af1..0123ba78 100644 --- a/tests/sealed/__snapshots__/jsfmt.spec.js.snap +++ b/tests/sealed/__snapshots__/jsfmt.spec.js.snap @@ -13,15 +13,12 @@ module.exports = Bar; function Bar(x: number) { this.x = x; } - Bar.prototype.getX = function() { return this.x; }; - Bar.prototype.getY = function(): string { return this.y; }; - module.exports = Bar; " `; @@ -44,26 +41,19 @@ module.exports = export_o; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // awkward type cast function Foo() {} - var o = new Foo(); var x: number = o.x; - Foo.prototype.m = function() { return this.x; }; - var y: number = o.m(); - o.x = \"...\"; - Foo.prototype = { m: function() { return false; } }; - var export_o: { x: any } = o; - module.exports = export_o; " `; @@ -83,19 +73,13 @@ a.y = \'abc\'; // error, needs to be declared in Bar\'s constructor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error, needs to be declared in Bar\'s constructor var o = require(\"./proto\"); - o.z = 0; - var x: string = o.x; var Bar = require(\"./function\"); var a = new Bar(234); - a.x = 123; - a.y = \"abc\"; - (a.getX(): number); - (a.getY(): string); " `; diff --git a/tests/shape/__snapshots__/jsfmt.spec.js.snap b/tests/shape/__snapshots__/jsfmt.spec.js.snap index 454eda45..421bf828 100644 --- a/tests/shape/__snapshots__/jsfmt.spec.js.snap +++ b/tests/shape/__snapshots__/jsfmt.spec.js.snap @@ -10,7 +10,6 @@ var y: $Shape = x; type Foo = { field: number }; var x: { field?: number } = {}; var y: $Shape = x; - (y.field: number); " `; diff --git a/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap b/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap index a96fc1ee..3090fcfd 100644 --- a/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap @@ -29,26 +29,20 @@ function baz(i:number): string { return a[i]; } // uncalled internal functions will not find a type error, which is acceptable // behavior as such functions are dead code. var a = []; - for (var i = 0; i < 10; ++i) { if (i % 2 == 0) { a[i] = 0; } else { a[i] = \"\"; } - } - function foo(i): string { return a[i]; } - function bar(i): string { return a[i]; } - bar(0); - function baz(i: number): string { return a[i]; } @@ -67,16 +61,13 @@ function foo(i: number): string { return a[i]; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var a = []; - for (var i = 0; i < 10; ++i) { if (i % 2 == 0) { a[i] = 0; } else { a[i] = \"\"; } - } - function foo(i: number): string { return a[i]; } diff --git a/tests/singleton/__snapshots__/jsfmt.spec.js.snap b/tests/singleton/__snapshots__/jsfmt.spec.js.snap index 7007bccd..3dd6356d 100644 --- a/tests/singleton/__snapshots__/jsfmt.spec.js.snap +++ b/tests/singleton/__snapshots__/jsfmt.spec.js.snap @@ -45,18 +45,14 @@ function alwaysFalsy(x: boolean): false { function veryOptimistic(isThisAwesome: true): boolean { return isThisAwesome; } - var x: boolean = veryOptimistic(true); var y: boolean = veryOptimistic(false); - function veryPessimistic(isThisAwesome: true): boolean { return !isThisAwesome; } - var x: boolean = veryPessimistic(true); var y: boolean = veryPessimistic(false); type MyOwnBooleanLOL = true | false; - function bar(x: MyOwnBooleanLOL): false { if (x) { return x; @@ -64,13 +60,9 @@ function bar(x: MyOwnBooleanLOL): false { return !x; } } - bar(true); - bar(false); - bar(1); - function alwaysFalsy(x: boolean): false { if (x) { return !x; @@ -113,27 +105,17 @@ sort((x, y) => -1); function highlander(howMany: 1): number { return howMany; } - highlander(1); - highlander(2); - type Foo = 1 | 2; - function bar(num: Foo): number { return num + 1; } - bar(1); - bar(2); - bar(3); - type ComparatorResult = -1 | 0 | 1; - function sort(fn: (x: any, y: any) => ComparatorResult) {} - sort((x, y) => -1); " `; @@ -149,11 +131,8 @@ type HasSpaces = \"foo bar\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ type NoSpaces = \"foobar\"; - (\"foobar\": NoSpaces); - type HasSpaces = \"foo bar\"; - (\"foo bar\": HasSpaces); " `; diff --git a/tests/spread/__snapshots__/jsfmt.spec.js.snap b/tests/spread/__snapshots__/jsfmt.spec.js.snap index 6948a575..76fd2b49 100644 --- a/tests/spread/__snapshots__/jsfmt.spec.js.snap +++ b/tests/spread/__snapshots__/jsfmt.spec.js.snap @@ -33,11 +33,9 @@ function parseTimeframe(line: string): { begin: number; end: number } { function parseTimestamp(timestamp: string): number { return 0; } - function parseCounter(line: string): number { return 0; } - function parseGroup( lines: Array ): { counter: number, begin: number, end: number, text: string } { @@ -45,7 +43,6 @@ function parseGroup( var timeframe = parseTimeframe(lines[1]); return { counter, ...timeframe, text: lines[2] }; } - function parseTimeframe(line: string): { begin: number, end: number } { var timestamps = line.split(\"-->\"); return { @@ -73,9 +70,7 @@ foo({foo: 42}); function foo(o) { bar({ ...o }); } - function bar(_: { foo: number }) {} - foo({ foo: 42 }); " `; @@ -120,7 +115,6 @@ test(0, ...[1, 2, 3]); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ function test(...nums: Array) {} - test(0, ...[ 1, 2, 3 ]); " `; @@ -164,14 +158,12 @@ declare function map( obj: { [key: string]: Tv }, iterator: (obj: Tv) => TNext ): Array; - function test( x: { kind: ?string }, kinds: { [key: string]: string } ): Array<{ kind: ?string }> { return map(kinds, value => { (value: string); - return { ...x, kind: value }; }); } @@ -202,25 +194,16 @@ for (var i = 0; i < 10; i++) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error, p doesn\'t have \`abc\` yet var o = { foo: \"bar\" }; - o = { ...o }; - (o: { foo: string }); - var p = { foo: \"bar\" }; - (p: { foo: string, abc: string }); - p = { ...p, abc: \"def\" }; - (p: { foo: string, abc: string }); - var q = { foo: \"bar\" }; - for (var i = 0; i < 10; i++) { q = { ...q }; } - (q: { foo: string }); " `; @@ -240,7 +223,6 @@ let tests = [ let tests = [ function(x: Object) { ({ ...x }: Object); - ({ ...x }: void); } ]; diff --git a/tests/statics/__snapshots__/jsfmt.spec.js.snap b/tests/statics/__snapshots__/jsfmt.spec.js.snap index a6dfaaf9..ee746b8f 100644 --- a/tests/statics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/statics/__snapshots__/jsfmt.spec.js.snap @@ -13,15 +13,11 @@ class C { static f(x: number) {} static x: string; } - C.g = function(x: string) { C.f(x); }; - C.g(0); - var x: number = C.x; - C.x = 0; " `; @@ -34,15 +30,12 @@ C.g = function(x) { return x; }; var x:string = new C().f(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function C() {} - C.prototype.f = function() { return C.g(0); }; - C.g = function(x) { return x; }; - var x: string = new C().f(); " `; diff --git a/tests/strict/__snapshots__/jsfmt.spec.js.snap b/tests/strict/__snapshots__/jsfmt.spec.js.snap index b17d52e3..95f78003 100644 --- a/tests/strict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/strict/__snapshots__/jsfmt.spec.js.snap @@ -19,7 +19,6 @@ class B extends A { return x; } } - module.exports = B; " `; @@ -48,9 +47,7 @@ module.exports = f; function f(x: number) { return x; } - var x: string = f(0); - module.exports = f; " `; @@ -76,7 +73,6 @@ module.exports = o; //var o: {x: number;} = { x: 0 } var o = { x: 0 }; var x: string = o.x; - module.exports = o; " `; diff --git a/tests/strict_requires/__snapshots__/jsfmt.spec.js.snap b/tests/strict_requires/__snapshots__/jsfmt.spec.js.snap index 735c86ff..c7ecb582 100644 --- a/tests/strict_requires/__snapshots__/jsfmt.spec.js.snap +++ b/tests/strict_requires/__snapshots__/jsfmt.spec.js.snap @@ -26,7 +26,6 @@ module.exports = o; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var o = { A: require(\"./A\"), ...require(\"./B\") }; - module.exports = o; " `; @@ -42,7 +41,6 @@ C.A = false; var C = require(\"./C\"); var x: number = C.foo; var y: string = C.A; - C.A = false; " `; diff --git a/tests/strings/__snapshots__/jsfmt.spec.js.snap b/tests/strings/__snapshots__/jsfmt.spec.js.snap index eed59f20..3c0c0783 100644 --- a/tests/strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/strings/__snapshots__/jsfmt.spec.js.snap @@ -22,33 +22,19 @@ exports[`test strings.js 1`] = ` \'🐶\' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \"abc\"; - \"abc\"; - \"\'\"; - \"\\\"\"; - \"\\\"\"; - \"\\\\\\\"\"; - \"\'\"; - \"\'\"; - \"\\\\\'\"; - \"\'\\\"\"; - \"\'\\\"\"; - \"\\\\\"; - \"\\\\\"; - \"\\u0000\"; - \"🐶\"; " `; diff --git a/tests/structural_subtyping/__snapshots__/jsfmt.spec.js.snap b/tests/structural_subtyping/__snapshots__/jsfmt.spec.js.snap index 6d433c2d..2a63f7cc 100644 --- a/tests/structural_subtyping/__snapshots__/jsfmt.spec.js.snap +++ b/tests/structural_subtyping/__snapshots__/jsfmt.spec.js.snap @@ -101,11 +101,9 @@ var propTest1: IHasXString = { x: \"hello\" }; var propTest2: IHasXString = { x: 123 }; var propTest3: IHasXString = {}; var propTest4: IHasXString = ({}: Object); - function propTest5(y: { [key: string]: string }) { (y: IHasXString); } - function propTest6(y: { [key: string]: number }) { (y: IHasXString); } diff --git a/tests/suggest/__snapshots__/jsfmt.spec.js.snap b/tests/suggest/__snapshots__/jsfmt.spec.js.snap index 8fd14ea7..3e4009b9 100644 --- a/tests/suggest/__snapshots__/jsfmt.spec.js.snap +++ b/tests/suggest/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,6 @@ module.exports = bar; function bar(w: number): number { return w; } - module.exports = bar; " `; @@ -28,15 +27,11 @@ module.exports = {foo:foo}; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var bar = require(\"./lib\"); - function foo(z: number) { return bar(z); } - var array = [ \"foo\", \"bar\" ]; - array; - module.exports = { foo: foo }; " `; diff --git a/tests/super/__snapshots__/jsfmt.spec.js.snap b/tests/super/__snapshots__/jsfmt.spec.js.snap index 950eeeaa..2271b049 100644 --- a/tests/super/__snapshots__/jsfmt.spec.js.snap +++ b/tests/super/__snapshots__/jsfmt.spec.js.snap @@ -195,7 +195,6 @@ class D extends A { y: number; constructor() { this.y; - this.x; } } @@ -203,28 +202,20 @@ class E extends A { y: number; constructor() { super(); - this.y; - this.x; } } - function leak(f) { f.y; - f.x; } - class F extends A { y: number; constructor() { leak(this); - super(); - this.y; - this.x; } } @@ -240,9 +231,7 @@ class H extends A { super(); else super(); - this.y; - this.x; } } @@ -261,7 +250,6 @@ class J__ {} class J_ extends J__ { constructor(closure_leaking_this) { closure_leaking_this(); - super(); } foo() {} @@ -284,9 +272,7 @@ class K extends K_ { if (_this) _this.foo(); }); - var _this = this; - this.closure_leaking_this(); } } @@ -301,11 +287,8 @@ class L extends L_ { return x; } } - (new L_(): L_); - (new L(): L); - class M_ { constructor() { return { foo: \"foo\" }; @@ -316,11 +299,8 @@ class M extends M_ { return super(); } } - (new M_(): { foo: string }); - (new M(): { foo: string }); - class N_ { constructor(): this { let x = this; @@ -332,9 +312,7 @@ class N extends N_ { return super(); } } - (new N_(): N_); - (new N(): N); " `; @@ -350,7 +328,6 @@ class D { return 0; } } - module.exports = D; " `; @@ -394,12 +371,10 @@ class B extends A { } static anotherStatic() { (super.staticMethod(\"foo\"): number); - super.doesntExist(); } g() { super.f(0); - return super.g; } } @@ -423,7 +398,6 @@ class C extends D { return super.foo(); } } - module.exports = C; " `; diff --git a/tests/suppress/__snapshots__/jsfmt.spec.js.snap b/tests/suppress/__snapshots__/jsfmt.spec.js.snap index e8493fb7..dcc945d8 100644 --- a/tests/suppress/__snapshots__/jsfmt.spec.js.snap +++ b/tests/suppress/__snapshots__/jsfmt.spec.js.snap @@ -39,11 +39,9 @@ var test6: string = 123; */ var test1: string = 123; var test2: string = 123; - function getNum() { return 123; } - var test3: string = getNum(); var test4: string = 123; var test5: string = 123; @@ -72,7 +70,6 @@ function runTest(y: number): void { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* $FlowFixMe - suppressing the error op location should also work */ function takesAString(x: string): void {} - function runTest(y: number): void { takesAString(y); } diff --git a/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap b/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap index 656cc2c1..ade0d0ba 100644 --- a/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap +++ b/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap @@ -26,11 +26,9 @@ var a: string = foo(\'hi\'); // error number ~> string function bar(): number { return 5; } - function foo(x: string) { return bar(); } - var a: string = foo(\"hi\"); " `; diff --git a/tests/switch/__snapshots__/jsfmt.spec.js.snap b/tests/switch/__snapshots__/jsfmt.spec.js.snap index 080cdf78..4c4e95c7 100644 --- a/tests/switch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/switch/__snapshots__/jsfmt.spec.js.snap @@ -36,7 +36,6 @@ function foo(x): number { throw new Error(\"hi\"); } } - function bar(x) { switch (x) { case 0: @@ -44,10 +43,8 @@ function bar(x) { default: return; } - 1; } - function baz(x): number { switch (x) { case 0: @@ -104,7 +101,6 @@ function foo(): number { } return 2; } - function bar() { switch (\"bar\") { case \"bar\": @@ -113,18 +109,13 @@ function bar() { break; } } - function qux(b) { var x = b ? 0 : \"\"; switch (\"qux\") { case \"\": - x = 0; - case \"qux\": - x = x * x; - } } " @@ -200,51 +191,31 @@ function foo(x: mixed): string { var b = \"\"; switch (x) { case \"foo\": - a = 0; - default: - b = 0; - } - (a: string); - (a: number); - (b: number); - return b; } - function baz(x: mixed): number { var a = \"\"; var b = \"\"; switch (x) { case \"baz\": - a = 0; - break; case \"bar\": - a = \"\"; - default: - b = 0; - } - (a: string); - (a: number); - (b: string); - (b: number); - return a + b; } " @@ -345,44 +316,32 @@ function f1(i) { var x; switch (i) { case 0: - x = 0; - break; case 1: - x = 1; - break; default: - x = -1; - break; case 2: - x = \"2\"; - break; } var y: number = x; } - function f2(i) { var x; switch (i) { case 0: case 1: default: - x = 1; - break; case 2: } var y: number = x; } - function f3(i) { var x; switch (i) { @@ -390,13 +349,10 @@ function f3(i) { case 1: default: case 2: - x = 1; - } var y: number = x; } - function foo(x): number { switch (x) { case 0: @@ -406,7 +362,6 @@ function foo(x): number { return 1; } } - function bar(x) { switch (x) { default: @@ -414,10 +369,8 @@ function bar(x) { case 0: break; } - 1; } - function baz(x): number { switch (x) { case 0: diff --git a/tests/symlink/__snapshots__/jsfmt.spec.js.snap b/tests/symlink/__snapshots__/jsfmt.spec.js.snap index a39bdb41..01e98a10 100644 --- a/tests/symlink/__snapshots__/jsfmt.spec.js.snap +++ b/tests/symlink/__snapshots__/jsfmt.spec.js.snap @@ -17,7 +17,6 @@ exports[`test qux.js 1`] = ` ({ x: \"\" }: Foo); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import type {Foo} from \"./bar.js\"; - ({ x: \"\" }: Foo); " `; diff --git a/tests/tagged-unions/__snapshots__/jsfmt.spec.js.snap b/tests/tagged-unions/__snapshots__/jsfmt.spec.js.snap index 18f81902..1c32f91f 100644 --- a/tests/tagged-unions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/tagged-unions/__snapshots__/jsfmt.spec.js.snap @@ -41,7 +41,6 @@ class Bar { bar: string; } type Foobar = Foo | Bar; - function foobar(x: Foobar): string { if (x.type === \"foo\") { return foo(x); @@ -51,11 +50,9 @@ function foobar(x: Foobar): string { return \"unknown\"; } } - function foo(x: Foo): string { return x.foo; } - function bar(x: Bar): string { return x.bar; } @@ -96,7 +93,6 @@ interface IUserData extends IDataBase { kind: \"user\" } interface ISystemData extends IDataBase { kind: \"system\" } type IData = IUserData | ISystemData; const data: IData = { id: \"\", name: \"\", kind: \"system\" }; - if (data.kind === \"user\") { (data: ISystemData); } @@ -137,7 +133,6 @@ interface IUserData extends IDataBase { kind: \"user\" } interface ISystemData extends IDataBase { kind: \"system\" } type IData = IUserData | ISystemData; const data: IData = { id: \"\", name: \"\", kind: \"system\" }; - if (data.kind === \"system\") { (data: ISystemData); } @@ -182,7 +177,6 @@ type UserData = { id: string, name: string, kind: \"user\" }; type SystemData = { id: string, name: string, kind: \"system\" }; type Data = UserData | SystemData; const data: Data = { id: \"\", name: \"\", kind: \"system\" }; - if (data.kind === \"user\") { (data: SystemData); } @@ -227,7 +221,6 @@ type UserData = { id: string, name: string, kind: \"user\" }; type SystemData = { id: string, name: string, kind: \"system\" }; type Data = UserData | SystemData; const data: Data = { id: \"\", name: \"\", kind: \"system\" }; - if (data.kind === \"system\") { (data: SystemData); } diff --git a/tests/taint/__snapshots__/jsfmt.spec.js.snap b/tests/taint/__snapshots__/jsfmt.spec.js.snap index ce9c0f86..15da7235 100644 --- a/tests/taint/__snapshots__/jsfmt.spec.js.snap +++ b/tests/taint/__snapshots__/jsfmt.spec.js.snap @@ -40,31 +40,24 @@ function f7(x : $Tainted, y : $Tainted) { function f(x: $Tainted, y: $Tainted) { var z: $Tainted = x + y; } - function f1(x: $Tainted, y: number) { var z: $Tainted = x + y; } - function f2(x: number, y: $Tainted) { var z: $Tainted = x + y; } - function f3(x: $Tainted, y: number) { var z: number = x + y; } - function f4(x: number, y: $Tainted) { var z: number = x + y; } - function f5(x: number, y: $Tainted) { var z: string = x + y; } - function f6(x: string, y: $Tainted) { var z: string = x + y; } - function f7(x: $Tainted, y: $Tainted) { var z: string = x + y; } @@ -110,23 +103,17 @@ let tests = [ let tests = [ function(x: $Tainted, y: string) { let obj: Object = {}; - obj.foo = x; - obj[y] = x; }, function() { let obj: Object = { foo: \"foo\" }; - (obj.foo: $Tainted); }, function(x: $Tainted) { let obj: Object = {}; - obj.foo(x); - let foo = obj.foo; - foo(x); } ]; @@ -166,27 +153,21 @@ function f_foo3(f1 : Function, o1 : Object, o2 : {t : $Tainted}) { function foo(x: $Tainted, o: Object) { o.f(x); } - function foo1(x: $Tainted, o: { f(y: $Tainted): void }) { o.f(x); } - function foo2(o1: Object, o2: { t: $Tainted }) { o1.f(o2.t); } - function foo3(x: $Tainted, o: { f(y: $Tainted): void }) { o.f(x); } - function f_foo1(x: $Tainted, f: Function) { f(x); } - function f_foo2(f1: Function, o: { t: $Tainted }) { f1(o.t); } - function f_foo3(f1: Function, o1: Object, o2: { t: $Tainted }) { f1(o1)(o2.t); } @@ -222,15 +203,12 @@ function f3(x : $Tainted, y : string) { function f(x: $Tainted, y: $Tainted) { var z: $Tainted = x < y; } - function f1(x: string, y: $Tainted) { var z: $Tainted = x < y; } - function f2(x: $Tainted, y: number) { var z: $Tainted = x < y; } - function f3(x: $Tainted, y: string) { var z: boolean = x < y; } @@ -263,7 +241,6 @@ let tests = [ }, function(x: any, y: $Tainted) { let z = x(); - z(y); } ]; @@ -291,7 +268,6 @@ class A { class A { f(x: $Tainted) { fakeDocument.location = x; - doStuff(x); } f1(x: $Tainted) { @@ -425,7 +401,6 @@ function f(x : $Tainted) { // Should cause error. var safe: string = \"safe\"; var tainted: $Tainted = safe; - function f(x: $Tainted) { var y: any = x; } @@ -477,27 +452,21 @@ function foo6 (a : $Tainted>) { function foo(x: $Tainted) { var should_fail: number = x * 42; } - function foo1(x: $Tainted<{ f: number }>) { var ok: number = x.f; } - function foo2(o: { f(y: number): number }, t: $Tainted) { return o.f(t); } - function foo3(x: $Tainted<{ f: number }>) { var also_tainted: $Tainted = x.f; } - function foo4(a: $Tainted>) { var trusted: string = a[0]; } - function foo5(a: $Tainted>) { var trusted_number: number = a[0]; } - function foo6(a: $Tainted>) { var trusted: $Tainted = a[0]; } diff --git a/tests/template/__snapshots__/jsfmt.spec.js.snap b/tests/template/__snapshots__/jsfmt.spec.js.snap index 1068458d..e7ff9907 100644 --- a/tests/template/__snapshots__/jsfmt.spec.js.snap +++ b/tests/template/__snapshots__/jsfmt.spec.js.snap @@ -50,42 +50,29 @@ let tests = [ // error // error (\`foo\`: string); - (\`bar\`: \"bar\"); - (\`baz\`: number); - \`foo \${123} bar\`; - \`foo \${{ bar: 123 }} baz\`; - let tests = [ function(x: string) { \`foo \${x}\`; - \`\${x} bar\`; - \`foo \${\"bar\"} \${x}\`; }, function(x: number) { \`foo \${x}\`; - \`\${x} bar\`; - \`foo \${\"bar\"} \${x}\`; }, function(x: boolean) { \`foo \${x}\`; - \`\${x} bar\`; - \`foo \${\"bar\"} \${x}\`; }, function(x: mixed) { \`foo \${x}\`; - \`\${x} bar\`; - \`foo \${\"bar\"} \${x}\`; } ]; diff --git a/tests/this/__snapshots__/jsfmt.spec.js.snap b/tests/this/__snapshots__/jsfmt.spec.js.snap index 72a20a46..de16a566 100644 --- a/tests/this/__snapshots__/jsfmt.spec.js.snap +++ b/tests/this/__snapshots__/jsfmt.spec.js.snap @@ -88,41 +88,25 @@ module.exports = true; function F() { this.x = 0; } - F.prototype.m = function() { this.y = 0; }; - function foo(p: string) {} - var o1 = new F(); - o1.x = \"\"; - foo(o1.x); - var o2 = new F(); - o1.y = 0; - o2.y = \"\"; - foo(o2.y); - var o3 = new F(); - o3.m(); - o3.y = \"\"; - foo(o3.y); - foo(o2.y); - function f1(): number { return this.x; } - var f1_1 = f1.bind({ x: 0 })(); var f1_2: string = f1.bind({ x: 0 })(); var f1_3 = f1.bind({ x: \"\" })(); @@ -131,21 +115,17 @@ var a1 = () => { return this.x; }; var ax = a1(); - function f2(): number { var a2 = () => { return this.x; }; return a2(); } - var f2_1 = f2.bind({ x: 0 })(); var f2_2: string = f2.bind({ x: 0 })(); var f2_3 = f2.bind({ x: \"\" })(); var f2_4 = f2(); - (this: void); - module.exports = true; " `; @@ -200,16 +180,12 @@ class C { var c = new C(); var f = c.foo(); var i = f(); - (i: C); - class D extends C {} var d = new D(); var g = d.foo(); var j = g(); - (j: D); - class E { foo(x: number) {} } diff --git a/tests/this_type/__snapshots__/jsfmt.spec.js.snap b/tests/this_type/__snapshots__/jsfmt.spec.js.snap index 9b92f99e..21960c0f 100644 --- a/tests/this_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/this_type/__snapshots__/jsfmt.spec.js.snap @@ -91,11 +91,8 @@ class C { } class D extends C {} var d = new D(); - (d: C).next = new C(); - (d.next: D); - class A { foo(that: X) {} } @@ -127,7 +124,6 @@ class Misc { inout_promise: Promise; *out_generator(): Generator { yield this; - return this; } in_generator(_: Generator) {} @@ -196,7 +192,6 @@ class Implicit { class ImplicitNumber extends Implicit { arg: number; } - (new ImplicitNumber().val: string); " `; @@ -242,23 +237,16 @@ class B1 extends A1 { return new B1(); } } - (new B1().bar(): B1); - class B3 extends A3 { foo(): B3 { return new B3(); } } - (new B3().bar(): B3<*>); - (new B3().qux(0): string); - (new B3().bar(): A2<*>); - ((new B3().bar(): B3): A2); - ((new B3(): A2).qux(0): string); " `; @@ -281,11 +269,9 @@ class C { return this; } } - function foo(c: C): I { return c; } - function bar(c: C): J { return c; } @@ -305,9 +291,7 @@ class C { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (new DoublyLinkedList().prev(): DoublyLinkedList); - (new DoublyLinkedList().next(): DoublyLinkedList); - var MiniImmutable = require(\"mini-immutable\"); class C { map: MiniImmutable.OrderedMap; @@ -381,13 +365,9 @@ class A { } } class B extends A {} - (A.make(): A); - (B.make(): B); - (B.make(): A); - (A.make(): B); " `; @@ -511,21 +491,13 @@ class Override extends Base { } } class InheritOverride extends Override {} - (new Inherit().foo(): Base); - (new Inherit().foo(): Inherit); - ((new Inherit(): Base).foo(): Base); - (new Override().foo(): Base); - (new Override().foo(): Override); - ((new Override(): Base).foo(): Base); - (new InheritOverride().bar_caller(): InheritOverride); - class Base2 { foo(): this { return this; @@ -557,21 +529,13 @@ class Override2 extends Base2 { grault(that: this) {} } class InheritOverride2 extends Override2 {} - (new Inherit2().foo(): Base2); - (new Inherit2().foo(): Inherit2); - ((new Inherit2(): Base2).foo(): Base2); - (new Override2().foo(): Base2); - (new Override2().foo(): Override2); - ((new Override2(): Base2).foo(): Base2); - (new InheritOverride2().bar_caller(): InheritOverride2); - (new Override2(): Base2).corge(new Base2()); " `; diff --git a/tests/throw/__snapshots__/jsfmt.spec.js.snap b/tests/throw/__snapshots__/jsfmt.spec.js.snap index 24a8561a..2ae1e197 100644 --- a/tests/throw/__snapshots__/jsfmt.spec.js.snap +++ b/tests/throw/__snapshots__/jsfmt.spec.js.snap @@ -30,15 +30,12 @@ function h(x: number): string { function f(): number { throw new Error(); } - function g(a: ?string) { if (a == null) { throw new Error(); } - return a * 1; } - function h(x: number): string { if (x) { return \"foo\"; diff --git a/tests/traces/__snapshots__/jsfmt.spec.js.snap b/tests/traces/__snapshots__/jsfmt.spec.js.snap index e20570a8..7d8c67f4 100644 --- a/tests/traces/__snapshots__/jsfmt.spec.js.snap +++ b/tests/traces/__snapshots__/jsfmt.spec.js.snap @@ -25,41 +25,29 @@ f3(double); // h/o call with function expr // h/o call with function def function g0(y: string) {} - function f0(x) { g0(x); } - f0(0); - function g1(a: string, b: string) {} - function f1(x, y) { g1(x, y); } - f1(\"hey\", 0); - function g2(ylam: (s: string) => number) {} - function f2(xlam) { g2(xlam); } - f2(function(x) { return x * x; }); - function g3(ylam: (s: string) => number) {} - function f3(xlam) { g3(xlam); } - function double(n) { return n * 2; } - f3(double); " `; @@ -93,7 +81,6 @@ var A = React.createClass({ var B = React.createClass({ propTypes: { bar: React.PropTypes.string.isRequired } }); - function f(b): React.Element<*> { if (b) { return ; diff --git a/tests/traits/__snapshots__/jsfmt.spec.js.snap b/tests/traits/__snapshots__/jsfmt.spec.js.snap index 50497109..3b9f14eb 100644 --- a/tests/traits/__snapshots__/jsfmt.spec.js.snap +++ b/tests/traits/__snapshots__/jsfmt.spec.js.snap @@ -32,11 +32,8 @@ declare class Foo extends Qux {} declare class Bar extends Baz { y: T } declare class Qux extends Baz { y: T, z: T } declare class Baz { x: T } - (new Foo().x: number); - (new Foo().y: string); - (new Foo().z: number); " `; diff --git a/tests/try/__snapshots__/jsfmt.spec.js.snap b/tests/try/__snapshots__/jsfmt.spec.js.snap index edbcb261..3db60317 100644 --- a/tests/try/__snapshots__/jsfmt.spec.js.snap +++ b/tests/try/__snapshots__/jsfmt.spec.js.snap @@ -220,41 +220,34 @@ function f(b) { // ditto // error function might_throw() {} - function f() { try { var x: number = 0; var y: number = x; } catch (e) {} } - function f() { try {} catch (e) { var x: number = 0; var y: number = x; } } - function f() { try { might_throw(); - var x: number = 0; } catch (e) { var y: number = x; } } - function f() { try { might_throw(); - var x: number = 0; } finally { var y: number = x; } } - function f() { try {} catch (e) { var x: number = 0; @@ -262,90 +255,74 @@ function f() { var y: number = x; } } - function f() { try { var x: number = 0; } catch (e) { might_throw(); - var x: number = 0; } finally { var y: number = x; } } - function f() { try { var x: number = 0; } catch (e) { might_throw(); - var x: number = 0; } var y: number = x; } - function f() { try {} catch (e) {} finally { might_throw(); - var x: number = 0; } var y: number = x; } - function f() { try { var x: number; } catch (e) {} finally { might_throw(); - x = 0; } var y: number = x; } - function f() { try {} catch (e) { var x: number; } finally { might_throw(); - x = 0; } var y: number = x; } - function f() { var y: number = x; try { var x: number = 0; } catch (e) {} } - function f() { try { var x: number = 0; } catch (e) {} var y: number = x; } - function f() { try {} catch (e) { var x: number = 0; } var y: number = x; } - function f(b) { try { var x: number; - if (b) { throw new Error(); } - x = 0; } catch (e) {} var y: number = x; @@ -429,12 +406,9 @@ function foo(x: ?number): string { try {} catch (e) { return \"bar\"; } - console.log(); - return \"foo\"; } - function bar(): string { try { return \"foo\"; @@ -442,7 +416,6 @@ function bar(): string { return \"bar\"; } } - function baz(): string { try { throw new Error(\"foo\"); @@ -451,24 +424,19 @@ function baz(): string { } return \"bar\"; } - function qux(): string { try { throw new Error(\"foo\"); } catch (e) {} - console.log(); - return \"bar\"; } - function quux(): string { try { return qux(); } catch (e) {} return \"bar\"; } - function bliffl(): string { try { throw new Error(\"foo\"); @@ -478,14 +446,12 @@ function bliffl(): string { return \"bar\"; } } - function corge(): string { try { return \"foo\"; } catch (e) { throw new Error(\"bar\"); } - bar(); } " @@ -553,17 +519,13 @@ function foo() { x = \"\"; } catch (e) { x = false; - throw -1; } finally { y = {}; } - x(); - y(); } - function bar(response) { var payload; try { @@ -571,16 +533,13 @@ function bar(response) { } catch (e) { throw new Error(\"...\"); } - if (payload.error) {} } - function qux() { var x = 5; try { throw -1; } finally {} - x(); } " diff --git a/tests/tuples/__snapshots__/jsfmt.spec.js.snap b/tests/tuples/__snapshots__/jsfmt.spec.js.snap index a20396e1..db7e4c9f 100644 --- a/tests/tuples/__snapshots__/jsfmt.spec.js.snap +++ b/tests/tuples/__snapshots__/jsfmt.spec.js.snap @@ -15,7 +15,6 @@ function foo(x: Array): [number, ?number] { function foo(x: Array): [number, ?number] { return x; } - function foo(x: Array): [number, ?number] { return [ x[0], x[1] ]; } @@ -35,9 +34,7 @@ exports[`test optional.js 1`] = ` // Error, arity is enforced // error, since second element is not marked optional ([ 0, undefined ]: [number, ?string]); - ([ 0 ]: [number, ?string]); - ([]: [?number, string]); " `; @@ -52,7 +49,6 @@ foo([ {} ]); // error, too few elements in array passed to a tuple /* @flow */ // error, too few elements in array passed to a tuple function foo(a: [Object, Object]) {} - foo([ {} ]); " `; diff --git a/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap b/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap index d1301597..5a035d9f 100644 --- a/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap @@ -91,36 +91,24 @@ mn; // error: application of non-poly type class C {} var cn: C = new C(); - cn; - function foo() { return C; } - var D = foo(); var dn: D = new C(); - dn; - type E = C; var en: E = new C(); - en; - type F = C; var fn: F = new C(); - fn; - type O = { x: X }; var on: O = { x: 0 }; - on; - type Mono = C; var mn: Mono = new C(); - mn; " `; @@ -134,11 +122,8 @@ module.exports = num; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var num = 42; - function bar() {} - bar(); - module.exports = num; " `; @@ -157,7 +142,6 @@ let tests = [ let tests = [ function() { let x = {}; - Object.defineProperty(x, \"foo\", { value: \"\" }); } ]; @@ -185,13 +169,10 @@ function qux(x?) { function foo(x?: string) { return x; } - foo(); - function bar(obj: { x?: string }) { return obj.x; } - function qux(x?) { return x; } @@ -208,11 +189,8 @@ if (Array.isArray(x)) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ let x = 0; - if (x == null) {} - if (x == undefined) {} - if (Array.isArray(x)) {} " `; @@ -222,7 +200,6 @@ exports[`test react.js 1`] = ` React.createElement; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import React from \"react\"; - React.createElement; " `; @@ -254,13 +231,9 @@ const w:MyNum = 42; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var str = require(\"./import\"); - function foo() {} - foo(); - str; - type Point = [number, string]; const x: Point = [ 1, \"foo\" ]; type MyStr = \"cool\"; diff --git a/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap b/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap index 139e58b5..e163844c 100644 --- a/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap @@ -24,11 +24,8 @@ function foo(x: ?string): $NonMaybeType { } else return 0; } - (0: $NonMaybeType); - (0: $NonMaybeType); - (0: $NonMaybeType); " `; @@ -49,9 +46,7 @@ function foo(o: Obj): $PropertyType { type Malformed = $PropertyType; type Obj = { x: string }; type Obj_Prop_x = $PropertyType; - (42: Obj_Prop_x); - function foo(o: Obj): $PropertyType { if (false) return o.x; diff --git a/tests/type-printer/__snapshots__/jsfmt.spec.js.snap b/tests/type-printer/__snapshots__/jsfmt.spec.js.snap index d04f224a..c6f1f442 100644 --- a/tests/type-printer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type-printer/__snapshots__/jsfmt.spec.js.snap @@ -29,13 +29,10 @@ module.exports = printBinaryExpression; * the root directory of this source tree. */ \"use babel\"; - import type {BinaryExpression} from \"./types\"; - function printBinaryExpression(node: BinaryExpression) { console.log(node); } - module.exports = printBinaryExpression; " `; @@ -5114,7 +5111,6 @@ export type JSXSpreadAttribute = { // TODO: Make this correct. // TODO: Make this correct. \"use strict\"; - export type Comment = { type: \"CommentLine\", _CommentLine: void, diff --git a/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap b/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap index 7d03d261..2769d314 100644 --- a/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap @@ -109,7 +109,6 @@ class MyClass2 { y: U; constructor(x: T, y: U) { this.x = x; - this.y = y; } } @@ -125,11 +124,9 @@ class MySubclass extends MyClass { super(y); } } - function singleton(x: T): Array { return [ x ]; } - var num_array: Array = singleton(0); " `; diff --git a/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap b/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap index f02094f2..73e59e3a 100644 --- a/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap @@ -107,7 +107,6 @@ class MyClass2 { y: U; constructor(x: T, y: U) { this.x = x; - this.y = y; } } @@ -123,11 +122,9 @@ class MySubclass extends MyClass { super(y); } } - function singleton(x: T): Array { return [ x ]; } - var num_array: Array = singleton(0); " `; diff --git a/tests/type_only_vars/__snapshots__/jsfmt.spec.js.snap b/tests/type_only_vars/__snapshots__/jsfmt.spec.js.snap index 661f8f1e..097d8b72 100644 --- a/tests/type_only_vars/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_only_vars/__snapshots__/jsfmt.spec.js.snap @@ -19,7 +19,6 @@ module.exports = { */ class Foo {} class Bar {} - module.exports = { Foo: Foo, Bar: Bar }; " `; @@ -96,7 +95,6 @@ var n = Foo; var o = Baz; var a: Foo = new Foo(); var b: Foo = new A.Foo(); - (new A.Bar(): Baz); " `; @@ -132,7 +130,6 @@ var m = A; var n = Foo; var o = Baz; var a: Foo = new actualA.Foo(); - (new actualA.Bar(): Baz); " `; diff --git a/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap index 6f485b21..913a7d62 100644 --- a/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap @@ -98,27 +98,18 @@ var b_number: B = new B(123); var b_void: B = new B(); var b_default: B<> = new B(\"hello\"); var b_star: B<*> = new B(123); - (b_number.p: boolean); - (b_void.p: boolean); - (b_default.p: boolean); - (b_star.p: boolean); - class C extends A {} var c_number: C = new C(123); var c_void: C = new C(); var c_default: C<> = new C(\"hello\"); var c_star: C<*> = new C(\"hello\"); - (c_void.p: boolean); - (c_default.p: boolean); - (c_star.p: boolean); - class D extends A {} var d_number: D = new D(123); var d_void: D = new D(); @@ -126,22 +117,15 @@ var d_default: D = new D(\"hello\"); var d_too_few_args: D<> = new D(\"hello\"); var d_too_many: D = new D(\"hello\"); var d_star: D<*> = new D(10); - (d_number.p: boolean); - (d_void.p: boolean); - (d_default.p: boolean); - (d_star.p: boolean); - class E {} class F {} class G extends A {} var g_default: G = new G(\"hello\"); - (g_default.p: boolean); - class H {} class I extends A {} var i_number: I = new I(123); diff --git a/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap index 56ca7f23..5bb63cb2 100644 --- a/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap @@ -13,7 +13,6 @@ exports[`test class.js 1`] = ` class C { a(x: T, a: A) { this.b(x); - this.b(a); } b(x: T) {} @@ -45,21 +44,14 @@ f(0); // ok function f(a: T) { function g(b: U, c: T = a) { function h(d: U = b) {} - h(); - h(b); - h(c); } - g(0); - g(0, a); - g(0, 0); } - f(0); " `; @@ -157,13 +149,9 @@ class G { } } declare var g: G; - g.m(0); - g.m(true); - (g.m(\"\"): G); - class H { x: T; m(x: T) { diff --git a/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap index b76e51ad..185e5603 100644 --- a/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap @@ -47,13 +47,10 @@ async function foo(x: boolean): Promise { return null; } } - async function run() { console.log(await foo(true)); - console.log(await foo(false)); } - run(); " `; diff --git a/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap index 85c01473..adc9efec 100644 --- a/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap @@ -41,13 +41,10 @@ async function foo(x: boolean): Promise { return null; } } - async function run() { console.log(await foo(true)); - console.log(await foo(false)); } - run(); " `; diff --git a/tests/typeapp_perf/__snapshots__/jsfmt.spec.js.snap b/tests/typeapp_perf/__snapshots__/jsfmt.spec.js.snap index be94c4d3..2de29582 100644 --- a/tests/typeapp_perf/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typeapp_perf/__snapshots__/jsfmt.spec.js.snap @@ -36,7 +36,6 @@ type B = A & +i: () => B }; declare var b: B; - (b: B); " `; @@ -79,7 +78,6 @@ type B = A & +i: (x: B) => void }; declare var b: B; - (b: B); " `; diff --git a/tests/unary/__snapshots__/jsfmt.spec.js.snap b/tests/unary/__snapshots__/jsfmt.spec.js.snap index a268caf4..8caffa30 100644 --- a/tests/unary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unary/__snapshots__/jsfmt.spec.js.snap @@ -28,19 +28,15 @@ function x4(y: string): boolean { function x0(y: string): number { return +y; } - function x1(y: string): number { return -y; } - function x3(y: string) { return ~y; } - function x4(y: string): boolean { return !y; } - (-1: void); " `; @@ -98,18 +94,13 @@ let tests = [ let tests = [ function(y: number) { y++; - y--; - ++y; - --y; }, function(y: string) { y++; - (y: number); - y++; }, function(y: string) { @@ -123,9 +114,7 @@ let tests = [ }, function() { const y = 123; - y++; - y--; }, function(y: any) { diff --git a/tests/undefined/__snapshots__/jsfmt.spec.js.snap b/tests/undefined/__snapshots__/jsfmt.spec.js.snap index 7042def1..8535e766 100644 --- a/tests/undefined/__snapshots__/jsfmt.spec.js.snap +++ b/tests/undefined/__snapshots__/jsfmt.spec.js.snap @@ -17,15 +17,11 @@ foo(); function doSomethingAsync(): Promise { return new Promise((resolve, reject) => { resolve(); - var anotherVoidPromise: Promise = Promise.resolve(); - resolve(anotherVoidPromise); }); } - function foo(x: void) {} - foo(); " `; @@ -45,17 +41,13 @@ function qux(x?: number, y:string = \"\", z) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo() { var x; - x.foo(); } - function bar() { var x: ?{ bar(): void }; - if (x) x.bar(); } - function qux(x?: number, y: string = \"\", z) {} " `; @@ -103,26 +95,18 @@ let tests = [ function(x: number) { var id; var name = id ? \"John\" : undefined; - (name: boolean); - const bar = [ undefined, \"bar\" ]; - (bar[x]: boolean); }, function(x: number) { var undefined = \"foo\"; - (undefined: string); - var x; - if (x !== undefined) { x[0]; } - const bar = [ undefined, \"bar\" ]; - (bar[x]: boolean); } ]; diff --git a/tests/unicode/__snapshots__/jsfmt.spec.js.snap b/tests/unicode/__snapshots__/jsfmt.spec.js.snap index 2c48b0b7..b9fa1163 100644 --- a/tests/unicode/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unicode/__snapshots__/jsfmt.spec.js.snap @@ -62,7 +62,6 @@ function utf16Length(str, pos) { function inSurrogateRange(codeUnit) { return 55296 <= codeUnit && codeUnit <= 57343; } - function utf16Length(str, pos) { return 1 + inSurrogateRange(str.charCodeAt(pos)); } diff --git a/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap b/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap index 2c907e32..4f6d862e 100644 --- a/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap @@ -5004,7 +5004,6 @@ type TAction = { type: \"a1\", a1: number } | { type: \"a998\", a100: number } | { type: \"a999\", a100: number } | { type: \"a1000\", a100: number }; - function foo(x: TAction): TAction { return x; } @@ -5032,25 +5031,18 @@ type A = { a: number }; type B = { b: number }; type C = { c: number }; type T1 = (A | B) & C; - function f1(x: T1): T1 { return x; } - type T2 = (A & B) | C; - function f2(x: T2): T2 { return x; } - type T3 = (A & C) | (B & C); - function f3(x: T3): T3 { return x; } - type T4 = (A | C) & (B | C); - function f4(x: T4): T4 { return x; } diff --git a/tests/union/__snapshots__/jsfmt.spec.js.snap b/tests/union/__snapshots__/jsfmt.spec.js.snap index 33a6c05e..abb305ad 100644 --- a/tests/union/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union/__snapshots__/jsfmt.spec.js.snap @@ -31,7 +31,6 @@ class D { content: string | C; copyContent(content: C): string | C { this.content = content; - return this.content; } } @@ -107,9 +106,7 @@ myclass.myfun([\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", function (ar) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare class Myclass { myfun(myarray: Array): any } declare var myclass: Myclass; - myclass.myfun([ \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", function(ar) {} ]); - myclass.myfun([ \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", function(ar) {} ]); " `; @@ -132,7 +129,6 @@ module.exports = Foo; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ class Foo {} - module.exports = Foo; " `; @@ -152,7 +148,6 @@ class Foo {} class Bar {} var foostr: Foo | string = new Foo(); var barstr: Bar | string = new Bar(); - foostr = barstr; " `; @@ -314,21 +309,14 @@ var C = require(\"test-lib\"); type Foo = Array; var x: Array = []; var y: Array = []; - function foo(x: Foo) {} - foo(x); - foo(y); - type Bar = () => C | string; - function f() { return \"\"; } - function bar(x: Bar) {} - bar(f); " `; @@ -341,7 +329,6 @@ module.exports = C; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule test-lib */ class C {} - module.exports = C; " `; @@ -403,28 +390,19 @@ function corge(b) { // this annotation is an error: is it C, or is it D? // OK function bar(x: Document | string): void {} - bar(0); - class C {} class D {} - function CD(b) { var E = b ? C : D; var c: C = new E(); - function qux(e: E) {} - function qux2(e: C | D) {} - qux2(new C()); } - declare class F { foo(x: number): void, foo(x: string): void } - function corge(b) { var x = b ? \"\" : 0; - new F().foo(x); } " @@ -5477,7 +5455,6 @@ type Data = { // but not sure it\'s worth doing that before the real solution. // also, error pos omits this line completely \"use strict\"; - class SecurityCheckupTypedLogger { _data: Data; setError(value: ErrorCode) { diff --git a/tests/union_new/__snapshots__/jsfmt.spec.js.snap b/tests/union_new/__snapshots__/jsfmt.spec.js.snap index a71d9ff9..8086d870 100644 --- a/tests/union_new/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union_new/__snapshots__/jsfmt.spec.js.snap @@ -25,9 +25,7 @@ class VirtualNode { type T = A | B; class U {} declare var children: U; - (children: T | U); - class A {} class B {} type VirtualElement = Thunk | VirtualNode; @@ -149,9 +147,7 @@ function node(content: ?Foobar | String | Array) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ import type {Foobar} from \"./issue-1455-helper\"; - function create(content: ?Foobar | String | Array) {} - function node(content: ?Foobar | String | Array) { create(content); } @@ -197,11 +193,9 @@ type Common = {}; type A = Common & { type: \"A\", foo: number }; type B = Common & { type: \"B\", foo: Array }; type MyType = A | B; - function print(x: number) { console.log(x); } - function printAll(val: MyType) { print(val.foo); } @@ -241,11 +235,9 @@ type Common = {}; type A = { type: \"A\", foo: number } & Common; type B = { type: \"B\", foo: Array } & Common; type MyType = A | B; - function print(x: number) { console.log(x); } - function printAll(val: MyType) { if (val.type === \"A\") { print(val.foo); @@ -290,7 +282,6 @@ type UserData = DataBase & { kind: \"user\" }; type SystemData = DataBase & { kind: \"system\" }; type Data = UserData | SystemData; const data: Data = { id: \"\", name: \"\", kind: \"system\" }; - if (data.kind === \"system\") { (data: SystemData); } @@ -310,7 +301,6 @@ function hello(x:X): string { // @flow //type X = {a:true, b:string} | {a:false, c:string}; // this works. type X = ({ a: true } & { b: string }) | ({ a: false } & { c: string }); - function hello(x: X): string { if (x.a === true) return x.b; @@ -351,7 +341,6 @@ type Entity = { id: T, name: string }; type StringEntity = Entity; type Foo = StringEntity & { bars: Object, kind: 1 }; type EmptyFoo = StringEntity & { bars: null, kind: 2 }; - function test(f: Foo | EmptyFoo) { if (f.kind === 1) { (f: Foo); @@ -444,34 +433,25 @@ type A6 = B6[]; function obj(a: A1 | A2) { return a.x; } - const obj_result = obj({ x: \"\" }); type A1 = { x: B1 }; type A2 = { x: B2 }; type B1 = number; type B2 = string; - (obj_result: B1 | B2); - function fun(a: A3 | A4) { return a(); } - const fun_result = fun(() => \"\"); type A3 = () => B3; type A4 = () => B4; type B3 = number; type B4 = string; - (fun_result: B3 | B4); - function inst(a: A5 | A6) {} - class B5 {} class B6 {} - inst([ new B6() ]); - type A5 = B5[]; type A6 = B6[]; " @@ -575,50 +555,32 @@ type B6 = string; // class statics // tuples function obj(a: { x: number } | { x: string }) {} - obj(({ x: \"\" }: A1)); - type A1 = { x: B1 }; type B1 = string; - function fun(a: (() => number) | (() => string)) {} - fun((() => \"\": A2)); - type A2 = () => B2; type B2 = string; class C {} - function inst(a: C | C) {} - inst((new C(): A3)); - type A3 = C; type B3 = string; - function alias(a: T | T) {} - alias({ x: (x: V) => {} }); - type T = { x: U }; type U = (x: V) => void; type V = X; type B4 = string; - function stat(a: { x: number } | { x: string }) {} - class D { static x: B5; } - stat(D); - type B5 = string; - function tup(a: [number, boolean] | [string, boolean]) {} - tup(([ \"\", false ]: A6)); - type A6 = [B6, boolean]; type B6 = string; " @@ -666,16 +628,11 @@ type B2 = string; // example with array types //////////////////////////// function fun(a: ((x: number) => void) | ((x: string) => void)) {} - fun((x => {}: A1)); - type A1 = (x: B1) => void; type B1 = string; - function arr(a: number[] | string[]) {} - arr(([]: A2)); - type A2 = B2[]; type B2 = string; " @@ -730,32 +687,22 @@ type B2 = string; // example with array types //////////////////////////// function fun(a: ((x: number) => void) | ((x: string) => void)) {} - const a1 = (x => {}: A1); - fun(a1); - function fun_call(x: string) { a1(x); } - type A1 = (x: B1) => void; type B1 = string; - function arr(a: number[] | string[]) {} - const a2 = ([]: A2); - arr(a2); - function arr_set(x: string, i: number) { a2[i] = x; } - function arr_get(i: number): string { return a2[i]; } - type A2 = B2[]; type B2 = string; " @@ -801,23 +748,16 @@ function arr_set(x: string, i: number) { a2[i] = x; } // example with array types ///////////////////////////// function fun(a: ((x: number) => number) | ((x: string) => string)) {} - function a1(x) { return x; } - fun(a1); - function fun_call(x: string): string { return a1(x); } - function arr(a: number[] | string[]) {} - var a2 = []; - arr(a2); - function arr_set(x: string, i: number) { a2[i] = x; } @@ -861,7 +801,6 @@ class C { } function inst(a: E): C | C { return a; } - const mk_C = () => C; const mk_D = () => D; const mk_E = () => E; @@ -916,20 +855,15 @@ type PG = { x: X, y?: PG }; // polymorphic recursive types /////////////////////////////// function rec(x: F1 | F2) {} - rec({ x: 0 }); - type F1 = G1; type F2 = G2; type G1 = { x: H1, y?: G1 }; type G2 = { x: H2, y?: G2 }; type H1 = string; type H2 = number; - function polyrec(x: PF | PF) {} - rec({ x: 0 }); - type PF = PG; type PG = { x: X, y?: PG }; " @@ -968,9 +902,7 @@ type H2_ = number; // nested union types ////////////////////// function rec(x: F1 | F2) {} - rec({ x: 0 }); - type F1 = G1 | G1_; type F2 = G2 | G2_; type G1 = { x: H1 }; @@ -1012,9 +944,7 @@ foo((x): number => square(x)) function square(x? = 0) { return x * x; } - function foo(f: ((_: ?number) => ?number) | (() => void)) {} - foo((x): number => square(x)); " `; @@ -1125,42 +1055,24 @@ check_poly_inst(new P); function id(x: X): X { return x; } - function check_prim(_: number | string) {} - check_prim(\"\"); - check_prim(id(\"\")); - class C {} class D {} - function check_inst(_: C | D) {} - check_inst(new D()); - check_inst(id(new C())); - function check_fun(_: ((_: number) => number) | ((_: string) => string)) {} - check_fun(x => x); - function check_obj(_: { x: number } | { x: string }) {} - check_obj({ x: \"\" }); - check_obj({ x: id(\"\") }); - function check_arr(_: number[] | string[]) {} - check_arr([ \"\" ]); - check_arr([ id(\"\") ]); - class P {} - function check_poly_inst(_: P | P) {} - check_poly_inst(new P()); " `; @@ -1195,15 +1107,10 @@ function length(list: List) { else return 0; } - length({ kind: \"nil\" }); - length({ kind: \"cons\" }); - length({ kind: \"cons\", next: { kind: \"nil\" } }); - length({ kind: \"empty\" }); - type List = Nil | Cons; type Nil = { kind: \"nil\" }; type Cons = { kind: \"cons\", next: List }; @@ -1226,7 +1133,6 @@ function rec(x: F): G | H { return x; } type F = { f: F, x: X }; type G = { x: number }; type H = { x: string }; - function rec(x: F): G | H { return x; } @@ -1271,9 +1177,7 @@ function foo(c: C) { // @noflow // annotations declare class C { get(): X } - function union(o: { x: string } | { x: number }) {} - function foo(c: C) { union({ x: c.get() }); } @@ -1312,7 +1216,6 @@ bar(() => { }); function foo(target: EventTarget) { target.addEventListener(\"click\", e => {}); } - declare class EventTarget { addEventListener(type: \"foo\", listener: KeyboardEventHandler): void, addEventListener(type: string, listener: EventHandler): void @@ -1321,9 +1224,7 @@ declare class Event {} declare class KeyboardEvent {} type EventHandler = (event: Event) => mixed; type KeyboardEventHandler = (event: KeyboardEvent) => mixed; - function bar(x: (() => void) | { x: number }) {} - bar(() => {}); " `; @@ -1353,21 +1254,14 @@ x = \"\"; type T = number | (() => string); type Foo = T | (() => boolean); type Bar = number | (() => string) | (() => boolean); - function foo(x: Foo) {} - foo(() => qux()); - function bar(x: Bar) {} - bar(() => qux()); - var x = false; - function qux() { return x; } - x = \"\"; " `; @@ -1384,7 +1278,6 @@ exports[`test test17.js 1`] = ` // @noflow // Array#concat [].concat([]); - ([].concat([ 0, 1 ])[1]: string); " `; @@ -1406,11 +1299,9 @@ new C().m(f()); // @noflow // method overloads declare class C { m(x: number): void, m(x: string): void } - function f() { return 0; } - new C().m(f()); " `; @@ -1434,7 +1325,6 @@ declare class D { function m() { return new D(); } - declare class D { constructor(_: void): void, constructor(_: null): void } " `; @@ -1458,14 +1348,12 @@ exports[`test test20.js 1`] = ` // @noflow // Array#reduce [ 0, 1 ].reduce((x, y, i) => y); - [ \"a\", \"b\" ].reduce( (regex, representation, index) => { return regex + (index ? \"|\" : \"\") + \"(\" + representation + \")\"; }, \"\" ); - [ \"\" ].reduce((acc, str) => acc * str.length); " `; @@ -1496,17 +1384,12 @@ function str() { // @noflow // annotations for disjoint unions type T = { type: \"FOO\", x: number } | { type: \"BAR\", x: string }; - ({ type: (bar(): \"BAR\"), x: str() }: T); - ({ type: bar(), x: str() }: T); - ({ type: bar(), x: (str(): string) }: T); - function bar() { return \"BAR\"; } - function str() { return \"hello\"; } @@ -1542,7 +1425,6 @@ type Empty = {}; type Success = { type: \"SUCCESS\", result: string }; type Error = { type: \"ERROR\" } & Empty; export type T = Success | Error; - function foo(x: T) { if (x.type === \"SUCCESS\") return x.result; @@ -1572,10 +1454,8 @@ function foo(obj: Obj) { // should also be OK (the check above shouldn\'t affect anything) type NestedObj = {} & { dummy: SomeLibClass }; type Obj = NestedObj & { x: string }; - function foo(obj: Obj) { obj.x; - obj.x; } " @@ -1643,7 +1523,6 @@ declare class D extends C { ref(): D, unref(): D } - (0: D | number); " `; @@ -1700,19 +1579,14 @@ new Record().set(\'foo\', \"42\"); declare function foo(x: number): number; declare function foo(x: string): string; declare var x: number | string; - (foo(x): number | string); - type T = number | string; declare var y: T; - (foo(y): T); - declare class Record { set(x: \"foo\", y: number): void, set(x: \"bar\", y: string): void } - new Record().set(\"foo\", \"42\"); " `; @@ -1742,21 +1616,18 @@ function hello4(x:X): string { // @noflow //type X = {a:true, b:string} | {a:false, c:string}; // this works. type X = ({ a: true } & { b: string }) | ({ a: false } & { c: string }); - function hello1(x: X): string { if (x.a === true) return x.b; else return x.c; } - function hello2(x: X): string { if (x.a === false) return x.c; else return x.b; } - function hello3(x: X): string { if (x.a) { return x.b; @@ -1764,7 +1635,6 @@ function hello3(x: X): string { return x.c; } } - function hello4(x: X): string { if (!x.a) { return x.c; @@ -1846,7 +1716,6 @@ type ActionType = // @noflow const Constants = require(\"./test30-helper\"); type ActionType = { type: \"foo\", x: number } | { type: \"bar\", x: number }; - ({ type: Constants.BAR, x: 0 }: ActionType); " `; @@ -1902,12 +1771,9 @@ declare class SomeMap { } declare class ImmutableMap {} declare function convert(iter: SomeIterable<[K, V]>): ImmutableMap; - function foo(): ImmutableMap { const countersGlobalMap = new SomeMap(); - countersGlobalMap.set(\"\", false); - return convert(countersGlobalMap); } " diff --git a/tests/unreachable/__snapshots__/jsfmt.spec.js.snap b/tests/unreachable/__snapshots__/jsfmt.spec.js.snap index 90ffeeb5..2d243973 100644 --- a/tests/unreachable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unreachable/__snapshots__/jsfmt.spec.js.snap @@ -30,16 +30,13 @@ function test2() { // error, n is number (EmptyT would work) function test1(): string { return bar(); - function bar() { return 0; } } - function test2() { const n = 0; return; - function f() { var x: typeof n = 0; var y: string = n; @@ -84,20 +81,16 @@ foo(1, 2); // assignments are not hoisted, should generate 2 warnings function foo(x, y) { \"use strict\"; - return bar(x) + baz(y); - function bar(ecks) { return x + ecks; } - var baz = function(why) { return y + why; }; var x, y, z; var t, u = 5, v, w = 7; } - foo(1, 2); " `; diff --git a/tests/value/__snapshots__/jsfmt.spec.js.snap b/tests/value/__snapshots__/jsfmt.spec.js.snap index e7d87b35..cb0d055f 100644 --- a/tests/value/__snapshots__/jsfmt.spec.js.snap +++ b/tests/value/__snapshots__/jsfmt.spec.js.snap @@ -7,12 +7,9 @@ var table: { [_: string]: number } = {}; table[\"x\"] = \"hello\"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var o = {}; - o[\"x\"] = 4; - var y: string = o[\"x\"]; var table: { [_: string]: number } = {}; - table[\"x\"] = \"hello\"; " `; diff --git a/tests/weakmode/__snapshots__/jsfmt.spec.js.snap b/tests/weakmode/__snapshots__/jsfmt.spec.js.snap index 4d9942af..3b30766d 100644 --- a/tests/weakmode/__snapshots__/jsfmt.spec.js.snap +++ b/tests/weakmode/__snapshots__/jsfmt.spec.js.snap @@ -15,7 +15,6 @@ function expects_an_int() { function returns_a_string() { return \"Hello\"; } - function expects_an_int() { return returns_a_string() * 10; } @@ -39,7 +38,6 @@ function expects_an_int() { function returns_a_string() { return \"Hello\"; } - function expects_an_int() { return returns_a_string() * 10; } diff --git a/tests/while/__snapshots__/jsfmt.spec.js.snap b/tests/while/__snapshots__/jsfmt.spec.js.snap index bbb9bc10..9c3cd3b2 100644 --- a/tests/while/__snapshots__/jsfmt.spec.js.snap +++ b/tests/while/__snapshots__/jsfmt.spec.js.snap @@ -29,11 +29,9 @@ function foo(x: boolean) { if (x) { continue; } - return; } } - function bar(x: boolean) { var ii = 0; while (ii > 0) { @@ -61,16 +59,12 @@ class C { return new C(); } } - function blah() {} - var node: ?C = new C(); while (node) { var parent = node.m(); var cloneable: C = node; - blah(); - node = parent.m(); } " diff --git a/tests/x/__snapshots__/jsfmt.spec.js.snap b/tests/x/__snapshots__/jsfmt.spec.js.snap index c579fbbe..492f2dd0 100644 --- a/tests/x/__snapshots__/jsfmt.spec.js.snap +++ b/tests/x/__snapshots__/jsfmt.spec.js.snap @@ -56,7 +56,6 @@ class XControllerURIBuilder { var tokenRegex = new RegExp(/^\\{(\\?)?(.+?)\\}$/); } } - module.exports = XControllerURIBuilder; " `;