"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isBinding;
var _getBindingIdentifiers = require("../retrievers/getBindingIdentifiers");
function isBinding(node, parent, grandparent) {
if (grandparent && node.type === "Identifier" && parent.type === "ObjectProperty" && grandparent.type === "ObjectExpression") {
return false;
}
const keys = _getBindingIdentifiers.default.keys[parent.type];
if (keys) {
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const val = parent[key];
if (Array.isArray(val)) {
if (val.indexOf(node) >= 0) return true;
} else {
if (val === node) return true;
}
}
}
return false;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isBlockScoped;
var _generated = require("./generated");
var _isLet = require("./isLet");
function isBlockScoped(node) {
return (0, _generated.isFunctionDeclaration)(node) || (0, _generated.isClassDeclaration)(node) || (0, _isLet.default)(node);
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isImmutable;
var _isType = require("./isType");
var _generated = require("./generated");
function isImmutable(node) {
if ((0, _isType.default)(node.type, "Immutable")) return true;
if ((0, _generated.isIdentifier)(node)) {
if (node.name === "undefined") {
return true;
} else {
return false;
}
}
return false;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isLet;
var _generated = require("./generated");
var _constants = require("../constants");
function isLet(node) {
return (0, _generated.isVariableDeclaration)(node) && (node.kind !== "var" || node[_constants.BLOCK_SCOPED_SYMBOL]);
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isNode;
var _definitions = require("../definitions");
function isNode(node) {
return !!(node && _definitions.VISITOR_KEYS[node.type]);
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isNodesEquivalent;
var _definitions = require("../definitions");
function isNodesEquivalent(a, b) {
if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) {
return a === b;
}
if (a.type !== b.type) {
return false;
}
const fields = Object.keys(_definitions.NODE_FIELDS[a.type] || a.type);
const visitorKeys = _definitions.VISITOR_KEYS[a.type];
for (const field of fields) {
const val_a = a[field];
const val_b = b[field];
if (typeof val_a !== typeof val_b) {
return false;
}
if (val_a == null && val_b == null) {
continue;
} else if (val_a == null || val_b == null) {
return false;
}
if (Array.isArray(val_a)) {
if (!Array.isArray(val_b)) {
return false;
}
if (val_a.length !== val_b.length) {
return false;
}
for (let i = 0; i < val_a.length; i++) {
if (!isNodesEquivalent(val_a[i], val_b[i])) {
return false;
}
}
continue;
}
if (typeof val_a === "object" && !(visitorKeys != null && visitorKeys.includes(field))) {
for (const key of Object.keys(val_a)) {
if (val_a[key] !== val_b[key]) {
return false;
}
}
continue;
}
if (!isNodesEquivalent(val_a, val_b)) {
return false;
}
}
return true;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isPlaceholderType;
var _definitions = require("../definitions");
function isPlaceholderType(placeholderType, targetType) {
if (placeholderType === targetType) return true;
const aliases = _definitions.PLACEHOLDERS_ALIAS[placeholderType];
if (aliases) {
for (const alias of aliases) {
if (targetType === alias) return true;
}
}
return false;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isReferenced;
function isReferenced(node, parent, grandparent) {
switch (parent.type) {
case "MemberExpression":
case "OptionalMemberExpression":
if (parent.property === node) {
return !!parent.computed;
}
return parent.object === node;
case "JSXMemberExpression":
return parent.object === node;
case "VariableDeclarator":
return parent.init === node;
case "ArrowFunctionExpression":
return parent.body === node;
case "PrivateName":
return false;
case "ClassMethod":
case "ClassPrivateMethod":
case "ObjectMethod":
if (parent.key === node) {
return !!parent.computed;
}
return false;
case "ObjectProperty":
if (parent.key === node) {
return !!parent.computed;
}
return !grandparent || grandparent.type !== "ObjectPattern";
case "ClassProperty":
case "ClassAccessorProperty":
if (parent.key === node) {
return !!parent.computed;
}
return true;
case "ClassPrivateProperty":
return parent.key !== node;
case "ClassDeclaration":
case "ClassExpression":
return parent.superClass === node;
case "AssignmentExpression":
return parent.right === node;
case "AssignmentPattern":
return parent.right === node;
case "LabeledStatement":
return false;
case "CatchClause":
return false;
case "RestElement":
return false;
case "BreakStatement":
case "ContinueStatement":
return false;
case "FunctionDeclaration":
case "FunctionExpression":
return false;
case "ExportNamespaceSpecifier":
case "ExportDefaultSpecifier":
return false;
case "ExportSpecifier":
if (grandparent != null && grandparent.source) {
return false;
}
return parent.local === node;
case "ImportDefaultSpecifier":
case "ImportNamespaceSpecifier":
case "ImportSpecifier":
return false;
case "ImportAttribute":
return false;
case "JSXAttribute":
return false;
case "ObjectPattern":
case "ArrayPattern":
return false;
case "MetaProperty":
return false;
case "ObjectTypeProperty":
return parent.key !== node;
case "TSEnumMember":
return parent.id !== node;
case "TSPropertySignature":
if (parent.key === node) {
return !!parent.computed;
}
return true;
}
return true;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isScope;
var _generated = require("./generated");
function isScope(node, parent) {
if ((0, _generated.isBlockStatement)(node) && ((0, _generated.isFunction)(parent) || (0, _generated.isCatchClause)(parent))) {
return false;
}
if ((0, _generated.isPattern)(node) && ((0, _generated.isFunction)(parent) || (0, _generated.isCatchClause)(parent))) {
return true;
}
return (0, _generated.isScopable)(node);
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isSpecifierDefault;
var _generated = require("./generated");
function isSpecifierDefault(specifier) {
return (0, _generated.isImportDefaultSpecifier)(specifier) || (0, _generated.isIdentifier)(specifier.imported || specifier.exported, {
name: "default"
});
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isType;
var _definitions = require("../definitions");
function isType(nodeType, targetType) {
if (nodeType === targetType) return true;
if (_definitions.ALIAS_KEYS[targetType]) return false;
const aliases = _definitions.FLIPPED_ALIAS_KEYS[targetType];
if (aliases) {
if (aliases[0] === nodeType) return true;
for (const alias of aliases) {
if (nodeType === alias) return true;
}
}
return false;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isValidES3Identifier;
var _isValidIdentifier = require("./isValidIdentifier");
const RESERVED_WORDS_ES3_ONLY = new Set(["abstract", "boolean", "byte", "char", "double", "enum", "final", "float", "goto", "implements", "int", "interface", "long", "native", "package", "private", "protected", "public", "short", "static", "synchronized", "throws", "transient", "volatile"]);
function isValidES3Identifier(name) {
return (0, _isValidIdentifier.default)(name) && !RESERVED_WORDS_ES3_ONLY.has(name);
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isValidIdentifier;
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");
function isValidIdentifier(name, reserved = true) {
if (typeof name !== "string") return false;
if (reserved) {
if ((0, _helperValidatorIdentifier.isKeyword)(name) || (0, _helperValidatorIdentifier.isStrictReservedWord)(name, true)) {
return false;
}
}
return (0, _helperValidatorIdentifier.isIdentifierName)(name);
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isVar;
var _generated = require("./generated");
var _constants = require("../constants");
function isVar(node) {
return (0, _generated.isVariableDeclaration)(node, {
kind: "var"
}) && !node[_constants.BLOCK_SCOPED_SYMBOL];
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = matchesPattern;
var _generated = require("./generated");
function matchesPattern(member, match, allowPartial) {
if (!(0, _generated.isMemberExpression)(member)) return false;
const parts = Array.isArray(match) ? match : match.split(".");
const nodes = [];
let node;
for (node = member; (0, _generated.isMemberExpression)(node); node = node.object) {
nodes.push(node.property);
}
nodes.push(node);
if (nodes.length < parts.length) return false;
if (!allowPartial && nodes.length > parts.length) return false;
for (let i = 0, j = nodes.length - 1; i < parts.length; i++, j--) {
const node = nodes[j];
let value;
if ((0, _generated.isIdentifier)(node)) {
value = node.name;
} else if ((0, _generated.isStringLiteral)(node)) {
value = node.value;
} else if ((0, _generated.isThisExpression)(node)) {
value = "this";
} else {
return false;
}
if (parts[i] !== value) return false;
}
return true;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isCompatTag;
function isCompatTag(tagName) {
return !!tagName && /^[a-z]/.test(tagName);
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _buildMatchMemberExpression = require("../buildMatchMemberExpression");
const isReactComponent = (0, _buildMatchMemberExpression.default)("React.Component");
var _default = isReactComponent;
exports.default = _default;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = validate;
exports.validateChild = validateChild;
exports.validateField = validateField;
var _definitions = require("../definitions");
function validate(node, key, val) {
if (!node) return;
const fields = _definitions.NODE_FIELDS[node.type];
if (!fields) return;
const field = fields[key];
validateField(node, key, val, field);
validateChild(node, key, val);
}
function validateField(node, key, val, field) {
if (!(field != null && field.validate)) return;
if (field.optional && val == null) return;
field.validate(node, key, val);
}
function validateChild(node, key, val) {
if (val == null) return;
const validate = _definitions.NODE_PARENT_VALIDATIONS[val.type];
if (!validate) return;
validate(node, key, val);
}
\ No newline at end of file
{
"name": "@babel/types",
"version": "7.18.7",
"description": "Babel Types is a Lodash-esque utility library for AST nodes",
"author": "The Babel Team (https://babel.dev/team)",
"homepage": "https://babel.dev/docs/en/next/babel-types",
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20types%22+is%3Aopen",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-types"
},
"main": "./lib/index.js",
"types": "./lib/index-legacy.d.ts",
"typesVersions": {
">=3.7": {
"lib/index-legacy.d.ts": [
"lib/index.d.ts"
]
}
},
"dependencies": {
"@babel/helper-validator-identifier": "^7.18.6",
"to-fast-properties": "^2.0.0"
},
"devDependencies": {
"@babel/generator": "^7.18.7",
"@babel/parser": "^7.18.6",
"chalk": "^4.1.0",
"glob": "^7.1.7"
},
"engines": {
"node": ">=6.9.0"
},
"type": "commonjs"
}
\ No newline at end of file
import * as definitions from "../../lib/definitions/index.js";
function addAssertHelper(type) {
const result =
definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type]
? `node is t.${type}`
: "boolean";
return `export function assert${type}(node: object | null | undefined, opts?: object | null): asserts ${
result === "boolean" ? "node" : result
} {
assert("${type}", node, opts) }
`;
}
export default function generateAsserts() {
let output = `/*
* This file is auto-generated! Do not modify it directly.
* To re-generate run 'make build'
*/
import is from "../../validators/is";
import type * as t from "../..";
function assert(type: string, node: any, opts?: any): void {
if (!is(type, node, opts)) {
throw new Error(
\`Expected type "\${type}" with option \${JSON.stringify(opts)}, \` +
\`but instead got "\${node.type}".\`,
);
}
}\n\n`;
Object.keys(definitions.VISITOR_KEYS).forEach(type => {
output += addAssertHelper(type);
});
Object.keys(definitions.FLIPPED_ALIAS_KEYS).forEach(type => {
output += addAssertHelper(type);
});
Object.keys(definitions.DEPRECATED_KEYS).forEach(type => {
const newType = definitions.DEPRECATED_KEYS[type];
output += `export function assert${type}(node: any, opts: any): void {
console.trace("The node type ${type} has been renamed to ${newType}");
assert("${type}", node, opts);
}\n`;
});
return output;
}