fix(javascript): correct indentation for expression in root template (#5607)
parent
cd141c5347
commit
419559e964
|
@ -2491,10 +2491,8 @@ function printPathNoParens(path, options, print, args) {
|
|||
// expression inside at the beginning of ${ instead of the beginning
|
||||
// of the `.
|
||||
const tabWidth = options.tabWidth;
|
||||
const indentSize = getIndentSize(
|
||||
childPath.getValue().value.raw,
|
||||
tabWidth
|
||||
);
|
||||
const quasi = childPath.getValue();
|
||||
const indentSize = getIndentSize(quasi.value.raw, tabWidth);
|
||||
|
||||
let printed = expressions[i];
|
||||
|
||||
|
@ -2507,7 +2505,10 @@ function printPathNoParens(path, options, print, args) {
|
|||
printed = concat([indent(concat([softline, printed])), softline]);
|
||||
}
|
||||
|
||||
const aligned = addAlignmentToDoc(printed, indentSize, tabWidth);
|
||||
const aligned =
|
||||
indentSize === 0 && quasi.value.raw.endsWith("\n")
|
||||
? align(-Infinity, printed)
|
||||
: addAlignmentToDoc(printed, indentSize, tabWidth);
|
||||
|
||||
parts.push(group(concat(["${", aligned, lineSuffixBoundary, "}"])));
|
||||
}
|
||||
|
|
|
@ -187,6 +187,59 @@ module.exports = Relay.createContainer(
|
|||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`indent.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babylon"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const foo = () => {
|
||||
{
|
||||
{
|
||||
{
|
||||
return \`
|
||||
line 1
|
||||
line 2
|
||||
...
|
||||
line n
|
||||
\${foo({
|
||||
many: keys,
|
||||
many: keys
|
||||
})}
|
||||
line n + 1
|
||||
line n + 2
|
||||
line n + n
|
||||
\`;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
=====================================output=====================================
|
||||
const foo = () => {
|
||||
{
|
||||
{
|
||||
{
|
||||
return \`
|
||||
line 1
|
||||
line 2
|
||||
...
|
||||
line n
|
||||
\${foo({
|
||||
many: keys,
|
||||
many: keys
|
||||
})}
|
||||
line n + 1
|
||||
line n + 2
|
||||
line n + n
|
||||
\`;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`inline.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babylon"]
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
const foo = () => {
|
||||
{
|
||||
{
|
||||
{
|
||||
return `
|
||||
line 1
|
||||
line 2
|
||||
...
|
||||
line n
|
||||
${foo({
|
||||
many: keys,
|
||||
many: keys
|
||||
})}
|
||||
line n + 1
|
||||
line n + 2
|
||||
line n + n
|
||||
`;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue