ttsc 0.7.2 → 0.8.0-dev.20260505

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 (72) hide show
  1. package/README.md +5 -5
  2. package/cmd/platform/main.go +86 -76
  3. package/cmd/ttsc/api_compile.go +122 -105
  4. package/cmd/ttsc/api_transform.go +57 -49
  5. package/cmd/ttsc/build.go +116 -103
  6. package/cmd/ttsc/main.go +117 -117
  7. package/cmd/ttsc/main_test.go +191 -191
  8. package/driver/host.go +9 -9
  9. package/driver/program.go +285 -285
  10. package/driver/rewrite.go +266 -219
  11. package/lib/compiler/internal/compileProjectInMemory.js +3 -3
  12. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  13. package/lib/compiler/internal/resolveEmittedJavaScript.js +2 -1
  14. package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -1
  15. package/lib/compiler/internal/resolveTsgo.js.map +1 -1
  16. package/lib/compiler/internal/runBuild.js +47 -49
  17. package/lib/compiler/internal/runBuild.js.map +1 -1
  18. package/lib/compiler/internal/transformProjectInMemory.js +44 -4
  19. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
  20. package/lib/launcher/internal/getCompilerVersionText.js +1 -2
  21. package/lib/launcher/internal/getCompilerVersionText.js.map +1 -1
  22. package/lib/launcher/internal/prepareExecution.js +6 -4
  23. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  24. package/lib/launcher/internal/runTtsc.js +49 -5
  25. package/lib/launcher/internal/runTtsc.js.map +1 -1
  26. package/lib/launcher/internal/runTtsx.js +7 -2
  27. package/lib/launcher/internal/runTtsx.js.map +1 -1
  28. package/lib/plugin/internal/buildSourcePlugin.js +6 -0
  29. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
  30. package/lib/plugin/internal/loadProjectPlugins.js +55 -2
  31. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
  32. package/lib/structures/ITtscPlugin.d.ts +19 -3
  33. package/lib/structures/ITtscPlugin.js +4 -0
  34. package/lib/structures/ITtscPlugin.js.map +1 -1
  35. package/lib/structures/TtscPluginStage.d.ts +4 -10
  36. package/lib/structures/internal/ITtscLoadedNativePlugin.d.ts +5 -0
  37. package/package.json +11 -10
  38. package/shim/ast/lint.go +172 -171
  39. package/shim/ast/shim.go +84 -83
  40. package/shim/bundled/shim.go +5 -1
  41. package/shim/checker/shim.go +79 -79
  42. package/shim/compiler/emit_hooks.go +494 -0
  43. package/shim/compiler/shim.go +16 -1
  44. package/shim/core/shim.go +13 -10
  45. package/shim/diagnosticwriter/lint.go +79 -79
  46. package/shim/diagnosticwriter/shim.go +19 -19
  47. package/shim/parser/shim.go +7 -1
  48. package/shim/scanner/shim.go +39 -1
  49. package/shim/tsoptions/shim.go +51 -1
  50. package/shim/tspath/shim.go +72 -1
  51. package/shim/vfs/cachedvfs/shim.go +1 -1
  52. package/shim/vfs/osvfs/shim.go +1 -1
  53. package/shim/vfs/shim.go +4 -1
  54. package/src/compiler/internal/compileProjectInMemory.ts +6 -3
  55. package/src/compiler/internal/resolveEmittedJavaScript.ts +2 -1
  56. package/src/compiler/internal/resolveTsgo.ts +0 -1
  57. package/src/compiler/internal/runBuild.ts +58 -86
  58. package/src/compiler/internal/transformProjectInMemory.ts +51 -6
  59. package/src/launcher/internal/getCompilerVersionText.ts +1 -2
  60. package/src/launcher/internal/prepareExecution.ts +6 -6
  61. package/src/launcher/internal/runTtsc.ts +52 -5
  62. package/src/launcher/internal/runTtsx.ts +16 -5
  63. package/src/plugin/internal/buildSourcePlugin.ts +30 -2
  64. package/src/plugin/internal/loadProjectPlugins.ts +81 -2
  65. package/src/structures/ITtscPlugin.ts +30 -3
  66. package/src/structures/TtscPluginStage.ts +4 -10
  67. package/src/structures/internal/ITtscLoadedNativePlugin.ts +5 -0
  68. package/test/compiler.test.ts +3 -3
  69. package/test/platform.test.ts +1 -3
  70. package/test/tsgo.test.ts +15 -7
  71. package/tools/gen_shims/main.go +409 -409
  72. package/utility/host.go +707 -0
