Skip to content

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

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

Open
AviVahl opened this issue Apr 5, 2025 · 0 comments Β· May be fixed by #61534
Open

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

AviVahl opened this issue Apr 5, 2025 · 0 comments Β· May be fixed by #61534
Assignees
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@AviVahl
Copy link

AviVahl commented Apr 5, 2025

πŸ”Ž Search Terms

react-jsxdev, jsxdev, location

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?jsx=5#code/KYDwDg9gTgLgBAYwgOwM7wLIE8DCEC2YcAvHABQCUJAfHAN4BQccUwMArlMuU83ADwATAJYA3OAHpqvCgwC+DIA

πŸ’» Code

export const MyComp = () => {
  return (
    <div />
  )
}

πŸ™ Actual behavior

import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
const _jsxFileName = "file:///input.tsx";
export const MyComp = () => {
    return (_jsxDEV("div", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 2, columnNumber: 11 }, this));
};

πŸ™‚ Expected behavior

import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
const _jsxFileName = "file:///input.tsx";
export const MyComp = () => {
    return (_jsxDEV("div", {}, void 0, false, { fileName: _jsxFileName, lineNumber: 3, columnNumber: 5 }, this));
};

Additional information about the issue

Babel has correct location:
https://babeljs.io/repl/#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=KYDwDg9gTgLgBAYwgOwM7wLIE8DCEC2YcAvHABQCUJAfHAN4BQccUwMArlMuU83ADwATAJYA3OAHpqvCgwC-DIA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=react%2Cstage-2&prettier=false&targets=&version=7.27.0&externalPlugins=%40babel%2Fplugin-transform-react-jsx-development%407.25.9&assumptions=%7B%7D

AviVahl added a commit to AviVahl/TypeScript that referenced this issue Apr 5, 2025
…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.
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Apr 8, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants