Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-eslint

Package Overview
Dependencies
Maintainers
3
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-eslint - npm Package Compare versions

Comparing version 7.2.1 to 7.2.2

babylon-to-espree/convertComments.js

2

babylon-to-espree/attachComments.js

@@ -0,1 +1,3 @@

"use strict";
// comment fixes

@@ -2,0 +4,0 @@ module.exports = function (ast, comments, tokens) {

@@ -0,1 +1,3 @@

"use strict";
module.exports = function (tokens, tt) {

@@ -2,0 +4,0 @@ var startingToken = 0;

50

babylon-to-espree/index.js

@@ -1,20 +0,36 @@

exports.attachComments = require("./attachComments");
"use strict";
exports.toTokens = require("./toTokens");
exports.toAST = require("./toAST");
var attachComments = require("./attachComments");
var convertComments = require("./convertComments");
var toTokens = require("./toTokens");
var toAST = require("./toAST");
exports.convertComments = function (comments) {
for (var i = 0; i < comments.length; i++) {
var comment = comments[i];
if (comment.type === "CommentBlock") {
comment.type = "Block";
} else if (comment.type === "CommentLine") {
comment.type = "Line";
}
// sometimes comments don't get ranges computed,
// even with options.ranges === true
if (!comment.range) {
comment.range = [comment.start, comment.end];
}
}
module.exports = function (ast, traverse, tt, code) {
// remove EOF token, eslint doesn't use this for anything and it interferes
// with some rules see https://github.com/babel/babel-eslint/issues/2
// todo: find a more elegant way to do this
ast.tokens.pop();
// convert tokens
ast.tokens = toTokens(ast.tokens, tt, code);
// add comments
convertComments(ast.comments);
// transform esprima and acorn divergent nodes
toAST(ast, traverse, code);
// ast.program.tokens = ast.tokens;
// ast.program.comments = ast.comments;
// ast = ast.program;
// remove File
ast.type = "Program";
ast.sourceType = ast.program.sourceType;
ast.directives = ast.program.directives;
ast.body = ast.program.body;
delete ast.program;
delete ast._paths;
attachComments(ast, ast.comments, ast.tokens);
};

@@ -1,10 +0,12 @@

var source;
"use strict";
var convertComments = require("./convertComments");
module.exports = function (ast, traverse, code) {
source = code;
var state = { source: code };
ast.range = [ast.start, ast.end];
traverse(ast, astTransformVisitor);
traverse(ast, astTransformVisitor, null, state);
};
function changeToLiteral(node) {
function changeToLiteral(node, state) {
node.type = "Literal";

@@ -15,3 +17,3 @@ if (!node.raw) {

} else {
node.raw = source.slice(node.start, node.end);
node.raw = state.source.slice(node.start, node.end);
}

@@ -21,14 +23,2 @@ }

function changeComments(nodeComments) {
for (var i = 0; i < nodeComments.length; i++) {
var comment = nodeComments[i];
if (comment.type === "CommentLine") {
comment.type = "Line";
} else if (comment.type === "CommentBlock") {
comment.type = "Block";
}
comment.range = [comment.start, comment.end];
}
}
var astTransformVisitor = {

@@ -50,7 +40,7 @@ noScope: true,

if (node.trailingComments) {
changeComments(node.trailingComments);
convertComments(node.trailingComments);
}
if (node.leadingComments) {
changeComments(node.leadingComments);
convertComments(node.leadingComments);
}

@@ -61,10 +51,26 @@

},
exit (path) {
exit (path, state) {
var node = path.node;
[
fixDirectives,
].forEach((fixer) => {
fixer(path);
});
// fixDirectives
if (path.isFunction() || path.isProgram()) {
var directivesContainer = node;
var body = node.body;
if (node.type !== "Program") {
directivesContainer = body;
body = body.body;
}
if (directivesContainer.directives) {
for (var i = directivesContainer.directives.length - 1; i >= 0; i--) {
var directive = directivesContainer.directives[i];
directive.type = "ExpressionStatement";
directive.expression = directive.value;
delete directive.value;
directive.expression.type = "Literal";
changeToLiteral(directive.expression, state);
body.unshift(directive);
}
delete directivesContainer.directives;
}
}

@@ -78,3 +84,3 @@ if (path.isJSXText()) {

path.isStringLiteral()) {
changeToLiteral(node);
changeToLiteral(node, state);
}

@@ -112,3 +118,3 @@

if (path.isClassMethod() || path.isObjectMethod()) {
var code = source.slice(node.key.end, node.body.start);
var code = state.source.slice(node.key.end, node.body.start);
var offset = code.indexOf("(");

@@ -220,3 +226,4 @@

if (path.isTemplateLiteral()) {
node.quasis.forEach((q) => {
for (var j = 0; j < node.quasis.length; j++) {
var q = node.quasis[j];
q.range[0] -= 1;

@@ -234,32 +241,5 @@ if (q.tail) {

}
});
}
}
}
};
function fixDirectives (path) {
if (!(path.isProgram() || path.isFunction())) return;
var node = path.node;
var directivesContainer = node;
var body = node.body;
if (node.type !== "Program") {
directivesContainer = body;
body = body.body;
}
if (!directivesContainer.directives) return;
directivesContainer.directives.reverse().forEach((directive) => {
directive.type = "ExpressionStatement";
directive.expression = directive.value;
delete directive.value;
directive.expression.type = "Literal";
changeToLiteral(directive.expression);
body.unshift(directive);
});
delete directivesContainer.directives;
}
// fixDirectives

@@ -0,1 +1,3 @@

"use strict";
module.exports = function (token, tt, source) {

@@ -2,0 +4,0 @@ var type = token.type;

@@ -0,1 +1,3 @@

"use strict";
var convertTemplateType = require("./convertTemplateType");

@@ -7,8 +9,9 @@ var toToken = require("./toToken");

convertTemplateType(tokens, tt);
var transformedTokens = tokens.filter((token) => {
return token.type !== "CommentLine" && token.type !== "CommentBlock";
});
for (var i = 0, l = transformedTokens.length; i < l; i++) {
transformedTokens[i] = toToken(transformedTokens[i], tt, code);
var transformedTokens = [];
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
if (token.type !== "CommentLine" && token.type !== "CommentBlock") {
transformedTokens.push(toToken(token, tt, code));
}
}

@@ -15,0 +18,0 @@

@@ -13,17 +13,6 @@ var babylonToEspree = require("./babylon-to-espree");

function createModule(filename) {
var mod = new Module(filename);
mod.filename = filename;
mod.paths = Module._nodeModulePaths(path.dirname(filename));
return mod;
}
function monkeypatch() {
if (hasPatched) return;
hasPatched = true;
var eslintLoc;
function getModules() {
try {
// avoid importing a local copy of eslint, try to find a peer dependency
eslintLoc = Module._resolveFilename("eslint", module.parent);
var eslintLoc = Module._resolveFilename("eslint", module.parent);
} catch (err) {

@@ -39,6 +28,34 @@ try {

// get modules relative to what eslint will load
var eslintMod = createModule(eslintLoc);
// ESLint v1.9.0 uses estraverse directly to work around https://github.com/npm/npm/issues/9663
var eslintMod = new Module(eslintLoc);
eslintMod.filename = eslintLoc;
eslintMod.paths = Module._nodeModulePaths(path.dirname(eslintLoc));
try {
var escope = eslintMod.require("eslint-scope");
var Definition = eslintMod.require("eslint-scope/lib/definition").Definition;
var referencer = eslintMod.require("eslint-scope/lib/referencer");
} catch (err) {
escope = eslintMod.require("escope");
Definition = eslintMod.require("escope/lib/definition").Definition;
referencer = eslintMod.require("escope/lib/referencer");
}
var estraverse = eslintMod.require("estraverse");
if (referencer.__esModule) referencer = referencer.default;
return {
Definition,
escope,
estraverse,
referencer,
};
}
function monkeypatch(modules) {
var Definition = modules.Definition;
var escope = modules.escope;
var estraverse = modules.estraverse;
var referencer = modules.referencer;
Object.assign(estraverse.VisitorKeys, t.VISITOR_KEYS);

@@ -48,6 +65,2 @@ estraverse.VisitorKeys.MethodDefinition.push("decorators");

// monkeypatch escope
var escopeLoc = Module._resolveFilename("escope", eslintMod);
var escopeMod = createModule(escopeLoc);
var escope = require(escopeLoc);
var analyze = escope.analyze;

@@ -65,24 +78,2 @@ escope.analyze = function (ast, opts) {

// monkeypatch escope/referencer
var referencerLoc;
try {
referencerLoc = Module._resolveFilename("./referencer", escopeMod);
} catch (err) {
throw new ReferenceError("couldn't resolve escope/referencer");
}
var referencerMod = createModule(referencerLoc);
var referencer = require(referencerLoc);
if (referencer.__esModule) {
referencer = referencer.default;
}
// reference Definition
var definitionLoc;
try {
definitionLoc = Module._resolveFilename("./definition", referencerMod);
} catch (err) {
throw new ReferenceError("couldn't resolve escope/definition");
}
var Definition = require(definitionLoc).Definition;
// if there are decorators, then visit each

@@ -375,7 +366,10 @@ function visitDecorators(node) {

try {
monkeypatch();
} catch (err) {
console.error(err.stack);
process.exit(1);
if (!hasPatched) {
hasPatched = true;
try {
monkeypatch(getModules());
} catch (err) {
console.error(err.stack);
process.exit(1);
}
}

@@ -436,31 +430,5 @@

// remove EOF token, eslint doesn't use this for anything and it interferes with some rules
// see https://github.com/babel/babel-eslint/issues/2 for more info
// todo: find a more elegant way to do this
ast.tokens.pop();
babylonToEspree(ast, traverse, tt, code);
// convert tokens
ast.tokens = babylonToEspree.toTokens(ast.tokens, tt, code);
// add comments
babylonToEspree.convertComments(ast.comments);
// transform esprima and acorn divergent nodes
babylonToEspree.toAST(ast, traverse, code);
// ast.program.tokens = ast.tokens;
// ast.program.comments = ast.comments;
// ast = ast.program;
// remove File
ast.type = "Program";
ast.sourceType = ast.program.sourceType;
ast.directives = ast.program.directives;
ast.body = ast.program.body;
delete ast.program;
delete ast._paths;
babylonToEspree.attachComments(ast, ast.comments, ast.tokens);
return ast;
};
{
"name": "babel-eslint",
"version": "7.2.1",
"version": "7.2.2",
"description": "Custom parser for ESLint",

@@ -39,2 +39,3 @@ "main": "index.js",

"babel-eslint": "^7.0.0",
"dedent": "^0.7.0",
"eslint": "^3.18.0",

@@ -41,0 +42,0 @@ "eslint-config-babel": "^6.0.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc