Chain prebuild sourcemaps through BrighterScript transpile#1676
Chain prebuild sourcemaps through BrighterScript transpile#1676TwitchBronBron merged 14 commits intomasterfrom
Conversation
TwitchBronBron
left a comment
There was a problem hiding this comment.
@copilot this pr isn't quite right. it's turning _getTranspiledFileContents async. Is that a problem? Evaluate the effectiveness of this pr. maybe add more tests if we need them. also, verify we aren't breaking any existing functionality.
Should this be behind a flag since it's technically changing behavior? However, i might consider it a bug fix because we were orphaning the files from their original locations to begin with.
There was a problem hiding this comment.
Pull request overview
This PR adds sourcemap chaining support so that when a .brs file enters the compiler with an existing sourcemap (from a prebuild step), the emitted .map can trace all the way back to the original pre-prebuild source instead of stopping at the intermediate .brs.
Changes:
- Added
util.resolveInputSourceMap()to discover incoming sourcemaps via co-located.map,sourceMappingURL(relative/absolute), or inline base64 data URIs. - Added
util.applySourceMap()and wired it intoProgram._getTranspiledFileContents()to apply the incoming map onto the generated one. - Added
Programtests covering the four input sourcemap discovery strategies and verifying the final map chains to the original source.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/util.ts |
Adds input sourcemap discovery and a helper to apply/chaining onto a generated map. |
src/Program.ts |
Applies discovered input sourcemaps during transpile and makes the transpile helper async to support async filesystem reads. |
src/Program.spec.ts |
Adds tests ensuring prebuild sourcemaps are discovered and correctly chained into the output. |
Agent-Logs-Url: https://github.com/rokucommunity/brighterscript/sessions/713a1975-d0c5-4c05-99e2-af78bd212baa Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Agent-Logs-Url: https://github.com/rokucommunity/brighterscript/sessions/713a1975-d0c5-4c05-99e2-af78bd212baa Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Making Evaluation: The feature is effective — 4 tests verify all discovery strategies work correctly and the output map chains all the way back to the original source file. No flag needed: behavior only changes when an input sourcemap actually exists (via co-located Added two more edge-case tests (commit
Zero new test failures (the 247 failing tests are pre-existing and unrelated). |
…tests Agent-Logs-Url: https://github.com/rokucommunity/brighterscript/sessions/08c3cd8d-a829-402c-9445-af2294a0cda7 Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Agent-Logs-Url: https://github.com/rokucommunity/brighterscript/sessions/08c3cd8d-a829-402c-9445-af2294a0cda7 Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Agent-Logs-Url: https://github.com/rokucommunity/brighterscript/sessions/08c3cd8d-a829-402c-9445-af2294a0cda7 Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
|
@copilot this action is failing. Please fix. Error: src/testHelpers.spec.ts(275,30): error TS2345: Argument of type '(file: BscFile) => Promise' is not assignable to parameter of type '(file: BscFile) => CodeWithSourceMap'. |
… async callers Agent-Logs-Url: https://github.com/rokucommunity/brighterscript/sessions/42365d14-7736-4374-af0a-279db53a845f Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Fixed in The fix:
|
|
@copilot the build is failing still. plz fix |
The build is passing. The |
Bumped throttle delay from 5ms to 100ms so sleep(1) spacing between sets stays well inside the throttle window despite Windows timer resolution variance.
Summary
.brsfile entered the compiler with an existing sourcemap (produced by a preprocessor or other build step), BrighterScript would silently discard it and generate a fresh map pointing only to the intermediate.brsfile — making the final map useless for debugging back to original source.util.resolveInputSourceMap()to locate an incoming sourcemap from a.brsfile, supporting all four discovery strategies: co-located<file>.brs.map, relativesourceMappingURL, absolutesourceMappingURL, and inline base64data:URI.SourceMapGenerator.applySourceMap()inProgram._getTranspiledFileContents(), chaining it into the BrighterScript-generated map so the output traces all the way back to the original pre-prebuild source.Test plan
Program > prebuild sourcemap chaining > reads co-located .brs.map file— input map discovered via implicit<srcPath>.mapfallbackProgram > prebuild sourcemap chaining > follows relative sourceMappingURL comment in the .brs file— map path resolved relative to the.brsfile's directoryProgram > prebuild sourcemap chaining > follows absolute sourceMappingURL comment in the .brs file— map loaded from an absolute pathProgram > prebuild sourcemap chaining > decodes inline base64 sourceMappingURL in the .brs file— map decoded from embeddeddata:application/json;base64,...URIBrsFile.spec.tsandProgram.spec.tscontinue to pass (no regression for.bsfiles or files without an incoming map)🤖 Generated with Claude Code