tsc-ts 0.0.2 → 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.
@@ -0,0 +1,10 @@
1
+ export * from './ast.js';
2
+ export * from './enums.generated.js';
3
+ export type { CompilerOptions } from './compiler-options.generated.js';
4
+ export { symbolName } from './symbols.js';
5
+ export type { __String, BigIntLiteralType, BooleanLiteralType, ConditionalType, CreateProgramOptions, Diagnostic, FileSystemEntries, FreshableType, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, LiteralType, NumberLiteralType, ObjectType, ParsedConfigFile, Program, ProgramHost, Signature, SourceFileMetadata, StringLiteralType, StringMappingType, SubstitutionType, Symbol, TemplateLiteralType, TupleType, Type, TypeChecker, TypeParameter, TypePredicate, TypeReference, UnionOrIntersectionType, UnionType, } from './types.js';
6
+ /** The kind of an index signature's key, as TypeScript 5 numbers it. */
7
+ export declare enum IndexKind {
8
+ String = 0,
9
+ Number = 1
10
+ }
@@ -0,0 +1,11 @@
1
+ // tsc-ts's public API (`tsc-ts/api`): the types of programs, checkers, nodes, symbols, types and
2
+ // signatures, and the enums that number their kinds and flags as TypeScript 7's API does.
3
+ export * from './ast.js';
4
+ export * from './enums.generated.js';
5
+ export { symbolName } from './symbols.js';
6
+ /** The kind of an index signature's key, as TypeScript 5 numbers it. */
7
+ export var IndexKind;
8
+ (function (IndexKind) {
9
+ IndexKind[IndexKind["String"] = 0] = "String";
10
+ IndexKind[IndexKind["Number"] = 1] = "Number";
11
+ })(IndexKind || (IndexKind = {}));
@@ -0,0 +1,8 @@
1
+ import type { Symbol } from './types.js';
2
+ /** The prefix of tsc-ts's internal symbol names (`internalSymbolNamePrefix` in compiler/symbol.ts). */
3
+ export declare const internalNamePrefix = "\uFFFE";
4
+ /**
5
+ * The name of `symbol`, as TypeScript 7's API gives it: internal names start with `__` (`__call`,
6
+ * `__type`, `__object`), and `default`, `export=`, `this` and `module.exports` are written as they are.
7
+ */
8
+ export declare function symbolName(symbol: Symbol): string;
@@ -0,0 +1,11 @@
1
+ // Symbol functions of tsc-ts's public API.
2
+ /** The prefix of tsc-ts's internal symbol names (`internalSymbolNamePrefix` in compiler/symbol.ts). */
3
+ export const internalNamePrefix = '￾';
4
+ /**
5
+ * The name of `symbol`, as TypeScript 7's API gives it: internal names start with `__` (`__call`,
6
+ * `__type`, `__object`), and `default`, `export=`, `this` and `module.exports` are written as they are.
7
+ */
8
+ export function symbolName(symbol) {
9
+ const name = symbol.name;
10
+ return name.startsWith(internalNamePrefix) ? '__' + name.substring(1) : name;
11
+ }
@@ -0,0 +1,300 @@
1
+ import type { Expression, Identifier, Node, SourceFile, TypeNode } from './ast.js';
2
+ import type { CompilerOptions } from './compiler-options.generated.js';
3
+ import type { DiagnosticCategory, ElementFlags, ModuleKind, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypeFormatFlags, TypePredicateKind } from './enums.generated.js';
4
+ /**
5
+ * The escaped form of a symbol name, the key of member and export tables: internal names start with
6
+ * `__` (`__call`, `__type`), and names that already start with `__` have one more `_`.
7
+ */
8
+ export type __String = string & {
9
+ readonly __escapedIdentifier: void;
10
+ };
11
+ /**
12
+ * A symbol. Its name, as TypeScript 7's API gives it, is `symbolName(symbol)`; `escapedName` is the key
13
+ * of the tables it is a member or export of.
14
+ */
15
+ export interface Symbol {
16
+ /** Unique in the process. */
17
+ readonly id: number;
18
+ readonly escapedName: __String;
19
+ readonly flags: SymbolFlags;
20
+ readonly checkFlags: number;
21
+ readonly declarations: readonly Node[];
22
+ readonly valueDeclaration: Node | undefined;
23
+ getParent(): Symbol | undefined;
24
+ /** The symbol's export symbol, or the symbol itself if it has none. */
25
+ getExportSymbol(): Symbol;
26
+ /** The members, by escaped name. */
27
+ getMembers(): ReadonlyMap<__String, Symbol>;
28
+ /** The exports, by escaped name. */
29
+ getExports(): ReadonlyMap<__String, Symbol>;
30
+ }
31
+ /**
32
+ * A type. Its flags give its kind; the accessors answer undefined, or an empty list, where a kind has no
33
+ * such part. Type ids are unique within the program's checker.
34
+ */
35
+ export interface Type {
36
+ readonly flags: TypeFlags;
37
+ readonly objectFlags: ObjectFlags;
38
+ readonly id: number;
39
+ getSymbol(): Symbol | undefined;
40
+ getAliasSymbol(): Symbol | undefined;
41
+ getAliasTypeArguments(): readonly Type[];
42
+ /** The target of a type reference, index type (`keyof T`) or string mapping type. */
43
+ getTarget(): Type | undefined;
44
+ /** The members of a union or intersection, or the types of a template literal type. */
45
+ getTypes(): readonly Type[];
46
+ getFreshType(): Type | undefined;
47
+ getRegularType(): Type | undefined;
48
+ getObjectType(): Type | undefined;
49
+ getIndexType(): Type | undefined;
50
+ getCheckType(): Type | undefined;
51
+ getExtendsType(): Type | undefined;
52
+ getTrueType(): Type | undefined;
53
+ getFalseType(): Type | undefined;
54
+ /** The base type of a substitution type. */
55
+ getBaseType(): Type | undefined;
56
+ /** The constraint of a substitution type. */
57
+ getConstraint(): Type | undefined;
58
+ getTypeParameters(): readonly TypeParameter[];
59
+ getOuterTypeParameters(): readonly TypeParameter[];
60
+ getLocalTypeParameters(): readonly TypeParameter[];
61
+ /** The base types of a class or interface type, or undefined for any other type. */
62
+ getBaseTypes(): readonly Type[] | undefined;
63
+ isClassOrInterface(): this is InterfaceType;
64
+ isUnionType(): this is UnionType;
65
+ isIntersectionType(): this is IntersectionType;
66
+ isObjectType(): this is ObjectType;
67
+ isIntrinsicType(): this is IntrinsicType;
68
+ /** Whether this is the error type, which the checker gives where a type can't be determined. */
69
+ isErrorType(): boolean;
70
+ isLiteralType(): this is LiteralType;
71
+ isStringLiteralType(): this is StringLiteralType;
72
+ isNumberLiteralType(): this is NumberLiteralType;
73
+ isBigIntLiteralType(): this is BigIntLiteralType;
74
+ isBooleanLiteralType(): this is BooleanLiteralType;
75
+ isTypeReference(): this is TypeReference;
76
+ isTupleType(): this is TupleType;
77
+ isIndexType(): this is IndexType;
78
+ isIndexedAccessType(): this is IndexedAccessType;
79
+ isConditionalType(): this is ConditionalType;
80
+ isSubstitutionType(): this is SubstitutionType;
81
+ isTemplateLiteralType(): this is TemplateLiteralType;
82
+ isStringMappingType(): this is StringMappingType;
83
+ isTypeParameter(): this is TypeParameter;
84
+ }
85
+ /** Literal types (TypeFlags.Literal) and computed enum types (TypeFlags.Enum). */
86
+ export interface FreshableType extends Type {
87
+ getFreshType(): FreshableType | undefined;
88
+ getRegularType(): FreshableType | undefined;
89
+ }
90
+ export interface LiteralType extends FreshableType {
91
+ readonly value: string | number | boolean | bigint;
92
+ }
93
+ export interface StringLiteralType extends LiteralType {
94
+ readonly value: string;
95
+ }
96
+ export interface NumberLiteralType extends LiteralType {
97
+ readonly value: number;
98
+ }
99
+ export interface BigIntLiteralType extends LiteralType {
100
+ readonly value: bigint;
101
+ }
102
+ export interface BooleanLiteralType extends LiteralType {
103
+ readonly value: boolean;
104
+ }
105
+ export interface ObjectType extends Type {
106
+ }
107
+ export interface TypeReference extends ObjectType {
108
+ getTarget(): Type;
109
+ }
110
+ /** Classes and interfaces (ObjectFlags.ClassOrInterface). */
111
+ export interface InterfaceType extends TypeReference {
112
+ getBaseTypes(): readonly Type[];
113
+ }
114
+ /** Tuple targets (ObjectFlags.Tuple). */
115
+ export interface TupleType extends InterfaceType {
116
+ readonly elementFlags: readonly ElementFlags[];
117
+ /** The number of initial required or optional elements. */
118
+ readonly fixedLength: number;
119
+ readonly readonly: boolean;
120
+ }
121
+ export interface UnionOrIntersectionType extends Type {
122
+ }
123
+ export interface UnionType extends UnionOrIntersectionType {
124
+ }
125
+ export interface IntersectionType extends UnionOrIntersectionType {
126
+ }
127
+ export interface TypeParameter extends Type {
128
+ /** Whether this is the `this` type of a class, interface or tuple. */
129
+ readonly isThisType: boolean;
130
+ }
131
+ export interface IndexType extends Type {
132
+ getTarget(): Type;
133
+ }
134
+ export interface IndexedAccessType extends Type {
135
+ getObjectType(): Type;
136
+ getIndexType(): Type;
137
+ }
138
+ export interface ConditionalType extends Type {
139
+ getCheckType(): Type;
140
+ getExtendsType(): Type;
141
+ getTrueType(): Type;
142
+ getFalseType(): Type;
143
+ }
144
+ export interface SubstitutionType extends Type {
145
+ getBaseType(): Type;
146
+ getConstraint(): Type;
147
+ }
148
+ export interface TemplateLiteralType extends Type {
149
+ /** The text segments, one more than the types between them. */
150
+ readonly texts: readonly string[];
151
+ }
152
+ export interface StringMappingType extends Type {
153
+ getTarget(): Type;
154
+ }
155
+ /** any, unknown, string, number, bigint, symbol, void, undefined, null, never, object and the error type. */
156
+ export interface IntrinsicType extends Type {
157
+ readonly intrinsicName: string;
158
+ }
159
+ export interface Signature {
160
+ /** Unique within the program's checker. */
161
+ readonly id: number;
162
+ /** Has a rest parameter, is a construct signature, is abstract (SignatureFlags). */
163
+ readonly flags: SignatureFlags;
164
+ readonly declaration: Node | undefined;
165
+ getTypeParameters(): readonly TypeParameter[];
166
+ getParameters(): readonly Symbol[];
167
+ getThisParameter(): Symbol | undefined;
168
+ /** The signature this one was instantiated from. */
169
+ getTarget(): Signature | undefined;
170
+ }
171
+ export interface IndexInfo {
172
+ readonly keyType: Type;
173
+ readonly type: Type;
174
+ readonly isReadonly: boolean;
175
+ readonly declaration: Node | undefined;
176
+ }
177
+ export interface TypePredicate {
178
+ readonly kind: TypePredicateKind;
179
+ /** The parameter an identifier predicate names; undefined for a `this` predicate. */
180
+ readonly parameterName: string | undefined;
181
+ readonly parameterIndex: number | undefined;
182
+ /** The asserted type; undefined for `asserts x`. */
183
+ readonly type: Type | undefined;
184
+ }
185
+ /**
186
+ * A diagnostic, with its text and positions as TypeScript 7's API returns them. `fileName` is undefined
187
+ * for global and program diagnostics.
188
+ */
189
+ export interface Diagnostic {
190
+ readonly fileName: string | undefined;
191
+ readonly pos: number;
192
+ readonly end: number;
193
+ readonly code: number;
194
+ readonly category: DiagnosticCategory;
195
+ readonly text: string;
196
+ readonly reportsUnnecessary: boolean;
197
+ readonly reportsDeprecated: boolean;
198
+ readonly messageChain: readonly Diagnostic[];
199
+ readonly relatedInformation: readonly Diagnostic[];
200
+ }
201
+ export interface SourceFileMetadata {
202
+ readonly isDefaultLibrary: boolean;
203
+ readonly isFromExternalLibrary: boolean;
204
+ /** The `type` field of the file's nearest package.json, or '' if it has none. */
205
+ readonly packageJsonType: string;
206
+ /** The directory of the file's nearest package.json, or ''. */
207
+ readonly packageJsonDirectory: string;
208
+ readonly impliedNodeFormat: ModuleKind;
209
+ }
210
+ export interface FileSystemEntries {
211
+ readonly files: readonly string[];
212
+ readonly directories: readonly string[];
213
+ }
214
+ /**
215
+ * Where a program reads files. Each callback may answer undefined to fall back to the real file system;
216
+ * `readFile` answers null for a file that doesn't exist.
217
+ */
218
+ export interface ProgramHost {
219
+ readFile?(fileName: string): string | null | undefined;
220
+ fileExists?(fileName: string): boolean | undefined;
221
+ directoryExists?(directoryName: string): boolean | undefined;
222
+ realpath?(path: string): string | undefined;
223
+ getAccessibleEntries?(directoryName: string): FileSystemEntries | undefined;
224
+ getCurrentDirectory(): string;
225
+ useCaseSensitiveFileNames(): boolean;
226
+ /** The directory with TypeScript 7's `lib.*.d.ts` files. */
227
+ getDefaultLibraryDirectory(): string;
228
+ }
229
+ export interface CreateProgramOptions {
230
+ readonly rootNames: readonly string[];
231
+ readonly options: CompilerOptions;
232
+ readonly host: ProgramHost;
233
+ }
234
+ /** A config file's options and files, as `tsc-ts --api`'s parseConfigFile returns them. */
235
+ export interface ParsedConfigFile {
236
+ readonly options: CompilerOptions;
237
+ readonly fileNames: readonly string[];
238
+ readonly diagnostics: readonly Diagnostic[];
239
+ }
240
+ export interface Program {
241
+ getCompilerOptions(): CompilerOptions;
242
+ getSourceFile(fileName: string): SourceFile | undefined;
243
+ getSourceFiles(): readonly SourceFile[];
244
+ getSourceFileNames(): readonly string[];
245
+ getSourceFileMetadata(fileName: string): SourceFileMetadata | undefined;
246
+ isSourceFileDefaultLibrary(file: SourceFile): boolean;
247
+ isSourceFileFromExternalLibrary(file: SourceFile): boolean;
248
+ /** The program's checker for queries. Queries don't change the diagnostics the program reports. */
249
+ getTypeChecker(): TypeChecker;
250
+ getSyntacticDiagnostics(file?: SourceFile): readonly Diagnostic[];
251
+ getBindDiagnostics(file?: SourceFile): readonly Diagnostic[];
252
+ getSemanticDiagnostics(file?: SourceFile): readonly Diagnostic[];
253
+ getSuggestionDiagnostics(file?: SourceFile): readonly Diagnostic[];
254
+ getDeclarationDiagnostics(file?: SourceFile): readonly Diagnostic[];
255
+ getProgramDiagnostics(): readonly Diagnostic[];
256
+ getGlobalDiagnostics(): readonly Diagnostic[];
257
+ getConfigFileParsingDiagnostics(): readonly Diagnostic[];
258
+ /** Frees the program's checkers. The program and its objects must not be used after. */
259
+ dispose(): void;
260
+ }
261
+ export interface TypeChecker {
262
+ getSymbolAtLocation(node: Node): Symbol | undefined;
263
+ getTypeAtLocation(node: Node): Type | undefined;
264
+ getTypeOfSymbol(symbol: Symbol): Type | undefined;
265
+ getDeclaredTypeOfSymbol(symbol: Symbol): Type;
266
+ /** The type of a symbol as narrowed at `location`. */
267
+ getTypeOfSymbolAtLocation(symbol: Symbol, location: Node): Type;
268
+ getTypeArguments(type: TypeReference): readonly Type[];
269
+ getAliasedSymbol(symbol: Symbol): Symbol;
270
+ getPropertyOfType(type: Type, name: string): Symbol | undefined;
271
+ getPropertiesOfType(type: Type): readonly Symbol[];
272
+ getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[];
273
+ getIndexInfosOfType(type: Type): readonly IndexInfo[];
274
+ getReturnTypeOfSignature(signature: Signature): Type | undefined;
275
+ getTypePredicateOfSignature(signature: Signature): TypePredicate | undefined;
276
+ getSignatureFromDeclaration(node: Node): Signature | undefined;
277
+ getResolvedSignature(node: Node): Signature | undefined;
278
+ getContextualType(node: Expression): Type | undefined;
279
+ getShorthandAssignmentValueSymbol(node: Node): Symbol | undefined;
280
+ getTypeFromTypeNode(node: TypeNode): Type | undefined;
281
+ getBaseTypeOfLiteralType(type: Type): Type | undefined;
282
+ getNonNullableType(type: Type): Type | undefined;
283
+ getBaseTypes(type: InterfaceType): readonly Type[];
284
+ getConstantValue(node: Node): string | number | undefined;
285
+ isArrayType(type: Type): boolean;
286
+ isTupleType(type: Type): boolean;
287
+ isArrayLikeType(type: Type): boolean;
288
+ isTypeAssignableTo(source: Type, target: Type): boolean;
289
+ resolveName(name: string, meaning: SymbolFlags, location?: Node, excludeGlobals?: boolean): Symbol | undefined;
290
+ getResolvedSymbol(node: Identifier): Symbol | undefined;
291
+ /** The text TypeScript 7's API gives for `type`, printed in `enclosingDeclaration` with `flags`. */
292
+ typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
293
+ getAnyType(): Type;
294
+ getUnknownType(): Type;
295
+ getNeverType(): Type;
296
+ getStringType(): Type;
297
+ getNumberType(): Type;
298
+ getBigIntType(): Type;
299
+ getBooleanType(): Type;
300
+ }
@@ -0,0 +1,6 @@
1
+ // The program, checker, symbol, type and signature types of tsc-ts's public API. They follow TypeScript 7's
2
+ // API (`typescript/unstable/sync`): the same names, and the same answers for the same program. The objects
3
+ // are tsc-ts's own: one object per symbol, type and signature in a program, so they can be compared with
4
+ // `===` and used as Map keys. Everything here is read-only: nothing the API does changes what tsc-ts
5
+ // reports for the program.
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsc-ts",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "The TypeScript 7 compiler, ported to TypeScript and compiled to a native executable.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -14,19 +14,29 @@
14
14
  "files": [
15
15
  "bin",
16
16
  "README.md",
17
+ "dist/api",
18
+ "src/library",
17
19
  "THIRD_PARTY_NOTICES.md"
18
20
  ],
