add espree comment attachment tests and remove ranges test property from babylon tests

This commit is contained in:
Sebastian McKenzie 2015-07-25 06:07:51 +01:00
parent 350e901794
commit 55f3fb3015
233 changed files with 3512 additions and 586 deletions

View File

@ -36,11 +36,11 @@ pp.addComment = function (comment) {
};
pp.processComment = function (node) {
if (node.type === "Program" && node.body.length > 0) return;
var stack = this.bottomRightStack;
var lastChild;
var trailingComments;
var i;
var lastChild, trailingComments, i;
if (this.trailingComments.length > 0) {
// If the first comment in trailingComments comes after the
@ -73,9 +73,21 @@ pp.processComment = function (node) {
}
if (lastChild) {
if (lastChild !== node && lastChild.leadingComments && last(lastChild.leadingComments).end <= node.start) {
node.leadingComments = lastChild.leadingComments;
lastChild.leadingComments = null;
if (lastChild.leadingComments) {
if (last(lastChild.leadingComments).range[1] <= node.range[0]) {
node.leadingComments = lastChild.leadingComments;
delete lastChild.leadingComments;
} else {
// A leading comment for an anonymous class had been stolen by its first MethodDefinition,
// so this takes back the leading comment.
// See Also: https://github.com/eslint/espree/issues/158
for (i = lastChild.leadingComments.length - 2; i >= 0; --i) {
if (lastChild.leadingComments[i].range[1] <= node.range[0]) {
node.leadingComments = lastChild.leadingComments.splice(0, i + 1);
break;
}
}
}
}
} else if (this.leadingComments.length > 0) {
if (last(this.leadingComments).end <= node.start) {

View File

@ -0,0 +1,4 @@
{
a();
//comment
}

View File

@ -0,0 +1,135 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "a",
"range": [
6,
7
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 5
}
}
},
"arguments": [],
"range": [
6,
9
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 7
}
}
},
"range": [
6,
10
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 8
}
},
"trailingComments": [
{
"type": "CommentLine",
"value": "comment",
"range": [
15,
24
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 13
}
}
}
]
}
],
"range": [
0,
26
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
26
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
}
},
"comments": [
{
"type": "CommentLine",
"value": "comment",
"range": [
15,
24
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 13
}
}
}
]
}

View File

@ -0,0 +1,2 @@
/* foo */
if (/* bar */ a) {}

View File

@ -0,0 +1,155 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "IfStatement",
"test": {
"type": "Identifier",
"name": "a",
"range": [
25,
26
],
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 16
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " bar ",
"range": [
14,
23
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 13
}
}
}
]
},
"consequent": {
"type": "BlockStatement",
"body": [],
"range": [
28,
30
],
"loc": {
"start": {
"line": 2,
"column": 18
},
"end": {
"line": 2,
"column": 20
}
}
},
"alternate": null,
"range": [
10,
30
],
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 20
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " foo ",
"range": [
0,
9
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
}
}
]
}
],
"sourceType": "script",
"range": [
0,
30
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 20
}
}
},
"comments": [
{
"type": "CommentBlock",
"value": " foo ",
"range": [
0,
9
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
}
},
{
"type": "CommentBlock",
"value": " bar ",
"range": [
14,
23
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 13
}
}
}
]
}

View File

@ -0,0 +1,10 @@
/**
* this is anonymous class.
*/
export default class {
/**
* this is method1.
*/
method1(){
}
}

View File

