-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Space-infix-ops should ignore type annotations in TypeScript
Typescript allows type annotations in variable declarations. This commit ensures they are skipped over and not considered when checking Variable Declaration nodes.
- Loading branch information
Showing
5 changed files
with
1,196 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
298 changes: 298 additions & 0 deletions
298
tests/fixtures/parsers/typescript-parsers/function-declaration-type-annotation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,298 @@ | ||
/** | ||
* Parser: typescript-eslint-parser v2.0.0 (TS 2.2.1) | ||
* Source code: | ||
* function foo(): Bar { } | ||
*/ | ||
|
||
exports.parse = () => ({ | ||
"type": "Program", | ||
"range": [ | ||
0, | ||
23 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 23 | ||
} | ||
}, | ||
"body": [ | ||
{ | ||
"type": "FunctionDeclaration", | ||
"range": [ | ||
0, | ||
23 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 23 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"range": [ | ||
9, | ||
12 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 9 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 12 | ||
} | ||
}, | ||
"name": "foo" | ||
}, | ||
"generator": false, | ||
"expression": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"range": [ | ||
20, | ||
23 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 20 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 23 | ||
} | ||
}, | ||
"body": [] | ||
}, | ||
"returnType": { | ||
"type": "TypeAnnotation", | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 16 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 19 | ||
} | ||
}, | ||
"range": [ | ||
16, | ||
19 | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeReference", | ||
"range": [ | ||
16, | ||
19 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 16 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 19 | ||
} | ||
}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"range": [ | ||
16, | ||
19 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 16 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 19 | ||
} | ||
}, | ||
"name": "Bar" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"sourceType": "script", | ||
"tokens": [ | ||
{ | ||
"type": "Keyword", | ||
"value": "function", | ||
"start": 0, | ||
"end": 8, | ||
"range": [ | ||
0, | ||
8 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 8 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Identifier", | ||
"value": "foo", | ||
"start": 9, | ||
"end": 12, | ||
"range": [ | ||
9, | ||
12 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 9 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 12 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Punctuator", | ||
"value": "(", | ||
"start": 12, | ||
"end": 13, | ||
"range": [ | ||
12, | ||
13 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 12 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 13 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Punctuator", | ||
"value": ")", | ||
"start": 13, | ||
"end": 14, | ||
"range": [ | ||
13, | ||
14 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 13 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 14 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Punctuator", | ||
"value": ":", | ||
"start": 14, | ||
"end": 15, | ||
"range": [ | ||
14, | ||
15 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 14 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 15 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Identifier", | ||
"value": "Bar", | ||
"start": 16, | ||
"end": 19, | ||
"range": [ | ||
16, | ||
19 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 16 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 19 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Punctuator", | ||
"value": "{", | ||
"start": 20, | ||
"end": 21, | ||
"range": [ | ||
20, | ||
21 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 20 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 21 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Punctuator", | ||
"value": "}", | ||
"start": 22, | ||
"end": 23, | ||
"range": [ | ||
22, | ||
23 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 22 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 23 | ||
} | ||
} | ||
} | ||
], | ||
"comments": [] | ||
}); |
Oops, something went wrong.