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

shift-validator

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shift-validator - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

README.md

232

dist/index.js

@@ -22,2 +22,6 @@ "use strict";

var _shiftRegexpAcceptor = require("shift-regexp-acceptor");
var _shiftRegexpAcceptor2 = _interopRequireDefault(_shiftRegexpAcceptor);
var _validationContext = require("./validation-context");

@@ -51,6 +55,6 @@

var isIdentifierNameES6 = _esutils.keyword.isIdentifierNameES6;
var isReservedWordES6 = _esutils.keyword.isReservedWordES6;
var isIdentifierStart = _esutils.code.isIdentifierStartES6;
var isIdentifierPart = _esutils.code.isIdentifierPartES6;
var isIdentifierNameES6 = _esutils.keyword.isIdentifierNameES6,
isReservedWordES6 = _esutils.keyword.isReservedWordES6;
var isIdentifierStart = _esutils.code.isIdentifierStartES6,
isIdentifierPart = _esutils.code.isIdentifierPartES6;
function isValid(node) {

@@ -107,12 +111,3 @@ return Validator.validate(node).length === 0;

function isValidIdentifier(name) {
return name === 'let' || name === 'yield' || name === 'enum' || isIdentifierNameES6(name) && !isReservedWordES6(name);
if (name.length === 0) {
return false;
}
try {
var res = new _shiftParser.Tokenizer(name).scanIdentifier();
return (res.type === _shiftParser.TokenType.IDENTIFIER || res.type === _shiftParser.TokenType.LET || res.type === _shiftParser.TokenType.YIELD) && res.value === name;
} catch (e) {
return false;
}
return name === 'let' || name === 'yield' || name === 'await' || name === 'async' || name === 'enum' || isIdentifierNameES6(name) && !isReservedWordES6(name);
}

@@ -130,6 +125,2 @@

function isValidRegex(pattern, flags) {
return true; // TODO fix this when pattern-acceptor is fixed
}
function isTemplateElement(rawValue) {

@@ -167,7 +158,6 @@ try {

function checkIllegalBody(node, s) {
var _ref = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
_ref$allowFunctions = _ref.allowFunctions,
allowFunctions = _ref$allowFunctions === undefined ? false : _ref$allowFunctions;
var _ref$allowFunctions = _ref.allowFunctions;
var allowFunctions = _ref$allowFunctions === undefined ? false : _ref$allowFunctions;
if (node.body.type === 'FunctionDeclaration' && !allowFunctions) {

@@ -187,3 +177,3 @@ return s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.FUNCTION_DECLARATION_AS_STATEMENT));

return _possibleConstructorReturn(this, Object.getPrototypeOf(Validator).call(this, _validationContext.ValidationContext));
return _possibleConstructorReturn(this, (Validator.__proto__ || Object.getPrototypeOf(Validator)).call(this, _validationContext.ValidationContext));
}

@@ -194,6 +184,7 @@

value: function reduceArrowExpression(node, _ref2) {
var params = _ref2.params;
var body = _ref2.body;
var params = _ref2.params,
body = _ref2.body;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceArrowExpression", this).call(this, node, { params: params, body: body.enforceYields() });
body = node.isAsync ? body.clearAwaitExpressionsNotInAsyncContext() : body.enforceAwaitExpressionsNotInAsyncContext();
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceArrowExpression", this).call(this, node, { params: params, body: body.enforceYields() });
return s;

@@ -204,3 +195,3 @@ }

value: function reduceAssignmentTargetIdentifier(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceAssignmentTargetIdentifier", this).call(this, node);
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceAssignmentTargetIdentifier", this).call(this, node);
if (!isValidIdentifier(node.name)) {

@@ -214,3 +205,3 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_BINDING_IDENTIFIER_NAME));

value: function reduceBindingIdentifier(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceBindingIdentifier", this).call(this, node);
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceBindingIdentifier", this).call(this, node);
if (!isValidIdentifier(node.name)) {

@@ -228,3 +219,3 @@ if (node.name == "*default*") {

value: function reduceBreakStatement(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceBreakStatement", this).call(this, node);
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceBreakStatement", this).call(this, node);
if (node.label !== null && !isValidIdentifier(node.label)) {

@@ -238,3 +229,3 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_BREAK_STATEMENT_LABEL));

value: function reduceContinueStatement(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceContinueStatement", this).call(this, node);
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceContinueStatement", this).call(this, node);
if (node.label !== null && !isValidIdentifier(node.label)) {

@@ -248,6 +239,6 @@ s = s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_CONTINUE_STATEMENT_LABEL));

value: function reduceDoWhileStatement(node, _ref3) {
var body = _ref3.body;
var test = _ref3.test;
var body = _ref3.body,
test = _ref3.test;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceDoWhileStatement", this).call(this, node, { body: body, test: test });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceDoWhileStatement", this).call(this, node, { body: body, test: test });
s = checkIllegalBody(node, s);

@@ -259,3 +250,3 @@ return s;

value: function reduceDirective(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceDirective", this).call(this, node);
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceDirective", this).call(this, node);
if (!isDirective(node.rawValue)) {

@@ -271,3 +262,3 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_DIRECTIVE));

var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceExportDefault", this).call(this, node, { body: body });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceExportDefault", this).call(this, node, { body: body });
if (node.body.type === 'FunctionDeclaration' || node.body.type == 'ClassDeclaration') {

@@ -281,3 +272,3 @@ s = s.clearBindingIdentifiersCalledDefault();

value: function reduceExportFromSpecifier(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceExportFromSpecifier", this).call(this, node);
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceExportFromSpecifier", this).call(this, node);
if (!isValidIdentifierName(node.name)) {

@@ -296,3 +287,3 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_EXPORT_SPECIFIER_NAME));

var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceExportLocalSpecifier", this).call(this, node, { name: name });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceExportLocalSpecifier", this).call(this, node, { name: name });
if (node.exportedName !== null && !isIdentifierNameES6(node.exportedName)) {

@@ -306,7 +297,7 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_EXPORTED_NAME));

value: function reduceForInStatement(node, _ref6) {
var left = _ref6.left;
var right = _ref6.right;
var body = _ref6.body;
var left = _ref6.left,
right = _ref6.right,
body = _ref6.body;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceForInStatement", this).call(this, node, { left: left, right: right, body: body });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceForInStatement", this).call(this, node, { left: left, right: right, body: body });
if (node.left.type === 'VariableDeclaration') {

@@ -326,7 +317,7 @@ if (node.left.declarators.length != 1) {

value: function reduceForOfStatement(node, _ref7) {
var left = _ref7.left;
var right = _ref7.right;
var body = _ref7.body;
var left = _ref7.left,
right = _ref7.right,
body = _ref7.body;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceForOfStatement", this).call(this, node, { left: left, right: right, body: body });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceForOfStatement", this).call(this, node, { left: left, right: right, body: body });
if (node.left.type === 'VariableDeclaration') {

@@ -346,8 +337,8 @@ if (node.left.declarators.length != 1) {

value: function reduceForStatement(node, _ref8) {
var init = _ref8.init;
var update = _ref8.update;
var test = _ref8.test;
var body = _ref8.body;
var init = _ref8.init,
update = _ref8.update,
test = _ref8.test,
body = _ref8.body;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceForStatement", this).call(this, node, { init: init, update: update, test: test, body: body });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceForStatement", this).call(this, node, { init: init, update: update, test: test, body: body });
s = checkIllegalBody(node, s);

@@ -359,7 +350,7 @@ return s;

value: function reduceFormalParameters(node, _ref9) {
var items = _ref9.items;
var rest = _ref9.rest;
var items = _ref9.items,
rest = _ref9.rest;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceFormalParameters", this).call(this, node, { items: items, rest: rest });
s = s.enforceYields();
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceFormalParameters", this).call(this, node, { items: items, rest: rest });
s = s.enforceYields().enforceAwaitExpressionsNotInAsyncContext();
return s;

@@ -370,6 +361,6 @@ }

value: function reduceFunctionBody(node, _ref10) {
var directives = _ref10.directives;
var statements = _ref10.statements;
var directives = _ref10.directives,
statements = _ref10.statements;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceFunctionBody", this).call(this, node, { directives: directives, statements: statements });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceFunctionBody", this).call(this, node, { directives: directives, statements: statements });
s = s.clearFreeReturnStatements();

@@ -381,8 +372,12 @@ return s;

value: function reduceFunctionDeclaration(node, _ref11) {
var name = _ref11.name;
var params = _ref11.params;
var body = _ref11.body;
var name = _ref11.name,
params = _ref11.params,
body = _ref11.body;
body = node.isGenerator ? body.clearYields() : body.enforceYields();
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceFunctionDeclaration", this).call(this, node, { name: name, params: params, body: body });
body = node.isAsync ? body.clearAwaitExpressionsNotInAsyncContext() : body.enforceAwaitExpressionsNotInAsyncContext();
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceFunctionDeclaration", this).call(this, node, { name: name, params: params, body: body });
if (node.isGenerator && node.isAsync) {
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.ASYNC_GENERATOR_FUNCTION));
}
return s;

@@ -393,8 +388,12 @@ }

value: function reduceFunctionExpression(node, _ref12) {
var name = _ref12.name;
var params = _ref12.params;
var body = _ref12.body;
var name = _ref12.name,
params = _ref12.params,
body = _ref12.body;
body = node.isGenerator ? body.clearYields() : body.enforceYields();
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceFunctionExpression", this).call(this, node, { name: name, params: params, body: body });
body = node.isAsync ? body.clearAwaitExpressionsNotInAsyncContext() : body.enforceAwaitExpressionsNotInAsyncContext();
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceFunctionExpression", this).call(this, node, { name: name, params: params, body: body });
if (node.isGenerator && node.isAsync) {
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.ASYNC_GENERATOR_FUNCTION));
}
return s;

@@ -405,6 +404,6 @@ }

value: function reduceGetter(node, _ref13) {
var name = _ref13.name;
var body = _ref13.body;
var name = _ref13.name,
body = _ref13.body;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceGetter", this).call(this, node, { name: name, body: body.enforceYields() });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceGetter", this).call(this, node, { name: name, body: body.enforceYields().enforceAwaitExpressionsNotInAsyncContext() });
return s;

@@ -415,3 +414,3 @@ }

value: function reduceIdentifierExpression(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceIdentifierExpression", this).call(this, node);
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceIdentifierExpression", this).call(this, node);
if (!isValidIdentifier(node.name)) {

@@ -425,7 +424,7 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_IDENTIFIER_NAME));

value: function reduceIfStatement(node, _ref14) {
var test = _ref14.test;
var consequent = _ref14.consequent;
var alternate = _ref14.alternate;
var test = _ref14.test,
consequent = _ref14.consequent,
alternate = _ref14.alternate;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceIfStatement", this).call(this, node, { test: test, consequent: consequent, alternate: alternate });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceIfStatement", this).call(this, node, { test: test, consequent: consequent, alternate: alternate });
if (isProblematicIfStatement(node)) {

@@ -447,3 +446,3 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_IF_STATEMENT));

var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceImportSpecifier", this).call(this, node, { binding: binding });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceImportSpecifier", this).call(this, node, { binding: binding });
if (node.name !== null && !isIdentifierNameES6(node.name)) {

@@ -459,3 +458,3 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_IMPORT_SPECIFIER_NAME));

