@playcanvas/attribute-parser 1.10.3 → 1.11.1

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/package.json CHANGED
@@ -1,71 +1,71 @@
1
1
  {
2
- "name": "@playcanvas/attribute-parser",
3
- "version": "1.10.3",
4
- "author": "PlayCanvas <support@playcanvas.com>",
5
- "homepage": "https://github.com/playcanvas/attribute-parser#readme",
6
- "description": "The PlayCanvas Attribute Parser",
7
- "keywords": [
8
- "playcanvas",
9
- "attribute",
10
- "parser"
11
- ],
12
- "license": "MIT",
13
- "type": "module",
14
- "main": "dist/index.js",
15
- "types": "types/index.d.ts",
16
- "exports": {
17
- ".": {
18
- "types": "./types/index.d.ts",
19
- "node": "./dist/index.node.mjs",
20
- "import": "./dist/index.js",
21
- "default": "./dist/index.js"
2
+ "name": "@playcanvas/attribute-parser",
3
+ "version": "1.11.1",
4
+ "description": "The PlayCanvas Attribute Parser",
5
+ "keywords": [
6
+ "playcanvas",
7
+ "attribute",
8
+ "parser"
9
+ ],
10
+ "homepage": "https://github.com/playcanvas/attribute-parser#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/playcanvas/attribute-parser/issues"
22
13
  },
23
- "./libs": "./dist/libs.d.ts"
24
- },
25
- "bugs": {
26
- "url": "https://github.com/playcanvas/attribute-parser/issues"
27
- },
28
- "repository": {
29
- "type": "git",
30
- "url": "git+https://github.com/playcanvas/attribute-parser.git"
31
- },
32
- "files": [
33
- "dist/index.js",
34
- "dist/index.node.mjs",
35
- "dist/libs.d.ts",
36
- "types",
37
- "README.md",
38
- "LICENSE.md"
39
- ],
40
- "devDependencies": {
41
- "@rollup/plugin-commonjs": "28.0.6",
42
- "@rollup/plugin-node-resolve": "16.0.1",
43
- "@rollup/plugin-swc": "0.4.0",
44
- "@swc/core": "1.13.3",
45
- "chai": "5.2.1",
46
- "globals": "16.3.0",
47
- "mocha": "11.7.1",
48
- "playcanvas": "^2.12.3",
49
- "publint": "0.3.12",
50
- "rollup": "4.46.2"
51
- },
52
- "dependencies": {
53
- "@playcanvas/eslint-config": "^2.0.0",
54
- "@typescript/vfs": "^1.6.0",
55
- "eslint": "^9.0.0",
56
- "typescript": "^5.5.3"
57
- },
58
- "scripts": {
59
- "build": "rollup -c && npm run build:types",
60
- "build:types": "tsc -p tsconfig.build.json",
61
- "lint": "eslint src rollup.config.mjs eslint.config.mjs",
62
- "lint:fix": "eslint src rollup.config.mjs eslint.config.mjs --fix",
63
- "publint": "publint",
64
- "test": "mocha test/**/*.test.js --timeout 10000",
65
- "type:check": "tsc --noEmit",
66
- "watch": "rollup -c -w"
67
- },
68
- "engines": {
69
- "node": ">=18.0.0"
70
- }
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/playcanvas/attribute-parser.git"
17
+ },
18
+ "license": "MIT",
19
+ "author": "PlayCanvas <support@playcanvas.com>",
20
+ "type": "module",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./types/index.d.ts",
24
+ "node": "./dist/index.node.mjs",
25
+ "import": "./dist/index.js",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./libs": "./dist/libs.d.ts"
29
+ },
30
+ "main": "dist/index.js",
31
+ "types": "types/index.d.ts",
32
+ "files": [
33
+ "dist/index.node.mjs",
34
+ "dist/libs.d.ts",
35
+ "types"
36
+ ],
37
+ "scripts": {
38
+ "build": "rollup -c && npm run build:types",
39
+ "build:types": "tsc -p tsconfig.build.json",
40
+ "fmt": "prettier --check .",
41
+ "fmt:fix": "prettier --write .",
42
+ "lint": "eslint .",
43
+ "lint:fix": "eslint . --fix",
44
+ "publint": "publint",
45
+ "test": "mocha",
46
+ "typecheck": "tsc --noEmit",
47
+ "watch": "rollup -c -w"
48
+ },
49
+ "dependencies": {
50
+ "@playcanvas/eslint-config": "3.0.0-beta.8",
51
+ "@typescript/vfs": "^1.6.0",
52
+ "eslint": "^9.0.0",
53
+ "typescript": "^5.5.3"
54
+ },
55
+ "devDependencies": {
56
+ "@rollup/plugin-commonjs": "28.0.9",
57
+ "@rollup/plugin-node-resolve": "16.0.3",
58
+ "@rollup/plugin-swc": "0.4.1",
59
+ "@swc/core": "1.15.43",
60
+ "@types/node": "26.1.0",
61
+ "chai": "5.3.3",
62
+ "mocha": "11.7.6",
63
+ "playcanvas": "2.23.3",
64
+ "prettier": "3.9.4",
65
+ "publint": "0.3.21",
66
+ "rollup": "4.62.2"
67
+ },
68
+ "engines": {
69
+ "node": ">=22.0.0"
70
+ }
71
71
  }
