This repository was archived by the owner on Jan 19, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 74
This repository was archived by the owner on Jan 19, 2019. It is now read-only.
"use strict"/etc directives should be labeled as such #267
Copy link
Copy link
Closed
Labels
Description
What version of TypeScript are you using?
2.3.2
What version of typescript-eslint-parser
are you using?
What code were you trying to parse?
"use strict";
"other directive";
What did you expect to happen?
I expected an AST indicating that these literals are part of a Directive Prologue.
What happened?
The AST doesn't differentiate between directive literals and non-directive literals. For example:
typescript-eslint-parser/tests/fixtures/ast/Tolerant-parse.json
Lines 4104 to 4167 in f5fcc87
"function hello() { \"octal directive\\1\"; \"use strict\"; }": { | |
"type": "Program", | |
"body": [ | |
{ | |
"type": "FunctionDeclaration", | |
"id": { | |
"type": "Identifier", | |
"name": "hello", | |
"range": [ | |
9, | |
14 | |
], | |
"loc": { | |
"start": { | |
"line": 1, | |
"column": 9 | |
}, | |
"end": { | |
"line": 1, | |
"column": 14 | |
} | |
} | |
}, | |
"params": [], | |
"body": { | |
"type": "BlockStatement", | |
"body": [ | |
{ | |
"type": "ExpressionStatement", | |
"expression": { | |
"type": "Literal", | |
"value": "octal directive\u0001", | |
"raw": "\"octal directive\\1\"", | |
"range": [ | |
19, | |
38 | |
], | |
"loc": { | |
"start": { | |
"line": 1, | |
"column": 19 | |
}, | |
"end": { | |
"line": 1, | |
"column": 38 | |
} | |
} | |
}, | |
"range": [ | |
19, | |
39 | |
], | |
"loc": { | |
"start": { | |
"line": 1, | |
"column": 19 | |
}, | |
"end": { | |
"line": 1, | |
"column": 39 | |
} | |
} | |
}, |
For comparison, here are some other ASTs for "octal directive"
, both of which indicate that the literal is a directive:
- Babylon: http://astexplorer.net/#/gist/29393e8fc8313aa11944f9146ceca787/0c135e856c8212bfe68702ae122261ecd4d08330
- Flow: http://astexplorer.net/#/gist/29393e8fc8313aa11944f9146ceca787/a59985860d2ee2faef66046f1d22180364a2e53b
Discovered in prettier/prettier#1560 (comment)