Skip to content

printer.printNode stripping text within html tags #27216

Closed

Description

@yulric

TypeScript Version: 3.0.3

Search Terms:
printNode JSX
printNode not printing JSX text

Code

const html = '<div>Text within a node</div>';
const jsxAst = ts.createSourceFile(
    'test-file.tsx',
    html,
    ts.ScriptTarget.Latest,
    false,
    ts.ScriptKind.TSX,
);
const printer = ts.createPrinter({
    newLine: ts.NewLineKind.LineFeed,
});
const result = printer.printNode(ts.EmitHint.Unspecified, jsxAst, jsxAst);

Expected behavior:
Value of the result variable should be the same as the html variable

Actual behavior:
result variable is <div></div>

Activity

  1. added
    Needs Investigation
    on Sep 24, 2018
  2. added
    Bug
    and removed
    Needs Investigation
    on Jan 25, 2019
  3. rbuckton commented on May 9, 2019

    @rbuckton
    Contributor

    I cannot reproduce this. I tried adding the following test case to src\testRunner\unittests\printer.ts and got the expected result:

    printsCorrectly("JsxText", {}, printer => {
        const html = '<div>Text within a node</div>';
        const jsxAst = ts.createSourceFile(
            'test-file.tsx',
            html,
            ts.ScriptTarget.Latest,
            false,
            ts.ScriptKind.TSX,
        );
        return printer.printNode(ts.EmitHint.Unspecified, jsxAst, jsxAst);
    });

    It is possible there was an error with either parent pointers or setting the .text property of a JsxText node that has been subsequently fixed.

  4. rbuckton commented on May 9, 2019

    @rbuckton
    Contributor

    It looks like this was fixed by #29439.

  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions