From 981bff08e4acebac32369af54c5d8fa3f2793ad4 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Tue, 22 May 2018 12:48:49 -0500 Subject: [PATCH] Fix some flow issues in @babel/parser flow plugin (#8002) --- packages/babel-parser/src/plugins/flow.js | 6 ++++-- packages/babel-parser/src/types.js | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js index 0052321c79..f09babfa7d 100644 --- a/packages/babel-parser/src/plugins/flow.js +++ b/packages/babel-parser/src/plugins/flow.js @@ -3,6 +3,7 @@ import type Parser from "../parser"; import { types as tt, type TokenType } from "../tokenizer/types"; import * as N from "../types"; +import type { Options } from "../options"; import type { Pos, Position } from "../util/location"; import type State from "../tokenizer/state"; import * as charCodes from "charcodes"; @@ -82,7 +83,7 @@ export default (superClass: Class): Class => return this.getPluginOption("flow", "all") || this.flowPragma === "flow"; } - addComment(comment: Comment): void { + addComment(comment: N.Comment): void { if (this.flowPragma === undefined) { // Try to parse a flow pragma. const matches = FLOW_PRAGMA_REGEX.exec(comment.value); @@ -2455,6 +2456,7 @@ export default (superClass: Class): Class => node.callee = base; node.typeArguments = this.flowParseTypeParameterInstantiation(); this.expect(tt.parenL); + // $FlowFixMe node.arguments = this.parseCallExpressionArguments(tt.parenR, false); node.optional = true; return this.finishNode(node, "OptionalCallExpression"); @@ -2463,7 +2465,7 @@ export default (superClass: Class): Class => this.shouldParseTypes() && this.isRelational("<") ) { - const node: N.CallExpression = this.startNodeAt(startPos, startLoc); + const node = this.startNodeAt(startPos, startLoc); node.callee = base; const state = this.state.clone(); try { diff --git a/packages/babel-parser/src/types.js b/packages/babel-parser/src/types.js index 37f217940b..0a7d2d0f52 100644 --- a/packages/babel-parser/src/types.js +++ b/packages/babel-parser/src/types.js @@ -547,6 +547,7 @@ export type ConditionalExpression = NodeBase & { export type CallOrNewBase = NodeBase & { callee: Expression | Super | Import, arguments: Array, // TODO: $ReadOnlyArray + typeArguments: ?TypeParameterInstantiationBase, typeParameters?: ?TypeParameterInstantiationBase, // TODO: Not in spec }; @@ -936,6 +937,12 @@ export type FlowTypeAnnotation = Node; export type FlowVariance = Node; export type FlowClassImplements = Node; +export type FlowInterfaceType = NodeBase & { + type: "FlowInterfaceType", + extends: FlowInterfaceExtends, + body: FlowObjectTypeAnnotation, +}; + // estree export type EstreeProperty = NodeBase & {