@@ -0,0 +1,494 @@
1
+ package compiler
2
+
3
+ import (
4
+ "context"
5
+
6
+ "github.com/microsoft/typescript-go/internal/ast"
7
+ "github.com/microsoft/typescript-go/internal/binder"
8
+ innercompiler "github.com/microsoft/typescript-go/internal/compiler"
9
+ "github.com/microsoft/typescript-go/internal/core"
10
+ "github.com/microsoft/typescript-go/internal/diagnostics"
11
+ "github.com/microsoft/typescript-go/internal/module"
12
+ "github.com/microsoft/typescript-go/internal/outputpaths"
13
+ "github.com/microsoft/typescript-go/internal/packagejson"
14
+ "github.com/microsoft/typescript-go/internal/printer"
15
+ "github.com/microsoft/typescript-go/internal/sourcemap"
16
+ "github.com/microsoft/typescript-go/internal/stringutil"
17
+ "github.com/microsoft/typescript-go/internal/symlinks"
18
+ "github.com/microsoft/typescript-go/internal/transformers"
19
+ "github.com/microsoft/typescript-go/internal/transformers/declarations"
20
+ "github.com/microsoft/typescript-go/internal/transformers/estransforms"
21
+ "github.com/microsoft/typescript-go/internal/transformers/inliners"
22
+ "github.com/microsoft/typescript-go/internal/transformers/jsxtransforms"
23
+ "github.com/microsoft/typescript-go/internal/transformers/moduletransforms"
24
+ "github.com/microsoft/typescript-go/internal/transformers/tstransforms"
25
+ "github.com/microsoft/typescript-go/internal/tsoptions"
26
+ "github.com/microsoft/typescript-go/internal/tspath"
27
+ )
28
+
29
+ type EmitContext = printer.EmitContext
30
+
31
+ type EmitSourceFileHook func(context *EmitContext, file *ast.SourceFile) *ast.SourceFile
32
+
33
+ type EmitHooks struct {
34
+ BeforePrintDeclaration EmitSourceFileHook
35
+ BeforePrintJS EmitSourceFileHook
36
+ }
37
+
38
+ type hookEmitHost struct {
39
+ program *innercompiler.Program
40
+ emitResolver printer.EmitResolver
41
+ }
42
+
43
+ type hookEmitter struct {
44
+ host *hookEmitHost
45
+ emitOnly innercompiler.EmitOnly
46
+ emitResult innercompiler.EmitResult
47
+ hooks EmitHooks
48
+ paths *outputpaths.OutputPaths
49
+ sourceFile *ast.SourceFile
50
+ writeFile innercompiler.WriteFile
51
+ writer printer.EmitTextWriter
52
+ }
53
+
54
+ func EmitWithHooks(ctx context.Context, program *innercompiler.Program, options innercompiler.EmitOptions, hooks EmitHooks) *innercompiler.EmitResult {
55
+ if program == nil {
56
+ return nil
57
+ }
58
+ if options.EmitOnly != innercompiler.EmitOnlyForcedDts {
59
+ result := HandleNoEmitOnError(ctx, program, options.TargetSourceFile)
60
+ if result != nil || ctx.Err() != nil {
61
+ return result
62
+ }
63
+ }
64
+ var results []*innercompiler.EmitResult
65
+ newLine := program.Options().NewLine.GetNewLineCharacter()
66
+ for _, sourceFile := range hookSourceFilesToEmit(program, options.TargetSourceFile, options.EmitOnly == innercompiler.EmitOnlyForcedDts) {
67
+ host, done := newHookEmitHost(ctx, program, sourceFile)
68
+ emitter := &hookEmitter{
69
+ host: host,
70
+ emitOnly: options.EmitOnly,
71
+ hooks: hooks,
72
+ paths: outputpaths.GetOutputPathsFor(sourceFile, host.Options(), host, options.EmitOnly == innercompiler.EmitOnlyForcedDts),
73
+ sourceFile: sourceFile,
74
+ writeFile: options.WriteFile,
75
+ writer: printer.NewTextWriter(newLine, 0),
76
+ }
77
+ emitter.emit()
78
+ done()
79
+ results = append(results, &emitter.emitResult)
80
+ }
81
+ return CombineEmitResults(results)
82
+ }
83
+
84
+ func hookSourceFilesToEmit(program *innercompiler.Program, target *ast.SourceFile, forceDtsEmit bool) []*ast.SourceFile {
85
+ if target != nil {
86
+ if program.SourceFileMayBeEmitted(target, forceDtsEmit) {
87
+ return []*ast.SourceFile{target}
88
+ }
89
+ return nil
90
+ }
91
+ var out []*ast.SourceFile
92
+ for _, sourceFile := range program.SourceFiles() {
93
+ if program.SourceFileMayBeEmitted(sourceFile, forceDtsEmit) {
94
+ out = append(out, sourceFile)
95
+ }
96
+ }
97
+ return out
98
+ }
99
+
100
+ func newHookEmitHost(ctx context.Context, program *innercompiler.Program, file *ast.SourceFile) (*hookEmitHost, func()) {
101
+ checker, done := program.GetTypeCheckerForFile(ctx, file)
102
+ return &hookEmitHost{
103
+ program: program,
104
+ emitResolver: checker.GetEmitResolver(),
105
+ }, done
106
+ }
107
+
108
+ func (e *hookEmitter) emit() {
109
+ e.emitJSFile(e.sourceFile, e.paths.JsFilePath(), e.paths.SourceMapFilePath())
110
+ e.emitDeclarationFile(e.sourceFile, e.paths.DeclarationFilePath(), e.paths.DeclarationMapPath())
111
+ e.emitResult.Diagnostics = e.emitterDiagnostics()
112
+ }
113
+
114
+ func (e *hookEmitter) emitterDiagnostics() []*ast.Diagnostic {
115
+ return e.emitResult.Diagnostics
116
+ }
117
+
118
+ func (e *hookEmitter) addDiagnostic(diag *ast.Diagnostic) {
119
+ e.emitResult.Diagnostics = append(e.emitResult.Diagnostics, diag)
120
+ }
121
+
122
+ func (e *hookEmitter) runScriptTransformers(emitContext *printer.EmitContext, sourceFile *ast.SourceFile) *ast.SourceFile {
123
+ for _, transformer := range hookScriptTransformers(emitContext, e.host, sourceFile) {
124
+ sourceFile = transformer.TransformSourceFile(sourceFile)
125
+ }
126
+ return sourceFile
127
+ }
128
+
129
+ func (e *hookEmitter) runDeclarationTransformers(emitContext *printer.EmitContext, sourceFile *ast.SourceFile, declarationFilePath, declarationMapPath string) (*ast.SourceFile, []*ast.Diagnostic) {
130
+ transform := declarations.NewDeclarationTransformer(e.host, emitContext, e.host.Options(), declarationFilePath, declarationMapPath)
131
+ sourceFile = transform.TransformSourceFile(sourceFile)
132
+ return sourceFile, transform.GetDiagnostics()
133
+ }
134
+
135
+ func (e *hookEmitter) emitJSFile(sourceFile *ast.SourceFile, jsFilePath string, sourceMapFilePath string) {
136
+ options := e.host.Options()
137
+ if sourceFile == nil || e.emitOnly != innercompiler.EmitAll && e.emitOnly != innercompiler.EmitOnlyJs || len(jsFilePath) == 0 {
138
+ return
139
+ }
140
+ if options.NoEmit == core.TSTrue || e.host.IsEmitBlocked(jsFilePath) {
141
+ e.emitResult.EmitSkipped = true
142
+ return
143
+ }
144
+ emitContext, putEmitContext := printer.GetEmitContext()
145
+ defer putEmitContext()
146
+ sourceFile = e.runScriptTransformers(emitContext, sourceFile)
147
+ if e.hooks.BeforePrintJS != nil {
148
+ sourceFile = e.hooks.BeforePrintJS(emitContext, sourceFile)
149
+ }
150
+ printerOptions := printer.PrinterOptions{
151
+ RemoveComments: options.RemoveComments.IsTrue(),
152
+ NewLine: options.NewLine,
153
+ NoEmitHelpers: options.NoEmitHelpers.IsTrue(),
154
+ SourceMap: options.SourceMap.IsTrue(),
155
+ InlineSourceMap: options.InlineSourceMap.IsTrue(),
156
+ InlineSources: options.InlineSources.IsTrue(),
157
+ Target: options.Target,
158
+ }
159
+ p := printer.NewPrinter(printerOptions, printer.PrintHandlers{}, emitContext)
160
+ e.printSourceFile(jsFilePath, sourceMapFilePath, sourceFile, p, hookShouldEmitSourceMaps(options, sourceFile))
161
+ }
162
+
163
+ func (e *hookEmitter) emitDeclarationFile(sourceFile *ast.SourceFile, declarationFilePath string, declarationMapPath string) {
164
+ options := e.host.Options()
165
+ if sourceFile == nil || e.emitOnly == innercompiler.EmitOnlyJs || len(declarationFilePath) == 0 {
166
+ return
167
+ }
168
+ if e.emitOnly != innercompiler.EmitOnlyForcedDts && (options.NoEmit == core.TSTrue || e.host.IsEmitBlocked(declarationFilePath)) {
169
+ e.emitResult.EmitSkipped = true
170
+ return
171
+ }
172
+ emitContext, putEmitContext := printer.GetEmitContext()
173
+ defer putEmitContext()
174
+ sourceFile, diags := e.runDeclarationTransformers(emitContext, sourceFile, declarationFilePath, declarationMapPath)
175
+ if e.hooks.BeforePrintDeclaration != nil {
176
+ sourceFile = e.hooks.BeforePrintDeclaration(emitContext, sourceFile)
177
+ }
178
+ printerOptions := printer.PrinterOptions{
179
+ RemoveComments: options.RemoveComments.IsTrue(),
180
+ OnlyPrintJSDocStyle: true,
181
+ NewLine: options.NewLine,
182
+ NoEmitHelpers: options.NoEmitHelpers.IsTrue(),
183
+ SourceMap: options.DeclarationMap.IsTrue(),
184
+ InlineSourceMap: options.InlineSourceMap.IsTrue(),
185
+ InlineSources: options.InlineSources.IsTrue(),
186
+ }
187
+ p := printer.NewPrinter(printerOptions, printer.PrintHandlers{}, emitContext)
188
+ for _, diag := range diags {
189
+ e.addDiagnostic(diag)
190
+ }
191
+ e.printSourceFile(declarationFilePath, declarationMapPath, sourceFile, p, e.emitOnly != innercompiler.EmitOnlyForcedDts && hookShouldEmitDeclarationSourceMaps(options, sourceFile))
192
+ }
193
+
194
+ func (e *hookEmitter) printSourceFile(filePath string, sourceMapFilePath string, sourceFile *ast.SourceFile, printer_ *printer.Printer, shouldEmitSourceMaps bool) {
195
+ options := e.host.Options()
196
+ var sourceMapGenerator *sourcemap.Generator
197
+ if shouldEmitSourceMaps {
198
+ sourceMapGenerator = sourcemap.NewGenerator(
199
+ tspath.GetBaseFileName(tspath.NormalizeSlashes(filePath)),
200
+ hookSourceRoot(options),
201
+ e.sourceMapDirectory(options, filePath, sourceFile),
202
+ tspath.ComparePathsOptions{
203
+ UseCaseSensitiveFileNames: e.host.UseCaseSensitiveFileNames(),
204
+ CurrentDirectory: e.host.GetCurrentDirectory(),
205
+ },
206
+ )
207
+ }
208
+ printer_.Write(sourceFile.AsNode(), sourceFile, e.writer, sourceMapGenerator)
209
+ sourceMapURLPos := -1
210
+ if sourceMapGenerator != nil {
211
+ if options.SourceMap.IsTrue() || options.InlineSourceMap.IsTrue() || options.GetAreDeclarationMapsEnabled() {
212
+ e.emitResult.SourceMaps = append(e.emitResult.SourceMaps, &innercompiler.SourceMapEmitResult{
213
+ InputSourceFileNames: sourceMapGenerator.Sources(),
214
+ SourceMap: sourceMapGenerator.RawSourceMap(),
215
+ GeneratedFile: filePath,
216
+ })
217
+ }
218
+ sourceMappingURL := e.sourceMappingURL(options, sourceMapGenerator, filePath, sourceMapFilePath, sourceFile)
219
+ if len(sourceMappingURL) > 0 {
220
+ if !e.writer.IsAtStartOfLine() {
221
+ e.writer.RawWrite(core.IfElse(options.NewLine == core.NewLineKindCRLF, "\r\n", "\n"))
222
+ }
223
+ sourceMapURLPos = e.writer.GetTextPos()
224
+ e.writer.WriteComment("//# sourceMappingURL=")
225
+ e.writer.WriteComment(sourceMappingURL)
226
+ }
227
+ if len(sourceMapFilePath) > 0 {
228
+ sourceMap := sourceMapGenerator.String()
229
+ if err := e.writeText(sourceMapFilePath, sourceMap, nil); err != nil {
230
+ e.addDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Could_not_write_file_0_Colon_1, filePath, err.Error()))
231
+ } else {
232
+ e.emitResult.EmittedFiles = append(e.emitResult.EmittedFiles, sourceMapFilePath)
233
+ }
234
+ }
235
+ } else {
236
+ e.writer.WriteLine()
237
+ }
238
+ text := e.writer.String()
239
+ if options.EmitBOM.IsTrue() {
240
+ text = stringutil.AddUTF8ByteOrderMark(text)
241
+ }
242
+ data := &innercompiler.WriteFileData{
243
+ SourceMapUrlPos: sourceMapURLPos,
244
+ Diagnostics: e.emitterDiagnostics(),
245
+ }
246
+ err := e.writeText(filePath, text, data)
247
+ skippedDtsWrite := data.SkippedDtsWrite
248
+ if err != nil {
249
+ e.addDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Could_not_write_file_0_Colon_1, filePath, err.Error()))
250
+ } else if !skippedDtsWrite {
251
+ e.emitResult.EmittedFiles = append(e.emitResult.EmittedFiles, filePath)
252
+ }
253
+ e.writer.Clear()
254
+ }
255
+
256
+ func (e *hookEmitter) writeText(fileName string, text string, data *innercompiler.WriteFileData) error {
257
+ if e.writeFile != nil {
258
+ return e.writeFile(fileName, text, data)
259
+ }
260
+ return e.host.WriteFile(fileName, text)
261
+ }
262
+
263
+ func (e *hookEmitter) sourceMapDirectory(options *core.CompilerOptions, filePath string, sourceFile *ast.SourceFile) string {
264
+ if len(options.SourceRoot) > 0 {
265
+ return e.host.CommonSourceDirectory()
266
+ }
267
+ if len(options.MapRoot) > 0 {
268
+ sourceMapDir := tspath.NormalizeSlashes(options.MapRoot)
269
+ if sourceFile != nil {
270
+ sourceMapDir = tspath.GetDirectoryPath(outputpaths.GetSourceFilePathInNewDir(
271
+ sourceFile.FileName(),
272
+ sourceMapDir,
273
+ e.host.GetCurrentDirectory(),
274
+ e.host.CommonSourceDirectory(),
275
+ e.host.UseCaseSensitiveFileNames(),
276
+ ))
277
+ }
278
+ if tspath.GetRootLength(sourceMapDir) == 0 {
279
+ sourceMapDir = tspath.CombinePaths(e.host.CommonSourceDirectory(), sourceMapDir)
280
+ }
281
+ return sourceMapDir
282
+ }
283
+ return tspath.GetDirectoryPath(tspath.NormalizePath(filePath))
284
+ }
285
+
286
+ func (e *hookEmitter) sourceMappingURL(options *core.CompilerOptions, sourceMapGenerator *sourcemap.Generator, filePath string, sourceMapFilePath string, sourceFile *ast.SourceFile) string {
287
+ if options.InlineSourceMap.IsTrue() {
288
+ return sourceMapGenerator.Base64DataURL()
289
+ }
290
+ sourceMapFile := tspath.GetBaseFileName(tspath.NormalizeSlashes(sourceMapFilePath))
291
+ if len(options.MapRoot) > 0 {
292
+ sourceMapDir := tspath.NormalizeSlashes(options.MapRoot)
293
+ if sourceFile != nil {
294
+ sourceMapDir = tspath.GetDirectoryPath(outputpaths.GetSourceFilePathInNewDir(
295
+ sourceFile.FileName(),
296
+ sourceMapDir,
297
+ e.host.GetCurrentDirectory(),
298
+ e.host.CommonSourceDirectory(),
299
+ e.host.UseCaseSensitiveFileNames(),
300
+ ))
301
+ }
302
+ if tspath.GetRootLength(sourceMapDir) == 0 {
303
+ sourceMapDir = tspath.CombinePaths(e.host.CommonSourceDirectory(), sourceMapDir)
304
+ return stringutil.EncodeURI(
305
+ tspath.GetRelativePathToDirectoryOrUrl(
306
+ tspath.GetDirectoryPath(tspath.NormalizePath(filePath)),
307
+ tspath.CombinePaths(sourceMapDir, sourceMapFile),
308
+ true,
309
+ tspath.ComparePathsOptions{
310
+ UseCaseSensitiveFileNames: e.host.UseCaseSensitiveFileNames(),
311
+ CurrentDirectory: e.host.GetCurrentDirectory(),
312
+ },
313
+ ),
314
+ )
315
+ }
316
+ return stringutil.EncodeURI(tspath.CombinePaths(sourceMapDir, sourceMapFile))
317
+ }
318
+ return stringutil.EncodeURI(sourceMapFile)
319
+ }
320
+
321
+ func hookShouldEmitSourceMaps(options *core.CompilerOptions, sourceFile *ast.SourceFile) bool {
322
+ return (options.SourceMap.IsTrue() || options.InlineSourceMap.IsTrue()) &&
323
+ !tspath.FileExtensionIs(sourceFile.FileName(), tspath.ExtensionJson)
324
+ }
325
+
326
+ func hookShouldEmitDeclarationSourceMaps(options *core.CompilerOptions, sourceFile *ast.SourceFile) bool {
327
+ return options.DeclarationMap.IsTrue() &&
328
+ !tspath.FileExtensionIs(sourceFile.FileName(), tspath.ExtensionJson)
329
+ }
330
+
331
+ func hookSourceRoot(options *core.CompilerOptions) string {
332
+ sourceRoot := tspath.NormalizeSlashes(options.SourceRoot)
333
+ if len(sourceRoot) > 0 {
334
+ sourceRoot = tspath.EnsureTrailingDirectorySeparator(sourceRoot)
335
+ }
336
+ return sourceRoot
337
+ }
338
+
339
+ func hookScriptTransformers(emitContext *printer.EmitContext, host printer.EmitHost, sourceFile *ast.SourceFile) []*transformers.Transformer {
340
+ var tx []*transformers.Transformer
341
+ options := host.Options()
342
+ importElisionEnabled := !options.VerbatimModuleSyntax.IsTrue() && !ast.IsInJSFile(sourceFile.AsNode())
343
+ jsxTransformEnabled := options.GetJSXTransformEnabled() && sourceFile.LanguageVariant == core.LanguageVariantJSX
344
+ emitResolver := host.GetEmitResolver()
345
+ var referenceResolver binder.ReferenceResolver
346
+ if importElisionEnabled || jsxTransformEnabled || !options.GetIsolatedModules() || options.EmitDecoratorMetadata.IsTrue() {
347
+ emitResolver.MarkLinkedReferencesRecursively(sourceFile)
348
+ referenceResolver = emitResolver
349
+ } else {
350
+ referenceResolver = binder.NewReferenceResolver(options, binder.ReferenceResolverHooks{})
351
+ }
352
+ opts := transformers.TransformOptions{
353
+ Context: emitContext,
354
+ CompilerOptions: options,
355
+ Resolver: referenceResolver,
356
+ EmitResolver: emitResolver,
357
+ GetEmitModuleFormatOfFile: host.GetEmitModuleFormatOfFile,
358
+ }
359
+ if options.EmitDecoratorMetadata.IsTrue() {
360
+ tx = append(tx, tstransforms.NewMetadataTransformer(&opts))
361
+ }
362
+ tx = append(tx, tstransforms.NewTypeEraserTransformer(&opts))
363
+ if importElisionEnabled {
364
+ tx = append(tx, tstransforms.NewImportElisionTransformer(&opts))
365
+ }
366
+ tx = append(tx, tstransforms.NewRuntimeSyntaxTransformer(&opts))
367
+ if options.ExperimentalDecorators.IsTrue() {
368
+ tx = append(tx, tstransforms.NewLegacyDecoratorsTransformer(&opts))
369
+ }
370
+ if jsxTransformEnabled {
371
+ tx = append(tx, jsxtransforms.NewJSXTransformer(&opts))
372
+ }
373
+ downleveler := estransforms.GetESTransformer(&opts)
374
+ if downleveler != nil {
375
+ tx = append(tx, downleveler)
376
+ }
377
+ tx = append(tx, estransforms.NewUseStrictTransformer(&opts))
378
+ tx = append(tx, hookModuleTransformer(&opts))
379
+ if !options.GetIsolatedModules() {
380
+ tx = append(tx, inliners.NewConstEnumInliningTransformer(&opts))
381
+ }
382
+ return tx
383
+ }
384
+
385
+ func hookModuleTransformer(opts *transformers.TransformOptions) *transformers.Transformer {
386
+ switch opts.CompilerOptions.GetEmitModuleKind() {
387
+ case core.ModuleKindPreserve:
388
+ return moduletransforms.NewESModuleTransformer(opts)
389
+ case core.ModuleKindESNext,
390
+ core.ModuleKindES2022,
391
+ core.ModuleKindES2020,
392
+ core.ModuleKindES2015,
393
+ core.ModuleKindNode20,
394
+ core.ModuleKindNode18,
395
+ core.ModuleKindNode16,
396
+ core.ModuleKindNodeNext,
397
+ core.ModuleKindCommonJS:
398
+ return moduletransforms.NewImpliedModuleTransformer(opts)
399
+ default:
400
+ return moduletransforms.NewCommonJSModuleTransformer(opts)
401
+ }
402
+ }
403
+
404
+ func (host *hookEmitHost) GetModeForUsageLocation(file ast.HasFileName, moduleSpecifier *ast.StringLiteralLike) core.ResolutionMode {
405
+ return host.program.GetModeForUsageLocation(file, moduleSpecifier)
406
+ }
407
+
408
+ func (host *hookEmitHost) GetResolvedModuleFromModuleSpecifier(file ast.HasFileName, moduleSpecifier *ast.StringLiteralLike) *module.ResolvedModule {
409
+ return host.program.GetResolvedModuleFromModuleSpecifier(file, moduleSpecifier)
410
+ }
411
+
412
+ func (host *hookEmitHost) GetDefaultResolutionModeForFile(file ast.HasFileName) core.ResolutionMode {
413
+ return host.program.GetDefaultResolutionModeForFile(file)
414
+ }
415
+
416
+ func (host *hookEmitHost) GetEmitModuleFormatOfFile(file ast.HasFileName) core.ModuleKind {
417
+ return host.program.GetEmitModuleFormatOfFile(file)
418
+ }
419
+
420
+ func (host *hookEmitHost) FileExists(path string) bool {
421
+ return host.program.FileExists(path)
422
+ }
423
+
424
+ func (host *hookEmitHost) GetGlobalTypingsCacheLocation() string {
425
+ return host.program.GetGlobalTypingsCacheLocation()
426
+ }
427
+
428
+ func (host *hookEmitHost) GetNearestAncestorDirectoryWithPackageJson(dirname string) string {
429
+ return host.program.GetNearestAncestorDirectoryWithPackageJson(dirname)
430
+ }
431
+
432
+ func (host *hookEmitHost) GetPackageJsonInfo(pkgJSONPath string) *packagejson.InfoCacheEntry {
433
+ return host.program.GetPackageJsonInfo(pkgJSONPath)
434
+ }
435
+
436
+ func (host *hookEmitHost) GetSourceOfProjectReferenceIfOutputIncluded(file ast.HasFileName) string {
437
+ return host.program.GetSourceOfProjectReferenceIfOutputIncluded(file)
438
+ }
439
+
440
+ func (host *hookEmitHost) GetProjectReferenceFromSource(path tspath.Path) *tsoptions.SourceOutputAndProjectReference {
441
+ return host.program.GetProjectReferenceFromSource(path)
442
+ }
443
+
444
+ func (host *hookEmitHost) GetRedirectTargets(path tspath.Path) []string {
445
+ return host.program.GetRedirectTargets(path)
446
+ }
447
+
448
+ func (host *hookEmitHost) GetEffectiveDeclarationFlags(node *ast.Node, flags ast.ModifierFlags) ast.ModifierFlags {
449
+ return host.GetEmitResolver().GetEffectiveDeclarationFlags(node, flags)
450
+ }
451
+
452
+ func (host *hookEmitHost) GetOutputPathsFor(file *ast.SourceFile, forceDtsPaths bool) declarations.OutputPaths {
453
+ return outputpaths.GetOutputPathsFor(file, host.Options(), host, forceDtsPaths)
454
+ }
455
+
456
+ func (host *hookEmitHost) GetResolutionModeOverride(node *ast.Node) core.ResolutionMode {
457
+ return host.GetEmitResolver().GetResolutionModeOverride(node)
458
+ }
459
+
460
+ func (host *hookEmitHost) GetSourceFileFromReference(origin *ast.SourceFile, ref *ast.FileReference) *ast.SourceFile {
461
+ return host.program.GetSourceFileFromReference(origin, ref)
462
+ }
463
+
464
+ func (host *hookEmitHost) Options() *core.CompilerOptions { return host.program.Options() }
465
+ func (host *hookEmitHost) SourceFiles() []*ast.SourceFile { return host.program.SourceFiles() }
466
+ func (host *hookEmitHost) GetCurrentDirectory() string { return host.program.GetCurrentDirectory() }
467
+ func (host *hookEmitHost) CommonSourceDirectory() string { return host.program.CommonSourceDirectory() }
468
+ func (host *hookEmitHost) UseCaseSensitiveFileNames() bool {
469
+ return host.program.UseCaseSensitiveFileNames()
470
+ }
471
+
472
+ func (host *hookEmitHost) IsEmitBlocked(file string) bool {
473
+ return host.program.IsEmitBlocked(file)
474
+ }
475
+
476
+ func (host *hookEmitHost) WriteFile(fileName string, text string) error {
477
+ return host.program.Host().FS().WriteFile(fileName, text)
478
+ }
479
+
480
+ func (host *hookEmitHost) GetEmitResolver() printer.EmitResolver {
481
+ return host.emitResolver
482
+ }
483
+
484
+ func (host *hookEmitHost) IsSourceFileFromExternalLibrary(file *ast.SourceFile) bool {
485
+ return host.program.IsSourceFileFromExternalLibrary(file)
486
+ }
487
+
488
+ func (host *hookEmitHost) GetSymlinkCache() *symlinks.KnownSymlinks {
489
+ return host.program.GetSymlinkCache()
490
+ }
491
+
492
+ func (host *hookEmitHost) ResolveModuleName(moduleName string, containingFile string, resolutionMode core.ResolutionMode) *module.ResolvedModule {
493
+ return host.program.ResolveModuleName(moduleName, containingFile, resolutionMode)
494
+ }
@@ -1,4 +1,3 @@
1
-
2
1
  // Code generated by packages/ttsc/tools/gen_shims. DO NOT EDIT.
3
2
 
4
3
  package compiler
@@ -13,37 +12,53 @@ import "github.com/microsoft/typescript-go/internal/vfs"
13
12
  import _ "unsafe"
14
13
 
15
14
  type CheckerPool = compiler.CheckerPool
15
+
16
16
  //go:linkname CombineEmitResults github.com/microsoft/typescript-go/internal/compiler.CombineEmitResults
17
17
  func CombineEmitResults(results []*compiler.EmitResult) *compiler.EmitResult
18
+
18
19
  type CompilerHost = compiler.CompilerHost
19
20
  type DuplicateSourceFile = compiler.DuplicateSourceFile
21
+
20
22
  const EmitAll = compiler.EmitAll
23
+
21
24
  type EmitHost = compiler.EmitHost
22
25
  type EmitOnly = compiler.EmitOnly
26
+
23
27
  const EmitOnlyDts = compiler.EmitOnlyDts
24
28
  const EmitOnlyForcedDts = compiler.EmitOnlyForcedDts
25
29
  const EmitOnlyJs = compiler.EmitOnlyJs
30
+
26
31
  type EmitOptions = compiler.EmitOptions
27
32
  type EmitResult = compiler.EmitResult
28
33
  type FileIncludeReason = compiler.FileIncludeReason
34
+
29
35
  //go:linkname FilterNoEmitSemanticDiagnostics github.com/microsoft/typescript-go/internal/compiler.FilterNoEmitSemanticDiagnostics
