fix: report missing plugins on type exports (#11417)
* fix: report missing plugins on type exports * nit refactors * Update packages/babel-parser/src/parser/statement.js [skip ci]
This commit is contained in:
parent
070ec201bb
commit
a466f9c310
@ -1834,10 +1834,28 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
isExportDefaultSpecifier(): boolean {
|
||||
if (this.match(tt.name)) {
|
||||
return this.state.value !== "async" && this.state.value !== "let";
|
||||
}
|
||||
|
||||
if (!this.match(tt._default)) {
|
||||
const value = this.state.value;
|
||||
if (value === "async" || value === "let") {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
(value === "type" || value === "interface") &&
|
||||
!this.state.containsEsc
|
||||
) {
|
||||
const l = this.lookahead();
|
||||
// If we see any variable name other than `from` after `type` keyword,
|
||||
// we consider it as flow/typescript type exports
|
||||
// note that this approach may fail on some pedantic cases
|
||||
// export type from = number
|
||||
if (
|
||||
(l.type === tt.name && l.value !== "from") ||
|
||||
l.type === tt.braceL
|
||||
) {
|
||||
this.expectOnePlugin(["flow", "typescript"]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (!this.match(tt._default)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
1
packages/babel-parser/test/fixtures/flow/expect-plugin/export-interface/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/flow/expect-plugin/export-interface/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
export interface Foo {}
|
||||
7
packages/babel-parser/test/fixtures/flow/expect-plugin/export-interface/options.json
vendored
Normal file
7
packages/babel-parser/test/fixtures/flow/expect-plugin/export-interface/options.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"jsx"
|
||||
],
|
||||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/flow/expect-plugin/export-type-named/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/flow/expect-plugin/export-type-named/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
var Foo;
|
||||
export type { Foo };
|
||||
7
packages/babel-parser/test/fixtures/flow/expect-plugin/export-type-named/options.json
vendored
Normal file
7
packages/babel-parser/test/fixtures/flow/expect-plugin/export-type-named/options.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"jsx"
|
||||
],
|
||||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (2:7)"
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/flow/expect-plugin/export-type/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/flow/expect-plugin/export-type/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
export type Foo = number;
|
||||
7
packages/babel-parser/test/fixtures/flow/expect-plugin/export-type/options.json
vendored
Normal file
7
packages/babel-parser/test/fixtures/flow/expect-plugin/export-type/options.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"jsx"
|
||||
],
|
||||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/expect-plugin/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/expect-plugin/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["jsx"]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-interface/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-interface/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
export interface Foo {}
|
||||
4
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-interface/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-interface/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type-named/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type-named/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
var Foo;
|
||||
export type { Foo };
|
||||
4
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type-named/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type-named/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (2:7)"
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
export type Foo = number;
|
||||
4
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/typescript/expect-plugin/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/expect-plugin/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sourceType": "module"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user