@ -0,0 +1,233 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "ExportDefaultDeclaration",
"declaration": {
"type": "ClassExpression",
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"body": [
{
"type": "MethodDefinition",
"key": {
"type": "Identifier",
"name": "method1",
"range": [
103,
110
],
"loc": {
"start": {
"line": 8,
"column": 4
},
"end": {
"line": 8,
"column": 11
}
}
},
"value": {
"type": "FunctionExpression",
"id": null,
"params": [],
"body": {
"type": "BlockStatement",
"body": [],
"range": [
112,
119
],
"loc": {
"start": {
"line": 8,
"column": 13
},
"end": {
"line": 9,
"column": 5
}
}
},
"generator": false,
"expression": false,
"range": [
110,
119
],
"loc": {
"start": {
"line": 8,
"column": 11
},
"end": {
"line": 9,
"column": 5
}
}
},
"kind": "method",
"computed": false,
"range": [
103,
119
],
"loc": {
"start": {
"line": 8,
"column": 4
},
"end": {
"line": 9,
"column": 5
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\n * this is method1.\n ",
"range": [
63,
98
],
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 7,
"column": 7
}
}
}
],
"static": false
}
],
"range": [
57,
121
],
"loc": {
"start": {
"line": 4,
"column": 21
},
"end": {
"line": 10,
"column": 1
}
}
},
"range": [
51,
121
],
"loc": {
"start": {
"line": 4,
"column": 15
},
"end": {
"line": 10,
"column": 1
}
}
},
"range": [
36,
121
],
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 10,
"column": 1
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\n * this is anonymous class.\n ",
"range": [
0,
35
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 3
}
}
}
]
}
],
"sourceType": "module",
"range": [
0,
121
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 10,
"column": 1
}
}
},
"comments": [
{
"type": "CommentBlock",
"value": "*\n * this is anonymous class.\n ",
"range": [
0,
35
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 3
}
}
},
{
"type": "CommentBlock",
"value": "*\n * this is method1.\n ",
"range": [
63,
98
],
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 7,
"column": 7
}
}
}
]
}

View File

@ -0,0 +1,3 @@
{
"sourceType": "module"
}

View File

@ -0,0 +1,5 @@
function a() {
/* before */
foo();
/* after */
}

View File

@ -0,0 +1,211 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "a",
"range": [
9,
10
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
}
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "foo",
"range": [
36,
39
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 7
}
}
},
"arguments": [],
"range": [
36,
41
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 9
}
}
},
"range": [
36,
42
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 10
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " before ",
"range": [
19,
31
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 16
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": " after ",
"range": [
47,
58
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 15
}
}
}
]
}
],
"range": [
13,
60
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 5,
"column": 1
}
}
},
"generator": false,
"expression": false,
"range": [
0,
60
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
60
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
},
"comments": [
{
"type": "CommentBlock",
"value": " before ",
"range": [
19,
31
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 16
}
}
},
{
"type": "CommentBlock",
"value": " after ",
"range": [
47,
58
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 15
}
}
}
]
}

View File

@ -0,0 +1,5 @@
function a() {
/* before */
debugger;
/* after */
}

View File

@ -0,0 +1,175 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "a",
"range": [
9,
10
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
}
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "DebuggerStatement",
"range": [
36,
45
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 13
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " before ",
"range": [
19,
31
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 16
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": " after ",
"range": [
50,
61
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 15
}
}
}
]
}
],
"range": [
13,
63
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 5,
"column": 1
}
}
},
"generator": false,
"expression": false,
"range": [
0,
63
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
63
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
},
"comments": [
{
"type": "CommentBlock",
"value": " before ",
"range": [
19,
31
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 16
}
}
},
{
"type": "CommentBlock",
"value": " after ",
"range": [
50,
61
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 15
}
}
}
]
}

View File

@ -0,0 +1,5 @@
function a() {
/* before */
return;
/* after */
}

View File

@ -0,0 +1,176 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "a",
"range": [
9,
10
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
}
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": null,
"range": [
36,
43
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 11
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " before ",
"range": [
19,
31
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 16
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": " after ",
"range": [
48,
59
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 15
}
}
}
]
}
],
"range": [
13,
61
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 5,
"column": 1
}
}
},
"generator": false,
"expression": false,
"range": [
0,
61
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
61
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
},
"comments": [
{
"type": "CommentBlock",
"value": " before ",
"range": [
19,
31
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 16
}
}
},
{
"type": "CommentBlock",
"value": " after ",
"range": [
48,
59
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 15
}
}
}
]
}

