Skip to content
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

Printer incorrectly adding line break when emitting node list with non-synthesized nodes as of TS 4.3 #44068

Closed
devversion opened this issue May 13, 2021 · 0 comments · Fixed by #44070
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@devversion
Copy link
Contributor

devversion commented May 13, 2021

Bug Report

🔎 Search Terms

printer, line break, ts 4.3, beta, for non-synthesized nodes, line separator, new line.

🕗 Version & Regression Information

Started as of v4.3-dev.

⏯ Playground Link

Specific to the compiler API; not reproduce in the playground.

💻 Code

Reproduction repository: https://github.com/devversion/ts-4.3-emitter-node-list-line-breaks

Consider an input file as the followed:

const FirstSymbol = Symbol();
const SecondSymbol = Symbol();

Assume we have the AST for this source file and have access to these variables. i.e. firstVarNode and secondVarNode. If we construct a new array literal containing the names of these variables and print the array literal, the array literal will be multi-line.

const arrayLiteral = ts.createArrayLiteral([
    firstVarNode.name,
    secondVarNode.name
]);

console.log(printer.printNode(ts.EmitHint.Unspecified, arrayLiteral, testFile));

the output will be:

[FirstSymbol,
    SecondSymbol]

while I'd expect it to be [FirstSymbol, SecondSymbol] unless I specify multiLine = true for the array literal expression.

Additional information

This seems to have changed with 3c32f6e. The printer now checks if the non-synthesized nodes are on the same line, even if they do not have the same parent.

@devversion devversion changed the title Printer incorrectly adding line break when emitting node list as of TS 4.3 Printer incorrectly adding line break when emitting node list with non-synthesized nodes as of TS 4.3 May 13, 2021
devversion added a commit to devversion/TypeScript that referenced this issue May 13, 2021
…mitting node list

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This is wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
devversion added a commit to devversion/TypeScript that referenced this issue May 13, 2021
…mitting node list

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This is wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
devversion added a commit to devversion/TypeScript that referenced this issue May 13, 2021
…mitting node list

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This is wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
devversion added a commit to devversion/TypeScript that referenced this issue May 13, 2021
…mitting node list

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This is wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
devversion added a commit to devversion/TypeScript that referenced this issue May 13, 2021
…mitting node list

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This is wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
devversion added a commit to devversion/TypeScript that referenced this issue May 13, 2021
…mitting node list

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This it push s wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 13, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.4.0 milestone May 13, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label May 13, 2021
devversion added a commit to devversion/TypeScript that referenced this issue May 14, 2021
…mitting node list

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This it push s wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
devversion added a commit to devversion/TypeScript that referenced this issue May 14, 2021
…mitting node list

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This it push s wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
devversion added a commit to devversion/TypeScript that referenced this issue May 14, 2021
…mitting node list

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This it push s wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this issue May 20, 2021
Component commits:
d192080 Do not incorrectly add line separators for non-synthetic nodes when emitting node list
As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This it push s wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes microsoft#44068.
andrewbranch pushed a commit that referenced this issue Jun 4, 2021
…mitting node list (#44070)

As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This it push s wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes #44068.
DanielRosenwasser pushed a commit that referenced this issue Jun 16, 2021
Component commits:
d192080 Do not incorrectly add line separators for non-synthetic nodes when emitting node list
As of 3c32f6e, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This it push s wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes #44068.

Co-authored-by: Paul Gschwendtner <paulgschwendtner@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
5 participants