check valid function/class token when parsing export default before converting to a declaration - fixes #2145
This commit is contained in:
parent
a0f9d5fbc8
commit
94e345e0b2
@ -648,9 +648,10 @@ pp.parseExport = function (node) {
|
||||
}
|
||||
this.parseExportFrom(node, true);
|
||||
} else if (this.eat(tt._default)) { // export default ...
|
||||
let possibleDeclaration = this.match(tt._function) || this.match(tt._class);
|
||||
let expr = this.parseMaybeAssign();
|
||||
let needsSemi = true;
|
||||
if (expr.type === "FunctionExpression" || expr.type === "ClassExpression") {
|
||||
if (possibleDeclaration) {
|
||||
needsSemi = false;
|
||||
if (expr.id) {
|
||||
expr.type = expr.type === "FunctionExpression" ? "FunctionDeclaration" : "ClassDeclaration";
|
||||
|
||||
1
test/fixtures/harmony/modules/export-default-function-declaration/actual.js
vendored
Normal file
1
test/fixtures/harmony/modules/export-default-function-declaration/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
export default function a() {}
|
||||
98
test/fixtures/harmony/modules/export-default-function-declaration/expected.json
vendored
Normal file
98
test/fixtures/harmony/modules/export-default-function-declaration/expected.json
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 30
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 30
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportDefaultDeclaration",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 30
|
||||
}
|
||||
},
|
||||
"declaration": {
|
||||
"type": "FunctionDeclaration",
|
||||
"start": 15,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 30
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 24,
|
||||
"end": 25,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 24
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 25
|
||||
}
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"generator": false,
|
||||
"expression": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 28,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 28
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 30
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
3
test/fixtures/harmony/modules/export-default-function-declaration/options.json
vendored
Normal file
3
test/fixtures/harmony/modules/export-default-function-declaration/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sourceType": "module"
|
||||
}
|
||||
1
test/fixtures/harmony/modules/export-default-function-expression/actual.js
vendored
Normal file
1
test/fixtures/harmony/modules/export-default-function-expression/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
export default (function a() {});
|
||||
99
test/fixtures/harmony/modules/export-default-function-expression/expected.json
vendored
Normal file
99
test/fixtures/harmony/modules/export-default-function-expression/expected.json
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 33,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 33
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 33,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 33
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportDefaultDeclaration",
|
||||
"start": 0,
|
||||
"end": 33,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 33
|
||||
}
|
||||
},
|
||||
"declaration": {
|
||||
"type": "FunctionExpression",
|
||||
"start": 16,
|
||||
"end": 31,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 31
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 25,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 25
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 26
|
||||
}
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"generator": false,
|
||||
"expression": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 29,
|
||||
"end": 31,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 29
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 31
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
},
|
||||
"parenthesizedExpression": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
3
test/fixtures/harmony/modules/export-default-function-expression/options.json
vendored
Normal file
3
test/fixtures/harmony/modules/export-default-function-expression/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sourceType": "module"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user