update acorn-to-esprima, add tests for babel/babel-eslint#216
This commit is contained in:
parent
f76be581b3
commit
4249dcd353
@ -414,13 +414,13 @@ exports.parseNoPatch = function (code) {
|
|||||||
ast.tokens.pop();
|
ast.tokens.pop();
|
||||||
|
|
||||||
// convert tokens
|
// convert tokens
|
||||||
ast.tokens = acornToEsprima.toTokens(ast.tokens, tt);
|
ast.tokens = acornToEsprima.toTokens(ast.tokens, tt, code);
|
||||||
|
|
||||||
// add comments
|
// add comments
|
||||||
acornToEsprima.convertComments(ast.comments);
|
acornToEsprima.convertComments(ast.comments);
|
||||||
|
|
||||||
// transform esprima and acorn divergent nodes
|
// transform esprima and acorn divergent nodes
|
||||||
acornToEsprima.toAST(ast, traverse);
|
acornToEsprima.toAST(ast, traverse, code);
|
||||||
|
|
||||||
// ast.program.tokens = ast.tokens;
|
// ast.program.tokens = ast.tokens;
|
||||||
// ast.program.comments = ast.comments;
|
// ast.program.comments = ast.comments;
|
||||||
|
|||||||
@ -330,76 +330,84 @@ describe("acorn-to-esprima", function () {
|
|||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("MethodDefinition", function () {
|
describe("babel 6 tests", function () {
|
||||||
parseAndAssertSame([
|
it("MethodDefinition", function () {
|
||||||
"export default class A {",
|
parseAndAssertSame([
|
||||||
"a() {}",
|
"export default class A {",
|
||||||
"}"
|
"a() {}",
|
||||||
].join("\n"));
|
"}"
|
||||||
});
|
].join("\n"));
|
||||||
|
});
|
||||||
|
|
||||||
it("MethodDefinition 2", function () {
|
it("MethodDefinition 2", function () {
|
||||||
parseAndAssertSame([
|
parseAndAssertSame([
|
||||||
"export default class Bar { get bar() { return 42; }}"
|
"export default class Bar { get bar() { return 42; }}"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod", function () {
|
it("ClassMethod", function () {
|
||||||
parseAndAssertSame([
|
parseAndAssertSame([
|
||||||
"class A {",
|
"class A {",
|
||||||
"constructor() {",
|
"constructor() {",
|
||||||
"}",
|
"}",
|
||||||
"}"
|
"}"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod multiple params", function () {
|
it("ClassMethod multiple params", function () {
|
||||||
parseAndAssertSame([
|
parseAndAssertSame([
|
||||||
"class A {",
|
"class A {",
|
||||||
"constructor(a, b, c) {",
|
"constructor(a, b, c) {",
|
||||||
"}",
|
"}",
|
||||||
"}"
|
"}"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod multiline", function () {
|
it("ClassMethod multiline", function () {
|
||||||
parseAndAssertSame([
|
parseAndAssertSame([
|
||||||
"class A {",
|
"class A {",
|
||||||
" constructor(",
|
" constructor(",
|
||||||
" a,",
|
" a,",
|
||||||
" b,",
|
" b,",
|
||||||
" c",
|
" c",
|
||||||
" ) {",
|
" ) {",
|
||||||
"",
|
"",
|
||||||
" }",
|
" }",
|
||||||
"}"
|
"}"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod oneline", function () {
|
it("ClassMethod oneline", function () {
|
||||||
parseAndAssertSame("class A { constructor(a, b, c) {} }");
|
parseAndAssertSame("class A { constructor(a, b, c) {} }");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ObjectMethod", function () {
|
it("ObjectMethod", function () {
|
||||||
parseAndAssertSame([
|
parseAndAssertSame([
|
||||||
"var a = {",
|
"var a = {",
|
||||||
"b(c) {",
|
"b(c) {",
|
||||||
"}",
|
"}",
|
||||||
"}"
|
"}"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("do not allow import export everywhere", function() {
|
it("do not allow import export everywhere", function() {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
parseAndAssertSame("function F() { import a from \"a\"; }");
|
parseAndAssertSame("function F() { import a from \"a\"; }");
|
||||||
}, /Illegal import declaration/)
|
}, /Illegal import declaration/)
|
||||||
});
|
});
|
||||||
|
|
||||||
it("return outside function", function () {
|
it("return outside function", function () {
|
||||||
parseAndAssertSame("return;");
|
parseAndAssertSame("return;");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("super outside method", function () {
|
it("super outside method", function () {
|
||||||
parseAndAssertSame("function F() { super(); }");
|
parseAndAssertSame("function F() { super(); }");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("StringLiteral", function () {
|
||||||
|
parseAndAssertSame('');
|
||||||
|
parseAndAssertSame("");
|
||||||
|
parseAndAssertSame("a");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1296,4 +1296,12 @@ describe("verify", function () {
|
|||||||
[ "1:13 \"x\" was used before it was defined no-use-before-define" ]
|
[ "1:13 \"x\" was used before it was defined no-use-before-define" ]
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("jsx and stringliteral #216", function () {
|
||||||
|
verifyAndAssertMessages(
|
||||||
|
"<div className=''></div>",
|
||||||
|
{},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user