Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Fix: Calculate range correctly when class is exported (fixes #152) #153

Merged
merged 1 commit into from
Feb 5, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/ast-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,9 @@ module.exports = function(ast, extra) {
* could be multiple before the open brace
*/
var lastModifier = node.modifiers[node.modifiers.length - 1];
lastClassToken = ts.findNextToken(lastModifier, ast);
if (!lastClassToken || lastModifier.pos > lastClassToken.pos) {
lastClassToken = ts.findNextToken(lastModifier, ast);
}

} else if (!lastClassToken) { // no name
lastClassToken = node.getFirstToken();
Expand Down
168 changes: 168 additions & 0 deletions tests/fixtures/ecma-features/modules/export-default-class.result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
module.exports = {
"type": "Program",
"range": [
0,
25
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ExportDefaultDeclaration",
"declaration": {
"type": "ClassDeclaration",
"range": [
15,
25
],
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 3,
"column": 1
}
},
"id": null,
"body": {
"type": "ClassBody",
"body": [],
"range": [
21,
25
],
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 3,
"column": 1
}
}
},
"superClass": null,
"implements": [],
"decorators": []
},
"range": [
0,
25
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
}
}
],
"sourceType": "module",
"tokens": [
{
"type": "Keyword",
"value": "export",
"range": [
0,
6
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
}
},
{
"type": "Keyword",
"value": "default",
"range": [
7,
14
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 14
}
}
},
{
"type": "Keyword",
"value": "class",
"range": [
15,
20
],
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 20
}
}
},
{
"type": "Punctuator",
"value": "{",
"range": [
21,
22
],
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 22
}
}
},
{
"type": "Punctuator",
"value": "}",
"range": [
24,
25
],
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
}
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default class {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
module.exports = {
"type": "Program",
"range": [
0,
30
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ExportDefaultDeclaration",
"declaration": {
"type": "ClassDeclaration",
"range": [
15,
30
],
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"range": [
21,
25
],
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 25
}
},
"name": "Test"
},
"body": {
"type": "ClassBody",
"body": [],
"range": [
26,
30
],
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 3,
"column": 1
}
}
},
"superClass": null,
"implements": [],
"decorators": []
},
"range": [
0,
30
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
}
}
],
"sourceType": "module",
"tokens": [
{
"type": "Keyword",
"value": "export",
"range": [
0,
6
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
}
},
{
"type": "Keyword",
"value": "default",
"range": [
7,
14
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 14
}
}
},
{
"type": "Keyword",
"value": "class",
"range": [
15,
20
],
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 20
}
}
},
{
"type": "Identifier",
"value": "Test",
"range": [
21,
25
],
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 25
}
}
},
{
"type": "Punctuator",
"value": "{",
"range": [
26,
27
],
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 27
}
}
},
{
"type": "Punctuator",
"value": "}",
"range": [
29,
30
],
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
}
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default class Test {

}
Loading