diff --git a/src/ast/nodes/AssignmentExpression.ts b/src/ast/nodes/AssignmentExpression.ts index 70923632523..8dcd6f4fd0c 100644 --- a/src/ast/nodes/AssignmentExpression.ts +++ b/src/ast/nodes/AssignmentExpression.ts @@ -4,6 +4,7 @@ import { findFirstOccurrenceOutsideComment, findNonWhiteSpace, NodeRenderOptions, + removeLineBreaks, RenderOptions } from '../../utils/renderHelpers'; import { getSystemExportFunctionLeft } from '../../utils/systemJsRendering'; @@ -67,17 +68,23 @@ export default class AssignmentExpression extends NodeBase { render( code: MagicString, options: RenderOptions, - { renderedParentType }: NodeRenderOptions = BLANK + { preventASI, renderedParentType }: NodeRenderOptions = BLANK ) { if (this.left.included) { this.left.render(code, options); this.right.render(code, options); } else { + const inclusionStart = findNonWhiteSpace( + code.original, + findFirstOccurrenceOutsideComment(code.original, '=', this.left.end) + 1 + ); + code.remove(this.start, inclusionStart); + if (preventASI) { + removeLineBreaks(code, inclusionStart, this.right.start); + } this.right.render(code, options, { renderedParentType: renderedParentType || this.parent.type }); - const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', this.left.end); - code.remove(this.start, findNonWhiteSpace(code.original, operatorPos + 1)); } if (options.format === 'system') { const exportNames = diff --git a/src/ast/nodes/CallExpression.ts b/src/ast/nodes/CallExpression.ts index 2bf7a1c5e4f..49d71192052 100644 --- a/src/ast/nodes/CallExpression.ts +++ b/src/ast/nodes/CallExpression.ts @@ -226,9 +226,14 @@ export default class CallExpression extends NodeBase implements DeoptimizableEnt render( code: MagicString, options: RenderOptions, - { renderedParentType }: NodeRenderOptions = BLANK + { renderedParentType, renderedSurroundingElement }: NodeRenderOptions = BLANK ) { - this.callee.render(code, options); + const surroundingELement = renderedParentType || renderedSurroundingElement; + this.callee.render( + code, + options, + surroundingELement ? { renderedSurroundingElement: surroundingELement } : BLANK + ); if (this.arguments.length > 0) { if (this.arguments[this.arguments.length - 1].included) { for (const arg of this.arguments) { @@ -259,13 +264,6 @@ export default class CallExpression extends NodeBase implements DeoptimizableEnt } } } - if ( - renderedParentType === NodeType.ExpressionStatement && - this.callee.type === NodeType.FunctionExpression - ) { - code.appendRight(this.start, '('); - code.prependLeft(this.end, ')'); - } } private getReturnExpression(recursionTracker: PathTracker): ExpressionEntity { diff --git a/src/ast/nodes/ClassExpression.ts b/src/ast/nodes/ClassExpression.ts index 6d9effd2dda..ceea4803202 100644 --- a/src/ast/nodes/ClassExpression.ts +++ b/src/ast/nodes/ClassExpression.ts @@ -1,6 +1,22 @@ +import MagicString from 'magic-string'; +import { BLANK } from '../../utils/blank'; +import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; import * as NodeType from './NodeType'; import ClassNode from './shared/ClassNode'; export default class ClassExpression extends ClassNode { type!: NodeType.tClassExpression; + + render( + code: MagicString, + options: RenderOptions, + { renderedParentType, renderedSurroundingElement }: NodeRenderOptions = BLANK + ) { + super.render(code, options); + const surroundingElement = renderedParentType || renderedSurroundingElement; + if (surroundingElement === NodeType.ExpressionStatement) { + code.appendRight(this.start, '('); + code.prependLeft(this.end, ')'); + } + } } diff --git a/src/ast/nodes/ConditionalExpression.ts b/src/ast/nodes/ConditionalExpression.ts index 1a498e4dbe6..2b1dfea88a3 100644 --- a/src/ast/nodes/ConditionalExpression.ts +++ b/src/ast/nodes/ConditionalExpression.ts @@ -2,6 +2,7 @@ import MagicString from 'magic-string'; import { BLANK } from '../../utils/blank'; import { findFirstOccurrenceOutsideComment, + findNonWhiteSpace, NodeRenderOptions, removeLineBreaks, RenderOptions @@ -171,10 +172,12 @@ export default class ConditionalExpression extends NodeBase implements Deoptimiz ) { if (!this.test.included) { const colonPos = findFirstOccurrenceOutsideComment(code.original, ':', this.consequent.end); - const inclusionStart = + const inclusionStart = findNonWhiteSpace( + code.original, (this.consequent.included ? findFirstOccurrenceOutsideComment(code.original, '?', this.test.end) - : colonPos) + 1; + : colonPos) + 1 + ); if (preventASI) { removeLineBreaks(code, inclusionStart, this.usedBranch!.start); } diff --git a/src/ast/nodes/FunctionExpression.ts b/src/ast/nodes/FunctionExpression.ts index 999126de59c..77e44b70111 100644 --- a/src/ast/nodes/FunctionExpression.ts +++ b/src/ast/nodes/FunctionExpression.ts @@ -1,6 +1,22 @@ +import MagicString from 'magic-string'; +import { BLANK } from '../../utils/blank'; +import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; import * as NodeType from './NodeType'; import FunctionNode from './shared/FunctionNode'; export default class FunctionExpression extends FunctionNode { type!: NodeType.tFunctionExpression; + + render( + code: MagicString, + options: RenderOptions, + { renderedParentType, renderedSurroundingElement }: NodeRenderOptions = BLANK + ) { + super.render(code, options); + const surroundingElement = renderedParentType || renderedSurroundingElement; + if (surroundingElement === NodeType.ExpressionStatement) { + code.appendRight(this.start, '('); + code.prependLeft(this.end, ')'); + } + } } diff --git a/src/ast/nodes/LabeledStatement.ts b/src/ast/nodes/LabeledStatement.ts index b4063439d0c..a8aab9dcf98 100644 --- a/src/ast/nodes/LabeledStatement.ts +++ b/src/ast/nodes/LabeledStatement.ts @@ -1,5 +1,9 @@ import MagicString from 'magic-string'; -import { findFirstOccurrenceOutsideComment, RenderOptions } from '../../utils/renderHelpers'; +import { + findFirstOccurrenceOutsideComment, + findNonWhiteSpace, + RenderOptions +} from '../../utils/renderHelpers'; import { HasEffectsContext, InclusionContext } from '../ExecutionContext'; import Identifier from './Identifier'; import * as NodeType from './NodeType'; @@ -39,7 +43,10 @@ export default class LabeledStatement extends StatementBase { } else { code.remove( this.start, - findFirstOccurrenceOutsideComment(code.original, ':', this.label.end) + 1 + findNonWhiteSpace( + code.original, + findFirstOccurrenceOutsideComment(code.original, ':', this.label.end) + 1 + ) ); } this.body.render(code, options); diff --git a/src/ast/nodes/LogicalExpression.ts b/src/ast/nodes/LogicalExpression.ts index 50125fe9052..e19ba265c9e 100644 --- a/src/ast/nodes/LogicalExpression.ts +++ b/src/ast/nodes/LogicalExpression.ts @@ -2,6 +2,7 @@ import MagicString from 'magic-string'; import { BLANK } from '../../utils/blank'; import { findFirstOccurrenceOutsideComment, + findNonWhiteSpace, NodeRenderOptions, removeLineBreaks, RenderOptions @@ -168,9 +169,10 @@ export default class LogicalExpression extends NodeBase implements Deoptimizable this.left.end ); if (this.right.included) { - code.remove(this.start, operatorPos + 2); + const removePos = findNonWhiteSpace(code.original, operatorPos + 2); + code.remove(this.start, removePos); if (preventASI) { - removeLineBreaks(code, operatorPos + 2, this.right.start); + removeLineBreaks(code, removePos, this.right.start); } } else { code.remove(operatorPos, this.end); diff --git a/src/ast/nodes/MemberExpression.ts b/src/ast/nodes/MemberExpression.ts index 413d69c2a1e..0008111d389 100644 --- a/src/ast/nodes/MemberExpression.ts +++ b/src/ast/nodes/MemberExpression.ts @@ -235,7 +235,11 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE render( code: MagicString, options: RenderOptions, - { renderedParentType, isCalleeOfRenderedParent }: NodeRenderOptions = BLANK + { + renderedParentType, + isCalleeOfRenderedParent, + renderedSurroundingElement + }: NodeRenderOptions = BLANK ) { const isCalleeOfDifferentParent = renderedParentType === NodeType.CallExpression && isCalleeOfRenderedParent; @@ -250,7 +254,13 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE if (isCalleeOfDifferentParent) { code.appendRight(this.start, '0, '); } - super.render(code, options); + const surroundingElement = renderedParentType || renderedSurroundingElement; + this.object.render( + code, + options, + surroundingElement ? { renderedSurroundingElement: surroundingElement } : BLANK + ); + this.property.render(code, options); } } diff --git a/src/ast/nodes/ObjectExpression.ts b/src/ast/nodes/ObjectExpression.ts index d9fc93d07cd..1925c70bc93 100644 --- a/src/ast/nodes/ObjectExpression.ts +++ b/src/ast/nodes/ObjectExpression.ts @@ -259,12 +259,13 @@ export default class ObjectExpression extends NodeBase implements DeoptimizableE render( code: MagicString, options: RenderOptions, - { renderedParentType }: NodeRenderOptions = BLANK + { renderedParentType, renderedSurroundingElement }: NodeRenderOptions = BLANK ) { super.render(code, options); + const surroundingElement = renderedParentType || renderedSurroundingElement; if ( - renderedParentType === NodeType.ExpressionStatement || - renderedParentType === NodeType.ArrowFunctionExpression + surroundingElement === NodeType.ExpressionStatement || + surroundingElement === NodeType.ArrowFunctionExpression ) { code.appendRight(this.start, '('); code.prependLeft(this.end, ')'); diff --git a/src/utils/renderHelpers.ts b/src/utils/renderHelpers.ts index a52ba90c62f..e2fe09b2e88 100644 --- a/src/utils/renderHelpers.ts +++ b/src/utils/renderHelpers.ts @@ -24,6 +24,7 @@ export interface NodeRenderOptions { isShorthandProperty?: boolean; preventASI?: boolean; renderedParentType?: string; // also serves as a flag if the rendered parent is different from the actual parent + renderedSurroundingElement?: string; // same as parent type, but for changed non-direct parents that directly preceed elements start?: number; } diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/hsl2hsv.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/hsl2hsv.js index 24f12a215a4..3b4de4c78d8 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/amd/hsl2hsv.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/amd/hsl2hsv.js @@ -3,7 +3,7 @@ define(['exports'], function (exports) { 'use strict'; var hsl2hsv = (h, s, l) => { const t = s * (l < 0.5 ? 1 : 1 - l), V = 1 + t, - S = 2 * t / V ; + S = 2 * t / V ; return [h, S, V]; }; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/cjs/hsl2hsv.js b/test/chunking-form/samples/namespace-reexports/_expected/cjs/hsl2hsv.js index 0f6d686f138..9f38e088474 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/cjs/hsl2hsv.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/cjs/hsl2hsv.js @@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true }); var hsl2hsv = (h, s, l) => { const t = s * (l < 0.5 ? 1 : 1 - l), V = 1 + t, - S = 2 * t / V ; + S = 2 * t / V ; return [h, S, V]; }; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/es/hsl2hsv.js b/test/chunking-form/samples/namespace-reexports/_expected/es/hsl2hsv.js index 17aa334990a..e2b167b0949 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/es/hsl2hsv.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/es/hsl2hsv.js @@ -1,7 +1,7 @@ var hsl2hsv = (h, s, l) => { const t = s * (l < 0.5 ? 1 : 1 - l), V = 1 + t, - S = 2 * t / V ; + S = 2 * t / V ; return [h, S, V]; }; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/system/hsl2hsv.js b/test/chunking-form/samples/namespace-reexports/_expected/system/hsl2hsv.js index c106dbea40b..2ccb8a5d8c7 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/system/hsl2hsv.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/system/hsl2hsv.js @@ -6,7 +6,7 @@ System.register([], function (exports) { var hsl2hsv = exports('default', (h, s, l) => { const t = s * (l < 0.5 ? 1 : 1 - l), V = 1 + t, - S = 2 * t / V ; + S = 2 * t / V ; return [h, S, V]; }); diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/amd/19d89d54.js b/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/amd/16d985e6.js similarity index 74% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/amd/19d89d54.js rename to test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/amd/16d985e6.js index a8664412cb4..6cd703051b6 100644 --- a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/amd/19d89d54.js +++ b/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/amd/16d985e6.js @@ -1,6 +1,6 @@ define(function () { 'use strict'; - var main = null; + var main = null; return main; diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/cjs/797a17bf.js b/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/cjs/05ff8838.js similarity index 68% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/cjs/797a17bf.js rename to test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/cjs/05ff8838.js index cffa3b92f13..17727e7adc9 100644 --- a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/cjs/797a17bf.js +++ b/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/cjs/05ff8838.js @@ -1,5 +1,5 @@ 'use strict'; -var main = null; +var main = null; module.exports = main; diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/es/114f0e8d.js b/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/es/bed29d35.js similarity index 55% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/es/114f0e8d.js rename to test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/es/bed29d35.js index 520227215f2..ed075f84a16 100644 --- a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/es/114f0e8d.js +++ b/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/es/bed29d35.js @@ -1,3 +1,3 @@ -var main = null; +var main = null; export default main; diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/system/52b8365a.js b/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/system/0998116a.js similarity index 71% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/system/52b8365a.js rename to test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/system/0998116a.js index ed0ada9d5f0..f54762cad18 100644 --- a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/system/52b8365a.js +++ b/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/system/0998116a.js @@ -3,7 +3,7 @@ System.register([], function (exports) { return { execute: function () { - var main = exports('default', null); + var main = exports('default', null); } }; diff --git a/test/form/samples/break-control-flow/break-statement-labels-in-loops/_expected.js b/test/form/samples/break-control-flow/break-statement-labels-in-loops/_expected.js index 13a13529a71..15235a556ea 100644 --- a/test/form/samples/break-control-flow/break-statement-labels-in-loops/_expected.js +++ b/test/form/samples/break-control-flow/break-statement-labels-in-loops/_expected.js @@ -1,6 +1,6 @@ while (globalThis.unknown) { console.log('retained'); - { + { break; } } diff --git a/test/form/samples/break-control-flow/break-statement-labels/_expected.js b/test/form/samples/break-control-flow/break-statement-labels/_expected.js index 623a4b6c02d..aabe93c3509 100644 --- a/test/form/samples/break-control-flow/break-statement-labels/_expected.js +++ b/test/form/samples/break-control-flow/break-statement-labels/_expected.js @@ -32,15 +32,15 @@ outer: { } function withConsequentReturn() { - { + { inner: { if (globalThis.unknown) return; else break inner; } console.log('retained'); } - { - { + { + { return; } } @@ -49,7 +49,7 @@ function withConsequentReturn() { withConsequentReturn(); function withAlternateReturn() { - { + { inner: { if (globalThis.unknown) break inner; else return; diff --git a/test/form/samples/builtin-prototypes/object-expression/_expected.js b/test/form/samples/builtin-prototypes/object-expression/_expected.js index 39a3811f480..95b55b099ae 100644 --- a/test/form/samples/builtin-prototypes/object-expression/_expected.js +++ b/test/form/samples/builtin-prototypes/object-expression/_expected.js @@ -1,11 +1,11 @@ const object = {}; object.propertyIsEnumerable( 'toString' ); -{}.propertyIsEnumerable( 'toString' ); -{}.propertyIsEnumerable( 'toString' ).valueOf(); +({}).propertyIsEnumerable( 'toString' ); +({}).propertyIsEnumerable( 'toString' ).valueOf(); -{}.hasOwnProperty( 'toString' ).valueOf(); -{}.isPrototypeOf( {} ).valueOf(); -{}.propertyIsEnumerable( 'toString' ).valueOf(); -{}.toLocaleString().trim(); -{}.toString().trim(); -{}.valueOf(); +({}).hasOwnProperty( 'toString' ).valueOf(); +({}).isPrototypeOf( {} ).valueOf(); +({}).propertyIsEnumerable( 'toString' ).valueOf(); +({}).toLocaleString().trim(); +({}).toString().trim(); +({}).valueOf(); diff --git a/test/form/samples/conditional-expression-paths/_expected.js b/test/form/samples/conditional-expression-paths/_expected.js index 67e12a605bb..f78090cebcb 100644 --- a/test/form/samples/conditional-expression-paths/_expected.js +++ b/test/form/samples/conditional-expression-paths/_expected.js @@ -12,16 +12,16 @@ var baz = { x: () => console.log('effect') }; (unknownValue ? foo : baz).x(); // known branch without side-effects -( foo ).y.z; -( foo).y.z; -( foo ).x(); -( foo).x(); +(foo ).y.z; +(foo).y.z; +(foo ).x(); +(foo).x(); // known branch with side-effect -( baz ).y.z; -( baz).y.z; -( baz ).x(); -( baz).x(); +(baz ).y.z; +(baz).y.z; +(baz ).x(); +(baz).x(); var baz3 = {}; -( baz3 ).y.z = 1; -( baz3).y.z = 1; +(baz3 ).y.z = 1; +(baz3).y.z = 1; diff --git a/test/form/samples/conditional-expression/_expected.js b/test/form/samples/conditional-expression/_expected.js index 8852b522f04..e9277e08e7a 100644 --- a/test/form/samples/conditional-expression/_expected.js +++ b/test/form/samples/conditional-expression/_expected.js @@ -9,9 +9,9 @@ unknownValue ? 1 : foo(); (unknownValue ? function () {} : function () {this.x = 1;})(); // known side-effect - foo() ; -( function () {this.x = 1;} )(); -( () => () => console.log( 'effect' ) )()(); - foo(); -( function () {this.x = 1;})(); -( () => () => console.log( 'effect' ))()(); +foo() ; +(function () {this.x = 1;} )(); +(() => () => console.log( 'effect' ) )()(); +foo(); +(function () {this.x = 1;})(); +(() => () => console.log( 'effect' ))()(); diff --git a/test/form/samples/conditional-put-parens-around-sequence/_expected.js b/test/form/samples/conditional-put-parens-around-sequence/_expected.js index be5bbdf1382..6c93af0bb24 100644 --- a/test/form/samples/conditional-put-parens-around-sequence/_expected.js +++ b/test/form/samples/conditional-put-parens-around-sequence/_expected.js @@ -1,5 +1,5 @@ -var a = ( foo(), 3 ) ; -var b = ( bar(), 6 ); +var a = ( foo(), 3 ) ; +var b = ( bar(), 6 ); foo( a, b ); // verify works with no whitespace diff --git a/test/form/samples/keep-tree-shaking-comments-no-asi/_expected.js b/test/form/samples/keep-tree-shaking-comments-no-asi/_expected.js index 760c721a884..4c056ba02cc 100644 --- a/test/form/samples/keep-tree-shaking-comments-no-asi/_expected.js +++ b/test/form/samples/keep-tree-shaking-comments-no-asi/_expected.js @@ -1,13 +1,10 @@ -console.log( - /* keep me */ +console.log(/* keep me */ 'expected'); -console.log( - /* keep me */ +console.log(/* keep me */ 'expected' ); -console.log( - /* keep me */ +console.log(/* keep me */ 'expected'); console.log((/* keep me */ diff --git a/test/form/samples/logical-expression/mutate-logical-expression/_expected/amd.js b/test/form/samples/logical-expression/mutate-logical-expression/_expected/amd.js index 52c1ce390e9..a3a822306d0 100644 --- a/test/form/samples/logical-expression/mutate-logical-expression/_expected/amd.js +++ b/test/form/samples/logical-expression/mutate-logical-expression/_expected/amd.js @@ -5,11 +5,11 @@ define(['exports'], function (exports) { 'use strict'; logicalAExp.bar = 1; var bExp = {}; - var logicalBExp = bExp; + var logicalBExp = bExp; logicalBExp.bar = 1; var cExp = {}; - var logicalCExp = cExp; + var logicalCExp = cExp; logicalCExp.bar = 1; exports.aExp = aExp; diff --git a/test/form/samples/logical-expression/mutate-logical-expression/_expected/cjs.js b/test/form/samples/logical-expression/mutate-logical-expression/_expected/cjs.js index 2efb4988918..cb639a91a09 100644 --- a/test/form/samples/logical-expression/mutate-logical-expression/_expected/cjs.js +++ b/test/form/samples/logical-expression/mutate-logical-expression/_expected/cjs.js @@ -7,11 +7,11 @@ var logicalAExp = aExp || {}; logicalAExp.bar = 1; var bExp = {}; -var logicalBExp = bExp; +var logicalBExp = bExp; logicalBExp.bar = 1; var cExp = {}; -var logicalCExp = cExp; +var logicalCExp = cExp; logicalCExp.bar = 1; exports.aExp = aExp; diff --git a/test/form/samples/logical-expression/mutate-logical-expression/_expected/es.js b/test/form/samples/logical-expression/mutate-logical-expression/_expected/es.js index c805d2d450f..78297b3e78c 100644 --- a/test/form/samples/logical-expression/mutate-logical-expression/_expected/es.js +++ b/test/form/samples/logical-expression/mutate-logical-expression/_expected/es.js @@ -3,11 +3,11 @@ var logicalAExp = aExp || {}; logicalAExp.bar = 1; var bExp = {}; -var logicalBExp = bExp; +var logicalBExp = bExp; logicalBExp.bar = 1; var cExp = {}; -var logicalCExp = cExp; +var logicalCExp = cExp; logicalCExp.bar = 1; export { aExp, bExp, cExp }; diff --git a/test/form/samples/logical-expression/mutate-logical-expression/_expected/iife.js b/test/form/samples/logical-expression/mutate-logical-expression/_expected/iife.js index d8c890c7aa0..5a799268786 100644 --- a/test/form/samples/logical-expression/mutate-logical-expression/_expected/iife.js +++ b/test/form/samples/logical-expression/mutate-logical-expression/_expected/iife.js @@ -6,11 +6,11 @@ var bundle = (function (exports) { logicalAExp.bar = 1; var bExp = {}; - var logicalBExp = bExp; + var logicalBExp = bExp; logicalBExp.bar = 1; var cExp = {}; - var logicalCExp = cExp; + var logicalCExp = cExp; logicalCExp.bar = 1; exports.aExp = aExp; diff --git a/test/form/samples/logical-expression/mutate-logical-expression/_expected/system.js b/test/form/samples/logical-expression/mutate-logical-expression/_expected/system.js index 072089bc39c..ff4e7b3145d 100644 --- a/test/form/samples/logical-expression/mutate-logical-expression/_expected/system.js +++ b/test/form/samples/logical-expression/mutate-logical-expression/_expected/system.js @@ -8,11 +8,11 @@ System.register('bundle', [], function (exports) { logicalAExp.bar = 1; var bExp = exports('bExp', {}); - var logicalBExp = bExp; + var logicalBExp = bExp; logicalBExp.bar = 1; var cExp = exports('cExp', {}); - var logicalCExp = cExp; + var logicalCExp = cExp; logicalCExp.bar = 1; } diff --git a/test/form/samples/logical-expression/mutate-logical-expression/_expected/umd.js b/test/form/samples/logical-expression/mutate-logical-expression/_expected/umd.js index eb804009f51..d1dc4f9a7d3 100644 --- a/test/form/samples/logical-expression/mutate-logical-expression/_expected/umd.js +++ b/test/form/samples/logical-expression/mutate-logical-expression/_expected/umd.js @@ -9,11 +9,11 @@ logicalAExp.bar = 1; var bExp = {}; - var logicalBExp = bExp; + var logicalBExp = bExp; logicalBExp.bar = 1; var cExp = {}; - var logicalCExp = cExp; + var logicalCExp = cExp; logicalCExp.bar = 1; exports.aExp = aExp; diff --git a/test/form/samples/logical-expression/simplify-non-boolean/_expected.js b/test/form/samples/logical-expression/simplify-non-boolean/_expected.js index eae6aa2b088..d887e0745c8 100644 --- a/test/form/samples/logical-expression/simplify-non-boolean/_expected.js +++ b/test/form/samples/logical-expression/simplify-non-boolean/_expected.js @@ -1,6 +1,6 @@ console.log('keep' ); -console.log( 'keep'); +console.log('keep'); const x = 'keep'; console.log(x ); -console.log( x); +console.log(x); diff --git a/test/form/samples/nullish-coalescing/_expected.js b/test/form/samples/nullish-coalescing/_expected.js index eede517bb67..16ea2b26039 100644 --- a/test/form/samples/nullish-coalescing/_expected.js +++ b/test/form/samples/nullish-coalescing/_expected.js @@ -3,11 +3,11 @@ function getNullSideEffect() { return null; } -console.log( 'null'); -console.log( 'undefined'); +console.log('null'); +console.log('undefined'); console.log(0 ); console.log('' ); console.log('Hello' ); -console.log( 'null return'); +console.log('null return'); console.log(getNullSideEffect() ?? 'null return with side-effect'); diff --git a/test/form/samples/pure-comment-line-break/_expected.js b/test/form/samples/pure-comment-line-break/_expected.js index c47ef3ca995..2594544f535 100644 --- a/test/form/samples/pure-comment-line-break/_expected.js +++ b/test/form/samples/pure-comment-line-break/_expected.js @@ -24,9 +24,9 @@ console.log('should remain impure'); console.log('code'); console.log('should remain impure'); - console.log('should remain impure'); +console.log('should remain impure'); - console.log('should remain impure') ; +console.log('should remain impure') ; console.log('code'); console.log('should remain impure', x); diff --git a/test/form/samples/pure-comment-scenarios-complex/_expected.js b/test/form/samples/pure-comment-scenarios-complex/_expected.js index fa608916cd1..32b4350eab2 100644 --- a/test/form/samples/pure-comment-scenarios-complex/_expected.js +++ b/test/form/samples/pure-comment-scenarios-complex/_expected.js @@ -11,9 +11,9 @@ global.iife1 = /*@__PURE__*/(function() { bar(), baz(), quux(); a.b(), f.g(); /* @__PURE__ */(function(){})() || true ? foo() : bar(); - foo() ; +foo() ; /* @__PURE__ */(function(){})() && false ? foo() : bar(); - bar(); +bar(); /* @__PURE__ */(function(){})() + "foo" ? bar() : baz(); "foo" + /* @__PURE__ */(function(){})() ? bar() : baz(); /* @__PURE__ */(function(){})() ? foo() : foo(); diff --git a/test/form/samples/side-effects-logical-expressions/_expected/amd.js b/test/form/samples/side-effects-logical-expressions/_expected/amd.js index 0c23f5c1969..6065cf6e88a 100644 --- a/test/form/samples/side-effects-logical-expressions/_expected/amd.js +++ b/test/form/samples/side-effects-logical-expressions/_expected/amd.js @@ -1,8 +1,8 @@ define(function () { 'use strict'; // effect - console.log( 'effect' ); - console.log( 'effect' ); + console.log( 'effect' ); + console.log( 'effect' ); console.log( 'effect' ) || {}; console.log( 'effect' ) && {}; @@ -14,23 +14,23 @@ define(function () { 'use strict'; }; // effect - ( foo).effect; - ( foo).effect; + (foo).effect; + (foo).effect; // effect - ( null).foo = 1; - ( null).foo = 1; + (null).foo = 1; + (null).foo = 1; // effect (true )(); (false )(); - ( (() => console.log( 'effect' )))(); - ( (() => console.log( 'effect' )))(); + ((() => console.log( 'effect' )))(); + ((() => console.log( 'effect' )))(); // effect (true )()(); (false )()(); - ( (() => () => console.log( 'effect' )))()(); - ( (() => () => console.log( 'effect' )))()(); + ((() => () => console.log( 'effect' )))()(); + ((() => () => console.log( 'effect' )))()(); }); diff --git a/test/form/samples/side-effects-logical-expressions/_expected/cjs.js b/test/form/samples/side-effects-logical-expressions/_expected/cjs.js index 52d272b7f65..f39a15cadc7 100644 --- a/test/form/samples/side-effects-logical-expressions/_expected/cjs.js +++ b/test/form/samples/side-effects-logical-expressions/_expected/cjs.js @@ -1,8 +1,8 @@ 'use strict'; // effect - console.log( 'effect' ); - console.log( 'effect' ); +console.log( 'effect' ); +console.log( 'effect' ); console.log( 'effect' ) || {}; console.log( 'effect' ) && {}; @@ -14,21 +14,21 @@ const foo = { }; // effect -( foo).effect; -( foo).effect; +(foo).effect; +(foo).effect; // effect -( null).foo = 1; -( null).foo = 1; +(null).foo = 1; +(null).foo = 1; // effect (true )(); (false )(); -( (() => console.log( 'effect' )))(); -( (() => console.log( 'effect' )))(); +((() => console.log( 'effect' )))(); +((() => console.log( 'effect' )))(); // effect (true )()(); (false )()(); -( (() => () => console.log( 'effect' )))()(); -( (() => () => console.log( 'effect' )))()(); +((() => () => console.log( 'effect' )))()(); +((() => () => console.log( 'effect' )))()(); diff --git a/test/form/samples/side-effects-logical-expressions/_expected/es.js b/test/form/samples/side-effects-logical-expressions/_expected/es.js index 36c93850b7f..9de928c8d83 100644 --- a/test/form/samples/side-effects-logical-expressions/_expected/es.js +++ b/test/form/samples/side-effects-logical-expressions/_expected/es.js @@ -1,6 +1,6 @@ // effect - console.log( 'effect' ); - console.log( 'effect' ); +console.log( 'effect' ); +console.log( 'effect' ); console.log( 'effect' ) || {}; console.log( 'effect' ) && {}; @@ -12,21 +12,21 @@ const foo = { }; // effect -( foo).effect; -( foo).effect; +(foo).effect; +(foo).effect; // effect -( null).foo = 1; -( null).foo = 1; +(null).foo = 1; +(null).foo = 1; // effect (true )(); (false )(); -( (() => console.log( 'effect' )))(); -( (() => console.log( 'effect' )))(); +((() => console.log( 'effect' )))(); +((() => console.log( 'effect' )))(); // effect (true )()(); (false )()(); -( (() => () => console.log( 'effect' )))()(); -( (() => () => console.log( 'effect' )))()(); +((() => () => console.log( 'effect' )))()(); +((() => () => console.log( 'effect' )))()(); diff --git a/test/form/samples/side-effects-logical-expressions/_expected/iife.js b/test/form/samples/side-effects-logical-expressions/_expected/iife.js index 0a092974e70..00fa987dc6b 100644 --- a/test/form/samples/side-effects-logical-expressions/_expected/iife.js +++ b/test/form/samples/side-effects-logical-expressions/_expected/iife.js @@ -2,8 +2,8 @@ 'use strict'; // effect - console.log( 'effect' ); - console.log( 'effect' ); + console.log( 'effect' ); + console.log( 'effect' ); console.log( 'effect' ) || {}; console.log( 'effect' ) && {}; @@ -15,23 +15,23 @@ }; // effect - ( foo).effect; - ( foo).effect; + (foo).effect; + (foo).effect; // effect - ( null).foo = 1; - ( null).foo = 1; + (null).foo = 1; + (null).foo = 1; // effect (true )(); (false )(); - ( (() => console.log( 'effect' )))(); - ( (() => console.log( 'effect' )))(); + ((() => console.log( 'effect' )))(); + ((() => console.log( 'effect' )))(); // effect (true )()(); (false )()(); - ( (() => () => console.log( 'effect' )))()(); - ( (() => () => console.log( 'effect' )))()(); + ((() => () => console.log( 'effect' )))()(); + ((() => () => console.log( 'effect' )))()(); }()); diff --git a/test/form/samples/side-effects-logical-expressions/_expected/system.js b/test/form/samples/side-effects-logical-expressions/_expected/system.js index b0a5c921939..5a5da5a790d 100644 --- a/test/form/samples/side-effects-logical-expressions/_expected/system.js +++ b/test/form/samples/side-effects-logical-expressions/_expected/system.js @@ -4,8 +4,8 @@ System.register([], function () { execute: function () { // effect - console.log( 'effect' ); - console.log( 'effect' ); + console.log( 'effect' ); + console.log( 'effect' ); console.log( 'effect' ) || {}; console.log( 'effect' ) && {}; @@ -17,24 +17,24 @@ System.register([], function () { }; // effect - ( foo).effect; - ( foo).effect; + (foo).effect; + (foo).effect; // effect - ( null).foo = 1; - ( null).foo = 1; + (null).foo = 1; + (null).foo = 1; // effect (true )(); (false )(); - ( (() => console.log( 'effect' )))(); - ( (() => console.log( 'effect' )))(); + ((() => console.log( 'effect' )))(); + ((() => console.log( 'effect' )))(); // effect (true )()(); (false )()(); - ( (() => () => console.log( 'effect' )))()(); - ( (() => () => console.log( 'effect' )))()(); + ((() => () => console.log( 'effect' )))()(); + ((() => () => console.log( 'effect' )))()(); } }; diff --git a/test/form/samples/side-effects-logical-expressions/_expected/umd.js b/test/form/samples/side-effects-logical-expressions/_expected/umd.js index 4cfcf96fc8b..1ab69e5e23f 100644 --- a/test/form/samples/side-effects-logical-expressions/_expected/umd.js +++ b/test/form/samples/side-effects-logical-expressions/_expected/umd.js @@ -4,8 +4,8 @@ }((function () { 'use strict'; // effect - console.log( 'effect' ); - console.log( 'effect' ); + console.log( 'effect' ); + console.log( 'effect' ); console.log( 'effect' ) || {}; console.log( 'effect' ) && {}; @@ -17,23 +17,23 @@ }; // effect - ( foo).effect; - ( foo).effect; + (foo).effect; + (foo).effect; // effect - ( null).foo = 1; - ( null).foo = 1; + (null).foo = 1; + (null).foo = 1; // effect (true )(); (false )(); - ( (() => console.log( 'effect' )))(); - ( (() => console.log( 'effect' )))(); + ((() => console.log( 'effect' )))(); + ((() => console.log( 'effect' )))(); // effect (true )()(); (false )()(); - ( (() => () => console.log( 'effect' )))()(); - ( (() => () => console.log( 'effect' )))()(); + ((() => () => console.log( 'effect' )))()(); + ((() => () => console.log( 'effect' )))()(); }))); diff --git a/test/form/samples/side-effects-object-literal-mutation-misc/_expected.js b/test/form/samples/side-effects-object-literal-mutation-misc/_expected.js index 3f385c224c0..77d0532039f 100644 --- a/test/form/samples/side-effects-object-literal-mutation-misc/_expected.js +++ b/test/form/samples/side-effects-object-literal-mutation-misc/_expected.js @@ -6,18 +6,18 @@ }; obj.modify(); console.log(obj.modified ? "PASS1" : "FAIL1"); -})()); +}))(); - ((function() { +((function() { const obj = {}; function modify() { this.modified = true; } modify.call(obj); console.log(obj.modified ? "PASS2" : "FAIL2"); -})()); +}))(); - ((function() { +((function() { const obj = {}; obj.modify = modify; function modify() { @@ -25,7 +25,7 @@ } obj.modify(); console.log(obj.modified ? "PASS3" : "FAIL3"); -})()); +}))(); { const axis = {}; diff --git a/test/form/samples/simplify-expression-annotations/_expected.js b/test/form/samples/simplify-expression-annotations/_expected.js index 657e5de27d3..13c4a45f196 100644 --- a/test/form/samples/simplify-expression-annotations/_expected.js +++ b/test/form/samples/simplify-expression-annotations/_expected.js @@ -1,4 +1,4 @@ -console.log( /*@__PURE__*/ noEffect() ); -console.log( /*@__PURE__*/ noEffect()); -console.log( /*@__PURE__*/ noEffect()); -console.log( /*@__PURE__*/ noEffect()); +console.log(/*@__PURE__*/ noEffect() ); +console.log(/*@__PURE__*/ noEffect()); +console.log(/*@__PURE__*/ noEffect()); +console.log(/*@__PURE__*/ noEffect()); diff --git a/test/form/samples/simplify-return-expression/_expected.js b/test/form/samples/simplify-return-expression/_expected.js index d5ec416c972..67a7fcbae5a 100644 --- a/test/form/samples/simplify-return-expression/_expected.js +++ b/test/form/samples/simplify-return-expression/_expected.js @@ -4,11 +4,11 @@ const test = () => { }; const foo = () => { - return A ; + return A ; }; const bar = () => { - return A ; + return A ; }; export { test }; diff --git a/test/form/samples/skips-dead-branches-g/_expected/amd.js b/test/form/samples/skips-dead-branches-g/_expected/amd.js index 161d2da2246..463cee0be03 100644 --- a/test/form/samples/skips-dead-branches-g/_expected/amd.js +++ b/test/form/samples/skips-dead-branches-g/_expected/amd.js @@ -3,8 +3,8 @@ define(function () { 'use strict'; var a = 0; var b = 1; - var x = a ; - var y = b; + var x = a ; + var y = b; console.log( x + y ); diff --git a/test/form/samples/skips-dead-branches-g/_expected/cjs.js b/test/form/samples/skips-dead-branches-g/_expected/cjs.js index 343757d2ce2..a7f68535220 100644 --- a/test/form/samples/skips-dead-branches-g/_expected/cjs.js +++ b/test/form/samples/skips-dead-branches-g/_expected/cjs.js @@ -3,7 +3,7 @@ var a = 0; var b = 1; -var x = a ; -var y = b; +var x = a ; +var y = b; console.log( x + y ); diff --git a/test/form/samples/skips-dead-branches-g/_expected/es.js b/test/form/samples/skips-dead-branches-g/_expected/es.js index 7250ab17e6b..25b8db8cb0c 100644 --- a/test/form/samples/skips-dead-branches-g/_expected/es.js +++ b/test/form/samples/skips-dead-branches-g/_expected/es.js @@ -1,7 +1,7 @@ var a = 0; var b = 1; -var x = a ; -var y = b; +var x = a ; +var y = b; console.log( x + y ); diff --git a/test/form/samples/skips-dead-branches-g/_expected/iife.js b/test/form/samples/skips-dead-branches-g/_expected/iife.js index 1054fe9593d..c5763647b5c 100644 --- a/test/form/samples/skips-dead-branches-g/_expected/iife.js +++ b/test/form/samples/skips-dead-branches-g/_expected/iife.js @@ -4,8 +4,8 @@ var a = 0; var b = 1; - var x = a ; - var y = b; + var x = a ; + var y = b; console.log( x + y ); diff --git a/test/form/samples/skips-dead-branches-g/_expected/system.js b/test/form/samples/skips-dead-branches-g/_expected/system.js index 7371a6e8ad3..680a2b3c9c0 100644 --- a/test/form/samples/skips-dead-branches-g/_expected/system.js +++ b/test/form/samples/skips-dead-branches-g/_expected/system.js @@ -6,8 +6,8 @@ System.register([], function () { var a = 0; var b = 1; - var x = a ; - var y = b; + var x = a ; + var y = b; console.log( x + y ); diff --git a/test/form/samples/skips-dead-branches-g/_expected/umd.js b/test/form/samples/skips-dead-branches-g/_expected/umd.js index c987378b9e0..23e965b5297 100644 --- a/test/form/samples/skips-dead-branches-g/_expected/umd.js +++ b/test/form/samples/skips-dead-branches-g/_expected/umd.js @@ -6,8 +6,8 @@ var a = 0; var b = 1; - var x = a ; - var y = b; + var x = a ; + var y = b; console.log( x + y ); diff --git a/test/form/samples/supports-core-js/_expected.js b/test/form/samples/supports-core-js/_expected.js index 701dc6b6d48..77825bb728f 100644 --- a/test/form/samples/supports-core-js/_expected.js +++ b/test/form/samples/supports-core-js/_expected.js @@ -213,7 +213,7 @@ var shared = createCommonjsModule(function (module) { return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {}); })('versions', []).push({ version: '3.8.2', - mode: 'global', + mode: 'global', copyright: '© 2021 Denis Pushkarev (zloirock.ru)' }); }); @@ -2218,7 +2218,7 @@ if ([].keys) { if (IteratorPrototype == undefined) IteratorPrototype = {}; // 25.1.2.1.1 %IteratorPrototype%[@@iterator]() -if ( !has(IteratorPrototype, ITERATOR$3)) { +if (!has(IteratorPrototype, ITERATOR$3)) { createNonEnumerableProperty(IteratorPrototype, ITERATOR$3, returnThis); } @@ -2279,7 +2279,7 @@ var defineIterator = function (Iterable, NAME, IteratorConstructor, next, DEFAUL if (anyNativeIterator) { CurrentIteratorPrototype = objectGetPrototypeOf(anyNativeIterator.call(new Iterable())); if (IteratorPrototype$2 !== Object.prototype && CurrentIteratorPrototype.next) { - if ( objectGetPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype$2) { + if (objectGetPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype$2) { if (objectSetPrototypeOf) { objectSetPrototypeOf(CurrentIteratorPrototype, IteratorPrototype$2); } else if (typeof CurrentIteratorPrototype[ITERATOR$4] != 'function') { @@ -2298,7 +2298,7 @@ var defineIterator = function (Iterable, NAME, IteratorConstructor, next, DEFAUL } // define iterator - if ( IterablePrototype[ITERATOR$4] !== defaultIterator) { + if (IterablePrototype[ITERATOR$4] !== defaultIterator) { createNonEnumerableProperty(IterablePrototype, ITERATOR$4, defaultIterator); } iterators[NAME] = defaultIterator; @@ -2805,7 +2805,7 @@ if (!toStringTagSupport) { } // Forced replacement object prototype accessors methods -var objectPrototypeAccessorsForced = !fails(function () { +var objectPrototypeAccessorsForced = !fails(function () { var key = Math.random(); // In FF throws only define methods // eslint-disable-next-line no-undef, no-useless-call @@ -2984,7 +2984,7 @@ var min$5 = Math.min; var CORRECT_IS_REGEXP_LOGIC = correctIsRegexpLogic('endsWith'); // https://github.com/zloirock/core-js/pull/702 -var MDN_POLYFILL_BUG = !CORRECT_IS_REGEXP_LOGIC && !!function () { +var MDN_POLYFILL_BUG = !CORRECT_IS_REGEXP_LOGIC && !!function () { var descriptor = getOwnPropertyDescriptor$4(String.prototype, 'endsWith'); return descriptor && !descriptor.writable; }(); @@ -3428,11 +3428,11 @@ _export({ target: 'String', proto: true, forced: WORKS_WITH_NON_GLOBAL_REGEX }, } else if (WORKS_WITH_NON_GLOBAL_REGEX) return nativeMatchAll.apply(O, arguments); S = String(O); rx = new RegExp(regexp, 'g'); - return rx[MATCH_ALL](S); + return rx[MATCH_ALL](S); } }); - MATCH_ALL in RegExpPrototype || createNonEnumerableProperty(RegExpPrototype, MATCH_ALL, $matchAll); +MATCH_ALL in RegExpPrototype || createNonEnumerableProperty(RegExpPrototype, MATCH_ALL, $matchAll); // `String.prototype.repeat` method implementation // https://tc39.es/ecma262/#sec-string.prototype.repeat @@ -3802,7 +3802,7 @@ var min$8 = Math.min; var CORRECT_IS_REGEXP_LOGIC$1 = correctIsRegexpLogic('startsWith'); // https://github.com/zloirock/core-js/pull/702 -var MDN_POLYFILL_BUG$1 = !CORRECT_IS_REGEXP_LOGIC$1 && !!function () { +var MDN_POLYFILL_BUG$1 = !CORRECT_IS_REGEXP_LOGIC$1 && !!function () { var descriptor = getOwnPropertyDescriptor$5(String.prototype, 'startsWith'); return descriptor && !descriptor.writable; }(); @@ -5539,7 +5539,7 @@ if (FORCED$g) { : newGenericPromiseCapability(C); }; - if ( typeof nativePromiseConstructor == 'function') { + if (typeof nativePromiseConstructor == 'function') { nativeThen = nativePromiseConstructor.prototype.then; // wrap native Promise#then for native async functions @@ -5581,11 +5581,11 @@ _export({ target: PROMISE, stat: true, forced: FORCED$g }, { } }); -_export({ target: PROMISE, stat: true, forced: FORCED$g }, { +_export({ target: PROMISE, stat: true, forced: FORCED$g }, { // `Promise.resolve` method // https://tc39.es/ecma262/#sec-promise.resolve resolve: function resolve(x) { - return promiseResolve( this, x); + return promiseResolve(this, x); } }); @@ -5735,7 +5735,7 @@ _export({ target: 'Promise', proto: true, real: true, forced: NON_GENERIC }, { }); // patch native Promise.prototype for native async functions -if ( typeof nativePromiseConstructor == 'function' && !nativePromiseConstructor.prototype['finally']) { +if (typeof nativePromiseConstructor == 'function' && !nativePromiseConstructor.prototype['finally']) { redefine(nativePromiseConstructor.prototype, 'finally', getBuiltIn('Promise').prototype['finally']); } @@ -9698,7 +9698,7 @@ _export({ target: 'Map', proto: true, real: true, forced: isPure }, { } }); -var getMapIterator = function (it) { +var getMapIterator = function (it) { // eslint-disable-next-line no-undef return Map.prototype.entries.call(it); }; @@ -9910,7 +9910,7 @@ _export({ target: 'Set', proto: true, real: true, forced: isPure }, { } }); -var getSetIterator = function (it) { +var getSetIterator = function (it) { // eslint-disable-next-line no-undef return Set.prototype.values.call(it); }; @@ -11360,7 +11360,7 @@ var TO_STRING_TAG$6 = wellKnownSymbol('toStringTag'); var NativeIterator = global$1.Iterator; // FF56- have non-standard global helper `Iterator` -var FORCED$m = typeof NativeIterator != 'function' +var FORCED$m = typeof NativeIterator != 'function' || NativeIterator.prototype !== IteratorPrototype$3 // FF44- non-standard `Iterator` passes previous tests || !fails(function () { NativeIterator({}); }); diff --git a/test/form/samples/tree-shake-arguments-conditional/_expected.js b/test/form/samples/tree-shake-arguments-conditional/_expected.js index adcbf70cb37..a5e144ebe2b 100644 --- a/test/form/samples/tree-shake-arguments-conditional/_expected.js +++ b/test/form/samples/tree-shake-arguments-conditional/_expected.js @@ -2,6 +2,6 @@ function ignoringArgs() { return 'no args'; } -const handler = ignoringArgs; +const handler = ignoringArgs; console.log(handler()); diff --git a/test/form/samples/tree-shake-logical-expressions/_expected/amd.js b/test/form/samples/tree-shake-logical-expressions/_expected/amd.js index f2f99d30102..31345bf4fa3 100644 --- a/test/form/samples/tree-shake-logical-expressions/_expected/amd.js +++ b/test/form/samples/tree-shake-logical-expressions/_expected/amd.js @@ -4,7 +4,7 @@ define(function () { 'use strict'; return 'A'; } - console.log( getStringA()); + console.log(getStringA()); console.log(false ); @@ -14,6 +14,6 @@ define(function () { 'use strict'; return 'D'; } - console.log( getStringD()); + console.log(getStringD()); }); diff --git a/test/form/samples/tree-shake-logical-expressions/_expected/cjs.js b/test/form/samples/tree-shake-logical-expressions/_expected/cjs.js index 38945707823..d36465fff14 100644 --- a/test/form/samples/tree-shake-logical-expressions/_expected/cjs.js +++ b/test/form/samples/tree-shake-logical-expressions/_expected/cjs.js @@ -4,7 +4,7 @@ function getStringA() { return 'A'; } -console.log( getStringA()); +console.log(getStringA()); console.log(false ); @@ -14,4 +14,4 @@ function getStringD() { return 'D'; } -console.log( getStringD()); +console.log(getStringD()); diff --git a/test/form/samples/tree-shake-logical-expressions/_expected/es.js b/test/form/samples/tree-shake-logical-expressions/_expected/es.js index b7e245d3edb..bc04584d034 100644 --- a/test/form/samples/tree-shake-logical-expressions/_expected/es.js +++ b/test/form/samples/tree-shake-logical-expressions/_expected/es.js @@ -2,7 +2,7 @@ function getStringA() { return 'A'; } -console.log( getStringA()); +console.log(getStringA()); console.log(false ); @@ -12,4 +12,4 @@ function getStringD() { return 'D'; } -console.log( getStringD()); +console.log(getStringD()); diff --git a/test/form/samples/tree-shake-logical-expressions/_expected/iife.js b/test/form/samples/tree-shake-logical-expressions/_expected/iife.js index 151726c1737..2ce582c819f 100644 --- a/test/form/samples/tree-shake-logical-expressions/_expected/iife.js +++ b/test/form/samples/tree-shake-logical-expressions/_expected/iife.js @@ -5,7 +5,7 @@ return 'A'; } - console.log( getStringA()); + console.log(getStringA()); console.log(false ); @@ -15,6 +15,6 @@ return 'D'; } - console.log( getStringD()); + console.log(getStringD()); }()); diff --git a/test/form/samples/tree-shake-logical-expressions/_expected/system.js b/test/form/samples/tree-shake-logical-expressions/_expected/system.js index 0c8ee8bc720..05ea8647e1a 100644 --- a/test/form/samples/tree-shake-logical-expressions/_expected/system.js +++ b/test/form/samples/tree-shake-logical-expressions/_expected/system.js @@ -7,7 +7,7 @@ System.register([], function () { return 'A'; } - console.log( getStringA()); + console.log(getStringA()); console.log(false ); @@ -17,7 +17,7 @@ System.register([], function () { return 'D'; } - console.log( getStringD()); + console.log(getStringD()); } }; diff --git a/test/form/samples/tree-shake-logical-expressions/_expected/umd.js b/test/form/samples/tree-shake-logical-expressions/_expected/umd.js index 0599c255a06..ac7fc0f38ab 100644 --- a/test/form/samples/tree-shake-logical-expressions/_expected/umd.js +++ b/test/form/samples/tree-shake-logical-expressions/_expected/umd.js @@ -7,7 +7,7 @@ return 'A'; } - console.log( getStringA()); + console.log(getStringA()); console.log(false ); @@ -17,6 +17,6 @@ return 'D'; } - console.log( getStringD()); + console.log(getStringD()); }))); diff --git a/test/form/samples/wrap-simplified-expressions/_expected/amd.js b/test/form/samples/wrap-simplified-expressions/_expected/amd.js index d7b09c16a74..435a2bc2ac0 100644 --- a/test/form/samples/wrap-simplified-expressions/_expected/amd.js +++ b/test/form/samples/wrap-simplified-expressions/_expected/amd.js @@ -7,20 +7,20 @@ define(function () { 'use strict'; }; // Indirectly called member expressions set the callee's context to global "this" - ( 0, wrapper.foo)(); - ( 0, wrapper.foo )(); (0, wrapper.foo)(); - ( ( 0, wrapper.foo))(); - ( ( 0, wrapper.foo ))(); - ( (0, wrapper.foo))(); + (0, wrapper.foo )(); + (0, wrapper.foo)(); + ((0, wrapper.foo))(); + ((0, wrapper.foo ))(); + ((0, wrapper.foo))(); // Only callees of call expressions should be wrapped - console.log( wrapper.foo); + console.log(wrapper.foo); // Indirectly invoked eval is executed in the global scope function testEval() { - console.log(( 0, eval)('this')); - console.log(( 0, eval )('this')); + console.log((0, eval)('this')); + console.log((0, eval )('this')); console.log((0, eval)('this')); } diff --git a/test/form/samples/wrap-simplified-expressions/_expected/cjs.js b/test/form/samples/wrap-simplified-expressions/_expected/cjs.js index cddfc119c96..29fea2740d7 100644 --- a/test/form/samples/wrap-simplified-expressions/_expected/cjs.js +++ b/test/form/samples/wrap-simplified-expressions/_expected/cjs.js @@ -7,20 +7,20 @@ const wrapper = { }; // Indirectly called member expressions set the callee's context to global "this" -( 0, wrapper.foo)(); -( 0, wrapper.foo )(); (0, wrapper.foo)(); -( ( 0, wrapper.foo))(); -( ( 0, wrapper.foo ))(); -( (0, wrapper.foo))(); +(0, wrapper.foo )(); +(0, wrapper.foo)(); +((0, wrapper.foo))(); +((0, wrapper.foo ))(); +((0, wrapper.foo))(); // Only callees of call expressions should be wrapped -console.log( wrapper.foo); +console.log(wrapper.foo); // Indirectly invoked eval is executed in the global scope function testEval() { - console.log(( 0, eval)('this')); - console.log(( 0, eval )('this')); + console.log((0, eval)('this')); + console.log((0, eval )('this')); console.log((0, eval)('this')); } diff --git a/test/form/samples/wrap-simplified-expressions/_expected/es.js b/test/form/samples/wrap-simplified-expressions/_expected/es.js index ad4dce62df9..6b80a4e2b2f 100644 --- a/test/form/samples/wrap-simplified-expressions/_expected/es.js +++ b/test/form/samples/wrap-simplified-expressions/_expected/es.js @@ -5,20 +5,20 @@ const wrapper = { }; // Indirectly called member expressions set the callee's context to global "this" -( 0, wrapper.foo)(); -( 0, wrapper.foo )(); (0, wrapper.foo)(); -( ( 0, wrapper.foo))(); -( ( 0, wrapper.foo ))(); -( (0, wrapper.foo))(); +(0, wrapper.foo )(); +(0, wrapper.foo)(); +((0, wrapper.foo))(); +((0, wrapper.foo ))(); +((0, wrapper.foo))(); // Only callees of call expressions should be wrapped -console.log( wrapper.foo); +console.log(wrapper.foo); // Indirectly invoked eval is executed in the global scope function testEval() { - console.log(( 0, eval)('this')); - console.log(( 0, eval )('this')); + console.log((0, eval)('this')); + console.log((0, eval )('this')); console.log((0, eval)('this')); } diff --git a/test/form/samples/wrap-simplified-expressions/_expected/iife.js b/test/form/samples/wrap-simplified-expressions/_expected/iife.js index 542c0e6c13b..15613c42434 100644 --- a/test/form/samples/wrap-simplified-expressions/_expected/iife.js +++ b/test/form/samples/wrap-simplified-expressions/_expected/iife.js @@ -8,20 +8,20 @@ }; // Indirectly called member expressions set the callee's context to global "this" - ( 0, wrapper.foo)(); - ( 0, wrapper.foo )(); (0, wrapper.foo)(); - ( ( 0, wrapper.foo))(); - ( ( 0, wrapper.foo ))(); - ( (0, wrapper.foo))(); + (0, wrapper.foo )(); + (0, wrapper.foo)(); + ((0, wrapper.foo))(); + ((0, wrapper.foo ))(); + ((0, wrapper.foo))(); // Only callees of call expressions should be wrapped - console.log( wrapper.foo); + console.log(wrapper.foo); // Indirectly invoked eval is executed in the global scope function testEval() { - console.log(( 0, eval)('this')); - console.log(( 0, eval )('this')); + console.log((0, eval)('this')); + console.log((0, eval )('this')); console.log((0, eval)('this')); } diff --git a/test/form/samples/wrap-simplified-expressions/_expected/system.js b/test/form/samples/wrap-simplified-expressions/_expected/system.js index c4247daa2ac..5098c174597 100644 --- a/test/form/samples/wrap-simplified-expressions/_expected/system.js +++ b/test/form/samples/wrap-simplified-expressions/_expected/system.js @@ -10,20 +10,20 @@ System.register([], function () { }; // Indirectly called member expressions set the callee's context to global "this" - ( 0, wrapper.foo)(); - ( 0, wrapper.foo )(); (0, wrapper.foo)(); - ( ( 0, wrapper.foo))(); - ( ( 0, wrapper.foo ))(); - ( (0, wrapper.foo))(); + (0, wrapper.foo )(); + (0, wrapper.foo)(); + ((0, wrapper.foo))(); + ((0, wrapper.foo ))(); + ((0, wrapper.foo))(); // Only callees of call expressions should be wrapped - console.log( wrapper.foo); + console.log(wrapper.foo); // Indirectly invoked eval is executed in the global scope function testEval() { - console.log(( 0, eval)('this')); - console.log(( 0, eval )('this')); + console.log((0, eval)('this')); + console.log((0, eval )('this')); console.log((0, eval)('this')); } diff --git a/test/form/samples/wrap-simplified-expressions/_expected/umd.js b/test/form/samples/wrap-simplified-expressions/_expected/umd.js index f29169d15b1..62e10c51297 100644 --- a/test/form/samples/wrap-simplified-expressions/_expected/umd.js +++ b/test/form/samples/wrap-simplified-expressions/_expected/umd.js @@ -10,20 +10,20 @@ }; // Indirectly called member expressions set the callee's context to global "this" - ( 0, wrapper.foo)(); - ( 0, wrapper.foo )(); (0, wrapper.foo)(); - ( ( 0, wrapper.foo))(); - ( ( 0, wrapper.foo ))(); - ( (0, wrapper.foo))(); + (0, wrapper.foo )(); + (0, wrapper.foo)(); + ((0, wrapper.foo))(); + ((0, wrapper.foo ))(); + ((0, wrapper.foo))(); // Only callees of call expressions should be wrapped - console.log( wrapper.foo); + console.log(wrapper.foo); // Indirectly invoked eval is executed in the global scope function testEval() { - console.log(( 0, eval)('this')); - console.log(( 0, eval )('this')); + console.log((0, eval)('this')); + console.log((0, eval )('this')); console.log((0, eval)('this')); } diff --git a/test/function/samples/prevent-tree-shaking-asi/main.js b/test/function/samples/prevent-tree-shaking-asi/main.js index 86c8abe3c00..b6cbee1f6b0 100644 --- a/test/function/samples/prevent-tree-shaking-asi/main.js +++ b/test/function/samples/prevent-tree-shaking-asi/main.js @@ -56,3 +56,10 @@ function* test6() { 'expected' } assert.strictEqual(test6().next().value, 'expected'); + +function test7() { + var x; + return x = /* kept */ + 'expected'; +} +assert.strictEqual(test7(), 'expected'); diff --git a/test/function/samples/simplify-class-expression-assignment/_config.js b/test/function/samples/simplify-class-expression-assignment/_config.js new file mode 100644 index 00000000000..2e3c44bdbac --- /dev/null +++ b/test/function/samples/simplify-class-expression-assignment/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'wraps class expressions in call expressions in simplified assignments' +}; diff --git a/test/function/samples/simplify-class-expression-assignment/main.js b/test/function/samples/simplify-class-expression-assignment/main.js new file mode 100644 index 00000000000..34d5ea915f2 --- /dev/null +++ b/test/function/samples/simplify-class-expression-assignment/main.js @@ -0,0 +1,13 @@ +let calls = 0; + +Function.prototype.testFunc = () => { + calls++; + return { test: () => calls++ }; +}; + +var x = class {}.testFunc(); +var y; +y = class {}.testFunc().test(); + +delete Object.prototype.testFunc; +assert.strictEqual(calls, 3); diff --git a/test/function/samples/simplify-function-expression-assignment/_config.js b/test/function/samples/simplify-function-expression-assignment/_config.js new file mode 100644 index 00000000000..173965d0199 --- /dev/null +++ b/test/function/samples/simplify-function-expression-assignment/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'wraps function expressions in call expressions in simplified assignments' +}; diff --git a/test/function/samples/simplify-function-expression-assignment/main.js b/test/function/samples/simplify-function-expression-assignment/main.js new file mode 100644 index 00000000000..7fec8af8793 --- /dev/null +++ b/test/function/samples/simplify-function-expression-assignment/main.js @@ -0,0 +1,13 @@ +let calls = 0; + +Function.prototype.testFunc = () => { + calls++; + return { test: () => calls++ }; +}; + +var x = function () {}.testFunc(); +var y; +y = function () {}.testFunc().test(); + +delete Object.prototype.testFunc; +assert.strictEqual(calls, 3); diff --git a/test/function/samples/simplify-object-expression-assignment/_config.js b/test/function/samples/simplify-object-expression-assignment/_config.js new file mode 100644 index 00000000000..f8c4f0cf135 --- /dev/null +++ b/test/function/samples/simplify-object-expression-assignment/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'wraps object expressions in call expressions in simplified assignments' +}; diff --git a/test/function/samples/simplify-object-expression-assignment/main.js b/test/function/samples/simplify-object-expression-assignment/main.js new file mode 100644 index 00000000000..b2daa9a023a --- /dev/null +++ b/test/function/samples/simplify-object-expression-assignment/main.js @@ -0,0 +1,13 @@ +let calls = 0; + +Object.prototype.testFunc = () => { + calls++; + return { test: () => calls++ }; +}; + +var x = {}.testFunc(); +var y; +y = {}.testFunc().test(); + +delete Object.prototype.testFunc; +assert.strictEqual(calls, 3); diff --git a/test/misc/bundle-information.js b/test/misc/bundle-information.js index 42f039ec279..5d1a8380482 100644 --- a/test/misc/bundle-information.js +++ b/test/misc/bundle-information.js @@ -441,7 +441,7 @@ describe('The bundle object', () => { originalLength: 47, removedExports: [], renderedExports: ['default'], - renderedLength: 18 + renderedLength: 17 } } ],