Skip to content

Conversation

@AviVahl
Copy link

@AviVahl AviVahl commented Apr 5, 2025

the code seemed to be using node.pos (node.getFullStart()) instead of node.getStart(), which caused the source location to be off.

now baselines match babel's output (which seems correct).

not sure about using getTokenPosOfNode() (used by getStart()), but didn't find any better way to do things internally.

fixes #61533

@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Apr 5, 2025
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Apr 5, 2025
@AviVahl
Copy link
Author

AviVahl commented Apr 6, 2025

I've applied the same fix for fragments as well, as they seemed to use the same pattern for source location handling.

…e jsx

fixes microsoft#61533

the code seemed to be using `node.pos` (`node.getFullStart()`) instead of `node.getStart()`, which caused the source location to be off.

now baselines match babel's output (which seems correct).

not sure about using `getTokenPosOfNode()` (used by `getStart()`), but didn't find any better way to do things internally.
original reported issue did not include any fragment, but pattern seems the same, so correct these as well
@AviVahl AviVahl force-pushed the fix-jsxdev-source-location branch from ffaf949 to 484a445 Compare December 22, 2025 13:53
Copilot AI review requested due to automatic review settings December 22, 2025 13:53
@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Dec 22, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect source location information in JSX transformation when using react-jsx mode with whitespace before JSX elements. The issue was that the code was using node.pos (which includes leading trivia) instead of node.getStart() (which excludes leading trivia), causing column numbers in generated code to be off by the amount of leading whitespace.

Key changes:

  • Updated visitJsxElement, visitJsxSelfClosingElement, and visitJsxFragment functions to use getTokenPosOfNode() for accurate source location
  • All test baselines now show corrected column numbers that match Babel's output

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/compiler/transformers/jsx.ts Modified JSX visitor functions to use getTokenPosOfNode() for correct source locations
tests/baselines/reference/tsxReactEmit8(jsx=react-jsxdev).js Updated baseline with corrected line and column numbers
tests/baselines/reference/reactImportUnusedInNewJSXEmit(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxRuntimePragma(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxNamespaceNoElementChildrenAttributeReactJsx(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxNamespaceElementChildrenAttributeIgnoredWhenReactJsx(jsx=react-jsxdev).js Updated baseline with corrected line and column numbers
tests/baselines/reference/jsxJsxsCjsTransformSubstitutesNamesFragment(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxJsxsCjsTransformSubstitutesNames(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxJsxsCjsTransformNestedSelfClosingChild(jsx=react-jsxdev).js Updated baseline with corrected line and column numbers
tests/baselines/reference/jsxJsxsCjsTransformKeyPropCustomImportPragma(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxJsxsCjsTransformKeyPropCustomImport(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxJsxsCjsTransformKeyProp(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxJsxsCjsTransformChildren(jsx=react-jsxdev).js Updated baseline with corrected column numbers
tests/baselines/reference/jsxEmptyExpressionNotCountedAsChild(jsx=react-jsxdev).js Updated baseline with corrected line and column numbers
tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).js Updated baseline with corrected column numbers
tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).js Updated baseline with corrected column numbers
tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).js Updated baseline with corrected column numbers
tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).js Updated baseline with corrected column numbers
tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).js Updated baseline with corrected column numbers
tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).js Updated baseline with corrected column numbers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Wrong location generated for JSX with whitespace around it when react-jsxdev

3 participants