var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceLabeledStatement", this).call(this, node, { body: body });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceLabeledStatement", this).call(this, node, { body: body });
if (!isValidIdentifier(node.label)) {

@@ -470,3 +469,3 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_LABEL));

value: function reduceLiteralNumericExpression(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceLiteralNumericExpression", this).call(this, node);
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceLiteralNumericExpression", this).call(this, node);
if (isNaN(node.value)) {

@@ -487,4 +486,4 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.LITERAL_NUMERIC_VALUE_NOT_NAN));

value: function reduceLiteralRegExpExpression(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceLiteralRegExpExpression", this).call(this, node);
if (!isValidRegex(node.pattern, node.flags)) {
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceLiteralRegExpExpression", this).call(this, node);
if (!(0, _shiftRegexpAcceptor2.default)(node.pattern, { unicode: node.unicode })) {
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_REG_EX_PATTERN));

@@ -497,8 +496,12 @@ }

value: function reduceMethod(node, _ref17) {
var params = _ref17.params;
var body = _ref17.body;
var name = _ref17.name;
var params = _ref17.params,
body = _ref17.body,
name = _ref17.name;
body = node.isGenerator ? body.clearYields() : body.enforceYields();
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceMethod", this).call(this, node, { params: params, body: body, name: name });
body = node.isAsync ? body.clearAwaitExpressionsNotInAsyncContext() : body.enforceAwaitExpressionsNotInAsyncContext();
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceMethod", this).call(this, node, { params: params, body: body, name: name });
if (node.isGenerator && node.isAsync) {
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.ASYNC_GENERATOR_FUNCTION));
}
return s;

@@ -509,9 +512,10 @@ }

value: function reduceModule(node, _ref18) {
var directives = _ref18.directives;
var items = _ref18.items;
var directives = _ref18.directives,
items = _ref18.items;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceModule", this).call(this, node, { directives: directives, items: items });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceModule", this).call(this, node, { directives: directives, items: items });
s = s.enforceFreeReturnStatements();
s = s.enforceBindingIdentifiersCalledDefault();
s = s.enforceYields();
s = s.enforceAwaitExpressionsNotInAsyncContext();
return s;

@@ -524,3 +528,3 @@ }

var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceReturnStatement", this).call(this, node, { expression: expression });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceReturnStatement", this).call(this, node, { expression: expression });
s = s.addFreeReturnStatement(node);

@@ -532,9 +536,10 @@ return s;

value: function reduceScript(node, _ref20) {
var directives = _ref20.directives;
var statements = _ref20.statements;
var directives = _ref20.directives,
statements = _ref20.statements;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceScript", this).call(this, node, { directives: directives, statements: statements });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceScript", this).call(this, node, { directives: directives, statements: statements });
s = s.enforceFreeReturnStatements();
s = s.enforceBindingIdentifiersCalledDefault();
s = s.enforceYields();
s = s.enforceAwaitExpressionsNotInAsyncContext();
return s;

