move eslint out of the core into a separate plugin
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
{
|
||||
"parser": "/Users/sebastian/Projects/babel/core/eslint.js",
|
||||
"ecmaFeatures": {
|
||||
"blockBindings": true
|
||||
},
|
||||
"parser": "babel-eslint",
|
||||
"rules": {
|
||||
"strict": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
|
||||
52
eslint.js
52
eslint.js
@@ -1,52 +0,0 @@
|
||||
var acornToEsprima = require("./lib/babel/helpers/acorn-to-esprima");
|
||||
var traverse = require("./lib/babel/traversal");
|
||||
var extend = require("lodash/object/extend");
|
||||
var Module = require("module");
|
||||
var acorn = require("acorn-babel");
|
||||
var t = require("./lib/babel/types");
|
||||
|
||||
var hasPatched = false;
|
||||
|
||||
function monkeypatch() {
|
||||
if (hasPatched) return;
|
||||
hasPatched = true;
|
||||
|
||||
// monkeypatch estraverse
|
||||
var estraverse = require("estraverse");
|
||||
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||
|
||||
// monkeypatch escope
|
||||
var escope = require("eslint/node_modules/escope");
|
||||
var analyze = escope.analyze;
|
||||
escope.analyze = function (ast, opts) {
|
||||
opts.sourceType = 'module';
|
||||
opts.ecmaVersion = 6;
|
||||
return analyze.call(this, ast, opts)
|
||||
};
|
||||
}
|
||||
|
||||
exports.parse = function (code) {
|
||||
monkeypatch();
|
||||
|
||||
var opts = {};
|
||||
opts.ecmaVersion = 7;
|
||||
opts.locations = true;
|
||||
opts.playground = true;
|
||||
opts.ranges = true;
|
||||
|
||||
var comments = opts.onComment = [];
|
||||
var tokens = opts.onToken = [];
|
||||
|
||||
var ast = acorn.parse(code, opts);
|
||||
|
||||
// convert tokens
|
||||
ast.tokens = tokens.map(acornToEsprima.toEsprimaToken);
|
||||
|
||||
// add comments
|
||||
ast.comments = comments;
|
||||
|
||||
// transform esprima and acorn divergent nodes
|
||||
acornToEsprima.toEsprimaAST(ast);
|
||||
|
||||
return ast;
|
||||
};
|
||||
@@ -71,6 +71,7 @@
|
||||
"browserify": "^9.0.3",
|
||||
"chai": "^2.0.0",
|
||||
"eslint": "^0.15.1",
|
||||
"babel-eslint": "^1.0.0",
|
||||
"esvalid": "^1.1.0",
|
||||
"istanbul": "^0.3.5",
|
||||
"matcha": "^0.6.0",
|
||||
|
||||
@@ -2,13 +2,13 @@ import isFunction from "lodash/lang/isFunction";
|
||||
import transform from "../transformation";
|
||||
import fs from "fs";
|
||||
|
||||
export { default as acorn } from "acorn-babel";
|
||||
export { default as _util, canCompile } from "../util";
|
||||
export { default as transform } from "../transformation";
|
||||
|
||||
export { version } from "../../../package";
|
||||
|
||||
export { default as traverse } from "../traversal";
|
||||
export { default as buildExternalHelpers } from "../build-external-helpers";
|
||||
export { default as types } from "../types";
|
||||
export { version } from "../../../package";
|
||||
|
||||
export function register(opts) {
|
||||
var callback = require("./register/node");
|
||||
|
||||
@@ -11,7 +11,9 @@ import n from "./node";
|
||||
import t from "../types";
|
||||
|
||||
class CodeGenerator {
|
||||
constructor(ast, opts = {}, code) {
|
||||
constructor(ast, opts, code) {
|
||||
opts ||= {};
|
||||
|
||||
this.comments = ast.comments || [];
|
||||
this.tokens = ast.tokens || [];
|
||||
this.format = CodeGenerator.normalizeOptions(code, opts);
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import traverse from "../traversal";
|
||||
import { tokTypes } from "acorn-babel";
|
||||
import t from "../types";
|
||||
|
||||
export function toEsprimaToken(token) {
|
||||
var type = token.type;
|
||||
|
||||
if (type === tokTypes.name) {
|
||||
token.type = "Identifier";
|
||||
} else if (type === tokTypes.semi || type === tokTypes.comma || type === tokTypes.parenL || type === tokTypes.parenR || type === tokTypes.braceL || type === tokTypes.braceR) {
|
||||
token.type = "Punctuator";
|
||||
token.value = type.type;
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
export function toEsprimaAST(ast) {
|
||||
traverse(ast, astTransformVisitor);
|
||||
}
|
||||
|
||||
var astTransformVisitor = {
|
||||
noScope: true,
|
||||
enter(node) {
|
||||
if (t.isImportBatchSpecifier(node)) {
|
||||
node.type = "ImportNamespaceSpecifier";
|
||||
node.id = node.name;
|
||||
delete node.name;
|
||||
} else 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;
|
||||
}
|
||||
});
|
||||
|
||||
if (t.isRestElement(node.params[node.params.length - 1])) {
|
||||
node.rest = node.params.pop();
|
||||
}
|
||||
} else if (t.isClassProperty(node)) {
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user