package/types/index.d.ts CHANGED
@@ -1,57 +1,74 @@
1
- export class JSDocParser {
2
- /**
3
- * @type {import('@typescript/vfs').VirtualTypeScriptEnvironment}
4
- * @private
5
- */
1
+ import * as ts from 'typescript';
2
+ import type { AttributeData } from './parsers/attribute-parser.ts';
3
+ import { ParsingError } from './parsers/parsing-error.ts';
4
+ import { ScriptParser } from './parsers/script-parser.ts';
5
+ import type { ValidationError } from './parsers/script-parser.ts';
6
+ type ScriptResults = {
7
+ /** The extracted attributes, keyed by attribute name */
8
+ attributes: Record<string, AttributeData>;
9
+ /** The parsing errors for this script */
10
+ errors: ParsingError[];
11
+ };
12
+ type MemberInfo = {
13
+ /** The name of the member */
14
+ name: string;
15
+ /** Whether the member is a script attribute */
16
+ isAttribute: boolean;
17
+ /** The type of the member, with an array suffix when applicable */
18
+ type: string;
19
+ /** The start of the member, including any JSDoc block */
20
+ start: {
21
+ line: number;
22
+ column: number;
23
+ };
24
+ /** The end of the member */
25
+ end: {
26
+ line: number;
27
+ column: number;
28
+ };
29
+ };
30
+ export declare class JSDocParser {
6
31
  private _env;
7
32
  /**
8
33
  * An internal array of program errors
9
- * @private
10
34
  */
11
35
  private _errors;
36
+ parser: ScriptParser;
37
+ program: ts.Program;
12
38
  /**
13
39
  * Initializes the JSDocParser with the standard library files
14
40
  *
15
- * @param {string} libPath - A path to a directory of library types, or a path to the '.d.ts' file itself
16
- * @returns {Promise<JSDocParser>} - The initialized JSDocParser
41
+ * @param libPath - A path to a directory of library types, or a path to the '.d.ts' file itself
42
+ * @returns The initialized JSDocParser
17
43
  */
18
- init(libPath: string): Promise<JSDocParser>;
44
+ init(libPath?: string): Promise<this>;
19
45
  /**
20
46
  * Creates program from fileName and scriptsContents
21
47
  *
22
- * @param {[string, string][]} newFiles - An array of {[path]: [content]} which represent the files in the program
23
- * @param {string[]} removedFiles - An array of file paths that should be removed from the program
24
- * @returns {{ parser: ScriptParser, program: ts.Program,
25
- * errors: import('./parsers/script-parser.js').ValidationError[]}} - The extracted attributes
48
+ * @param newFiles - An array of [path, content] tuples which represent the files in the program
49
+ * @param removedFiles - An array of file paths that should be removed from the program
50
+ * @returns The program errors
26
51
  */
27
- updateProgram(newFiles?: [string, string][], removedFiles?: string[]): {
28
- parser: ScriptParser;
29
- program: ts.Program;
30
- errors: import("./parsers/script-parser.js").ValidationError[];
31
- };
32
- parser: ScriptParser;
33
- program: ts.Program;
52
+ updateProgram(newFiles?: [string, string][], removedFiles?: string[]): ValidationError[];
34
53
  /**
35
54
  * Returns all the valid ESM Scripts within a file
36
- * @param {string} fileName - The file name in the program to check
37
- * @param {ParsingError[]} errors - An array to store any parsing errors
38
- * @returns {Map<string, import('typescript').Node>} - A map of valid ESM Script <names, nodes> within the file
55
+ * @param fileName - The file name in the program to check
56
+ * @param errors - An array to store any parsing errors
57
+ * @returns A map of valid ESM Script <names, nodes> within the file
39
58
  */
40
- getAllEsmScripts(fileName: string, errors?: ParsingError[]): Map<string, import("typescript").Node>;
59
+ getAllEsmScripts(fileName: string, errors?: (ParsingError | ValidationError)[]): Map<string, ts.Node>;
41
60
  /**
42
61
  * Analyzes the specified TypeScript file and extracts metadata from JSDoc comments.
43
62
  *
44
- * @param {string} fileName - The name of the file in the program to run
45
- * @returns {[results: object, errors: import('./parsers/script-parser.js').ValidationError[]]} - The extracted attributes
63
+ * @param fileName - The name of the file in the program to run
64
+ * @returns The extracted attributes and errors
46
65
  */
47
- parseAttributes(fileName: string): [results: object, errors: import("./parsers/script-parser.js").ValidationError[]];
66
+ parseAttributes(fileName: string): [Record<string, ScriptResults>, (ParsingError | ValidationError)[]];
48
67
  /**
49
68
  * Analyzes the specified TypeScript file and extracts metadata from JSDoc comments.
50
- * @param {string} fileName - The name of the file to run
51
- * @returns {[results: object, errors: import('./parsers/script-parser.js').ValidationError[]]} - The extracted attributes
69
+ * @param fileName - The name of the file to run
70
+ * @returns The extracted attributes and errors
52
71
  */
53
- getAttributes(fileName: string): [results: object, errors: import("./parsers/script-parser.js").ValidationError[]];
72
+ getAttributes(fileName: string): [Record<string, MemberInfo[]>, (ParsingError | ValidationError)[]];
54
73
  }
55
- import { ScriptParser } from './parsers/script-parser.js';
56
- import * as ts from 'typescript';
57
- import { ParsingError } from './parsers/parsing-error.js';
74
+ export {};
@@ -1,78 +1,97 @@
1
+ import type { VirtualTypeScriptEnvironment } from '@typescript/vfs';
2
+ import * as ts from 'typescript';
3
+ import type { LiteralValue } from '../utils/ts-utils.ts';
4
+ import { ParsingError } from './parsing-error.ts';
5
+ export type TagDefinition = {
6
+ /** The type of the tag */
7
+ type: string;
8
+ /** A function to generate a support message for the tag */
9
+ supportMessage?: () => string;
10
+ /** A string to fix the tag */
11
+ fix?: string;
12
+ };
13
+ export type TypeSerializer = (node: ts.Node, typeChecker?: ts.TypeChecker) => LiteralValue;
1
14
  /**
2
- * @typedef {Object} TagDefinition
3
- * @property {string} type - The type of the tag
4
- * @property {() => string} supportMessage - A function to generate a support message for the tag
5
- * @property {string} fix - A function to fix the tag
15
+ * The internal representation of a parsed attribute. Known fields are set while parsing;
16
+ * custom block tags (e.g. @placeholder, @size) land on the index signature.
6
17
  */
18
+ export type AttributeData = {
19
+ /** The resolved type, replaced with its lowercased type name on output */
20
+ type: ts.Type | string;
21
+ /** The name of the attribute */
22
+ name: string;
23
+ /** The type name, removed on output */
24
+ typeName?: string;
25
+ /** Whether the attribute is an array type */
26
+ array: boolean;
27
+ /** The serialized value, moved to default on output */
28
+ value?: LiteralValue;
29
+ /** The enum members, removed on output when empty */
30
+ enum?: Record<string, LiteralValue>[];
31
+ description?: string;
32
+ range?: number[];
33
+ min?: number;
34
+ max?: number;
35
+ attributes?: Record<string, AttributeData>;
36
+ schema?: AttributeData[];
37
+ resource?: string;
38
+ assetType?: string;
39
+ default?: LiteralValue;
40
+ enabledif?: string;
41
+ visibleif?: string;
42
+ [key: string]: unknown;
43
+ };
7
44
  /**
8
45
  * A class to parse JSDoc comments and extract attribute metadata.
9
46
  */
10
- export class AttributeParser {
47
+ export declare class AttributeParser {
48
+ env: VirtualTypeScriptEnvironment;
49
+ tagTypeAnnotations: Map<string, TagDefinition>;
50
+ typeSerializerMap: Map<string, TypeSerializer>;
51
+ program: ts.Program;
52
+ typeChecker: ts.TypeChecker;
11
53
  /**
12
54
  * Creates a new instance of the ScriptParser class.
13
55
  *
14
- * @param {Map<string, TagDefinition>} tags - An set of tag definitions and their validators to add to the parser
15
- * @param {object} env - The TypeScript environment to use
16
- * @param {Map<string, Function>} typeSerializerMap - A map of custom serializers
56
+ * @param tags - An set of tag definitions and their validators to add to the parser
57
+ * @param env - The TypeScript environment to use
58
+ * @param typeSerializerMap - A map of custom serializers
17
59
  */
18
- constructor(tags: Map<string, TagDefinition>, env: object, typeSerializerMap: Map<string, Function>);
19
- env: any;
20
- tagTypeAnnotations: Map<string, TagDefinition>;
21
- typeSerializerMap: Map<string, Function>;
22
- program: any;
23
- typeChecker: any;
60
+ constructor(tags: Map<string, TagDefinition>, env: VirtualTypeScriptEnvironment, typeSerializerMap: Map<string, TypeSerializer>);
24
61
  /**
25
62
  * Parses a JSdoc comment and extracts any associated metadata if the `@attribute`
26
63
  * modifier is used. Returns null if this is not an attribute comment.
27
64
  *
28
- * @param {ts.Node} node - The node to parse
29
- * @param {ParsingError[]} errors - An array to store any parsing errors
30
- * @param {boolean} requiresAttributeTag - Whether the comment must have an attribute tag
31
- * @param {string} scriptName - The name of the script this node belongs to
32
- * @param {string} attributeName - The name of the attribute this node belongs to
33
- * @returns {*} - The extracted metadata or null if no metadata was found
65
+ * @param node - The node to parse
66
+ * @param errors - An array to store any parsing errors
67
+ * @param requiresAttributeTag - Whether the comment must have an attribute tag
68
+ * @param scriptName - The name of the script this node belongs to
69
+ * @param attributeName - The name of the attribute this node belongs to
70
+ * @returns The extracted metadata or undefined if no metadata was found
34
71
  */
35
- parseAttributeComment(node: ts.Node, errors: ParsingError[], requiresAttributeTag: boolean, scriptName: string, attributeName: string): any;
72
+ parseAttributeComment(node: ts.Node, errors?: ParsingError[], requiresAttributeTag?: boolean, scriptName?: string, attributeName?: string): AttributeData;
36
73
  /**
37
74
  * Extract the public members and their values from a TypeScript node.
38
75
  *
39
- * @param {ts.Node} node - The node to parse
40
- * @param {ParsingError[]} errors - An array to store any parsing errors
41
- * @param {string} [scriptName] - The name of the script this node belongs to
42
- * @returns {*} - The extracted members
76
+ * @param node - The node to parse
77
+ * @param errors - An array to store any parsing errors
78
+ * @param scriptName - The name of the script this node belongs to
79
+ * @returns The extracted members
43
80
  */
44
- getNodeAsAttribute(node: ts.Node, errors?: ParsingError[], scriptName?: string): any;
81
+ getNodeAsAttribute(node: ts.Node, errors?: ParsingError[], scriptName?: string): AttributeData;
45
82
  /**
46
83
  * Extracts the members of an enum from a TypeScript node.
47
84
  *
48
- * @param {import('typescript').Node} node - The TypeScript node to analyze
49
- * @param {ParsingError[]} errors - An array to store any parsing errors
50
- * @returns {Object<string, *>[]} - An array of enum members
85
+ * @param node - The TypeScript node to analyze
86
+ * @param _errors - An array to store any parsing errors
87
+ * @returns An array of enum members
51
88
  */
52
- getEnumMembers(node: import("typescript").Node, errors: ParsingError[]): {
53
- [x: string]: any;
54
- }[];
89
+ getEnumMembers(node: ts.Node, _errors: ParsingError[]): Record<string, LiteralValue>[];
55
90
  /**
56
91
  * Extract the public members and their values from a TypeScript node.
57
92
  *
58
- * @param {ts.Node} node - The node to parse
59
- * @returns {any[]} - The extracted members
93
+ * @param node - The node to parse
94
+ * @returns The extracted members
60
95
  */
61
- getMembers(node: ts.Node): any[];
96
+ getMembers(node: ts.Node): Record<string, LiteralValue>[];
62
97
  }
63
- export type TagDefinition = {
64
- /**
65
- * - The type of the tag
66
- */
67
- type: string;
68
- /**
69
- * - A function to generate a support message for the tag
70
- */
71
- supportMessage: () => string;
72
- /**
73
- * - A function to fix the tag
74
- */
75
- fix: string;
76
- };
77
- import * as ts from 'typescript';
78
- import { ParsingError } from './parsing-error.js';
@@ -1,40 +1,10 @@
1
- /**
2
- * @typedef {Object} Fix
3
- * @property {string} text - The text to insert at the fix location
4
- * @property {string} title - The title of the fix
5
- * @property {{ startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number }} range - The range of the fix
6
- */
7
- /**
8
- * A class representing a parsing error.
9
- * @param {import('typescript').Node} node - The AST node which caused the error
10
- * @param {string} type - The type of the error
11
- * @param {string} message - The description of the error
12
- * @param {Fix} [fix] - The fix for the error
13
- * @param {string} [scriptName] - The name of the script this error belongs to (required)
14
- * @param {string} [attributeName] - The name of the attribute this error belongs to (optional)
15
- */
16
- export class ParsingError {
17
- constructor(node: any, type: any, message: any, fix: any, scriptName: any, attributeName: any);
18
- node: any;
19
- type: any;
20
- message: any;
21
- fix: any;
22
- scriptName: any;
23
- attributeName: any;
24
- toString(): string;
25
- }
1
+ import type { Node } from 'typescript';
26
2
  export type Fix = {
27
- /**
28
- * - The text to insert at the fix location
29
- */
3
+ /** The text to insert at the fix location */
30
4
  text: string;
31
- /**
32
- * - The title of the fix
33
- */
5
+ /** The title of the fix */
34
6
  title: string;
35
- /**
36
- * - The range of the fix
37
- */
7
+ /** The range of the fix */
38
8
  range: {
39
9
  startLineNumber: number;
40
10
  startColumn: number;
@@ -42,3 +12,22 @@ export type Fix = {
42
12
  endColumn: number;
43
13
  };
44
14
  };
15
+ /**
16
+ * A class representing a parsing error.
17
+ */
18
+ export declare class ParsingError {
19
+ /** The AST node which caused the error */
20
+ node: Node;
21
+ /** The type of the error */
22
+ type: string;
23
+ /** The description of the error */
24
+ message: string;
25
+ /** The fix for the error */
26
+ fix?: Fix;
27
+ /** The name of the script this error belongs to */
28
+ scriptName?: string;
29
+ /** The name of the attribute this error belongs to */
30
+ attributeName?: string;
31
+ constructor(node: Node, type: string, message: string, fix?: Fix, scriptName?: string, attributeName?: string);
32
+ toString(): string;
33
+ }
@@ -1,125 +1,86 @@
1
- /**
2
- * A class to parse ESM Scripts and extract attribute metadata from JSDoc comments.
3
- * This class uses the TypeScript compiler API to parse the script and extract the metadata.
4
- */
5
- export class ScriptParser {
6
- /**
7
- * @param {import('@typescript/vfs').VirtualTypeScriptEnvironment} env - The TypeScript virtual environment
8
- * @param {number} [maxDepth] - The maximum recursion depth
9
- */
10
- constructor(env: import("@typescript/vfs").VirtualTypeScriptEnvironment, maxDepth?: number);
11
- env: import("@typescript/vfs").VirtualTypeScriptEnvironment;
12
- program: ts.Program;
13
- typeChecker: ts.TypeChecker;
14
- maxDepth: number;
15
- typeSerializerMap: Map<any, any>;
16
- allSupportedTypesSet: Set<ts.Type>;
17
- attributeParser: AttributeParser;
18
- /**
19
- * Checks a program for compile errors and returns a list of formatted error messages.
20
- * @param {ValidationError[]} errors - The array to store error messages
21
- * @returns {boolean} - True if the program has no errors, false otherwise
22
- */
23
- validateProgram(errors?: ValidationError[]): boolean;
24
- /**
25
- * @typedef {Object} ParserOptions
26
- * @property {object} [attributes] - The attributes object to add to
27
- * @property {ParsingError[]} [errors] - The array to store parsing errors
28
- * @property {boolean} [requiresAttributeTag] - Whether the attribute requires an @attribute tag
29
- * @property {number} [depth] - The current recursion depth
30
- * @property {string} [scriptName] - The current script name for context
31
- */
32
- /**
33
- * Extracts Script Attributes from JSDoc style tag from a AST node
34
- *
35
- * @param {import('typescript').Node} node - The TypeScript node to analyze
36
- * @param {ParserOptions} [opts] - The input options
37
- * @returns {Attribute[]} - The extracted attributes;
38
- */
39
- extractAttributes(node: import("typescript").Node, opts?: {
40
- /**
41
- * - The attributes object to add to
42
- */
43
- attributes?: object;
44
- /**
45
- * - The array to store parsing errors
46
- */
47
- errors?: ParsingError[];
48
- /**
49
- * - Whether the attribute requires an
50
- */
51
- requiresAttributeTag?: boolean;
52
- }): Attribute[];
53
- }
1
+ import type { VirtualTypeScriptEnvironment } from '@typescript/vfs';
2
+ import * as ts from 'typescript';
3
+ import { AttributeParser } from './attribute-parser.ts';
4
+ import type { AttributeData, TypeSerializer } from './attribute-parser.ts';
5
+ import { ParsingError } from './parsing-error.ts';
54
6
  export type Attribute = {
55
- /**
56
- * - The type of the attribute
57
- */
7
+ /** The type of the attribute */
58
8
  type: string;
59
- /**
60
- * - Whether the attribute is an array type of not
61
- */
9
+ /** Whether the attribute is an array type of not */
62
10
  array: boolean;
63
- /**
64
- * - The description of the attribute
65
- */
11
+ /** The description of the attribute */
66
12
  description?: string;
67
- /**
68
- * - Placeholder for Editor's for field UI.
69
- */
13
+ /** Placeholder for Editor's for field UI. */
70
14
  placeholder?: string;
71
- /**
72
- * - The default value of the attribute
73
- */
74
- defaultValue?: any;
75
- /**
76
- * - An array of possible values for the attribute
77
- */
78
- enum?: {
79
- [x: string]: number | boolean | string;
80
- }[];
81
- /**
82
- * - Numerical constraints for the attribute
83
- */
15
+ /** The default value of the attribute */
16
+ defaultValue?: unknown;
17
+ /** An array of possible values for the attribute */
18
+ enum?: Record<string, number | boolean | string>[];
19
+ /** Numerical constraints for the attribute */
84
20
  range?: {
85
21
  min: number;
86
22
  max: number;
87
23
  };
88
- /**
89
- * - Numerical constraints for the attribute
90
- */
24
+ /** Numerical constraints for the attribute */
91
25
  precision?: number;
92
- /**
93
- * - Numerical constraints for the attribute
94
- */
26
+ /** Numerical constraints for the attribute */
95
27
  step?: number;
96
- /**
97
- * - Name of asset type to be used in 'asset' type attribute
98
- */
28
+ /** Name of asset type to be used in 'asset' type attribute */
99
29
  resource?: string;
100
30
  };
101
31
  export type ValidationError = {
102
- /**
103
- * - The error message
104
- */
32
+ /** The error message */
105
33
  message: string;
106
- /**
107
- * - The file the error occurred in
108
- */
34
+ /** The file the error occurred in */
109
35
  file?: string;
36
+ /** The line the error occurred on */
37
+ line?: number;
38
+ /** The column the error occurred on */
39
+ column?: number;
40
+ /** The length of the error */
41
+ length?: number;
42
+ };
43
+ export type ParserOptions = {
44
+ /** The attributes object to add to */
45
+ attributes?: Record<string, AttributeData>;
46
+ /** The array to store parsing errors */
47
+ errors?: ParsingError[];
48
+ /** Whether the attribute requires an @attribute tag */
49
+ requiresAttributeTag?: boolean;
50
+ /** The current recursion depth */
51
+ depth?: number;
52
+ /** The current script name for context */
53
+ scriptName?: string;
54
+ };
55
+ /**
56
+ * A class to parse ESM Scripts and extract attribute metadata from JSDoc comments.
57
+ * This class uses the TypeScript compiler API to parse the script and extract the metadata.
58
+ */
59
+ export declare class ScriptParser {
60
+ env: VirtualTypeScriptEnvironment;
61
+ program: ts.Program;
62
+ typeChecker: ts.TypeChecker;
63
+ maxDepth: number;
64
+ typeSerializerMap: Map<string, TypeSerializer>;
65
+ allSupportedTypesSet: Set<ts.Type>;
66
+ attributeParser: AttributeParser;
110
67
  /**
111
- * - The line the error occurred on
68
+ * @param env - The TypeScript virtual environment
69
+ * @param maxDepth - The maximum recursion depth
112
70
  */
113
- line?: number;
71
+ constructor(env: VirtualTypeScriptEnvironment, maxDepth?: number);
114
72
  /**
115
- * - The column the error occurred on
73
+ * Checks a program for compile errors and returns a list of formatted error messages.
74
+ * @param errors - The array to store error messages
75
+ * @returns True if the program has no errors, false otherwise
116
76
  */
117
- column?: number;
77
+ validateProgram(errors?: ValidationError[]): boolean;
118
78
  /**
119
- * - The length of the error
79
+ * Extracts Script Attributes from JSDoc style tag from a AST node
80
+ *
81
+ * @param node - The TypeScript node to analyze
82
+ * @param opts - The input options
83
+ * @returns The extracted attributes
120
84
  */
121
- length?: number;
122
- };
123
- import * as ts from 'typescript';
124
- import { AttributeParser } from './attribute-parser.js';
125
- import { ParsingError } from './parsing-error.js';
85
+ extractAttributes(node: ts.Node, opts?: ParserOptions): Record<string, AttributeData>;
86
+ }