-
Notifications
You must be signed in to change notification settings - Fork 13.2k
fix(jsx): correct source location when react-jsx and whitespace before jsx #61534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
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
ffaf949 to
484a445
Compare
There was a problem hiding this 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, andvisitJsxFragmentfunctions to usegetTokenPosOfNode()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 |
the code seemed to be using
node.pos(node.getFullStart()) instead ofnode.getStart(), which caused the source location to be off.now baselines match babel's output (which seems correct).
not sure about using
getTokenPosOfNode()(used bygetStart()), but didn't find any better way to do things internally.fixes #61533