Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Comment node loc.filename #80

Merged
merged 1 commit into from
Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/parser/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function last(stack) {
const pp = Parser.prototype;

pp.addComment = function (comment) {
if (this.filename) comment.loc.filename = this.filename;
this.state.trailingComments.push(comment);
this.state.leadingComments.push(comment);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// This comment should have a filename prop attached to loc
var node = "shouldHaveFilenameLocProp";
88 changes: 64 additions & 24 deletions test/fixtures/core/categorized/filename-specified/expected.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
{
"type": "File",
"start": 0,
"end": 39,
"end": 99,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"line": 2,
"column": 39
},
"filename": "path/to/input-file.js"
},
"program": {
"type": "Program",
"start": 0,
"end": 39,
"end": 99,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"line": 2,
"column": 39
},
"filename": "path/to/input-file.js"
Expand All @@ -32,63 +32,64 @@
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 39,
"start": 60,
"end": 99,
"loc": {
"start": {
"line": 1,
"line": 2,
"column": 0
},
"end": {
"line": 1,
"line": 2,
"column": 39
},
"filename": "path/to/input-file.js"
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 38,
"start": 64,
"end": 98,
"loc": {
"start": {
"line": 1,
"line": 2,
"column": 4
},
"end": {
"line": 1,
"line": 2,
"column": 38
},
"filename": "path/to/input-file.js"
},
"id": {
"type": "Identifier",
"start": 4,
"end": 8,
"start": 64,
"end": 68,
"loc": {
"start": {
"line": 1,
"line": 2,
"column": 4
},
"end": {
"line": 1,
"line": 2,
"column": 8
},
"filename": "path/to/input-file.js"
},
"name": "node"
"name": "node",
"leadingComments": null
},
"init": {
"type": "StringLiteral",
"start": 11,
"end": 38,
"start": 71,
"end": 98,
"loc": {
"start": {
"line": 1,
"line": 2,
"column": 11
},
"end": {
"line": 1,
"line": 2,
"column": 38
},
"filename": "path/to/input-file.js"
Expand All @@ -98,12 +99,51 @@
"raw": "\"shouldHaveFilenameLocProp\""
},
"value": "shouldHaveFilenameLocProp"
}
},
"leadingComments": null
}
],
"kind": "var"
"kind": "var",
"leadingComments": [
{
"type": "CommentLine",
"value": " This comment should have a filename prop attached to loc",
"start": 0,
"end": 59,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 59
},
"filename": "path/to/input-file.js"
}
}
]
}
],
"directives": []
}
},
"comments": [
{
"type": "CommentLine",
"value": " This comment should have a filename prop attached to loc",
"start": 0,
"end": 59,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 59
},
"filename": "path/to/input-file.js"
}
}
]
}