View File

@ -0,0 +1,5 @@
function a() {
/* before */
throw 55;
/* after */
}

View File

@ -0,0 +1,194 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "a",
"range": [
9,
10
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
}
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ThrowStatement",
"argument": {
"type": "Literal",
"value": 55,
"raw": "55",
"range": [
42,
44
],
"loc": {
"start": {
"line": 3,
"column": 10
},
"end": {
"line": 3,
"column": 12
}
}
},
"range": [
36,
45
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 13
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " before ",
"range": [
19,
31
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 16
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": " after ",
"range": [
50,
61
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 15
}
}
}
]
}
],
"range": [
13,
63
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 5,
"column": 1
}
}
},
"generator": false,
"expression": false,
"range": [
0,
63
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
63
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
},
"comments": [
{
"type": "CommentBlock",
"value": " before ",
"range": [
19,
31
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 16
}
}
},
{
"type": "CommentBlock",
"value": " after ",
"range": [
50,
61
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 15
}
}
}
]
}

View File

@ -0,0 +1 @@
function f() { /* infinite */ while (true) { } /* bar */ var each; }

View File

@ -0,0 +1,288 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "f",
"range": [
9,
10
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
}
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "WhileStatement",
"test": {
"type": "Literal",
"value": true,
"raw": "true",
"range": [
37,
41
],
"loc": {
"start": {
"line": 1,
"column": 37
},
"end": {
"line": 1,
"column": 41
}
}
},
"body": {
"type": "BlockStatement",
"body": [],
"range": [
43,
46
],
"loc": {
"start": {
"line": 1,
"column": 43
},
"end": {
"line": 1,
"column": 46
}
}
},
"range": [
30,
46
],
"loc": {
"start": {
"line": 1,
"column": 30
},
"end": {
"line": 1,
"column": 46
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " infinite ",
"range": [
15,
29
],
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 29
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": " bar ",
"range": [
47,
56
],
"loc": {
"start": {
"line": 1,
"column": 47
},
"end": {
"line": 1,
"column": 56
}
}
}
]
},
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "each",
"range": [
61,
65
],
"loc": {
"start": {
"line": 1,
"column": 61
},
"end": {
"line": 1,
"column": 65
}
}
},
"init": null,
"range": [
61,
65
],
"loc": {
"start": {
"line": 1,
"column": 61
},
"end": {
"line": 1,
"column": 65
}
}
}
],
"kind": "var",
"range": [
57,
66
],
"loc": {
"start": {
"line": 1,
"column": 57
},
"end": {
"line": 1,
"column": 66
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " bar ",
"range": [
47,
56
],
"loc": {
"start": {
"line": 1,
"column": 47
},
"end": {
"line": 1,
"column": 56
}
}
}
]
}
],
"range": [
13,
68
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 68
}
}
},
"generator": false,
"expression": false,
"range": [
0,
68
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 68
}
}
}
],
"sourceType": "script",
"range": [
0,
68
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 68
}
}
},
"comments": [
{
"type": "CommentBlock",
"value": " infinite ",
"range": [
15,
29
],
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 29
}
}
},
{
"type": "CommentBlock",
"value": " bar ",
"range": [
47,
56
],
"loc": {
"start": {
"line": 1,
"column": 47
},
"end": {
"line": 1,
"column": 56
}
}
}
]
}

View File

@ -0,0 +1,9 @@
function bar(foo) {
switch(foo) {
// foo
case 1:
// falls through
case 2:
doIt();
}
}

View File

