add all espree ecmaFeatures, fixes babel/babel-eslint#31 again
This commit is contained in:
parent
573020678a
commit
9cc077638a
@ -80,8 +80,10 @@ function isCompatTag(tagName) {
|
|||||||
function convertTemplateType(tokens) {
|
function convertTemplateType(tokens) {
|
||||||
var startingToken = 0;
|
var startingToken = 0;
|
||||||
var currentToken = 0;
|
var currentToken = 0;
|
||||||
|
// track use of {}
|
||||||
var numBraces = 0;
|
var numBraces = 0;
|
||||||
var hasTemplateEnded = true;
|
// track number of nested templates
|
||||||
|
var numBackQuotes = 0;
|
||||||
|
|
||||||
function isBackQuote(token) {
|
function isBackQuote(token) {
|
||||||
return tokens[token].type === tt.backQuote;
|
return tokens[token].type === tt.backQuote;
|
||||||
@ -89,7 +91,8 @@ function convertTemplateType(tokens) {
|
|||||||
|
|
||||||
function isTemplateStarter(token) {
|
function isTemplateStarter(token) {
|
||||||
return isBackQuote(token) ||
|
return isBackQuote(token) ||
|
||||||
tokens[token].type === tt.braceR;
|
// only can be a template starter when in a template already
|
||||||
|
tokens[token].type === tt.braceR && numBackQuotes > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isTemplateEnder(token) {
|
function isTemplateEnder(token) {
|
||||||
@ -138,6 +141,10 @@ function convertTemplateType(tokens) {
|
|||||||
while (startingToken < tokens.length) {
|
while (startingToken < tokens.length) {
|
||||||
// template start: check if ` or }
|
// template start: check if ` or }
|
||||||
if (isTemplateStarter(startingToken) && numBraces === 0) {
|
if (isTemplateStarter(startingToken) && numBraces === 0) {
|
||||||
|
if (isBackQuote(startingToken)) {
|
||||||
|
numBackQuotes++;
|
||||||
|
}
|
||||||
|
|
||||||
currentToken = startingToken + 1;
|
currentToken = startingToken + 1;
|
||||||
|
|
||||||
// check if token after template start is "template"
|
// check if token after template start is "template"
|
||||||
@ -153,10 +160,12 @@ function convertTemplateType(tokens) {
|
|||||||
currentToken++;
|
currentToken++;
|
||||||
}
|
}
|
||||||
|
|
||||||
hasTemplateEnded = isBackQuote(currentToken);
|
if (isBackQuote(currentToken)) {
|
||||||
|
numBackQuotes--;
|
||||||
|
}
|
||||||
// template start and end found: create new token
|
// template start and end found: create new token
|
||||||
replaceWithTemplateType(startingToken, currentToken);
|
replaceWithTemplateType(startingToken, currentToken);
|
||||||
} else if (!hasTemplateEnded) {
|
} else if (numBackQuotes > 0) {
|
||||||
trackNumBraces(startingToken);
|
trackNumBraces(startingToken);
|
||||||
}
|
}
|
||||||
startingToken++;
|
startingToken++;
|
||||||
|
|||||||
@ -33,16 +33,29 @@ function assertImplementsAST(target, source, path) {
|
|||||||
|
|
||||||
function parseAndAssertSame(code) {
|
function parseAndAssertSame(code) {
|
||||||
var esAST = espree.parse(code, {
|
var esAST = espree.parse(code, {
|
||||||
env: {
|
|
||||||
"es6": true,
|
|
||||||
"node": true
|
|
||||||
},
|
|
||||||
ecmaFeatures: {
|
ecmaFeatures: {
|
||||||
|
arrowFunctions: true,
|
||||||
blockBindings: true,
|
blockBindings: true,
|
||||||
|
destructuring: true,
|
||||||
|
regexYFlag: true,
|
||||||
|
regexUFlag: true,
|
||||||
templateStrings: true,
|
templateStrings: true,
|
||||||
modules: true,
|
binaryLiterals: true,
|
||||||
|
octalLiterals: true,
|
||||||
|
unicodeCodePointEscapes: true,
|
||||||
|
defaultParams: true,
|
||||||
|
restParams: true,
|
||||||
|
forOf: true,
|
||||||
|
objectLiteralComputedProperties: true,
|
||||||
|
objectLiteralShorthandMethods: true,
|
||||||
|
objectLiteralShorthandProperties: true,
|
||||||
|
objectLiteralDuplicateProperties: true,
|
||||||
|
generators: true,
|
||||||
|
spread: true,
|
||||||
classes: true,
|
classes: true,
|
||||||
jsx: true
|
modules: true,
|
||||||
|
jsx: true,
|
||||||
|
globalReturn: true
|
||||||
},
|
},
|
||||||
tokens: true,
|
tokens: true,
|
||||||
loc: true,
|
loc: true,
|
||||||
@ -124,6 +137,17 @@ describe("acorn-to-esprima", function () {
|
|||||||
"}"
|
"}"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("template with destructuring #31", function () {
|
||||||
|
parseAndAssertSame([
|
||||||
|
"module.exports = {",
|
||||||
|
"render() {",
|
||||||
|
"var {name} = this.props;",
|
||||||
|
"return Math.max(null, `Name: ${name}, Name: ${name}`);",
|
||||||
|
"}",
|
||||||
|
"};"
|
||||||
|
].join("\n"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("simple expression", function () {
|
it("simple expression", function () {
|
||||||
|
|||||||
@ -164,6 +164,19 @@ describe("verify", function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("template with destructuring #31", function () {
|
||||||
|
verifyAndAssertMessages([
|
||||||
|
"module.exports = {",
|
||||||
|
"render() {",
|
||||||
|
"var {name} = this.props;",
|
||||||
|
"return Math.max(null, `Name: ${name}, Name: ${name}`);",
|
||||||
|
"}",
|
||||||
|
"};"].join("\n"),
|
||||||
|
{ "comma-spacing": 1 },
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
describe("decorators #72", function () {
|
describe("decorators #72", function () {
|
||||||
it("class declaration", function () {
|
it("class declaration", function () {
|
||||||
verifyAndAssertMessages(
|
verifyAndAssertMessages(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user