zhanS
zhanS

Reputation: 33

babel parser cannot parse `import type` declaration

When I try to use parser.parse("import type {Element} from 'react-devtools-shared/src/frontend/types';", {sourceType: "unambiguous"}); to parse the statement, I encounter an error Unexpected token, expected "from".

Is there any problem?

Someone can help me? Thanks a lot.

I try to set errorRecovery:true and strictMode:false, but these are not helpful.

Upvotes: 0

Views: 190

Answers (1)

morganney
morganney

Reputation: 13610

You need either the flow or typescript plugin.

parser.parse("import type {Element} from 'react-devtools-shared/src/frontend/types';", {
  sourceType: "unambiguous",
  plugins: ['typescript']
})

See it on AST Explorer for reference.

Configuration used in AST Explorer

Upvotes: 1

Related Questions