30
36
  func FilterNoEmitSemanticDiagnostics(diagnostics []*ast.Diagnostic, options *core.CompilerOptions) []*ast.Diagnostic
37
+
31
38
  //go:linkname GetDiagnosticsOfAnyProgram github.com/microsoft/typescript-go/internal/compiler.GetDiagnosticsOfAnyProgram
32
39
  func GetDiagnosticsOfAnyProgram(ctx context.Context, program compiler.ProgramLike, file *ast.SourceFile, skipNoEmitCheckForDtsDiagnostics bool, getBindDiagnostics func(context.Context, *ast.SourceFile) []*ast.Diagnostic, getSemanticDiagnostics func(context.Context, *ast.SourceFile) []*ast.Diagnostic) []*ast.Diagnostic
40
+
33
41
  //go:linkname HandleNoEmitOnError github.com/microsoft/typescript-go/internal/compiler.HandleNoEmitOnError
34
42
  func HandleNoEmitOnError(ctx context.Context, program compiler.ProgramLike, file *ast.SourceFile) *compiler.EmitResult
43
+
35
44
  type LibFile = compiler.LibFile
45
+
36
46
  //go:linkname NewCachedFSCompilerHost github.com/microsoft/typescript-go/internal/compiler.NewCachedFSCompilerHost
37
47
  func NewCachedFSCompilerHost(currentDirectory string, fs vfs.FS, defaultLibraryPath string, extendedConfigCache tsoptions.ExtendedConfigCache, trace func(msg *diagnostics.Message, args ...any)) compiler.CompilerHost
48
+
38
49
  //go:linkname NewCompilerHost github.com/microsoft/typescript-go/internal/compiler.NewCompilerHost
39
50
  func NewCompilerHost(currentDirectory string, fs vfs.FS, defaultLibraryPath string, extendedConfigCache tsoptions.ExtendedConfigCache, trace func(msg *diagnostics.Message, args ...any)) compiler.CompilerHost
51
+
40
52
  //go:linkname NewProgram github.com/microsoft/typescript-go/internal/compiler.NewProgram
41
53
  func NewProgram(opts compiler.ProgramOptions) *compiler.Program
54
+
42
55
  type Program = compiler.Program
43
56
  type ProgramLike = compiler.ProgramLike
44
57
  type ProgramOptions = compiler.ProgramOptions
58
+
45
59
  //go:linkname SortAndDeduplicateDiagnostics github.com/microsoft/typescript-go/internal/compiler.SortAndDeduplicateDiagnostics
46
60
  func SortAndDeduplicateDiagnostics(diagnostics []*ast.Diagnostic) []*ast.Diagnostic
