Skip to content

Commit

Permalink
Fix babel#437: only prohibit 'export type from "module" ' when flow i…
Browse files Browse the repository at this point in the history
…s enabled (babel#438) (babel#531)

* Only prohibit 'export type' when flow is enabled

* Fix lint
  • Loading branch information
danez committed May 19, 2017
1 parent b7c13a8 commit 990675d
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,7 @@ pp.parseExportDeclaration = function () {

pp.isExportDefaultSpecifier = function () {
if (this.match(tt.name)) {
return this.state.value !== "type"
&& this.state.value !== "async"
&& this.state.value !== "interface";
return this.state.value !== "async";
}

if (!this.match(tt._default)) {
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,19 @@ export default function (instance) {
};
});

instance.extend("isExportDefaultSpecifier", function (inner) {
return function () {
if (
this.match(tt.name) &&
(this.state.value === "type" || this.state.value === "interface")
) {
return false;
}

return inner.call(this);
};
});

instance.extend("parseConditional", function (inner) {
return function (expr, noIn, startPos, startLoc, refNeedsArrowPos) {
// only do the expensive clone if there is a question mark
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type from 'test';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": ["exportExtensions", "flow"],
"sourceType": "module",
"throws": "Unexpected token, expected = (1:17)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type from 'test';
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"type": "File",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"program": {
"type": "Program",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"sourceType": "module",
"body": [
{
"type": "ExportNamedDeclaration",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"specifiers": [
{
"type": "ExportDefaultSpecifier",
"start": 7,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 11
}
},
"exported": {
"type": "Identifier",
"start": 7,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "type"
},
"name": "type"
}
}
],
"source": {
"type": "StringLiteral",
"start": 17,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 23
}
},
"extra": {
"rawValue": "test",
"raw": "'test'"
},
"value": "test"
}
}
],
"directives": []
}
}

0 comments on commit 990675d

Please sign in to comment.