ttsc 0.18.3 → 0.19.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.
Files changed (173) hide show
  1. package/README.md +5 -6
  2. package/cmd/graphbench/main.go +1 -1
  3. package/cmd/platform/main.go +1 -48
  4. package/cmd/ttsc/build_branches_test.go +5 -1
  5. package/cmd/ttsc/main.go +0 -50
  6. package/cmd/ttsc/main_alias_branches_test.go +6 -12
  7. package/cmd/ttscgraph/dump.go +13 -3
  8. package/cmd/ttscgraph/main.go +18 -12
  9. package/cmd/ttscgraph/run_help_version_and_bad_flags_exit_codes_test.go +23 -5
  10. package/cmd/ttscgraph/serve.go +863 -0
  11. package/cmd/ttscgraph/serve_protocol_rejects_invalid_request_line_test.go +43 -0
  12. package/cmd/ttscgraph/serve_protocol_retries_session_creation_test.go +83 -0
  13. package/cmd/ttscgraph/serve_protocol_reuses_session_test.go +35 -0
  14. package/cmd/ttscgraph/serve_session_applies_source_edit_incrementally_test.go +55 -0
  15. package/cmd/ttscgraph/serve_session_fails_closed_on_deleted_config_test.go +68 -0
  16. package/cmd/ttscgraph/serve_session_fails_closed_on_invalid_config_test.go +50 -0
  17. package/cmd/ttscgraph/serve_session_keeps_missing_literal_root_unchanged_test.go +46 -0
  18. package/cmd/ttscgraph/serve_session_rebuilds_import_graph_change_test.go +60 -0
  19. package/cmd/ttscgraph/serve_session_reloads_created_literal_root_test.go +44 -0
  20. package/cmd/ttscgraph/serve_session_reloads_extended_config_change_test.go +45 -0
  21. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_conditional_export_test.go +60 -0
  22. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_config_types_test.go +44 -0
  23. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_excluded_import_test.go +62 -0
  24. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_package_export_test.go +46 -0
  25. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_package_import_test.go +46 -0
  26. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_path_alias_test.go +47 -0
  27. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_reference_path_test.go +42 -0
  28. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_root_dirs_target_test.go +46 -0
  29. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_type_reference_test.go +42 -0
  30. package/cmd/ttscgraph/serve_session_reloads_root_file_set_test.go +52 -0
  31. package/cmd/ttscgraph/serve_session_reloads_source_deleted_during_load_test.go +60 -0
  32. package/cmd/ttscgraph/serve_session_reloads_transitive_project_reference_test.go +55 -0
  33. package/cmd/ttscgraph/serve_session_reloads_when_program_plugin_linked_test.go +53 -0
  34. package/cmd/ttscgraph/serve_session_reuses_unchanged_preamble_source_test.go +45 -0
  35. package/cmd/ttscgraph/serve_session_reuses_unchanged_snapshot_test.go +52 -0
  36. package/cmd/ttscgraph/serve_session_revisits_source_edited_during_load_test.go +61 -0
  37. package/cmd/ttscgraph/serve_session_tolerates_os_invalid_resolution_candidate_test.go +56 -0
  38. package/cmd/ttscgraph/serve_session_tracks_all_module_specifier_forms_test.go +41 -0
  39. package/cmd/ttscgraph/serve_session_tracks_diamond_project_references_once_test.go +61 -0
  40. package/cmd/ttscserver/main.go +5 -3
  41. package/driver/lsp.go +13 -1
  42. package/driver/plugins.go +56 -5
  43. package/driver/program.go +25 -10
  44. package/driver/rewrite.go +381 -21
  45. package/driver/session.go +11 -3
  46. package/go.mod +1 -0
  47. package/internal/graph/build.go +297 -3
  48. package/internal/graph/build_records_a_node_per_top_level_declaration_test.go +16 -2
  49. package/internal/graph/diagnostics.go +5 -4
  50. package/internal/graph/dump.go +60 -4
  51. package/internal/graph/dump_is_a_function_of_the_source_test.go +71 -0
  52. package/internal/graph/dump_serializes_the_full_graph_test.go +16 -4
  53. package/internal/graph/edges.go +122 -11
  54. package/internal/graph/exports.go +74 -17
  55. package/internal/graph/graph.go +33 -1
  56. package/internal/graph/node_identity_is_position_invariant_test.go +4 -2
  57. package/internal/graph/resolve.go +24 -0
  58. package/internal/graphsymbols/provider.go +50 -14
  59. package/internal/lspserver/lsp_native_plugin_source.go +77 -23
  60. package/internal/lspserver/lsp_plugin.go +19 -2
  61. package/internal/lspserver/lsp_proxy.go +244 -52
  62. package/internal/lspserver/lsp_server.go +35 -27
  63. package/internal/lspserver/lsp_symbols.go +25 -16
  64. package/lib/TtscCompiler.d.ts +13 -2
  65. package/lib/TtscCompiler.js +30 -20
  66. package/lib/TtscCompiler.js.map +1 -1
  67. package/lib/TtscService.js +9 -7
  68. package/lib/TtscService.js.map +1 -1
  69. package/lib/compiler/internal/compileProjectInMemory.js +15 -1
  70. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  71. package/lib/compiler/internal/project/createNativeProjectContextArgs.d.ts +3 -0
  72. package/lib/compiler/internal/project/createNativeProjectContextArgs.js +14 -0
  73. package/lib/compiler/internal/project/createNativeProjectContextArgs.js.map +1 -0
  74. package/lib/compiler/internal/project/readProjectConfig.js +53 -4
  75. package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
  76. package/lib/compiler/internal/project/resolveProjectConfig.d.ts +9 -2
  77. package/lib/compiler/internal/project/resolveProjectConfig.js +45 -16
  78. package/lib/compiler/internal/project/resolveProjectConfig.js.map +1 -1
  79. package/lib/compiler/internal/residentTransformProcess.d.ts +16 -5
  80. package/lib/compiler/internal/residentTransformProcess.js +68 -20
  81. package/lib/compiler/internal/residentTransformProcess.js.map +1 -1
  82. package/lib/compiler/internal/runBuild.d.ts +18 -0
  83. package/lib/compiler/internal/runBuild.js +220 -24
  84. package/lib/compiler/internal/runBuild.js.map +1 -1
  85. package/lib/compiler/internal/runSingleFileEmit.js +7 -4
  86. package/lib/compiler/internal/runSingleFileEmit.js.map +1 -1
  87. package/lib/compiler/internal/sharedHostHelpers.d.ts +16 -0
  88. package/lib/compiler/internal/sharedHostHelpers.js +23 -0
  89. package/lib/compiler/internal/sharedHostHelpers.js.map +1 -1
  90. package/lib/compiler/internal/startResidentTransform.js +18 -1
  91. package/lib/compiler/internal/startResidentTransform.js.map +1 -1
  92. package/lib/compiler/internal/transformProjectInMemory.js +34 -8
  93. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
  94. package/lib/flags/parser.d.ts +17 -0
  95. package/lib/flags/parser.js +11 -1
  96. package/lib/flags/parser.js.map +1 -1
  97. package/lib/flags/schema.js +7 -0
  98. package/lib/flags/schema.js.map +1 -1
  99. package/lib/launcher/internal/prepareExecution.js +21 -2
  100. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  101. package/lib/launcher/internal/runTtsc.js +13 -53
  102. package/lib/launcher/internal/runTtsc.js.map +1 -1
  103. package/lib/launcher/internal/runTtscserver.js +11 -0
  104. package/lib/launcher/internal/runTtscserver.js.map +1 -1
  105. package/lib/launcher/internal/runTtsx.js +27 -11
  106. package/lib/launcher/internal/runTtsx.js.map +1 -1
  107. package/lib/launcher/internal/runtimeHooks.d.ts +81 -0
  108. package/lib/launcher/internal/runtimeHooks.js +632 -43
  109. package/lib/launcher/internal/runtimeHooks.js.map +1 -1
  110. package/lib/launcher/internal/servedSourceMap.d.ts +25 -0
  111. package/lib/launcher/internal/servedSourceMap.js +164 -0
  112. package/lib/launcher/internal/servedSourceMap.js.map +1 -0
  113. package/lib/plugin/internal/buildSourcePlugin.d.ts +146 -2
  114. package/lib/plugin/internal/buildSourcePlugin.js +651 -113
  115. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
  116. package/lib/plugin/internal/loadProjectPlugins.d.ts +7 -0
  117. package/lib/plugin/internal/loadProjectPlugins.js +33 -10
  118. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
  119. package/lib/structures/ITtscCompilerContext.d.ts +16 -2
  120. package/lib/structures/ITtscCompilerResult.d.ts +8 -5
  121. package/lib/structures/ITtscPluginCapabilities.d.ts +8 -0
  122. package/lib/structures/ITtscPluginFactoryContext.d.ts +14 -0
  123. package/lib/structures/internal/ITtscParsedProjectConfig.d.ts +3 -0
  124. package/lib/structures/internal/ITtscProjectIdentity.d.ts +17 -0
  125. package/lib/structures/internal/ITtscProjectIdentity.js +3 -0
  126. package/lib/structures/internal/ITtscProjectIdentity.js.map +1 -0
  127. package/lib/structures/internal/TtscCommonOptions.d.ts +8 -0
  128. package/package.json +11 -8
  129. package/shim/ast/lint.go +10 -0
  130. package/shim/ast/shim.go +44 -0
  131. package/shim/checker/enums_gen.go +19 -0
  132. package/shim/checker/shim.go +130 -0
  133. package/shim/diagnosticwriter/lint.go +30 -3
  134. package/shim/printer/shim.go +22 -4
  135. package/shim/scanner/regexp.go +27 -0
  136. package/src/TtscCompiler.ts +29 -22
  137. package/src/TtscService.ts +15 -7
  138. package/src/compiler/internal/compileProjectInMemory.ts +18 -1
  139. package/src/compiler/internal/project/createNativeProjectContextArgs.ts +15 -0
  140. package/src/compiler/internal/project/readProjectConfig.ts +61 -5
  141. package/src/compiler/internal/project/resolveProjectConfig.ts +51 -21
  142. package/src/compiler/internal/residentTransformProcess.ts +95 -21
  143. package/src/compiler/internal/runBuild.ts +313 -32
  144. package/src/compiler/internal/runSingleFileEmit.ts +7 -4
  145. package/src/compiler/internal/sharedHostHelpers.ts +24 -0
  146. package/src/compiler/internal/startResidentTransform.ts +21 -1
  147. package/src/compiler/internal/transformProjectInMemory.ts +49 -6
  148. package/src/flags/parser.ts +28 -1
  149. package/src/flags/schema.ts +8 -0
  150. package/src/launcher/internal/prepareExecution.ts +22 -2
  151. package/src/launcher/internal/runTtsc.ts +13 -61
  152. package/src/launcher/internal/runTtscserver.ts +14 -0
  153. package/src/launcher/internal/runTtsx.ts +28 -13
  154. package/src/launcher/internal/runtimeHooks.ts +771 -53
  155. package/src/launcher/internal/servedSourceMap.ts +183 -0
  156. package/src/plugin/internal/buildSourcePlugin.ts +859 -122
  157. package/src/plugin/internal/loadProjectPlugins.ts +36 -6
  158. package/src/structures/ITtscCompilerContext.ts +17 -2
  159. package/src/structures/ITtscCompilerResult.ts +8 -5
  160. package/src/structures/ITtscPluginCapabilities.ts +9 -0
  161. package/src/structures/ITtscPluginFactoryContext.ts +15 -0
  162. package/src/structures/internal/ITtscParsedProjectConfig.ts +3 -0
  163. package/src/structures/internal/ITtscProjectIdentity.ts +17 -0
  164. package/src/structures/internal/TtscCommonOptions.ts +8 -0
  165. package/tools/shim_audit/baseline.json +16 -7
  166. package/tools/shim_audit/main.go +777 -71
  167. package/tools/shim_audit/main_test.go +28 -1
  168. package/tools/shim_audit/producer_exemptions_require_rationale_test.go +42 -0
  169. package/tools/shim_audit/producer_surface_includes_exposed_methods_test.go +154 -0
  170. package/tools/shim_audit/producer_surface_rejects_unproducible_reference_test.go +142 -0
  171. package/utility/host.go +46 -20
  172. package/utility/serve.go +1 -1
  173. package/shim/checker/signature_api_completeness.go +0 -58
