📄 test-utils.ts¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 8 |
| 📦 Imports | 3 |
| 📊 Variables & Constants | 3 |
| 📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/typescript-estree/tests/test-utils/test-utils.ts
📦 Imports¶
| Name | Source |
|---|---|
ParseAndGenerateServicesResult |
../../src |
TSESTreeOptions |
../../src |
parseAndGenerateServices |
../../src |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
node |
{ [x: string]: unknown; } |
const | { ...oNode } |
✗ |
child |
UnknownObject | UnknownObject[] |
const | node[prop] as UnknownObject | UnknownObject[] |
✗ |
value |
any[] |
const | [] |
✗ |
Functions¶
parseCodeAndGenerateServices(code: string, config: TSESTreeOptions): ParseAndGenerateServicesResult<TSESTreeOptions>¶
Code
- Parameters:
code: stringconfig: TSESTreeOptions- Return Type:
ParseAndGenerateServicesResult<TSESTreeOptions> - Calls:
parseAndGenerateServices (from ../../src)
formatSnapshotName(filename: string, fixturesDir: string, fileExtension: string): string¶
Code
- Parameters:
filename: stringfixturesDir: stringfileExtension: string- Return Type:
string - Calls:
filename .replace(${fixturesDir}/, '') .replace
isJSXFileType(fileType: string): boolean¶
Code
-
JSDoc:
-
Parameters:
fileType: string- Return Type:
boolean - Calls:
fileType.startsWithfileType.slice
deeplyCopy(ast: T): T¶
Code
-
JSDoc:
-
Parameters:
ast: T- Return Type:
T - Calls:
omitDeep
isObjectLike(value: unknown): boolean¶
Code
- Parameters:
value: unknown- Return Type:
boolean
`omitDeep(root: UnknownObject, keysToOmit: { key: string; predicate: (value: unknown) => boolean }[], selectors: Record<¶
string,
(node: UnknownObject, parent: UnknownObject | null) => void
): UnknownObject`
Code
export function omitDeep(
root: UnknownObject,
keysToOmit: { key: string; predicate: (value: unknown) => boolean }[] = [],
selectors: Record<
string,
(node: UnknownObject, parent: UnknownObject | null) => void
> = {},
): UnknownObject {
function shouldOmit(keyName: string, val: unknown): boolean {
if (keysToOmit.length) {
return keysToOmit.some(
keyConfig => keyConfig.key === keyName && keyConfig.predicate(val),
);
}
return false;
}
function visit(
oNode: UnknownObject,
parent: UnknownObject | null,
): UnknownObject {
if (!Array.isArray(oNode) && !isObjectLike(oNode)) {
return oNode;
}
const node = { ...oNode };
for (const prop in node) {
if (Object.hasOwn(node, prop)) {
// eslint-disable-next-line @typescript-eslint/internal/eqeq-nullish
if (shouldOmit(prop, node[prop]) || node[prop] === undefined) {
// Filter out omitted and undefined props from the node
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete node[prop];
continue;
}
const child = node[prop] as UnknownObject | UnknownObject[];
if (Array.isArray(child)) {
const value = [];
for (const el of child) {
value.push(visit(el, node));
}
node[prop] = value;
} else if (isObjectLike(child)) {
node[prop] = visit(child, node);
}
}
}
if (typeof node.type === 'string' && node.type in selectors) {
selectors[node.type](node, parent);
}
return node;
}
return visit(root, null);
}
-
JSDoc:
/** * Removes the given keys from the given AST object recursively * @param root A JavaScript object to remove keys from * @param keysToOmit Names and predicate functions use to determine what keys to omit from the final object * @param selectors advance ast modifications * @returns formatted object */ -
Parameters:
root: UnknownObjectkeysToOmit: { key: string; predicate: (value: unknown) => boolean }[]- `selectors: Record<
string,
(node: UnknownObject, parent: UnknownObject | null) => void
`
- Return Type:
UnknownObject - Calls:
keysToOmit.somekeyConfig.predicateArray.isArrayisObjectLikeObject.hasOwnshouldOmitvalue.pushvisitcomplex_call_3100- Internal Comments:
shouldOmit(keyName: string, val: unknown): boolean¶
Code
- Parameters:
keyName: stringval: unknown- Return Type:
boolean - Calls:
keysToOmit.somekeyConfig.predicate
visit(oNode: UnknownObject, parent: UnknownObject | null): UnknownObject¶
Code
function visit(
oNode: UnknownObject,
parent: UnknownObject | null,
): UnknownObject {
if (!Array.isArray(oNode) && !isObjectLike(oNode)) {
return oNode;
}
const node = { ...oNode };
for (const prop in node) {
if (Object.hasOwn(node, prop)) {
// eslint-disable-next-line @typescript-eslint/internal/eqeq-nullish
if (shouldOmit(prop, node[prop]) || node[prop] === undefined) {
// Filter out omitted and undefined props from the node
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete node[prop];
continue;
}
const child = node[prop] as UnknownObject | UnknownObject[];
if (Array.isArray(child)) {
const value = [];
for (const el of child) {
value.push(visit(el, node));
}
node[prop] = value;
} else if (isObjectLike(child)) {
node[prop] = visit(child, node);
}
}
}
if (typeof node.type === 'string' && node.type in selectors) {
selectors[node.type](node, parent);
}
return node;
}
- Parameters:
oNode: UnknownObjectparent: UnknownObject | null- Return Type:
UnknownObject - Calls:
Array.isArrayisObjectLikeObject.hasOwnshouldOmitvalue.pushvisitcomplex_call_3100- Internal Comments: