Skip to content

Commit

Permalink
Update: Pass file path to parse function (fixes eslint#5344)
Browse files Browse the repository at this point in the history
  • Loading branch information
annie committed Aug 31, 2016
1 parent 326f457 commit d3d4290
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/eslint.js
Expand Up @@ -601,7 +601,7 @@ module.exports = (function() {
* @returns {ASTNode} The AST if successful or null if not.
* @private
*/
function parse(text, config) {
function parse(text, config, filePath) {

let parser,
parserOptions = {
Expand All @@ -610,7 +610,8 @@ module.exports = (function() {
raw: true,
tokens: true,
comment: true,
attachComment: true
attachComment: true,
filePath: filePath
};

try {
Expand Down Expand Up @@ -783,7 +784,8 @@ module.exports = (function() {
shebang = captured;
return "//" + captured;
}),
config
config,
currentFilename
);

if (ast) {
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures/parsers/stub-parser.js
@@ -0,0 +1,11 @@
exports.parse = function(text, parserOptions) {
return {
"type": "Program",
"loc": {},
"range": [],
"body": [],
"comments": [],
"errors": [],
"tokens": []
};
};
14 changes: 14 additions & 0 deletions tests/lib/eslint.js
Expand Up @@ -101,6 +101,20 @@ describe("eslint", function() {
});
});

describe("parser", function() {

it("should have file path passed to it", function() {
const code = "/* this is code */";
const parserFixtures = path.join(__dirname, "../fixtures/parsers");
const parser = path.join(parserFixtures, "stub-parser.js");
const parseSpy = sinon.spy(require(parser), "parse");

eslint.verify(code, { parser }, filename, true);

sinon.assert.calledWithMatch(parseSpy, "", { filePath: filename });
});
});

describe("getSourceLines()", function() {

it("should get proper lines when using \\n as a line break", function() {
Expand Down

0 comments on commit d3d4290

Please sign in to comment.