-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request babel/babel-eslint#455 from babel/babylon-to-espre…
…e-tidy Tidy up babylon-to-espree
- Loading branch information
Showing
8 changed files
with
103 additions
and
107 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
eslint/babel-eslint-parser/babylon-to-espree/attachComments.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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
"use strict"; | ||
|
||
// comment fixes | ||
module.exports = function (ast, comments, tokens) { | ||
if (comments.length) { | ||
|
17 changes: 17 additions & 0 deletions
17
eslint/babel-eslint-parser/babylon-to-espree/convertComments.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,17 @@ | ||
"use strict"; | ||
|
||
module.exports = function (comments) { | ||
for (var i = 0; i < comments.length; i++) { | ||
var comment = comments[i]; | ||
if (comment.type === "CommentBlock") { | ||
comment.type = "Block"; | ||
} else if (comment.type === "CommentLine") { | ||
comment.type = "Line"; | ||
} | ||
// sometimes comments don't get ranges computed, | ||
// even with options.ranges === true | ||
if (!comment.range) { | ||
comment.range = [comment.start, comment.end]; | ||
} | ||
} | ||
}; |
2 changes: 2 additions & 0 deletions
2
eslint/babel-eslint-parser/babylon-to-espree/convertTemplateType.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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
"use strict"; | ||
|
||
module.exports = function (tokens, tt) { | ||
var startingToken = 0; | ||
var currentToken = 0; | ||
|
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 |
---|---|---|
@@ -1,20 +1,36 @@ | ||
exports.attachComments = require("./attachComments"); | ||
|
||
exports.toTokens = require("./toTokens"); | ||
exports.toAST = require("./toAST"); | ||
|
||
exports.convertComments = function (comments) { | ||
for (var i = 0; i < comments.length; i++) { | ||
var comment = comments[i]; | ||
if (comment.type === "CommentBlock") { | ||
comment.type = "Block"; | ||
} else if (comment.type === "CommentLine") { | ||
comment.type = "Line"; | ||
} | ||
// sometimes comments don't get ranges computed, | ||
// even with options.ranges === true | ||
if (!comment.range) { | ||
comment.range = [comment.start, comment.end]; | ||
} | ||
} | ||
"use strict"; | ||
|
||
var attachComments = require("./attachComments"); | ||
var convertComments = require("./convertComments"); | ||
var toTokens = require("./toTokens"); | ||
var toAST = require("./toAST"); | ||
|
||
module.exports = function (ast, traverse, tt, code) { | ||
// remove EOF token, eslint doesn't use this for anything and it interferes | ||
// with some rules see https://github.com/babel/babel-eslint/issues/2 | ||
// todo: find a more elegant way to do this | ||
ast.tokens.pop(); | ||
|
||
// convert tokens | ||
ast.tokens = toTokens(ast.tokens, tt, code); | ||
|
||
// add comments | ||
convertComments(ast.comments); | ||
|
||
// transform esprima and acorn divergent nodes | ||
toAST(ast, traverse, code); | ||
|
||
// ast.program.tokens = ast.tokens; | ||
// ast.program.comments = ast.comments; | ||
// ast = ast.program; | ||
|
||
// remove File | ||
ast.type = "Program"; | ||
ast.sourceType = ast.program.sourceType; | ||
ast.directives = ast.program.directives; | ||
ast.body = ast.program.body; | ||
delete ast.program; | ||
delete ast._paths; | ||
|
||
attachComments(ast, ast.comments, ast.tokens); | ||
}; |
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
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
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
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