@ttsc/wasm 0.15.1 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ttsc.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// gen_shims:hand-maintained
|
|
2
|
+
//
|
|
3
|
+
// Source-map emission for the single-file plugin-transform emit path.
|
|
4
|
+
//
|
|
5
|
+
// tsgo's Program.Emit has no hook to inject a custom transformer, so ttsc's
|
|
6
|
+
// driver assembles the per-file emit pipeline by hand (see GetSourceFilesToEmit
|
|
7
|
+
// / GetScriptTransformers / GetOutputPathsFor). That hand-assembly must also
|
|
8
|
+
// reproduce the source-map step the emitter would otherwise run: a bare
|
|
9
|
+
// printer.Write with a nil generator drops the `.js.map` entirely. This file
|
|
10
|
+
// ports internal/compiler/emitter.go's `printSourceFile` source-map branch so a
|
|
11
|
+
// `sourceMap` / `inlineSourceMap` build that goes through a plugin transform
|
|
12
|
+
// produces the same map (and `//# sourceMappingURL=` trailer) a plain build
|
|
13
|
+
// does. Keep it in sync with that emitter source when the pin is bumped.
|
|
14
|
+
package compiler
|
|
15
|
+
|
|
16
|
+
import (
|
|
17
|
+
innerast "github.com/microsoft/typescript-go/internal/ast"
|
|
18
|
+
innercore "github.com/microsoft/typescript-go/internal/core"
|
|
19
|
+
inneroutputpaths "github.com/microsoft/typescript-go/internal/outputpaths"
|
|
20
|
+
innerprinter "github.com/microsoft/typescript-go/internal/printer"
|
|
21
|
+
innersourcemap "github.com/microsoft/typescript-go/internal/sourcemap"
|
|
22
|
+
innerstringutil "github.com/microsoft/typescript-go/internal/stringutil"
|
|
23
|
+
innertspath "github.com/microsoft/typescript-go/internal/tspath"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
// PrintedFile is the rendered output of one source file in the plugin-transform
|
|
27
|
+
// emit path. JS is the JavaScript text, already carrying a trailing
|
|
28
|
+
// `//# sourceMappingURL=` comment when a map was produced. MapText/MapPath are
|
|
29
|
+
// the external source-map file and its path; both are empty when no external map
|
|
30
|
+
// is written (source maps disabled, or an inline map encoded into the JS).
|
|
31
|
+
type PrintedFile struct {
|
|
32
|
+
JS string
|
|
33
|
+
MapText string
|
|
34
|
+
MapPath string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// PrintFileWithSourceMap renders sourceFile through a printer built from options
|
|
38
|
+
// and emitContext, optionally generating a source map, mirroring
|
|
39
|
+
// emitter.printSourceFile for the single-file plugin-transform path. When
|
|
40
|
+
// `sourceMap`/`inlineSourceMap` is enabled (and the file is not JSON) it builds a
|
|
41
|
+
// sourcemap.Generator, feeds it to the printer so positions are recorded,
|
|
42
|
+
// appends the sourceMappingURL trailer, and returns the external map text/path
|
|
43
|
+
// (or encodes the map inline). host supplies the same directory/casing context
|
|
44
|
+
// tsgo's emitter reads. With source maps off it is byte-for-byte the prior
|
|
45
|
+
// bare-printer behavior.
|
|
46
|
+
func PrintFileWithSourceMap(
|
|
47
|
+
emitContext *innerprinter.EmitContext,
|
|
48
|
+
node *innerast.Node,
|
|
49
|
+
sourceFile *innerast.SourceFile,
|
|
50
|
+
options *innercore.CompilerOptions,
|
|
51
|
+
host innerprinter.EmitHost,
|
|
52
|
+
jsFilePath string,
|
|
53
|
+
sourceMapFilePath string,
|
|
54
|
+
) PrintedFile {
|
|
55
|
+
printer := innerprinter.NewPrinter(innerprinter.PrinterOptions{
|
|
56
|
+
NewLine: options.NewLine,
|
|
57
|
+
SourceMap: options.SourceMap.IsTrue(),
|
|
58
|
+
InlineSourceMap: options.InlineSourceMap.IsTrue(),
|
|
59
|
+
InlineSources: options.InlineSources.IsTrue(),
|
|
60
|
+
}, innerprinter.PrintHandlers{}, emitContext)
|
|
61
|
+
writer := innerprinter.NewTextWriter(options.NewLine.GetNewLineCharacter(), 0)
|
|
62
|
+
|
|
63
|
+
shouldEmit := (options.SourceMap.IsTrue() || options.InlineSourceMap.IsTrue()) &&
|
|
64
|
+
!innertspath.FileExtensionIs(sourceFile.FileName(), innertspath.ExtensionJson)
|
|
65
|
+
|
|
66
|
+
var generator *innersourcemap.Generator
|
|
67
|
+
if shouldEmit {
|
|
68
|
+
generator = innersourcemap.NewGenerator(
|
|
69
|
+
innertspath.GetBaseFileName(innertspath.NormalizeSlashes(jsFilePath)),
|
|
70
|
+
sourceMapSourceRoot(options),
|
|
71
|
+
sourceMapDirectory(options, host, jsFilePath, sourceFile),
|
|
72
|
+
innertspath.ComparePathsOptions{
|
|
73
|
+
UseCaseSensitiveFileNames: host.UseCaseSensitiveFileNames(),
|
|
74
|
+
CurrentDirectory: host.GetCurrentDirectory(),
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
printer.Write(node, sourceFile, writer, generator)
|
|
80
|
+
|
|
81
|
+
result := PrintedFile{}
|
|
82
|
+
if generator != nil {
|
|
83
|
+
url := sourceMappingURL(options, generator, host, jsFilePath, sourceMapFilePath, sourceFile)
|
|
84
|
+
if len(url) > 0 {
|
|
85
|
+
if !writer.IsAtStartOfLine() {
|
|
86
|
+
if options.NewLine == innercore.NewLineKindCRLF {
|
|
87
|
+
writer.RawWrite("\r\n")
|
|
88
|
+
} else {
|
|
89
|
+
writer.RawWrite("\n")
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
writer.WriteComment("//# sourceMappingURL=")
|
|
93
|
+
writer.WriteComment(url)
|
|
94
|
+
}
|
|
95
|
+
if !options.InlineSourceMap.IsTrue() && len(sourceMapFilePath) > 0 {
|
|
96
|
+
result.MapText = generator.String()
|
|
97
|
+
result.MapPath = sourceMapFilePath
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
writer.WriteLine()
|
|
101
|
+
}
|
|
102
|
+
result.JS = writer.String()
|
|
103
|
+
return result
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// sourceMapSourceRoot mirrors emitter.getSourceRoot: a normalized sourceRoot
|
|
107
|
+
// with a trailing separator so it composes with the relative source paths.
|
|
108
|
+
func sourceMapSourceRoot(options *innercore.CompilerOptions) string {
|
|
109
|
+
root := innertspath.NormalizeSlashes(options.SourceRoot)
|
|
110
|
+
if len(root) > 0 {
|
|
111
|
+
root = innertspath.EnsureTrailingDirectorySeparator(root)
|
|
112
|
+
}
|
|
113
|
+
return root
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// sourceMapDirectory mirrors emitter.getSourceMapDirectory: the directory the
|
|
117
|
+
// sourcemap generator resolves source paths against, honoring sourceRoot/mapRoot
|
|
118
|
+
// and falling back to the .js output directory.
|
|
119
|
+
func sourceMapDirectory(options *innercore.CompilerOptions, host innerprinter.EmitHost, filePath string, sourceFile *innerast.SourceFile) string {
|
|
120
|
+
if len(options.SourceRoot) > 0 {
|
|
121
|
+
return host.CommonSourceDirectory()
|
|
122
|
+
}
|
|
123
|
+
if len(options.MapRoot) > 0 {
|
|
124
|
+
dir := innertspath.NormalizeSlashes(options.MapRoot)
|
|
125
|
+
if sourceFile != nil {
|
|
126
|
+
dir = innertspath.GetDirectoryPath(inneroutputpaths.GetSourceFilePathInNewDir(
|
|
127
|
+
sourceFile.FileName(),
|
|
128
|
+
dir,
|
|
129
|
+
host.GetCurrentDirectory(),
|
|
130
|
+
host.CommonSourceDirectory(),
|
|
131
|
+
host.UseCaseSensitiveFileNames(),
|
|
132
|
+
))
|
|
133
|
+
}
|
|
134
|
+
if innertspath.GetRootLength(dir) == 0 {
|
|
135
|
+
dir = innertspath.CombinePaths(host.CommonSourceDirectory(), dir)
|
|
136
|
+
}
|
|
137
|
+
return dir
|
|
138
|
+
}
|
|
139
|
+
return innertspath.GetDirectoryPath(innertspath.NormalizePath(filePath))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// sourceMappingURL mirrors emitter.getSourceMappingURL: the value written after
|
|
143
|
+
// `//# sourceMappingURL=`, either an inline base64 data URL or the encoded path
|
|
144
|
+
// to the external `.js.map` (honoring mapRoot).
|
|
145
|
+
func sourceMappingURL(options *innercore.CompilerOptions, generator *innersourcemap.Generator, host innerprinter.EmitHost, filePath string, sourceMapFilePath string, sourceFile *innerast.SourceFile) string {
|
|
146
|
+
if options.InlineSourceMap.IsTrue() {
|
|
147
|
+
return generator.Base64DataURL()
|
|
148
|
+
}
|
|
149
|
+
sourceMapFile := innertspath.GetBaseFileName(innertspath.NormalizeSlashes(sourceMapFilePath))
|
|
150
|
+
if len(options.MapRoot) > 0 {
|
|
151
|
+
dir := innertspath.NormalizeSlashes(options.MapRoot)
|
|
152
|
+
if sourceFile != nil {
|
|
153
|
+
dir = innertspath.GetDirectoryPath(inneroutputpaths.GetSourceFilePathInNewDir(
|
|
154
|
+
sourceFile.FileName(),
|
|
155
|
+
dir,
|
|
156
|
+
host.GetCurrentDirectory(),
|
|
157
|
+
host.CommonSourceDirectory(),
|
|
158
|
+
host.UseCaseSensitiveFileNames(),
|
|
159
|
+
))
|
|
160
|
+
}
|
|
161
|
+
if innertspath.GetRootLength(dir) == 0 {
|
|
162
|
+
dir = innertspath.CombinePaths(host.CommonSourceDirectory(), dir)
|
|
163
|
+
return innerstringutil.EncodeURI(innertspath.GetRelativePathToDirectoryOrUrl(
|
|
164
|
+
innertspath.GetDirectoryPath(innertspath.NormalizePath(filePath)),
|
|
165
|
+
innertspath.CombinePaths(dir, sourceMapFile),
|
|
166
|
+
true,
|
|
167
|
+
innertspath.ComparePathsOptions{
|
|
168
|
+
UseCaseSensitiveFileNames: host.UseCaseSensitiveFileNames(),
|
|
169
|
+
CurrentDirectory: host.GetCurrentDirectory(),
|
|
170
|
+
},
|
|
171
|
+
))
|
|
172
|
+
}
|
|
173
|
+
return innerstringutil.EncodeURI(innertspath.CombinePaths(dir, sourceMapFile))
|
|
174
|
+
}
|
|
175
|
+
return innerstringutil.EncodeURI(sourceMapFile)
|
|
176
|
+
}
|