@ -0,0 +1,362 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "bar",
"range": [
9,
12
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
}
}
},
"params": [
{
"type": "Identifier",
"name": "foo",
"range": [
13,
16
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 16
}
}
}
],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "SwitchStatement",
"discriminant": {
"type": "Identifier",
"name": "foo",
"range": [
31,
34
],
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 14
}
}
},
"cases": [
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 1,
"raw": "1",
"range": [
66,
67
],
"loc": {
"start": {
"line": 4,
"column": 13
},
"end": {
"line": 4,
"column": 14
}
}
},
"consequent": [],
"range": [
61,
68
],
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 4,
"column": 15
}
},
"leadingComments": [
{
"type": "CommentLine",
"value": " foo",
"range": [
46,
52
],
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 3,
"column": 14
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": " falls through",
"range": [
81,
97
],
"loc": {
"start": {
"line": 5,
"column": 12
},
"end": {
"line": 5,
"column": 28
}
}
}
]
},
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 2,
"raw": "2",
"range": [
111,
112
],
"loc": {
"start": {
"line": 6,
"column": 13
},
"end": {
"line": 6,
"column": 14
}
}
},
"consequent": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "doIt",
"range": [
126,
130
],
"loc": {
"start": {
"line": 7,
"column": 12
},
"end": {
"line": 7,
"column": 16
}
}
},
"arguments": [],
"range": [
126,
132
],
"loc": {
"start": {
"line": 7,
"column": 12
},
"end": {
"line": 7,
"column": 18
}
}
},
"range": [
126,
133
],
"loc": {
"start": {
"line": 7,
"column": 12
},
"end": {
"line": 7,
"column": 19
}
}
}
],
"range": [
106,
133
],
"loc": {
"start": {
"line": 6,
"column": 8
},
"end": {
"line": 7,
"column": 19
}
},
"leadingComments": [
{
"type": "CommentLine",
"value": " falls through",
"range": [
81,
97
],
"loc": {
"start": {
"line": 5,
"column": 12
},
"end": {
"line": 5,
"column": 28
}
}
}
]
}
],
"range": [
24,
139
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 8,
"column": 5
}
}
}
],
"range": [
18,
141
],
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 9,
"column": 1
}
}
},
"generator": false,
"expression": false,
"range": [
0,
141
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
141
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 1
}
}
},
"comments": [
{
"type": "CommentLine",
"value": " foo",
"range": [
46,
52
],
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 3,
"column": 14
}
}
},
{
"type": "CommentLine",
"value": " falls through",
"range": [
81,
97
],
"loc": {
"start": {
"line": 5,
"column": 12
},
"end": {
"line": 5,
"column": 28
}
}
}
]
}

View File

@ -0,0 +1,7 @@
switch(foo) {
// foo
case 1:
// falls through
case 2:
doIt();
}

View File

@ -0,0 +1,286 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "SwitchStatement",
"discriminant": {
"type": "Identifier",
"name": "foo",
"range": [
7,
10
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 10
}
}
},
"cases": [
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 1,
"raw": "1",
"range": [
34,
35
],
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 10
}
}
},
"consequent": [],
"range": [
29,
36
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 11
}
},
"leadingComments": [
{
"type": "CommentLine",
"value": " foo",
"range": [
18,
24
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 10
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": " falls through",
"range": [
45,
61
],
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 4,
"column": 24
}
}
}
]
},
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 2,
"raw": "2",
"range": [
71,
72
],
"loc": {
"start": {
"line": 5,
"column": 9
},
"end": {
"line": 5,
"column": 10
}
}
},
"consequent": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "doIt",
"range": [
82,
86
],
"loc": {
"start": {
"line": 6,
"column": 8
},
"end": {
"line": 6,
"column": 12
}
}
},
"arguments": [],
"range": [
82,
88
],
"loc": {
"start": {
"line": 6,
"column": 8
},
"end": {
"line": 6,
"column": 14
}
}
},
"range": [
82,
89
],
"loc": {
"start": {
"line": 6,
"column": 8
},
"end": {
"line": 6,
"column": 15
}
}
}
],
"range": [
66,
89
],
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 6,
"column": 15
}
},
"leadingComments": [
{
"type": "CommentLine",
"value": " falls through",
"range": [
45,
61
],
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 4,
"column": 24
}
}
}
]
}
],
"range": [
0,
91
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
91
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 1
}
}
},
"comments": [
{
"type": "CommentLine",
"value": " foo",
"range": [
18,
24
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 10
}
}
},
{
"type": "CommentLine",
"value": " falls through",
"range": [
45,
61
],
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 4,
"column": 24
}
}
}
]
}

View File

@ -0,0 +1,9 @@
function bar(a) {
switch (a) {
case 2:
break;
case 1:
break;
//no default
}
}

View File

@ -0,0 +1,288 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "bar",
"range": [
9,
12
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
}
}
},
"params": [
{
"type": "Identifier",
"name": "a",
"range": [
13,
14
],
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
}
}
],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "SwitchStatement",
"discriminant": {
"type": "Identifier",
"name": "a",
"range": [
30,
31
],
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 13
}
}
},
"cases": [
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 2,
"raw": "2",
"range": [
48,
49
],
"loc": {
"start": {
"line": 3,
"column": 13
},
"end": {
"line": 3,
"column": 14
}
}
},
"consequent": [
{
"type": "BreakStatement",
"label": null,
"range": [
63,
69
],
"loc": {
"start": {
"line": 4,
"column": 12
},
"end": {
"line": 4,
"column": 18
}
}
}
],
"range": [
43,
69
],
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 4,
"column": 18
}
}
},
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 1,
"raw": "1",
"range": [
83,
84
],
"loc": {
"start": {
"line": 5,
"column": 13
},
"end": {
"line": 5,
"column": 14
}
}
},
"consequent": [
{
"type": "BreakStatement",
"label": null,
"range": [
98,
104
],
"loc": {
"start": {
"line": 6,
"column": 12
},
"end": {
"line": 6,
"column": 18
}
}
}
],
"range": [
78,
104
],
"loc": {
"start": {
"line": 5,
"column": 8
},
"end": {
"line": 6,
"column": 18
}
},
"trailingComments": [
{
"type": "CommentLine",
"value": "no default",
"range": [
113,
125
],
"loc": {
"start": {
"line": 7,
"column": 8
},
"end": {
"line": 7,
"column": 20
}
}
}
]
}
],
"range": [
22,
131
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 8,
"column": 5
}
}
}
],
"range": [
16,
133
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 9,
"column": 1
}
}
},
"generator": false,
"expression": false,
"range": [
0,
133
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
133
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 1
}
}
},
"comments": [
{
"type": "CommentLine",
"value": "no default",
"range": [
113,
125
],
"loc": {
"start": {
"line": 7,
"column": 8
},
"end": {
"line": 7,
"column": 20
}
}
}
]
}

View File

@ -0,0 +1,12 @@
module.exports = function(context) {
function isConstant(node) {
switch (node.type) {
case "SequenceExpression":
return isConstant(node.expressions[node.expressions.length - 1]);
// no default
}
return false;
}
};

View File

