Skip to content

ts.createSourceFile trims leading newlines, causing stored line numbers to mismatchΒ #58517

@Artur-

Description

@Artur-

πŸ”Ž Search Terms

createSourceFile newlines trim

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about createSourceFile

⏯ Playground Link

No response

πŸ’» Code

import React from 'react';

export default function HelloWorldView() {
  return <span>Hello</span>;
}

πŸ™ Actual behavior

Given this TSX file, React tooling will store a source reference on the <span> element as e.g.

$0.__reactFiber$wzqrbgzp6o._debugSource

and it will contain

{
columnNumber: 10,
fileName: ".../something.tsx",
lineNumber: 7
}

However, if you feed the TSX file into ts.createSourceFile and look for an element on line 7, you will not find anything because the file has been changed to

import React from 'react';

export default function HelloWorldView() {
  return <span>Hello</span>;
}

and it only has 5 lines

πŸ™‚ Expected behavior

ts.createSourceFile does no transformations whatsoever on the given input

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions