@playcanvas/attribute-parser 1.10.2 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,30 @@
1
- export function getTag(tag: string, node: import("typescript").Node): import("typescript").JSDocTag | null;
2
- export function hasTag(tag: string, node: import("typescript").Node): boolean;
3
- export function isInterface(node: import("typescript").Node): boolean;
4
- export function isStaticMember(member: import("typescript").Node): boolean;
1
+ import type { Declaration, Node } from 'typescript';
2
+ /**
3
+ * @file Utility functions for parsing Script attributes.
4
+ */
5
+ /**
6
+ * Returns a JSDoc tag from a node if it exists
7
+ * @param tag - The tag to search for
8
+ * @param node - The node to analyze
9
+ * @returns The tag node or null if not found
10
+ */
11
+ export declare const getTag: (tag: string, node: Node) => import("typescript").JSDocTag;
12
+ /**
13
+ * Checks if a node has a specific JSDoc tag.
14
+ * @param tag - The tag to search for
15
+ * @param node - The node to analyze
16
+ * @returns True if the tag is found
17
+ */
18
+ export declare const hasTag: (tag: string, node: Node) => boolean;
19
+ /**
20
+ * Checks if the JSDoc node node has an '@interface' tag
21
+ * @param node - The node to analyze
22
+ * @returns True if the node is an interface
23
+ */
24
+ export declare const isInterface: (node: Node) => boolean;
25
+ /**
26
+ * Checks if a node is a scriptName property
27
+ * @param member - The node to analyze
28
+ * @returns True if the node is a scriptName property
29
+ */
30
+ export declare const isStaticMember: (member: Declaration) => boolean;
@@ -2,8 +2,8 @@
2
2
  * This merges two arrays together, filling in the missing values
3
3
  * in the first array with values from the second array.
4
4
  *
5
- * @param {array} a - The first array
6
- * @param {array} b - The second array
7
- * @returns {array} - The merged array
5
+ * @param a - The first array
6
+ * @param b - The second array
7
+ * @returns The merged array
8
8
  */
9
- export function zipArrays(a: any[], b: any[]): any[];
9
+ export declare function zipArrays<T>(a: T[], b: T[]): T[];
@@ -1,16 +1,17 @@
1
+ import type { VirtualTypeScriptEnvironment } from '@typescript/vfs';
1
2
  /**
2
3
  * Parses a tag value into a boolean, number, array or string
3
- * @param {string} input - The tag value to parse
4
- * @returns {boolean|number|string|Array<any>} - The parsed value
4
+ * @param input - The tag value to parse
5
+ * @returns The parsed value
5
6
  */
6
- export function parseTag(input?: string): boolean | number | string | Array<any>;
7
+ export declare function parseTag(input?: string): string | number | boolean | any[];
7
8
  /**
8
9
  * Validates that a tag value matches the expected type
9
10
  *
10
- * @param {String} value - The value to be validated.
11
- * @param {String} typeAnnotation - The TypeScript type annotation as a string.
12
- * @param {import('@typescript/vfs').VirtualTypeScriptEnvironment} env - The environment containing the language service and file creation utilities.
11
+ * @param value - The value to be validated.
12
+ * @param typeAnnotation - The TypeScript type annotation as a string.
13
+ * @param env - The environment containing the language service and file creation utilities.
13
14
  * @throws Will throw an error if the value does not conform to the typeAnnotation.
14
- * @returns {true} if validation passes without type errors.
15
+ * @returns true if validation passes without type errors.
15
16
  */
16
- export function validateTag(value: string, typeAnnotation: string, env: import("@typescript/vfs").VirtualTypeScriptEnvironment): true;
17
+ export declare function validateTag(value: string, typeAnnotation: string, env: VirtualTypeScriptEnvironment): boolean;
@@ -1,103 +1,147 @@
1
- export function createDefaultMapFromCDN(options: any, prefix: any, ts: any): Promise<Map<any, any>>;
1
+ import * as ts from 'typescript';
2
+ /**
3
+ * A TS AST node with internal properties that are absent from the public type definitions.
4
+ */
5
+ export type InternalNode = ts.Node & {
6
+ jsDoc?: ts.JSDoc[];
7
+ initializer?: ts.Expression;
8
+ name?: ts.DeclarationName;
9
+ type?: ts.TypeNode;
10
+ members?: ts.NodeArray<ts.Node>;
11
+ properties?: ts.NodeArray<ts.Node>;
12
+ symbol?: ts.Symbol;
13
+ };
14
+ /**
15
+ * A literal value extracted from an AST node.
16
+ */
17
+ export type LiteralValue = string | number | boolean | null | undefined | ts.PseudoBigInt | LiteralValue[] | {
18
+ [key: string]: LiteralValue;
19
+ };
20
+ export declare function createDefaultMapFromCDN(options: ts.CompilerOptions, prefix: string, tsLib: typeof ts): Promise<Map<string, string>>;
2
21
  /**
3
- * Returns an array of exported nodes from a TypeScript source file.
4
- * @param {import('typescript').Program} program - The TypeScript program
5
- * @param {import('typescript').SourceFile} sourceFile - The TypeScript source file
6
- * @returns {let map: Map<string, Set<import('typescript').Node>>} - A Map of exported nodes
22
+ * Returns a map of exported nodes from a TypeScript source file.
23
+ * @param program - The TypeScript program
24
+ * @param sourceFile - The TypeScript source file
25
+ * @returns A Map of exported nodes
7
26
  */
