GeezerVison is showing github.com — fix(minify): keep parentheses around an assignment under `*`, an `imp… · webpack/webpack@beb300d
File treeExpand file treeCollapse file tree Open diff view settings test/unitCases/javascript
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/javascript/syntax-printer.js +13-5Lines changed: 13 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7183,6 +7183,7 @@ const createNodePrinter = (modules) => { | 7183 | 7183 | if ( | 7184 | 7184 | level === 0 && | 7185 | 7185 | typeOf(parent) === NodeType.BinaryExpression && | | 7186 | + operatorOf(parent) === "+" && | 7186 | 7187 | addedStringOperand(parent, parentAt(1)) === node | 7187 | 7188 | ) { | 7188 | 7189 | return assignNeedsParens(parent, 1); | @@ -11826,7 +11827,7 @@ const createNodePrinter = (modules) => { | 11826 | 11827 | const newCallee = | 11827 | 11828 | typeOf(parentAt(0)) === NodeType.NewExpression && | 11828 | 11829 | childOf(Field.callee, parentAt(0)) === node && | 11829 | | - opensWithCall(shown); | | 11830 | + (typeOf(shown) === NodeType.ImportExpression || opensWithCall(shown)); | 11830 | 11831 | if (wrap || newCallee) output.print("("); | 11831 | 11832 | printPiece( | 11832 | 11833 | /** @type {JavascriptPrintContext} */ (writer).consume(value), | @@ -16589,7 +16590,7 @@ const createNodePrinter = (modules) => { | 16589 | 16590 | if (parent !== undefined) holder = parent; | 16590 | 16591 | } | 16591 | 16592 | dropTailExit(body, holder, type); | 16592 | | - if (FUNCTION_TYPES[type] === 1) noteVoidTail(body, type); | | 16593 | + if (FUNCTION_TYPES[type] === 1) noteVoidTail(holder, body, type); | 16593 | 16594 | // A label whose body went labels nothing. | 16594 | 16595 | if ( | 16595 | 16596 | type === NodeType.LabeledStatement && | @@ -16721,13 +16722,20 @@ const createNodePrinter = (modules) => { | 16721 | 16722 | * A `return` of what is `undefined` anyway ending a function's body prints | 16722 | 16723 | * as a statement of what it runs, its value unread: `return void f()` is `f()`. | 16723 | 16724 | * Nested in an `if`, it would no longer leave before what follows the `if`. | | 16725 | + * @param {number} fn the function | 16724 | 16726 | * @param {number} body the function's body | 16725 | 16727 | * @param {number} type the function's type | 16726 | 16728 | * @returns {void} | 16727 | 16729 | */ | 16728 | | - const noteVoidTail = (body, type) => { | 16729 | | - // An arrow's body of one `return` prints as what that returns. | 16730 | | - if (type === NodeType.ArrowFunctionExpression) return; | | 16730 | + const noteVoidTail = (fn, body, type) => { | | 16731 | + // An arrow's body of one `return` prints as what that returns, and a | | 16732 | + // call printing as the value prints its `void` too. | | 16733 | + if ( | | 16734 | + type === NodeType.ArrowFunctionExpression || | | 16735 | + (reducing.size !== 0 && reducing.has(fn)) | | 16736 | + ) { | | 16737 | + return; | | 16738 | + } | 16731 | 16739 | let last = 0; | 16732 | 16740 | for ( | 16733 | 16741 | let i = tree.fieldCount(Field.body, body) - 1; | |
Collapse file Copy file name to clipboardExpand all lines: test/unitCases/javascript/printer.unittest.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -674,6 +674,8 @@ describe("JavaScript minifier printing a SyntaxTree", () => { | 674 | 674 | // A call of a function running expression statements before its `return` prints them and the value as one sequence. | 675 | 675 | ["var await,yield;async function a(){function b(){await=1}b()}a();async function c(){(function(){await=2})();x=function(){return await}()}c();function*d(){(function(){yield=1})()}d().next();g(await,yield)", { compress: { toplevel: true } }, "var await,yield;(async function(){(function(){await=1})()})();(async function(){!function(){await=2}(),x=function(){return await}()})();(function*(){!function(){yield=1}()})().next();g(await,yield);"], | 676 | 676 | ["function f(){g(this);return 1}x=f();function h(){g(arguments);return 1}y=h();function k(){g(new.target);return 1}z=k();function m(){g(m);return 1}w=m()", { compress: { toplevel: true } }, "x=function(){return g(this),1}(),y=function(){return g(arguments),1}(),z=function(){return g(new.target),1}();function m(){return g(m),1}w=m();"], | | 677 | + ["a=\"\"*(x=\"s\");b=\"\"-(x+=\"s\");function f(){var t=import(\"x\");return new t}console.log(function(){return void g()}())", { compress: {} }, "a=\"\"*(x=\"s\"),b=\"\"-(x+=\"s\");function f(){return new(import(\"x\"))}console.log(void g());"], | | 678 | + ["a=[Infinity][0]/x;b=[Infinity][0]**x;c=-[Infinity][0];d=[Infinity][0]?.toFixed();e=x/[Infinity][0]", { compress: {} }, "a=[1/0][0]/x,b=[1/0][0]**x,c=-[1/0][0],d=[1/0][0]?.toFixed(),e=x/[1/0][0];"], | 677 | 679 | ["a=``.length;b=`abc`[1];c=\"abc\"[3];d=\"a\"[1];e=+void 0;f=void 0*2;g=void 0+void 0;h=void 0|0;i=void 0<1;j=void 0==null;k=void f()+1", { compress: {} }, "a=0,b=\"b\",c=void 0,d=\"a\"[1],e=NaN,f=NaN,g=NaN,h=0,i=!1,j=null==null,k=void f()+1;"], | 678 | 680 | ["var a=f();function k(){a;return g()}x=k();var b=f();function m(){b;return function(){}}m()()", { compress: { toplevel: true } }, "f();x=g();f();(function(){})();"], | 679 | 681 | ["function f(){g();return 1}x=f();function k(){h();return{a:1}}y=k().a;function m(){q();return 2}a(),m(),b()", { compress: { toplevel: true } }, "x=(g(),1),y=(h(),{a:1}).a,a(),q(),b();"], | |
|