Repository navigation
fix: map while/else/catch/finally/case/default keywords to source - #117
Merged
Merged
Conversation
|
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #116 - extends keyword sourcemap coverage to control-flow keywords that were previously emitted as raw text.
Implementation changes (
src/languages/ts/index.js)DoWhileStatement: derivewhilesource position fromtest.column - 7when test is on the same line as body end; fall back to plain text otherwise.IfStatementalternate: deriveelsesource position fromalternate.column - 5when alternate is on the same line as consequent end.SwitchCase: routecaseanddefaultthroughwrite_keywordusing the case node's ownloc.TryStatement:catchuseswrite_keyword(handler, ...);finallyderives its position fromfinalizer.column - 8since theBlockStatementfinalizer doesn't carry the keyword's loc.handle_var_declaration: collapsed theif (node.loc) / elsesplit into a singlecreate_keyword_writepath with(n) => !!n.locpredicate.@type {string}casts onnode.accessibility.Why the
.mapupdates are betterEach control-flow keyword now has its own segment pointing back to source. Before,
while/else/case/default/catch/finallywere raw strings with no mapping - debuggers stepping on them would land on the previous mapped token (or nowhere). After: breakpoints on keywords resolve, stack traces pointing at acase/catchshow the right source line, devtools highlight the actual keyword.try-catch: new dedicated segments forcatchandfinally.switch: new segments forcaseanddefault.empty-body:do ... whileandelse ifnow get separatewhile/elsesegments.Test improvements (
test/sourcemap-keywords.test.js)Previously only class-level keywords were covered (static/get). Added 6 new tests asserting
seg[3] === source.indexOf(keyword):throw / return / awaitif / elsetry / catch / finallydo / whileswitch / case / default