@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.
- package/README.md +34 -37
- package/dist/index.js +64 -41
- package/dist/index.node.mjs +23 -0
- package/dist/libs.d.ts +22437 -7555
- package/package.json +68 -65
- package/types/index.d.ts +50 -33
- package/types/parsers/attribute-parser.d.ts +70 -51
- package/types/parsers/parsing-error.d.ts +23 -34
- package/types/parsers/script-parser.d.ts +64 -103
- package/types/utils/attribute-utils.d.ts +30 -4
- package/types/utils/generic-utils.d.ts +4 -4
- package/types/utils/tag-utils.d.ts +9 -8
- package/types/utils/ts-utils.d.ts +102 -58
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
6
|
-
* @param
|
|
7
|
-
* @returns
|
|
5
|
+
* @param a - The first array
|
|
6
|
+
* @param b - The second array
|
|
7
|
+
* @returns The merged array
|
|
8
8
|
*/
|
|
9
|
-
export function zipArrays(a:
|
|
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
|
|
4
|
-
* @returns
|
|
4
|
+
* @param input - The tag value to parse
|
|
5
|
+
* @returns The parsed value
|
|
5
6
|
*/
|
|
6
|
-
export function parseTag(input?: string):
|
|
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
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
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
|
|
15
|
+
* @returns true if validation passes without type errors.
|
|
15
16
|
*/
|
|
16
|
-
export function validateTag(value: string, typeAnnotation: string, env:
|
|
17
|
+
export declare function validateTag(value: string, typeAnnotation: string, env: VirtualTypeScriptEnvironment): boolean;
|
|
@@ -1,103 +1,147 @@
|
|
|
1
|
-
|
|
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
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @returns
|
|
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:
|
|
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
|
|
13
|
-
* @param
|
|
14
|
-
* @returns
|
|
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:
|
|
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
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* @returns
|
|
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
|
|
28
|
-
* @param
|
|
29
|
-
* @returns
|
|
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:
|
|
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
|
|
36
|
-
* @param
|
|
37
|
-
* @
|
|
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:
|
|
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
|
|
48
|
-
* @returns
|
|
64
|
+
* @param node - The TypeScript node to analyze
|
|
65
|
+
* @returns True if the node is an enum
|
|
49
66
|
*/
|
|
50
|
-
export function isEnum(node:
|
|
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
|
|
55
|
-
* @param
|
|
56
|
-
* @returns
|
|
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" | "
|
|
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
|
|
63
|
-
* @param
|
|
64
|
-
* @returns
|
|
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
|
-
|
|
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
|
|
76
|
-
* @returns
|
|
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
|
|
83
|
-
* @returns
|
|
84
|
-
* @throws
|
|
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
|
|
93
|
-
* @param
|
|
94
|
-
* @returns
|
|
95
|
-
*/
|
|
96
|
-
export function getLiteralValue(node:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
export
|
|
103
|
-
|
|
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;
|