@@ -39,12 +39,14 @@ export declare namespace ITtscCompilerResult {
39
39
  output: Record<string, string>;
40
40
  }
41
41
  /**
42
- * Represents a ttsc compilation that completed but had diagnostics.
42
+ * Represents a ttsc compilation that completed with diagnostics or a
43
+ * recoverable plugin failure.
43
44
  *
44
45
  * This interface is returned when the compiler reports errors, warnings, or
45
- * other diagnostics during normal compilation. It contains both structured
46
- * diagnostic information and any output that was still generated despite the
47
- * diagnostics.
46
+ * other diagnostics during normal compilation, or when a plugin failure can
47
+ * be retained as a build result while an independent TypeScript check runs.
48
+ * It contains both structured diagnostic information and any output that was
49
+ * still generated despite the failure.
48
50
  */
49
51
  interface IFailure {
50
52
  /** Indicates that compilation completed with diagnostics. */
@@ -74,7 +76,8 @@ export declare namespace ITtscCompilerResult {
74
76
  * pattern-matching error messages. Omitted when ttsc cannot determine the
75
77
  * origin. Treat as `"unknown"` when missing.
76
78
  *
77
- * - `"plugin"`: a native plugin sidecar crashed or exited non-zero.
79
+ * - `"plugin"`: plugin preparation failed before a build result could be
80
+ * recovered.
78
81
  * - `"host"`: the TypeScript-Go host could not start (missing binary, cache
79
82
  * lock, invalid config).
80
83
  * - `"unknown"`: any other host-level failure.
@@ -35,6 +35,14 @@ export interface ITtscPluginCapabilities {
35
35
  * @default false
36
36
  */
37
37
  lsp?: boolean;
38
+ /**
39
+ * Whether the sidecar accepts ttsc's `--project-context-json` identity
40
+ * protocol. The payload keeps lexical selection paths, physical Program
41
+ * paths, and explicit overrides as separate fields.
42
+ *
43
+ * @default false
44
+ */
45
+ projectContextArgs?: boolean;
38
46
  /**
39
47
  * Whether the sidecar accepts `--singleThreaded` and `--checkers` on its
40
48
  * command line. The lint sidecar parses both flags via `parseSubcommandFlags`
@@ -60,6 +60,20 @@ export interface ITtscPluginFactoryContext<T = ITtscProjectPluginConfig> {
60
60
  * plugin manifest.
61
61
  */
62
62
  plugin: T;
63
+ /**
64
+ * Caller-declared anchor for plugin config-file discovery and relative
65
+ * `configFile` resolution.
66
+ *
67
+ * Absent for ordinary invocations, where a factory anchors config discovery
68
+ * at the {@link ITtscPluginFactoryContext.tsconfig} directory. Present when
69
+ * the embedder compiles through a generated tsconfig outside the project (the
70
+ * bundler adapters' alias overlay): it names the real project directory, and
71
+ * a factory that discovers its own config file should anchor there instead of
72
+ * the generated tsconfig's temp-dir ancestry. Mirrors the
73
+ * `TTSC_PLUGIN_CONFIG_DIR` environment variable ttsc sets for native plugin
74
+ * processes.
75
+ */
76
+ pluginConfigDir?: string;
63
77
  /**
64
78
  * Project root used as the native plugin working directory and package
65
79
  * discovery base.
@@ -1,4 +1,5 @@
1
1
  import type { ITtscProjectPluginConfig } from "../ITtscProjectPluginConfig";
2
+ import type { ITtscProjectIdentity } from "./ITtscProjectIdentity";
2
3
  /** Resolved project config subset used inside the ttsc host. */
3
4
  export interface ITtscParsedProjectConfig {
4
5
  /** Compiler options after extends inheritance has been applied. */
@@ -8,6 +9,8 @@ export interface ITtscParsedProjectConfig {
8
9
  /** Project plugin entries after inheritance resolution. */
9
10
  plugins: ITtscProjectPluginConfig[];
10
11
  } & Record<string, unknown>;
12
+ /** Lexical and physical identities retained for native plugin contexts. */
13
+ identity: Omit<ITtscProjectIdentity, "pluginConfigOrigin">;
11
14
  /** Absolute path to the resolved tsconfig/jsconfig. */
12
15
  path: string;
13
16
  /** Directory that declared each inherited plugin entry. */
@@ -0,0 +1,17 @@
1
+ /** Separate lexical and physical identities for one selected project. */
2
+ export interface ITtscProjectIdentity {
3
+ /** Caller working directory before filesystem canonicalization. */
4
+ invocationCwd: string;
5
+ /** Caller-selected config spelling before filesystem canonicalization. */
6
+ logicalConfigPath: string;
7
+ /** Directory containing the caller-selected config spelling. */
8
+ logicalProjectRoot: string;
9
+ /** Realpath-resolved config used to load the TypeScript Program. */
10
+ physicalConfigPath: string;
11
+ /** Realpath-resolved root supplied to the TypeScript Program host. */
12
+ physicalProjectRoot: string;
13
+ /** Caller-declared project-root override, when present. */
14
+ explicitProjectRoot?: string;
15
+ /** Caller-declared plugin-config discovery origin, when present. */
16
+ pluginConfigOrigin?: string;
17
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ITtscProjectIdentity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ITtscProjectIdentity.js","sourceRoot":"","sources":["../../../src/structures/internal/ITtscProjectIdentity.ts"],"names":[],"mappings":""}
@@ -15,6 +15,14 @@ export interface TtscCommonOptions {
15
15
  cwd?: string;
16
16
  /** Project root override for generated tsconfig wrappers. */
17
17
  projectRoot?: string;
18
+ /**
19
+ * Directory that anchors plugin config-file discovery and relative
20
+ * `configFile` resolution (forwarded to plugin processes as
21
+ * `TTSC_PLUGIN_CONFIG_DIR`). Set by build integrations that compile through a
22
+ * generated tsconfig outside the project; when omitted, plugins anchor at the
23
+ * tsconfig's own directory.
24
+ */
25
+ pluginConfigDir?: string;
18
26
  /** Environment variables merged over `process.env` for child processes. */
19
27
  env?: NodeJS.ProcessEnv;
20
28
  /** Explicit root directory for compiled source-plugin cache artifacts. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ttsc",
3
- "version": "0.18.3",
3
+ "version": "0.19.0",
4
4
  "description": "General-purpose TypeScript-Go compiler, runtime, plugin host, and LSP host.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -22,6 +22,9 @@
22
22
  },
23
23
  "author": "Jeongho Nam",
24
24
  "license": "MIT",
25
+ "engines": {
26
+ "node": ">=22.15.0"
27
+ },
25
28
  "bugs": {
26
29
  "url": "https://github.com/samchon/ttsc/issues"
27
30
  },
@@ -32,13 +35,13 @@
32
35
  "typescript": "^7.0.2"
33
36
  },
34
37
  "optionalDependencies": {
35
- "@ttsc/linux-x64": "0.18.3",
36
- "@ttsc/linux-arm": "0.18.3",
37
- "@ttsc/linux-arm64": "0.18.3",
38
- "@ttsc/darwin-arm64": "0.18.3",
39
- "@ttsc/win32-x64": "0.18.3",
40
- "@ttsc/win32-arm64": "0.18.3",
41
- "@ttsc/darwin-x64": "0.18.3"
38
+ "@ttsc/linux-x64": "0.19.0",
39
+ "@ttsc/darwin-x64": "0.19.0",
40
+ "@ttsc/linux-arm64": "0.19.0",
41
+ "@ttsc/darwin-arm64": "0.19.0",
42
+ "@ttsc/linux-arm": "0.19.0",
43
+ "@ttsc/win32-x64": "0.19.0",
44
+ "@ttsc/win32-arm64": "0.19.0"
42
45
  },
43
46
  "sideEffects": false,
44
47
  "files": [
package/shim/ast/lint.go CHANGED
@@ -322,6 +322,16 @@ func GetCombinedNodeFlags(node *Node) NodeFlags {
322
322
  return innerast.GetCombinedNodeFlags(node)
323
323
  }
324
324
 
325
+ // IsConstAssertion reports whether node is an `as const` or `<const>`
326
+ // assertion. Unlike ordinary type assertions, a const assertion propagates
327
+ // its own contextual type to the asserted expression.
328
+ func IsConstAssertion(node *Node) bool { return innerast.IsConstAssertion(node) }
329
+
330
+ // IsPartOfTypeNode reports whether node belongs to syntax that is evaluated
331
+ // only by the type system. Lint rules use the upstream classifier so runtime
332
+ // reference analysis stays aligned with TypeScript's AST semantics.
333
+ func IsPartOfTypeNode(node *Node) bool { return innerast.IsPartOfTypeNode(node) }
334
+
325
335
  // IsLet reports whether the declaration was introduced by `let` / `using`.
326
336
  func IsLet(node *Node) bool { return GetCombinedNodeFlags(node)&NodeFlagsLet != 0 }
327
337
 
package/shim/ast/shim.go CHANGED
@@ -177,6 +177,42 @@ const (
177
177
  ModifierFlagsReadonly = innerast.ModifierFlagsReadonly
178
178
  )
179
179
 
180
+ // OperatorPrecedence members. The complete family is re-exported by hand so
181
+ // precedence comparisons (e.g. a lint fixer deciding whether a spliced
182
+ // replacement must be parenthesized) can name every level of the
183
+ // OperatorPrecedence type aliased in surface.go; a partial re-export would
184
+ // trip the shim_audit zero-tolerance enum gate.
185
+ const (
186
+ OperatorPrecedenceComma = innerast.OperatorPrecedenceComma
187
+ OperatorPrecedenceSpread = innerast.OperatorPrecedenceSpread
188
+ OperatorPrecedenceYield = innerast.OperatorPrecedenceYield
189
+ OperatorPrecedenceAssignment = innerast.OperatorPrecedenceAssignment
190
+ OperatorPrecedenceConditional = innerast.OperatorPrecedenceConditional
191
+ OperatorPrecedenceLogicalOR = innerast.OperatorPrecedenceLogicalOR
192
+ OperatorPrecedenceLogicalAND = innerast.OperatorPrecedenceLogicalAND
193
+ OperatorPrecedenceBitwiseOR = innerast.OperatorPrecedenceBitwiseOR
194
+ OperatorPrecedenceBitwiseXOR = innerast.OperatorPrecedenceBitwiseXOR
195
+ OperatorPrecedenceBitwiseAND = innerast.OperatorPrecedenceBitwiseAND
196
+ OperatorPrecedenceEquality = innerast.OperatorPrecedenceEquality
197
+ OperatorPrecedenceRelational = innerast.OperatorPrecedenceRelational
198
+ OperatorPrecedenceShift = innerast.OperatorPrecedenceShift
199
+ OperatorPrecedenceAdditive = innerast.OperatorPrecedenceAdditive
200
+ OperatorPrecedenceMultiplicative = innerast.OperatorPrecedenceMultiplicative
201
+ OperatorPrecedenceExponentiation = innerast.OperatorPrecedenceExponentiation
202
+ OperatorPrecedenceUnary = innerast.OperatorPrecedenceUnary
203
+ OperatorPrecedenceUpdate = innerast.OperatorPrecedenceUpdate
204
+ OperatorPrecedenceLeftHandSide = innerast.OperatorPrecedenceLeftHandSide
205
+ OperatorPrecedenceOptionalChain = innerast.OperatorPrecedenceOptionalChain
206
+ OperatorPrecedenceMember = innerast.OperatorPrecedenceMember
207
+ OperatorPrecedencePrimary = innerast.OperatorPrecedencePrimary
208
+ OperatorPrecedenceParentheses = innerast.OperatorPrecedenceParentheses
209
+ OperatorPrecedenceLowest = innerast.OperatorPrecedenceLowest
210
+ OperatorPrecedenceHighest = innerast.OperatorPrecedenceHighest
211
+ OperatorPrecedenceDisallowComma = innerast.OperatorPrecedenceDisallowComma
212
+ OperatorPrecedenceCoalesce = innerast.OperatorPrecedenceCoalesce
213
+ OperatorPrecedenceInvalid = innerast.OperatorPrecedenceInvalid
214
+ )
215
+
180
216
  // NewNodeFactory creates an AST node factory with the supplied creation hooks.
181
217
  // Pass a zero-value NodeFactoryHooks to get the default factory behaviour.
182
218
  func NewNodeFactory(options NodeFactoryHooks) *NodeFactory {
@@ -195,6 +231,14 @@ func GetCombinedModifierFlags(node *Node) ModifierFlags {
195
231
  return innerast.GetCombinedModifierFlags(node)
196
232
  }
197
233
 
234
+ // GetExpressionPrecedence returns the operator precedence of an expression
235
+ // node — the level at which it binds relative to a surrounding expression.
236
+ // Callers compare it against an OperatorPrecedence floor to decide whether a
237
+ // textual splice of the expression into a new position needs parentheses.
238
+ func GetExpressionPrecedence(expression *Expression) OperatorPrecedence {
239
+ return innerast.GetExpressionPrecedence(expression)
240
+ }
241
+
198
242
  // IsFunctionLike reports whether node is any function-like construct
199
243
  // (function declaration, arrow function, method, constructor, accessor, etc.).
200
244
  func IsFunctionLike(node *Node) bool {
@@ -15,6 +15,25 @@ const (
15
15
  ElementFlagsNonRequired = innerchecker.ElementFlagsNonRequired
16
16
  ElementFlagsNonRest = innerchecker.ElementFlagsNonRest
17
17
  ElementFlagsVariable = innerchecker.ElementFlagsVariable
18
+ IterationTypeKindNext = innerchecker.IterationTypeKindNext
19
+ IterationTypeKindReturn = innerchecker.IterationTypeKindReturn
20
+ IterationUseAllowsAsyncIterablesFlag = innerchecker.IterationUseAllowsAsyncIterablesFlag
21
+ IterationUseAllowsStringInputFlag = innerchecker.IterationUseAllowsStringInputFlag
22
+ IterationUseAllowsSyncIterablesFlag = innerchecker.IterationUseAllowsSyncIterablesFlag
23
+ IterationUseAsyncGeneratorReturnType = innerchecker.IterationUseAsyncGeneratorReturnType
24
+ IterationUseAsyncYieldStar = innerchecker.IterationUseAsyncYieldStar
25
+ IterationUseCacheFlags = innerchecker.IterationUseCacheFlags
26
+ IterationUseDestructuring = innerchecker.IterationUseDestructuring
27
+ IterationUseDestructuringFlag = innerchecker.IterationUseDestructuringFlag
28
+ IterationUseForAwaitOf = innerchecker.IterationUseForAwaitOf
29
+ IterationUseForOf = innerchecker.IterationUseForOf
30
+ IterationUseForOfFlag = innerchecker.IterationUseForOfFlag
31
+ IterationUseGeneratorReturnType = innerchecker.IterationUseGeneratorReturnType
32
+ IterationUsePossiblyOutOfBounds = innerchecker.IterationUsePossiblyOutOfBounds
33
+ IterationUseSpread = innerchecker.IterationUseSpread
34
+ IterationUseSpreadFlag = innerchecker.IterationUseSpreadFlag
35
+ IterationUseYieldStar = innerchecker.IterationUseYieldStar
36
+ IterationUseYieldStarFlag = innerchecker.IterationUseYieldStarFlag
18
37
  ObjectFlagsAnonymous = innerchecker.ObjectFlagsAnonymous
19
38
  ObjectFlagsArrayLiteral = innerchecker.ObjectFlagsArrayLiteral
20
39
  ObjectFlagsContainsIntersections = innerchecker.ObjectFlagsContainsIntersections
@@ -9,8 +9,11 @@
9
9
  package checker
10
10
 
11
11
  import (
12
+ "sync"
13
+
12
14
  innerast "github.com/microsoft/typescript-go/internal/ast"
13
15
  innerchecker "github.com/microsoft/typescript-go/internal/checker"
16
+ innerprinter "github.com/microsoft/typescript-go/internal/printer"
14
17
  _ "unsafe"
15
18
  )
16
19
 
@@ -22,6 +25,80 @@ type Type = innerchecker.Type
22
25
  type TypeFlags = innerchecker.TypeFlags
23
26
  type ObjectFlags = innerchecker.ObjectFlags
24
27
  type ElementFlags = innerchecker.ElementFlags
28
+ type Program = innerchecker.Program
29
+ type Tracer = innerchecker.Tracer
30
+
31
+ // NewChecker creates a checker that owns its complete type graph for program.
32
+ // The returned mutex is the upstream checker-pool synchronization primitive;
33
+ // callers that share the checker must serialize access through it.
34
+ func NewChecker(program Program, tracer *Tracer) (*Checker, *sync.Mutex) {
35
+ return innerchecker.NewChecker(program, tracer)
36
+ }
37
+
38
+ //go:linkname checkerGetRegularTypeOfLiteralType github.com/microsoft/typescript-go/internal/checker.(*Checker).getRegularTypeOfLiteralType
39
+ func checkerGetRegularTypeOfLiteralType(recv *innerchecker.Checker, t *innerchecker.Type) *innerchecker.Type
40
+
41
+ // Checker_getRegularTypeOfLiteralType returns the canonical regular form of a
42
+ // literal type. TypeScript's checker uses this before comparing switch case
43
+ // types because a source literal's fresh type and a union member's regular type
44
+ // denote the same runtime value but have different pointers.
45
+ func Checker_getRegularTypeOfLiteralType(recv *innerchecker.Checker, t *innerchecker.Type) *innerchecker.Type {
46
+ if recv == nil || t == nil {
47
+ return t
48
+ }
49
+ return checkerGetRegularTypeOfLiteralType(recv, t)
50
+ }
51
+
52
+ // Checker_typeToStringFullyQualified formats a type with the same stable,
53
+ // alias-aware flags TypeScript uses in diagnostics that name union members.
54
+ // Keeping the flag bundle inside the shim avoids leaking checker-internal enum
55
+ // types through consumer code.
56
+ func Checker_typeToStringFullyQualified(recv *innerchecker.Checker, t *innerchecker.Type, enclosingDeclaration *innerast.Node) string {
57
+ if recv == nil || t == nil {
58
+ return ""
59
+ }
60
+ return recv.TypeToStringEx(
61
+ t,
62
+ enclosingDeclaration,
63
+ innerchecker.TypeFormatFlagsAllowUniqueESSymbolType|
64
+ innerchecker.TypeFormatFlagsUseAliasDefinedOutsideCurrentScope|
65
+ innerchecker.TypeFormatFlagsUseFullyQualifiedType,
66
+ nil,
67
+ )
68
+ }
69
+
70
+ // Checker_symbolToValueString formats a symbol as a value-position expression
71
+ // at enclosingDeclaration. AllowAnyNodeKind lets the checker emit indexed
72
+ // access for enum members whose names cannot use dot notation.
73
+ func Checker_symbolToValueString(recv *innerchecker.Checker, symbol *innerast.Symbol, enclosingDeclaration *innerast.Node) string {
74
+ if recv == nil || symbol == nil {
75
+ return ""
76
+ }
77
+ return recv.SymbolToStringEx(
78
+ symbol,
79
+ enclosingDeclaration,
80
+ innerast.SymbolFlagsValue,
81
+ innerchecker.SymbolFormatFlagsAllowAnyNodeKind,
82
+ )
83
+ }
84
+
85
+ // Checker_isSymbolAccessibleAsValue verifies that SymbolToStringEx can name a
86
+ // symbol from enclosingDeclaration. Unlike GetAccessibleSymbolChain, the
87
+ // checker also follows containing enum, class, and namespace symbols, so a
88
+ // qualified member such as Domain.Mode.Done is accepted when its container is
89
+ // visible.
90
+ func Checker_isSymbolAccessibleAsValue(recv *innerchecker.Checker, symbol *innerast.Symbol, enclosingDeclaration *innerast.Node) bool {
91
+ if recv == nil || symbol == nil || enclosingDeclaration == nil {
92
+ return false
93
+ }
94
+ result := recv.IsSymbolAccessible(
95
+ symbol,
96
+ enclosingDeclaration,
97
+ innerast.SymbolFlagsValue,
98
+ false,
99
+ )
100
+ return result.Accessibility == innerprinter.SymbolAccessibilityAccessible
101
+ }
25
102
 
26
103
  const (
27
104
  SignatureKindCall = innerchecker.SignatureKindCall
@@ -110,6 +187,59 @@ func Checker_getTypeOfPropertyOfType(recv *innerchecker.Checker, t *innerchecker
110
187
  return recv.GetTypeOfPropertyOfType(t, name)
111
188
  }
112
189
 
190
+ //go:linkname checkerGetPropertyNameForKnownSymbolName github.com/microsoft/typescript-go/internal/checker.(*Checker).getPropertyNameForKnownSymbolName
191
+ func checkerGetPropertyNameForKnownSymbolName(recv *innerchecker.Checker, symbolName string) string
192
+
193
+ // Checker_getPropertyNameForKnownSymbolName returns the late-bound property
194
+ // name the checker uses for a member keyed by the global well-known symbol
195
+ // `Symbol.<symbolName>` (e.g. "asyncIterator", "asyncDispose", "iterator").
196
+ // It resolves the unique-symbol type of that property on the global
197
+ // `SymbolConstructor` — including lib-provided and `declare global` augmented
198
+ // members — so `(*Checker).GetPropertyOfType(t, name)` with the returned name
199
+ // finds exactly the members declared as `[Symbol.<symbolName>]`. This is the
200
+ // same resolution the checker itself performs when it validates `for await`
201
+ // iterability, which is why a lint rule that mirrors typescript-eslint's
202
+ // well-known-symbol protocol checks must go through it instead of matching
203
+ // property-name text. When the global `Symbol` constructor lacks the member,
204
+ // the checker's internal fallback name (a `\xFE@`-prefixed string no
205
+ // source-declared property can late-bind to) is returned, so lookups simply
206
+ // find nothing. Returns "" if recv is nil.
207
+ func Checker_getPropertyNameForKnownSymbolName(recv *innerchecker.Checker, symbolName string) string {
208
+ if recv == nil {
209
+ return ""
210
+ }
211
+ return checkerGetPropertyNameForKnownSymbolName(recv, symbolName)
212
+ }
213
+
214
+ //go:linkname checkerGetIterationTypeOfIterable github.com/microsoft/typescript-go/internal/checker.(*Checker).getIterationTypeOfIterable
215
+ func checkerGetIterationTypeOfIterable(
216
+ recv *innerchecker.Checker,
217
+ use innerchecker.IterationUse,
218
+ typeKind innerchecker.IterationTypeKind,
219
+ inputType *innerchecker.Type,
220
+ errorNode *innerast.Node,
221
+ ) *innerchecker.Type
222
+
223
+ // Checker_getSynchronousIterationYieldType returns the value type produced by
224
+ // inputType's checked `[Symbol.iterator]` protocol. It delegates to the same
225
+ // TypeScript-Go traversal used for synchronous iteration, including inherited
226
+ // and structural iterables, instantiated iterator returns, intersections, and
227
+ // primitive strings. A nil result means the checker could not derive a valid
228
+ // synchronous iteration type. Diagnostics are intentionally disabled because
229
+ // callers use this as a type query after normal TypeScript checking.
230
+ func Checker_getSynchronousIterationYieldType(recv *innerchecker.Checker, inputType *innerchecker.Type) *innerchecker.Type {
231
+ if recv == nil || inputType == nil {
232
+ return nil
233
+ }
234
+ return checkerGetIterationTypeOfIterable(
235
+ recv,
236
+ innerchecker.IterationUseElement,
237
+ innerchecker.IterationTypeKindYield,
238
+ inputType,
239
+ nil,
240
+ )
241
+ }
242
+
113
243
  //go:linkname checkerGetAliasSymbolForTypeNode github.com/microsoft/typescript-go/internal/checker.(*Checker).getAliasSymbolForTypeNode
114
244
  func checkerGetAliasSymbolForTypeNode(recv *innerchecker.Checker, node *innerast.Node) *innerast.Symbol
115
245
 
@@ -30,6 +30,35 @@ const (
30
30
  LintCategoryError
31
31
  )
32
32
 
33
+ // NormalizeLintRange returns a renderer-safe half-open source span. Diagnostic
34
+ // producers are a plugin trust boundary, so offsets are clamped even when the
35
+ // caller's contract says they point inside the current file. Reversed and
36
+ // zero-width ranges select one byte when one exists at pos; EOF and empty-file
37
+ // ranges remain zero-width instead of manufacturing a byte past the source.
38
+ func NormalizeLintRange(file *ast.SourceFile, pos, end int) (int, int) {
39
+ if file == nil {
40
+ return 0, 0
41
+ }
42
+ sourceLen := len(file.Text())
43
+ if pos < 0 {
44
+ pos = 0
45
+ } else if pos > sourceLen {
46
+ pos = sourceLen
47
+ }
48
+ if end < 0 {
49
+ end = 0
50
+ } else if end > sourceLen {
51
+ end = sourceLen
52
+ }
53
+ if end <= pos {
54
+ end = pos
55
+ if pos < sourceLen {
56
+ end++
57
+ }
58
+ }
59
+ return pos, end
60
+ }
61
+
33
62
  // LintDiagnostic is a public, plugin-emittable diagnostic shaped like the
34
63
  // `internal/diagnosticwriter.Diagnostic` interface. The internal type is
35
64
  // unexported, so this is the only way to mix lint output with tsgo's own
@@ -47,9 +76,7 @@ type LintDiagnostic struct {
47
76
  // supplied source file. `code` shows up in the rendered banner — the
48
77
  // convention is to give each rule its own stable integer.
49
78
  func NewLintDiagnostic(file *ast.SourceFile, pos, end int, code int32, category LintCategory, message string) *LintDiagnostic {
50
- if end <= pos {
51
- end = pos + 1
52
- }
79
+ pos, end = NormalizeLintRange(file, pos, end)
53
80
  return &LintDiagnostic{
54
81
  file: file,
55
82
  pos: pos,
@@ -1,7 +1,6 @@
1
- // Package printer re-exports the typescript-go internal/printer types and
2
- // wraps the three functions that the ttsc driver and transform plugins need
3
- // to emit source text from an AST. The surface is intentionally narrow: only
4
- // the construction and single-file emit path are exposed.
1
+ // Package printer re-exports the typescript-go internal/printer types that the
2
+ // ttsc driver and transform plugins need to emit source text and allocate
3
+ // collision-safe generated identifiers. The surface is intentionally narrow.
5
4
  package printer
6
5
 
7
6
  import (
@@ -24,6 +23,25 @@ type PrinterOptions = innerprinter.PrinterOptions
24
23
  // and must be created fresh for each emit round via NewEmitContext.
25
24
  type EmitContext = innerprinter.EmitContext
26
25
 
26
+ // AutoGenerateOptions configures how NodeFactory allocates generated names.
27
+ type AutoGenerateOptions = innerprinter.AutoGenerateOptions
28
+
29
+ // GeneratedIdentifierFlags controls generated-name scope and collision checks.
30
+ type GeneratedIdentifierFlags = innerprinter.GeneratedIdentifierFlags
31
+
32
+ const (
33
+ GeneratedIdentifierFlagsNone = innerprinter.GeneratedIdentifierFlagsNone
34
+ GeneratedIdentifierFlagsAuto = innerprinter.GeneratedIdentifierFlagsAuto
35
+ GeneratedIdentifierFlagsLoop = innerprinter.GeneratedIdentifierFlagsLoop
36
+ GeneratedIdentifierFlagsUnique = innerprinter.GeneratedIdentifierFlagsUnique
37
+ GeneratedIdentifierFlagsNode = innerprinter.GeneratedIdentifierFlagsNode
38
+ GeneratedIdentifierFlagsKindMask = innerprinter.GeneratedIdentifierFlagsKindMask
39
+ GeneratedIdentifierFlagsReservedInNestedScopes = innerprinter.GeneratedIdentifierFlagsReservedInNestedScopes
40
+ GeneratedIdentifierFlagsOptimistic = innerprinter.GeneratedIdentifierFlagsOptimistic
41
+ GeneratedIdentifierFlagsFileLevel = innerprinter.GeneratedIdentifierFlagsFileLevel
42
+ GeneratedIdentifierFlagsAllowNameSubstitution = innerprinter.GeneratedIdentifierFlagsAllowNameSubstitution
43
+ )
44
+
27
45
  // NewPrinter creates an emitter with the supplied options, substitution hooks,
28
46
  // and emit context. Callers must pass the same EmitContext to all operations
29
47
  // in a single emit round.
@@ -0,0 +1,27 @@
1
+ package scanner
2
+
3
+ import (
4
+ "github.com/microsoft/typescript-go/internal/ast"
5
+ "github.com/microsoft/typescript-go/internal/diagnostics"
6
+ )
7
+
8
+ // IsValidRegularExpressionLiteral reports whether text is one complete,
9
+ // grammar-valid ECMAScript regular-expression literal. It deliberately uses
10
+ // typescript-go's own scanner and regexp parser so callers share the compiler's
11
+ // handling of escapes, flags, Unicode mode, and Unicode Sets syntax.
12
+ func IsValidRegularExpressionLiteral(text string) bool {
13
+ scanner := NewScanner()
14
+ valid := true
15
+ scanner.SetOnError(func(_ *diagnostics.Message, _, _ int, _ ...any) {
16
+ valid = false
17
+ })
18
+ scanner.SetText(text)
19
+ token := scanner.Scan()
20
+ if token != ast.KindSlashToken && token != ast.KindSlashEqualsToken {
21
+ return false
22
+ }
23
+ if scanner.ReScanSlashToken(true) != ast.KindRegularExpressionLiteral {
24
+ return false
25
+ }
26
+ return valid && scanner.TokenEnd() == len(text)
27
+ }
@@ -4,6 +4,7 @@ import path from "node:path";
4
4
  import { compileProjectInMemory } from "./compiler/internal/compileProjectInMemory";
5
5
  import { resolveProjectConfig } from "./compiler/internal/project/resolveProjectConfig";
6
6
  import { resolveBinary } from "./compiler/internal/resolveBinary";
7
+ import { createProcessDiagnostic } from "./compiler/internal/runBuild";
7
8
  import { transformProjectInMemory } from "./compiler/internal/transformProjectInMemory";
8
9
  import { resolveCleanTargets } from "./plugin/internal/buildSourcePlugin";
9
10
  import { loadProjectPlugins } from "./plugin/internal/loadProjectPlugins";
@@ -73,6 +74,8 @@ export class TtscCompiler {
73
74
  cacheDir: this.resolvePluginCacheDir(),
74
75
  cwd: execution.cwd,
75
76
  entries: this.context.plugins,
77
+ env: this.resolveEffectiveEnv(),
78
+ pluginConfigDir: this.context.pluginConfigDir,
76
79
  projectRoot: execution.projectRoot,
77
80
  tsconfig: execution.tsconfig,
78
81
  });
@@ -107,16 +110,20 @@ export class TtscCompiler {
107
110
  // cache dir.
108
111
  return removeExistingDirectories([explicitCacheDir, ...legacyTargets]);
109
112
  }
110
- // Default / `context.env.TTSC_CACHE_DIR`: resolve the cache root exactly as
111
- // prepare() does (`context.env.TTSC_CACHE_DIR`) and the Go build cache from
112
- // the ambient process env — the same source `go build` reads via
113
- // goBuildEnv — then remove only the ttsc-owned subdirectories, so a
114
- // possibly-shared root is never deleted.
113
+ // Default / `context.env.TTSC_CACHE_DIR`: resolve the cache root and the Go
114
+ // build cache (`TTSC_GO_CACHE_DIR`) from this instance's effective
115
+ // environment — the same `{ ...process.env, ...context.env }` that
116
+ // prepare()/compile()/transform() build with — then remove only the
117
+ // ttsc-owned subdirectories, so a possibly-shared root is never deleted and
118
+ // a user-provided `GOCACHE` is never touched. Using the effective env (not
119
+ // ambient `process.env`) makes clean() remove exactly the artifacts this
120
+ // instance owns, including a `TTSC_GO_CACHE_DIR` supplied only in
121
+ // `context.env`.
115
122
  return removeExistingDirectories(
116
123
  resolveCleanTargets(
117
124
  projectRoot,
118
125
  this.resolvePluginCacheDir(),
119
- process.env,
126
+ this.resolveEffectiveEnv(),
120
127
  ),
121
128
  );
122
129
  }
@@ -132,8 +139,9 @@ export class TtscCompiler {
132
139
  * directory before returning.
133
140
  *
134
141
  * The result uses an `embed-typescript`-style discriminated union: `success`
135
- * for clean compiles, `failure` for normal compiler diagnostics, and
136
- * `exception` for host setup or process failures.
142
+ * for clean compiles, `failure` for compiler diagnostics or plugin failures
143
+ * that reached the build pipeline, and `exception` for host failures that
144
+ * prevent any project check from running.
137
145
  *
138
146
  * @returns Structured compilation result containing diagnostics or output.
139
147
  */
@@ -217,6 +225,19 @@ export class TtscCompiler {
217
225
  private resolvePluginCacheDir(): string | undefined {
218
226
  return this.resolveCacheDir() ?? this.context.env?.TTSC_CACHE_DIR;
219
227
  }
228
+
229
+ /**
230
+ * The effective environment for this instance's source-plugin builds and
231
+ * clean targets: `context.env` merged over `process.env`, matching the
232
+ * documented {@link ITtscCompilerContext.env} contract that child compiler,
233
+ * native-plugin, and native-host processes already receive. Returned as a
234
+ * fresh object so callers never mutate the shared `process.env`; when no
235
+ * `context.env` was supplied this is a plain copy of `process.env`, so CLI /
236
+ * default behavior is unchanged.
237
+ */
238
+ private resolveEffectiveEnv(): NodeJS.ProcessEnv {
239
+ return { ...process.env, ...this.context.env };
240
+ }
220
241
  }
221
242
 
222
243
  function removeExistingDirectories(directories: readonly string[]): string[] {
@@ -347,20 +368,6 @@ function toCompilerResult(project: ProjectResult): ITtscCompilerResult {
347
368
  };
348
369
  }
349
370
 
350
- function createProcessDiagnostic(
351
- result: TtscBuildResult,
352
- ): ITtscCompilerDiagnostic {
353
- const messageText =
354
- (result.stderr || result.stdout).trim() ||
355
- `ttsc exited with status ${result.status}`;
356
- return {
357
- category: "error",
358
- code: "TTSC_PROCESS",
359
- file: null,
360
- messageText,
361
- };
362
- }
363
-
364
371
  function toCompilerTransformation(
365
372
  project: ProjectTransformation,
366
373
  ): ITtscCompilerTransformation {