GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(minify): keep parentheses around an assignment under `*`, an `imp… · webpack/webpack@beb300d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/javascript
    • syntax-printer.js
  • test/unitCases/javascript
    • printer.unittest.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/javascript/syntax-printer.js‎

Copy file name to clipboardExpand all lines: lib/javascript/syntax-printer.js
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7183,6 +7183,7 @@ const createNodePrinter = (modules) => {
71837183
if (
71847184
level === 0 &&
71857185
typeOf(parent) === NodeType.BinaryExpression &&
7186+
operatorOf(parent) === "+" &&
71867187
addedStringOperand(parent, parentAt(1)) === node
71877188
) {
71887189
return assignNeedsParens(parent, 1);
@@ -11826,7 +11827,7 @@ const createNodePrinter = (modules) => {
1182611827
const newCallee =
1182711828
typeOf(parentAt(0)) === NodeType.NewExpression &&
1182811829
childOf(Field.callee, parentAt(0)) === node &&
11829-
opensWithCall(shown);
11830+
(typeOf(shown) === NodeType.ImportExpression || opensWithCall(shown));
1183011831
if (wrap || newCallee) output.print("(");
1183111832
printPiece(
1183211833
/** @type {JavascriptPrintContext} */ (writer).consume(value),
@@ -16589,7 +16590,7 @@ const createNodePrinter = (modules) => {
1658916590
if (parent !== undefined) holder = parent;
1659016591
}
1659116592
dropTailExit(body, holder, type);
16592-
if (FUNCTION_TYPES[type] === 1) noteVoidTail(body, type);
16593+
if (FUNCTION_TYPES[type] === 1) noteVoidTail(holder, body, type);
1659316594
// A label whose body went labels nothing.
1659416595
if (
1659516596
type === NodeType.LabeledStatement &&
@@ -16721,13 +16722,20 @@ const createNodePrinter = (modules) => {
1672116722
* A `return` of what is `undefined` anyway ending a function's body prints
1672216723
* as a statement of what it runs, its value unread: `return void f()` is `f()`.
1672316724
* Nested in an `if`, it would no longer leave before what follows the `if`.
16725+
* @param {number} fn the function
1672416726
* @param {number} body the function's body
1672516727
* @param {number} type the function's type
1672616728
* @returns {void}
1672716729
*/
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+
}
1673116739
let last = 0;
1673216740
for (
1673316741
let i = tree.fieldCount(Field.body, body) - 1;
Collapse file

‎test/unitCases/javascript/printer.unittest.js‎

Copy file name to clipboardExpand all lines: test/unitCases/javascript/printer.unittest.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,8 @@ describe("JavaScript minifier printing a SyntaxTree", () => {
674674
// A call of a function running expression statements before its `return` prints them and the value as one sequence.
675675
["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);"],
676676
["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];"],
677679
["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;"],
678680
["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(){})();"],
679681
["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();"],

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.