@@ -545,7 +550,7 @@ }

value: function reduceSetter(node, _ref21) {
var name = _ref21.name;
var param = _ref21.param;
var body = _ref21.body;
var name = _ref21.name,
param = _ref21.param,
body = _ref21.body;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceSetter", this).call(this, node, { name: name, param: param, body: body.enforceYields() });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceSetter", this).call(this, node, { name: name, param: param, body: body.enforceYields().enforceAwaitExpressionsNotInAsyncContext() });
return s;

@@ -558,3 +563,3 @@ }

var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceStaticMemberExpression", this).call(this, node, { object: object });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceStaticMemberExpression", this).call(this, node, { object: object });
if (!isIdentifierNameES6(node.property)) {

@@ -568,3 +573,3 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_STATIC_MEMBER_EXPRESSION_PROPERTY_NAME));

value: function reduceTemplateElement(node) {
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceTemplateElement", this).call(this, node);
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceTemplateElement", this).call(this, node);
if (!isTemplateElement(node.rawValue)) {

@@ -578,6 +583,6 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_TEMPLATE_ELEMENT_VALUE));

value: function reduceTemplateExpression(node, _ref23) {
var tag = _ref23.tag;
var elements = _ref23.elements;
var tag = _ref23.tag,
elements = _ref23.elements;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceTemplateExpression", this).call(this, node, { tag: tag, elements: elements });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceTemplateExpression", this).call(this, node, { tag: tag, elements: elements });
if (node.elements.length > 0) {

@@ -607,3 +612,3 @@ if (node.elements.length % 2 == 0) {

var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceVariableDeclaration", this).call(this, node, { declarators: declarators });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceVariableDeclaration", this).call(this, node, { declarators: declarators });
if (node.declarators.length == 0) {

@@ -617,6 +622,6 @@ s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.NOT_EMPTY_VARIABLE_DECLARATORS_LIST));

value: function reduceWhileStatement(node, _ref25) {
var test = _ref25.test;
var body = _ref25.body;
var test = _ref25.test,
body = _ref25.body;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceWhileStatement", this).call(this, node, { test: test, body: body });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceWhileStatement", this).call(this, node, { test: test, body: body });
s = checkIllegalBody(node, s);

@@ -628,6 +633,6 @@ return s;

value: function reduceWithStatement(node, _ref26) {
var object = _ref26.object;
var body = _ref26.body;
var object = _ref26.object,
body = _ref26.body;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceWithStatement", this).call(this, node, { object: object, body: body });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceWithStatement", this).call(this, node, { object: object, body: body });
s = checkIllegalBody(node, s);

