Allow any reserved word in export {} from specifiers (#9616)
This commit is contained in:
parent
f13f4adcbb
commit
17f4195bcc
@ -1866,9 +1866,17 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
// Named exports
|
// Named exports
|
||||||
for (const specifier of node.specifiers) {
|
for (const specifier of node.specifiers) {
|
||||||
this.checkDuplicateExports(specifier, specifier.exported.name);
|
this.checkDuplicateExports(specifier, specifier.exported.name);
|
||||||
// check if export is defined
|
|
||||||
// $FlowIgnore
|
// $FlowIgnore
|
||||||
if (!isFrom && specifier.local) {
|
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);
|
this.scope.checkLocalExport(specifier.local);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1954,7 +1962,6 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
parseExportSpecifiers(): Array<N.ExportSpecifier> {
|
parseExportSpecifiers(): Array<N.ExportSpecifier> {
|
||||||
const nodes = [];
|
const nodes = [];
|
||||||
let first = true;
|
let first = true;
|
||||||
let needsFrom;
|
|
||||||
|
|
||||||
// export { x, y as z } [from '...']
|
// export { x, y as z } [from '...']
|
||||||
this.expect(tt.braceL);
|
this.expect(tt.braceL);
|
||||||
@ -1967,22 +1974,14 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
if (this.eat(tt.braceR)) break;
|
if (this.eat(tt.braceR)) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDefault = this.match(tt._default);
|
|
||||||
if (isDefault && !needsFrom) needsFrom = true;
|
|
||||||
|
|
||||||
const node = this.startNode();
|
const node = this.startNode();
|
||||||
node.local = this.parseIdentifier(isDefault);
|
node.local = this.parseIdentifier(true);
|
||||||
node.exported = this.eatContextual("as")
|
node.exported = this.eatContextual("as")
|
||||||
? this.parseIdentifier(true)
|
? this.parseIdentifier(true)
|
||||||
: node.local.__clone();
|
: node.local.__clone();
|
||||||
nodes.push(this.finishNode(node, "ExportSpecifier"));
|
nodes.push(this.finishNode(node, "ExportSpecifier"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/ember-cli/ember-cli/pull/3739
|
|
||||||
if (needsFrom && !this.isContextual("from")) {
|
|
||||||
this.unexpected();
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { if } from 'foo'
|
||||||
122
packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/output.json
vendored
Normal file
122
packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/output.json
vendored
Normal file
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"throws": "Unexpected token (1:17)"
|
"sourceType": "module",
|
||||||
}
|
"throws": "Unexpected token, expected \";\" (1:17)"
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"throws": "Unexpected token (1:16)"
|
"sourceType": "module",
|
||||||
}
|
"throws": "Unexpected keyword 'default' (1:8)"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user