Avoid breaking arguments for last arg expansion (#1305)
We've had this issue since the beginning and I tagged it as 1.0 but haven't managed to fix it by then. We shouldn't allow things to break in the argument list if we are in the last argument expansion mode. It turns out that we now have all the building blocks needed to fix this: - have a special way to flag when we are printing the last argument expansion in the code that prints the argument list - have a way to remove all the softlines from the argument list Fixes #1301master
parent
5995af25a3
commit
8d03423d17
|
@ -1437,21 +1437,6 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
case "TemplateLiteral":
|
case "TemplateLiteral":
|
||||||
var expressions = path.map(print, "expressions");
|
var expressions = path.map(print, "expressions");
|
||||||
|
|
||||||
function removeLines(doc) {
|
|
||||||
// Force this doc into flat mode by statically converting all
|
|
||||||
// lines into spaces (or soft lines into nothing). Hard lines
|
|
||||||
// should still output because there's too great of a chance
|
|
||||||
// of breaking existing assumptions otherwise.
|
|
||||||
return docUtils.mapDoc(doc, d => {
|
|
||||||
if (d.type === "line" && !d.hard) {
|
|
||||||
return d.soft ? "" : " ";
|
|
||||||
} else if (d.type === "if-break") {
|
|
||||||
return d.flatContents || "";
|
|
||||||
}
|
|
||||||
return d;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
parts.push("`");
|
parts.push("`");
|
||||||
|
|
||||||
path.each(function(childPath) {
|
path.each(function(childPath) {
|
||||||
|
@ -2291,7 +2276,7 @@ function printFunctionParams(path, print, options, expandArg) {
|
||||||
// }) ) => {
|
// }) ) => {
|
||||||
// })
|
// })
|
||||||
if (expandArg) {
|
if (expandArg) {
|
||||||
return group(concat(["(", join(", ", printed), ")"]));
|
return group(concat(["(", join(", ", printed.map(removeLines)), ")"]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Single object destructuring should hug
|
// Single object destructuring should hug
|
||||||
|
@ -3579,6 +3564,21 @@ function printArrayItems(path, options, printPath, print) {
|
||||||
return concat(printedElements);
|
return concat(printedElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeLines(doc) {
|
||||||
|
// Force this doc into flat mode by statically converting all
|
||||||
|
// lines into spaces (or soft lines into nothing). Hard lines
|
||||||
|
// should still output because there's too great of a chance
|
||||||
|
// of breaking existing assumptions otherwise.
|
||||||
|
return docUtils.mapDoc(doc, d => {
|
||||||
|
if (d.type === "line" && !d.hard) {
|
||||||
|
return d.soft ? "" : " ";
|
||||||
|
} else if (d.type === "if-break") {
|
||||||
|
return d.flatContents || "";
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function printAstToDoc(ast, options) {
|
function printAstToDoc(ast, options) {
|
||||||
function printGenerically(path, args) {
|
function printGenerically(path, args) {
|
||||||
return comments.printComments(
|
return comments.printComments(
|
||||||
|
|
|
@ -39,6 +39,37 @@ export default function searchUsers(action$) {
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`break.js 1`] = `
|
||||||
|
export default class AddAssetHtmlPlugin {
|
||||||
|
apply(compiler: WebpackCompilerType) {
|
||||||
|
compiler.plugin('compilation', (compilation: WebpackCompilationType) => {
|
||||||
|
compilation.plugin('html-webpack-plugin-before-html', (callback: Callback<any>) => {
|
||||||
|
addAllAssetsToCompilation(this.assets, compilation, htmlPluginData, callback);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
export default class AddAssetHtmlPlugin {
|
||||||
|
apply(compiler: WebpackCompilerType) {
|
||||||
|
compiler.plugin("compilation", (compilation: WebpackCompilationType) => {
|
||||||
|
compilation.plugin(
|
||||||
|
"html-webpack-plugin-before-html",
|
||||||
|
(callback: Callback<any>) => {
|
||||||
|
addAllAssetsToCompilation(
|
||||||
|
this.assets,
|
||||||
|
compilation,
|
||||||
|
htmlPluginData,
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`break-parent.js 1`] = `
|
exports[`break-parent.js 1`] = `
|
||||||
({
|
({
|
||||||
processors: [
|
processors: [
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
export default class AddAssetHtmlPlugin {
|
||||||
|
apply(compiler: WebpackCompilerType) {
|
||||||
|
compiler.plugin('compilation', (compilation: WebpackCompilationType) => {
|
||||||
|
compilation.plugin('html-webpack-plugin-before-html', (callback: Callback<any>) => {
|
||||||
|
addAllAssetsToCompilation(this.assets, compilation, htmlPluginData, callback);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue