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

Allow any reserved word in export {} from specifiers #9616

Merged
merged 1 commit into from
Feb 28, 2019
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
21 changes: 10 additions & 11 deletions packages/babel-parser/src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -1866,9 +1866,17 @@ export default class StatementParser extends ExpressionParser {
// Named exports
for (const specifier of node.specifiers) {
this.checkDuplicateExports(specifier, specifier.exported.name);
// check if export is defined
// $FlowIgnore
if (!isFrom && specifier.local) {
// check for keywords used as local names
this.checkReservedWord(
specifier.local.name,
specifier.local.start,
true,
false,
);
// check if export is defined
// $FlowIgnore
this.scope.checkLocalExport(specifier.local);
}
}
Expand Down Expand Up @@ -1954,7 +1962,6 @@ export default class StatementParser extends ExpressionParser {
parseExportSpecifiers(): Array<N.ExportSpecifier> {
const nodes = [];
let first = true;
let needsFrom;

// export { x, y as z } [from '...']
this.expect(tt.braceL);
Expand All @@ -1967,22 +1974,14 @@ export default class StatementParser extends ExpressionParser {
if (this.eat(tt.braceR)) break;
}

const isDefault = this.match(tt._default);
if (isDefault && !needsFrom) needsFrom = true;

const node = this.startNode();
node.local = this.parseIdentifier(isDefault);
node.local = this.parseIdentifier(true);
node.exported = this.eatContextual("as")
? this.parseIdentifier(true)
: node.local.__clone();
nodes.push(this.finishNode(node, "ExportSpecifier"));
}

// https://github.com/ember-cli/ember-cli/pull/3739
if (needsFrom && !this.isContextual("from")) {
this.unexpected();
}

return nodes;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { if } from 'foo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"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",
"interpreter": null,
"body": [
{
"type": "ExportNamedDeclaration",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"specifiers": [
{
"type": "ExportSpecifier",
"start": 9,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 11
}
},
"local": {
"type": "Identifier",
"start": 9,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "if"
},
"name": "if"
},
"exported": {
"type": "Identifier",
"start": 9,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "if"
},
"name": "if"
}
}
],
"source": {
"type": "StringLiteral",
"start": 19,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 24
}
},
"extra": {
"rawValue": "foo",
"raw": "'foo'"
},
"value": "foo"
},
"declaration": null
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"throws": "Unexpected token (1:17)"
}
"sourceType": "module",
"throws": "Unexpected token, expected \";\" (1:17)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"throws": "Unexpected token (1:16)"
}
"sourceType": "module",
"throws": "Unexpected keyword 'default' (1:8)"
}