diff --git a/packages/babel-generator/src/generators/expressions.js b/packages/babel-generator/src/generators/expressions.js index 8aa84f2f5e..b331880ce1 100644 --- a/packages/babel-generator/src/generators/expressions.js +++ b/packages/babel-generator/src/generators/expressions.js @@ -67,6 +67,7 @@ export function NewExpression(node: Object, parent: Object) { return; } + this.print(node.typeArguments, node); // Flow this.print(node.typeParameters, node); // TS if (node.optional) { @@ -125,6 +126,7 @@ export function OptionalMemberExpression(node: Object) { export function OptionalCallExpression(node: Object) { this.print(node.callee, node); + this.print(node.typeArguments, node); // Flow this.print(node.typeParameters, node); // TS if (node.optional) { @@ -138,6 +140,7 @@ export function OptionalCallExpression(node: Object) { export function CallExpression(node: Object) { this.print(node.callee, node); + this.print(node.typeArguments, node); // Flow this.print(node.typeParameters, node); // TS this.token("("); this.printList(node.arguments, node); diff --git a/packages/babel-generator/test/fixtures/flow/typeapp-call/input.js b/packages/babel-generator/test/fixtures/flow/typeapp-call/input.js new file mode 100644 index 0000000000..d27c256fc3 --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/typeapp-call/input.js @@ -0,0 +1,18 @@ +// @flow +f(); +f; +new C; +f(e); +o[e](); +f(x)(y); +async () => {}; +async (): T => {} +new C(e); +f[e]; +new C(); +o.m(); +f.0; +o?.m(e); +o.m?.(e); +async(); +f?.(e); diff --git a/packages/babel-generator/test/fixtures/flow/typeapp-call/options.json b/packages/babel-generator/test/fixtures/flow/typeapp-call/options.json new file mode 100644 index 0000000000..a33f917064 --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/typeapp-call/options.json @@ -0,0 +1 @@ +{ "plugins": ["jsx", "optionalChaining", "flow"] } diff --git a/packages/babel-generator/test/fixtures/flow/typeapp-call/output.js b/packages/babel-generator/test/fixtures/flow/typeapp-call/output.js new file mode 100644 index 0000000000..2c2f43ea08 --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/typeapp-call/output.js @@ -0,0 +1,21 @@ +// @flow +f(); +f < T > ; +new C(); +f(e); +o[e](); +f(x)(y); + +async () => {}; + +async (): T => {}; + +new C(e); +f < T > [e]; +new C(); +o.m(); +f < T > .0; +o?.m(e); +o.m?.(e); +async(); +f?.(e); \ No newline at end of file diff --git a/packages/babel-plugin-syntax-flow/src/index.js b/packages/babel-plugin-syntax-flow/src/index.js index 3ad2fbb2db..855586638b 100644 --- a/packages/babel-plugin-syntax-flow/src/index.js +++ b/packages/babel-plugin-syntax-flow/src/index.js @@ -1,11 +1,15 @@ import { declare } from "@babel/helper-plugin-utils"; -export default declare(api => { +export default declare((api, options) => { api.assertVersion(7); + // When enabled and plugins includes flow, all files should be parsed as if + // the @flow pragma was provided. + const { all } = options; + return { manipulateOptions(opts, parserOpts) { - parserOpts.plugins.push("flow"); + parserOpts.plugins.push(["flow", { all }]); }, }; }); diff --git a/packages/babel-plugin-transform-flow-strip-types/src/index.js b/packages/babel-plugin-transform-flow-strip-types/src/index.js index ae633effd3..9e2ec6aac1 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -108,6 +108,21 @@ export default declare(api => { } while (t.isTypeCastExpression(node)); path.replaceWith(node); }, + + CallExpression({ node }) { + if (skipStrip) return; + node.typeArguments = null; + }, + + OptionalCallExpression({ node }) { + if (skipStrip) return; + node.typeArguments = null; + }, + + NewExpression({ node }) { + if (skipStrip) return; + node.typeArguments = null; + }, }, }; }); diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-typeapp-call/input.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-typeapp-call/input.js new file mode 100644 index 0000000000..d27c256fc3 --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-typeapp-call/input.js @@ -0,0 +1,18 @@ +// @flow +f(); +f; +new C; +f(e); +o[e](); +f(x)(y); +async () => {}; +async (): T => {} +new C(e); +f[e]; +new C(); +o.m(); +f.0; +o?.m(e); +o.m?.(e); +async(); +f?.(e); diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-typeapp-call/options.json b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-typeapp-call/options.json new file mode 100644 index 0000000000..06f4fa1ede --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-typeapp-call/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["syntax-jsx", "syntax-optional-chaining", "transform-flow-strip-types"] +} diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-typeapp-call/output.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-typeapp-call/output.js new file mode 100644 index 0000000000..2d91f26e8b --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-typeapp-call/output.js @@ -0,0 +1,20 @@ +f(); +f < T > ; +new C(); +f(e); +o[e](); +f(x)(y); + +async () => {}; + +async () => {}; + +new C(e); +f < T > [e]; +new C(); +o.m(); +f < T > .0; +o?.m(e); +o.m?.(e); +async(); +f?.(e); diff --git a/packages/babel-types/README.md b/packages/babel-types/README.md index d4b183a29b..417ba98145 100644 --- a/packages/babel-types/README.md +++ b/packages/babel-types/README.md @@ -231,7 +231,8 @@ Aliases: `Expression` - `callee`: `Expression` (required) - `arguments`: `Array` (required) - `optional`: `true | false` (default: `null`) - - `typeParameters`: `TypeParameterInstantiation | TSTypeParameterInstantiation` (default: `null`) + - `typeArguments`: `TypeParameterInstantiation` (default: `null`) + - `typeParameters`: `TSTypeParameterInstantiation` (default: `null`) --- @@ -1359,7 +1360,8 @@ Aliases: `Expression` - `callee`: `Expression` (required) - `arguments`: `Array` (required) - `optional`: `true | false` (default: `null`) - - `typeParameters`: `TypeParameterInstantiation | TSTypeParameterInstantiation` (default: `null`) + - `typeArguments`: `TypeParameterInstantiation` (default: `null`) + - `typeParameters`: `TSTypeParameterInstantiation` (default: `null`) --- @@ -1621,7 +1623,8 @@ Aliases: `Expression` - `callee`: `Expression` (required) - `arguments`: `Array` (required) - `optional`: `boolean` (required) - - `typeParameters`: `TypeParameterInstantiation | TSTypeParameterInstantiation` (default: `null`) + - `typeArguments`: `TypeParameterInstantiation` (default: `null`) + - `typeParameters`: `TSTypeParameterInstantiation` (default: `null`) --- diff --git a/packages/babel-types/src/definitions/core.js b/packages/babel-types/src/definitions/core.js index ab1e8b70b3..d12807df9f 100644 --- a/packages/babel-types/src/definitions/core.js +++ b/packages/babel-types/src/definitions/core.js @@ -137,11 +137,12 @@ defineType("CallExpression", { validate: assertOneOf(true, false), optional: true, }, + typeArguments: { + validate: assertNodeType("TypeParameterInstantiation"), + optional: true, + }, typeParameters: { - validate: assertNodeType( - "TypeParameterInstantiation", - "TSTypeParameterInstantiation", - ), + validate: assertNodeType("TSTypeParameterInstantiation"), optional: true, }, }, diff --git a/packages/babel-types/src/definitions/experimental.js b/packages/babel-types/src/definitions/experimental.js index 87d4cafcfa..98e78bdfdf 100644 --- a/packages/babel-types/src/definitions/experimental.js +++ b/packages/babel-types/src/definitions/experimental.js @@ -105,11 +105,12 @@ defineType("OptionalCallExpression", { optional: { validate: assertValueType("boolean"), }, + typeArguments: { + validate: assertNodeType("TypeParameterInstantiation"), + optional: true, + }, typeParameters: { - validate: assertNodeType( - "TypeParameterInstantiation", - "TSTypeParameterInstantiation", - ), + validate: assertNodeType("TSTypeParameterInstantiation"), optional: true, }, }, diff --git a/packages/babylon/src/parser/expression.js b/packages/babylon/src/parser/expression.js index d6c09adcf7..89e15210e9 100644 --- a/packages/babylon/src/parser/expression.js +++ b/packages/babylon/src/parser/expression.js @@ -502,7 +502,6 @@ export default class ExpressionParser extends LValParser { possibleAsync, ); node.optional = true; - return this.finishNode(node, "OptionalCallExpression"); } else { node.object = base; diff --git a/packages/babylon/src/parser/util.js b/packages/babylon/src/parser/util.js index 7871141ca7..d889982f83 100644 --- a/packages/babylon/src/parser/util.js +++ b/packages/babylon/src/parser/util.js @@ -23,6 +23,11 @@ export default class UtilParser extends Tokenizer { return this.match(tt.relational) && this.state.value === op; } + isLookaheadRelational(op: "<" | ">"): boolean { + const l = this.lookahead(); + return l.type == tt.relational && l.value == op; + } + // TODO expectRelational(op: "<" | ">"): void { diff --git a/packages/babylon/src/plugins/flow.js b/packages/babylon/src/plugins/flow.js index 7dba4ca5e0..87a738e464 100644 --- a/packages/babylon/src/plugins/flow.js +++ b/packages/babylon/src/plugins/flow.js @@ -64,8 +64,41 @@ function partition( return [list1, list2]; } +const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/; + export default (superClass: Class): Class => class extends superClass { + // The value of the @flow/@noflow pragma. Initially undefined, transitions + // to "@flow" or "@noflow" if we see a pragma. Transitions to null if we are + // past the initial comment. + flowPragma: void | null | "flow" | "noflow"; + + constructor(options: ?Options, input: string) { + super(options, input); + this.flowPragma = undefined; + } + + shouldParseTypes(): boolean { + return this.getPluginOption("flow", "all") || this.flowPragma === "flow"; + } + + addComment(comment: Comment): void { + if (this.flowPragma === undefined) { + // Try to parse a flow pragma. + const matches = FLOW_PRAGMA_REGEX.exec(comment.value); + if (!matches) { + this.flowPragma = null; + } else if (matches[1] === "flow") { + this.flowPragma = "flow"; + } else if (matches[1] === "noflow") { + this.flowPragma = "noflow"; + } else { + throw new Error("Unexpected flow pragma"); + } + } + return super.addComment(comment); + } + flowParseTypeInitialiser(tok?: TokenType): N.FlowType { const oldInType = this.state.inType; this.state.inType = true; @@ -1370,7 +1403,12 @@ export default (superClass: Class): Class => this.next(); return this.flowParseInterface(node); } else { - return super.parseStatement(declaration, topLevel); + const stmt = super.parseStatement(declaration, topLevel); + // We will parse a flow pragma in any comment before the first statement. + if (this.flowPragma === undefined && !this.isValidDirective(stmt)) { + this.flowPragma = null; + } + return stmt; } } @@ -2375,6 +2413,85 @@ export default (superClass: Class): Class => return super.parseSubscripts(base, startPos, startLoc, noCalls); } + parseSubscript( + base: N.Expression, + startPos: number, + startLoc: Position, + noCalls: ?boolean, + subscriptState: N.ParseSubscriptState, + ): N.Expression { + if (this.match(tt.questionDot) && this.isLookaheadRelational("<")) { + this.expectPlugin("optionalChaining"); + subscriptState.optionalChainMember = true; + if (noCalls) { + subscriptState.stop = true; + return base; + } + this.next(); + const node: N.OptionalCallExpression = this.startNodeAt( + startPos, + startLoc, + ); + node.callee = base; + node.typeArguments = this.flowParseTypeParameterInstantiation(); + this.expect(tt.parenL); + node.arguments = this.parseCallExpressionArguments(tt.parenR, false); + node.optional = true; + return this.finishNode(node, "OptionalCallExpression"); + } else if ( + !noCalls && + this.shouldParseTypes() && + this.isRelational("<") + ) { + const node: N.CallExpression = this.startNodeAt(startPos, startLoc); + node.callee = base; + const state = this.state.clone(); + try { + node.typeArguments = this.flowParseTypeParameterInstantiation(); + this.expect(tt.parenL); + node.arguments = this.parseCallExpressionArguments(tt.parenR, false); + if (subscriptState.optionalChainMember) { + node.optional = false; + return this.finishNode(node, "OptionalCallExpression"); + } + return this.finishNode(node, "CallExpression"); + } catch (e) { + if (e instanceof SyntaxError) { + this.state = state; + } else { + throw e; + } + } + } + + return super.parseSubscript( + base, + startPos, + startLoc, + noCalls, + subscriptState, + ); + } + + parseNewArguments(node: N.NewExpression): void { + let targs = null; + if (this.shouldParseTypes() && this.isRelational("<")) { + const state = this.state.clone(); + try { + targs = this.flowParseTypeParameterInstantiation(); + } catch (e) { + if (e instanceof SyntaxError) { + this.state = state; + } else { + throw e; + } + } + } + node.typeArguments = targs; + + super.parseNewArguments(node); + } + parseAsyncArrowWithTypeParameters( startPos: number, startLoc: Position, diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/async-call/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/async-call/input.js new file mode 100644 index 0000000000..3e9a44083c --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/async-call/input.js @@ -0,0 +1,2 @@ +// @flow +async(); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/async-call/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/async-call/output.json new file mode 100644 index 0000000000..94ae974c0f --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/async-call/output.json @@ -0,0 +1,168 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "expression": { + "type": "CallExpression", + "start": 9, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "callee": { + "type": "Identifier", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "async" + }, + "name": "async" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/async-generic-arrow/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/async-generic-arrow/input.js new file mode 100644 index 0000000000..05d9c531ff --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/async-generic-arrow/input.js @@ -0,0 +1,3 @@ +// @flow +async () => {}; +async (): T => {} diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/async-generic-arrow/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/async-generic-arrow/output.json new file mode 100644 index 0000000000..11e4113866 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/async-generic-arrow/output.json @@ -0,0 +1,289 @@ +{ + "type": "File", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 9, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "name": "T", + "variance": null + } + ] + }, + "params": [], + "id": null, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "body": [], + "directives": [] + } + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + }, + { + "type": "ExpressionStatement", + "start": 28, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 28, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 34, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "name": "T", + "variance": null + } + ] + }, + "params": [], + "predicate": null, + "returnType": { + "type": "TypeAnnotation", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + }, + "identifierName": "T" + }, + "name": "T" + } + } + }, + "id": null, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 46, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-call/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-call/input.js new file mode 100644 index 0000000000..13d3d3b790 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-call/input.js @@ -0,0 +1 @@ +f(e); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-call/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-call/output.json new file mode 100644 index 0000000000..7aef11d5b0 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-call/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "left": { + "type": "BinaryExpression", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "operator": "<", + "right": { + "type": "Identifier", + "start": 2, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "T" + }, + "name": "T" + } + }, + "operator": ">", + "right": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "e" + }, + "name": "e", + "extra": { + "parenthesized": true, + "parenStart": 4 + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-new/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-new/input.js new file mode 100644 index 0000000000..b51cafcd75 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-new/input.js @@ -0,0 +1 @@ +new C(e); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-new/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-new/output.json new file mode 100644 index 0000000000..2322c67e51 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/disabled-ambiguous-new/output.json @@ -0,0 +1,153 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "left": { + "type": "BinaryExpression", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "left": { + "type": "NewExpression", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "callee": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "C" + }, + "name": "C" + }, + "typeArguments": null, + "arguments": [] + }, + "operator": "<", + "right": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "T" + }, + "name": "T" + } + }, + "operator": ">", + "right": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "e" + }, + "name": "e", + "extra": { + "parenthesized": true, + "parenStart": 8 + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/function-call-chain/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-chain/input.js new file mode 100644 index 0000000000..1768d2cdd5 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-chain/input.js @@ -0,0 +1,2 @@ +// @flow +f(x)(y); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/function-call-chain/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-chain/output.json new file mode 100644 index 0000000000..3485f17b61 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-chain/output.json @@ -0,0 +1,270 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "expression": { + "type": "CallExpression", + "start": 9, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "callee": { + "type": "CallExpression", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "callee": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + } + ] + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "U" + }, + "name": "U" + } + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "y" + }, + "name": "y" + } + ] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/function-call-optional/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-optional/input.js new file mode 100644 index 0000000000..dc184b4aab --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-optional/input.js @@ -0,0 +1,2 @@ +// @flow +f?.(e); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/function-call-optional/options.json b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-optional/options.json new file mode 100644 index 0000000000..05e42d8105 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-optional/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["jsx", "flow", "optionalChaining"] +} diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/function-call-optional/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-optional/output.json new file mode 100644 index 0000000000..29c2e9a179 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/function-call-optional/output.json @@ -0,0 +1,187 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "expression": { + "type": "OptionalCallExpression", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "callee": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "e" + }, + "name": "e" + } + ], + "optional": true + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/function-call/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/function-call/input.js new file mode 100644 index 0000000000..124d341d63 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/function-call/input.js @@ -0,0 +1,2 @@ +// @flow +f(); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/function-call/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/function-call/output.json new file mode 100644 index 0000000000..4ddde5608c --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/function-call/output.json @@ -0,0 +1,168 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "expression": { + "type": "CallExpression", + "start": 9, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "callee": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call-computed/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-computed/input.js new file mode 100644 index 0000000000..878b1ae95d --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-computed/input.js @@ -0,0 +1,2 @@ +// @flow +o[e](); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call-computed/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-computed/output.json new file mode 100644 index 0000000000..156426ba12 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-computed/output.json @@ -0,0 +1,201 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "expression": { + "type": "CallExpression", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "callee": { + "type": "MemberExpression", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "object": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "o" + }, + "name": "o" + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "e" + }, + "name": "e" + }, + "computed": true + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional/input.js new file mode 100644 index 0000000000..413c2e4d2f --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional/input.js @@ -0,0 +1,2 @@ +// @flow +o?.m(e); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional/options.json b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional/options.json new file mode 100644 index 0000000000..05e42d8105 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["jsx", "flow", "optionalChaining"] +} diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional/output.json new file mode 100644 index 0000000000..cd667d811f --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional/output.json @@ -0,0 +1,221 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "expression": { + "type": "OptionalCallExpression", + "start": 9, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "callee": { + "type": "OptionalMemberExpression", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "object": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "o" + }, + "name": "o" + }, + "property": { + "type": "Identifier", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "m" + }, + "name": "m" + }, + "computed": false, + "optional": true + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "e" + }, + "name": "e" + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional2/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional2/input.js new file mode 100644 index 0000000000..c9d0767354 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional2/input.js @@ -0,0 +1,2 @@ +// @flow +o.m?.(e); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional2/options.json b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional2/options.json new file mode 100644 index 0000000000..05e42d8105 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional2/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["jsx", "flow", "optionalChaining"] +} diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional2/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional2/output.json new file mode 100644 index 0000000000..ae40c58359 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call-optional2/output.json @@ -0,0 +1,220 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "expression": { + "type": "OptionalCallExpression", + "start": 9, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "callee": { + "type": "MemberExpression", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "object": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "o" + }, + "name": "o" + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "m" + }, + "name": "m" + }, + "computed": false + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "e" + }, + "name": "e" + } + ], + "optional": true + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/method-call/input.js new file mode 100644 index 0000000000..88640eae63 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call/input.js @@ -0,0 +1,2 @@ +// @flow +o.m(); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/method-call/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/method-call/output.json new file mode 100644 index 0000000000..6fde3137e5 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/method-call/output.json @@ -0,0 +1,201 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "expression": { + "type": "CallExpression", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "callee": { + "type": "MemberExpression", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "object": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "o" + }, + "name": "o" + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "m" + }, + "name": "m" + }, + "computed": false + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/new-noparens/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/new-noparens/input.js new file mode 100644 index 0000000000..91b85b6ba9 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/new-noparens/input.js @@ -0,0 +1,2 @@ +// @flow +new C; diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/new-noparens/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/new-noparens/output.json new file mode 100644 index 0000000000..902a0f80de --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/new-noparens/output.json @@ -0,0 +1,168 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "expression": { + "type": "NewExpression", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "callee": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "C" + }, + "name": "C" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/new/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/new/input.js new file mode 100644 index 0000000000..0cd4468b2f --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/new/input.js @@ -0,0 +1,2 @@ +// @flow +new C(); diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/new/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/new/output.json new file mode 100644 index 0000000000..0f4d43e251 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/new/output.json @@ -0,0 +1,168 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "expression": { + "type": "NewExpression", + "start": 9, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "callee": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "C" + }, + "name": "C" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "T" + }, + "name": "T" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/rollback-computed/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-computed/input.js new file mode 100644 index 0000000000..819142d5d1 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-computed/input.js @@ -0,0 +1,2 @@ +// @flow +f[e]; diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/rollback-computed/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-computed/output.json new file mode 100644 index 0000000000..8e91571e57 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-computed/output.json @@ -0,0 +1,185 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "left": { + "type": "BinaryExpression", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "left": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "operator": "<", + "right": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "T" + }, + "name": "T" + } + }, + "operator": ">", + "right": { + "type": "ArrayExpression", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "e" + }, + "name": "e" + } + ] + } + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/rollback-dot/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-dot/input.js new file mode 100644 index 0000000000..62f0ccf0c1 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-dot/input.js @@ -0,0 +1,2 @@ +// @flow +f.0; diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/rollback-dot/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-dot/output.json new file mode 100644 index 0000000000..0b828ea5d6 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-dot/output.json @@ -0,0 +1,171 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 9, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "left": { + "type": "BinaryExpression", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "left": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "operator": "<", + "right": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "T" + }, + "name": "T" + } + }, + "operator": ">", + "right": { + "type": "NumericLiteral", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "extra": { + "rawValue": 0, + "raw": ".0" + }, + "value": 0 + } + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/rollback-jsx/input.js b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-jsx/input.js new file mode 100644 index 0000000000..aa2c47cb84 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-jsx/input.js @@ -0,0 +1,2 @@ +// @flow +f; diff --git a/packages/babylon/test/fixtures/flow/typeapp-call/rollback-jsx/output.json b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-jsx/output.json new file mode 100644 index 0000000000..cafb1f03e5 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/typeapp-call/rollback-jsx/output.json @@ -0,0 +1,231 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 9, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "left": { + "type": "BinaryExpression", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "left": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "operator": "<", + "right": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "T" + }, + "name": "T" + } + }, + "operator": ">", + "right": { + "type": "JSXElement", + "start": 13, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "attributes": [], + "name": { + "type": "JSXIdentifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "name": "U" + }, + "selfClosing": false + }, + "closingElement": { + "type": "JSXClosingElement", + "start": 16, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "name": { + "type": "JSXIdentifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "name": "U" + } + }, + "children": [] + } + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/scripts/tests/flow/flow_tests_whitelist.txt b/scripts/tests/flow/flow_tests_whitelist.txt index 74d9819c0d..f6a827bd65 100644 --- a/scripts/tests/flow/flow_tests_whitelist.txt +++ b/scripts/tests/flow/flow_tests_whitelist.txt @@ -37,11 +37,4 @@ numbers/underscored_float_whole.js numbers/underscored_hex.js numbers/underscored_number.js numbers/underscored_oct.js -typeapp_call/function_call.js -typeapp_call/function_call_optional.js -typeapp_call/method_call.js -typeapp_call/method_call_computed.js -typeapp_call/method_call_optional2.js -typeapp_call/new.js -typeapp_call/new_noparens.js types/declare_class/proto.js diff --git a/scripts/tests/flow/run_babylon_flow_tests.js b/scripts/tests/flow/run_babylon_flow_tests.js index e7c4934300..880ea5a5b3 100644 --- a/scripts/tests/flow/run_babylon_flow_tests.js +++ b/scripts/tests/flow/run_babylon_flow_tests.js @@ -111,7 +111,7 @@ const options = { plugins: [ "asyncGenerators", "dynamicImport", - "flow", + ["flow", { all: true }], "flowComments", "jsx", "objectRestSpread",