61
+
47
62
  type SourceFileMayBeEmittedHost = compiler.SourceFileMayBeEmittedHost
48
63
  type SourceMapEmitResult = compiler.SourceMapEmitResult
49
64
  type WriteFile = compiler.WriteFile
package/shim/core/shim.go CHANGED
@@ -9,18 +9,21 @@ type TextRange = innercore.TextRange
9
9
  type ScriptKind = innercore.ScriptKind
10
10
 
11
11
  const (
12
- TSFalse = innercore.TSFalse
13
- TSTrue = innercore.TSTrue
12
+ TSFalse = innercore.TSFalse
13
+ TSTrue = innercore.TSTrue
14
14
 
15
- ScriptKindUnknown = innercore.ScriptKindUnknown
16
- ScriptKindJS = innercore.ScriptKindJS
17
- ScriptKindJSX = innercore.ScriptKindJSX
18
- ScriptKindTS = innercore.ScriptKindTS
19
- ScriptKindTSX = innercore.ScriptKindTSX
20
- ScriptKindExternal = innercore.ScriptKindExternal
21
- ScriptKindJSON = innercore.ScriptKindJSON
22
- ScriptKindDeferred = innercore.ScriptKindDeferred
15
+ ScriptKindUnknown = innercore.ScriptKindUnknown
16
+ ScriptKindJS = innercore.ScriptKindJS
17
+ ScriptKindJSX = innercore.ScriptKindJSX
18
+ ScriptKindTS = innercore.ScriptKindTS
19
+ ScriptKindTSX = innercore.ScriptKindTSX
20
+ ScriptKindExternal = innercore.ScriptKindExternal
21
+ ScriptKindJSON = innercore.ScriptKindJSON
22
+ ScriptKindDeferred = innercore.ScriptKindDeferred
23
23
  )
24
24
 
25
25
  // NewTextRange constructs a closed/open [pos, end) text range.
26
26
  func NewTextRange(pos, end int) TextRange { return innercore.NewTextRange(pos, end) }
27
+
28
+ // UndefinedTextRange marks synthesized AST nodes that do not map to source.
29
+ func UndefinedTextRange() TextRange { return innercore.UndefinedTextRange() }