@@ -641,3 +646,3 @@ return s;

var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceYieldExpression", this).call(this, node, { expression: expression });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceYieldExpression", this).call(this, node, { expression: expression });
s = s.addYieldExpressionNotInGeneratorContext(node);

@@ -647,7 +652,16 @@ return s;

}, {
key: "reduceYieldGeneratorExpression",
value: function reduceYieldGeneratorExpression(node, _ref28) {
key: "reduceAwaitExpression",
value: function reduceAwaitExpression(node, _ref28) {
var expression = _ref28.expression;
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceYieldGeneratorExpression", this).call(this, node, { expression: expression });
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceAwaitExpression", this).call(this, node, { expression: expression });
s = s.addAwaitExpressionNotInAsyncContext(node);
return s;
}
}, {
key: "reduceYieldGeneratorExpression",
value: function reduceYieldGeneratorExpression(node, _ref29) {
var expression = _ref29.expression;
var s = _get(Validator.prototype.__proto__ || Object.getPrototypeOf(Validator.prototype), "reduceYieldGeneratorExpression", this).call(this, node, { expression: expression });
s = s.addYieldGeneratorExpressionNotInGeneratorContext(node);

@@ -654,0 +668,0 @@ return s;

@@ -38,15 +38,16 @@ "use strict";

function ValidationContext() {
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$errors = _ref.errors,
errors = _ref$errors === undefined ? [] : _ref$errors,
_ref$freeReturnStatem = _ref.freeReturnStatements,
freeReturnStatements = _ref$freeReturnStatem === undefined ? [] : _ref$freeReturnStatem,
_ref$bindingIdentifie = _ref.bindingIdentifiersCalledDefault,
bindingIdentifiersCalledDefault = _ref$bindingIdentifie === undefined ? [] : _ref$bindingIdentifie,
_ref$yieldExpressions = _ref.yieldExpressionsNotInGeneratorContext,
yieldExpressionsNotInGeneratorContext = _ref$yieldExpressions === undefined ? [] : _ref$yieldExpressions,
_ref$awaitExpressions = _ref.awaitExpressionsNotInAsyncContext,
awaitExpressionsNotInAsyncContext = _ref$awaitExpressions === undefined ? [] : _ref$awaitExpressions,
_ref$yieldGeneratorEx = _ref.yieldGeneratorExpressionsNotInGeneratorContext,
yieldGeneratorExpressionsNotInGeneratorContext = _ref$yieldGeneratorEx === undefined ? [] : _ref$yieldGeneratorEx;
var _ref$errors = _ref.errors;
var errors = _ref$errors === undefined ? [] : _ref$errors;
var _ref$freeReturnStatem = _ref.freeReturnStatements;
var freeReturnStatements = _ref$freeReturnStatem === undefined ? [] : _ref$freeReturnStatem;
var _ref$bindingIdentifie = _ref.bindingIdentifiersCalledDefault;
var bindingIdentifiersCalledDefault = _ref$bindingIdentifie === undefined ? [] : _ref$bindingIdentifie;
var _ref$yieldExpressions = _ref.yieldExpressionsNotInGeneratorContext;
var yieldExpressionsNotInGeneratorContext = _ref$yieldExpressions === undefined ? [] : _ref$yieldExpressions;
var _ref$yieldGeneratorEx = _ref.yieldGeneratorExpressionsNotInGeneratorContext;
var yieldGeneratorExpressionsNotInGeneratorContext = _ref$yieldGeneratorEx === undefined ? [] : _ref$yieldGeneratorEx;
_classCallCheck(this, ValidationContext);

@@ -58,2 +59,3 @@

this.yieldExpressionsNotInGeneratorContext = yieldExpressionsNotInGeneratorContext;
this.awaitExpressionsNotInAsyncContext = awaitExpressionsNotInAsyncContext;
this.yieldGeneratorExpressionsNotInGeneratorContext = yieldGeneratorExpressionsNotInGeneratorContext;

@@ -70,2 +72,3 @@ }

yieldExpressionsNotInGeneratorContext: this.yieldExpressionsNotInGeneratorContext.concat(b.yieldExpressionsNotInGeneratorContext),
awaitExpressionsNotInAsyncContext: this.awaitExpressionsNotInAsyncContext.concat(b.awaitExpressionsNotInAsyncContext),
yieldGeneratorExpressionsNotInGeneratorContext: this.yieldGeneratorExpressionsNotInGeneratorContext.concat(b.yieldGeneratorExpressionsNotInGeneratorContext)

@@ -141,2 +144,9 @@ });

}, {
key: "addAwaitExpressionNotInAsyncContext",
value: function addAwaitExpressionNotInAsyncContext(e) {
var s = new ValidationContext(this);
s.awaitExpressionsNotInAsyncContext = s.awaitExpressionsNotInAsyncContext.concat([e]);
return s;
}
}, {
key: "enforceYieldExpressionsNotInGeneratorContext",

@@ -154,2 +164,14 @@ value: function enforceYieldExpressionsNotInGeneratorContext() {

}, {
key: "enforceAwaitExpressionsNotInAsyncContext",
value: function enforceAwaitExpressionsNotInAsyncContext() {
var errors = [];
this.awaitExpressionsNotInAsyncContext.forEach(function (r) {
return errors.push(new ValidationError(r, _validationErrors2.default.VALID_AWAIT_EXPRESSION_POSITION));
});
var s = new ValidationContext(this);
s.errors = s.errors.concat(errors);
s.awaitExpressionsNotInAsyncContext = [];
return s;
}
}, {
key: "clearYieldExpressionsNotInGeneratorContext",

@@ -162,2 +184,9 @@ value: function clearYieldExpressionsNotInGeneratorContext() {

}, {
key: "clearAwaitExpressionsNotInAsyncContext",
value: function clearAwaitExpressionsNotInAsyncContext() {
var s = new ValidationContext(this);
s.awaitExpressionsNotInAsyncContext = [];
return s;
}
}, {
key: "addYieldGeneratorExpressionNotInGeneratorContext",

@@ -214,3 +243,3 @@ value: function addYieldGeneratorExpressionNotInGeneratorContext(e) {

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ValidationError).call(this));
var _this = _possibleConstructorReturn(this, (ValidationError.__proto__ || Object.getPrototypeOf(ValidationError)).call(this));

@@ -217,0 +246,0 @@ _this.node = node;

@@ -46,2 +46,3 @@ "use strict";

VALID_YIELD_EXPRESSION_POSITION: "YieldExpression is only allowed within a generator function or method",
VALID_AWAIT_EXPRESSION_POSITION: "AwaitExpression is only allowed within an async function or method",
VALID_YIELD_GENERATOR_EXPRESSION_POSITION: "YieldGeneratorExpression is only allowed within a generator function or method",

@@ -54,3 +55,4 @@ VALID_STATIC_MEMBER_EXPRESSION_PROPERTY_NAME: "The property field of StaticMemberExpression must be a valid identifier name",

FUNCTION_DECLARATION_AS_STATEMENT: "Function declarations may not be the body of a WithStatement or loop",
PROPER_DECLARATION_AS_STATEMENT: "Class, generator function, and let/const declarations may not be the consequent or alternate of an IfStatement or the body of a LabeledStatement, WithStatement, or loop"
PROPER_DECLARATION_AS_STATEMENT: "Class, generator function, and let/const declarations may not be the consequent or alternate of an IfStatement or the body of a LabeledStatement, WithStatement, or loop",
ASYNC_GENERATOR_FUNCTION: "Async functions cannot be generators"
};
{
"name": "shift-validator",
"version": "3.0.0",
"version": "4.0.0",
"description": "validator for the Shift AST format",
"author": "Shape Security Labs",
"author": "Shape Security",
"homepage": "https://github.com/shapesecurity/shift-validator-js",

@@ -22,4 +22,5 @@ "repository": {

"esutils": "2.0.2",
"shift-parser": "^5.0.0",
"shift-reducer": "^4.0.0"
"shift-parser": "6.0.0",
"shift-reducer": "5.0.0",
"shift-regexp-acceptor": "1.0.1"
},

@@ -31,4 +32,4 @@ "devDependencies": {

"everything.js": "1.0.3",
"mocha": "^2.3.4",
"shift-ast": "^4.0.0"
"mocha": "2.3.4",
"shift-ast": "5.0.0"
},

@@ -35,0 +36,0 @@ "keywords": [

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