Eagerly evaluate ifBreak when processing template literals (fixes #795) (#798)

This commit is contained in:
James Long authored and Christopher Chedeau committed 2017-02-23 21:21:13 -08:00
1 parent 2111f1152c
commit cea254857a
5 files changed
+133 -20

No files matched your search

+3
View File
@@ -1388,6 +1388,9 @@ function genericPrintNoParens(path, options, print) {
if (d.type === "line" && !d.hard) {
return d.soft ? "" : " ";
}
else if(d.type === "if-break") {
return d.flatContents || "";
}
return d;
});
}
+116 -10
View File
@@ -26,16 +26,6 @@ exports[`strings.js 1`] = `
'\\\\uD801\\\\uDC28',
];
foo(\`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 } with expr\`);
const x = \`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {return 3 })() + 3 + 2 + 3 + 2 + 3 } with expr\`;
foo(\`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {
const x = 5;
return x;
})() + 3 + 2 + 3 + 2 + 3 } with expr\`);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[
\\"abc\\",
@@ -61,17 +51,133 @@ foo(\`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( functi
\\"🐶\\",
'\\\\uD801\\\\uDC28'
];
"
`;
exports[`strings.js 2`] = `
"[
\\"abc\\",
'abc',
'\\\\'',
'\\"',
'\\\\\\"',
'\\\\\\\\\\"',
\\"'\\",
\\"\\\\'\\",
\\"\\\\\\\\'\\",
\\"'\\\\\\"\\",
'\\\\'\\"',
'\\\\\\\\',
\\"\\\\\\\\\\",
'\\\\0',
'🐶',
'\\\\uD801\\\\uDC28',
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[
\\"abc\\",
\\"abc\\",
\\"'\\",
'\\"',
'\\"',
'\\\\\\\\\\"',
\\"'\\",
\\"'\\",
\\"\\\\\\\\'\\",
\\"'\\\\\\"\\",
\\"'\\\\\\"\\",
\\"\\\\\\\\\\",
\\"\\\\\\\\\\",
\\"\\\\0\\",
\\"🐶\\",
'\\\\uD801\\\\uDC28',
];
"
`;
exports[`template-literals.js 1`] = `
"foo(\`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 } with expr\`);
const x = \`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {return 3 })() + 3 + 2 + 3 + 2 + 3 } with expr\`;
foo(\`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {
const x = 5;
return x;
})() + 3 + 2 + 3 + 2 + 3 } with expr\`);
pipe.write(
\`\\\\n \${chalk.dim(\`\\\\u203A and \${more} more \${more} more \${more} more \${more}\`)}\`,
);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo(
\`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3} with expr\`
);
const x = \`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + (function() {
return 3;
})() + 3 + 2 + 3 + 2 + 3} with expr\`;
foo(
\`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + (function() {
const x = 5;
return x;
})() + 3 + 2 + 3 + 2 + 3} with expr\`
);
pipe.write(
\`\\\\n \${chalk.dim(\`\\\\u203A and \${more} more \${more} more \${more} more \${more}\`)}\`
);
"
`;
exports[`template-literals.js 2`] = `
"foo(\`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 } with expr\`);
const x = \`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {return 3 })() + 3 + 2 + 3 + 2 + 3 } with expr\`;
foo(\`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {
const x = 5;
return x;
})() + 3 + 2 + 3 + 2 + 3 } with expr\`);
pipe.write(
\`\\\\n \${chalk.dim(\`\\\\u203A and \${more} more \${more} more \${more} more \${more}\`)}\`,
);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo(
\`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3} with expr\`,
);
const x = \`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + (function() {
return 3;
})() + 3 + 2 + 3 + 2 + 3} with expr\`;
foo(
\`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + (function() {
const x = 5;
return x;
})() + 3 + 2 + 3 + 2 + 3} with expr\`,
);
pipe.write(
\`\\\\n \${chalk.dim(\`\\\\u203A and \${more} more \${more} more \${more} more \${more}\`)}\`,
);
"
`;
+1
View File
@@ -1 +1,2 @@
run_spec(__dirname);
run_spec(__dirname, { trailingComma: "all" });
-10
View File
@@ -23,13 +23,3 @@
'\uD801\uDC28',
];
foo(`a long string ${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 } with expr`);
const x = `a long string ${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {return 3 })() + 3 + 2 + 3 + 2 + 3 } with expr`;
foo(`a long string ${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {
const x = 5;
return x;
})() + 3 + 2 + 3 + 2 + 3 } with expr`);
+13
View File
@@ -0,0 +1,13 @@
foo(`a long string ${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 } with expr`);
const x = `a long string ${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {return 3 })() + 3 + 2 + 3 + 2 + 3 } with expr`;
foo(`a long string ${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function() {
const x = 5;
return x;
})() + 3 + 2 + 3 + 2 + 3 } with expr`);
pipe.write(
`\n ${chalk.dim(`\u203A and ${more} more ${more} more ${more} more ${more}`)}`,
);