diff --git a/eslint/babel-eslint-parser/index.js b/eslint/babel-eslint-parser/index.js index 820afe48e4..f0e7dea838 100644 --- a/eslint/babel-eslint-parser/index.js +++ b/eslint/babel-eslint-parser/index.js @@ -414,13 +414,13 @@ exports.parseNoPatch = function (code) { ast.tokens.pop(); // convert tokens - ast.tokens = acornToEsprima.toTokens(ast.tokens, tt); + ast.tokens = acornToEsprima.toTokens(ast.tokens, tt, code); // add comments acornToEsprima.convertComments(ast.comments); // transform esprima and acorn divergent nodes - acornToEsprima.toAST(ast, traverse); + acornToEsprima.toAST(ast, traverse, code); // ast.program.tokens = ast.tokens; // ast.program.comments = ast.comments; diff --git a/eslint/babel-eslint-parser/test/babel-eslint.js b/eslint/babel-eslint-parser/test/babel-eslint.js index b4498042fe..c709f7da63 100644 --- a/eslint/babel-eslint-parser/test/babel-eslint.js +++ b/eslint/babel-eslint-parser/test/babel-eslint.js @@ -330,76 +330,84 @@ describe("acorn-to-esprima", function () { ].join("\n")); }); - it("MethodDefinition", function () { - parseAndAssertSame([ - "export default class A {", - "a() {}", - "}" - ].join("\n")); - }); + describe("babel 6 tests", function () { + it("MethodDefinition", function () { + parseAndAssertSame([ + "export default class A {", + "a() {}", + "}" + ].join("\n")); + }); - it("MethodDefinition 2", function () { - parseAndAssertSame([ - "export default class Bar { get bar() { return 42; }}" - ].join("\n")); - }); + it("MethodDefinition 2", function () { + parseAndAssertSame([ + "export default class Bar { get bar() { return 42; }}" + ].join("\n")); + }); - it("ClassMethod", function () { - parseAndAssertSame([ - "class A {", - "constructor() {", - "}", - "}" - ].join("\n")); - }); + it("ClassMethod", function () { + parseAndAssertSame([ + "class A {", + "constructor() {", + "}", + "}" + ].join("\n")); + }); - it("ClassMethod multiple params", function () { - parseAndAssertSame([ - "class A {", - "constructor(a, b, c) {", - "}", - "}" - ].join("\n")); - }); + it("ClassMethod multiple params", function () { + parseAndAssertSame([ + "class A {", + "constructor(a, b, c) {", + "}", + "}" + ].join("\n")); + }); - it("ClassMethod multiline", function () { - parseAndAssertSame([ - "class A {", - " constructor(", - " a,", - " b,", - " c", - " ) {", - "", - " }", - "}" - ].join("\n")); - }); + it("ClassMethod multiline", function () { + parseAndAssertSame([ + "class A {", + " constructor(", + " a,", + " b,", + " c", + " ) {", + "", + " }", + "}" + ].join("\n")); + }); - it("ClassMethod oneline", function () { - parseAndAssertSame("class A { constructor(a, b, c) {} }"); - }); + it("ClassMethod oneline", function () { + parseAndAssertSame("class A { constructor(a, b, c) {} }"); + }); - it("ObjectMethod", function () { - parseAndAssertSame([ - "var a = {", - "b(c) {", - "}", - "}" - ].join("\n")); - }); + it("ObjectMethod", function () { + parseAndAssertSame([ + "var a = {", + "b(c) {", + "}", + "}" + ].join("\n")); + }); - it("do not allow import export everywhere", function() { - assert.throws(function () { - parseAndAssertSame("function F() { import a from \"a\"; }"); - }, /Illegal import declaration/) - }); + it("do not allow import export everywhere", function() { + assert.throws(function () { + parseAndAssertSame("function F() { import a from \"a\"; }"); + }, /Illegal import declaration/) + }); - it("return outside function", function () { - parseAndAssertSame("return;"); - }); + it("return outside function", function () { + parseAndAssertSame("return;"); + }); - it("super outside method", function () { - parseAndAssertSame("function F() { super(); }"); + it("super outside method", function () { + parseAndAssertSame("function F() { super(); }"); + }); + + it("StringLiteral", function () { + parseAndAssertSame(''); + parseAndAssertSame(""); + parseAndAssertSame("a"); + }); }); }); diff --git a/eslint/babel-eslint-parser/test/non-regression.js b/eslint/babel-eslint-parser/test/non-regression.js index cdbc5555a5..0e7559df3b 100644 --- a/eslint/babel-eslint-parser/test/non-regression.js +++ b/eslint/babel-eslint-parser/test/non-regression.js @@ -1296,4 +1296,12 @@ describe("verify", function () { [ "1:13 \"x\" was used before it was defined no-use-before-define" ] ) }); + + it("jsx and stringliteral #216", function () { + verifyAndAssertMessages( + "
", + {}, + [] + ) + }); });