Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: report missing plugins on type exports #11417

Merged
merged 3 commits into from Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -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;
}

Expand Down
@@ -0,0 +1 @@
export interface Foo {}
@@ -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)"
}
@@ -0,0 +1,2 @@
var Foo;
export type { Foo };
@@ -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)"
}
@@ -0,0 +1 @@
export type Foo = number;
@@ -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)"
}
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["jsx"]
}
@@ -0,0 +1 @@
export interface Foo {}
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
}
@@ -0,0 +1,2 @@
var Foo;
export type { Foo };
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (2:7)"
}
@@ -0,0 +1 @@
export type Foo = number;
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
}
@@ -0,0 +1,3 @@
{
"sourceType": "module"
}