ttsc 0.18.4 → 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.
- package/README.md +5 -6
- package/cmd/graphbench/main.go +1 -1
- package/cmd/platform/main.go +1 -48
- package/cmd/ttsc/build_branches_test.go +5 -1
- package/cmd/ttsc/main.go +0 -50
- package/cmd/ttsc/main_alias_branches_test.go +6 -12
- package/cmd/ttscgraph/dump.go +13 -3
- package/cmd/ttscserver/main.go +5 -3
- package/driver/lsp.go +13 -1
- package/driver/plugins.go +35 -0
- package/driver/program.go +7 -8
- package/driver/rewrite.go +381 -21
- package/go.mod +1 -0
- package/internal/graph/build.go +297 -3
- package/internal/graph/build_records_a_node_per_top_level_declaration_test.go +16 -2
- package/internal/graph/diagnostics.go +5 -4
- package/internal/graph/dump.go +60 -4
- package/internal/graph/dump_is_a_function_of_the_source_test.go +71 -0
- package/internal/graph/dump_serializes_the_full_graph_test.go +16 -4
- package/internal/graph/edges.go +122 -11
- package/internal/graph/exports.go +74 -17
- package/internal/graph/graph.go +33 -1
- package/internal/graph/node_identity_is_position_invariant_test.go +4 -2
- package/internal/graph/resolve.go +24 -0
- package/internal/graphsymbols/provider.go +50 -14
- package/internal/lspserver/lsp_native_plugin_source.go +77 -23
- package/internal/lspserver/lsp_plugin.go +19 -2
- package/internal/lspserver/lsp_proxy.go +244 -52
- package/internal/lspserver/lsp_server.go +35 -27
- package/internal/lspserver/lsp_symbols.go +25 -16
- package/lib/TtscCompiler.d.ts +10 -0
- package/lib/TtscCompiler.js +24 -6
- package/lib/TtscCompiler.js.map +1 -1
- package/lib/TtscService.js +9 -7
- package/lib/TtscService.js.map +1 -1
- package/lib/compiler/internal/compileProjectInMemory.js +1 -0
- package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
- package/lib/compiler/internal/project/createNativeProjectContextArgs.d.ts +3 -0
- package/lib/compiler/internal/project/createNativeProjectContextArgs.js +14 -0
- package/lib/compiler/internal/project/createNativeProjectContextArgs.js.map +1 -0
- package/lib/compiler/internal/project/readProjectConfig.js +53 -4
- package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
- package/lib/compiler/internal/project/resolveProjectConfig.d.ts +9 -2
- package/lib/compiler/internal/project/resolveProjectConfig.js +45 -16
- package/lib/compiler/internal/project/resolveProjectConfig.js.map +1 -1
- package/lib/compiler/internal/residentTransformProcess.d.ts +16 -5
- package/lib/compiler/internal/residentTransformProcess.js +68 -20
- package/lib/compiler/internal/residentTransformProcess.js.map +1 -1
- package/lib/compiler/internal/runBuild.d.ts +11 -0
- package/lib/compiler/internal/runBuild.js +44 -8
- package/lib/compiler/internal/runBuild.js.map +1 -1
- package/lib/compiler/internal/runSingleFileEmit.js +7 -4
- package/lib/compiler/internal/runSingleFileEmit.js.map +1 -1
- package/lib/compiler/internal/sharedHostHelpers.d.ts +16 -0
- package/lib/compiler/internal/sharedHostHelpers.js +23 -0
- package/lib/compiler/internal/sharedHostHelpers.js.map +1 -1
- package/lib/compiler/internal/startResidentTransform.js +18 -1
- package/lib/compiler/internal/startResidentTransform.js.map +1 -1
- package/lib/compiler/internal/transformProjectInMemory.js +34 -8
- package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
- package/lib/flags/parser.d.ts +17 -0
- package/lib/flags/parser.js +11 -1
- package/lib/flags/parser.js.map +1 -1
- package/lib/flags/schema.js +7 -0
- package/lib/flags/schema.js.map +1 -1
- package/lib/launcher/internal/prepareExecution.js +21 -2
- package/lib/launcher/internal/prepareExecution.js.map +1 -1
- package/lib/launcher/internal/runTtsc.js +13 -53
- package/lib/launcher/internal/runTtsc.js.map +1 -1
- package/lib/launcher/internal/runTtscserver.js +11 -0
- package/lib/launcher/internal/runTtscserver.js.map +1 -1
- package/lib/launcher/internal/runTtsx.js +27 -11
- package/lib/launcher/internal/runTtsx.js.map +1 -1
- package/lib/launcher/internal/runtimeHooks.d.ts +81 -0
- package/lib/launcher/internal/runtimeHooks.js +632 -43
- package/lib/launcher/internal/runtimeHooks.js.map +1 -1
- package/lib/launcher/internal/servedSourceMap.d.ts +25 -0
- package/lib/launcher/internal/servedSourceMap.js +164 -0
- package/lib/launcher/internal/servedSourceMap.js.map +1 -0
- package/lib/plugin/internal/buildSourcePlugin.d.ts +146 -2
- package/lib/plugin/internal/buildSourcePlugin.js +651 -113
- package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
- package/lib/plugin/internal/loadProjectPlugins.d.ts +7 -0
- package/lib/plugin/internal/loadProjectPlugins.js +33 -10
- package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
- package/lib/structures/ITtscCompilerContext.d.ts +16 -2
- package/lib/structures/ITtscPluginCapabilities.d.ts +8 -0
- package/lib/structures/ITtscPluginFactoryContext.d.ts +14 -0
- package/lib/structures/internal/ITtscParsedProjectConfig.d.ts +3 -0
- package/lib/structures/internal/ITtscProjectIdentity.d.ts +17 -0
- package/lib/structures/internal/ITtscProjectIdentity.js +3 -0
- package/lib/structures/internal/ITtscProjectIdentity.js.map +1 -0
- package/lib/structures/internal/TtscCommonOptions.d.ts +8 -0
- package/package.json +11 -8
- package/shim/ast/lint.go +10 -0
- package/shim/ast/shim.go +44 -0
- package/shim/checker/enums_gen.go +19 -0
- package/shim/checker/shim.go +130 -0
- package/shim/diagnosticwriter/lint.go +30 -3
- package/shim/scanner/regexp.go +27 -0
- package/src/TtscCompiler.ts +25 -6
- package/src/TtscService.ts +15 -7
- package/src/compiler/internal/compileProjectInMemory.ts +1 -0
- package/src/compiler/internal/project/createNativeProjectContextArgs.ts +15 -0
- package/src/compiler/internal/project/readProjectConfig.ts +61 -5
- package/src/compiler/internal/project/resolveProjectConfig.ts +51 -21
- package/src/compiler/internal/residentTransformProcess.ts +95 -21
- package/src/compiler/internal/runBuild.ts +76 -9
- package/src/compiler/internal/runSingleFileEmit.ts +7 -4
- package/src/compiler/internal/sharedHostHelpers.ts +24 -0
- package/src/compiler/internal/startResidentTransform.ts +21 -1
- package/src/compiler/internal/transformProjectInMemory.ts +49 -6
- package/src/flags/parser.ts +28 -1
- package/src/flags/schema.ts +8 -0
- package/src/launcher/internal/prepareExecution.ts +22 -2
- package/src/launcher/internal/runTtsc.ts +13 -61
- package/src/launcher/internal/runTtscserver.ts +14 -0
- package/src/launcher/internal/runTtsx.ts +28 -13
- package/src/launcher/internal/runtimeHooks.ts +771 -53
- package/src/launcher/internal/servedSourceMap.ts +183 -0
- package/src/plugin/internal/buildSourcePlugin.ts +859 -122
- package/src/plugin/internal/loadProjectPlugins.ts +36 -6
- package/src/structures/ITtscCompilerContext.ts +17 -2
- package/src/structures/ITtscPluginCapabilities.ts +9 -0
- package/src/structures/ITtscPluginFactoryContext.ts +15 -0
- package/src/structures/internal/ITtscParsedProjectConfig.ts +3 -0
- package/src/structures/internal/ITtscProjectIdentity.ts +17 -0
- package/src/structures/internal/TtscCommonOptions.ts +8 -0
- package/tools/shim_audit/baseline.json +16 -7
- package/tools/shim_audit/main.go +777 -71
- package/tools/shim_audit/main_test.go +28 -1
- package/tools/shim_audit/producer_exemptions_require_rationale_test.go +42 -0
- package/tools/shim_audit/producer_surface_includes_exposed_methods_test.go +154 -0
- package/tools/shim_audit/producer_surface_rejects_unproducible_reference_test.go +142 -0
- package/utility/host.go +46 -20
- package/utility/serve.go +1 -1
- package/shim/checker/signature_api_completeness.go +0 -58
|
@@ -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 @@
|
|
|
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.
|
|
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.
|
|
36
|
-
"@ttsc/
|
|
37
|
-
"@ttsc/linux-arm64": "0.
|
|
38
|
-
"@ttsc/darwin-arm64": "0.
|
|
39
|
-
"@ttsc/
|
|
40
|
-
"@ttsc/win32-
|
|
41
|
-
"@ttsc/
|
|
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
|
package/shim/checker/shim.go
CHANGED
|
@@ -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
|
-
|
|
51
|
-
end = pos + 1
|
|
52
|
-
}
|
|
79
|
+
pos, end = NormalizeLintRange(file, pos, end)
|
|
53
80
|
return &LintDiagnostic{
|
|
54
81
|
file: file,
|
|
55
82
|
pos: pos,
|
|
@@ -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
|
+
}
|
package/src/TtscCompiler.ts
CHANGED
|
@@ -74,6 +74,8 @@ export class TtscCompiler {
|
|
|
74
74
|
cacheDir: this.resolvePluginCacheDir(),
|
|
75
75
|
cwd: execution.cwd,
|
|
76
76
|
entries: this.context.plugins,
|
|
77
|
+
env: this.resolveEffectiveEnv(),
|
|
78
|
+
pluginConfigDir: this.context.pluginConfigDir,
|
|
77
79
|
projectRoot: execution.projectRoot,
|
|
78
80
|
tsconfig: execution.tsconfig,
|
|
79
81
|
});
|
|
@@ -108,16 +110,20 @@ export class TtscCompiler {
|
|
|
108
110
|
// cache dir.
|
|
109
111
|
return removeExistingDirectories([explicitCacheDir, ...legacyTargets]);
|
|
110
112
|
}
|
|
111
|
-
// Default / `context.env.TTSC_CACHE_DIR`: resolve the cache root
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
// 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`.
|
|
116
122
|
return removeExistingDirectories(
|
|
117
123
|
resolveCleanTargets(
|
|
118
124
|
projectRoot,
|
|
119
125
|
this.resolvePluginCacheDir(),
|
|
120
|
-
|
|
126
|
+
this.resolveEffectiveEnv(),
|
|
121
127
|
),
|
|
122
128
|
);
|
|
123
129
|
}
|
|
@@ -219,6 +225,19 @@ export class TtscCompiler {
|
|
|
219
225
|
private resolvePluginCacheDir(): string | undefined {
|
|
220
226
|
return this.resolveCacheDir() ?? this.context.env?.TTSC_CACHE_DIR;
|
|
221
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
|
+
}
|
|
222
241
|
}
|
|
223
242
|
|
|
224
243
|
function removeExistingDirectories(directories: readonly string[]): string[] {
|
package/src/TtscService.ts
CHANGED
|
@@ -58,9 +58,14 @@ export class TtscService {
|
|
|
58
58
|
* carries the host's diagnostics so callers can surface a real build error.
|
|
59
59
|
*/
|
|
60
60
|
public async transformFile(fileName: string): Promise<string | undefined> {
|
|
61
|
-
const reply = await this.resident.request(
|
|
62
|
-
file: this.absolutePath(fileName),
|
|
63
|
-
|
|
61
|
+
const reply = await this.resident.request(
|
|
62
|
+
{ file: this.absolutePath(fileName) },
|
|
63
|
+
"transform",
|
|
64
|
+
);
|
|
65
|
+
// The resident client already validated the reply shape (boolean `found`,
|
|
66
|
+
// string `typescript` when found), so a malformed or wrong-shape reply
|
|
67
|
+
// rejected instead of reaching here. `found: false` is the only path to
|
|
68
|
+
// `undefined`; a protocol failure never masquerades as an absent file.
|
|
64
69
|
return reply.found === true && typeof reply.typescript === "string"
|
|
65
70
|
? reply.typescript
|
|
66
71
|
: undefined;
|
|
@@ -74,10 +79,13 @@ export class TtscService {
|
|
|
74
79
|
* `fileName` is resolved against the project root.
|
|
75
80
|
*/
|
|
76
81
|
public async updateFile(fileName: string, content: string): Promise<boolean> {
|
|
77
|
-
const reply = await this.resident.request(
|
|
78
|
-
content,
|
|
79
|
-
update
|
|
80
|
-
|
|
82
|
+
const reply = await this.resident.request(
|
|
83
|
+
{ content, update: this.absolutePath(fileName) },
|
|
84
|
+
"update",
|
|
85
|
+
);
|
|
86
|
+
// The resident client validated the reply carries a boolean `updated`, so a
|
|
87
|
+
// malformed or wrong-shape reply rejected instead of collapsing to `false`.
|
|
88
|
+
// `false` here means only that the edit did not compile.
|
|
81
89
|
return reply.updated === true;
|
|
82
90
|
}
|
|
83
91
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ITtscParsedProjectConfig } from "../../../structures/internal/ITtscParsedProjectConfig";
|
|
2
|
+
|
|
3
|
+
/** Serialize the retained project identity for a native sidecar invocation. */
|
|
4
|
+
export function createNativeProjectContextArgs(
|
|
5
|
+
project: ITtscParsedProjectConfig,
|
|
6
|
+
pluginConfigOrigin?: string,
|
|
7
|
+
): string[] {
|
|
8
|
+
return [
|
|
9
|
+
"--project-context-json=" +
|
|
10
|
+
JSON.stringify({
|
|
11
|
+
...project.identity,
|
|
12
|
+
...(pluginConfigOrigin === undefined ? {} : { pluginConfigOrigin }),
|
|
13
|
+
}),
|
|
14
|
+
];
|
|
15
|
+
}
|