@ttsc/wasm 0.26.1 → 0.26.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.
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
|
-
"identity": "
|
|
3
|
+
"identity": "d2aaebc4a3fb711653c25dd4bd96266235c1765720f25de03366130d14fe1d2e",
|
|
4
4
|
"artifacts": [
|
|
5
5
|
{
|
|
6
6
|
"path": "/home/runner/work/ttsc/ttsc/packages/wasm/dist/ttsc.wasm",
|
|
7
7
|
"type": "file",
|
|
8
|
-
"sha256": "
|
|
8
|
+
"sha256": "29bafd930043ecd531782f8565448fb18ea8c5ae703b78dd1dca1c183e06ba83"
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
"path": "/home/runner/work/ttsc/ttsc/packages/wasm/dist/wasm_exec.js",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
121
|
"path": "compiler/emit_sourcemap.go",
|
|
122
|
-
"sha256": "
|
|
122
|
+
"sha256": "78e2a0ad04a7d8845b95a7a248c70fc8348d1c932854ab7976aa7e4e2cc7ecdc"
|
|
123
123
|
},
|
|
124
124
|
{
|
|
125
125
|
"path": "compiler/emitassemble.go",
|
package/dist/ttsc.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -5,12 +5,27 @@
|
|
|
5
5
|
// tsgo's Program.Emit has no hook to inject a custom transformer, so ttsc's
|
|
6
6
|
// driver assembles the per-file emit pipeline by hand (see GetSourceFilesToEmit
|
|
7
7
|
// / GetScriptTransformers / GetOutputPathsFor). That hand-assembly must also
|
|
8
|
-
// reproduce
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// `
|
|
12
|
-
//
|
|
13
|
-
//
|
|
8
|
+
// reproduce every step the emitter would otherwise run: building the printer's
|
|
9
|
+
// options from the compiler options, the source-map branch a bare printer.Write
|
|
10
|
+
// with a nil generator drops entirely, the `emitBOM` byte-order mark, and the
|
|
11
|
+
// `WriteFileData` the emitter hands its writeFile callback. This file ports
|
|
12
|
+
// internal/compiler/emitter.go's `emitJSFile` PrinterOptions construction and
|
|
13
|
+
// the whole of its `printSourceFile` so a build that goes through a plugin
|
|
14
|
+
// transform honors the same compiler options — and produces the same map (and
|
|
15
|
+
// `//# sourceMappingURL=` trailer, and the same first bytes) — a plain build
|
|
16
|
+
// does.
|
|
17
|
+
//
|
|
18
|
+
// Keep it in sync with that emitter source when the pin is bumped. Anything
|
|
19
|
+
// `emitJSFile` sets and this file omits takes the Go zero value, which silently
|
|
20
|
+
// turns the option off for every project that emits through a plugin transform,
|
|
21
|
+
// and anything `printSourceFile` does around the printer that this file omits
|
|
22
|
+
// is missing from the plugin lane's output even when the option set matches.
|
|
23
|
+
// `printer_options_field_set_matches_pinned_emitter_test.go` fails when the pin
|
|
24
|
+
// changes the PrinterOptions field set,
|
|
25
|
+
// `write_file_data_field_set_matches_pinned_emitter_test.go` fails when it
|
|
26
|
+
// changes the WriteFileData field set, and
|
|
27
|
+
// `emit_plugin_transform_matches_plain_emit_for_printer_options_test.go` fails
|
|
28
|
+
// when a forwarded option stops matching the plain emit.
|
|
14
29
|
package compiler
|
|
15
30
|
|
|
16
31
|
import (
|
|
@@ -25,24 +40,43 @@ import (
|
|
|
25
40
|
|
|
26
41
|
// PrintedFile is the rendered output of one source file in the plugin-transform
|
|
27
42
|
// emit path. JS is the JavaScript text, already carrying a trailing
|
|
28
|
-
// `//# sourceMappingURL=` comment when a map was produced
|
|
29
|
-
//
|
|
30
|
-
//
|
|
43
|
+
// `//# sourceMappingURL=` comment when a map was produced and a leading UTF-8
|
|
44
|
+
// byte order mark when `emitBOM` is on. MapText/MapPath are the external
|
|
45
|
+
// source-map file and its path; both are empty when no external map is written
|
|
46
|
+
// (source maps disabled, or an inline map encoded into the JS).
|
|
31
47
|
type PrintedFile struct {
|
|
32
48
|
JS string
|
|
33
49
|
MapText string
|
|
34
50
|
MapPath string
|
|
51
|
+
// SourceMapUrlPos is the offset of the `//# sourceMappingURL=` trailer in JS,
|
|
52
|
+
// or -1 when no trailer was written — the value tsgo's emitter reports as
|
|
53
|
+
// WriteFileData.SourceMapUrlPos so a caller can locate and rewrite the
|
|
54
|
+
// trailer without re-scanning the text. Like the emitter's, it is the printer
|
|
55
|
+
// writer's text position, taken BEFORE the `emitBOM` mark is prepended, so a
|
|
56
|
+
// BOM build's offset is three bytes short of the trailer's position in the
|
|
57
|
+
// written file. That is the pinned emitter's own behavior
|
|
58
|
+
// (internal/compiler/emitter.go::printSourceFile computes sourceMapUrlPos
|
|
59
|
+
// from the writer and only then calls AddUTF8ByteOrderMark), and this lane
|
|
60
|
+
// exists to match it: "correcting" the offset here would make a plugin build
|
|
61
|
+
// disagree with the plain build of the same project.
|
|
62
|
+
SourceMapUrlPos int
|
|
35
63
|
}
|
|
36
64
|
|
|
37
65
|
// PrintFileWithSourceMap renders sourceFile through a printer built from options
|
|
38
66
|
// and emitContext, optionally generating a source map, mirroring
|
|
39
|
-
// emitter.printSourceFile for the single-file
|
|
67
|
+
// emitter.emitJSFile and emitter.printSourceFile for the single-file
|
|
68
|
+
// plugin-transform path. The PrinterOptions below are emitJSFile's, field for
|
|
69
|
+
// field: `removeComments`, `newLine`, `noEmitHelpers`, `sourceMap`,
|
|
70
|
+
// `inlineSourceMap`, `inlineSources`, and `target`. When
|
|
40
71
|
// `sourceMap`/`inlineSourceMap` is enabled (and the file is not JSON) it builds a
|
|
41
72
|
// sourcemap.Generator, feeds it to the printer so positions are recorded,
|
|
42
|
-
// appends the sourceMappingURL trailer, and returns the
|
|
43
|
-
// (or encodes the map inline).
|
|
44
|
-
//
|
|
45
|
-
//
|
|
73
|
+
// appends the sourceMappingURL trailer, records its offset, and returns the
|
|
74
|
+
// external map text/path (or encodes the map inline). `emitBOM` prepends the
|
|
75
|
+
// UTF-8 byte order mark to the JavaScript afterwards, exactly where
|
|
76
|
+
// printSourceFile does it — outside PrinterOptions, which is why forwarding the
|
|
77
|
+
// whole options struct never reached it. The external map is written without a
|
|
78
|
+
// mark, matching the emitter's own `writeText(sourceMapFilePath, ..., nil)`.
|
|
79
|
+
// host supplies the same directory/casing context tsgo's emitter reads.
|
|
46
80
|
func PrintFileWithSourceMap(
|
|
47
81
|
emitContext *innerprinter.EmitContext,
|
|
48
82
|
node *innerast.Node,
|
|
@@ -53,10 +87,13 @@ func PrintFileWithSourceMap(
|
|
|
53
87
|
sourceMapFilePath string,
|
|
54
88
|
) PrintedFile {
|
|
55
89
|
printer := innerprinter.NewPrinter(innerprinter.PrinterOptions{
|
|
90
|
+
RemoveComments: options.RemoveComments.IsTrue(),
|
|
56
91
|
NewLine: options.NewLine,
|
|
92
|
+
NoEmitHelpers: options.NoEmitHelpers.IsTrue(),
|
|
57
93
|
SourceMap: options.SourceMap.IsTrue(),
|
|
58
94
|
InlineSourceMap: options.InlineSourceMap.IsTrue(),
|
|
59
95
|
InlineSources: options.InlineSources.IsTrue(),
|
|
96
|
+
Target: options.Target,
|
|
60
97
|
}, innerprinter.PrintHandlers{}, emitContext)
|
|
61
98
|
writer := innerprinter.NewTextWriter(options.NewLine.GetNewLineCharacter(), 0)
|
|
62
99
|
|
|
@@ -78,7 +115,7 @@ func PrintFileWithSourceMap(
|
|
|
78
115
|
|
|
79
116
|
printer.Write(node, sourceFile, writer, generator)
|
|
80
117
|
|
|
81
|
-
result := PrintedFile{}
|
|
118
|
+
result := PrintedFile{SourceMapUrlPos: -1}
|
|
82
119
|
if generator != nil {
|
|
83
120
|
url := sourceMappingURL(options, generator, host, jsFilePath, sourceMapFilePath, sourceFile)
|
|
84
121
|
if len(url) > 0 {
|
|
@@ -89,6 +126,7 @@ func PrintFileWithSourceMap(
|
|
|
89
126
|
writer.RawWrite("\n")
|
|
90
127
|
}
|
|
91
128
|
}
|
|
129
|
+
result.SourceMapUrlPos = writer.GetTextPos()
|
|
92
130
|
writer.WriteComment("//# sourceMappingURL=")
|
|
93
131
|
writer.WriteComment(url)
|
|
94
132
|
}
|
|
@@ -100,6 +138,9 @@ func PrintFileWithSourceMap(
|
|
|
100
138
|
writer.WriteLine()
|
|
101
139
|
}
|
|
102
140
|
result.JS = writer.String()
|
|
141
|
+
if options.EmitBOM.IsTrue() {
|
|
142
|
+
result.JS = innerstringutil.AddUTF8ByteOrderMark(result.JS)
|
|
143
|
+
}
|
|
103
144
|
return result
|
|
104
145
|
}
|
|
105
146
|
|