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

babel-eslint

Package Overview
Dependencies
Maintainers
12
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 11.0.0-beta.1 to 11.0.0-beta.2

156

lib/analyze-scope.js
"use strict";
const t = require("@babel/core").types;
const escope = require("eslint-scope");
const Definition = require("eslint-scope/lib/definition").Definition;
const OriginalPatternVisitor = require("eslint-scope/lib/pattern-visitor");
const OriginalReferencer = require("eslint-scope/lib/referencer");
const fallback = require("eslint-visitor-keys").getKeys;
const childVisitorKeys = require("./visitor-keys");
const flowFlippedAliasKeys = t.FLIPPED_ALIAS_KEYS.Flow.concat(["ArrayPattern", "ClassDeclaration", "ClassExpression", "FunctionDeclaration", "FunctionExpression", "Identifier", "ObjectPattern", "RestElement"]);
const visitorKeysMap = Object.keys(t.VISITOR_KEYS).reduce(function (acc, key) {
const flowFlippedAliasKeys = t.FLIPPED_ALIAS_KEYS.Flow.concat([
"ArrayPattern",
"ClassDeclaration",
"ClassExpression",
"FunctionDeclaration",
"FunctionExpression",
"Identifier",
"ObjectPattern",
"RestElement",
]);
const visitorKeysMap = Object.keys(t.VISITOR_KEYS).reduce(function(acc, key) {
const value = t.VISITOR_KEYS[key];
if (flowFlippedAliasKeys.indexOf(value) === -1) {
acc[key] = value;
}
return acc;
}, {});
const propertyTypes = {
callProperties: {
type: "loop",
values: ["value"]
},
indexers: {
type: "loop",
values: ["key", "value"]
},
properties: {
type: "loop",
values: ["argument", "value"]
},
types: {
type: "loop"
},
params: {
type: "loop"
},
argument: {
type: "single"
},
elementType: {
type: "single"
},
qualification: {
type: "single"
},
rest: {
type: "single"
},
returnType: {
type: "single"
},
typeAnnotation: {
type: "typeAnnotation"
},
typeParameters: {
type: "typeParameters"
},
id: {
type: "id"
}
// loops
callProperties: { type: "loop", values: ["value"] },
indexers: { type: "loop", values: ["key", "value"] },
properties: { type: "loop", values: ["argument", "value"] },
types: { type: "loop" },
params: { type: "loop" },
// single property
argument: { type: "single" },
elementType: { type: "single" },
qualification: { type: "single" },
rest: { type: "single" },
returnType: { type: "single" },
// others
typeAnnotation: { type: "typeAnnotation" },
typeParameters: { type: "typeParameters" },
id: { type: "id" },
};

@@ -80,6 +56,6 @@

}
}
class Referencer extends OriginalReferencer {
// inherits.
visitPattern(node, options, callback) {

@@ -90,4 +66,4 @@ if (!node) {

// Visit type annotations.
this._checkIdentifierOrVisit(node.typeAnnotation);
if (t.isAssignmentPattern(node)) {

@@ -97,7 +73,6 @@ this._checkIdentifierOrVisit(node.left.typeAnnotation);

// Overwrite `super.visitPattern(node, options, callback)` in order to not visit `ArrayPattern#typeAnnotation` and `ObjectPattern#typeAnnotation`.
if (typeof options === "function") {
callback = options;
options = {
processRightHandNodes: false
};
options = { processRightHandNodes: false };
}

@@ -108,2 +83,3 @@

// Process the right hand nodes recursively.
if (options.processRightHandNodes) {

@@ -114,13 +90,20 @@ visitor.rightHandNodes.forEach(this.visit, this);

// inherits.
visitClass(node) {
// Decorators.
this._visitArray(node.decorators);
// Flow type parameters.
const typeParamScope = this._nestTypeParamScope(node);
// Flow super types.
this._visitTypeAnnotation(node.implements);
this._visitTypeAnnotation(
node.superTypeParameters && node.superTypeParameters.params
);
this._visitTypeAnnotation(node.superTypeParameters && node.superTypeParameters.params);
// Basic.
super.visitClass(node);
// Close the type parameter scope.
if (typeParamScope) {

@@ -131,9 +114,13 @@ this.close(node);

// inherits.
visitFunction(node) {
const typeParamScope = this._nestTypeParamScope(node);
// Flow return types.
this._checkIdentifierOrVisit(node.returnType);
// Basic.
super.visitFunction(node);
// Close the type parameter scope.
if (typeParamScope) {

@@ -144,2 +131,3 @@ this.close(node);

// inherits.
visitProperty(node) {

@@ -149,5 +137,3 @@ if (node.value && node.value.type === "TypeCastExpression") {

}
this._visitArray(node.decorators);
super.visitProperty(node);

@@ -161,4 +147,4 @@ }

// TODO: Handle mixins
this._visitArray(node.extends);
this.visit(node.body);

@@ -207,2 +193,3 @@

// visit OptionalMemberExpression as a MemberExpression.
OptionalMemberExpression(node) {

@@ -214,3 +201,2 @@ super.MemberExpression(node);

this._visitTypeAnnotation(node.typeAnnotation);
this.visitProperty(node);

@@ -225,3 +211,2 @@ }

const typeParamScope = this._nestTypeParamScope(node);
if (typeParamScope) {

@@ -233,3 +218,6 @@ this.close(node);

_createScopeVariable(node, name) {
this.currentScope().variableScope.__define(name, new Definition("Variable", name, node, null, null, null));
this.currentScope().variableScope.__define(
name,
new Definition("Variable", name, node, null, null, null)
);
}

@@ -243,11 +231,14 @@

const parentScope = this.scopeManager.__currentScope;
const scope = new escope.Scope(this.scopeManager, "type-parameters", parentScope, node, false);
const scope = new escope.Scope(
this.scopeManager,
"type-parameters",
parentScope,
node,
false
);
this.scopeManager.__nestScope(scope);
for (let j = 0; j < node.typeParameters.params.length; j++) {
const name = node.typeParameters.params[j];
scope.__define(name, new Definition("TypeParameter", name, name));
if (name.typeAnnotation) {

@@ -257,4 +248,3 @@ this._checkIdentifierOrVisit(name);

}
scope.__define = function () {
scope.__define = function() {
return parentScope.__define.apply(parentScope, arguments);

@@ -270,3 +260,2 @@ };

}
if (Array.isArray(node)) {

@@ -277,4 +266,4 @@ node.forEach(this._visitTypeAnnotation, this);

// get property to check (params, id, etc...)
const visitorValues = visitorKeysMap[node.type];
if (!visitorValues) {

@@ -284,2 +273,3 @@ return;

// can have multiple properties
for (let i = 0; i < visitorValues.length; i++) {

@@ -289,7 +279,6 @@ const visitorValue = visitorValues[i];

const nodeProperty = node[visitorValue];
// check if property or type is defined
if (propertyType == null || nodeProperty == null) {
continue;
}
if (propertyType.type === "loop") {

@@ -300,3 +289,2 @@ for (let j = 0; j < nodeProperty.length; j++) {

const loopPropertyNode = nodeProperty[j][propertyType.values[k]];
if (loopPropertyNode) {

@@ -345,6 +333,5 @@ this._checkIdentifierOrVisit(loopPropertyNode);

}
}
module.exports = function (ast, parserOptions) {
module.exports = function(ast, parserOptions) {
const options = {

@@ -354,13 +341,20 @@ ignoreEval: true,

directive: false,
nodejsScope: ast.sourceType === "script" && (parserOptions.ecmaFeatures && parserOptions.ecmaFeatures.globalReturn) === true,
nodejsScope:
ast.sourceType === "script" &&
(parserOptions.ecmaFeatures &&
parserOptions.ecmaFeatures.globalReturn) === true,
impliedStrict: false,
sourceType: ast.sourceType,
ecmaVersion: parserOptions.ecmaVersion,
fallback
fallback,
};
options.childVisitorKeys = childVisitorKeys;
const scopeManager = new escope.ScopeManager(options);
const referencer = new Referencer(options, scopeManager);
referencer.visit(ast);
return scopeManager;
};
};
"use strict";
const t = require("@babel/core").types;
const convertProgramNode = require("./convertProgramNode");
module.exports = function (ast, traverse, code) {
const state = {
source: code
};
module.exports = function(ast, traverse, code) {
const state = { source: code };
// Monkey patch visitor keys in order to be able to traverse the estree nodes
t.VISITOR_KEYS.Property = t.VISITOR_KEYS.ObjectProperty;
t.VISITOR_KEYS.MethodDefinition = ["key", "value", "decorators", "returnType", "typeParameters"];
t.VISITOR_KEYS.MethodDefinition = [
"key",
"value",
"decorators",
"returnType",
"typeParameters",
];
traverse(ast, astTransformVisitor, null, state);
delete t.VISITOR_KEYS.Property;
delete t.VISITOR_KEYS.MethodDefinition;
convertProgramNode(ast);

@@ -21,5 +29,6 @@ };

noScope: true,
enter(path) {
const node = path.node;
// private var to track original node type
node._babelType = node.type;

@@ -39,3 +48,2 @@

},
exit(path) {

@@ -50,14 +58,16 @@ const node = path.node;

// flow: prevent "no-undef"
// for "Component" in: "let x: React.Component"
if (path.isQualifiedTypeIdentifier()) {
delete node.id;
}
// for "b" in: "var a: { b: Foo }"
if (path.isObjectTypeProperty()) {
delete node.key;
}
// for "indexer" in: "var a: {[indexer: string]: number}"
if (path.isObjectTypeIndexer()) {
delete node.id;
}
// for "param" in: "var a: { func(param: Foo): Bar };"
if (path.isFunctionTypeParam()) {

@@ -67,2 +77,4 @@ delete node.name;

// modules
if (path.isImportDeclaration()) {

@@ -72,2 +84,3 @@ delete node.isType;

// template string range fixes
if (path.isTemplateLiteral()) {

@@ -77,3 +90,2 @@ for (let j = 0; j < node.quasis.length; j++) {

q.range[0] -= 1;
if (q.tail) {

@@ -84,5 +96,3 @@ q.range[1] += 1;

}
q.loc.start.column -= 1;
if (q.tail) {

@@ -95,4 +105,3 @@ q.loc.end.column += 1;

}
}
};
},
};
"use strict";
module.exports = function (comments) {
module.exports = function(comments) {
for (let i = 0; i < comments.length; i++) {
const comment = comments[i];
if (comment.type === "CommentBlock") {

@@ -12,3 +11,4 @@ comment.type = "Block";

}
// sometimes comments don't get ranges computed,
// even with options.ranges === true
if (!comment.range) {

@@ -18,2 +18,2 @@ comment.range = [comment.start, comment.end];

}
};
};
"use strict";
module.exports = function (ast) {
module.exports = function(ast) {
ast.type = "Program";

@@ -14,2 +14,3 @@ ast.sourceType = ast.program.sourceType;

if (!ast.tokens.length) {
// if no tokens, the program starts at the end of the last comment
ast.start = lastComment.end;

@@ -22,2 +23,4 @@ ast.loc.start.line = lastComment.loc.end.line;

if (lastComment.end > lastToken.end) {
// If there is a comment after the last token, the program ends at the
// last token and not the comment
ast.range[1] = lastToken.end;

@@ -39,2 +42,2 @@ ast.loc.end.line = lastToken.loc.end.line;

}
};
};
"use strict";
module.exports = function (tokens, tt) {
module.exports = function(tokens, tt) {
let curlyBrace = null;

@@ -11,2 +11,3 @@ let templateTokens = [];

const end = templateTokens[templateTokens.length - 1];
const value = templateTokens.reduce((result, token) => {

@@ -21,2 +22,3 @@ if (token.value) {

}, "");
result.push({

@@ -29,5 +31,6 @@ type: "Template",

start: start.loc.start,
end: end.loc.end
}
end: end.loc.end,
},
});
templateTokens = [];

@@ -90,3 +93,4 @@ }

});
return result;
};
};
"use strict";
module.exports = function (token, tt, source) {
module.exports = function(token, tt, source) {
const type = token.type;

@@ -9,3 +9,43 @@ token.range = [token.start, token.end];

token.type = "Identifier";
} 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.pipeline || type === tt.star || type === tt.incDec || type === tt.colon || type === tt.question || type === tt.questionDot || type === tt.template || type === tt.backQuote || type === tt.dollarBraceL || type === tt.at || type === tt.logicalOR || type === tt.logicalAND || type === tt.nullishCoalescing || type === tt.bitwiseOR || type === tt.bitwiseXOR || type === tt.bitwiseAND || type === tt.equality || type === tt.relational || type === tt.bitShift || type === tt.plusMin || type === tt.modulo || type === tt.exponent || type === tt.bang || type === tt.tilde || type === tt.doubleColon || type === tt.hash || type.isAssign) {
} 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.pipeline ||
type === tt.star ||
type === tt.incDec ||
type === tt.colon ||
type === tt.question ||
type === tt.questionDot ||
type === tt.template ||
type === tt.backQuote ||
type === tt.dollarBraceL ||
type === tt.at ||
type === tt.logicalOR ||
type === tt.logicalAND ||
type === tt.nullishCoalescing ||
type === tt.bitwiseOR ||
type === tt.bitwiseXOR ||
type === tt.bitwiseAND ||
type === tt.equality ||
type === tt.relational ||
type === tt.bitShift ||
type === tt.plusMin ||
type === tt.modulo ||
type === tt.exponent ||
type === tt.bang ||
type === tt.tilde ||
type === tt.doubleColon ||
type === tt.hash ||
type.isAssign
) {
token.type = "Punctuator";

@@ -40,3 +80,3 @@ if (!token.value) token.value = type.label;

pattern: value.pattern,
flags: value.flags
flags: value.flags,
};

@@ -47,2 +87,2 @@ token.value = `/${value.pattern}/${value.flags}`;

return token;
};
};
"use strict";
const convertTemplateType = require("./convertTemplateType");
const convertToken = require("./convertToken");
module.exports = function (tokens, tt, code) {
return convertTemplateType(tokens, tt).filter(t => t.type !== "CommentLine" && t.type !== "CommentBlock").map(t => convertToken(t, tt, code));
};
module.exports = function(tokens, tt, code) {
return convertTemplateType(tokens, tt)
.filter(t => t.type !== "CommentLine" && t.type !== "CommentBlock")
.map(t => convertToken(t, tt, code));
};
"use strict";
const convertTokens = require("./convertTokens");
const convertComments = require("./convertComments");
const convertAST = require("./convertAST");
module.exports = function (ast, traverse, tt, code) {
module.exports = function(ast, traverse, tt, code) {
ast.tokens = convertTokens(ast.tokens, tt, code);
convertComments(ast.comments);
convertAST(ast, traverse, code);
};
};
"use strict";
const semver = require("semver");
const babelCore = require("@babel/core");
const packageJson = require("../package.json");
const CURRENT_BABEL_VERSION = babelCore.version;
const SUPPORTED_BABEL_VERSION_RANGE = packageJson.peerDependencies["@babel/core"];
const IS_RUNNING_SUPPORTED_VERSION = semver.satisfies(CURRENT_BABEL_VERSION, SUPPORTED_BABEL_VERSION_RANGE);
const SUPPORTED_BABEL_VERSION_RANGE =
packageJson.peerDependencies["@babel/core"];
const IS_RUNNING_SUPPORTED_VERSION = semver.satisfies(
CURRENT_BABEL_VERSION,
SUPPORTED_BABEL_VERSION_RANGE
);
exports.parse = function (code, options) {
exports.parse = function(code, options) {
return exports.parseForESLint(code, options).ast;
};
exports.parseForESLint = function (code, options = {}) {
exports.parseForESLint = function(code, options = {}) {
if (!IS_RUNNING_SUPPORTED_VERSION) {
throw new Error(`babel-eslint@${packageJson.version} does not support @babel/core@${CURRENT_BABEL_VERSION}. Please downgrade to babel-eslint@^10 or upgrade to @babel/core@${SUPPORTED_BABEL_VERSION_RANGE}`);
throw new Error(
`babel-eslint@${packageJson.version} does not support @babel/core@${CURRENT_BABEL_VERSION}. Please downgrade to babel-eslint@^10 or upgrade to @babel/core@${SUPPORTED_BABEL_VERSION_RANGE}`
);
}

@@ -25,4 +29,6 @@

options.sourceType = options.sourceType || "module";
options.allowImportExportEverywhere = options.allowImportExportEverywhere || false;
options.allowImportExportEverywhere =
options.allowImportExportEverywhere || false;
return require("./parse-with-scope")(code, options);
};
};
"use strict";
const visitorKeys = require("./visitor-keys");
const analyzeScope = require("./analyze-scope");
const parse = require("./parse");
module.exports = function (code, options) {
module.exports = function(code, options) {
const ast = parse(code, options);
const scopeManager = analyzeScope(ast, options);
return {
ast,
scopeManager,
visitorKeys
};
};
return { ast, scopeManager, visitorKeys };
};
"use strict";
const babylonToEspree = require("./babylon-to-espree");
const {

@@ -9,6 +8,6 @@ parseSync: parse,

traverse,
loadPartialConfig
loadPartialConfig,
} = require("@babel/core");
module.exports = function (code, options) {
module.exports = function(code, options) {
let opts = {

@@ -33,3 +32,3 @@ sourceType: options.sourceType,

parserOpts: {
allowImportExportEverywhere: options.allowImportExportEverywhere,
allowImportExportEverywhere: options.allowImportExportEverywhere, // consistent with espree
allowReturnOutsideFunction: true,

@@ -39,7 +38,7 @@ allowSuperOutsideMethod: true,

tokens: true,
plugins: ["estree"]
plugins: ["estree"],
},
caller: {
name: "babel-eslint"
}
name: "babel-eslint",
},
};

@@ -52,3 +51,5 @@

if (!config.hasFilesystemConfig()) {
throw new Error(`No Babel config file detected for ${config.options.filename}. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.`);
throw new Error(
`No Babel config file detected for ${config.options.filename}. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.`
);
}

@@ -74,3 +75,4 @@

babylonToEspree(ast, traverse, tt, code);
return ast;
};
};
"use strict";
const BABEL_VISITOR_KEYS = require("@babel/core").types.VISITOR_KEYS;
const ESLINT_VISITOR_KEYS = require("eslint-visitor-keys").KEYS;
module.exports = Object.assign({
Literal: ESLINT_VISITOR_KEYS.Literal,
MethodDefinition: ["decorators"].concat(ESLINT_VISITOR_KEYS.MethodDefinition),
Property: ["decorators"].concat(ESLINT_VISITOR_KEYS.Property)
}, BABEL_VISITOR_KEYS);
module.exports = Object.assign(
{
Literal: ESLINT_VISITOR_KEYS.Literal,
MethodDefinition: ["decorators"].concat(
ESLINT_VISITOR_KEYS.MethodDefinition
),
Property: ["decorators"].concat(ESLINT_VISITOR_KEYS.Property),
},
BABEL_VISITOR_KEYS
);
{
"name": "babel-eslint",
"version": "11.0.0-beta.1",
"version": "11.0.0-beta.2",
"description": "Custom parser for ESLint",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"license": "MIT",
"private": false,
"repository": {

@@ -17,15 +16,24 @@ "type": "git",

"scripts": {
"test": "npm run lint && npm run test-only",
"test-only": "cd test && mocha specs && cd -",
"lint": "eslint .",
"lint-fix": "npm run lint -- --fix",
"precommit": "lint-staged",
"preversion": "npm test",
"changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"main": "lib/index.js",
"files": [
"lib"
],
"peerDependencies": {
"@babel/core": ">=7.2.0",
"eslint": ">= 4.12.1"
"eslint": ">= 6.0.0"
},
"dependencies": {
"eslint-scope": "3.7.1",
"eslint-visitor-keys": "^1.0.0",
"eslint-scope": "5.0.0",
"eslint-visitor-keys": "^1.1.0",
"semver": "^6.3.0"

@@ -48,6 +56,21 @@ },

"@babel/preset-react": "^7.0.0",
"babel-eslint": "^10.0.2",
"dedent": "^0.7.0",
"eslint": "^6.0.1",
"espree": "^6.0.0"
"eslint-config-babel": "^9.0.0",
"eslint-plugin-flowtype": "^3.11.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^3.1.0",
"espree": "^6.0.0",
"husky": "^1.0.0-rc.13",
"lint-staged": "^7.2.2",
"mocha": "^6.1.4",
"prettier": "^1.4.4"
},
"lint-staged": {
"*.js": [
"eslint --format=codeframe --fix",
"git add"
]
}
}

Sorry, the diff of this file is not supported yet

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