@ -0,0 +1,707 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "Identifier",
"name": "module",
"range": [
0,
6
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
}
},
"property": {
"type": "Identifier",
"name": "exports",
"range": [
7,
14
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 14
}
}
},
"range": [
0,
14
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
}
},
"right": {
"type": "FunctionExpression",
"id": null,
"params": [
{
"type": "Identifier",
"name": "context",
"range": [
26,
33
],
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 33
}
}
}
],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "isConstant",
"range": [
51,
61
],
"loc": {
"start": {
"line": 3,
"column": 13
},
"end": {
"line": 3,
"column": 23
}
}
},
"params": [
{
"type": "Identifier",
"name": "node",
"range": [
62,
66
],
"loc": {
"start": {
"line": 3,
"column": 24
},
"end": {
"line": 3,
"column": 28
}
}
}
],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "SwitchStatement",
"discriminant": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "Identifier",
"name": "node",
"range": [
86,
90
],
"loc": {
"start": {
"line": 4,
"column": 16
},
"end": {
"line": 4,
"column": 20
}
}
},
"property": {
"type": "Identifier",
"name": "type",
"range": [
91,
95
],
"loc": {
"start": {
"line": 4,
"column": 21
},
"end": {
"line": 4,
"column": 25
}
}
},
"range": [
86,
95
],
"loc": {
"start": {
"line": 4,
"column": 16
},
"end": {
"line": 4,
"column": 25
}
}
},
"cases": [
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": "SequenceExpression",
"raw": "\"SequenceExpression\"",
"range": [
116,
136
],
"loc": {
"start": {
"line": 5,
"column": 17
},
"end": {
"line": 5,
"column": 37
}
}
},
"consequent": [
{
"type": "ReturnStatement",
"argument": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "isConstant",
"range": [
161,
171
],
"loc": {
"start": {
"line": 6,
"column": 23
},
"end": {
"line": 6,
"column": 33
}
}
},
"arguments": [
{
"type": "MemberExpression",
"computed": true,
"object": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "Identifier",
"name": "node",
"range": [
172,
176
],
"loc": {
"start": {
"line": 6,
"column": 34
},
"end": {
"line": 6,
"column": 38
}
}
},
"property": {
"type": "Identifier",
"name": "expressions",
"range": [
177,
188
],
"loc": {
"start": {
"line": 6,
"column": 39
},
"end": {
"line": 6,
"column": 50
}
}
},
"range": [
172,
188
],
"loc": {
"start": {
"line": 6,
"column": 34
},
"end": {
"line": 6,
"column": 50
}
}
},
"property": {
"type": "BinaryExpression",
"operator": "-",
"left": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "Identifier",
"name": "node",
"range": [
189,
193
],
"loc": {
"start": {
"line": 6,
"column": 51
},
"end": {
"line": 6,
"column": 55
}
}
},
"property": {
"type": "Identifier",
"name": "expressions",
"range": [
194,
205
],
"loc": {
"start": {
"line": 6,
"column": 56
},
"end": {
"line": 6,
"column": 67
}
}
},
"range": [
189,
205
],
"loc": {
"start": {
"line": 6,
"column": 51
},
"end": {
"line": 6,
"column": 67
}
}
},
"property": {
"type": "Identifier",
"name": "length",
"range": [
206,
212
],
"loc": {
"start": {
"line": 6,
"column": 68
},
"end": {
"line": 6,
"column": 74
}
}
},
"range": [
189,
212
],
"loc": {
"start": {
"line": 6,
"column": 51
},
"end": {
"line": 6,
"column": 74
}
}
},
"right": {
"type": "Literal",
"value": 1,
"raw": "1",
"range": [
215,
216
],
"loc": {
"start": {
"line": 6,
"column": 77
},
"end": {
"line": 6,
"column": 78
}
}
},
"range": [
189,
216
],
"loc": {
"start": {
"line": 6,
"column": 51
},
"end": {
"line": 6,
"column": 78
}
}
},
"range": [
172,
217
],
"loc": {
"start": {
"line": 6,
"column": 34
},
"end": {
"line": 6,
"column": 79
}
}
}
],
"range": [
161,
218
],
"loc": {
"start": {
"line": 6,
"column": 23
},
"end": {
"line": 6,
"column": 80
}
}
},
"range": [
154,
219
],
"loc": {
"start": {
"line": 6,
"column": 16
},
"end": {
"line": 6,
"column": 81
}
}
}
],
"range": [
111,
219
],
"loc": {
"start": {
"line": 5,
"column": 12
},
"end": {
"line": 6,
"column": 81
}
},
"trailingComments": [
{
"type": "CommentLine",
"value": " no default",
"range": [
232,
245
],
"loc": {
"start": {
"line": 7,
"column": 12
},
"end": {
"line": 7,
"column": 25
}
}
}
]
}
],
"range": [
78,
255
],
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 8,
"column": 9
}
}
},
{
"type": "ReturnStatement",
"argument": {
"type": "Literal",
"value": false,
"raw": "false",
"range": [
271,
276
],
"loc": {
"start": {
"line": 9,
"column": 15
},
"end": {
"line": 9,
"column": 20
}
}
},
"range": [
264,
277
],
"loc": {
"start": {
"line": 9,
"column": 8
},
"end": {
"line": 9,
"column": 21
}
},
"leadingComments": [
{
"type": "CommentLine",
"value": " no default",
"range": [
232,
245
],
"loc": {
"start": {
"line": 7,
"column": 12
},
"end": {
"line": 7,
"column": 25
}
}
}
]
}
],
"range": [
68,
283
],
"loc": {
"start": {
"line": 3,
"column": 30
},
"end": {
"line": 10,
"column": 5
}
}
},
"generator": false,
"expression": false,
"range": [
42,
283
],
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 10,
"column": 5
}
}
}
],
"range": [
35,
286
],
"loc": {
"start": {
"line": 1,
"column": 35
},
"end": {
"line": 12,
"column": 1
}
}
},
"generator": false,
"expression": false,
"range": [
17,
286
],
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 12,
"column": 1
}
}
},
"range": [
0,
286
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 12,
"column": 1
}
}
},
"range": [
0,
287
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 12,
"column": 2
}
}
}
],
"sourceType": "script",
"range": [
0,
287
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 12,
"column": 2
}
}
},
"comments": [
{
"type": "CommentLine",
"value": " no default",
"range": [
232,
245
],
"loc": {
"start": {
"line": 7,
"column": 12
},
"end": {
"line": 7,
"column": 25
}
}
}
]
}

