Skip to content

Babel chokes on valid Flow syntax (typeof blah.default) #10571

@cakoose

Description

@cakoose

Bug Report

package.json

{
    "devDependencies": {
        "@babel/cli": "7.6.4",
        "@babel/core": "7.6.4",
        "@babel/preset-flow": "7.0.0",
        "flow-bin": "0.109.0"
    }
}

.flowconfig

[include]
src

.babelrc

{
    "presets": ["@babel/preset-flow"]
}

src/test.js

// @flow
type Stuff = {
  x: number,
  default: string,
};

function f(stuff: Stuff) {
  const x: typeof stuff.x = 1;
  const y: typeof stuff.default = "hi";
}

Flow runs fine:

$ ./node_modules/.bin/flow 
No errors!

Babel does not:

$ ./node_modules/.bin/babel src
{ SyntaxError: /Users/kannan/h/babel-flow-default-token/src/test.js: Unexpected keyword 'default' (9:24)

   7 | function f(stuff: Stuff) {
   8 |   const x: typeof stuff.x = 1;
>  9 |   const y: typeof stuff.default = "hi";
     |                         ^
  10 | }
  11 | 
    at Object.raise (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:6420:17)
    at Object.checkReservedWord (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:9722:12)
    at Object.parseIdentifierName (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:9697:12)
    at Object.parseIdentifier (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:9667:23)
    at Object.flowParseQualifiedTypeIdentifier (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:1595:23)
    at Object.flowParseGenericType (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:1605:20)
    at Object.flowIdentToTypeAnnotation (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:1713:21)
    at Object.flowParsePrimaryType (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:1732:21)
    at Object.flowParseTypeofType (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:1617:26)
    at Object.flowParsePrimaryType (/Users/kannan/h/babel-flow-default-token/node_modules/@babel/parser/lib/index.js:1862:23)
  pos: 142,
  loc: Position { line: 9, column: 24 },
  code: 'BABEL_PARSE_ERROR' }

My Node version:

$ node --version
v8.15.0

BTW, I know Flow is processing the file because I added a type error to "test.js" and Flow caught it.

Metadata

Metadata

Labels

Has PRarea: flowoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions