perf(packages/codegen): check sourceText only once - #25887
graphite-app[bot] merged 1 commit into
Conversation
last in printImportAttributes and printIf
#25882
There was a problem hiding this comment.
Pull request overview
This PR is a follow-on optimization to packages/codegen source map generation: it aims to validate options.sourceText once up-front when sourcemap: true, so the rest of the printing/mapping pipeline can assume state.sourceText is present and avoid repeated checks.
Changes:
- Adds a
State-constructor validation forsourceTextwhensourcemapis enabled, and storessourceTextasstring | null. - Removes per-write
sourceTextpresence checks in mapping helpers and relies onStateinvariants instead. - Updates source map generation to read
sourceTextfromState, and adds tests for invalid/missingsourceText.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/codegen/test/source-maps.test.ts | Adds tests asserting printSync rejects missing/invalid sourceText when sourcemaps are enabled. |
| packages/codegen/src-js/state.ts | Makes State.sourceText string | null and performs sourceText validation during state construction for sourcemap builds. |
| packages/codegen/src-js/print/write.ts | Removes repeated sourceText checks in mapping recorders and relies on State invariants. |
| packages/codegen/src-js/print/source_map.ts | Stops reading options.sourceText, instead uses state.sourceText and always includes sourcesContent in the zero-mapping case. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
593b204 to
21612de
Compare
ea9b372 to
95e5ffe
Compare
21612de to
38701e8
Compare
95e5ffe to
0307c70
Compare
0307c70 to
d351c1e
Compare
38701e8 to
8783524
Compare
d351c1e to
b2f9f27
Compare
camc314
left a comment
There was a problem hiding this comment.
can we not enforce this in the type system rather than at runtime?
I don't really see how. |
I was thinking about the logic inside the |
Merge activity
|
Follow-on after #25585. Small optimization. Sourcemaps can't be generated unless `options.sourceText` is provided. This is already checked at the start. So everywhere else can then rely on `state.sourceText != null`, rather than re-checking it on each write.
b2f9f27 to
603b904
Compare
Ah now I get you (I think). #25916 |

Follow-on after #25585. Small optimization.
Sourcemaps can't be generated unless
options.sourceTextis provided. This is already checked at the start. So everywhere else can then rely onstate.sourceText != null, rather than re-checking it on each write.