Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.
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

Description

@josephfrazier

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions