Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Parse error on import typeof in declare module #775

Closed
lydell opened this issue Jun 24, 2019 · 2 comments
Closed

Parse error on import typeof in declare module #775

lydell opened this issue Jun 24, 2019 · 2 comments

Comments

@lydell
Copy link

lydell commented Jun 24, 2019

Repro repo: https://github.com/lydell/babel-eslint-flow-import-issue

package.json:

{
  "private": true,
  "scripts": {
    "test": "eslint test.js"
  },
  "dependencies": {
    "babel-eslint": "10.0.2",
    "eslint": "6.0.0"
  }
}

.eslintrc.json:

{
  "parser": "babel-eslint"
}

test.js:

// @flow

declare module "cross-spawn" {
  import typeof childProcess from "child_process";

  declare module.exports: {
    sync: $PropertyType<childProcess, "spawnSync">,
  };
}

Result:

$ npm test

> @ test /home/lydell/stuff/babel-eslint
> eslint test.js


/home/lydell/stuff/babel-eslint/test.js
  4:3  error  Parsing error: Imports within a `declare module` body must always be `import type` or `import typeof`

  2 | 
  3 | declare module "cross-spawn" {
> 4 |   import typeof childProcess from "child_process";
    |   ^
  5 | 
  6 |   declare module.exports: {
  7 |     sync: $PropertyType<childProcess, "spawnSync">,

✖ 1 problem (1 error, 0 warnings)

npm ERR! Test failed.  See above for more details.

Expected: No errors.

Flow itself accepts this input.

@lydell
Copy link
Author

lydell commented Jun 25, 2019

Just realized this is a bug in @babel/parser, so I filed a bug there: babel/babel#10124

But I think the bug is most likely to be found by babel-eslint users.

@lydell
Copy link
Author

lydell commented Jun 26, 2019

Fixed by babel/babel#10132.

@lydell lydell closed this as completed Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant