typia 13.0.0-dev.20260509 → 13.0.0-dev.20260510

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 (53) hide show
  1. package/native/adapter/adapter.go +3 -3
  2. package/native/go.mod +0 -4
  3. package/native/internal/printer/printer.go +229 -0
  4. package/package.json +6 -6
  5. package/native/go.work +0 -20
  6. package/native/go.work.sum +0 -11
  7. package/native/shim/printer/go.mod +0 -5
  8. package/native/shim/printer/shim.go +0 -249
  9. package/native/third_party/ttsc/driver/host.go +0 -31
  10. package/native/third_party/ttsc/driver/program.go +0 -466
  11. package/native/third_party/ttsc/driver/rewrite.go +0 -341
  12. package/native/third_party/ttsc/go.mod +0 -48
  13. package/native/third_party/ttsc/go.sum +0 -22
  14. package/native/third_party/ttsc/shim/ast/extra-shim.json +0 -4
  15. package/native/third_party/ttsc/shim/ast/go.mod +0 -5
  16. package/native/third_party/ttsc/shim/ast/lint.go +0 -331
  17. package/native/third_party/ttsc/shim/ast/shim.go +0 -210
  18. package/native/third_party/ttsc/shim/bundled/extra-shim.json +0 -1
  19. package/native/third_party/ttsc/shim/bundled/go.mod +0 -5
  20. package/native/third_party/ttsc/shim/bundled/shim.go +0 -23
  21. package/native/third_party/ttsc/shim/checker/extra-shim.json +0 -31
  22. package/native/third_party/ttsc/shim/checker/go.mod +0 -5
  23. package/native/third_party/ttsc/shim/checker/shim.go +0 -166
  24. package/native/third_party/ttsc/shim/compiler/extra-shim.json +0 -4
  25. package/native/third_party/ttsc/shim/compiler/go.mod +0 -5
  26. package/native/third_party/ttsc/shim/compiler/shim.go +0 -65
  27. package/native/third_party/ttsc/shim/core/extra-shim.json +0 -4
  28. package/native/third_party/ttsc/shim/core/go.mod +0 -5
  29. package/native/third_party/ttsc/shim/core/shim.go +0 -29
  30. package/native/third_party/ttsc/shim/diagnosticwriter/go.mod +0 -5
  31. package/native/third_party/ttsc/shim/diagnosticwriter/lint.go +0 -137
  32. package/native/third_party/ttsc/shim/diagnosticwriter/shim.go +0 -29
  33. package/native/third_party/ttsc/shim/parser/extra-shim.json +0 -4
  34. package/native/third_party/ttsc/shim/parser/go.mod +0 -5
  35. package/native/third_party/ttsc/shim/parser/shim.go +0 -61
  36. package/native/third_party/ttsc/shim/scanner/extra-shim.json +0 -4
  37. package/native/third_party/ttsc/shim/scanner/go.mod +0 -5
  38. package/native/third_party/ttsc/shim/scanner/shim.go +0 -134
  39. package/native/third_party/ttsc/shim/tsoptions/extra-shim.json +0 -4
  40. package/native/third_party/ttsc/shim/tsoptions/go.mod +0 -5
  41. package/native/third_party/ttsc/shim/tsoptions/shim.go +0 -173
  42. package/native/third_party/ttsc/shim/tspath/extra-shim.json +0 -4
  43. package/native/third_party/ttsc/shim/tspath/go.mod +0 -5
  44. package/native/third_party/ttsc/shim/tspath/shim.go +0 -236
  45. package/native/third_party/ttsc/shim/vfs/cachedvfs/extra-shim.json +0 -4
  46. package/native/third_party/ttsc/shim/vfs/cachedvfs/go.mod +0 -5
  47. package/native/third_party/ttsc/shim/vfs/cachedvfs/shim.go +0 -12
  48. package/native/third_party/ttsc/shim/vfs/extra-shim.json +0 -4
  49. package/native/third_party/ttsc/shim/vfs/go.mod +0 -5
  50. package/native/third_party/ttsc/shim/vfs/osvfs/extra-shim.json +0 -4
  51. package/native/third_party/ttsc/shim/vfs/osvfs/go.mod +0 -5
  52. package/native/third_party/ttsc/shim/vfs/osvfs/shim.go +0 -13
  53. package/native/third_party/ttsc/shim/vfs/shim.go +0 -22
@@ -1,341 +0,0 @@
1
- // Package driver: post-emit rewriter.
2
- //
3
- // tsgo emits `.js` with plugin-owned call expressions preserved as-is because
4
- // the compile-time transformer stage is now hosted outside the native
5
- // compiler. This file implements the emit-time rewrite pattern pioneered by
6
- // tsgonest: we intercept tsgo's Emit() via its WriteFile callback, locate each
7
- // previously-recognized plugin call in the emitted JS, and replace the call
8
- // expression with the JS the native consumer produced.
9
- //
10
- // The rewriter operates on the output text only — it relies on the caller
11
- // having already produced an ordered list of (file, call, emittedJS) triples.
12
- // Today we match by textual pattern (`<alias>.<method>(...)`), which is safe
13
- // because the compiler-stripped call site is distinctive.
14
- package driver
15
-
16
- import (
17
- "context"
18
- "errors"
19
- "fmt"
20
- "os"
21
- "path/filepath"
22
- "strings"
23
- "unicode"
24
-
25
- "github.com/microsoft/typescript-go/shim/ast"
26
- shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
27
- )
28
-
29
- // Rewrite describes one emit-time patch. Produced by CollectCallSites after
30
- // the engine has generated a replacement JS fragment for the call.
31
- type Rewrite struct {
32
- File *ast.SourceFile
33
- RootName string
34
- Namespaces []string
35
- Method string
36
- Replacement string
37
- ConsumeParens bool
38
- }
39
-
40
- // RewriteSet groups rewrites by file, preserving source order.
41
- type RewriteSet struct {
42
- byPath map[string][]Rewrite
43
- }
44
-
45
- // NewRewriteSet returns an empty set.
46
- func NewRewriteSet() *RewriteSet { return &RewriteSet{byPath: map[string][]Rewrite{}} }
47
-
48
- // Add registers a rewrite under the absolute path of its source file.
49
- func (rs *RewriteSet) Add(r Rewrite) {
50
- if r.File == nil {
51
- return
52
- }
53
- path := filepath.ToSlash(r.File.FileName())
54
- rs.byPath[path] = append(rs.byPath[path], r)
55
- }
56
-
57
- // Len returns the total number of rewrites across every file.
58
- func (rs *RewriteSet) Len() int {
59
- n := 0
60
- for _, rws := range rs.byPath {
61
- n += len(rws)
62
- }
63
- return n
64
- }
65
-
66
- // RewriteSentinel is the marker inserted at the top of a patched file so
67
- // re-running the emit on an already-rewritten file is a no-op.
68
- const RewriteSentinel = "/* @ttsc-rewritten */"
69
-
70
- // EmitAll runs tsgo's emitter, patching every registered plugin-owned call in
71
- // the output. Returns the tsgo diagnostics and any patch-time error. When
72
- // `writeFile` is nil, the patched JS is written to disk via the standard
73
- // tsgo WriteFile.
74
- func (p *Program) EmitAll(rs *RewriteSet, writeFile shimcompiler.WriteFile) (*shimcompiler.EmitResult, []Diagnostic, error) {
75
- return p.emit(rs, nil, writeFile)
76
- }
77
-
78
- // EmitAllRaw runs TypeScript-Go emit without ttsc output-text rewrites.
79
- func (p *Program) EmitAllRaw(writeFile shimcompiler.WriteFile) (*shimcompiler.EmitResult, []Diagnostic, error) {
80
- if p == nil || p.TSProgram == nil {
81
- return nil, nil, errors.New("driver: nil program")
82
- }
83
- wf := writeFile
84
- if wf == nil {
85
- wf = func(fileName, text string, data *shimcompiler.WriteFileData) error {
86
- return DefaultWriteFile(fileName, text)
87
- }
88
- }
89
- result := p.TSProgram.Emit(context.Background(), shimcompiler.EmitOptions{
90
- WriteFile: wf,
91
- })
92
- if result == nil {
93
- return nil, nil, errors.New("driver: Emit returned nil")
94
- }
95
- return result, convertDiagnostics(result.Diagnostics), nil
96
- }
97
-
98
- // EmitFile runs tsgo's emitter for one source file, applying the same rewrite
99
- // pipeline as EmitAll.
100
- func (p *Program) EmitFile(rs *RewriteSet, target *ast.SourceFile, writeFile shimcompiler.WriteFile) (*shimcompiler.EmitResult, []Diagnostic, error) {
101
- return p.emit(rs, target, writeFile)
102
- }
103
-
104
- func (p *Program) emit(rs *RewriteSet, target *ast.SourceFile, writeFile shimcompiler.WriteFile) (*shimcompiler.EmitResult, []Diagnostic, error) {
105
- if p == nil || p.TSProgram == nil {
106
- return nil, nil, errors.New("driver: nil program")
107
- }
108
- if rs == nil {
109
- rs = NewRewriteSet()
110
- }
111
- cursors := map[string]int{}
112
- wf := func(fileName, text string, data *shimcompiler.WriteFileData) error {
113
- // A patched file is idempotent: once the sentinel exists, the emitted text
114
- // is passed through unchanged. This matters for watch/rebuild loops and
115
- // tests that re-run emit over the same output directory.
116
- if strings.Contains(text, RewriteSentinel) {
117
- if writeFile != nil {
118
- return writeFile(fileName, text, data)
119
- }
120
- return DefaultWriteFile(fileName, text)
121
- }
122
- // Rewrites are matched after tsgo has printed JavaScript. The source-file
123
- // association is recovered from the output path because WriteFile receives
124
- // only the final file name and text.
125
- patched, err := applyRewrites(fileName, text, rs, cursors)
126
- if err != nil {
127
- return err
128
- }
129
- if patched != text {
130
- patched = insertSentinel(patched)
131
- }
132
- if writeFile != nil {
133
- return writeFile(fileName, patched, data)
134
- }
135
- return DefaultWriteFile(fileName, patched)
136
- }
137
-
138
- result := p.TSProgram.Emit(context.Background(), shimcompiler.EmitOptions{
139
- TargetSourceFile: target,
140
- WriteFile: wf,
141
- })
142
- if result == nil {
143
- return nil, nil, errors.New("driver: Emit returned nil")
144
- }
145
- return result, convertDiagnostics(result.Diagnostics), nil
146
- }
147
-
148
- // DefaultWriteFile is the default disk writer used when EmitAll's caller does not
149
- // supply a custom WriteFile callback.
150
- func DefaultWriteFile(fileName, text string) error {
151
- if dir := filepath.Dir(fileName); dir != "" {
152
- if err := os.MkdirAll(dir, 0o755); err != nil {
153
- return err
154
- }
155
- }
156
- return os.WriteFile(fileName, []byte(text), 0o644)
157
- }
158
-
159
- func insertSentinel(text string) string {
160
- for _, prefix := range []string{"\"use strict\";\n", "'use strict';\n"} {
161
- if strings.HasPrefix(text, prefix) {
162
- return prefix + RewriteSentinel + "\n" + text[len(prefix):]
163
- }
164
- }
165
- return RewriteSentinel + "\n" + text
166
- }
167
-
168
- func applyRewrites(outputName, text string, rs *RewriteSet, cursors map[string]int) (string, error) {
169
- srcPath, ok := findSourceForOutput(outputName, rs)
170
- if !ok || len(rs.byPath[srcPath]) == 0 {
171
- return text, nil
172
- }
173
- rewrites := rs.byPath[srcPath]
174
- pos := cursors[srcPath]
175
- out := text
176
- searchFrom := 0
177
- for pos < len(rewrites) {
178
- r := rewrites[pos]
179
- replaced, nextSearchFrom, ok, err := spliceCall(out, r, searchFrom)
180
- if err != nil {
181
- return "", err
182
- }
183
- if !ok {
184
- preview := out
185
- if len(preview) > 400 {
186
- preview = preview[:400] + "…"
187
- }
188
- return "", fmt.Errorf("driver: could not locate %s.%s(…) call in %s (tried roots %v; preview: %q)", joinRootAndNamespaces(r), r.Method, outputName, candidateRoots(r.RootName), preview)
189
- }
190
- out = replaced
191
- searchFrom = nextSearchFrom
192
- pos++
193
- }
194
- cursors[srcPath] = pos
195
- return out, nil
196
- }
197
-
198
- func findSourceForOutput(outputName string, rs *RewriteSet) (string, bool) {
199
- outSlash := strings.TrimSuffix(filepath.ToSlash(outputName), filepath.Ext(outputName))
200
- var best string
201
- bestScore := 0
202
- for path := range rs.byPath {
203
- srcStem := strings.TrimSuffix(filepath.ToSlash(path), filepath.Ext(path))
204
- score := commonSuffixSegments(srcStem, outSlash)
205
- if score > bestScore {
206
- best = path
207
- bestScore = score
208
- }
209
- }
210
- return best, bestScore > 0
211
- }
212
-
213
- func commonSuffixSegments(a, b string) int {
214
- as := strings.Split(a, "/")
215
- bs := strings.Split(b, "/")
216
- n := len(as)
217
- if len(bs) < n {
218
- n = len(bs)
219
- }
220
- shared := 0
221
- for i := 1; i <= n; i++ {
222
- if as[len(as)-i] != bs[len(bs)-i] {
223
- break
224
- }
225
- shared++
226
- }
227
- return shared
228
- }
229
-
230
- func spliceCall(text string, r Rewrite, searchFrom int) (string, int, bool, error) {
231
- aliases := candidateRoots(r.RootName)
232
- tail := needleTail(r)
233
- idx := -1
234
- needleLen := 0
235
- for _, cand := range aliases {
236
- candNeedle := cand + tail
237
- if i := indexAtCallStart(text, candNeedle, searchFrom); i >= 0 {
238
- idx = i
239
- needleLen = len(candNeedle) - 1
240
- break
241
- }
242
- }
243
- if idx < 0 {
244
- return text, searchFrom, false, nil
245
- }
246
- parenPos := idx + needleLen
247
- if parenPos >= len(text) || text[parenPos] != '(' {
248
- return text, searchFrom, false, errors.New("driver: expected '(' after method name")
249
- }
250
- closePos, ok := matchParen(text, parenPos)
251
- if !ok {
252
- return text, searchFrom, false, errors.New("driver: unbalanced parens while locating plugin call")
253
- }
254
- if r.ConsumeParens {
255
- replaced := text[:idx] + r.Replacement + text[closePos+1:]
256
- return replaced, idx + len(r.Replacement), true, nil
257
- }
258
- replaced := text[:idx] + r.Replacement + text[idx+needleLen:]
259
- return replaced, idx + len(r.Replacement), true, nil
260
- }
261
-
262
- func candidateRoots(root string) []string {
263
- return []string{
264
- root,
265
- root + "_1.default",
266
- root + "_2.default",
267
- root + ".default",
268
- root + "_1",
269
- root + "_2",
270
- }
271
- }
272
-
273
- func joinRootAndNamespaces(r Rewrite) string {
274
- if len(r.Namespaces) == 0 {
275
- return r.RootName
276
- }
277
- return r.RootName + "." + strings.Join(r.Namespaces, ".")
278
- }
279
-
280
- func needleTail(r Rewrite) string {
281
- if len(r.Namespaces) == 0 {
282
- return "." + r.Method + "("
283
- }
284
- return "." + strings.Join(r.Namespaces, ".") + "." + r.Method + "("
285
- }
286
-
287
- func indexAtCallStart(text, needle string, searchFrom int) int {
288
- start := searchFrom
289
- if start < 0 {
290
- start = 0
291
- }
292
- for {
293
- hit := strings.Index(text[start:], needle)
294
- if hit < 0 {
295
- return -1
296
- }
297
- pos := start + hit
298
- if pos == 0 {
299
- return pos
300
- }
301
- prev := rune(text[pos-1])
302
- if isIdentifierPart(prev) {
303
- start = pos + 1
304
- continue
305
- }
306
- return pos
307
- }
308
- }
309
-
310
- func isIdentifierPart(r rune) bool {
311
- return r == '_' || r == '$' || unicode.IsLetter(r) || unicode.IsDigit(r)
312
- }
313
-
314
- func matchParen(text string, pos int) (int, bool) {
315
- if pos >= len(text) || text[pos] != '(' {
316
- return 0, false
317
- }
318
- depth := 1
319
- for i := pos + 1; i < len(text); i++ {
320
- switch text[i] {
321
- case '(':
322
- depth++
323
- case ')':
324
- depth--
325
- if depth == 0 {
326
- return i, true
327
- }
328
- case '"', '\'', '`':
329
- q := text[i]
330
- j := i + 1
331
- for j < len(text) && text[j] != q {
332
- if text[j] == '\\' {
333
- j++
334
- }
335
- j++
336
- }
337
- i = j
338
- }
339
- }
340
- return 0, false
341
- }
@@ -1,48 +0,0 @@
1
- module github.com/samchon/ttsc/packages/ttsc
2
-
3
- go 1.26
4
-
5
- // Every shim sub-module is wired up via the sibling go.work file together
6
- // with the local typescript-go checkout under ../../third_party/typescript-go.
7
- // Tagged upstream versions can replace these local wires when the shim API
8
- // stabilizes.
9
- replace (
10
- github.com/microsoft/typescript-go/shim/ast => ./shim/ast
11
- github.com/microsoft/typescript-go/shim/bundled => ./shim/bundled
12
- github.com/microsoft/typescript-go/shim/checker => ./shim/checker
13
- github.com/microsoft/typescript-go/shim/compiler => ./shim/compiler
14
- github.com/microsoft/typescript-go/shim/core => ./shim/core
15
- github.com/microsoft/typescript-go/shim/diagnosticwriter => ./shim/diagnosticwriter
16
- github.com/microsoft/typescript-go/shim/parser => ./shim/parser
17
- github.com/microsoft/typescript-go/shim/scanner => ./shim/scanner
18
- github.com/microsoft/typescript-go/shim/tsoptions => ./shim/tsoptions
19
- github.com/microsoft/typescript-go/shim/tspath => ./shim/tspath
20
- github.com/microsoft/typescript-go/shim/vfs => ./shim/vfs
21
- github.com/microsoft/typescript-go/shim/vfs/cachedvfs => ./shim/vfs/cachedvfs
22
- github.com/microsoft/typescript-go/shim/vfs/osvfs => ./shim/vfs/osvfs
23
- )
24
-
25
- require (
26
- github.com/microsoft/typescript-go/shim/ast v0.0.0
27
- github.com/microsoft/typescript-go/shim/bundled v0.0.0
28
- github.com/microsoft/typescript-go/shim/checker v0.0.0
29
- github.com/microsoft/typescript-go/shim/compiler v0.0.0
30
- github.com/microsoft/typescript-go/shim/core v0.0.0
31
- github.com/microsoft/typescript-go/shim/diagnosticwriter v0.0.0
32
- github.com/microsoft/typescript-go/shim/scanner v0.0.0
33
- github.com/microsoft/typescript-go/shim/tsoptions v0.0.0
34
- github.com/microsoft/typescript-go/shim/tspath v0.0.0
35
- github.com/microsoft/typescript-go/shim/vfs v0.0.0
36
- github.com/microsoft/typescript-go/shim/vfs/cachedvfs v0.0.0
37
- github.com/microsoft/typescript-go/shim/vfs/osvfs v0.0.0
38
- )
39
-
40
- require (
41
- github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 // indirect
42
- github.com/klauspost/cpuid/v2 v2.2.10 // indirect
43
- github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157 // indirect
44
- github.com/zeebo/xxh3 v1.1.0 // indirect
45
- golang.org/x/sync v0.20.0 // indirect
46
- golang.org/x/sys v0.43.0 // indirect
47
- golang.org/x/text v0.36.0 // indirect
48
- )
@@ -1,22 +0,0 @@
1
- github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 h1:vymEbVwYFP/L05h5TKQxvkXoKxNvTpjxYKdF1Nlwuao=
2
- github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
3
- github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
4
- github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
5
- github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
6
- github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
7
- github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157 h1:llOMPhKDiQ+UEJiAaQuuWaJOTg5V7tNNTEf9JPWoYSY=
8
- github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157/go.mod h1:m8YA0PMC7ti0GW0RI05D6fEcjQeu98XVS+FWF+VDW2k=
9
- github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
10
- github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
11
- github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
12
- github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
13
- github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
14
- github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
15
- golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
16
- golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
17
- golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
18
- golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
19
- golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
20
- golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
21
- gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
22
- gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
@@ -1,4 +0,0 @@
1
- {
2
- "ExtraMethods": {},
3
- "ExtraFields": {}
4
- }
@@ -1,5 +0,0 @@
1
- module github.com/microsoft/typescript-go/shim/ast
2
-
3
- go 1.26
4
-
5
- require github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157