shift-validator
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -104,5 +104,4 @@ "use strict"; | ||
function isValidIdentifierName(name) { | ||
return name === 'let' || name == 'yield' || isIdentifierNameES6(name) && !isReservedWordES6(name); | ||
//return name.length > 0 && isIdentifierStart(name.charCodeAt(0)) && Array.prototype.every.call(name, c => isIdentifierPart(c.charCodeAt(0))); | ||
function isValidIdentifier(name) { | ||
return name === 'let' || name === 'yield' || name === 'enum' || isIdentifierNameES6(name) && !isReservedWordES6(name); | ||
if (name.length === 0) { | ||
@@ -119,2 +118,8 @@ return false; | ||
function isValidIdentifierName(name) { | ||
return name.length > 0 && isIdentifierStart(name.charCodeAt(0)) && Array.prototype.every.call(name, function (c) { | ||
return isIdentifierPart(c.charCodeAt(0)); | ||
}); | ||
} | ||
function isValidStaticPropertyName(name) { | ||
@@ -128,6 +133,2 @@ return isIdentifierNameES6(name); | ||
function isMemberExpression(binding) { | ||
return binding.type == 'ComputedMemberExpression' || binding.type == 'StaticMemberExpression'; | ||
} | ||
function isTemplateElement(rawValue) { | ||
@@ -164,2 +165,16 @@ try { | ||
function checkIllegalBody(node, s) { | ||
var _ref = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var _ref$allowFunctions = _ref.allowFunctions; | ||
var allowFunctions = _ref$allowFunctions === undefined ? false : _ref$allowFunctions; | ||
if (node.body.type === 'FunctionDeclaration' && !allowFunctions) { | ||
return s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.FUNCTION_DECLARATION_AS_STATEMENT)); | ||
} else if (node.body.type === 'ClassDeclaration' || node.body.type === 'FunctionDeclaration' && node.body.isGenerator || node.body.type === 'VariableDeclarationStatement' && (node.body.declaration.kind === 'let' || node.body.declaration.kind === 'const')) { | ||
return s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.PROPER_DECLARATION_AS_STATEMENT)); | ||
} | ||
return s; | ||
} | ||
var Validator = exports.Validator = function (_MonoidalReducer) { | ||
@@ -175,6 +190,24 @@ _inherits(Validator, _MonoidalReducer); | ||
_createClass(Validator, [{ | ||
key: "reduceArrowExpression", | ||
value: function reduceArrowExpression(node, _ref2) { | ||
var params = _ref2.params; | ||
var body = _ref2.body; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceArrowExpression", this).call(this, node, { params: params, body: body.enforceYields() }); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceAssignmentTargetIdentifier", | ||
value: function reduceAssignmentTargetIdentifier(node) { | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceAssignmentTargetIdentifier", this).call(this, node); | ||
if (!isValidIdentifier(node.name)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_BINDING_IDENTIFIER_NAME)); | ||
} | ||
return s; | ||
} | ||
}, { | ||
key: "reduceBindingIdentifier", | ||
value: function reduceBindingIdentifier(node) { | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceBindingIdentifier", this).call(this, node); | ||
if (!isValidIdentifierName(node.name)) { | ||
if (!isValidIdentifier(node.name)) { | ||
if (node.name == "*default*") { | ||
@@ -192,3 +225,3 @@ s = s.addBindingIdentifierCalledDefault(node); | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceBreakStatement", this).call(this, node); | ||
if (node.label !== null && !isValidIdentifierName(node.label)) { | ||
if (node.label !== null && !isValidIdentifier(node.label)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_BREAK_STATEMENT_LABEL)); | ||
@@ -199,18 +232,6 @@ } | ||
}, { | ||
key: "reduceCatchClause", | ||
value: function reduceCatchClause(node, _ref) { | ||
var binding = _ref.binding; | ||
var body = _ref.body; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceCatchClause", this).call(this, node, { binding: binding, body: body }); | ||
if (isMemberExpression(node.binding)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.CATCH_CLAUSE_BINDING_NOT_MEMBER_EXPRESSION)); | ||
} | ||
return s; | ||
} | ||
}, { | ||
key: "reduceContinueStatement", | ||
value: function reduceContinueStatement(node) { | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceContinueStatement", this).call(this, node); | ||
if (node.label !== null && !isValidIdentifierName(node.label)) { | ||
if (node.label !== null && !isValidIdentifier(node.label)) { | ||
s = s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_CONTINUE_STATEMENT_LABEL)); | ||
@@ -221,2 +242,12 @@ } | ||
}, { | ||
key: "reduceDoWhileStatement", | ||
value: function reduceDoWhileStatement(node, _ref3) { | ||
var body = _ref3.body; | ||
var test = _ref3.test; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceDoWhileStatement", this).call(this, node, { body: body, test: test }); | ||
s = checkIllegalBody(node, s); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceDirective", | ||
@@ -232,4 +263,4 @@ value: function reduceDirective(node) { | ||
key: "reduceExportDefault", | ||
value: function reduceExportDefault(node, _ref2) { | ||
var body = _ref2.body; | ||
value: function reduceExportDefault(node, _ref4) { | ||
var body = _ref4.body; | ||
@@ -243,9 +274,9 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceExportDefault", this).call(this, node, { body: body }); | ||
}, { | ||
key: "reduceExportSpecifier", | ||
value: function reduceExportSpecifier(node) { | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceExportSpecifier", this).call(this, node); | ||
if (node.name !== null && !isValidIdentifierName(node.name)) { | ||
key: "reduceExportFromSpecifier", | ||
value: function reduceExportFromSpecifier(node) { | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceExportFromSpecifier", this).call(this, node); | ||
if (!isValidIdentifierName(node.name)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_EXPORT_SPECIFIER_NAME)); | ||
} | ||
if (!isIdentifierNameES6(node.exportedName)) { | ||
if (node.exportedName !== null && !isValidIdentifierName(node.exportedName)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_EXPORTED_NAME)); | ||
@@ -256,7 +287,18 @@ } | ||
}, { | ||
key: "reduceExportLocalSpecifier", | ||
value: function reduceExportLocalSpecifier(node, _ref5) { | ||
var name = _ref5.name; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceExportLocalSpecifier", this).call(this, node, { name: name }); | ||
if (node.exportedName !== null && !isIdentifierNameES6(node.exportedName)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_EXPORTED_NAME)); | ||
} | ||
return s; | ||
} | ||
}, { | ||
key: "reduceForInStatement", | ||
value: function reduceForInStatement(node, _ref3) { | ||
var left = _ref3.left; | ||
var right = _ref3.right; | ||
var body = _ref3.body; | ||
value: function reduceForInStatement(node, _ref6) { | ||
var left = _ref6.left; | ||
var right = _ref6.right; | ||
var body = _ref6.body; | ||
@@ -272,2 +314,3 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceForInStatement", this).call(this, node, { left: left, right: right, body: body }); | ||
} | ||
s = checkIllegalBody(node, s); | ||
return s; | ||
@@ -277,6 +320,6 @@ } | ||
key: "reduceForOfStatement", | ||
value: function reduceForOfStatement(node, _ref4) { | ||
var left = _ref4.left; | ||
var right = _ref4.right; | ||
var body = _ref4.body; | ||
value: function reduceForOfStatement(node, _ref7) { | ||
var left = _ref7.left; | ||
var right = _ref7.right; | ||
var body = _ref7.body; | ||
@@ -292,20 +335,25 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceForOfStatement", this).call(this, node, { left: left, right: right, body: body }); | ||
} | ||
s = checkIllegalBody(node, s); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceForStatement", | ||
value: function reduceForStatement(node, _ref8) { | ||
var init = _ref8.init; | ||
var update = _ref8.update; | ||
var test = _ref8.test; | ||
var body = _ref8.body; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceForStatement", this).call(this, node, { init: init, update: update, test: test, body: body }); | ||
s = checkIllegalBody(node, s); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceFormalParameters", | ||
value: function reduceFormalParameters(node, _ref5) { | ||
var items = _ref5.items; | ||
var rest = _ref5.rest; | ||
value: function reduceFormalParameters(node, _ref9) { | ||
var items = _ref9.items; | ||
var rest = _ref9.rest; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceFormalParameters", this).call(this, node, { items: items, rest: rest }); | ||
node.items.forEach(function (x) { | ||
if (isMemberExpression(x)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.FORMAL_PARAMETER_ITEMS_NOT_MEMBER_EXPRESSION)); | ||
} else if (x.type === 'BindingWithDefault') { | ||
if (isMemberExpression(x.binding)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.FORMAL_PARAMETER_ITEMS_BINDING_NOT_MEMBER_EXPRESSION)); | ||
} | ||
} | ||
}); | ||
s = s.enforceYields(); | ||
return s; | ||
@@ -315,5 +363,5 @@ } | ||
key: "reduceFunctionBody", | ||
value: function reduceFunctionBody(node, _ref6) { | ||
var directives = _ref6.directives; | ||
var statements = _ref6.statements; | ||
value: function reduceFunctionBody(node, _ref10) { | ||
var directives = _ref10.directives; | ||
var statements = _ref10.statements; | ||
@@ -326,12 +374,9 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceFunctionBody", this).call(this, node, { directives: directives, statements: statements }); | ||
key: "reduceFunctionDeclaration", | ||
value: function reduceFunctionDeclaration(node, _ref7) { | ||
var name = _ref7.name; | ||
var params = _ref7.params; | ||
var body = _ref7.body; | ||
value: function reduceFunctionDeclaration(node, _ref11) { | ||
var name = _ref11.name; | ||
var params = _ref11.params; | ||
var 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 }); | ||
if (node.isGenerator) { | ||
s = s.clearYieldExpressionsNotInGeneratorContext(); | ||
s = s.clearYieldGeneratorExpressionsNotInGeneratorContext(); | ||
} | ||
return s; | ||
@@ -341,19 +386,25 @@ } | ||
key: "reduceFunctionExpression", | ||
value: function reduceFunctionExpression(node, _ref8) { | ||
var name = _ref8.name; | ||
var params = _ref8.params; | ||
var body = _ref8.body; | ||
value: function reduceFunctionExpression(node, _ref12) { | ||
var name = _ref12.name; | ||
var params = _ref12.params; | ||
var 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 }); | ||
if (node.isGenerator) { | ||
s = s.clearYieldExpressionsNotInGeneratorContext(); | ||
s = s.clearYieldGeneratorExpressionsNotInGeneratorContext(); | ||
} | ||
return s; | ||
} | ||
}, { | ||
key: "reduceGetter", | ||
value: function reduceGetter(node, _ref13) { | ||
var name = _ref13.name; | ||
var body = _ref13.body; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceGetter", this).call(this, node, { name: name, body: body.enforceYields() }); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceIdentifierExpression", | ||
value: function reduceIdentifierExpression(node) { | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceIdentifierExpression", this).call(this, node); | ||
if (!isValidIdentifierName(node.name)) { | ||
if (!isValidIdentifier(node.name)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_IDENTIFIER_NAME)); | ||
@@ -365,6 +416,6 @@ } | ||
key: "reduceIfStatement", | ||
value: function reduceIfStatement(node, _ref9) { | ||
var test = _ref9.test; | ||
var consequent = _ref9.consequent; | ||
var alternate = _ref9.alternate; | ||
value: function reduceIfStatement(node, _ref14) { | ||
var test = _ref14.test; | ||
var consequent = _ref14.consequent; | ||
var alternate = _ref14.alternate; | ||
@@ -375,2 +426,8 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceIfStatement", this).call(this, node, { test: test, consequent: consequent, alternate: alternate }); | ||
} | ||
if (node.consequent.type === 'ClassDeclaration' || node.consequent.type === 'FunctionDeclaration' && node.consequent.isGenerator || node.consequent.type === 'VariableDeclarationStatement' && (node.consequent.declaration.kind === 'let' || node.consequent.declaration.kind === 'const')) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.PROPER_DECLARATION_AS_STATEMENT)); | ||
} | ||
if (node.alternate && (node.alternate.type === 'ClassDeclaration' || node.alternate.type === 'FunctionDeclaration' && node.alternate.isGenerator || node.alternate.type === 'VariableDeclarationStatement' && (node.alternate.declaration.kind === 'let' || node.alternate.declaration.kind === 'const'))) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.PROPER_DECLARATION_AS_STATEMENT)); | ||
} | ||
return s; | ||
@@ -380,4 +437,4 @@ } | ||
key: "reduceImportSpecifier", | ||
value: function reduceImportSpecifier(node, _ref10) { | ||
var binding = _ref10.binding; | ||
value: function reduceImportSpecifier(node, _ref15) { | ||
var binding = _ref15.binding; | ||
@@ -392,9 +449,10 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceImportSpecifier", this).call(this, node, { binding: binding }); | ||
key: "reduceLabeledStatement", | ||
value: function reduceLabeledStatement(node, _ref11) { | ||
var body = _ref11.body; | ||
value: function reduceLabeledStatement(node, _ref16) { | ||
var body = _ref16.body; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceLabeledStatement", this).call(this, node, { body: body }); | ||
if (!isValidIdentifierName(node.label)) { | ||
if (!isValidIdentifier(node.label)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_LABEL)); | ||
} | ||
s = checkIllegalBody(node, s, { allowFunctions: true }); | ||
return s; | ||
@@ -429,12 +487,9 @@ } | ||
key: "reduceMethod", | ||
value: function reduceMethod(node, _ref12) { | ||
var params = _ref12.params; | ||
var body = _ref12.body; | ||
var name = _ref12.name; | ||
value: function reduceMethod(node, _ref17) { | ||
var params = _ref17.params; | ||
var body = _ref17.body; | ||
var 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 }); | ||
if (node.isGenerator) { | ||
s = s.clearYieldExpressionsNotInGeneratorContext(); | ||
s = s.clearYieldGeneratorExpressionsNotInGeneratorContext(); | ||
} | ||
return s; | ||
@@ -444,5 +499,5 @@ } | ||
key: "reduceModule", | ||
value: function reduceModule(node, _ref13) { | ||
var directives = _ref13.directives; | ||
var items = _ref13.items; | ||
value: function reduceModule(node, _ref18) { | ||
var directives = _ref18.directives; | ||
var items = _ref18.items; | ||
@@ -452,5 +507,3 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceModule", this).call(this, node, { directives: directives, items: items }); | ||
s = s.enforceBindingIdentifiersCalledDefault(); | ||
s = s.enforceYieldExpressionsNotInGeneratorContext(); | ||
s = s.enforceYieldGeneratorExpressionsNotInGeneratorContext(); | ||
// s.errors.forEach(console.log.bind(console)) | ||
s = s.enforceYields(); | ||
return s; | ||
@@ -460,4 +513,4 @@ } | ||
key: "reduceReturnStatement", | ||
value: function reduceReturnStatement(node, _ref14) { | ||
var expression = _ref14.expression; | ||
value: function reduceReturnStatement(node, _ref19) { | ||
var expression = _ref19.expression; | ||
@@ -470,5 +523,5 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceReturnStatement", this).call(this, node, { expression: expression }); | ||
key: "reduceScript", | ||
value: function reduceScript(node, _ref15) { | ||
var directives = _ref15.directives; | ||
var statements = _ref15.statements; | ||
value: function reduceScript(node, _ref20) { | ||
var directives = _ref20.directives; | ||
var statements = _ref20.statements; | ||
@@ -478,5 +531,3 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceScript", this).call(this, node, { directives: directives, statements: statements }); | ||
s = s.enforceBindingIdentifiersCalledDefault(); | ||
s = s.enforceYieldExpressionsNotInGeneratorContext(); | ||
s = s.enforceYieldGeneratorExpressionsNotInGeneratorContext(); | ||
// s.errors.forEach(console.log.bind(console)) | ||
s = s.enforceYields(); | ||
return s; | ||
@@ -486,30 +537,14 @@ } | ||
key: "reduceSetter", | ||
value: function reduceSetter(node, _ref16) { | ||
var name = _ref16.name; | ||
var param = _ref16.param; | ||
var body = _ref16.body; | ||
value: function reduceSetter(node, _ref21) { | ||
var name = _ref21.name; | ||
var param = _ref21.param; | ||
var body = _ref21.body; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceSetter", this).call(this, node, { name: name, param: param, body: body }); | ||
if (isMemberExpression(node.param)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.SETTER_PARAM_NOT_MEMBER_EXPRESSION)); | ||
} else if (node.param.type === 'BindingWithDefault') { | ||
if (isMemberExpression(node.param).binding) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.SETTER_PARAM_BINDING_NOT_MEMBER_EXPRESSION)); | ||
} | ||
} | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceSetter", this).call(this, node, { name: name, param: param, body: body.enforceYields() }); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceShorthandProperty", | ||
value: function reduceShorthandProperty(node) { | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceShorthandProperty", this).call(this, node); | ||
if (!isValidIdentifierName(node.name)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VALID_SHORTHAND_PROPERTY_NAME)); | ||
} | ||
return s; | ||
} | ||
}, { | ||
key: "reduceStaticMemberExpression", | ||
value: function reduceStaticMemberExpression(node, _ref17) { | ||
var object = _ref17.object; | ||
value: function reduceStaticMemberExpression(node, _ref22) { | ||
var object = _ref22.object; | ||
@@ -533,5 +568,5 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceStaticMemberExpression", this).call(this, node, { object: object }); | ||
key: "reduceTemplateExpression", | ||
value: function reduceTemplateExpression(node, _ref18) { | ||
var tag = _ref18.tag; | ||
var elements = _ref18.elements; | ||
value: function reduceTemplateExpression(node, _ref23) { | ||
var tag = _ref23.tag; | ||
var elements = _ref23.elements; | ||
@@ -560,4 +595,4 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceTemplateExpression", this).call(this, node, { tag: tag, elements: elements }); | ||
key: "reduceVariableDeclaration", | ||
value: function reduceVariableDeclaration(node, _ref19) { | ||
var declarators = _ref19.declarators; | ||
value: function reduceVariableDeclaration(node, _ref24) { | ||
var declarators = _ref24.declarators; | ||
@@ -571,26 +606,19 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceVariableDeclaration", this).call(this, node, { declarators: declarators }); | ||
}, { | ||
key: "reduceVariableDeclarationStatement", | ||
value: function reduceVariableDeclarationStatement(node, _ref20) { | ||
var declaration = _ref20.declaration; | ||
key: "reduceWhileStatement", | ||
value: function reduceWhileStatement(node, _ref25) { | ||
var test = _ref25.test; | ||
var body = _ref25.body; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceVariableDeclarationStatement", this).call(this, node, { declaration: declaration }); | ||
if (node.declaration.kind === 'const') { | ||
node.declaration.declarators.forEach(function (x) { | ||
if (x.init === null) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.CONST_VARIABLE_DECLARATION_MUST_HAVE_INIT)); | ||
} | ||
}); | ||
} | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceWhileStatement", this).call(this, node, { test: test, body: body }); | ||
s = checkIllegalBody(node, s); | ||
return s; | ||
} | ||
}, { | ||
key: "reduceVariableDeclarator", | ||
value: function reduceVariableDeclarator(node, _ref21) { | ||
var binding = _ref21.binding; | ||
var init = _ref21.init; | ||
key: "reduceWithStatement", | ||
value: function reduceWithStatement(node, _ref26) { | ||
var object = _ref26.object; | ||
var body = _ref26.body; | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceVariableDeclarator", this).call(this, node, { binding: binding, init: init }); | ||
if (isMemberExpression(node.binding)) { | ||
s = s.addError(new _validationContext.ValidationError(node, _validationErrors2.default.VARIABLE_DECLARATION_BINDING_NOT_MEMBER_EXPRESSION)); | ||
} | ||
var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceWithStatement", this).call(this, node, { object: object, body: body }); | ||
s = checkIllegalBody(node, s); | ||
return s; | ||
@@ -600,4 +628,4 @@ } | ||
key: "reduceYieldExpression", | ||
value: function reduceYieldExpression(node, _ref22) { | ||
var expression = _ref22.expression; | ||
value: function reduceYieldExpression(node, _ref27) { | ||
var expression = _ref27.expression; | ||
@@ -610,4 +638,4 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceYieldExpression", this).call(this, node, { expression: expression }); | ||
key: "reduceYieldGeneratorExpression", | ||
value: function reduceYieldGeneratorExpression(node, _ref23) { | ||
var expression = _ref23.expression; | ||
value: function reduceYieldGeneratorExpression(node, _ref28) { | ||
var expression = _ref28.expression; | ||
@@ -621,3 +649,3 @@ var s = _get(Object.getPrototypeOf(Validator.prototype), "reduceYieldGeneratorExpression", this).call(this, node, { expression: expression }); | ||
value: function validate(node) { | ||
return (0, _shiftReducer2.default)(new Validator(), node).errors; | ||
return (0, _shiftReducer2.default)(new Validator(), node).errors.concat(_shiftParser.EarlyErrorChecker.check(node)); | ||
} | ||
@@ -624,0 +652,0 @@ }]); |
@@ -182,2 +182,12 @@ "use strict"; | ||
} | ||
}, { | ||
key: "enforceYields", | ||
value: function enforceYields() { | ||
return this.enforceYieldExpressionsNotInGeneratorContext().enforceYieldGeneratorExpressionsNotInGeneratorContext(); | ||
} | ||
}, { | ||
key: "clearYields", | ||
value: function clearYields() { | ||
return this.clearYieldExpressionsNotInGeneratorContext().clearYieldGeneratorExpressionsNotInGeneratorContext(); | ||
} | ||
}], [{ | ||
@@ -184,0 +194,0 @@ key: "empty", |
@@ -25,3 +25,2 @@ "use strict"; | ||
VALID_BREAK_STATEMENT_LABEL: "The label field of BreakStatement exists and must be a valid identifier name", | ||
CATCH_CLAUSE_BINDING_NOT_MEMBER_EXPRESSION: "The binding field of CatchClause must not be a MemberExpression", | ||
VALID_CONTINUE_STATEMENT_LABEL: "The label field of ContinueStatement exists and must be a valid identifier name", | ||
@@ -35,4 +34,2 @@ VALID_DIRECTIVE: "The raw value field of Directive must either be an empty string, or match the ES6 grammar production DoubleStringCharacter or SingleStringCharacter", | ||
NO_INIT_IN_VARIABLE_DECLARATOR_IN_FOR_OF: "The VariableDeclarator in ForOfStatement should not have an initializer", | ||
FORMAL_PARAMETER_ITEMS_NOT_MEMBER_EXPRESSION: "The items field of FormalParameters must not be a MemberExpression", | ||
FORMAL_PARAMETER_ITEMS_BINDING_NOT_MEMBER_EXPRESSION: "binding field of the items field of FormalParameters must not be a MemberExpression", | ||
VALID_IDENTIFIER_NAME: "The name field of IdentifierExpression must be a valid identifier name", | ||
@@ -52,5 +49,2 @@ VALID_IF_STATEMENT: "IfStatement with null 'alternate' must not be the 'consequent' of an IfStatement with a non-null 'alternate'", | ||
VALID_YIELD_GENERATOR_EXPRESSION_POSITION: "YieldGeneratorExpression is only allowed within a generator function or method", | ||
SETTER_PARAM_NOT_MEMBER_EXPRESSION: "The param field of Setter must not be a MemberExpression", | ||
SETTER_PARAM_BINDING_NOT_MEMBER_EXPRESSION: "The binding field of the param field of Setter must not be a MemberExpression", | ||
VALID_SHORTHAND_PROPERTY_NAME: "The name field of ShorthandProperty must be a valid identifier name", | ||
VALID_STATIC_MEMBER_EXPRESSION_PROPERTY_NAME: "The property field of StaticMemberExpression must be a valid identifier name", | ||
@@ -60,4 +54,5 @@ VALID_TEMPLATE_ELEMENT_VALUE: "The raw value field of TemplateElement must match the ES6 grammar production TemplateCharacters", | ||
NOT_EMPTY_VARIABLE_DECLARATORS_LIST: "The declarators field in VariableDeclaration must not be an empty list", | ||
CONST_VARIABLE_DECLARATION_MUST_HAVE_INIT: "VariableDeclarationStatements with a VariableDeclaration of kind CONST cannot have a VariableDeclarator with no initializer", | ||
VARIABLE_DECLARATION_BINDING_NOT_MEMBER_EXPRESSION: "The binding field of VariableDeclarator must not be a MemberExpression" | ||
CONST_VARIABLE_DECLARATION_MUST_HAVE_INIT: "VariableDeclarationStatements with a VariableDeclaration of kind const cannot have a VariableDeclarator with no initializer", | ||
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" | ||
}; |
{ | ||
"name": "shift-validator", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "validator for the Shift AST format", | ||
@@ -22,4 +22,4 @@ "author": "Shape Security Labs", | ||
"esutils": "2.0.2", | ||
"shift-parser": "4.1.3", | ||
"shift-reducer": "3.0.3" | ||
"shift-parser": "^5.0.0", | ||
"shift-reducer": "^4.0.0" | ||
}, | ||
@@ -32,3 +32,3 @@ "devDependencies": { | ||
"mocha": "^2.3.4", | ||
"shift-ast": "3.1.0" | ||
"shift-ast": "^4.0.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
814
0
68106
5
2
0
+ Addedshift-ast@4.0.0(transitive)
+ Addedshift-parser@5.2.4(transitive)
+ Addedshift-reducer@4.4.1(transitive)
- Removedshift-parser@4.1.3(transitive)
- Removedshift-reducer@3.0.3(transitive)
- Removedshift-spec@2015.2.1(transitive)
Updatedshift-parser@^5.0.0
Updatedshift-reducer@^4.0.0