Skip to content
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

Closed
josephfrazier opened this issue May 10, 2017 · 4 comments
Closed

"use strict"/etc directives should be labeled as such #267

josephfrazier opened this issue May 10, 2017 · 4 comments

Comments

@josephfrazier
Copy link

What version of TypeScript are you using?

2.3.2

What version of typescript-eslint-parser are you using?

a294afa

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:

"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:


Discovered in prettier/prettier#1560 (comment)

@soda0289
Copy link
Member

This is not yet part of the ESTree spec. There has been a lot of discussion about it here:
estree/estree#6
and a PR:
estree/estree#152

We could implement the proposal and change it if its modified. But it might be better to wait for it to become official.

@josephfrazier
Copy link
Author

Thanks for the quick response and references! That makes sense, why it's not implemented yet. Cheers!

@JamesHenry
Copy link
Member

We will implement this if it gets accepted into ESTree

@azz
Copy link
Contributor

azz commented Sep 6, 2017

Good news! estree/estree#152

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants