@babel/types
Advanced tools
Comparing version 7.5.0 to 7.5.5
@@ -20,3 +20,3 @@ "use strict"; | ||
left: { | ||
validate: (0, _utils.assertNodeType)("Identifier", "ObjectPattern", "ArrayPattern") | ||
validate: (0, _utils.assertNodeType)("Identifier", "ObjectPattern", "ArrayPattern", "MemberExpression") | ||
}, | ||
@@ -359,3 +359,13 @@ right: { | ||
fields: { | ||
value: {}, | ||
value: { | ||
validate: (0, _utils.assertShape)({ | ||
raw: { | ||
validate: (0, _utils.assertValueType)("string") | ||
}, | ||
cooked: { | ||
validate: (0, _utils.assertValueType)("string"), | ||
optional: true | ||
} | ||
}) | ||
}, | ||
tail: { | ||
@@ -362,0 +372,0 @@ validate: (0, _utils.assertValueType)("boolean"), |
@@ -19,2 +19,3 @@ "use strict"; | ||
exports.assertValueType = assertValueType; | ||
exports.assertShape = assertShape; | ||
exports.chain = chain; | ||
@@ -26,2 +27,4 @@ exports.default = defineType; | ||
var _validate = require("../validators/validate"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -171,2 +174,28 @@ | ||
function assertShape(shape) { | ||
function validate(node, key, val) { | ||
const errors = []; | ||
for (const property of Object.keys(shape)) { | ||
try { | ||
(0, _validate.validateField)(node, property, val[property], shape[property]); | ||
} catch (error) { | ||
if (error instanceof TypeError) { | ||
errors.push(error.message); | ||
continue; | ||
} | ||
throw error; | ||
} | ||
} | ||
if (errors.length) { | ||
throw new TypeError(`Property ${key} of ${node.type} expected to have the following:\n${errors.join("\n")}`); | ||
} | ||
} | ||
validate.shapeOf = shape; | ||
return validate; | ||
} | ||
function chain(...fns) { | ||
@@ -173,0 +202,0 @@ function validate(...args) { |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.default = validate; | ||
exports.validateField = validateField; | ||
@@ -16,2 +17,6 @@ var _definitions = require("../definitions"); | ||
const field = fields[key]; | ||
validateField(node, key, val, field); | ||
} | ||
function validateField(node, key, val, field) { | ||
if (!field || !field.validate) return; | ||
@@ -18,0 +23,0 @@ if (field.optional && val == null) return; |
{ | ||
"name": "@babel/types", | ||
"version": "7.5.0", | ||
"version": "7.5.5", | ||
"description": "Babel Types is a Lodash-esque utility library for AST nodes", | ||
@@ -13,10 +13,10 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"esutils": "^2.0.2", | ||
"lodash": "^4.17.11", | ||
"lodash": "^4.17.13", | ||
"to-fast-properties": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/generator": "^7.5.0", | ||
"@babel/parser": "^7.5.0" | ||
"@babel/generator": "^7.5.5", | ||
"@babel/parser": "^7.5.5" | ||
}, | ||
"gitHead": "49da9a07c81156e997e60146eb001ea77b7044c4" | ||
"gitHead": "0407f034f09381b95e9cabefbf6b176c76485a43" | ||
} |
@@ -34,2 +34,25 @@ module.exports = function stringifyValidator(validator, nodePrefix) { | ||
if (validator.shapeOf) { | ||
return ( | ||
"{ " + | ||
Object.keys(validator.shapeOf) | ||
.map(shapeKey => { | ||
const propertyDefinition = validator.shapeOf[shapeKey]; | ||
if (propertyDefinition.validate) { | ||
const isOptional = | ||
propertyDefinition.optional || propertyDefinition.default != null; | ||
return ( | ||
shapeKey + | ||
(isOptional ? "?: " : ": ") + | ||
stringifyValidator(propertyDefinition.validate) | ||
); | ||
} | ||
return null; | ||
}) | ||
.filter(Boolean) | ||
.join(", ") + | ||
" }" | ||
); | ||
} | ||
return ["any"]; | ||
@@ -36,0 +59,0 @@ }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
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
610869
12677
Updatedlodash@^4.17.13