diff --git a/eslint/babel-eslint-parser/acorn-to-esprima.js b/eslint/babel-eslint-parser/acorn-to-esprima.js index ca6516526d..5375a3b118 100644 --- a/eslint/babel-eslint-parser/acorn-to-esprima.js +++ b/eslint/babel-eslint-parser/acorn-to-esprima.js @@ -1,36 +1,36 @@ -var tokTypes = require("babel-core").acorn.tokTypes; var traverse = require("babel-core").traverse; +var tt = require("babel-core").acorn.tokTypes; var t = require("babel-core").types; exports.toToken = function (token) { var type = token.type; - if (type === tokTypes.name) { + if (type === tt.name) { token.type = "Identifier"; - } else if (type === tokTypes.semi || type === tokTypes.comma || - type === tokTypes.parenL || type === tokTypes.parenR || - type === tokTypes.braceL || type === tokTypes.braceR || - type === tokTypes.slash || type === tokTypes.dot || - type === tokTypes.bracketL || type === tokTypes.bracketR || - type === tokTypes.ellipsis || type === tokTypes.arrow || - type === tokTypes.star || + } else if (type === tt.semi || type === tt.comma || + type === tt.parenL || type === tt.parenR || + type === tt.braceL || type === tt.braceR || + type === tt.slash || type === tt.dot || + type === tt.bracketL || type === tt.bracketR || + type === tt.ellipsis || type === tt.arrow || + type === tt.star || type.isAssign) { token.type = "Punctuator"; - if (!token.value) token.value = type.type; - } else if (type === tokTypes.jsxTagStart) { + if (!token.value) token.value = type.label; + } else if (type === tt.jsxTagStart) { token.type = "Punctuator"; token.value = "<"; - } else if (type === tokTypes.jsxTagEnd) { + } else if (type === tt.jsxTagEnd) { token.type = "Punctuator"; token.value = ">"; - } else if (type === tokTypes.jsxName) { + } else if (type === tt.jsxName) { token.type = "JSXIdentifier"; } else if (type.keyword) { token.type = "Keyword"; - } else if (type === tokTypes.num) { + } else if (type === tt.num) { token.type = "Numeric"; token.value = String(token.value); - } else if (type === tokTypes.string) { + } else if (type === tt.string) { token.type = "String"; token.value = JSON.stringify(token.value); } @@ -62,14 +62,6 @@ var astTransformVisitor = { return node.argument; } - // playground - - if (t.isAssignmentExpression(node)) { - if (node.operator === "||=" || node.operator === "?=") { - node.operator = "+="; - } - } - // modules if (t.isImportDeclaration(node)) { @@ -77,49 +69,11 @@ var astTransformVisitor = { } if (t.isExportDeclaration(node)) { - if (node.default) { - delete node.specifiers; - delete node.source; - node.type = "ExportDefaultDeclaration"; - if (node.declaration.type === "FunctionExpression") { - node.declaration.type = "FunctionDeclaration"; - } else if (node.declaration.type === "ClassExpression") { - node.declaration.type = "ClassDeclaration"; - } - } else if (node.specifiers && t.isExportBatchSpecifier(node.specifiers[0])) { - node.type = "ExportAllDeclaration"; - delete node.specifiers; - delete node.declaration; - } else { - node.type = "ExportNamedDeclaration"; + if (t.isClassExpression(node.declaration)) { + node.declaration.type = "ClassDeclaration"; + } else if (t.isFunctionExpression(node.declaration)) { + node.declaration.type = "FunctionDeclaration"; } - delete node.default; - } - - if (t.isExportSpecifier(node)) { - node.local = node.id; - node.exported = node.name || node.id; - delete node.id; - delete node.name; - } - - if (t.isImportSpecifier(node)) { - node.local = node.name || node.id; - if (node.default) { - node.type = "ImportDefaultSpecifier"; - } else { - node.imported = node.id; - } - delete node.id; - delete node.name; - delete node.default; - } - - if (t.isImportBatchSpecifier(node)) { - // ImportBatchSpecifier => ImportNamespaceSpecifier - node.type = "ImportNamespaceSpecifier"; - node.local = node.name; - delete node.name; } // classes @@ -136,18 +90,6 @@ var astTransformVisitor = { // functions if (t.isFunction(node)) { - node.defaults = []; - node.params = node.params.map(function (param) { - if (t.isAssignmentPattern(param)) { - node.defaults.push(param.right); - return param.left; - } else { - node.defaults.push(null); - return param; - } - }); - - node.rest = null; if (node.async) node.generator = true; delete node.async; } diff --git a/eslint/babel-eslint-parser/index.js b/eslint/babel-eslint-parser/index.js index 6a40a13643..7b056e70ac 100644 --- a/eslint/babel-eslint-parser/index.js +++ b/eslint/babel-eslint-parser/index.js @@ -53,11 +53,26 @@ exports.parse = function (code) { process.exit(1); } - var opts = {}; - opts.ecmaVersion = 7; - opts.playground = true; - opts.locations = true; - opts.ranges = true; + var opts = { + ecmaVersion: 7, + locations: true, + ranges: true, + sourceType: "module", + plugins: { + jsx: true, + flow: true + }, + features: { + "es7.asyncFunctions": true, + "es7.classProperties": true, + "es7.comprehensions": true, + "es7.decorators": true, + "es7.doExpressions": true, + "es7.exponentiationOperator": true, + "es7.exportExtensions": true, + "es7.objectRestSpread": true + } + }; var comments = opts.onComment = []; var tokens = opts.onToken = []; diff --git a/eslint/babel-eslint-parser/package.json b/eslint/babel-eslint-parser/package.json index 527e51ba44..c3356a36bf 100644 --- a/eslint/babel-eslint-parser/package.json +++ b/eslint/babel-eslint-parser/package.json @@ -8,7 +8,7 @@ "url": "https://github.com/babel/babel-eslint.git" }, "dependencies": { - "babel-core": "^4.7.8", + "babel-core": "^5.0.0-beta4", "lodash.assign": "^3.0.0" }, "scripts": { @@ -21,8 +21,8 @@ }, "homepage": "https://github.com/babel/babel-eslint", "devDependencies": { - "eslint": "^0.16.0", - "espree": "^1.10.0", + "eslint": "^0.18.0", + "espree": "^2.0.0", "mocha": "^2.1.0" }, "scripts": { diff --git a/eslint/babel-eslint-parser/test/non-regression.js b/eslint/babel-eslint-parser/test/non-regression.js index 7eacdc794e..400ab62c7e 100644 --- a/eslint/babel-eslint-parser/test/non-regression.js +++ b/eslint/babel-eslint-parser/test/non-regression.js @@ -51,15 +51,6 @@ describe("verify", function () { ); }); - it("Unused vars in JSX (issue #5)", function () { - verifyAndAssertMessages( - "var App = require('./App');\n" + - "module.exports = ;", - { "no-unused-vars": 1 }, - [] - ); - }); - it("Modules support (issue #5)", function () { verifyAndAssertMessages( "import Foo from 'foo';\n" +