19
21
  "type": "module",
22
+ "exports": {
23
+ "./api": {
24
+ "source": "./src/library/index.ts",
25
+ "types": "./dist/api/library/index.d.ts",
26
+ "default": "./dist/api/library/index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
20
30
  "engines": {
21
31
  "node": ">=20"
22
32
  },
23
33
  "optionalDependencies": {
24
- "@tsc-ts/darwin-arm64": "0.0.2",
25
- "@tsc-ts/darwin-x64": "0.0.2",
26
- "@tsc-ts/linux-arm64-gnu": "0.0.2",
27
- "@tsc-ts/linux-arm64-musl": "0.0.2",
28
- "@tsc-ts/linux-x64-gnu": "0.0.2",
29
- "@tsc-ts/linux-x64-musl": "0.0.2",
30
- "@tsc-ts/win32-x64-msvc": "0.0.2"
34
+ "@tsc-ts/darwin-arm64": "0.0.4",
35
+ "@tsc-ts/darwin-x64": "0.0.4",
36
+ "@tsc-ts/linux-arm64-gnu": "0.0.4",
37
+ "@tsc-ts/linux-arm64-musl": "0.0.4",
38
+ "@tsc-ts/linux-x64-gnu": "0.0.4",
39
+ "@tsc-ts/linux-x64-musl": "0.0.4",
40
+ "@tsc-ts/win32-x64-msvc": "0.0.4"
31
41
  }
32
42
  }