port to babel 5.0.0

This commit is contained in:
Sebastian McKenzie 2015-04-08 22:07:21 -07:00
parent ded2e420b1
commit 4a531aaba4
4 changed files with 42 additions and 94 deletions

View File

@ -1,36 +1,36 @@
var tokTypes = require("babel-core").acorn.tokTypes;
var traverse = require("babel-core").traverse; var traverse = require("babel-core").traverse;
var tt = require("babel-core").acorn.tokTypes;
var t = require("babel-core").types; var t = require("babel-core").types;
exports.toToken = function (token) { exports.toToken = function (token) {
var type = token.type; var type = token.type;
if (type === tokTypes.name) { if (type === tt.name) {
token.type = "Identifier"; token.type = "Identifier";
} else if (type === tokTypes.semi || type === tokTypes.comma || } else if (type === tt.semi || type === tt.comma ||
type === tokTypes.parenL || type === tokTypes.parenR || type === tt.parenL || type === tt.parenR ||
type === tokTypes.braceL || type === tokTypes.braceR || type === tt.braceL || type === tt.braceR ||
type === tokTypes.slash || type === tokTypes.dot || type === tt.slash || type === tt.dot ||
type === tokTypes.bracketL || type === tokTypes.bracketR || type === tt.bracketL || type === tt.bracketR ||
type === tokTypes.ellipsis || type === tokTypes.arrow || type === tt.ellipsis || type === tt.arrow ||
type === tokTypes.star || type === tt.star ||
type.isAssign) { type.isAssign) {
token.type = "Punctuator"; token.type = "Punctuator";
if (!token.value) token.value = type.type; if (!token.value) token.value = type.label;
} else if (type === tokTypes.jsxTagStart) { } else if (type === tt.jsxTagStart) {
token.type = "Punctuator"; token.type = "Punctuator";
token.value = "<"; token.value = "<";
} else if (type === tokTypes.jsxTagEnd) { } else if (type === tt.jsxTagEnd) {
token.type = "Punctuator"; token.type = "Punctuator";
token.value = ">"; token.value = ">";
} else if (type === tokTypes.jsxName) { } else if (type === tt.jsxName) {
token.type = "JSXIdentifier"; token.type = "JSXIdentifier";
} else if (type.keyword) { } else if (type.keyword) {
token.type = "Keyword"; token.type = "Keyword";
} else if (type === tokTypes.num) { } else if (type === tt.num) {
token.type = "Numeric"; token.type = "Numeric";
token.value = String(token.value); token.value = String(token.value);
} else if (type === tokTypes.string) { } else if (type === tt.string) {
token.type = "String"; token.type = "String";
token.value = JSON.stringify(token.value); token.value = JSON.stringify(token.value);
} }
@ -62,14 +62,6 @@ var astTransformVisitor = {
return node.argument; return node.argument;
} }
// playground
if (t.isAssignmentExpression(node)) {
if (node.operator === "||=" || node.operator === "?=") {
node.operator = "+=";
}
}
// modules // modules
if (t.isImportDeclaration(node)) { if (t.isImportDeclaration(node)) {
@ -77,49 +69,11 @@ var astTransformVisitor = {
} }
if (t.isExportDeclaration(node)) { if (t.isExportDeclaration(node)) {
if (node.default) { if (t.isClassExpression(node.declaration)) {
delete node.specifiers; node.declaration.type = "ClassDeclaration";
delete node.source; } else if (t.isFunctionExpression(node.declaration)) {
node.type = "ExportDefaultDeclaration"; node.declaration.type = "FunctionDeclaration";
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";
} }
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<name> => ImportNamespaceSpecifier<id>
node.type = "ImportNamespaceSpecifier";
node.local = node.name;
delete node.name;
} }
// classes // classes
@ -136,18 +90,6 @@ var astTransformVisitor = {
// functions // functions
if (t.isFunction(node)) { 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; if (node.async) node.generator = true;
delete node.async; delete node.async;
} }

View File

@ -53,11 +53,26 @@ exports.parse = function (code) {
process.exit(1); process.exit(1);
} }
var opts = {}; var opts = {
opts.ecmaVersion = 7; ecmaVersion: 7,
opts.playground = true; locations: true,
opts.locations = true; ranges: true,
opts.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 comments = opts.onComment = [];
var tokens = opts.onToken = []; var tokens = opts.onToken = [];

View File

@ -8,7 +8,7 @@
"url": "https://github.com/babel/babel-eslint.git" "url": "https://github.com/babel/babel-eslint.git"
}, },
"dependencies": { "dependencies": {
"babel-core": "^4.7.8", "babel-core": "^5.0.0-beta4",
"lodash.assign": "^3.0.0" "lodash.assign": "^3.0.0"
}, },
"scripts": { "scripts": {
@ -21,8 +21,8 @@
}, },
"homepage": "https://github.com/babel/babel-eslint", "homepage": "https://github.com/babel/babel-eslint",
"devDependencies": { "devDependencies": {
"eslint": "^0.16.0", "eslint": "^0.18.0",
"espree": "^1.10.0", "espree": "^2.0.0",
"mocha": "^2.1.0" "mocha": "^2.1.0"
}, },
"scripts": { "scripts": {

View File

@ -51,15 +51,6 @@ describe("verify", function () {
); );
}); });
it("Unused vars in JSX (issue #5)", function () {
verifyAndAssertMessages(
"var App = require('./App');\n" +
"module.exports = <App />;",
{ "no-unused-vars": 1 },
[]
);
});
it("Modules support (issue #5)", function () { it("Modules support (issue #5)", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
"import Foo from 'foo';\n" + "import Foo from 'foo';\n" +