tsc-ts 0.1.1 → 0.1.2

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.
Files changed (33) hide show
  1. package/README.md +6 -0
  2. package/dist/api/compiler/ast.d.ts +6 -0
  3. package/dist/api/compiler/ast.js +19 -3
  4. package/dist/api/compiler/checker-grammar.d.ts +39 -4
  5. package/dist/api/compiler/checker-grammar.js +239 -75
  6. package/dist/api/compiler/checker-heritage.js +20 -14
  7. package/dist/api/compiler/checker-modules.js +4 -2
  8. package/dist/api/compiler/checker-source-file.js +1 -1
  9. package/dist/api/compiler/checker-type-factory.js +17 -7
  10. package/dist/api/compiler/checker-type-nodes.d.ts +1 -1
  11. package/dist/api/compiler/checker-type-nodes.js +5 -5
  12. package/dist/api/compiler/checker-unused.js +15 -10
  13. package/dist/api/compiler/checker.d.ts +2 -0
  14. package/dist/api/compiler/checker.js +4 -0
  15. package/dist/api/compiler/file-loader.d.ts +5 -0
  16. package/dist/api/compiler/file-loader.js +7 -0
  17. package/dist/api/compiler/program-checker.d.ts +18 -0
  18. package/dist/api/compiler/program-checker.js +27 -0
  19. package/package.json +14 -9
  20. package/src/compiler/ast.ts +20 -3
  21. package/src/compiler/checker-grammar.ts +247 -88
  22. package/src/compiler/checker-heritage.ts +31 -17
  23. package/src/compiler/checker-modules.ts +4 -2
  24. package/src/compiler/checker-source-file.ts +1 -1
  25. package/src/compiler/checker-type-factory.ts +14 -7
  26. package/src/compiler/checker-type-nodes.ts +5 -5
  27. package/src/compiler/checker-unused.ts +13 -8
  28. package/src/compiler/checker.ts +4 -0
  29. package/src/compiler/file-loader.ts +8 -0
  30. package/src/compiler/parallel-check.ts +11 -0
  31. package/src/compiler/parse-thread.ts +24 -2
  32. package/src/compiler/program-checker.ts +28 -0
  33. package/src/compiler/tsc-compile.ts +10 -1
package/README.md CHANGED
@@ -84,3 +84,9 @@ The program's diagnostics, with their text and positions, are those `tsc --api`
84
84
  An exception the compiler throws while answering a call reaches the caller as an `InternalCompilerError`, with the exception as its `cause`; the program's checker may be inconsistent after one, so dispose of the program. `program.dispose()` frees the program's checkers; calls on the program or its checker after it throw a `DisposedProgramError`.
85
85
 
86
86
  The package has a JavaScript build with declaration files for Node.js, and the TypeScript sources of the API and the compiler (the `source` export condition) for compilers that build it from source. The sources compile with scriptc: a test builds a program on `tsc-ts/api` natively and checks that it answers as the Node build.
87
+
88
+ The API imports `@scriptc/threads`, an optional peer dependency that the command line doesn't use. Install it next to `tsc-ts` to use `tsc-ts/api`:
89
+
90
+ ```bash
91
+ npm install -D tsc-ts @scriptc/threads
92
+ ```
@@ -2327,6 +2327,12 @@ export declare class SourceFile extends Node {
2327
2327
  patternAmbientModules: readonly PatternAmbientModule[];
2328
2328
  /** UMD exports from `export as namespace N`. */
2329
2329
  globalExports: SymbolTable | undefined;
2330
+ /** The diagnostics the parse thread's grammar walk reported for this file. */
2331
+ grammarDiagnostics: Diagnostic[] | undefined;
2332
+ /** The nodes of this file whose grammar check needs the checker, in tree order. */
2333
+ grammarResidualNodes: Node[] | undefined;
2334
+ /** The blocks and statements that reported a statement in an ambient context. */
2335
+ grammarAmbientReports: readonly number[];
2330
2336
  constructor(fileName: string, path: string, text: string, externalModuleIndicatorOptions: ExternalModuleIndicatorOptions, statements: NodeList, endOfFileToken: Token);
2331
2337
  forEachChild(v: NodeVisitor): boolean;
2332
2338
  setParentOfChildren(): void;
@@ -52,9 +52,14 @@ export class NodeVisitor {
52
52
  return this.visitList(list);
53
53
  }
54
54
  }
