tsc-ts 0.0.3 → 0.0.4

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 CHANGED
@@ -38,3 +38,17 @@ npx tsc-ts --noEmit src/index.ts
38
38
  The native executable never frees syntax trees, types, signatures or symbols: it keeps them until it exits, which saves the cost of tracking them during a build. A one-shot build is unaffected, but a long-running process grows with each rebuild or project update. Native `--watch` (also with `--build`) runs in a child process, and when a change arrives while that process holds more than 2.5 times the memory it held after its first build, a new process replaces it and builds the change, reporting what the old process would have. `TSC_TS_WATCH_MEMORY` sets that limit in megabytes, and `TSC_TS_WATCH_MEMORY=0` turns the replacement off. A `--api` process grows with each project update; restart it to reclaim the memory.
39
39
 
40
40
  The default lib files (`lib.*.d.ts`) ship next to the executable. Set `TSC_TS_LIB_DIR` to use another directory.
41
+
42
+ ## Programmatic API
43
+
44
+ `tsc-ts/api` describes tsc-ts's programs, checkers, nodes, symbols, types and signatures in TypeScript, with the names and numbering of TypeScript 7's API (`typescript/unstable/sync`): the node interfaces, `Symbol`, `Type` and its kinds, `Signature`, `IndexInfo`, `TypePredicate`, `Diagnostic`, `Program`, `TypeChecker`, `CompilerOptions`, and the enums `SyntaxKind`, `NodeFlags`, `ModifierFlags`, `TokenFlags`, `SymbolFlags`, `TypeFlags`, `ObjectFlags`, `ElementFlags`, `SignatureFlags`, `SignatureKind`, `IndexKind`, `TypePredicateKind`, `TypeFormatFlags`, `NodeBuilderFlags`, `ScriptTarget`, `ModuleKind`, `ModuleResolutionKind`, `ModuleDetectionKind`, `ScriptKind`, `LanguageVariant`, `JsxEmit`, `NewLineKind`, `DiagnosticCategory` and `InternalSymbolName`.
45
+
46
+ ```ts
47
+ import { SyntaxKind, type Node } from 'tsc-ts/api';
48
+
49
+ const isIdentifier = (node: Node): boolean => node.kind === SyntaxKind.Identifier;
50
+ ```
51
+
52
+ Lists of child nodes are `NodeList` objects: `node.arguments.nodes` holds the nodes, and `pos` and `end` the list's range. `symbolName(symbol)` gives a symbol's name as TypeScript 7's API does (`__call`, `export=`).
53
+
54
+ The package has a JavaScript build with declaration files for Node.js, and the TypeScript sources of the API (the `source` export condition) for compilers that build it from source.
@@ -0,0 +1,73 @@
1
+ import type { EndOfFile, EntityName, Identifier, KeywordSyntaxKind, ModifierSyntaxKind, PropertyAccessExpression, PunctuationSyntaxKind, Statement, ThisExpression, Token } from './ast.generated.js';
2
+ import type { LanguageVariant, ModifierFlags, NodeFlags, ScriptKind, SyntaxKind } from './enums.generated.js';
3
+ export interface TextRange {
4
+ readonly pos: number;
5
+ readonly end: number;
6
+ }
7
+ /**
8
+ * A node. `pos` is where the node's leading trivia starts and `end` where the node ends, as UTF-16
9
+ * offsets into the file's text; `tokenStartOfNode` gives the start of its first token. `parent` is the
10
+ * enclosing node, and the source file for its statements; a source file's `parent` is undefined.
11
+ */
12
+ export interface Node extends TextRange {
13
+ readonly kind: SyntaxKind;
14
+ readonly flags: NodeFlags;
15
+ readonly parent: Node;
16
+ }
17
+ /** The children of a node in one list: `nodes`, and the range from the list's opening to its closing token. */
18
+ export interface NodeList<T extends Node = Node> extends TextRange {
19
+ readonly nodes: readonly T[];
20
+ /** Whether a comma follows the last node before the list's end. */
21
+ hasTrailingComma(): boolean;
22
+ }
23
+ /** The modifiers of a declaration, with the flags of all of them. */
24
+ export interface ModifierList<T extends Node = Node> extends NodeList<T> {
25
+ readonly modifierFlags: ModifierFlags;
26
+ }
27
+ /** A `/// <reference path>`, `types` or `lib` directive. */
28
+ export interface FileReference extends TextRange {
29
+ readonly fileName: string;
30
+ /** The `resolution-mode` attribute: ModuleKind.ESNext, ModuleKind.CommonJS, or ModuleKind.None without one. */
31
+ readonly resolutionMode: number;
32
+ readonly preserve: boolean;
33
+ }
34
+ export interface LineAndCharacter {
35
+ /** 0-based line number. */
36
+ readonly line: number;
37
+ /** 0-based character offset, in UTF-16 code units, from the start of the line. */
38
+ readonly character: number;
39
+ }
40
+ export interface SourceFile extends Node {
41
+ readonly kind: SyntaxKind.SourceFile;
42
+ readonly statements: NodeList<Statement>;
43
+ readonly endOfFileToken: EndOfFile;
44
+ readonly text: string;
45
+ readonly fileName: string;
46
+ /** The file's path: its absolute, normalized file name, lower-cased where file names are case-insensitive. */
47
+ readonly path: string;
48
+ readonly languageVariant: LanguageVariant;
49
+ readonly scriptKind: ScriptKind;
50
+ readonly isDeclarationFile: boolean;
51
+ readonly referencedFiles: readonly FileReference[];
52
+ readonly typeReferenceDirectives: readonly FileReference[];
53
+ readonly libReferenceDirectives: readonly FileReference[];
54
+ /** The module specifiers of the file's imports, exports, `require` calls and import types, in source order. */
55
+ readonly imports: readonly Node[];
56
+ readonly moduleAugmentations: readonly Node[];
57
+ readonly ambientModuleNames: readonly string[];
58
+ /** The first import or export that makes the file a module, or undefined for a script. */
59
+ readonly externalModuleIndicator: Node | undefined;
60
+ }
61
+ export type PunctuationToken<TKind extends PunctuationSyntaxKind> = Token<TKind>;
62
+ export type KeywordToken<TKind extends KeywordSyntaxKind> = Token<TKind>;
63
+ export type ModifierToken<TKind extends ModifierSyntaxKind> = KeywordToken<TKind>;
64
+ export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression {
65
+ readonly expression: EntityNameExpression;
66
+ readonly name: Identifier;
67
+ }
68
+ export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression;
69
+ export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression;
70
+ export interface JsxTagNamePropertyAccess extends PropertyAccessExpression {
71
+ readonly expression: Identifier | ThisExpression | JsxTagNamePropertyAccess;
72
+ }
73
+ export * from './ast.generated.js';