Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update: Pass file path to parse function (fixes #5344) (#7024)
  • Loading branch information
annie authored and ilyavolodin committed Sep 2, 2016
1 parent 3f13325 commit 00b3042
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/eslint.js
Expand Up @@ -598,10 +598,11 @@ module.exports = (function() {
* as possible
* @param {string} text The text to parse.
* @param {Object} config The ESLint configuration object.
* @param {string} filePath The path to the file being parsed.
* @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 +611,8 @@ module.exports = (function() {
raw: true,
tokens: true,
comment: true,
attachComment: true
attachComment: true,
filePath
};

try {
Expand Down Expand Up @@ -783,7 +785,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": []
};
};
10 changes: 10 additions & 0 deletions tests/lib/eslint.js
Expand Up @@ -3821,6 +3821,16 @@ describe("eslint", function() {
const parserFixtures = path.join(__dirname, "../fixtures/parsers"),
errorPrefix = "Parsing error: ";

it("should have file path passed to it", function() {
const code = "/* this is code */";
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 });
});

it("should not report an error when JSX code contains a spread operator and JSX is enabled", function() {
const code = "var myDivElement = <div {...this.props} />;";
const messages = eslint.verify(code, { parser: "esprima-fb" }, "filename");
Expand Down

0 comments on commit 00b3042

Please sign in to comment.