55
- // Native builds store `pos`, `end` and `id` as 32-bit integers when every write provably stores an
56
- // int32, so writes of values the compiler can't bound (parameters, the id counter) are coerced
57
- // with `| 0`; the values are always int32.
55
+ // Native builds store `pos`, `end` and `id` as 32-bit integers when every write provably stores
56
+ // an int32, so writes of values the compiler can't bound (parameters, the id counter) are
57
+ // coerced with `| 0`; the values are always int32.
58
+ //
59
+ // The fields of a node that the public API's node types declare are stored fields, not values
60
+ // computed from or packed into another field: a native build copies the stored fields of a node
61
+ // into a record when API code narrows one (`node as StringLiteralLike`), and a field behind an
62
+ // accessor is not copied.
58
63
  export class Node {
59
64
  kind;
60
65
  flags;
@@ -6626,6 +6631,7 @@ export const emptyCommentDirectives = [];
6626
6631
  export const emptyPragmas = [];
6627
6632
  export const emptyFileReferences = [];
6628
6633
  export const emptyPatternAmbientModules = [];
6634
+ const emptyNumbers = [];
6629
6635
  /** `list` with `item` appended: a new array when `list` is empty (it may be shared), else `list` itself. */
6630
6636
  export function appendToList(list, item) {
6631
6637
  if (list.length === 0)
@@ -6698,6 +6704,13 @@ export class SourceFile extends Node {
6698
6704
  patternAmbientModules;
6699
6705
  /** UMD exports from `export as namespace N`. */
6700
6706
  globalExports;
6707
+ // Set by the grammar checks of a parse thread (checker-grammar.ts).
6708
+ /** The diagnostics the parse thread's grammar walk reported for this file. */
6709
+ grammarDiagnostics;
6710
+ /** The nodes of this file whose grammar check needs the checker, in tree order. */
6711
+ grammarResidualNodes;
6712
+ /** The blocks and statements that reported a statement in an ambient context. */
6713
+ grammarAmbientReports;
6701
6714
  constructor(fileName, path, text, externalModuleIndicatorOptions, statements, endOfFileToken) {
6702
6715
  super(308 /* SyntaxKind.SourceFile */);
6703
6716
  this.fileName = fileName;
@@ -6744,6 +6757,9 @@ export class SourceFile extends Node {
6744
6757
  this.symbolCount = 0;
6745
6758
  this.patternAmbientModules = emptyPatternAmbientModules;
6746
6759
  this.globalExports = undefined;
6760
+ this.grammarDiagnostics = undefined;
6761
+ this.grammarResidualNodes = undefined;
6762
+ this.grammarAmbientReports = emptyNumbers;
6747
6763
  }
6748
6764
  forEachChild(v) {
6749
6765
  return v.visitList(this.statements) || v.visitNode(this.endOfFileToken);
@@ -1,10 +1,17 @@
1
1
  import { type Node, type NodeList, NodeVisitor, type ObjectLiteralExpression, type SourceFile } from './ast.js';
2
2
  import { type Checker } from './checker.js';
3
- import { ModuleKind } from './options.js';
3
+ import { Diagnostic, type DiagnosticMessage } from './diagnostics.js';
4
+ import { type CompilerOptions, ModuleKind } from './options.js';
4
5
  import { SourceFileMetadata } from './program-utilities.js';
5
6
  import { Scanner } from './scanner.js';
6
7
  /** Runs the grammar checks of every node of `file`. */
7
8
  export declare function checkGrammarSourceFile(c: Checker, file: SourceFile): void;
9
+ /**
10
+ * Runs the grammar checks of `file` in a parse thread, before the file is published: the checks that
11
+ * don't need the checker report now, and the nodes of those that do are kept for the checker, which
12
+ * runs them in the same tree order (`checkGrammarSourceFile`).
13
+ */
14
+ export declare function checkGrammarSourceFileInParseThread(file: SourceFile, options: CompilerOptions, metadata: SourceFileMetadata): void;
8
15
  /** Checks the grammar of an object literal each time it is checked, as tsgo does. */
9
16
  export declare function checkGrammarObjectLiteralOfExpression(c: Checker, node: ObjectLiteralExpression, inDestructuring: boolean): void;
10
17
  /** Reports a trailing comma after the rest element of a destructuring assignment. */
@@ -17,7 +24,10 @@ export declare function checkGrammarAwaitExpression(c: Checker, node: Node): voi
17
24
  export declare function checkGrammarYieldOfExpression(c: Checker, node: Node): void;
18
25
  /** Per-file state of the grammar walk. */
19
26
  export declare class GrammarChecker extends NodeVisitor {
20
- readonly c: Checker;
27
+ /** The checker of a walk in the checker thread; undefined for a walk in a parse thread. */
28
+ readonly c: Checker | undefined;
29
+ readonly compilerOptions: CompilerOptions;
30
+ readonly languageVersion: number;
21
31
  readonly file: SourceFile;
22
32
  /** Grammar errors are only reported in files without parse errors. */
23
33
  readonly hasParseErrors: boolean;
@@ -25,10 +35,35 @@ export declare class GrammarChecker extends NodeVisitor {
25
35
  readonly metadata: SourceFileMetadata;
26
36
  readonly legacyDecorators: boolean;
27
37
  /** Blocks and statements that already reported a statement in an ambient context. */
28
- readonly reportedAmbientStatements: Set<number>;
38
+ reportedAmbientStatements: Set<number>;
39
+ /**
40
+ * The IDs `reportedAmbientStatements` gained in a parse thread's walk, in the order it gained them, so
41
+ * that the reports of a node whose check the checker runs are undone without copying the set.
42
+ * Undefined in the checker thread, where no check is undone.
43
+ */
44
+ private readonly ambientReportLog;
45
+ /**
46
+ * The diagnostics of a walk in a parse thread, which has no checker, for the checker to add to its
47
+ * collection; undefined in the checker thread, where they are reported as they are found.
48
+ */
49
+ readonly diagnostics: Diagnostic[] | undefined;
50
+ /** The nodes of a parse thread's walk whose check needs the checker, in tree order. */
51
+ readonly residualNodes: Node[] | undefined;
52
+ /** Set when the check of a parse thread's walk needs the checker: the checker runs that node. */
53
+ needsChecker: boolean;
29
54
  private scanner;
30
- constructor(c: Checker, file: SourceFile);
55
+ constructor(c: Checker | undefined, file: SourceFile, options?: CompilerOptions, metadata?: SourceFileMetadata,
56
+ /** `file.grammarAmbientReports`: what a parse thread's walk already reported. */
57
+ ambientReports?: readonly number[]);
31
58
  visitNode(node: Node): boolean;
59
+ /** Records that `id` reported a statement in an ambient context. */
60
+ reportAmbientStatement(id: number): void;
61
+ /** Undoes the ambient-context reports added since the log had `mark` entries. */
62
+ private undoAmbientReports;
63
+ /** Reports an error at `node`, as `Checker.error`; returns the diagnostic. */
64
+ error(node: Node | undefined, message: DiagnosticMessage, ...args: string[]): Diagnostic;
65
+ /** Reports `diagnostic`, as `Checker.addDiagnostic`. */
66
+ report(diagnostic: Diagnostic): void;
32
67
  /** A scanner over the file's text, for rescanning tokens. */
33
68
  getScanner(): Scanner;
34
69
  }