Always use unpad (babel/babel-eslint#535)
This commit is contained in:
parent
f43062ebbb
commit
090269e5a0
@ -61,6 +61,7 @@ function lookup(obj, keypath, backwardsDepth) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseAndAssertSame(code) {
|
function parseAndAssertSame(code) {
|
||||||
|
code = unpad(code);
|
||||||
var esAST = espree.parse(code, {
|
var esAST = espree.parse(code, {
|
||||||
ecmaFeatures: {
|
ecmaFeatures: {
|
||||||
// enable JSX parsing
|
// enable JSX parsing
|
||||||
@ -177,8 +178,7 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("template also with braces #96", () => {
|
it("template also with braces #96", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
export default function f1() {
|
export default function f1() {
|
||||||
function f2(foo) {
|
function f2(foo) {
|
||||||
const bar = 3;
|
const bar = 3;
|
||||||
@ -186,21 +186,18 @@ describe("babylon-to-esprima", () => {
|
|||||||
}
|
}
|
||||||
return f2;
|
return f2;
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("template with destructuring #31", () => {
|
it("template with destructuring #31", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
render() {
|
render() {
|
||||||
var {name} = this.props;
|
var {name} = this.props;
|
||||||
return Math.max(null, \`Name: \${name}, Name: \${name}\`);
|
return Math.max(null, \`Name: \${name}, Name: \${name}\`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -301,31 +298,26 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("line comments", () => {
|
it("line comments", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
// single comment
|
// single comment
|
||||||
var foo = 15; // comment next to statement
|
var foo = 15; // comment next to statement
|
||||||
// second comment after statement
|
// second comment after statement
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("block comments", () => {
|
it("block comments", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
/* single comment */
|
/* single comment */
|
||||||
var foo = 15; /* comment next to statement */
|
var foo = 15; /* comment next to statement */
|
||||||
/*
|
/*
|
||||||
* multiline
|
* multiline
|
||||||
* comment
|
* comment
|
||||||
*/
|
*/
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("block comments #124", () => {
|
it("block comments #124", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
React.createClass({
|
React.createClass({
|
||||||
render() {
|
render() {
|
||||||
// return (
|
// return (
|
||||||
@ -333,8 +325,7 @@ describe("babylon-to-esprima", () => {
|
|||||||
// ); // <-- this is the line that is reported
|
// ); // <-- this is the line that is reported
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("null", () => {
|
it("null", () => {
|
||||||
@ -374,8 +365,7 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("jsdoc", () => {
|
it("jsdoc", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
/**
|
/**
|
||||||
* @param {object} options
|
* @param {object} options
|
||||||
* @return {number}
|
* @return {number}
|
||||||
@ -384,13 +374,11 @@ describe("babylon-to-esprima", () => {
|
|||||||
return a + b + c;
|
return a + b + c;
|
||||||
};
|
};
|
||||||
module.exports = test;
|
module.exports = test;
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("empty block with comment", () => {
|
it("empty block with comment", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
function a () {
|
function a () {
|
||||||
try {
|
try {
|
||||||
b();
|
b();
|
||||||
@ -398,19 +386,16 @@ describe("babylon-to-esprima", () => {
|
|||||||
// asdf
|
// asdf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("babel tests", () => {
|
describe("babel tests", () => {
|
||||||
it("MethodDefinition", () => {
|
it("MethodDefinition", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
export default class A {
|
export default class A {
|
||||||
a() {}
|
a() {}
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("MethodDefinition 2", () => {
|
it("MethodDefinition 2", () => {
|
||||||
@ -420,30 +405,25 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod", () => {
|
it("ClassMethod", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
class A {
|
class A {
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod multiple params", () => {
|
it("ClassMethod multiple params", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
class A {
|
class A {
|
||||||
constructor(a, b, c) {
|
constructor(a, b, c) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod multiline", () => {
|
it("ClassMethod multiline", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
class A {
|
class A {
|
||||||
constructor (
|
constructor (
|
||||||
a,
|
a,
|
||||||
@ -455,8 +435,7 @@ describe("babylon-to-esprima", () => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod oneline", () => {
|
it("ClassMethod oneline", () => {
|
||||||
@ -464,14 +443,12 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("ObjectMethod", () => {
|
it("ObjectMethod", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
var a = {
|
var a = {
|
||||||
b(c) {
|
b(c) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("do not allow import export everywhere", () => {
|
it("do not allow import export everywhere", () => {
|
||||||
@ -496,8 +473,7 @@ describe("babylon-to-esprima", () => {
|
|||||||
|
|
||||||
it("getters and setters", () => {
|
it("getters and setters", () => {
|
||||||
parseAndAssertSame("class A { get x ( ) { ; } }");
|
parseAndAssertSame("class A { get x ( ) { ; } }");
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
class A {
|
class A {
|
||||||
get x(
|
get x(
|
||||||
)
|
)
|
||||||
@ -505,11 +481,9 @@ describe("babylon-to-esprima", () => {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
parseAndAssertSame("class A { set x (a) { ; } }");
|
parseAndAssertSame("class A { set x (a) { ; } }");
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
class A {
|
class A {
|
||||||
set x(a
|
set x(a
|
||||||
)
|
)
|
||||||
@ -517,10 +491,8 @@ describe("babylon-to-esprima", () => {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
parseAndAssertSame(`
|
||||||
parseAndAssertSame(
|
|
||||||
unpad(`
|
|
||||||
var B = {
|
var B = {
|
||||||
get x () {
|
get x () {
|
||||||
return this.ecks;
|
return this.ecks;
|
||||||
@ -529,8 +501,7 @@ describe("babylon-to-esprima", () => {
|
|||||||
this.ecks = ecks;
|
this.ecks = ecks;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("RestOperator", () => {
|
it("RestOperator", () => {
|
||||||
@ -546,13 +517,11 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Async/Await", () => {
|
it("Async/Await", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
|
||||||
async function a() {
|
async function a() {
|
||||||
await 1;
|
await 1;
|
||||||
}
|
}
|
||||||
`)
|
`);
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user