8
- export function getExportedNodes(program: import("typescript").Program, sourceFile: import("typescript").SourceFile): let;
27
+ export declare function getExportedNodes(program: ts.Program, sourceFile: ts.SourceFile): Map<string, ts.Node>;
9
28
  /**
10
29
  * Checks if the node or its aliased symbol is a class declaration.
11
30
  *
12
- * @param {import('typescript').Node} node - The TypeScript node
13
- * @param {import('typescript').TypeChecker} typeChecker - The TypeScript type checker
14
- * @returns {boolean} - True if the node or its original declaration is a class declaration, false otherwise
31
+ * @param node - The TypeScript node
32
+ * @param typeChecker - The TypeScript type checker
33
+ * @returns True if the node or its original declaration is a class declaration, false otherwise
15
34
  */
16
- export function isAliasedClassDeclaration(node: import("typescript").Node, typeChecker: import("typescript").TypeChecker): boolean;
35
+ export declare function isAliasedClassDeclaration(node: ts.Node, typeChecker: ts.TypeChecker): boolean;
17
36
  /**
18
37
  * Determines if a TypeScript node inherits from a specific base class.
19
- * @param {ts.ClassDeclaration} node - The TypeScript node to analyze
20
- * @param {ts.TypeChecker} typeChecker - The TypeScript type checker
21
- * @param {ts.Symbol} baseClassSymbol - The base class symbol to check inheritance against
22
- * @returns {boolean} - True if the node inherits from the base class
38
+ * @param node - The TypeScript node to analyze
39
+ * @param typeChecker - The TypeScript type checker
40
+ * @param baseClassSymbol - The base class symbol to check inheritance against
41
+ * @returns True if the node inherits from the base class
23
42
  */
24
- export function inheritsFrom(node: ts.ClassDeclaration, typeChecker: ts.TypeChecker, baseClassSymbol: ts.Symbol): boolean;
43
+ export declare function inheritsFrom(node: ts.ClassDeclaration, typeChecker: ts.TypeChecker, baseClassSymbol: ts.Symbol): boolean;
25
44
  /**
26
45
  * Recursively gathers and flat maps and nodes that meet a specific filter.
27
- * @param {import('typescript').Node} node - The TypeScript node to analyze
28
- * @param {function} filter - A function to filter the nodes
29
- * @returns {import('typescript').Node[]} - An array of exported class declarations
46
+ * @param node - The TypeScript node to analyze
47
+ * @param filter - A function to filter the nodes
48
+ * @returns An array of exported class declarations
30
49
  */
31
- export function flatMapAnyNodes(node: import("typescript").Node, filter?: Function): import("typescript").Node[];
50
+ export declare function flatMapAnyNodes(node: ts.Node, filter?: (node: ts.Node) => boolean): ts.Node[];
32
51
  /**
33
52
  * Retrieves the JSDoc-style comments associated with a specific AST node.
34
53
  *
35
- * @param {import('typescript').Node} node - The TypeScript node to analyze
36
- * @param {string} text - The full text content of the source file
37
- * @param {import('typescript').TypeChecker} typeChecker - The TypeScript type checker
38
- * @returns {{ memberName: string, member: Node, range: import('typescript').CommentRange}[]} - An array of comment ranges
54
+ * @param node - The TypeScript node to analyze
55
+ * @param typeChecker - The TypeScript type checker
56
+ * @returns An array of members with JSDoc comments
39
57
  */
