Description
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.