View File

@ -0,0 +1,5 @@
switch (a) {
case 1:
break;
//no default
}

View File

@ -0,0 +1,156 @@
{
"type": "File",
"program": {
"type": "Program",
"body": [
{
"type": "SwitchStatement",
"discriminant": {
"type": "Identifier",
"name": "a",
"range": [
8,
9
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
}
}
},
"cases": [
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 1,
"raw": "1",
"range": [
22,
23
],
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 10
}
}
},
"consequent": [
{
"type": "BreakStatement",
"label": null,
"range": [
33,
39
],
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 3,
"column": 14
}
}
}
],
"range": [
17,
39
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 3,
"column": 14
}
},
"trailingComments": [
{
"type": "CommentLine",
"value": "no default",
"range": [
44,
56
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 16
}
}
}
]
}
],
"range": [
0,
58
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
}
],
"sourceType": "script",
"range": [
0,
58
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
}
},
"comments": [
{
"type": "CommentLine",
"value": "no default",
"range": [
44,
56
],
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 16
}
}
}
]
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,6 +1,5 @@
{
"features": {
"es7.asyncFunctions": true
},
"ranges": true
}
}

View File

@ -1,6 +1,5 @@
{
"features": {
"es7.asyncFunctions": true
},
"ranges": true
}
}

View File

@ -1,6 +1,5 @@
{
"features": {
"es7.asyncFunctions": true
},
"ranges": true
}
}

View File

@ -1,6 +1,5 @@
{
"sourceType": "module",
"plugins": { "jsx": true, "flow": true },
"features": { "es7.asyncFunctions": true },
"ranges": true
"features": { "es7.asyncFunctions": true }
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,4 +1,3 @@
{
"sourceType": "module",
"ranges": true
"sourceType": "module"
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

View File

@ -1,3 +0,0 @@
{
"ranges": true
}

Some files were not shown because too many files have changed in this diff Show More