@babel/types
Advanced tools
Comparing version
@@ -583,2 +583,5 @@ "use strict"; | ||
} | ||
function assertImportAttribute(node, opts) { | ||
assert("ImportAttribute", node, opts); | ||
} | ||
function assertAnyTypeAnnotation(node, opts) { | ||
@@ -839,5 +842,2 @@ assert("AnyTypeAnnotation", node, opts); | ||
} | ||
function assertImportAttribute(node, opts) { | ||
assert("ImportAttribute", node, opts); | ||
} | ||
function assertDecorator(node, opts) { | ||
@@ -844,0 +844,0 @@ assert("Decorator", node, opts); |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.UPDATE_OPERATORS = exports.UNARY_OPERATORS = exports.STRING_UNARY_OPERATORS = exports.STATEMENT_OR_BLOCK_KEYS = exports.NUMBER_UNARY_OPERATORS = exports.NUMBER_BINARY_OPERATORS = exports.NOT_LOCAL_BINDING = exports.LOGICAL_OPERATORS = exports.INHERIT_KEYS = exports.FOR_INIT_KEYS = exports.FLATTENABLE_KEYS = exports.EQUALITY_BINARY_OPERATORS = exports.COMPARISON_BINARY_OPERATORS = exports.COMMENT_KEYS = exports.BOOLEAN_UNARY_OPERATORS = exports.BOOLEAN_NUMBER_BINARY_OPERATORS = exports.BOOLEAN_BINARY_OPERATORS = exports.BLOCK_SCOPED_SYMBOL = exports.BINARY_OPERATORS = exports.ASSIGNMENT_OPERATORS = void 0; | ||
exports.UPDATE_OPERATORS = exports.UNARY_OPERATORS = exports.STRING_UNARY_OPERATORS = exports.STATEMENT_OR_BLOCK_KEYS = exports.NUMBER_UNARY_OPERATORS = exports.NUMBER_BINARY_OPERATORS = exports.LOGICAL_OPERATORS = exports.INHERIT_KEYS = exports.FOR_INIT_KEYS = exports.FLATTENABLE_KEYS = exports.EQUALITY_BINARY_OPERATORS = exports.COMPARISON_BINARY_OPERATORS = exports.COMMENT_KEYS = exports.BOOLEAN_UNARY_OPERATORS = exports.BOOLEAN_NUMBER_BINARY_OPERATORS = exports.BOOLEAN_BINARY_OPERATORS = exports.BINARY_OPERATORS = exports.ASSIGNMENT_OPERATORS = void 0; | ||
const STATEMENT_OR_BLOCK_KEYS = exports.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"]; | ||
@@ -29,5 +29,7 @@ const FLATTENABLE_KEYS = exports.FLATTENABLE_KEYS = ["body", "expressions"]; | ||
}; | ||
const BLOCK_SCOPED_SYMBOL = exports.BLOCK_SCOPED_SYMBOL = Symbol.for("var used to be block scoped"); | ||
const NOT_LOCAL_BINDING = exports.NOT_LOCAL_BINDING = Symbol.for("should not be considered a local binding"); | ||
{ | ||
exports.BLOCK_SCOPED_SYMBOL = Symbol.for("var used to be block scoped"); | ||
exports.NOT_LOCAL_BINDING = Symbol.for("should not be considered a local binding"); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -52,2 +52,5 @@ "use strict"; | ||
} | ||
if (typeof value === "bigint") { | ||
return (0, _index.bigIntLiteral)(value.toString()); | ||
} | ||
if (isRegExp(value)) { | ||
@@ -64,9 +67,15 @@ const pattern = value.source; | ||
for (const key of Object.keys(value)) { | ||
let nodeKey; | ||
let nodeKey, | ||
computed = false; | ||
if ((0, _isValidIdentifier.default)(key)) { | ||
nodeKey = (0, _index.identifier)(key); | ||
if (key === "__proto__") { | ||
computed = true; | ||
nodeKey = (0, _index.stringLiteral)(key); | ||
} else { | ||
nodeKey = (0, _index.identifier)(key); | ||
} | ||
} else { | ||
nodeKey = (0, _index.stringLiteral)(key); | ||
} | ||
props.push((0, _index.objectProperty)(nodeKey, valueToNode(value[key]))); | ||
props.push((0, _index.objectProperty)(nodeKey, valueToNode(value[key]), computed)); | ||
} | ||
@@ -73,0 +82,0 @@ return (0, _index.objectExpression)(props); |
@@ -377,3 +377,3 @@ "use strict"; | ||
validate: process.env.BABEL_TYPES_8_BREAKING ? function (parent, key, node) { | ||
const match = /\.(\w+)$/.exec(key); | ||
const match = /\.(\w+)$/.exec(key.toString()); | ||
if (!match) return; | ||
@@ -667,3 +667,3 @@ const [, parentKey] = match; | ||
validate: process.env.BABEL_TYPES_8_BREAKING ? function (parent, key) { | ||
const match = /(\w+)\[(\d+)\]/.exec(key); | ||
const match = /(\w+)\[(\d+)\]/.exec(key.toString()); | ||
if (!match) throw new Error("Internal Babel error: malformed key."); | ||
@@ -1640,3 +1640,14 @@ const [, listKey, index] = match; | ||
}); | ||
defineType("ImportAttribute", { | ||
visitor: ["key", "value"], | ||
fields: { | ||
key: { | ||
validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral") | ||
}, | ||
value: { | ||
validate: (0, _utils.assertNodeType)("StringLiteral") | ||
} | ||
} | ||
}); | ||
//# sourceMappingURL=core.js.map |
@@ -28,13 +28,2 @@ "use strict"; | ||
}); | ||
(0, _utils.default)("ImportAttribute", { | ||
visitor: ["key", "value"], | ||
fields: { | ||
key: { | ||
validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral") | ||
}, | ||
value: { | ||
validate: (0, _utils.assertNodeType)("StringLiteral") | ||
} | ||
} | ||
}); | ||
(0, _utils.default)("Decorator", { | ||
@@ -41,0 +30,0 @@ visitor: ["expression"], |
@@ -85,4 +85,17 @@ "use strict"; | ||
}); | ||
for (const { | ||
types, | ||
set | ||
} of _utils.allExpandedTypes) { | ||
for (const type of types) { | ||
const aliases = _utils.FLIPPED_ALIAS_KEYS[type]; | ||
if (aliases) { | ||
aliases.forEach(set.add, set); | ||
} else { | ||
set.add(type); | ||
} | ||
} | ||
} | ||
const TYPES = exports.TYPES = [].concat(Object.keys(_utils.VISITOR_KEYS), Object.keys(_utils.FLIPPED_ALIAS_KEYS), Object.keys(_utils.DEPRECATED_KEYS)); | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.VISITOR_KEYS = exports.NODE_PARENT_VALIDATIONS = exports.NODE_FIELDS = exports.FLIPPED_ALIAS_KEYS = exports.DEPRECATED_KEYS = exports.BUILDER_KEYS = exports.ALIAS_KEYS = void 0; | ||
exports.allExpandedTypes = exports.VISITOR_KEYS = exports.NODE_PARENT_VALIDATIONS = exports.NODE_FIELDS = exports.FLIPPED_ALIAS_KEYS = exports.DEPRECATED_KEYS = exports.BUILDER_KEYS = exports.ALIAS_KEYS = void 0; | ||
exports.arrayOf = arrayOf; | ||
@@ -76,7 +76,12 @@ exports.arrayOfType = arrayOfType; | ||
if (!Array.isArray(val)) return; | ||
for (let i = 0; i < val.length; i++) { | ||
const subkey = `${key}[${i}]`; | ||
let i = 0; | ||
const subKey = { | ||
toString() { | ||
return `${key}[${i}]`; | ||
} | ||
}; | ||
for (; i < val.length; i++) { | ||
const v = val[i]; | ||
callback(node, subkey, v); | ||
childValidator(node, subkey, v); | ||
callback(node, subKey, v); | ||
childValidator(node, subKey, v); | ||
} | ||
@@ -96,11 +101,26 @@ } | ||
} | ||
const allExpandedTypes = exports.allExpandedTypes = []; | ||
function assertNodeType(...types) { | ||
const expandedTypes = new Set(); | ||
allExpandedTypes.push({ | ||
types, | ||
set: expandedTypes | ||
}); | ||
function validate(node, key, val) { | ||
for (const type of types) { | ||
if ((0, _is.default)(type, val)) { | ||
const valType = val == null ? void 0 : val.type; | ||
if (valType != null) { | ||
if (expandedTypes.has(valType)) { | ||
(0, _validate.validateChild)(node, key, val); | ||
return; | ||
} | ||
if (valType === "Placeholder") { | ||
for (const type of types) { | ||
if ((0, _is.default)(type, val)) { | ||
(0, _validate.validateChild)(node, key, val); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val == null ? void 0 : val.type)}`); | ||
throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(valType)}`); | ||
} | ||
@@ -112,4 +132,5 @@ validate.oneOfNodeTypes = types; | ||
function validate(node, key, val) { | ||
const primitiveType = getType(val); | ||
for (const type of types) { | ||
if (getType(val) === type || (0, _is.default)(type, val)) { | ||
if (primitiveType === type || (0, _is.default)(type, val)) { | ||
(0, _validate.validateChild)(node, key, val); | ||
@@ -126,6 +147,6 @@ return; | ||
function validate(node, key, val) { | ||
const valid = getType(val) === type; | ||
if (!valid) { | ||
throw new TypeError(`Property ${key} expected type of ${type} but got ${getType(val)}`); | ||
if (getType(val) === type) { | ||
return; | ||
} | ||
throw new TypeError(`Property ${key} expected type of ${type} but got ${getType(val)}`); | ||
} | ||
@@ -136,5 +157,6 @@ validate.type = type; | ||
function assertShape(shape) { | ||
const keys = Object.keys(shape); | ||
function validate(node, key, val) { | ||
const errors = []; | ||
for (const property of Object.keys(shape)) { | ||
for (const property of keys) { | ||
try { | ||
@@ -141,0 +163,0 @@ (0, _validate.validateField)(node, property, val[property], shape[property]); |
@@ -8,20 +8,34 @@ "use strict"; | ||
var _index = require("../definitions/index.js"); | ||
const _skip = Symbol(); | ||
const _stop = Symbol(); | ||
function traverseFast(node, enter, opts) { | ||
if (!node) return; | ||
if (!node) return false; | ||
const keys = _index.VISITOR_KEYS[node.type]; | ||
if (!keys) return; | ||
if (!keys) return false; | ||
opts = opts || {}; | ||
enter(node, opts); | ||
const ret = enter(node, opts); | ||
if (ret !== undefined) { | ||
switch (ret) { | ||
case _skip: | ||
return false; | ||
case _stop: | ||
return true; | ||
} | ||
} | ||
for (const key of keys) { | ||
const subNode = node[key]; | ||
if (!subNode) continue; | ||
if (Array.isArray(subNode)) { | ||
for (const node of subNode) { | ||
traverseFast(node, enter, opts); | ||
if (traverseFast(node, enter, opts)) return true; | ||
} | ||
} else { | ||
traverseFast(subNode, enter, opts); | ||
if (traverseFast(subNode, enter, opts)) return true; | ||
} | ||
} | ||
return false; | ||
} | ||
traverseFast.skip = _skip; | ||
traverseFast.stop = _stop; | ||
//# sourceMappingURL=traverseFast.js.map |
@@ -8,7 +8,11 @@ "use strict"; | ||
var _index = require("./generated/index.js"); | ||
var _index2 = require("../constants/index.js"); | ||
{ | ||
var BLOCK_SCOPED_SYMBOL = Symbol.for("var used to be block scoped"); | ||
} | ||
function isLet(node) { | ||
return (0, _index.isVariableDeclaration)(node) && (node.kind !== "var" || node[_index2.BLOCK_SCOPED_SYMBOL]); | ||
{ | ||
return (0, _index.isVariableDeclaration)(node) && (node.kind !== "var" || node[BLOCK_SCOPED_SYMBOL]); | ||
} | ||
} | ||
//# sourceMappingURL=isLet.js.map |
@@ -11,7 +11,3 @@ "use strict"; | ||
const aliases = _index.PLACEHOLDERS_ALIAS[placeholderType]; | ||
if (aliases) { | ||
for (const alias of aliases) { | ||
if (targetType === alias) return true; | ||
} | ||
} | ||
if (aliases != null && aliases.includes(targetType)) return true; | ||
return false; | ||
@@ -18,0 +14,0 @@ } |
@@ -13,8 +13,3 @@ "use strict"; | ||
const aliases = _index.FLIPPED_ALIAS_KEYS[targetType]; | ||
if (aliases) { | ||
if (aliases[0] === nodeType) return true; | ||
for (const alias of aliases) { | ||
if (nodeType === alias) return true; | ||
} | ||
} | ||
if (aliases != null && aliases.includes(nodeType)) return true; | ||
return false; | ||
@@ -21,0 +16,0 @@ } |
@@ -8,9 +8,13 @@ "use strict"; | ||
var _index = require("./generated/index.js"); | ||
var _index2 = require("../constants/index.js"); | ||
{ | ||
var BLOCK_SCOPED_SYMBOL = Symbol.for("var used to be block scoped"); | ||
} | ||
function isVar(node) { | ||
return (0, _index.isVariableDeclaration)(node, { | ||
kind: "var" | ||
}) && !node[_index2.BLOCK_SCOPED_SYMBOL]; | ||
{ | ||
return (0, _index.isVariableDeclaration)(node, { | ||
kind: "var" | ||
}) && !node[BLOCK_SCOPED_SYMBOL]; | ||
} | ||
} | ||
//# sourceMappingURL=isVar.js.map |
{ | ||
"name": "@babel/types", | ||
"version": "7.26.10", | ||
"version": "7.27.0", | ||
"description": "Babel Types is a Lodash-esque utility library for AST nodes", | ||
@@ -23,4 +23,4 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"devDependencies": { | ||
"@babel/generator": "^7.26.10", | ||
"@babel/parser": "^7.26.10", | ||
"@babel/generator": "^7.27.0", | ||
"@babel/parser": "^7.27.0", | ||
"glob": "^7.2.0" | ||
@@ -27,0 +27,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2583295
0.24%21452
0.32%