40
- export function getJSDocTags(node: import("typescript").Node, typeChecker: import("typescript").TypeChecker): {
58
+ export declare function getJSDocTags(node: ts.Node, typeChecker: ts.TypeChecker): {
41
59
  memberName: string;
42
- member: Node;
43
- range: import("typescript").CommentRange;
60
+ member: ts.Node;
44
61
  }[];
45
62
  /**
46
63
  * Determines if a TypeScript node is an enum.
47
- * @param {import('typescript').Node} node - The TypeScript node to analyze
48
- * @returns {boolean} - True if the node is an enum
64
+ * @param node - The TypeScript node to analyze
65
+ * @returns True if the node is an enum
49
66
  */
50
- export function isEnum(node: import("typescript").Node): boolean;
67
+ export declare function isEnum(node: ts.Node): boolean;
51
68
  /**
52
69
  * Determines the primitive type for enums, or falls back to the actual type name.
53
70
  *
54
- * @param {ts.Type} type - The type to inspect.
55
- * @param {ts.TypeChecker} typeChecker - The TypeScript type checker.
56
- * @returns {'string' | 'boolean' | 'number' | null} - The primitive type of the enum or the type's name.
71
+ * @param type - The type to inspect.
72
+ * @param typeChecker - The TypeScript type checker.
73
+ * @returns The primitive type of the enum or null.
57
74
  */
58
- export function getPrimitiveEnumType(type: ts.Type, typeChecker: ts.TypeChecker): "string" | "boolean" | "number" | null;
75
+ export declare function getPrimitiveEnumType(type: ts.Type, typeChecker: ts.TypeChecker): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
59
76
  /**
60
77
  * Gets the inferred type of a TypeScript node.
61
78
  *
62
- * @param {ts.Node} node - The TypeScript node to analyze
63
- * @param {ts.TypeChecker} typeChecker - The TypeScript type checker
64
- * @returns {{ array: boolean, name: string | undefined, type: Type | null }} - The inferred type of the node
79
+ * @param node - The TypeScript node to analyze
80
+ * @param typeChecker - The TypeScript type checker
81
+ * @returns The inferred type of the node
65
82
  */
66
- export function getType(node: ts.Node, typeChecker: ts.TypeChecker): {
83
+ export declare function getType(node: ts.Node, typeChecker: ts.TypeChecker): {
84
+ type: ts.Type;
85
+ name: string;
67
86
  array: boolean;
68
- name: string | undefined;
69
- type: Type | null;
87
+ isMixedUnion: boolean;
70
88
  };
71
89
  /**
72
90
  * Parses a numerical string into a number. Handles hexadecimal, binary,
73
91
  * octal, exponential notation and underscore notation
74
92
  *
75
- * @param {string} input - The string to parse
76
- * @returns {number} The parsed number, or NaN if the input is not a number
93
+ * @param input - The string to parse
94
+ * @returns The parsed number, or NaN if the input is not a number
77
95
  */
78
- export function parseNumber(input: string): number;
96
+ export declare function parseNumber(input: string): number;
79
97
  /**
80
98
  * Parses a string representation of a numerical array into an array of numbers.
81
99
  *
82
- * @param {string} input - The string to parse
83
- * @returns {number[]} - The parsed array of numbers
84
- * @throws {Error} - If the input contains invalid characters or is not a valid array
100
+ * @param input - The string to parse
101
+ * @returns The parsed array of numbers
102
+ * @throws If the input contains invalid characters or is not a valid array
85
103
  */
86
- export function parseStringToNumericalArray(input: string): number[];
104
+ export declare function parseStringToNumericalArray(input: string): number[];
105
+ /**
106
+ * Checks if the given node is a numerical literal or a unary expression.
107
+ * @param node - The node to check
108
+ * @returns True if the node is a numeric literal
109
+ */
110
+ export declare const isNumericLiteral: (node: ts.Node) => boolean;
111
+ /**
112
+ * If the given node is a numeric literal, returns the parsed number.
113
+ * @param node - The node to check
114
+ * @param isArgument - True if the node is an argument in a parameter list
115
+ * @returns The parsed number
116
+ * @throws {ParsingError} If the node is not a numeric literal
117
+ */
118
+ export declare const parseFloatNode: (node: ts.Node, isArgument?: boolean) => number;
119
+ /**
120
+ * If the given node is a boolean literal, returns the parsed boolean.
121
+ * @param node - The node to check
122
+ * @returns The parsed boolean
123
+ */
124
+ export declare const parseBooleanNode: (node: ts.Node) => boolean;
87
125
  /**
88
126
  * Attempts to extract a literal value from a TypeScript node. This function
89
127
  * supports various types of literals and expressions, including object literals,
90
128
  * array literals, identifiers, and unary expressions.
91
129
  *
92
- * @param {import('typescript').Node} node - The AST node to evaluate
93
- * @param {import('typescript').TypeChecker} typeChecker - The TypeScript type checker
94
- * @returns {any} - The extracted literal value
95
- */
96
- export function getLiteralValue(node: import("typescript").Node, typeChecker: import("typescript").TypeChecker): any;
97
- export function isNumericLiteral(node: import("typescript").Node): boolean;
98
- export function parseFloatNode(node: import("typescript").Node, isArgument?: boolean): number;
99
- export function parseBooleanNode(node: import("typescript").Node): boolean;
100
- export function parseStringNode(node: import("typescript").Node): string;
101
- export function parseArrayLiteralNode(node: any, isArgument?: boolean): any;
102
- export function parseArrayLiteral(args: ts.Node[]): number[];
103
- import * as ts from 'typescript';
130
+ * @param node - The AST node to evaluate
131
+ * @param typeChecker - The TypeScript type checker
132
+ * @returns The extracted literal value
133
+ */
134
+ export declare function getLiteralValue(node: ts.Node, typeChecker?: ts.TypeChecker): LiteralValue;
135
+ /**
136
+ * If the given node is a string literal, returns the parsed string.
137
+ * @param node - The node to check
138
+ * @returns The parsed string
139
+ */
140
+ export declare const parseStringNode: (node: ts.Node) => string;
141
+ export declare const parseArrayLiteralNode: (node: ts.Node, isArgument?: boolean) => any;
142
+ /**
143
+ * Parses the first argument as an array literal.
144
+ * @param args - The arguments to parse
145
+ * @returns The parsed array
146
+ */
147
+ export declare const parseArrayLiteral: (args: readonly ts.Node[]) => any;