From b2260363a9cd6e2c8549a772444e4584d2ec3d94 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 8 Sep 2019 11:35:06 +0200 Subject: [PATCH] Make accessing unknown globals a side-effect (#3068) * Make accessing unknown globals a side-effect; also, introduce global object concept * Test or remove some edge-cases * Add option to control unknown global side effects * Add additional known globals test * Refactor global declarations to unite access and pureness --- docs/999-big-list-of-options.md | 25 +- src/Graph.ts | 7 +- src/Module.ts | 3 + src/ast/nodes/Identifier.ts | 45 +-- src/ast/nodes/shared/FunctionNode.ts | 4 +- src/ast/nodes/shared/knownGlobals.ts | 299 ++++++++++++++++++ src/ast/nodes/shared/pureFunctions.ts | 130 -------- src/ast/variables/GlobalVariable.ts | 21 +- src/rollup/types.d.ts | 1 + .../samples/assignment-to-global/_expected.js | 1 + .../assignment-to-global/_expected/amd.js | 5 - .../assignment-to-global/_expected/cjs.js | 3 - .../assignment-to-global/_expected/es.js | 1 - .../assignment-to-global/_expected/iife.js | 6 - .../assignment-to-global/_expected/system.js | 10 - .../assignment-to-global/_expected/umd.js | 8 - .../form/samples/assignment-to-global/main.js | 2 +- .../{_expected/cjs.js => _expected.js} | 6 +- .../_expected/amd.js | 20 -- .../_expected/es.js | 16 - .../_expected/iife.js | 21 -- .../_expected/system.js | 25 -- .../_expected/umd.js | 23 -- .../main.js | 4 +- .../conditional-expression-paths/_expected.js | 2 +- .../conditional-expression-paths/main.js | 2 +- .../dynamic-import-unresolvable/_expected.js | 3 - .../_expected/amd.js | 26 ++ .../_expected/cjs.js | 24 ++ .../_expected/es.js | 3 + .../_expected/iife.js | 8 + .../_expected}/system.js | 10 +- .../_expected/umd.js | 5 +- .../dynamic-import-unresolvable/main.js | 4 +- .../{_expected/es.js => _expected.js} | 0 .../empty-for-in-statement/_expected/amd.js | 6 - .../empty-for-in-statement/_expected/cjs.js | 4 - .../empty-for-in-statement/_expected/iife.js | 7 - .../_expected/system.js | 11 - .../empty-for-in-statement/_expected/umd.js | 9 - .../samples/empty-for-in-statement/main.js | 2 +- .../{_expected/es.js => _expected.js} | 0 .../empty-for-of-statement/_expected/amd.js | 6 - .../empty-for-of-statement/_expected/cjs.js | 4 - .../empty-for-of-statement/_expected/iife.js | 7 - .../_expected/system.js | 11 - .../samples/empty-for-of-statement/main.js | 2 +- .../{_expected/es.js => _expected.js} | 0 .../empty-if-statement/_expected/amd.js | 6 - .../empty-if-statement/_expected/cjs.js | 4 - .../empty-if-statement/_expected/iife.js | 7 - .../empty-if-statement/_expected/system.js | 11 - .../empty-if-statement/_expected/umd.js | 9 - test/form/samples/empty-if-statement/main.js | 2 +- .../{_expected/es.js => _expected.js} | 0 .../empty-switch-statement/_expected/amd.js | 6 - .../empty-switch-statement/_expected/cjs.js | 4 - .../empty-switch-statement/_expected/iife.js | 7 - .../_expected/system.js | 11 - .../empty-switch-statement/_expected/umd.js | 9 - .../samples/empty-switch-statement/main.js | 4 +- .../{_expected/es.js => _expected.js} | 2 +- .../samples/for-in-scopes/_expected/amd.js | 16 - .../samples/for-in-scopes/_expected/cjs.js | 14 - .../samples/for-in-scopes/_expected/iife.js | 17 - .../samples/for-in-scopes/_expected/system.js | 21 -- .../samples/for-in-scopes/_expected/umd.js | 19 -- test/form/samples/for-in-scopes/main.js | 2 +- .../{_expected/es.js => _expected.js} | 2 +- .../samples/for-of-scopes/_expected/amd.js | 15 - .../samples/for-of-scopes/_expected/cjs.js | 13 - .../samples/for-of-scopes/_expected/iife.js | 16 - .../samples/for-of-scopes/_expected/system.js | 20 -- .../samples/for-of-scopes/_expected/umd.js | 18 -- test/form/samples/for-of-scopes/main.js | 2 +- .../{_expected/es.js => _expected.js} | 4 +- .../_expected/amd.js | 42 --- .../_expected/cjs.js | 40 --- .../_expected/iife.js | 43 --- .../_expected/system.js | 47 --- .../_expected/umd.js | 45 --- .../function-body-return-values/main.js | 4 +- .../hoisted-variable-case-stmt/_expected.js | 2 +- .../hoisted-variable-case-stmt/main.js | 2 +- .../{_expected/es.js => _expected.js} | 0 .../_expected/amd.js | 5 - .../_expected/cjs.js | 2 - .../_expected/iife.js | 6 - .../_expected/system.js | 10 - .../_expected/umd.js | 8 - .../main.js | 2 +- .../_config.js | 10 + .../_expected.js} | 0 .../main.js | 2 + .../_expected.js} | 0 .../_expected/amd.js | 5 - .../_expected/cjs.js | 2 - .../_expected/iife.js | 6 - .../_expected/system.js | 10 - .../_expected/umd.js | 8 - .../browser.js | 2 +- .../{_expected/es.js => _expected.js} | 2 +- .../_expected/amd.js | 20 -- .../_expected/cjs.js | 18 -- .../_expected/iife.js | 21 -- .../_expected/system.js | 25 -- .../_expected/umd.js | 23 -- .../keep-property-access-side-effects/main.js | 2 +- test/form/samples/known-globals/_config.js | 3 + test/form/samples/known-globals/_expected.js | 1 + test/form/samples/known-globals/main.js | 5 + .../{_expected/es.js => _expected.js} | 4 +- .../labeled-break-statements/_expected/amd.js | 31 -- .../labeled-break-statements/_expected/cjs.js | 29 -- .../_expected/iife.js | 32 -- .../_expected/system.js | 36 --- .../labeled-break-statements/_expected/umd.js | 34 -- .../samples/labeled-break-statements/main.js | 6 +- .../{_expected/es.js => _expected.js} | 2 +- .../nested-member-access/_expected/amd.js | 27 -- .../nested-member-access/_expected/cjs.js | 25 -- .../nested-member-access/_expected/iife.js | 28 -- .../nested-member-access/_expected/system.js | 32 -- .../nested-member-access/_expected/umd.js | 30 -- .../form/samples/nested-member-access/main.js | 2 +- .../{_expected/es.js => _expected.js} | 4 +- .../nested-this-expressions/_expected/amd.js | 29 -- .../nested-this-expressions/_expected/cjs.js | 27 -- .../nested-this-expressions/_expected/iife.js | 30 -- .../_expected/system.js | 34 -- .../nested-this-expressions/_expected/umd.js | 32 -- .../samples/nested-this-expressions/main.js | 8 +- .../{_expected/es.js => _expected.js} | 2 +- .../nested-tree-shaking/_expected/amd.js | 12 - .../nested-tree-shaking/_expected/cjs.js | 10 - .../nested-tree-shaking/_expected/iife.js | 13 - .../nested-tree-shaking/_expected/system.js | 17 - .../nested-tree-shaking/_expected/umd.js | 15 - test/form/samples/nested-tree-shaking/main.js | 4 +- .../method-side-effects/_expected.js | 4 +- .../method-side-effects/main.js | 6 +- .../return-expressions/_expected.js | 4 +- .../return-expressions/main.js | 6 +- .../{_expected/cjs.js => _expected.js} | 6 +- .../_expected/amd.js | 41 --- .../_expected/es.js | 37 --- .../_expected/iife.js | 42 --- .../_expected/system.js | 46 --- .../_expected/umd.js | 44 --- .../main.js | 10 +- .../{_expected/cjs.js => _expected.js} | 4 +- .../_expected/amd.js | 23 -- .../_expected/es.js | 19 -- .../_expected/iife.js | 24 -- .../_expected/system.js | 28 -- .../_expected/umd.js | 26 -- .../pattern-member-expressions/main.js | 2 +- .../pure-comment-scenarios-complex/main.js | 1 + .../form/samples/recursive-calls/_expected.js | 39 +++ .../samples/recursive-calls/_expected/amd.js | 43 --- .../samples/recursive-calls/_expected/cjs.js | 41 --- .../samples/recursive-calls/_expected/es.js | 39 --- .../samples/recursive-calls/_expected/iife.js | 44 --- .../recursive-calls/_expected/system.js | 48 --- .../samples/recursive-calls/_expected/umd.js | 46 --- test/form/samples/recursive-calls/main.js | 32 +- .../removes-unused-babel-helpers/_expected.js | 1 + .../_expected/amd.js | 5 - .../_expected/cjs.js | 2 - .../_expected/iife.js | 6 - .../_expected/system.js | 10 - .../_expected/umd.js | 8 - .../{_expected/es.js => _expected.js} | 16 +- .../_expected/amd.js | 63 ---- .../_expected/cjs.js | 61 ---- .../_expected/iife.js | 64 ---- .../_expected/system.js | 68 ---- .../_expected/umd.js | 66 ---- .../samples/render-removed-statements/main.js | 16 +- .../{_expected/es.js => _expected.js} | 4 +- .../side-effects-await/_expected/amd.js | 16 - .../side-effects-await/_expected/cjs.js | 14 - .../side-effects-await/_expected/iife.js | 17 - .../side-effects-await/_expected/system.js | 21 -- .../side-effects-await/_expected/umd.js | 19 -- test/form/samples/side-effects-await/main.js | 6 +- .../{_expected/es.js => _expected.js} | 2 +- .../_expected/amd.js | 11 - .../_expected/cjs.js | 9 - .../_expected/iife.js | 12 - .../_expected/system.js | 16 - .../_expected/umd.js | 14 - .../side-effects-call-arguments/main.js | 4 +- .../_expected.js | 1 + .../_expected/amd.js | 5 - .../_expected/cjs.js | 3 - .../_expected/es.js | 1 - .../_expected/iife.js | 6 - .../_expected/system.js | 10 - .../_expected/umd.js | 8 - .../main.js | 4 +- .../side-effects-delete/_expected/amd.js | 2 +- .../side-effects-delete/_expected/cjs.js | 2 +- .../side-effects-delete/_expected/es.js | 2 +- .../side-effects-delete/_expected/iife.js | 2 +- .../side-effects-delete/_expected/system.js | 2 +- .../side-effects-delete/_expected/umd.js | 2 +- test/form/samples/side-effects-delete/main.js | 2 +- .../{_expected/es.js => _expected.js} | 2 +- .../_expected/amd.js | 40 --- .../_expected/cjs.js | 38 --- .../_expected/iife.js | 41 --- .../_expected/system.js | 45 --- .../_expected/umd.js | 43 --- .../side-effects-es6-super-classes/main.js | 2 +- .../{_expected/cjs.js => _expected.js} | 6 +- .../_expected/amd.js | 10 - .../_expected/es.js | 6 - .../_expected/iife.js | 11 - .../_expected/system.js | 15 - .../_expected/umd.js | 13 - .../main.js | 4 +- .../{_expected/es.js => _expected.js} | 6 +- .../side-effects-generators/_expected/amd.js | 28 -- .../side-effects-generators/_expected/cjs.js | 26 -- .../side-effects-generators/_expected/iife.js | 29 -- .../_expected/system.js | 33 -- .../side-effects-generators/_expected/umd.js | 31 -- .../samples/side-effects-generators/main.js | 6 +- .../{_expected/es.js => _expected.js} | 6 +- .../_expected/amd.js | 30 -- .../_expected/cjs.js | 28 -- .../_expected/iife.js | 31 -- .../_expected/system.js | 33 -- .../_expected/umd.js | 34 -- .../side-effects-in-template-literals/main.js | 6 +- .../{_expected/es.js => _expected.js} | 2 +- .../_expected/amd.js | 32 -- .../_expected/cjs.js | 30 -- .../_expected/iife.js | 33 -- .../_expected/system.js | 33 -- .../_expected/umd.js | 36 --- .../main.js | 4 +- .../_expected.js | 27 ++ .../_expected/amd.js | 31 -- .../_expected/cjs.js | 29 -- .../_expected/es.js | 27 -- .../_expected/iife.js | 32 -- .../_expected/system.js | 36 --- .../_expected/umd.js | 34 -- .../side-effects-pattern-assignment/main.js | 32 +- .../{_expected/es.js => _expected.js} | 18 +- .../_expected/amd.js | 36 --- .../_expected/cjs.js | 34 -- .../_expected/iife.js | 37 --- .../_expected/system.js | 41 --- .../_expected/umd.js | 39 --- .../side-effects-switch-statements/main.js | 24 +- test/form/samples/switch-scopes/_expected.js | 10 + .../samples/switch-scopes/_expected/amd.js | 14 - .../samples/switch-scopes/_expected/cjs.js | 12 - .../samples/switch-scopes/_expected/es.js | 10 - .../samples/switch-scopes/_expected/iife.js | 15 - .../samples/switch-scopes/_expected/system.js | 19 -- .../samples/switch-scopes/_expected/umd.js | 17 - test/form/samples/switch-scopes/main.js | 12 +- .../unused-parameters/_expected.js | 8 +- .../unused-parameters/main.js | 8 +- .../unknown-global-side-effects/_config.js | 14 + .../unknown-global-side-effects/main.js | 7 + .../wraps-simplified-expressions/main.js | 7 +- 271 files changed, 739 insertions(+), 4053 deletions(-) create mode 100644 src/ast/nodes/shared/knownGlobals.ts delete mode 100644 src/ast/nodes/shared/pureFunctions.ts create mode 100644 test/form/samples/assignment-to-global/_expected.js delete mode 100644 test/form/samples/assignment-to-global/_expected/amd.js delete mode 100644 test/form/samples/assignment-to-global/_expected/cjs.js delete mode 100644 test/form/samples/assignment-to-global/_expected/es.js delete mode 100644 test/form/samples/assignment-to-global/_expected/iife.js delete mode 100644 test/form/samples/assignment-to-global/_expected/system.js delete mode 100644 test/form/samples/assignment-to-global/_expected/umd.js rename test/form/samples/computed-member-expression-assignments/{_expected/cjs.js => _expected.js} (78%) delete mode 100644 test/form/samples/computed-member-expression-assignments/_expected/amd.js delete mode 100644 test/form/samples/computed-member-expression-assignments/_expected/es.js delete mode 100644 test/form/samples/computed-member-expression-assignments/_expected/iife.js delete mode 100644 test/form/samples/computed-member-expression-assignments/_expected/system.js delete mode 100644 test/form/samples/computed-member-expression-assignments/_expected/umd.js delete mode 100644 test/form/samples/dynamic-import-unresolvable/_expected.js create mode 100644 test/form/samples/dynamic-import-unresolvable/_expected/amd.js create mode 100644 test/form/samples/dynamic-import-unresolvable/_expected/cjs.js create mode 100644 test/form/samples/dynamic-import-unresolvable/_expected/es.js create mode 100644 test/form/samples/dynamic-import-unresolvable/_expected/iife.js rename test/form/samples/{side-effects-computed-pattern-keys => dynamic-import-unresolvable/_expected}/system.js (50%) rename test/form/samples/{empty-for-of-statement => dynamic-import-unresolvable}/_expected/umd.js (61%) rename test/form/samples/empty-for-in-statement/{_expected/es.js => _expected.js} (100%) delete mode 100644 test/form/samples/empty-for-in-statement/_expected/amd.js delete mode 100644 test/form/samples/empty-for-in-statement/_expected/cjs.js delete mode 100644 test/form/samples/empty-for-in-statement/_expected/iife.js delete mode 100644 test/form/samples/empty-for-in-statement/_expected/system.js delete mode 100644 test/form/samples/empty-for-in-statement/_expected/umd.js rename test/form/samples/empty-for-of-statement/{_expected/es.js => _expected.js} (100%) delete mode 100644 test/form/samples/empty-for-of-statement/_expected/amd.js delete mode 100644 test/form/samples/empty-for-of-statement/_expected/cjs.js delete mode 100644 test/form/samples/empty-for-of-statement/_expected/iife.js delete mode 100644 test/form/samples/empty-for-of-statement/_expected/system.js rename test/form/samples/empty-if-statement/{_expected/es.js => _expected.js} (100%) delete mode 100644 test/form/samples/empty-if-statement/_expected/amd.js delete mode 100644 test/form/samples/empty-if-statement/_expected/cjs.js delete mode 100644 test/form/samples/empty-if-statement/_expected/iife.js delete mode 100644 test/form/samples/empty-if-statement/_expected/system.js delete mode 100644 test/form/samples/empty-if-statement/_expected/umd.js rename test/form/samples/empty-switch-statement/{_expected/es.js => _expected.js} (100%) delete mode 100644 test/form/samples/empty-switch-statement/_expected/amd.js delete mode 100644 test/form/samples/empty-switch-statement/_expected/cjs.js delete mode 100644 test/form/samples/empty-switch-statement/_expected/iife.js delete mode 100644 test/form/samples/empty-switch-statement/_expected/system.js delete mode 100644 test/form/samples/empty-switch-statement/_expected/umd.js rename test/form/samples/for-in-scopes/{_expected/es.js => _expected.js} (84%) delete mode 100644 test/form/samples/for-in-scopes/_expected/amd.js delete mode 100644 test/form/samples/for-in-scopes/_expected/cjs.js delete mode 100644 test/form/samples/for-in-scopes/_expected/iife.js delete mode 100644 test/form/samples/for-in-scopes/_expected/system.js delete mode 100644 test/form/samples/for-in-scopes/_expected/umd.js rename test/form/samples/for-of-scopes/{_expected/es.js => _expected.js} (87%) delete mode 100644 test/form/samples/for-of-scopes/_expected/amd.js delete mode 100644 test/form/samples/for-of-scopes/_expected/cjs.js delete mode 100644 test/form/samples/for-of-scopes/_expected/iife.js delete mode 100644 test/form/samples/for-of-scopes/_expected/system.js delete mode 100644 test/form/samples/for-of-scopes/_expected/umd.js rename test/form/samples/function-body-return-values/{_expected/es.js => _expected.js} (88%) delete mode 100644 test/form/samples/function-body-return-values/_expected/amd.js delete mode 100644 test/form/samples/function-body-return-values/_expected/cjs.js delete mode 100644 test/form/samples/function-body-return-values/_expected/iife.js delete mode 100644 test/form/samples/function-body-return-values/_expected/system.js delete mode 100644 test/form/samples/function-body-return-values/_expected/umd.js rename test/form/samples/ignore-property-access-side-effects/{_expected/es.js => _expected.js} (100%) delete mode 100644 test/form/samples/ignore-property-access-side-effects/_expected/amd.js delete mode 100644 test/form/samples/ignore-property-access-side-effects/_expected/cjs.js delete mode 100644 test/form/samples/ignore-property-access-side-effects/_expected/iife.js delete mode 100644 test/form/samples/ignore-property-access-side-effects/_expected/system.js delete mode 100644 test/form/samples/ignore-property-access-side-effects/_expected/umd.js create mode 100644 test/form/samples/ignore-unknown-global-side-effects/_config.js rename test/form/samples/{import-named-exported-global-with-alias/_expected/es.js => ignore-unknown-global-side-effects/_expected.js} (100%) create mode 100644 test/form/samples/ignore-unknown-global-side-effects/main.js rename test/form/samples/{removes-unused-babel-helpers/_expected/es.js => import-named-exported-global-with-alias/_expected.js} (100%) delete mode 100644 test/form/samples/import-named-exported-global-with-alias/_expected/amd.js delete mode 100644 test/form/samples/import-named-exported-global-with-alias/_expected/cjs.js delete mode 100644 test/form/samples/import-named-exported-global-with-alias/_expected/iife.js delete mode 100644 test/form/samples/import-named-exported-global-with-alias/_expected/system.js delete mode 100644 test/form/samples/import-named-exported-global-with-alias/_expected/umd.js rename test/form/samples/keep-property-access-side-effects/{_expected/es.js => _expected.js} (81%) delete mode 100644 test/form/samples/keep-property-access-side-effects/_expected/amd.js delete mode 100644 test/form/samples/keep-property-access-side-effects/_expected/cjs.js delete mode 100644 test/form/samples/keep-property-access-side-effects/_expected/iife.js delete mode 100644 test/form/samples/keep-property-access-side-effects/_expected/system.js delete mode 100644 test/form/samples/keep-property-access-side-effects/_expected/umd.js create mode 100644 test/form/samples/known-globals/_config.js create mode 100644 test/form/samples/known-globals/_expected.js create mode 100644 test/form/samples/known-globals/main.js rename test/form/samples/labeled-break-statements/{_expected/es.js => _expected.js} (87%) delete mode 100644 test/form/samples/labeled-break-statements/_expected/amd.js delete mode 100644 test/form/samples/labeled-break-statements/_expected/cjs.js delete mode 100644 test/form/samples/labeled-break-statements/_expected/iife.js delete mode 100644 test/form/samples/labeled-break-statements/_expected/system.js delete mode 100644 test/form/samples/labeled-break-statements/_expected/umd.js rename test/form/samples/nested-member-access/{_expected/es.js => _expected.js} (92%) delete mode 100644 test/form/samples/nested-member-access/_expected/amd.js delete mode 100644 test/form/samples/nested-member-access/_expected/cjs.js delete mode 100644 test/form/samples/nested-member-access/_expected/iife.js delete mode 100644 test/form/samples/nested-member-access/_expected/system.js delete mode 100644 test/form/samples/nested-member-access/_expected/umd.js rename test/form/samples/nested-this-expressions/{_expected/es.js => _expected.js} (85%) delete mode 100644 test/form/samples/nested-this-expressions/_expected/amd.js delete mode 100644 test/form/samples/nested-this-expressions/_expected/cjs.js delete mode 100644 test/form/samples/nested-this-expressions/_expected/iife.js delete mode 100644 test/form/samples/nested-this-expressions/_expected/system.js delete mode 100644 test/form/samples/nested-this-expressions/_expected/umd.js rename test/form/samples/nested-tree-shaking/{_expected/es.js => _expected.js} (75%) delete mode 100644 test/form/samples/nested-tree-shaking/_expected/amd.js delete mode 100644 test/form/samples/nested-tree-shaking/_expected/cjs.js delete mode 100644 test/form/samples/nested-tree-shaking/_expected/iife.js delete mode 100644 test/form/samples/nested-tree-shaking/_expected/system.js delete mode 100644 test/form/samples/nested-tree-shaking/_expected/umd.js rename test/form/samples/object-literal-property-overwrites/{_expected/cjs.js => _expected.js} (89%) delete mode 100644 test/form/samples/object-literal-property-overwrites/_expected/amd.js delete mode 100644 test/form/samples/object-literal-property-overwrites/_expected/es.js delete mode 100644 test/form/samples/object-literal-property-overwrites/_expected/iife.js delete mode 100644 test/form/samples/object-literal-property-overwrites/_expected/system.js delete mode 100644 test/form/samples/object-literal-property-overwrites/_expected/umd.js rename test/form/samples/pattern-member-expressions/{_expected/cjs.js => _expected.js} (76%) delete mode 100644 test/form/samples/pattern-member-expressions/_expected/amd.js delete mode 100644 test/form/samples/pattern-member-expressions/_expected/es.js delete mode 100644 test/form/samples/pattern-member-expressions/_expected/iife.js delete mode 100644 test/form/samples/pattern-member-expressions/_expected/system.js delete mode 100644 test/form/samples/pattern-member-expressions/_expected/umd.js create mode 100644 test/form/samples/recursive-calls/_expected.js delete mode 100644 test/form/samples/recursive-calls/_expected/amd.js delete mode 100644 test/form/samples/recursive-calls/_expected/cjs.js delete mode 100644 test/form/samples/recursive-calls/_expected/es.js delete mode 100644 test/form/samples/recursive-calls/_expected/iife.js delete mode 100644 test/form/samples/recursive-calls/_expected/system.js delete mode 100644 test/form/samples/recursive-calls/_expected/umd.js create mode 100644 test/form/samples/removes-unused-babel-helpers/_expected.js delete mode 100644 test/form/samples/removes-unused-babel-helpers/_expected/amd.js delete mode 100644 test/form/samples/removes-unused-babel-helpers/_expected/cjs.js delete mode 100644 test/form/samples/removes-unused-babel-helpers/_expected/iife.js delete mode 100644 test/form/samples/removes-unused-babel-helpers/_expected/system.js delete mode 100644 test/form/samples/removes-unused-babel-helpers/_expected/umd.js rename test/form/samples/render-removed-statements/{_expected/es.js => _expected.js} (74%) delete mode 100644 test/form/samples/render-removed-statements/_expected/amd.js delete mode 100644 test/form/samples/render-removed-statements/_expected/cjs.js delete mode 100644 test/form/samples/render-removed-statements/_expected/iife.js delete mode 100644 test/form/samples/render-removed-statements/_expected/system.js delete mode 100644 test/form/samples/render-removed-statements/_expected/umd.js rename test/form/samples/side-effects-await/{_expected/es.js => _expected.js} (69%) delete mode 100644 test/form/samples/side-effects-await/_expected/amd.js delete mode 100644 test/form/samples/side-effects-await/_expected/cjs.js delete mode 100644 test/form/samples/side-effects-await/_expected/iife.js delete mode 100644 test/form/samples/side-effects-await/_expected/system.js delete mode 100644 test/form/samples/side-effects-await/_expected/umd.js rename test/form/samples/side-effects-call-arguments/{_expected/es.js => _expected.js} (70%) delete mode 100644 test/form/samples/side-effects-call-arguments/_expected/amd.js delete mode 100644 test/form/samples/side-effects-call-arguments/_expected/cjs.js delete mode 100644 test/form/samples/side-effects-call-arguments/_expected/iife.js delete mode 100644 test/form/samples/side-effects-call-arguments/_expected/system.js delete mode 100644 test/form/samples/side-effects-call-arguments/_expected/umd.js create mode 100644 test/form/samples/side-effects-computed-pattern-keys/_expected.js delete mode 100644 test/form/samples/side-effects-computed-pattern-keys/_expected/amd.js delete mode 100644 test/form/samples/side-effects-computed-pattern-keys/_expected/cjs.js delete mode 100644 test/form/samples/side-effects-computed-pattern-keys/_expected/es.js delete mode 100644 test/form/samples/side-effects-computed-pattern-keys/_expected/iife.js delete mode 100644 test/form/samples/side-effects-computed-pattern-keys/_expected/system.js delete mode 100644 test/form/samples/side-effects-computed-pattern-keys/_expected/umd.js rename test/form/samples/side-effects-es6-super-classes/{_expected/es.js => _expected.js} (93%) delete mode 100644 test/form/samples/side-effects-es6-super-classes/_expected/amd.js delete mode 100644 test/form/samples/side-effects-es6-super-classes/_expected/cjs.js delete mode 100644 test/form/samples/side-effects-es6-super-classes/_expected/iife.js delete mode 100644 test/form/samples/side-effects-es6-super-classes/_expected/system.js delete mode 100644 test/form/samples/side-effects-es6-super-classes/_expected/umd.js rename test/form/samples/side-effects-expressions-as-statements/{_expected/cjs.js => _expected.js} (57%) delete mode 100644 test/form/samples/side-effects-expressions-as-statements/_expected/amd.js delete mode 100644 test/form/samples/side-effects-expressions-as-statements/_expected/es.js delete mode 100644 test/form/samples/side-effects-expressions-as-statements/_expected/iife.js delete mode 100644 test/form/samples/side-effects-expressions-as-statements/_expected/system.js delete mode 100644 test/form/samples/side-effects-expressions-as-statements/_expected/umd.js rename test/form/samples/side-effects-generators/{_expected/es.js => _expected.js} (81%) delete mode 100644 test/form/samples/side-effects-generators/_expected/amd.js delete mode 100644 test/form/samples/side-effects-generators/_expected/cjs.js delete mode 100644 test/form/samples/side-effects-generators/_expected/iife.js delete mode 100644 test/form/samples/side-effects-generators/_expected/system.js delete mode 100644 test/form/samples/side-effects-generators/_expected/umd.js rename test/form/samples/side-effects-in-template-literals/{_expected/es.js => _expected.js} (66%) delete mode 100644 test/form/samples/side-effects-in-template-literals/_expected/amd.js delete mode 100644 test/form/samples/side-effects-in-template-literals/_expected/cjs.js delete mode 100644 test/form/samples/side-effects-in-template-literals/_expected/iife.js delete mode 100644 test/form/samples/side-effects-in-template-literals/_expected/system.js delete mode 100644 test/form/samples/side-effects-in-template-literals/_expected/umd.js rename test/form/samples/side-effects-object-literal-mutation/{_expected/es.js => _expected.js} (89%) delete mode 100644 test/form/samples/side-effects-object-literal-mutation/_expected/amd.js delete mode 100644 test/form/samples/side-effects-object-literal-mutation/_expected/cjs.js delete mode 100644 test/form/samples/side-effects-object-literal-mutation/_expected/iife.js delete mode 100644 test/form/samples/side-effects-object-literal-mutation/_expected/system.js delete mode 100644 test/form/samples/side-effects-object-literal-mutation/_expected/umd.js create mode 100644 test/form/samples/side-effects-pattern-assignment/_expected.js delete mode 100644 test/form/samples/side-effects-pattern-assignment/_expected/amd.js delete mode 100644 test/form/samples/side-effects-pattern-assignment/_expected/cjs.js delete mode 100644 test/form/samples/side-effects-pattern-assignment/_expected/es.js delete mode 100644 test/form/samples/side-effects-pattern-assignment/_expected/iife.js delete mode 100644 test/form/samples/side-effects-pattern-assignment/_expected/system.js delete mode 100644 test/form/samples/side-effects-pattern-assignment/_expected/umd.js rename test/form/samples/side-effects-switch-statements/{_expected/es.js => _expected.js} (52%) delete mode 100644 test/form/samples/side-effects-switch-statements/_expected/amd.js delete mode 100644 test/form/samples/side-effects-switch-statements/_expected/cjs.js delete mode 100644 test/form/samples/side-effects-switch-statements/_expected/iife.js delete mode 100644 test/form/samples/side-effects-switch-statements/_expected/system.js delete mode 100644 test/form/samples/side-effects-switch-statements/_expected/umd.js create mode 100644 test/form/samples/switch-scopes/_expected.js delete mode 100644 test/form/samples/switch-scopes/_expected/amd.js delete mode 100644 test/form/samples/switch-scopes/_expected/cjs.js delete mode 100644 test/form/samples/switch-scopes/_expected/es.js delete mode 100644 test/form/samples/switch-scopes/_expected/iife.js delete mode 100644 test/form/samples/switch-scopes/_expected/system.js delete mode 100644 test/form/samples/switch-scopes/_expected/umd.js create mode 100644 test/function/samples/unknown-global-side-effects/_config.js create mode 100644 test/function/samples/unknown-global-side-effects/main.js diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index 5b105f9a8af..a0863c232bc 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -802,7 +802,7 @@ Default: `false` If this option is provided, bundling will not fail if bindings are imported from a file that does not define these bindings. Instead, new variables will be created for these bindings with the value `undefined`. #### treeshake -Type: `boolean | { annotations?: boolean, moduleSideEffects?: ModuleSideEffectsOption, propertyReadSideEffects?: boolean }`
+Type: `boolean | { annotations?: boolean, moduleSideEffects?: ModuleSideEffectsOption, propertyReadSideEffects?: boolean, tryCatchDeoptimization?: boolean, unknownGlobalSideEffects?: boolean }`
CLI: `--treeshake`/`--no-treeshake`
Default: `true` @@ -938,6 +938,29 @@ test(otherFn); ``` +**treeshake.unknownGlobalSideEffects** +Type: `boolean`
+CLI: `--treeshake.unknownGlobalSideEffects`/`--no-treeshake.unknownGlobalSideEffects`
+Default: `true` + +Since accessing a non-existing global variable will throw an error, Rollup does by default retain any accesses to non-builtin global variables. Set this option to `false` to avoid this check. This is probably safe for most code-bases. + +```js +// input +const jQuery = $; +const requestTimeout = setTimeout; +const element = angular.element; + +// output with unknownGlobalSideEffects == true +const jQuery = $; +const element = angular.element; + +// output with unknownGlobalSideEffects == false +const element = angular.element; +``` + +In the example, the last line is always retained as accessing the `element` property could also throw an error if `angular` is e.g. `null`. To avoid this check, set `treeshake.propertyReadSideEffects` to `false` as well. + ### Experimental options These options reflect new features that have not yet been fully finalized. Availability, behaviour and usage may therefore be subject to change between minor versions. diff --git a/src/Graph.ts b/src/Graph.ts index 6ad883f4110..7c928a052b1 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -116,13 +116,16 @@ export default class Graph { (options.treeshake as TreeshakingOptions).propertyReadSideEffects !== false, pureExternalModules: (options.treeshake as TreeshakingOptions).pureExternalModules, tryCatchDeoptimization: - (options.treeshake as TreeshakingOptions).tryCatchDeoptimization !== false + (options.treeshake as TreeshakingOptions).tryCatchDeoptimization !== false, + unknownGlobalSideEffects: + (options.treeshake as TreeshakingOptions).unknownGlobalSideEffects !== false } : { annotations: true, moduleSideEffects: true, propertyReadSideEffects: true, - tryCatchDeoptimization: true + tryCatchDeoptimization: true, + unknownGlobalSideEffects: true }; if (typeof this.treeshakingOptions.pureExternalModules !== 'undefined') { this.warnDeprecation( diff --git a/src/Module.ts b/src/Module.ts index 50e31c3ee49..38f4e6643b3 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -110,6 +110,7 @@ export interface AstContext { traceVariable: (name: string) => Variable | null; treeshake: boolean; tryCatchDeoptimization: boolean; + unknownGlobalSideEffects: boolean; usesTopLevelAwait: boolean; warn: (warning: RollupWarning, pos: number) => void; warnDeprecation: (deprecation: string | RollupWarning, activeDeprecation: boolean) => void; @@ -606,6 +607,8 @@ export default class Module { treeshake: !!this.graph.treeshakingOptions, tryCatchDeoptimization: (!this.graph.treeshakingOptions || this.graph.treeshakingOptions.tryCatchDeoptimization) as boolean, + unknownGlobalSideEffects: (!this.graph.treeshakingOptions || + this.graph.treeshakingOptions.unknownGlobalSideEffects) as boolean, usesTopLevelAwait: false, warn: this.warn.bind(this), warnDeprecation: this.graph.warnDeprecation.bind(this.graph) diff --git a/src/ast/nodes/Identifier.ts b/src/ast/nodes/Identifier.ts index 33ea3147fff..056e8338d15 100644 --- a/src/ast/nodes/Identifier.ts +++ b/src/ast/nodes/Identifier.ts @@ -7,7 +7,8 @@ import { DeoptimizableEntity } from '../DeoptimizableEntity'; import { ExecutionPathOptions } from '../ExecutionPathOptions'; import FunctionScope from '../scopes/FunctionScope'; import { ImmutableEntityPathTracker } from '../utils/ImmutableEntityPathTracker'; -import { LiteralValueOrUnknown, ObjectPath, UNKNOWN_EXPRESSION, UNKNOWN_VALUE } from '../values'; +import { EMPTY_PATH, LiteralValueOrUnknown, ObjectPath } from '../values'; +import GlobalVariable from '../variables/GlobalVariable'; import LocalVariable from '../variables/LocalVariable'; import Variable from '../variables/Variable'; import * as NodeType from './NodeType'; @@ -62,24 +63,20 @@ export default class Identifier extends NodeBase implements PatternNode { case 'parameter': variable = (this.scope as FunctionScope).addParameterDeclaration(this); break; + /* istanbul ignore next */ default: - throw new Error(`Unexpected identifier kind ${kind}.`); + /* istanbul ignore next */ + throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`); } return [(this.variable = variable)]; } deoptimizePath(path: ObjectPath) { if (!this.bound) this.bind(); - if (this.variable !== null) { - if ( - path.length === 0 && - this.name in this.context.importDescriptions && - !this.scope.contains(this.name) - ) { - this.disallowImportReassignment(); - } - this.variable.deoptimizePath(path); + if (path.length === 0 && !this.scope.contains(this.name)) { + this.disallowImportReassignment(); } + (this.variable as Variable).deoptimizePath(path); } getLiteralValueAtPath( @@ -88,10 +85,7 @@ export default class Identifier extends NodeBase implements PatternNode { origin: DeoptimizableEntity ): LiteralValueOrUnknown { if (!this.bound) this.bind(); - if (this.variable !== null) { - return this.variable.getLiteralValueAtPath(path, recursionTracker, origin); - } - return UNKNOWN_VALUE; + return (this.variable as Variable).getLiteralValueAtPath(path, recursionTracker, origin); } getReturnExpressionWhenCalledAtPath( @@ -100,10 +94,19 @@ export default class Identifier extends NodeBase implements PatternNode { origin: DeoptimizableEntity ) { if (!this.bound) this.bind(); - if (this.variable !== null) { - return this.variable.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin); - } - return UNKNOWN_EXPRESSION; + return (this.variable as Variable).getReturnExpressionWhenCalledAtPath( + path, + recursionTracker, + origin + ); + } + + hasEffects(): boolean { + return ( + this.context.unknownGlobalSideEffects && + this.variable instanceof GlobalVariable && + this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH) + ); } hasEffectsWhenAccessedAtPath(path: ObjectPath, options: ExecutionPathOptions): boolean { @@ -132,9 +135,7 @@ export default class Identifier extends NodeBase implements PatternNode { } includeCallArguments(args: (ExpressionNode | SpreadElement)[]): void { - if (this.variable) { - this.variable.includeCallArguments(args); - } + (this.variable as Variable).includeCallArguments(args); } render( diff --git a/src/ast/nodes/shared/FunctionNode.ts b/src/ast/nodes/shared/FunctionNode.ts index 523303450f9..4d8ae7002a9 100644 --- a/src/ast/nodes/shared/FunctionNode.ts +++ b/src/ast/nodes/shared/FunctionNode.ts @@ -41,8 +41,8 @@ export default class FunctionNode extends NodeBase { return path.length === 0 ? this.scope.getReturnExpression() : UNKNOWN_EXPRESSION; } - hasEffects(options: ExecutionPathOptions) { - return this.id !== null && this.id.hasEffects(options); + hasEffects() { + return this.id !== null && this.id.hasEffects(); } hasEffectsWhenAccessedAtPath(path: ObjectPath) { diff --git a/src/ast/nodes/shared/knownGlobals.ts b/src/ast/nodes/shared/knownGlobals.ts new file mode 100644 index 00000000000..097db5ea036 --- /dev/null +++ b/src/ast/nodes/shared/knownGlobals.ts @@ -0,0 +1,299 @@ +import { ObjectPath } from '../../values'; + +const ValueProperties = Symbol('Value Properties'); + +interface ValueDescription { + pure: boolean; +} + +interface GlobalDescription { + [ValueProperties]: ValueDescription; + [pathKey: string]: GlobalDescription; +} + +const PURE: ValueDescription = { pure: true }; +const IMPURE: ValueDescription = { pure: false }; + +const OBJECT: GlobalDescription = { + // @ts-ignore + __proto__: null, + [ValueProperties]: IMPURE +}; + +const PURE_FUNCTION: GlobalDescription = { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE +}; + +const CONSTRUCTOR: GlobalDescription = { + // @ts-ignore + __proto__: null, + [ValueProperties]: IMPURE, + prototype: OBJECT +}; + +const PURE_CONSTRUCTOR: GlobalDescription = { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE, + prototype: OBJECT +}; + +const ARRAY_TYPE: GlobalDescription = { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE, + from: PURE_FUNCTION, + of: PURE_FUNCTION, + prototype: OBJECT +}; + +const INTL_MEMBER: GlobalDescription = { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE, + supportedLocalesOf: PURE_CONSTRUCTOR +}; + +const knownGlobals: GlobalDescription = { + // @ts-ignore + __proto__: null, + [ValueProperties]: IMPURE, + Array: { + // @ts-ignore + __proto__: null, + [ValueProperties]: IMPURE, + from: PURE_FUNCTION, + isArray: PURE_FUNCTION, + of: PURE_FUNCTION, + prototype: OBJECT + }, + ArrayBuffer: { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE, + isView: PURE_FUNCTION, + prototype: OBJECT + }, + Atomics: OBJECT, + BigInt: CONSTRUCTOR, + BigInt64Array: CONSTRUCTOR, + BigUint64Array: CONSTRUCTOR, + Boolean: PURE_CONSTRUCTOR, + // @ts-ignore + constructor: CONSTRUCTOR, + DataView: PURE_CONSTRUCTOR, + Date: { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE, + now: PURE_FUNCTION, + parse: PURE_FUNCTION, + prototype: OBJECT, + UTC: PURE_FUNCTION + }, + decodeURI: PURE_FUNCTION, + decodeURIComponent: PURE_FUNCTION, + encodeURI: PURE_FUNCTION, + encodeURIComponent: PURE_FUNCTION, + Error: PURE_CONSTRUCTOR, + escape: PURE_FUNCTION, + eval: OBJECT, + EvalError: PURE_CONSTRUCTOR, + Float32Array: ARRAY_TYPE, + Float64Array: ARRAY_TYPE, + Function: CONSTRUCTOR, + // @ts-ignore + hasOwnProperty: OBJECT, + Infinity: OBJECT, + Int16Array: ARRAY_TYPE, + Int32Array: ARRAY_TYPE, + Int8Array: ARRAY_TYPE, + isFinite: PURE_FUNCTION, + isNaN: PURE_FUNCTION, + // @ts-ignore + isPrototypeOf: OBJECT, + JSON: OBJECT, + Map: PURE_CONSTRUCTOR, + Math: { + // @ts-ignore + __proto__: null, + [ValueProperties]: IMPURE, + abs: PURE_FUNCTION, + acos: PURE_FUNCTION, + acosh: PURE_FUNCTION, + asin: PURE_FUNCTION, + asinh: PURE_FUNCTION, + atan: PURE_FUNCTION, + atan2: PURE_FUNCTION, + atanh: PURE_FUNCTION, + cbrt: PURE_FUNCTION, + ceil: PURE_FUNCTION, + clz32: PURE_FUNCTION, + cos: PURE_FUNCTION, + cosh: PURE_FUNCTION, + exp: PURE_FUNCTION, + expm1: PURE_FUNCTION, + floor: PURE_FUNCTION, + fround: PURE_FUNCTION, + hypot: PURE_FUNCTION, + imul: PURE_FUNCTION, + log: PURE_FUNCTION, + log10: PURE_FUNCTION, + log1p: PURE_FUNCTION, + log2: PURE_FUNCTION, + max: PURE_FUNCTION, + min: PURE_FUNCTION, + pow: PURE_FUNCTION, + random: PURE_FUNCTION, + round: PURE_FUNCTION, + sign: PURE_FUNCTION, + sin: PURE_FUNCTION, + sinh: PURE_FUNCTION, + sqrt: PURE_FUNCTION, + tan: PURE_FUNCTION, + tanh: PURE_FUNCTION, + trunc: PURE_FUNCTION + }, + NaN: OBJECT, + Number: { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE, + isFinite: PURE_FUNCTION, + isInteger: PURE_FUNCTION, + isNaN: PURE_FUNCTION, + isSafeInteger: PURE_FUNCTION, + parseFloat: PURE_FUNCTION, + parseInt: PURE_FUNCTION, + prototype: OBJECT + }, + Object: { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE, + create: PURE_FUNCTION, + getNotifier: PURE_FUNCTION, + getOwn: PURE_FUNCTION, + getOwnPropertyDescriptor: PURE_FUNCTION, + getOwnPropertyNames: PURE_FUNCTION, + getOwnPropertySymbols: PURE_FUNCTION, + getPrototypeOf: PURE_FUNCTION, + is: PURE_FUNCTION, + isExtensible: PURE_FUNCTION, + isFrozen: PURE_FUNCTION, + isSealed: PURE_FUNCTION, + keys: PURE_FUNCTION, + prototype: OBJECT + }, + parseFloat: PURE_FUNCTION, + parseInt: PURE_FUNCTION, + Promise: { + // @ts-ignore + __proto__: null, + [ValueProperties]: IMPURE, + all: PURE_FUNCTION, + prototype: OBJECT, + race: PURE_FUNCTION, + resolve: PURE_FUNCTION + }, + // @ts-ignore + propertyIsEnumerable: OBJECT, + Proxy: OBJECT, + RangeError: PURE_CONSTRUCTOR, + ReferenceError: PURE_CONSTRUCTOR, + Reflect: OBJECT, + RegExp: PURE_CONSTRUCTOR, + Set: PURE_CONSTRUCTOR, + SharedArrayBuffer: CONSTRUCTOR, + String: { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE, + fromCharCode: PURE_FUNCTION, + fromCodePoint: PURE_FUNCTION, + prototype: OBJECT, + raw: PURE_FUNCTION + }, + Symbol: { + // @ts-ignore + __proto__: null, + [ValueProperties]: PURE, + for: PURE_FUNCTION, + keyFor: PURE_FUNCTION, + prototype: OBJECT + }, + SyntaxError: PURE_CONSTRUCTOR, + // @ts-ignore + toLocaleString: OBJECT, + // @ts-ignore + toString: OBJECT, + TypeError: PURE_CONSTRUCTOR, + Uint16Array: ARRAY_TYPE, + Uint32Array: ARRAY_TYPE, + Uint8Array: ARRAY_TYPE, + Uint8ClampedArray: ARRAY_TYPE, + // Technically, this is a global, but it needs special handling + // undefined: ?, + unescape: PURE_FUNCTION, + URIError: PURE_CONSTRUCTOR, + // @ts-ignore + valueOf: OBJECT, + WeakMap: PURE_CONSTRUCTOR, + WeakSet: PURE_CONSTRUCTOR, + + // Additional globals shared by Node and Browser that are not strictly part of the language + clearInterval: CONSTRUCTOR, + clearTimeout: CONSTRUCTOR, + console: OBJECT, + Intl: { + // @ts-ignore + __proto__: null, + [ValueProperties]: IMPURE, + Collator: INTL_MEMBER, + DateTimeFormat: INTL_MEMBER, + ListFormat: INTL_MEMBER, + NumberFormat: INTL_MEMBER, + PluralRules: INTL_MEMBER, + RelativeTimeFormat: INTL_MEMBER + }, + setInterval: CONSTRUCTOR, + setTimeout: CONSTRUCTOR, + TextDecoder: CONSTRUCTOR, + TextEncoder: CONSTRUCTOR, + URL: CONSTRUCTOR, + URLSearchParams: CONSTRUCTOR +}; + +for (const global of ['window', 'global', 'self', 'globalThis']) { + knownGlobals[global] = knownGlobals; +} + +function getGlobalAtPath(path: ObjectPath): ValueDescription | null { + let currentGlobal = knownGlobals; + for (const pathSegment of path) { + if (typeof pathSegment !== 'string') { + return null; + } + currentGlobal = currentGlobal[pathSegment]; + if (!currentGlobal) { + return null; + } + } + return currentGlobal[ValueProperties]; +} + +export function isPureGlobal(path: ObjectPath): boolean { + const globalAtPath = getGlobalAtPath(path); + return globalAtPath !== null && globalAtPath.pure; +} + +export function isGlobalMember(path: ObjectPath): boolean { + if (path.length === 1) { + return path[0] === 'undefined' || getGlobalAtPath(path) !== null; + } + return getGlobalAtPath(path.slice(0, -1)) !== null; +} + +// TODO add others to this list from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects diff --git a/src/ast/nodes/shared/pureFunctions.ts b/src/ast/nodes/shared/pureFunctions.ts deleted file mode 100644 index 6fd4746e7e6..00000000000 --- a/src/ast/nodes/shared/pureFunctions.ts +++ /dev/null @@ -1,130 +0,0 @@ -const pureFunctions = [ - 'Array.isArray', - 'Error', - 'EvalError', - 'InternalError', - 'RangeError', - 'ReferenceError', - 'SyntaxError', - 'TypeError', - 'URIError', - 'isFinite', - 'isNaN', - 'parseFloat', - 'parseInt', - 'decodeURI', - 'decodeURIComponent', - 'encodeURI', - 'encodeURIComponent', - 'escape', - 'unescape', - 'Object', - 'Object.create', - 'Object.getNotifier', - 'Object.getOwn', - 'Object.getOwnPropertyDescriptor', - 'Object.getOwnPropertyNames', - 'Object.getOwnPropertySymbols', - 'Object.getPrototypeOf', - 'Object.is', - 'Object.isExtensible', - 'Object.isFrozen', - 'Object.isSealed', - 'Object.keys', - 'Boolean', - 'Number', - 'Number.isFinite', - 'Number.isInteger', - 'Number.isNaN', - 'Number.isSafeInteger', - 'Number.parseFloat', - 'Number.parseInt', - 'Symbol', - 'Symbol.for', - 'Symbol.keyFor', - 'Math.abs', - 'Math.acos', - 'Math.acosh', - 'Math.asin', - 'Math.asinh', - 'Math.atan', - 'Math.atan2', - 'Math.atanh', - 'Math.cbrt', - 'Math.ceil', - 'Math.clz32', - 'Math.cos', - 'Math.cosh', - 'Math.exp', - 'Math.expm1', - 'Math.floor', - 'Math.fround', - 'Math.hypot', - 'Math.imul', - 'Math.log', - 'Math.log10', - 'Math.log1p', - 'Math.log2', - 'Math.max', - 'Math.min', - 'Math.pow', - 'Math.random', - 'Math.round', - 'Math.sign', - 'Math.sin', - 'Math.sinh', - 'Math.sqrt', - 'Math.tan', - 'Math.tanh', - 'Math.trunc', - 'Date', - 'Date.UTC', - 'Date.now', - 'Date.parse', - 'String', - 'String.fromCharCode', - 'String.fromCodePoint', - 'String.raw', - 'RegExp', - 'Map', - 'Set', - 'WeakMap', - 'WeakSet', - 'ArrayBuffer', - 'ArrayBuffer.isView', - 'DataView', - 'Promise.all', - 'Promise.race', - 'Promise.resolve', - 'Intl.Collator', - 'Intl.Collator.supportedLocalesOf', - 'Intl.DateTimeFormat', - 'Intl.DateTimeFormat.supportedLocalesOf', - 'Intl.NumberFormat', - 'Intl.NumberFormat.supportedLocalesOf' -]; - -const arrayTypes = 'Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split( - ' ' -); - -for (const type of arrayTypes) { - pureFunctions.push(type, `${type}.from`, `${type}.of`); -} - -const simdTypes = 'Int8x16 Int16x8 Int32x4 Float32x4 Float64x2'.split(' '); -const simdMethods = 'abs add and bool check div equal extractLane fromFloat32x4 fromFloat32x4Bits fromFloat64x2 fromFloat64x2Bits fromInt16x8Bits fromInt32x4 fromInt32x4Bits fromInt8x16Bits greaterThan greaterThanOrEqual lessThan lessThanOrEqual load max maxNum min minNum mul neg not notEqual or reciprocalApproximation reciprocalSqrtApproximation replaceLane select selectBits shiftLeftByScalar shiftRightArithmeticByScalar shiftRightLogicalByScalar shuffle splat sqrt store sub swizzle xor'.split( - ' ' -); - -for (const type of simdTypes) { - const typeString = `SIMD.${type}`; - pureFunctions.push(typeString); - for (const method of simdMethods) { - pureFunctions.push(`${typeString}.${method}`); - } -} - -// TODO add others to this list from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects - -export default new Set(pureFunctions); diff --git a/src/ast/variables/GlobalVariable.ts b/src/ast/variables/GlobalVariable.ts index 07358c7d3ea..6aa5d5b9561 100644 --- a/src/ast/variables/GlobalVariable.ts +++ b/src/ast/variables/GlobalVariable.ts @@ -1,28 +1,13 @@ -import pureFunctions from '../nodes/shared/pureFunctions'; +import { isGlobalMember, isPureGlobal } from '../nodes/shared/knownGlobals'; import { ObjectPath } from '../values'; import Variable from './Variable'; export default class GlobalVariable extends Variable { hasEffectsWhenAccessedAtPath(path: ObjectPath) { - // path.length == 0 can also have an effect but we postpone this for now - return ( - path.length > 0 && - !this.isPureFunctionMember(path) && - !(this.name === 'Reflect' && path.length === 1) - ); + return !isGlobalMember([this.name, ...path]); } hasEffectsWhenCalledAtPath(path: ObjectPath) { - return !pureFunctions.has([this.name, ...path].join('.')); - } - - private isPureFunctionMember(path: ObjectPath) { - return ( - pureFunctions.has([this.name, ...path].join('.')) || - (path.length >= 1 && pureFunctions.has([this.name, ...path.slice(0, -1)].join('.'))) || - (path.length >= 2 && - pureFunctions.has([this.name, ...path.slice(0, -2)].join('.')) && - path[path.length - 2] === 'prototype') - ); + return !isPureGlobal([this.name, ...path]); } } diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 027860f4281..67daf46526a 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -390,6 +390,7 @@ export interface TreeshakingOptions { /** @deprecated Use `moduleSideEffects` instead */ pureExternalModules?: PureModulesOption; tryCatchDeoptimization?: boolean; + unknownGlobalSideEffects?: boolean; } export type GetManualChunk = (id: string) => string | null | undefined; diff --git a/test/form/samples/assignment-to-global/_expected.js b/test/form/samples/assignment-to-global/_expected.js new file mode 100644 index 00000000000..d981fe4b5aa --- /dev/null +++ b/test/form/samples/assignment-to-global/_expected.js @@ -0,0 +1 @@ +globalThis.unknown = 1; diff --git a/test/form/samples/assignment-to-global/_expected/amd.js b/test/form/samples/assignment-to-global/_expected/amd.js deleted file mode 100644 index 826e028df97..00000000000 --- a/test/form/samples/assignment-to-global/_expected/amd.js +++ /dev/null @@ -1,5 +0,0 @@ -define(function () { 'use strict'; - - globalVar = 1; - -}); diff --git a/test/form/samples/assignment-to-global/_expected/cjs.js b/test/form/samples/assignment-to-global/_expected/cjs.js deleted file mode 100644 index 189cafbb629..00000000000 --- a/test/form/samples/assignment-to-global/_expected/cjs.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -globalVar = 1; diff --git a/test/form/samples/assignment-to-global/_expected/es.js b/test/form/samples/assignment-to-global/_expected/es.js deleted file mode 100644 index 55bd74e7872..00000000000 --- a/test/form/samples/assignment-to-global/_expected/es.js +++ /dev/null @@ -1 +0,0 @@ -globalVar = 1; diff --git a/test/form/samples/assignment-to-global/_expected/iife.js b/test/form/samples/assignment-to-global/_expected/iife.js deleted file mode 100644 index 7de37834705..00000000000 --- a/test/form/samples/assignment-to-global/_expected/iife.js +++ /dev/null @@ -1,6 +0,0 @@ -(function () { - 'use strict'; - - globalVar = 1; - -}()); diff --git a/test/form/samples/assignment-to-global/_expected/system.js b/test/form/samples/assignment-to-global/_expected/system.js deleted file mode 100644 index 7689b8672c9..00000000000 --- a/test/form/samples/assignment-to-global/_expected/system.js +++ /dev/null @@ -1,10 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - globalVar = 1; - - } - }; -}); diff --git a/test/form/samples/assignment-to-global/_expected/umd.js b/test/form/samples/assignment-to-global/_expected/umd.js deleted file mode 100644 index 6b9ab0bbaf2..00000000000 --- a/test/form/samples/assignment-to-global/_expected/umd.js +++ /dev/null @@ -1,8 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - globalVar = 1; - -})); diff --git a/test/form/samples/assignment-to-global/main.js b/test/form/samples/assignment-to-global/main.js index 55bd74e7872..d981fe4b5aa 100644 --- a/test/form/samples/assignment-to-global/main.js +++ b/test/form/samples/assignment-to-global/main.js @@ -1 +1 @@ -globalVar = 1; +globalThis.unknown = 1; diff --git a/test/form/samples/computed-member-expression-assignments/_expected/cjs.js b/test/form/samples/computed-member-expression-assignments/_expected.js similarity index 78% rename from test/form/samples/computed-member-expression-assignments/_expected/cjs.js rename to test/form/samples/computed-member-expression-assignments/_expected.js index 92523c3dd90..04e85852949 100644 --- a/test/form/samples/computed-member-expression-assignments/_expected/cjs.js +++ b/test/form/samples/computed-member-expression-assignments/_expected.js @@ -1,13 +1,11 @@ -'use strict'; - const retained1 = { foo: {} }; -retained1[ 'f' + 'oo' ] = globalVar; +retained1[ 'f' + 'oo' ] = globalThis.unknown; retained1.foo.bar = 1; const retained2 = {}; retained2[ 'f' + 'oo' ].bar = 1; -const retained3 = { foo: globalVar }; +const retained3 = { foo: globalThis.unknown }; retained3.foo[ 'b' + 'ar' ] = 1; const retained4 = { foo: () => {} }; diff --git a/test/form/samples/computed-member-expression-assignments/_expected/amd.js b/test/form/samples/computed-member-expression-assignments/_expected/amd.js deleted file mode 100644 index 1a5957392ff..00000000000 --- a/test/form/samples/computed-member-expression-assignments/_expected/amd.js +++ /dev/null @@ -1,20 +0,0 @@ -define(function () { 'use strict'; - - const retained1 = { foo: {} }; - retained1[ 'f' + 'oo' ] = globalVar; - retained1.foo.bar = 1; - - const retained2 = {}; - retained2[ 'f' + 'oo' ].bar = 1; - - const retained3 = { foo: globalVar }; - retained3.foo[ 'b' + 'ar' ] = 1; - - const retained4 = { foo: () => {} }; - retained4[ 'f' + 'oo' ] = function () {this.x = 1;}; - retained4.foo(); - - const retained5 = { foo: function () {this.x = 1;} }; - retained5[ 'f' + 'oo' ](); - -}); diff --git a/test/form/samples/computed-member-expression-assignments/_expected/es.js b/test/form/samples/computed-member-expression-assignments/_expected/es.js deleted file mode 100644 index 9d96b1ed68e..00000000000 --- a/test/form/samples/computed-member-expression-assignments/_expected/es.js +++ /dev/null @@ -1,16 +0,0 @@ -const retained1 = { foo: {} }; -retained1[ 'f' + 'oo' ] = globalVar; -retained1.foo.bar = 1; - -const retained2 = {}; -retained2[ 'f' + 'oo' ].bar = 1; - -const retained3 = { foo: globalVar }; -retained3.foo[ 'b' + 'ar' ] = 1; - -const retained4 = { foo: () => {} }; -retained4[ 'f' + 'oo' ] = function () {this.x = 1;}; -retained4.foo(); - -const retained5 = { foo: function () {this.x = 1;} }; -retained5[ 'f' + 'oo' ](); diff --git a/test/form/samples/computed-member-expression-assignments/_expected/iife.js b/test/form/samples/computed-member-expression-assignments/_expected/iife.js deleted file mode 100644 index c57a69a8822..00000000000 --- a/test/form/samples/computed-member-expression-assignments/_expected/iife.js +++ /dev/null @@ -1,21 +0,0 @@ -(function () { - 'use strict'; - - const retained1 = { foo: {} }; - retained1[ 'f' + 'oo' ] = globalVar; - retained1.foo.bar = 1; - - const retained2 = {}; - retained2[ 'f' + 'oo' ].bar = 1; - - const retained3 = { foo: globalVar }; - retained3.foo[ 'b' + 'ar' ] = 1; - - const retained4 = { foo: () => {} }; - retained4[ 'f' + 'oo' ] = function () {this.x = 1;}; - retained4.foo(); - - const retained5 = { foo: function () {this.x = 1;} }; - retained5[ 'f' + 'oo' ](); - -}()); diff --git a/test/form/samples/computed-member-expression-assignments/_expected/system.js b/test/form/samples/computed-member-expression-assignments/_expected/system.js deleted file mode 100644 index 07716bb6620..00000000000 --- a/test/form/samples/computed-member-expression-assignments/_expected/system.js +++ /dev/null @@ -1,25 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - const retained1 = { foo: {} }; - retained1[ 'f' + 'oo' ] = globalVar; - retained1.foo.bar = 1; - - const retained2 = {}; - retained2[ 'f' + 'oo' ].bar = 1; - - const retained3 = { foo: globalVar }; - retained3.foo[ 'b' + 'ar' ] = 1; - - const retained4 = { foo: () => {} }; - retained4[ 'f' + 'oo' ] = function () {this.x = 1;}; - retained4.foo(); - - const retained5 = { foo: function () {this.x = 1;} }; - retained5[ 'f' + 'oo' ](); - - } - }; -}); diff --git a/test/form/samples/computed-member-expression-assignments/_expected/umd.js b/test/form/samples/computed-member-expression-assignments/_expected/umd.js deleted file mode 100644 index 69834d5df84..00000000000 --- a/test/form/samples/computed-member-expression-assignments/_expected/umd.js +++ /dev/null @@ -1,23 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - const retained1 = { foo: {} }; - retained1[ 'f' + 'oo' ] = globalVar; - retained1.foo.bar = 1; - - const retained2 = {}; - retained2[ 'f' + 'oo' ].bar = 1; - - const retained3 = { foo: globalVar }; - retained3.foo[ 'b' + 'ar' ] = 1; - - const retained4 = { foo: () => {} }; - retained4[ 'f' + 'oo' ] = function () {this.x = 1;}; - retained4.foo(); - - const retained5 = { foo: function () {this.x = 1;} }; - retained5[ 'f' + 'oo' ](); - -})); diff --git a/test/form/samples/computed-member-expression-assignments/main.js b/test/form/samples/computed-member-expression-assignments/main.js index 0660d2c4cf3..249be4dbfa3 100644 --- a/test/form/samples/computed-member-expression-assignments/main.js +++ b/test/form/samples/computed-member-expression-assignments/main.js @@ -1,11 +1,11 @@ const retained1 = { foo: {} }; -retained1[ 'f' + 'oo' ] = globalVar; +retained1[ 'f' + 'oo' ] = globalThis.unknown; retained1.foo.bar = 1; const retained2 = {}; retained2[ 'f' + 'oo' ].bar = 1; -const retained3 = { foo: globalVar }; +const retained3 = { foo: globalThis.unknown }; retained3.foo[ 'b' + 'ar' ] = 1; const retained4 = { foo: () => {} }; diff --git a/test/form/samples/conditional-expression-paths/_expected.js b/test/form/samples/conditional-expression-paths/_expected.js index c33903b0aea..882a3d152d2 100644 --- a/test/form/samples/conditional-expression-paths/_expected.js +++ b/test/form/samples/conditional-expression-paths/_expected.js @@ -1,4 +1,4 @@ -var unknownValue = globalFunction(); +var unknownValue = globalThis.unknown(); var foo = { x: () => {}, y: {} }; var baz = { x: () => console.log('effect') }; diff --git a/test/form/samples/conditional-expression-paths/main.js b/test/form/samples/conditional-expression-paths/main.js index 3fb0574de07..67d2162a495 100644 --- a/test/form/samples/conditional-expression-paths/main.js +++ b/test/form/samples/conditional-expression-paths/main.js @@ -1,4 +1,4 @@ -var unknownValue = globalFunction(); +var unknownValue = globalThis.unknown(); var foo = { x: () => {}, y: {} }; var bar = { x: () => {}, y: {} }; var baz = { x: () => console.log('effect') }; diff --git a/test/form/samples/dynamic-import-unresolvable/_expected.js b/test/form/samples/dynamic-import-unresolvable/_expected.js deleted file mode 100644 index 10da593b0b0..00000000000 --- a/test/form/samples/dynamic-import-unresolvable/_expected.js +++ /dev/null @@ -1,3 +0,0 @@ -import(`${globalVar}`); -import(`My ${globalVar}`); -import(7); diff --git a/test/form/samples/dynamic-import-unresolvable/_expected/amd.js b/test/form/samples/dynamic-import-unresolvable/_expected/amd.js new file mode 100644 index 00000000000..23dd8232c03 --- /dev/null +++ b/test/form/samples/dynamic-import-unresolvable/_expected/amd.js @@ -0,0 +1,26 @@ +define(['require'], function (require) { 'use strict'; + + function _interopNamespace(e) { + if (e && e.__esModule) { return e; } else { + var n = {}; + if (e) { + Object.keys(e).forEach(function (k) { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { + return e[k]; + } + }); + }); + } + n['default'] = e; + return n; + } + } + + new Promise(function (resolve, reject) { require([`${globalThis.unknown}`], function (m) { resolve(_interopNamespace(m)); }, reject) }); + new Promise(function (resolve, reject) { require([`My ${globalThis.unknown}`], function (m) { resolve(_interopNamespace(m)); }, reject) }); + new Promise(function (resolve, reject) { require([7], function (m) { resolve(_interopNamespace(m)); }, reject) }); + +}); diff --git a/test/form/samples/dynamic-import-unresolvable/_expected/cjs.js b/test/form/samples/dynamic-import-unresolvable/_expected/cjs.js new file mode 100644 index 00000000000..0290948c069 --- /dev/null +++ b/test/form/samples/dynamic-import-unresolvable/_expected/cjs.js @@ -0,0 +1,24 @@ +'use strict'; + +function _interopNamespace(e) { + if (e && e.__esModule) { return e; } else { + var n = {}; + if (e) { + Object.keys(e).forEach(function (k) { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { + return e[k]; + } + }); + }); + } + n['default'] = e; + return n; + } +} + +new Promise(function (resolve) { resolve(_interopNamespace(require(`${globalThis.unknown}`))); }); +new Promise(function (resolve) { resolve(_interopNamespace(require(`My ${globalThis.unknown}`))); }); +new Promise(function (resolve) { resolve(_interopNamespace(require(7))); }); diff --git a/test/form/samples/dynamic-import-unresolvable/_expected/es.js b/test/form/samples/dynamic-import-unresolvable/_expected/es.js new file mode 100644 index 00000000000..2c04ceceac4 --- /dev/null +++ b/test/form/samples/dynamic-import-unresolvable/_expected/es.js @@ -0,0 +1,3 @@ +import(`${globalThis.unknown}`); +import(`My ${globalThis.unknown}`); +import(7); diff --git a/test/form/samples/dynamic-import-unresolvable/_expected/iife.js b/test/form/samples/dynamic-import-unresolvable/_expected/iife.js new file mode 100644 index 00000000000..c8fccafa406 --- /dev/null +++ b/test/form/samples/dynamic-import-unresolvable/_expected/iife.js @@ -0,0 +1,8 @@ +(function () { + 'use strict'; + + import(`${globalThis.unknown}`); + import(`My ${globalThis.unknown}`); + import(7); + +}()); diff --git a/test/form/samples/side-effects-computed-pattern-keys/system.js b/test/form/samples/dynamic-import-unresolvable/_expected/system.js similarity index 50% rename from test/form/samples/side-effects-computed-pattern-keys/system.js rename to test/form/samples/dynamic-import-unresolvable/_expected/system.js index b5d40096427..f8b7f8294c5 100644 --- a/test/form/samples/side-effects-computed-pattern-keys/system.js +++ b/test/form/samples/dynamic-import-unresolvable/_expected/system.js @@ -3,13 +3,9 @@ System.register([], function (exports, module) { return { execute: function () { - function foo () {} - foo( globalFunction() ); - - var baz = 2; - foo( baz++ ); - - assert.equal(baz, 3); + module.import(`${globalThis.unknown}`); + module.import(`My ${globalThis.unknown}`); + module.import(7); } }; diff --git a/test/form/samples/empty-for-of-statement/_expected/umd.js b/test/form/samples/dynamic-import-unresolvable/_expected/umd.js similarity index 61% rename from test/form/samples/empty-for-of-statement/_expected/umd.js rename to test/form/samples/dynamic-import-unresolvable/_expected/umd.js index 407e9a0ed49..9aa8b996258 100644 --- a/test/form/samples/empty-for-of-statement/_expected/umd.js +++ b/test/form/samples/dynamic-import-unresolvable/_expected/umd.js @@ -3,7 +3,8 @@ factory(); }(function () { 'use strict'; - console.log( 1 ); - console.log( 2 ); + import(`${globalThis.unknown}`); + import(`My ${globalThis.unknown}`); + import(7); })); diff --git a/test/form/samples/dynamic-import-unresolvable/main.js b/test/form/samples/dynamic-import-unresolvable/main.js index 10da593b0b0..2c04ceceac4 100644 --- a/test/form/samples/dynamic-import-unresolvable/main.js +++ b/test/form/samples/dynamic-import-unresolvable/main.js @@ -1,3 +1,3 @@ -import(`${globalVar}`); -import(`My ${globalVar}`); +import(`${globalThis.unknown}`); +import(`My ${globalThis.unknown}`); import(7); diff --git a/test/form/samples/empty-for-in-statement/_expected/es.js b/test/form/samples/empty-for-in-statement/_expected.js similarity index 100% rename from test/form/samples/empty-for-in-statement/_expected/es.js rename to test/form/samples/empty-for-in-statement/_expected.js diff --git a/test/form/samples/empty-for-in-statement/_expected/amd.js b/test/form/samples/empty-for-in-statement/_expected/amd.js deleted file mode 100644 index 6036f2851d3..00000000000 --- a/test/form/samples/empty-for-in-statement/_expected/amd.js +++ /dev/null @@ -1,6 +0,0 @@ -define(function () { 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -}); diff --git a/test/form/samples/empty-for-in-statement/_expected/cjs.js b/test/form/samples/empty-for-in-statement/_expected/cjs.js deleted file mode 100644 index 33f9de05030..00000000000 --- a/test/form/samples/empty-for-in-statement/_expected/cjs.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -console.log( 1 ); -console.log( 2 ); diff --git a/test/form/samples/empty-for-in-statement/_expected/iife.js b/test/form/samples/empty-for-in-statement/_expected/iife.js deleted file mode 100644 index 08a84a95e53..00000000000 --- a/test/form/samples/empty-for-in-statement/_expected/iife.js +++ /dev/null @@ -1,7 +0,0 @@ -(function () { - 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -}()); diff --git a/test/form/samples/empty-for-in-statement/_expected/system.js b/test/form/samples/empty-for-in-statement/_expected/system.js deleted file mode 100644 index d8a0e92b62a..00000000000 --- a/test/form/samples/empty-for-in-statement/_expected/system.js +++ /dev/null @@ -1,11 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - console.log( 1 ); - console.log( 2 ); - - } - }; -}); diff --git a/test/form/samples/empty-for-in-statement/_expected/umd.js b/test/form/samples/empty-for-in-statement/_expected/umd.js deleted file mode 100644 index 407e9a0ed49..00000000000 --- a/test/form/samples/empty-for-in-statement/_expected/umd.js +++ /dev/null @@ -1,9 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -})); diff --git a/test/form/samples/empty-for-in-statement/main.js b/test/form/samples/empty-for-in-statement/main.js index cb706f7a16c..c93ef45d2c5 100644 --- a/test/form/samples/empty-for-in-statement/main.js +++ b/test/form/samples/empty-for-in-statement/main.js @@ -1,5 +1,5 @@ console.log( 1 ); -for ( const i in whatever ) { +for ( const i in globalThis.unknown ) { // do nothing } console.log( 2 ); diff --git a/test/form/samples/empty-for-of-statement/_expected/es.js b/test/form/samples/empty-for-of-statement/_expected.js similarity index 100% rename from test/form/samples/empty-for-of-statement/_expected/es.js rename to test/form/samples/empty-for-of-statement/_expected.js diff --git a/test/form/samples/empty-for-of-statement/_expected/amd.js b/test/form/samples/empty-for-of-statement/_expected/amd.js deleted file mode 100644 index 6036f2851d3..00000000000 --- a/test/form/samples/empty-for-of-statement/_expected/amd.js +++ /dev/null @@ -1,6 +0,0 @@ -define(function () { 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -}); diff --git a/test/form/samples/empty-for-of-statement/_expected/cjs.js b/test/form/samples/empty-for-of-statement/_expected/cjs.js deleted file mode 100644 index 33f9de05030..00000000000 --- a/test/form/samples/empty-for-of-statement/_expected/cjs.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -console.log( 1 ); -console.log( 2 ); diff --git a/test/form/samples/empty-for-of-statement/_expected/iife.js b/test/form/samples/empty-for-of-statement/_expected/iife.js deleted file mode 100644 index 08a84a95e53..00000000000 --- a/test/form/samples/empty-for-of-statement/_expected/iife.js +++ /dev/null @@ -1,7 +0,0 @@ -(function () { - 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -}()); diff --git a/test/form/samples/empty-for-of-statement/_expected/system.js b/test/form/samples/empty-for-of-statement/_expected/system.js deleted file mode 100644 index d8a0e92b62a..00000000000 --- a/test/form/samples/empty-for-of-statement/_expected/system.js +++ /dev/null @@ -1,11 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - console.log( 1 ); - console.log( 2 ); - - } - }; -}); diff --git a/test/form/samples/empty-for-of-statement/main.js b/test/form/samples/empty-for-of-statement/main.js index e591ddeaef2..90cdbd9806c 100644 --- a/test/form/samples/empty-for-of-statement/main.js +++ b/test/form/samples/empty-for-of-statement/main.js @@ -1,5 +1,5 @@ console.log( 1 ); -for ( const i of whatever ) { +for ( const i of globalThis.unknown ) { // do nothing } console.log( 2 ); diff --git a/test/form/samples/empty-if-statement/_expected/es.js b/test/form/samples/empty-if-statement/_expected.js similarity index 100% rename from test/form/samples/empty-if-statement/_expected/es.js rename to test/form/samples/empty-if-statement/_expected.js diff --git a/test/form/samples/empty-if-statement/_expected/amd.js b/test/form/samples/empty-if-statement/_expected/amd.js deleted file mode 100644 index 6036f2851d3..00000000000 --- a/test/form/samples/empty-if-statement/_expected/amd.js +++ /dev/null @@ -1,6 +0,0 @@ -define(function () { 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -}); diff --git a/test/form/samples/empty-if-statement/_expected/cjs.js b/test/form/samples/empty-if-statement/_expected/cjs.js deleted file mode 100644 index 33f9de05030..00000000000 --- a/test/form/samples/empty-if-statement/_expected/cjs.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -console.log( 1 ); -console.log( 2 ); diff --git a/test/form/samples/empty-if-statement/_expected/iife.js b/test/form/samples/empty-if-statement/_expected/iife.js deleted file mode 100644 index 08a84a95e53..00000000000 --- a/test/form/samples/empty-if-statement/_expected/iife.js +++ /dev/null @@ -1,7 +0,0 @@ -(function () { - 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -}()); diff --git a/test/form/samples/empty-if-statement/_expected/system.js b/test/form/samples/empty-if-statement/_expected/system.js deleted file mode 100644 index d8a0e92b62a..00000000000 --- a/test/form/samples/empty-if-statement/_expected/system.js +++ /dev/null @@ -1,11 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - console.log( 1 ); - console.log( 2 ); - - } - }; -}); diff --git a/test/form/samples/empty-if-statement/_expected/umd.js b/test/form/samples/empty-if-statement/_expected/umd.js deleted file mode 100644 index 407e9a0ed49..00000000000 --- a/test/form/samples/empty-if-statement/_expected/umd.js +++ /dev/null @@ -1,9 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -})); diff --git a/test/form/samples/empty-if-statement/main.js b/test/form/samples/empty-if-statement/main.js index 6db9dc163b9..80f1d780ca3 100644 --- a/test/form/samples/empty-if-statement/main.js +++ b/test/form/samples/empty-if-statement/main.js @@ -1,5 +1,5 @@ console.log( 1 ); -if ( nothing ) { +if ( globalThis.unknown ) { // empty } console.log( 2 ); diff --git a/test/form/samples/empty-switch-statement/_expected/es.js b/test/form/samples/empty-switch-statement/_expected.js similarity index 100% rename from test/form/samples/empty-switch-statement/_expected/es.js rename to test/form/samples/empty-switch-statement/_expected.js diff --git a/test/form/samples/empty-switch-statement/_expected/amd.js b/test/form/samples/empty-switch-statement/_expected/amd.js deleted file mode 100644 index 6036f2851d3..00000000000 --- a/test/form/samples/empty-switch-statement/_expected/amd.js +++ /dev/null @@ -1,6 +0,0 @@ -define(function () { 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -}); diff --git a/test/form/samples/empty-switch-statement/_expected/cjs.js b/test/form/samples/empty-switch-statement/_expected/cjs.js deleted file mode 100644 index 33f9de05030..00000000000 --- a/test/form/samples/empty-switch-statement/_expected/cjs.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -console.log( 1 ); -console.log( 2 ); diff --git a/test/form/samples/empty-switch-statement/_expected/iife.js b/test/form/samples/empty-switch-statement/_expected/iife.js deleted file mode 100644 index 08a84a95e53..00000000000 --- a/test/form/samples/empty-switch-statement/_expected/iife.js +++ /dev/null @@ -1,7 +0,0 @@ -(function () { - 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -}()); diff --git a/test/form/samples/empty-switch-statement/_expected/system.js b/test/form/samples/empty-switch-statement/_expected/system.js deleted file mode 100644 index d8a0e92b62a..00000000000 --- a/test/form/samples/empty-switch-statement/_expected/system.js +++ /dev/null @@ -1,11 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - console.log( 1 ); - console.log( 2 ); - - } - }; -}); diff --git a/test/form/samples/empty-switch-statement/_expected/umd.js b/test/form/samples/empty-switch-statement/_expected/umd.js deleted file mode 100644 index 407e9a0ed49..00000000000 --- a/test/form/samples/empty-switch-statement/_expected/umd.js +++ /dev/null @@ -1,9 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - console.log( 1 ); - console.log( 2 ); - -})); diff --git a/test/form/samples/empty-switch-statement/main.js b/test/form/samples/empty-switch-statement/main.js index 58da4d475d3..b5d2ef32d03 100644 --- a/test/form/samples/empty-switch-statement/main.js +++ b/test/form/samples/empty-switch-statement/main.js @@ -1,7 +1,7 @@ console.log( 1 ); var result; -switch ( whatever ) { - case foo: +switch ( globalThis.unknown ) { + case 'foo': result = 'foo'; break; diff --git a/test/form/samples/for-in-scopes/_expected/es.js b/test/form/samples/for-in-scopes/_expected.js similarity index 84% rename from test/form/samples/for-in-scopes/_expected/es.js rename to test/form/samples/for-in-scopes/_expected.js index a2ad98b8702..38b7769d2c2 100644 --- a/test/form/samples/for-in-scopes/_expected/es.js +++ b/test/form/samples/for-in-scopes/_expected.js @@ -9,4 +9,4 @@ var effect3 = () => console.log( 'effect' ); for ( const foo in { x: effect3() } ) { } -for ( globalVar in { x: 1 } ) {} +for ( globalThis.unknown in { x: 1 } ) {} diff --git a/test/form/samples/for-in-scopes/_expected/amd.js b/test/form/samples/for-in-scopes/_expected/amd.js deleted file mode 100644 index d3dc86884a2..00000000000 --- a/test/form/samples/for-in-scopes/_expected/amd.js +++ /dev/null @@ -1,16 +0,0 @@ -define(function () { 'use strict'; - - var effect1 = () => console.log( 'effect' ); - var associated = () => {}; - for ( var associated in { x: 1 } ) { - associated = effect1; - } - associated(); - - var effect3 = () => console.log( 'effect' ); - for ( const foo in { x: effect3() } ) { - } - - for ( globalVar in { x: 1 } ) {} - -}); diff --git a/test/form/samples/for-in-scopes/_expected/cjs.js b/test/form/samples/for-in-scopes/_expected/cjs.js deleted file mode 100644 index 9d97b8645b2..00000000000 --- a/test/form/samples/for-in-scopes/_expected/cjs.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -var effect1 = () => console.log( 'effect' ); -var associated = () => {}; -for ( var associated in { x: 1 } ) { - associated = effect1; -} -associated(); - -var effect3 = () => console.log( 'effect' ); -for ( const foo in { x: effect3() } ) { -} - -for ( globalVar in { x: 1 } ) {} diff --git a/test/form/samples/for-in-scopes/_expected/iife.js b/test/form/samples/for-in-scopes/_expected/iife.js deleted file mode 100644 index 71677721491..00000000000 --- a/test/form/samples/for-in-scopes/_expected/iife.js +++ /dev/null @@ -1,17 +0,0 @@ -(function () { - 'use strict'; - - var effect1 = () => console.log( 'effect' ); - var associated = () => {}; - for ( var associated in { x: 1 } ) { - associated = effect1; - } - associated(); - - var effect3 = () => console.log( 'effect' ); - for ( const foo in { x: effect3() } ) { - } - - for ( globalVar in { x: 1 } ) {} - -}()); diff --git a/test/form/samples/for-in-scopes/_expected/system.js b/test/form/samples/for-in-scopes/_expected/system.js deleted file mode 100644 index 52f00fe4778..00000000000 --- a/test/form/samples/for-in-scopes/_expected/system.js +++ /dev/null @@ -1,21 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - var effect1 = () => console.log( 'effect' ); - var associated = () => {}; - for ( var associated in { x: 1 } ) { - associated = effect1; - } - associated(); - - var effect3 = () => console.log( 'effect' ); - for ( const foo in { x: effect3() } ) { - } - - for ( globalVar in { x: 1 } ) {} - - } - }; -}); diff --git a/test/form/samples/for-in-scopes/_expected/umd.js b/test/form/samples/for-in-scopes/_expected/umd.js deleted file mode 100644 index a7e1c46a35f..00000000000 --- a/test/form/samples/for-in-scopes/_expected/umd.js +++ /dev/null @@ -1,19 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - var effect1 = () => console.log( 'effect' ); - var associated = () => {}; - for ( var associated in { x: 1 } ) { - associated = effect1; - } - associated(); - - var effect3 = () => console.log( 'effect' ); - for ( const foo in { x: effect3() } ) { - } - - for ( globalVar in { x: 1 } ) {} - -})); diff --git a/test/form/samples/for-in-scopes/main.js b/test/form/samples/for-in-scopes/main.js index eacc2952263..8e528fc2a26 100644 --- a/test/form/samples/for-in-scopes/main.js +++ b/test/form/samples/for-in-scopes/main.js @@ -17,4 +17,4 @@ for ( const foo in { x: effect3() } ) { let effect3 = () => {}; // This can be removed } -for ( globalVar in { x: 1 } ) {} +for ( globalThis.unknown in { x: 1 } ) {} diff --git a/test/form/samples/for-of-scopes/_expected/es.js b/test/form/samples/for-of-scopes/_expected.js similarity index 87% rename from test/form/samples/for-of-scopes/_expected/es.js rename to test/form/samples/for-of-scopes/_expected.js index 52f4227f14d..7a3d255e13a 100644 --- a/test/form/samples/for-of-scopes/_expected/es.js +++ b/test/form/samples/for-of-scopes/_expected.js @@ -8,4 +8,4 @@ for ( const foo of [ effect3 ] ) { foo(); // Must not be removed! } -for ( globalVar of [ 1 ] ) {} +for ( globalThis.unknown of [ 1 ] ) {} diff --git a/test/form/samples/for-of-scopes/_expected/amd.js b/test/form/samples/for-of-scopes/_expected/amd.js deleted file mode 100644 index 95a1e97798a..00000000000 --- a/test/form/samples/for-of-scopes/_expected/amd.js +++ /dev/null @@ -1,15 +0,0 @@ -define(function () { 'use strict'; - - var effect1 = () => console.log( 'effect' ); - var associated = () => {}; - for ( var associated of [ effect1 ] ) {} - associated(); - - var effect3 = () => console.log( 'effect' ); // Must not be removed! - for ( const foo of [ effect3 ] ) { - foo(); // Must not be removed! - } - - for ( globalVar of [ 1 ] ) {} - -}); diff --git a/test/form/samples/for-of-scopes/_expected/cjs.js b/test/form/samples/for-of-scopes/_expected/cjs.js deleted file mode 100644 index 4a723c6f0e8..00000000000 --- a/test/form/samples/for-of-scopes/_expected/cjs.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -var effect1 = () => console.log( 'effect' ); -var associated = () => {}; -for ( var associated of [ effect1 ] ) {} -associated(); - -var effect3 = () => console.log( 'effect' ); // Must not be removed! -for ( const foo of [ effect3 ] ) { - foo(); // Must not be removed! -} - -for ( globalVar of [ 1 ] ) {} diff --git a/test/form/samples/for-of-scopes/_expected/iife.js b/test/form/samples/for-of-scopes/_expected/iife.js deleted file mode 100644 index 8f8d92c8ba2..00000000000 --- a/test/form/samples/for-of-scopes/_expected/iife.js +++ /dev/null @@ -1,16 +0,0 @@ -(function () { - 'use strict'; - - var effect1 = () => console.log( 'effect' ); - var associated = () => {}; - for ( var associated of [ effect1 ] ) {} - associated(); - - var effect3 = () => console.log( 'effect' ); // Must not be removed! - for ( const foo of [ effect3 ] ) { - foo(); // Must not be removed! - } - - for ( globalVar of [ 1 ] ) {} - -}()); diff --git a/test/form/samples/for-of-scopes/_expected/system.js b/test/form/samples/for-of-scopes/_expected/system.js deleted file mode 100644 index 7c11c39d154..00000000000 --- a/test/form/samples/for-of-scopes/_expected/system.js +++ /dev/null @@ -1,20 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - var effect1 = () => console.log( 'effect' ); - var associated = () => {}; - for ( var associated of [ effect1 ] ) {} - associated(); - - var effect3 = () => console.log( 'effect' ); // Must not be removed! - for ( const foo of [ effect3 ] ) { - foo(); // Must not be removed! - } - - for ( globalVar of [ 1 ] ) {} - - } - }; -}); diff --git a/test/form/samples/for-of-scopes/_expected/umd.js b/test/form/samples/for-of-scopes/_expected/umd.js deleted file mode 100644 index e64a9051077..00000000000 --- a/test/form/samples/for-of-scopes/_expected/umd.js +++ /dev/null @@ -1,18 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - var effect1 = () => console.log( 'effect' ); - var associated = () => {}; - for ( var associated of [ effect1 ] ) {} - associated(); - - var effect3 = () => console.log( 'effect' ); // Must not be removed! - for ( const foo of [ effect3 ] ) { - foo(); // Must not be removed! - } - - for ( globalVar of [ 1 ] ) {} - -})); diff --git a/test/form/samples/for-of-scopes/main.js b/test/form/samples/for-of-scopes/main.js index 161f3e39dda..0006ec5197b 100644 --- a/test/form/samples/for-of-scopes/main.js +++ b/test/form/samples/for-of-scopes/main.js @@ -14,4 +14,4 @@ for ( const foo of [ effect3 ] ) { foo(); // Must not be removed! } -for ( globalVar of [ 1 ] ) {} +for ( globalThis.unknown of [ 1 ] ) {} diff --git a/test/form/samples/function-body-return-values/_expected/es.js b/test/form/samples/function-body-return-values/_expected.js similarity index 88% rename from test/form/samples/function-body-return-values/_expected/es.js rename to test/form/samples/function-body-return-values/_expected.js index 43220dda943..0064a3f4c4a 100644 --- a/test/form/samples/function-body-return-values/_expected/es.js +++ b/test/form/samples/function-body-return-values/_expected.js @@ -5,7 +5,7 @@ function retained1 () { retained1()(); function retained2 () { - if ( globalCondition ) { + if ( globalThis.unknown ) { return () => console.log( 'effect' ); } return () => {}; @@ -14,7 +14,7 @@ function retained2 () { retained2()(); function retained3 () { - if ( globalCondition ) { + if ( globalThis.unknown ) { return () => {}; } } diff --git a/test/form/samples/function-body-return-values/_expected/amd.js b/test/form/samples/function-body-return-values/_expected/amd.js deleted file mode 100644 index ec039c4ce51..00000000000 --- a/test/form/samples/function-body-return-values/_expected/amd.js +++ /dev/null @@ -1,42 +0,0 @@ -define(function () { 'use strict'; - - function retained1 () { - return () => console.log( 'effect' ); - } - - retained1()(); - - function retained2 () { - if ( globalCondition ) { - return () => console.log( 'effect' ); - } - return () => {}; - } - - retained2()(); - - function retained3 () { - if ( globalCondition ) { - return () => {}; - } - } - - retained3()(); - - function retained4 () {} - - retained4()(); - - function retained5 () { - return {}; - } - - retained5().x.y = 1; - - function retained6 () { - return { x: () => console.log( 'effect' ) }; - } - - retained6().x(); - -}); diff --git a/test/form/samples/function-body-return-values/_expected/cjs.js b/test/form/samples/function-body-return-values/_expected/cjs.js deleted file mode 100644 index bb29db746fb..00000000000 --- a/test/form/samples/function-body-return-values/_expected/cjs.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -function retained1 () { - return () => console.log( 'effect' ); -} - -retained1()(); - -function retained2 () { - if ( globalCondition ) { - return () => console.log( 'effect' ); - } - return () => {}; -} - -retained2()(); - -function retained3 () { - if ( globalCondition ) { - return () => {}; - } -} - -retained3()(); - -function retained4 () {} - -retained4()(); - -function retained5 () { - return {}; -} - -retained5().x.y = 1; - -function retained6 () { - return { x: () => console.log( 'effect' ) }; -} - -retained6().x(); diff --git a/test/form/samples/function-body-return-values/_expected/iife.js b/test/form/samples/function-body-return-values/_expected/iife.js deleted file mode 100644 index db28c2aa400..00000000000 --- a/test/form/samples/function-body-return-values/_expected/iife.js +++ /dev/null @@ -1,43 +0,0 @@ -(function () { - 'use strict'; - - function retained1 () { - return () => console.log( 'effect' ); - } - - retained1()(); - - function retained2 () { - if ( globalCondition ) { - return () => console.log( 'effect' ); - } - return () => {}; - } - - retained2()(); - - function retained3 () { - if ( globalCondition ) { - return () => {}; - } - } - - retained3()(); - - function retained4 () {} - - retained4()(); - - function retained5 () { - return {}; - } - - retained5().x.y = 1; - - function retained6 () { - return { x: () => console.log( 'effect' ) }; - } - - retained6().x(); - -}()); diff --git a/test/form/samples/function-body-return-values/_expected/system.js b/test/form/samples/function-body-return-values/_expected/system.js deleted file mode 100644 index 02b25682ac7..00000000000 --- a/test/form/samples/function-body-return-values/_expected/system.js +++ /dev/null @@ -1,47 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - function retained1 () { - return () => console.log( 'effect' ); - } - - retained1()(); - - function retained2 () { - if ( globalCondition ) { - return () => console.log( 'effect' ); - } - return () => {}; - } - - retained2()(); - - function retained3 () { - if ( globalCondition ) { - return () => {}; - } - } - - retained3()(); - - function retained4 () {} - - retained4()(); - - function retained5 () { - return {}; - } - - retained5().x.y = 1; - - function retained6 () { - return { x: () => console.log( 'effect' ) }; - } - - retained6().x(); - - } - }; -}); diff --git a/test/form/samples/function-body-return-values/_expected/umd.js b/test/form/samples/function-body-return-values/_expected/umd.js deleted file mode 100644 index 7a116a711aa..00000000000 --- a/test/form/samples/function-body-return-values/_expected/umd.js +++ /dev/null @@ -1,45 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - function retained1 () { - return () => console.log( 'effect' ); - } - - retained1()(); - - function retained2 () { - if ( globalCondition ) { - return () => console.log( 'effect' ); - } - return () => {}; - } - - retained2()(); - - function retained3 () { - if ( globalCondition ) { - return () => {}; - } - } - - retained3()(); - - function retained4 () {} - - retained4()(); - - function retained5 () { - return {}; - } - - retained5().x.y = 1; - - function retained6 () { - return { x: () => console.log( 'effect' ) }; - } - - retained6().x(); - -})); diff --git a/test/form/samples/function-body-return-values/main.js b/test/form/samples/function-body-return-values/main.js index 197b10a41fd..c2351f1bf49 100644 --- a/test/form/samples/function-body-return-values/main.js +++ b/test/form/samples/function-body-return-values/main.js @@ -23,7 +23,7 @@ function retained1 () { retained1()(); function retained2 () { - if ( globalCondition ) { + if ( globalThis.unknown ) { return () => console.log( 'effect' ); } return () => {}; @@ -32,7 +32,7 @@ function retained2 () { retained2()(); function retained3 () { - if ( globalCondition ) { + if ( globalThis.unknown ) { return () => {}; } } diff --git a/test/form/samples/hoisted-variable-case-stmt/_expected.js b/test/form/samples/hoisted-variable-case-stmt/_expected.js index 872b496dacf..c17c6a85527 100644 --- a/test/form/samples/hoisted-variable-case-stmt/_expected.js +++ b/test/form/samples/hoisted-variable-case-stmt/_expected.js @@ -1,4 +1,4 @@ -switch (someGlobal) { +switch (globalThis.unknown) { case 1: var hoisted = true; case 2: diff --git a/test/form/samples/hoisted-variable-case-stmt/main.js b/test/form/samples/hoisted-variable-case-stmt/main.js index 872b496dacf..c17c6a85527 100644 --- a/test/form/samples/hoisted-variable-case-stmt/main.js +++ b/test/form/samples/hoisted-variable-case-stmt/main.js @@ -1,4 +1,4 @@ -switch (someGlobal) { +switch (globalThis.unknown) { case 1: var hoisted = true; case 2: diff --git a/test/form/samples/ignore-property-access-side-effects/_expected/es.js b/test/form/samples/ignore-property-access-side-effects/_expected.js similarity index 100% rename from test/form/samples/ignore-property-access-side-effects/_expected/es.js rename to test/form/samples/ignore-property-access-side-effects/_expected.js diff --git a/test/form/samples/ignore-property-access-side-effects/_expected/amd.js b/test/form/samples/ignore-property-access-side-effects/_expected/amd.js deleted file mode 100644 index f9f8229aa40..00000000000 --- a/test/form/samples/ignore-property-access-side-effects/_expected/amd.js +++ /dev/null @@ -1,5 +0,0 @@ -define(function () { 'use strict'; - - - -}); diff --git a/test/form/samples/ignore-property-access-side-effects/_expected/cjs.js b/test/form/samples/ignore-property-access-side-effects/_expected/cjs.js deleted file mode 100644 index eb109abbed0..00000000000 --- a/test/form/samples/ignore-property-access-side-effects/_expected/cjs.js +++ /dev/null @@ -1,2 +0,0 @@ -'use strict'; - diff --git a/test/form/samples/ignore-property-access-side-effects/_expected/iife.js b/test/form/samples/ignore-property-access-side-effects/_expected/iife.js deleted file mode 100644 index 43ef5426880..00000000000 --- a/test/form/samples/ignore-property-access-side-effects/_expected/iife.js +++ /dev/null @@ -1,6 +0,0 @@ -(function () { - 'use strict'; - - - -}()); diff --git a/test/form/samples/ignore-property-access-side-effects/_expected/system.js b/test/form/samples/ignore-property-access-side-effects/_expected/system.js deleted file mode 100644 index a702f2b06ef..00000000000 --- a/test/form/samples/ignore-property-access-side-effects/_expected/system.js +++ /dev/null @@ -1,10 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - - - } - }; -}); diff --git a/test/form/samples/ignore-property-access-side-effects/_expected/umd.js b/test/form/samples/ignore-property-access-side-effects/_expected/umd.js deleted file mode 100644 index a12a1990f01..00000000000 --- a/test/form/samples/ignore-property-access-side-effects/_expected/umd.js +++ /dev/null @@ -1,8 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - - -})); diff --git a/test/form/samples/ignore-property-access-side-effects/main.js b/test/form/samples/ignore-property-access-side-effects/main.js index 7aa83fb57fb..a501b27ef3f 100644 --- a/test/form/samples/ignore-property-access-side-effects/main.js +++ b/test/form/samples/ignore-property-access-side-effects/main.js @@ -13,4 +13,4 @@ function accessArg(arg) { } accessArg(null); -const foo4 = globalVar.unknownProperty; +const foo4 = globalThis.globalThis.unknown.unknownProperty; diff --git a/test/form/samples/ignore-unknown-global-side-effects/_config.js b/test/form/samples/ignore-unknown-global-side-effects/_config.js new file mode 100644 index 00000000000..08ae295d520 --- /dev/null +++ b/test/form/samples/ignore-unknown-global-side-effects/_config.js @@ -0,0 +1,10 @@ +module.exports = { + description: + 'ignore side-effects when accessing unknown globals if treeshake.unknownGlobalSideEffects is false', + expectedWarnings: ['EMPTY_BUNDLE'], + options: { + treeshake: { + unknownGlobalSideEffects: false + } + } +}; diff --git a/test/form/samples/import-named-exported-global-with-alias/_expected/es.js b/test/form/samples/ignore-unknown-global-side-effects/_expected.js similarity index 100% rename from test/form/samples/import-named-exported-global-with-alias/_expected/es.js rename to test/form/samples/ignore-unknown-global-side-effects/_expected.js diff --git a/test/form/samples/ignore-unknown-global-side-effects/main.js b/test/form/samples/ignore-unknown-global-side-effects/main.js new file mode 100644 index 00000000000..5efa5034a33 --- /dev/null +++ b/test/form/samples/ignore-unknown-global-side-effects/main.js @@ -0,0 +1,2 @@ +foo; +class bar extends baz {} diff --git a/test/form/samples/removes-unused-babel-helpers/_expected/es.js b/test/form/samples/import-named-exported-global-with-alias/_expected.js similarity index 100% rename from test/form/samples/removes-unused-babel-helpers/_expected/es.js rename to test/form/samples/import-named-exported-global-with-alias/_expected.js diff --git a/test/form/samples/import-named-exported-global-with-alias/_expected/amd.js b/test/form/samples/import-named-exported-global-with-alias/_expected/amd.js deleted file mode 100644 index f9f8229aa40..00000000000 --- a/test/form/samples/import-named-exported-global-with-alias/_expected/amd.js +++ /dev/null @@ -1,5 +0,0 @@ -define(function () { 'use strict'; - - - -}); diff --git a/test/form/samples/import-named-exported-global-with-alias/_expected/cjs.js b/test/form/samples/import-named-exported-global-with-alias/_expected/cjs.js deleted file mode 100644 index eb109abbed0..00000000000 --- a/test/form/samples/import-named-exported-global-with-alias/_expected/cjs.js +++ /dev/null @@ -1,2 +0,0 @@ -'use strict'; - diff --git a/test/form/samples/import-named-exported-global-with-alias/_expected/iife.js b/test/form/samples/import-named-exported-global-with-alias/_expected/iife.js deleted file mode 100644 index 43ef5426880..00000000000 --- a/test/form/samples/import-named-exported-global-with-alias/_expected/iife.js +++ /dev/null @@ -1,6 +0,0 @@ -(function () { - 'use strict'; - - - -}()); diff --git a/test/form/samples/import-named-exported-global-with-alias/_expected/system.js b/test/form/samples/import-named-exported-global-with-alias/_expected/system.js deleted file mode 100644 index 1b75f66aa19..00000000000 --- a/test/form/samples/import-named-exported-global-with-alias/_expected/system.js +++ /dev/null @@ -1,10 +0,0 @@ -System.register('doc', [], function () { - 'use strict'; - return { - execute: function () { - - - - } - }; -}); diff --git a/test/form/samples/import-named-exported-global-with-alias/_expected/umd.js b/test/form/samples/import-named-exported-global-with-alias/_expected/umd.js deleted file mode 100644 index a12a1990f01..00000000000 --- a/test/form/samples/import-named-exported-global-with-alias/_expected/umd.js +++ /dev/null @@ -1,8 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - - -})); diff --git a/test/form/samples/import-named-exported-global-with-alias/browser.js b/test/form/samples/import-named-exported-global-with-alias/browser.js index c4404294c94..1810250cf38 100644 --- a/test/form/samples/import-named-exported-global-with-alias/browser.js +++ b/test/form/samples/import-named-exported-global-with-alias/browser.js @@ -1,2 +1,2 @@ -const localDocument = document; +const localDocument = window.document; export { localDocument as document }; diff --git a/test/form/samples/keep-property-access-side-effects/_expected/es.js b/test/form/samples/keep-property-access-side-effects/_expected.js similarity index 81% rename from test/form/samples/keep-property-access-side-effects/_expected/es.js rename to test/form/samples/keep-property-access-side-effects/_expected.js index 7aa83fb57fb..79c0b9bf78d 100644 --- a/test/form/samples/keep-property-access-side-effects/_expected/es.js +++ b/test/form/samples/keep-property-access-side-effects/_expected.js @@ -13,4 +13,4 @@ function accessArg(arg) { } accessArg(null); -const foo4 = globalVar.unknownProperty; +const foo4 = globalThis.unknown.unknownProperty; diff --git a/test/form/samples/keep-property-access-side-effects/_expected/amd.js b/test/form/samples/keep-property-access-side-effects/_expected/amd.js deleted file mode 100644 index cb02ec870b2..00000000000 --- a/test/form/samples/keep-property-access-side-effects/_expected/amd.js +++ /dev/null @@ -1,20 +0,0 @@ -define(function () { 'use strict'; - - const getter = { - get foo () { - console.log( 'effect' ); - } - }; - const foo1 = getter.foo; - - const empty = {}; - const foo2 = empty.foo.tooDeep; - - function accessArg(arg) { - const foo3 = arg.tooDeep; - } - accessArg(null); - - const foo4 = globalVar.unknownProperty; - -}); diff --git a/test/form/samples/keep-property-access-side-effects/_expected/cjs.js b/test/form/samples/keep-property-access-side-effects/_expected/cjs.js deleted file mode 100644 index 2051a6b34c0..00000000000 --- a/test/form/samples/keep-property-access-side-effects/_expected/cjs.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -const getter = { - get foo () { - console.log( 'effect' ); - } -}; -const foo1 = getter.foo; - -const empty = {}; -const foo2 = empty.foo.tooDeep; - -function accessArg(arg) { - const foo3 = arg.tooDeep; -} -accessArg(null); - -const foo4 = globalVar.unknownProperty; diff --git a/test/form/samples/keep-property-access-side-effects/_expected/iife.js b/test/form/samples/keep-property-access-side-effects/_expected/iife.js deleted file mode 100644 index 8270348953d..00000000000 --- a/test/form/samples/keep-property-access-side-effects/_expected/iife.js +++ /dev/null @@ -1,21 +0,0 @@ -(function () { - 'use strict'; - - const getter = { - get foo () { - console.log( 'effect' ); - } - }; - const foo1 = getter.foo; - - const empty = {}; - const foo2 = empty.foo.tooDeep; - - function accessArg(arg) { - const foo3 = arg.tooDeep; - } - accessArg(null); - - const foo4 = globalVar.unknownProperty; - -}()); diff --git a/test/form/samples/keep-property-access-side-effects/_expected/system.js b/test/form/samples/keep-property-access-side-effects/_expected/system.js deleted file mode 100644 index 96a402eb727..00000000000 --- a/test/form/samples/keep-property-access-side-effects/_expected/system.js +++ /dev/null @@ -1,25 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - const getter = { - get foo () { - console.log( 'effect' ); - } - }; - const foo1 = getter.foo; - - const empty = {}; - const foo2 = empty.foo.tooDeep; - - function accessArg(arg) { - const foo3 = arg.tooDeep; - } - accessArg(null); - - const foo4 = globalVar.unknownProperty; - - } - }; -}); diff --git a/test/form/samples/keep-property-access-side-effects/_expected/umd.js b/test/form/samples/keep-property-access-side-effects/_expected/umd.js deleted file mode 100644 index cc59d657d23..00000000000 --- a/test/form/samples/keep-property-access-side-effects/_expected/umd.js +++ /dev/null @@ -1,23 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - const getter = { - get foo () { - console.log( 'effect' ); - } - }; - const foo1 = getter.foo; - - const empty = {}; - const foo2 = empty.foo.tooDeep; - - function accessArg(arg) { - const foo3 = arg.tooDeep; - } - accessArg(null); - - const foo4 = globalVar.unknownProperty; - -})); diff --git a/test/form/samples/keep-property-access-side-effects/main.js b/test/form/samples/keep-property-access-side-effects/main.js index 7aa83fb57fb..79c0b9bf78d 100644 --- a/test/form/samples/keep-property-access-side-effects/main.js +++ b/test/form/samples/keep-property-access-side-effects/main.js @@ -13,4 +13,4 @@ function accessArg(arg) { } accessArg(null); -const foo4 = globalVar.unknownProperty; +const foo4 = globalThis.unknown.unknownProperty; diff --git a/test/form/samples/known-globals/_config.js b/test/form/samples/known-globals/_config.js new file mode 100644 index 00000000000..9811990bbd2 --- /dev/null +++ b/test/form/samples/known-globals/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not consider it a side-effect if a known global variable is accessed' +}; diff --git a/test/form/samples/known-globals/_expected.js b/test/form/samples/known-globals/_expected.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/form/samples/known-globals/_expected.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/form/samples/known-globals/main.js b/test/form/samples/known-globals/main.js new file mode 100644 index 00000000000..01b36b51d3a --- /dev/null +++ b/test/form/samples/known-globals/main.js @@ -0,0 +1,5 @@ +console.log('main'); +const a = setTimeout; +const b = globalThis.setTimeout; +const c = Math.max(1, 2); +const d = globalThis.Math.max(1, 2); diff --git a/test/form/samples/labeled-break-statements/_expected/es.js b/test/form/samples/labeled-break-statements/_expected.js similarity index 87% rename from test/form/samples/labeled-break-statements/_expected/es.js rename to test/form/samples/labeled-break-statements/_expected.js index 38632576137..d56ce86639b 100644 --- a/test/form/samples/labeled-break-statements/_expected/es.js +++ b/test/form/samples/labeled-break-statements/_expected.js @@ -17,8 +17,8 @@ label2: { } label3: - while ( foo ) { - while ( bar ) { + while ( condition ) { + while ( condition ) { if ( condition ) { continue label3; } diff --git a/test/form/samples/labeled-break-statements/_expected/amd.js b/test/form/samples/labeled-break-statements/_expected/amd.js deleted file mode 100644 index 1727a416aee..00000000000 --- a/test/form/samples/labeled-break-statements/_expected/amd.js +++ /dev/null @@ -1,31 +0,0 @@ -define(function () { 'use strict'; - - const condition = Math.random() > 0.5; - - label1: { - if ( condition ) { - break label1; - } - console.log( 'effect' ); - } - - label2: { - while ( condition ) { - if ( condition ) { - break label2; - } - } - console.log( 'effect' ); - } - - label3: - while ( foo ) { - while ( bar ) { - if ( condition ) { - continue label3; - } - } - console.log( 'effect' ); - } - -}); diff --git a/test/form/samples/labeled-break-statements/_expected/cjs.js b/test/form/samples/labeled-break-statements/_expected/cjs.js deleted file mode 100644 index 907217fa304..00000000000 --- a/test/form/samples/labeled-break-statements/_expected/cjs.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -const condition = Math.random() > 0.5; - -label1: { - if ( condition ) { - break label1; - } - console.log( 'effect' ); -} - -label2: { - while ( condition ) { - if ( condition ) { - break label2; - } - } - console.log( 'effect' ); -} - -label3: - while ( foo ) { - while ( bar ) { - if ( condition ) { - continue label3; - } - } - console.log( 'effect' ); - } diff --git a/test/form/samples/labeled-break-statements/_expected/iife.js b/test/form/samples/labeled-break-statements/_expected/iife.js deleted file mode 100644 index bcaccc168fd..00000000000 --- a/test/form/samples/labeled-break-statements/_expected/iife.js +++ /dev/null @@ -1,32 +0,0 @@ -(function () { - 'use strict'; - - const condition = Math.random() > 0.5; - - label1: { - if ( condition ) { - break label1; - } - console.log( 'effect' ); - } - - label2: { - while ( condition ) { - if ( condition ) { - break label2; - } - } - console.log( 'effect' ); - } - - label3: - while ( foo ) { - while ( bar ) { - if ( condition ) { - continue label3; - } - } - console.log( 'effect' ); - } - -}()); diff --git a/test/form/samples/labeled-break-statements/_expected/system.js b/test/form/samples/labeled-break-statements/_expected/system.js deleted file mode 100644 index bf402c28ba8..00000000000 --- a/test/form/samples/labeled-break-statements/_expected/system.js +++ /dev/null @@ -1,36 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - const condition = Math.random() > 0.5; - - label1: { - if ( condition ) { - break label1; - } - console.log( 'effect' ); - } - - label2: { - while ( condition ) { - if ( condition ) { - break label2; - } - } - console.log( 'effect' ); - } - - label3: - while ( foo ) { - while ( bar ) { - if ( condition ) { - continue label3; - } - } - console.log( 'effect' ); - } - - } - }; -}); diff --git a/test/form/samples/labeled-break-statements/_expected/umd.js b/test/form/samples/labeled-break-statements/_expected/umd.js deleted file mode 100644 index 76d6b284270..00000000000 --- a/test/form/samples/labeled-break-statements/_expected/umd.js +++ /dev/null @@ -1,34 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - const condition = Math.random() > 0.5; - - label1: { - if ( condition ) { - break label1; - } - console.log( 'effect' ); - } - - label2: { - while ( condition ) { - if ( condition ) { - break label2; - } - } - console.log( 'effect' ); - } - - label3: - while ( foo ) { - while ( bar ) { - if ( condition ) { - continue label3; - } - } - console.log( 'effect' ); - } - -})); diff --git a/test/form/samples/labeled-break-statements/main.js b/test/form/samples/labeled-break-statements/main.js index 7a53e81847c..e9c093ab833 100644 --- a/test/form/samples/labeled-break-statements/main.js +++ b/test/form/samples/labeled-break-statements/main.js @@ -23,7 +23,7 @@ label2: { } label2NoEffect: { - while ( foo ) { + while ( condition ) { if ( condition ) { break label2NoEffect; } @@ -31,8 +31,8 @@ label2NoEffect: { } label3: - while ( foo ) { - while ( bar ) { + while ( condition ) { + while ( condition ) { if ( condition ) { continue label3; } diff --git a/test/form/samples/nested-member-access/_expected/es.js b/test/form/samples/nested-member-access/_expected.js similarity index 92% rename from test/form/samples/nested-member-access/_expected/es.js rename to test/form/samples/nested-member-access/_expected.js index fb62410e135..efa8afcd2c8 100644 --- a/test/form/samples/nested-member-access/_expected/es.js +++ b/test/form/samples/nested-member-access/_expected.js @@ -20,4 +20,4 @@ const retainedResult6 = retained6.foo.bar; let retained7 = 3; const retainedResult7 = (retained7++).foo.bar; -const retained8 = globalVar.x; +const retained8 = globalThis.unknown .x; diff --git a/test/form/samples/nested-member-access/_expected/amd.js b/test/form/samples/nested-member-access/_expected/amd.js deleted file mode 100644 index e2891a2991c..00000000000 --- a/test/form/samples/nested-member-access/_expected/amd.js +++ /dev/null @@ -1,27 +0,0 @@ -define(function () { 'use strict'; - - const retained1 = {}; - const retainedResult1 = retained1.foo.bar; - - const retained2 = new function () {}(); - const retainedResult2 = retained2.foo.bar; - - const retained3 = void {}; - const retainedResult3 = retained3.foo; - - let retained4a; - const retained4b = retained4a = undefined; - const retainedResult4 = retained4b.foo; - - const retained5 = 1 + 2; - const retainedResult5 = retained5.foo.bar; - - const retained6 = class {}; - const retainedResult6 = retained6.foo.bar; - - let retained7 = 3; - const retainedResult7 = (retained7++).foo.bar; - - const retained8 = globalVar.x; - -}); diff --git a/test/form/samples/nested-member-access/_expected/cjs.js b/test/form/samples/nested-member-access/_expected/cjs.js deleted file mode 100644 index dba1bd55247..00000000000 --- a/test/form/samples/nested-member-access/_expected/cjs.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -const retained1 = {}; -const retainedResult1 = retained1.foo.bar; - -const retained2 = new function () {}(); -const retainedResult2 = retained2.foo.bar; - -const retained3 = void {}; -const retainedResult3 = retained3.foo; - -let retained4a; -const retained4b = retained4a = undefined; -const retainedResult4 = retained4b.foo; - -const retained5 = 1 + 2; -const retainedResult5 = retained5.foo.bar; - -const retained6 = class {}; -const retainedResult6 = retained6.foo.bar; - -let retained7 = 3; -const retainedResult7 = (retained7++).foo.bar; - -const retained8 = globalVar.x; diff --git a/test/form/samples/nested-member-access/_expected/iife.js b/test/form/samples/nested-member-access/_expected/iife.js deleted file mode 100644 index 340e3bb0cbb..00000000000 --- a/test/form/samples/nested-member-access/_expected/iife.js +++ /dev/null @@ -1,28 +0,0 @@ -(function () { - 'use strict'; - - const retained1 = {}; - const retainedResult1 = retained1.foo.bar; - - const retained2 = new function () {}(); - const retainedResult2 = retained2.foo.bar; - - const retained3 = void {}; - const retainedResult3 = retained3.foo; - - let retained4a; - const retained4b = retained4a = undefined; - const retainedResult4 = retained4b.foo; - - const retained5 = 1 + 2; - const retainedResult5 = retained5.foo.bar; - - const retained6 = class {}; - const retainedResult6 = retained6.foo.bar; - - let retained7 = 3; - const retainedResult7 = (retained7++).foo.bar; - - const retained8 = globalVar.x; - -}()); diff --git a/test/form/samples/nested-member-access/_expected/system.js b/test/form/samples/nested-member-access/_expected/system.js deleted file mode 100644 index 128aa4eaf6c..00000000000 --- a/test/form/samples/nested-member-access/_expected/system.js +++ /dev/null @@ -1,32 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - const retained1 = {}; - const retainedResult1 = retained1.foo.bar; - - const retained2 = new function () {}(); - const retainedResult2 = retained2.foo.bar; - - const retained3 = void {}; - const retainedResult3 = retained3.foo; - - let retained4a; - const retained4b = retained4a = undefined; - const retainedResult4 = retained4b.foo; - - const retained5 = 1 + 2; - const retainedResult5 = retained5.foo.bar; - - const retained6 = class {}; - const retainedResult6 = retained6.foo.bar; - - let retained7 = 3; - const retainedResult7 = (retained7++).foo.bar; - - const retained8 = globalVar.x; - - } - }; -}); diff --git a/test/form/samples/nested-member-access/_expected/umd.js b/test/form/samples/nested-member-access/_expected/umd.js deleted file mode 100644 index 145dd33b8e0..00000000000 --- a/test/form/samples/nested-member-access/_expected/umd.js +++ /dev/null @@ -1,30 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - const retained1 = {}; - const retainedResult1 = retained1.foo.bar; - - const retained2 = new function () {}(); - const retainedResult2 = retained2.foo.bar; - - const retained3 = void {}; - const retainedResult3 = retained3.foo; - - let retained4a; - const retained4b = retained4a = undefined; - const retainedResult4 = retained4b.foo; - - const retained5 = 1 + 2; - const retainedResult5 = retained5.foo.bar; - - const retained6 = class {}; - const retainedResult6 = retained6.foo.bar; - - let retained7 = 3; - const retainedResult7 = (retained7++).foo.bar; - - const retained8 = globalVar.x; - -})); diff --git a/test/form/samples/nested-member-access/main.js b/test/form/samples/nested-member-access/main.js index 0b4418d3c1b..8b42d3c5ad3 100644 --- a/test/form/samples/nested-member-access/main.js +++ b/test/form/samples/nested-member-access/main.js @@ -45,4 +45,4 @@ const retainedResult6 = retained6.foo.bar; let retained7 = 3; const retainedResult7 = (retained7++).foo.bar; -const retained8 = globalVar.x; +const retained8 = globalThis.unknown .x; diff --git a/test/form/samples/nested-this-expressions/_expected/es.js b/test/form/samples/nested-this-expressions/_expected.js similarity index 85% rename from test/form/samples/nested-this-expressions/_expected/es.js rename to test/form/samples/nested-this-expressions/_expected.js index 10211b9472d..dde2c6a71ef 100644 --- a/test/form/samples/nested-this-expressions/_expected/es.js +++ b/test/form/samples/nested-this-expressions/_expected.js @@ -10,7 +10,7 @@ function mutateNestedThis () { mutateNestedThis(); function mutateThisConditionally () { - if ( globalCondition ) { + if ( globalThis.condition ) { this.baz = 1; } } @@ -18,7 +18,7 @@ mutateThisConditionally(); function CallSelfWithoutNew () { this.quux = 1; - if ( globalCondition ) { + if ( globalThis.condition ) { CallSelfWithoutNew(); } } diff --git a/test/form/samples/nested-this-expressions/_expected/amd.js b/test/form/samples/nested-this-expressions/_expected/amd.js deleted file mode 100644 index d76580245b4..00000000000 --- a/test/form/samples/nested-this-expressions/_expected/amd.js +++ /dev/null @@ -1,29 +0,0 @@ -define(function () { 'use strict'; - - function mutateThis () { - this.x = 1; - } - mutateThis(); - - function mutateNestedThis () { - const mutateNested = () => this.bar = 1; - mutateNested(); - } - mutateNestedThis(); - - function mutateThisConditionally () { - if ( globalCondition ) { - this.baz = 1; - } - } - mutateThisConditionally(); - - function CallSelfWithoutNew () { - this.quux = 1; - if ( globalCondition ) { - CallSelfWithoutNew(); - } - } - const c = new CallSelfWithoutNew(); - -}); diff --git a/test/form/samples/nested-this-expressions/_expected/cjs.js b/test/form/samples/nested-this-expressions/_expected/cjs.js deleted file mode 100644 index bdaa0616e61..00000000000 --- a/test/form/samples/nested-this-expressions/_expected/cjs.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -function mutateThis () { - this.x = 1; -} -mutateThis(); - -function mutateNestedThis () { - const mutateNested = () => this.bar = 1; - mutateNested(); -} -mutateNestedThis(); - -function mutateThisConditionally () { - if ( globalCondition ) { - this.baz = 1; - } -} -mutateThisConditionally(); - -function CallSelfWithoutNew () { - this.quux = 1; - if ( globalCondition ) { - CallSelfWithoutNew(); - } -} -const c = new CallSelfWithoutNew(); diff --git a/test/form/samples/nested-this-expressions/_expected/iife.js b/test/form/samples/nested-this-expressions/_expected/iife.js deleted file mode 100644 index bb15739d2b7..00000000000 --- a/test/form/samples/nested-this-expressions/_expected/iife.js +++ /dev/null @@ -1,30 +0,0 @@ -(function () { - 'use strict'; - - function mutateThis () { - this.x = 1; - } - mutateThis(); - - function mutateNestedThis () { - const mutateNested = () => this.bar = 1; - mutateNested(); - } - mutateNestedThis(); - - function mutateThisConditionally () { - if ( globalCondition ) { - this.baz = 1; - } - } - mutateThisConditionally(); - - function CallSelfWithoutNew () { - this.quux = 1; - if ( globalCondition ) { - CallSelfWithoutNew(); - } - } - const c = new CallSelfWithoutNew(); - -}()); diff --git a/test/form/samples/nested-this-expressions/_expected/system.js b/test/form/samples/nested-this-expressions/_expected/system.js deleted file mode 100644 index 39035c4ad15..00000000000 --- a/test/form/samples/nested-this-expressions/_expected/system.js +++ /dev/null @@ -1,34 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - function mutateThis () { - this.x = 1; - } - mutateThis(); - - function mutateNestedThis () { - const mutateNested = () => this.bar = 1; - mutateNested(); - } - mutateNestedThis(); - - function mutateThisConditionally () { - if ( globalCondition ) { - this.baz = 1; - } - } - mutateThisConditionally(); - - function CallSelfWithoutNew () { - this.quux = 1; - if ( globalCondition ) { - CallSelfWithoutNew(); - } - } - const c = new CallSelfWithoutNew(); - - } - }; -}); diff --git a/test/form/samples/nested-this-expressions/_expected/umd.js b/test/form/samples/nested-this-expressions/_expected/umd.js deleted file mode 100644 index 0abe56dcd41..00000000000 --- a/test/form/samples/nested-this-expressions/_expected/umd.js +++ /dev/null @@ -1,32 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - function mutateThis () { - this.x = 1; - } - mutateThis(); - - function mutateNestedThis () { - const mutateNested = () => this.bar = 1; - mutateNested(); - } - mutateNestedThis(); - - function mutateThisConditionally () { - if ( globalCondition ) { - this.baz = 1; - } - } - mutateThisConditionally(); - - function CallSelfWithoutNew () { - this.quux = 1; - if ( globalCondition ) { - CallSelfWithoutNew(); - } - } - const c = new CallSelfWithoutNew(); - -})); diff --git a/test/form/samples/nested-this-expressions/main.js b/test/form/samples/nested-this-expressions/main.js index 35ef4bfdbe8..ef39c339c5a 100644 --- a/test/form/samples/nested-this-expressions/main.js +++ b/test/form/samples/nested-this-expressions/main.js @@ -4,7 +4,7 @@ function NoEffectsDeclaration () { const mutateNested = () => this.bar = 1; mutateNested(); - if ( globalCondition ) { + if ( globalThis.condition ) { this.baz = 1; } } @@ -16,7 +16,7 @@ const NoEffectsExpression = function () { const mutateNested = () => this.bar = 1; mutateNested(); - if ( globalCondition ) { + if ( globalThis.condition ) { this.baz = 1; } }; @@ -34,7 +34,7 @@ function mutateNestedThis () { mutateNestedThis(); function mutateThisConditionally () { - if ( globalCondition ) { + if ( globalThis.condition ) { this.baz = 1; } } @@ -42,7 +42,7 @@ mutateThisConditionally(); function CallSelfWithoutNew () { this.quux = 1; - if ( globalCondition ) { + if ( globalThis.condition ) { CallSelfWithoutNew(); } } diff --git a/test/form/samples/nested-tree-shaking/_expected/es.js b/test/form/samples/nested-tree-shaking/_expected.js similarity index 75% rename from test/form/samples/nested-tree-shaking/_expected/es.js rename to test/form/samples/nested-tree-shaking/_expected.js index 8fc8f1a9092..0c742f0ab14 100644 --- a/test/form/samples/nested-tree-shaking/_expected/es.js +++ b/test/form/samples/nested-tree-shaking/_expected.js @@ -2,7 +2,7 @@ function withEffects() { console.log('effect'); } -if (globalVar > 0) { +if (globalThis.unknown > 0) { console.log('effect'); withEffects(); } diff --git a/test/form/samples/nested-tree-shaking/_expected/amd.js b/test/form/samples/nested-tree-shaking/_expected/amd.js deleted file mode 100644 index 17efd3c8617..00000000000 --- a/test/form/samples/nested-tree-shaking/_expected/amd.js +++ /dev/null @@ -1,12 +0,0 @@ -define(function () { 'use strict'; - - function withEffects() { - console.log('effect'); - } - - if (globalVar > 0) { - console.log('effect'); - withEffects(); - } - -}); diff --git a/test/form/samples/nested-tree-shaking/_expected/cjs.js b/test/form/samples/nested-tree-shaking/_expected/cjs.js deleted file mode 100644 index d971429603d..00000000000 --- a/test/form/samples/nested-tree-shaking/_expected/cjs.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -function withEffects() { - console.log('effect'); -} - -if (globalVar > 0) { - console.log('effect'); - withEffects(); -} diff --git a/test/form/samples/nested-tree-shaking/_expected/iife.js b/test/form/samples/nested-tree-shaking/_expected/iife.js deleted file mode 100644 index fab6b7fcb5e..00000000000 --- a/test/form/samples/nested-tree-shaking/_expected/iife.js +++ /dev/null @@ -1,13 +0,0 @@ -(function () { - 'use strict'; - - function withEffects() { - console.log('effect'); - } - - if (globalVar > 0) { - console.log('effect'); - withEffects(); - } - -}()); diff --git a/test/form/samples/nested-tree-shaking/_expected/system.js b/test/form/samples/nested-tree-shaking/_expected/system.js deleted file mode 100644 index 43b7708400e..00000000000 --- a/test/form/samples/nested-tree-shaking/_expected/system.js +++ /dev/null @@ -1,17 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - function withEffects() { - console.log('effect'); - } - - if (globalVar > 0) { - console.log('effect'); - withEffects(); - } - - } - }; -}); diff --git a/test/form/samples/nested-tree-shaking/_expected/umd.js b/test/form/samples/nested-tree-shaking/_expected/umd.js deleted file mode 100644 index e4de26fc806..00000000000 --- a/test/form/samples/nested-tree-shaking/_expected/umd.js +++ /dev/null @@ -1,15 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - function withEffects() { - console.log('effect'); - } - - if (globalVar > 0) { - console.log('effect'); - withEffects(); - } - -})); diff --git a/test/form/samples/nested-tree-shaking/main.js b/test/form/samples/nested-tree-shaking/main.js index 011c8736e6b..b54b9055c16 100644 --- a/test/form/samples/nested-tree-shaking/main.js +++ b/test/form/samples/nested-tree-shaking/main.js @@ -1,10 +1,10 @@ import {noEffects, withEffects} from './foo.js'; -if (globalVar > 0) { +if (globalThis.unknown > 0) { noEffects(); } -if (globalVar > 0) { +if (globalThis.unknown > 0) { console.log('effect'); noEffects(); withEffects(); diff --git a/test/form/samples/object-expression/method-side-effects/_expected.js b/test/form/samples/object-expression/method-side-effects/_expected.js index 85a79176f16..b95ee292ad0 100644 --- a/test/form/samples/object-expression/method-side-effects/_expected.js +++ b/test/form/samples/object-expression/method-side-effects/_expected.js @@ -1,6 +1,6 @@ const y = { a() {}, - [unknown]() { + [globalThis.unknown]() { console.log('effect'); } }; @@ -8,7 +8,7 @@ const y = { y.a(); const z = { - [unknown]() {} + [globalThis.unknown]() {} }; z.a(); diff --git a/test/form/samples/object-expression/method-side-effects/main.js b/test/form/samples/object-expression/method-side-effects/main.js index deac99fa6ef..d40ea5a9315 100644 --- a/test/form/samples/object-expression/method-side-effects/main.js +++ b/test/form/samples/object-expression/method-side-effects/main.js @@ -1,5 +1,5 @@ const x = { - [unknown]() { + [globalThis.unknown]() { console.log('effect'); }, a() {} @@ -9,7 +9,7 @@ x.a(); const y = { a() {}, - [unknown]() { + [globalThis.unknown]() { console.log('effect'); } }; @@ -17,7 +17,7 @@ const y = { y.a(); const z = { - [unknown]() {} + [globalThis.unknown]() {} }; z.a(); diff --git a/test/form/samples/object-expression/return-expressions/_expected.js b/test/form/samples/object-expression/return-expressions/_expected.js index 93d8f71bb09..3538f6d9b82 100644 --- a/test/form/samples/object-expression/return-expressions/_expected.js +++ b/test/form/samples/object-expression/return-expressions/_expected.js @@ -1,12 +1,12 @@ const y = { a: () => () => {}, - [unknown]: () => () => console.log('effect') + [globalThis.unknown]: () => () => console.log('effect') }; y.a()(); const z = { - [unknown]: () => ({}) + [globalThis.unknown]: () => ({}) }; z.a()(); diff --git a/test/form/samples/object-expression/return-expressions/main.js b/test/form/samples/object-expression/return-expressions/main.js index 225e7edde17..9565727abf5 100644 --- a/test/form/samples/object-expression/return-expressions/main.js +++ b/test/form/samples/object-expression/return-expressions/main.js @@ -1,5 +1,5 @@ const x = { - [unknown]: () => () => console.log('effect'), + [globalThis.unknown]: () => () => console.log('effect'), a: () => () => {} }; @@ -7,13 +7,13 @@ x.a()(); const y = { a: () => () => {}, - [unknown]: () => () => console.log('effect') + [globalThis.unknown]: () => () => console.log('effect') }; y.a()(); const z = { - [unknown]: () => ({}) + [globalThis.unknown]: () => ({}) }; z.a()(); diff --git a/test/form/samples/object-literal-property-overwrites/_expected/cjs.js b/test/form/samples/object-literal-property-overwrites/_expected.js similarity index 89% rename from test/form/samples/object-literal-property-overwrites/_expected/cjs.js rename to test/form/samples/object-literal-property-overwrites/_expected.js index 6d7143c492a..ecd783e1d52 100644 --- a/test/form/samples/object-literal-property-overwrites/_expected/cjs.js +++ b/test/form/samples/object-literal-property-overwrites/_expected.js @@ -1,5 +1,3 @@ -'use strict'; - const retained1 = { foo: () => {}, foo: function () {this.x = 1;} @@ -21,13 +19,13 @@ retained3.bar(); const retained4 = { foo: {}, - foo: globalVar + foo: globalThis.unknown }; retained4.foo.bar = 1; const retained5 = { foo: {}, - ['f' + 'oo']: globalVar, + ['f' + 'oo']: globalThis.unknown, ['b' + 'ar']: {}, }; retained5.foo.bar = 1; diff --git a/test/form/samples/object-literal-property-overwrites/_expected/amd.js b/test/form/samples/object-literal-property-overwrites/_expected/amd.js deleted file mode 100644 index 0270ef5deaa..00000000000 --- a/test/form/samples/object-literal-property-overwrites/_expected/amd.js +++ /dev/null @@ -1,41 +0,0 @@ -define(function () { 'use strict'; - - const retained1 = { - foo: () => {}, - foo: function () {this.x = 1;} - }; - retained1.foo(); - - const retained2 = { - foo: () => {}, - ['f' + 'oo']: function () {this.x = 1;}, - ['b' + 'ar']: () => {} - }; - retained2.foo(); - - const retained3 = { - ['fo' + 'o']: () => {}, - ['f' + 'oo']: () => {} - }; - retained3.bar(); - - const retained4 = { - foo: {}, - foo: globalVar - }; - retained4.foo.bar = 1; - - const retained5 = { - foo: {}, - ['f' + 'oo']: globalVar, - ['b' + 'ar']: {}, - }; - retained5.foo.bar = 1; - - const retained6 = { - ['fo' + 'o']: {}, - ['f' + 'oo']: {} - }; - retained6.bar.baz = 1; - -}); diff --git a/test/form/samples/object-literal-property-overwrites/_expected/es.js b/test/form/samples/object-literal-property-overwrites/_expected/es.js deleted file mode 100644 index 205a9baf9cf..00000000000 --- a/test/form/samples/object-literal-property-overwrites/_expected/es.js +++ /dev/null @@ -1,37 +0,0 @@ -const retained1 = { - foo: () => {}, - foo: function () {this.x = 1;} -}; -retained1.foo(); - -const retained2 = { - foo: () => {}, - ['f' + 'oo']: function () {this.x = 1;}, - ['b' + 'ar']: () => {} -}; -retained2.foo(); - -const retained3 = { - ['fo' + 'o']: () => {}, - ['f' + 'oo']: () => {} -}; -retained3.bar(); - -const retained4 = { - foo: {}, - foo: globalVar -}; -retained4.foo.bar = 1; - -const retained5 = { - foo: {}, - ['f' + 'oo']: globalVar, - ['b' + 'ar']: {}, -}; -retained5.foo.bar = 1; - -const retained6 = { - ['fo' + 'o']: {}, - ['f' + 'oo']: {} -}; -retained6.bar.baz = 1; diff --git a/test/form/samples/object-literal-property-overwrites/_expected/iife.js b/test/form/samples/object-literal-property-overwrites/_expected/iife.js deleted file mode 100644 index 2758c9ed398..00000000000 --- a/test/form/samples/object-literal-property-overwrites/_expected/iife.js +++ /dev/null @@ -1,42 +0,0 @@ -(function () { - 'use strict'; - - const retained1 = { - foo: () => {}, - foo: function () {this.x = 1;} - }; - retained1.foo(); - - const retained2 = { - foo: () => {}, - ['f' + 'oo']: function () {this.x = 1;}, - ['b' + 'ar']: () => {} - }; - retained2.foo(); - - const retained3 = { - ['fo' + 'o']: () => {}, - ['f' + 'oo']: () => {} - }; - retained3.bar(); - - const retained4 = { - foo: {}, - foo: globalVar - }; - retained4.foo.bar = 1; - - const retained5 = { - foo: {}, - ['f' + 'oo']: globalVar, - ['b' + 'ar']: {}, - }; - retained5.foo.bar = 1; - - const retained6 = { - ['fo' + 'o']: {}, - ['f' + 'oo']: {} - }; - retained6.bar.baz = 1; - -}()); diff --git a/test/form/samples/object-literal-property-overwrites/_expected/system.js b/test/form/samples/object-literal-property-overwrites/_expected/system.js deleted file mode 100644 index 6c6aca94483..00000000000 --- a/test/form/samples/object-literal-property-overwrites/_expected/system.js +++ /dev/null @@ -1,46 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - const retained1 = { - foo: () => {}, - foo: function () {this.x = 1;} - }; - retained1.foo(); - - const retained2 = { - foo: () => {}, - ['f' + 'oo']: function () {this.x = 1;}, - ['b' + 'ar']: () => {} - }; - retained2.foo(); - - const retained3 = { - ['fo' + 'o']: () => {}, - ['f' + 'oo']: () => {} - }; - retained3.bar(); - - const retained4 = { - foo: {}, - foo: globalVar - }; - retained4.foo.bar = 1; - - const retained5 = { - foo: {}, - ['f' + 'oo']: globalVar, - ['b' + 'ar']: {}, - }; - retained5.foo.bar = 1; - - const retained6 = { - ['fo' + 'o']: {}, - ['f' + 'oo']: {} - }; - retained6.bar.baz = 1; - - } - }; -}); diff --git a/test/form/samples/object-literal-property-overwrites/_expected/umd.js b/test/form/samples/object-literal-property-overwrites/_expected/umd.js deleted file mode 100644 index 61142209b9d..00000000000 --- a/test/form/samples/object-literal-property-overwrites/_expected/umd.js +++ /dev/null @@ -1,44 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - const retained1 = { - foo: () => {}, - foo: function () {this.x = 1;} - }; - retained1.foo(); - - const retained2 = { - foo: () => {}, - ['f' + 'oo']: function () {this.x = 1;}, - ['b' + 'ar']: () => {} - }; - retained2.foo(); - - const retained3 = { - ['fo' + 'o']: () => {}, - ['f' + 'oo']: () => {} - }; - retained3.bar(); - - const retained4 = { - foo: {}, - foo: globalVar - }; - retained4.foo.bar = 1; - - const retained5 = { - foo: {}, - ['f' + 'oo']: globalVar, - ['b' + 'ar']: {}, - }; - retained5.foo.bar = 1; - - const retained6 = { - ['fo' + 'o']: {}, - ['f' + 'oo']: {} - }; - retained6.bar.baz = 1; - -})); diff --git a/test/form/samples/object-literal-property-overwrites/main.js b/test/form/samples/object-literal-property-overwrites/main.js index fa1b06e1cc4..81a72b541ea 100644 --- a/test/form/samples/object-literal-property-overwrites/main.js +++ b/test/form/samples/object-literal-property-overwrites/main.js @@ -26,14 +26,14 @@ const removed4 = { removed4.foo.bar = 1; const removed5 = { - foo: globalVar, + foo: globalThis.unknown, foo: () => {} }; removed5.foo.bar = 1; const removed6 = { - ['f' + 'oo']: globalVar, - ['fo' + 'o']: globalVar, + ['f' + 'oo']: globalThis.unknown, + ['fo' + 'o']: globalThis.unknown, foo: () => {} }; removed6.foo.bar = 1; @@ -59,13 +59,13 @@ retained3.bar(); const retained4 = { foo: {}, - foo: globalVar + foo: globalThis.unknown }; retained4.foo.bar = 1; const retained5 = { foo: {}, - ['f' + 'oo']: globalVar, + ['f' + 'oo']: globalThis.unknown, ['b' + 'ar']: {}, }; retained5.foo.bar = 1; diff --git a/test/form/samples/pattern-member-expressions/_expected/cjs.js b/test/form/samples/pattern-member-expressions/_expected.js similarity index 76% rename from test/form/samples/pattern-member-expressions/_expected/cjs.js rename to test/form/samples/pattern-member-expressions/_expected.js index cc195f4e43d..48cdcd4a811 100644 --- a/test/form/samples/pattern-member-expressions/_expected/cjs.js +++ b/test/form/samples/pattern-member-expressions/_expected.js @@ -1,12 +1,10 @@ -'use strict'; - const array = [false]; const obj1 = {value: false}; const obj2 = {value: false}; ([array[0]] = [true]); ({a: obj1.value} = {a: true}); -({[globalVar1]: obj2[globalVar2]} = {[globalVar3]: true}); +({[globalThis.unknown1]: obj2[globalThis.unknown2]} = {[globalThis.unknown3]: true}); if (array[0]) { console.log('retained'); diff --git a/test/form/samples/pattern-member-expressions/_expected/amd.js b/test/form/samples/pattern-member-expressions/_expected/amd.js deleted file mode 100644 index 79926d37cc2..00000000000 --- a/test/form/samples/pattern-member-expressions/_expected/amd.js +++ /dev/null @@ -1,23 +0,0 @@ -define(function () { 'use strict'; - - const array = [false]; - const obj1 = {value: false}; - const obj2 = {value: false}; - - ([array[0]] = [true]); - ({a: obj1.value} = {a: true}); - ({[globalVar1]: obj2[globalVar2]} = {[globalVar3]: true}); - - if (array[0]) { - console.log('retained'); - } - - if (obj1.value) { - console.log('retained'); - } - - if (obj2.value) { - console.log('retained'); - } - -}); diff --git a/test/form/samples/pattern-member-expressions/_expected/es.js b/test/form/samples/pattern-member-expressions/_expected/es.js deleted file mode 100644 index b39488c0d71..00000000000 --- a/test/form/samples/pattern-member-expressions/_expected/es.js +++ /dev/null @@ -1,19 +0,0 @@ -const array = [false]; -const obj1 = {value: false}; -const obj2 = {value: false}; - -([array[0]] = [true]); -({a: obj1.value} = {a: true}); -({[globalVar1]: obj2[globalVar2]} = {[globalVar3]: true}); - -if (array[0]) { - console.log('retained'); -} - -if (obj1.value) { - console.log('retained'); -} - -if (obj2.value) { - console.log('retained'); -} diff --git a/test/form/samples/pattern-member-expressions/_expected/iife.js b/test/form/samples/pattern-member-expressions/_expected/iife.js deleted file mode 100644 index 6e33e092356..00000000000 --- a/test/form/samples/pattern-member-expressions/_expected/iife.js +++ /dev/null @@ -1,24 +0,0 @@ -(function () { - 'use strict'; - - const array = [false]; - const obj1 = {value: false}; - const obj2 = {value: false}; - - ([array[0]] = [true]); - ({a: obj1.value} = {a: true}); - ({[globalVar1]: obj2[globalVar2]} = {[globalVar3]: true}); - - if (array[0]) { - console.log('retained'); - } - - if (obj1.value) { - console.log('retained'); - } - - if (obj2.value) { - console.log('retained'); - } - -}()); diff --git a/test/form/samples/pattern-member-expressions/_expected/system.js b/test/form/samples/pattern-member-expressions/_expected/system.js deleted file mode 100644 index a7a3b1fef94..00000000000 --- a/test/form/samples/pattern-member-expressions/_expected/system.js +++ /dev/null @@ -1,28 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - const array = [false]; - const obj1 = {value: false}; - const obj2 = {value: false}; - - ([array[0]] = [true]); - ({a: obj1.value} = {a: true}); - ({[globalVar1]: obj2[globalVar2]} = {[globalVar3]: true}); - - if (array[0]) { - console.log('retained'); - } - - if (obj1.value) { - console.log('retained'); - } - - if (obj2.value) { - console.log('retained'); - } - - } - }; -}); diff --git a/test/form/samples/pattern-member-expressions/_expected/umd.js b/test/form/samples/pattern-member-expressions/_expected/umd.js deleted file mode 100644 index a56a2604097..00000000000 --- a/test/form/samples/pattern-member-expressions/_expected/umd.js +++ /dev/null @@ -1,26 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - const array = [false]; - const obj1 = {value: false}; - const obj2 = {value: false}; - - ([array[0]] = [true]); - ({a: obj1.value} = {a: true}); - ({[globalVar1]: obj2[globalVar2]} = {[globalVar3]: true}); - - if (array[0]) { - console.log('retained'); - } - - if (obj1.value) { - console.log('retained'); - } - - if (obj2.value) { - console.log('retained'); - } - -})); diff --git a/test/form/samples/pattern-member-expressions/main.js b/test/form/samples/pattern-member-expressions/main.js index b39488c0d71..48cdcd4a811 100644 --- a/test/form/samples/pattern-member-expressions/main.js +++ b/test/form/samples/pattern-member-expressions/main.js @@ -4,7 +4,7 @@ const obj2 = {value: false}; ([array[0]] = [true]); ({a: obj1.value} = {a: true}); -({[globalVar1]: obj2[globalVar2]} = {[globalVar3]: true}); +({[globalThis.unknown1]: obj2[globalThis.unknown2]} = {[globalThis.unknown3]: true}); if (array[0]) { console.log('retained'); diff --git a/test/form/samples/pure-comment-scenarios-complex/main.js b/test/form/samples/pure-comment-scenarios-complex/main.js index e2260078450..6c49311118b 100644 --- a/test/form/samples/pure-comment-scenarios-complex/main.js +++ b/test/form/samples/pure-comment-scenarios-complex/main.js @@ -34,6 +34,7 @@ bar(); bar(), baz(), quux(); a.b(), /* @__PURE__ */ c.d.e(), f.g(); +var x, y; /* @__PURE__ */(function(){x})(), void/* @__PURE__ */(function(){y})(); /* @__PURE__ */(function(){x})() || true ? foo() : bar(); true || /* @__PURE__ */(function(){y})() ? foo() : bar(); diff --git a/test/form/samples/recursive-calls/_expected.js b/test/form/samples/recursive-calls/_expected.js new file mode 100644 index 00000000000..b5e78683edd --- /dev/null +++ b/test/form/samples/recursive-calls/_expected.js @@ -0,0 +1,39 @@ +const retained1 = () => globalThis.unknown ? retained1() : console.log( 'effect' ); +retained1(); + +const retained2 = () => globalThis.unknown ? () => retained2()() : () => console.log( 'effect' ); +retained2()(); + +const retained3 = () => globalThis.unknown ? retained3() : {}; +retained3().x.y = 3; + +const retained4 = () => globalThis.unknown ? retained4() : { x: () => console.log( 'effect' ) }; +retained4().x(); + +const retained5 = { + get x () { + return globalThis.unknown ? retained5.x : console.log( 'effect' ); + } +}; +retained5.x; + +const retained6 = { + get x () { + return globalThis.unknown ? retained6.x : () => console.log( 'effect' ); + } +}; +retained6.x(); + +const retained7 = { + get x () { + return globalThis.unknown ? retained7.x : {}; + } +}; +retained7.x.y.z = 7; + +const retained8 = { + get x () { + return globalThis.unknown ? retained8.x : { y: () => console.log( 'effect' ) }; + } +}; +retained8.x.y(); diff --git a/test/form/samples/recursive-calls/_expected/amd.js b/test/form/samples/recursive-calls/_expected/amd.js deleted file mode 100644 index b0c545e2a2a..00000000000 --- a/test/form/samples/recursive-calls/_expected/amd.js +++ /dev/null @@ -1,43 +0,0 @@ -define(function () { 'use strict'; - - const retained1 = () => globalVar ? retained1() : console.log( 'effect' ); - retained1(); - - const retained2 = () => globalVar ? () => retained2()() : () => console.log( 'effect' ); - retained2()(); - - const retained3 = () => globalVar ? retained3() : {}; - retained3().x.y = 3; - - const retained4 = () => globalVar ? retained4() : { x: () => console.log( 'effect' ) }; - retained4().x(); - - const retained5 = { - get x () { - return globalVar ? retained5.x : console.log( 'effect' ); - } - }; - retained5.x; - - const retained6 = { - get x () { - return globalVar ? retained6.x : () => console.log( 'effect' ); - } - }; - retained6.x(); - - const retained7 = { - get x () { - return globalVar ? retained7.x : {}; - } - }; - retained7.x.y.z = 7; - - const retained8 = { - get x () { - return globalVar ? retained8.x : { y: () => console.log( 'effect' ) }; - } - }; - retained8.x.y(); - -}); diff --git a/test/form/samples/recursive-calls/_expected/cjs.js b/test/form/samples/recursive-calls/_expected/cjs.js deleted file mode 100644 index 928df1ebb04..00000000000 --- a/test/form/samples/recursive-calls/_expected/cjs.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -const retained1 = () => globalVar ? retained1() : console.log( 'effect' ); -retained1(); - -const retained2 = () => globalVar ? () => retained2()() : () => console.log( 'effect' ); -retained2()(); - -const retained3 = () => globalVar ? retained3() : {}; -retained3().x.y = 3; - -const retained4 = () => globalVar ? retained4() : { x: () => console.log( 'effect' ) }; -retained4().x(); - -const retained5 = { - get x () { - return globalVar ? retained5.x : console.log( 'effect' ); - } -}; -retained5.x; - -const retained6 = { - get x () { - return globalVar ? retained6.x : () => console.log( 'effect' ); - } -}; -retained6.x(); - -const retained7 = { - get x () { - return globalVar ? retained7.x : {}; - } -}; -retained7.x.y.z = 7; - -const retained8 = { - get x () { - return globalVar ? retained8.x : { y: () => console.log( 'effect' ) }; - } -}; -retained8.x.y(); diff --git a/test/form/samples/recursive-calls/_expected/es.js b/test/form/samples/recursive-calls/_expected/es.js deleted file mode 100644 index 55529c36ed6..00000000000 --- a/test/form/samples/recursive-calls/_expected/es.js +++ /dev/null @@ -1,39 +0,0 @@ -const retained1 = () => globalVar ? retained1() : console.log( 'effect' ); -retained1(); - -const retained2 = () => globalVar ? () => retained2()() : () => console.log( 'effect' ); -retained2()(); - -const retained3 = () => globalVar ? retained3() : {}; -retained3().x.y = 3; - -const retained4 = () => globalVar ? retained4() : { x: () => console.log( 'effect' ) }; -retained4().x(); - -const retained5 = { - get x () { - return globalVar ? retained5.x : console.log( 'effect' ); - } -}; -retained5.x; - -const retained6 = { - get x () { - return globalVar ? retained6.x : () => console.log( 'effect' ); - } -}; -retained6.x(); - -const retained7 = { - get x () { - return globalVar ? retained7.x : {}; - } -}; -retained7.x.y.z = 7; - -const retained8 = { - get x () { - return globalVar ? retained8.x : { y: () => console.log( 'effect' ) }; - } -}; -retained8.x.y(); diff --git a/test/form/samples/recursive-calls/_expected/iife.js b/test/form/samples/recursive-calls/_expected/iife.js deleted file mode 100644 index 84fd6d69a78..00000000000 --- a/test/form/samples/recursive-calls/_expected/iife.js +++ /dev/null @@ -1,44 +0,0 @@ -(function () { - 'use strict'; - - const retained1 = () => globalVar ? retained1() : console.log( 'effect' ); - retained1(); - - const retained2 = () => globalVar ? () => retained2()() : () => console.log( 'effect' ); - retained2()(); - - const retained3 = () => globalVar ? retained3() : {}; - retained3().x.y = 3; - - const retained4 = () => globalVar ? retained4() : { x: () => console.log( 'effect' ) }; - retained4().x(); - - const retained5 = { - get x () { - return globalVar ? retained5.x : console.log( 'effect' ); - } - }; - retained5.x; - - const retained6 = { - get x () { - return globalVar ? retained6.x : () => console.log( 'effect' ); - } - }; - retained6.x(); - - const retained7 = { - get x () { - return globalVar ? retained7.x : {}; - } - }; - retained7.x.y.z = 7; - - const retained8 = { - get x () { - return globalVar ? retained8.x : { y: () => console.log( 'effect' ) }; - } - }; - retained8.x.y(); - -}()); diff --git a/test/form/samples/recursive-calls/_expected/system.js b/test/form/samples/recursive-calls/_expected/system.js deleted file mode 100644 index 7f307d0e5e6..00000000000 --- a/test/form/samples/recursive-calls/_expected/system.js +++ /dev/null @@ -1,48 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - const retained1 = () => globalVar ? retained1() : console.log( 'effect' ); - retained1(); - - const retained2 = () => globalVar ? () => retained2()() : () => console.log( 'effect' ); - retained2()(); - - const retained3 = () => globalVar ? retained3() : {}; - retained3().x.y = 3; - - const retained4 = () => globalVar ? retained4() : { x: () => console.log( 'effect' ) }; - retained4().x(); - - const retained5 = { - get x () { - return globalVar ? retained5.x : console.log( 'effect' ); - } - }; - retained5.x; - - const retained6 = { - get x () { - return globalVar ? retained6.x : () => console.log( 'effect' ); - } - }; - retained6.x(); - - const retained7 = { - get x () { - return globalVar ? retained7.x : {}; - } - }; - retained7.x.y.z = 7; - - const retained8 = { - get x () { - return globalVar ? retained8.x : { y: () => console.log( 'effect' ) }; - } - }; - retained8.x.y(); - - } - }; -}); diff --git a/test/form/samples/recursive-calls/_expected/umd.js b/test/form/samples/recursive-calls/_expected/umd.js deleted file mode 100644 index 3ffa3a9f382..00000000000 --- a/test/form/samples/recursive-calls/_expected/umd.js +++ /dev/null @@ -1,46 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - const retained1 = () => globalVar ? retained1() : console.log( 'effect' ); - retained1(); - - const retained2 = () => globalVar ? () => retained2()() : () => console.log( 'effect' ); - retained2()(); - - const retained3 = () => globalVar ? retained3() : {}; - retained3().x.y = 3; - - const retained4 = () => globalVar ? retained4() : { x: () => console.log( 'effect' ) }; - retained4().x(); - - const retained5 = { - get x () { - return globalVar ? retained5.x : console.log( 'effect' ); - } - }; - retained5.x; - - const retained6 = { - get x () { - return globalVar ? retained6.x : () => console.log( 'effect' ); - } - }; - retained6.x(); - - const retained7 = { - get x () { - return globalVar ? retained7.x : {}; - } - }; - retained7.x.y.z = 7; - - const retained8 = { - get x () { - return globalVar ? retained8.x : { y: () => console.log( 'effect' ) }; - } - }; - retained8.x.y(); - -})); diff --git a/test/form/samples/recursive-calls/main.js b/test/form/samples/recursive-calls/main.js index 2fba7ddac73..89bae2a7738 100644 --- a/test/form/samples/recursive-calls/main.js +++ b/test/form/samples/recursive-calls/main.js @@ -1,79 +1,79 @@ -const removed1 = () => globalVar || removed1(); +const removed1 = () => globalThis.unknown || removed1(); removed1(); -const removed2 = () => globalVar ? () => removed2()() : () => {}; +const removed2 = () => globalThis.unknown ? () => removed2()() : () => {}; removed2()(); -const removed3 = () => globalVar ? removed3() : {}; +const removed3 = () => globalThis.unknown ? removed3() : {}; removed3().x = 3; -const removed4 = () => globalVar ? removed4() : { x: () => {} }; +const removed4 = () => globalThis.unknown ? removed4() : { x: () => {} }; removed4().x(); const removed5 = { get x () { - return globalVar || removed5.x; + return globalThis.unknown || removed5.x; } }; removed5.x; const removed6 = { get x () { - return globalVar ? removed6.x : () => {}; + return globalThis.unknown ? removed6.x : () => {}; } }; removed6.x(); const removed7 = { get x () { - return globalVar ? removed7.x : {}; + return globalThis.unknown ? removed7.x : {}; } }; removed7.x.y = 7; const removed8 = { get x () { - return globalVar ? removed8.x : { y: () => {} }; + return globalThis.unknown ? removed8.x : { y: () => {} }; } }; removed8.x.y(); -const retained1 = () => globalVar ? retained1() : console.log( 'effect' ); +const retained1 = () => globalThis.unknown ? retained1() : console.log( 'effect' ); retained1(); -const retained2 = () => globalVar ? () => retained2()() : () => console.log( 'effect' ); +const retained2 = () => globalThis.unknown ? () => retained2()() : () => console.log( 'effect' ); retained2()(); -const retained3 = () => globalVar ? retained3() : {}; +const retained3 = () => globalThis.unknown ? retained3() : {}; retained3().x.y = 3; -const retained4 = () => globalVar ? retained4() : { x: () => console.log( 'effect' ) }; +const retained4 = () => globalThis.unknown ? retained4() : { x: () => console.log( 'effect' ) }; retained4().x(); const retained5 = { get x () { - return globalVar ? retained5.x : console.log( 'effect' ); + return globalThis.unknown ? retained5.x : console.log( 'effect' ); } }; retained5.x; const retained6 = { get x () { - return globalVar ? retained6.x : () => console.log( 'effect' ); + return globalThis.unknown ? retained6.x : () => console.log( 'effect' ); } }; retained6.x(); const retained7 = { get x () { - return globalVar ? retained7.x : {}; + return globalThis.unknown ? retained7.x : {}; } }; retained7.x.y.z = 7; const retained8 = { get x () { - return globalVar ? retained8.x : { y: () => console.log( 'effect' ) }; + return globalThis.unknown ? retained8.x : { y: () => console.log( 'effect' ) }; } }; retained8.x.y(); diff --git a/test/form/samples/removes-unused-babel-helpers/_expected.js b/test/form/samples/removes-unused-babel-helpers/_expected.js new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/test/form/samples/removes-unused-babel-helpers/_expected.js @@ -0,0 +1 @@ + diff --git a/test/form/samples/removes-unused-babel-helpers/_expected/amd.js b/test/form/samples/removes-unused-babel-helpers/_expected/amd.js deleted file mode 100644 index f9f8229aa40..00000000000 --- a/test/form/samples/removes-unused-babel-helpers/_expected/amd.js +++ /dev/null @@ -1,5 +0,0 @@ -define(function () { 'use strict'; - - - -}); diff --git a/test/form/samples/removes-unused-babel-helpers/_expected/cjs.js b/test/form/samples/removes-unused-babel-helpers/_expected/cjs.js deleted file mode 100644 index eb109abbed0..00000000000 --- a/test/form/samples/removes-unused-babel-helpers/_expected/cjs.js +++ /dev/null @@ -1,2 +0,0 @@ -'use strict'; - diff --git a/test/form/samples/removes-unused-babel-helpers/_expected/iife.js b/test/form/samples/removes-unused-babel-helpers/_expected/iife.js deleted file mode 100644 index 43ef5426880..00000000000 --- a/test/form/samples/removes-unused-babel-helpers/_expected/iife.js +++ /dev/null @@ -1,6 +0,0 @@ -(function () { - 'use strict'; - - - -}()); diff --git a/test/form/samples/removes-unused-babel-helpers/_expected/system.js b/test/form/samples/removes-unused-babel-helpers/_expected/system.js deleted file mode 100644 index a702f2b06ef..00000000000 --- a/test/form/samples/removes-unused-babel-helpers/_expected/system.js +++ /dev/null @@ -1,10 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - - - } - }; -}); diff --git a/test/form/samples/removes-unused-babel-helpers/_expected/umd.js b/test/form/samples/removes-unused-babel-helpers/_expected/umd.js deleted file mode 100644 index a12a1990f01..00000000000 --- a/test/form/samples/removes-unused-babel-helpers/_expected/umd.js +++ /dev/null @@ -1,8 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - - -})); diff --git a/test/form/samples/render-removed-statements/_expected/es.js b/test/form/samples/render-removed-statements/_expected.js similarity index 74% rename from test/form/samples/render-removed-statements/_expected/es.js rename to test/form/samples/render-removed-statements/_expected.js index b57d32defa2..840b8dc5f5a 100644 --- a/test/form/samples/render-removed-statements/_expected/es.js +++ b/test/form/samples/render-removed-statements/_expected.js @@ -11,32 +11,32 @@ retained */ console.log(2); // trail retained console.log(2); -if (globalVar) { +if (globalThis.unknown) { // lead retained console.log(2); // trail retained } -if (globalVar) { +if (globalThis.unknown) { // lead retained console.log(2); // trail retained } -if (globalVar) { +if (globalThis.unknown) { // lead retained console.log(2); // trail retained } -if (globalVar) { +if (globalThis.unknown) { console.log(2); } -if (globalVar) { /* retained */ console.log(2);} +if (globalThis.unknown) { /* retained */ console.log(2);} -if (globalVar) { /* retained */ console.log(2);} +if (globalThis.unknown) { /* retained */ console.log(2);} -if (globalVar) { /* retained */ console.log(2);} +if (globalThis.unknown) { /* retained */ console.log(2);} -switch (globalVar) { +switch (globalThis.unknown) { case 1: // retained // lead retained console.log(2); // trail retained diff --git a/test/form/samples/render-removed-statements/_expected/amd.js b/test/form/samples/render-removed-statements/_expected/amd.js deleted file mode 100644 index 7013d74aff9..00000000000 --- a/test/form/samples/render-removed-statements/_expected/amd.js +++ /dev/null @@ -1,63 +0,0 @@ -define(function () { 'use strict'; - - /* header retained */ - /* lead - retained */ console.log(2); // trail retained - console.log(2); // trail retained - - /* lead retained */ - console.log(2); /* trail - retained */ /* trail - retained */ - - console.log(2); // trail retained - console.log(2); - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - console.log(2); - } - - if (globalVar) { /* retained */ console.log(2);} - - if (globalVar) { /* retained */ console.log(2);} - - if (globalVar) { /* retained */ console.log(2);} - - switch (globalVar) { - case 1: // retained - // lead retained - console.log(2); // trail retained - case 2: // retained - // lead retained - console.log(2); // trail retained - case 3: // retained - // lead retained - console.log(2); // trail retained - - case 4: /* lead retained */ console.log('3'); // trail retained - default: // retained - /* lead retained */ - console.log(2); // trail retained - } - - // lead retained - console.log(2); // trail retained - - /* footer retained */ - -}); diff --git a/test/form/samples/render-removed-statements/_expected/cjs.js b/test/form/samples/render-removed-statements/_expected/cjs.js deleted file mode 100644 index 7fb1ca3cc73..00000000000 --- a/test/form/samples/render-removed-statements/_expected/cjs.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict'; - -/* header retained */ - /* lead -retained */ console.log(2); // trail retained -console.log(2); // trail retained - -/* lead retained */ -console.log(2); /* trail -retained */ /* trail -retained */ - -console.log(2); // trail retained - console.log(2); - -if (globalVar) { - // lead retained - console.log(2); // trail retained -} - -if (globalVar) { - // lead retained - console.log(2); // trail retained -} - -if (globalVar) { - // lead retained - console.log(2); // trail retained -} - -if (globalVar) { - console.log(2); -} - -if (globalVar) { /* retained */ console.log(2);} - -if (globalVar) { /* retained */ console.log(2);} - -if (globalVar) { /* retained */ console.log(2);} - -switch (globalVar) { - case 1: // retained - // lead retained - console.log(2); // trail retained - case 2: // retained - // lead retained - console.log(2); // trail retained - case 3: // retained - // lead retained - console.log(2); // trail retained - - case 4: /* lead retained */ console.log('3'); // trail retained - default: // retained - /* lead retained */ - console.log(2); // trail retained -} - -// lead retained -console.log(2); // trail retained - -/* footer retained */ diff --git a/test/form/samples/render-removed-statements/_expected/iife.js b/test/form/samples/render-removed-statements/_expected/iife.js deleted file mode 100644 index 007910f88f0..00000000000 --- a/test/form/samples/render-removed-statements/_expected/iife.js +++ /dev/null @@ -1,64 +0,0 @@ -(function () { - 'use strict'; - - /* header retained */ - /* lead - retained */ console.log(2); // trail retained - console.log(2); // trail retained - - /* lead retained */ - console.log(2); /* trail - retained */ /* trail - retained */ - - console.log(2); // trail retained - console.log(2); - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - console.log(2); - } - - if (globalVar) { /* retained */ console.log(2);} - - if (globalVar) { /* retained */ console.log(2);} - - if (globalVar) { /* retained */ console.log(2);} - - switch (globalVar) { - case 1: // retained - // lead retained - console.log(2); // trail retained - case 2: // retained - // lead retained - console.log(2); // trail retained - case 3: // retained - // lead retained - console.log(2); // trail retained - - case 4: /* lead retained */ console.log('3'); // trail retained - default: // retained - /* lead retained */ - console.log(2); // trail retained - } - - // lead retained - console.log(2); // trail retained - - /* footer retained */ - -}()); diff --git a/test/form/samples/render-removed-statements/_expected/system.js b/test/form/samples/render-removed-statements/_expected/system.js deleted file mode 100644 index d79206de699..00000000000 --- a/test/form/samples/render-removed-statements/_expected/system.js +++ /dev/null @@ -1,68 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - /* header retained */ - /* lead - retained */ console.log(2); // trail retained - console.log(2); // trail retained - - /* lead retained */ - console.log(2); /* trail - retained */ /* trail - retained */ - - console.log(2); // trail retained - console.log(2); - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - console.log(2); - } - - if (globalVar) { /* retained */ console.log(2);} - - if (globalVar) { /* retained */ console.log(2);} - - if (globalVar) { /* retained */ console.log(2);} - - switch (globalVar) { - case 1: // retained - // lead retained - console.log(2); // trail retained - case 2: // retained - // lead retained - console.log(2); // trail retained - case 3: // retained - // lead retained - console.log(2); // trail retained - - case 4: /* lead retained */ console.log('3'); // trail retained - default: // retained - /* lead retained */ - console.log(2); // trail retained - } - - // lead retained - console.log(2); // trail retained - - /* footer retained */ - - } - }; -}); diff --git a/test/form/samples/render-removed-statements/_expected/umd.js b/test/form/samples/render-removed-statements/_expected/umd.js deleted file mode 100644 index 76956811294..00000000000 --- a/test/form/samples/render-removed-statements/_expected/umd.js +++ /dev/null @@ -1,66 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - /* header retained */ - /* lead - retained */ console.log(2); // trail retained - console.log(2); // trail retained - - /* lead retained */ - console.log(2); /* trail - retained */ /* trail - retained */ - - console.log(2); // trail retained - console.log(2); - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - // lead retained - console.log(2); // trail retained - } - - if (globalVar) { - console.log(2); - } - - if (globalVar) { /* retained */ console.log(2);} - - if (globalVar) { /* retained */ console.log(2);} - - if (globalVar) { /* retained */ console.log(2);} - - switch (globalVar) { - case 1: // retained - // lead retained - console.log(2); // trail retained - case 2: // retained - // lead retained - console.log(2); // trail retained - case 3: // retained - // lead retained - console.log(2); // trail retained - - case 4: /* lead retained */ console.log('3'); // trail retained - default: // retained - /* lead retained */ - console.log(2); // trail retained - } - - // lead retained - console.log(2); // trail retained - - /* footer retained */ - -})); diff --git a/test/form/samples/render-removed-statements/main.js b/test/form/samples/render-removed-statements/main.js index 24e73c94ba2..37707412e3b 100644 --- a/test/form/samples/render-removed-statements/main.js +++ b/test/form/samples/render-removed-statements/main.js @@ -20,14 +20,14 @@ retained */ console.log(2); // trail retained var a = 1; console.log(2); -if (globalVar) { +if (globalThis.unknown) { // lead removed var a = 1; // trail removed // lead retained console.log(2); // trail retained } -if (globalVar) { +if (globalThis.unknown) { // lead removed var a = 1; // trail removed // lead retained @@ -36,26 +36,26 @@ if (globalVar) { var a = 1; // trail removed } -if (globalVar) { +if (globalThis.unknown) { // lead retained console.log(2); // trail retained // lead removed var a = 1; // trail removed } -if (globalVar) { +if (globalThis.unknown) { console.log(2); var a = 1; /* trail removed */ } -if (globalVar) { /* removed */ var a = 1; /* retained */ console.log(2);} +if (globalThis.unknown) { /* removed */ var a = 1; /* retained */ console.log(2);} -if (globalVar) { /* removed */ var a = 1; /* retained */ console.log(2); /* removed */ var a = 1;} +if (globalThis.unknown) { /* removed */ var a = 1; /* retained */ console.log(2); /* removed */ var a = 1;} -if (globalVar) { /* retained */ console.log(2); /* removed */ var a = 1;} +if (globalThis.unknown) { /* retained */ console.log(2); /* removed */ var a = 1;} -switch (globalVar) { +switch (globalThis.unknown) { case 1: // retained // lead removed var a = 1; // trail removed diff --git a/test/form/samples/side-effects-await/_expected/es.js b/test/form/samples/side-effects-await/_expected.js similarity index 69% rename from test/form/samples/side-effects-await/_expected/es.js rename to test/form/samples/side-effects-await/_expected.js index e22a6d47886..371e9cc7312 100644 --- a/test/form/samples/side-effects-await/_expected/es.js +++ b/test/form/samples/side-effects-await/_expected.js @@ -1,12 +1,12 @@ async function hasEffects1 () { - await globalPromise; + await globalThis.unknown; console.log( 'effect' ); } hasEffects1(); async function hasEffects2 () { - await globalFunction(); + await globalThis.unknown(); } hasEffects2(); diff --git a/test/form/samples/side-effects-await/_expected/amd.js b/test/form/samples/side-effects-await/_expected/amd.js deleted file mode 100644 index fcd4a2f41da..00000000000 --- a/test/form/samples/side-effects-await/_expected/amd.js +++ /dev/null @@ -1,16 +0,0 @@ -define(function () { 'use strict'; - - async function hasEffects1 () { - await globalPromise; - console.log( 'effect' ); - } - - hasEffects1(); - - async function hasEffects2 () { - await globalFunction(); - } - - hasEffects2(); - -}); diff --git a/test/form/samples/side-effects-await/_expected/cjs.js b/test/form/samples/side-effects-await/_expected/cjs.js deleted file mode 100644 index 90e0b388d83..00000000000 --- a/test/form/samples/side-effects-await/_expected/cjs.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -async function hasEffects1 () { - await globalPromise; - console.log( 'effect' ); -} - -hasEffects1(); - -async function hasEffects2 () { - await globalFunction(); -} - -hasEffects2(); diff --git a/test/form/samples/side-effects-await/_expected/iife.js b/test/form/samples/side-effects-await/_expected/iife.js deleted file mode 100644 index fa19185c4b8..00000000000 --- a/test/form/samples/side-effects-await/_expected/iife.js +++ /dev/null @@ -1,17 +0,0 @@ -(function () { - 'use strict'; - - async function hasEffects1 () { - await globalPromise; - console.log( 'effect' ); - } - - hasEffects1(); - - async function hasEffects2 () { - await globalFunction(); - } - - hasEffects2(); - -}()); diff --git a/test/form/samples/side-effects-await/_expected/system.js b/test/form/samples/side-effects-await/_expected/system.js deleted file mode 100644 index f433b86b319..00000000000 --- a/test/form/samples/side-effects-await/_expected/system.js +++ /dev/null @@ -1,21 +0,0 @@ -System.register('myBundle', [], function () { - 'use strict'; - return { - execute: function () { - - async function hasEffects1 () { - await globalPromise; - console.log( 'effect' ); - } - - hasEffects1(); - - async function hasEffects2 () { - await globalFunction(); - } - - hasEffects2(); - - } - }; -}); diff --git a/test/form/samples/side-effects-await/_expected/umd.js b/test/form/samples/side-effects-await/_expected/umd.js deleted file mode 100644 index 0363b0cd7d8..00000000000 --- a/test/form/samples/side-effects-await/_expected/umd.js +++ /dev/null @@ -1,19 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - async function hasEffects1 () { - await globalPromise; - console.log( 'effect' ); - } - - hasEffects1(); - - async function hasEffects2 () { - await globalFunction(); - } - - hasEffects2(); - -})); diff --git a/test/form/samples/side-effects-await/main.js b/test/form/samples/side-effects-await/main.js index c6966a1fa9f..0641421d34a 100644 --- a/test/form/samples/side-effects-await/main.js +++ b/test/form/samples/side-effects-await/main.js @@ -1,18 +1,18 @@ async function hasEffects1 () { - await globalPromise; + await globalThis.unknown; console.log( 'effect' ); } hasEffects1(); async function hasEffects2 () { - await globalFunction(); + await globalThis.unknown(); } hasEffects2(); async function isRemoved () { - await globalPromise; + await globalThis.unknown; } isRemoved(); diff --git a/test/form/samples/side-effects-call-arguments/_expected/es.js b/test/form/samples/side-effects-call-arguments/_expected.js similarity index 70% rename from test/form/samples/side-effects-call-arguments/_expected/es.js rename to test/form/samples/side-effects-call-arguments/_expected.js index ad7a297384b..e42532c678a 100644 --- a/test/form/samples/side-effects-call-arguments/_expected/es.js +++ b/test/form/samples/side-effects-call-arguments/_expected.js @@ -1,5 +1,5 @@ function foo () {} -foo( globalFunction() ); +foo( globalThis.unknown() ); var baz = 2; foo( baz++ ); diff --git a/test/form/samples/side-effects-call-arguments/_expected/amd.js b/test/form/samples/side-effects-call-arguments/_expected/amd.js deleted file mode 100644 index a90079ac01e..00000000000 --- a/test/form/samples/side-effects-call-arguments/_expected/amd.js +++ /dev/null @@ -1,11 +0,0 @@ -define(function () { 'use strict'; - - function foo () {} - foo( globalFunction() ); - - var baz = 2; - foo( baz++ ); - - assert.equal(baz, 3); - -}); diff --git a/test/form/samples/side-effects-call-arguments/_expected/cjs.js b/test/form/samples/side-effects-call-arguments/_expected/cjs.js deleted file mode 100644 index 9b76714241b..00000000000 --- a/test/form/samples/side-effects-call-arguments/_expected/cjs.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -function foo () {} -foo( globalFunction() ); - -var baz = 2; -foo( baz++ ); - -assert.equal(baz, 3); diff --git a/test/form/samples/side-effects-call-arguments/_expected/iife.js b/test/form/samples/side-effects-call-arguments/_expected/iife.js deleted file mode 100644 index fb4d4535e18..00000000000 --- a/test/form/samples/side-effects-call-arguments/_expected/iife.js +++ /dev/null @@ -1,12 +0,0 @@ -(function () { - 'use strict'; - - function foo () {} - foo( globalFunction() ); - - var baz = 2; - foo( baz++ ); - - assert.equal(baz, 3); - -}()); diff --git a/test/form/samples/side-effects-call-arguments/_expected/system.js b/test/form/samples/side-effects-call-arguments/_expected/system.js deleted file mode 100644 index 5cda537c9ea..00000000000 --- a/test/form/samples/side-effects-call-arguments/_expected/system.js +++ /dev/null @@ -1,16 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - function foo () {} - foo( globalFunction() ); - - var baz = 2; - foo( baz++ ); - - assert.equal(baz, 3); - - } - }; -}); diff --git a/test/form/samples/side-effects-call-arguments/_expected/umd.js b/test/form/samples/side-effects-call-arguments/_expected/umd.js deleted file mode 100644 index 638a58b2f11..00000000000 --- a/test/form/samples/side-effects-call-arguments/_expected/umd.js +++ /dev/null @@ -1,14 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - function foo () {} - foo( globalFunction() ); - - var baz = 2; - foo( baz++ ); - - assert.equal(baz, 3); - -})); diff --git a/test/form/samples/side-effects-call-arguments/main.js b/test/form/samples/side-effects-call-arguments/main.js index fe12a9d2fe8..cd2c6b23415 100644 --- a/test/form/samples/side-effects-call-arguments/main.js +++ b/test/form/samples/side-effects-call-arguments/main.js @@ -3,8 +3,8 @@ function foo () {} foo(); foo( 1 ); foo( foo() ); -foo( globalValue ); -foo( globalFunction() ); +foo( globalThis.unknown ); +foo( globalThis.unknown() ); var bar = 1; foo( bar++ ); diff --git a/test/form/samples/side-effects-computed-pattern-keys/_expected.js b/test/form/samples/side-effects-computed-pattern-keys/_expected.js new file mode 100644 index 00000000000..d8ab4d2a660 --- /dev/null +++ b/test/form/samples/side-effects-computed-pattern-keys/_expected.js @@ -0,0 +1 @@ +const { [globalThis.unknown()]: isKept } = {}; diff --git a/test/form/samples/side-effects-computed-pattern-keys/_expected/amd.js b/test/form/samples/side-effects-computed-pattern-keys/_expected/amd.js deleted file mode 100644 index 57b70fb22a1..00000000000 --- a/test/form/samples/side-effects-computed-pattern-keys/_expected/amd.js +++ /dev/null @@ -1,5 +0,0 @@ -define(function () { 'use strict'; - - const { [globalValue()]: isKept } = {}; - -}); diff --git a/test/form/samples/side-effects-computed-pattern-keys/_expected/cjs.js b/test/form/samples/side-effects-computed-pattern-keys/_expected/cjs.js deleted file mode 100644 index 88424574d04..00000000000 --- a/test/form/samples/side-effects-computed-pattern-keys/_expected/cjs.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -const { [globalValue()]: isKept } = {}; diff --git a/test/form/samples/side-effects-computed-pattern-keys/_expected/es.js b/test/form/samples/side-effects-computed-pattern-keys/_expected/es.js deleted file mode 100644 index 393820744e9..00000000000 --- a/test/form/samples/side-effects-computed-pattern-keys/_expected/es.js +++ /dev/null @@ -1 +0,0 @@ -const { [globalValue()]: isKept } = {}; diff --git a/test/form/samples/side-effects-computed-pattern-keys/_expected/iife.js b/test/form/samples/side-effects-computed-pattern-keys/_expected/iife.js deleted file mode 100644 index f89ee63e6bf..00000000000 --- a/test/form/samples/side-effects-computed-pattern-keys/_expected/iife.js +++ /dev/null @@ -1,6 +0,0 @@ -(function () { - 'use strict'; - - const { [globalValue()]: isKept } = {}; - -}()); diff --git a/test/form/samples/side-effects-computed-pattern-keys/_expected/system.js b/test/form/samples/side-effects-computed-pattern-keys/_expected/system.js deleted file mode 100644 index 71ff3eff218..00000000000 --- a/test/form/samples/side-effects-computed-pattern-keys/_expected/system.js +++ /dev/null @@ -1,10 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - const { [globalValue()]: isKept } = {}; - - } - }; -}); diff --git a/test/form/samples/side-effects-computed-pattern-keys/_expected/umd.js b/test/form/samples/side-effects-computed-pattern-keys/_expected/umd.js deleted file mode 100644 index 8ce7c7f77de..00000000000 --- a/test/form/samples/side-effects-computed-pattern-keys/_expected/umd.js +++ /dev/null @@ -1,8 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - const { [globalValue()]: isKept } = {}; - -})); diff --git a/test/form/samples/side-effects-computed-pattern-keys/main.js b/test/form/samples/side-effects-computed-pattern-keys/main.js index 1400fae156c..bc1aefa12f1 100644 --- a/test/form/samples/side-effects-computed-pattern-keys/main.js +++ b/test/form/samples/side-effects-computed-pattern-keys/main.js @@ -1,2 +1,2 @@ -const { [globalValue]: isRemoved } = { foo: 'bar' }; -const { [globalValue()]: isKept } = {}; +const { [globalThis.unknown]: isRemoved } = { foo: 'bar' }; +const { [globalThis.unknown()]: isKept } = {}; diff --git a/test/form/samples/side-effects-delete/_expected/amd.js b/test/form/samples/side-effects-delete/_expected/amd.js index d287a99f985..2c24744efd5 100644 --- a/test/form/samples/side-effects-delete/_expected/amd.js +++ b/test/form/samples/side-effects-delete/_expected/amd.js @@ -3,7 +3,7 @@ define(['exports'], function (exports) { 'use strict'; var x = {foo: 'bar'}; delete x.foo; - delete globalVariable.foo; + delete globalThis.unknown.foo; exports.x = x; diff --git a/test/form/samples/side-effects-delete/_expected/cjs.js b/test/form/samples/side-effects-delete/_expected/cjs.js index 6d9a28d53b4..cdaada5d697 100644 --- a/test/form/samples/side-effects-delete/_expected/cjs.js +++ b/test/form/samples/side-effects-delete/_expected/cjs.js @@ -5,6 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true }); var x = {foo: 'bar'}; delete x.foo; -delete globalVariable.foo; +delete globalThis.unknown.foo; exports.x = x; diff --git a/test/form/samples/side-effects-delete/_expected/es.js b/test/form/samples/side-effects-delete/_expected/es.js index 8aea2c6799c..02ca55afe2a 100644 --- a/test/form/samples/side-effects-delete/_expected/es.js +++ b/test/form/samples/side-effects-delete/_expected/es.js @@ -1,6 +1,6 @@ var x = {foo: 'bar'}; delete x.foo; -delete globalVariable.foo; +delete globalThis.unknown.foo; export { x }; diff --git a/test/form/samples/side-effects-delete/_expected/iife.js b/test/form/samples/side-effects-delete/_expected/iife.js index ba3f40af1a2..a90e0231e0c 100644 --- a/test/form/samples/side-effects-delete/_expected/iife.js +++ b/test/form/samples/side-effects-delete/_expected/iife.js @@ -4,7 +4,7 @@ var myBundle = (function (exports) { var x = {foo: 'bar'}; delete x.foo; - delete globalVariable.foo; + delete globalThis.unknown.foo; exports.x = x; diff --git a/test/form/samples/side-effects-delete/_expected/system.js b/test/form/samples/side-effects-delete/_expected/system.js index 5b24ca5821a..7dcd588e1a5 100644 --- a/test/form/samples/side-effects-delete/_expected/system.js +++ b/test/form/samples/side-effects-delete/_expected/system.js @@ -6,7 +6,7 @@ System.register('myBundle', [], function (exports) { var x = exports('x', {foo: 'bar'}); delete x.foo; - delete globalVariable.foo; + delete globalThis.unknown.foo; } }; diff --git a/test/form/samples/side-effects-delete/_expected/umd.js b/test/form/samples/side-effects-delete/_expected/umd.js index fef4b137fab..4bfde2da0c1 100644 --- a/test/form/samples/side-effects-delete/_expected/umd.js +++ b/test/form/samples/side-effects-delete/_expected/umd.js @@ -7,7 +7,7 @@ var x = {foo: 'bar'}; delete x.foo; - delete globalVariable.foo; + delete globalThis.unknown.foo; exports.x = x; diff --git a/test/form/samples/side-effects-delete/main.js b/test/form/samples/side-effects-delete/main.js index 3e59b876db7..d4cdfc018b0 100644 --- a/test/form/samples/side-effects-delete/main.js +++ b/test/form/samples/side-effects-delete/main.js @@ -4,6 +4,6 @@ delete x.foo; var y = {foo: 'bar'}; delete y.foo; -delete globalVariable.foo; +delete globalThis.unknown.foo; export {x}; diff --git a/test/form/samples/side-effects-es6-super-classes/_expected/es.js b/test/form/samples/side-effects-es6-super-classes/_expected.js similarity index 93% rename from test/form/samples/side-effects-es6-super-classes/_expected/es.js rename to test/form/samples/side-effects-es6-super-classes/_expected.js index 6bfc565f41d..939cafb7450 100644 --- a/test/form/samples/side-effects-es6-super-classes/_expected/es.js +++ b/test/form/samples/side-effects-es6-super-classes/_expected.js @@ -1,4 +1,4 @@ -class GlobalSuper extends GlobalClass {} +class GlobalSuper extends globalThis.UnknownClass {} const globalSuper = new GlobalSuper(); class SideEffectSuper extends (() => { diff --git a/test/form/samples/side-effects-es6-super-classes/_expected/amd.js b/test/form/samples/side-effects-es6-super-classes/_expected/amd.js deleted file mode 100644 index ce2f8ad4037..00000000000 --- a/test/form/samples/side-effects-es6-super-classes/_expected/amd.js +++ /dev/null @@ -1,40 +0,0 @@ -define(function () { 'use strict'; - - class GlobalSuper extends GlobalClass {} - const globalSuper = new GlobalSuper(); - - class SideEffectSuper extends (() => { - console.log( 'effect' ); - return class {}; - })() { - } - - class SuperConstructorEffect { - constructor () { - console.log( 'effect' ); - } - } - class SideEffectsSuperConstructor1 extends SuperConstructorEffect {} - const sideEffectsSuperConstructor1 = new SideEffectsSuperConstructor1(); - - class SideEffectsSuperConstructor2 extends SuperConstructorEffect { - constructor () { - super(); - } - } - const sideEffectsSuperConstructor2 = new SideEffectsSuperConstructor2(); - - class SuperMethodEffect { - effect () { - console.log( 'effect' ); - } - } - class SideEffectsSuperMethod extends SuperMethodEffect { - constructor () { - super(); - super.effect(); - } - } - const sideEffectsSuperMethod = new SideEffectsSuperMethod(); - -}); diff --git a/test/form/samples/side-effects-es6-super-classes/_expected/cjs.js b/test/form/samples/side-effects-es6-super-classes/_expected/cjs.js deleted file mode 100644 index 226a7b60c6e..00000000000 --- a/test/form/samples/side-effects-es6-super-classes/_expected/cjs.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -class GlobalSuper extends GlobalClass {} -const globalSuper = new GlobalSuper(); - -class SideEffectSuper extends (() => { - console.log( 'effect' ); - return class {}; -})() { -} - -class SuperConstructorEffect { - constructor () { - console.log( 'effect' ); - } -} -class SideEffectsSuperConstructor1 extends SuperConstructorEffect {} -const sideEffectsSuperConstructor1 = new SideEffectsSuperConstructor1(); - -class SideEffectsSuperConstructor2 extends SuperConstructorEffect { - constructor () { - super(); - } -} -const sideEffectsSuperConstructor2 = new SideEffectsSuperConstructor2(); - -class SuperMethodEffect { - effect () { - console.log( 'effect' ); - } -} -class SideEffectsSuperMethod extends SuperMethodEffect { - constructor () { - super(); - super.effect(); - } -} -const sideEffectsSuperMethod = new SideEffectsSuperMethod(); diff --git a/test/form/samples/side-effects-es6-super-classes/_expected/iife.js b/test/form/samples/side-effects-es6-super-classes/_expected/iife.js deleted file mode 100644 index 729980f7013..00000000000 --- a/test/form/samples/side-effects-es6-super-classes/_expected/iife.js +++ /dev/null @@ -1,41 +0,0 @@ -(function () { - 'use strict'; - - class GlobalSuper extends GlobalClass {} - const globalSuper = new GlobalSuper(); - - class SideEffectSuper extends (() => { - console.log( 'effect' ); - return class {}; - })() { - } - - class SuperConstructorEffect { - constructor () { - console.log( 'effect' ); - } - } - class SideEffectsSuperConstructor1 extends SuperConstructorEffect {} - const sideEffectsSuperConstructor1 = new SideEffectsSuperConstructor1(); - - class SideEffectsSuperConstructor2 extends SuperConstructorEffect { - constructor () { - super(); - } - } - const sideEffectsSuperConstructor2 = new SideEffectsSuperConstructor2(); - - class SuperMethodEffect { - effect () { - console.log( 'effect' ); - } - } - class SideEffectsSuperMethod extends SuperMethodEffect { - constructor () { - super(); - super.effect(); - } - } - const sideEffectsSuperMethod = new SideEffectsSuperMethod(); - -}()); diff --git a/test/form/samples/side-effects-es6-super-classes/_expected/system.js b/test/form/samples/side-effects-es6-super-classes/_expected/system.js deleted file mode 100644 index e89e51dedb0..00000000000 --- a/test/form/samples/side-effects-es6-super-classes/_expected/system.js +++ /dev/null @@ -1,45 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - class GlobalSuper extends GlobalClass {} - const globalSuper = new GlobalSuper(); - - class SideEffectSuper extends (() => { - console.log( 'effect' ); - return class {}; - })() { - } - - class SuperConstructorEffect { - constructor () { - console.log( 'effect' ); - } - } - class SideEffectsSuperConstructor1 extends SuperConstructorEffect {} - const sideEffectsSuperConstructor1 = new SideEffectsSuperConstructor1(); - - class SideEffectsSuperConstructor2 extends SuperConstructorEffect { - constructor () { - super(); - } - } - const sideEffectsSuperConstructor2 = new SideEffectsSuperConstructor2(); - - class SuperMethodEffect { - effect () { - console.log( 'effect' ); - } - } - class SideEffectsSuperMethod extends SuperMethodEffect { - constructor () { - super(); - super.effect(); - } - } - const sideEffectsSuperMethod = new SideEffectsSuperMethod(); - - } - }; -}); diff --git a/test/form/samples/side-effects-es6-super-classes/_expected/umd.js b/test/form/samples/side-effects-es6-super-classes/_expected/umd.js deleted file mode 100644 index cba2378599e..00000000000 --- a/test/form/samples/side-effects-es6-super-classes/_expected/umd.js +++ /dev/null @@ -1,43 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - class GlobalSuper extends GlobalClass {} - const globalSuper = new GlobalSuper(); - - class SideEffectSuper extends (() => { - console.log( 'effect' ); - return class {}; - })() { - } - - class SuperConstructorEffect { - constructor () { - console.log( 'effect' ); - } - } - class SideEffectsSuperConstructor1 extends SuperConstructorEffect {} - const sideEffectsSuperConstructor1 = new SideEffectsSuperConstructor1(); - - class SideEffectsSuperConstructor2 extends SuperConstructorEffect { - constructor () { - super(); - } - } - const sideEffectsSuperConstructor2 = new SideEffectsSuperConstructor2(); - - class SuperMethodEffect { - effect () { - console.log( 'effect' ); - } - } - class SideEffectsSuperMethod extends SuperMethodEffect { - constructor () { - super(); - super.effect(); - } - } - const sideEffectsSuperMethod = new SideEffectsSuperMethod(); - -})); diff --git a/test/form/samples/side-effects-es6-super-classes/main.js b/test/form/samples/side-effects-es6-super-classes/main.js index 28fe486508a..62d521866ee 100644 --- a/test/form/samples/side-effects-es6-super-classes/main.js +++ b/test/form/samples/side-effects-es6-super-classes/main.js @@ -7,7 +7,7 @@ class SuperNoEffects { class NoEffects extends SuperNoEffects {} const noEffects = new NoEffects(); -class GlobalSuper extends GlobalClass {} +class GlobalSuper extends globalThis.UnknownClass {} const globalSuper = new GlobalSuper(); class SideEffectSuper extends (() => { diff --git a/test/form/samples/side-effects-expressions-as-statements/_expected/cjs.js b/test/form/samples/side-effects-expressions-as-statements/_expected.js similarity index 57% rename from test/form/samples/side-effects-expressions-as-statements/_expected/cjs.js rename to test/form/samples/side-effects-expressions-as-statements/_expected.js index 98b353fa085..394e046d4ce 100644 --- a/test/form/samples/side-effects-expressions-as-statements/_expected/cjs.js +++ b/test/form/samples/side-effects-expressions-as-statements/_expected.js @@ -1,8 +1,6 @@ -'use strict'; - // Access getters with side-effects to e.g. force DOM repaints -globalVar.getter; -globalVar && globalVar.member && globalVar.member.getter; +globalThis.unknown.getter; +globalThis.unknown && globalThis.unknown.member && globalThis.unknown.member.getter; // Call pure constructors for side-effects for e.g. feature detection new Function(''); diff --git a/test/form/samples/side-effects-expressions-as-statements/_expected/amd.js b/test/form/samples/side-effects-expressions-as-statements/_expected/amd.js deleted file mode 100644 index 97343e340d5..00000000000 --- a/test/form/samples/side-effects-expressions-as-statements/_expected/amd.js +++ /dev/null @@ -1,10 +0,0 @@ -define(function () { 'use strict'; - - // Access getters with side-effects to e.g. force DOM repaints - globalVar.getter; - globalVar && globalVar.member && globalVar.member.getter; - - // Call pure constructors for side-effects for e.g. feature detection - new Function(''); - -}); diff --git a/test/form/samples/side-effects-expressions-as-statements/_expected/es.js b/test/form/samples/side-effects-expressions-as-statements/_expected/es.js deleted file mode 100644 index 86f9cf0f080..00000000000 --- a/test/form/samples/side-effects-expressions-as-statements/_expected/es.js +++ /dev/null @@ -1,6 +0,0 @@ -// Access getters with side-effects to e.g. force DOM repaints -globalVar.getter; -globalVar && globalVar.member && globalVar.member.getter; - -// Call pure constructors for side-effects for e.g. feature detection -new Function(''); diff --git a/test/form/samples/side-effects-expressions-as-statements/_expected/iife.js b/test/form/samples/side-effects-expressions-as-statements/_expected/iife.js deleted file mode 100644 index 18a0f833c9a..00000000000 --- a/test/form/samples/side-effects-expressions-as-statements/_expected/iife.js +++ /dev/null @@ -1,11 +0,0 @@ -(function () { - 'use strict'; - - // Access getters with side-effects to e.g. force DOM repaints - globalVar.getter; - globalVar && globalVar.member && globalVar.member.getter; - - // Call pure constructors for side-effects for e.g. feature detection - new Function(''); - -}()); diff --git a/test/form/samples/side-effects-expressions-as-statements/_expected/system.js b/test/form/samples/side-effects-expressions-as-statements/_expected/system.js deleted file mode 100644 index e0e2649dd3e..00000000000 --- a/test/form/samples/side-effects-expressions-as-statements/_expected/system.js +++ /dev/null @@ -1,15 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - // Access getters with side-effects to e.g. force DOM repaints - globalVar.getter; - globalVar && globalVar.member && globalVar.member.getter; - - // Call pure constructors for side-effects for e.g. feature detection - new Function(''); - - } - }; -}); diff --git a/test/form/samples/side-effects-expressions-as-statements/_expected/umd.js b/test/form/samples/side-effects-expressions-as-statements/_expected/umd.js deleted file mode 100644 index 2d87b957317..00000000000 --- a/test/form/samples/side-effects-expressions-as-statements/_expected/umd.js +++ /dev/null @@ -1,13 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - // Access getters with side-effects to e.g. force DOM repaints - globalVar.getter; - globalVar && globalVar.member && globalVar.member.getter; - - // Call pure constructors for side-effects for e.g. feature detection - new Function(''); - -})); diff --git a/test/form/samples/side-effects-expressions-as-statements/main.js b/test/form/samples/side-effects-expressions-as-statements/main.js index 3feecf7f6b2..d44ca444bbf 100644 --- a/test/form/samples/side-effects-expressions-as-statements/main.js +++ b/test/form/samples/side-effects-expressions-as-statements/main.js @@ -1,6 +1,6 @@ // Access getters with side-effects to e.g. force DOM repaints -globalVar.getter; -globalVar && globalVar.member && globalVar.member.getter; +globalThis.unknown.getter; +globalThis.unknown && globalThis.unknown.member && globalThis.unknown.member.getter; // Call pure constructors for side-effects for e.g. feature detection new Function(''); diff --git a/test/form/samples/side-effects-generators/_expected/es.js b/test/form/samples/side-effects-generators/_expected.js similarity index 81% rename from test/form/samples/side-effects-generators/_expected/es.js rename to test/form/samples/side-effects-generators/_expected.js index 9913ed35aa0..c1a459ffac0 100644 --- a/test/form/samples/side-effects-generators/_expected/es.js +++ b/test/form/samples/side-effects-generators/_expected.js @@ -1,5 +1,5 @@ function* sideEffectYield() { - yield globalFunction(); + yield globalThis.unknown(); yield 'no side-effect but must be included to ensure proper control flow'; } @@ -11,10 +11,10 @@ function* effectCallYield() { } const iterator3 = effectCallYield(); -iterator3.next(globalFunction); +iterator3.next(globalThis.unknown); function* sideEffectYield2() { - yield globalFunction(); + yield globalThis.unknown(); } function* sideEffectNestedYield() { diff --git a/test/form/samples/side-effects-generators/_expected/amd.js b/test/form/samples/side-effects-generators/_expected/amd.js deleted file mode 100644 index fff0219aae2..00000000000 --- a/test/form/samples/side-effects-generators/_expected/amd.js +++ /dev/null @@ -1,28 +0,0 @@ -define(function () { 'use strict'; - - function* sideEffectYield() { - yield globalFunction(); - yield 'no side-effect but must be included to ensure proper control flow'; - } - - const iterator2 = sideEffectYield(); - - function* effectCallYield() { - const yieldedValue = yield; - yieldedValue(); - } - - const iterator3 = effectCallYield(); - iterator3.next(globalFunction); - - function* sideEffectYield2() { - yield globalFunction(); - } - - function* sideEffectNestedYield() { - yield* sideEffectYield2(); - } - - const iterator4 = sideEffectNestedYield(); - -}); diff --git a/test/form/samples/side-effects-generators/_expected/cjs.js b/test/form/samples/side-effects-generators/_expected/cjs.js deleted file mode 100644 index e3333459876..00000000000 --- a/test/form/samples/side-effects-generators/_expected/cjs.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -function* sideEffectYield() { - yield globalFunction(); - yield 'no side-effect but must be included to ensure proper control flow'; -} - -const iterator2 = sideEffectYield(); - -function* effectCallYield() { - const yieldedValue = yield; - yieldedValue(); -} - -const iterator3 = effectCallYield(); -iterator3.next(globalFunction); - -function* sideEffectYield2() { - yield globalFunction(); -} - -function* sideEffectNestedYield() { - yield* sideEffectYield2(); -} - -const iterator4 = sideEffectNestedYield(); diff --git a/test/form/samples/side-effects-generators/_expected/iife.js b/test/form/samples/side-effects-generators/_expected/iife.js deleted file mode 100644 index fad8ac77e15..00000000000 --- a/test/form/samples/side-effects-generators/_expected/iife.js +++ /dev/null @@ -1,29 +0,0 @@ -(function () { - 'use strict'; - - function* sideEffectYield() { - yield globalFunction(); - yield 'no side-effect but must be included to ensure proper control flow'; - } - - const iterator2 = sideEffectYield(); - - function* effectCallYield() { - const yieldedValue = yield; - yieldedValue(); - } - - const iterator3 = effectCallYield(); - iterator3.next(globalFunction); - - function* sideEffectYield2() { - yield globalFunction(); - } - - function* sideEffectNestedYield() { - yield* sideEffectYield2(); - } - - const iterator4 = sideEffectNestedYield(); - -}()); diff --git a/test/form/samples/side-effects-generators/_expected/system.js b/test/form/samples/side-effects-generators/_expected/system.js deleted file mode 100644 index 3874292e885..00000000000 --- a/test/form/samples/side-effects-generators/_expected/system.js +++ /dev/null @@ -1,33 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - function* sideEffectYield() { - yield globalFunction(); - yield 'no side-effect but must be included to ensure proper control flow'; - } - - const iterator2 = sideEffectYield(); - - function* effectCallYield() { - const yieldedValue = yield; - yieldedValue(); - } - - const iterator3 = effectCallYield(); - iterator3.next(globalFunction); - - function* sideEffectYield2() { - yield globalFunction(); - } - - function* sideEffectNestedYield() { - yield* sideEffectYield2(); - } - - const iterator4 = sideEffectNestedYield(); - - } - }; -}); diff --git a/test/form/samples/side-effects-generators/_expected/umd.js b/test/form/samples/side-effects-generators/_expected/umd.js deleted file mode 100644 index 44149f8c116..00000000000 --- a/test/form/samples/side-effects-generators/_expected/umd.js +++ /dev/null @@ -1,31 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - function* sideEffectYield() { - yield globalFunction(); - yield 'no side-effect but must be included to ensure proper control flow'; - } - - const iterator2 = sideEffectYield(); - - function* effectCallYield() { - const yieldedValue = yield; - yieldedValue(); - } - - const iterator3 = effectCallYield(); - iterator3.next(globalFunction); - - function* sideEffectYield2() { - yield globalFunction(); - } - - function* sideEffectNestedYield() { - yield* sideEffectYield2(); - } - - const iterator4 = sideEffectNestedYield(); - -})); diff --git a/test/form/samples/side-effects-generators/main.js b/test/form/samples/side-effects-generators/main.js index 0387aed7770..ac53f9614fd 100644 --- a/test/form/samples/side-effects-generators/main.js +++ b/test/form/samples/side-effects-generators/main.js @@ -8,7 +8,7 @@ function* noEffects() { const iterator1 = noEffects(); function* sideEffectYield() { - yield globalFunction(); + yield globalThis.unknown(); yield 'no side-effect but must be included to ensure proper control flow'; } @@ -20,10 +20,10 @@ function* effectCallYield() { } const iterator3 = effectCallYield(); -iterator3.next(globalFunction); +iterator3.next(globalThis.unknown); function* sideEffectYield2() { - yield globalFunction(); + yield globalThis.unknown(); } function* sideEffectNestedYield() { diff --git a/test/form/samples/side-effects-in-template-literals/_expected/es.js b/test/form/samples/side-effects-in-template-literals/_expected.js similarity index 66% rename from test/form/samples/side-effects-in-template-literals/_expected/es.js rename to test/form/samples/side-effects-in-template-literals/_expected.js index df1d707aaf1..a0ea948e4db 100644 --- a/test/form/samples/side-effects-in-template-literals/_expected/es.js +++ b/test/form/samples/side-effects-in-template-literals/_expected.js @@ -6,15 +6,15 @@ function modifyX () { return x++; } -const b = `${globalFunction()}has effects`; +const b = `${globalThis.unknown()}has effects`; const c = `${modifyX()}has effects`; -const e = noEffects`${globalFunction()}has effects`; +const e = noEffects`${globalThis.unknown()}has effects`; const f = noEffects`${modifyX()}has effects`; -const g = globalFunction`has effects`; +const g = globalThis.unknown`has effects`; const h = (() => { console.log( 'effect' ); diff --git a/test/form/samples/side-effects-in-template-literals/_expected/amd.js b/test/form/samples/side-effects-in-template-literals/_expected/amd.js deleted file mode 100644 index 2de49f2bac1..00000000000 --- a/test/form/samples/side-effects-in-template-literals/_expected/amd.js +++ /dev/null @@ -1,30 +0,0 @@ -define(['exports'], function (exports) { 'use strict'; - - exports.x = 0; - - function noEffects () {} - - function modifyX () { - return exports.x++; - } - - const b = `${globalFunction()}has effects`; - - const c = `${modifyX()}has effects`; - - const e = noEffects`${globalFunction()}has effects`; - - const f = noEffects`${modifyX()}has effects`; - - const g = globalFunction`has effects`; - - const h = (() => { - console.log( 'effect' ); - return () => {}; - })()`has effects`; - - const i = modifyX`has effects`; - - Object.defineProperty(exports, '__esModule', { value: true }); - -}); diff --git a/test/form/samples/side-effects-in-template-literals/_expected/cjs.js b/test/form/samples/side-effects-in-template-literals/_expected/cjs.js deleted file mode 100644 index 0983d23a3a4..00000000000 --- a/test/form/samples/side-effects-in-template-literals/_expected/cjs.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { value: true }); - -exports.x = 0; - -function noEffects () {} - -function modifyX () { - return exports.x++; -} - -const b = `${globalFunction()}has effects`; - -const c = `${modifyX()}has effects`; - -const e = noEffects`${globalFunction()}has effects`; - -const f = noEffects`${modifyX()}has effects`; - -const g = globalFunction`has effects`; - -const h = (() => { - console.log( 'effect' ); - return () => {}; -})()`has effects`; - -const i = modifyX`has effects`; diff --git a/test/form/samples/side-effects-in-template-literals/_expected/iife.js b/test/form/samples/side-effects-in-template-literals/_expected/iife.js deleted file mode 100644 index 79ce9135036..00000000000 --- a/test/form/samples/side-effects-in-template-literals/_expected/iife.js +++ /dev/null @@ -1,31 +0,0 @@ -var myBundle = (function (exports) { - 'use strict'; - - exports.x = 0; - - function noEffects () {} - - function modifyX () { - return exports.x++; - } - - const b = `${globalFunction()}has effects`; - - const c = `${modifyX()}has effects`; - - const e = noEffects`${globalFunction()}has effects`; - - const f = noEffects`${modifyX()}has effects`; - - const g = globalFunction`has effects`; - - const h = (() => { - console.log( 'effect' ); - return () => {}; - })()`has effects`; - - const i = modifyX`has effects`; - - return exports; - -}({})); diff --git a/test/form/samples/side-effects-in-template-literals/_expected/system.js b/test/form/samples/side-effects-in-template-literals/_expected/system.js deleted file mode 100644 index fefc9b90a87..00000000000 --- a/test/form/samples/side-effects-in-template-literals/_expected/system.js +++ /dev/null @@ -1,33 +0,0 @@ -System.register('myBundle', [], function (exports) { - 'use strict'; - return { - execute: function () { - - let x = exports('x', 0); - - function noEffects () {} - - function modifyX () { - return (exports('x', x + 1), x++); - } - - const b = `${globalFunction()}has effects`; - - const c = `${modifyX()}has effects`; - - const e = noEffects`${globalFunction()}has effects`; - - const f = noEffects`${modifyX()}has effects`; - - const g = globalFunction`has effects`; - - const h = (() => { - console.log( 'effect' ); - return () => {}; - })()`has effects`; - - const i = modifyX`has effects`; - - } - }; -}); diff --git a/test/form/samples/side-effects-in-template-literals/_expected/umd.js b/test/form/samples/side-effects-in-template-literals/_expected/umd.js deleted file mode 100644 index c210dbbd554..00000000000 --- a/test/form/samples/side-effects-in-template-literals/_expected/umd.js +++ /dev/null @@ -1,34 +0,0 @@ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (global = global || self, factory(global.myBundle = {})); -}(this, function (exports) { 'use strict'; - - exports.x = 0; - - function noEffects () {} - - function modifyX () { - return exports.x++; - } - - const b = `${globalFunction()}has effects`; - - const c = `${modifyX()}has effects`; - - const e = noEffects`${globalFunction()}has effects`; - - const f = noEffects`${modifyX()}has effects`; - - const g = globalFunction`has effects`; - - const h = (() => { - console.log( 'effect' ); - return () => {}; - })()`has effects`; - - const i = modifyX`has effects`; - - Object.defineProperty(exports, '__esModule', { value: true }); - -})); diff --git a/test/form/samples/side-effects-in-template-literals/main.js b/test/form/samples/side-effects-in-template-literals/main.js index dc5a4dbfaa5..dd07f243420 100644 --- a/test/form/samples/side-effects-in-template-literals/main.js +++ b/test/form/samples/side-effects-in-template-literals/main.js @@ -8,17 +8,17 @@ function modifyX () { const a = `${noEffects()}is removed`; -const b = `${globalFunction()}has effects`; +const b = `${globalThis.unknown()}has effects`; const c = `${modifyX()}has effects`; const d = noEffects`is removed`; -const e = noEffects`${globalFunction()}has effects`; +const e = noEffects`${globalThis.unknown()}has effects`; const f = noEffects`${modifyX()}has effects`; -const g = globalFunction`has effects`; +const g = globalThis.unknown`has effects`; const h = (() => { console.log( 'effect' ); diff --git a/test/form/samples/side-effects-object-literal-mutation/_expected/es.js b/test/form/samples/side-effects-object-literal-mutation/_expected.js similarity index 89% rename from test/form/samples/side-effects-object-literal-mutation/_expected/es.js rename to test/form/samples/side-effects-object-literal-mutation/_expected.js index 393144c9da4..f42a72e8a66 100644 --- a/test/form/samples/side-effects-object-literal-mutation/_expected/es.js +++ b/test/form/samples/side-effects-object-literal-mutation/_expected.js @@ -19,7 +19,7 @@ const retained6 = { x: { y: {} } }; retained6.x = {}; retained6.x.y.z = 3; -const retained7 = { x: { y: globalVar } }; +const retained7 = { x: { y: globalThis.unknown } }; const retained8 = { x: retained7.x }; retained8.x.y.z = 3; diff --git a/test/form/samples/side-effects-object-literal-mutation/_expected/amd.js b/test/form/samples/side-effects-object-literal-mutation/_expected/amd.js deleted file mode 100644 index 7d706cf2c6f..00000000000 --- a/test/form/samples/side-effects-object-literal-mutation/_expected/amd.js +++ /dev/null @@ -1,32 +0,0 @@ -define(['exports'], function (exports) { 'use strict'; - - const retained1 = { x: {} }; - retained1.y = 1; - retained1.x.y = 2; - - const retained2 = { x: {} }; - retained2.y.z = 1; - - const retained3 = { x: {} }; - delete retained3.x; - retained3.x.y = 2; - - const retained4 = { x: undefined }; - retained4.x.y = 2; - - const retained5 = { x: null }; - retained5.x.y = 2; - - const retained6 = { x: { y: {} } }; - retained6.x = {}; - retained6.x.y.z = 3; - - const retained7 = { x: { y: globalVar } }; - const retained8 = { x: retained7.x }; - retained8.x.y.z = 3; - - exports.retained1 = retained1; - - Object.defineProperty(exports, '__esModule', { value: true }); - -}); diff --git a/test/form/samples/side-effects-object-literal-mutation/_expected/cjs.js b/test/form/samples/side-effects-object-literal-mutation/_expected/cjs.js deleted file mode 100644 index 0629a3d2883..00000000000 --- a/test/form/samples/side-effects-object-literal-mutation/_expected/cjs.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { value: true }); - -const retained1 = { x: {} }; -retained1.y = 1; -retained1.x.y = 2; - -const retained2 = { x: {} }; -retained2.y.z = 1; - -const retained3 = { x: {} }; -delete retained3.x; -retained3.x.y = 2; - -const retained4 = { x: undefined }; -retained4.x.y = 2; - -const retained5 = { x: null }; -retained5.x.y = 2; - -const retained6 = { x: { y: {} } }; -retained6.x = {}; -retained6.x.y.z = 3; - -const retained7 = { x: { y: globalVar } }; -const retained8 = { x: retained7.x }; -retained8.x.y.z = 3; - -exports.retained1 = retained1; diff --git a/test/form/samples/side-effects-object-literal-mutation/_expected/iife.js b/test/form/samples/side-effects-object-literal-mutation/_expected/iife.js deleted file mode 100644 index 64a2bffe83d..00000000000 --- a/test/form/samples/side-effects-object-literal-mutation/_expected/iife.js +++ /dev/null @@ -1,33 +0,0 @@ -var bundle = (function (exports) { - 'use strict'; - - const retained1 = { x: {} }; - retained1.y = 1; - retained1.x.y = 2; - - const retained2 = { x: {} }; - retained2.y.z = 1; - - const retained3 = { x: {} }; - delete retained3.x; - retained3.x.y = 2; - - const retained4 = { x: undefined }; - retained4.x.y = 2; - - const retained5 = { x: null }; - retained5.x.y = 2; - - const retained6 = { x: { y: {} } }; - retained6.x = {}; - retained6.x.y.z = 3; - - const retained7 = { x: { y: globalVar } }; - const retained8 = { x: retained7.x }; - retained8.x.y.z = 3; - - exports.retained1 = retained1; - - return exports; - -}({})); diff --git a/test/form/samples/side-effects-object-literal-mutation/_expected/system.js b/test/form/samples/side-effects-object-literal-mutation/_expected/system.js deleted file mode 100644 index 547c993047c..00000000000 --- a/test/form/samples/side-effects-object-literal-mutation/_expected/system.js +++ /dev/null @@ -1,33 +0,0 @@ -System.register('bundle', [], function (exports) { - 'use strict'; - return { - execute: function () { - - const retained1 = exports('retained1', { x: {} }); - retained1.y = 1; - retained1.x.y = 2; - - const retained2 = { x: {} }; - retained2.y.z = 1; - - const retained3 = { x: {} }; - delete retained3.x; - retained3.x.y = 2; - - const retained4 = { x: undefined }; - retained4.x.y = 2; - - const retained5 = { x: null }; - retained5.x.y = 2; - - const retained6 = { x: { y: {} } }; - retained6.x = {}; - retained6.x.y.z = 3; - - const retained7 = { x: { y: globalVar } }; - const retained8 = { x: retained7.x }; - retained8.x.y.z = 3; - - } - }; -}); diff --git a/test/form/samples/side-effects-object-literal-mutation/_expected/umd.js b/test/form/samples/side-effects-object-literal-mutation/_expected/umd.js deleted file mode 100644 index d5a59658254..00000000000 --- a/test/form/samples/side-effects-object-literal-mutation/_expected/umd.js +++ /dev/null @@ -1,36 +0,0 @@ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (global = global || self, factory(global.bundle = {})); -}(this, function (exports) { 'use strict'; - - const retained1 = { x: {} }; - retained1.y = 1; - retained1.x.y = 2; - - const retained2 = { x: {} }; - retained2.y.z = 1; - - const retained3 = { x: {} }; - delete retained3.x; - retained3.x.y = 2; - - const retained4 = { x: undefined }; - retained4.x.y = 2; - - const retained5 = { x: null }; - retained5.x.y = 2; - - const retained6 = { x: { y: {} } }; - retained6.x = {}; - retained6.x.y.z = 3; - - const retained7 = { x: { y: globalVar } }; - const retained8 = { x: retained7.x }; - retained8.x.y.z = 3; - - exports.retained1 = retained1; - - Object.defineProperty(exports, '__esModule', { value: true }); - -})); diff --git a/test/form/samples/side-effects-object-literal-mutation/main.js b/test/form/samples/side-effects-object-literal-mutation/main.js index f4acf425e91..a0a465fda19 100644 --- a/test/form/samples/side-effects-object-literal-mutation/main.js +++ b/test/form/samples/side-effects-object-literal-mutation/main.js @@ -26,10 +26,10 @@ const retained6 = { x: { y: {} } }; retained6.x = {}; retained6.x.y.z = 3; -const retained7 = { x: { y: globalVar } }; +const retained7 = { x: { y: globalThis.unknown } }; const retained8 = { x: retained7.x }; retained8.x.y.z = 3; -const removed3 = { a: { x: { y: globalVar } } }; +const removed3 = { a: { x: { y: globalThis.unknown } } }; const removed4 = { x: removed3.a.x }; removed4.x.y = 2; diff --git a/test/form/samples/side-effects-pattern-assignment/_expected.js b/test/form/samples/side-effects-pattern-assignment/_expected.js new file mode 100644 index 00000000000..16c6cefd9c2 --- /dev/null +++ b/test/form/samples/side-effects-pattern-assignment/_expected.js @@ -0,0 +1,27 @@ +var e = {}; +({x: e} = globalThis.unknown); +e.foo = 1; + +var f = {}; +({f} = globalThis.unknown); +f.foo = 1; + +var {x: g} = globalThis.unknown; +g.foo = 1; + +var {h} = globalThis.unknown; +h.foo = 1; + +var m = {}; +[m] = globalThis.unknown; +m.foo = 1; + +var [n] = globalThis.unknown; +n.foo = 1; + +var o = {}; +[...o] = globalThis.unknown; +o.foo = 1; + +var [...p] = globalThis.unknown; +p.foo = 1; diff --git a/test/form/samples/side-effects-pattern-assignment/_expected/amd.js b/test/form/samples/side-effects-pattern-assignment/_expected/amd.js deleted file mode 100644 index da086a80181..00000000000 --- a/test/form/samples/side-effects-pattern-assignment/_expected/amd.js +++ /dev/null @@ -1,31 +0,0 @@ -define(function () { 'use strict'; - - var e = {}; - ({x: e} = globalVar); - e.foo = 1; - - var f = {}; - ({f} = globalVar); - f.foo = 1; - - var {x: g} = globalVar; - g.foo = 1; - - var {h} = globalVar; - h.foo = 1; - - var m = {}; - [m] = globalVar; - m.foo = 1; - - var [n] = globalVar; - n.foo = 1; - - var o = {}; - [...o] = globalVar; - o.foo = 1; - - var [...p] = globalVar; - p.foo = 1; - -}); diff --git a/test/form/samples/side-effects-pattern-assignment/_expected/cjs.js b/test/form/samples/side-effects-pattern-assignment/_expected/cjs.js deleted file mode 100644 index d6944ae84fc..00000000000 --- a/test/form/samples/side-effects-pattern-assignment/_expected/cjs.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -var e = {}; -({x: e} = globalVar); -e.foo = 1; - -var f = {}; -({f} = globalVar); -f.foo = 1; - -var {x: g} = globalVar; -g.foo = 1; - -var {h} = globalVar; -h.foo = 1; - -var m = {}; -[m] = globalVar; -m.foo = 1; - -var [n] = globalVar; -n.foo = 1; - -var o = {}; -[...o] = globalVar; -o.foo = 1; - -var [...p] = globalVar; -p.foo = 1; diff --git a/test/form/samples/side-effects-pattern-assignment/_expected/es.js b/test/form/samples/side-effects-pattern-assignment/_expected/es.js deleted file mode 100644 index 13cd82699ae..00000000000 --- a/test/form/samples/side-effects-pattern-assignment/_expected/es.js +++ /dev/null @@ -1,27 +0,0 @@ -var e = {}; -({x: e} = globalVar); -e.foo = 1; - -var f = {}; -({f} = globalVar); -f.foo = 1; - -var {x: g} = globalVar; -g.foo = 1; - -var {h} = globalVar; -h.foo = 1; - -var m = {}; -[m] = globalVar; -m.foo = 1; - -var [n] = globalVar; -n.foo = 1; - -var o = {}; -[...o] = globalVar; -o.foo = 1; - -var [...p] = globalVar; -p.foo = 1; diff --git a/test/form/samples/side-effects-pattern-assignment/_expected/iife.js b/test/form/samples/side-effects-pattern-assignment/_expected/iife.js deleted file mode 100644 index 68658b6d48f..00000000000 --- a/test/form/samples/side-effects-pattern-assignment/_expected/iife.js +++ /dev/null @@ -1,32 +0,0 @@ -(function () { - 'use strict'; - - var e = {}; - ({x: e} = globalVar); - e.foo = 1; - - var f = {}; - ({f} = globalVar); - f.foo = 1; - - var {x: g} = globalVar; - g.foo = 1; - - var {h} = globalVar; - h.foo = 1; - - var m = {}; - [m] = globalVar; - m.foo = 1; - - var [n] = globalVar; - n.foo = 1; - - var o = {}; - [...o] = globalVar; - o.foo = 1; - - var [...p] = globalVar; - p.foo = 1; - -}()); diff --git a/test/form/samples/side-effects-pattern-assignment/_expected/system.js b/test/form/samples/side-effects-pattern-assignment/_expected/system.js deleted file mode 100644 index edcecf4d5f9..00000000000 --- a/test/form/samples/side-effects-pattern-assignment/_expected/system.js +++ /dev/null @@ -1,36 +0,0 @@ -System.register([], function () { - 'use strict'; - return { - execute: function () { - - var e = {}; - ({x: e} = globalVar); - e.foo = 1; - - var f = {}; - ({f} = globalVar); - f.foo = 1; - - var {x: g} = globalVar; - g.foo = 1; - - var {h} = globalVar; - h.foo = 1; - - var m = {}; - [m] = globalVar; - m.foo = 1; - - var [n] = globalVar; - n.foo = 1; - - var o = {}; - [...o] = globalVar; - o.foo = 1; - - var [...p] = globalVar; - p.foo = 1; - - } - }; -}); diff --git a/test/form/samples/side-effects-pattern-assignment/_expected/umd.js b/test/form/samples/side-effects-pattern-assignment/_expected/umd.js deleted file mode 100644 index 1a084c714d2..00000000000 --- a/test/form/samples/side-effects-pattern-assignment/_expected/umd.js +++ /dev/null @@ -1,34 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - var e = {}; - ({x: e} = globalVar); - e.foo = 1; - - var f = {}; - ({f} = globalVar); - f.foo = 1; - - var {x: g} = globalVar; - g.foo = 1; - - var {h} = globalVar; - h.foo = 1; - - var m = {}; - [m] = globalVar; - m.foo = 1; - - var [n] = globalVar; - n.foo = 1; - - var o = {}; - [...o] = globalVar; - o.foo = 1; - - var [...p] = globalVar; - p.foo = 1; - -})); diff --git a/test/form/samples/side-effects-pattern-assignment/main.js b/test/form/samples/side-effects-pattern-assignment/main.js index 66f24a40ec8..a86b215304b 100644 --- a/test/form/samples/side-effects-pattern-assignment/main.js +++ b/test/form/samples/side-effects-pattern-assignment/main.js @@ -1,47 +1,47 @@ var a = {}; -({x: a} = globalVar); +({x: a} = globalThis.unknown); var b = {}; -({b} = globalVar); +({b} = globalThis.unknown); -var {x: c} = globalVar; +var {x: c} = globalThis.unknown; -var {d} = globalVar; +var {d} = globalThis.unknown; var e = {}; -({x: e} = globalVar); +({x: e} = globalThis.unknown); e.foo = 1; var f = {}; -({f} = globalVar); +({f} = globalThis.unknown); f.foo = 1; -var {x: g} = globalVar; +var {x: g} = globalThis.unknown; g.foo = 1; -var {h} = globalVar; +var {h} = globalThis.unknown; h.foo = 1; var i = {}; -[i] = globalVar; +[i] = globalThis.unknown; -var [j] = globalVar; +var [j] = globalThis.unknown; var k = {}; -[,...k] = globalVar; +[,...k] = globalThis.unknown; -var [,...l] = globalVar; +var [,...l] = globalThis.unknown; var m = {}; -[m] = globalVar; +[m] = globalThis.unknown; m.foo = 1; -var [n] = globalVar; +var [n] = globalThis.unknown; n.foo = 1; var o = {}; -[...o] = globalVar; +[...o] = globalThis.unknown; o.foo = 1; -var [...p] = globalVar; +var [...p] = globalThis.unknown; p.foo = 1; diff --git a/test/form/samples/side-effects-switch-statements/_expected/es.js b/test/form/samples/side-effects-switch-statements/_expected.js similarity index 52% rename from test/form/samples/side-effects-switch-statements/_expected/es.js rename to test/form/samples/side-effects-switch-statements/_expected.js index 6df30c21be2..1637398c2b5 100644 --- a/test/form/samples/side-effects-switch-statements/_expected/es.js +++ b/test/form/samples/side-effects-switch-statements/_expected.js @@ -2,30 +2,30 @@ function effect () { console.log( 'effect' ); } -switch ( globalVar ) { - case foo: - case bar: +switch ( globalThis.unknown ) { + case 'foo': + case 'bar': effect(); - if ( globalVar > 1 ) { + if ( globalThis.unknown > 1 ) { break; } - case baz: + case 'baz': effect(); default: } -switch ( globalVar ) { - case foo: +switch ( globalThis.unknown ) { + case 'foo': break; - case bar: + case 'bar': effect(); default: effect(); } (function nestedSwitchWithEffects () { - switch ( globalVar ) { + switch ( globalThis.unknown ) { default: effect(); } diff --git a/test/form/samples/side-effects-switch-statements/_expected/amd.js b/test/form/samples/side-effects-switch-statements/_expected/amd.js deleted file mode 100644 index 1c564b9058d..00000000000 --- a/test/form/samples/side-effects-switch-statements/_expected/amd.js +++ /dev/null @@ -1,36 +0,0 @@ -define(function () { 'use strict'; - - function effect () { - console.log( 'effect' ); - } - - switch ( globalVar ) { - case foo: - case bar: - effect(); - if ( globalVar > 1 ) { - break; - } - case baz: - effect(); - default: - - } - - switch ( globalVar ) { - case foo: - break; - case bar: - effect(); - default: - effect(); - } - - (function nestedSwitchWithEffects () { - switch ( globalVar ) { - default: - effect(); - } - }()); - -}); diff --git a/test/form/samples/side-effects-switch-statements/_expected/cjs.js b/test/form/samples/side-effects-switch-statements/_expected/cjs.js deleted file mode 100644 index b38e20d2b8f..00000000000 --- a/test/form/samples/side-effects-switch-statements/_expected/cjs.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -function effect () { - console.log( 'effect' ); -} - -switch ( globalVar ) { - case foo: - case bar: - effect(); - if ( globalVar > 1 ) { - break; - } - case baz: - effect(); - default: - -} - -switch ( globalVar ) { - case foo: - break; - case bar: - effect(); - default: - effect(); -} - -(function nestedSwitchWithEffects () { - switch ( globalVar ) { - default: - effect(); - } -}()); diff --git a/test/form/samples/side-effects-switch-statements/_expected/iife.js b/test/form/samples/side-effects-switch-statements/_expected/iife.js deleted file mode 100644 index 6273f69b404..00000000000 --- a/test/form/samples/side-effects-switch-statements/_expected/iife.js +++ /dev/null @@ -1,37 +0,0 @@ -(function () { - 'use strict'; - - function effect () { - console.log( 'effect' ); - } - - switch ( globalVar ) { - case foo: - case bar: - effect(); - if ( globalVar > 1 ) { - break; - } - case baz: - effect(); - default: - - } - - switch ( globalVar ) { - case foo: - break; - case bar: - effect(); - default: - effect(); - } - - (function nestedSwitchWithEffects () { - switch ( globalVar ) { - default: - effect(); - } - }()); - -}()); diff --git a/test/form/samples/side-effects-switch-statements/_expected/system.js b/test/form/samples/side-effects-switch-statements/_expected/system.js deleted file mode 100644 index ae86e4931f4..00000000000 --- a/test/form/samples/side-effects-switch-statements/_expected/system.js +++ /dev/null @@ -1,41 +0,0 @@ -System.register('myBundle', [], function () { - 'use strict'; - return { - execute: function () { - - function effect () { - console.log( 'effect' ); - } - - switch ( globalVar ) { - case foo: - case bar: - effect(); - if ( globalVar > 1 ) { - break; - } - case baz: - effect(); - default: - - } - - switch ( globalVar ) { - case foo: - break; - case bar: - effect(); - default: - effect(); - } - - (function nestedSwitchWithEffects () { - switch ( globalVar ) { - default: - effect(); - } - }()); - - } - }; -}); diff --git a/test/form/samples/side-effects-switch-statements/_expected/umd.js b/test/form/samples/side-effects-switch-statements/_expected/umd.js deleted file mode 100644 index 1425498a1dd..00000000000 --- a/test/form/samples/side-effects-switch-statements/_expected/umd.js +++ /dev/null @@ -1,39 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - function effect () { - console.log( 'effect' ); - } - - switch ( globalVar ) { - case foo: - case bar: - effect(); - if ( globalVar > 1 ) { - break; - } - case baz: - effect(); - default: - - } - - switch ( globalVar ) { - case foo: - break; - case bar: - effect(); - default: - effect(); - } - - (function nestedSwitchWithEffects () { - switch ( globalVar ) { - default: - effect(); - } - }()); - -})); diff --git a/test/form/samples/side-effects-switch-statements/main.js b/test/form/samples/side-effects-switch-statements/main.js index 460df2e1c92..306c82ecf5c 100644 --- a/test/form/samples/side-effects-switch-statements/main.js +++ b/test/form/samples/side-effects-switch-statements/main.js @@ -4,43 +4,43 @@ function effect () { console.log( 'effect' ); } -switch ( globalVar ) { - case foo: - case bar: +switch ( globalThis.unknown ) { + case 'foo': + case 'bar': effect(); noEffect(); - if ( globalVar > 1 ) { + if ( globalThis.unknown > 1 ) { break; } - case baz: + case 'baz': effect(); default: noEffect(); } -switch ( globalVar ) { - case foo: +switch ( globalThis.unknown ) { + case 'foo': noEffect(); break; - case bar: + case 'bar': effect(); default: effect(); } (function nestedSwitchWithEffects () { - switch ( globalVar ) { + switch ( globalThis.unknown ) { default: effect(); } }()); (function nestedSwitchWithoutEffects () { - switch ( globalVar ) { - case foo: + switch ( globalThis.unknown ) { + case 'foo': noEffect(); break; - case bar: + case 'bar': default: } }()); diff --git a/test/form/samples/switch-scopes/_expected.js b/test/form/samples/switch-scopes/_expected.js new file mode 100644 index 00000000000..4dcd34c1b95 --- /dev/null +++ b/test/form/samples/switch-scopes/_expected.js @@ -0,0 +1,10 @@ +const x = globalThis.unknown; + +switch ( globalThis.unknown ) { + case 2: + x(); +} + +switch ( globalThis.unknown() ) { + case 4: +} diff --git a/test/form/samples/switch-scopes/_expected/amd.js b/test/form/samples/switch-scopes/_expected/amd.js deleted file mode 100644 index b4615ca613e..00000000000 --- a/test/form/samples/switch-scopes/_expected/amd.js +++ /dev/null @@ -1,14 +0,0 @@ -define(function () { 'use strict'; - - const x = globalFunction; - - switch ( anotherGlobal ) { - case 2: - x(); - } - - switch ( globalFunction() ) { - case 4: - } - -}); diff --git a/test/form/samples/switch-scopes/_expected/cjs.js b/test/form/samples/switch-scopes/_expected/cjs.js deleted file mode 100644 index a56193c4057..00000000000 --- a/test/form/samples/switch-scopes/_expected/cjs.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -const x = globalFunction; - -switch ( anotherGlobal ) { - case 2: - x(); -} - -switch ( globalFunction() ) { - case 4: -} diff --git a/test/form/samples/switch-scopes/_expected/es.js b/test/form/samples/switch-scopes/_expected/es.js deleted file mode 100644 index 43d842d3ade..00000000000 --- a/test/form/samples/switch-scopes/_expected/es.js +++ /dev/null @@ -1,10 +0,0 @@ -const x = globalFunction; - -switch ( anotherGlobal ) { - case 2: - x(); -} - -switch ( globalFunction() ) { - case 4: -} diff --git a/test/form/samples/switch-scopes/_expected/iife.js b/test/form/samples/switch-scopes/_expected/iife.js deleted file mode 100644 index 8ecee29b379..00000000000 --- a/test/form/samples/switch-scopes/_expected/iife.js +++ /dev/null @@ -1,15 +0,0 @@ -(function () { - 'use strict'; - - const x = globalFunction; - - switch ( anotherGlobal ) { - case 2: - x(); - } - - switch ( globalFunction() ) { - case 4: - } - -}()); diff --git a/test/form/samples/switch-scopes/_expected/system.js b/test/form/samples/switch-scopes/_expected/system.js deleted file mode 100644 index 673438e124c..00000000000 --- a/test/form/samples/switch-scopes/_expected/system.js +++ /dev/null @@ -1,19 +0,0 @@ -System.register('myBundle', [], function () { - 'use strict'; - return { - execute: function () { - - const x = globalFunction; - - switch ( anotherGlobal ) { - case 2: - x(); - } - - switch ( globalFunction() ) { - case 4: - } - - } - }; -}); diff --git a/test/form/samples/switch-scopes/_expected/umd.js b/test/form/samples/switch-scopes/_expected/umd.js deleted file mode 100644 index 9d4e6d912d5..00000000000 --- a/test/form/samples/switch-scopes/_expected/umd.js +++ /dev/null @@ -1,17 +0,0 @@ -(function (factory) { - typeof define === 'function' && define.amd ? define(factory) : - factory(); -}(function () { 'use strict'; - - const x = globalFunction; - - switch ( anotherGlobal ) { - case 2: - x(); - } - - switch ( globalFunction() ) { - case 4: - } - -})); diff --git a/test/form/samples/switch-scopes/main.js b/test/form/samples/switch-scopes/main.js index 092ec07c8b2..7441a56389b 100644 --- a/test/form/samples/switch-scopes/main.js +++ b/test/form/samples/switch-scopes/main.js @@ -1,23 +1,23 @@ -const x = globalFunction; +const x = globalThis.unknown; function y () {} -switch ( anotherGlobal ) { +switch ( globalThis.unknown ) { case 1: const x = function () {}; x(); } -switch ( anotherGlobal ) { +switch ( globalThis.unknown ) { case 2: x(); } -switch ( anotherGlobal ) { +switch ( globalThis.unknown ) { case 3: - const y = globalFunction; + const y = globalThis.unknown; } y(); -switch ( globalFunction() ) { +switch ( globalThis.unknown() ) { case 4: } diff --git a/test/form/samples/treeshake-excess-arguments/unused-parameters/_expected.js b/test/form/samples/treeshake-excess-arguments/unused-parameters/_expected.js index 74123e6973b..256b223b12a 100644 --- a/test/form/samples/treeshake-excess-arguments/unused-parameters/_expected.js +++ b/test/form/samples/treeshake-excess-arguments/unused-parameters/_expected.js @@ -1,11 +1,11 @@ -function test(a, b = global(), c) {} +function test(a, b = globalThis.unknown(), c) {} test(1, 2); function noEffect() {} -test(1, 2, noEffect(), global()); +test(1, 2, noEffect(), globalThis.unknown()); -const testArr = (a, b = global(), c) => {}; +const testArr = (a, b = globalThis.unknown(), c) => {}; testArr(1, 2); function noEffectArr() {} -testArr(1, 2, noEffectArr(), global()); +testArr(1, 2, noEffectArr(), globalThis.unknown()); diff --git a/test/form/samples/treeshake-excess-arguments/unused-parameters/main.js b/test/form/samples/treeshake-excess-arguments/unused-parameters/main.js index 43ad6a6100f..d41208d34f8 100644 --- a/test/form/samples/treeshake-excess-arguments/unused-parameters/main.js +++ b/test/form/samples/treeshake-excess-arguments/unused-parameters/main.js @@ -1,15 +1,15 @@ -function test(a, b = global(), c) {} +function test(a, b = globalThis.unknown(), c) {} const someStuff = {x: 1}; test(1, 2, 3, someStuff); function noEffect() {} -test(1, 2, noEffect(), global()); +test(1, 2, noEffect(), globalThis.unknown()); -const testArr = (a, b = global(), c) => {} +const testArr = (a, b = globalThis.unknown(), c) => {} const someStuffArr = {x: 1}; testArr(1, 2, 3, someStuffArr); function noEffectArr() {} -testArr(1, 2, noEffectArr(), global()); +testArr(1, 2, noEffectArr(), globalThis.unknown()); diff --git a/test/function/samples/unknown-global-side-effects/_config.js b/test/function/samples/unknown-global-side-effects/_config.js new file mode 100644 index 00000000000..41910fe91d2 --- /dev/null +++ b/test/function/samples/unknown-global-side-effects/_config.js @@ -0,0 +1,14 @@ +module.exports = { + description: 'does not omit side-effects from unknown globals', + exports(exports) { + let error; + try { + exports.max(1, 2); + } catch (err) { + error = err; + } + if (!(error instanceof ReferenceError)) { + throw new Error('Expected a ReferenceError to be thrown.'); + } + } +}; diff --git a/test/function/samples/unknown-global-side-effects/main.js b/test/function/samples/unknown-global-side-effects/main.js new file mode 100644 index 00000000000..a59f24aac1f --- /dev/null +++ b/test/function/samples/unknown-global-side-effects/main.js @@ -0,0 +1,7 @@ +function myMax(a, b) { + return Math.max(a, b); +} + +export function max(a, b) { + return myMax(a, b, doesNotExist); +} diff --git a/test/function/samples/wraps-simplified-expressions/main.js b/test/function/samples/wraps-simplified-expressions/main.js index edeac8d4c45..560aedd2b8a 100644 --- a/test/function/samples/wraps-simplified-expressions/main.js +++ b/test/function/samples/wraps-simplified-expressions/main.js @@ -1,6 +1,6 @@ const wrapper = { foo() { - assert.notEqual(this, wrapper) + assert.notEqual(this, wrapper); } }; @@ -12,11 +12,16 @@ const wrapper = { (true && (true ? wrapper.foo : null))(); (true && (1, 2, wrapper.foo))(); +function evoke(callee, arg) { + return callee(arg); +} + // Indirectly invoked eval is executed in the global scope function testEval() { assert.notEqual((true && eval)('this'), 'test'); assert.notEqual((true ? eval : null)('this'), 'test'); assert.notEqual((1, 2, eval)('this'), 'test'); + assert.equal(evoke(true && eval, '42'), '42'); } testEval.call('test');