Adds an optional source map to downlevel and downlevel-jsx modes, and makes the JSX output easier to map.
Source maps #
transform(src, { mode: "downlevel", sourceMap: true }) returns { code, map }. The chunked generator returns the map as its done value. Erase mode returns map: null, since it keeps every offset. The option also takes { source, file, includeContent }.
Every generated line gets an identity segment at column 0, because Chrome and Node floor-search across lines and Mozilla's library returns null for a line with no segment. Rewritten lines get a segment at each edit boundary and at each copied token after the first shift. No names, no Scopes: nothing is renamed.
In the engine, the three output primitives log records (generated line and column, source line and column) into a new MAP region with mapCount, mapPtr, mapLine, and mapSrcLine exports. Records under an anchor are held and adjusted by the two remaining insert-into-earlier-output paths. The wrapper fills identity segments and encodes VLQ with a ten-line function. The erase engine carries none of it.
JSX output #
- The callee and
children:[are fixed-width slots filled in place at the element's close. Only_createElement(still inserts. - The automatic runtime's imports go before the trailing trivia, so a file ending in a
//comment keeps its line count. - A moved
keycarries its value's source position into its record.
Docs and tests #
docs/sourcemaps.md explains the no-map common case, the line-preserving approach, the consumer rule, a worked example checked against real output, and the implementation. test/sourcemap.mjs round-trips every downlevel and JSX corpus case through @jridgewell/trace-mapping, with random chunking.
Sizes (gzip) #
| Engine | Before | After |
|---|---|---|
| erase.wasm | 13.7 kB | 13.7 kB |
| downlevel.wasm | 19.0 kB | 20.1 kB |
| downlevel-jsx.wasm | 23.6 kB | 25.0 kB |
| wrapper | 3.3 kB | 4.1 kB |
Throughput on the OSS samples is unchanged within noise in all three modes. Parameter-property fields stay at the class {: moving them after the constructor changes own-key order, which the downlevel corpus pins.