From fa68cbd74ad2b36c0f1aaec563320114d5603cae Mon Sep 17 00:00:00 2001 From: magic-akari Date: Mon, 27 Jun 2022 20:32:06 +0800 Subject: [PATCH] refactor(es/module): Implement new module transformer (#4758) --- Cargo.lock | 3 + crates/swc/src/builder.rs | 43 +- crates/swc/src/config/mod.rs | 94 +- crates/swc/tests/exec.rs | 6 +- .../codegen/escape/case-1/output/index.js | 8 +- .../codegen/escape/case-2/output/index.js | 8 +- .../deno/paths/cjs-001/output/index.ts | 3 + .../issue-2126/output/packages/a/src/index.ts | 5 +- .../deno/paths/issue-2126/output/src/index.ts | 7 +- .../issue-2724/output/packages/a/src/index.ts | 5 +- .../deno/paths/issue-2724/output/src/index.ts | 9 +- .../2-cjs/output/src/command/restore.ts | 5 +- .../output/src/core/utils/utilFile.ts | 5 +- .../deno/paths/issue-2844/output/src/index.ts | 3 + .../issue-2844/output/src/utils/index.ts | 9 +- .../fixture/issues-1xxx/1135/1/input/.swcrc | 16 + .../fixture/issues-1xxx/1135/1/input/index.ts | 6 + .../issues-1xxx/1135/1/output/index.ts | 24 + .../fixture/issues-1xxx/1160/output/entry.ts | 11 +- .../fixture/issues-1xxx/1213/output/index.js | 20 +- .../issues-1xxx/1232/cjs/output/index.js | 11 +- .../fixture/issues-1xxx/1259/output/index.js | 7 +- .../fixture/issues-1xxx/1278/output/index.ts | 11 +- .../fixture/issues-1xxx/1307/output/index.ts | 10 +- .../issues-1xxx/1309/case1/output/index.map | 2 +- .../issues-1xxx/1309/case1/output/index.ts | 6 +- .../issues-1xxx/1333/case1/output/index.js | 13 +- .../issues-1xxx/1333/case2/output/index.js | 133 +- .../issues-1xxx/1333/case3/output/index.js | 35 +- .../issues-1xxx/1341/case1/output/index.ts | 9 +- .../issues-1xxx/1362/case1/output/index.ts | 44 +- .../issues-1xxx/1362/case2/output/index.ts | 4 +- .../issues-1xxx/1421/case1/output/index.ts | 15 +- .../issues-1xxx/1423/case1/output/index.js | 3 + .../issues-1xxx/1448/case1/input/.swcrc | 5 +- .../issues-1xxx/1448/case1/output/index.ts | 5 +- .../issues-1xxx/1454/case1/output/index.ts | 8 +- .../issues-1xxx/1454/case2/output/index.ts | 8 +- .../issues-1xxx/1455/case1/output/index.ts | 7 +- .../issues-1xxx/1456/case1/output/index.ts | 59 +- .../issues-1xxx/1456/case2/output/index.ts | 37 +- .../issues-1xxx/1490/case1/output/index.js | 19 +- .../issues-1xxx/1490/full/output/index.js | 37 +- .../issues-1xxx/1515/case1/output/input.ts | 5 +- .../issues-1xxx/1525/case1/output/index.tsx | 7 +- .../issues-1xxx/1554/case1/output/index.js | 22 +- .../issues-1xxx/1554/case2/output/index.js | 29 +- .../issues-1xxx/1568/case1/output/index.ts | 7 +- .../issues-1xxx/1614/case1/output/index.ts | 9 +- .../issues-1xxx/1682/case1/output/index.ts | 13 +- .../issues-1xxx/1682/case2/output/index.ts | 13 +- .../issues-1xxx/1714/case1/output/index.js | 23 +- .../issues-1xxx/1734/case1-B/output/index.js | 7 +- .../issues-1xxx/1734/case2-C/output/index.js | 7 +- .../issues-1xxx/1734/case3-D/output/index.js | 7 +- .../issues-1xxx/1757/case1/output/index.js | 5 +- .../issues-1xxx/1799/case1/output/index.js | 17 +- .../1799/case2-no-loose/output/index.js | 13 +- .../issues-1xxx/1799/case2/output/index.js | 13 +- .../issues-1xxx/1799/case3/output/index.js | 13 +- .../issues-1xxx/1799/case4/output/index.js | 9 +- .../issues-1xxx/1799/case5/output/index.js | 9 +- .../1799/case6-no-jsx/output/index.js | 17 +- .../1799/case7-no-async/output/index.js | 11 +- .../issues-1xxx/1859/case1-js/output/index.js | 29 +- .../issues-1xxx/1859/case2-ts/output/index.ts | 29 +- .../issues-1xxx/1859/case3/output/bar.ts | 8 +- .../issues-1xxx/1859/case3/output/foo.ts | 8 +- .../issues-1xxx/1859/case3/output/index.ts | 9 +- .../issues-1xxx/1859/case3/output/lib.ts | 29 +- .../1918/es5-after-other/output/index.js | 11 +- .../issues-1xxx/1918/es5/output/index.js | 21 +- .../issues-1xxx/1924/case1/output/index.js | 7 +- .../issues-1xxx/1938/cjs/output/index.js | 11 +- .../issues-2xxx/2021/full/output/index.js | 7 +- .../issues-2xxx/2024/full/output/index.js | 11 +- .../fixture/issues-2xxx/2050/output/index.ts | 7 +- .../issues-2xxx/2050/output/subfolder/A.ts | 8 +- .../issues-2xxx/2050/output/subfolder/B.ts | 6 +- .../issues-2xxx/2281/case1/output/index.js | 2 +- .../fixture/issues-2xxx/2372/output/index.js | 7 +- .../issues-2xxx/2428/1/output/index.ts | 31 +- .../issues-2xxx/2539/1/output/index.js | 6 +- .../issues-2xxx/2606/1/output/index.ts | 19 +- .../issues-2xxx/2613/1/output/index.ts | 3 - .../issues-2xxx/2856/1/output/index.js | 9 +- .../issues-2xxx/2858/2/output/index.js | 17 +- .../issues-2xxx/2964/case-2/output/index.ts | 19 +- .../issues-2xxx/2964/case-3/output/index.ts | 7 +- .../issues-2xxx/2964/case-4/output/index.tsx | 6 +- .../issues-3xxx/3272/1/output/index.js | 7 +- .../fixture/issues-3xxx/3337/output/input.ts | 21 +- .../issues-3xxx/3686/1/output/index.ts | 14 +- .../fixture/issues-3xxx/3782/output/index.map | 4 +- .../fixture/issues-3xxx/3782/output/index.ts | 15 +- .../fixture/issues-4xxx/4063/1/input/.swcrc | 12 + .../fixture/issues-4xxx/4063/1/input/index.ts | 10 + .../issues-4xxx/4063/1/output/index.ts | 28 + .../issues-4xxx/4127/1/output/index.ts | 10 +- .../fixture/issues-4xxx/4226/3/output/exec.js | 11 +- .../issues-4xxx/4316/1/output/index.ts | 4 +- .../fixture/issues-4xxx/4896/output/index.ts | 9 +- .../fixture/issues-4xxx/4897/output/index.ts | 18 +- .../fixture/issues-4xxx/4898/output/index.ts | 4 +- .../fixture/issues-4xxx/4899/output/index.ts | 5 +- .../fixture/issues-4xxx/4953/output/index.js | 12 +- .../fixture/issues-4xxx/4988/input/.swcrc | 12 + .../fixture/issues-4xxx/4988/input/index.ts | 3 + .../fixture/issues-4xxx/4988/output/index.ts | 11 + .../fixture/jest/sourcemap-1/output/index.ts | 10 +- .../module/ignore-dynamic/1/output/index.js | 7 +- .../tests/fixture/shopify/001/output/index.js | 9 +- .../tests/fixture/shopify/002/output/index.js | 15 +- .../fixture/shopify/003-env/output/index.js | 15 +- .../fixture/shopify/004-jest/output/index.js | 15 +- .../fixture/sourcemap/001/output/index.map | 2 +- .../fixture/sourcemap/001/output/index.ts | 6 +- .../issue-3854/1-true/output/index.map | 24 +- .../issue-3854/1-true/output/index.ts | 184 +- .../issue-3854/2-inline/output/index.ts | 186 +- crates/swc/tests/projects.rs | 4 +- ...licateExportAssignments_es2015.1.normal.js | 2 +- ...cateExportAssignments_es2015.2.minified.js | 2 +- ...duplicateExportAssignments_es5.1.normal.js | 2 +- ...plicateExportAssignments_es5.2.minified.js | 2 +- ...dulekindWithES5Target10_es2015.1.normal.js | 3 +- ...6modulekindWithES5Target10_es5.1.normal.js | 3 +- ...dulekindWithES5Target10_es2015.1.normal.js | 3 +- ...tmodulekindWithES5Target10_es5.1.normal.js | 3 +- .../exportAssignDottedName_es2015.1.normal.js | 3 +- .../exportAssignDottedName_es5.1.normal.js | 3 +- .../exportNonVisibleType_es2015.1.normal.js | 5 +- .../exportNonVisibleType_es2015.2.minified.js | 9 +- .../exportNonVisibleType_es5.1.normal.js | 5 +- .../exportNonVisibleType_es5.2.minified.js | 5 +- ...essionInExportEqualsAMD_es2015.1.normal.js | 6 +- ...sionInExportEqualsAMD_es2015.2.minified.js | 6 +- ...xpressionInExportEqualsAMD_es5.1.normal.js | 19 +- ...ressionInExportEqualsAMD_es5.2.minified.js | 18 +- ...essionInExportEqualsCJS_es2015.1.normal.js | 6 +- ...sionInExportEqualsCJS_es2015.2.minified.js | 6 +- ...xpressionInExportEqualsCJS_es5.1.normal.js | 19 +- ...ressionInExportEqualsCJS_es5.2.minified.js | 18 +- ...essionInExportEqualsUMD_es2015.1.normal.js | 6 +- ...sionInExportEqualsUMD_es2015.2.minified.js | 6 +- ...xpressionInExportEqualsUMD_es5.1.normal.js | 19 +- ...ressionInExportEqualsUMD_es5.2.minified.js | 18 +- .../importEquals2_es2015.1.normal.js | 3 +- .../importEquals2_es2015.2.minified.js | 2 +- .../importEquals2_es5.1.normal.js | 3 +- .../importEquals2_es5.2.minified.js | 1 + ...tsNotUsedAsValues_error_es2015.1.normal.js | 2 +- ...NotUsedAsValues_error_es2015.2.minified.js | 10 +- ...portsNotUsedAsValues_error_es5.1.normal.js | 2 +- ...rtsNotUsedAsValues_error_es5.2.minified.js | 8 +- .../preserveValueImports_es2015.1.normal.js | 2 + .../preserveValueImports_es2015.2.minified.js | 1 + .../preserveValueImports_es5.1.normal.js | 2 + .../preserveValueImports_es5.2.minified.js | 1 + ...reexportClassDefinition_es2015.1.normal.js | 4 +- ...exportClassDefinition_es2015.2.minified.js | 9 +- .../reexportClassDefinition_es5.1.normal.js | 4 +- .../reexportClassDefinition_es5.2.minified.js | 10 +- .../full/react-autosuggest/1/output/index.js | 3 + .../full/react-autowhatever/1/output/index.js | 13 +- .../full/react-autowhatever/2/output/index.js | 13 +- crates/swc_ecma_ast/src/expr.rs | 27 + crates/swc_ecma_ast/src/module_decl.rs | 22 + .../swc_ecma_preset_env/benches/polyfills.rs | 1 + crates/swc_ecma_preset_env/src/lib.rs | 7 + crates/swc_ecma_preset_env/tests/test.rs | 3 +- crates/swc_ecma_transforms/src/lib.rs | 2 +- .../swc_ecma_transforms/tests/decorators.rs | 25 +- .../tests/es2015_function_name.rs | 22 +- crates/swc_ecma_transforms_base/Cargo.toml | 35 +- .../swc_ecma_transforms_base/src/feature.rs | 246 + .../src/helpers/_export_star.js | 12 + .../src/helpers/mod.rs | 1 + crates/swc_ecma_transforms_base/src/lib.rs | 1 + crates/swc_ecma_transforms_module/Cargo.toml | 1 + crates/swc_ecma_transforms_module/src/amd.rs | 1343 ++-- .../src/common_js.rs | 1602 ++--- .../swc_ecma_transforms_module/src/hoist.rs | 300 - .../src/import_analysis.rs | 207 +- crates/swc_ecma_transforms_module/src/lib.rs | 3 +- .../src/module_decl_strip.rs | 665 ++ .../src/module_ref_rewriter.rs | 139 + crates/swc_ecma_transforms_module/src/umd.rs | 1230 ++-- crates/swc_ecma_transforms_module/src/util.rs | 1214 +--- .../swc_ecma_transforms_module/tests/amd.rs | 1378 +---- .../tests/common_js.rs | 5507 +---------------- .../class-property/input.js | 0 .../common/class-property/output.amd.js | 17 + .../fixture/common/class-property/output.cjs | 12 + .../common/class-property/output.umd.js | 20 + .../cts-import-export/export-assign/input.cts | 3 + .../export-assign/output.amd.ts | 7 + .../export-assign/output.cts | 3 + .../export-assign/output.umd.ts | 10 + .../cts-import-export/export-import/input.cts | 1 + .../export-import/output.amd.ts | 14 + .../export-import/output.cts | 9 + .../export-import/output.umd.ts | 17 + .../common/cts-import-export/mixed/input.cts | 5 + .../cts-import-export/mixed/output.amd.ts | 13 + .../common/cts-import-export/mixed/output.cts | 8 + .../cts-import-export/mixed/output.umd.ts | 16 + .../tests/fixture/common/custom/01/input.js | 3 + .../fixture/common/custom/01/output.amd.js | 16 + .../tests/fixture/common/custom/01/output.cjs | 11 + .../fixture/common/custom/01/output.umd.js | 19 + .../tests/fixture/common/custom/02/input.js | 5 + .../fixture/common/custom/02/output.amd.js | 18 + .../tests/fixture/common/custom/02/output.cjs | 13 + .../fixture/common/custom/02/output.umd.js | 21 + .../common/custom/named-define/input.js | 2 + .../custom/named-define/module.amd.json | 3 + .../common/custom/named-define/output.amd.js | 14 + .../common/custom/named-define/output.cjs | 9 + .../common/custom/named-define/output.umd.js | 17 + .../common/custom/non-strict-mode/input.js | 1 + .../common/custom/non-strict-mode/module.json | 3 + .../custom/non-strict-mode/output.amd.js | 13 + .../common/custom/non-strict-mode/output.cjs | 8 + .../custom/non-strict-mode/output.umd.js | 16 + .../fixture/common/custom/usage/input.js | 2 + .../fixture/common/custom/usage/output.amd.js | 12 + .../fixture/common/custom/usage/output.cjs | 6 + .../fixture/common/custom/usage/output.umd.js | 15 + .../input.js | 3 + .../module.json | 3 + .../output.amd.js | 11 + .../output.cjs | 6 + .../output.umd.js | 14 + .../export-update/1/input.js | 2 +- .../common/export-update/1/output.amd.js | 27 + .../fixture/common/export-update/1/output.cjs | 22 + .../common/export-update/1/output.umd.js | 30 + .../fixture/common/ignore-dynamic/1/input.js | 11 + .../common/ignore-dynamic/1/module.json | 3 + .../common/ignore-dynamic/1/output.amd.js | 17 + .../common/ignore-dynamic/1/output.cjs | 11 + .../common/ignore-dynamic/1/output.umd.js | 20 + .../common/interop/export-all/input.js | 6 + .../common/interop/export-all/output.amd.js | 16 + .../common/interop/export-all/output.cjs | 10 + .../common/interop/export-all/output.umd.js | 19 + .../common/interop/export-default-10/input.js | 3 + .../interop/export-default-10/output.amd.js | 16 + .../interop/export-default-10/output.cjs | 11 + .../interop/export-default-10/output.umd.js | 19 + .../common/interop/export-default-11/input.js | 3 + .../interop/export-default-11/output.amd.js | 21 + .../interop/export-default-11/output.cjs | 16 + .../interop/export-default-11/output.umd.js | 24 + .../common/interop/export-default-2/input.js | 1 + .../interop/export-default-2/output.amd.js | 14 + .../interop/export-default-2/output.cjs | 9 + .../interop/export-default-2/output.umd.js | 17 + .../common/interop/export-default-3/input.js | 1 + .../interop/export-default-3/output.amd.js | 14 + .../interop/export-default-3/output.cjs | 9 + .../interop/export-default-3/output.umd.js | 17 + .../common/interop/export-default-4/input.js | 1 + .../interop/export-default-4/output.amd.js | 14 + .../interop/export-default-4/output.cjs | 9 + .../interop/export-default-4/output.umd.js | 17 + .../common/interop/export-default-5/input.js | 1 + .../interop/export-default-5/output.amd.js | 14 + .../interop/export-default-5/output.cjs | 9 + .../interop/export-default-5/output.umd.js | 17 + .../common/interop/export-default-6/input.js | 1 + .../interop/export-default-6/output.amd.js | 15 + .../interop/export-default-6/output.cjs | 10 + .../interop/export-default-6/output.umd.js | 18 + .../common/interop/export-default-7/input.js | 1 + .../interop/export-default-7/output.amd.js | 14 + .../interop/export-default-7/output.cjs | 9 + .../interop/export-default-7/output.umd.js | 17 + .../common/interop/export-default-8/input.js | 1 + .../interop/export-default-8/output.amd.js | 15 + .../interop/export-default-8/output.cjs | 10 + .../interop/export-default-8/output.umd.js | 18 + .../common/interop/export-default-9/input.js | 2 + .../interop/export-default-9/output.amd.js | 14 + .../interop/export-default-9/output.cjs | 9 + .../interop/export-default-9/output.umd.js | 17 + .../common/interop/export-default/input.js | 1 + .../interop/export-default/output.amd.js | 14 + .../common/interop/export-default/output.cjs | 9 + .../interop/export-default/output.umd.js | 17 + .../interop/export-destructured/input.js | 18 + .../interop/export-destructured/output.amd.js | 50 + .../interop/export-destructured/output.cjs | 45 + .../interop/export-destructured/output.umd.js | 53 + .../common/interop/export-from-1/input.js | 1 + .../interop/export-from-1/output.amd.js | 11 + .../common/interop/export-from-1/output.cjs | 5 + .../interop/export-from-1/output.umd.js | 14 + .../common/interop/export-from-2/input.js | 1 + .../interop/export-from-2/output.amd.js | 14 + .../common/interop/export-from-2/output.cjs | 9 + .../interop/export-from-2/output.umd.js | 17 + .../common/interop/export-from-3/input.js | 1 + .../interop/export-from-3/output.amd.js | 20 + .../common/interop/export-from-3/output.cjs | 15 + .../interop/export-from-3/output.umd.js | 23 + .../common/interop/export-from-4/input.js | 1 + .../interop/export-from-4/output.amd.js | 14 + .../common/interop/export-from-4/output.cjs | 9 + .../interop/export-from-4/output.umd.js | 17 + .../common/interop/export-from-5/input.js | 1 + .../interop/export-from-5/output.amd.js | 14 + .../common/interop/export-from-5/output.cjs | 9 + .../interop/export-from-5/output.umd.js | 17 + .../common/interop/export-from-6/input.js | 1 + .../interop/export-from-6/output.amd.js | 20 + .../common/interop/export-from-6/output.cjs | 15 + .../interop/export-from-6/output.umd.js | 23 + .../common/interop/export-from-7/input.js | 1 + .../interop/export-from-7/output.amd.js | 15 + .../common/interop/export-from-7/output.cjs | 9 + .../interop/export-from-7/output.umd.js | 18 + .../common/interop/export-from-8/input.js | 206 + .../interop/export-from-8/output.amd.js | 119 + .../common/interop/export-from-8/output.cjs | 114 + .../interop/export-from-8/output.umd.js | 122 + .../common/interop/export-named-1/input.js | 2 + .../interop/export-named-1/output.amd.js | 14 + .../common/interop/export-named-1/output.cjs | 9 + .../interop/export-named-1/output.umd.js | 17 + .../common/interop/export-named-2/input.js | 2 + .../interop/export-named-2/output.amd.js | 20 + .../common/interop/export-named-2/output.cjs | 15 + .../interop/export-named-2/output.umd.js | 23 + .../common/interop/export-named-3/input.js | 2 + .../interop/export-named-3/output.amd.js | 14 + .../common/interop/export-named-3/output.cjs | 9 + .../interop/export-named-3/output.umd.js | 17 + .../common/interop/export-named-4/input.js | 2 + .../interop/export-named-4/output.amd.js | 14 + .../common/interop/export-named-4/output.cjs | 9 + .../interop/export-named-4/output.umd.js | 17 + .../common/interop/export-named-5/input.js | 2 + .../interop/export-named-5/output.amd.js | 20 + .../common/interop/export-named-5/output.cjs | 15 + .../interop/export-named-5/output.umd.js | 23 + .../common/interop/exports-variable/input.js | 9 + .../interop/exports-variable/output.amd.js | 37 + .../interop/exports-variable/output.cjs | 32 + .../interop/exports-variable/output.umd.js | 40 + .../interop/hoist-function-exports/input.js | 11 + .../hoist-function-exports/output.amd.js | 28 + .../interop/hoist-function-exports/output.cjs | 23 + .../hoist-function-exports/output.umd.js | 31 + .../common/interop/imports-default/input.js | 5 + .../interop/imports-default/output.amd.js | 13 + .../common/interop/imports-default/output.cjs | 7 + .../interop/imports-default/output.umd.js | 16 + .../common/interop/imports-glob/input.js | 1 + .../common/interop/imports-glob/output.amd.js | 11 + .../common/interop/imports-glob/output.cjs | 5 + .../common/interop/imports-glob/output.umd.js | 14 + .../common/interop/imports-mixing/input.js | 4 + .../interop/imports-mixing/output.amd.js | 13 + .../common/interop/imports-mixing/output.cjs | 7 + .../interop/imports-mixing/output.umd.js | 16 + .../common/interop/imports-named/input.js | 11 + .../interop/imports-named/output.amd.js | 16 + .../common/interop/imports-named/output.cjs | 11 + .../interop/imports-named/output.umd.js | 19 + .../common/interop/imports-ordering/input.js | 4 + .../interop/imports-ordering/output.amd.js | 14 + .../interop/imports-ordering/output.cjs | 8 + .../interop/imports-ordering/output.umd.js | 17 + .../fixture/common/interop/imports/input.js | 3 + .../common/interop/imports/output.amd.js | 12 + .../fixture/common/interop/imports/output.cjs | 7 + .../common/interop/imports/output.umd.js | 15 + .../fixture/common/interop/overview/input.js | 15 + .../common/interop/overview/output.amd.js | 33 + .../common/interop/overview/output.cjs | 26 + .../common/interop/overview/output.umd.js | 36 + .../fixture/common/interop/remap/input.js | 21 + .../common/interop/remap/output.amd.js | 36 + .../fixture/common/interop/remap/output.cjs | 31 + .../common/interop/remap/output.umd.js | 39 + .../fixture/common/issue-1018/1/input.js | 3 + .../fixture/common/issue-1018/1/output.amd.js | 10 + .../fixture/common/issue-1018/1/output.cjs | 4 + .../fixture/common/issue-1018/1/output.umd.js | 10 + .../fixture/common/issue-1043/1/input.js | 2 + .../fixture/common/issue-1043/1/output.amd.js | 16 + .../fixture/common/issue-1043/1/output.cjs | 10 + .../fixture/common/issue-1043/1/output.umd.js | 19 + .../fixture/common/issue-1043/2/input.js | 5 + .../fixture/common/issue-1043/2/output.amd.js | 19 + .../fixture/common/issue-1043/2/output.cjs | 12 + .../fixture/common/issue-1043/2/output.umd.js | 22 + .../issue-1201/1/input.js | 0 .../fixture/common/issue-1201/1/output.amd.js | 7 + .../issue-1201/1/output.cjs} | 0 .../fixture/common/issue-1201/1/output.umd.js | 8 + .../tests/fixture/common/issue-1213/input.js | 13 + .../fixture/common/issue-1213/output.amd.js | 25 + .../fixture/common/issue-1213/output.cjs | 19 + .../fixture/common/issue-1213/output.umd.js | 28 + .../fixture/common/issue-1423/1/input.js | 9 + .../fixture/common/issue-1423/1/output.amd.js | 17 + .../fixture/common/issue-1423/1/output.cjs | 12 + .../fixture/common/issue-1423/1/output.umd.js | 20 + .../fixture/common/issue-1480/1/input.js | 1 + .../fixture/common/issue-1480/1/module.json | 6 + .../fixture/common/issue-1480/1/output.amd.js | 8 + .../fixture/common/issue-1480/1/output.cjs | 2 + .../fixture/common/issue-1480/1/output.umd.js | 8 + .../fixture/common/issue-1480/2/input.js | 1 + .../fixture/common/issue-1480/2/module.json | 6 + .../fixture/common/issue-1480/2/output.amd.js | 11 + .../fixture/common/issue-1480/2/output.cjs | 5 + .../fixture/common/issue-1480/2/output.umd.js | 14 + .../fixture/common/issue-1568/1/input.js | 3 + .../fixture/common/issue-1568/1/output.amd.js | 16 + .../fixture/common/issue-1568/1/output.cjs | 11 + .../fixture/common/issue-1568/1/output.umd.js | 19 + .../fixture/common/issue-1568/2/input.js | 5 + .../fixture/common/issue-1568/2/output.amd.js | 23 + .../fixture/common/issue-1568/2/output.cjs | 18 + .../fixture/common/issue-1568/2/output.umd.js | 26 + .../fixture/common/issue-1588/1/input.js | 5 + .../fixture/common/issue-1588/1/output.amd.js | 14 + .../fixture/common/issue-1588/1/output.cjs | 8 + .../fixture/common/issue-1588/1/output.umd.js | 17 + .../fixture/common/issue-1614/1/input.js | 4 + .../fixture/common/issue-1614/1/output.amd.js | 11 + .../fixture/common/issue-1614/1/output.cjs | 5 + .../fixture/common/issue-1614/1/output.umd.js | 11 + .../fixture/common/issue-1757/1/input.js | 4 + .../fixture/common/issue-1757/1/output.amd.js | 11 + .../fixture/common/issue-1757/1/output.cjs | 6 + .../fixture/common/issue-1757/1/output.umd.js | 14 + .../tests/fixture/common/issue-176/input.js | 3 + .../fixture/common/issue-176/output.amd.js | 6 + .../tests/fixture/common/issue-176/output.cjs | 2 + .../fixture/common/issue-176/output.umd.js | 8 + .../fixture/common/issue-1780/1/input.js | 3 + .../fixture/common/issue-1780/1/output.amd.js | 18 + .../fixture/common/issue-1780/1/output.cjs | 11 + .../fixture/common/issue-1780/1/output.umd.js | 21 + .../fixture/common/issue-1786/1/input.js | 2 + .../fixture/common/issue-1786/1/output.amd.js | 15 + .../fixture/common/issue-1786/1/output.cjs | 9 + .../fixture/common/issue-1786/1/output.umd.js | 18 + .../fixture/common/issue-1787/1/input.js | 3 + .../fixture/common/issue-1787/1/output.amd.js | 17 + .../fixture/common/issue-1787/1/output.cjs | 10 + .../fixture/common/issue-1787/1/output.umd.js | 20 + .../fixture/common/issue-1799/1/input.js | 3 + .../fixture/common/issue-1799/1/output.amd.js | 16 + .../fixture/common/issue-1799/1/output.cjs | 11 + .../fixture/common/issue-1799/1/output.umd.js | 19 + .../fixture/common/issue-1799/2/input.js | 3 + .../fixture/common/issue-1799/2/output.amd.js | 16 + .../fixture/common/issue-1799/2/output.cjs | 11 + .../fixture/common/issue-1799/2/output.umd.js | 19 + .../issue-2101/1/input.js | 0 .../fixture/common/issue-2101/1/output.amd.js | 16 + .../fixture/common/issue-2101/1/output.cjs | 10 + .../fixture/common/issue-2101/1/output.umd.js | 19 + .../issue-2101/2/input.js | 0 .../fixture/common/issue-2101/2/output.amd.js | 16 + .../fixture/common/issue-2101/2/output.cjs | 10 + .../fixture/common/issue-2101/2/output.umd.js | 19 + .../issue-2211/1/input.js | 0 .../fixture/common/issue-2211/1/output.amd.js | 17 + .../fixture/common/issue-2211/1/output.cjs | 12 + .../fixture/common/issue-2211/1/output.umd.js | 20 + .../issue-2211/2/input.js | 0 .../fixture/common/issue-2211/2/output.amd.js | 17 + .../fixture/common/issue-2211/2/output.cjs | 12 + .../fixture/common/issue-2211/2/output.umd.js | 20 + .../{commonjs => common}/issue-2297/input.js | 0 .../fixture/common/issue-2297/output.amd.js | 15 + .../fixture/common/issue-2297/output.cjs | 10 + .../fixture/common/issue-2297/output.umd.js | 18 + .../fixture/common/issue-2344/1/input.js | 9 + .../fixture/common/issue-2344/1/output.amd.js | 14 + .../fixture/common/issue-2344/1/output.cjs | 10 + .../fixture/common/issue-2344/1/output.umd.js | 16 + .../fixture/common/issue-2344/2/input.js | 16 + .../fixture/common/issue-2344/2/output.amd.js | 21 + .../fixture/common/issue-2344/2/output.cjs | 17 + .../fixture/common/issue-2344/2/output.umd.js | 23 + .../fixture/common/issue-2344/3/input.js | 5 + .../fixture/common/issue-2344/3/output.amd.js | 10 + .../fixture/common/issue-2344/3/output.cjs | 6 + .../fixture/common/issue-2344/3/output.umd.js | 12 + .../tests/fixture/common/issue-235/input.js | 2 + .../fixture/common/issue-235/output.amd.js | 15 + .../tests/fixture/common/issue-235/output.cjs | 10 + .../fixture/common/issue-235/output.umd.js | 18 + .../issue-2548/case1/input.js} | 0 .../common/issue-2548/case1/output.amd.js | 15 + .../common/issue-2548/case1/output.cjs | 9 + .../common/issue-2548/case1/output.umd.js | 18 + .../issue-2548/case2/input.js} | 0 .../common/issue-2548/case2/output.amd.js | 15 + .../common/issue-2548/case2/output.cjs | 9 + .../common/issue-2548/case2/output.umd.js | 18 + .../fixture/common/issue-2548/case3/input.js | 2 + .../common/issue-2548/case3/output.amd.js | 22 + .../common/issue-2548/case3/output.cjs | 16 + .../common/issue-2548/case3/output.umd.js | 25 + .../{commonjs => common}/issue-2549/input.js | 0 .../fixture/common/issue-2549/output.amd.js | 58 + .../issue-2549/output.cjs} | 37 +- .../fixture/common/issue-2549/output.umd.js | 61 + .../{commonjs => common}/issue-2678/input.js | 0 .../fixture/common/issue-2678/output.amd.js | 38 + .../issue-2678/output.cjs} | 22 +- .../fixture/common/issue-2678/output.umd.js | 41 + .../fixture/common/issue-3246/1/input.js | 3 + .../fixture/common/issue-3246/1/output.amd.js | 13 + .../fixture/common/issue-3246/1/output.cjs | 6 + .../fixture/common/issue-3246/1/output.umd.js | 14 + .../fixture/common/issue-3246/2/input.js | 3 + .../fixture/common/issue-3246/2/output.amd.js | 14 + .../fixture/common/issue-3246/2/output.cjs | 6 + .../fixture/common/issue-3246/2/output.umd.js | 15 + .../tests/fixture/common/issue-326/input.js | 3 + .../fixture/common/issue-326/output.amd.js | 14 + .../tests/fixture/common/issue-326/output.cjs | 7 + .../fixture/common/issue-326/output.umd.js | 17 + .../tests/fixture/common/issue-332/input.js | 3 + .../fixture/common/issue-332/output.amd.js | 18 + .../tests/fixture/common/issue-332/output.cjs | 12 + .../fixture/common/issue-332/output.umd.js | 21 + .../tests/fixture/common/issue-335/input.js | 3 + .../fixture/common/issue-335/output.amd.js | 12 + .../tests/fixture/common/issue-335/output.cjs | 6 + .../fixture/common/issue-335/output.umd.js | 15 + .../tests/fixture/common/issue-3438/input.js | 3 + .../fixture/common/issue-3438/output.amd.js | 13 + .../fixture/common/issue-3438/output.cjs | 6 + .../fixture/common/issue-3438/output.umd.js | 14 + .../issue-3439/1/input.js | 2 +- .../fixture/common/issue-3439/1/output.amd.js | 17 + .../fixture/common/issue-3439/1/output.cjs | 12 + .../fixture/common/issue-3439/1/output.umd.js | 20 + .../issue-3439/2/input.js | 4 +- .../fixture/common/issue-3439/2/output.amd.js | 26 + .../fixture/common/issue-3439/2/output.cjs | 21 + .../fixture/common/issue-3439/2/output.umd.js | 29 + .../issue-3439/3/input.js | 4 +- .../fixture/common/issue-3439/3/output.amd.js | 25 + .../fixture/common/issue-3439/3/output.cjs | 20 + .../fixture/common/issue-3439/3/output.umd.js | 28 + .../issue-3439/4/input.js | 0 .../fixture/common/issue-3439/4/output.amd.js | 22 + .../fixture/common/issue-3439/4/output.cjs | 17 + .../fixture/common/issue-3439/4/output.umd.js | 25 + .../issue-3439/5/input.js | 0 .../fixture/common/issue-3439/5/output.amd.js | 23 + .../fixture/common/issue-3439/5/output.cjs | 18 + .../fixture/common/issue-3439/5/output.umd.js | 26 + .../tests/fixture/common/issue-369/input.js | 11 + .../fixture/common/issue-369/output.amd.js | 28 + .../tests/fixture/common/issue-369/output.cjs | 23 + .../fixture/common/issue-369/output.umd.js | 31 + .../{commonjs => common}/issue-3732/input.js | 0 .../fixture/common/issue-3732/output.amd.js | 27 + .../fixture/common/issue-3732/output.cjs | 21 + .../fixture/common/issue-3732/output.umd.js | 30 + .../tests/fixture/common/issue-389/1/input.js | 2 + .../fixture/common/issue-389/1/output.amd.js | 12 + .../fixture/common/issue-389/1/output.cjs | 6 + .../fixture/common/issue-389/1/output.umd.js | 15 + .../tests/fixture/common/issue-389/2/input.js | 2 + .../fixture/common/issue-389/2/output.amd.js | 12 + .../fixture/common/issue-389/2/output.cjs | 6 + .../fixture/common/issue-389/2/output.umd.js | 15 + .../issue-3898/1/input.js | 0 .../fixture/common/issue-3898/1/output.amd.js | 37 + .../fixture/common/issue-3898/1/output.cjs | 32 + .../fixture/common/issue-3898/1/output.umd.js | 40 + .../tests/fixture/common/issue-396/1/input.js | 4 + .../fixture/common/issue-396/1/output.amd.js | 9 + .../fixture/common/issue-396/1/output.cjs | 5 + .../fixture/common/issue-396/1/output.umd.js | 11 + .../tests/fixture/common/issue-396/2/input.js | 4 + .../fixture/common/issue-396/2/output.amd.js | 9 + .../fixture/common/issue-396/2/output.cjs | 5 + .../fixture/common/issue-396/2/output.umd.js | 11 + .../tests/fixture/common/issue-4064/input.js | 4 + .../fixture/common/issue-4064/output.amd.js | 18 + .../fixture/common/issue-4064/output.cjs | 11 + .../fixture/common/issue-4064/output.umd.js | 21 + .../tests/fixture/common/issue-4253/input.js | 1 + .../fixture/common/issue-4253/output.amd.js | 8 + .../fixture/common/issue-4253/output.cjs | 2 + .../fixture/common/issue-4253/output.umd.js | 8 + .../fixture/common/issue-4313/1/input.js | 3 + .../fixture/common/issue-4313/1/output.amd.js | 16 + .../fixture/common/issue-4313/1/output.cjs | 11 + .../fixture/common/issue-4313/1/output.umd.js | 19 + .../fixture/common/issue-4456/1/input.ts | 16 + .../fixture/common/issue-4456/1/output.amd.ts | 33 + .../fixture/common/issue-4456/1/output.cts | 27 + .../fixture/common/issue-4456/1/output.umd.ts | 36 + .../fixture/common/issue-4534/1/input.js | 4 + .../fixture/common/issue-4534/1/output.amd.js | 21 + .../fixture/common/issue-4534/1/output.cjs | 15 + .../fixture/common/issue-4534/1/output.umd.js | 24 + .../tests/fixture/common/issue-456/1/input.js | 5 + .../fixture/common/issue-456/1/module.json | 5 + .../fixture/common/issue-456/1/output.amd.js | 15 + .../fixture/common/issue-456/1/output.cjs | 10 + .../fixture/common/issue-456/1/output.umd.js | 18 + .../tests/fixture/common/issue-456/2/input.js | 5 + .../fixture/common/issue-456/2/module.json | 5 + .../fixture/common/issue-456/2/output.amd.js | 15 + .../fixture/common/issue-456/2/output.cjs | 10 + .../fixture/common/issue-456/2/output.umd.js | 18 + .../fixture/common/issue-4567/1/input.js | 3 + .../fixture/common/issue-4567/1/output.amd.js | 16 + .../fixture/common/issue-4567/1/output.cjs | 11 + .../fixture/common/issue-4567/1/output.umd.js | 19 + .../issue-4700/1/input.js | 0 .../fixture/common/issue-4700/1/output.amd.js | 19 + .../fixture/common/issue-4700/1/output.cjs | 13 + .../fixture/common/issue-4700/1/output.umd.js | 22 + .../fixture/common/issue-4718/1/input.js | 3 + .../fixture/common/issue-4718/1/output.amd.js | 8 + .../fixture/common/issue-4718/1/output.cjs | 4 + .../fixture/common/issue-4718/1/output.umd.js | 10 + .../fixture/common/issue-4798/1/input.js | 2 + .../fixture/common/issue-4798/1/output.amd.js | 11 + .../fixture/common/issue-4798/1/output.cjs | 6 + .../fixture/common/issue-4798/1/output.umd.js | 14 + .../tests/fixture/common/issue-4799/input.js | 1 + .../fixture/common/issue-4799/module.json | 3 + .../fixture/common/issue-4799/output.amd.js | 14 + .../fixture/common/issue-4799/output.cjs | 9 + .../fixture/common/issue-4799/output.umd.js | 17 + .../fixture/common/issue-4866/1/input.js | 2 + .../fixture/common/issue-4866/1/output.amd.js | 24 + .../fixture/common/issue-4866/1/output.cjs | 19 + .../fixture/common/issue-4866/1/output.umd.js | 27 + .../fixture/common/issue-4898/1/input.ts | 3 + .../fixture/common/issue-4898/1/output.amd.ts | 11 + .../fixture/common/issue-4898/1/output.cts | 6 + .../fixture/common/issue-4898/1/output.umd.ts | 14 + .../fixture/common/issue-4898/2/input.ts | 5 + .../fixture/common/issue-4898/2/output.amd.ts | 13 + .../fixture/common/issue-4898/2/output.cts | 8 + .../fixture/common/issue-4898/2/output.umd.ts | 16 + .../fixture/common/issue-4981/1/input.js | 5 + .../fixture/common/issue-4981/1/output.amd.js | 22 + .../fixture/common/issue-4981/1/output.cjs | 17 + .../fixture/common/issue-4981/1/output.umd.js | 25 + .../fixture/common/issue-4984/1/input.js | 5 + .../fixture/common/issue-4984/1/output.amd.js | 17 + .../fixture/common/issue-4984/1/output.cjs | 12 + .../fixture/common/issue-4984/1/output.umd.js | 20 + .../fixture/common/issue-5042/1/input.ts | 5 + .../fixture/common/issue-5042/1/output.amd.ts | 21 + .../fixture/common/issue-5042/1/output.cts | 16 + .../fixture/common/issue-5042/1/output.umd.ts | 24 + .../fixture/common/issue-5042/2/input.ts | 7 + .../fixture/common/issue-5042/2/output.amd.ts | 9 + .../fixture/common/issue-5042/2/output.cts | 5 + .../fixture/common/issue-5042/2/output.umd.ts | 12 + .../fixture/common/issue-5042/3/input.ts | 2 + .../fixture/common/issue-5042/3/output.amd.ts | 16 + .../fixture/common/issue-5042/3/output.cts | 10 + .../fixture/common/issue-5042/3/output.umd.ts | 19 + .../tests/fixture/common/issue-578/2/input.js | 23 + .../fixture/common/issue-578/2/output.amd.js | 29 + .../fixture/common/issue-578/2/output.cjs | 24 + .../fixture/common/issue-578/2/output.umd.js | 32 + .../tests/fixture/common/issue-605/input.js | 1 + .../fixture/common/issue-605/module.json | 5 + .../fixture/common/issue-605/output.amd.js | 8 + .../tests/fixture/common/issue-605/output.cjs | 2 + .../fixture/common/issue-605/output.umd.js | 11 + .../tests/fixture/common/issue-724/input.js | 2 + .../fixture/common/issue-724/module.json | 5 + .../fixture/common/issue-724/output.amd.js | 7 + .../tests/fixture/common/issue-724/output.cjs | 3 + .../fixture/common/issue-724/output.umd.js | 10 + .../tests/fixture/common/issue-763/input.js | 21 + .../fixture/common/issue-763/module.json | 4 + .../fixture/common/issue-763/output.amd.js | 24 + .../tests/fixture/common/issue-763/output.cjs | 19 + .../fixture/common/issue-763/output.umd.js | 27 + .../tests/fixture/common/issue-831/2/input.js | 3 + .../fixture/common/issue-831/2/output.amd.js | 20 + .../fixture/common/issue-831/2/output.cjs | 15 + .../fixture/common/issue-831/2/output.umd.js | 23 + .../tests/fixture/common/issue-895/input.ts | 7 + .../fixture/common/issue-895/output.amd.ts | 19 + .../tests/fixture/common/issue-895/output.cts | 14 + .../fixture/common/issue-895/output.umd.ts | 22 + .../tests/fixture/common/issue-962/input.js | 17 + .../fixture/common/issue-962/output.amd.js | 24 + .../tests/fixture/common/issue-962/output.cjs | 17 + .../fixture/common/issue-962/output.umd.js | 27 + .../common/lazy/computed-prop-name/input.js | 9 + .../lazy/computed-prop-name/module.json | 3 + .../lazy/computed-prop-name/output.amd.js | 17 + .../common/lazy/computed-prop-name/output.cjs | 24 + .../lazy/computed-prop-name/output.umd.js | 20 + .../common/lazy/dep-import-default/input.js | 5 + .../lazy/dep-import-default/module.json | 3 + .../lazy/dep-import-default/output.amd.js | 14 + .../common/lazy/dep-import-default/output.cjs | 14 + .../lazy/dep-import-default/output.umd.js | 17 + .../common/lazy/dep-import-named/input.js | 5 + .../common/lazy/dep-import-named/module.json | 3 + .../lazy/dep-import-named/output.amd.js | 13 + .../common/lazy/dep-import-named/output.cjs | 14 + .../lazy/dep-import-named/output.umd.js | 16 + .../common/lazy/dep-import-namespace/input.js | 5 + .../lazy/dep-import-namespace/module.json | 3 + .../lazy/dep-import-namespace/output.amd.js | 14 + .../lazy/dep-import-namespace/output.cjs | 14 + .../lazy/dep-import-namespace/output.umd.js | 17 + .../common/lazy/dep-reexport-all/input.js | 1 + .../common/lazy/dep-reexport-all/module.json | 3 + .../lazy/dep-reexport-all/output.amd.js | 11 + .../common/lazy/dep-reexport-all/output.cjs | 5 + .../lazy/dep-reexport-all/output.umd.js | 14 + .../common/lazy/dep-reexport-default/input.js | 2 + .../lazy/dep-reexport-default/module.json | 3 + .../lazy/dep-reexport-default/output.amd.js | 15 + .../lazy/dep-reexport-default/output.cjs | 15 + .../lazy/dep-reexport-default/output.umd.js | 18 + .../common/lazy/dep-reexport-named/input.js | 2 + .../lazy/dep-reexport-named/module.json | 3 + .../lazy/dep-reexport-named/output.amd.js | 14 + .../common/lazy/dep-reexport-named/output.cjs | 15 + .../lazy/dep-reexport-named/output.umd.js | 17 + .../lazy/dep-reexport-namespace/input.js | 2 + .../lazy/dep-reexport-namespace/module.json | 3 + .../lazy/dep-reexport-namespace/output.amd.js | 15 + .../lazy/dep-reexport-namespace/output.cjs | 15 + .../lazy/dep-reexport-namespace/output.umd.js | 18 + .../common/lazy/dep-sideeffect/input.js | 1 + .../common/lazy/dep-sideeffect/module.json | 3 + .../common/lazy/dep-sideeffect/output.amd.js | 10 + .../common/lazy/dep-sideeffect/output.cjs | 5 + .../common/lazy/dep-sideeffect/output.umd.js | 13 + .../fixture/common/lazy/export-named/input.js | 1 + .../common/lazy/export-named/module.json | 3 + .../common/lazy/export-named/output.amd.js | 14 + .../common/lazy/export-named/output.cjs | 15 + .../common/lazy/export-named/output.umd.js | 17 + .../import-all-from-object-config/input.js | 6 + .../import-all-from-object-config/module.json | 7 + .../output.amd.js | 14 + .../import-all-from-object-config/output.cjs | 21 + .../output.umd.js | 17 + .../input.js | 7 + .../module.json | 7 + .../output.amd.js | 15 + .../output.cjs | 16 + .../output.umd.js | 18 + .../fixture/common/lazy/issue-3081/1/input.js | 11 + .../common/lazy/issue-3081/1/module.json | 3 + .../common/lazy/issue-3081/1/output.amd.js | 18 + .../common/lazy/issue-3081/1/output.cjs | 19 + .../common/lazy/issue-3081/1/output.umd.js | 21 + .../fixture/common/lazy/issue-3081/2/input.js | 6 + .../common/lazy/issue-3081/2/module.json | 3 + .../common/lazy/issue-3081/2/output.amd.js | 15 + .../common/lazy/issue-3081/2/output.cjs | 16 + .../common/lazy/issue-3081/2/output.umd.js | 18 + .../common/lazy/local-import-default/input.js | 3 + .../lazy/local-import-default/module.json | 3 + .../lazy/local-import-default/output.amd.js | 12 + .../lazy/local-import-default/output.cjs | 6 + .../lazy/local-import-default/output.umd.js | 15 + .../common/lazy/local-import-named/input.js | 3 + .../lazy/local-import-named/module.json | 3 + .../lazy/local-import-named/output.amd.js | 11 + .../common/lazy/local-import-named/output.cjs | 6 + .../lazy/local-import-named/output.umd.js | 14 + .../lazy/local-import-namespace/input.js | 3 + .../lazy/local-import-namespace/module.json | 3 + .../lazy/local-import-namespace/output.amd.js | 12 + .../lazy/local-import-namespace/output.cjs | 6 + .../lazy/local-import-namespace/output.umd.js | 15 + .../common/lazy/local-reexport-all/input.js | 1 + .../lazy/local-reexport-all/output.amd.js | 11 + .../common/lazy/local-reexport-all/output.cjs | 5 + .../lazy/local-reexport-all/output.umd.js | 14 + .../lazy/local-reexport-default/input.js | 2 + .../lazy/local-reexport-default/module.json | 3 + .../lazy/local-reexport-default/output.amd.js | 15 + .../lazy/local-reexport-default/output.cjs | 9 + .../lazy/local-reexport-default/output.umd.js | 18 + .../common/lazy/local-reexport-named/input.js | 2 + .../lazy/local-reexport-named/module.json | 3 + .../lazy/local-reexport-named/output.amd.js | 14 + .../lazy/local-reexport-named/output.cjs | 9 + .../lazy/local-reexport-named/output.umd.js | 17 + .../lazy/local-reexport-namespace/input.js | 2 + .../lazy/local-reexport-namespace/module.json | 3 + .../local-reexport-namespace/output.amd.js | 15 + .../lazy/local-reexport-namespace/output.cjs | 9 + .../local-reexport-namespace/output.umd.js | 18 + .../common/lazy/local-sideeffect/input.js | 1 + .../common/lazy/local-sideeffect/module.json | 3 + .../lazy/local-sideeffect/output.amd.js | 10 + .../common/lazy/local-sideeffect/output.cjs | 5 + .../lazy/local-sideeffect/output.umd.js | 13 + .../lazy/not-shadowed-by-labels/.input.js | 10 + .../lazy/not-shadowed-by-labels/module.json | 3 + .../lazy/whitelist/import-default/input.js | 7 + .../lazy/whitelist/import-default/module.json | 5 + .../whitelist/import-default/output.amd.js | 15 + .../lazy/whitelist/import-default/output.cjs | 14 + .../whitelist/import-default/output.umd.js | 18 + .../lazy/whitelist/import-named/input.js | 11 + .../lazy/whitelist/import-named/module.json | 5 + .../lazy/whitelist/import-named/output.amd.js | 17 + .../lazy/whitelist/import-named/output.cjs | 18 + .../lazy/whitelist/import-named/output.umd.js | 20 + .../lazy/whitelist/import-namespace/input.js | 11 + .../whitelist/import-namespace/module.json | 5 + .../whitelist/import-namespace/output.amd.js | 19 + .../whitelist/import-namespace/output.cjs | 18 + .../whitelist/import-namespace/output.umd.js | 22 + .../lazy/whitelist/reexport-all/input.js | 3 + .../lazy/whitelist/reexport-all/module.json | 5 + .../lazy/whitelist/reexport-all/output.amd.js | 13 + .../lazy/whitelist/reexport-all/output.cjs | 6 + .../lazy/whitelist/reexport-all/output.umd.js | 16 + .../lazy/whitelist/reexport-default/input.js | 2 + .../whitelist/reexport-default/module.json | 5 + .../whitelist/reexport-default/output.amd.js | 15 + .../whitelist/reexport-default/output.cjs | 15 + .../whitelist/reexport-default/output.umd.js | 18 + .../lazy/whitelist/reexport-named/input.js | 5 + .../lazy/whitelist/reexport-named/module.json | 5 + .../whitelist/reexport-named/output.amd.js | 21 + .../lazy/whitelist/reexport-named/output.cjs | 22 + .../whitelist/reexport-named/output.umd.js | 24 + .../whitelist/reexport-namespace/input.js | 5 + .../whitelist/reexport-namespace/module.json | 5 + .../reexport-namespace/output.amd.js | 23 + .../whitelist/reexport-namespace/output.cjs | 22 + .../reexport-namespace/output.umd.js | 26 + .../common/lazy/whitelist/sideeffect/input.js | 2 + .../lazy/whitelist/sideeffect/module.json | 5 + .../lazy/whitelist/sideeffect/output.amd.js | 11 + .../lazy/whitelist/sideeffect/output.cjs | 6 + .../lazy/whitelist/sideeffect/output.umd.js | 14 + .../many-exports-chunked/1/input.js | 0 .../many-exports-chunked/1/output.amd.js | 517 ++ .../common/many-exports-chunked/1/output.cjs | 512 ++ .../many-exports-chunked/1/output.umd.js | 520 ++ .../common/misc/copy-getters-setters/input.js | 3 + .../misc/copy-getters-setters/output.amd.js | 21 + .../misc/copy-getters-setters/output.cjs | 15 + .../misc/copy-getters-setters/output.umd.js | 24 + .../common/misc/import-const-throw/input.js | 17 + .../misc/import-const-throw/output.amd.js | 23 + .../common/misc/import-const-throw/output.cjs | 16 + .../misc/import-const-throw/output.umd.js | 26 + .../undefined-this-arrow-function/input.js | 1 + .../output.amd.js | 6 + .../undefined-this-arrow-function/output.cjs | 2 + .../output.umd.js | 8 + .../misc/undefined-this-root-call/input.js | 1 + .../undefined-this-root-call/output.amd.js | 6 + .../misc/undefined-this-root-call/output.cjs | 2 + .../undefined-this-root-call/output.umd.js | 8 + .../undefined-this-root-declaration/input.js | 1 + .../output.amd.js | 6 + .../output.cjs | 2 + .../output.umd.js | 8 + .../undefined-this-root-reference/input.js | 1 + .../output.amd.js | 6 + .../undefined-this-root-reference/output.cjs | 2 + .../output.umd.js | 8 + .../common/no-interop/export-from/input.js | 1 + .../common/no-interop/export-from/module.json | 3 + .../no-interop/export-from/output.amd.js | 11 + .../common/no-interop/export-from/output.cjs | 6 + .../no-interop/export-from/output.umd.js | 14 + .../no-interop/import-default-only/input.js | 3 + .../import-default-only/module.json | 3 + .../import-default-only/output.amd.js | 7 + .../no-interop/import-default-only/output.cjs | 3 + .../import-default-only/output.umd.js | 10 + .../no-interop/import-wildcard/input.js | 4 + .../no-interop/import-wildcard/module.json | 3 + .../no-interop/import-wildcard/output.amd.js | 8 + .../no-interop/import-wildcard/output.cjs | 4 + .../no-interop/import-wildcard/output.umd.js | 11 + .../tests/fixture/common/pull-4688/input.js | 7 + .../fixture/common/pull-4688/output.amd.js | 26 + .../tests/fixture/common/pull-4688/output.cjs | 21 + .../fixture/common/pull-4688/output.umd.js | 29 + .../fixture/common/regression/4209/input.js | 10 + .../common/regression/4209/output.amd.js | 16 + .../fixture/common/regression/4209/output.cjs | 11 + .../common/regression/4209/output.umd.js | 19 + .../fixture/common/regression/6647/input.js | 2 + .../common/regression/6647/output.amd.js | 12 + .../fixture/common/regression/6647/output.cjs | 6 + .../common/regression/6647/output.umd.js | 15 + .../fixture/common/regression/6733/input.js | 4 + .../common/regression/6733/output.amd.js | 17 + .../fixture/common/regression/6733/output.cjs | 12 + .../common/regression/6733/output.umd.js | 20 + .../fixture/common/regression/t-7178/input.js | 9 + .../common/regression/t-7178/output.amd.js | 16 + .../common/regression/t-7178/output.cjs | 10 + .../common/regression/t-7178/output.umd.js | 19 + .../fixture/common/strict/export-1/input.js | 1 + .../common/strict/export-1/module.json | 3 + .../common/strict/export-1/output.amd.js | 14 + .../fixture/common/strict/export-1/output.cjs | 9 + .../common/strict/export-1/output.umd.js | 17 + .../fixture/common/strict/export-2/input.js | 2 + .../common/strict/export-2/module.json | 3 + .../common/strict/export-2/output.amd.js | 14 + .../fixture/common/strict/export-2/output.cjs | 9 + .../common/strict/export-2/output.umd.js | 17 + .../fixture/common/strict/export-3/input.js | 3 + .../common/strict/export-3/module.json | 3 + .../common/strict/export-3/output.amd.js | 10 + .../fixture/common/strict/export-3/output.cjs | 5 + .../common/strict/export-3/output.umd.js | 13 + .../fixture/common/strict/export-4/input.js | 1 + .../common/strict/export-4/module.json | 3 + .../common/strict/export-4/output.amd.js | 14 + .../fixture/common/strict/export-4/output.cjs | 9 + .../common/strict/export-4/output.umd.js | 17 + .../input.js | 1 + .../module.json | 3 + .../output.amd.js | 20 + .../output.cjs | 15 + .../output.umd.js | 23 + .../destructuring-array-rest/input.js | 1 + .../destructuring-array-rest/module.json | 3 + .../destructuring-array-rest/output.amd.js | 21 + .../destructuring-array-rest/output.cjs | 16 + .../destructuring-array-rest/output.umd.js | 24 + .../export-const/destructuring-array/input.js | 1 + .../destructuring-array/module.json | 3 + .../destructuring-array/output.amd.js | 20 + .../destructuring-array/output.cjs | 15 + .../destructuring-array/output.umd.js | 23 + .../export-const/destructuring-deep/input.js | 1 + .../destructuring-deep/module.json | 3 + .../destructuring-deep/output.amd.js | 20 + .../destructuring-deep/output.cjs | 15 + .../destructuring-deep/output.umd.js | 23 + .../input.js | 1 + .../module.json | 3 + .../output.amd.js | 20 + .../output.cjs | 15 + .../output.umd.js | 23 + .../destructuring-object-rest/input.js | 1 + .../destructuring-object-rest/module.json | 3 + .../destructuring-object-rest/output.amd.js | 20 + .../destructuring-object-rest/output.cjs | 15 + .../destructuring-object-rest/output.umd.js | 23 + .../destructuring-object/input.js | 1 + .../destructuring-object/module.json | 3 + .../destructuring-object/output.amd.js | 20 + .../destructuring-object/output.cjs | 15 + .../destructuring-object/output.umd.js | 23 + .../common/strict/import-wildcard/input.js | 4 + .../common/strict/import-wildcard/module.json | 3 + .../strict/import-wildcard/output.amd.js | 13 + .../common/strict/import-wildcard/output.cjs | 7 + .../strict/import-wildcard/output.umd.js | 16 + .../fixture/common/strict/import/input.js | 9 + .../fixture/common/strict/import/module.json | 3 + .../common/strict/import/output.amd.js | 15 + .../fixture/common/strict/import/output.cjs | 9 + .../common/strict/import/output.umd.js | 18 + .../negative-suffix/input.js | 7 + .../negative-suffix/output.amd.js | 25 + .../negative-suffix/output.cjs | 20 + .../negative-suffix/output.umd.js | 28 + .../positive-suffix/input.js | 7 + .../positive-suffix/output.amd.js | 25 + .../positive-suffix/output.cjs | 20 + .../positive-suffix/output.umd.js | 28 + .../fixture/commonjs/class-property/output.js | 9 - .../commonjs/export-update/1/output.js | 16 - .../fixture/commonjs/issue-2101/1/output.js | 27 - .../fixture/commonjs/issue-2101/2/output.js | 28 - .../fixture/commonjs/issue-2211/1/output.js | 10 - .../fixture/commonjs/issue-2211/2/output.js | 11 - .../fixture/commonjs/issue-2297/output.js | 8 - .../commonjs/issue-2548/case1/input/.swcrc | 5 - .../commonjs/issue-2548/case1/output/index.js | 16 - .../commonjs/issue-2548/case2/input/.swcrc | 5 - .../commonjs/issue-2548/case2/output/index.js | 48 - .../commonjs/issue-2548/case3/input/.swcrc | 5 - .../commonjs/issue-2548/case3/input/index.js | 2 - .../commonjs/issue-2548/case3/output/index.js | 62 - .../fixture/commonjs/issue-3439/1/output.js | 10 - .../fixture/commonjs/issue-3439/2/output.js | 14 - .../fixture/commonjs/issue-3439/3/output.js | 13 - .../fixture/commonjs/issue-3439/4/output.js | 10 - .../fixture/commonjs/issue-3439/5/output.js | 11 - .../fixture/commonjs/issue-3732/output.js | 15 - .../fixture/commonjs/issue-3898/1/output.js | 30 - .../fixture/commonjs/issue-4700/1/output.js | 24 - .../commonjs/many-exports-chunked/1/output.js | 508 -- .../swc_ecma_transforms_module/tests/umd.rs | 2004 +----- .../tests/simplify.rs | 18 +- .../src/jsx/tests.rs | 14 +- .../src/refresh/tests.rs | 21 +- crates/swc_ecma_transforms_testing/src/lib.rs | 7 +- .../src/import_export_assign.rs | 226 + .../src/inline_enum.rs | 8 +- .../swc_ecma_transforms_typescript/src/lib.rs | 1 + .../src/strip.rs | 188 +- .../tests/strip.rs | 67 +- crates/swc_ecma_utils/Cargo.toml | 1 + crates/swc_ecma_utils/src/factory.rs | 194 +- crates/swc_ecma_utils/src/lib.rs | 7 +- node-swc/__tests__/module_test.js | 4 +- .../__tests__/transform/issue_4606_test.mjs | 156 +- .../__tests__/transform/issue_4730_test.mjs | 27 +- packages/swc-helpers/src/_export_star.mjs | 12 + 1034 files changed, 16755 insertions(+), 15257 deletions(-) create mode 100644 crates/swc/tests/fixture/issues-1xxx/1135/1/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-1xxx/1135/1/input/index.ts create mode 100644 crates/swc/tests/fixture/issues-1xxx/1135/1/output/index.ts create mode 100644 crates/swc/tests/fixture/issues-4xxx/4063/1/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-4xxx/4063/1/input/index.ts create mode 100644 crates/swc/tests/fixture/issues-4xxx/4063/1/output/index.ts create mode 100644 crates/swc/tests/fixture/issues-4xxx/4988/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-4xxx/4988/input/index.ts create mode 100644 crates/swc/tests/fixture/issues-4xxx/4988/output/index.ts create mode 100644 crates/swc_ecma_transforms_base/src/feature.rs create mode 100644 crates/swc_ecma_transforms_base/src/helpers/_export_star.js delete mode 100644 crates/swc_ecma_transforms_module/src/hoist.rs create mode 100644 crates/swc_ecma_transforms_module/src/module_decl_strip.rs create mode 100644 crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/class-property/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/input.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/input.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/input.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/module.amd.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/export-update/1/input.js (67%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-1201/1/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.amd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs/issue-1201/1/output.js => common/issue-1201/1/output.cjs} (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-2101/1/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-2101/2/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-2211/1/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-2211/2/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-2297/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs/issue-2548/case1/input/index.js => common/issue-2548/case1/input.js} (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs/issue-2548/case2/input/index.js => common/issue-2548/case2/input.js} (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-2549/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.amd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs/issue-2549/output.js => common/issue-2549/output.cjs} (54%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-2678/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.amd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs/issue-2678/output.js => common/issue-2678/output.cjs} (55%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-3439/1/input.js (78%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-3439/2/input.js (50%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-3439/3/input.js (53%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-3439/4/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-3439/5/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-3732/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-3898/1/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/input.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/issue-4700/1/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/input.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/input.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/input.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/input.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/input.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/input.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.amd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.cts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.umd.ts create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/not-shadowed-by-labels/.input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/not-shadowed-by-labels/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.umd.js rename crates/swc_ecma_transforms_module/tests/fixture/{commonjs => common}/many-exports-chunked/1/input.js (100%) create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/module.json create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.umd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/input.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.amd.js create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.cjs create mode 100644 crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.umd.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/class-property/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/export-update/1/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/1/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/2/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/1/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/2/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2297/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/input/.swcrc delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/output/index.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/input/.swcrc delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/output/index.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/input/.swcrc delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/input/index.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/output/index.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/1/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/2/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/3/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/4/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/5/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3732/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3898/1/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-4700/1/output.js delete mode 100644 crates/swc_ecma_transforms_module/tests/fixture/commonjs/many-exports-chunked/1/output.js create mode 100644 crates/swc_ecma_transforms_typescript/src/import_export_assign.rs create mode 100644 packages/swc-helpers/src/_export_star.mjs diff --git a/Cargo.lock b/Cargo.lock index e41d8a36b85..bbc084b167f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3561,6 +3561,7 @@ name = "swc_ecma_transforms_base" version = "0.89.6" dependencies = [ "better_scoped_tls", + "bitflags", "criterion", "num_cpus", "once_cell", @@ -3642,6 +3643,7 @@ dependencies = [ "Inflector", "ahash", "anyhow", + "bitflags", "indexmap", "path-clean", "pathdiff", @@ -3800,6 +3802,7 @@ dependencies = [ "swc_ecma_parser", "swc_ecma_visit", "tracing", + "unicode-id", ] [[package]] diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index 14762b5ea85..cff77679efa 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -1,6 +1,6 @@ -use std::{cell::RefCell, path::PathBuf, rc::Rc, sync::Arc}; +use std::{path::PathBuf, sync::Arc}; -use compat::{es2015::regenerator, es2020::export_namespace_from}; +use compat::es2015::regenerator; use either::Either; use rustc_hash::FxHashMap; use swc_atoms::JsWord; @@ -16,9 +16,15 @@ use swc_ecma_ast::{EsVersion, Module}; use swc_ecma_minifier::option::{terser::TerserTopLevelOptions, MinifyOptions}; use swc_ecma_parser::Syntax; use swc_ecma_transforms::{ - compat, compat::es2022::private_in_object, fixer, helpers, hygiene, - hygiene::hygiene_with_config, modules, modules::util::Scope, optimization::const_modules, - pass::Optional, Assumptions, + compat, + compat::es2022::private_in_object, + feature::{enable_available_feature_from_es_version, FeatureFlag}, + fixer, helpers, hygiene, + hygiene::hygiene_with_config, + modules, + optimization::const_modules, + pass::Optional, + Assumptions, }; use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut}; @@ -176,13 +182,18 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { where P: 'cmt, { - let need_interop_analysis = match module { - Some(ModuleConfig::CommonJs(ref c)) => !c.no_interop, - Some(ModuleConfig::Amd(ref c)) => !c.config.no_interop, - Some(ModuleConfig::Umd(ref c)) => !c.config.no_interop, - Some(ModuleConfig::SystemJs(_)) | Some(ModuleConfig::Es6) | None => false, + let (need_analyzer, no_interop, ignore_dynamic) = match module { + Some(ModuleConfig::CommonJs(ref c)) => (true, c.no_interop, c.ignore_dynamic), + Some(ModuleConfig::Amd(ref c)) => (true, c.config.no_interop, c.config.ignore_dynamic), + Some(ModuleConfig::Umd(ref c)) => (true, c.config.no_interop, c.config.ignore_dynamic), + Some(ModuleConfig::SystemJs(_)) + | Some(ModuleConfig::Es6) + | Some(ModuleConfig::NodeNext) + | None => (false, true, true), }; + let mut feature_flag = FeatureFlag::empty(); + // compat let compat_pass = if let Some(env) = self.env { Either::Left(swc_ecma_preset_env::preset_env( @@ -190,9 +201,13 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { comments, env, self.assumptions, + &mut feature_flag, )) } else { let assumptions = self.assumptions; + + feature_flag = enable_available_feature_from_es_version(self.target); + Either::Right(chain!( Optional::new( compat::es2022::es2022( @@ -299,18 +314,16 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { .map(|v| v.mangle.is_obj() || v.mangle.is_true()) .unwrap_or(false); - let module_scope = Rc::new(RefCell::new(Scope::default())); chain!( self.pass, Optional::new(private_in_object(), syntax.private_in_object()), compat_pass, // module / helper Optional::new( - modules::import_analysis::import_analyzer(Rc::clone(&module_scope)), - need_interop_analysis + modules::import_analysis::import_analyzer(no_interop, ignore_dynamic), + need_analyzer ), compat::reserved_words::reserved_words(), - Optional::new(export_namespace_from(), need_interop_analysis), Optional::new(helpers::inject_helpers(), self.inject_helpers), ModuleConfig::build( self.cm.clone(), @@ -319,7 +332,7 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { base, self.unresolved_mark, module, - Rc::clone(&module_scope) + feature_flag ), as_folder(MinifierPass { options: self.minify, diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index e49a548ddc5..fb86ea01bd6 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -1,10 +1,8 @@ #![cfg_attr(any(not(feature = "plugin"), target_arch = "wasm32"), allow(unused))] use std::{ - cell::RefCell, collections::{HashMap, HashSet}, env, fmt, path::{Path, PathBuf}, - rc::Rc as RustRc, sync::Arc, usize, }; @@ -50,16 +48,15 @@ use swc_ecma_minifier::option::{ pub use swc_ecma_parser::JscTarget; use swc_ecma_parser::{parse_file_as_expr, Syntax, TsConfig}; use swc_ecma_transforms::{ + feature::FeatureFlag, hygiene, modules, - modules::{ - hoist::module_hoister, path::NodeImportResolver, rewriter::import_rewriter, util::Scope, - }, + modules::{path::NodeImportResolver, rewriter::import_rewriter}, optimization::{const_modules, json_parse, simplifier}, pass::{noop, Optional}, proposals::{decorators, export_default_from, import_assertions}, react::{self, default_pragma, default_pragma_frag}, resolver, - typescript::{self, TSEnumConfig}, + typescript::{self, TsEnumConfig, TsImportExportAssignConfig}, Assumptions, }; use swc_ecma_transforms_compat::es2015::regenerator; @@ -471,7 +468,14 @@ impl Options { json_parse_pass ); - let preserve_import_export_assign = matches!(&cfg.module, Some(ModuleConfig::Amd(..))); + let import_export_assign_config = match cfg.module { + Some(ModuleConfig::CommonJs(..)) + | Some(ModuleConfig::Amd(..)) + | Some(ModuleConfig::Umd(..)) => TsImportExportAssignConfig::Preserve, + Some(ModuleConfig::NodeNext) => TsImportExportAssignConfig::NodeNext, + // TODO: should Preserve for SystemJS + _ => TsImportExportAssignConfig::Classic, + }; let pass = PassBuilder::new( cm, @@ -605,14 +609,14 @@ impl Options { .clone() .unwrap_or_else(default_pragma_frag) ), - ts_enum_config: TSEnumConfig { + ts_enum_config: TsEnumConfig { treat_const_enum_as_enum: transform .treat_const_enum_as_enum .into_bool(), ts_enum_is_readonly: assumptions.ts_enum_is_readonly, }, use_define_for_class_fields: !assumptions.set_public_class_fields, - preserve_import_export_assign, + import_export_assign_config, ..Default::default() }, comments, @@ -1260,6 +1264,8 @@ pub enum ModuleConfig { SystemJs(modules::system_js::Config), #[serde(rename = "es6")] Es6, + #[serde(rename = "nodenext")] + NodeNext, } impl ModuleConfig { @@ -1270,7 +1276,7 @@ impl ModuleConfig { base: &FileName, unresolved_mark: Mark, config: Option, - scope: RustRc>, + available_features: FeatureFlag, ) -> Box { let base = match base { FileName::Real(v) if !paths.is_empty() => { @@ -1280,7 +1286,7 @@ impl ModuleConfig { }; match config { - None | Some(ModuleConfig::Es6) => { + None | Some(ModuleConfig::Es6) | Some(ModuleConfig::NodeNext) => { if paths.is_empty() { Box::new(noop()) } else { @@ -1290,60 +1296,60 @@ impl ModuleConfig { } } Some(ModuleConfig::CommonJs(config)) => { - let base_pass = module_hoister(); if paths.is_empty() { - Box::new(chain!( - base_pass, - modules::common_js::common_js(unresolved_mark, config, Some(scope),) + Box::new(modules::common_js::common_js( + unresolved_mark, + config, + available_features, )) } else { let resolver = build_resolver(base_url, paths); - Box::new(chain!( - base_pass, - modules::common_js::common_js_with_resolver( - resolver, - base, - unresolved_mark, - config, - Some(scope), - ) + Box::new(modules::common_js::common_js_with_resolver( + resolver, + base, + unresolved_mark, + config, + available_features, )) } } Some(ModuleConfig::Umd(config)) => { - let base_pass = module_hoister(); - if paths.is_empty() { - Box::new(chain!( - base_pass, - modules::umd::umd(cm, unresolved_mark, config) + Box::new(modules::umd::umd( + cm, + unresolved_mark, + config, + available_features, )) } else { let resolver = build_resolver(base_url, paths); - Box::new(chain!( - base_pass, - modules::umd::umd_with_resolver( - resolver, - base, - cm, - unresolved_mark, - config, - ) + Box::new(modules::umd::umd_with_resolver( + cm, + resolver, + base, + unresolved_mark, + config, + available_features, )) } } Some(ModuleConfig::Amd(config)) => { - let base_pass = module_hoister(); - if paths.is_empty() { - Box::new(chain!(base_pass, modules::amd::amd(config))) + Box::new(modules::amd::amd( + unresolved_mark, + config, + available_features, + )) } else { let resolver = build_resolver(base_url, paths); - Box::new(chain!( - base_pass, - modules::amd::amd_with_resolver(resolver, base, config) + Box::new(modules::amd::amd_with_resolver( + resolver, + base, + unresolved_mark, + config, + available_features, )) } } diff --git a/crates/swc/tests/exec.rs b/crates/swc/tests/exec.rs index ca201c2c432..50c74761f96 100644 --- a/crates/swc/tests/exec.rs +++ b/crates/swc/tests/exec.rs @@ -174,7 +174,11 @@ fn create_matrix(entry: &Path) -> Vec { }, ..Default::default() }, - module: Some(ModuleConfig::CommonJs(Default::default())), + module: if entry.extension().unwrap() == "mjs" { + Some(ModuleConfig::Es6) + } else { + Some(ModuleConfig::CommonJs(Default::default())) + }, minify: minify.into(), ..Default::default() }, diff --git a/crates/swc/tests/fixture/codegen/escape/case-1/output/index.js b/crates/swc/tests/fixture/codegen/escape/case-1/output/index.js index fe6fb0c7d1e..9fb4b89efc5 100644 --- a/crates/swc/tests/fixture/codegen/escape/case-1/output/index.js +++ b/crates/swc/tests/fixture/codegen/escape/case-1/output/index.js @@ -2,6 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; +Object.defineProperty(exports, "default", { + get: function() { + return _default; + }, + enumerable: true +}); var _default = "\nvoid main() {\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n"; -exports.default = _default; diff --git a/crates/swc/tests/fixture/codegen/escape/case-2/output/index.js b/crates/swc/tests/fixture/codegen/escape/case-2/output/index.js index e78bab01ed5..c6eddd03489 100644 --- a/crates/swc/tests/fixture/codegen/escape/case-2/output/index.js +++ b/crates/swc/tests/fixture/codegen/escape/case-2/output/index.js @@ -2,6 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; +Object.defineProperty(exports, "default", { + get: function() { + return _default; + }, + enumerable: true +}); var _default = '\n// Analytical approximation of the DFG LUT, one half of the\n// split-sum approximation used in indirect specular lighting.\n// via \'environmentBRDF\' from "Physically Based Shading on Mobile"\n// https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n return vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n // based upon Frostbite 3 Moving to Physically-based Rendering\n // page 32, equation 26: E[window1]\n // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\n // this is intended to be used on spot and point lights who are represented as luminous intensity\n // but who must be converted to luminous irradiance for surface lighting calculation\n float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n if( cutoffDistance > 0.0 ) {\n distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n }\n return distanceFalloff;\n#else\n if( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n }\n return 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n} // validated\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n // Original approximation by Christophe Schlick \'94\n // float fresnel = pow( 1.0 - dotLH, 5.0 );\n // Optimized variant (presented by Epic at SIGGRAPH \'13)\n // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n} // validated\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n // See F_Schlick\n float fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n vec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n return Fr * fresnel + F0;\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (34)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is "roughness squared" in Disney\u2019s reparameterization\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n // geometry term (normalized) = G(l)\u22C5G(v) / 4(n\u22C5l)(n\u22C5v)\n // also see #12151\n float a2 = pow2( alpha );\n float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n return 1.0 / ( gl * gv );\n} // validated\n// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2\n// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = pow2( alpha );\n // dotNL and dotNV are explicitly swapped. This is not a mistake.\n float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n return 0.5 / max( gv + gl, EPSILON );\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is "roughness squared" in Disney\u2019s reparameterization\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = pow2( alpha );\n float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\n return RECIPROCAL_PI * a2 / pow2( denom );\n}\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n float alpha = pow2( roughness ); // UE4\'s roughness\n vec3 halfDir = normalize( incidentLight.direction + viewDir );\n float dotNL = saturate( dot( normal, incidentLight.direction ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( G * D );\n} // validated\n// Rect Area Light\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\n// by Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt\n// code: https://github.com/selfshadow/ltc_code/\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n const float LUT_SIZE = 64.0;\n const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n const float LUT_BIAS = 0.5 / LUT_SIZE;\n float dotNV = saturate( dot( N, V ) );\n // texture parameterized by sqrt( GGX alpha ) and sqrt( 1 - cos( theta ) )\n vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n uv = uv * LUT_SCALE + LUT_BIAS;\n return uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n // Real-Time Area Lighting: a Journey from Research to Production (p.102)\n // An approximation of the form factor of a horizon-clipped rectangle.\n float l = length( f );\n return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n float x = dot( v1, v2 );\n float y = abs( x );\n // rational polynomial approximation to theta / sin( theta ) / 2PI\n float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n float b = 3.4175940 + ( 4.1616724 + y ) * y;\n float v = a / b;\n float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n return cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n // bail if point is on back side of plane of light\n // assumes ccw winding order of light vertices\n vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n vec3 lightNormal = cross( v1, v2 );\n if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n // construct orthonormal basis around N\n vec3 T1, T2;\n T1 = normalize( V - N * dot( V, N ) );\n T2 = - cross( N, T1 ); // negated from paper; possibly due to a different handedness of world coordinate system\n // compute transform\n mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n // transform rect\n vec3 coords[ 4 ];\n coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n // project rect onto sphere\n coords[ 0 ] = normalize( coords[ 0 ] );\n coords[ 1 ] = normalize( coords[ 1 ] );\n coords[ 2 ] = normalize( coords[ 2 ] );\n coords[ 3 ] = normalize( coords[ 3 ] );\n // calculate vector form factor\n vec3 vectorFormFactor = vec3( 0.0 );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n // adjust for horizon clipping\n float result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n/*\n // alternate method of adjusting for horizon clipping (see referece)\n // refactoring required\n float len = length( vectorFormFactor );\n float z = vectorFormFactor.z / len;\n const float LUT_SIZE = 64.0;\n const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n const float LUT_BIAS = 0.5 / LUT_SIZE;\n // tabulated horizon-clipped sphere, apparently...\n vec2 uv = vec2( z * 0.5 + 0.5, len );\n uv = uv * LUT_SCALE + LUT_BIAS;\n float scale = texture2D( ltc_2, uv ).w;\n float result = len * scale;\n*/\n return vec3( result );\n}\n// End Rect Area Light\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n float dotNV = saturate( dot( normal, viewDir ) );\n vec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n return specularColor * brdf.x + brdf.y;\n} // validated\n// Fdez-Ag\xfcera\'s "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting"\n// Approximates multiscattering in order to preserve energy.\n// http://www.jcgt.org/published/0008/01/03/\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n vec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n vec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n vec3 FssEss = F * brdf.x + brdf.y;\n float Ess = brdf.x + brdf.y;\n float Ems = 1.0 - Ess;\n vec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619; // 1/21\n vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n singleScatter += FssEss;\n multiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {\n // geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\n return 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n //float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n //float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n} // validated\n// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n return sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L94\nfloat D_Charlie(float roughness, float NoH) {\n // Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF"\n float invAlpha = 1.0 / roughness;\n float cos2h = NoH * NoH;\n float sin2h = max(1.0 - cos2h, 0.0078125); // 2^(-14/2), so sin2h^2 > 0 in fp16\n return (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L136\nfloat V_Neubelt(float NoV, float NoL) {\n // Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"\n return saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n vec3 N = geometry.normal;\n vec3 V = geometry.viewDir;\n vec3 H = normalize( V + L );\n float dotNH = saturate( dot( N, H ) );\n return specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif\n'; -exports.default = _default; diff --git a/crates/swc/tests/fixture/deno/paths/cjs-001/output/index.ts b/crates/swc/tests/fixture/deno/paths/cjs-001/output/index.ts index c84a45a5d1e..9f255ccd22b 100644 --- a/crates/swc/tests/fixture/deno/paths/cjs-001/output/index.ts +++ b/crates/swc/tests/fixture/deno/paths/cjs-001/output/index.ts @@ -1,3 +1,6 @@ "use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); require("./src/dep"); require("./src2/dep-2"); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2126/output/packages/a/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2126/output/packages/a/src/index.ts index d8b6f80f8b9..145f4dee5a4 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2126/output/packages/a/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2126/output/packages/a/src/index.ts @@ -2,7 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.displayA = displayA; +Object.defineProperty(exports, "displayA", { + get: ()=>displayA, + enumerable: true +}); function displayA() { return "Display A"; } diff --git a/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts index 85c71f5f87e..758fa00b755 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts @@ -1,3 +1,6 @@ "use strict"; -var _a = require("../packages/a/src/index"); -console.log(`${(0, _a).displayA()}`); +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _a = require("../packages/a/src/index"); +console.log(`${(0, _a.displayA)()}`); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2724/output/packages/a/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2724/output/packages/a/src/index.ts index d8b6f80f8b9..145f4dee5a4 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2724/output/packages/a/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2724/output/packages/a/src/index.ts @@ -2,7 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.displayA = displayA; +Object.defineProperty(exports, "displayA", { + get: ()=>displayA, + enumerable: true +}); function displayA() { return "Display A"; } diff --git a/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts index 7fe951aa964..8e922119871 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts @@ -1,8 +1,9 @@ "use strict"; -var _interop_require_wildcard = require("../../../../../../../../../packages/swc-helpers/src/_interop_require_wildcard.mjs").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _interopRequireWildcard = require("../../../../../../../../../packages/swc-helpers/src/_interop_require_wildcard.mjs").default; (async function() { - const { displayA } = await Promise.resolve().then(function() { - return _interop_require_wildcard(require("../packages/a/src/index")); - }); + const { displayA } = await Promise.resolve("../packages/a/src/index").then((p)=>_interopRequireWildcard(require(p))); console.log(displayA()); })(); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2753/2-cjs/output/src/command/restore.ts b/crates/swc/tests/fixture/deno/paths/issue-2753/2-cjs/output/src/command/restore.ts index fb90ac3ae16..7793058058c 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2753/2-cjs/output/src/command/restore.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2753/2-cjs/output/src/command/restore.ts @@ -1,2 +1,5 @@ "use strict"; -var _config = require("../config"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _config = require("../config"); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/core/utils/utilFile.ts b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/core/utils/utilFile.ts index 00ce3625bf2..8e5407a6a43 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/core/utils/utilFile.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/core/utils/utilFile.ts @@ -2,5 +2,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.test = test; +Object.defineProperty(exports, "test", { + get: ()=>test, + enumerable: true +}); function test() {} diff --git a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts index fd75e7545b3..347a167bd2a 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts @@ -1,4 +1,7 @@ "use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); require("./core/module/moduleFile"); require("./core/utils"); require("./core/utilFile"); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/utils/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/utils/index.ts index 28496e4b1b5..cc7efc33e6c 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/utils/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/utils/index.ts @@ -2,7 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.utilFn = utilFn; -var _utilFile = require("../core/utils/utilFile"); -(0, _utilFile).test(); +Object.defineProperty(exports, "utilFn", { + get: ()=>utilFn, + enumerable: true +}); +const _utilFile = require("../core/utils/utilFile"); +(0, _utilFile.test)(); function utilFn() {} diff --git a/crates/swc/tests/fixture/issues-1xxx/1135/1/input/.swcrc b/crates/swc/tests/fixture/issues-1xxx/1135/1/input/.swcrc new file mode 100644 index 00000000000..0f6b51f4b67 --- /dev/null +++ b/crates/swc/tests/fixture/issues-1xxx/1135/1/input/.swcrc @@ -0,0 +1,16 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true + }, + "target": "es2020", + "transform": { + "legacyDecorator": true + } + }, + "module": { + "type": "commonjs", + "lazy": true + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-1xxx/1135/1/input/index.ts b/crates/swc/tests/fixture/issues-1xxx/1135/1/input/index.ts new file mode 100644 index 00000000000..7fb5b5d9ddd --- /dev/null +++ b/crates/swc/tests/fixture/issues-1xxx/1135/1/input/index.ts @@ -0,0 +1,6 @@ +import { Class } from "module"; + +class MyClass extends Class { + @Class.Decorator() + async method() {} +} diff --git a/crates/swc/tests/fixture/issues-1xxx/1135/1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1135/1/output/index.ts new file mode 100644 index 00000000000..cc98baf131e --- /dev/null +++ b/crates/swc/tests/fixture/issues-1xxx/1135/1/output/index.ts @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _tsDecorate() { + const data = require("@swc/helpers/lib/_ts_decorate.js").default; + _tsDecorate = function() { + return data; + }; + return data; +} +function _module() { + const data = require("module"); + _module = function() { + return data; + }; + return data; +} +class MyClass extends _module().Class { + async method() {} +} +_tsDecorate()([ + _module().Class.Decorator() +], MyClass.prototype, "method", null); diff --git a/crates/swc/tests/fixture/issues-1xxx/1160/output/entry.ts b/crates/swc/tests/fixture/issues-1xxx/1160/output/entry.ts index 07d93e7070d..47c111acb03 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1160/output/entry.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1160/output/entry.ts @@ -1,6 +1,9 @@ "use strict"; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; -var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; +const _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; var MyEnum; (function(MyEnum) { MyEnum["x"] = "xxx"; @@ -8,9 +11,9 @@ var MyEnum; })(MyEnum || (MyEnum = {})); class Xpto { } -_ts_decorate([ +_tsDecorate([ Decorator(), - _ts_metadata("design:type", String) + _tsMetadata("design:type", String) ], Xpto.prototype, "value", void 0); function Decorator() { return function(...args) {}; diff --git a/crates/swc/tests/fixture/issues-1xxx/1213/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1213/output/index.js index df6dacbdf20..83e0778da84 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1213/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1213/output/index.js @@ -2,17 +2,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _foo = _interop_require_default(require("foo")); -class NotOK { - constructor(){ - console.log(_foo.default); - } -} -exports.default = NotOK; +Object.defineProperty(exports, "default", { + get: ()=>NotOK, + enumerable: true +}); +const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +const _foo = _interopRequireDefault(require("foo")); class OK { constructor(){ console.log(_foo.default); } } +class NotOK { + constructor(){ + console.log(_foo.default); + } +} diff --git a/crates/swc/tests/fixture/issues-1xxx/1232/cjs/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1232/cjs/output/index.js index 0d0e974becb..70380c4b10b 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1232/cjs/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1232/cjs/output/index.js @@ -1,5 +1,8 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var action = _interop_require_wildcard(require("./actions")); -console.log(action); -console.log(action.foo); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _actions = _interopRequireWildcard(require("./actions")); +console.log(_actions); +console.log(_actions.foo); diff --git a/crates/swc/tests/fixture/issues-1xxx/1259/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1259/output/index.js index ff114e425e5..f5f75e26611 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1259/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1259/output/index.js @@ -1,6 +1,9 @@ -var _tagged_template_literal = require("@swc/helpers/lib/_tagged_template_literal.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _taggedTemplateLiteral = require("@swc/helpers/lib/_tagged_template_literal.js").default; function _templateObject() { - var data = _tagged_template_literal([ + var data = _taggedTemplateLiteral([ "'#ERROR'" ]); _templateObject = function _templateObject() { diff --git a/crates/swc/tests/fixture/issues-1xxx/1278/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1278/output/index.ts index 121f8f84a0b..8295065ec9d 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1278/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1278/output/index.ts @@ -1,6 +1,9 @@ "use strict"; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; -var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; +const _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; function MyDecorator(klass) { return ()=>{ // do something @@ -9,8 +12,8 @@ function MyDecorator(klass) { } class MyClass { } -_ts_decorate([ +_tsDecorate([ MyDecorator(MyClass), - _ts_metadata("design:type", String) + _tsMetadata("design:type", String) ], MyClass.prototype, "prop", void 0); console.log(new MyClass()); diff --git a/crates/swc/tests/fixture/issues-1xxx/1307/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1307/output/index.ts index 58b7edda7fb..e0cdd542d93 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1307/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1307/output/index.ts @@ -2,7 +2,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.foo = void 0; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _foo = _interop_require_wildcard(require("./foo")); -exports.foo = _foo; +Object.defineProperty(exports, "foo", { + get: ()=>_foo, + enumerable: true +}); +const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +const _foo = _interopRequireWildcard(require("./foo")); diff --git a/crates/swc/tests/fixture/issues-1xxx/1309/case1/output/index.map b/crates/swc/tests/fixture/issues-1xxx/1309/case1/output/index.map index cebbcbc09e9..1f99bca567b 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1309/case1/output/index.map +++ b/crates/swc/tests/fixture/issues-1xxx/1309/case1/output/index.map @@ -1,5 +1,5 @@ { - "mappings": "AAAA;;;;;AAAO,MAAMA,GAAG,GAAG,CAAC,AAAC;QAARA,GAAG,GAAHA,GAAG", + "mappings": "AAAA;;;;+BAAaA,KAAG;aAAHA,GAAG;;;AAAT,MAAMA,GAAG,GAAG,CAAC,AAAC", "names": [ "foo" ], diff --git a/crates/swc/tests/fixture/issues-1xxx/1309/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1309/case1/output/index.ts index 80b8bb6072b..308c329210d 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1309/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1309/case1/output/index.ts @@ -2,6 +2,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.foo = void 0; +Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true +}); const foo = 1; -exports.foo = foo; diff --git a/crates/swc/tests/fixture/issues-1xxx/1333/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1333/case1/output/index.js index 9b06ab9da7b..79c4fb42af1 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1333/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1333/case1/output/index.js @@ -1,17 +1,20 @@ "use strict"; -var _class_private_field_get = require("@swc/helpers/lib/_class_private_field_get.js").default; -var _class_private_field_init = require("@swc/helpers/lib/_class_private_field_init.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _classPrivateFieldGet = require("@swc/helpers/lib/_class_private_field_get.js").default; +const _classPrivateFieldInit = require("@swc/helpers/lib/_class_private_field_init.js").default; var _ws = /*#__PURE__*/ new WeakMap(), _ws2 = /*#__PURE__*/ new WeakMap(); class Foo { get connected() { - return _class_private_field_get(this, _ws2) && _class_private_field_get(this, _ws).readyState === _ws1.default.OPEN; + return _classPrivateFieldGet(this, _ws2) && _classPrivateFieldGet(this, _ws).readyState === _ws1.default.OPEN; } constructor(){ - _class_private_field_init(this, _ws, { + _classPrivateFieldInit(this, _ws, { writable: true, value: void 0 }); - _class_private_field_init(this, _ws2, { + _classPrivateFieldInit(this, _ws2, { writable: true, value: void 0 }); diff --git a/crates/swc/tests/fixture/issues-1xxx/1333/case2/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1333/case2/output/index.js index 59afe4da27b..52cc9fa5b5a 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1333/case2/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1333/case2/output/index.js @@ -2,15 +2,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _class_private_field_get = require("@swc/helpers/lib/_class_private_field_get.js").default; -var _class_private_field_init = require("@swc/helpers/lib/_class_private_field_init.js").default; -var _class_private_field_set = require("@swc/helpers/lib/_class_private_field_set.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _ws = _interop_require_default(require("ws")); -var _utils = require("../../utils"); -var _connection = require("./connection"); -var _serialization = require("./serialization"); -var _compression = require("./compression"); +Object.defineProperty(exports, "Shard", { + get: ()=>Shard, + enumerable: true +}); +const _classPrivateFieldGet = require("@swc/helpers/lib/_class_private_field_get.js").default; +const _classPrivateFieldInit = require("@swc/helpers/lib/_class_private_field_init.js").default; +const _classPrivateFieldSet = require("@swc/helpers/lib/_class_private_field_set.js").default; +const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +const _ws = _interopRequireDefault(require("ws")); +const _utils = require("../../utils"); +const _connection = require("./connection"); +const _serialization = require("./serialization"); +const _compression = require("./compression"); const connectionStates = Object.keys(_ws.default); var /** * The serialization handler. @@ -42,13 +46,13 @@ class Shard extends _utils.Emitter { * The current sequence * @type {number} */ get seq() { - return _class_private_field_get(this, _seq); + return _classPrivateFieldGet(this, _seq); } /** * The closing sequence. * @type {number} */ get closingSeq() { - return _class_private_field_get(this, _closingSeq); + return _classPrivateFieldGet(this, _closingSeq); } /** * The client instance. @@ -60,7 +64,7 @@ class Shard extends _utils.Emitter { * Whether this shard is connected to the gateway or not. * @type {boolean} */ get connected() { - return _class_private_field_get(this, _ws1) && _class_private_field_get(this, _ws1).readyState === _ws.default.OPEN; + return _classPrivateFieldGet(this, _ws1) && _classPrivateFieldGet(this, _ws1).readyState === _ws.default.OPEN; } /** * Send a new packet to the discord gateway. @@ -73,16 +77,16 @@ class Shard extends _utils.Emitter { if (++_i < _w) { return; } - const encoded = _class_private_field_get(this, _serialization1).encode(data); - _class_private_field_get(this, _ws1).send(encoded); + const encoded = _classPrivateFieldGet(this, _serialization1).encode(data); + _classPrivateFieldGet(this, _ws1).send(encoded); }; if (data.op === _utils.GatewayOp.PRESENCE_UPDATE) { ++_w; - _class_private_field_get(this, _presenceBucket).queue(func, prioritized); + _classPrivateFieldGet(this, _presenceBucket).queue(func, prioritized); } - return _class_private_field_get(this, _bucket).queue(func, prioritized); + return _classPrivateFieldGet(this, _bucket).queue(func, prioritized); } - _class_private_field_get(this, _queue)[prioritized ? "unshift" : "push"](data); + _classPrivateFieldGet(this, _queue)[prioritized ? "unshift" : "push"](data); } /** * Destroys this shard. @@ -95,14 +99,14 @@ class Shard extends _utils.Emitter { this.heartbeat.reset(); this.session.clearHelloTimeout(); // (Step 1) Close the websocket connection. - if (_class_private_field_get(this, _ws1)) { - if (_class_private_field_get(this, _ws1).readyState === _ws.default.OPEN) { - _class_private_field_get(this, _ws1).close(code); + if (_classPrivateFieldGet(this, _ws1)) { + if (_classPrivateFieldGet(this, _ws1).readyState === _ws.default.OPEN) { + _classPrivateFieldGet(this, _ws1).close(code); } else { - this._debug(`Ws State: ${connectionStates[_class_private_field_get(this, _ws1).readyState]}`); + this._debug(`Ws State: ${connectionStates[_classPrivateFieldGet(this, _ws1).readyState]}`); this._cleanupConnection(); try { - _class_private_field_get(this, _ws1).close(code); + _classPrivateFieldGet(this, _ws1).close(code); } catch { // no-op } @@ -116,19 +120,19 @@ class Shard extends _utils.Emitter { } else if (emit) { this.emit(_utils.ShardEvent.DESTROYED); } - _class_private_field_set(this, _ws1, undefined); + _classPrivateFieldSet(this, _ws1, undefined); // (Step 4) Set the shard status to disconnected. this.status = _utils.Status.DISCONNECTED; // (Step 5) Cache ze current sequence! - if (_class_private_field_get(this, _seq) !== -1) { - _class_private_field_set(this, _closingSeq, _class_private_field_get(this, _seq)); + if (_classPrivateFieldGet(this, _seq) !== -1) { + _classPrivateFieldSet(this, _closingSeq, _classPrivateFieldGet(this, _seq)); } // (Step 6) Reset the shit. if (reset) { - _class_private_field_set(this, _seq, -1); + _classPrivateFieldSet(this, _seq, -1); this.session.reset(); } - _class_private_field_set(this, _bucket, new _utils.Bucket(120, 6e4)); + _classPrivateFieldSet(this, _bucket, new _utils.Bucket(120, 6e4)); } connect() { /* Step 0 - Check if a connection already exists. If so identify the session. */ if (this.connected) { @@ -136,7 +140,7 @@ class Shard extends _utils.Emitter { this.session.identify(); return; } - /* Step 1 - If a socket is already present, destroy it. */ if (_class_private_field_get(this, _ws1)) { + /* Step 1 - If a socket is already present, destroy it. */ if (_classPrivateFieldGet(this, _ws1)) { this._debug("A connection is already present, cleaning up..."); this.destroy({ emit: false @@ -147,10 +151,10 @@ class Shard extends _utils.Emitter { // Step 2.1 - Serialization const encoding = this.manager.options.useEtf ? "etf" : "json"; qs.append("encoding", encoding); - _class_private_field_set(this, _serialization1, _serialization.Serialization.create(encoding)); + _classPrivateFieldSet(this, _serialization1, _serialization.Serialization.create(encoding)); // Step 2.2 - Compression if (this.manager.compression) { - _class_private_field_set(this, _compression1, _compression.Compression.create(this.manager.compression).on("data", (buffer)=>this._packet(buffer)).on("error", (error)=>this.emit(_utils.ShardEvent.ERROR, error)).on("debug", (message)=>this._debug(message))); + _classPrivateFieldSet(this, _compression1, _compression.Compression.create(this.manager.compression).on("data", (buffer)=>this._packet(buffer)).on("error", (error)=>this.emit(_utils.ShardEvent.ERROR, error)).on("debug", (message)=>this._debug(message))); qs.append("compress", "zlib-stream"); } /* Step 5 - Set the status and wait for the hello op code. */ this.status = this.status === _utils.Status.DISCONNECTED ? _utils.Status.RECONNECTING : _utils.Status.CONNECTING; @@ -160,16 +164,16 @@ class Shard extends _utils.Emitter { * @type {number} */ this.connectedAt = Date.now(); /* Step 6 - Connect to the gateway. */ const uri = this.manager.gatewayUrl.replace(/\/*$/m, ""); - _class_private_field_set(this, _ws1, new _ws.default(`${uri}/?${qs}`)); - /* Step 7 - Attach the listeners. */ _class_private_field_get(this, _ws1).onopen = this._open.bind(this); - _class_private_field_get(this, _ws1).onclose = this._close.bind(this); - _class_private_field_get(this, _ws1).onerror = this._error.bind(this); - _class_private_field_get(this, _ws1).onmessage = this._message.bind(this); + _classPrivateFieldSet(this, _ws1, new _ws.default(`${uri}/?${qs}`)); + /* Step 7 - Attach the listeners. */ _classPrivateFieldGet(this, _ws1).onopen = this._open.bind(this); + _classPrivateFieldGet(this, _ws1).onclose = this._close.bind(this); + _classPrivateFieldGet(this, _ws1).onerror = this._error.bind(this); + _classPrivateFieldGet(this, _ws1).onmessage = this._message.bind(this); } _packet(raw) { /** @type {DiscordPacket} */ let pak; try { - pak = _class_private_field_get(this, _serialization1).decode(raw); + pak = _classPrivateFieldGet(this, _serialization1).decode(raw); this.manager.emit(_utils.ClientEvent.RAW_PACKET, pak, this); } catch (e) { this.manager.client.emit(_utils.ClientEvent.SHARD_ERROR, e, this); @@ -198,10 +202,10 @@ class Shard extends _utils.Emitter { break; } if (pak.s !== null) { - if (_class_private_field_get(this, _seq) !== -1 && pak.s > _class_private_field_get(this, _seq) + 1) { - this._debug(`Non-consecutive sequence [${_class_private_field_get(this, _seq)} => ${pak.s}]`); + if (_classPrivateFieldGet(this, _seq) !== -1 && pak.s > _classPrivateFieldGet(this, _seq) + 1) { + this._debug(`Non-consecutive sequence [${_classPrivateFieldGet(this, _seq)} => ${pak.s}]`); } - _class_private_field_set(this, _seq, pak.s); + _classPrivateFieldSet(this, _seq, pak.s); } switch(pak.op){ case _utils.GatewayOp.HELLO: @@ -220,7 +224,7 @@ class Shard extends _utils.Emitter { this.session.resume(); break; } - _class_private_field_set(this, _seq, -1); + _classPrivateFieldSet(this, _seq, -1); this.session.reset(); this.status = _utils.Status.RECONNECTING; this.emit(_utils.ShardEvent.INVALID_SESSION); @@ -265,11 +269,11 @@ class Shard extends _utils.Emitter { */ _open() { var ref; this.status = _utils.Status.HANDSHAKING; - this._debug(`Connected. ${(ref = _class_private_field_get(this, _ws1)) === null || ref === void 0 ? void 0 : ref.url} in ${Date.now() - this.connectedAt}`); - if (_class_private_field_get(this, _queue).length) { - this._debug(`${_class_private_field_get(this, _queue).length} packets waiting... sending all now.`); - while(_class_private_field_get(this, _queue).length){ - const pk = _class_private_field_get(this, _queue).shift(); + this._debug(`Connected. ${(ref = _classPrivateFieldGet(this, _ws1)) === null || ref === void 0 ? void 0 : ref.url} in ${Date.now() - this.connectedAt}`); + if (_classPrivateFieldGet(this, _queue).length) { + this._debug(`${_classPrivateFieldGet(this, _queue).length} packets waiting... sending all now.`); + while(_classPrivateFieldGet(this, _queue).length){ + const pk = _classPrivateFieldGet(this, _queue).shift(); if (!pk) { break; } @@ -295,13 +299,13 @@ class Shard extends _utils.Emitter { var ref; const reason = (ref = evt.reason || _utils.GatewayCloseCode[evt.code]) !== null && ref !== void 0 ? ref : "unknown"; this._debug(`Closed; Code = ${evt.code}, Clean? = ${evt.wasClean}, Reason = ${reason}`); - if (_class_private_field_get(this, _seq) !== -1) { - _class_private_field_set(this, _closingSeq, _class_private_field_get(this, _seq)); + if (_classPrivateFieldGet(this, _seq) !== -1) { + _classPrivateFieldSet(this, _closingSeq, _classPrivateFieldGet(this, _seq)); } - _class_private_field_set(this, _seq, -1); + _classPrivateFieldSet(this, _seq, -1); this.heartbeat.reset(); this.session.clearHelloTimeout(); - if (_class_private_field_get(this, _ws1)) { + if (_classPrivateFieldGet(this, _ws1)) { this._cleanupConnection(); } this.status = _utils.Status.DISCONNECTED; @@ -316,13 +320,13 @@ class Shard extends _utils.Emitter { * @param {WebSocket.MessageEvent} evt * @private */ _message(evt) { - return _class_private_field_get(this, _compression1) ? _class_private_field_get(this, _compression1).add(evt.data) : this._packet(evt.data); + return _classPrivateFieldGet(this, _compression1) ? _classPrivateFieldGet(this, _compression1).add(evt.data) : this._packet(evt.data); } /** * Cleans up the WebSocket connection listeners. * @private */ _cleanupConnection() { - _class_private_field_get(this, _ws1).onopen = _class_private_field_get(this, _ws1).onclose = _class_private_field_get(this, _ws1).onerror = _class_private_field_get(this, _ws1).onmessage = null; + _classPrivateFieldGet(this, _ws1).onopen = _classPrivateFieldGet(this, _ws1).onclose = _classPrivateFieldGet(this, _ws1).onerror = _classPrivateFieldGet(this, _ws1).onmessage = null; } /** * Used for debugging shard stuff. @@ -336,35 +340,35 @@ class Shard extends _utils.Emitter { * @param {number} id The ID of this shard. */ constructor(manager, id){ super(); - _class_private_field_init(this, _serialization1, { + _classPrivateFieldInit(this, _serialization1, { writable: true, value: void 0 }); - _class_private_field_init(this, _compression1, { + _classPrivateFieldInit(this, _compression1, { writable: true, value: void 0 }); - _class_private_field_init(this, _seq, { + _classPrivateFieldInit(this, _seq, { writable: true, value: void 0 }); - _class_private_field_init(this, _closingSeq, { + _classPrivateFieldInit(this, _closingSeq, { writable: true, value: void 0 }); - _class_private_field_init(this, _bucket, { + _classPrivateFieldInit(this, _bucket, { writable: true, value: void 0 }); - _class_private_field_init(this, _presenceBucket, { + _classPrivateFieldInit(this, _presenceBucket, { writable: true, value: void 0 }); - _class_private_field_init(this, _ws1, { + _classPrivateFieldInit(this, _ws1, { writable: true, value: void 0 }); - _class_private_field_init(this, _queue, { + _classPrivateFieldInit(this, _queue, { writable: true, value: void 0 }); @@ -396,13 +400,13 @@ class Shard extends _utils.Emitter { * Guilds that are expected to be received. * @type {Set} */ this.expectedGuilds = new Set(); - _class_private_field_set(this, _seq, -1); - _class_private_field_set(this, _closingSeq, 0); - _class_private_field_set(this, _queue, []); - _class_private_field_set(this, _bucket, new _utils.Bucket(120, 6e4, { + _classPrivateFieldSet(this, _seq, -1); + _classPrivateFieldSet(this, _closingSeq, 0); + _classPrivateFieldSet(this, _queue, []); + _classPrivateFieldSet(this, _bucket, new _utils.Bucket(120, 6e4, { reservedTokens: 5 })); - _class_private_field_set(this, _presenceBucket, new _utils.Bucket(5, 6e4)); + _classPrivateFieldSet(this, _presenceBucket, new _utils.Bucket(5, 6e4)); } } /** * @typedef {Object} DiscordPacket @@ -417,4 +421,3 @@ class Shard extends _utils.Emitter { * @property {boolean} [log=false] Whether to emit a debug log. * @property {number} [code=1000] The code to use. */ -exports.Shard = Shard; diff --git a/crates/swc/tests/fixture/issues-1xxx/1333/case3/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1333/case3/output/index.js index 07143250523..37ec4ce3fee 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1333/case3/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1333/case3/output/index.js @@ -2,13 +2,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _class_private_field_get = require("@swc/helpers/lib/_class_private_field_get.js").default; -var _class_private_field_init = require("@swc/helpers/lib/_class_private_field_init.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _nodeFetch = _interop_require_default(require("node-fetch")); -var _abortSignal = require("./misc/AbortSignal"); -var _errors = require("../../errors"); -var _utils = require("../../utils"); +Object.defineProperty(exports, "RequestHandler", { + get: ()=>RequestHandler, + enumerable: true +}); +const _classPrivateFieldGet = require("@swc/helpers/lib/_class_private_field_get.js").default; +const _classPrivateFieldInit = require("@swc/helpers/lib/_class_private_field_init.js").default; +const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +const _nodeFetch = _interopRequireDefault(require("node-fetch")); +const _abortSignal = require("./misc/AbortSignal"); +const _errors = require("../../errors"); +const _utils = require("../../utils"); const headers = [ "x-ratelimit-limit", "x-ratelimit-remaining", @@ -25,7 +29,7 @@ class RequestHandler { * Whether this handler is inactive or not. * @return {boolean} */ get inactive() { - return !_class_private_field_get(this, _queue).remaining && !this._limited; + return !_classPrivateFieldGet(this, _queue).remaining && !this._limited; } /** * Whether the rate-limit bucket is currently limited. @@ -82,7 +86,7 @@ class RequestHandler { * * @return {Promise<*>} */ async push(url, request) { - await _class_private_field_get(this, _queue).wait(); + await _classPrivateFieldGet(this, _queue).wait(); try { await this.rest.globalTimeout; if (this._limited) { @@ -100,11 +104,11 @@ class RequestHandler { method: request.method, url }); - await (0, _utils).sleep(this._untilReset); + await (0, _utils.sleep)(this._untilReset); } return this._make(url, request); } finally{ - _class_private_field_get(this, _queue).next(); + _classPrivateFieldGet(this, _queue).next(); } } /** @@ -120,7 +124,7 @@ class RequestHandler { const timeout = _utils.Timers.setTimeout(()=>signal.abort(), this.rest.options.timeout); let res; try { - res = await (0, _nodeFetch).default(url, { + res = await (0, _nodeFetch.default)(url, { ...request, signal }); @@ -142,7 +146,7 @@ class RequestHandler { _retry = ~~reset * (cf ? 1000 : 1 + this.rest.options.offset); } if (res.headers.get("X-RateLimit-Global")) { - this.rest.globalTimeout = (0, _utils).sleep(_retry).then(()=>{ + this.rest.globalTimeout = (0, _utils.sleep)(_retry).then(()=>{ this.api.globalTimeout = null; }); } @@ -152,7 +156,7 @@ class RequestHandler { } if (res.status === 429) { this.rest.client.emit(_utils.ClientEvent.LIMITED, `Hit a 429 on route: ${this.id}, Retrying After: ${_retry}ms`); - await (0, _utils).sleep(_retry); + await (0, _utils.sleep)(_retry); return this._make(url, request, tries++); } if (res.status >= 500 && res.status < 600) { @@ -171,7 +175,7 @@ class RequestHandler { * @param {Rest} rest The REST Manager. * @param {string} id The ID of this request handler. */ constructor(rest, id){ - _class_private_field_init(this, _queue, { + _classPrivateFieldInit(this, _queue, { writable: true, value: new _utils.AsyncQueue() }); @@ -197,7 +201,6 @@ class RequestHandler { */ this.limit = Infinity; } } -exports.RequestHandler = RequestHandler; /** * Bulk fetch headers from a node-fetch response. * @param {Response} res The request response. diff --git a/crates/swc/tests/fixture/issues-1xxx/1341/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1341/case1/output/index.ts index 640ddab59de..a286e6d96ca 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1341/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1341/case1/output/index.ts @@ -1,12 +1,15 @@ "use strict"; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; class A { foo() { var _this = this; - return _async_to_generator(function*() { + return _asyncToGenerator(function*() { try { return yield (function() { - var _ref = _async_to_generator(function*(x) { + var _ref = _asyncToGenerator(function*(x) { return x + _this.val; }); return function(x) { diff --git a/crates/swc/tests/fixture/issues-1xxx/1362/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1362/case1/output/index.ts index aa860ad1af6..5a0a95ac6c9 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1362/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1362/case1/output/index.ts @@ -2,13 +2,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.AppController = void 0; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; -var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default; -var _ts_param = require("@swc/helpers/lib/_ts_param.js").default; -var _common = require("@nestjs/common"); -var _appService = require("./app.service"); -var _createUserDto = require("./dtos/CreateUserDto"); +Object.defineProperty(exports, "AppController", { + get: ()=>AppController, + enumerable: true +}); +const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; +const _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; +const _tsParam = require("@swc/helpers/lib/_ts_param.js").default; +const _common = require("@nestjs/common"); +const _appService = require("./app.service"); +const _createUserDto = require("./dtos/CreateUserDto"); let AppController = class AppController { async getHello() { const result = await this.appService.getHello(); @@ -22,24 +25,23 @@ let AppController = class AppController { this.appService = appService; } }; -exports.AppController = AppController; -_ts_decorate([ - (0, _common).Get(), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", []) +_tsDecorate([ + (0, _common.Get)(), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", []) ], AppController.prototype, "getHello", null); -_ts_decorate([ - (0, _common).Post(), - _ts_param(0, (0, _common).Body()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +_tsDecorate([ + (0, _common.Post)(), + _tsParam(0, (0, _common.Body)()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof _createUserDto.CreateUserDto === "undefined" ? Object : _createUserDto.CreateUserDto ]) ], AppController.prototype, "create", null); -exports.AppController = AppController = _ts_decorate([ - (0, _common).Controller(), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +AppController = _tsDecorate([ + (0, _common.Controller)(), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof _appService.AppService === "undefined" ? Object : _appService.AppService ]) ], AppController); diff --git a/crates/swc/tests/fixture/issues-1xxx/1362/case2/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1362/case2/output/index.ts index 00c1c94af55..3fc2fc981c7 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1362/case2/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1362/case2/output/index.ts @@ -1,3 +1,3 @@ "use strict"; -var request = require("supertest"); -console.log(request()); +const _supertest = require("supertest"); +console.log(_supertest()); diff --git a/crates/swc/tests/fixture/issues-1xxx/1421/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1421/case1/output/index.ts index c7ae1206b05..e60a82cf766 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1421/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1421/case1/output/index.ts @@ -1,7 +1,10 @@ "use strict"; -var _class_call_check = require("@swc/helpers/lib/_class_call_check.js").default; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; -var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _classCallCheck = require("@swc/helpers/lib/_class_call_check.js").default; +var _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; +var _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; require("reflect-metadata"); var COL_KEY = Symbol("col"); var column = function() { @@ -11,9 +14,9 @@ var column = function() { }; var User = function User() { "use strict"; - _class_call_check(this, User); + _classCallCheck(this, User); }; -_ts_decorate([ +_tsDecorate([ column(), - _ts_metadata("design:type", String) + _tsMetadata("design:type", String) ], User.prototype, "currency", void 0); diff --git a/crates/swc/tests/fixture/issues-1xxx/1423/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1423/case1/output/index.js index 3580fe36ad6..7488b7222af 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1423/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1423/case1/output/index.js @@ -1,4 +1,7 @@ "use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); var _necessary = require("necessary"); var second = _necessary.arrayUtilities.second; var elements = [ diff --git a/crates/swc/tests/fixture/issues-1xxx/1448/case1/input/.swcrc b/crates/swc/tests/fixture/issues-1xxx/1448/case1/input/.swcrc index 70e636ce3fc..b58283b8f46 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1448/case1/input/.swcrc +++ b/crates/swc/tests/fixture/issues-1xxx/1448/case1/input/.swcrc @@ -8,5 +8,8 @@ "tsx": true }, "loose": true + }, + "module": { + "type": "nodenext" } -} +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-1xxx/1448/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1448/case1/output/index.ts index 272706b9fc2..9694556cf46 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1448/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1448/case1/output/index.ts @@ -1,3 +1,4 @@ -var F = require("yaml"); +import { createRequire as _createRequire } from "module"; +var __require = _createRequire(import.meta.url); +var F = __require("yaml"); console.log(F); -export { }; diff --git a/crates/swc/tests/fixture/issues-1xxx/1454/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1454/case1/output/index.ts index 11efcb9c617..18e77fa1e01 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1454/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1454/case1/output/index.ts @@ -1,3 +1,9 @@ +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "AbstractProviderDeliveryService", { + get: ()=>AbstractProviderDeliveryService, + enumerable: true +}); class AbstractProviderDeliveryService { } -exports.AbstractProviderDeliveryService = AbstractProviderDeliveryService; diff --git a/crates/swc/tests/fixture/issues-1xxx/1454/case2/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1454/case2/output/index.ts index 11efcb9c617..18e77fa1e01 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1454/case2/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1454/case2/output/index.ts @@ -1,3 +1,9 @@ +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "AbstractProviderDeliveryService", { + get: ()=>AbstractProviderDeliveryService, + enumerable: true +}); class AbstractProviderDeliveryService { } -exports.AbstractProviderDeliveryService = AbstractProviderDeliveryService; diff --git a/crates/swc/tests/fixture/issues-1xxx/1455/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1455/case1/output/index.ts index 108bfd9dd52..64ac0944772 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1455/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1455/case1/output/index.ts @@ -1,8 +1,11 @@ "use strict"; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; const SampleData = typedModel("SampleVideo", VideosSchema, undefined, undefined, { byPlatform: function() { - var _ref = _async_to_generator(function*(platform) { + var _ref = _asyncToGenerator(function*(platform) { const result = yield this.find({ platform: { $eq: platform diff --git a/crates/swc/tests/fixture/issues-1xxx/1456/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1456/case1/output/index.ts index c79e8e85dfc..c7651f5e185 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1456/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1456/case1/output/index.ts @@ -1,17 +1,20 @@ "use strict"; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; -var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default; -var _ts_param = require("@swc/helpers/lib/_ts_param.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; +const _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; +const _tsParam = require("@swc/helpers/lib/_ts_param.js").default; // not work class MyClass1 { constructor(param1){ this.param1 = param1; } } -MyClass1 = _ts_decorate([ - _ts_param(0, Inject()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +MyClass1 = _tsDecorate([ + _tsParam(0, Inject()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof Injected === "undefined" ? Object : Injected ]) ], MyClass1); @@ -20,10 +23,10 @@ class MyClass2 { this.param1 = param1; } } -MyClass2 = _ts_decorate([ - _ts_param(0, Inject()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +MyClass2 = _tsDecorate([ + _tsParam(0, Inject()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof Injected === "undefined" ? Object : Injected ]) ], MyClass2); @@ -32,10 +35,10 @@ class MyClass3 { this.param1 = param1; } } -MyClass3 = _ts_decorate([ - _ts_param(0, Inject()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +MyClass3 = _tsDecorate([ + _tsParam(0, Inject()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof Injected === "undefined" ? Object : Injected ]) ], MyClass3); @@ -44,10 +47,10 @@ class MyClass4 { this.param1 = param1; } } -MyClass4 = _ts_decorate([ - _ts_param(0, Inject()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +MyClass4 = _tsDecorate([ + _tsParam(0, Inject()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof Injected === "undefined" ? Object : Injected ]) ], MyClass4); @@ -56,10 +59,10 @@ class MyClass5 { this.param1 = param1; } } -MyClass5 = _ts_decorate([ - _ts_param(0, Inject()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +MyClass5 = _tsDecorate([ + _tsParam(0, Inject()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof Injected === "undefined" ? Object : Injected ]) ], MyClass5); @@ -69,11 +72,11 @@ class MyClass6 { this.param2 = param2; } } -MyClass6 = _ts_decorate([ - _ts_param(0, Inject()), - _ts_param(1, Inject()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +MyClass6 = _tsDecorate([ + _tsParam(0, Inject()), + _tsParam(1, Inject()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof Injected === "undefined" ? Object : Injected, typeof Injected === "undefined" ? Object : Injected ]) diff --git a/crates/swc/tests/fixture/issues-1xxx/1456/case2/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1456/case2/output/index.ts index fab4a4dc9ef..cf950fcecfe 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1456/case2/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1456/case2/output/index.ts @@ -1,15 +1,18 @@ "use strict"; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; -var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default; -var _ts_param = require("@swc/helpers/lib/_ts_param.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; +const _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; +const _tsParam = require("@swc/helpers/lib/_ts_param.js").default; // work class MyClass1 { constructor(param1){} } -MyClass1 = _ts_decorate([ - _ts_param(0, Inject()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +MyClass1 = _tsDecorate([ + _tsParam(0, Inject()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof Injected === "undefined" ? Object : Injected ]) ], MyClass1); @@ -18,11 +21,11 @@ class MyClass2 { this.param1 = param1; } } -MyClass2 = _ts_decorate([ - _ts_param(0, Inject()), - _ts_param(1, Inject()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +MyClass2 = _tsDecorate([ + _tsParam(0, Inject()), + _tsParam(1, Inject()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof Injected === "undefined" ? Object : Injected, typeof Injected === "undefined" ? Object : Injected ]) @@ -32,11 +35,11 @@ class MyClass3 { this.param2 = param2; } } -MyClass3 = _ts_decorate([ - _ts_param(0, Inject()), - _ts_param(1, Inject()), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ +MyClass3 = _tsDecorate([ + _tsParam(0, Inject()), + _tsParam(1, Inject()), + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ typeof Injected === "undefined" ? Object : Injected, typeof Injected === "undefined" ? Object : Injected ]) diff --git a/crates/swc/tests/fixture/issues-1xxx/1490/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1490/case1/output/index.js index 9d4edd473da..0ed20403cc7 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1490/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1490/case1/output/index.js @@ -1,23 +1,26 @@ "use strict"; -var _class_call_check = require("@swc/helpers/lib/_class_call_check.js").default; -var _create_class = require("@swc/helpers/lib/_create_class.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _classCallCheck = require("@swc/helpers/lib/_class_call_check.js").default; +var _createClass = require("@swc/helpers/lib/_create_class.js").default; var _get = require("@swc/helpers/lib/_get.js").default; -var _get_prototype_of = require("@swc/helpers/lib/_get_prototype_of.js").default; +var _getPrototypeOf = require("@swc/helpers/lib/_get_prototype_of.js").default; var _inherits = require("@swc/helpers/lib/_inherits.js").default; -var _create_super = require("@swc/helpers/lib/_create_super.js").default; +var _createSuper = require("@swc/helpers/lib/_create_super.js").default; var ColouredCanvasElement = /*#__PURE__*/ function(CanvasElement1) { "use strict"; _inherits(ColouredCanvasElement, CanvasElement1); - var _super = _create_super(ColouredCanvasElement); + var _super = _createSuper(ColouredCanvasElement); function ColouredCanvasElement() { - _class_call_check(this, ColouredCanvasElement); + _classCallCheck(this, ColouredCanvasElement); return _super.apply(this, arguments); } - _create_class(ColouredCanvasElement, [ + _createClass(ColouredCanvasElement, [ { key: "createFacets", value: function createFacets(hidden) { - hidden = _get(_get_prototype_of(ColouredCanvasElement.prototype), "createFacets", this).call(this, hidden); + hidden = _get(_getPrototypeOf(ColouredCanvasElement.prototype), "createFacets", this).call(this, hidden); } } ]); diff --git a/crates/swc/tests/fixture/issues-1xxx/1490/full/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1490/full/output/index.js index 68f91b742d7..44f5cab9a89 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1490/full/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1490/full/output/index.js @@ -1,16 +1,19 @@ "use strict"; -var _class_call_check = require("@swc/helpers/lib/_class_call_check.js").default; -var _create_class = require("@swc/helpers/lib/_create_class.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _classCallCheck = require("@swc/helpers/lib/_class_call_check.js").default; +var _createClass = require("@swc/helpers/lib/_create_class.js").default; var _get = require("@swc/helpers/lib/_get.js").default; -var _get_prototype_of = require("@swc/helpers/lib/_get_prototype_of.js").default; +var _getPrototypeOf = require("@swc/helpers/lib/_get_prototype_of.js").default; var _inherits = require("@swc/helpers/lib/_inherits.js").default; -var _wrap_native_super = require("@swc/helpers/lib/_wrap_native_super.js").default; -var _create_super = require("@swc/helpers/lib/_create_super.js").default; +var _wrapNativeSuper = require("@swc/helpers/lib/_wrap_native_super.js").default; +var _createSuper = require("@swc/helpers/lib/_create_super.js").default; var Element = /*#__PURE__*/ function() { function Element() { - _class_call_check(this, Element); + _classCallCheck(this, Element); } - _create_class(Element, [ + _createClass(Element, [ { key: "getChildElements", value: function getChildElements() { @@ -22,12 +25,12 @@ var Element = /*#__PURE__*/ function() { }(); var CanvasElement = /*#__PURE__*/ function(Element) { _inherits(CanvasElement, Element); - var _super = _create_super(CanvasElement); + var _super = _createSuper(CanvasElement); function CanvasElement() { - _class_call_check(this, CanvasElement); + _classCallCheck(this, CanvasElement); return _super.apply(this, arguments); } - _create_class(CanvasElement, [ + _createClass(CanvasElement, [ { key: "createFacets", value: function createFacets(hidden) { @@ -37,19 +40,19 @@ var CanvasElement = /*#__PURE__*/ function(Element) { } ]); return CanvasElement; -}(_wrap_native_super(Element)); +}(_wrapNativeSuper(Element)); var ColouredCanvasElement = /*#__PURE__*/ function(CanvasElement) { _inherits(ColouredCanvasElement, CanvasElement); - var _super = _create_super(ColouredCanvasElement); + var _super = _createSuper(ColouredCanvasElement); function ColouredCanvasElement() { - _class_call_check(this, ColouredCanvasElement); + _classCallCheck(this, ColouredCanvasElement); return _super.apply(this, arguments); } - _create_class(ColouredCanvasElement, [ + _createClass(ColouredCanvasElement, [ { key: "createFacets", value: function createFacets(hidden) { - hidden = _get(_get_prototype_of(ColouredCanvasElement.prototype), "createFacets", this).call(this, hidden); /// + hidden = _get(_getPrototypeOf(ColouredCanvasElement.prototype), "createFacets", this).call(this, hidden); /// /// } } @@ -58,9 +61,9 @@ var ColouredCanvasElement = /*#__PURE__*/ function(CanvasElement) { }(CanvasElement); var ColouredSquare = /*#__PURE__*/ function(ColouredCanvasElement) { _inherits(ColouredSquare, ColouredCanvasElement); - var _super = _create_super(ColouredSquare); + var _super = _createSuper(ColouredSquare); function ColouredSquare() { - _class_call_check(this, ColouredSquare); + _classCallCheck(this, ColouredSquare); return _super.apply(this, arguments); } return ColouredSquare; diff --git a/crates/swc/tests/fixture/issues-1xxx/1515/case1/output/input.ts b/crates/swc/tests/fixture/issues-1xxx/1515/case1/output/input.ts index 1dba257b80b..5765c10b808 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1515/case1/output/input.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1515/case1/output/input.ts @@ -2,6 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); +Object.defineProperty(exports, "ServiceError", { + get: ()=>ServiceError, + enumerable: true +}); class ServiceError extends Error { constructor(...args){ super(...args); @@ -9,7 +13,6 @@ class ServiceError extends Error { this.name = "ServiceError.BadResponse"; } } -exports.ServiceError = ServiceError; (function(ServiceError1) { let Code; (function(Code) { diff --git a/crates/swc/tests/fixture/issues-1xxx/1525/case1/output/index.tsx b/crates/swc/tests/fixture/issues-1xxx/1525/case1/output/index.tsx index 4a382c9fef3..c8341048d66 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1525/case1/output/index.tsx +++ b/crates/swc/tests/fixture/issues-1xxx/1525/case1/output/index.tsx @@ -1,6 +1,9 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _react = _interop_require_wildcard(require("react")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +const _react = _interopRequireWildcard(require("react")); class X extends _react.Component { } _react.default.render(document.getElementById("#root"), /*#__PURE__*/ _react.default.createElement(X, null)); diff --git a/crates/swc/tests/fixture/issues-1xxx/1554/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1554/case1/output/index.js index 13835df295e..8fb85f39529 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1554/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1554/case1/output/index.js @@ -2,17 +2,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); -Object.defineProperty(exports, "X", { - enumerable: true, - get: function() { +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + X: function() { return _z.default; - } -}); -Object.defineProperty(exports, "Y", { - enumerable: true, - get: function() { + }, + Y: function() { return _z.Y; } }); -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _z = _interop_require_wildcard(require("./Z")); +var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _z = _interopRequireWildcard(require("./Z")); diff --git a/crates/swc/tests/fixture/issues-1xxx/1554/case2/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1554/case2/output/index.js index 0bc42b724d5..061d2e84d58 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1554/case2/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1554/case2/output/index.js @@ -2,23 +2,22 @@ Object.defineProperty(exports, "__esModule", { value: true }); -Object.defineProperty(exports, "X", { - enumerable: true, - get: function() { +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + X: function() { return _module.default; - } -}); -Object.defineProperty(exports, "Y", { - enumerable: true, - get: function() { + }, + Y: function() { return _module.Y; - } -}); -Object.defineProperty(exports, "Z", { - enumerable: true, - get: function() { + }, + Z: function() { return _module.Z; } }); -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _module = _interop_require_wildcard(require("./module")); +var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _module = _interopRequireWildcard(require("./module")); diff --git a/crates/swc/tests/fixture/issues-1xxx/1568/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1568/case1/output/index.ts index b453e508ce0..b0200af1b62 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1568/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1568/case1/output/index.ts @@ -2,7 +2,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = get; +Object.defineProperty(exports, "default", { + get: function() { + return get; + }, + enumerable: true +}); function get(key) { console.log(key); } diff --git a/crates/swc/tests/fixture/issues-1xxx/1614/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1614/case1/output/index.ts index 5714ff88a31..0af6cf43160 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1614/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1614/case1/output/index.ts @@ -1,8 +1,9 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; (async ()=>{ - const example = await Promise.resolve().then(function() { - return _interop_require_wildcard(require("./example")); - }); + const example = await Promise.resolve("./example").then((p)=>_interopRequireWildcard(require(p))); console.log(example.foo); })(); diff --git a/crates/swc/tests/fixture/issues-1xxx/1682/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1682/case1/output/index.ts index 5723d5c944a..5af7fc6c679 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1682/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1682/case1/output/index.ts @@ -2,13 +2,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.getPackage = getPackage; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _path = require("path"); +Object.defineProperty(exports, "getPackage", { + get: ()=>getPackage, + enumerable: true +}); +const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +const _path = require("path"); async function getPackage() { - const pkg = await Promise.resolve(`${(0, _path).join(process.cwd(), "package.json")}`).then(function(s) { - return _interop_require_wildcard(require(s)); - }); + const pkg = await Promise.resolve((0, _path.join)(process.cwd(), "package.json")).then((p)=>_interopRequireWildcard(require(p))); return pkg.default || pkg; } (async function() { diff --git a/crates/swc/tests/fixture/issues-1xxx/1682/case2/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1682/case2/output/index.ts index 5723d5c944a..5af7fc6c679 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1682/case2/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1682/case2/output/index.ts @@ -2,13 +2,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.getPackage = getPackage; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _path = require("path"); +Object.defineProperty(exports, "getPackage", { + get: ()=>getPackage, + enumerable: true +}); +const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +const _path = require("path"); async function getPackage() { - const pkg = await Promise.resolve(`${(0, _path).join(process.cwd(), "package.json")}`).then(function(s) { - return _interop_require_wildcard(require(s)); - }); + const pkg = await Promise.resolve((0, _path.join)(process.cwd(), "package.json")).then((p)=>_interopRequireWildcard(require(p))); return pkg.default || pkg; } (async function() { diff --git a/crates/swc/tests/fixture/issues-1xxx/1714/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1714/case1/output/index.js index 0dec9ee46f7..559d118de45 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1714/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1714/case1/output/index.js @@ -3,26 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "render", { - enumerable: true, get: function() { return _customRender.customRender; - } + }, + enumerable: true }); -var _exportNames = { - render: true -}; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _exportStar = require("@swc/helpers/lib/_export_star.js").default; var _customRender = require("./customRender"); -var _react = _interop_require_wildcard(require("@testing-library/react")); -// re-export everything -Object.keys(_react).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _react[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _react[key]; - } - }); -}); +_exportStar(require("@testing-library/react"), exports); diff --git a/crates/swc/tests/fixture/issues-1xxx/1734/case1-B/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1734/case1-B/output/index.js index 4f5bcb275d1..a23188cf887 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1734/case1-B/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1734/case1-B/output/index.js @@ -1,4 +1,7 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _a = _interop_require_wildcard(require("./A")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _a = _interopRequireWildcard(require("./A")); console.log(_a.default, _a.foo); diff --git a/crates/swc/tests/fixture/issues-1xxx/1734/case2-C/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1734/case2-C/output/index.js index 65bc5cba98b..0a0b6e0bff1 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1734/case2-C/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1734/case2-C/output/index.js @@ -1,4 +1,7 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _a = _interop_require_wildcard(require("./A")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _a = _interopRequireWildcard(require("./A")); console.log(_a.default, _a.foo); // <-- baz foo diff --git a/crates/swc/tests/fixture/issues-1xxx/1734/case3-D/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1734/case3-D/output/index.js index 4f5bcb275d1..a23188cf887 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1734/case3-D/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1734/case3-D/output/index.js @@ -1,4 +1,7 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _a = _interop_require_wildcard(require("./A")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _a = _interopRequireWildcard(require("./A")); console.log(_a.default, _a.foo); diff --git a/crates/swc/tests/fixture/issues-1xxx/1757/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1757/case1/output/index.js index 3bbe62b8e7f..6b1cf5b2230 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1757/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1757/case1/output/index.js @@ -1,3 +1,6 @@ "use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); var _testlibrary = require("testlibrary"); -console.log("aFunc: ", (0, _testlibrary).aFunc(1, 2)); +console.log("aFunc: ", (0, _testlibrary.aFunc)(1, 2)); diff --git a/crates/swc/tests/fixture/issues-1xxx/1799/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1799/case1/output/index.js index 0b4be22c6ee..32febdffd3d 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1799/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1799/case1/output/index.js @@ -2,14 +2,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = Foo; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _regeneratorRuntime = _interop_require_default(require("regenerator-runtime")); -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "default", { + get: function() { + return Foo; + }, + enumerable: true +}); +var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime")); +var _react = _interopRequireDefault(require("react")); function Foo() { return /*#__PURE__*/ _react.default.createElement("div", { - onClick: _async_to_generator(_regeneratorRuntime.default.mark(function _callee(e) { + onClick: _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee(e) { return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: diff --git a/crates/swc/tests/fixture/issues-1xxx/1799/case2-no-loose/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1799/case2-no-loose/output/index.js index e28c3d41cc1..a3fdc78a51f 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1799/case2-no-loose/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1799/case2-no-loose/output/index.js @@ -2,14 +2,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = Foo; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true +}); +const _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +const _react = _interopRequireDefault(require("react")); function Foo() { return /*#__PURE__*/ _react.default.createElement("div", { onClick: function() { - var _ref = _async_to_generator(function*(e) { + var _ref = _asyncToGenerator(function*(e) { yield doSomething(); }); return function(e) { diff --git a/crates/swc/tests/fixture/issues-1xxx/1799/case2/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1799/case2/output/index.js index a09f5e83a57..ded281d1125 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1799/case2/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1799/case2/output/index.js @@ -2,13 +2,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = Foo; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true +}); +const _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +const _react = _interopRequireDefault(require("react")); function Foo() { return /*#__PURE__*/ _react.default.createElement("div", { - onClick: _async_to_generator(function*(e) { + onClick: _asyncToGenerator(function*(e) { yield doSomething(); }) }); diff --git a/crates/swc/tests/fixture/issues-1xxx/1799/case3/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1799/case3/output/index.js index a09f5e83a57..ded281d1125 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1799/case3/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1799/case3/output/index.js @@ -2,13 +2,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = Foo; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true +}); +const _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +const _react = _interopRequireDefault(require("react")); function Foo() { return /*#__PURE__*/ _react.default.createElement("div", { - onClick: _async_to_generator(function*(e) { + onClick: _asyncToGenerator(function*(e) { yield doSomething(); }) }); diff --git a/crates/swc/tests/fixture/issues-1xxx/1799/case4/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1799/case4/output/index.js index 973039e827b..8f430ba2c8e 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1799/case4/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1799/case4/output/index.js @@ -2,9 +2,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = Foo; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true +}); +const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +const _react = _interopRequireDefault(require("react")); function Foo() { return /*#__PURE__*/ _react.default.createElement("div", { onClick: async (e)=>{ diff --git a/crates/swc/tests/fixture/issues-1xxx/1799/case5/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1799/case5/output/index.js index 148d242193e..c64285e876b 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1799/case5/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1799/case5/output/index.js @@ -2,9 +2,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = Foo; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true +}); +const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +const _react = _interopRequireDefault(require("react")); function Foo() { return call(async (e)=>{ await doSomething(); diff --git a/crates/swc/tests/fixture/issues-1xxx/1799/case6-no-jsx/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1799/case6-no-jsx/output/index.js index 09290c0d6ea..7c1b6b4e308 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1799/case6-no-jsx/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1799/case6-no-jsx/output/index.js @@ -2,13 +2,18 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = Foo; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _regeneratorRuntime = _interop_require_default(require("regenerator-runtime")); -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "default", { + get: function() { + return Foo; + }, + enumerable: true +}); +var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime")); +var _react = _interopRequireDefault(require("react")); function Foo() { - return call(_async_to_generator(_regeneratorRuntime.default.mark(function _callee(e) { + return call(_asyncToGenerator(_regeneratorRuntime.default.mark(function _callee(e) { return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: diff --git a/crates/swc/tests/fixture/issues-1xxx/1799/case7-no-async/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1799/case7-no-async/output/index.js index 4478be876ba..4a641de2dc7 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1799/case7-no-async/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1799/case7-no-async/output/index.js @@ -2,9 +2,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = Foo; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "default", { + get: function() { + return Foo; + }, + enumerable: true +}); +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _react = _interopRequireDefault(require("react")); function Foo() { return call(function(e) { doSomething(); diff --git a/crates/swc/tests/fixture/issues-1xxx/1859/case1-js/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1859/case1-js/output/index.js index 4b05aa7c4df..def7b424ca9 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1859/case1-js/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1859/case1-js/output/index.js @@ -2,29 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _exportNames = {}; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _appConfig = _interop_require_wildcard(require("./app.config")); -Object.keys(_appConfig).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _appConfig[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _appConfig[key]; - } - }); -}); -var _databaseConfig = _interop_require_wildcard(require("./database.config")); -Object.keys(_databaseConfig).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _databaseConfig[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _databaseConfig[key]; - } - }); -}); +var _exportStar = require("@swc/helpers/lib/_export_star.js").default; +_exportStar(require("./app.config"), exports); +_exportStar(require("./database.config"), exports); diff --git a/crates/swc/tests/fixture/issues-1xxx/1859/case2-ts/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1859/case2-ts/output/index.ts index 4b05aa7c4df..def7b424ca9 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1859/case2-ts/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1859/case2-ts/output/index.ts @@ -2,29 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _exportNames = {}; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _appConfig = _interop_require_wildcard(require("./app.config")); -Object.keys(_appConfig).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _appConfig[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _appConfig[key]; - } - }); -}); -var _databaseConfig = _interop_require_wildcard(require("./database.config")); -Object.keys(_databaseConfig).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _databaseConfig[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _databaseConfig[key]; - } - }); -}); +var _exportStar = require("@swc/helpers/lib/_export_star.js").default; +_exportStar(require("./app.config"), exports); +_exportStar(require("./database.config"), exports); diff --git a/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/bar.ts b/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/bar.ts index db33db9ecc4..4dc8e31d343 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/bar.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/bar.ts @@ -2,6 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.bar = void 0; +Object.defineProperty(exports, "bar", { + get: function() { + return bar; + }, + enumerable: true +}); var bar = function() {}; -exports.bar = bar; diff --git a/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/foo.ts b/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/foo.ts index 488a7b85a7d..87c414af194 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/foo.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/foo.ts @@ -2,6 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.foo = void 0; +Object.defineProperty(exports, "foo", { + get: function() { + return foo; + }, + enumerable: true +}); var foo = function() {}; -exports.foo = foo; diff --git a/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/index.ts index 6339c3a3dd5..49f7013047f 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/index.ts @@ -1,4 +1,7 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var lib = _interop_require_wildcard(require("./lib")); -console.log(lib); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _lib = _interopRequireWildcard(require("./lib")); +console.log(_lib); diff --git a/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/lib.ts b/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/lib.ts index db1abe63ed7..a4babc8d450 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/lib.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1859/case3/output/lib.ts @@ -2,29 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _exportNames = {}; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _foo = _interop_require_wildcard(require("./foo")); -Object.keys(_foo).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _foo[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _foo[key]; - } - }); -}); -var _bar = _interop_require_wildcard(require("./bar")); -Object.keys(_bar).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _bar[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _bar[key]; - } - }); -}); +var _exportStar = require("@swc/helpers/lib/_export_star.js").default; +_exportStar(require("./foo"), exports); +_exportStar(require("./bar"), exports); diff --git a/crates/swc/tests/fixture/issues-1xxx/1918/es5-after-other/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1918/es5-after-other/output/index.js index 2bb0e4b2321..c9821025c6d 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1918/es5-after-other/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1918/es5-after-other/output/index.js @@ -1,7 +1,10 @@ "use strict"; -var _define_property = require("@swc/helpers/lib/_define_property.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _regeneratorRuntime = _interop_require_default(require("regenerator-runtime")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _defineProperty = require("@swc/helpers/lib/_define_property.js").default; +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime")); function _asyncIterator(iterable) { var method; if (typeof Symbol === "function") { @@ -55,7 +58,7 @@ _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { promise = new Promise(function(r) { return resolve = r; }); - iterable = _define_property({}, Symbol.asyncIterator, function() { + iterable = _defineProperty({}, Symbol.asyncIterator, function() { return { next: function next() { return promise; diff --git a/crates/swc/tests/fixture/issues-1xxx/1918/es5/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1918/es5/output/index.js index c05317a30b6..f4a93abd72f 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1918/es5/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1918/es5/output/index.js @@ -1,10 +1,13 @@ "use strict"; -var _async_iterator = require("@swc/helpers/lib/_async_iterator.js").default; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; -var _define_property = require("@swc/helpers/lib/_define_property.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _regeneratorRuntime = _interop_require_default(require("regenerator-runtime")); -_async_to_generator(_regeneratorRuntime.default.mark(function _callee() { +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _asyncIterator = require("@swc/helpers/lib/_async_iterator.js").default; +var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +var _defineProperty = require("@swc/helpers/lib/_define_property.js").default; +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime")); +_asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var counter, resolve, promise, iterable, res, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, v, oldresolve; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ @@ -14,21 +17,21 @@ _async_to_generator(_regeneratorRuntime.default.mark(function _callee() { promise = new Promise(function(r) { return resolve = r; }); - iterable = _define_property({}, Symbol.asyncIterator, function() { + iterable = _defineProperty({}, Symbol.asyncIterator, function() { return { next: function next() { return promise; } }; }); - res = _async_to_generator(_regeneratorRuntime.default.mark(function _callee() { + res = _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, value; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: _iteratorAbruptCompletion = false, _didIteratorError = false; _ctx.prev = 1; - _iterator = _async_iterator(iterable); + _iterator = _asyncIterator(iterable); case 3: _ctx.next = 5; return _iterator.next(); diff --git a/crates/swc/tests/fixture/issues-1xxx/1924/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1924/case1/output/index.js index 6adeb31d811..4473dd9c4ac 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1924/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1924/case1/output/index.js @@ -1,6 +1,9 @@ "use strict"; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _regeneratorRuntime = _interop_require_default(require("regenerator-runtime")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime")); var _marked = _regeneratorRuntime.default.mark(foo); function foo() { return _regeneratorRuntime.default.wrap(function foo$(_ctx) { diff --git a/crates/swc/tests/fixture/issues-1xxx/1938/cjs/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1938/cjs/output/index.js index 362246764bd..73b709cbc43 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1938/cjs/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1938/cjs/output/index.js @@ -1,5 +1,8 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var action = _interop_require_wildcard(require("./actions")); -console.log(action); -console.log(action.default); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _actions = _interopRequireWildcard(require("./actions")); +console.log(_actions); +console.log(_actions.default); diff --git a/crates/swc/tests/fixture/issues-2xxx/2021/full/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2021/full/output/index.js index 3e00f90a4ca..1efff82417d 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2021/full/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2021/full/output/index.js @@ -1,8 +1,11 @@ "use strict"; -var _define_property = require("@swc/helpers/lib/_define_property.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _defineProperty = require("@swc/helpers/lib/_define_property.js").default; class Item extends Component { constructor(props){ super(props); - _define_property(this, "input", this.props.item); + _defineProperty(this, "input", this.props.item); } } diff --git a/crates/swc/tests/fixture/issues-2xxx/2024/full/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2024/full/output/index.js index ed06bfe5935..4d901a36a3c 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2024/full/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2024/full/output/index.js @@ -1,8 +1,11 @@ "use strict"; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _regeneratorRuntime = _interop_require_default(require("regenerator-runtime")); -_async_to_generator(_regeneratorRuntime.default.mark(function _callee() { +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime")); +_asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() { var sleep, result; return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ diff --git a/crates/swc/tests/fixture/issues-2xxx/2050/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2050/output/index.ts index 5a80b731b37..87c29380ef3 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2050/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2050/output/index.ts @@ -1,4 +1,7 @@ "use strict"; -var _interop_require_default = require("../../../../../../../packages/swc-helpers/src/_interop_require_default.mjs").default; -var _a = _interop_require_default(require("./subfolder/A")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _interopRequireDefault = require("../../../../../../../packages/swc-helpers/src/_interop_require_default.mjs").default; +const _a = _interopRequireDefault(require("./subfolder/A")); console.log(_a.default); diff --git a/crates/swc/tests/fixture/issues-2xxx/2050/output/subfolder/A.ts b/crates/swc/tests/fixture/issues-2xxx/2050/output/subfolder/A.ts index 33979bf901a..f5e762441dd 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2050/output/subfolder/A.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2050/output/subfolder/A.ts @@ -2,8 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.A = void 0; -var _b = require("./B"); +Object.defineProperty(exports, "A", { + get: ()=>A, + enumerable: true +}); +const _b = require("./B"); console.log(_b.B); const A = 400; -exports.A = A; diff --git a/crates/swc/tests/fixture/issues-2xxx/2050/output/subfolder/B.ts b/crates/swc/tests/fixture/issues-2xxx/2050/output/subfolder/B.ts index 658b5e3abbb..95cb66c38ed 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2050/output/subfolder/B.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2050/output/subfolder/B.ts @@ -2,6 +2,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.B = void 0; +Object.defineProperty(exports, "B", { + get: ()=>B, + enumerable: true +}); const B = 500; -exports.B = B; diff --git a/crates/swc/tests/fixture/issues-2xxx/2281/case1/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2281/case1/output/index.js index f2a4e0db513..e4ef83f1625 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2281/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2281/case1/output/index.js @@ -1,4 +1,4 @@ -var _func = require("./src/func"); +const _func = require("./src/func"); console.log(_func.func1); function something({ func =0 }) { const haha = false; diff --git a/crates/swc/tests/fixture/issues-2xxx/2372/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2372/output/index.js index 2aefcde0fec..6bb940d66bb 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2372/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2372/output/index.js @@ -1,5 +1,8 @@ "use strict"; -var _ = require("./"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _ = require("./"); describe("example test that should fail due to compilation", ()=>{ test.each([ [ @@ -15,7 +18,7 @@ describe("example test that should fail due to compilation", ()=>{ 4 ], ])("for entry %s", (_1, a, b, expected)=>{ - const result = (0, _).sum(a, b); + const result = (0, _.sum)(a, b); expect(result).toEqual(expected); }); }); diff --git a/crates/swc/tests/fixture/issues-2xxx/2428/1/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2428/1/output/index.ts index 6d0c972d5c6..2d36979f652 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2428/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2428/1/output/index.ts @@ -1,31 +1,34 @@ "use strict"; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; -var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default; -var _ts_param = require("@swc/helpers/lib/_ts_param.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; +const _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; +const _tsParam = require("@swc/helpers/lib/_ts_param.js").default; class Foo { fnName1(argName) { - return _async_to_generator(function*() {})(); + return _asyncToGenerator(function*() {})(); } fnName2(argName = false) { - return _async_to_generator(function*() {})(); + return _asyncToGenerator(function*() {})(); } } -_ts_decorate([ - _ts_param(0, Arg("GraphQLArgName", { +_tsDecorate([ + _tsParam(0, Arg("GraphQLArgName", { nullable: true })), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ Boolean ]) ], Foo.prototype, "fnName1", null); -_ts_decorate([ - _ts_param(0, Arg("GraphQLArgName", { +_tsDecorate([ + _tsParam(0, Arg("GraphQLArgName", { nullable: true })), - _ts_metadata("design:type", Function), - _ts_metadata("design:paramtypes", [ + _tsMetadata("design:type", Function), + _tsMetadata("design:paramtypes", [ Boolean ]) ], Foo.prototype, "fnName2", null); diff --git a/crates/swc/tests/fixture/issues-2xxx/2539/1/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2539/1/output/index.js index d47cd90176e..e213260d977 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2539/1/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2539/1/output/index.js @@ -2,11 +2,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); var _default = { foo: { func1 (index) {}, func2 (index, index1) {} } }; -exports.default = _default; diff --git a/crates/swc/tests/fixture/issues-2xxx/2606/1/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2606/1/output/index.ts index 79cce376577..69edd124445 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2606/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2606/1/output/index.ts @@ -2,24 +2,31 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.warn = warn; -exports.test2 = exports.test = void 0; +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + test: ()=>test, + test2: ()=>test2, + warn: ()=>warn +}); function warn() { throw new Error("this should not be called"); } const test = {}; -exports.test = test; const test2 = {}; -exports.test2 = test2; Object.defineProperty(test, "warn", { get: ()=>warn, set: (v)=>{ - exports.warn = warn = v; + warn = v; } }); Object.defineProperty(test2, "work", { get: ()=>warn, set: (v)=>{ - exports.warn = warn = v; + warn = v; } }); diff --git a/crates/swc/tests/fixture/issues-2xxx/2613/1/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2613/1/output/index.ts index ce456a9e988..4f64e1fe5b4 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2613/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2613/1/output/index.ts @@ -1,7 +1,4 @@ "use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); module.exports = function(foo, bar) { return true; }; diff --git a/crates/swc/tests/fixture/issues-2xxx/2856/1/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2856/1/output/index.js index 0da4420c5bd..71f4640a7eb 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2856/1/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2856/1/output/index.js @@ -1,5 +1,8 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _boo = _interop_require_wildcard(require("boo")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +const _boo = _interopRequireWildcard(require("boo")); _boo.default.some(); -(0, _boo).sdx(); +(0, _boo.sdx)(); diff --git a/crates/swc/tests/fixture/issues-2xxx/2858/2/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2858/2/output/index.js index b367e2aa577..df7105f0975 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2858/2/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2858/2/output/index.js @@ -2,7 +2,20 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.b2 = exports.a2 = void 0; +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + a2: function() { + return a2; + }, + b2: function() { + return b2; + } +}); var ref = { a: 1, b: 2 @@ -12,5 +25,3 @@ var ref1 = { b: 2 }; var a2 = ref1.a, b2 = ref1.b; -exports.a2 = a2; -exports.b2 = b2; diff --git a/crates/swc/tests/fixture/issues-2xxx/2964/case-2/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2964/case-2/output/index.ts index d87e4d5f89a..5a8fb74d9ea 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2964/case-2/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2964/case-2/output/index.ts @@ -2,13 +2,22 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.downloadDocument = exports.badIstanbul = exports.noop = void 0; -var _object_without_properties = require("@swc/helpers/lib/_object_without_properties.js").default; +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + badIstanbul: ()=>badIstanbul, + downloadDocument: ()=>downloadDocument, + noop: ()=>noop +}); +const _objectWithoutProperties = require("@swc/helpers/lib/_object_without_properties.js").default; //top comment const noop = ()=>{}; -exports.noop = noop; var /* istanbul ignore next */ badIstanbul = (test)=>{ - const { value } = test, pixelParams = _object_without_properties(test, [ + const { value } = test, pixelParams = _objectWithoutProperties(test, [ "value" ]); console.log("fail"); @@ -16,5 +25,3 @@ var /* istanbul ignore next */ badIstanbul = (test)=>{ /* istanbul ignore next: UI-5137 */ const downloadDocument = ()=>{ console.log("fail"); }; -exports.downloadDocument = downloadDocument; -exports.badIstanbul = badIstanbul; diff --git a/crates/swc/tests/fixture/issues-2xxx/2964/case-3/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2964/case-3/output/index.ts index a8d05a79d75..328b5ad004e 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2964/case-3/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2964/case-3/output/index.ts @@ -1,8 +1,11 @@ "use strict"; -var _object_without_properties = require("@swc/helpers/lib/_object_without_properties.js").default; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _objectWithoutProperties = require("@swc/helpers/lib/_object_without_properties.js").default; // single line comment const x = (_param)=>/*todo: refactor any type*/ { - var { y } = _param, rest = _object_without_properties(_param, [ + var { y } = _param, rest = _objectWithoutProperties(_param, [ "y" ]); return { diff --git a/crates/swc/tests/fixture/issues-2xxx/2964/case-4/output/index.tsx b/crates/swc/tests/fixture/issues-2xxx/2964/case-4/output/index.tsx index 58f03166a35..63dc49d3acb 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2964/case-4/output/index.tsx +++ b/crates/swc/tests/fixture/issues-2xxx/2964/case-4/output/index.tsx @@ -2,7 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.AnElement = void 0; +Object.defineProperty(exports, "AnElement", { + get: ()=>AnElement, + enumerable: true +}); const AnElement = ({ prop1 , prop2 , prop3 , num , data })=>{ return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(SomeElement, { prop1: prop1, @@ -11,4 +14,3 @@ const AnElement = ({ prop1 , prop2 , prop3 , num , data })=>{ }), // istanbul ignore next !(num > 0) && data.name && /*#__PURE__*/ React.createElement(React.Fragment, null, '"Hello"')); }; -exports.AnElement = AnElement; diff --git a/crates/swc/tests/fixture/issues-3xxx/3272/1/output/index.js b/crates/swc/tests/fixture/issues-3xxx/3272/1/output/index.js index e3c83a935da..a655de9848e 100644 --- a/crates/swc/tests/fixture/issues-3xxx/3272/1/output/index.js +++ b/crates/swc/tests/fixture/issues-3xxx/3272/1/output/index.js @@ -1,4 +1,7 @@ "use strict"; -var _interop_require_default = require("../../../../../../../../packages/swc-helpers/src/_interop_require_default.mjs").default; -var _handlebars = _interop_require_default(require("handlebars")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _interopRequireDefault = require("../../../../../../../../packages/swc-helpers/src/_interop_require_default.mjs").default; +var _handlebars = _interopRequireDefault(require("handlebars")); console.log(_handlebars.default); diff --git a/crates/swc/tests/fixture/issues-3xxx/3337/output/input.ts b/crates/swc/tests/fixture/issues-3xxx/3337/output/input.ts index 75020032def..836ddd8089f 100644 --- a/crates/swc/tests/fixture/issues-3xxx/3337/output/input.ts +++ b/crates/swc/tests/fixture/issues-3xxx/3337/output/input.ts @@ -1,14 +1,17 @@ "use strict"; -var _class_call_check = require("@swc/helpers/lib/_class_call_check.js").default; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; -var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default; -var joiful = _interop_require_wildcard(require("joiful")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _classCallCheck = require("@swc/helpers/lib/_class_call_check.js").default; +var _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +var _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; +var _tsMetadata = require("@swc/helpers/lib/_ts_metadata.js").default; +var _joiful = _interopRequireWildcard(require("joiful")); var Schema = function Schema() { "use strict"; - _class_call_check(this, Schema); + _classCallCheck(this, Schema); }; -_ts_decorate([ - joiful.string().guid().required(), - _ts_metadata("design:type", String) +_tsDecorate([ + _joiful.string().guid().required(), + _tsMetadata("design:type", String) ], Schema.prototype, "id", void 0); diff --git a/crates/swc/tests/fixture/issues-3xxx/3686/1/output/index.ts b/crates/swc/tests/fixture/issues-3xxx/3686/1/output/index.ts index b5948f5a2f6..69e80556e36 100644 --- a/crates/swc/tests/fixture/issues-3xxx/3686/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-3xxx/3686/1/output/index.ts @@ -2,8 +2,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.ServiceError = void 0; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; +Object.defineProperty(exports, "ServiceError", { + get: ()=>ServiceError, + enumerable: true +}); +const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; const CD = ()=>{}; const PD = ()=>{}; let ServiceError = class ServiceError extends Error { @@ -13,11 +16,10 @@ let ServiceError = class ServiceError extends Error { } name = "ServiceError.BadResponse"; }; -exports.ServiceError = ServiceError; -_ts_decorate([ +_tsDecorate([ PD ], ServiceError.prototype, "code", void 0); -exports.ServiceError = ServiceError = _ts_decorate([ +ServiceError = _tsDecorate([ CD ], ServiceError); (function(ServiceError1) { @@ -42,4 +44,4 @@ exports.ServiceError = ServiceError = _ts_decorate([ }; } ServiceError1.toMessageBody = toMessageBody; -})(ServiceError || (exports.ServiceError = ServiceError = {})); +})(ServiceError || (ServiceError = {})); diff --git a/crates/swc/tests/fixture/issues-3xxx/3782/output/index.map b/crates/swc/tests/fixture/issues-3xxx/3782/output/index.map index e1f74951683..8287477afd5 100644 --- a/crates/swc/tests/fixture/issues-3xxx/3782/output/index.map +++ b/crates/swc/tests/fixture/issues-3xxx/3782/output/index.map @@ -1,8 +1,8 @@ { - "mappings": "AACA;;mBAAqB,OAAO;AAArB,QAAKA,GAAG,OAAA,CAAA;AAIR,MAAMC,IAAI,GAAG,CAACC,EAAU,GAAsB;IACjD,sBAAsB;IACtB,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,GACvBC,UAAU,CAAC,IAAM;YACbD,OAAO,CAAC,QAAQ,CAAC,CAAC;SACrB,EAAE,IAAI,CAAC,CACX,CAAC;CACL,AAAC;QAPWH,IAAI,GAAJA,IAAI", + "mappings": "AACA;;;;;;;;IAIaA,IAAI,MAAJA,IAAI;IAJLC,GAAG;;qBAAM,OAAO;AAIrB,MAAMD,IAAI,GAAG,CAACE,EAAU,GAAsB;IACjD,sBAAsB;IACtB,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,GACvBC,UAAU,CAAC,IAAM;YACbD,OAAO,CAAC,QAAQ,CAAC,CAAC;SACrB,EAAE,IAAI,CAAC,CACX,CAAC;CACL,AAAC", "names": [ - "get", "byID", + "get", "id", "Promise", "resolve", diff --git a/crates/swc/tests/fixture/issues-3xxx/3782/output/index.ts b/crates/swc/tests/fixture/issues-3xxx/3782/output/index.ts index a1c3b42257b..e070acfb25f 100644 --- a/crates/swc/tests/fixture/issues-3xxx/3782/output/index.ts +++ b/crates/swc/tests/fixture/issues-3xxx/3782/output/index.ts @@ -1,11 +1,18 @@ "use strict"; -exports.byID = exports.get = void 0; -var _get = require("./get"); -exports.get = _get; +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + byID: ()=>byID, + get: ()=>_get +}); +const _get = require("./get"); const byID = (id)=>{ // Do some async stuff return new Promise((resolve)=>setTimeout(()=>{ resolve("result"); }, 2000)); }; -exports.byID = byID; diff --git a/crates/swc/tests/fixture/issues-4xxx/4063/1/input/.swcrc b/crates/swc/tests/fixture/issues-4xxx/4063/1/input/.swcrc new file mode 100644 index 00000000000..152781cb902 --- /dev/null +++ b/crates/swc/tests/fixture/issues-4xxx/4063/1/input/.swcrc @@ -0,0 +1,12 @@ +{ + "module": { + "type": "amd" + }, + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true + }, + "target": "es2016" + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-4xxx/4063/1/input/index.ts b/crates/swc/tests/fixture/issues-4xxx/4063/1/input/index.ts new file mode 100644 index 00000000000..ed0d49eaf8b --- /dev/null +++ b/crates/swc/tests/fixture/issues-4xxx/4063/1/input/index.ts @@ -0,0 +1,10 @@ +function state() {} + +class Controller {} + +export default class extends Controller { + @state + isTest = false; + + onChange() {} +} diff --git a/crates/swc/tests/fixture/issues-4xxx/4063/1/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4063/1/output/index.ts new file mode 100644 index 00000000000..a86b3d7759d --- /dev/null +++ b/crates/swc/tests/fixture/issues-4xxx/4063/1/output/index.ts @@ -0,0 +1,28 @@ +define([ + "require", + "exports", + "@swc/helpers/src/_ts_decorate.mjs" +], function(require, exports, _tsDecorate) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_class, + enumerable: true + }); + _tsDecorate = _tsDecorate.default; + function state() {} + class Controller { + } + class _class extends Controller { + onChange() {} + constructor(...args){ + super(...args); + this.isTest = false; + } + } + _tsDecorate([ + state + ], _class.prototype, "isTest", void 0); +}); diff --git a/crates/swc/tests/fixture/issues-4xxx/4127/1/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4127/1/output/index.ts index 986ceb46c7d..1472d1c7b12 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4127/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4127/1/output/index.ts @@ -2,14 +2,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; -var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default; +Object.defineProperty(exports, "default", { + get: ()=>_class, + enumerable: true +}); +const _tsDecorate = require("@swc/helpers/lib/_ts_decorate.js").default; function test(constructor) { console.log(constructor); } let _class = class _class { }; -exports.default = _class = _ts_decorate([ +_class = _tsDecorate([ test ], _class); -exports.default = _class; diff --git a/crates/swc/tests/fixture/issues-4xxx/4226/3/output/exec.js b/crates/swc/tests/fixture/issues-4xxx/4226/3/output/exec.js index b91a621f712..c3fbe259ebe 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4226/3/output/exec.js +++ b/crates/swc/tests/fixture/issues-4xxx/4226/3/output/exec.js @@ -1,10 +1,13 @@ "use strict"; -var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _regeneratorRuntime = _interop_require_default(require("regenerator-runtime")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default; +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime")); require("reflect-metadata"); var v0 = function() { - var _ref = _async_to_generator(_regeneratorRuntime.default.mark(function _callee(v1) { + var _ref = _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee(v1) { return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: diff --git a/crates/swc/tests/fixture/issues-4xxx/4316/1/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4316/1/output/index.ts index 6d868c050a2..7dc19269cb1 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4316/1/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4316/1/output/index.ts @@ -1,9 +1,9 @@ define([ "require", "exports" -], function(require, _exports) { +], function(require, exports) { "use strict"; - Object.defineProperty(_exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); }); diff --git a/crates/swc/tests/fixture/issues-4xxx/4896/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4896/output/index.ts index 6239de8b636..78fbe11d88c 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4896/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4896/output/index.ts @@ -2,11 +2,10 @@ define([ "require", "exports", "vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedIcons" -], function(require, _exports, _gettingStartedIcons) { +], function(require, exports, _gettingStartedIcons) { "use strict"; - Object.defineProperty(_exports, "__esModule", { - value: true + Object.defineProperty(exports, "icons", { + get: ()=>_gettingStartedIcons, + enumerable: true }); - _exports.icons = void 0; - _exports.icons = _gettingStartedIcons; }); diff --git a/crates/swc/tests/fixture/issues-4xxx/4897/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4897/output/index.ts index 554c3dce966..39074bb877a 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4897/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4897/output/index.ts @@ -1,19 +1,23 @@ define([ "require", "exports" -], function(require, _exports) { +], function(require, exports) { "use strict"; - Object.defineProperty(_exports, "__esModule", { - value: true + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + Foo: ()=>Foo, + boo: ()=>boo }); - _exports.boo = boo; - _exports.Foo = void 0; function boo() { return Foo.Bar * 2; } var Foo; - _exports.Foo = Foo; (function(Foo) { var Bar = Foo.Bar = 1234; - })(Foo || (_exports.Foo = Foo = {})); + })(Foo || (Foo = {})); }); diff --git a/crates/swc/tests/fixture/issues-4xxx/4898/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4898/output/index.ts index 14a9ff8414c..1b648d230bf 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4898/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4898/output/index.ts @@ -1,9 +1,9 @@ define([ "require", "assert" -], function(require, assert) { +], function(require, _assert) { "use strict"; - assert(true); + _assert(true); let foo = 1; foo = 2; return foo; diff --git a/crates/swc/tests/fixture/issues-4xxx/4899/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4899/output/index.ts index 6d9c2fdd8d5..604dc507299 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4899/output/index.ts +++ b/crates/swc/tests/fixture/issues-4xxx/4899/output/index.ts @@ -1,8 +1,9 @@ define([ "require", "@swc/helpers/src/_ts_decorate.mjs" -], function(require, _ts_decorate) { +], function(require, _tsDecorate) { "use strict"; + _tsDecorate = _tsDecorate.default; function es5ClassCompat(target) { function _() { return Reflect.construct(target, arguments, this.constructor); @@ -18,7 +19,7 @@ define([ } constructor(){} }; - Foo = _ts_decorate([ + Foo = _tsDecorate([ es5ClassCompat ], Foo); }); diff --git a/crates/swc/tests/fixture/issues-4xxx/4953/output/index.js b/crates/swc/tests/fixture/issues-4xxx/4953/output/index.js index f033cd06e85..fe56d76cc99 100644 --- a/crates/swc/tests/fixture/issues-4xxx/4953/output/index.js +++ b/crates/swc/tests/fixture/issues-4xxx/4953/output/index.js @@ -1,7 +1,5 @@ "use strict"; -Object.defineProperty(exports, "__esModule", { - value: !0 -}), exports.default = function(a, b) { +function a(a, b) { "use strict"; !function(a, c) { c(b); @@ -14,4 +12,10 @@ Object.defineProperty(exports, "__esModule", { return d; }; }); -}; +} +Object.defineProperty(exports, "__esModule", { + value: !0 +}), Object.defineProperty(exports, "default", { + get: ()=>a, + enumerable: !0 +}); diff --git a/crates/swc/tests/fixture/issues-4xxx/4988/input/.swcrc b/crates/swc/tests/fixture/issues-4xxx/4988/input/.swcrc new file mode 100644 index 00000000000..947d6e693af --- /dev/null +++ b/crates/swc/tests/fixture/issues-4xxx/4988/input/.swcrc @@ -0,0 +1,12 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2022", + "loose": false + }, + "module": { + "type": "commonjs" + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-4xxx/4988/input/index.ts b/crates/swc/tests/fixture/issues-4xxx/4988/input/index.ts new file mode 100644 index 00000000000..87d0138f777 --- /dev/null +++ b/crates/swc/tests/fixture/issues-4xxx/4988/input/index.ts @@ -0,0 +1,3 @@ +import * as testUtils from "vs/base/test/common/testUtils"; + +export import flakySuite = testUtils.flakySuite; diff --git a/crates/swc/tests/fixture/issues-4xxx/4988/output/index.ts b/crates/swc/tests/fixture/issues-4xxx/4988/output/index.ts new file mode 100644 index 00000000000..088157a7d48 --- /dev/null +++ b/crates/swc/tests/fixture/issues-4xxx/4988/output/index.ts @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "flakySuite", { + get: ()=>flakySuite, + enumerable: true +}); +const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +const _testUtils = _interopRequireWildcard(require("vs/base/test/common/testUtils")); +var flakySuite = _testUtils.flakySuite; diff --git a/crates/swc/tests/fixture/jest/sourcemap-1/output/index.ts b/crates/swc/tests/fixture/jest/sourcemap-1/output/index.ts index 9cab6b93d1a..10032c8b4ed 100644 --- a/crates/swc/tests/fixture/jest/sourcemap-1/output/index.ts +++ b/crates/swc/tests/fixture/jest/sourcemap-1/output/index.ts @@ -2,11 +2,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.Button = void 0; -var _linaria = require("linaria"); +Object.defineProperty(exports, "Button", { + get: ()=>Button, + enumerable: true +}); +const _linaria = require("linaria"); const Button = _linaria.css` color: red; `; -exports.Button = Button; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL2lucHV0L2luZGV4LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcyB9IGZyb20gXCJsaW5hcmlhXCI7XG5cbmV4cG9ydCBjb25zdCBCdXR0b24gPSBjc3NgXG4gICAgY29sb3I6IHJlZDtcbmA7XG4iXSwibmFtZXMiOlsiQnV0dG9uIiwiY3NzIl0sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7QUFBb0IsSUFBQSxRQUFTLFdBQVQsU0FBUyxDQUFBO0FBRXRCLE1BQU1BLE1BQU0sR0FBR0MsUUFBRyxJQUFBLENBQUM7O0FBRTFCLENBQUMsQUFBQztRQUZXRCxNQUFNLEdBQU5BLE1BQU0ifQ== +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL2lucHV0L2luZGV4LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcyB9IGZyb20gXCJsaW5hcmlhXCI7XG5cbmV4cG9ydCBjb25zdCBCdXR0b24gPSBjc3NgXG4gICAgY29sb3I6IHJlZDtcbmA7XG4iXSwibmFtZXMiOlsiQnV0dG9uIiwiY3NzIl0sIm1hcHBpbmdzIjoiQUFBQTs7OzsrQkFFYUEsUUFBTTthQUFOQSxNQUFNOzs7eUJBRkMsU0FBUztBQUV0QixNQUFNQSxNQUFNLEdBQUdDLFFBQUcsSUFBQSxDQUFDOztBQUUxQixDQUFDLEFBQUMifQ== diff --git a/crates/swc/tests/fixture/module/ignore-dynamic/1/output/index.js b/crates/swc/tests/fixture/module/ignore-dynamic/1/output/index.js index 14354e6b5d0..946cee94363 100644 --- a/crates/swc/tests/fixture/module/ignore-dynamic/1/output/index.js +++ b/crates/swc/tests/fixture/module/ignore-dynamic/1/output/index.js @@ -1,6 +1,9 @@ "use strict"; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _foo = _interop_require_wildcard(require("foo")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +const _foo = _interopRequireDefault(require("foo")); async function foo() { await import("foo"); callback(()=>import("foo")); diff --git a/crates/swc/tests/fixture/shopify/001/output/index.js b/crates/swc/tests/fixture/shopify/001/output/index.js index d626be07c52..87e1f7b01e5 100644 --- a/crates/swc/tests/fixture/shopify/001/output/index.js +++ b/crates/swc/tests/fixture/shopify/001/output/index.js @@ -1,6 +1,9 @@ "use strict"; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _react = _interop_require_default(require("react")); -var _reactDom = _interop_require_default(require("react-dom")); +Object.defineProperty(exports, "__esModule", { + value: true +}); +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _react = _interopRequireDefault(require("react")); +var _reactDom = _interopRequireDefault(require("react-dom")); var _app = require("./App"); _reactDom.default.render(/*#__PURE__*/ _react.default.createElement(_app.App, null), "div"); diff --git a/crates/swc/tests/fixture/shopify/002/output/index.js b/crates/swc/tests/fixture/shopify/002/output/index.js index 3a2295d93f9..e5766b1e640 100644 --- a/crates/swc/tests/fixture/shopify/002/output/index.js +++ b/crates/swc/tests/fixture/shopify/002/output/index.js @@ -2,12 +2,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.App = App; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _sliced_to_array = require("@swc/helpers/lib/_sliced_to_array.js").default; -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "App", { + get: function() { + return App; + }, + enumerable: true +}); +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _slicedToArray = require("@swc/helpers/lib/_sliced_to_array.js").default; +var _react = _interopRequireDefault(require("react")); var _reactI18N = require("@shopify/react-i18n"); function App() { - var ref = _sliced_to_array((0, _reactI18N).useI18n(), 1), i18n = ref[0]; + var ref = _slicedToArray((0, _reactI18N.useI18n)(), 1), i18n = ref[0]; return /*#__PURE__*/ _react.default.createElement("h1", null, i18n.translate("foo")); } diff --git a/crates/swc/tests/fixture/shopify/003-env/output/index.js b/crates/swc/tests/fixture/shopify/003-env/output/index.js index 3a2295d93f9..e5766b1e640 100644 --- a/crates/swc/tests/fixture/shopify/003-env/output/index.js +++ b/crates/swc/tests/fixture/shopify/003-env/output/index.js @@ -2,12 +2,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.App = App; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _sliced_to_array = require("@swc/helpers/lib/_sliced_to_array.js").default; -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "App", { + get: function() { + return App; + }, + enumerable: true +}); +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _slicedToArray = require("@swc/helpers/lib/_sliced_to_array.js").default; +var _react = _interopRequireDefault(require("react")); var _reactI18N = require("@shopify/react-i18n"); function App() { - var ref = _sliced_to_array((0, _reactI18N).useI18n(), 1), i18n = ref[0]; + var ref = _slicedToArray((0, _reactI18N.useI18n)(), 1), i18n = ref[0]; return /*#__PURE__*/ _react.default.createElement("h1", null, i18n.translate("foo")); } diff --git a/crates/swc/tests/fixture/shopify/004-jest/output/index.js b/crates/swc/tests/fixture/shopify/004-jest/output/index.js index 3a2295d93f9..e5766b1e640 100644 --- a/crates/swc/tests/fixture/shopify/004-jest/output/index.js +++ b/crates/swc/tests/fixture/shopify/004-jest/output/index.js @@ -2,12 +2,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.App = App; -var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default; -var _sliced_to_array = require("@swc/helpers/lib/_sliced_to_array.js").default; -var _react = _interop_require_default(require("react")); +Object.defineProperty(exports, "App", { + get: function() { + return App; + }, + enumerable: true +}); +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _slicedToArray = require("@swc/helpers/lib/_sliced_to_array.js").default; +var _react = _interopRequireDefault(require("react")); var _reactI18N = require("@shopify/react-i18n"); function App() { - var ref = _sliced_to_array((0, _reactI18N).useI18n(), 1), i18n = ref[0]; + var ref = _slicedToArray((0, _reactI18N.useI18n)(), 1), i18n = ref[0]; return /*#__PURE__*/ _react.default.createElement("h1", null, i18n.translate("foo")); } diff --git a/crates/swc/tests/fixture/sourcemap/001/output/index.map b/crates/swc/tests/fixture/sourcemap/001/output/index.map index 2d02bc27537..13c73f37d96 100644 --- a/crates/swc/tests/fixture/sourcemap/001/output/index.map +++ b/crates/swc/tests/fixture/sourcemap/001/output/index.map @@ -1,5 +1,5 @@ { - "mappings": "AAAA;;;;;AAAO,MAAMA,GAAG,GAAG;IACfC,GAAG,EAAE,EAAE;CACV,AAAC;QAFWD,GAAG,GAAHA,GAAG", + "mappings": "AAAA;;;;+BAAaA,KAAG;aAAHA,GAAG;;;AAAT,MAAMA,GAAG,GAAG;IACfC,GAAG,EAAE,EAAE;CACV,AAAC", "names": [ "foo", "arr" diff --git a/crates/swc/tests/fixture/sourcemap/001/output/index.ts b/crates/swc/tests/fixture/sourcemap/001/output/index.ts index de1b59b9085..c8e5d1650d2 100644 --- a/crates/swc/tests/fixture/sourcemap/001/output/index.ts +++ b/crates/swc/tests/fixture/sourcemap/001/output/index.ts @@ -2,8 +2,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.foo = void 0; +Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true +}); const foo = { arr: [] }; -exports.foo = foo; diff --git a/crates/swc/tests/fixture/sourcemap/issue-3854/1-true/output/index.map b/crates/swc/tests/fixture/sourcemap/issue-3854/1-true/output/index.map index cdbbca89bf4..0c5fa350797 100644 --- a/crates/swc/tests/fixture/sourcemap/issue-3854/1-true/output/index.map +++ b/crates/swc/tests/fixture/sourcemap/issue-3854/1-true/output/index.map @@ -1,23 +1,23 @@ { - "mappings": "AAAA;;;;;;;;;;;;;;;;;;;;AAAoD,IAAA,iBAAoB,WAApB,oBAAoB,CAAA;AACxB,IAAA,aAAiB,WAAjB,iBAAiB,CAAA;AAC3C,IAAA,eAAkB,WAAlB,kBAAkB,CAAA;AAyB5BA,IAAAA,KAAI,qCAAM,oBAAoB,EAA1B;AAJhB;;GAEG,CACH,YAAA,KAAmC;;;2CAAnC,KAAmC;;;;mBAAnC,KAAmC;;;EAAA;AAG5B,MAAMC,MAAM,GAA+B,IAAM,IAAIC,WAAW,EAAE,AAAC;QAA7DD,MAAM,GAANA,MAAM;AACZ,MAAME,QAAQ,GAAmC,IACpD,IAAIC,eAAe,EAAE,AAAC;QADbD,QAAQ,GAARA,QAAQ;AAEd,MAAME,MAAM,GAAiC,IAAM,IAAIC,aAAa,EAAE,AAAC;QAAjED,MAAM,GAANA,MAAM;AACZ,MAAME,KAAK,GAAoC,IAClD,IAAIC,gBAAgB,EAAE,AAAC;QADdD,KAAK,GAALA,KAAK;AAEX,MAAME,MAAM,GAAqC,IACpD,IAAIC,iBAAiB,EAAE,AAAC;QADfD,MAAM,GAANA,MAAM;AAEZ,MAAME,MAAM,GAGf,CAACC,KAA+B,GAAG,EAAE,GACrC,IAAIC,oBAAoB,IAAID,KAAK,CAAC,AAAC;QAJ1BD,MAAM,GAANA,MAAM;AAKZ,MAAMG,OAAO,GAAyC,IACzD,IAAIC,qBAAqB,EAAE,AAAC;QADnBD,OAAO,GAAPA,OAAO;AAGb,MAAME,GAAG,GAAG;IACfT,KAAK,EAAG,IACJ,IAAIU,mBAAmB,EAAE;IAC7BN,MAAM,EAAG,IACL,IAAIO,uBAAuB,EAAE;CACpC,AAAS,AAAC;QALEF,GAAG,GAAHA,GAAG;IAQZ,OAAO,gCACP,SAAS,gCACT,WAAW,gCACX,eAAe;AAJnB,MAAMd,WAAW,SAASiB,iBAAe,gBAAA;IAMrCC,MAAM,CAAC,GAAGA,MAAM,AAAsB,EAAQ;uCACpCA,OAAM,EAAGA,MAAM,CAACC,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACvC,OAAO,IAAI,CAAC;KACf;IAEDnB,QAAQ,CAACA,QAA6B,EAAQ;uCACpCA,SAAQ,EAAGmB,CAAAA,GAAAA,aAAW,AAAU,CAAA,YAAV,CAACnB,QAAQ,CAAC,EAAC;QACvC,OAAO,IAAI,CAAC;KACf;IAEDoB,UAAU,CAACA,UAAqC,EAAQ;uCAC9CA,WAAU,EAAGA,UAAU,EAAEF,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QAChD,OAAO,IAAI,CAAC;KACf;IAEDE,cAAc,CAACA,cAAyC,EAAQ;uCACtDA,eAAc,EAAGF,CAAAA,GAAAA,aAAW,AAAgB,CAAA,YAAhB,CAACE,cAAc,CAAC,EAAC;QACnD,OAAO,IAAI,CAAC;KACf;IAEDC,KAAK,GAAS;QACV,OAAO;YACHL,MAAM,2BAAE,IAAI,EAAEA,OAAM;YACpBjB,QAAQ,2BAAE,IAAI,EAAEA,SAAQ;YACxBoB,UAAU,2BAAE,IAAI,EAAEA,WAAU;YAC5BC,cAAc,2BAAE,IAAI,EAAEA,eAAc;SACvC,CAAC;KACL;;;QAhCD,gCAAA,OAAO;;mBAAgB,EAAE;UAAC,CAAA;QAC1B,gCAAA,SAAS;;mBAAcE,SAAS;UAAC,CAAA;QACjC,gCAAA,WAAW;;mBAAqBA,SAAS;UAAC,CAAA;QAC1C,gCAAA,eAAe;;mBAAoBA,SAAS;UAAC,CAAA;;CA8BhD;IAGG,MAAM,gCACN,OAAO;AAFX,MAAMtB,eAAe,SAASe,iBAAe,gBAAA;IAIzCP,KAAK,CAACA,KAA+B,EAAQ;uCACnCA,MAAK,EAAGA,KAAK,CAACS,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACrC,OAAO,IAAI,CAAC;KACf;IAEDK,MAAM,CAACA,MAAgC,EAAQ;uCACrCA,OAAM,EAAGA,MAAM,CAACN,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACvC,OAAO,IAAI,CAAC;KACf;IAEDG,KAAK,GAAa;QACd,OAAO;YACHb,KAAK,2BAAE,IAAI,EAAEA,MAAK;YAClBe,MAAM,2BAAE,IAAI,EAAEA,OAAM;SACvB,CAAC;KACL;;;QAlBD,gCAAA,MAAM;;mBAAoB,EAAE;UAAC,CAAA;QAC7B,gCAAA,OAAO;;mBAAoB,EAAE;UAAC,CAAA;;CAkBjC;IAGG,QAAQ;AADZ,MAAMrB,aAAa,SAASa,iBAAe,gBAAA;IAGvCS,OAAO,CAACA,OAAoC,EAAQ;uCAC1CA,QAAO,EAAGN,CAAAA,GAAAA,aAAW,AAAS,CAAA,YAAT,CAACM,OAAO,CAAC,EAAC;QACrC,OAAO,IAAI,CAAC;KACf;IAEDH,KAAK,GAAW;QACZ,OAAO;YACHG,OAAO,2BAAE,IAAI,EAAEA,QAAO;SACzB,CAAC;KACL;;;QAXD,gCAAA,QAAQ;;mBAAsBC,CAAAA,GAAAA,eAAK,AAAE,CAAA,MAAF,EAAE,CAACJ,KAAK,EAAE;UAAC,CAAA;;CAYjD;IAGG,OAAM,gCACN,OAAO,gCACP,WAAW,gCACX,sBAAsB;AAJ1B,MAAMR,mBAAmB,SAASa,iBAAkB,mBAAA;IAMhDlB,KAAK,CAACA,KAA2C,EAAQ;uCAC/CA,OAAK,EAAGA,KAAK,CAACS,GAAG,CAACU,aAAY,aAAA,CAAC,EAAC;QACtC,OAAO,IAAI,CAAC;KACf;IAEDtB,MAAM,CAACA,MAAyC,EAAQ;uCAC9CA,OAAM,EAAGsB,CAAAA,GAAAA,aAAY,AAAc,CAAA,aAAd,CAACtB,MAAM,IAAI,EAAE,CAAC,EAAC;QAC1C,OAAO,IAAI,CAAC;KACf;IAEDuB,UAAU,CAACA,UAAsD,EAAQ;uCAC/DA,WAAU,EAAGA,UAAU,CAACX,GAAG,CAACU,aAAY,aAAA,CAAC,EAAC;QAChD,OAAO,IAAI,CAAC;KACf;IAEDE,qBAAqB,CACjBA,qBAA2D,EACvD;uCACEA,sBAAqB,EAAGA,qBAAqB,CAACZ,GAAG,CAACU,aAAY,aAAA,CAAC,EAAC;QACtE,OAAO,IAAI,CAAC;KACf;IAEDG,aAAa,CAACC,cAAuC,EAAa;QAC9D,OAAO;YACHC,EAAE,EAAEC,CAAAA,GAAAA,aAAI,AAMP,CAAA,KANO,CACJ,WAAW,2BACX,IAAI,EAAEzB,OAAK,4BACX,IAAI,EAAEoB,WAAU,4BAChB,IAAI,EAAEC,sBAAqB,4BAC3B,IAAI,EAAExB,OAAM,EACf;YACDG,KAAK,EAAEuB,cAAc,CAACG,KAAK,0BAAC,IAAI,EAAE1B,OAAK,EAAC;YACxCH,MAAM,EAAE0B,cAAc,CAACI,KAAK,0BAAC,IAAI,EAAE9B,OAAM,EAAC;YAC1CuB,UAAU,EAAEG,cAAc,CAACG,KAAK,0BAAC,IAAI,EAAEN,WAAU,EAAC;YAClDC,qBAAqB,EAAEE,cAAc,CAACG,KAAK,0BACvC,IAAI,EAAEL,sBAAqB,EAC9B;SACJ,CAAC;KACL;;;QA3CD,gCAAA,OAAM;;mBAAgC,EAAE;UAAC,CAAA;QACzC,gCAAA,OAAO;;mBAA4BP,SAAS;UAAC,CAAA;QAC7C,gCAAA,WAAW;;mBAAsC,EAAE;UAAC,CAAA;QACpD,gCAAA,sBAAsB;;mBAAgC,EAAE;UAAC,CAAA;;CAyC5D;IAGG,WAAW;AADf,MAAMlB,gBAAgB,SAASW,iBAAe,gBAAA;IAG1CP,KAAK,CAACA,KAA+B,EAAQ;QACzC,yBAAA,IAAI,EAAE4B,WAAU,EAAC5B,KAAK,CAAC;YAACA,KAAK;SAAC,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;KACf;IAEDH,MAAM,CAACA,MAA6B,EAAQ;QACxC,IAAIA,MAAM,EAAE;YACR,yBAAA,IAAI,EAAE+B,WAAU,EAAC/B,MAAM,CAAC;gBAACA,MAAM;aAAC,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;KACf;IAEDuB,UAAU,CAACA,UAA0C,EAAQ;QACzD,yBAAA,IAAI,EAAEQ,WAAU,EAACR,UAAU,CAAC;YAACA,UAAU;SAAC,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;KACf;IAEDC,qBAAqB,CACjBA,qBAA+C,EAC3C;QACJ,yBAAA,IAAI,EAAEO,WAAU,EAACP,qBAAqB,CAAC;YAACA,qBAAqB;SAAC,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC;KACf;IAEDR,KAAK,GAAc;QACf,OAAO,yBAAA,IAAI,EAAEe,WAAU,EAACf,KAAK,EAAE,CAAC;KACnC;;;QA5BD,gCAAA,WAAW;;mBAAwB,IAAIR,mBAAmB,EAAE;UAAC,CAAA;;CA6BhE;IAGG,QAAQ,gCACR,OAAO;AAFX,MAAMP,iBAAiB,SAASS,iBAAe,gBAAA;IAI3CsB,OAAO,CAACA,OAA8B,EAAQ;uCACpCA,QAAO,EAAGA,OAAO,EAAC;QACxB,OAAO,IAAI,CAAC;KACf;IAEDpC,MAAM,CAACA,MAAwB,EAAQ;uCAC7BA,OAAM,EAAGiB,CAAAA,GAAAA,aAAW,AAAQ,CAAA,YAAR,CAACjB,MAAM,CAAC,EAAC;QACnC,OAAO,IAAI,CAAC;KACf;IAEDoB,KAAK,GAAe;QAChB,OAAO;YACHgB,OAAO,2BAAE,IAAI,EAAEA,QAAO;YACtBpC,MAAM,2BAAE,IAAI,EAAEA,OAAM;SACvB,CAAC;KACL;;;QAlBD,gCAAA,QAAQ;;mBAA0B,MAAM;UAAC,CAAA;QACzC,gCAAA,OAAO;;mBAAYqB,SAAS;UAAC,CAAA;;CAkBhC;IAGG,OAAM;AADV,MAAMR,uBAAuB,SAASY,iBAAkB,mBAAA;IAGpDlB,KAAK,CAACA,KAA2C,EAAQ;uCAC/CA,OAAK,EAAGA,KAAK,CAACS,GAAG,CAACU,aAAY,aAAA,CAAC,EAAC;QACtC,OAAO,IAAI,CAAC;KACf;IAEDG,aAAa,CAACC,cAAuC,EAAiB;QAClE,MAAMC,EAAE,GAAGC,CAAAA,GAAAA,aAAI,AAA+B,CAAA,KAA/B,CAAC,gBAAgB,2BAAE,IAAI,EAAEzB,OAAK,EAAC,AAAC;QAC/C,OAAO;YACHwB,EAAE;YACFxB,KAAK,EAAEuB,cAAc,CAACG,KAAK,0BAAC,IAAI,EAAE1B,OAAK,EAAC;SAC3C,CAAC;KACL;;;QAbD,gCAAA,OAAM;;mBAAgC,EAAE;UAAC,CAAA;;CAc5C;IAGG,YAAW;AADf,MAAMC,oBAAoB,SAASM,iBAAe,gBAAA;IAQ9CP,KAAK,CAAC,GAAGA,KAAK,AAA0B,EAAQ;QAC5C,yBAAA,IAAI,EAAE4B,YAAU,EAAC5B,KAAK,CAAC;YAACA,KAAK;SAAC,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;KACf;IAEDa,KAAK,GAAkB;QACnB,OAAO,yBAAA,IAAI,EAAEe,YAAU,EAACf,KAAK,EAAE,CAAC;KACnC;IAZDiB,YAAY,GAAG9B,KAAK,AAA0B,CAAE;QAC5C,KAAK,EAAE,CAAC;QAHZ,gCAAA,YAAW;;mBAA4B,IAAIM,uBAAuB,EAAE;UAAC,CAAA;QAIjE,IAAI,CAACN,KAAK,IAAIA,KAAK,CAAC,CAAC;KACxB;CAUJ;IAGG,OAAM,gCACN,QAAO;AAFX,MAAMG,qBAAqB,SAASI,iBAAe,gBAAA;IAI/CP,KAAK,CAAC,GAAGA,KAAK,AAA0B,EAAQ;uCACtCA,OAAK,EAAGA,KAAK,CAACS,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACrC,OAAO,IAAI,CAAC;KACf;IAEDK,MAAM,CAAC,GAAGA,MAAM,AAA0B,EAAQ;uCACxCA,QAAM,EAAGA,MAAM,CAACN,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACvC,OAAO,IAAI,CAAC;KACf;IAEDG,KAAK,GAAmB;QACpB,OAAO;YACHb,KAAK,2BAAE,IAAI,EAAEA,OAAK;YAClBe,MAAM,2BAAE,IAAI,EAAEA,QAAM;SACvB,CAAC;KACL;;;QAlBD,gCAAA,OAAM;;mBAAoB,EAAE;UAAC,CAAA;QAC7B,gCAAA,QAAO;;mBAAoB,EAAE;UAAC,CAAA;;CAkBjC;QA9PW3B,IAAI,GAAJA,KAAI", + "mappings": "AAAA;;;;;;;;;;;IA6BaA,MAAM,MAANA,MAAM;IAMNC,MAAM,MAANA,MAAM;IARPC,IAAI;IAKHC,MAAM,MAANA,MAAM;IAaNC,GAAG,MAAHA,GAAG;IARHC,MAAM,MAANA,MAAM;IAKNC,OAAO,MAAPA,OAAO;IATPC,KAAK,MAALA,KAAK;IAHLC,QAAQ,MAARA,QAAQ;;;;;;;kCA9B+B,oBAAoB;8BACxB,iBAAiB;gCAC3C,kBAAkB;sEAwB1B,oBAAoB;AAG3B,MAAMR,MAAM,GAA+B,IAAM,IAAIS,WAAW,EAAE,AAAC;AACnE,MAAMD,QAAQ,GAAmC,IACpD,IAAIE,eAAe,EAAE,AAAC;AACnB,MAAMP,MAAM,GAAiC,IAAM,IAAIQ,aAAa,EAAE,AAAC;AACvE,MAAMJ,KAAK,GAAoC,IAClD,IAAIK,gBAAgB,EAAE,AAAC;AACpB,MAAMX,MAAM,GAAqC,IACpD,IAAIY,iBAAiB,EAAE,AAAC;AACrB,MAAMR,MAAM,GAGf,CAACS,KAA+B,GAAG,EAAE,GACrC,IAAIC,oBAAoB,IAAID,KAAK,CAAC,AAAC;AAChC,MAAMR,OAAO,GAAyC,IACzD,IAAIU,qBAAqB,EAAE,AAAC;AAEzB,MAAMZ,GAAG,GAAG;IACfG,KAAK,EAAG,IACJ,IAAIU,mBAAmB,EAAE;IAC7BZ,MAAM,EAAG,IACL,IAAIa,uBAAuB,EAAE;CACpC,AAAS,AAAC;IAGP,OAAO,gCACP,SAAS,gCACT,WAAW,gCACX,eAAe;AAJnB,MAAMT,WAAW,SAASU,iBAAe,gBAAA;IAMrCC,MAAM,CAAC,GAAGA,MAAM,AAAsB,EAAQ;oCACpCA,OAAM,EAAGA,MAAM,CAACC,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACvC,OAAO,IAAI,CAAC;KACf;IAEDd,QAAQ,CAACA,QAA6B,EAAQ;oCACpCA,SAAQ,EAAGc,IAAAA,aAAW,YAAA,EAACd,QAAQ,CAAC,EAAC;QACvC,OAAO,IAAI,CAAC;KACf;IAEDe,UAAU,CAACA,UAAqC,EAAQ;oCAC9CA,WAAU,EAAGA,UAAU,EAAEF,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QAChD,OAAO,IAAI,CAAC;KACf;IAEDE,cAAc,CAACA,cAAyC,EAAQ;oCACtDA,eAAc,EAAGF,IAAAA,aAAW,YAAA,EAACE,cAAc,CAAC,EAAC;QACnD,OAAO,IAAI,CAAC;KACf;IAEDC,KAAK,GAAS;QACV,OAAO;YACHL,MAAM,wBAAE,IAAI,EAAEA,OAAM;YACpBZ,QAAQ,wBAAE,IAAI,EAAEA,SAAQ;YACxBe,UAAU,wBAAE,IAAI,EAAEA,WAAU;YAC5BC,cAAc,wBAAE,IAAI,EAAEA,eAAc;SACvC,CAAC;KACL;;;QAhCD,6BAAA,OAAO;;mBAAgB,EAAE;UAAC,CAAA;QAC1B,6BAAA,SAAS;;mBAAcE,SAAS;UAAC,CAAA;QACjC,6BAAA,WAAW;;mBAAqBA,SAAS;UAAC,CAAA;QAC1C,6BAAA,eAAe;;mBAAoBA,SAAS;UAAC,CAAA;;CA8BhD;IAGG,MAAM,gCACN,OAAO;AAFX,MAAMhB,eAAe,SAASS,iBAAe,gBAAA;IAIzCL,KAAK,CAACA,KAA+B,EAAQ;oCACnCA,MAAK,EAAGA,KAAK,CAACO,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACrC,OAAO,IAAI,CAAC;KACf;IAEDK,MAAM,CAACA,MAAgC,EAAQ;oCACrCA,OAAM,EAAGA,MAAM,CAACN,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACvC,OAAO,IAAI,CAAC;KACf;IAEDG,KAAK,GAAa;QACd,OAAO;YACHX,KAAK,wBAAE,IAAI,EAAEA,MAAK;YAClBa,MAAM,wBAAE,IAAI,EAAEA,OAAM;SACvB,CAAC;KACL;;;QAlBD,6BAAA,MAAM;;mBAAoB,EAAE;UAAC,CAAA;QAC7B,6BAAA,OAAO;;mBAAoB,EAAE;UAAC,CAAA;;CAkBjC;IAGG,QAAQ;AADZ,MAAMhB,aAAa,SAASQ,iBAAe,gBAAA;IAGvCS,OAAO,CAACA,OAAoC,EAAQ;oCAC1CA,QAAO,EAAGN,IAAAA,aAAW,YAAA,EAACM,OAAO,CAAC,EAAC;QACrC,OAAO,IAAI,CAAC;KACf;IAEDH,KAAK,GAAW;QACZ,OAAO;YACHG,OAAO,wBAAE,IAAI,EAAEA,QAAO;SACzB,CAAC;KACL;;;QAXD,6BAAA,QAAQ;;mBAAsBC,IAAAA,eAAK,MAAA,GAAE,CAACJ,KAAK,EAAE;UAAC,CAAA;;CAYjD;IAGG,OAAM,gCACN,OAAO,gCACP,WAAW,gCACX,sBAAsB;AAJ1B,MAAMR,mBAAmB,SAASa,iBAAkB,mBAAA;IAMhDhB,KAAK,CAACA,KAA2C,EAAQ;oCAC/CA,OAAK,EAAGA,KAAK,CAACO,GAAG,CAACU,aAAY,aAAA,CAAC,EAAC;QACtC,OAAO,IAAI,CAAC;KACf;IAED9B,MAAM,CAACA,MAAyC,EAAQ;oCAC9CA,OAAM,EAAG8B,IAAAA,aAAY,aAAA,EAAC9B,MAAM,IAAI,EAAE,CAAC,EAAC;QAC1C,OAAO,IAAI,CAAC;KACf;IAED+B,UAAU,CAACA,UAAsD,EAAQ;oCAC/DA,WAAU,EAAGA,UAAU,CAACX,GAAG,CAACU,aAAY,aAAA,CAAC,EAAC;QAChD,OAAO,IAAI,CAAC;KACf;IAEDE,qBAAqB,CACjBA,qBAA2D,EACvD;oCACEA,sBAAqB,EAAGA,qBAAqB,CAACZ,GAAG,CAACU,aAAY,aAAA,CAAC,EAAC;QACtE,OAAO,IAAI,CAAC;KACf;IAEDG,aAAa,CAACC,cAAuC,EAAa;QAC9D,OAAO;YACHC,EAAE,EAAEC,IAAAA,aAAI,KAAA,EACJ,WAAW,wBACX,IAAI,EAAEvB,OAAK,yBACX,IAAI,EAAEkB,WAAU,yBAChB,IAAI,EAAEC,sBAAqB,yBAC3B,IAAI,EAAEhC,OAAM,EACf;YACDa,KAAK,EAAEqB,cAAc,CAACG,KAAK,uBAAC,IAAI,EAAExB,OAAK,EAAC;YACxCb,MAAM,EAAEkC,cAAc,CAACI,KAAK,uBAAC,IAAI,EAAEtC,OAAM,EAAC;YAC1C+B,UAAU,EAAEG,cAAc,CAACG,KAAK,uBAAC,IAAI,EAAEN,WAAU,EAAC;YAClDC,qBAAqB,EAAEE,cAAc,CAACG,KAAK,uBACvC,IAAI,EAAEL,sBAAqB,EAC9B;SACJ,CAAC;KACL;;;QA3CD,6BAAA,OAAM;;mBAAgC,EAAE;UAAC,CAAA;QACzC,6BAAA,OAAO;;mBAA4BP,SAAS;UAAC,CAAA;QAC7C,6BAAA,WAAW;;mBAAsC,EAAE;UAAC,CAAA;QACpD,6BAAA,sBAAsB;;mBAAgC,EAAE;UAAC,CAAA;;CAyC5D;IAGG,WAAW;AADf,MAAMd,gBAAgB,SAASO,iBAAe,gBAAA;IAG1CL,KAAK,CAACA,KAA+B,EAAQ;QACzC,sBAAA,IAAI,EAAE0B,WAAU,EAAC1B,KAAK,CAAC;YAACA,KAAK;SAAC,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;KACf;IAEDb,MAAM,CAACA,MAA6B,EAAQ;QACxC,IAAIA,MAAM,EAAE;YACR,sBAAA,IAAI,EAAEuC,WAAU,EAACvC,MAAM,CAAC;gBAACA,MAAM;aAAC,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;KACf;IAED+B,UAAU,CAACA,UAA0C,EAAQ;QACzD,sBAAA,IAAI,EAAEQ,WAAU,EAACR,UAAU,CAAC;YAACA,UAAU;SAAC,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;KACf;IAEDC,qBAAqB,CACjBA,qBAA+C,EAC3C;QACJ,sBAAA,IAAI,EAAEO,WAAU,EAACP,qBAAqB,CAAC;YAACA,qBAAqB;SAAC,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC;KACf;IAEDR,KAAK,GAAc;QACf,OAAO,sBAAA,IAAI,EAAEe,WAAU,EAACf,KAAK,EAAE,CAAC;KACnC;;;QA5BD,6BAAA,WAAW;;mBAAwB,IAAIR,mBAAmB,EAAE;UAAC,CAAA;;CA6BhE;IAGG,QAAQ,gCACR,OAAO;AAFX,MAAMJ,iBAAiB,SAASM,iBAAe,gBAAA;IAI3CsB,OAAO,CAACA,OAA8B,EAAQ;oCACpCA,QAAO,EAAGA,OAAO,EAAC;QACxB,OAAO,IAAI,CAAC;KACf;IAEDtC,MAAM,CAACA,MAAwB,EAAQ;oCAC7BA,OAAM,EAAGmB,IAAAA,aAAW,YAAA,EAACnB,MAAM,CAAC,EAAC;QACnC,OAAO,IAAI,CAAC;KACf;IAEDsB,KAAK,GAAe;QAChB,OAAO;YACHgB,OAAO,wBAAE,IAAI,EAAEA,QAAO;YACtBtC,MAAM,wBAAE,IAAI,EAAEA,OAAM;SACvB,CAAC;KACL;;;QAlBD,6BAAA,QAAQ;;mBAA0B,MAAM;UAAC,CAAA;QACzC,6BAAA,OAAO;;mBAAYuB,SAAS;UAAC,CAAA;;CAkBhC;IAGG,OAAM;AADV,MAAMR,uBAAuB,SAASY,iBAAkB,mBAAA;IAGpDhB,KAAK,CAACA,KAA2C,EAAQ;oCAC/CA,OAAK,EAAGA,KAAK,CAACO,GAAG,CAACU,aAAY,aAAA,CAAC,EAAC;QACtC,OAAO,IAAI,CAAC;KACf;IAEDG,aAAa,CAACC,cAAuC,EAAiB;QAClE,MAAMC,EAAE,GAAGC,IAAAA,aAAI,KAAA,EAAC,gBAAgB,wBAAE,IAAI,EAAEvB,OAAK,EAAC,AAAC;QAC/C,OAAO;YACHsB,EAAE;YACFtB,KAAK,EAAEqB,cAAc,CAACG,KAAK,uBAAC,IAAI,EAAExB,OAAK,EAAC;SAC3C,CAAC;KACL;;;QAbD,6BAAA,OAAM;;mBAAgC,EAAE;UAAC,CAAA;;CAc5C;IAGG,YAAW;AADf,MAAMC,oBAAoB,SAASI,iBAAe,gBAAA;IAQ9CL,KAAK,CAAC,GAAGA,KAAK,AAA0B,EAAQ;QAC5C,sBAAA,IAAI,EAAE0B,YAAU,EAAC1B,KAAK,CAAC;YAACA,KAAK;SAAC,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;KACf;IAEDW,KAAK,GAAkB;QACnB,OAAO,sBAAA,IAAI,EAAEe,YAAU,EAACf,KAAK,EAAE,CAAC;KACnC;IAZDiB,YAAY,GAAG5B,KAAK,AAA0B,CAAE;QAC5C,KAAK,EAAE,CAAC;QAHZ,6BAAA,YAAW;;mBAA4B,IAAII,uBAAuB,EAAE;UAAC,CAAA;QAIjE,IAAI,CAACJ,KAAK,IAAIA,KAAK,CAAC,CAAC;KACxB;CAUJ;IAGG,OAAM,gCACN,QAAO;AAFX,MAAME,qBAAqB,SAASG,iBAAe,gBAAA;IAI/CL,KAAK,CAAC,GAAGA,KAAK,AAA0B,EAAQ;oCACtCA,OAAK,EAAGA,KAAK,CAACO,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACrC,OAAO,IAAI,CAAC;KACf;IAEDK,MAAM,CAAC,GAAGA,MAAM,AAA0B,EAAQ;oCACxCA,QAAM,EAAGA,MAAM,CAACN,GAAG,CAACC,aAAW,YAAA,CAAC,EAAC;QACvC,OAAO,IAAI,CAAC;KACf;IAEDG,KAAK,GAAmB;QACpB,OAAO;YACHX,KAAK,wBAAE,IAAI,EAAEA,OAAK;YAClBa,MAAM,wBAAE,IAAI,EAAEA,QAAM;SACvB,CAAC;KACL;;;QAlBD,6BAAA,OAAM;;mBAAoB,EAAE;UAAC,CAAA;QAC7B,6BAAA,QAAO;;mBAAoB,EAAE;UAAC,CAAA;;CAkBjC", "names": [ - "node", "create", - "BodyBuilder", - "trustBox", - "TrustBoxBuilder", - "opener", - "OpenerBuilder", - "stage", - "BodyStageBuilder", "header", - "BodyHeaderBuilder", + "node", + "opener", + "seq", "source", + "sources", + "stage", + "trustBox", + "BodyBuilder", + "TrustBoxBuilder", + "OpenerBuilder", + "BodyStageBuilder", + "BodyHeaderBuilder", "nodes", "ArticleSourceBuilder", - "sources", "ArticleSourcesBuilder", - "seq", "BodyStageSeqBuilder", "ArticleSourceSeqBuilder", "AbstractBuilder", diff --git a/crates/swc/tests/fixture/sourcemap/issue-3854/1-true/output/index.ts b/crates/swc/tests/fixture/sourcemap/issue-3854/1-true/output/index.ts index e5c0b991a76..76a152eda06 100644 --- a/crates/swc/tests/fixture/sourcemap/issue-3854/1-true/output/index.ts +++ b/crates/swc/tests/fixture/sourcemap/issue-3854/1-true/output/index.ts @@ -2,99 +2,84 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _exportNames = { - node: true, - create: true, - trustBox: true, - opener: true, - stage: true, - header: true, - source: true, - sources: true, - seq: true -}; -exports.seq = exports.sources = exports.source = exports.header = exports.stage = exports.opener = exports.trustBox = exports.create = exports.node = void 0; -var _class_private_field_get = require("@swc/helpers/lib/_class_private_field_get.js").default; -var _class_private_field_init = require("@swc/helpers/lib/_class_private_field_init.js").default; -var _class_private_field_set = require("@swc/helpers/lib/_class_private_field_set.js").default; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _abstractBuilders = require("./AbstractBuilders"); -var _builderUtils = require("./Builder.utils"); -var _elementBuilder = require("./ElementBuilder"); -var _node = _interop_require_wildcard(require("./BodyNodesBuilder")); -/** - * @deprecated use {Builder.body.node.img()} - */ Object.keys(_node).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _node[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _node[key]; - } +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true }); +} +_export(exports, { + create: ()=>create, + header: ()=>header, + node: ()=>_bodyNodesBuilder, + opener: ()=>opener, + seq: ()=>seq, + source: ()=>source, + sources: ()=>sources, + stage: ()=>stage, + trustBox: ()=>trustBox }); +const _classPrivateFieldGet = require("@swc/helpers/lib/_class_private_field_get.js").default; +const _classPrivateFieldInit = require("@swc/helpers/lib/_class_private_field_init.js").default; +const _classPrivateFieldSet = require("@swc/helpers/lib/_class_private_field_set.js").default; +const _exportStar = require("@swc/helpers/lib/_export_star.js").default; +const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +const _abstractBuilders = require("./AbstractBuilders"); +const _builderUtils = require("./Builder.utils"); +const _elementBuilder = require("./ElementBuilder"); +const _bodyNodesBuilder = _interopRequireWildcard(_exportStar(require("./BodyNodesBuilder"), exports)); const create = ()=>new BodyBuilder(); -exports.create = create; const trustBox = ()=>new TrustBoxBuilder(); -exports.trustBox = trustBox; const opener = ()=>new OpenerBuilder(); -exports.opener = opener; const stage = ()=>new BodyStageBuilder(); -exports.stage = stage; const header = ()=>new BodyHeaderBuilder(); -exports.header = header; const source = (nodes = [])=>new ArticleSourceBuilder(...nodes); -exports.source = source; const sources = ()=>new ArticleSourcesBuilder(); -exports.sources = sources; const seq = { stage: ()=>new BodyStageSeqBuilder(), source: ()=>new ArticleSourceSeqBuilder() }; -exports.seq = seq; var _stages = /*#__PURE__*/ new WeakMap(), _trustBox = /*#__PURE__*/ new WeakMap(), _disclaimer = /*#__PURE__*/ new WeakMap(), _articleSources = /*#__PURE__*/ new WeakMap(); class BodyBuilder extends _abstractBuilders.AbstractBuilder { stages(...stages) { - _class_private_field_set(this, _stages, stages.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _stages, stages.map(_builderUtils.mapBuildArg)); return this; } trustBox(trustBox) { - _class_private_field_set(this, _trustBox, (0, _builderUtils).mapBuildArg(trustBox)); + _classPrivateFieldSet(this, _trustBox, (0, _builderUtils.mapBuildArg)(trustBox)); return this; } disclaimer(disclaimer) { - _class_private_field_set(this, _disclaimer, disclaimer?.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _disclaimer, disclaimer?.map(_builderUtils.mapBuildArg)); return this; } articleSources(articleSources) { - _class_private_field_set(this, _articleSources, (0, _builderUtils).mapBuildArg(articleSources)); + _classPrivateFieldSet(this, _articleSources, (0, _builderUtils.mapBuildArg)(articleSources)); return this; } build() { return { - stages: _class_private_field_get(this, _stages), - trustBox: _class_private_field_get(this, _trustBox), - disclaimer: _class_private_field_get(this, _disclaimer), - articleSources: _class_private_field_get(this, _articleSources) + stages: _classPrivateFieldGet(this, _stages), + trustBox: _classPrivateFieldGet(this, _trustBox), + disclaimer: _classPrivateFieldGet(this, _disclaimer), + articleSources: _classPrivateFieldGet(this, _articleSources) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _stages, { + _classPrivateFieldInit(this, _stages, { writable: true, value: [] }); - _class_private_field_init(this, _trustBox, { + _classPrivateFieldInit(this, _trustBox, { writable: true, value: undefined }); - _class_private_field_init(this, _disclaimer, { + _classPrivateFieldInit(this, _disclaimer, { writable: true, value: undefined }); - _class_private_field_init(this, _articleSources, { + _classPrivateFieldInit(this, _articleSources, { writable: true, value: undefined }); @@ -103,26 +88,26 @@ class BodyBuilder extends _abstractBuilders.AbstractBuilder { var _nodes = /*#__PURE__*/ new WeakMap(), _hidden = /*#__PURE__*/ new WeakMap(); class TrustBoxBuilder extends _abstractBuilders.AbstractBuilder { nodes(nodes) { - _class_private_field_set(this, _nodes, nodes.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _nodes, nodes.map(_builderUtils.mapBuildArg)); return this; } hidden(hidden) { - _class_private_field_set(this, _hidden, hidden.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _hidden, hidden.map(_builderUtils.mapBuildArg)); return this; } build() { return { - nodes: _class_private_field_get(this, _nodes), - hidden: _class_private_field_get(this, _hidden) + nodes: _classPrivateFieldGet(this, _nodes), + hidden: _classPrivateFieldGet(this, _hidden) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _nodes, { + _classPrivateFieldInit(this, _nodes, { writable: true, value: [] }); - _class_private_field_init(this, _hidden, { + _classPrivateFieldInit(this, _hidden, { writable: true, value: [] }); @@ -131,64 +116,64 @@ class TrustBoxBuilder extends _abstractBuilders.AbstractBuilder { var _element = /*#__PURE__*/ new WeakMap(); class OpenerBuilder extends _abstractBuilders.AbstractBuilder { element(element) { - _class_private_field_set(this, _element, (0, _builderUtils).mapBuildArg(element)); + _classPrivateFieldSet(this, _element, (0, _builderUtils.mapBuildArg)(element)); return this; } build() { return { - element: _class_private_field_get(this, _element) + element: _classPrivateFieldGet(this, _element) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _element, { + _classPrivateFieldInit(this, _element, { writable: true, - value: (0, _elementBuilder).image().build() + value: (0, _elementBuilder.image)().build() }); } } var _nodes1 = /*#__PURE__*/ new WeakMap(), _header = /*#__PURE__*/ new WeakMap(), _companions = /*#__PURE__*/ new WeakMap(), _commercialsEndOfStage = /*#__PURE__*/ new WeakMap(); class BodyStageSeqBuilder extends _abstractBuilders.AbstractSeqBuilder { nodes(nodes) { - _class_private_field_set(this, _nodes1, nodes.map(_builderUtils.mapBuildArgs)); + _classPrivateFieldSet(this, _nodes1, nodes.map(_builderUtils.mapBuildArgs)); return this; } header(header) { - _class_private_field_set(this, _header, (0, _builderUtils).mapBuildArgs(header ?? [])); + _classPrivateFieldSet(this, _header, (0, _builderUtils.mapBuildArgs)(header ?? [])); return this; } companions(companions) { - _class_private_field_set(this, _companions, companions.map(_builderUtils.mapBuildArgs)); + _classPrivateFieldSet(this, _companions, companions.map(_builderUtils.mapBuildArgs)); return this; } commercialsEndOfStage(commercialsEndOfStage) { - _class_private_field_set(this, _commercialsEndOfStage, commercialsEndOfStage.map(_builderUtils.mapBuildArgs)); + _classPrivateFieldSet(this, _commercialsEndOfStage, commercialsEndOfStage.map(_builderUtils.mapBuildArgs)); return this; } buildListItem(seqNextElement) { return { - id: (0, _builderUtils).hash("bodyStage", _class_private_field_get(this, _nodes1), _class_private_field_get(this, _companions), _class_private_field_get(this, _commercialsEndOfStage), _class_private_field_get(this, _header)), - nodes: seqNextElement.array(_class_private_field_get(this, _nodes1)), - header: seqNextElement.maybe(_class_private_field_get(this, _header)), - companions: seqNextElement.array(_class_private_field_get(this, _companions)), - commercialsEndOfStage: seqNextElement.array(_class_private_field_get(this, _commercialsEndOfStage)) + id: (0, _builderUtils.hash)("bodyStage", _classPrivateFieldGet(this, _nodes1), _classPrivateFieldGet(this, _companions), _classPrivateFieldGet(this, _commercialsEndOfStage), _classPrivateFieldGet(this, _header)), + nodes: seqNextElement.array(_classPrivateFieldGet(this, _nodes1)), + header: seqNextElement.maybe(_classPrivateFieldGet(this, _header)), + companions: seqNextElement.array(_classPrivateFieldGet(this, _companions)), + commercialsEndOfStage: seqNextElement.array(_classPrivateFieldGet(this, _commercialsEndOfStage)) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _nodes1, { + _classPrivateFieldInit(this, _nodes1, { writable: true, value: [] }); - _class_private_field_init(this, _header, { + _classPrivateFieldInit(this, _header, { writable: true, value: undefined }); - _class_private_field_init(this, _companions, { + _classPrivateFieldInit(this, _companions, { writable: true, value: [] }); - _class_private_field_init(this, _commercialsEndOfStage, { + _classPrivateFieldInit(this, _commercialsEndOfStage, { writable: true, value: [] }); @@ -197,37 +182,37 @@ class BodyStageSeqBuilder extends _abstractBuilders.AbstractSeqBuilder { var _seqBuilder = /*#__PURE__*/ new WeakMap(); class BodyStageBuilder extends _abstractBuilders.AbstractBuilder { nodes(nodes) { - _class_private_field_get(this, _seqBuilder).nodes([ + _classPrivateFieldGet(this, _seqBuilder).nodes([ nodes ]); return this; } header(header) { if (header) { - _class_private_field_get(this, _seqBuilder).header([ + _classPrivateFieldGet(this, _seqBuilder).header([ header ]); } return this; } companions(companions) { - _class_private_field_get(this, _seqBuilder).companions([ + _classPrivateFieldGet(this, _seqBuilder).companions([ companions ]); return this; } commercialsEndOfStage(commercialsEndOfStage) { - _class_private_field_get(this, _seqBuilder).commercialsEndOfStage([ + _classPrivateFieldGet(this, _seqBuilder).commercialsEndOfStage([ commercialsEndOfStage ]); return this; } build() { - return _class_private_field_get(this, _seqBuilder).build(); + return _classPrivateFieldGet(this, _seqBuilder).build(); } constructor(...args){ super(...args); - _class_private_field_init(this, _seqBuilder, { + _classPrivateFieldInit(this, _seqBuilder, { writable: true, value: new BodyStageSeqBuilder() }); @@ -236,26 +221,26 @@ class BodyStageBuilder extends _abstractBuilders.AbstractBuilder { var _variant = /*#__PURE__*/ new WeakMap(), _opener = /*#__PURE__*/ new WeakMap(); class BodyHeaderBuilder extends _abstractBuilders.AbstractBuilder { variant(variant) { - _class_private_field_set(this, _variant, variant); + _classPrivateFieldSet(this, _variant, variant); return this; } opener(opener) { - _class_private_field_set(this, _opener, (0, _builderUtils).mapBuildArg(opener)); + _classPrivateFieldSet(this, _opener, (0, _builderUtils.mapBuildArg)(opener)); return this; } build() { return { - variant: _class_private_field_get(this, _variant), - opener: _class_private_field_get(this, _opener) + variant: _classPrivateFieldGet(this, _variant), + opener: _classPrivateFieldGet(this, _opener) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _variant, { + _classPrivateFieldInit(this, _variant, { writable: true, value: "full" }); - _class_private_field_init(this, _opener, { + _classPrivateFieldInit(this, _opener, { writable: true, value: undefined }); @@ -264,19 +249,19 @@ class BodyHeaderBuilder extends _abstractBuilders.AbstractBuilder { var _nodes2 = /*#__PURE__*/ new WeakMap(); class ArticleSourceSeqBuilder extends _abstractBuilders.AbstractSeqBuilder { nodes(nodes) { - _class_private_field_set(this, _nodes2, nodes.map(_builderUtils.mapBuildArgs)); + _classPrivateFieldSet(this, _nodes2, nodes.map(_builderUtils.mapBuildArgs)); return this; } buildListItem(seqNextElement) { - const id = (0, _builderUtils).hash("article-source", _class_private_field_get(this, _nodes2)); + const id = (0, _builderUtils.hash)("article-source", _classPrivateFieldGet(this, _nodes2)); return { id, - nodes: seqNextElement.array(_class_private_field_get(this, _nodes2)) + nodes: seqNextElement.array(_classPrivateFieldGet(this, _nodes2)) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _nodes2, { + _classPrivateFieldInit(this, _nodes2, { writable: true, value: [] }); @@ -285,17 +270,17 @@ class ArticleSourceSeqBuilder extends _abstractBuilders.AbstractSeqBuilder { var _seqBuilder1 = /*#__PURE__*/ new WeakMap(); class ArticleSourceBuilder extends _abstractBuilders.AbstractBuilder { nodes(...nodes) { - _class_private_field_get(this, _seqBuilder1).nodes([ + _classPrivateFieldGet(this, _seqBuilder1).nodes([ nodes ]); return this; } build() { - return _class_private_field_get(this, _seqBuilder1).build(); + return _classPrivateFieldGet(this, _seqBuilder1).build(); } constructor(...nodes){ super(); - _class_private_field_init(this, _seqBuilder1, { + _classPrivateFieldInit(this, _seqBuilder1, { writable: true, value: new ArticleSourceSeqBuilder() }); @@ -305,29 +290,28 @@ class ArticleSourceBuilder extends _abstractBuilders.AbstractBuilder { var _nodes3 = /*#__PURE__*/ new WeakMap(), _hidden1 = /*#__PURE__*/ new WeakMap(); class ArticleSourcesBuilder extends _abstractBuilders.AbstractBuilder { nodes(...nodes) { - _class_private_field_set(this, _nodes3, nodes.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _nodes3, nodes.map(_builderUtils.mapBuildArg)); return this; } hidden(...hidden) { - _class_private_field_set(this, _hidden1, hidden.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _hidden1, hidden.map(_builderUtils.mapBuildArg)); return this; } build() { return { - nodes: _class_private_field_get(this, _nodes3), - hidden: _class_private_field_get(this, _hidden1) + nodes: _classPrivateFieldGet(this, _nodes3), + hidden: _classPrivateFieldGet(this, _hidden1) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _nodes3, { + _classPrivateFieldInit(this, _nodes3, { writable: true, value: [] }); - _class_private_field_init(this, _hidden1, { + _classPrivateFieldInit(this, _hidden1, { writable: true, value: [] }); } } -exports.node = _node; diff --git a/crates/swc/tests/fixture/sourcemap/issue-3854/2-inline/output/index.ts b/crates/swc/tests/fixture/sourcemap/issue-3854/2-inline/output/index.ts index a39ce3ebd0b..57103eeabf0 100644 --- a/crates/swc/tests/fixture/sourcemap/issue-3854/2-inline/output/index.ts +++ b/crates/swc/tests/fixture/sourcemap/issue-3854/2-inline/output/index.ts @@ -2,99 +2,84 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _exportNames = { - node: true, - create: true, - trustBox: true, - opener: true, - stage: true, - header: true, - source: true, - sources: true, - seq: true -}; -exports.seq = exports.sources = exports.source = exports.header = exports.stage = exports.opener = exports.trustBox = exports.create = exports.node = void 0; -var _class_private_field_get = require("@swc/helpers/lib/_class_private_field_get.js").default; -var _class_private_field_init = require("@swc/helpers/lib/_class_private_field_init.js").default; -var _class_private_field_set = require("@swc/helpers/lib/_class_private_field_set.js").default; -var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; -var _abstractBuilders = require("./AbstractBuilders"); -var _builderUtils = require("./Builder.utils"); -var _elementBuilder = require("./ElementBuilder"); -var _node = _interop_require_wildcard(require("./BodyNodesBuilder")); -/** - * @deprecated use {Builder.body.node.img()} - */ Object.keys(_node).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _node[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _node[key]; - } +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true }); +} +_export(exports, { + create: ()=>create, + header: ()=>header, + node: ()=>_bodyNodesBuilder, + opener: ()=>opener, + seq: ()=>seq, + source: ()=>source, + sources: ()=>sources, + stage: ()=>stage, + trustBox: ()=>trustBox }); +const _classPrivateFieldGet = require("@swc/helpers/lib/_class_private_field_get.js").default; +const _classPrivateFieldInit = require("@swc/helpers/lib/_class_private_field_init.js").default; +const _classPrivateFieldSet = require("@swc/helpers/lib/_class_private_field_set.js").default; +const _exportStar = require("@swc/helpers/lib/_export_star.js").default; +const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; +const _abstractBuilders = require("./AbstractBuilders"); +const _builderUtils = require("./Builder.utils"); +const _elementBuilder = require("./ElementBuilder"); +const _bodyNodesBuilder = _interopRequireWildcard(_exportStar(require("./BodyNodesBuilder"), exports)); const create = ()=>new BodyBuilder(); -exports.create = create; const trustBox = ()=>new TrustBoxBuilder(); -exports.trustBox = trustBox; const opener = ()=>new OpenerBuilder(); -exports.opener = opener; const stage = ()=>new BodyStageBuilder(); -exports.stage = stage; const header = ()=>new BodyHeaderBuilder(); -exports.header = header; const source = (nodes = [])=>new ArticleSourceBuilder(...nodes); -exports.source = source; const sources = ()=>new ArticleSourcesBuilder(); -exports.sources = sources; const seq = { stage: ()=>new BodyStageSeqBuilder(), source: ()=>new ArticleSourceSeqBuilder() }; -exports.seq = seq; var _stages = /*#__PURE__*/ new WeakMap(), _trustBox = /*#__PURE__*/ new WeakMap(), _disclaimer = /*#__PURE__*/ new WeakMap(), _articleSources = /*#__PURE__*/ new WeakMap(); class BodyBuilder extends _abstractBuilders.AbstractBuilder { stages(...stages) { - _class_private_field_set(this, _stages, stages.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _stages, stages.map(_builderUtils.mapBuildArg)); return this; } trustBox(trustBox) { - _class_private_field_set(this, _trustBox, (0, _builderUtils).mapBuildArg(trustBox)); + _classPrivateFieldSet(this, _trustBox, (0, _builderUtils.mapBuildArg)(trustBox)); return this; } disclaimer(disclaimer) { - _class_private_field_set(this, _disclaimer, disclaimer?.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _disclaimer, disclaimer?.map(_builderUtils.mapBuildArg)); return this; } articleSources(articleSources) { - _class_private_field_set(this, _articleSources, (0, _builderUtils).mapBuildArg(articleSources)); + _classPrivateFieldSet(this, _articleSources, (0, _builderUtils.mapBuildArg)(articleSources)); return this; } build() { return { - stages: _class_private_field_get(this, _stages), - trustBox: _class_private_field_get(this, _trustBox), - disclaimer: _class_private_field_get(this, _disclaimer), - articleSources: _class_private_field_get(this, _articleSources) + stages: _classPrivateFieldGet(this, _stages), + trustBox: _classPrivateFieldGet(this, _trustBox), + disclaimer: _classPrivateFieldGet(this, _disclaimer), + articleSources: _classPrivateFieldGet(this, _articleSources) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _stages, { + _classPrivateFieldInit(this, _stages, { writable: true, value: [] }); - _class_private_field_init(this, _trustBox, { + _classPrivateFieldInit(this, _trustBox, { writable: true, value: undefined }); - _class_private_field_init(this, _disclaimer, { + _classPrivateFieldInit(this, _disclaimer, { writable: true, value: undefined }); - _class_private_field_init(this, _articleSources, { + _classPrivateFieldInit(this, _articleSources, { writable: true, value: undefined }); @@ -103,26 +88,26 @@ class BodyBuilder extends _abstractBuilders.AbstractBuilder { var _nodes = /*#__PURE__*/ new WeakMap(), _hidden = /*#__PURE__*/ new WeakMap(); class TrustBoxBuilder extends _abstractBuilders.AbstractBuilder { nodes(nodes) { - _class_private_field_set(this, _nodes, nodes.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _nodes, nodes.map(_builderUtils.mapBuildArg)); return this; } hidden(hidden) { - _class_private_field_set(this, _hidden, hidden.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _hidden, hidden.map(_builderUtils.mapBuildArg)); return this; } build() { return { - nodes: _class_private_field_get(this, _nodes), - hidden: _class_private_field_get(this, _hidden) + nodes: _classPrivateFieldGet(this, _nodes), + hidden: _classPrivateFieldGet(this, _hidden) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _nodes, { + _classPrivateFieldInit(this, _nodes, { writable: true, value: [] }); - _class_private_field_init(this, _hidden, { + _classPrivateFieldInit(this, _hidden, { writable: true, value: [] }); @@ -131,64 +116,64 @@ class TrustBoxBuilder extends _abstractBuilders.AbstractBuilder { var _element = /*#__PURE__*/ new WeakMap(); class OpenerBuilder extends _abstractBuilders.AbstractBuilder { element(element) { - _class_private_field_set(this, _element, (0, _builderUtils).mapBuildArg(element)); + _classPrivateFieldSet(this, _element, (0, _builderUtils.mapBuildArg)(element)); return this; } build() { return { - element: _class_private_field_get(this, _element) + element: _classPrivateFieldGet(this, _element) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _element, { + _classPrivateFieldInit(this, _element, { writable: true, - value: (0, _elementBuilder).image().build() + value: (0, _elementBuilder.image)().build() }); } } var _nodes1 = /*#__PURE__*/ new WeakMap(), _header = /*#__PURE__*/ new WeakMap(), _companions = /*#__PURE__*/ new WeakMap(), _commercialsEndOfStage = /*#__PURE__*/ new WeakMap(); class BodyStageSeqBuilder extends _abstractBuilders.AbstractSeqBuilder { nodes(nodes) { - _class_private_field_set(this, _nodes1, nodes.map(_builderUtils.mapBuildArgs)); + _classPrivateFieldSet(this, _nodes1, nodes.map(_builderUtils.mapBuildArgs)); return this; } header(header) { - _class_private_field_set(this, _header, (0, _builderUtils).mapBuildArgs(header ?? [])); + _classPrivateFieldSet(this, _header, (0, _builderUtils.mapBuildArgs)(header ?? [])); return this; } companions(companions) { - _class_private_field_set(this, _companions, companions.map(_builderUtils.mapBuildArgs)); + _classPrivateFieldSet(this, _companions, companions.map(_builderUtils.mapBuildArgs)); return this; } commercialsEndOfStage(commercialsEndOfStage) { - _class_private_field_set(this, _commercialsEndOfStage, commercialsEndOfStage.map(_builderUtils.mapBuildArgs)); + _classPrivateFieldSet(this, _commercialsEndOfStage, commercialsEndOfStage.map(_builderUtils.mapBuildArgs)); return this; } buildListItem(seqNextElement) { return { - id: (0, _builderUtils).hash("bodyStage", _class_private_field_get(this, _nodes1), _class_private_field_get(this, _companions), _class_private_field_get(this, _commercialsEndOfStage), _class_private_field_get(this, _header)), - nodes: seqNextElement.array(_class_private_field_get(this, _nodes1)), - header: seqNextElement.maybe(_class_private_field_get(this, _header)), - companions: seqNextElement.array(_class_private_field_get(this, _companions)), - commercialsEndOfStage: seqNextElement.array(_class_private_field_get(this, _commercialsEndOfStage)) + id: (0, _builderUtils.hash)("bodyStage", _classPrivateFieldGet(this, _nodes1), _classPrivateFieldGet(this, _companions), _classPrivateFieldGet(this, _commercialsEndOfStage), _classPrivateFieldGet(this, _header)), + nodes: seqNextElement.array(_classPrivateFieldGet(this, _nodes1)), + header: seqNextElement.maybe(_classPrivateFieldGet(this, _header)), + companions: seqNextElement.array(_classPrivateFieldGet(this, _companions)), + commercialsEndOfStage: seqNextElement.array(_classPrivateFieldGet(this, _commercialsEndOfStage)) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _nodes1, { + _classPrivateFieldInit(this, _nodes1, { writable: true, value: [] }); - _class_private_field_init(this, _header, { + _classPrivateFieldInit(this, _header, { writable: true, value: undefined }); - _class_private_field_init(this, _companions, { + _classPrivateFieldInit(this, _companions, { writable: true, value: [] }); - _class_private_field_init(this, _commercialsEndOfStage, { + _classPrivateFieldInit(this, _commercialsEndOfStage, { writable: true, value: [] }); @@ -197,37 +182,37 @@ class BodyStageSeqBuilder extends _abstractBuilders.AbstractSeqBuilder { var _seqBuilder = /*#__PURE__*/ new WeakMap(); class BodyStageBuilder extends _abstractBuilders.AbstractBuilder { nodes(nodes) { - _class_private_field_get(this, _seqBuilder).nodes([ + _classPrivateFieldGet(this, _seqBuilder).nodes([ nodes ]); return this; } header(header) { if (header) { - _class_private_field_get(this, _seqBuilder).header([ + _classPrivateFieldGet(this, _seqBuilder).header([ header ]); } return this; } companions(companions) { - _class_private_field_get(this, _seqBuilder).companions([ + _classPrivateFieldGet(this, _seqBuilder).companions([ companions ]); return this; } commercialsEndOfStage(commercialsEndOfStage) { - _class_private_field_get(this, _seqBuilder).commercialsEndOfStage([ + _classPrivateFieldGet(this, _seqBuilder).commercialsEndOfStage([ commercialsEndOfStage ]); return this; } build() { - return _class_private_field_get(this, _seqBuilder).build(); + return _classPrivateFieldGet(this, _seqBuilder).build(); } constructor(...args){ super(...args); - _class_private_field_init(this, _seqBuilder, { + _classPrivateFieldInit(this, _seqBuilder, { writable: true, value: new BodyStageSeqBuilder() }); @@ -236,26 +221,26 @@ class BodyStageBuilder extends _abstractBuilders.AbstractBuilder { var _variant = /*#__PURE__*/ new WeakMap(), _opener = /*#__PURE__*/ new WeakMap(); class BodyHeaderBuilder extends _abstractBuilders.AbstractBuilder { variant(variant) { - _class_private_field_set(this, _variant, variant); + _classPrivateFieldSet(this, _variant, variant); return this; } opener(opener) { - _class_private_field_set(this, _opener, (0, _builderUtils).mapBuildArg(opener)); + _classPrivateFieldSet(this, _opener, (0, _builderUtils.mapBuildArg)(opener)); return this; } build() { return { - variant: _class_private_field_get(this, _variant), - opener: _class_private_field_get(this, _opener) + variant: _classPrivateFieldGet(this, _variant), + opener: _classPrivateFieldGet(this, _opener) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _variant, { + _classPrivateFieldInit(this, _variant, { writable: true, value: "full" }); - _class_private_field_init(this, _opener, { + _classPrivateFieldInit(this, _opener, { writable: true, value: undefined }); @@ -264,19 +249,19 @@ class BodyHeaderBuilder extends _abstractBuilders.AbstractBuilder { var _nodes2 = /*#__PURE__*/ new WeakMap(); class ArticleSourceSeqBuilder extends _abstractBuilders.AbstractSeqBuilder { nodes(nodes) { - _class_private_field_set(this, _nodes2, nodes.map(_builderUtils.mapBuildArgs)); + _classPrivateFieldSet(this, _nodes2, nodes.map(_builderUtils.mapBuildArgs)); return this; } buildListItem(seqNextElement) { - const id = (0, _builderUtils).hash("article-source", _class_private_field_get(this, _nodes2)); + const id = (0, _builderUtils.hash)("article-source", _classPrivateFieldGet(this, _nodes2)); return { id, - nodes: seqNextElement.array(_class_private_field_get(this, _nodes2)) + nodes: seqNextElement.array(_classPrivateFieldGet(this, _nodes2)) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _nodes2, { + _classPrivateFieldInit(this, _nodes2, { writable: true, value: [] }); @@ -285,17 +270,17 @@ class ArticleSourceSeqBuilder extends _abstractBuilders.AbstractSeqBuilder { var _seqBuilder1 = /*#__PURE__*/ new WeakMap(); class ArticleSourceBuilder extends _abstractBuilders.AbstractBuilder { nodes(...nodes) { - _class_private_field_get(this, _seqBuilder1).nodes([ + _classPrivateFieldGet(this, _seqBuilder1).nodes([ nodes ]); return this; } build() { - return _class_private_field_get(this, _seqBuilder1).build(); + return _classPrivateFieldGet(this, _seqBuilder1).build(); } constructor(...nodes){ super(); - _class_private_field_init(this, _seqBuilder1, { + _classPrivateFieldInit(this, _seqBuilder1, { writable: true, value: new ArticleSourceSeqBuilder() }); @@ -305,31 +290,30 @@ class ArticleSourceBuilder extends _abstractBuilders.AbstractBuilder { var _nodes3 = /*#__PURE__*/ new WeakMap(), _hidden1 = /*#__PURE__*/ new WeakMap(); class ArticleSourcesBuilder extends _abstractBuilders.AbstractBuilder { nodes(...nodes) { - _class_private_field_set(this, _nodes3, nodes.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _nodes3, nodes.map(_builderUtils.mapBuildArg)); return this; } hidden(...hidden) { - _class_private_field_set(this, _hidden1, hidden.map(_builderUtils.mapBuildArg)); + _classPrivateFieldSet(this, _hidden1, hidden.map(_builderUtils.mapBuildArg)); return this; } build() { return { - nodes: _class_private_field_get(this, _nodes3), - hidden: _class_private_field_get(this, _hidden1) + nodes: _classPrivateFieldGet(this, _nodes3), + hidden: _classPrivateFieldGet(this, _hidden1) }; } constructor(...args){ super(...args); - _class_private_field_init(this, _nodes3, { + _classPrivateFieldInit(this, _nodes3, { writable: true, value: [] }); - _class_private_field_init(this, _hidden1, { + _classPrivateFieldInit(this, _hidden1, { writable: true, value: [] }); } } -exports.node = _node; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL2lucHV0L2luZGV4LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IEFic3RyYWN0QnVpbGRlciwgQWJzdHJhY3RTZXFCdWlsZGVyIH0gZnJvbSBcIi4vQWJzdHJhY3RCdWlsZGVyc1wiO1xuaW1wb3J0IHsgaGFzaCwgbWFwQnVpbGRBcmcsIG1hcEJ1aWxkQXJncyB9IGZyb20gXCIuL0J1aWxkZXIudXRpbHNcIjtcbmltcG9ydCB7IGltYWdlIH0gZnJvbSBcIi4vRWxlbWVudEJ1aWxkZXJcIjtcblxuaW1wb3J0IHR5cGUge1xuICAgIEJvZHksXG4gICAgQm9keVN0YWdlLFxuICAgIFRydXN0Qm94LFxuICAgIFJpY2hUZXh0LFxuICAgIE9wZW5lcixcbiAgICBCb2R5SGVhZGVyLFxuICAgIFN0YWdlLFxuICAgIEFydGljbGVTb3VyY2UsXG4gICAgQXJ0aWNsZVNvdXJjZXMsXG59IGZyb20gXCJAcGFwZXIvbW9kZWxzXCI7XG5pbXBvcnQgdHlwZSB7XG4gICAgQnVpbGRBcmcsXG4gICAgQnVpbGRBcmdzLFxuICAgIENyZWF0ZUJ1aWxkZXIsXG4gICAgU2VxRWxlbWVudCxcbiAgICBTZXFOZXh0RWxlbWVudENvbnZlcnRlcixcbn0gZnJvbSBcIi4vdHlwZXNcIjtcblxuLyoqXG4gKiBAZGVwcmVjYXRlZCB1c2Uge0J1aWxkZXIuYm9keS5ub2RlLmltZygpfVxuICovXG5leHBvcnQgKiBmcm9tIFwiLi9Cb2R5Tm9kZXNCdWlsZGVyXCI7XG5leHBvcnQgKiBhcyBub2RlIGZyb20gXCIuL0JvZHlOb2Rlc0J1aWxkZXJcIjtcblxuZXhwb3J0IGNvbnN0IGNyZWF0ZTogQ3JlYXRlQnVpbGRlcjxCb2R5QnVpbGRlcj4gPSAoKSA9PiBuZXcgQm9keUJ1aWxkZXIoKTtcbmV4cG9ydCBjb25zdCB0cnVzdEJveDogQ3JlYXRlQnVpbGRlcjxUcnVzdEJveEJ1aWxkZXI+ID0gKCkgPT5cbiAgICBuZXcgVHJ1c3RCb3hCdWlsZGVyKCk7XG5leHBvcnQgY29uc3Qgb3BlbmVyOiBDcmVhdGVCdWlsZGVyPE9wZW5lckJ1aWxkZXI+ID0gKCkgPT4gbmV3IE9wZW5lckJ1aWxkZXIoKTtcbmV4cG9ydCBjb25zdCBzdGFnZTogQ3JlYXRlQnVpbGRlcjxCb2R5U3RhZ2VCdWlsZGVyPiA9ICgpID0+XG4gICAgbmV3IEJvZHlTdGFnZUJ1aWxkZXIoKTtcbmV4cG9ydCBjb25zdCBoZWFkZXI6IENyZWF0ZUJ1aWxkZXI8Qm9keUhlYWRlckJ1aWxkZXI+ID0gKCkgPT5cbiAgICBuZXcgQm9keUhlYWRlckJ1aWxkZXIoKTtcbmV4cG9ydCBjb25zdCBzb3VyY2U6IENyZWF0ZUJ1aWxkZXI8XG4gICAgQXJ0aWNsZVNvdXJjZUJ1aWxkZXIsXG4gICAgQnVpbGRBcmdzPFJpY2hUZXh0Lk5vZGU+XG4+ID0gKG5vZGVzOiBCdWlsZEFyZ3M8UmljaFRleHQuTm9kZT4gPSBbXSkgPT5cbiAgICBuZXcgQXJ0aWNsZVNvdXJjZUJ1aWxkZXIoLi4ubm9kZXMpO1xuZXhwb3J0IGNvbnN0IHNvdXJjZXM6IENyZWF0ZUJ1aWxkZXI8QXJ0aWNsZVNvdXJjZXNCdWlsZGVyPiA9ICgpID0+XG4gICAgbmV3IEFydGljbGVTb3VyY2VzQnVpbGRlcigpO1xuXG5leHBvcnQgY29uc3Qgc2VxID0ge1xuICAgIHN0YWdlOiAoKCkgPT5cbiAgICAgICAgbmV3IEJvZHlTdGFnZVNlcUJ1aWxkZXIoKSkgYXMgQ3JlYXRlQnVpbGRlcjxCb2R5U3RhZ2VTZXFCdWlsZGVyPixcbiAgICBzb3VyY2U6ICgoKSA9PlxuICAgICAgICBuZXcgQXJ0aWNsZVNvdXJjZVNlcUJ1aWxkZXIoKSkgYXMgQ3JlYXRlQnVpbGRlcjxBcnRpY2xlU291cmNlU2VxQnVpbGRlcj4sXG59IGFzIGNvbnN0O1xuXG5jbGFzcyBCb2R5QnVpbGRlciBleHRlbmRzIEFic3RyYWN0QnVpbGRlcjxCb2R5PiB7XG4gICAgI3N0YWdlczogQm9keVN0YWdlW10gPSBbXTtcbiAgICAjdHJ1c3RCb3g/OiBUcnVzdEJveCA9IHVuZGVmaW5lZDtcbiAgICAjZGlzY2xhaW1lcj86IFJpY2hUZXh0Lk5vZGVbXSA9IHVuZGVmaW5lZDtcbiAgICAjYXJ0aWNsZVNvdXJjZXM/OiBBcnRpY2xlU291cmNlcyA9IHVuZGVmaW5lZDtcblxuICAgIHN0YWdlcyguLi5zdGFnZXM6IEJ1aWxkQXJnczxCb2R5U3RhZ2U+KTogdGhpcyB7XG4gICAgICAgIHRoaXMuI3N0YWdlcyA9IHN0YWdlcy5tYXAobWFwQnVpbGRBcmcpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICB0cnVzdEJveCh0cnVzdEJveD86IEJ1aWxkQXJnPFRydXN0Qm94Pik6IHRoaXMge1xuICAgICAgICB0aGlzLiN0cnVzdEJveCA9IG1hcEJ1aWxkQXJnKHRydXN0Qm94KTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgZGlzY2xhaW1lcihkaXNjbGFpbWVyPzogQnVpbGRBcmdzPFJpY2hUZXh0Lk5vZGU+KTogdGhpcyB7XG4gICAgICAgIHRoaXMuI2Rpc2NsYWltZXIgPSBkaXNjbGFpbWVyPy5tYXAobWFwQnVpbGRBcmcpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBhcnRpY2xlU291cmNlcyhhcnRpY2xlU291cmNlcz86IEJ1aWxkQXJnPEFydGljbGVTb3VyY2VzPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNhcnRpY2xlU291cmNlcyA9IG1hcEJ1aWxkQXJnKGFydGljbGVTb3VyY2VzKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGQoKTogQm9keSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBzdGFnZXM6IHRoaXMuI3N0YWdlcyxcbiAgICAgICAgICAgIHRydXN0Qm94OiB0aGlzLiN0cnVzdEJveCxcbiAgICAgICAgICAgIGRpc2NsYWltZXI6IHRoaXMuI2Rpc2NsYWltZXIsXG4gICAgICAgICAgICBhcnRpY2xlU291cmNlczogdGhpcy4jYXJ0aWNsZVNvdXJjZXMsXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBUcnVzdEJveEJ1aWxkZXIgZXh0ZW5kcyBBYnN0cmFjdEJ1aWxkZXI8VHJ1c3RCb3g+IHtcbiAgICAjbm9kZXM6IFJpY2hUZXh0Lk5vZGVbXSA9IFtdO1xuICAgICNoaWRkZW46IFJpY2hUZXh0Lk5vZGVbXSA9IFtdO1xuXG4gICAgbm9kZXMobm9kZXM6IEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNub2RlcyA9IG5vZGVzLm1hcChtYXBCdWlsZEFyZyk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGhpZGRlbihoaWRkZW46IEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNoaWRkZW4gPSBoaWRkZW4ubWFwKG1hcEJ1aWxkQXJnKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGQoKTogVHJ1c3RCb3gge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgbm9kZXM6IHRoaXMuI25vZGVzLFxuICAgICAgICAgICAgaGlkZGVuOiB0aGlzLiNoaWRkZW4sXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBPcGVuZXJCdWlsZGVyIGV4dGVuZHMgQWJzdHJhY3RCdWlsZGVyPE9wZW5lcj4ge1xuICAgICNlbGVtZW50OiBPcGVuZXJbXCJlbGVtZW50XCJdID0gaW1hZ2UoKS5idWlsZCgpO1xuXG4gICAgZWxlbWVudChlbGVtZW50OiBCdWlsZEFyZzxPcGVuZXJbXCJlbGVtZW50XCJdPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNlbGVtZW50ID0gbWFwQnVpbGRBcmcoZWxlbWVudCk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkKCk6IE9wZW5lciB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBlbGVtZW50OiB0aGlzLiNlbGVtZW50LFxuICAgICAgICB9O1xuICAgIH1cbn1cblxuY2xhc3MgQm9keVN0YWdlU2VxQnVpbGRlciBleHRlbmRzIEFic3RyYWN0U2VxQnVpbGRlcjxCb2R5U3RhZ2U+IHtcbiAgICAjbm9kZXM6IFNlcUVsZW1lbnQ8UmljaFRleHQuTm9kZVtdPiA9IFtdO1xuICAgICNoZWFkZXI/OiBTZXFFbGVtZW50PEJvZHlIZWFkZXI+ID0gdW5kZWZpbmVkO1xuICAgICNjb21wYW5pb25zOiBTZXFFbGVtZW50PFN0YWdlLkNvbXBhbmlvbkl0ZW1bXT4gPSBbXTtcbiAgICAjY29tbWVyY2lhbHNFbmRPZlN0YWdlOiBTZXFFbGVtZW50PFJpY2hUZXh0Lk5vZGVbXT4gPSBbXTtcblxuICAgIG5vZGVzKG5vZGVzOiBTZXFFbGVtZW50PEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPj4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jbm9kZXMgPSBub2Rlcy5tYXAobWFwQnVpbGRBcmdzKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgaGVhZGVyKGhlYWRlcj86IFNlcUVsZW1lbnQ8QnVpbGRBcmc8Qm9keUhlYWRlcj4+KTogdGhpcyB7XG4gICAgICAgIHRoaXMuI2hlYWRlciA9IG1hcEJ1aWxkQXJncyhoZWFkZXIgPz8gW10pO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBjb21wYW5pb25zKGNvbXBhbmlvbnM6IFNlcUVsZW1lbnQ8QnVpbGRBcmdzPFN0YWdlLkNvbXBhbmlvbkl0ZW0+Pik6IHRoaXMge1xuICAgICAgICB0aGlzLiNjb21wYW5pb25zID0gY29tcGFuaW9ucy5tYXAobWFwQnVpbGRBcmdzKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgY29tbWVyY2lhbHNFbmRPZlN0YWdlKFxuICAgICAgICBjb21tZXJjaWFsc0VuZE9mU3RhZ2U6IFNlcUVsZW1lbnQ8QnVpbGRBcmdzPFJpY2hUZXh0Lk5vZGU+PlxuICAgICk6IHRoaXMge1xuICAgICAgICB0aGlzLiNjb21tZXJjaWFsc0VuZE9mU3RhZ2UgPSBjb21tZXJjaWFsc0VuZE9mU3RhZ2UubWFwKG1hcEJ1aWxkQXJncyk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkTGlzdEl0ZW0oc2VxTmV4dEVsZW1lbnQ6IFNlcU5leHRFbGVtZW50Q29udmVydGVyKTogQm9keVN0YWdlIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIGlkOiBoYXNoKFxuICAgICAgICAgICAgICAgIFwiYm9keVN0YWdlXCIsXG4gICAgICAgICAgICAgICAgdGhpcy4jbm9kZXMsXG4gICAgICAgICAgICAgICAgdGhpcy4jY29tcGFuaW9ucyxcbiAgICAgICAgICAgICAgICB0aGlzLiNjb21tZXJjaWFsc0VuZE9mU3RhZ2UsXG4gICAgICAgICAgICAgICAgdGhpcy4jaGVhZGVyXG4gICAgICAgICAgICApLFxuICAgICAgICAgICAgbm9kZXM6IHNlcU5leHRFbGVtZW50LmFycmF5KHRoaXMuI25vZGVzKSxcbiAgICAgICAgICAgIGhlYWRlcjogc2VxTmV4dEVsZW1lbnQubWF5YmUodGhpcy4jaGVhZGVyKSxcbiAgICAgICAgICAgIGNvbXBhbmlvbnM6IHNlcU5leHRFbGVtZW50LmFycmF5KHRoaXMuI2NvbXBhbmlvbnMpLFxuICAgICAgICAgICAgY29tbWVyY2lhbHNFbmRPZlN0YWdlOiBzZXFOZXh0RWxlbWVudC5hcnJheShcbiAgICAgICAgICAgICAgICB0aGlzLiNjb21tZXJjaWFsc0VuZE9mU3RhZ2VcbiAgICAgICAgICAgICksXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBCb2R5U3RhZ2VCdWlsZGVyIGV4dGVuZHMgQWJzdHJhY3RCdWlsZGVyPEJvZHlTdGFnZT4ge1xuICAgICNzZXFCdWlsZGVyOiBCb2R5U3RhZ2VTZXFCdWlsZGVyID0gbmV3IEJvZHlTdGFnZVNlcUJ1aWxkZXIoKTtcblxuICAgIG5vZGVzKG5vZGVzOiBCdWlsZEFyZ3M8UmljaFRleHQuTm9kZT4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jc2VxQnVpbGRlci5ub2Rlcyhbbm9kZXNdKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgaGVhZGVyKGhlYWRlcj86IEJ1aWxkQXJnPEJvZHlIZWFkZXI+KTogdGhpcyB7XG4gICAgICAgIGlmIChoZWFkZXIpIHtcbiAgICAgICAgICAgIHRoaXMuI3NlcUJ1aWxkZXIuaGVhZGVyKFtoZWFkZXJdKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBjb21wYW5pb25zKGNvbXBhbmlvbnM6IEJ1aWxkQXJnczxTdGFnZS5Db21wYW5pb25JdGVtPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNzZXFCdWlsZGVyLmNvbXBhbmlvbnMoW2NvbXBhbmlvbnNdKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgY29tbWVyY2lhbHNFbmRPZlN0YWdlKFxuICAgICAgICBjb21tZXJjaWFsc0VuZE9mU3RhZ2U6IEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPlxuICAgICk6IHRoaXMge1xuICAgICAgICB0aGlzLiNzZXFCdWlsZGVyLmNvbW1lcmNpYWxzRW5kT2ZTdGFnZShbY29tbWVyY2lhbHNFbmRPZlN0YWdlXSk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkKCk6IEJvZHlTdGFnZSB7XG4gICAgICAgIHJldHVybiB0aGlzLiNzZXFCdWlsZGVyLmJ1aWxkKCk7XG4gICAgfVxufVxuXG5jbGFzcyBCb2R5SGVhZGVyQnVpbGRlciBleHRlbmRzIEFic3RyYWN0QnVpbGRlcjxCb2R5SGVhZGVyPiB7XG4gICAgI3ZhcmlhbnQ6IEJvZHlIZWFkZXJbXCJ2YXJpYW50XCJdID0gXCJmdWxsXCI7XG4gICAgI29wZW5lcj86IE9wZW5lciA9IHVuZGVmaW5lZDtcblxuICAgIHZhcmlhbnQodmFyaWFudDogQm9keUhlYWRlcltcInZhcmlhbnRcIl0pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jdmFyaWFudCA9IHZhcmlhbnQ7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIG9wZW5lcihvcGVuZXI6IEJ1aWxkQXJnPE9wZW5lcj4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jb3BlbmVyID0gbWFwQnVpbGRBcmcob3BlbmVyKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGQoKTogQm9keUhlYWRlciB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICB2YXJpYW50OiB0aGlzLiN2YXJpYW50LFxuICAgICAgICAgICAgb3BlbmVyOiB0aGlzLiNvcGVuZXIsXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBBcnRpY2xlU291cmNlU2VxQnVpbGRlciBleHRlbmRzIEFic3RyYWN0U2VxQnVpbGRlcjxBcnRpY2xlU291cmNlPiB7XG4gICAgI25vZGVzOiBTZXFFbGVtZW50PFJpY2hUZXh0Lk5vZGVbXT4gPSBbXTtcblxuICAgIG5vZGVzKG5vZGVzOiBTZXFFbGVtZW50PEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPj4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jbm9kZXMgPSBub2Rlcy5tYXAobWFwQnVpbGRBcmdzKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGRMaXN0SXRlbShzZXFOZXh0RWxlbWVudDogU2VxTmV4dEVsZW1lbnRDb252ZXJ0ZXIpOiBBcnRpY2xlU291cmNlIHtcbiAgICAgICAgY29uc3QgaWQgPSBoYXNoKFwiYXJ0aWNsZS1zb3VyY2VcIiwgdGhpcy4jbm9kZXMpO1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgaWQsXG4gICAgICAgICAgICBub2Rlczogc2VxTmV4dEVsZW1lbnQuYXJyYXkodGhpcy4jbm9kZXMpLFxuICAgICAgICB9O1xuICAgIH1cbn1cblxuY2xhc3MgQXJ0aWNsZVNvdXJjZUJ1aWxkZXIgZXh0ZW5kcyBBYnN0cmFjdEJ1aWxkZXI8QXJ0aWNsZVNvdXJjZT4ge1xuICAgICNzZXFCdWlsZGVyOiBBcnRpY2xlU291cmNlU2VxQnVpbGRlciA9IG5ldyBBcnRpY2xlU291cmNlU2VxQnVpbGRlcigpO1xuXG4gICAgY29uc3RydWN0b3IoLi4ubm9kZXM6IEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPikge1xuICAgICAgICBzdXBlcigpO1xuICAgICAgICB0aGlzLm5vZGVzKC4uLm5vZGVzKTtcbiAgICB9XG5cbiAgICBub2RlcyguLi5ub2RlczogQnVpbGRBcmdzPFJpY2hUZXh0Lk5vZGU+KTogdGhpcyB7XG4gICAgICAgIHRoaXMuI3NlcUJ1aWxkZXIubm9kZXMoW25vZGVzXSk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkKCk6IEFydGljbGVTb3VyY2Uge1xuICAgICAgICByZXR1cm4gdGhpcy4jc2VxQnVpbGRlci5idWlsZCgpO1xuICAgIH1cbn1cblxuY2xhc3MgQXJ0aWNsZVNvdXJjZXNCdWlsZGVyIGV4dGVuZHMgQWJzdHJhY3RCdWlsZGVyPEFydGljbGVTb3VyY2VzPiB7XG4gICAgI25vZGVzOiBBcnRpY2xlU291cmNlW10gPSBbXTtcbiAgICAjaGlkZGVuOiBBcnRpY2xlU291cmNlW10gPSBbXTtcblxuICAgIG5vZGVzKC4uLm5vZGVzOiBCdWlsZEFyZ3M8QXJ0aWNsZVNvdXJjZT4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jbm9kZXMgPSBub2Rlcy5tYXAobWFwQnVpbGRBcmcpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBoaWRkZW4oLi4uaGlkZGVuOiBCdWlsZEFyZ3M8QXJ0aWNsZVNvdXJjZT4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jaGlkZGVuID0gaGlkZGVuLm1hcChtYXBCdWlsZEFyZyk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkKCk6IEFydGljbGVTb3VyY2VzIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIG5vZGVzOiB0aGlzLiNub2RlcyxcbiAgICAgICAgICAgIGhpZGRlbjogdGhpcy4jaGlkZGVuLFxuICAgICAgICB9O1xuICAgIH1cbn1cbiJdLCJuYW1lcyI6WyJub2RlIiwiY3JlYXRlIiwiQm9keUJ1aWxkZXIiLCJ0cnVzdEJveCIsIlRydXN0Qm94QnVpbGRlciIsIm9wZW5lciIsIk9wZW5lckJ1aWxkZXIiLCJzdGFnZSIsIkJvZHlTdGFnZUJ1aWxkZXIiLCJoZWFkZXIiLCJCb2R5SGVhZGVyQnVpbGRlciIsInNvdXJjZSIsIm5vZGVzIiwiQXJ0aWNsZVNvdXJjZUJ1aWxkZXIiLCJzb3VyY2VzIiwiQXJ0aWNsZVNvdXJjZXNCdWlsZGVyIiwic2VxIiwiQm9keVN0YWdlU2VxQnVpbGRlciIsIkFydGljbGVTb3VyY2VTZXFCdWlsZGVyIiwiQWJzdHJhY3RCdWlsZGVyIiwic3RhZ2VzIiwibWFwIiwibWFwQnVpbGRBcmciLCJkaXNjbGFpbWVyIiwiYXJ0aWNsZVNvdXJjZXMiLCJidWlsZCIsInVuZGVmaW5lZCIsImhpZGRlbiIsImVsZW1lbnQiLCJpbWFnZSIsIkFic3RyYWN0U2VxQnVpbGRlciIsIm1hcEJ1aWxkQXJncyIsImNvbXBhbmlvbnMiLCJjb21tZXJjaWFsc0VuZE9mU3RhZ2UiLCJidWlsZExpc3RJdGVtIiwic2VxTmV4dEVsZW1lbnQiLCJpZCIsImhhc2giLCJhcnJheSIsIm1heWJlIiwic2VxQnVpbGRlciIsInZhcmlhbnQiLCJjb25zdHJ1Y3RvciJdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQW9ELElBQUEsaUJBQW9CLFdBQXBCLG9CQUFvQixDQUFBO0FBQ3hCLElBQUEsYUFBaUIsV0FBakIsaUJBQWlCLENBQUE7QUFDM0MsSUFBQSxlQUFrQixXQUFsQixrQkFBa0IsQ0FBQTtBQXlCNUJBLElBQUFBLEtBQUkscUNBQU0sb0JBQW9CLEVBQTFCO0FBSmhCOztHQUVHLENBQ0gsWUFBQSxLQUFtQzs7OzJDQUFuQyxLQUFtQzs7OzttQkFBbkMsS0FBbUM7OztFQUFBO0FBRzVCLE1BQU1DLE1BQU0sR0FBK0IsSUFBTSxJQUFJQyxXQUFXLEVBQUUsQUFBQztRQUE3REQsTUFBTSxHQUFOQSxNQUFNO0FBQ1osTUFBTUUsUUFBUSxHQUFtQyxJQUNwRCxJQUFJQyxlQUFlLEVBQUUsQUFBQztRQURiRCxRQUFRLEdBQVJBLFFBQVE7QUFFZCxNQUFNRSxNQUFNLEdBQWlDLElBQU0sSUFBSUMsYUFBYSxFQUFFLEFBQUM7UUFBakVELE1BQU0sR0FBTkEsTUFBTTtBQUNaLE1BQU1FLEtBQUssR0FBb0MsSUFDbEQsSUFBSUMsZ0JBQWdCLEVBQUUsQUFBQztRQURkRCxLQUFLLEdBQUxBLEtBQUs7QUFFWCxNQUFNRSxNQUFNLEdBQXFDLElBQ3BELElBQUlDLGlCQUFpQixFQUFFLEFBQUM7UUFEZkQsTUFBTSxHQUFOQSxNQUFNO0FBRVosTUFBTUUsTUFBTSxHQUdmLENBQUNDLEtBQStCLEdBQUcsRUFBRSxHQUNyQyxJQUFJQyxvQkFBb0IsSUFBSUQsS0FBSyxDQUFDLEFBQUM7UUFKMUJELE1BQU0sR0FBTkEsTUFBTTtBQUtaLE1BQU1HLE9BQU8sR0FBeUMsSUFDekQsSUFBSUMscUJBQXFCLEVBQUUsQUFBQztRQURuQkQsT0FBTyxHQUFQQSxPQUFPO0FBR2IsTUFBTUUsR0FBRyxHQUFHO0lBQ2ZULEtBQUssRUFBRyxJQUNKLElBQUlVLG1CQUFtQixFQUFFO0lBQzdCTixNQUFNLEVBQUcsSUFDTCxJQUFJTyx1QkFBdUIsRUFBRTtDQUNwQyxBQUFTLEFBQUM7UUFMRUYsR0FBRyxHQUFIQSxHQUFHO0lBUVosT0FBTyxnQ0FDUCxTQUFTLGdDQUNULFdBQVcsZ0NBQ1gsZUFBZTtBQUpuQixNQUFNZCxXQUFXLFNBQVNpQixpQkFBZSxnQkFBQTtJQU1yQ0MsTUFBTSxDQUFDLEdBQUdBLE1BQU0sQUFBc0IsRUFBUTt1Q0FDcENBLE9BQU0sRUFBR0EsTUFBTSxDQUFDQyxHQUFHLENBQUNDLGFBQVcsWUFBQSxDQUFDLEVBQUM7UUFDdkMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEbkIsUUFBUSxDQUFDQSxRQUE2QixFQUFRO3VDQUNwQ0EsU0FBUSxFQUFHbUIsQ0FBQUEsR0FBQUEsYUFBVyxBQUFVLENBQUEsWUFBVixDQUFDbkIsUUFBUSxDQUFDLEVBQUM7UUFDdkMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEb0IsVUFBVSxDQUFDQSxVQUFxQyxFQUFRO3VDQUM5Q0EsV0FBVSxFQUFHQSxVQUFVLEVBQUVGLEdBQUcsQ0FBQ0MsYUFBVyxZQUFBLENBQUMsRUFBQztRQUNoRCxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURFLGNBQWMsQ0FBQ0EsY0FBeUMsRUFBUTt1Q0FDdERBLGVBQWMsRUFBR0YsQ0FBQUEsR0FBQUEsYUFBVyxBQUFnQixDQUFBLFlBQWhCLENBQUNFLGNBQWMsQ0FBQyxFQUFDO1FBQ25ELE9BQU8sSUFBSSxDQUFDO0tBQ2Y7SUFFREMsS0FBSyxHQUFTO1FBQ1YsT0FBTztZQUNITCxNQUFNLDJCQUFFLElBQUksRUFBRUEsT0FBTTtZQUNwQmpCLFFBQVEsMkJBQUUsSUFBSSxFQUFFQSxTQUFRO1lBQ3hCb0IsVUFBVSwyQkFBRSxJQUFJLEVBQUVBLFdBQVU7WUFDNUJDLGNBQWMsMkJBQUUsSUFBSSxFQUFFQSxlQUFjO1NBQ3ZDLENBQUM7S0FDTDs7O1FBaENELGdDQUFBLE9BQU87O21CQUFnQixFQUFFO1VBQUMsQ0FBQTtRQUMxQixnQ0FBQSxTQUFTOzttQkFBY0UsU0FBUztVQUFDLENBQUE7UUFDakMsZ0NBQUEsV0FBVzs7bUJBQXFCQSxTQUFTO1VBQUMsQ0FBQTtRQUMxQyxnQ0FBQSxlQUFlOzttQkFBb0JBLFNBQVM7VUFBQyxDQUFBOztDQThCaEQ7SUFHRyxNQUFNLGdDQUNOLE9BQU87QUFGWCxNQUFNdEIsZUFBZSxTQUFTZSxpQkFBZSxnQkFBQTtJQUl6Q1AsS0FBSyxDQUFDQSxLQUErQixFQUFRO3VDQUNuQ0EsTUFBSyxFQUFHQSxLQUFLLENBQUNTLEdBQUcsQ0FBQ0MsYUFBVyxZQUFBLENBQUMsRUFBQztRQUNyQyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURLLE1BQU0sQ0FBQ0EsTUFBZ0MsRUFBUTt1Q0FDckNBLE9BQU0sRUFBR0EsTUFBTSxDQUFDTixHQUFHLENBQUNDLGFBQVcsWUFBQSxDQUFDLEVBQUM7UUFDdkMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVERyxLQUFLLEdBQWE7UUFDZCxPQUFPO1lBQ0hiLEtBQUssMkJBQUUsSUFBSSxFQUFFQSxNQUFLO1lBQ2xCZSxNQUFNLDJCQUFFLElBQUksRUFBRUEsT0FBTTtTQUN2QixDQUFDO0tBQ0w7OztRQWxCRCxnQ0FBQSxNQUFNOzttQkFBb0IsRUFBRTtVQUFDLENBQUE7UUFDN0IsZ0NBQUEsT0FBTzs7bUJBQW9CLEVBQUU7VUFBQyxDQUFBOztDQWtCakM7SUFHRyxRQUFRO0FBRFosTUFBTXJCLGFBQWEsU0FBU2EsaUJBQWUsZ0JBQUE7SUFHdkNTLE9BQU8sQ0FBQ0EsT0FBb0MsRUFBUTt1Q0FDMUNBLFFBQU8sRUFBR04sQ0FBQUEsR0FBQUEsYUFBVyxBQUFTLENBQUEsWUFBVCxDQUFDTSxPQUFPLENBQUMsRUFBQztRQUNyQyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURILEtBQUssR0FBVztRQUNaLE9BQU87WUFDSEcsT0FBTywyQkFBRSxJQUFJLEVBQUVBLFFBQU87U0FDekIsQ0FBQztLQUNMOzs7UUFYRCxnQ0FBQSxRQUFROzttQkFBc0JDLENBQUFBLEdBQUFBLGVBQUssQUFBRSxDQUFBLE1BQUYsRUFBRSxDQUFDSixLQUFLLEVBQUU7VUFBQyxDQUFBOztDQVlqRDtJQUdHLE9BQU0sZ0NBQ04sT0FBTyxnQ0FDUCxXQUFXLGdDQUNYLHNCQUFzQjtBQUoxQixNQUFNUixtQkFBbUIsU0FBU2EsaUJBQWtCLG1CQUFBO0lBTWhEbEIsS0FBSyxDQUFDQSxLQUEyQyxFQUFRO3VDQUMvQ0EsT0FBSyxFQUFHQSxLQUFLLENBQUNTLEdBQUcsQ0FBQ1UsYUFBWSxhQUFBLENBQUMsRUFBQztRQUN0QyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRUR0QixNQUFNLENBQUNBLE1BQXlDLEVBQVE7dUNBQzlDQSxPQUFNLEVBQUdzQixDQUFBQSxHQUFBQSxhQUFZLEFBQWMsQ0FBQSxhQUFkLENBQUN0QixNQUFNLElBQUksRUFBRSxDQUFDLEVBQUM7UUFDMUMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEdUIsVUFBVSxDQUFDQSxVQUFzRCxFQUFRO3VDQUMvREEsV0FBVSxFQUFHQSxVQUFVLENBQUNYLEdBQUcsQ0FBQ1UsYUFBWSxhQUFBLENBQUMsRUFBQztRQUNoRCxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURFLHFCQUFxQixDQUNqQkEscUJBQTJELEVBQ3ZEO3VDQUNFQSxzQkFBcUIsRUFBR0EscUJBQXFCLENBQUNaLEdBQUcsQ0FBQ1UsYUFBWSxhQUFBLENBQUMsRUFBQztRQUN0RSxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURHLGFBQWEsQ0FBQ0MsY0FBdUMsRUFBYTtRQUM5RCxPQUFPO1lBQ0hDLEVBQUUsRUFBRUMsQ0FBQUEsR0FBQUEsYUFBSSxBQU1QLENBQUEsS0FOTyxDQUNKLFdBQVcsMkJBQ1gsSUFBSSxFQUFFekIsT0FBSyw0QkFDWCxJQUFJLEVBQUVvQixXQUFVLDRCQUNoQixJQUFJLEVBQUVDLHNCQUFxQiw0QkFDM0IsSUFBSSxFQUFFeEIsT0FBTSxFQUNmO1lBQ0RHLEtBQUssRUFBRXVCLGNBQWMsQ0FBQ0csS0FBSywwQkFBQyxJQUFJLEVBQUUxQixPQUFLLEVBQUM7WUFDeENILE1BQU0sRUFBRTBCLGNBQWMsQ0FBQ0ksS0FBSywwQkFBQyxJQUFJLEVBQUU5QixPQUFNLEVBQUM7WUFDMUN1QixVQUFVLEVBQUVHLGNBQWMsQ0FBQ0csS0FBSywwQkFBQyxJQUFJLEVBQUVOLFdBQVUsRUFBQztZQUNsREMscUJBQXFCLEVBQUVFLGNBQWMsQ0FBQ0csS0FBSywwQkFDdkMsSUFBSSxFQUFFTCxzQkFBcUIsRUFDOUI7U0FDSixDQUFDO0tBQ0w7OztRQTNDRCxnQ0FBQSxPQUFNOzttQkFBZ0MsRUFBRTtVQUFDLENBQUE7UUFDekMsZ0NBQUEsT0FBTzs7bUJBQTRCUCxTQUFTO1VBQUMsQ0FBQTtRQUM3QyxnQ0FBQSxXQUFXOzttQkFBc0MsRUFBRTtVQUFDLENBQUE7UUFDcEQsZ0NBQUEsc0JBQXNCOzttQkFBZ0MsRUFBRTtVQUFDLENBQUE7O0NBeUM1RDtJQUdHLFdBQVc7QUFEZixNQUFNbEIsZ0JBQWdCLFNBQVNXLGlCQUFlLGdCQUFBO0lBRzFDUCxLQUFLLENBQUNBLEtBQStCLEVBQVE7UUFDekMseUJBQUEsSUFBSSxFQUFFNEIsV0FBVSxFQUFDNUIsS0FBSyxDQUFDO1lBQUNBLEtBQUs7U0FBQyxDQUFDLENBQUM7UUFDaEMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVESCxNQUFNLENBQUNBLE1BQTZCLEVBQVE7UUFDeEMsSUFBSUEsTUFBTSxFQUFFO1lBQ1IseUJBQUEsSUFBSSxFQUFFK0IsV0FBVSxFQUFDL0IsTUFBTSxDQUFDO2dCQUFDQSxNQUFNO2FBQUMsQ0FBQyxDQUFDO1NBQ3JDO1FBQ0QsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEdUIsVUFBVSxDQUFDQSxVQUEwQyxFQUFRO1FBQ3pELHlCQUFBLElBQUksRUFBRVEsV0FBVSxFQUFDUixVQUFVLENBQUM7WUFBQ0EsVUFBVTtTQUFDLENBQUMsQ0FBQztRQUMxQyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURDLHFCQUFxQixDQUNqQkEscUJBQStDLEVBQzNDO1FBQ0oseUJBQUEsSUFBSSxFQUFFTyxXQUFVLEVBQUNQLHFCQUFxQixDQUFDO1lBQUNBLHFCQUFxQjtTQUFDLENBQUMsQ0FBQztRQUNoRSxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURSLEtBQUssR0FBYztRQUNmLE9BQU8seUJBQUEsSUFBSSxFQUFFZSxXQUFVLEVBQUNmLEtBQUssRUFBRSxDQUFDO0tBQ25DOzs7UUE1QkQsZ0NBQUEsV0FBVzs7bUJBQXdCLElBQUlSLG1CQUFtQixFQUFFO1VBQUMsQ0FBQTs7Q0E2QmhFO0lBR0csUUFBUSxnQ0FDUixPQUFPO0FBRlgsTUFBTVAsaUJBQWlCLFNBQVNTLGlCQUFlLGdCQUFBO0lBSTNDc0IsT0FBTyxDQUFDQSxPQUE4QixFQUFRO3VDQUNwQ0EsUUFBTyxFQUFHQSxPQUFPLEVBQUM7UUFDeEIsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEcEMsTUFBTSxDQUFDQSxNQUF3QixFQUFRO3VDQUM3QkEsT0FBTSxFQUFHaUIsQ0FBQUEsR0FBQUEsYUFBVyxBQUFRLENBQUEsWUFBUixDQUFDakIsTUFBTSxDQUFDLEVBQUM7UUFDbkMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEb0IsS0FBSyxHQUFlO1FBQ2hCLE9BQU87WUFDSGdCLE9BQU8sMkJBQUUsSUFBSSxFQUFFQSxRQUFPO1lBQ3RCcEMsTUFBTSwyQkFBRSxJQUFJLEVBQUVBLE9BQU07U0FDdkIsQ0FBQztLQUNMOzs7UUFsQkQsZ0NBQUEsUUFBUTs7bUJBQTBCLE1BQU07VUFBQyxDQUFBO1FBQ3pDLGdDQUFBLE9BQU87O21CQUFZcUIsU0FBUztVQUFDLENBQUE7O0NBa0JoQztJQUdHLE9BQU07QUFEVixNQUFNUix1QkFBdUIsU0FBU1ksaUJBQWtCLG1CQUFBO0lBR3BEbEIsS0FBSyxDQUFDQSxLQUEyQyxFQUFRO3VDQUMvQ0EsT0FBSyxFQUFHQSxLQUFLLENBQUNTLEdBQUcsQ0FBQ1UsYUFBWSxhQUFBLENBQUMsRUFBQztRQUN0QyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURHLGFBQWEsQ0FBQ0MsY0FBdUMsRUFBaUI7UUFDbEUsTUFBTUMsRUFBRSxHQUFHQyxDQUFBQSxHQUFBQSxhQUFJLEFBQStCLENBQUEsS0FBL0IsQ0FBQyxnQkFBZ0IsMkJBQUUsSUFBSSxFQUFFekIsT0FBSyxFQUFDLEFBQUM7UUFDL0MsT0FBTztZQUNId0IsRUFBRTtZQUNGeEIsS0FBSyxFQUFFdUIsY0FBYyxDQUFDRyxLQUFLLDBCQUFDLElBQUksRUFBRTFCLE9BQUssRUFBQztTQUMzQyxDQUFDO0tBQ0w7OztRQWJELGdDQUFBLE9BQU07O21CQUFnQyxFQUFFO1VBQUMsQ0FBQTs7Q0FjNUM7SUFHRyxZQUFXO0FBRGYsTUFBTUMsb0JBQW9CLFNBQVNNLGlCQUFlLGdCQUFBO0lBUTlDUCxLQUFLLENBQUMsR0FBR0EsS0FBSyxBQUEwQixFQUFRO1FBQzVDLHlCQUFBLElBQUksRUFBRTRCLFlBQVUsRUFBQzVCLEtBQUssQ0FBQztZQUFDQSxLQUFLO1NBQUMsQ0FBQyxDQUFDO1FBQ2hDLE9BQU8sSUFBSSxDQUFDO0tBQ2Y7SUFFRGEsS0FBSyxHQUFrQjtRQUNuQixPQUFPLHlCQUFBLElBQUksRUFBRWUsWUFBVSxFQUFDZixLQUFLLEVBQUUsQ0FBQztLQUNuQztJQVpEaUIsWUFBWSxHQUFHOUIsS0FBSyxBQUEwQixDQUFFO1FBQzVDLEtBQUssRUFBRSxDQUFDO1FBSFosZ0NBQUEsWUFBVzs7bUJBQTRCLElBQUlNLHVCQUF1QixFQUFFO1VBQUMsQ0FBQTtRQUlqRSxJQUFJLENBQUNOLEtBQUssSUFBSUEsS0FBSyxDQUFDLENBQUM7S0FDeEI7Q0FVSjtJQUdHLE9BQU0sZ0NBQ04sUUFBTztBQUZYLE1BQU1HLHFCQUFxQixTQUFTSSxpQkFBZSxnQkFBQTtJQUkvQ1AsS0FBSyxDQUFDLEdBQUdBLEtBQUssQUFBMEIsRUFBUTt1Q0FDdENBLE9BQUssRUFBR0EsS0FBSyxDQUFDUyxHQUFHLENBQUNDLGFBQVcsWUFBQSxDQUFDLEVBQUM7UUFDckMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVESyxNQUFNLENBQUMsR0FBR0EsTUFBTSxBQUEwQixFQUFRO3VDQUN4Q0EsUUFBTSxFQUFHQSxNQUFNLENBQUNOLEdBQUcsQ0FBQ0MsYUFBVyxZQUFBLENBQUMsRUFBQztRQUN2QyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURHLEtBQUssR0FBbUI7UUFDcEIsT0FBTztZQUNIYixLQUFLLDJCQUFFLElBQUksRUFBRUEsT0FBSztZQUNsQmUsTUFBTSwyQkFBRSxJQUFJLEVBQUVBLFFBQU07U0FDdkIsQ0FBQztLQUNMOzs7UUFsQkQsZ0NBQUEsT0FBTTs7bUJBQW9CLEVBQUU7VUFBQyxDQUFBO1FBQzdCLGdDQUFBLFFBQU87O21CQUFvQixFQUFFO1VBQUMsQ0FBQTs7Q0FrQmpDO1FBOVBXM0IsSUFBSSxHQUFKQSxLQUFJIn0= +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL2lucHV0L2luZGV4LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IEFic3RyYWN0QnVpbGRlciwgQWJzdHJhY3RTZXFCdWlsZGVyIH0gZnJvbSBcIi4vQWJzdHJhY3RCdWlsZGVyc1wiO1xuaW1wb3J0IHsgaGFzaCwgbWFwQnVpbGRBcmcsIG1hcEJ1aWxkQXJncyB9IGZyb20gXCIuL0J1aWxkZXIudXRpbHNcIjtcbmltcG9ydCB7IGltYWdlIH0gZnJvbSBcIi4vRWxlbWVudEJ1aWxkZXJcIjtcblxuaW1wb3J0IHR5cGUge1xuICAgIEJvZHksXG4gICAgQm9keVN0YWdlLFxuICAgIFRydXN0Qm94LFxuICAgIFJpY2hUZXh0LFxuICAgIE9wZW5lcixcbiAgICBCb2R5SGVhZGVyLFxuICAgIFN0YWdlLFxuICAgIEFydGljbGVTb3VyY2UsXG4gICAgQXJ0aWNsZVNvdXJjZXMsXG59IGZyb20gXCJAcGFwZXIvbW9kZWxzXCI7XG5pbXBvcnQgdHlwZSB7XG4gICAgQnVpbGRBcmcsXG4gICAgQnVpbGRBcmdzLFxuICAgIENyZWF0ZUJ1aWxkZXIsXG4gICAgU2VxRWxlbWVudCxcbiAgICBTZXFOZXh0RWxlbWVudENvbnZlcnRlcixcbn0gZnJvbSBcIi4vdHlwZXNcIjtcblxuLyoqXG4gKiBAZGVwcmVjYXRlZCB1c2Uge0J1aWxkZXIuYm9keS5ub2RlLmltZygpfVxuICovXG5leHBvcnQgKiBmcm9tIFwiLi9Cb2R5Tm9kZXNCdWlsZGVyXCI7XG5leHBvcnQgKiBhcyBub2RlIGZyb20gXCIuL0JvZHlOb2Rlc0J1aWxkZXJcIjtcblxuZXhwb3J0IGNvbnN0IGNyZWF0ZTogQ3JlYXRlQnVpbGRlcjxCb2R5QnVpbGRlcj4gPSAoKSA9PiBuZXcgQm9keUJ1aWxkZXIoKTtcbmV4cG9ydCBjb25zdCB0cnVzdEJveDogQ3JlYXRlQnVpbGRlcjxUcnVzdEJveEJ1aWxkZXI+ID0gKCkgPT5cbiAgICBuZXcgVHJ1c3RCb3hCdWlsZGVyKCk7XG5leHBvcnQgY29uc3Qgb3BlbmVyOiBDcmVhdGVCdWlsZGVyPE9wZW5lckJ1aWxkZXI+ID0gKCkgPT4gbmV3IE9wZW5lckJ1aWxkZXIoKTtcbmV4cG9ydCBjb25zdCBzdGFnZTogQ3JlYXRlQnVpbGRlcjxCb2R5U3RhZ2VCdWlsZGVyPiA9ICgpID0+XG4gICAgbmV3IEJvZHlTdGFnZUJ1aWxkZXIoKTtcbmV4cG9ydCBjb25zdCBoZWFkZXI6IENyZWF0ZUJ1aWxkZXI8Qm9keUhlYWRlckJ1aWxkZXI+ID0gKCkgPT5cbiAgICBuZXcgQm9keUhlYWRlckJ1aWxkZXIoKTtcbmV4cG9ydCBjb25zdCBzb3VyY2U6IENyZWF0ZUJ1aWxkZXI8XG4gICAgQXJ0aWNsZVNvdXJjZUJ1aWxkZXIsXG4gICAgQnVpbGRBcmdzPFJpY2hUZXh0Lk5vZGU+XG4+ID0gKG5vZGVzOiBCdWlsZEFyZ3M8UmljaFRleHQuTm9kZT4gPSBbXSkgPT5cbiAgICBuZXcgQXJ0aWNsZVNvdXJjZUJ1aWxkZXIoLi4ubm9kZXMpO1xuZXhwb3J0IGNvbnN0IHNvdXJjZXM6IENyZWF0ZUJ1aWxkZXI8QXJ0aWNsZVNvdXJjZXNCdWlsZGVyPiA9ICgpID0+XG4gICAgbmV3IEFydGljbGVTb3VyY2VzQnVpbGRlcigpO1xuXG5leHBvcnQgY29uc3Qgc2VxID0ge1xuICAgIHN0YWdlOiAoKCkgPT5cbiAgICAgICAgbmV3IEJvZHlTdGFnZVNlcUJ1aWxkZXIoKSkgYXMgQ3JlYXRlQnVpbGRlcjxCb2R5U3RhZ2VTZXFCdWlsZGVyPixcbiAgICBzb3VyY2U6ICgoKSA9PlxuICAgICAgICBuZXcgQXJ0aWNsZVNvdXJjZVNlcUJ1aWxkZXIoKSkgYXMgQ3JlYXRlQnVpbGRlcjxBcnRpY2xlU291cmNlU2VxQnVpbGRlcj4sXG59IGFzIGNvbnN0O1xuXG5jbGFzcyBCb2R5QnVpbGRlciBleHRlbmRzIEFic3RyYWN0QnVpbGRlcjxCb2R5PiB7XG4gICAgI3N0YWdlczogQm9keVN0YWdlW10gPSBbXTtcbiAgICAjdHJ1c3RCb3g/OiBUcnVzdEJveCA9IHVuZGVmaW5lZDtcbiAgICAjZGlzY2xhaW1lcj86IFJpY2hUZXh0Lk5vZGVbXSA9IHVuZGVmaW5lZDtcbiAgICAjYXJ0aWNsZVNvdXJjZXM/OiBBcnRpY2xlU291cmNlcyA9IHVuZGVmaW5lZDtcblxuICAgIHN0YWdlcyguLi5zdGFnZXM6IEJ1aWxkQXJnczxCb2R5U3RhZ2U+KTogdGhpcyB7XG4gICAgICAgIHRoaXMuI3N0YWdlcyA9IHN0YWdlcy5tYXAobWFwQnVpbGRBcmcpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICB0cnVzdEJveCh0cnVzdEJveD86IEJ1aWxkQXJnPFRydXN0Qm94Pik6IHRoaXMge1xuICAgICAgICB0aGlzLiN0cnVzdEJveCA9IG1hcEJ1aWxkQXJnKHRydXN0Qm94KTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgZGlzY2xhaW1lcihkaXNjbGFpbWVyPzogQnVpbGRBcmdzPFJpY2hUZXh0Lk5vZGU+KTogdGhpcyB7XG4gICAgICAgIHRoaXMuI2Rpc2NsYWltZXIgPSBkaXNjbGFpbWVyPy5tYXAobWFwQnVpbGRBcmcpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBhcnRpY2xlU291cmNlcyhhcnRpY2xlU291cmNlcz86IEJ1aWxkQXJnPEFydGljbGVTb3VyY2VzPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNhcnRpY2xlU291cmNlcyA9IG1hcEJ1aWxkQXJnKGFydGljbGVTb3VyY2VzKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGQoKTogQm9keSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBzdGFnZXM6IHRoaXMuI3N0YWdlcyxcbiAgICAgICAgICAgIHRydXN0Qm94OiB0aGlzLiN0cnVzdEJveCxcbiAgICAgICAgICAgIGRpc2NsYWltZXI6IHRoaXMuI2Rpc2NsYWltZXIsXG4gICAgICAgICAgICBhcnRpY2xlU291cmNlczogdGhpcy4jYXJ0aWNsZVNvdXJjZXMsXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBUcnVzdEJveEJ1aWxkZXIgZXh0ZW5kcyBBYnN0cmFjdEJ1aWxkZXI8VHJ1c3RCb3g+IHtcbiAgICAjbm9kZXM6IFJpY2hUZXh0Lk5vZGVbXSA9IFtdO1xuICAgICNoaWRkZW46IFJpY2hUZXh0Lk5vZGVbXSA9IFtdO1xuXG4gICAgbm9kZXMobm9kZXM6IEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNub2RlcyA9IG5vZGVzLm1hcChtYXBCdWlsZEFyZyk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGhpZGRlbihoaWRkZW46IEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNoaWRkZW4gPSBoaWRkZW4ubWFwKG1hcEJ1aWxkQXJnKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGQoKTogVHJ1c3RCb3gge1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgbm9kZXM6IHRoaXMuI25vZGVzLFxuICAgICAgICAgICAgaGlkZGVuOiB0aGlzLiNoaWRkZW4sXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBPcGVuZXJCdWlsZGVyIGV4dGVuZHMgQWJzdHJhY3RCdWlsZGVyPE9wZW5lcj4ge1xuICAgICNlbGVtZW50OiBPcGVuZXJbXCJlbGVtZW50XCJdID0gaW1hZ2UoKS5idWlsZCgpO1xuXG4gICAgZWxlbWVudChlbGVtZW50OiBCdWlsZEFyZzxPcGVuZXJbXCJlbGVtZW50XCJdPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNlbGVtZW50ID0gbWFwQnVpbGRBcmcoZWxlbWVudCk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkKCk6IE9wZW5lciB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBlbGVtZW50OiB0aGlzLiNlbGVtZW50LFxuICAgICAgICB9O1xuICAgIH1cbn1cblxuY2xhc3MgQm9keVN0YWdlU2VxQnVpbGRlciBleHRlbmRzIEFic3RyYWN0U2VxQnVpbGRlcjxCb2R5U3RhZ2U+IHtcbiAgICAjbm9kZXM6IFNlcUVsZW1lbnQ8UmljaFRleHQuTm9kZVtdPiA9IFtdO1xuICAgICNoZWFkZXI/OiBTZXFFbGVtZW50PEJvZHlIZWFkZXI+ID0gdW5kZWZpbmVkO1xuICAgICNjb21wYW5pb25zOiBTZXFFbGVtZW50PFN0YWdlLkNvbXBhbmlvbkl0ZW1bXT4gPSBbXTtcbiAgICAjY29tbWVyY2lhbHNFbmRPZlN0YWdlOiBTZXFFbGVtZW50PFJpY2hUZXh0Lk5vZGVbXT4gPSBbXTtcblxuICAgIG5vZGVzKG5vZGVzOiBTZXFFbGVtZW50PEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPj4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jbm9kZXMgPSBub2Rlcy5tYXAobWFwQnVpbGRBcmdzKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgaGVhZGVyKGhlYWRlcj86IFNlcUVsZW1lbnQ8QnVpbGRBcmc8Qm9keUhlYWRlcj4+KTogdGhpcyB7XG4gICAgICAgIHRoaXMuI2hlYWRlciA9IG1hcEJ1aWxkQXJncyhoZWFkZXIgPz8gW10pO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBjb21wYW5pb25zKGNvbXBhbmlvbnM6IFNlcUVsZW1lbnQ8QnVpbGRBcmdzPFN0YWdlLkNvbXBhbmlvbkl0ZW0+Pik6IHRoaXMge1xuICAgICAgICB0aGlzLiNjb21wYW5pb25zID0gY29tcGFuaW9ucy5tYXAobWFwQnVpbGRBcmdzKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgY29tbWVyY2lhbHNFbmRPZlN0YWdlKFxuICAgICAgICBjb21tZXJjaWFsc0VuZE9mU3RhZ2U6IFNlcUVsZW1lbnQ8QnVpbGRBcmdzPFJpY2hUZXh0Lk5vZGU+PlxuICAgICk6IHRoaXMge1xuICAgICAgICB0aGlzLiNjb21tZXJjaWFsc0VuZE9mU3RhZ2UgPSBjb21tZXJjaWFsc0VuZE9mU3RhZ2UubWFwKG1hcEJ1aWxkQXJncyk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkTGlzdEl0ZW0oc2VxTmV4dEVsZW1lbnQ6IFNlcU5leHRFbGVtZW50Q29udmVydGVyKTogQm9keVN0YWdlIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIGlkOiBoYXNoKFxuICAgICAgICAgICAgICAgIFwiYm9keVN0YWdlXCIsXG4gICAgICAgICAgICAgICAgdGhpcy4jbm9kZXMsXG4gICAgICAgICAgICAgICAgdGhpcy4jY29tcGFuaW9ucyxcbiAgICAgICAgICAgICAgICB0aGlzLiNjb21tZXJjaWFsc0VuZE9mU3RhZ2UsXG4gICAgICAgICAgICAgICAgdGhpcy4jaGVhZGVyXG4gICAgICAgICAgICApLFxuICAgICAgICAgICAgbm9kZXM6IHNlcU5leHRFbGVtZW50LmFycmF5KHRoaXMuI25vZGVzKSxcbiAgICAgICAgICAgIGhlYWRlcjogc2VxTmV4dEVsZW1lbnQubWF5YmUodGhpcy4jaGVhZGVyKSxcbiAgICAgICAgICAgIGNvbXBhbmlvbnM6IHNlcU5leHRFbGVtZW50LmFycmF5KHRoaXMuI2NvbXBhbmlvbnMpLFxuICAgICAgICAgICAgY29tbWVyY2lhbHNFbmRPZlN0YWdlOiBzZXFOZXh0RWxlbWVudC5hcnJheShcbiAgICAgICAgICAgICAgICB0aGlzLiNjb21tZXJjaWFsc0VuZE9mU3RhZ2VcbiAgICAgICAgICAgICksXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBCb2R5U3RhZ2VCdWlsZGVyIGV4dGVuZHMgQWJzdHJhY3RCdWlsZGVyPEJvZHlTdGFnZT4ge1xuICAgICNzZXFCdWlsZGVyOiBCb2R5U3RhZ2VTZXFCdWlsZGVyID0gbmV3IEJvZHlTdGFnZVNlcUJ1aWxkZXIoKTtcblxuICAgIG5vZGVzKG5vZGVzOiBCdWlsZEFyZ3M8UmljaFRleHQuTm9kZT4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jc2VxQnVpbGRlci5ub2Rlcyhbbm9kZXNdKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgaGVhZGVyKGhlYWRlcj86IEJ1aWxkQXJnPEJvZHlIZWFkZXI+KTogdGhpcyB7XG4gICAgICAgIGlmIChoZWFkZXIpIHtcbiAgICAgICAgICAgIHRoaXMuI3NlcUJ1aWxkZXIuaGVhZGVyKFtoZWFkZXJdKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBjb21wYW5pb25zKGNvbXBhbmlvbnM6IEJ1aWxkQXJnczxTdGFnZS5Db21wYW5pb25JdGVtPik6IHRoaXMge1xuICAgICAgICB0aGlzLiNzZXFCdWlsZGVyLmNvbXBhbmlvbnMoW2NvbXBhbmlvbnNdKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgY29tbWVyY2lhbHNFbmRPZlN0YWdlKFxuICAgICAgICBjb21tZXJjaWFsc0VuZE9mU3RhZ2U6IEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPlxuICAgICk6IHRoaXMge1xuICAgICAgICB0aGlzLiNzZXFCdWlsZGVyLmNvbW1lcmNpYWxzRW5kT2ZTdGFnZShbY29tbWVyY2lhbHNFbmRPZlN0YWdlXSk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkKCk6IEJvZHlTdGFnZSB7XG4gICAgICAgIHJldHVybiB0aGlzLiNzZXFCdWlsZGVyLmJ1aWxkKCk7XG4gICAgfVxufVxuXG5jbGFzcyBCb2R5SGVhZGVyQnVpbGRlciBleHRlbmRzIEFic3RyYWN0QnVpbGRlcjxCb2R5SGVhZGVyPiB7XG4gICAgI3ZhcmlhbnQ6IEJvZHlIZWFkZXJbXCJ2YXJpYW50XCJdID0gXCJmdWxsXCI7XG4gICAgI29wZW5lcj86IE9wZW5lciA9IHVuZGVmaW5lZDtcblxuICAgIHZhcmlhbnQodmFyaWFudDogQm9keUhlYWRlcltcInZhcmlhbnRcIl0pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jdmFyaWFudCA9IHZhcmlhbnQ7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIG9wZW5lcihvcGVuZXI6IEJ1aWxkQXJnPE9wZW5lcj4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jb3BlbmVyID0gbWFwQnVpbGRBcmcob3BlbmVyKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGQoKTogQm9keUhlYWRlciB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICB2YXJpYW50OiB0aGlzLiN2YXJpYW50LFxuICAgICAgICAgICAgb3BlbmVyOiB0aGlzLiNvcGVuZXIsXG4gICAgICAgIH07XG4gICAgfVxufVxuXG5jbGFzcyBBcnRpY2xlU291cmNlU2VxQnVpbGRlciBleHRlbmRzIEFic3RyYWN0U2VxQnVpbGRlcjxBcnRpY2xlU291cmNlPiB7XG4gICAgI25vZGVzOiBTZXFFbGVtZW50PFJpY2hUZXh0Lk5vZGVbXT4gPSBbXTtcblxuICAgIG5vZGVzKG5vZGVzOiBTZXFFbGVtZW50PEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPj4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jbm9kZXMgPSBub2Rlcy5tYXAobWFwQnVpbGRBcmdzKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGRMaXN0SXRlbShzZXFOZXh0RWxlbWVudDogU2VxTmV4dEVsZW1lbnRDb252ZXJ0ZXIpOiBBcnRpY2xlU291cmNlIHtcbiAgICAgICAgY29uc3QgaWQgPSBoYXNoKFwiYXJ0aWNsZS1zb3VyY2VcIiwgdGhpcy4jbm9kZXMpO1xuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgaWQsXG4gICAgICAgICAgICBub2Rlczogc2VxTmV4dEVsZW1lbnQuYXJyYXkodGhpcy4jbm9kZXMpLFxuICAgICAgICB9O1xuICAgIH1cbn1cblxuY2xhc3MgQXJ0aWNsZVNvdXJjZUJ1aWxkZXIgZXh0ZW5kcyBBYnN0cmFjdEJ1aWxkZXI8QXJ0aWNsZVNvdXJjZT4ge1xuICAgICNzZXFCdWlsZGVyOiBBcnRpY2xlU291cmNlU2VxQnVpbGRlciA9IG5ldyBBcnRpY2xlU291cmNlU2VxQnVpbGRlcigpO1xuXG4gICAgY29uc3RydWN0b3IoLi4ubm9kZXM6IEJ1aWxkQXJnczxSaWNoVGV4dC5Ob2RlPikge1xuICAgICAgICBzdXBlcigpO1xuICAgICAgICB0aGlzLm5vZGVzKC4uLm5vZGVzKTtcbiAgICB9XG5cbiAgICBub2RlcyguLi5ub2RlczogQnVpbGRBcmdzPFJpY2hUZXh0Lk5vZGU+KTogdGhpcyB7XG4gICAgICAgIHRoaXMuI3NlcUJ1aWxkZXIubm9kZXMoW25vZGVzXSk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkKCk6IEFydGljbGVTb3VyY2Uge1xuICAgICAgICByZXR1cm4gdGhpcy4jc2VxQnVpbGRlci5idWlsZCgpO1xuICAgIH1cbn1cblxuY2xhc3MgQXJ0aWNsZVNvdXJjZXNCdWlsZGVyIGV4dGVuZHMgQWJzdHJhY3RCdWlsZGVyPEFydGljbGVTb3VyY2VzPiB7XG4gICAgI25vZGVzOiBBcnRpY2xlU291cmNlW10gPSBbXTtcbiAgICAjaGlkZGVuOiBBcnRpY2xlU291cmNlW10gPSBbXTtcblxuICAgIG5vZGVzKC4uLm5vZGVzOiBCdWlsZEFyZ3M8QXJ0aWNsZVNvdXJjZT4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jbm9kZXMgPSBub2Rlcy5tYXAobWFwQnVpbGRBcmcpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBoaWRkZW4oLi4uaGlkZGVuOiBCdWlsZEFyZ3M8QXJ0aWNsZVNvdXJjZT4pOiB0aGlzIHtcbiAgICAgICAgdGhpcy4jaGlkZGVuID0gaGlkZGVuLm1hcChtYXBCdWlsZEFyZyk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIGJ1aWxkKCk6IEFydGljbGVTb3VyY2VzIHtcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIG5vZGVzOiB0aGlzLiNub2RlcyxcbiAgICAgICAgICAgIGhpZGRlbjogdGhpcy4jaGlkZGVuLFxuICAgICAgICB9O1xuICAgIH1cbn1cbiJdLCJuYW1lcyI6WyJjcmVhdGUiLCJoZWFkZXIiLCJub2RlIiwib3BlbmVyIiwic2VxIiwic291cmNlIiwic291cmNlcyIsInN0YWdlIiwidHJ1c3RCb3giLCJCb2R5QnVpbGRlciIsIlRydXN0Qm94QnVpbGRlciIsIk9wZW5lckJ1aWxkZXIiLCJCb2R5U3RhZ2VCdWlsZGVyIiwiQm9keUhlYWRlckJ1aWxkZXIiLCJub2RlcyIsIkFydGljbGVTb3VyY2VCdWlsZGVyIiwiQXJ0aWNsZVNvdXJjZXNCdWlsZGVyIiwiQm9keVN0YWdlU2VxQnVpbGRlciIsIkFydGljbGVTb3VyY2VTZXFCdWlsZGVyIiwiQWJzdHJhY3RCdWlsZGVyIiwic3RhZ2VzIiwibWFwIiwibWFwQnVpbGRBcmciLCJkaXNjbGFpbWVyIiwiYXJ0aWNsZVNvdXJjZXMiLCJidWlsZCIsInVuZGVmaW5lZCIsImhpZGRlbiIsImVsZW1lbnQiLCJpbWFnZSIsIkFic3RyYWN0U2VxQnVpbGRlciIsIm1hcEJ1aWxkQXJncyIsImNvbXBhbmlvbnMiLCJjb21tZXJjaWFsc0VuZE9mU3RhZ2UiLCJidWlsZExpc3RJdGVtIiwic2VxTmV4dEVsZW1lbnQiLCJpZCIsImhhc2giLCJhcnJheSIsIm1heWJlIiwic2VxQnVpbGRlciIsInZhcmlhbnQiLCJjb25zdHJ1Y3RvciJdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7Ozs7O0lBNkJhQSxNQUFNLE1BQU5BLE1BQU07SUFNTkMsTUFBTSxNQUFOQSxNQUFNO0lBUlBDLElBQUk7SUFLSEMsTUFBTSxNQUFOQSxNQUFNO0lBYU5DLEdBQUcsTUFBSEEsR0FBRztJQVJIQyxNQUFNLE1BQU5BLE1BQU07SUFLTkMsT0FBTyxNQUFQQSxPQUFPO0lBVFBDLEtBQUssTUFBTEEsS0FBSztJQUhMQyxRQUFRLE1BQVJBLFFBQVE7Ozs7Ozs7a0NBOUIrQixvQkFBb0I7OEJBQ3hCLGlCQUFpQjtnQ0FDM0Msa0JBQWtCO3NFQXdCMUIsb0JBQW9CO0FBRzNCLE1BQU1SLE1BQU0sR0FBK0IsSUFBTSxJQUFJUyxXQUFXLEVBQUUsQUFBQztBQUNuRSxNQUFNRCxRQUFRLEdBQW1DLElBQ3BELElBQUlFLGVBQWUsRUFBRSxBQUFDO0FBQ25CLE1BQU1QLE1BQU0sR0FBaUMsSUFBTSxJQUFJUSxhQUFhLEVBQUUsQUFBQztBQUN2RSxNQUFNSixLQUFLLEdBQW9DLElBQ2xELElBQUlLLGdCQUFnQixFQUFFLEFBQUM7QUFDcEIsTUFBTVgsTUFBTSxHQUFxQyxJQUNwRCxJQUFJWSxpQkFBaUIsRUFBRSxBQUFDO0FBQ3JCLE1BQU1SLE1BQU0sR0FHZixDQUFDUyxLQUErQixHQUFHLEVBQUUsR0FDckMsSUFBSUMsb0JBQW9CLElBQUlELEtBQUssQ0FBQyxBQUFDO0FBQ2hDLE1BQU1SLE9BQU8sR0FBeUMsSUFDekQsSUFBSVUscUJBQXFCLEVBQUUsQUFBQztBQUV6QixNQUFNWixHQUFHLEdBQUc7SUFDZkcsS0FBSyxFQUFHLElBQ0osSUFBSVUsbUJBQW1CLEVBQUU7SUFDN0JaLE1BQU0sRUFBRyxJQUNMLElBQUlhLHVCQUF1QixFQUFFO0NBQ3BDLEFBQVMsQUFBQztJQUdQLE9BQU8sZ0NBQ1AsU0FBUyxnQ0FDVCxXQUFXLGdDQUNYLGVBQWU7QUFKbkIsTUFBTVQsV0FBVyxTQUFTVSxpQkFBZSxnQkFBQTtJQU1yQ0MsTUFBTSxDQUFDLEdBQUdBLE1BQU0sQUFBc0IsRUFBUTtvQ0FDcENBLE9BQU0sRUFBR0EsTUFBTSxDQUFDQyxHQUFHLENBQUNDLGFBQVcsWUFBQSxDQUFDLEVBQUM7UUFDdkMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEZCxRQUFRLENBQUNBLFFBQTZCLEVBQVE7b0NBQ3BDQSxTQUFRLEVBQUdjLElBQUFBLGFBQVcsWUFBQSxFQUFDZCxRQUFRLENBQUMsRUFBQztRQUN2QyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURlLFVBQVUsQ0FBQ0EsVUFBcUMsRUFBUTtvQ0FDOUNBLFdBQVUsRUFBR0EsVUFBVSxFQUFFRixHQUFHLENBQUNDLGFBQVcsWUFBQSxDQUFDLEVBQUM7UUFDaEQsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVERSxjQUFjLENBQUNBLGNBQXlDLEVBQVE7b0NBQ3REQSxlQUFjLEVBQUdGLElBQUFBLGFBQVcsWUFBQSxFQUFDRSxjQUFjLENBQUMsRUFBQztRQUNuRCxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURDLEtBQUssR0FBUztRQUNWLE9BQU87WUFDSEwsTUFBTSx3QkFBRSxJQUFJLEVBQUVBLE9BQU07WUFDcEJaLFFBQVEsd0JBQUUsSUFBSSxFQUFFQSxTQUFRO1lBQ3hCZSxVQUFVLHdCQUFFLElBQUksRUFBRUEsV0FBVTtZQUM1QkMsY0FBYyx3QkFBRSxJQUFJLEVBQUVBLGVBQWM7U0FDdkMsQ0FBQztLQUNMOzs7UUFoQ0QsNkJBQUEsT0FBTzs7bUJBQWdCLEVBQUU7VUFBQyxDQUFBO1FBQzFCLDZCQUFBLFNBQVM7O21CQUFjRSxTQUFTO1VBQUMsQ0FBQTtRQUNqQyw2QkFBQSxXQUFXOzttQkFBcUJBLFNBQVM7VUFBQyxDQUFBO1FBQzFDLDZCQUFBLGVBQWU7O21CQUFvQkEsU0FBUztVQUFDLENBQUE7O0NBOEJoRDtJQUdHLE1BQU0sZ0NBQ04sT0FBTztBQUZYLE1BQU1oQixlQUFlLFNBQVNTLGlCQUFlLGdCQUFBO0lBSXpDTCxLQUFLLENBQUNBLEtBQStCLEVBQVE7b0NBQ25DQSxNQUFLLEVBQUdBLEtBQUssQ0FBQ08sR0FBRyxDQUFDQyxhQUFXLFlBQUEsQ0FBQyxFQUFDO1FBQ3JDLE9BQU8sSUFBSSxDQUFDO0tBQ2Y7SUFFREssTUFBTSxDQUFDQSxNQUFnQyxFQUFRO29DQUNyQ0EsT0FBTSxFQUFHQSxNQUFNLENBQUNOLEdBQUcsQ0FBQ0MsYUFBVyxZQUFBLENBQUMsRUFBQztRQUN2QyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURHLEtBQUssR0FBYTtRQUNkLE9BQU87WUFDSFgsS0FBSyx3QkFBRSxJQUFJLEVBQUVBLE1BQUs7WUFDbEJhLE1BQU0sd0JBQUUsSUFBSSxFQUFFQSxPQUFNO1NBQ3ZCLENBQUM7S0FDTDs7O1FBbEJELDZCQUFBLE1BQU07O21CQUFvQixFQUFFO1VBQUMsQ0FBQTtRQUM3Qiw2QkFBQSxPQUFPOzttQkFBb0IsRUFBRTtVQUFDLENBQUE7O0NBa0JqQztJQUdHLFFBQVE7QUFEWixNQUFNaEIsYUFBYSxTQUFTUSxpQkFBZSxnQkFBQTtJQUd2Q1MsT0FBTyxDQUFDQSxPQUFvQyxFQUFRO29DQUMxQ0EsUUFBTyxFQUFHTixJQUFBQSxhQUFXLFlBQUEsRUFBQ00sT0FBTyxDQUFDLEVBQUM7UUFDckMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVESCxLQUFLLEdBQVc7UUFDWixPQUFPO1lBQ0hHLE9BQU8sd0JBQUUsSUFBSSxFQUFFQSxRQUFPO1NBQ3pCLENBQUM7S0FDTDs7O1FBWEQsNkJBQUEsUUFBUTs7bUJBQXNCQyxJQUFBQSxlQUFLLE1BQUEsR0FBRSxDQUFDSixLQUFLLEVBQUU7VUFBQyxDQUFBOztDQVlqRDtJQUdHLE9BQU0sZ0NBQ04sT0FBTyxnQ0FDUCxXQUFXLGdDQUNYLHNCQUFzQjtBQUoxQixNQUFNUixtQkFBbUIsU0FBU2EsaUJBQWtCLG1CQUFBO0lBTWhEaEIsS0FBSyxDQUFDQSxLQUEyQyxFQUFRO29DQUMvQ0EsT0FBSyxFQUFHQSxLQUFLLENBQUNPLEdBQUcsQ0FBQ1UsYUFBWSxhQUFBLENBQUMsRUFBQztRQUN0QyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRUQ5QixNQUFNLENBQUNBLE1BQXlDLEVBQVE7b0NBQzlDQSxPQUFNLEVBQUc4QixJQUFBQSxhQUFZLGFBQUEsRUFBQzlCLE1BQU0sSUFBSSxFQUFFLENBQUMsRUFBQztRQUMxQyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRUQrQixVQUFVLENBQUNBLFVBQXNELEVBQVE7b0NBQy9EQSxXQUFVLEVBQUdBLFVBQVUsQ0FBQ1gsR0FBRyxDQUFDVSxhQUFZLGFBQUEsQ0FBQyxFQUFDO1FBQ2hELE9BQU8sSUFBSSxDQUFDO0tBQ2Y7SUFFREUscUJBQXFCLENBQ2pCQSxxQkFBMkQsRUFDdkQ7b0NBQ0VBLHNCQUFxQixFQUFHQSxxQkFBcUIsQ0FBQ1osR0FBRyxDQUFDVSxhQUFZLGFBQUEsQ0FBQyxFQUFDO1FBQ3RFLE9BQU8sSUFBSSxDQUFDO0tBQ2Y7SUFFREcsYUFBYSxDQUFDQyxjQUF1QyxFQUFhO1FBQzlELE9BQU87WUFDSEMsRUFBRSxFQUFFQyxJQUFBQSxhQUFJLEtBQUEsRUFDSixXQUFXLHdCQUNYLElBQUksRUFBRXZCLE9BQUsseUJBQ1gsSUFBSSxFQUFFa0IsV0FBVSx5QkFDaEIsSUFBSSxFQUFFQyxzQkFBcUIseUJBQzNCLElBQUksRUFBRWhDLE9BQU0sRUFDZjtZQUNEYSxLQUFLLEVBQUVxQixjQUFjLENBQUNHLEtBQUssdUJBQUMsSUFBSSxFQUFFeEIsT0FBSyxFQUFDO1lBQ3hDYixNQUFNLEVBQUVrQyxjQUFjLENBQUNJLEtBQUssdUJBQUMsSUFBSSxFQUFFdEMsT0FBTSxFQUFDO1lBQzFDK0IsVUFBVSxFQUFFRyxjQUFjLENBQUNHLEtBQUssdUJBQUMsSUFBSSxFQUFFTixXQUFVLEVBQUM7WUFDbERDLHFCQUFxQixFQUFFRSxjQUFjLENBQUNHLEtBQUssdUJBQ3ZDLElBQUksRUFBRUwsc0JBQXFCLEVBQzlCO1NBQ0osQ0FBQztLQUNMOzs7UUEzQ0QsNkJBQUEsT0FBTTs7bUJBQWdDLEVBQUU7VUFBQyxDQUFBO1FBQ3pDLDZCQUFBLE9BQU87O21CQUE0QlAsU0FBUztVQUFDLENBQUE7UUFDN0MsNkJBQUEsV0FBVzs7bUJBQXNDLEVBQUU7VUFBQyxDQUFBO1FBQ3BELDZCQUFBLHNCQUFzQjs7bUJBQWdDLEVBQUU7VUFBQyxDQUFBOztDQXlDNUQ7SUFHRyxXQUFXO0FBRGYsTUFBTWQsZ0JBQWdCLFNBQVNPLGlCQUFlLGdCQUFBO0lBRzFDTCxLQUFLLENBQUNBLEtBQStCLEVBQVE7UUFDekMsc0JBQUEsSUFBSSxFQUFFMEIsV0FBVSxFQUFDMUIsS0FBSyxDQUFDO1lBQUNBLEtBQUs7U0FBQyxDQUFDLENBQUM7UUFDaEMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEYixNQUFNLENBQUNBLE1BQTZCLEVBQVE7UUFDeEMsSUFBSUEsTUFBTSxFQUFFO1lBQ1Isc0JBQUEsSUFBSSxFQUFFdUMsV0FBVSxFQUFDdkMsTUFBTSxDQUFDO2dCQUFDQSxNQUFNO2FBQUMsQ0FBQyxDQUFDO1NBQ3JDO1FBQ0QsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEK0IsVUFBVSxDQUFDQSxVQUEwQyxFQUFRO1FBQ3pELHNCQUFBLElBQUksRUFBRVEsV0FBVSxFQUFDUixVQUFVLENBQUM7WUFBQ0EsVUFBVTtTQUFDLENBQUMsQ0FBQztRQUMxQyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURDLHFCQUFxQixDQUNqQkEscUJBQStDLEVBQzNDO1FBQ0osc0JBQUEsSUFBSSxFQUFFTyxXQUFVLEVBQUNQLHFCQUFxQixDQUFDO1lBQUNBLHFCQUFxQjtTQUFDLENBQUMsQ0FBQztRQUNoRSxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURSLEtBQUssR0FBYztRQUNmLE9BQU8sc0JBQUEsSUFBSSxFQUFFZSxXQUFVLEVBQUNmLEtBQUssRUFBRSxDQUFDO0tBQ25DOzs7UUE1QkQsNkJBQUEsV0FBVzs7bUJBQXdCLElBQUlSLG1CQUFtQixFQUFFO1VBQUMsQ0FBQTs7Q0E2QmhFO0lBR0csUUFBUSxnQ0FDUixPQUFPO0FBRlgsTUFBTUosaUJBQWlCLFNBQVNNLGlCQUFlLGdCQUFBO0lBSTNDc0IsT0FBTyxDQUFDQSxPQUE4QixFQUFRO29DQUNwQ0EsUUFBTyxFQUFHQSxPQUFPLEVBQUM7UUFDeEIsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEdEMsTUFBTSxDQUFDQSxNQUF3QixFQUFRO29DQUM3QkEsT0FBTSxFQUFHbUIsSUFBQUEsYUFBVyxZQUFBLEVBQUNuQixNQUFNLENBQUMsRUFBQztRQUNuQyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURzQixLQUFLLEdBQWU7UUFDaEIsT0FBTztZQUNIZ0IsT0FBTyx3QkFBRSxJQUFJLEVBQUVBLFFBQU87WUFDdEJ0QyxNQUFNLHdCQUFFLElBQUksRUFBRUEsT0FBTTtTQUN2QixDQUFDO0tBQ0w7OztRQWxCRCw2QkFBQSxRQUFROzttQkFBMEIsTUFBTTtVQUFDLENBQUE7UUFDekMsNkJBQUEsT0FBTzs7bUJBQVl1QixTQUFTO1VBQUMsQ0FBQTs7Q0FrQmhDO0lBR0csT0FBTTtBQURWLE1BQU1SLHVCQUF1QixTQUFTWSxpQkFBa0IsbUJBQUE7SUFHcERoQixLQUFLLENBQUNBLEtBQTJDLEVBQVE7b0NBQy9DQSxPQUFLLEVBQUdBLEtBQUssQ0FBQ08sR0FBRyxDQUFDVSxhQUFZLGFBQUEsQ0FBQyxFQUFDO1FBQ3RDLE9BQU8sSUFBSSxDQUFDO0tBQ2Y7SUFFREcsYUFBYSxDQUFDQyxjQUF1QyxFQUFpQjtRQUNsRSxNQUFNQyxFQUFFLEdBQUdDLElBQUFBLGFBQUksS0FBQSxFQUFDLGdCQUFnQix3QkFBRSxJQUFJLEVBQUV2QixPQUFLLEVBQUMsQUFBQztRQUMvQyxPQUFPO1lBQ0hzQixFQUFFO1lBQ0Z0QixLQUFLLEVBQUVxQixjQUFjLENBQUNHLEtBQUssdUJBQUMsSUFBSSxFQUFFeEIsT0FBSyxFQUFDO1NBQzNDLENBQUM7S0FDTDs7O1FBYkQsNkJBQUEsT0FBTTs7bUJBQWdDLEVBQUU7VUFBQyxDQUFBOztDQWM1QztJQUdHLFlBQVc7QUFEZixNQUFNQyxvQkFBb0IsU0FBU0ksaUJBQWUsZ0JBQUE7SUFROUNMLEtBQUssQ0FBQyxHQUFHQSxLQUFLLEFBQTBCLEVBQVE7UUFDNUMsc0JBQUEsSUFBSSxFQUFFMEIsWUFBVSxFQUFDMUIsS0FBSyxDQUFDO1lBQUNBLEtBQUs7U0FBQyxDQUFDLENBQUM7UUFDaEMsT0FBTyxJQUFJLENBQUM7S0FDZjtJQUVEVyxLQUFLLEdBQWtCO1FBQ25CLE9BQU8sc0JBQUEsSUFBSSxFQUFFZSxZQUFVLEVBQUNmLEtBQUssRUFBRSxDQUFDO0tBQ25DO0lBWkRpQixZQUFZLEdBQUc1QixLQUFLLEFBQTBCLENBQUU7UUFDNUMsS0FBSyxFQUFFLENBQUM7UUFIWiw2QkFBQSxZQUFXOzttQkFBNEIsSUFBSUksdUJBQXVCLEVBQUU7VUFBQyxDQUFBO1FBSWpFLElBQUksQ0FBQ0osS0FBSyxJQUFJQSxLQUFLLENBQUMsQ0FBQztLQUN4QjtDQVVKO0lBR0csT0FBTSxnQ0FDTixRQUFPO0FBRlgsTUFBTUUscUJBQXFCLFNBQVNHLGlCQUFlLGdCQUFBO0lBSS9DTCxLQUFLLENBQUMsR0FBR0EsS0FBSyxBQUEwQixFQUFRO29DQUN0Q0EsT0FBSyxFQUFHQSxLQUFLLENBQUNPLEdBQUcsQ0FBQ0MsYUFBVyxZQUFBLENBQUMsRUFBQztRQUNyQyxPQUFPLElBQUksQ0FBQztLQUNmO0lBRURLLE1BQU0sQ0FBQyxHQUFHQSxNQUFNLEFBQTBCLEVBQVE7b0NBQ3hDQSxRQUFNLEVBQUdBLE1BQU0sQ0FBQ04sR0FBRyxDQUFDQyxhQUFXLFlBQUEsQ0FBQyxFQUFDO1FBQ3ZDLE9BQU8sSUFBSSxDQUFDO0tBQ2Y7SUFFREcsS0FBSyxHQUFtQjtRQUNwQixPQUFPO1lBQ0hYLEtBQUssd0JBQUUsSUFBSSxFQUFFQSxPQUFLO1lBQ2xCYSxNQUFNLHdCQUFFLElBQUksRUFBRUEsUUFBTTtTQUN2QixDQUFDO0tBQ0w7OztRQWxCRCw2QkFBQSxPQUFNOzttQkFBb0IsRUFBRTtVQUFDLENBQUE7UUFDN0IsNkJBQUEsUUFBTzs7bUJBQW9CLEVBQUU7VUFBQyxDQUFBOztDQWtCakMifQ== diff --git a/crates/swc/tests/projects.rs b/crates/swc/tests/projects.rs index a10bef958e1..4dc027b3704 100644 --- a/crates/swc/tests/projects.rs +++ b/crates/swc/tests/projects.rs @@ -412,7 +412,7 @@ fn issue_605() { let f = file("tests/projects/issue-605/input.js").unwrap(); println!("{}", f); - assert!(f.contains("Object.keys(_c)")); + assert!(f.contains(r#"_exportStar(require("c"), exports);"#)); } #[test] @@ -597,7 +597,7 @@ fn issue_895() { println!("{}", f); assert!(f.contains("_url =")); - assert!(f.contains("(0, _url).queryString")); + assert!(f.contains("(0, _url.queryString)")); let s = f.replace("_url =", "").replace("_url.queryString", ""); assert!(!s.contains("_url.")); diff --git a/crates/swc/tests/tsc-references/duplicateExportAssignments_es2015.1.normal.js b/crates/swc/tests/tsc-references/duplicateExportAssignments_es2015.1.normal.js index 6e872467afb..48bacd0781b 100644 --- a/crates/swc/tests/tsc-references/duplicateExportAssignments_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/duplicateExportAssignments_es2015.1.normal.js @@ -20,5 +20,5 @@ function y() { var x = 5; var y = "test"; var z = {}; -module.exports = z; +module.exports = x; export { }; diff --git a/crates/swc/tests/tsc-references/duplicateExportAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/duplicateExportAssignments_es2015.2.minified.js index 3df1c968268..557e7618c54 100644 --- a/crates/swc/tests/tsc-references/duplicateExportAssignments_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/duplicateExportAssignments_es2015.2.minified.js @@ -1,5 +1,5 @@ var x = 10; (x || (x = {})).x = 10; var x = 5; -module.exports = {}; +module.exports = x; export { }; diff --git a/crates/swc/tests/tsc-references/duplicateExportAssignments_es5.1.normal.js b/crates/swc/tests/tsc-references/duplicateExportAssignments_es5.1.normal.js index baef9c16970..dbecfb61c40 100644 --- a/crates/swc/tests/tsc-references/duplicateExportAssignments_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/duplicateExportAssignments_es5.1.normal.js @@ -25,5 +25,5 @@ function y() { var x = 5; var y = "test"; var z = {}; -module.exports = z; +module.exports = x; export { }; diff --git a/crates/swc/tests/tsc-references/duplicateExportAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/duplicateExportAssignments_es5.2.minified.js index f5da2b02d41..2239c6aa99d 100644 --- a/crates/swc/tests/tsc-references/duplicateExportAssignments_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/duplicateExportAssignments_es5.2.minified.js @@ -12,4 +12,4 @@ function y() { return 42; } var x = 5, y = "test"; -module.exports = {}; +module.exports = x; diff --git a/crates/swc/tests/tsc-references/es6modulekindWithES5Target10_es2015.1.normal.js b/crates/swc/tests/tsc-references/es6modulekindWithES5Target10_es2015.1.normal.js index f3b6e0a1a5e..553194e97a7 100644 --- a/crates/swc/tests/tsc-references/es6modulekindWithES5Target10_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/es6modulekindWithES5Target10_es2015.1.normal.js @@ -1,6 +1,5 @@ // @target: es5 // @module: es2015 const i = require("mod"); // Error; -module.exports = N // Error -; +module.exports = N; // Error export { }; diff --git a/crates/swc/tests/tsc-references/es6modulekindWithES5Target10_es5.1.normal.js b/crates/swc/tests/tsc-references/es6modulekindWithES5Target10_es5.1.normal.js index e8aadf866b2..eb37cfcf832 100644 --- a/crates/swc/tests/tsc-references/es6modulekindWithES5Target10_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/es6modulekindWithES5Target10_es5.1.normal.js @@ -1,6 +1,5 @@ // @target: es5 // @module: es2015 var i = require("mod"); // Error; -module.exports = N // Error -; +module.exports = N; // Error export { }; diff --git a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target10_es2015.1.normal.js b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target10_es2015.1.normal.js index 30740c2e839..c8c63a813a3 100644 --- a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target10_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target10_es2015.1.normal.js @@ -1,6 +1,5 @@ // @target: es5 // @module: esnext const i = require("mod"); // Error; -module.exports = N // Error -; +module.exports = N; // Error export { }; diff --git a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target10_es5.1.normal.js b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target10_es5.1.normal.js index 7793bf6e6cf..2f5c14faf37 100644 --- a/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target10_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/esnextmodulekindWithES5Target10_es5.1.normal.js @@ -1,6 +1,5 @@ // @target: es5 // @module: esnext var i = require("mod"); // Error; -module.exports = N // Error -; +module.exports = N; // Error export { }; diff --git a/crates/swc/tests/tsc-references/exportAssignDottedName_es2015.1.normal.js b/crates/swc/tests/tsc-references/exportAssignDottedName_es2015.1.normal.js index 06ab7607b6f..2c877178549 100644 --- a/crates/swc/tests/tsc-references/exportAssignDottedName_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/exportAssignDottedName_es2015.1.normal.js @@ -4,5 +4,4 @@ export function x() { } // @Filename: foo2.ts const foo1 = require('./foo1'); -module.exports = foo1.x // Ok -; +module.exports = foo1.x; // Ok diff --git a/crates/swc/tests/tsc-references/exportAssignDottedName_es5.1.normal.js b/crates/swc/tests/tsc-references/exportAssignDottedName_es5.1.normal.js index a6d79f4e852..c9e40315577 100644 --- a/crates/swc/tests/tsc-references/exportAssignDottedName_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/exportAssignDottedName_es5.1.normal.js @@ -4,5 +4,4 @@ export function x() { } // @Filename: foo2.ts var foo1 = require("./foo1"); -module.exports = foo1.x // Ok -; +module.exports = foo1.x; // Ok diff --git a/crates/swc/tests/tsc-references/exportNonVisibleType_es2015.1.normal.js b/crates/swc/tests/tsc-references/exportNonVisibleType_es2015.1.normal.js index b8d09d666ea..4d96a39dfe1 100644 --- a/crates/swc/tests/tsc-references/exportNonVisibleType_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/exportNonVisibleType_es2015.1.normal.js @@ -6,7 +6,6 @@ class C1 { } class C1 { } -module.exports = C1 // Should work, private type I1 of visible class C1 only used in private member m1. -; +module.exports = x; // Should fail, I1 not exported. // @Filename: foo1.ts -export { }; +export { }; // Should work, private type I1 of visible class C1 only used in private member m1. diff --git a/crates/swc/tests/tsc-references/exportNonVisibleType_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportNonVisibleType_es2015.2.minified.js index 64c1aa64a4b..a9f01bdc5a8 100644 --- a/crates/swc/tests/tsc-references/exportNonVisibleType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportNonVisibleType_es2015.2.minified.js @@ -1,6 +1,5 @@ -class C1 { -} -class C1 { -} -module.exports = C1; +module.exports = { + a: "test", + b: 42 +}; export { }; diff --git a/crates/swc/tests/tsc-references/exportNonVisibleType_es5.1.normal.js b/crates/swc/tests/tsc-references/exportNonVisibleType_es5.1.normal.js index 1ac22031a70..c1834b2f8ca 100644 --- a/crates/swc/tests/tsc-references/exportNonVisibleType_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/exportNonVisibleType_es5.1.normal.js @@ -11,7 +11,6 @@ var C1 = function C1() { "use strict"; _class_call_check(this, C1); }; -module.exports = C1 // Should work, private type I1 of visible class C1 only used in private member m1. -; +module.exports = x; // Should fail, I1 not exported. // @Filename: foo1.ts -export { }; +export { }; // Should work, private type I1 of visible class C1 only used in private member m1. diff --git a/crates/swc/tests/tsc-references/exportNonVisibleType_es5.2.minified.js b/crates/swc/tests/tsc-references/exportNonVisibleType_es5.2.minified.js index 42369800862..e4c822a7426 100644 --- a/crates/swc/tests/tsc-references/exportNonVisibleType_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/exportNonVisibleType_es5.2.minified.js @@ -6,4 +6,7 @@ var C1 = function() { "use strict"; _class_call_check(this, C1); }; -module.exports = C1; +module.exports = { + a: "test", + b: 42 +}; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es2015.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es2015.1.normal.js index 985aae845e2..775ef0367b4 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es2015.1.normal.js @@ -1,9 +1,5 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -// @filename: index.ts -module.exports = _async_to_generator(function*() { - const something = yield import("./something"); -}); // @module: amd // @target: esnext // @filename: something.ts +module.exports = 42; export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es2015.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es2015.2.minified.js index 9a11bf4e280..d8b61fd48f4 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es2015.2.minified.js @@ -1,4 +1,2 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -module.exports = _async_to_generator(function*() { - yield import("./something"); -}); +module.exports = 42; +export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es5.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es5.1.normal.js index 825eca6c1b6..775ef0367b4 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es5.1.normal.js @@ -1,22 +1,5 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -import regeneratorRuntime from "regenerator-runtime"; -// @filename: index.ts -module.exports = _async_to_generator(regeneratorRuntime.mark(function _callee() { - var something; - return regeneratorRuntime.wrap(function _callee$(_ctx) { - while(1)switch(_ctx.prev = _ctx.next){ - case 0: - _ctx.next = 2; - return import("./something"); - case 2: - something = _ctx.sent; - case 3: - case "end": - return _ctx.stop(); - } - }, _callee); -})); // @module: amd // @target: esnext // @filename: something.ts +module.exports = 42; export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es5.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es5.2.minified.js index cd173a50d2a..d8b61fd48f4 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsAMD_es5.2.minified.js @@ -1,16 +1,2 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -import regeneratorRuntime from "regenerator-runtime"; -module.exports = _async_to_generator(regeneratorRuntime.mark(function _callee() { - var something; - return regeneratorRuntime.wrap(function(_ctx) { - for(;;)switch(_ctx.prev = _ctx.next){ - case 0: - return _ctx.next = 2, import("./something"); - case 2: - something = _ctx.sent; - case 3: - case "end": - return _ctx.stop(); - } - }, _callee); -})); +module.exports = 42; +export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es2015.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es2015.1.normal.js index 1b85762cea6..8748fccf8f5 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es2015.1.normal.js @@ -1,9 +1,5 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -// @filename: index.ts -module.exports = _async_to_generator(function*() { - const something = yield import("./something"); -}); // @module: commonjs // @target: esnext // @filename: something.ts +module.exports = 42; export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es2015.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es2015.2.minified.js index 9a11bf4e280..d8b61fd48f4 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es2015.2.minified.js @@ -1,4 +1,2 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -module.exports = _async_to_generator(function*() { - yield import("./something"); -}); +module.exports = 42; +export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es5.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es5.1.normal.js index e39e83cd166..8748fccf8f5 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es5.1.normal.js @@ -1,22 +1,5 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -import regeneratorRuntime from "regenerator-runtime"; -// @filename: index.ts -module.exports = _async_to_generator(regeneratorRuntime.mark(function _callee() { - var something; - return regeneratorRuntime.wrap(function _callee$(_ctx) { - while(1)switch(_ctx.prev = _ctx.next){ - case 0: - _ctx.next = 2; - return import("./something"); - case 2: - something = _ctx.sent; - case 3: - case "end": - return _ctx.stop(); - } - }, _callee); -})); // @module: commonjs // @target: esnext // @filename: something.ts +module.exports = 42; export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es5.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es5.2.minified.js index cd173a50d2a..d8b61fd48f4 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsCJS_es5.2.minified.js @@ -1,16 +1,2 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -import regeneratorRuntime from "regenerator-runtime"; -module.exports = _async_to_generator(regeneratorRuntime.mark(function _callee() { - var something; - return regeneratorRuntime.wrap(function(_ctx) { - for(;;)switch(_ctx.prev = _ctx.next){ - case 0: - return _ctx.next = 2, import("./something"); - case 2: - something = _ctx.sent; - case 3: - case "end": - return _ctx.stop(); - } - }, _callee); -})); +module.exports = 42; +export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es2015.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es2015.1.normal.js index 883b7977d70..984d52d0f06 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es2015.1.normal.js @@ -1,9 +1,5 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -// @filename: index.ts -module.exports = _async_to_generator(function*() { - const something = yield import("./something"); -}); // @module: umd // @target: esnext // @filename: something.ts +module.exports = 42; export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es2015.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es2015.2.minified.js index 9a11bf4e280..d8b61fd48f4 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es2015.2.minified.js @@ -1,4 +1,2 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -module.exports = _async_to_generator(function*() { - yield import("./something"); -}); +module.exports = 42; +export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es5.1.normal.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es5.1.normal.js index 7c73951801c..984d52d0f06 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es5.1.normal.js @@ -1,22 +1,5 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -import regeneratorRuntime from "regenerator-runtime"; -// @filename: index.ts -module.exports = _async_to_generator(regeneratorRuntime.mark(function _callee() { - var something; - return regeneratorRuntime.wrap(function _callee$(_ctx) { - while(1)switch(_ctx.prev = _ctx.next){ - case 0: - _ctx.next = 2; - return import("./something"); - case 2: - something = _ctx.sent; - case 3: - case "end": - return _ctx.stop(); - } - }, _callee); -})); // @module: umd // @target: esnext // @filename: something.ts +module.exports = 42; export { }; diff --git a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es5.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es5.2.minified.js index cd173a50d2a..d8b61fd48f4 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionInExportEqualsUMD_es5.2.minified.js @@ -1,16 +1,2 @@ -import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -import regeneratorRuntime from "regenerator-runtime"; -module.exports = _async_to_generator(regeneratorRuntime.mark(function _callee() { - var something; - return regeneratorRuntime.wrap(function(_ctx) { - for(;;)switch(_ctx.prev = _ctx.next){ - case 0: - return _ctx.next = 2, import("./something"); - case 2: - something = _ctx.sent; - case 3: - case "end": - return _ctx.stop(); - } - }, _callee); -})); +module.exports = 42; +export { }; diff --git a/crates/swc/tests/tsc-references/importEquals2_es2015.1.normal.js b/crates/swc/tests/tsc-references/importEquals2_es2015.1.normal.js index 3f90b7237f0..b90ab653378 100644 --- a/crates/swc/tests/tsc-references/importEquals2_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/importEquals2_es2015.1.normal.js @@ -1,3 +1,5 @@ +// @Filename: /b.ts +import * as a from './a'; // @esModuleInterop: true // @Filename: /a.ts class A { @@ -6,4 +8,3 @@ class A { const a = require('./b'); new a.A(); // Error module.exports = a; -export { }; diff --git a/crates/swc/tests/tsc-references/importEquals2_es2015.2.minified.js b/crates/swc/tests/tsc-references/importEquals2_es2015.2.minified.js index 5f2fc0b9a3e..aed571b6ff5 100644 --- a/crates/swc/tests/tsc-references/importEquals2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/importEquals2_es2015.2.minified.js @@ -1,3 +1,3 @@ +import * as a from './a'; let a = require('./b'); new a.A(), module.exports = a; -export { }; diff --git a/crates/swc/tests/tsc-references/importEquals2_es5.1.normal.js b/crates/swc/tests/tsc-references/importEquals2_es5.1.normal.js index 1841c88a702..1b63357733e 100644 --- a/crates/swc/tests/tsc-references/importEquals2_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/importEquals2_es5.1.normal.js @@ -1,4 +1,6 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +// @Filename: /b.ts +import * as a from "./a"; // @esModuleInterop: true // @Filename: /a.ts var A = function A() { @@ -9,4 +11,3 @@ var A = function A() { var a = require("./b"); new a.A(); // Error module.exports = a; -export { }; diff --git a/crates/swc/tests/tsc-references/importEquals2_es5.2.minified.js b/crates/swc/tests/tsc-references/importEquals2_es5.2.minified.js index 4d12ded2614..3d4e710305e 100644 --- a/crates/swc/tests/tsc-references/importEquals2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/importEquals2_es5.2.minified.js @@ -1,4 +1,5 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; +import * as a from "./a"; var A = function() { "use strict"; _class_call_check(this, A); diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.1.normal.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.1.normal.js index feb7c840bde..8e5dad25bdc 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.1.normal.js @@ -45,4 +45,4 @@ K; const K = require('./k'); 0; // @Filename: /j.ts // Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 -module.exports = K; +module.exports = H; diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js index fea53ea16a1..83aa09d54f5 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js @@ -12,8 +12,14 @@ console.log(a, b); let a, b; console.log(a, b); let a = A, b; -console.log(a, b), console.log(1, 1), console.log(1, 1), require('./h'), console.log({}), require('./h'), function(K) { +console.log(a, b), console.log(1, 1), console.log(1, 1); +class H { +} +let H = require('./h'); +console.log({}); +let H = require('./h'); +!function(K) { K[K.One = 0] = "One", K[K.Two = 1] = "Two"; }(K || (K = {})); let K = require('./k'); -module.exports = K; +module.exports = H; diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.1.normal.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.1.normal.js index 765bfac6ee8..2ac93c2952f 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.1.normal.js @@ -50,4 +50,4 @@ K; var K = require("./k"); 0; // @Filename: /j.ts // Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 -module.exports = K; +module.exports = H; diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js index 82a781d0cf6..3baa8ff113c 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js @@ -14,9 +14,13 @@ export var C; var a = A; console.log(a, b); var c = 1, d = 1; -console.log(c, d), console.log(c, d), require("./h"), console.log({}), require("./h"), function(K) { +console.log(c, d), console.log(c, d); +var H = require("./h"); +console.log({}); +var H = require("./h"); +!function(K) { K[K.One = 0] = "One", K[K.Two = 1] = "Two"; }(K || (K = {})); var K = require("./k"); -module.exports = K; +module.exports = H; export { _default as default }; diff --git a/crates/swc/tests/tsc-references/preserveValueImports_es2015.1.normal.js b/crates/swc/tests/tsc-references/preserveValueImports_es2015.1.normal.js index aaef614f7ab..08f69850f53 100644 --- a/crates/swc/tests/tsc-references/preserveValueImports_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/preserveValueImports_es2015.1.normal.js @@ -1,3 +1,5 @@ +// @Filename: b.ts +import { D } from "./a"; // @preserveValueImports: true // @isolatedModules: true,false // @module: esnext diff --git a/crates/swc/tests/tsc-references/preserveValueImports_es2015.2.minified.js b/crates/swc/tests/tsc-references/preserveValueImports_es2015.2.minified.js index 1802ae93cde..275de1d703b 100644 --- a/crates/swc/tests/tsc-references/preserveValueImports_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/preserveValueImports_es2015.2.minified.js @@ -1,3 +1,4 @@ +import { D } from "./a"; export default {}; export const b = 0; export const c = 1; diff --git a/crates/swc/tests/tsc-references/preserveValueImports_es5.1.normal.js b/crates/swc/tests/tsc-references/preserveValueImports_es5.1.normal.js index d4897f0d4f2..5a3cdbf6095 100644 --- a/crates/swc/tests/tsc-references/preserveValueImports_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/preserveValueImports_es5.1.normal.js @@ -1,3 +1,5 @@ +// @Filename: b.ts +import { D } from "./a"; // @preserveValueImports: true // @isolatedModules: true,false // @module: esnext diff --git a/crates/swc/tests/tsc-references/preserveValueImports_es5.2.minified.js b/crates/swc/tests/tsc-references/preserveValueImports_es5.2.minified.js index 13b0ff28186..03118c933e9 100644 --- a/crates/swc/tests/tsc-references/preserveValueImports_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/preserveValueImports_es5.2.minified.js @@ -1,3 +1,4 @@ +import { D } from "./a"; export default {}; export var b = 0; export var c = 1; diff --git a/crates/swc/tests/tsc-references/reexportClassDefinition_es2015.1.normal.js b/crates/swc/tests/tsc-references/reexportClassDefinition_es2015.1.normal.js index 13a4a756992..d2bcaa4ba90 100644 --- a/crates/swc/tests/tsc-references/reexportClassDefinition_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/reexportClassDefinition_es2015.1.normal.js @@ -8,7 +8,5 @@ const foo1 = require('./foo1'); const foo2 = require('./foo2'); class x extends foo2.x { } -module.exports = { - x: foo1 -}; +module.exports = x; export { }; diff --git a/crates/swc/tests/tsc-references/reexportClassDefinition_es2015.2.minified.js b/crates/swc/tests/tsc-references/reexportClassDefinition_es2015.2.minified.js index 3b9a4adfc94..229100316c8 100644 --- a/crates/swc/tests/tsc-references/reexportClassDefinition_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/reexportClassDefinition_es2015.2.minified.js @@ -1,7 +1,8 @@ -let foo1 = require('./foo1'), foo2 = require('./foo2'); +class x { +} +require('./foo1'); +let foo2 = require('./foo2'); class x extends foo2.x { } -module.exports = { - x: foo1 -}; +module.exports = x; export { }; diff --git a/crates/swc/tests/tsc-references/reexportClassDefinition_es5.1.normal.js b/crates/swc/tests/tsc-references/reexportClassDefinition_es5.1.normal.js index c20318e72f2..9fdffad640e 100644 --- a/crates/swc/tests/tsc-references/reexportClassDefinition_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/reexportClassDefinition_es5.1.normal.js @@ -21,7 +21,5 @@ var x = /*#__PURE__*/ function(_x) { } return x; }(foo2.x); -module.exports = { - x: foo1 -}; +module.exports = x; export { }; diff --git a/crates/swc/tests/tsc-references/reexportClassDefinition_es5.2.minified.js b/crates/swc/tests/tsc-references/reexportClassDefinition_es5.2.minified.js index 3209a5372ed..d64d4fc3309 100644 --- a/crates/swc/tests/tsc-references/reexportClassDefinition_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/reexportClassDefinition_es5.2.minified.js @@ -4,7 +4,9 @@ import _create_super from "@swc/helpers/src/_create_super.mjs"; var x = function() { "use strict"; _class_call_check(this, x); -}, foo1 = require("./foo1"), foo2 = require("./foo2"), x = function(_x) { +}; +require("./foo1"); +var x = function(_x) { "use strict"; _inherits(x, _x); var _super = _create_super(x); @@ -12,7 +14,5 @@ var x = function() { return _class_call_check(this, x), _super.apply(this, arguments); } return x; -}(foo2.x); -module.exports = { - x: foo1 -}; +}(require("./foo2").x); +module.exports = x; diff --git a/crates/swc/tests/vercel/full/react-autosuggest/1/output/index.js b/crates/swc/tests/vercel/full/react-autosuggest/1/output/index.js index aed80f431a0..7ce21c9debf 100644 --- a/crates/swc/tests/vercel/full/react-autosuggest/1/output/index.js +++ b/crates/swc/tests/vercel/full/react-autosuggest/1/output/index.js @@ -1,4 +1,7 @@ "use strict"; +Object.defineProperty(exports, "__esModule", { + value: !0 +}); var _instanceof = require("@swc/helpers/lib/_instanceof.js").default; Object.defineProperty(exports, "__esModule", { value: !0 diff --git a/crates/swc/tests/vercel/full/react-autowhatever/1/output/index.js b/crates/swc/tests/vercel/full/react-autowhatever/1/output/index.js index 68bd353ed18..a91d2fbd02d 100644 --- a/crates/swc/tests/vercel/full/react-autowhatever/1/output/index.js +++ b/crates/swc/tests/vercel/full/react-autowhatever/1/output/index.js @@ -1,7 +1,12 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: !0 -}), exports.default = void 0; +}), Object.defineProperty(exports, "default", { + get: function() { + return k; + }, + enumerable: !0 +}); var a = require("@swc/helpers/lib/_class_call_check.js").default, b = require("@swc/helpers/lib/_inherits.js").default, c = require("@swc/helpers/lib/_interop_require_default.js").default, d = require("@swc/helpers/lib/_interop_require_wildcard.js").default, e = require("@swc/helpers/lib/_object_spread.js").default, f = require("@swc/helpers/lib/_object_spread_props.js").default, g = require("@swc/helpers/lib/_create_super.js").default, h = require("react/jsx-runtime"), i = d(require("react")), j = c(require("prop-types")), k = function(c) { "use strict"; b(k, c); @@ -17,7 +22,7 @@ var a = require("@swc/helpers/lib/_class_call_check.js").default, b = require("@ return !0; }, i.render = function() { var a = this, b = this.props, c = b.items, d = b.itemProps, g = b.renderItem, i = b.renderItemData, j = b.sectionIndex, k = b.highlightedItemIndex, l = b.getItemId, m = b.theme, n = b.keyPrefix, o = null === j ? n : "".concat(n, "section-").concat(j, "-"), p = "function" == typeof d; - return h.jsx("ul", f(e({ + return (0, h.jsx)("ul", f(e({ role: "listbox" }, m("".concat(o, "items-list"), "itemsList")), { children: c.map(function(b, c) { @@ -28,7 +33,7 @@ var a = require("@swc/helpers/lib/_class_call_check.js").default, b = require("@ id: l(j, c), "aria-selected": n }, m(q, "item", 0 === c && "itemFirst", n && "itemHighlighted"), r); - return n && (s.ref = a.storeHighlightedItemReference), h.jsx(Item, f(e({}, s), { + return n && (s.ref = a.storeHighlightedItemReference), (0, h.jsx)(Item, f(e({}, s), { sectionIndex: j, isHighlighted: n, itemIndex: c, @@ -56,4 +61,4 @@ k.propTypes = { keyPrefix: j.default.string.isRequired }, k.defaultProps = { sectionIndex: null -}, new k(), exports.default = k; +}, new k(); diff --git a/crates/swc/tests/vercel/full/react-autowhatever/2/output/index.js b/crates/swc/tests/vercel/full/react-autowhatever/2/output/index.js index 01161e66929..f509703f113 100644 --- a/crates/swc/tests/vercel/full/react-autowhatever/2/output/index.js +++ b/crates/swc/tests/vercel/full/react-autowhatever/2/output/index.js @@ -1,7 +1,12 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: !0 -}), exports.default = void 0; +}), Object.defineProperty(exports, "default", { + get: function() { + return i; + }, + enumerable: !0 +}); var a = require("@swc/helpers/lib/_class_call_check.js").default, b = require("@swc/helpers/lib/_inherits.js").default, c = require("@swc/helpers/lib/_interop_require_wildcard.js").default, d = require("@swc/helpers/lib/_object_spread.js").default, e = require("@swc/helpers/lib/_object_spread_props.js").default, f = require("@swc/helpers/lib/_create_super.js").default, g = require("react/jsx-runtime"), h = c(require("react")), i = function(c) { "use strict"; b(i, c); @@ -19,7 +24,7 @@ var a = require("@swc/helpers/lib/_class_call_check.js").default, b = require("@ ]); }, j.render = function() { var a = this, b = this.props, c = b.items, f = b.itemProps, h = b.renderItem, i = b.renderItemData, j = b.sectionIndex, k = b.highlightedItemIndex, l = b.getItemId, m = b.theme, n = b.keyPrefix, o = null === j ? n : "".concat(n, "section-").concat(j, "-"), p = "function" == typeof f; - return g.jsx("ul", e(d({ + return (0, g.jsx)("ul", e(d({ role: "listbox" }, m("".concat(o, "items-list"), "itemsList")), { children: c.map(function(b, c) { @@ -30,7 +35,7 @@ var a = require("@swc/helpers/lib/_class_call_check.js").default, b = require("@ id: l(j, c), "aria-selected": n }, m(q, "item", 0 === c && "itemFirst", n && "itemHighlighted"), r); - return n && (s.ref = a.storeHighlightedItemReference), g.jsx(Item, e(d({}, s), { + return n && (s.ref = a.storeHighlightedItemReference), (0, g.jsx)(Item, e(d({}, s), { sectionIndex: j, isHighlighted: n, itemIndex: c, @@ -46,4 +51,4 @@ i.propTypes = { items: 500 }, i.defaultProps = { sectionIndex: null -}, new i(), exports.default = i; +}, new i(); diff --git a/crates/swc_ecma_ast/src/expr.rs b/crates/swc_ecma_ast/src/expr.rs index ad48631ddb8..31decf29636 100644 --- a/crates/swc_ecma_ast/src/expr.rs +++ b/crates/swc_ecma_ast/src/expr.rs @@ -301,6 +301,12 @@ pub enum PropOrSpread { Prop(Box), } +impl From for PropOrSpread { + fn from(p: Prop) -> Self { + Self::Prop(Box::new(p)) + } +} + #[ast_node("SpreadElement")] #[derive(Eq, Hash, EqIgnoreSpan)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] @@ -948,6 +954,15 @@ pub enum BlockStmtOrExpr { Expr(Box), } +impl From for BlockStmtOrExpr +where + T: Into, +{ + fn from(e: T) -> Self { + Self::Expr(Box::new(e.into())) + } +} + impl Take for BlockStmtOrExpr { fn dummy() -> Self { BlockStmtOrExpr::Expr(Take::dummy()) @@ -1001,6 +1016,18 @@ pub enum PatOrExpr { Pat(Box), } +impl From for PatOrExpr { + fn from(p: Pat) -> Self { + Self::Pat(Box::new(p)) + } +} + +impl From for PatOrExpr { + fn from(e: Expr) -> Self { + Self::Expr(Box::new(e)) + } +} + impl PatOrExpr { /// Returns the [Pat] if this is a pattern, otherwise returns [None]. pub fn pat(self) -> Option> { diff --git a/crates/swc_ecma_ast/src/module_decl.rs b/crates/swc_ecma_ast/src/module_decl.rs index 565fa61c9f2..cf1f41c2587 100644 --- a/crates/swc_ecma_ast/src/module_decl.rs +++ b/crates/swc_ecma_ast/src/module_decl.rs @@ -113,6 +113,16 @@ pub struct ExportAll { pub asserts: Option, } +impl Take for ExportAll { + fn dummy() -> Self { + Self { + span: DUMMY_SP, + src: Take::dummy(), + asserts: Take::dummy(), + } + } +} + /// `export { foo } from 'mod'` /// `export { foo as bar } from 'mod'` #[ast_node("ExportNamedDeclaration")] @@ -133,6 +143,18 @@ pub struct NamedExport { pub asserts: Option, } +impl Take for NamedExport { + fn dummy() -> Self { + Self { + span: DUMMY_SP, + specifiers: Take::dummy(), + src: Take::dummy(), + type_only: Default::default(), + asserts: Take::dummy(), + } + } +} + #[ast_node("ExportDefaultDeclaration")] #[derive(Eq, Hash, EqIgnoreSpan)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] diff --git a/crates/swc_ecma_preset_env/benches/polyfills.rs b/crates/swc_ecma_preset_env/benches/polyfills.rs index 99f2364787f..99a8ab30124 100644 --- a/crates/swc_ecma_preset_env/benches/polyfills.rs +++ b/crates/swc_ecma_preset_env/benches/polyfills.rs @@ -23,6 +23,7 @@ fn run(b: &mut Bencher, src: &str, config: Config) { Some(SingleThreadedComments::default()), config, Default::default(), + &mut Default::default(), ); b.iter(|| black_box(module.clone().fold_with(&mut folder))); diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 8e453855ccf..40cd37f990e 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -15,6 +15,7 @@ use swc_ecma_transforms::{ bugfixes, es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es3, regexp::{self, regexp}, }, + feature::FeatureFlag, pass::{noop, Optional}, Assumptions, }; @@ -35,6 +36,7 @@ pub fn preset_env( comments: Option, c: Config, assumptions: Assumptions, + feature_set: &mut FeatureFlag, ) -> impl Fold where C: Comments + Clone, @@ -67,6 +69,11 @@ where let f = transform_data::Feature::$feature; let enable = should_enable!($feature, $default); + + if !enable { + *feature_set |= swc_ecma_transforms::feature::FeatureFlag::$feature; + } + if c.debug { println!("{}: {:?}", f.as_str(), enable); } diff --git a/crates/swc_ecma_preset_env/tests/test.rs b/crates/swc_ecma_preset_env/tests/test.rs index 1f802ccb94e..85debdf3116 100644 --- a/crates/swc_ecma_preset_env/tests/test.rs +++ b/crates/swc_ecma_preset_env/tests/test.rs @@ -149,7 +149,8 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { targets: c.targets, path: std::env::current_dir().unwrap(), }, - Default::default() + Default::default(), + &mut Default::default(), ), fixer(None) ); diff --git a/crates/swc_ecma_transforms/src/lib.rs b/crates/swc_ecma_transforms/src/lib.rs index 049ad797b22..fe0ea058caf 100644 --- a/crates/swc_ecma_transforms/src/lib.rs +++ b/crates/swc_ecma_transforms/src/lib.rs @@ -3,7 +3,7 @@ #![deny(unused)] pub use swc_ecma_transforms_base::{ - assumptions::Assumptions, fixer, helpers, hygiene, pass, perf, resolver, + assumptions::Assumptions, feature, fixer, helpers, hygiene, pass, perf, resolver, }; #[cfg(feature = "swc_ecma_transforms_compat")] #[cfg_attr(docsrs, doc(cfg(feature = "compat")))] diff --git a/crates/swc_ecma_transforms/tests/decorators.rs b/crates/swc_ecma_transforms/tests/decorators.rs index 16b4384367d..be9e09334c3 100644 --- a/crates/swc_ecma_transforms/tests/decorators.rs +++ b/crates/swc_ecma_transforms/tests/decorators.rs @@ -3875,7 +3875,7 @@ test!( no_interop: true, ..Default::default() }, - None + Default::default() ), ), issue_395_1, @@ -3892,7 +3892,7 @@ class Demo { " \"use strict\"; var _moduleAJs = require(\"./moduleA.js\"); -let Demo = _decorate([(0, _moduleAJs).default('0.0.1')], function(_initialize) { +let Demo = _decorate([(0, _moduleAJs.default)('0.0.1')], function(_initialize) { class Demo{ constructor(){ _initialize(this); @@ -3920,7 +3920,7 @@ test!( no_interop: true, ..Default::default() }, - None + Default::default(), ), ), issue_395_2, @@ -3935,17 +3935,18 @@ export default Test ", " \"use strict\"; -Object.defineProperty(exports, \"__esModule\", { - value: true +Object.defineProperty(exports, \"default\", { + get: function() { + return _default; + }, + enumerable: true }); -exports.default = void 0; const Test = (version)=>{ return (target)=>{ target.version = version; }; }; var _default = Test; -exports.default = _default; " ); @@ -4281,7 +4282,11 @@ test!( }), classes(Some(t.comments.clone()), Default::default()), function_name(), - common_js(Mark::fresh(Mark::root()), Default::default(), None), + common_js( + Mark::fresh(Mark::root()), + Default::default(), + Default::default(), + ), ) }, function_name_modules, @@ -4299,7 +4304,9 @@ console.log(new Template().events()); "#, r#" "use strict"; - +Object.defineProperty(exports, "__esModule", { + value: true +}); var _events = _interopRequireDefault(require("events")); let Template = diff --git a/crates/swc_ecma_transforms/tests/es2015_function_name.rs b/crates/swc_ecma_transforms/tests/es2015_function_name.rs index a7bd6f48dd3..87583bd1db7 100644 --- a/crates/swc_ecma_transforms/tests/es2015_function_name.rs +++ b/crates/swc_ecma_transforms/tests/es2015_function_name.rs @@ -287,7 +287,7 @@ test!( legacy: true, ..Default::default() }), - common_js(unresolved_mark, Default::default(), None) + common_js(unresolved_mark, Default::default(), Default::default(),) ) }, function_name_modules_3, @@ -307,7 +307,13 @@ export default class Login extends React.Component { Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; + +Object.defineProperty(exports, "default", { + get: function() { + return Login; + }, + enumerable: true +}); var _store = require("./store"); @@ -325,14 +331,12 @@ function (_Component) { _createClass(Login, [{ key: "getForm", value: function getForm() { - return (0, _store).getForm().toJS(); + return (0, _store.getForm)().toJS(); } }]); return Login; }(React.Component); -exports.default = Login; - "# ); @@ -376,7 +380,11 @@ test!( arrow(), shorthand(), function_name(), - common_js(Mark::fresh(Mark::root()), Default::default(), None) + common_js( + Mark::fresh(Mark::root()), + Default::default(), + Default::default() + ) ), function_name_export_default_arrow_renaming, r#" @@ -907,7 +915,7 @@ test!( }), classes(Some(t.comments.clone()), Default::default()), function_name(), - common_js(unresolved_mark, Default::default(), None) + common_js(unresolved_mark, Default::default(), Default::default()) ) }, function_name_modules_2, diff --git a/crates/swc_ecma_transforms_base/Cargo.toml b/crates/swc_ecma_transforms_base/Cargo.toml index da5fb695b88..fee6176fa9d 100644 --- a/crates/swc_ecma_transforms_base/Cargo.toml +++ b/crates/swc_ecma_transforms_base/Cargo.toml @@ -13,36 +13,33 @@ version = "0.89.6" bench = false [features] -concurrent = [ - "concurrent-renamer", - "rayon", - "swc_ecma_utils/concurrent", -] +concurrent = ["concurrent-renamer", "rayon", "swc_ecma_utils/concurrent"] concurrent-renamer = ["rayon"] [dependencies] -better_scoped_tls = {version = "0.1.0", path = "../better_scoped_tls"} +better_scoped_tls = { version = "0.1.0", path = "../better_scoped_tls" } +bitflags = "1" num_cpus = "1.13.1" once_cell = "1.10.0" -phf = {version = "0.10", features = ["macros"]} -rayon = {version = "1", optional = true} +phf = { version = "0.10", features = ["macros"] } +rayon = { version = "1", optional = true } rustc-hash = "1.1.0" -serde = {version = "1", features = ["derive"]} +serde = { version = "1", features = ["derive"] } smallvec = "1.8.0" -swc_atoms = {version = "0.2", path = "../swc_atoms"} -swc_common = {version = "0.18.0", path = "../swc_common"} -swc_ecma_ast = {version = "0.79.0", path = "../swc_ecma_ast"} -swc_ecma_parser = {version = "0.105.0", path = "../swc_ecma_parser"} -swc_ecma_utils = {version = "0.86.0", path = "../swc_ecma_utils"} -swc_ecma_visit = {version = "0.65.0", path = "../swc_ecma_visit"} +swc_atoms = { version = "0.2", path = "../swc_atoms" } +swc_common = { version = "0.18.0", path = "../swc_common" } +swc_ecma_ast = { version = "0.79.0", path = "../swc_ecma_ast" } +swc_ecma_parser = { version = "0.105.0", path = "../swc_ecma_parser" } +swc_ecma_utils = { version = "0.86.0", path = "../swc_ecma_utils" } +swc_ecma_visit = { version = "0.65.0", path = "../swc_ecma_visit" } tracing = "0.1.32" [dev-dependencies] criterion = "0.3" -swc_ecma_codegen = {version = "0.109.0", path = "../swc_ecma_codegen"} -swc_ecma_transforms_macros = {version = "0.5.0", path = "../swc_ecma_transforms_macros"} -swc_node_base = {version = "0.5.5", path = "../swc_node_base"} -testing = {version = "0.20.0", path = "../testing"} +swc_ecma_codegen = { version = "0.109.0", path = "../swc_ecma_codegen" } +swc_ecma_transforms_macros = { version = "0.5.0", path = "../swc_ecma_transforms_macros" } +swc_node_base = { version = "0.5.5", path = "../swc_node_base" } +testing = { version = "0.20.0", path = "../testing" } [[bench]] harness = false diff --git a/crates/swc_ecma_transforms_base/src/feature.rs b/crates/swc_ecma_transforms_base/src/feature.rs new file mode 100644 index 00000000000..ad48c9506f7 --- /dev/null +++ b/crates/swc_ecma_transforms_base/src/feature.rs @@ -0,0 +1,246 @@ +#![allow(non_upper_case_globals)] +use bitflags::bitflags; +use swc_ecma_ast::EsVersion::{self, *}; + +bitflags! { + #[derive(Default)] + pub struct FeatureFlag: u64 { + /// `transform-template-literals` + const TemplateLiterals = 1 << 0; + + /// `transform-literals` + const Literals = 1 << 1; + + /// `transform-function-name` + const FunctionName = 1 << 2; + + /// `transform-arrow-functions` + const ArrowFunctions = 1 << 3; + + /// `transform-block-scoped-functions` + const BlockScopedFunctions = 1 << 4; + + /// `transform-classes` + const Classes = 1 << 5; + + /// `transform-object-super` + const ObjectSuper = 1 << 6; + + /// `transform-shorthand-properties` + const ShorthandProperties = 1 << 7; + + /// `transform-duplicate-keys` + const DuplicateKeys = 1 << 8; + + /// `transform-computed-properties` + const ComputedProperties = 1 << 9; + + /// `transform-for-of` + const ForOf = 1 << 10; + + /// `transform-sticky-regex` + const StickyRegex = 1 << 11; + + /// `transform-dotall-regex` + const DotAllRegex = 1 << 12; + + /// `transform-unicode-regex` + const UnicodeRegex = 1 << 13; + + /// `transform-spread` + const Spread = 1 << 14; + + /// `transform-parameters` + const Parameters = 1 << 15; + + /// `transform-destructuring` + const Destructuring = 1 << 16; + + /// `transform-block-scoping` + const BlockScoping = 1 << 17; + + /// `transform-typeof-symbol` + const TypeOfSymbol = 1 << 18; + + /// `transform-new-target` + const NewTarget = 1 << 19; + + /// `transform-regenerator` + const Regenerator = 1 << 20; + + /// `transform-exponentiation-operator` + const ExponentiationOperator = 1 << 21; + + /// `transform-async-to-generator` + const AsyncToGenerator = 1 << 22; + + /// `proposal-async-generator-functions` + const AsyncGeneratorFunctions = 1 << 23; + + /// `proposal-object-rest-spread` + const ObjectRestSpread = 1 << 24; + + /// `proposal-unicode-property-regex` + const UnicodePropertyRegex = 1 << 25; + + /// `proposal-json-strings` + const JsonStrings = 1 << 26; + + /// `proposal-optional-catch-binding` + const OptionalCatchBinding = 1 << 27; + + /// `transform-named-capturing-groups-regex` + const NamedCapturingGroupsRegex = 1 << 28; + + /// `transform-member-expression-literals` + const MemberExpressionLiterals = 1 << 29; + + /// `transform-property-literals` + const PropertyLiterals = 1 << 30; + + /// `transform-reserved-words` + const ReservedWords = 1 << 31; + + /// `proposal-export-namespace-from` + const ExportNamespaceFrom = 1 << 32; + + /// `proposal-nullish-coalescing-operator` + const NullishCoalescing = 1 << 33; + + /// `proposal-logical-assignment-operators` + const LogicalAssignmentOperators = 1 << 34; + + /// `proposal-optional-chaining` + const OptionalChaining = 1 << 35; + + /// `proposal-class-properties` + const ClassProperties = 1 << 36; + + /// `proposal-numeric-separator` + const NumericSeparator = 1 << 37; + + /// `proposal-private-methods` + const PrivateMethods = 1 << 38; + + /// `proposal-class-static-block` + const ClassStaticBlock = 1 << 39; + + /// `proposal-private-property-in-object` + const PrivatePropertyInObject = 1 << 40; + + /// `transform-unicode-escapes` + const UnicodeEscapes = 1 << 41; + + /// `bugfix/transform-async-arrows-in-class` + const BugfixAsyncArrowsInClass = 1 << 42; + + /// `bugfix/transform-edge-default-parameters` + const BugfixEdgeDefaultParam = 1 << 43; + + /// `bugfix/transform-tagged-template-caching` + const BugfixTaggedTemplateCaching = 1 << 44; + + /// `bugfix/transform-safari-id-destructuring-collision-in-function-expression` + const BugfixSafariIdDestructuringCollisionInFunctionExpression = 1 << 45; + + /// `bugfix/transform-edge-function-name` + const BugfixTransformEdgeFunctionName = 1 << 46; // TODO + + /// `bugfix/transform-safari-block-shadowing` + const BugfixTransformSafariBlockShadowing = 1 << 47; // TODO + + /// `bugfix/transform-safari-for-shadowing` + const BugfixTransformSafariForShadowing = 1 << 48; // TODO + + /// `bugfix/transform-v8-spread-parameters-in-optional-chaining` + const BugfixTransformV8SpreadParametersInOptionalChaining = 1 << 49; // TODO + } +} + +pub fn enable_available_feature_from_es_version(version: EsVersion) -> FeatureFlag { + let mut feature = FeatureFlag::empty(); + + if version < Es5 { + return feature; + } + + feature |= FeatureFlag::PropertyLiterals + | FeatureFlag::MemberExpressionLiterals + | FeatureFlag::ReservedWords; + + if version < Es2015 { + return feature; + } + + feature |= FeatureFlag::ArrowFunctions + | FeatureFlag::BlockScopedFunctions + | FeatureFlag::BlockScoping + | FeatureFlag::Classes + | FeatureFlag::ComputedProperties + | FeatureFlag::Destructuring + | FeatureFlag::DuplicateKeys + | FeatureFlag::ForOf + | FeatureFlag::FunctionName + | FeatureFlag::NewTarget + | FeatureFlag::ObjectSuper + | FeatureFlag::Parameters + | FeatureFlag::Regenerator + | FeatureFlag::ShorthandProperties + | FeatureFlag::Spread + | FeatureFlag::StickyRegex + | FeatureFlag::TemplateLiterals + | FeatureFlag::TypeOfSymbol + | FeatureFlag::UnicodeRegex; + + if version < Es2016 { + return feature; + } + + feature |= FeatureFlag::ExponentiationOperator; + + if version < Es2017 { + return feature; + } + + // support `async` + feature |= FeatureFlag::AsyncToGenerator; + + if version < Es2018 { + return feature; + } + + feature |= FeatureFlag::ObjectRestSpread + | FeatureFlag::DotAllRegex + | FeatureFlag::NamedCapturingGroupsRegex + | FeatureFlag::UnicodePropertyRegex; + + if version < Es2019 { + return feature; + } + + feature |= FeatureFlag::OptionalCatchBinding; + + if version < Es2020 { + return feature; + } + + feature |= FeatureFlag::ExportNamespaceFrom + | FeatureFlag::NullishCoalescing + | FeatureFlag::OptionalChaining; + + if version < Es2021 { + return feature; + } + + feature |= FeatureFlag::LogicalAssignmentOperators; + + if version < Es2022 { + return feature; + } + + feature |= FeatureFlag::ClassProperties + | FeatureFlag::ClassStaticBlock + | FeatureFlag::PrivatePropertyInObject; + + feature +} diff --git a/crates/swc_ecma_transforms_base/src/helpers/_export_star.js b/crates/swc_ecma_transforms_base/src/helpers/_export_star.js new file mode 100644 index 00000000000..5646e14c9cb --- /dev/null +++ b/crates/swc_ecma_transforms_base/src/helpers/_export_star.js @@ -0,0 +1,12 @@ +function _exportStar(from, to) { + Object.keys(from).forEach(function (k) { + if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) + Object.defineProperty(to, k, { + enumerable: true, + get: function () { + return from[k]; + }, + }); + }); + return from; +} diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index 96d8cbef8fd..cec422304d6 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -264,6 +264,7 @@ define_helpers!(Helpers { defaults: (), define_enumerable_properties: (), define_property: (), + export_star: (), extends: (), get: (super_prop_base), get_prototype_of: (), diff --git a/crates/swc_ecma_transforms_base/src/lib.rs b/crates/swc_ecma_transforms_base/src/lib.rs index e73333ff533..402ce8b8767 100644 --- a/crates/swc_ecma_transforms_base/src/lib.rs +++ b/crates/swc_ecma_transforms_base/src/lib.rs @@ -8,6 +8,7 @@ pub mod fixer; #[macro_use] pub mod hygiene; pub mod assumptions; +pub mod feature; pub mod helpers; #[doc(hidden)] pub mod native; diff --git a/crates/swc_ecma_transforms_module/Cargo.toml b/crates/swc_ecma_transforms_module/Cargo.toml index b989ae257f2..4aebeb8a57c 100644 --- a/crates/swc_ecma_transforms_module/Cargo.toml +++ b/crates/swc_ecma_transforms_module/Cargo.toml @@ -16,6 +16,7 @@ bench = false Inflector = "0.11.4" ahash = "0.7.4" anyhow = "1.0.41" +bitflags = "1" indexmap = "1.8.0" path-clean = "0.1.0" pathdiff = "0.2.0" diff --git a/crates/swc_ecma_transforms_module/src/amd.rs b/crates/swc_ecma_transforms_module/src/amd.rs index 4cd7d2bc349..697d674cff6 100644 --- a/crates/swc_ecma_transforms_module/src/amd.rs +++ b/crates/swc_ecma_transforms_module/src/amd.rs @@ -1,85 +1,23 @@ -use std::{ - cell::{Ref, RefCell, RefMut}, - iter, -}; - use anyhow::Context; -use indexmap::IndexSet; use serde::{Deserialize, Serialize}; -use swc_atoms::js_word; -use swc_common::{FileName, Mark, Span, DUMMY_SP}; +use swc_atoms::{js_word, JsWord}; +use swc_common::{util::take::Take, FileName, Mark, Span, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_transforms_base::helper; +use swc_ecma_transforms_base::{feature::FeatureFlag, helper, helper_expr}; use swc_ecma_utils::{ - prepend_stmts, private_ident, quote_ident, quote_str, var::VarCollector, DestructuringFinder, - ExprFactory, + member_expr, private_ident, quote_ident, quote_str, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{noop_fold_type, Fold, FoldWith, Visit, VisitWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; -use super::util::{ - self, define_es_module, define_property, has_use_strict, initialize_to_undefined, - local_name_for_src, make_descriptor, use_strict, Exports, ModulePass, Scope, +pub use super::util::Config as InnerConfig; +use crate::{ + module_decl_strip::{Export, Link, LinkFlag, LinkItem, LinkSpecifierReducer, ModuleDeclStrip}, + module_ref_rewriter::{ImportMap, ModuleRefRewriter}, + path::{ImportResolver, Resolver}, + util::{ + clone_first_use_strict, define_es_module, emit_export_stmts, local_name_for_src, use_strict, + }, }; -use crate::path::{ImportResolver, Resolver}; - -pub fn amd(config: Config) -> impl Fold { - Amd { - config, - in_top_level: Default::default(), - scope: RefCell::new(Default::default()), - exports: Default::default(), - - resolver: Resolver::Default, - vars: Default::default(), - } -} - -pub fn amd_with_resolver( - resolver: Box, - base: FileName, - config: Config, -) -> impl Fold { - Amd { - config, - in_top_level: Default::default(), - scope: Default::default(), - exports: Default::default(), - - resolver: Resolver::Real { base, resolver }, - vars: Default::default(), - } -} - -struct LocalScopedRequireVisitor { - pub require_ident: Option, -} - -impl LocalScopedRequireVisitor { - pub fn new() -> Self { - LocalScopedRequireVisitor { - require_ident: Default::default(), - } - } -} - -impl Visit for LocalScopedRequireVisitor { - fn visit_ident(&mut self, ident: &Ident) { - if self.require_ident.is_none() && &*ident.sym == "require" { - self.require_ident = Some(ident.clone()); - } - } -} - -struct Amd { - config: Config, - in_top_level: bool, - scope: RefCell, - exports: Exports, - - resolver: Resolver, - - vars: RefCell>, -} #[derive(Debug, Clone, Default, Serialize, Deserialize)] #[serde(deny_unknown_fields, rename_all = "camelCase")] @@ -88,875 +26,456 @@ pub struct Config { pub module_id: Option, #[serde(flatten, default)] - pub config: util::Config, + pub config: InnerConfig, } -/// TODO: VisitMut -impl Fold for Amd { - noop_fold_type!(); +pub fn amd( + unresolved_mark: Mark, + config: Config, + available_features: FeatureFlag, +) -> impl Fold + VisitMut { + let Config { module_id, config } = config; - mark_as_nested!(); + as_folder(Amd { + module_id, + config, + unresolved_mark, + resolver: Resolver::Default, + available_features, + support_arrow: caniuse!(available_features.ArrowFunctions), + const_var_kind: if caniuse!(available_features.BlockScoping) { + VarDeclKind::Const + } else { + VarDeclKind::Var + }, - fn fold_expr(&mut self, expr: Expr) -> Expr { - let top_level = self.in_top_level; + dep_list: Default::default(), + require: quote_ident!(DUMMY_SP.apply_mark(unresolved_mark), "require"), + exports: None, + module: None, + found_import_meta: false, + }) +} - Scope::fold_expr(self, self.exports.0.clone(), top_level, expr) - } +pub fn amd_with_resolver( + resolver: Box, + base: FileName, + unresolved_mark: Mark, + config: Config, + available_features: FeatureFlag, +) -> impl Fold + VisitMut { + let Config { module_id, config } = config; - fn fold_module(&mut self, module: Module) -> Module { - let mut local_scoped_require_visitor = LocalScopedRequireVisitor::new(); - module.visit_with(&mut local_scoped_require_visitor); + as_folder(Amd { + module_id, + config, + unresolved_mark, + resolver: Resolver::Real { base, resolver }, + available_features, + support_arrow: caniuse!(available_features.ArrowFunctions), + const_var_kind: if caniuse!(available_features.BlockScoping) { + VarDeclKind::Const + } else { + VarDeclKind::Var + }, - let items = module.body; - self.in_top_level = true; + dep_list: Default::default(), + require: quote_ident!(DUMMY_SP.apply_mark(unresolved_mark), "require"), + exports: None, + module: None, + found_import_meta: false, + }) +} - // Inserted after initializing exported names to undefined. - let mut extra_stmts = vec![]; - let mut stmts = Vec::with_capacity(items.len() + 3); - if self.config.config.strict_mode && !has_use_strict(&items) { - stmts.push(use_strict()); +pub struct Amd { + module_id: Option, + config: InnerConfig, + unresolved_mark: Mark, + resolver: Resolver, + + available_features: FeatureFlag, + support_arrow: bool, + const_var_kind: VarDeclKind, + + dep_list: Vec<(Ident, JsWord, Span)>, + require: Ident, + exports: Option, + module: Option, + found_import_meta: bool, +} + +impl VisitMut for Amd { + noop_visit_mut_type!(); + + fn visit_mut_module_items(&mut self, n: &mut Vec) { + let mut strip = ModuleDeclStrip::default(); + n.visit_mut_with(&mut strip); + + let mut stmts: Vec = Vec::with_capacity(n.len() + 4); + + // "use strict"; + if self.config.strict_mode { + stmts.push(clone_first_use_strict(n).unwrap_or_else(use_strict)); } - let mut exports = vec![]; - let mut initialized = IndexSet::default(); - let mut export_alls = vec![]; - let mut emitted_esmodule = false; - let mut has_export = false; - let exports_ident = self.exports.0.clone(); - // We'll preserve local scoped `require` ident as amd's local require ident - // shadows global one - let scoped_local_require_ident = local_scoped_require_visitor - .require_ident - .unwrap_or_else(|| private_ident!("require")); + let ModuleDeclStrip { + link, + export, + export_assign, + has_module_decl, + .. + } = strip; - // Process items - for item in items { - let decl = match item { - ModuleItem::Stmt(stmt) => { - extra_stmts.push(stmt.fold_with(self)); - continue; - } - ModuleItem::ModuleDecl(decl) => decl, + let is_export_assign = export_assign.is_some(); + + if has_module_decl && !self.config.no_interop && !is_export_assign { + stmts.push(define_es_module(self.exports())) + } + + let mut import_map = Default::default(); + + stmts.extend( + self.handle_import_export(&mut import_map, link, export, is_export_assign) + .map(Into::into), + ); + + stmts.extend(n.take().into_iter().filter_map(|item| match item { + ModuleItem::Stmt(stmt) if !stmt.is_use_strict() => Some(stmt), + _ => None, + })); + + if let Some(export_assign) = export_assign { + let return_stmt = ReturnStmt { + span: DUMMY_SP, + arg: Some(export_assign), }; - match decl { - ModuleDecl::Import(import) => self.scope.borrow_mut().insert_import(import), - ModuleDecl::ExportAll(..) - | ModuleDecl::ExportDecl(..) - | ModuleDecl::ExportDefaultDecl(..) - | ModuleDecl::ExportDefaultExpr(..) - | ModuleDecl::ExportNamed(..) => { - has_export = true; - if !self.config.config.strict && !emitted_esmodule { - emitted_esmodule = true; - stmts.push(define_es_module(exports_ident.clone())); - } - - macro_rules! init_export { - ("default") => {{ - init_export!(js_word!("default")) - }}; - ($name:expr) => {{ - exports.push($name.clone()); - initialized.insert($name.clone()); - }}; - } - match decl { - // Function declaration cannot throw an error. - ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { - decl: DefaultDecl::Fn(..), - .. - }) => { - // initialized.insert(js_word!("default")); - } - - ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { - decl: DefaultDecl::TsInterfaceDecl(..), - .. - }) => {} - - ModuleDecl::ExportAll(ref export) => { - self.scope - .borrow_mut() - .import_types - .entry(export.src.value.clone()) - .and_modify(|v| *v = true); - } - - ModuleDecl::ExportDefaultDecl(..) | ModuleDecl::ExportDefaultExpr(..) => { - // TODO: Optimization (when expr cannot throw, `exports.default = - // void 0` is not required) - init_export!("default") - } - _ => {} - } - - match decl { - ModuleDecl::ExportAll(export) => export_alls.push(export), - ModuleDecl::ExportDecl(ExportDecl { - decl: decl @ Decl::Class(..), - .. - }) - | ModuleDecl::ExportDecl(ExportDecl { - decl: decl @ Decl::Fn(..), - .. - }) => { - let (ident, is_class) = match decl { - Decl::Class(ref c) => (c.ident.clone(), true), - Decl::Fn(ref f) => (f.ident.clone(), false), - _ => unreachable!(), - }; - - // - extra_stmts.push(Stmt::Decl(decl.fold_with(self))); - - let append_to: &mut Vec<_> = if is_class { - &mut extra_stmts - } else { - // Function declaration cannot throw - &mut stmts - }; - - append_to.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident.clone().make_member(ident.clone()), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt(), - ); - } - ModuleDecl::ExportDecl(ExportDecl { - decl: Decl::Var(var), - .. - }) => { - extra_stmts.push(Stmt::Decl(Decl::Var(var.clone().fold_with(self)))); - - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - var.decls.visit_with(&mut VarCollector { - to: &mut scope.declared_vars, - }); - - let mut found: Vec = vec![]; - for decl in var.decls { - let mut v = DestructuringFinder { found: &mut found }; - decl.visit_with(&mut v); - - for ident in found.drain(..) { - scope - .exported_bindings - .entry((ident.sym.clone(), ident.span.ctxt())) - .or_default() - .push((ident.sym.clone(), ident.span.ctxt())); - init_export!(ident.sym); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident.clone().make_member(ident.clone()), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt(), - ); - } - } - } - ModuleDecl::ExportDefaultDecl(decl) => match decl { - ExportDefaultDecl { - decl: DefaultDecl::Class(ClassExpr { ident, class }), - .. - } => { - let ident = ident.unwrap_or_else(|| private_ident!("_default")); - - extra_stmts.push(Stmt::Decl(Decl::Class(ClassDecl { - ident: ident.clone(), - class, - declare: false, - }))); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident - .clone() - .make_member(quote_ident!("default")), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt(), - ); - } - ExportDefaultDecl { - decl: DefaultDecl::Fn(FnExpr { ident, function }), - .. - } => { - let ident = ident.unwrap_or_else(|| private_ident!("_default")); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident - .clone() - .make_member(quote_ident!("default")), - )), - op: op!("="), - right: Box::new(ident.clone().into()), - } - .into_stmt(), - ); - - extra_stmts.push(Stmt::Decl(Decl::Fn( - FnDecl { - ident, - function, - declare: false, - } - .fold_with(self), - ))); - } - _ => {} - }, - - ModuleDecl::ExportDefaultExpr(ExportDefaultExpr { expr, .. }) => { - let ident = private_ident!("_default"); - - // We use extra statements because of the initialization - extra_stmts.push(Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: Some(expr.fold_with(self)), - definite: false, - }], - declare: false, - }))); - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident.clone().make_member(quote_ident!("default")), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt(), - ); - } - - // export { foo } from 'foo'; - ModuleDecl::ExportNamed(export) => { - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - let imported = export.src.clone().map(|src| { - scope.import_to_export(&src, !export.specifiers.is_empty()) - }); - drop(scope_ref_mut); - - stmts.reserve(export.specifiers.len()); - - for s in export.specifiers { - match s { - ExportSpecifier::Named(ExportNamedSpecifier { - orig, - exported, - is_type_only: false, - .. - }) => { - let orig = match orig { - ModuleExportName::Ident(ident) => ident, - ModuleExportName::Str(..) => { - unimplemented!("module string names unimplemented") - } - }; - let exported = match exported { - Some(ModuleExportName::Ident(ident)) => Some(ident), - Some(ModuleExportName::Str(..)) => { - unimplemented!("module string names unimplemented") - } - _ => None, - }; - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - let is_import_default = orig.sym == js_word!("default"); - - let key = (orig.sym.clone(), orig.span.ctxt()); - if scope.declared_vars.contains(&key) { - scope - .exported_bindings - .entry(key.clone()) - .or_default() - .push( - exported - .clone() - .map(|i| (i.sym.clone(), i.span.ctxt())) - .unwrap_or_else(|| { - (orig.sym.clone(), orig.span.ctxt()) - }), - ); - } - - if let Some(ref src) = export.src { - if is_import_default { - scope - .import_types - .entry(src.value.clone()) - .or_insert(false); - } - } - drop(scope_ref_mut); - let value = match imported { - Some(ref imported) => Box::new( - imported.clone().unwrap().make_member(orig.clone()), - ), - None => { - Box::new(Expr::Ident(orig.clone()).fold_with(self)) - } - }; - - // True if we are exporting our own stuff. - let is_value_ident = matches!(*value, Expr::Ident(..)); - - if is_value_ident { - let exported_symbol = exported - .as_ref() - .map(|e| e.sym.clone()) - .unwrap_or_else(|| orig.sym.clone()); - init_export!(exported_symbol); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident - .clone() - .make_member(exported.unwrap_or(orig)), - )), - op: op!("="), - right: value, - } - .into_stmt(), - ); - } else { - stmts.push( - define_property(vec![ - exports_ident.clone().as_arg(), - { - // export { foo } - // -> 'foo' - - // export { foo as bar } - // -> 'bar' - let i = exported.unwrap_or(orig); - Lit::Str(quote_str!(i.span, i.sym)).as_arg() - }, - make_descriptor(value).as_arg(), - ]) - .into_stmt(), - ); - } - } - - ExportSpecifier::Namespace(ExportNamespaceSpecifier { - span, - name, - }) => { - let name = match &name { - ModuleExportName::Ident(ident) => ident, - _ => { - unimplemented!("module string names unimplemented") - } - }; - - // Create exports.foo = void 0; - init_export!(name.sym); - - let id = if let Some(ref src) = export.src { - let mut scope = self.scope.borrow_mut(); - - let id = scope.import_to_export(src, true).unwrap(); - scope - .import_types - .entry(src.value.clone()) - .or_insert(true); - - id - } else { - unreachable!() - }; - - extra_stmts.push( - AssignExpr { - span, - op: op!("="), - left: PatOrExpr::Expr(Box::new( - self.exports - .0 - .clone() - .make_member(name.clone()), - )), - right: Box::new(id.into()), - } - .into_stmt(), - ); - } - - ExportSpecifier::Default(..) => { - unimplemented!("amd: export default from './foo'") - } - - _ => {} - } - } - } - - _ => {} - } - } - - ModuleDecl::TsImportEquals(TsImportEqualsDecl { - span, - declare: false, - is_type_only: false, - id, - module_ref: TsModuleRef::TsExternalModuleRef(src), - .. - }) => { - self.scope.borrow_mut().insert_import(ImportDecl { - span, - specifiers: vec![ImportSpecifier::Namespace(ImportStarAsSpecifier { - span: id.span, - local: id, - })], - src: src.expr, - type_only: false, - asserts: Default::default(), - }); - } - - ModuleDecl::TsExportAssignment(TsExportAssignment { span, expr }) => extra_stmts - .push( - ReturnStmt { - span, - arg: Some(expr), - } - .into(), - ), - _ => {} - } + stmts.push(return_stmt.into()) } - let vars = self.vars_take(); - - if !vars.is_empty() { - let var_stmt = Stmt::Decl( - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: false, - decls: vars, - } - .into(), - ); - - stmts.push(var_stmt); + if !self.config.ignore_dynamic || !self.config.preserve_import_meta { + stmts.visit_mut_children_with(self); } - // ==================== - // Handle imports - // ==================== - - // Prepended to statements. - let mut import_stmts = vec![]; - let mut define_deps_arg = ArrayLit { - span: DUMMY_SP, - elems: vec![], - }; - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - let mut factory_params = Vec::with_capacity(scope.imports.len() + 1); - - // inject local scoped `require` regardless of having exports or not, as long as - // it can be considered as module (either having import or export) - if !scope.imports.is_empty() || has_export { - define_deps_arg.elems.push(Some("require".as_arg())); - factory_params.push(Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: scoped_local_require_ident.into(), - }); - } - - if has_export { - define_deps_arg.elems.push(Some("exports".as_arg())); - factory_params.push(Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: exports_ident.clone().into(), - }); - } - - // Used only if export * exists - let exported_names = { - if !export_alls.is_empty() && !exports.is_empty() { - let exported_names = private_ident!("_exportNames"); - stmts.push(Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: exported_names.clone().into(), - init: Some(Box::new(Expr::Object(ObjectLit { - span: DUMMY_SP, - props: exports - .into_iter() - .filter_map(|export| { - if export == js_word!("default") { - return None; - } - - Some(PropOrSpread::Prop(Box::new(Prop::KeyValue( - KeyValueProp { - key: PropName::Ident(Ident::new(export, DUMMY_SP)), - value: true.into(), - }, - )))) - }) - .collect(), - }))), - definite: false, - }], - declare: false, - }))); - - Some(exported_names) - } else { - None - } - }; - - for export in export_alls { - let span = export.span; - let export = scope - .import_to_export(&export.src, true) - .expect("Export should exists"); - stmts.push(Scope::handle_export_all( - span, - exports_ident.clone(), - exported_names.clone(), - export, - )); - } - - if !initialized.is_empty() { - stmts.extend(initialize_to_undefined(exports_ident, initialized)); - } - - for (src, (_, import)) in scope.imports.drain(..) { - let import = import.unwrap_or_else(|| { - ( - local_name_for_src(&src), - DUMMY_SP.apply_mark(Mark::fresh(Mark::root())), - ) - }); - let ident = Ident::new(import.0.clone(), import.1); - - { - let src = match &self.resolver { - Resolver::Real { resolver, base } => resolver - .resolve_import(base, &src) - .with_context(|| format!("failed to resolve `{}`", src)) - .unwrap(), - Resolver::Default => src.clone(), - }; - - define_deps_arg.elems.push(Some(src.as_arg())); - } - factory_params.push(Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: ident.clone().into(), - }); - - { - // handle interop - let ty = scope.import_types.get(&src); - - if let Some(&wildcard) = ty { - if !self.config.config.no_interop { - let imported = ident.clone(); - let right = Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: if wildcard { - helper!(interop_require_wildcard, "interopRequireWildcard") - } else { - helper!(interop_require_default, "interopRequireDefault") - }, - args: vec![imported.as_arg()], - type_args: Default::default(), - })); - import_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Pat(ident.clone().into()), - op: op!("="), - right, - } - .into_stmt(), - ); - } - } - } - } - - prepend_stmts(&mut stmts, import_stmts.into_iter()); - stmts.append(&mut extra_stmts); + stmts.visit_mut_children_with(&mut ModuleRefRewriter { + import_map, + lazy_record: Default::default(), + top_level: true, + }); // ==================== // Emit // ==================== - Module { - body: vec![CallExpr { - span: DUMMY_SP, - callee: quote_ident!("define").as_callee(), - args: self - .config - .module_id - .clone() - .map(|s| quote_str!(s).as_arg()) - .into_iter() - .chain(iter::once(define_deps_arg.as_arg())) - .chain(iter::once( - FnExpr { - ident: None, - function: Function { - span: DUMMY_SP, - is_async: false, - is_generator: false, - decorators: Default::default(), - params: factory_params, - body: Some(BlockStmt { - span: DUMMY_SP, - stmts, - }), - type_params: Default::default(), - return_type: Default::default(), - }, - } - .as_arg(), - )) - .collect(), - type_args: Default::default(), - } - .into_stmt() - .into()], - ..module + let mut elems = vec![Some(quote_str!("require").as_arg())]; + let mut params = vec![self.require.clone().into()]; + + if let Some(exports) = self.exports.take() { + elems.push(Some(quote_str!("exports").as_arg())); + params.push(exports.into()) } - } - fn fold_prop(&mut self, p: Prop) -> Prop { - match p { - Prop::Shorthand(ident) => Scope::fold_shorthand_prop(self, ident), - - _ => p.fold_children_with(self), + if let Some(module) = self.module.clone() { + elems.push(Some(quote_str!("module").as_arg())); + params.push(module.into()) } - } - /// - /// - collects all declared variables for let and var. - fn fold_var_decl(&mut self, var: VarDecl) -> VarDecl { - if var.kind != VarDeclKind::Const { - var.decls.visit_with(&mut VarCollector { - to: &mut self.scope.borrow_mut().declared_vars, + self.dep_list + .take() + .into_iter() + .for_each(|(ident, src_path, src_span)| { + let src_path = match &self.resolver { + Resolver::Real { resolver, base } => resolver + .resolve_import(base, &src_path) + .with_context(|| format!("failed to resolve `{}`", src_path)) + .unwrap(), + Resolver::Default => src_path, + }; + + elems.push(Some(quote_str!(src_span, src_path).as_arg())); + params.push(ident.into()); }); + + let mut amd_call_args = Vec::with_capacity(3); + if let Some(module_id) = self.module_id.clone() { + amd_call_args.push(quote_str!(module_id).as_arg()); } - - VarDecl { - decls: var.decls.fold_with(self), - ..var - } - } -} - -impl ModulePass for Amd { - fn config(&self) -> &util::Config { - &self.config.config - } - - fn scope(&self) -> Ref { - self.scope.borrow() - } - - fn scope_mut(&mut self) -> RefMut { - self.scope.borrow_mut() - } - - fn resolver(&self) -> &Resolver { - &self.resolver - } - - fn make_dynamic_import(&mut self, span: Span, args: Vec) -> Expr { - handle_dynamic_import(span, args) - } - - fn vars(&mut self) -> Ref> { - self.vars.borrow() - } - - fn vars_mut(&mut self) -> RefMut> { - self.vars.borrow_mut() - } - - fn vars_take(&mut self) -> Vec { - self.vars.take() - } -} - -/// ```js -/// -/// new Promise(function(resolve, reject) { -/// require([ -/// 'js/foo' -/// ], function (foo) { -/// resolve(foo) -/// }, function (err) { -// reject(err); -/// }); -/// }); -/// -/// ``` -pub(super) fn handle_dynamic_import(span: Span, args: Vec) -> Expr { - Expr::New(NewExpr { - span, - callee: Box::new(Expr::Ident(quote_ident!("Promise"))), - args: Some(vec![FnExpr { - ident: None, - function: Function { + amd_call_args.push( + ArrayLit { span: DUMMY_SP, - is_async: false, - is_generator: false, - decorators: Default::default(), - type_params: Default::default(), - return_type: Default::default(), - params: vec![ - // resolve - Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: quote_ident!("resolve").into(), - }, - // reject - Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: quote_ident!("reject").into(), - }, - ], + elems, + } + .as_arg(), + ); - // require([ - // 'js/foo' - // ], function (foo) { - // resolve(foo) - // }, function (err) { - // reject(err); - // }); + amd_call_args.push( + Function { + params, + decorators: Default::default(), + span: DUMMY_SP, body: Some(BlockStmt { span: DUMMY_SP, - stmts: vec![Stmt::Expr(ExprStmt { - span: DUMMY_SP, - expr: Box::new( - CallExpr { - span: DUMMY_SP, - callee: quote_ident!("require").as_callee(), - args: vec![ - ArrayLit { - span: DUMMY_SP, - elems: args.into_iter().map(Some).collect(), - } - .as_arg(), - // function (foo) { - // resolve(foo) - // } - FnExpr { - ident: None, - - function: Function { - span: DUMMY_SP, - decorators: Default::default(), - is_async: false, - is_generator: false, - type_params: Default::default(), - return_type: Default::default(), - params: vec![Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: quote_ident!("dep").into(), - }], - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![CallExpr { - span: DUMMY_SP, - callee: quote_ident!("resolve").as_callee(), - args: vec![quote_ident!("dep").as_arg()], - type_args: Default::default(), - } - .into_stmt()], - }), - }, - } - .as_arg(), - // function (err) { - // reject(err); - // }; - FnExpr { - ident: None, - function: Function { - span: DUMMY_SP, - decorators: Default::default(), - is_async: false, - is_generator: false, - type_params: Default::default(), - return_type: Default::default(), - params: vec![Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: quote_ident!("err").into(), - }], - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![CallExpr { - span: DUMMY_SP, - callee: quote_ident!("reject").as_callee(), - args: vec![quote_ident!("err").as_arg()], - type_args: Default::default(), - } - .into_stmt()], - }), - }, - } - .as_arg(), - ], - type_args: Default::default(), - } - .into(), - ), - })], + stmts, }), - }, + is_generator: false, + is_async: false, + type_params: None, + return_type: None, + } + .into_fn_expr(None) + .as_arg(), + ); + + *n = vec![ + quote_ident!(DUMMY_SP.apply_mark(self.unresolved_mark), "define") + .as_call(DUMMY_SP, amd_call_args) + .into_stmt() + .into(), + ]; + } + + fn visit_mut_expr(&mut self, n: &mut Expr) { + match n { + Expr::Call(CallExpr { + span, + callee: Callee::Import(Import { span: import_span }), + args, + .. + }) if !self.config.ignore_dynamic => { + args.visit_mut_with(self); + + args.get_mut(0).into_iter().for_each(|x| { + if let ExprOrSpread { spread: None, expr } = x { + if let Expr::Lit(Lit::Str(Str { value, raw, .. })) = &mut **expr { + *value = self.resolver.resolve(value.clone()); + *raw = None; + } + } + }); + + let mut require = self.require.clone(); + require.span = import_span.apply_mark(require.span.ctxt().outer()); + + *n = amd_dynamic_import( + *span, + args.take(), + require, + !self.config.no_interop, + self.support_arrow, + ); + } + Expr::Member(MemberExpr { + span, + obj, + prop: + MemberProp::Ident(Ident { + sym: js_word!("url"), + .. + }), + }) if !self.config.preserve_import_meta + && obj + .as_meta_prop() + .map(|p| p.kind == MetaPropKind::ImportMeta) + .unwrap_or_default() => + { + obj.visit_mut_with(self); + + *n = amd_import_meta_url(*span, self.module()); + self.found_import_meta = true; + } + _ => n.visit_mut_children_with(self), } - .as_arg()]), - type_args: Default::default(), - }) + } +} + +impl Amd { + fn handle_import_export( + &mut self, + import_map: &mut ImportMap, + link: Link, + export: Export, + is_export_assign: bool, + ) -> impl Iterator { + let mut stmts = Vec::with_capacity(link.len()); + + let mut export_obj_prop_list = export + .into_iter() + .map(|((key, span), ident)| (key, span, ident.into())) + .collect(); + + link.into_iter().for_each( + |(src, LinkItem(src_span, link_specifier_set, mut link_flag))| { + let is_swc_default_helper = + !link_flag.has_named() && src.starts_with("@swc/helpers/"); + + if self.config.no_interop || is_swc_default_helper { + link_flag -= LinkFlag::NAMESPACE; + } + + let need_re_export = link_flag.export_star(); + let need_interop = link_flag.interop(); + let need_new_var = link_flag.need_raw_import(); + + let mod_ident = private_ident!(local_name_for_src(&src)); + let new_var_ident = if need_new_var { + private_ident!(local_name_for_src(&src)) + } else { + mod_ident.clone() + }; + + self.dep_list.push((mod_ident.clone(), src, src_span)); + + link_specifier_set.reduce( + import_map, + &mut export_obj_prop_list, + &new_var_ident, + &Some(mod_ident.clone()), + &mut false, + is_swc_default_helper, + ); + + if is_swc_default_helper { + stmts.push( + mod_ident + .clone() + .make_member(quote_ident!("default")) + .make_assign_to(op!("="), mod_ident.clone().as_pat_or_expr()) + .into_stmt(), + ) + } + + // _exportStar(mod, exports); + let mut import_expr: Expr = if need_re_export { + helper_expr!(export_star, "exportStar").as_call( + DUMMY_SP, + vec![mod_ident.clone().as_arg(), self.exports().as_arg()], + ) + } else { + mod_ident.clone().into() + }; + + // _introp(mod); + if need_interop { + import_expr = CallExpr { + span: DUMMY_SP, + callee: if link_flag.namespace() { + helper!(interop_require_wildcard, "interopRequireWildcard") + } else { + helper!(interop_require_default, "interopRequireDefault") + }, + args: vec![import_expr.as_arg()], + type_args: Default::default(), + } + .into() + }; + + // mod = _introp(mod); + // var mod1 = _introp(mod); + if need_new_var { + let stmt: Stmt = Stmt::Decl(Decl::Var( + import_expr.into_var_decl(self.const_var_kind, new_var_ident.into()), + )); + + stmts.push(stmt) + } else if need_interop { + let stmt = import_expr + .make_assign_to(op!("="), mod_ident.as_pat_or_expr()) + .into_stmt(); + stmts.push(stmt); + } else if need_re_export { + stmts.push(import_expr.into_stmt()); + }; + }, + ); + + let mut export_stmts = Default::default(); + + if !export_obj_prop_list.is_empty() && !is_export_assign { + let features = self.available_features; + let exports = self.exports(); + + export_stmts = emit_export_stmts(features, exports, export_obj_prop_list); + } + + export_stmts.into_iter().chain(stmts) + } + + fn module(&mut self) -> Ident { + self.module + .get_or_insert_with(|| private_ident!("module")) + .clone() + } + + fn exports(&mut self) -> Ident { + self.exports + .get_or_insert_with(|| private_ident!("exports")) + .clone() + } +} + +/// new Promise((resolve, reject) => require([arg], m => resolve(m), reject)) +pub(crate) fn amd_dynamic_import( + span: Span, + args: Vec, + require: Ident, + es_module_interop: bool, + support_arrow: bool, +) -> Expr { + let resolve = private_ident!("resolve"); + let reject = private_ident!("reject"); + let arg = args[..1].iter().cloned().map(Option::Some).collect(); + + let module = private_ident!("m"); + + let resolved_module: Expr = if es_module_interop { + helper_expr!(interop_require_wildcard, "interopRequireWildcard") + .as_call(DUMMY_SP, vec![module.clone().as_arg()]) + } else { + module.clone().into() + }; + + let resolve_callback = resolve + .clone() + .as_call(DUMMY_SP, vec![resolved_module.as_arg()]) + .into_lazy_auto(vec![module.into()], support_arrow); + + let require_call = require.as_call( + DUMMY_SP, + vec![ + ArrayLit { + span: DUMMY_SP, + elems: arg, + } + .as_arg(), + resolve_callback.as_arg(), + reject.clone().as_arg(), + ], + ); + + let promise_executer = + require_call.into_lazy_auto(vec![resolve.into(), reject.into()], support_arrow); + + NewExpr { + span, + callee: Box::new(quote_ident!("Promise").into()), + args: Some(vec![promise_executer.as_arg()]), + type_args: None, + } + .into() +} + +/// new URL(module.uri, document.baseURI).href +fn amd_import_meta_url(span: Span, module: Ident) -> Expr { + MemberExpr { + span, + obj: Box::new(Expr::New(quote_ident!("URL").into_new_expr( + DUMMY_SP, + Some(vec![ + module.make_member(quote_ident!("uri")).as_arg(), + member_expr!(DUMMY_SP, document.baseURI).as_arg(), + ]), + ))), + prop: quote_ident!("href").into(), + } + .into() } diff --git a/crates/swc_ecma_transforms_module/src/common_js.rs b/crates/swc_ecma_transforms_module/src/common_js.rs index a27a263c2b0..ad60e8869b2 100644 --- a/crates/swc_ecma_transforms_module/src/common_js.rs +++ b/crates/swc_ecma_transforms_module/src/common_js.rs @@ -1,1206 +1,442 @@ -use std::{ - cell::{Ref, RefCell, RefMut}, - rc::Rc, -}; - -use indexmap::IndexSet; -use swc_atoms::{js_word, JsWord}; -use swc_common::{ - collections::{AHashMap, AHashSet}, - FileName, Mark, Span, SyntaxContext, DUMMY_SP, -}; +use swc_atoms::js_word; +use swc_common::{collections::AHashSet, util::take::Take, FileName, Mark, Span, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_transforms_base::helper; +use swc_ecma_transforms_base::{feature::FeatureFlag, helper, helper_expr}; use swc_ecma_utils::{ - find_pat_ids, member_expr, private_ident, quote_ident, quote_str, var::VarCollector, - DestructuringFinder, ExprFactory, IsDirective, + member_expr, private_ident, quote_ident, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{noop_fold_type, noop_visit_type, Fold, FoldWith, Visit, VisitWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub use super::util::Config; -use super::util::{ - define_es_module, define_property, has_use_strict, initialize_to_undefined, make_descriptor, - use_strict, ModulePass, Scope, +use crate::{ + module_decl_strip::{Export, Link, LinkFlag, LinkItem, LinkSpecifierReducer, ModuleDeclStrip}, + module_ref_rewriter::{ImportMap, ModuleRefRewriter}, + path::{ImportResolver, Resolver}, + util::{ + clone_first_use_strict, define_es_module, emit_export_stmts, local_name_for_src, use_strict, + }, }; -use crate::path::{ImportResolver, Resolver}; -/// See [common_js_with_resolver] for docs. pub fn common_js( unresolved_mark: Mark, config: Config, - scope: Option>>, -) -> impl Fold { - let scope = scope.unwrap_or_default(); - CommonJs { - unresolved_mark, + available_features: FeatureFlag, +) -> impl Fold + VisitMut { + as_folder(Cjs { config, - scope, - in_top_level: Default::default(), resolver: Resolver::Default, - vars: Default::default(), - } + unresolved_mark, + available_features, + support_arrow: caniuse!(available_features.ArrowFunctions), + const_var_kind: if caniuse!(available_features.BlockScoping) { + VarDeclKind::Const + } else { + VarDeclKind::Var + }, + }) } -/// # Paramteres -/// -/// ## `unresolved_mark` -/// -/// Used to generate `require` call. This is required because the generated -/// `require` shuold not be shadowned by a declaration named `require` in the -/// same file. pub fn common_js_with_resolver( resolver: Box, base: FileName, unresolved_mark: Mark, config: Config, - scope: Option>>, -) -> impl Fold { - let scope = scope.unwrap_or_default(); - - CommonJs { - unresolved_mark, + available_features: FeatureFlag, +) -> impl Fold + VisitMut { + as_folder(Cjs { config, - scope, - in_top_level: Default::default(), resolver: Resolver::Real { base, resolver }, - vars: Default::default(), - } -} - -struct LazyIdentifierVisitor { - scope: Rc>, - denied_sources: AHashSet, -} -impl LazyIdentifierVisitor { - fn new(scope: Rc>) -> Self { - LazyIdentifierVisitor { - scope, - denied_sources: Default::default(), - } - } -} - -/* -An import can be performed lazily if it isn't used at the module's top-level. -This visitor scans only the identifiers at the top level by not traversing nodes -that introduce nesting. It then looks up identifiers to see if they match an -imported specifier name. - */ -impl Visit for LazyIdentifierVisitor { - noop_visit_type!(); - - fn visit_arrow_expr(&mut self, _: &ArrowExpr) {} - - fn visit_class_prop(&mut self, _: &ClassProp) {} - - fn visit_constructor(&mut self, _: &Constructor) {} - - fn visit_continue_stmt(&mut self, _: &ContinueStmt) {} - - fn visit_decl(&mut self, decl: &Decl) { - if let Decl::Class(ref c) = decl { - c.class.super_class.visit_with(self); - c.class.body.visit_with(self); - } - } - - fn visit_export_all(&mut self, export: &ExportAll) { - self.denied_sources.insert(export.src.value.clone()); - } - - fn visit_export_decl(&mut self, _: &ExportDecl) {} - - fn visit_export_default_decl(&mut self, _: &ExportDefaultDecl) {} - - fn visit_export_default_expr(&mut self, _: &ExportDefaultExpr) {} - - fn visit_export_default_specifier(&mut self, _: &ExportDefaultSpecifier) {} - - fn visit_export_named_specifier(&mut self, _: &ExportNamedSpecifier) {} - - fn visit_export_namespace_specifier(&mut self, _: &ExportNamespaceSpecifier) {} - - fn visit_function(&mut self, _: &Function) {} - - fn visit_getter_prop(&mut self, _: &GetterProp) {} - - fn visit_ident(&mut self, ident: &Ident) { - let v = self.scope.borrow().idents.get(&ident.to_id()).cloned(); - if let Some((src, _)) = v { - self.denied_sources.insert(src); - } - } - - fn visit_import_decl(&mut self, _: &ImportDecl) {} - - fn visit_labeled_stmt(&mut self, _: &LabeledStmt) {} - - fn visit_member_prop(&mut self, n: &MemberProp) { - if let MemberProp::Computed(n) = n { - n.visit_with(self); - } - } - - fn visit_named_export(&mut self, _: &NamedExport) {} - - fn visit_prop_name(&mut self, prop_name: &PropName) { - if let PropName::Computed(n) = prop_name { - n.visit_with(self) - } - } - - fn visit_setter_prop(&mut self, _: &SetterProp) {} -} - -struct CommonJs { - unresolved_mark: Mark, - config: Config, - scope: Rc>, - in_top_level: bool, - resolver: Resolver, - vars: Rc>>, -} - -/// TODO: VisitMut -impl Fold for CommonJs { - noop_fold_type!(); - - mark_as_nested!(); - - fn fold_module_items(&mut self, items: Vec) -> Vec { - let mut emitted_esmodule = false; - let mut stmts = Vec::with_capacity(items.len() + 5); - let mut extra_stmts = Vec::with_capacity(items.len()); - // appended after extra_stmts - let mut extra_exports = vec![]; - - if self.config.strict_mode && !has_use_strict(&items) { - stmts.push(ModuleItem::Stmt(use_strict())); - } - - let mut exports = vec![]; - let mut initialized = IndexSet::default(); - - let mut export_alls: AHashMap = Default::default(); - // Used only if export * exists - let mut exported_names: Option = None; - - // Make a preliminary pass through to collect exported names ahead of time - for item in &items { - match item { - ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(NamedExport { - ref specifiers, - .. - })) => { - for ExportNamedSpecifier { orig, exported, .. } in - specifiers.iter().filter_map(|e| match e { - ExportSpecifier::Named(e) => Some(e), - _ => None, - }) - { - let exported = match &exported { - Some(ModuleExportName::Ident(ident)) => Some(ident), - Some(ModuleExportName::Str(..)) => { - unimplemented!("module string names unimplemented") - } - _ => None, - }; - let orig = match &orig { - ModuleExportName::Ident(ident) => ident, - _ => unimplemented!("module string names unimplemented"), - }; - if let Some(exported) = &exported { - exports.push(exported.sym.clone()); - } else { - exports.push(orig.sym.clone()); - } - } - } - ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { decl, .. })) => { - let mut found: Vec = vec![]; - - match decl { - Decl::Class(d) => { - found.push(d.ident.clone()); - } - Decl::Fn(d) => { - found.push(d.ident.clone()); - } - Decl::Var(v) => { - found.extend(find_pat_ids(&v.decls)); - } - _ => { - unreachable!() - } - } - - for ident in found { - exports.push(ident.sym.clone()); - } - - if let Decl::Var(var) = decl { - for id in find_pat_ids(&var.decls) { - self.scope.borrow_mut().insert_exported_bindings(id); - } - } - } - _ => {} - } - } - - // Make another preliminary pass to collect all import sources and their - // specifiers. - for item in &items { - self.in_top_level = true; - if let ModuleItem::ModuleDecl(ModuleDecl::Import(import)) = item { - self.scope.borrow_mut().insert_import(import.clone()) - } - } - - // Map all top-level identifiers that match imported specifiers, and denylist - // them from lazy imports. - let mut visitor = LazyIdentifierVisitor::new(self.scope.clone()); - items.visit_with(&mut visitor); - for ident in visitor.denied_sources { - self.scope.borrow_mut().lazy_denylist.insert(ident); - } - - for item in items { - self.in_top_level = true; - - match item { - ModuleItem::Stmt(ref s) if s.is_use_strict() => { - stmts.push(item); - } - - ModuleItem::ModuleDecl(ModuleDecl::Import(import)) => { - self.scope.borrow_mut().insert_import(import) - } - ModuleItem::ModuleDecl(ModuleDecl::ExportAll(..)) - | ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(..)) - | ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(..)) - | ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultExpr(..)) - | ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(..)) => { - if !self.config.strict && !emitted_esmodule { - emitted_esmodule = true; - - stmts.push(ModuleItem::Stmt(define_es_module(quote_ident!("exports")))); - } - - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - macro_rules! init_export { - ("default") => {{ - init_export!(js_word!("default")) - }}; - ($name:expr) => {{ - initialized.insert($name.clone()); - }}; - } - match item { - ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl( - ExportDefaultDecl { - decl: DefaultDecl::Fn(..), - .. - }, - )) => { - // initialized.insert(js_word!("default")); - } - - ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl( - ExportDefaultDecl { - decl: DefaultDecl::TsInterfaceDecl(..), - .. - }, - )) => {} - - ModuleItem::ModuleDecl(ModuleDecl::ExportAll(ref export)) => { - scope.import_to_export(&export.src, true); - - scope - .import_types - .entry(export.src.value.clone()) - .and_modify(|v| *v = true); - } - - ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(..)) - | ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultExpr(..)) => { - init_export!("default") - } - - ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(NamedExport { - src: Some(ref src), - ref specifiers, - .. - })) => { - scope.import_to_export(src, !specifiers.is_empty()); - } - - _ => {} - } - drop(scope_ref_mut); - - match item { - ModuleItem::ModuleDecl(ModuleDecl::ExportAll(export)) => { - let span = export.span; - - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - - if exported_names.is_none() - && (!export_alls.is_empty() || !exports.is_empty()) - { - let exported_names_ident = private_ident!("_exportNames"); - stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: exported_names_ident.clone().into(), - init: Some(Box::new(Expr::Object(ObjectLit { - span: DUMMY_SP, - props: exports - .clone() - .into_iter() - .filter_map(|export| { - if export == js_word!("default") { - return None; - } - - Some(PropOrSpread::Prop(Box::new( - Prop::KeyValue(KeyValueProp { - key: PropName::Ident(Ident::new( - export, DUMMY_SP, - )), - value: true.into(), - }), - ))) - }) - .collect(), - }))), - definite: false, - }], - declare: false, - })))); - - exported_names = Some(exported_names_ident); - } - - let mut data = scope - .import_to_export(&export.src, true) - .expect("Export should exists"); - data.span.lo = span.lo; - data.span.hi = span.hi; - export_alls.entry(export.src.value.clone()).or_insert(data); - - drop(scope_ref_mut); - } - ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { - decl: decl @ Decl::Class(..), - .. - })) - | ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { - decl: decl @ Decl::Fn(..), - .. - })) => { - let (ident, is_class) = match decl { - Decl::Class(ref c) => (c.ident.clone(), true), - Decl::Fn(ref f) => (f.ident.clone(), false), - _ => unreachable!(), - }; - - extra_stmts.push(ModuleItem::Stmt(Stmt::Decl(decl.fold_with(self)))); - - if !is_class { - let mut scope = self.scope.borrow_mut(); - scope.insert_exported_bindings(ident.to_id()); - } - - let append_to: &mut Vec<_> = if is_class { - &mut extra_stmts - } else { - // Function declaration cannot throw - &mut stmts - }; - - append_to.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - quote_ident!("exports").make_member(ident.clone()), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt() - .into(), - ); - } - ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { - decl: Decl::Var(var), - .. - })) => { - extra_stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var( - var.clone().fold_with(self), - )))); - - let mut scope = self.scope.borrow_mut(); - var.decls.visit_with(&mut VarCollector { - to: &mut scope.declared_vars, - }); - - let mut found: Vec = vec![]; - for decl in var.decls { - let mut v = DestructuringFinder { found: &mut found }; - decl.visit_with(&mut v); - - for ident in found.drain(..) { - scope.insert_exported_bindings(ident.to_id()); - init_export!(ident.sym); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - quote_ident!("exports").make_member(ident.clone()), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt() - .into(), - ); - } - } - drop(scope); - } - ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(..)) => { - // - extra_stmts.push(item.fold_with(self)); - } - ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(decl)) => { - match decl.decl { - DefaultDecl::Class(ClassExpr { ident, class }) => { - let class = class.fold_with(self); - - init_export!("default"); - - let ident = ident.unwrap_or_else(|| private_ident!("_default")); - - extra_stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Class( - ClassDecl { - ident: ident.clone(), - class, - declare: false, - } - .fold_with(self), - )))); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(member_expr!( - DUMMY_SP, - exports.default - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt() - .into(), - ); - } - DefaultDecl::Fn(FnExpr { ident, function }) => { - // init_export!("default"); - let ident = ident.unwrap_or_else(|| private_ident!("_default")); - - // bind default exported fn into scope. Note this assigns - // syntaxcontext - // for the `default` ident, since default export is always named - // as `export.default` - // instead of actual ident of FnExpr even if it exists. - { - let mut scope = self.scope.borrow_mut(); - - scope - .exported_bindings - .entry((ident.sym.clone(), ident.span.ctxt())) - .or_default() - .push((js_word!("default"), DUMMY_SP.ctxt())); - } - - extra_stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Fn( - FnDecl { - ident: ident.clone(), - function, - declare: false, - } - .fold_with(self), - )))); - - stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(member_expr!( - DUMMY_SP, - exports.default - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt() - .into(), - ); - } - _ => extra_stmts.push( - ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(decl)) - .fold_with(self), - ), - } - } - - ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultExpr(expr)) => { - let ident = private_ident!("_default"); - - // TODO: Optimization (when expr cannot throw, `exports.default = - // void 0` is not required) - - // We use extra statements because of the initialization - extra_stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: Some(expr.expr.fold_with(self)), - definite: false, - }], - declare: false, - })))); - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(member_expr!(DUMMY_SP, exports.default)), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt() - .into(), - ); - } - - // export { foo } from 'foo'; - ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(export)) => { - let mut scope = self.scope.borrow_mut(); - let imported = export.src.clone().map(|src| { - scope.import_to_export(&src, !export.specifiers.is_empty()) - }); - - stmts.reserve(export.specifiers.len()); - - drop(scope); - - for s in export.specifiers { - match s { - ExportSpecifier::Named(ExportNamedSpecifier { - orig, - exported, - is_type_only: false, - .. - }) => { - let exported = match &exported { - Some(ModuleExportName::Ident(ident)) => Some(ident), - Some(ModuleExportName::Str(..)) => { - unimplemented!("module string names unimplemented") - } - _ => None, - }; - let orig = match &orig { - ModuleExportName::Ident(ident) => ident, - _ => { - unimplemented!("module string names unimplemented") - } - }; - - let mut scope = self.scope.borrow_mut(); - let is_import_default = orig.sym == js_word!("default"); - - let key = orig.to_id(); - if scope.declared_vars.contains(&key) { - scope - .exported_bindings - .entry(key.clone()) - .or_default() - .push( - exported - .map(|i| (i.sym.clone(), i.span.ctxt())) - .unwrap_or_else(|| { - (orig.sym.clone(), orig.span.ctxt()) - }), - ); - } - - if let Some(ref src) = export.src { - if is_import_default { - scope - .import_types - .entry(src.value.clone()) - .or_insert(false); - } - } - - let lazy = if let Some(ref src) = export.src { - if scope.lazy_denylist.contains(&src.value) { - false - } else { - self.config.lazy.is_lazy(&src.value) - } - } else { - match scope - .idents - .get(&(orig.sym.clone(), orig.span.ctxt())) - { - Some((ref src, _)) => { - if scope.lazy_denylist.contains(src) { - false - } else { - self.config.lazy.is_lazy(src) - } - } - None => false, - } - }; - - drop(scope); - - let old = self.in_top_level; - - let value = match imported { - Some(ref imported) => { - let receiver = if lazy { - Expr::Call(CallExpr { - span: DUMMY_SP, - callee: imported - .clone() - .unwrap() - .as_callee(), - args: vec![], - type_args: Default::default(), - }) - } else { - Expr::Ident(imported.clone().unwrap()) - }; - Box::new(receiver.make_member(orig.clone())) - } - None => { - Box::new(Expr::Ident(orig.clone()).fold_with(self)) - } - }; - - // True if we are exporting our own stuff. - let is_value_ident = matches!(*value, Expr::Ident(..)); - - self.in_top_level = old; - - if is_value_ident { - let exported_symbol = exported - .as_ref() - .map(|e| e.sym.clone()) - .unwrap_or_else(|| orig.sym.clone()); - init_export!(exported_symbol); - - extra_exports.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - quote_ident!("exports").make_member( - (exported.unwrap_or(orig)).clone(), - ), - )), - op: op!("="), - right: value, - } - .into_stmt() - .into(), - ); - } else { - stmts.push( - define_property(vec![ - quote_ident!("exports").as_arg(), - { - // export { foo } - // -> 'foo' - - // export { foo as bar } - // -> 'bar' - let i = exported.unwrap_or(orig).clone(); - quote_str!(i.span, i.sym).as_arg() - }, - make_descriptor(value).as_arg(), - ]) - .into_stmt() - .into(), - ); - } - } - - ExportSpecifier::Namespace(ExportNamespaceSpecifier { - span, - name, - }) => { - let name = match &name { - ModuleExportName::Ident(ident) => ident, - _ => { - unimplemented!("module string names unimplemented") - } - }; - - // Create exports.foo = void 0; - init_export!(name.sym); - - let id = if let Some(ref src) = export.src { - let mut scope = self.scope.borrow_mut(); - - let id = scope.import_to_export(src, true).unwrap(); - scope - .import_types - .entry(src.value.clone()) - .or_insert(true); - - id - } else { - unreachable!() - }; - - extra_stmts.push( - AssignExpr { - span, - op: op!("="), - left: PatOrExpr::Expr(Box::new( - quote_ident!("exports") - .make_member(name.clone()), - )), - right: Box::new(id.into()), - } - .into_stmt() - .into(), - ); - } - - _ => {} - } - } - } - - _ => unreachable!(), - } - } - _ => extra_stmts.push(item.fold_with(self)), - } - } - - if !initialized.is_empty() { - stmts.extend(initialize_to_undefined( - quote_ident!("exports"), - initialized, - )); - } - - let vars = self.vars_take(); - - if !vars.is_empty() { - let var_stmt = Stmt::Decl( - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: false, - decls: vars, - } - .into(), - ) - .into(); - - stmts.push(var_stmt); - } - - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - - let scope = &mut *scope; - for (src, (src_span, import)) in scope.imports.drain(..) { - let lazy = if scope.lazy_denylist.contains(&src) { - false - } else { - self.config.lazy.is_lazy(&src) - }; - - let mut require = - self.resolver - .make_require_call(self.unresolved_mark, src.clone(), src_span); - - // We can't use _interopRequireDefault - if src.starts_with("@swc/helpers/src/") { - require = require.make_member(quote_ident!("default")); - } - - match import { - Some(import) => { - let ty = scope.import_types.get(&src); - let rhs = match ty { - Some(true) if !self.config.no_interop => Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: helper!(interop_require_wildcard, "interopRequireWildcard"), - args: vec![require.as_arg()], - type_args: Default::default(), - })), - Some(false) if !self.config.no_interop => Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: helper!(interop_require_default, "interopRequireDefault"), - args: vec![require.as_arg()], - type_args: Default::default(), - })), - _ => Box::new(require), - }; - - let ident = Ident::new(import.0, import.1); - - if lazy { - let return_data = Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: Some(Box::new(quote_ident!("data").into())), - }); - - stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Fn(FnDecl { - ident: ident.clone(), - function: Function { - span: DUMMY_SP, - is_async: false, - is_generator: false, - decorators: Default::default(), - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![ - // const data = require(); - Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Const, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: quote_ident!("data").into(), - init: Some(rhs), - definite: false, - }], - declare: false, - })), - // foo = function() { return data; }; - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Pat(ident.into()), - op: op!("="), - right: Box::new( - FnExpr { - ident: None, - function: Function { - span: DUMMY_SP, - is_async: false, - is_generator: false, - decorators: Default::default(), - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![return_data.clone()], - }), - params: vec![], - type_params: Default::default(), - return_type: Default::default(), - }, - } - .into(), - ), - } - .into_stmt(), - // return data - return_data, - ], - }), - params: vec![], - type_params: Default::default(), - return_type: Default::default(), - }, - declare: false, - })))); - } else { - stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl { - span: import.1, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: ident.into(), - init: Some(rhs), - definite: false, - }], - declare: false, - })))); - } - } - None => { - stmts.push(require.into_stmt().into()); - } - } - - let exported = export_alls.remove(&src); - if let Some(export) = exported { - stmts.push(ModuleItem::Stmt(Scope::handle_export_all( - export.span.with_ctxt(SyntaxContext::empty()), - quote_ident!("exports"), - exported_names.clone(), - export, - ))); - } - } - - stmts.append(&mut extra_stmts); - stmts.append(&mut extra_exports); - - stmts - } - - fn fold_expr(&mut self, mut expr: Expr) -> Expr { - if !self.config.preserve_import_meta { - // https://github.com/swc-project/swc/issues/1202 - if let Expr::Member(MemberExpr { - obj, - prop: MemberProp::Ident(prop), - .. - }) = &mut expr - { - if &*prop.sym == "url" { - if let Expr::MetaProp(MetaPropExpr { - span, - kind: MetaPropKind::ImportMeta, - .. - }) = &**obj - { - // require('url').pathToFileURL(__filename).toString() - - let url_module = CallExpr { - span: DUMMY_SP, - callee: quote_ident!("require").as_callee(), - args: vec!["url".as_arg()], - type_args: Default::default(), - }; - - let url_obj = CallExpr { - span: DUMMY_SP, - callee: url_module - .make_member(quote_ident!("pathToFileURL")) - .as_callee(), - args: vec![Ident::new( - "__filename".into(), - DUMMY_SP.with_ctxt( - SyntaxContext::empty().apply_mark(self.unresolved_mark), - ), - ) - .as_arg()], - type_args: Default::default(), - }; - - expr = Expr::Call(CallExpr { - span: *span, - callee: url_obj.make_member(quote_ident!("toString")).as_callee(), - args: Default::default(), - type_args: Default::default(), - }); - } - } - } - } - - let top_level = self.in_top_level; - Scope::fold_expr(self, quote_ident!("exports"), top_level, expr) - } - - fn fold_prop(&mut self, p: Prop) -> Prop { - match p { - Prop::Shorthand(ident) => Scope::fold_shorthand_prop(self, ident), - - _ => p.fold_children_with(self), - } - } - - /// - /// - collects all declared variables for let and var. - fn fold_var_decl(&mut self, var: VarDecl) -> VarDecl { - if var.kind != VarDeclKind::Const { - var.decls.visit_with(&mut VarCollector { - to: &mut self.scope.borrow_mut().declared_vars, - }); - } - - VarDecl { - decls: var.decls.fold_with(self), - ..var - } - } - - fn fold_fn_decl(&mut self, node: FnDecl) -> FnDecl { - self.scope - .borrow_mut() - .declared_vars - .push((node.ident.sym.clone(), node.ident.span.ctxt())); - - node.fold_children_with(self) - } - - fn fold_class_decl(&mut self, node: ClassDecl) -> ClassDecl { - self.scope - .borrow_mut() - .declared_vars - .push((node.ident.sym.clone(), node.ident.span.ctxt())); - - node.fold_children_with(self) - } -} - -impl ModulePass for CommonJs { - fn config(&self) -> &Config { - &self.config - } - - fn scope(&self) -> Ref { - self.scope.borrow() - } - - fn scope_mut(&mut self) -> RefMut { - self.scope.borrow_mut() - } - - fn resolver(&self) -> &Resolver { - &self.resolver - } - - fn make_dynamic_import(&mut self, span: Span, args: Vec) -> Expr { - handle_dynamic_import(span, args, !self.config.no_interop) - } - - fn vars(&mut self) -> Ref> { - self.vars.borrow() - } - - fn vars_mut(&mut self) -> RefMut> { - self.vars.borrow_mut() - } - - fn vars_take(&mut self) -> Vec { - self.vars.take() - } -} - -/// ```js -/// Promise.resolve().then(function () { return require('./foo'); }) -/// ``` -pub(super) fn handle_dynamic_import( - span: Span, - mut args: Vec, - es_module_interop: bool, -) -> Expr { - // there's a evalution order problem here - let (resolve_arg, then_arg, require_arg) = if let Expr::Lit(Lit::Str(_)) = &*args[0].expr { - (Vec::new(), Vec::new(), args) - } else { - let arg = private_ident!("s"); - let rest = args.split_off(1); - let import = args.into_iter().next().unwrap(); - ( - vec![ExprOrSpread { - spread: None, - expr: if import.expr.is_tpl() { - import.expr - } else { - Box::new(Expr::Tpl(Tpl { - span: DUMMY_SP, - exprs: vec![import.expr], - quasis: vec![ - TplElement { - span: DUMMY_SP, - tail: true, - cooked: None, - raw: "".into(), - }, - TplElement { - span: DUMMY_SP, - tail: true, - cooked: None, - raw: "".into(), - }, - ], - })) - }, - }], - vec![arg.clone().into()], - { - let mut require_arg = vec![arg.as_arg()]; - require_arg.extend(rest); - require_arg - }, - ) - }; - - let resolve_call = CallExpr { - span: DUMMY_SP, - callee: member_expr!(DUMMY_SP, Promise.resolve).as_callee(), - args: resolve_arg, - type_args: Default::default(), - }; - // Promise.resolve().then - let then = resolve_call.make_member(quote_ident!("then")); - - Expr::Call(CallExpr { - span, - callee: then.as_callee(), - args: vec![ - // function () { return require('./foo'); } - FnExpr { - ident: None, - function: Function { - span: DUMMY_SP, - params: then_arg, - is_generator: false, - is_async: false, - type_params: Default::default(), - return_type: Default::default(), - decorators: Default::default(), - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: Some({ - let mut expr = Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: quote_ident!("require").as_callee(), - args: require_arg, - type_args: Default::default(), - })); - - if es_module_interop { - expr = Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: helper!( - interop_require_wildcard, - "interopRequireWildcard" - ), - args: vec![expr.as_arg()], - type_args: Default::default(), - })); - } - - expr - }), - })], - }), - }, - } - .as_arg(), - ], - type_args: Default::default(), + unresolved_mark, + available_features, + support_arrow: caniuse!(available_features.ArrowFunctions), + const_var_kind: if caniuse!(available_features.BlockScoping) { + VarDeclKind::Const + } else { + VarDeclKind::Var + }, }) } + +pub struct Cjs { + config: Config, + resolver: Resolver, + unresolved_mark: Mark, + available_features: FeatureFlag, + support_arrow: bool, + const_var_kind: VarDeclKind, +} + +impl VisitMut for Cjs { + noop_visit_mut_type!(); + + fn visit_mut_module_items(&mut self, n: &mut Vec) { + let mut strip = ModuleDeclStrip::default(); + n.visit_mut_with(&mut strip); + + let mut stmts: Vec = Vec::with_capacity(n.len() + 4); + + // "use strict"; + if self.config.strict_mode { + stmts.push(clone_first_use_strict(n).unwrap_or_else(use_strict).into()); + } + + let ModuleDeclStrip { + link, + export, + export_assign, + has_module_decl, + .. + } = strip; + + let is_export_assign = export_assign.is_some(); + + if has_module_decl && !self.config.no_interop && !is_export_assign { + stmts.push(define_es_module(self.exports()).into()) + } + + let mut import_map = Default::default(); + let mut lazy_record = Default::default(); + + // `import` -> `require` + // `export` -> `_export(exports, {});` + stmts.extend( + self.handle_import_export( + &mut import_map, + &mut lazy_record, + link, + export, + is_export_assign, + ) + .map(Into::into), + ); + + stmts.extend(n.take().into_iter().filter(|item| match item { + ModuleItem::Stmt(stmt) => !stmt.is_use_strict(), + _ => false, + })); + + // `export = expr;` -> `module.exports = expr;` + if let Some(export_assign) = export_assign { + stmts.push( + export_assign + .make_assign_to( + op!("="), + member_expr!(DUMMY_SP.apply_mark(self.unresolved_mark), module.exports) + .into(), + ) + .into_stmt() + .into(), + ) + } + + if !self.config.ignore_dynamic || !self.config.preserve_import_meta { + stmts.visit_mut_children_with(self); + } + + stmts.visit_mut_children_with(&mut ModuleRefRewriter { + import_map, + lazy_record, + top_level: true, + }); + + *n = stmts; + } + + fn visit_mut_expr(&mut self, n: &mut Expr) { + match n { + Expr::Call(CallExpr { + span, + callee: Callee::Import(Import { span: import_span }), + args, + .. + }) if !self.config.ignore_dynamic => { + args.visit_mut_with(self); + + args.get_mut(0).into_iter().for_each(|x| { + if let ExprOrSpread { spread: None, expr } = x { + if let Expr::Lit(Lit::Str(Str { value, raw, .. })) = &mut **expr { + *value = self.resolver.resolve(value.clone()); + *raw = None; + } + } + }); + + let require_span = import_span.apply_mark(self.unresolved_mark); + *n = cjs_dynamic_import( + *span, + args.take(), + quote_ident!(require_span, "require"), + !self.config.no_interop, + self.support_arrow, + ); + } + Expr::Member(MemberExpr { + span, + obj, + prop: + MemberProp::Ident(Ident { + sym: js_word!("url"), + .. + }), + }) if !self.config.preserve_import_meta + && obj + .as_meta_prop() + .map(|p| p.kind == MetaPropKind::ImportMeta) + .unwrap_or_default() => + { + obj.visit_mut_with(self); + + let require = quote_ident!(DUMMY_SP.apply_mark(self.unresolved_mark), "require"); + *n = cjs_import_meta_url(*span, require, self.unresolved_mark); + } + _ => n.visit_mut_children_with(self), + } + } +} + +impl Cjs { + fn handle_import_export( + &mut self, + import_map: &mut ImportMap, + lazy_record: &mut AHashSet, + link: Link, + export: Export, + is_export_assign: bool, + ) -> impl Iterator { + let mut stmts = Vec::with_capacity(link.len()); + + let mut export_obj_prop_list = export + .into_iter() + .map(|((key, span), ident)| (key, span, ident.into())) + .collect(); + + link.into_iter().for_each( + |(src, LinkItem(src_span, link_specifier_set, mut link_flag))| { + // Optimize for `@swc/helpers`: + // if there is no named import/export + // avoid to generate + // ``` + // var foo = require("@swc/helpers/foo"); + // (0, foo.default)(bar); + // ``` + // instead, we prefer + // ``` + // var foo = require("@swc/helpers/foo").default; + // foo(bar); + // ``` + + let is_swc_default_helper = + !link_flag.has_named() && src.starts_with("@swc/helpers/"); + + if self.config.no_interop || is_swc_default_helper { + link_flag -= LinkFlag::NAMESPACE; + } + + let mod_ident = private_ident!(local_name_for_src(&src)); + let raw_mod_ident = link_flag + .need_raw_import() + .then(|| private_ident!(local_name_for_src(&src))); + + let mut decl_mod_ident = false; + + link_specifier_set.reduce( + import_map, + &mut export_obj_prop_list, + &mod_ident, + &raw_mod_ident, + &mut decl_mod_ident, + is_swc_default_helper, + ); + + let is_lazy = + decl_mod_ident && !link_flag.export_star() && self.config.lazy.is_lazy(&src); + + if is_lazy { + lazy_record.insert(mod_ident.to_id()); + if let Some(raw_mod_ident) = &raw_mod_ident { + lazy_record.insert(raw_mod_ident.to_id()); + } + } + + // require("mod"); + let import_expr = + self.resolver + .make_require_call(self.unresolved_mark, src, src_span); + + let import_expr = if is_swc_default_helper { + import_expr.make_member(quote_ident!("default")) + } else { + import_expr + }; + + let import_assign = raw_mod_ident.map(|raw_mod_ident| { + let import_expr = import_expr.clone(); + if is_lazy { + Stmt::Decl(Decl::Fn(lazy_require( + import_expr, + raw_mod_ident, + self.const_var_kind, + ))) + } else { + Stmt::Decl(Decl::Var( + import_expr.into_var_decl(self.const_var_kind, raw_mod_ident.into()), + )) + } + }); + + // _exportStar(require("mod"), exports); + let import_expr = if link_flag.export_star() { + helper_expr!(export_star, "exportStar").as_call( + DUMMY_SP, + vec![import_expr.as_arg(), self.exports().as_arg()], + ) + } else { + import_expr + }; + + // _introp(require("mod")); + let import_expr = if !link_flag.interop() { + import_expr + } else { + CallExpr { + span: DUMMY_SP, + callee: if link_flag.namespace() { + helper!(interop_require_wildcard, "interopRequireWildcard") + } else { + helper!(interop_require_default, "interopRequireDefault") + }, + args: vec![import_expr.as_arg()], + type_args: Default::default(), + } + .into() + }; + + if decl_mod_ident { + let stmt = if is_lazy { + Stmt::Decl(Decl::Fn(lazy_require( + import_expr, + mod_ident, + self.const_var_kind, + ))) + } else { + Stmt::Decl( + import_expr + .into_var_decl(self.const_var_kind, mod_ident.into()) + .into(), + ) + }; + + if let Some(import_assign) = import_assign { + stmts.push(import_assign); + } + + stmts.push(stmt); + } else { + stmts.push(import_expr.into_stmt()); + } + }, + ); + + let mut export_stmts = Default::default(); + + if !export_obj_prop_list.is_empty() && !is_export_assign { + let features = self.available_features; + let exports = self.exports(); + + export_stmts = emit_export_stmts(features, exports, export_obj_prop_list); + } + + export_stmts.into_iter().chain(stmts) + } + + fn exports(&mut self) -> Ident { + quote_ident!(DUMMY_SP.apply_mark(self.unresolved_mark), "exports") + } +} + +/// Promise.resolve(args).then(p => require(p)) +pub(crate) fn cjs_dynamic_import( + span: Span, + args: Vec, + require: Ident, + es_module_interop: bool, + support_arrow: bool, +) -> Expr { + let then = member_expr!(DUMMY_SP, Promise.resolve) + // TODO: handle import assert + .as_call(DUMMY_SP, args) + .make_member(quote_ident!("then")); + + let path = private_ident!("p"); + + let import_expr = { + let require = require.as_call(DUMMY_SP, vec![path.clone().as_arg()]); + + if es_module_interop { + helper_expr!(interop_require_wildcard, "interopRequireWildcard") + .as_call(DUMMY_SP, vec![require.as_arg()]) + } else { + require + } + }; + + then.as_call( + span, + vec![import_expr + .into_lazy_auto(vec![path.into()], support_arrow) + .as_arg()], + ) +} + +/// require('url').pathToFileURL(__filename).toString() +fn cjs_import_meta_url(span: Span, require: Ident, unresolved_mark: Mark) -> Expr { + require + .as_call(DUMMY_SP, vec!["url".as_arg()]) + .make_member(quote_ident!("pathToFileURL")) + .as_call( + DUMMY_SP, + vec![quote_ident!(DUMMY_SP.apply_mark(unresolved_mark), "__filename").as_arg()], + ) + .make_member(quote_ident!("toString")) + .as_call(span, Default::default()) +} + +/// ```javascript +/// function foo() { +/// const data = expr; +/// +/// foo = () => data; +/// +/// return data; +/// } +/// ``` +pub fn lazy_require(expr: Expr, mod_ident: Ident, var_kind: VarDeclKind) -> FnDecl { + let data = private_ident!("data"); + let data_decl = expr.into_var_decl(var_kind, data.clone().into()); + let data_stmt = Stmt::Decl(Decl::Var(data_decl)); + let overwrite_stmt = data + .clone() + .into_lazy_fn(Default::default()) + .into_fn_expr(None) + .make_assign_to(op!("="), mod_ident.clone().as_pat_or_expr()) + .into_stmt(); + let return_stmt = data.into_return_stmt().into(); + + FnDecl { + ident: mod_ident, + declare: false, + function: Function { + params: Default::default(), + decorators: Default::default(), + span: DUMMY_SP, + body: Some(BlockStmt { + span: DUMMY_SP, + stmts: vec![data_stmt, overwrite_stmt, return_stmt], + }), + is_generator: false, + is_async: false, + type_params: None, + return_type: None, + }, + } +} diff --git a/crates/swc_ecma_transforms_module/src/hoist.rs b/crates/swc_ecma_transforms_module/src/hoist.rs deleted file mode 100644 index cb0d740312e..00000000000 --- a/crates/swc_ecma_transforms_module/src/hoist.rs +++ /dev/null @@ -1,300 +0,0 @@ -use std::borrow::Cow; - -use indexmap::IndexMap; -use swc_atoms::JsWord; -use swc_common::{pass::CompilerPass, util::take::Take, DUMMY_SP}; -use swc_ecma_ast::*; -use swc_ecma_utils::{find_pat_ids, IsDirective}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut}; - -pub fn module_hoister() -> impl Fold + VisitMut + CompilerPass { - as_folder(ModuleHoister) -} - -struct ModuleHoister; - -impl CompilerPass for ModuleHoister { - fn name() -> Cow<'static, str> { - Cow::Borrowed("module-hoister") - } -} - -impl VisitMut for ModuleHoister { - noop_visit_mut_type!(); - - fn visit_mut_module(&mut self, module: &mut Module) { - let mut found_other = false; - let mut need_hoist_up = false; - let mut need_hoist_down = false; - - for stmt in &module.body { - match stmt { - ModuleItem::ModuleDecl(ModuleDecl::Import(..)) if found_other => { - need_hoist_up = true; - } - - ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { - decl: - DefaultDecl::Class(ClassExpr { - ident: Some(..), .. - }) - | DefaultDecl::Fn(FnExpr { - ident: Some(..), .. - }), - .. - })) if found_other => { - need_hoist_up = true; - } - - ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(NamedExport { - specifiers, - src: None, - type_only: false, - asserts: None, - .. - })) if !specifiers.is_empty() => { - need_hoist_down = true; - } - - ModuleItem::Stmt(stmt) if stmt.is_use_strict() => { - // ignore - } - _ => { - found_other = true; - } - } - - if need_hoist_up && need_hoist_down { - break; - } - } - - if !need_hoist_up && !need_hoist_down { - return; - } - - let stmts = if !need_hoist_up { - module.body.take() - } else { - let body = module.body.take(); - let mut stmts = Vec::with_capacity(body.len()); - let mut extra = vec![]; - - for item in body.into_iter() { - match item { - ModuleItem::ModuleDecl(ModuleDecl::Import(..)) => { - stmts.push(item); - } - ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { - decl: - DefaultDecl::Class(ClassExpr { - ident: Some(..), .. - }) - | DefaultDecl::Fn(FnExpr { - ident: Some(..), .. - }), - .. - })) => { - stmts.push(item); - } - ModuleItem::Stmt(ref stmt) if stmt.is_use_strict() => { - stmts.push(item); - } - _ => { - extra.push(item); - } - } - } - - stmts.extend(extra); - stmts - }; - - // for something like - // ```javascript - // export { foo, bar as baz }; - // const foo = 1; - // let bar = 2; - // ``` - // - // convert it into - // ```javascript - // const foo = 1; - // export { foo }; - // let bar = 2; - // export { bar as baz }; - // ``` - let stmts = if !need_hoist_down { - stmts - } else { - let body = stmts; - - let mut stmts = Vec::with_capacity(body.len()); - let mut named_exports = IndexMap::>::default(); - - // collect all named export stmts which bind local idents - for item in body.into_iter() { - match item { - ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(NamedExport { - span, - specifiers, - // ignore reexport `export { x } from "x";` - src: None, - type_only: false, - // asserts can only appear with reexport - asserts: None, - })) if !specifiers.is_empty() => { - let mut retain_exports = vec![]; - - for export in specifiers.into_iter() { - match export { - ExportSpecifier::Default(ExportDefaultSpecifier { - ref exported, - }) => { - let key = exported.sym.clone(); - - named_exports.entry(key).or_default().push(export); - } - ExportSpecifier::Named(ExportNamedSpecifier { - orig: ModuleExportName::Ident(ref ident), - is_type_only: false, - .. - }) => { - let key = ident.sym.clone(); - named_exports.entry(key).or_default().push(export); - } - _ => { - retain_exports.push(export); - } - } - } - - if !retain_exports.is_empty() { - stmts.push(ModuleItem::ModuleDecl( - NamedExport { - span, - specifiers: retain_exports, - src: None, - type_only: false, - asserts: None, - } - .into(), - )) - } - } - - _ => { - stmts.push(item); - } - }; - } - - let body = stmts; - let mut stmts = Vec::with_capacity(body.len() + named_exports.len() + 1); - - // append export stmts where it is declared - for item in body.into_iter() { - let key_list = match item { - ModuleItem::Stmt(Stmt::Decl(ref decl)) => { - match decl { - Decl::Class(class_decl) => vec![class_decl.ident.sym.clone()], - Decl::Fn(fn_decl) => vec![fn_decl.ident.sym.clone()], - Decl::Var(var_decl) => find_pat_ids(var_decl) - .into_iter() - .map(|x: Ident| x.sym) - .collect(), - // Decl::TsInterface(_) => {} - // Decl::TsTypeAlias(_) => {} - // Decl::TsEnum(_) => {} - // Decl::TsModule(_) => {} - _ => { - vec![] - } - } - } - ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { - ref specifiers, - .. - })) => specifiers - .iter() - .filter_map(|i| match i { - ImportSpecifier::Named(ImportNamedSpecifier { - local, - is_type_only: false, - .. - }) => Some(local.sym.clone()), - ImportSpecifier::Default(default) => Some(default.local.sym.clone()), - ImportSpecifier::Namespace(namespace) => { - Some(namespace.local.sym.clone()) - } - _ => None, - }) - .collect(), - - ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { - decl: - DefaultDecl::Class(ClassExpr { - ident: Some(ref ident), - .. - }) - | DefaultDecl::Fn(FnExpr { - ident: Some(ref ident), - .. - }), - .. - })) => { - vec![ident.sym.clone()] - } - - _ => { - vec![] - } - }; - - stmts.push(item); - - if key_list.is_empty() { - continue; - } - - let export_list: Vec = key_list - .iter() - .flat_map(|key| named_exports.remove(key)) - .flatten() - .collect(); - - if !export_list.is_empty() { - stmts.push(ModuleItem::ModuleDecl( - NamedExport { - span: DUMMY_SP, - specifiers: export_list, - src: None, - type_only: false, - asserts: None, - } - .into(), - )); - } - } - - // debug_assert!(named_exports.is_empty()); - if !named_exports.is_empty() { - let specifiers = named_exports.into_values().flatten().collect(); - stmts.push(ModuleItem::ModuleDecl( - NamedExport { - span: DUMMY_SP, - specifiers, - src: None, - type_only: false, - asserts: None, - } - .into(), - )); - } - - stmts - }; - - module.body = stmts; - } -} diff --git a/crates/swc_ecma_transforms_module/src/import_analysis.rs b/crates/swc_ecma_transforms_module/src/import_analysis.rs index b97887de786..672dc42ab7f 100644 --- a/crates/swc_ecma_transforms_module/src/import_analysis.rs +++ b/crates/swc_ecma_transforms_module/src/import_analysis.rs @@ -1,25 +1,28 @@ -use std::{cell::RefCell, rc::Rc}; - -use swc_atoms::{js_word, JsWord}; -use swc_common::collections::AHashSet; +use swc_atoms::JsWord; +use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_transforms_base::enable_helper; use swc_ecma_visit::{ as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitWith, }; -use super::util::Scope; +use crate::module_decl_strip::LinkFlag; -pub fn import_analyzer(scope: Rc>) -> impl Fold + VisitMut { +pub fn import_analyzer(no_interop: bool, ignore_dynamic: bool) -> impl Fold + VisitMut { as_folder(ImportAnalyzer { - scope, - import_srcs: Default::default(), + no_interop, + ignore_dynamic, + flag_record: Default::default(), + dynamic_import_found: false, }) } pub struct ImportAnalyzer { - scope: Rc>, - import_srcs: AHashSet, + no_interop: bool, + ignore_dynamic: bool, + + flag_record: AHashMap, + dynamic_import_found: bool, } /// Inject required helpers methods **for** module transform passes. @@ -28,160 +31,74 @@ impl VisitMut for ImportAnalyzer { fn visit_mut_module(&mut self, module: &mut Module) { self.visit_module(&*module); - - for (_, ty) in self.scope.borrow().import_types.iter() { - if *ty { - enable_helper!(interop_require_wildcard); - } else { - enable_helper!(interop_require_default); - } - } - - let (need_wildcard, need_default) = self.scope.borrow().unknown_imports; - - if need_wildcard { - enable_helper!(interop_require_wildcard); - } - - if need_default { - enable_helper!(interop_require_default); - } } } impl Visit for ImportAnalyzer { noop_visit_type!(); - fn visit_call_expr(&mut self, n: &CallExpr) { - n.visit_children_with(self); - let mut scope = self.scope.borrow_mut(); - if let Callee::Import(..) = &n.callee { - if let Some(ExprOrSpread { spread: None, expr }) = n.args.first() { - match &**expr { - Expr::Lit(Lit::Str(src)) => { - *scope.import_types.entry(src.value.clone()).or_default() = true; - } - _ => { - scope.unknown_imports.0 = true; - } - } + fn visit_module_items(&mut self, n: &[ModuleItem]) { + for item in n.iter() { + if item.is_module_decl() { + item.visit_with(self); } } - } - fn visit_export_all(&mut self, export: &ExportAll) { - *self - .scope - .borrow_mut() - .import_types - .entry(export.src.value.clone()) - .or_default() = true - } + let flag_record = &self.flag_record; - fn visit_import_decl(&mut self, import: &ImportDecl) { - let mut scope = self.scope.borrow_mut(); - if import.specifiers.is_empty() { - // import 'foo'; - // -> require('foo'); - } else if import.specifiers.len() == 1 - && matches!(import.specifiers[0], ImportSpecifier::Namespace(..)) - { - scope.import_types.insert(import.src.value.clone(), true); - } else { - let mut has_non_default = false; - - for s in &import.specifiers { - match *s { - ImportSpecifier::Namespace(ref _ns) => { - scope.import_types.insert(import.src.value.clone(), true); - } - ImportSpecifier::Default(_) => { - if !import.src.value.starts_with("@swc/helpers") { - let src = import.src.value.clone(); - let src_already_exist = self.import_srcs.contains(&src); - - scope.import_types.entry(src).or_insert(src_already_exist); - } - } - ImportSpecifier::Named(ref i) => { - let ImportNamedSpecifier { - ref local, - ref imported, - .. - } = *i; - let imported = match imported { - Some(ModuleExportName::Ident(ident)) => Some(ident), - Some(ModuleExportName::Str(..)) => { - unimplemented!("module string names unimplemented") - } - _ => None, - }; - let name = imported - .as_ref() - .map(|i| i.sym.clone()) - .unwrap_or_else(|| local.sym.clone()); - let is_default = name == js_word!("default"); - - // in case of default import comes after named import, it needs to know - // if there's prior import to same src to determine interopDefault or - // interopWildcard. - self.import_srcs.insert(import.src.value.clone()); - - if is_default { - scope - .import_types - .entry(import.src.value.clone()) - .or_insert(has_non_default); - } else { - has_non_default = true; - scope - .import_types - .entry(import.src.value.clone()) - .and_modify(|v| *v = true); - } - } - } - } + if flag_record.values().any(|flag| flag.export_star()) { + enable_helper!(export_star); } - } - fn visit_named_export(&mut self, export: &NamedExport) { - if export - .specifiers - .iter() - .any(|v| matches!(v, ExportSpecifier::Namespace(..))) - { - let mut scope = self.scope.borrow_mut(); - - if let Some(ref src) = export.src { - *scope.import_types.entry(src.value.clone()).or_default() = true; - } + if self.no_interop { return; } - let mut scope = self.scope.borrow_mut(); - for &ExportNamedSpecifier { ref orig, .. } in - export.specifiers.iter().filter_map(|e| match *e { - ExportSpecifier::Named(ref e) => Some(e), - _ => None, - }) + if flag_record + .values() + .any(|flag| flag.interop() && !flag.has_named()) { - let orig = match orig { - ModuleExportName::Ident(ident) => ident, - _ => unimplemented!("module string names unimplemented"), - }; - let is_import_default = orig.sym == js_word!("default"); + enable_helper!(interop_require_default); + } - if let Some(ref src) = export.src { - if is_import_default { - scope.import_types.entry(src.value.clone()).or_insert(false); - } else { - scope - .import_types - .entry(src.value.clone()) - .and_modify(|v| *v = true); + if flag_record.values().any(|flag| flag.namespace()) { + enable_helper!(interop_require_wildcard); + } else if !self.ignore_dynamic { + // `import/export * as foo from "foo"` not found + // but it may be used with dynamic import + for item in n.iter() { + if item.is_stmt() { + item.visit_with(self); + } + if self.dynamic_import_found { + enable_helper!(interop_require_wildcard); + break; } } } } + + fn visit_import_decl(&mut self, n: &ImportDecl) { + let flag = self.flag_record.entry(n.src.value.clone()).or_default(); + for s in &n.specifiers { + *flag |= s.into(); + } + } + + fn visit_named_export(&mut self, n: &NamedExport) { + if let Some(src) = n.src.clone() { + let flag = self.flag_record.entry(src.value).or_default(); + for s in &n.specifiers { + *flag |= s.into(); + } + } + } + + fn visit_export_all(&mut self, n: &ExportAll) { + *self.flag_record.entry(n.src.value.clone()).or_default() |= LinkFlag::EXPORT_STAR; + } + + fn visit_import(&mut self, _: &Import) { + self.dynamic_import_found = true; + } } diff --git a/crates/swc_ecma_transforms_module/src/lib.rs b/crates/swc_ecma_transforms_module/src/lib.rs index 162496515ea..6c73f690ddc 100644 --- a/crates/swc_ecma_transforms_module/src/lib.rs +++ b/crates/swc_ecma_transforms_module/src/lib.rs @@ -9,8 +9,9 @@ pub use self::{amd::amd, common_js::common_js, system_js::system_js, umd::umd}; pub mod util; pub mod amd; pub mod common_js; -pub mod hoist; pub mod import_analysis; +pub(crate) mod module_decl_strip; +pub(crate) mod module_ref_rewriter; pub mod path; pub mod rewriter; pub mod system_js; diff --git a/crates/swc_ecma_transforms_module/src/module_decl_strip.rs b/crates/swc_ecma_transforms_module/src/module_decl_strip.rs new file mode 100644 index 00000000000..22df60d9e64 --- /dev/null +++ b/crates/swc_ecma_transforms_module/src/module_decl_strip.rs @@ -0,0 +1,665 @@ +use indexmap::IndexMap; +use swc_atoms::{js_word, JsWord}; +use swc_common::{collections::AHashSet, util::take::Take, Span, DUMMY_SP}; +use swc_ecma_ast::*; +use swc_ecma_utils::{find_pat_ids, is_valid_prop_ident, private_ident, quote_ident, ExprFactory}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; + +use crate::module_ref_rewriter::ImportMap; + +pub type Link = IndexMap; +pub type Export = IndexMap<(JsWord, Span), Ident>; + +#[derive(Debug, Default)] +pub struct ModuleDeclStrip { + /// all import/export ordered by path + pub link: Link, + + /// local exported binding + /// + /// `export { foo as "1", bar }` + /// -> Map("1" => foo, bar => bar) + pub export: Export, + + /// `export = ` detected + pub export_assign: Option>, + + pub has_module_decl: bool, + + /// `export default expr` + export_default: Option, +} + +impl VisitMut for ModuleDeclStrip { + noop_visit_mut_type!(); + + fn visit_mut_module_items(&mut self, n: &mut Vec) { + let mut list = Vec::with_capacity(n.len()); + + for item in n.drain(..) { + match item { + ModuleItem::Stmt(stmt) => list.push(stmt.into()), + + ModuleItem::ModuleDecl(mut module_decl) => { + // collect link meta + module_decl.visit_mut_with(self); + self.has_module_decl = true; + + // emit stmt + match module_decl { + ModuleDecl::Import(..) => continue, + ModuleDecl::ExportDecl(ExportDecl { decl, .. }) => { + list.push(Stmt::Decl(decl).into()); + } + ModuleDecl::ExportNamed(..) => continue, + ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { decl, .. }) => match decl + { + DefaultDecl::Class(class_expr) => list.extend( + class_expr + .as_class_decl() + .map(|decl| Stmt::Decl(Decl::Class(decl))) + .map(Into::into), + ), + DefaultDecl::Fn(fn_expr) => list.extend( + fn_expr + .as_fn_decl() + .map(|decl| Stmt::Decl(Decl::Fn(decl))) + .map(Into::into), + ), + DefaultDecl::TsInterfaceDecl(_) => continue, + }, + ModuleDecl::ExportDefaultExpr(..) => { + list.extend(self.export_default.take().map(Into::into)) + } + ModuleDecl::ExportAll(..) => continue, + ModuleDecl::TsImportEquals(..) => continue, + ModuleDecl::TsExportAssignment(..) => continue, + ModuleDecl::TsNamespaceExport(..) => continue, + }; + } + }; + } + + *n = list; + } + + // collect all static import + fn visit_mut_import_decl(&mut self, n: &mut ImportDecl) { + let ImportDecl { + specifiers, src, .. + } = n.take(); + + self.link + .entry(src.value) + .or_default() + .mut_dummy_span(src.span) + .extend(specifiers.into_iter().map(Into::into)); + } + + /// ```javascript + /// export const foo = 1, bar = 2, { baz } = { baz: 3 }; + /// export let a = 1, [b] = [2]; + /// export function x() {} + /// export class y {} + /// ``` + /// -> + /// ```javascript + /// const foo = 1, bar = 2, { baz } = { baz: 3 }; + /// let a = 1, [b] = [2]; + /// function x() {} + /// class y {} + /// ``` + fn visit_mut_export_decl(&mut self, n: &mut ExportDecl) { + match &n.decl { + Decl::Class(ClassDecl { ident, .. }) | Decl::Fn(FnDecl { ident, .. }) => { + let ident = ident.clone(); + + self.export.insert((ident.sym.clone(), ident.span), ident); + } + + Decl::Var(v) => { + self.export + .extend(find_pat_ids::<_, Ident>(&v.decls).into_iter().map(|id| { + let ident = id.clone(); + ((id.sym, id.span), ident) + })); + } + _ => {} + }; + } + + /// ```javascript + /// export { foo, foo as bar, foo as "baz" }; + /// export { "foo", foo as bar, "foo" as "baz" } from "mod"; + /// export * as foo from "mod"; + /// export * as "bar" from "mod"; + /// ``` + fn visit_mut_named_export(&mut self, n: &mut NamedExport) { + let NamedExport { + specifiers, src, .. + } = n.take(); + + if let Some(src) = src { + self.link + .entry(src.value) + .or_default() + .mut_dummy_span(src.span) + .extend(specifiers.into_iter().map(Into::into)); + } else { + self.export.extend(specifiers.into_iter().map(|e| match e { + ExportSpecifier::Namespace(..) => { + unreachable!("`export *` without src is invalid") + } + ExportSpecifier::Default(ExportDefaultSpecifier { exported }) => { + ((js_word!("default"), DUMMY_SP), exported) + } + ExportSpecifier::Named(ExportNamedSpecifier { orig, exported, .. }) => { + let orig = match orig { + ModuleExportName::Ident(id) => id, + ModuleExportName::Str(_) => { + unreachable!(r#"`export {{ "foo" }}` without src is invalid"#) + } + }; + + if let Some(exported) = exported { + let exported = match exported { + ModuleExportName::Ident(Ident { span, sym, .. }) => (sym, span), + ModuleExportName::Str(Str { span, value, .. }) => (value, span), + }; + + (exported, orig) + } else { + let exported = orig.sym.clone(); + ((exported, orig.span), orig) + } + } + })) + } + } + + /// ```javascript + /// export default class foo {}; + /// export default class {}; + /// export default function bar () {}; + /// export default function () {}; + /// ``` + /// -> + /// ```javascript + /// class foo {}; + /// class _default {}; + /// function bar () {}; + /// function _default () {}; + /// ``` + fn visit_mut_export_default_decl(&mut self, n: &mut ExportDefaultDecl) { + match &mut n.decl { + DefaultDecl::Class(class_expr) => { + let ident = class_expr + .ident + .get_or_insert_with(|| private_ident!("_default")) + .clone(); + + self.export.insert((js_word!("default"), DUMMY_SP), ident); + } + DefaultDecl::Fn(fn_expr) => { + let ident = fn_expr + .ident + .get_or_insert_with(|| private_ident!("_default")) + .clone(); + + self.export.insert((js_word!("default"), DUMMY_SP), ident); + } + DefaultDecl::TsInterfaceDecl(_) => {} + } + } + + /// ```javascript + /// export default foo; + /// export default 1 + /// ``` + /// -> + /// ```javascript + /// var _default = foo; + /// var _default = 1; + /// ``` + fn visit_mut_export_default_expr(&mut self, n: &mut ExportDefaultExpr) { + let ident = private_ident!("_default"); + + self.export + .insert((js_word!("default"), DUMMY_SP), ident.clone()); + + self.export_default = Some(Stmt::Decl( + n.expr + .take() + .into_var_decl(VarDeclKind::Var, ident.into()) + .into(), + )); + } + + /// ```javascript + /// export * from "mod"; + /// ``` + fn visit_mut_export_all(&mut self, n: &mut ExportAll) { + let Str { + value: src_key, + span: src_span, + .. + } = n.take().src; + + self.link + .entry(src_key) + .or_default() + .mut_dummy_span(src_span) + .insert(LinkSpecifier::ExportStar); + } + + /// ```javascript + /// import foo = require("mod"); + /// export import foo = require("mod"); + /// ``` + fn visit_mut_ts_import_equals_decl(&mut self, n: &mut TsImportEqualsDecl) { + let TsImportEqualsDecl { + id, + module_ref, + is_export, + declare, + is_type_only, + .. + } = n; + + debug_assert!(!*declare); + debug_assert!(!*is_type_only); + + if let TsModuleRef::TsExternalModuleRef(TsExternalModuleRef { + expr: + Str { + span, + value: src_key, + .. + }, + .. + }) = module_ref + { + if *is_export { + self.export.insert((id.sym.clone(), id.span), id.clone()); + } + + self.link + .entry(src_key.clone()) + .or_default() + .mut_dummy_span(*span) + .insert(LinkSpecifier::ImportEqual(id.to_id())); + } + } + + /// ```javascript + /// export = expr; + /// ``` + fn visit_mut_ts_export_assignment(&mut self, n: &mut TsExportAssignment) { + self.export_assign = Some(n.expr.take()); + } +} + +#[derive(Debug, PartialEq, Eq, Hash)] +pub enum LinkSpecifier { + /// ```javascript + /// import { imported as local, local } from "mod"; + /// import { "imported" as local } from "mod"; + /// ``` + /// Note: imported will never be `default` + ImportNamed { imported: Option, local: Id }, + + /// ```javascript + /// import foo from "mod"; + /// ``` + ImportDefault(Id), + + /// ```javascript + /// import * as foo from "mod"; + /// ``` + ImportStarAs(Id), + + /// ```javascript + /// export { orig, orig as exported } from "mod"; + /// export { "orig", "orig" as "exported" } from "mod"; + /// ``` + /// Note: orig will never be `default` + ExportNamed { + orig: (JsWord, Span), + exported: Option<(JsWord, Span)>, + }, + + /// ```javascript + /// export { default } from "foo"; + /// export { "default" } from "foo"; + /// export { default as foo } from "mod"; + /// ``` + /// (default_span, local_sym, local_span) + ExportDefaultAs(Span, JsWord, Span), + + /// ```javascript + /// export * as foo from "mod"; + /// export * as "bar" from "mod"; + /// ``` + ExportStarAs(JsWord, Span), + + /// ```javascript + /// export * from "mod"; + /// ``` + ExportStar, + + /// ```javascript + /// import foo = require("foo"); + /// ``` + ImportEqual(Id), +} + +impl From for LinkSpecifier { + fn from(i: ImportSpecifier) -> Self { + match i { + ImportSpecifier::Namespace(ImportStarAsSpecifier { local, .. }) => { + Self::ImportStarAs(local.to_id()) + } + + ImportSpecifier::Default(ImportDefaultSpecifier { local, .. }) + | ImportSpecifier::Named(ImportNamedSpecifier { + local, + imported: + Some(ModuleExportName::Ident(Ident { + sym: js_word!("default"), + .. + })) + | Some(ModuleExportName::Str(Str { + value: js_word!("default"), + .. + })), + .. + }) => Self::ImportDefault(local.to_id()), + + ImportSpecifier::Named(ImportNamedSpecifier { + local, imported, .. + }) => { + let imported = imported.map(|e| match e { + ModuleExportName::Ident(Ident { sym, .. }) => sym, + ModuleExportName::Str(Str { value, .. }) => value, + }); + + Self::ImportNamed { + local: local.to_id(), + imported, + } + } + } + } +} + +impl From for LinkSpecifier { + fn from(e: ExportSpecifier) -> Self { + match e { + ExportSpecifier::Namespace(ExportNamespaceSpecifier { + name: + ModuleExportName::Ident(Ident { span, sym, .. }) + | ModuleExportName::Str(Str { + span, value: sym, .. + }), + .. + }) => Self::ExportStarAs(sym, span), + + ExportSpecifier::Default(ExportDefaultSpecifier { exported }) => { + // https://github.com/tc39/proposal-export-default-from + Self::ExportDefaultAs(exported.span, exported.sym, exported.span) + } + + ExportSpecifier::Named(ExportNamedSpecifier { orig, exported, .. }) => { + let orig = match orig { + ModuleExportName::Ident(Ident { span, sym, .. }) + | ModuleExportName::Str(Str { + span, value: sym, .. + }) => (sym, span), + }; + + let exported = exported.map(|exported| match exported { + ModuleExportName::Ident(Ident { span, sym, .. }) + | ModuleExportName::Str(Str { + span, value: sym, .. + }) => (sym, span), + }); + + match orig { + (js_word!("default"), default_span) => { + let (sym, span) = exported.unwrap_or(orig); + + Self::ExportDefaultAs(default_span, sym, span) + } + _ => Self::ExportNamed { orig, exported }, + } + } + } + } +} + +#[derive(Debug, Default)] +pub struct LinkItem(pub Span, pub AHashSet, pub LinkFlag); + +use bitflags::bitflags; + +bitflags! { + #[derive(Default)] + pub struct LinkFlag: u8 { + const NAMED = 1 << 0; + const DEFAULT = 1 << 1; + const NAMESPACE = Self::NAMED.bits | Self::DEFAULT.bits; + const EXPORT_STAR = 1 << 2; + const IMPORT_EQUAL = 1 << 3; + } +} + +impl LinkFlag { + pub fn interop(&self) -> bool { + self.intersects(Self::DEFAULT) + } + + pub fn has_named(&self) -> bool { + self.intersects(Self::NAMED) + } + + pub fn namespace(&self) -> bool { + self.contains(Self::NAMESPACE) + } + + pub fn need_raw_import(&self) -> bool { + self.interop() && self.intersects(Self::IMPORT_EQUAL) + } + + pub fn export_star(&self) -> bool { + self.intersects(Self::EXPORT_STAR) + } +} + +impl From<&LinkSpecifier> for LinkFlag { + fn from(s: &LinkSpecifier) -> Self { + match s { + LinkSpecifier::ImportStarAs(..) => Self::NAMESPACE, + LinkSpecifier::ImportDefault(..) => Self::DEFAULT, + LinkSpecifier::ImportNamed { .. } => Self::NAMED, + + LinkSpecifier::ExportStarAs(..) => Self::NAMESPACE, + LinkSpecifier::ExportDefaultAs(..) => Self::DEFAULT, + LinkSpecifier::ExportNamed { .. } => Self::NAMED, + + LinkSpecifier::ImportEqual(..) => Self::IMPORT_EQUAL, + LinkSpecifier::ExportStar => Self::EXPORT_STAR, + } + } +} + +impl From<&ImportSpecifier> for LinkFlag { + fn from(i: &ImportSpecifier) -> Self { + match i { + ImportSpecifier::Namespace(..) => Self::NAMESPACE, + + ImportSpecifier::Default(ImportDefaultSpecifier { .. }) + | ImportSpecifier::Named(ImportNamedSpecifier { + imported: + Some(ModuleExportName::Ident(Ident { + sym: js_word!("default"), + .. + })) + | Some(ModuleExportName::Str(Str { + value: js_word!("default"), + .. + })), + .. + }) => Self::DEFAULT, + + ImportSpecifier::Named(..) => Self::NAMED, + } + } +} + +impl From<&ExportSpecifier> for LinkFlag { + fn from(e: &ExportSpecifier) -> Self { + match e { + ExportSpecifier::Namespace(..) => Self::NAMESPACE, + + // https://github.com/tc39/proposal-export-default-from + ExportSpecifier::Default(..) + | ExportSpecifier::Named(ExportNamedSpecifier { + orig: + ModuleExportName::Ident(Ident { + sym: js_word!("default"), + .. + }) + | ModuleExportName::Str(Str { + value: js_word!("default"), + .. + }), + .. + }) => Self::DEFAULT, + + ExportSpecifier::Named(..) => Self::NAMED, + } + } +} + +impl Extend for LinkItem { + fn extend>(&mut self, iter: T) { + iter.into_iter().for_each(|link| { + self.insert(link); + }); + } +} + +impl LinkItem { + fn mut_dummy_span(&mut self, span: Span) -> &mut Self { + if self.0.is_dummy() { + self.0 = span; + } + + self + } + + fn insert(&mut self, link: LinkSpecifier) -> bool { + self.2 |= (&link).into(); + self.1.insert(link) + } +} + +/// (exported_name, exported_span, expr) +pub type ExportObjPropList = Vec<(JsWord, Span, Expr)>; + +/// Reduce self to generate ImportMap and ExportObjPropList +pub trait LinkSpecifierReducer { + fn reduce( + self, + import_map: &mut ImportMap, + export_obj_prop_list: &mut ExportObjPropList, + mod_ident: &Ident, + raw_mod_ident: &Option, + ref_to_mod_ident: &mut bool, + is_swc_default_helper: bool, + ); +} + +impl LinkSpecifierReducer for AHashSet { + fn reduce( + self, + import_map: &mut ImportMap, + export_obj_prop_list: &mut ExportObjPropList, + mod_ident: &Ident, + raw_mod_ident: &Option, + ref_to_mod_ident: &mut bool, + is_swc_default_helper: bool, + ) { + self.into_iter().for_each(|s| match s { + LinkSpecifier::ImportNamed { imported, local } => { + *ref_to_mod_ident = true; + + import_map.insert( + local.clone(), + (mod_ident.clone(), imported.or(Some(local.0))), + ); + } + LinkSpecifier::ImportDefault(id) => { + *ref_to_mod_ident = true; + + import_map.insert( + id, + ( + mod_ident.clone(), + (!is_swc_default_helper).then(|| js_word!("default")), + ), + ); + } + LinkSpecifier::ImportStarAs(id) => { + *ref_to_mod_ident = true; + + import_map.insert(id, (mod_ident.clone(), None)); + } + LinkSpecifier::ExportNamed { orig, exported } => { + *ref_to_mod_ident = true; + + let (key, span) = exported.unwrap_or_else(|| orig.clone()); + + let expr = { + let (name, span) = orig; + if is_valid_prop_ident(&name) { + mod_ident.clone().make_member(quote_ident!(span, name)) + } else { + mod_ident.clone().computed_member(Str { + span, + value: name, + raw: None, + }) + } + }; + export_obj_prop_list.push((key, span, expr)) + } + LinkSpecifier::ExportDefaultAs(default_span, key, span) => { + *ref_to_mod_ident = true; + + let expr = mod_ident + .clone() + .make_member(quote_ident!(default_span, "default")); + export_obj_prop_list.push((key, span, expr)) + } + LinkSpecifier::ExportStarAs(key, span) => { + *ref_to_mod_ident = true; + + let expr = mod_ident.clone().into(); + export_obj_prop_list.push((key, span, expr)) + } + LinkSpecifier::ExportStar => {} + LinkSpecifier::ImportEqual(id) => { + *ref_to_mod_ident = true; + + import_map.insert( + id, + ( + raw_mod_ident.clone().unwrap_or_else(|| mod_ident.clone()), + None, + ), + ); + } + }) + } +} diff --git a/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs b/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs new file mode 100644 index 00000000000..b72cef18d24 --- /dev/null +++ b/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs @@ -0,0 +1,139 @@ +use swc_atoms::JsWord; +use swc_common::{ + collections::{AHashMap, AHashSet}, + util::take::Take, + DUMMY_SP, +}; +use swc_ecma_ast::{Id, Ident, *}; +use swc_ecma_utils::{undefined, ExprFactory, IntoIndirectCall}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; + +use crate::util::prop_name; + +pub type ImportMap = AHashMap)>; + +pub(crate) struct ModuleRefRewriter { + /// ```javascript + /// import foo, { a as b, c } from "mod"; + /// import * as x from "x"; + /// foo, b, c; + /// x; + /// ``` + /// -> + /// ```javascript + /// _mod.default, _mod.a, _mod.c; + /// _x; + /// + /// Map( + /// foo => (_mod, Some("default")), + /// b => (_mod, Some("a")), + /// c => (_mod, Some("c")), + /// x => (_x, None), + /// ) + /// ``` + pub import_map: ImportMap, + + pub lazy_record: AHashSet, + + pub top_level: bool, +} + +impl VisitMut for ModuleRefRewriter { + noop_visit_mut_type!(); + + fn visit_mut_expr(&mut self, n: &mut Expr) { + match n { + Expr::Ident(ref_ident) => { + if let Some((mod_ident, mod_prop)) = self.import_map.get(&ref_ident.to_id()) { + let mut mod_ident = mod_ident.clone(); + let span = ref_ident.span.with_ctxt(mod_ident.span.ctxt); + mod_ident.span = span; + + let mod_expr = if self.lazy_record.contains(&mod_ident.to_id()) { + mod_ident.as_call(span, Default::default()) + } else { + mod_ident.into() + }; + + if let Some(imported_name) = mod_prop { + let prop = prop_name(imported_name, DUMMY_SP).into(); + + *n = MemberExpr { + obj: Box::new(mod_expr), + span, + prop, + } + .into(); + } else { + *n = mod_expr; + } + } + } + + Expr::This(ThisExpr { span }) => { + if self.top_level { + *n = *undefined(*span); + } + } + + _ => n.visit_mut_children_with(self), + }; + } + + fn visit_mut_callee(&mut self, n: &mut Callee) { + match n { + Callee::Expr(e) if e.is_ident() => { + let is_indirect_callee = e + .as_ident() + .and_then(|ident| self.import_map.get(&ident.to_id())) + .map(|(mod_ident, prop)| { + prop.is_some() && !self.lazy_record.contains(&mod_ident.to_id()) + }) + .unwrap_or_default(); + + e.visit_mut_with(self); + + if is_indirect_callee { + *n = n.take().into_indirect() + } + } + + _ => n.visit_mut_children_with(self), + } + } + + fn visit_mut_function(&mut self, n: &mut Function) { + n.params.visit_mut_with(self); + + self.visit_mut_with_non_top_level(&mut n.body); + } + + fn visit_mut_constructor(&mut self, n: &mut Constructor) { + n.params.visit_mut_with(self); + + self.visit_mut_with_non_top_level(&mut n.body); + } + + fn visit_mut_class_prop(&mut self, n: &mut ClassProp) { + n.key.visit_mut_with(self); + + self.visit_mut_with_non_top_level(&mut n.value); + } + + fn visit_mut_static_block(&mut self, n: &mut StaticBlock) { + self.visit_mut_with_non_top_level(&mut n.body); + } +} + +impl ModuleRefRewriter { + fn visit_mut_with_non_top_level(&mut self, n: &mut T) + where + T: VisitMutWith, + { + let top_level = self.top_level; + + self.top_level = false; + n.visit_mut_with(self); + self.top_level = top_level; + } +} diff --git a/crates/swc_ecma_transforms_module/src/umd.rs b/crates/swc_ecma_transforms_module/src/umd.rs index 90fbd6a7f07..f3aada5dc2e 100644 --- a/crates/swc_ecma_transforms_module/src/umd.rs +++ b/crates/swc_ecma_transforms_module/src/umd.rs @@ -1,862 +1,500 @@ -use std::cell::{Ref, RefCell, RefMut}; - -use indexmap::IndexSet; -use swc_atoms::js_word; -use swc_common::{sync::Lrc, FileName, Mark, SourceMap, DUMMY_SP}; +use anyhow::Context; +use swc_atoms::JsWord; +use swc_common::{sync::Lrc, util::take::Take, FileName, Mark, SourceMap, Span, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_transforms_base::helper; +use swc_ecma_transforms_base::{feature::FeatureFlag, helper, helper_expr}; use swc_ecma_utils::{ - member_expr, prepend_stmts, private_ident, quote_ident, quote_str, var::VarCollector, - DestructuringFinder, ExprFactory, + is_valid_prop_ident, private_ident, quote_ident, quote_str, ExprFactory, IsDirective, }; -use swc_ecma_visit::{noop_fold_type, Fold, FoldWith, VisitWith}; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use self::config::BuiltConfig; pub use self::config::Config; -use super::util::{ - self, define_es_module, define_property, has_use_strict, initialize_to_undefined, - local_name_for_src, make_descriptor, use_strict, Exports, ModulePass, Scope, +use crate::{ + module_decl_strip::{Export, Link, LinkFlag, LinkItem, LinkSpecifierReducer, ModuleDeclStrip}, + module_ref_rewriter::{ImportMap, ModuleRefRewriter}, + path::{ImportResolver, Resolver}, + util::{ + clone_first_use_strict, define_es_module, emit_export_stmts, local_name_for_src, use_strict, + }, }; -use crate::path::{ImportResolver, Resolver}; mod config; -pub fn umd(cm: Lrc, unresolved_mark: Mark, config: Config) -> impl Fold { - Umd { - config: config.build(cm.clone()), - unresolved_mark, - cm, - - in_top_level: Default::default(), - scope: RefCell::new(Default::default()), - exports: Default::default(), - - resolver: Resolver::Default, - vars: Default::default(), - } -} - -pub fn umd_with_resolver( - resolver: Box, - base: FileName, +pub fn umd( cm: Lrc, unresolved_mark: Mark, config: Config, -) -> impl Fold { - Umd { + available_features: FeatureFlag, +) -> impl Fold + VisitMut { + as_folder(Umd { config: config.build(cm.clone()), unresolved_mark, cm, + resolver: Resolver::Default, + available_features, + const_var_kind: if caniuse!(available_features.BlockScoping) { + VarDeclKind::Const + } else { + VarDeclKind::Var + }, - in_top_level: Default::default(), - scope: Default::default(), - exports: Default::default(), + dep_list: Default::default(), - resolver: Resolver::Real { base, resolver }, - vars: Default::default(), - } + exports: None, + }) } -struct Umd { +pub fn umd_with_resolver( + cm: Lrc, + resolver: Box, + base: FileName, + unresolved_mark: Mark, + config: Config, + available_features: FeatureFlag, +) -> impl Fold + VisitMut { + as_folder(Umd { + config: config.build(cm.clone()), + unresolved_mark, + cm, + resolver: Resolver::Real { base, resolver }, + available_features, + const_var_kind: if caniuse!(available_features.BlockScoping) { + VarDeclKind::Const + } else { + VarDeclKind::Var + }, + + dep_list: Default::default(), + exports: None, + }) +} + +pub struct Umd { cm: Lrc, unresolved_mark: Mark, - in_top_level: bool, config: BuiltConfig, - scope: RefCell, - exports: Exports, - resolver: Resolver, - vars: RefCell>, + available_features: FeatureFlag, + const_var_kind: VarDeclKind, + + dep_list: Vec<(Ident, JsWord, Span)>, + + exports: Option, } -/// TODO: VisitMut -impl Fold for Umd { - noop_fold_type!(); - - mark_as_nested!(); - - fn fold_expr(&mut self, expr: Expr) -> Expr { - let exports = self.exports.0.clone(); - let top_level = self.in_top_level; - - Scope::fold_expr(self, exports, top_level, expr) - } - - fn fold_module(&mut self, module: Module) -> Module { - self.in_top_level = true; +impl VisitMut for Umd { + noop_visit_mut_type!(); + fn visit_mut_module(&mut self, module: &mut Module) { let filename = self.cm.span_to_filename(module.span); + let exported_name = self.config.determine_export_name(filename); - let items = module.body; + let module_items = &mut module.body; - // Inserted after initializing exported names to undefined. - let mut extra_stmts = vec![]; - let mut stmts = Vec::with_capacity(items.len() + 3); - if self.config.config.strict_mode && !has_use_strict(&items) { - stmts.push(use_strict()); + let mut strip = ModuleDeclStrip::default(); + module_items.visit_mut_with(&mut strip); + + let mut stmts: Vec = Vec::with_capacity(module_items.len() + 4); + + // "use strict"; + if self.config.config.strict_mode { + stmts.push(clone_first_use_strict(module_items).unwrap_or_else(use_strict)); } - let mut exports = vec![]; - let mut initialized = IndexSet::default(); - let mut export_alls = vec![]; - let mut emitted_esmodule = false; - let mut has_export = false; - let exports_ident = self.exports.0.clone(); + let ModuleDeclStrip { + link, + export, + export_assign, + has_module_decl, + .. + } = strip; - // Process items - for item in items { - let decl = match item { - ModuleItem::Stmt(stmt) => { - extra_stmts.push(stmt.fold_with(self)); - continue; - } - ModuleItem::ModuleDecl(decl) => decl, + let is_export_assign = export_assign.is_some(); + + if has_module_decl && !self.config.config.no_interop && !is_export_assign { + stmts.push(define_es_module(self.exports())) + } + + let mut import_map = Default::default(); + + stmts.extend( + self.handle_import_export(&mut import_map, link, export, is_export_assign) + .map(Into::into), + ); + + stmts.extend(module_items.take().into_iter().filter_map(|i| match i { + ModuleItem::Stmt(stmt) if !stmt.is_use_strict() => Some(stmt), + _ => None, + })); + + if let Some(export_assign) = export_assign { + let return_stmt = ReturnStmt { + span: DUMMY_SP, + arg: Some(export_assign), }; - match decl { - ModuleDecl::Import(import) => self.scope.borrow_mut().insert_import(import), - - ModuleDecl::ExportAll(..) - | ModuleDecl::ExportDecl(..) - | ModuleDecl::ExportDefaultDecl(..) - | ModuleDecl::ExportDefaultExpr(..) - | ModuleDecl::ExportNamed(..) => { - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - has_export = true; - if !self.config.config.strict && !emitted_esmodule { - emitted_esmodule = true; - stmts.push(define_es_module(exports_ident.clone())); - } - - macro_rules! init_export { - ("default") => {{ - init_export!(js_word!("default")) - }}; - ($name:expr) => {{ - exports.push($name.clone()); - initialized.insert($name.clone()); - }}; - } - match decl { - // Function declaration cannot throw an error. - ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { - decl: DefaultDecl::Fn(..), - .. - }) => { - // initialized.insert(js_word!("default")); - } - - ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { - decl: DefaultDecl::TsInterfaceDecl(..), - .. - }) => {} - - ModuleDecl::ExportAll(ref export) => { - scope - .import_types - .entry(export.src.value.clone()) - .and_modify(|v| *v = true); - } - - ModuleDecl::ExportDefaultDecl(..) | ModuleDecl::ExportDefaultExpr(..) => { - // TODO: Optimization (when expr cannot throw, `exports.default = - // void 0` is not required) - init_export!("default") - } - _ => {} - } - drop(scope_ref_mut); - - match decl { - ModuleDecl::ExportAll(export) => export_alls.push(export), - ModuleDecl::ExportDecl(ExportDecl { - decl: decl @ Decl::Class(..), - .. - }) - | ModuleDecl::ExportDecl(ExportDecl { - decl: decl @ Decl::Fn(..), - .. - }) => { - let (ident, is_class) = match decl { - Decl::Class(ref c) => (c.ident.clone(), true), - Decl::Fn(ref f) => (f.ident.clone(), false), - _ => unreachable!(), - }; - - // - extra_stmts.push(Stmt::Decl(decl.fold_with(self))); - - let append_to: &mut Vec<_> = if is_class { - &mut extra_stmts - } else { - // Function declaration cannot throw - &mut stmts - }; - - append_to.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident.clone().make_member(ident.clone()), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt(), - ); - } - ModuleDecl::ExportDecl(ExportDecl { - decl: Decl::Var(var), - .. - }) => { - extra_stmts.push(Stmt::Decl(Decl::Var(var.clone().fold_with(self)))); - - let scope = &mut *self.scope.borrow_mut(); - var.decls.visit_with(&mut VarCollector { - to: &mut scope.declared_vars, - }); - - let mut found: Vec = vec![]; - for decl in var.decls { - let mut v = DestructuringFinder { found: &mut found }; - decl.visit_with(&mut v); - - for ident in found.drain(..) { - scope - .exported_bindings - .entry((ident.sym.clone(), ident.span.ctxt())) - .or_default() - .push((ident.sym.clone(), ident.span.ctxt())); - init_export!(ident.sym); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident.clone().make_member(ident.clone()), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt(), - ); - } - } - } - ModuleDecl::ExportDefaultDecl(decl) => match decl.decl { - DefaultDecl::Class(ClassExpr { ident, class }) => { - let ident = ident.unwrap_or_else(|| private_ident!("_default")); - - extra_stmts.push(Stmt::Decl(Decl::Class(ClassDecl { - ident: ident.clone(), - class, - declare: false, - }))); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident - .clone() - .make_member(quote_ident!("default")), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt(), - ); - } - DefaultDecl::Fn(FnExpr { ident, function }) => { - let ident = ident.unwrap_or_else(|| private_ident!("_default")); - - extra_stmts.push(Stmt::Decl(Decl::Fn( - FnDecl { - ident: ident.clone(), - function, - declare: false, - } - .fold_with(self), - ))); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident - .clone() - .make_member(quote_ident!("default")), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt(), - ); - } - _ => {} - }, - - ModuleDecl::ExportDefaultExpr(expr) => { - let ident = private_ident!("_default"); - - // We use extra statements because of the initialization - extra_stmts.push(Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: Some(expr.expr.fold_with(self)), - definite: false, - }], - declare: false, - }))); - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident.clone().make_member(quote_ident!("default")), - )), - op: op!("="), - right: Box::new(ident.into()), - } - .into_stmt(), - ); - } - - // export { foo } from 'foo'; - ModuleDecl::ExportNamed(export) => { - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - let imported = export.src.clone().map(|src| { - scope.import_to_export(&src, !export.specifiers.is_empty()) - }); - drop(scope_ref_mut); - - stmts.reserve(export.specifiers.len()); - - for ExportNamedSpecifier { orig, exported, .. } in export - .specifiers - .into_iter() - .map(|e| match e { - ExportSpecifier::Named(e) => e, - ExportSpecifier::Default(..) => unreachable!( - "export default from 'foo'; should be removed by previous \ - pass" - ), - ExportSpecifier::Namespace(..) => unreachable!( - "export * as Foo from 'foo'; should be removed by \ - previous pass" - ), - }) - .filter(|e| !e.is_type_only) - { - let orig = match orig { - ModuleExportName::Ident(ident) => ident, - _ => unimplemented!("module string names unimplemented"), - }; - let exported = match exported { - Some(ModuleExportName::Ident(ident)) => Some(ident), - Some(ModuleExportName::Str(..)) => { - unimplemented!("module string names unimplemented") - } - _ => None, - }; - - let is_import_default = orig.sym == js_word!("default"); - - let key = (orig.sym.clone(), orig.span.ctxt()); - let mut scope_ref_mut = self.scope.borrow_mut(); - let scope = &mut *scope_ref_mut; - if scope.declared_vars.contains(&key) { - scope - .exported_bindings - .entry(key.clone()) - .or_default() - .push( - exported - .clone() - .map(|i| (i.sym.clone(), i.span.ctxt())) - .unwrap_or_else(|| { - (orig.sym.clone(), orig.span.ctxt()) - }), - ); - } - - if let Some(ref src) = export.src { - if is_import_default { - scope - .import_types - .entry(src.value.clone()) - .or_insert(false); - } - } - drop(scope_ref_mut); - - let value = match imported { - Some(ref imported) => Box::new( - imported.clone().unwrap().make_member(orig.clone()), - ), - None => Box::new(Expr::Ident(orig.clone()).fold_with(self)), - }; - - // True if we are exporting our own stuff. - let is_value_ident = matches!(*value, Expr::Ident(..)); - - if is_value_ident { - let exported_symbol = exported - .as_ref() - .map(|e| e.sym.clone()) - .unwrap_or_else(|| orig.sym.clone()); - init_export!(exported_symbol); - - extra_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports_ident - .clone() - .make_member(exported.unwrap_or(orig)), - )), - op: op!("="), - right: value, - } - .into_stmt(), - ); - } else { - stmts.push( - define_property(vec![ - exports_ident.clone().as_arg(), - { - // export { foo } - // -> 'foo' - - // export { foo as bar } - // -> 'bar' - let i = exported.unwrap_or(orig); - quote_str!(i.span, i.sym).as_arg() - }, - make_descriptor(value).as_arg(), - ]) - .into_stmt(), - ); - } - } - } - - _ => {} - } - } - - ModuleDecl::TsImportEquals(..) - | ModuleDecl::TsExportAssignment(..) - | ModuleDecl::TsNamespaceExport(..) => {} - } + stmts.push(return_stmt.into()) } - let vars = self.vars_take(); - - if !vars.is_empty() { - let var_stmt = Stmt::Decl( - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: false, - decls: vars, - } - .into(), - ); - - stmts.push(var_stmt); - } - - // ==================== - // Handle imports - // ==================== - - // Prepended to statements. - let mut import_stmts = vec![]; - let mut define_deps_arg = ArrayLit { - span: DUMMY_SP, - elems: vec![], - }; - - let scope = &mut *self.scope.borrow_mut(); - let mut factory_params = Vec::with_capacity(scope.imports.len() + 1); - let mut factory_args = Vec::with_capacity(factory_params.capacity()); - let mut global_factory_args = Vec::with_capacity(factory_params.capacity()); - if has_export { - define_deps_arg - .elems - .push(Some(Lit::Str(quote_str!("exports")).as_arg())); - factory_params.push(Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: exports_ident.clone().into(), - }); - factory_args.push(quote_ident!("exports").as_arg()); - global_factory_args.push(member_expr!(DUMMY_SP, mod.exports).as_arg()); - } - - // Used only if export * exists - let exported_names = { - if !export_alls.is_empty() && !exports.is_empty() { - let exported_names = private_ident!("_exportNames"); - stmts.push(Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: exported_names.clone().into(), - init: Some(Box::new(Expr::Object(ObjectLit { - span: DUMMY_SP, - props: exports - .into_iter() - .filter_map(|export| { - if export == js_word!("default") { - return None; - } - - Some(PropOrSpread::Prop(Box::new(Prop::KeyValue( - KeyValueProp { - key: PropName::Ident(Ident::new(export, DUMMY_SP)), - value: true.into(), - }, - )))) - }) - .collect(), - }))), - definite: false, - }], - declare: false, - }))); - - Some(exported_names) - } else { - None - } - }; - - for export in export_alls { - let span = export.span; - let export = scope - .import_to_export(&export.src, true) - .expect("Export should exists"); - stmts.push(Scope::handle_export_all( - span, - exports_ident.clone(), - exported_names.clone(), - export, - )); - } - - if !initialized.is_empty() { - stmts.extend(initialize_to_undefined(exports_ident, initialized)); - } - - for (src, (src_span, import)) in scope.imports.drain(..) { - let global_ident = Ident::new(self.config.global_name(&src), DUMMY_SP); - let import = import.unwrap_or_else(|| { - ( - local_name_for_src(&src), - DUMMY_SP.apply_mark(Mark::fresh(Mark::root())), - ) - }); - let ident = Ident::new(import.0.clone(), import.1); - - define_deps_arg - .elems - .push(Some(Lit::Str(quote_str!(src.clone())).as_arg())); - factory_params.push(Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: ident.clone().into(), - }); - factory_args.push( - self.resolver - .make_require_call(self.unresolved_mark, src.clone(), src_span) - .as_arg(), - ); - global_factory_args.push(quote_ident!("global").make_member(global_ident).as_arg()); - - { - // handle interop - let ty = scope.import_types.get(&src); - - if let Some(&wildcard) = ty { - let imported = ident.clone(); - - if !self.config.config.no_interop { - let right = Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: if wildcard { - helper!(interop_require_wildcard, "interopRequireWildcard") - } else { - helper!(interop_require_default, "interopRequireDefault") - }, - args: vec![imported.as_arg()], - type_args: Default::default(), - })); - - import_stmts.push( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Pat(ident.clone().into()), - op: op!("="), - right, - } - .into_stmt(), - ); - } - }; - } - } - - prepend_stmts(&mut stmts, import_stmts.into_iter()); - stmts.append(&mut extra_stmts); + stmts.visit_mut_children_with(&mut ModuleRefRewriter { + import_map, + lazy_record: Default::default(), + top_level: true, + }); // ==================== // Emit // ==================== - let helper_fn = Function { - span: DUMMY_SP, - is_async: false, - is_generator: false, - decorators: Default::default(), - params: vec![ - Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: quote_ident!("global").into(), - }, - Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: quote_ident!("factory").into(), - }, - ], - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: { - // typeof define === 'function' && define.amd - let is_amd = Box::new( - UnaryExpr { - span: DUMMY_SP, - op: op!("typeof"), - arg: Box::new(Expr::Ident(quote_ident!("define"))), - } - .make_eq(Lit::Str(quote_str!("function"))) - .make_bin(op!("&&"), *member_expr!(DUMMY_SP, define.amd)), - ); + let (adapter_fn_expr, factory_params) = self.adapter(exported_name, is_export_assign); - let is_common_js = Box::new( - UnaryExpr { - span: DUMMY_SP, - op: op!("typeof"), - arg: Box::new(Expr::Ident(quote_ident!("exports"))), - } - .make_bin(op!("!=="), Lit::Str(quote_str!("undefined"))), - ); - - vec![Stmt::If(IfStmt { - span: DUMMY_SP, - test: is_amd, - cons: Box::new(Stmt::Block(BlockStmt { - span: DUMMY_SP, - stmts: vec![ - // define(['foo'], factory) - CallExpr { - span: DUMMY_SP, - callee: quote_ident!("define").as_callee(), - args: vec![ - define_deps_arg.as_arg(), - quote_ident!("factory").as_arg(), - ], - type_args: Default::default(), - } - .into_stmt(), - ], - })), - alt: Some(Box::new(Stmt::If(IfStmt { - span: DUMMY_SP, - test: is_common_js, - cons: Box::new(Stmt::Block(BlockStmt { - span: DUMMY_SP, - stmts: vec![ - // factory(require('foo')) - CallExpr { - span: DUMMY_SP, - callee: quote_ident!("factory").as_callee(), - args: factory_args, - type_args: Default::default(), - } - .into_stmt(), - ], - })), - alt: Some(Box::new(Stmt::Block(BlockStmt { - span: DUMMY_SP, - stmts: vec![ - Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: vec![VarDeclarator { - span: DUMMY_SP, - name: quote_ident!("mod").into(), - init: Some(Box::new(Expr::Object(ObjectLit { - span: DUMMY_SP, - props: vec![PropOrSpread::Prop(Box::new( - Prop::KeyValue(KeyValueProp { - key: PropName::Ident(quote_ident!( - "exports" - )), - value: Box::new(Expr::Object(ObjectLit { - span: DUMMY_SP, - props: vec![], - })), - }), - ))], - }))), - definite: false, - }], - declare: false, - })), - CallExpr { - span: DUMMY_SP, - callee: quote_ident!("factory").as_callee(), - args: global_factory_args, - type_args: Default::default(), - } - .into_stmt(), - { - let exported_name = - self.config.determine_export_name(filename); - - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - quote_ident!("global").make_member(exported_name), - )), - op: op!("="), - right: member_expr!(DUMMY_SP,mod.exports), - } - .into_stmt() - }, - ], - }))), - }))), - })] - }, - }), - - return_type: Default::default(), - type_params: Default::default(), - }; - - let factory_arg = FnExpr { + let factory_fn_expr = FnExpr { ident: None, function: Function { - span: DUMMY_SP, - is_async: false, - is_generator: false, - decorators: Default::default(), params: factory_params, + decorators: Default::default(), + span: DUMMY_SP, body: Some(BlockStmt { span: DUMMY_SP, stmts, }), - - return_type: Default::default(), - type_params: Default::default(), + is_generator: false, + is_async: false, + type_params: None, + return_type: None, }, - } - .as_arg(); + }; - Module { - body: vec![CallExpr { - span: DUMMY_SP, - callee: FnExpr { - ident: None, - function: helper_fn, - } - .wrap_with_paren() - .as_callee(), - args: vec![ThisExpr { span: DUMMY_SP }.as_arg(), factory_arg], - type_args: Default::default(), - } + *module_items = vec![adapter_fn_expr + .as_call( + DUMMY_SP, + vec![ + ThisExpr { span: DUMMY_SP }.as_arg(), + factory_fn_expr.as_arg(), + ], + ) .into_stmt() - .into()], - ..module - } - } - - fn fold_prop(&mut self, p: Prop) -> Prop { - match p { - Prop::Shorthand(ident) => Scope::fold_shorthand_prop(self, ident), - - _ => p.fold_children_with(self), - } - } - - /// - /// - collects all declared variables for let and var. - fn fold_var_decl(&mut self, var: VarDecl) -> VarDecl { - if var.kind != VarDeclKind::Const { - var.decls.visit_with(&mut VarCollector { - to: &mut self.scope.borrow_mut().declared_vars, - }); - } - - VarDecl { - decls: var.decls.fold_with(self), - ..var - } + .into()] } } -impl ModulePass for Umd { - fn config(&self) -> &util::Config { - &self.config.config +impl Umd { + fn handle_import_export( + &mut self, + import_map: &mut ImportMap, + link: Link, + export: Export, + is_export_assign: bool, + ) -> impl Iterator { + let mut stmts = Vec::with_capacity(link.len()); + + let mut export_obj_prop_list = export + .into_iter() + .map(|((key, span), ident)| (key, span, ident.into())) + .collect(); + + link.into_iter().for_each( + |(src, LinkItem(src_span, link_specifier_set, mut link_flag))| { + let is_swc_default_helper = + !link_flag.has_named() && src.starts_with("@swc/helpers/"); + + if self.config.config.no_interop || is_swc_default_helper { + link_flag -= LinkFlag::NAMESPACE; + } + + let need_re_export = link_flag.export_star(); + let need_interop = link_flag.interop(); + let need_new_var = link_flag.need_raw_import(); + + let mod_ident = private_ident!(local_name_for_src(&src)); + let new_var_ident = if need_new_var { + private_ident!(local_name_for_src(&src)) + } else { + mod_ident.clone() + }; + + self.dep_list.push((mod_ident.clone(), src, src_span)); + + link_specifier_set.reduce( + import_map, + &mut export_obj_prop_list, + &new_var_ident, + &Some(mod_ident.clone()), + &mut false, + is_swc_default_helper, + ); + + if is_swc_default_helper { + stmts.push( + mod_ident + .clone() + .make_member(quote_ident!("default")) + .make_assign_to(op!("="), mod_ident.clone().as_pat_or_expr()) + .into_stmt(), + ) + } + + // _exportStar(mod, exports); + let mut import_expr: Expr = if need_re_export { + helper_expr!(export_star, "exportStar").as_call( + DUMMY_SP, + vec![mod_ident.clone().as_arg(), self.exports().as_arg()], + ) + } else { + mod_ident.clone().into() + }; + + // _introp(mod); + if need_interop { + import_expr = CallExpr { + span: DUMMY_SP, + callee: if link_flag.namespace() { + helper!(interop_require_wildcard, "interopRequireWildcard") + } else { + helper!(interop_require_default, "interopRequireDefault") + }, + args: vec![import_expr.as_arg()], + type_args: Default::default(), + } + .into() + }; + + // mod = _introp(mod); + // var mod1 = _introp(mod); + if need_new_var { + let stmt: Stmt = Stmt::Decl(Decl::Var( + import_expr.into_var_decl(self.const_var_kind, new_var_ident.into()), + )); + + stmts.push(stmt) + } else if need_interop { + let stmt = import_expr + .make_assign_to(op!("="), mod_ident.as_pat_or_expr()) + .into_stmt(); + stmts.push(stmt); + } else if need_re_export { + stmts.push(import_expr.into_stmt()); + } + }, + ); + + let mut export_stmts = Default::default(); + + if !export_obj_prop_list.is_empty() && !is_export_assign { + let features = self.available_features; + let exports = self.exports(); + + export_stmts = emit_export_stmts(features, exports, export_obj_prop_list); + } + + export_stmts.into_iter().chain(stmts) } - fn scope(&self) -> Ref { - self.scope.borrow() + fn exports(&mut self) -> Ident { + self.exports + .get_or_insert_with(|| private_ident!("exports")) + .clone() } - fn scope_mut(&mut self) -> RefMut { - self.scope.borrow_mut() - } - - fn resolver(&self) -> &Resolver { - &self.resolver - } - - /// ```js - /// exports === undefined ? (try_amd) : (try_common_js) + /// - Without `export =` + /// ```javascript + /// (function (global, factory) { + /// if (typeof module === "object" && typeof module.exports === "object") { + /// factory(exports, require("mod")); + /// } else if (typeof define === "function" && define.amd) { + /// define(["exports", "mod"], factory); + /// } else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) { + /// factory((global.lib = {}), global.mod); + /// } + /// })(this, function (exports, mod) { + /// ... + /// }); /// ``` - fn make_dynamic_import(&mut self, span: swc_common::Span, args: Vec) -> Expr { - Expr::Cond(CondExpr { - span, - test: Box::new(quote_ident!("exports").make_eq(quote_ident!("undefined"))), - cons: Box::new(super::amd::handle_dynamic_import(span, args.clone())), - alt: Box::new(super::common_js::handle_dynamic_import( - span, - args, - !self.config.config.no_interop, - )), - }) - } + /// - With `export =` + /// ```javascript + /// (function (global, factory) { + /// if (typeof module === "object" && typeof module.exports === "object") { + /// module.exports = factory(require("mod")); + /// } else if (typeof define === "function" && define.amd) { + /// define(["mod"], factory); + /// } else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) { + /// global.lib = factory(global.mod); + /// } + /// })(this, function (mod) { + /// ... + /// }); + /// ``` + /// Return: adapter expr and factory params + fn adapter(&mut self, exported_name: Ident, is_export_assign: bool) -> (FnExpr, Vec) { + macro_rules! js_typeof { + ($test:expr =>! $type:expr) => { + Expr::Unary(UnaryExpr { + span: DUMMY_SP, + op: op!("typeof"), + arg: Box::new(Expr::from($test)), + }) + .make_bin(op!("!=="), quote_str!($type)) + }; - fn vars(&mut self) -> Ref> { - self.vars.borrow() - } + ($test:expr => $type:expr) => { + Expr::Unary(UnaryExpr { + span: DUMMY_SP, + op: op!("typeof"), + arg: Box::new(Expr::from($test)), + }) + .make_bin(op!("==="), quote_str!($type)) + }; + } - fn vars_mut(&mut self) -> RefMut> { - self.vars.borrow_mut() - } + // define unresolved ref + let module = quote_ident!(DUMMY_SP.apply_mark(self.unresolved_mark), "module"); - fn vars_take(&mut self) -> Vec { - self.vars.take() + let require = quote_ident!(DUMMY_SP.apply_mark(self.unresolved_mark), "require"); + let define = quote_ident!(DUMMY_SP.apply_mark(self.unresolved_mark), "define"); + let global_this = quote_ident!(DUMMY_SP.apply_mark(self.unresolved_mark), "globalThis"); + let js_self = quote_ident!(DUMMY_SP.apply_mark(self.unresolved_mark), "self"); + + // adapter arguments + let global = private_ident!("global"); + let factory = private_ident!("factory"); + + let module_exports = module.clone().make_member(quote_ident!("exports")); + let global_lib = global.clone().make_member(exported_name); + let define_amd = define.clone().make_member(quote_ident!("amd")); + + let mut cjs_args = vec![]; + let mut amd_dep_list = vec![]; + let mut browser_args = vec![]; + + let mut factory_params = vec![]; + + if !is_export_assign && self.exports.is_some() { + cjs_args.push(quote_ident!("exports").as_arg()); + amd_dep_list.push(Some(quote_str!("exports").as_arg())); + browser_args.push( + Expr::Object(ObjectLit { + span: DUMMY_SP, + props: Default::default(), + }) + .make_assign_to(op!("="), global_lib.as_pat_or_expr()) + .as_arg(), + ); + factory_params.push(self.exports().into()); + } + + self.dep_list + .take() + .into_iter() + .for_each(|(ident, src_path, src_span)| { + let src_path = match &self.resolver { + Resolver::Real { resolver, base } => resolver + .resolve_import(base, &src_path) + .with_context(|| format!("failed to resolve `{}`", src_path)) + .unwrap(), + Resolver::Default => src_path, + }; + + cjs_args.push( + require + .clone() + .as_call( + DUMMY_SP, + vec![quote_str!(src_span, src_path.clone()).as_arg()], + ) + .as_arg(), + ); + amd_dep_list.push(Some(quote_str!(src_span, src_path.clone()).as_arg())); + + let global_dep = { + let dep_name = self.config.global_name(&src_path); + let global = global.clone(); + if is_valid_prop_ident(&dep_name) { + global.make_member(quote_ident!(dep_name)) + } else { + global.computed_member(quote_str!(dep_name)) + } + }; + browser_args.push(global_dep.as_arg()); + factory_params.push(ident.into()); + }); + + let cjs_if_test = js_typeof!(module => "object") + .make_bin(op!("&&"), js_typeof!(module_exports.clone() => "object")); + let mut cjs_if_body = factory.clone().as_call(DUMMY_SP, cjs_args); + if is_export_assign { + cjs_if_body = + cjs_if_body.make_assign_to(op!("="), module_exports.clone().as_pat_or_expr()); + } + + let amd_if_test = js_typeof!(define.clone() => "function").make_bin(op!("&&"), define_amd); + let amd_if_body = define.as_call( + DUMMY_SP, + vec![ + ArrayLit { + span: DUMMY_SP, + elems: amd_dep_list, + } + .as_arg(), + factory.clone().as_arg(), + ], + ); + + let browser_if_test = CondExpr { + span: DUMMY_SP, + test: Box::new(js_typeof!(global_this.clone() =>! "undefined")), + cons: Box::new(global_this.into()), + alt: Box::new(global.clone().make_bin(op!("||"), js_self)), + } + .make_assign_to(op!("="), global.clone().as_pat_or_expr()); + + let mut browser_if_body = factory.clone().as_call(DUMMY_SP, browser_args); + if is_export_assign { + browser_if_body = + browser_if_body.make_assign_to(op!("="), module_exports.as_pat_or_expr()); + } + + let adapter_body = BlockStmt { + span: DUMMY_SP, + stmts: vec![IfStmt { + span: DUMMY_SP, + test: Box::new(cjs_if_test), + cons: Box::new(cjs_if_body.into_stmt()), + alt: Some(Box::new( + IfStmt { + span: DUMMY_SP, + test: Box::new(amd_if_test), + cons: Box::new(amd_if_body.into_stmt()), + alt: Some(Box::new( + IfStmt { + span: DUMMY_SP, + test: Box::new(browser_if_test), + cons: Box::new(browser_if_body.into_stmt()), + alt: None, + } + .into(), + )), + } + .into(), + )), + } + .into()], + }; + + let adapter_fn_expr = FnExpr { + ident: None, + function: Function { + params: vec![global.into(), factory.into()], + decorators: Default::default(), + span: DUMMY_SP, + body: Some(adapter_body), + is_generator: false, + is_async: false, + type_params: None, + return_type: None, + }, + }; + + (adapter_fn_expr, factory_params) } } diff --git a/crates/swc_ecma_transforms_module/src/util.rs b/crates/swc_ecma_transforms_module/src/util.rs index fbbe7c86c33..4b96a53fae1 100644 --- a/crates/swc_ecma_transforms_module/src/util.rs +++ b/crates/swc_ecma_transforms_module/src/util.rs @@ -1,39 +1,14 @@ -use std::{ - cell::{Ref, RefMut}, - collections::hash_map::Entry, - iter, -}; - -use indexmap::{IndexMap, IndexSet}; use inflector::Inflector; use serde::{Deserialize, Serialize}; use swc_atoms::{js_word, JsWord}; use swc_cached::regex::CachedRegex; -use swc_common::{ - collections::{AHashMap, AHashSet}, - util::take::Take, - Span, DUMMY_SP, -}; +use swc_common::{Span, DUMMY_SP}; use swc_ecma_ast::*; +use swc_ecma_transforms_base::feature::FeatureFlag; use swc_ecma_utils::{ - member_expr, private_ident, quote_ident, quote_str, undefined, DestructuringFinder, ExprFactory, + is_valid_prop_ident, member_expr, private_ident, quote_ident, quote_str, ExprFactory, + FunctionFactory, }; -use swc_ecma_visit::{Fold, FoldWith, VisitWith}; - -use crate::path::Resolver; - -pub(super) trait ModulePass: Fold { - fn config(&self) -> &Config; - fn scope(&self) -> Ref; - fn scope_mut(&mut self) -> RefMut; - - fn resolver(&self) -> &Resolver; - fn make_dynamic_import(&mut self, span: Span, args: Vec) -> Expr; - - fn vars(&mut self) -> Ref>; - fn vars_mut(&mut self) -> RefMut>; - fn vars_take(&mut self) -> Vec; -} #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(deny_unknown_fields, rename_all = "camelCase")] @@ -106,804 +81,35 @@ impl Default for Lazy { } } -#[derive(Clone, Default)] -pub struct Scope { - /// Map from source file to ident - /// - /// e.g. - /// - /// - `import 'foo'` - /// -> `{'foo': None}` - /// - /// - `import { foo } from 'bar';` - /// -> `{'bar': Some(_bar)}` - /// - /// - `import * as bar1 from 'bar';` - /// -> `{'bar': Some(bar1)}` - pub(crate) imports: IndexMap), ahash::RandomState>, - /// - /// - `true` is wildcard (`_interopRequireWildcard`) - /// - `false` is default (`_interopRequireDefault`) - pub(crate) import_types: AHashMap, - - /// This fields tracks if a helper should be injected. - /// - /// `(need_wildcard, need_default)` - pub(crate) unknown_imports: (bool, bool), - - /// Map from imported ident to (source file, property name). - /// - /// e.g. - /// - `import { foo } from 'bar';` - /// -> `{foo: ('bar', foo)}` - /// - /// - `import foo from 'bar';` - /// -> `{foo: ('bar', default)}` - pub(crate) idents: AHashMap, - - /// Declared variables except const. - pub(crate) declared_vars: Vec, - - /// Maps of exported bindings. - /// - /// - /// e.g. - /// - `export { a }` - /// -> `{ a: [a] }` - /// - /// - `export { a as b }` - /// -> `{ a: [b] }` - pub(crate) exported_bindings: AHashMap>, - - /// This is required to handle - /// `export * from 'foo';` - pub(crate) lazy_denylist: AHashSet, -} - -impl Scope { - /// insert exported bindings without duplication - pub(crate) fn insert_exported_bindings(&mut self, id: Id) { - let bindings = self.exported_bindings.entry(id.clone()).or_default(); - - if !bindings.contains(&id) { - bindings.push(id); - } - } - - /// - /// ```js - /// Object.keys(_foo).forEach(function (key) { - /// if (key === "default" || key === "__esModule") return; - /// if (key in exports && exports[key] === _foo[key]) return; - /// Object.defineProperty(exports, key, { - /// enumerable: true, - /// get: function () { - /// return _foo[key]; - /// } - /// }); - /// }) - /// ``` - /// - /// # Parameters - /// - `exported_names` Ident of the object literal. - pub(crate) fn handle_export_all( - span: Span, - exports: Ident, - exported_names: Option, - imported: Ident, - ) -> Stmt { - let key_ident = private_ident!("key"); - - let function = Function { - span: DUMMY_SP, - is_async: false, - is_generator: false, - decorators: Default::default(), - params: vec![Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: key_ident.clone().into(), - }], - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: iter::once(Stmt::If(IfStmt { - span: DUMMY_SP, - // key === "default" || key === "__esModule" - test: Box::new( - key_ident - .clone() - .make_eq(Lit::Str(quote_str!("default"))) - .make_bin( - op!("||"), - key_ident - .clone() - .make_eq(Lit::Str(quote_str!("__esModule"))), - ), - ), - cons: Box::new(Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: None, - })), - alt: None, - })) - .chain({ - // We should skip if the file explicitly exports - exported_names.map(|exported_names| { - Stmt::If(IfStmt { - span: DUMMY_SP, - test: Box::new( - CallExpr { - span: DUMMY_SP, - callee: member_expr!( - DUMMY_SP, - Object.prototype.hasOwnProperty.call - ) - .as_callee(), - args: vec![exported_names.as_arg(), key_ident.clone().as_arg()], - type_args: Default::default(), - } - .into(), - ), - cons: Box::new(Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: None, - })), - alt: None, - }) - }) - }) - .chain({ - Some(Stmt::If(IfStmt { - span: DUMMY_SP, - test: Box::new( - key_ident - .clone() - .make_bin(op!("in"), exports.clone()) - .make_bin( - op!("&&"), - exports.clone().computed_member(key_ident.clone()).make_eq( - imported.clone().computed_member(key_ident.clone()), - ), - ), - ), - cons: Box::new(Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: None, - })), - alt: None, - })) - }) - .chain(iter::once( - define_property(vec![ - exports.as_arg(), - key_ident.clone().as_arg(), - make_descriptor(Box::new(imported.clone().computed_member(key_ident))) - .as_arg(), - ]) - .into_stmt(), - )) - .collect(), - }), - return_type: Default::default(), - type_params: Default::default(), - }; - - Stmt::Expr(ExprStmt { - span, - expr: Box::new(Expr::Call(CallExpr { - span, - // Object.keys(_foo).forEach - callee: CallExpr { - span: DUMMY_SP, - callee: member_expr!(DUMMY_SP, Object.keys).as_callee(), - args: vec![imported.as_arg()], - type_args: Default::default(), - } - .make_member(quote_ident!("forEach")) - .as_callee(), - args: vec![FnExpr { - ident: None, - function, - } - .as_arg()], - type_args: Default::default(), - })), - }) - } - - /// Import src to export from it. - pub fn import_to_export(&mut self, src: &Str, init: bool) -> Option { - let entry = self - .imports - .entry(src.value.clone()) - .and_modify(|(span, v)| { - if init && v.is_none() { - *span = src.span; - *v = { - let ident = private_ident!(local_name_for_src(&src.value)); - Some((ident.sym, ident.span)) - } - } - }) - .or_insert_with(|| { - let v = if init { - let ident = private_ident!(local_name_for_src(&src.value)); - Some((ident.sym, ident.span)) - } else { - None - }; - - (src.span, v) - }); - if init { - let entry = entry.1.as_ref().unwrap(); - let ident = Ident::new(entry.0.clone(), entry.1); - - Some(ident) - } else { - None - } - } - - pub fn insert_import(&mut self, mut import: ImportDecl) { - if import.specifiers.is_empty() { - // import 'foo'; - // -> require('foo'); - self.imports - .entry(import.src.value.clone()) - .or_insert((import.src.span, None)); - } else if import.specifiers.len() == 1 - && matches!(import.specifiers[0], ImportSpecifier::Namespace(..)) - { - // import * as foo from 'src'; - let specifier = match import.specifiers.pop().unwrap() { - ImportSpecifier::Namespace(ns) => ns, - _ => unreachable!(), - }; - - self.idents.insert( - (specifier.local.sym.clone(), specifier.local.span.ctxt()), - (import.src.value.clone(), "".into()), - ); - - // Override symbol if one exists - self.imports - .entry(import.src.value.clone()) - .and_modify(|(span, v)| { - *span = import.src.span; - match *v { - Some(ref mut v) => v.0 = specifier.local.sym.clone(), - None => *v = Some((specifier.local.sym.clone(), specifier.local.span)), - } - }) - .or_insert_with(|| { - ( - import.src.span, - Some((specifier.local.sym.clone(), specifier.local.span)), - ) - }); - - self.import_types.insert(import.src.value, true); - } else { - let mut has_non_default = false; - for s in import.specifiers { - match s { - ImportSpecifier::Namespace(ref ns) => { - self.idents.insert( - (ns.local.sym.clone(), ns.local.span.ctxt()), - (import.src.value.clone(), "".into()), - ); - - // Override symbol if one exists - self.imports - .entry(import.src.value.clone()) - .and_modify(|(span, v)| { - *span = import.src.span; - match *v { - Some(ref mut v) => v.0 = ns.local.sym.clone(), - None => *v = Some((ns.local.sym.clone(), ns.local.span)), - } - }) - .or_insert_with(|| { - (import.src.span, Some((ns.local.sym.clone(), ns.local.span))) - }); - - self.import_types.insert(import.src.value.clone(), true); - } - ImportSpecifier::Default(i) => { - // Helpers are special. - if import.src.value.starts_with("@swc/helpers/src/") { - let ident = i.local.clone(); - - self.imports - .entry(import.src.value.clone()) - .and_modify(|(span, opt)| { - if opt.is_none() { - *span = import.src.span; - - *opt = Some((ident.sym.clone(), ident.span)); - } - }) - .or_insert_with(|| { - (import.src.span, Some((ident.sym, ident.span))) - }); - } else { - self.idents.insert( - i.local.to_id(), - (import.src.value.clone(), js_word!("default")), - ); - self.import_types - .entry(import.src.value.clone()) - .or_insert(false); - } - } - ImportSpecifier::Named(i) => { - let ImportNamedSpecifier { - local, imported, .. - } = i; - let imported_ident = match imported { - Some(ModuleExportName::Ident(ident)) => Some(ident), - _ => None, - }; - let name = imported_ident - .map(|i| i.sym) - .unwrap_or_else(|| local.sym.clone()); - let is_default = name == js_word!("default"); - - self.idents - .insert(local.to_id(), (import.src.value.clone(), name)); - - if is_default { - self.import_types - .entry(import.src.value.clone()) - .or_insert(has_non_default); - } else { - has_non_default = true; - self.import_types - .entry(import.src.value.clone()) - .and_modify(|v| *v = true); - } - } - } - } - - self.imports - .entry(import.src.value.clone()) - .and_modify(|(span, opt)| { - if opt.is_none() { - *span = import.src.span; - - let ident = - private_ident!(import.src.span, local_name_for_src(&import.src.value)); - *opt = Some((ident.sym, ident.span)); - } - }) - .or_insert_with(|| { - let ident = - private_ident!(import.src.span, local_name_for_src(&import.src.value)); - (import.src.span, Some((ident.sym, ident.span))) - }); - } - } - - pub(super) fn fold_shorthand_prop(folder: &mut impl ModulePass, prop: Ident) -> Prop { - let key = prop.clone(); - let value = Scope::fold_ident(folder, prop); - match value { - Ok(value) => Prop::KeyValue(KeyValueProp { - key: PropName::Ident(key), - value: Box::new(value), - }), - Err(ident) => Prop::Shorthand(ident), - } - } - - fn fold_ident(folder: &mut impl ModulePass, i: Ident) -> Result { - let orig_span = i.span; - let v = folder.scope().idents.get(&i.to_id()).cloned(); - match v { - None => Err(i), - Some((src, prop)) => { - let lazy = if folder.scope().lazy_denylist.contains(&src) { - false - } else { - folder.config().lazy.is_lazy(&src) - }; - - let scope = folder.scope(); - let (ident, span) = scope - .imports - .get(&src) - .as_ref() - .unwrap() - .1 - .as_ref() - .unwrap(); - - let obj = { - let ident = Ident::new(ident.clone(), orig_span.with_ctxt(span.ctxt)); - - if lazy { - Expr::Call(CallExpr { - span: DUMMY_SP, - callee: ident.as_callee(), - args: vec![], - type_args: Default::default(), - }) - } else { - Expr::Ident(ident) - } - }; - - if *prop == js_word!("") { - // import * as foo from 'foo'; - Ok(obj) - } else { - Ok(Expr::Member(MemberExpr { - obj: Box::new(obj), - span: orig_span, - prop: Ident::new(prop, DUMMY_SP).into(), - })) - } - } - } - } - - pub(super) fn fold_expr( - folder: &mut impl ModulePass, - exports: Ident, - top_level: bool, - expr: Expr, - ) -> Expr { - macro_rules! chain_assign { - ($entry:expr, $e:expr) => {{ - let mut e = $e; - for i in $entry.get() { - e = Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports - .clone() - .make_member(Ident::new(i.0.clone(), DUMMY_SP.with_ctxt(i.1))), - )), - op: op!("="), - right: e, - })); - } - e - }}; - } - - match expr { - // In a JavaScript module, this is undefined at the top level (i.e., outside functions). - Expr::This(ThisExpr { span }) if top_level => *undefined(span), - Expr::Ident(i) => match Self::fold_ident(folder, i) { - Ok(expr) => expr, - Err(ident) => Expr::Ident(ident), - }, - - // Handle dynamic imports. - // See https://github.com/swc-project/swc/issues/1018 - Expr::Call(CallExpr { - span, - callee: Callee::Import(_), - mut args, - .. - }) if !folder.config().ignore_dynamic - // TODO: import assertion - && args.len() == 1 => - { - let mut expr = args.pop().unwrap().expr.fold_with(folder); - let expr = match &mut *expr { - Expr::Lit(Lit::Str(s)) => { - let src = folder.resolver().resolve(s.value.clone()); - - Box::new(Expr::Lit(Lit::Str(Str { - raw: None, - value: src, - ..s.clone() - }))) - } - Expr::Ident(ident) => Box::new(match Self::fold_ident(folder, ident.take()) { - Ok(expr) => expr, - Err(ident) => Expr::Ident(ident), - }), - _ => expr, - }; - - folder.make_dynamic_import(span, vec![expr.as_arg()]) - } - - Expr::Call(CallExpr { - span, - callee, - args, - type_args, - }) => { - let callee = if let Callee::Expr(expr) = callee { - let callee = if let Expr::Ident(ident) = *expr { - match Self::fold_ident(folder, ident) { - Ok(mut expr) => { - if let Expr::Member(member) = &mut expr { - if let Expr::Ident(ident) = member.obj.as_mut() { - member.obj = Box::new(Expr::Paren(ParenExpr { - expr: Box::new(Expr::Seq(SeqExpr { - span, - exprs: vec![ - Box::new(0_f64.into()), - Box::new(ident.take().into()), - ], - })), - span, - })) - } - }; - expr - } - Err(ident) => Expr::Ident(ident), - } - } else { - *expr.fold_with(folder) - }; - callee.as_callee() - } else { - callee.fold_with(folder) - }; - Expr::Call(CallExpr { - span, - callee, - args: args.fold_with(folder), - type_args, - }) - } - - Expr::Member(e) => Expr::Member(MemberExpr { - obj: e.obj.fold_with(folder), - prop: if let MemberProp::Computed(c) = e.prop { - MemberProp::Computed(c.fold_with(folder)) - } else { - e.prop - }, - ..e - }), - - Expr::SuperProp(e) => Expr::SuperProp(SuperPropExpr { - prop: if let SuperProp::Computed(c) = e.prop { - SuperProp::Computed(c.fold_with(folder)) - } else { - e.prop - }, - ..e - }), - - Expr::Update(update) if update.arg.is_ident() => { - let arg = update.arg.clone().expect_ident(); - - let mut var = Default::default(); - - let expr = { - let mut scope = folder.scope_mut(); - let entry = scope - .exported_bindings - .entry((arg.sym.clone(), arg.span.ctxt())); - - match entry { - Entry::Occupied(entry) => { - if update.prefix { - // ++i - // => exports.i = ++i - *chain_assign!(entry, Box::new(update.into())) - } else { - // i++ - // (ref = i++, exports.i = i, ref) - - // TODO: optimize to `exports.i = ++i` if return value is not used. - - let ref_ident = private_ident!("ref"); - var = Some(ref_ident.clone()); - - Expr::Seq(SeqExpr { - span: update.span, - exprs: vec![ - Box::new( - AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: PatOrExpr::Pat(ref_ident.clone().into()), - right: Box::new(update.into()), - } - .into(), - ), - chain_assign!(entry, Box::new(arg.into())), - Box::new(ref_ident.into()), - ], - }) - } - } - _ => update.into(), - } - }; - - if let Some(ref_ident) = var { - folder.vars_mut().push(VarDeclarator { - span: DUMMY_SP, - name: ref_ident.into(), - init: None, - definite: false, - }); - }; - - expr - } - - Expr::Assign(mut expr) => { - expr.left = expr.left.fold_with(folder); - expr.right = expr.right.fold_with(folder); - - let mut found: Vec<(JsWord, Span)> = vec![]; - let mut v = DestructuringFinder { found: &mut found }; - - if let PatOrExpr::Expr(e) = &expr.left { - e.visit_children_with(&mut v); - } else { - expr.left.visit_with(&mut v); - } - - if v.found.is_empty() { - return Expr::Assign(AssignExpr { - left: expr.left, - ..expr - }); - } - - // imports are read-only - for i in &found { - let i = Ident::new(i.0.clone(), i.1); - if folder - .scope() - .idents - .get(&(i.sym.clone(), i.span.ctxt())) - .is_some() - { - let throw = Expr::Call(CallExpr { - span: DUMMY_SP, - callee: FnExpr { - ident: None, - function: Function { - span: DUMMY_SP, - is_async: false, - is_generator: false, - decorators: Default::default(), - params: vec![], - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![ - // throw new Error('"' + "Foo" + '" is read-only.') - Stmt::Throw(ThrowStmt { - span: DUMMY_SP, - arg: Box::new(Expr::New(NewExpr { - span: DUMMY_SP, - callee: Box::new(Expr::Ident(quote_ident!( - "Error" - ))), - args: Some(vec![quote_str!("'") - .make_bin( - op!(bin, "+"), - quote_str!(i.span, i.sym), - ) - .make_bin( - op!(bin, "+"), - quote_str!("' is read-only."), - ) - .as_arg()]), - type_args: Default::default(), - })), - }), - ], - }), - return_type: Default::default(), - type_params: Default::default(), - }, - } - .as_callee(), - args: vec![], - type_args: Default::default(), - }); - - let left = if let PatOrExpr::Pat(ref left_pat) = expr.left { - if let Pat::Ident(BindingIdent { ref id, .. }) = **left_pat { - let expr = match Self::fold_ident(folder, id.clone()) { - Ok(expr) => expr, - Err(ident) => Expr::Ident(ident), - }; - PatOrExpr::Expr(Box::new(expr)) - } else { - expr.left - } - } else { - expr.left - }; - - return Expr::Assign(AssignExpr { - right: Box::new(Expr::Seq(SeqExpr { - span: DUMMY_SP, - exprs: vec![expr.right, Box::new(throw)], - })), - left, - ..expr - }); - } - } - - if let Some(ident) = expr.left.as_ident() { - let mut scope = folder.scope_mut(); - let entry = scope - .exported_bindings - .entry((ident.sym.clone(), ident.span.ctxt())); - - match entry { - Entry::Occupied(entry) => { - let expr = Expr::Assign(expr); - - *chain_assign!(entry, Box::new(expr)) - } - _ => expr.into(), - } - } else { - let mut exprs = iter::once(Box::new(Expr::Assign(expr))) - .chain( - found - .into_iter() - .map(|var| Ident::new(var.0, var.1)) - .filter_map(|i| { - let mut scope = folder.scope_mut(); - let entry = match scope - .exported_bindings - .entry((i.sym.clone(), i.span.ctxt())) - { - Entry::Occupied(entry) => entry, - _ => { - return None; - } - }; - let e = chain_assign!(entry, Box::new(Expr::Ident(i))); - - // exports.name = x - Some(e) - }), - ) - .collect::>(); - if exprs.len() == 1 { - return *exprs.pop().unwrap(); - } - - Expr::Seq(SeqExpr { - span: DUMMY_SP, - exprs, - }) - } - } - _ => expr.fold_children_with(folder), - } - } -} - pub(super) fn local_name_for_src(src: &JsWord) -> JsWord { if !src.contains('/') { return format!("_{}", src.to_camel_case()).into(); } + let src = src + .starts_with("@swc/helpers/") + .then(|| src.strip_suffix(".mjs")) + .flatten() + .unwrap_or(src); + format!("_{}", src.split('/').last().unwrap().to_camel_case()).into() } -pub(super) fn define_property(args: Vec) -> Expr { - Expr::Call(CallExpr { - span: DUMMY_SP, - callee: member_expr!(DUMMY_SP, Object.defineProperty).as_callee(), - args, - - type_args: Default::default(), - }) +/// Creates +/// +///```js +/// +/// Object.defineProperty(target, prop_name, { +/// ...props +/// }); +/// ``` +pub(super) fn object_define_property( + target: ExprOrSpread, + prop_name: ExprOrSpread, + descriptor: ExprOrSpread, +) -> Expr { + member_expr!(DUMMY_SP, Object.defineProperty) + .as_call(DUMMY_SP, vec![target, prop_name, descriptor]) } /// Creates @@ -915,9 +121,9 @@ pub(super) fn define_property(args: Vec) -> Expr { /// }); /// ``` pub(super) fn define_es_module(exports: Ident) -> Stmt { - define_property(vec![ + object_define_property( exports.as_arg(), - Lit::Str(quote_str!("__esModule")).as_arg(), + quote_str!("__esModule").as_arg(), ObjectLit { span: DUMMY_SP, props: vec![PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { @@ -926,111 +132,30 @@ pub(super) fn define_es_module(exports: Ident) -> Stmt { })))], } .as_arg(), - ]) + ) .into_stmt() } -pub(super) fn has_use_strict(stmts: &[ModuleItem]) -> bool { +pub(super) fn clone_first_use_strict(stmts: &[ModuleItem]) -> Option { if stmts.is_empty() { - return false; + return None; } - if let ModuleItem::Stmt(Stmt::Expr(ExprStmt { expr, .. })) = stmts.first().unwrap() { - if let Expr::Lit(Lit::Str(Str { ref value, .. })) = &**expr { - return value == "use strict"; - } - } - - false + stmts.iter().find_map(|item| match item { + ModuleItem::Stmt(stmt @ Stmt::Expr(ExprStmt { expr, .. })) => match **expr { + Expr::Lit(Lit::Str(Str { ref value, .. })) if value == "use strict" => { + Some(stmt.clone()) + } + _ => None, + }, + _ => None, + }) } pub(super) fn use_strict() -> Stmt { Lit::Str(quote_str!("use strict")).into_stmt() } -/// Creates -/// -/// ```js -/// exports.default = exports.foo = void 0; -/// ``` -pub(super) fn initialize_to_undefined( - exports: Ident, - initialized: IndexSet, -) -> Vec -where - T: From, -{ - const CHUNK_SIZE: usize = 64; - let len = initialized.len(); - - let mut result = Vec::with_capacity(len / CHUNK_SIZE + 1); - - let initialized: Vec = initialized.into_iter().collect(); - - for chunks in initialized.chunks(CHUNK_SIZE) { - let mut rhs = undefined(DUMMY_SP); - - for name in chunks { - rhs = Box::new( - AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - exports - .clone() - .make_member(Ident::new(name.clone(), DUMMY_SP)), - )), - op: op!("="), - right: rhs, - } - .into(), - ); - } - - result.push(T::from(rhs.into_stmt())); - } - - result -} - -pub(super) fn make_descriptor(get_expr: Box) -> ObjectLit { - let get_fn_body = Some(BlockStmt { - span: DUMMY_SP, - stmts: vec![Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: Some(get_expr), - })], - }); - - ObjectLit { - span: DUMMY_SP, - props: vec![ - PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { - key: PropName::Ident(quote_ident!("enumerable")), - value: true.into(), - }))), - PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { - key: PropName::Ident(quote_ident!("get")), - value: Box::new( - FnExpr { - ident: None, - function: Function { - span: DUMMY_SP, - is_async: false, - is_generator: false, - decorators: Default::default(), - params: vec![], - body: get_fn_body, - return_type: Default::default(), - type_params: Default::default(), - }, - } - .into(), - ), - }))), - ], - } -} - /// Private `_exports` ident. pub(super) struct Exports(pub Ident); @@ -1040,44 +165,231 @@ impl Default for Exports { } } -macro_rules! mark_as_nested { - () => { - mark_as_nested!(fold_function, Function); - mark_as_nested!(fold_constructor, Constructor); - mark_as_nested!(fold_setter_prop, SetterProp); - mark_as_nested!(fold_getter_prop, GetterProp); - mark_as_nested!(fold_static_block, StaticBlock); - - fn fold_class_prop(&mut self, mut n: ClassProp) -> ClassProp { - use swc_common::util::take::Take; - if n.key.is_computed() { - let key = n.key.take().fold_children_with(self); - - let old = self.in_top_level; - self.in_top_level = false; - let mut n = n.fold_children_with(self); - self.in_top_level = old; - - n.key = key; - n - } else { - let old = self.in_top_level; - self.in_top_level = false; - let n = n.fold_children_with(self); - self.in_top_level = old; - n - } +pub(crate) fn object_define_enumerable( + target: ExprOrSpread, + prop_name: ExprOrSpread, + prop: PropOrSpread, +) -> Expr { + object_define_property( + target, + prop_name, + ObjectLit { + span: DUMMY_SP, + props: vec![ + prop, + PropOrSpread::Prop(Box::new( + KeyValueProp { + key: quote_ident!("enumerable").into(), + value: Box::new(true.into()), + } + .into(), + )), + ], } - }; + .as_arg(), + ) +} - ($name:ident, $T:tt) => { - fn $name(&mut self, f: $T) -> $T { - let old = self.in_top_level; - self.in_top_level = false.into(); - let f = f.fold_children_with(self); - self.in_top_level = old; - - f - } +#[macro_export] +macro_rules! caniuse { + ($feature_set:ident . $feature:ident) => { + $feature_set.intersects(swc_ecma_transforms_base::feature::FeatureFlag::$feature) }; } + +/// ```javascript +/// function _esmExport(target, all) { +/// for (var name in all)Object.defineProperty(target, name, { get: all[name], enumerable: true }); +/// } +/// ``` +pub(crate) fn esm_export() -> Function { + let target = private_ident!("target"); + let all = private_ident!("all"); + let name = private_ident!("name"); + + let getter = KeyValueProp { + key: quote_ident!("get").into(), + value: Box::new(all.clone().computed_member(Expr::from(name.clone()))), + }; + + let body = object_define_enumerable( + target.clone().as_arg(), + name.clone().as_arg(), + PropOrSpread::Prop(Box::new(Prop::KeyValue(getter))), + ) + .into_stmt(); + + let for_in_stmt: Stmt = ForInStmt { + span: DUMMY_SP, + left: VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Var, + declare: false, + decls: vec![VarDeclarator { + span: DUMMY_SP, + name: name.into(), + init: None, + definite: false, + }], + } + .into(), + right: Box::new(all.clone().into()), + body: Box::new(body), + } + .into(); + + Function { + params: vec![target.into(), all.into()], + decorators: Default::default(), + span: DUMMY_SP, + body: Some(BlockStmt { + span: DUMMY_SP, + stmts: vec![for_in_stmt], + }), + is_generator: false, + is_async: false, + type_params: None, + return_type: None, + } +} + +pub(crate) fn emit_export_stmts( + features: FeatureFlag, + exports: Ident, + mut prop_list: crate::module_decl_strip::ExportObjPropList, +) -> Vec { + let features = &features; + let support_arrow = caniuse!(features.ArrowFunctions); + let support_shorthand = caniuse!(features.ShorthandProperties); + + let prop_auto = if support_arrow { + prop_arrow + } else if support_shorthand { + prop_method + } else { + prop_function + }; + + match prop_list.len() { + 0 | 1 => prop_list + .pop() + .map(|(prop_name, span, expr)| { + object_define_enumerable( + exports.as_arg(), + quote_str!(span, prop_name).as_arg(), + prop_auto((js_word!("get"), DUMMY_SP, expr)).into(), + ) + .into_stmt() + }) + .into_iter() + .collect(), + _ => { + prop_list.sort_by(|a, b| a.0.cmp(&b.0)); + let props = prop_list + .into_iter() + .map(prop_auto) + .map(Into::into) + .collect(); + let obj_lit = ObjectLit { + span: DUMMY_SP, + props, + }; + + let esm_export_ident = private_ident!("_export"); + + vec![ + Stmt::Decl(Decl::Fn( + esm_export().into_fn_decl(esm_export_ident.clone()), + )), + esm_export_ident + .as_call(DUMMY_SP, vec![exports.as_arg(), obj_lit.as_arg()]) + .into_stmt(), + ] + } + } +} + +pub(crate) fn prop_name(key: &str, span: Span) -> IdentOrStr { + if is_valid_prop_ident(key) { + IdentOrStr::Ident(quote_ident!(span, key)) + } else { + IdentOrStr::Str(quote_str!(span, key)) + } +} + +pub(crate) enum IdentOrStr { + Ident(Ident), + Str(Str), +} + +impl From for PropName { + fn from(val: IdentOrStr) -> Self { + match val { + IdentOrStr::Ident(i) => Self::Ident(i), + IdentOrStr::Str(s) => Self::Str(s), + } + } +} + +impl From for MemberProp { + fn from(val: IdentOrStr) -> Self { + match val { + IdentOrStr::Ident(i) => Self::Ident(i), + IdentOrStr::Str(s) => Self::Computed(ComputedPropName { + span: DUMMY_SP, + expr: s.into(), + }), + } + } +} + +/// ```javascript +/// { +/// key: () => expr, +/// } +/// ``` +pub(crate) fn prop_arrow((key, span, expr): (JsWord, Span, Expr)) -> Prop { + let key = prop_name(&key, span).into(); + + KeyValueProp { + key, + value: Box::new(expr.into_lazy_arrow(Default::default()).into()), + } + .into() +} + +/// ```javascript +/// { +/// key() { +/// return expr; +/// }, +/// } +/// ``` +pub(crate) fn prop_method((key, span, expr): (JsWord, Span, Expr)) -> Prop { + let key = prop_name(&key, span).into(); + + expr.into_lazy_fn(Default::default()) + .into_method_prop(key) + .into() +} + +/// ```javascript +/// { +/// key: function() { +/// return expr; +/// }, +/// } +/// ``` +pub(crate) fn prop_function((key, span, expr): (JsWord, Span, Expr)) -> Prop { + let key = prop_name(&key, span).into(); + + KeyValueProp { + key, + value: Box::new( + expr.into_lazy_fn(Default::default()) + .into_fn_expr(None) + .into(), + ), + } + .into() +} diff --git a/crates/swc_ecma_transforms_module/tests/amd.rs b/crates/swc_ecma_transforms_module/tests/amd.rs index 7d04067fa76..d7e77ada391 100644 --- a/crates/swc_ecma_transforms_module/tests/amd.rs +++ b/crates/swc_ecma_transforms_module/tests/amd.rs @@ -1,1341 +1,93 @@ +use std::{fs::File, path::PathBuf}; + use swc_common::{chain, Mark}; -use swc_ecma_parser::{EsConfig, Syntax}; -use swc_ecma_transforms_base::resolver; -use swc_ecma_transforms_compat::es2015::{arrow, for_of, function_name, shorthand}; -use swc_ecma_transforms_module::{ - amd::{amd, Config}, - hoist::module_hoister, - util, -}; -use swc_ecma_transforms_testing::test; +use swc_ecma_parser::{Syntax, TsConfig}; +use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; +use swc_ecma_transforms_compat::es2015::for_of; +use swc_ecma_transforms_module::amd::{self, amd}; +use swc_ecma_transforms_testing::{test, test_fixture}; use swc_ecma_visit::Fold; fn syntax() -> Syntax { - Syntax::Es(EsConfig { - ..Default::default() - }) + Default::default() } -fn tr(config: Config) -> impl Fold { +fn ts_syntax() -> Syntax { + Syntax::Typescript(TsConfig::default()) +} + +fn tr(config: amd::Config, typescript: bool) -> impl Fold { + let unresolved_mark = Mark::new(); + let top_level_mark = Mark::new(); + + let avalible_set = FeatureFlag::all(); + chain!( - resolver(Mark::new(), Mark::new(), false), - module_hoister(), - amd(config) + resolver(unresolved_mark, top_level_mark, typescript), + amd(unresolved_mark, config, avalible_set), ) } -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_335, - "import bar from 'bar'; +#[testing::fixture("tests/fixture/common/**/input.js")] +#[testing::fixture("tests/fixture/common/**/input.ts")] +#[testing::fixture("tests/fixture/common/**/input.cts")] +fn esm_to_amd(input: PathBuf) { + let is_ts = input + .file_name() + .map(|x| x.to_string_lossy()) + .map(|x| x.ends_with(".ts") || x.ends_with(".mts") || x.ends_with(".cts")) + .unwrap_or_default(); -obj[bar('bas')] = '123'", - "define([\"require\", \"bar\"], function(require, _bar) { - \"use strict\"; - _bar = _interopRequireDefault(_bar); - obj[(0, _bar).default('bas')] = '123'; -});" -); + let dir = input.parent().unwrap().to_path_buf(); -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_332, - "import foo from 'foo'; + let output = dir + .join("output.amd.js") + .with_extension(if is_ts { "ts" } else { "js" }); -export const bar = { foo }", - " -define([\"require\", \"exports\", \"foo\"], function(require, _exports, _foo) { - \"use strict\"; - _foo = _interopRequireDefault(_foo); - Object.defineProperty(_exports, \"__esModule\", { - value: true - }); - _exports.bar = void 0; - const bar = { - foo: _foo.default + let amd_config_path = dir.join("module.amd.json"); + let config_path = dir.join("module.json"); + let config: amd::Config = match File::open(amd_config_path).or_else(|_| File::open(config_path)) + { + Ok(file) => serde_json::from_reader(file).unwrap(), + Err(..) => Default::default(), }; - _exports.bar = bar; -}); -" -); -test!( - syntax(), - |_| tr(Config { - config: util::Config { - strict: true, - ..Default::default() - }, - ..Default::default() - }), - custom_strict, - r#"export function foo(){}"#, - r#" -define(["require", "exports"], function(require, _exports) { - "use strict"; - _exports.foo = foo; - function foo(){} -}); -"# -); - -test!( - syntax(), - |_| tr(Config { - config: util::Config { - strict: true, - ..Default::default() - }, - ..Default::default() - }), - inner_scoped_local_require, - r#"export function foo(){ return require.toUrl(""); }"#, - r#" -define(["require", "exports"], function(require, _exports) { - "use strict"; - _exports.foo = foo; - function foo(){ return require.toUrl(""); } -}); -"# -); - -test!( - syntax(), - |_| tr(Config { - config: util::Config { - strict: true, - ..Default::default() - }, - ..Default::default() - }), - inner_scoped_local_require_member_expr, - r#"export const DefaultIconPath = FileAccess.asBrowserUri('./media/defaultIcon.png', require).toString(true);"#, - r#" -define([ - "require", - "exports", -], function(require, _exports) { - "use strict"; - _exports.DefaultIconPath = void 0; - const DefaultIconPath = FileAccess.asBrowserUri('./media/defaultIcon.png', require).toString(true); - _exports.DefaultIconPath = DefaultIconPath; -}); -"# -); - -test!( - syntax(), - |_| tr(Config { - config: util::Config { - strict: true, - ..Default::default() - }, - ..Default::default() - }), - inner_scoped_local_require_non_export_module, - r#" - import { getPathFromAmdModule } from 'vs/base/test/node/testUtils'; - const fixturesFolder = getPathFromAmdModule(require, './fixtures'); - "#, - r#" - define([ - "require", - "vs/base/test/node/testUtils" -], function(require, _testUtils) { - "use strict"; - const fixturesFolder = (0, _testUtils).getPathFromAmdModule(require, './fixtures'); -}); -"# -); - -test!( - syntax(), - |_| tr(Config { - config: util::Config { - strict_mode: false, - ..Default::default() - }, - ..Default::default() - }), - custom_non_strict_mode, - r#"export function foo(){}"#, - r#" -define(["require", "exports"], function(require, _exports) { - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.foo = foo; - function foo(){} -}); -"# -); - -test!( - syntax(), - |_| tr(Config { - config: util::Config { - no_interop: true, - ..Default::default() - }, - ..Default::default() - }), - custom_no_interop, - r#"import * as foo from 'foo'; - import bar from 'bar';"#, - r#" -define(["require", "foo", "bar"], function(require, foo, _bar) { - "use strict"; -}); -"# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - custom_usage, - r#" -import React from 'react' -window.React = React; - "#, - r#" -define(["require", "react"], function(require, _react) { - "use strict"; - _react = _interopRequireDefault(_react); - window.React = _react.default; -}); -"# -); - -test!( - syntax(), - |_| tr(Config { - module_id: Some("moduleId".into()), - ..Default::default() - }), - custom_named_define, - r#" -import {foo} from 'src'; -export {foo}; - "#, - r#"define("moduleId", ["require", "exports", "src"], function(require, _exports, _src) { - "use strict"; - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "foo", { - enumerable: true, - get: function() { - return _src.foo; - } - }); -}); -"# -); - -// export_default_4 -test!( - syntax(), - |_| tr(Default::default()), - export_default_4, - r#" -export default foo; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var _default = foo; - _exports.default = _default; -}); - -"# -); - -// export_from_2 -test!( - syntax(), - |_| tr(Default::default()), - export_from_2, - r#" -export {foo} from "foo"; - -"#, - r#" -define(["require", "exports", "foo"], function (require, _exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "foo", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); -}); - -"# -); - -// export_named_2 -test!( - syntax(), - |_| tr(Default::default()), - export_named_2, - r#" -var foo, bar; -export {foo, bar}; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.bar = _exports.foo = void 0; - var foo, bar; - _exports.foo = foo; - _exports.bar = bar; -}); - -"# -); - -// imports_default -test!( - syntax(), - |_| tr(Default::default()), - imports_default, - r#" -import foo from "foo"; -import {default as foo2} from "foo"; - -foo; -foo2; - -"#, - r#" -define(["require", "foo"], function (require, _foo) { - "use strict"; - - _foo = _interopRequireDefault(_foo); - _foo.default; - _foo.default; -}); - -"# -); - -// imports_mixing -test!( - syntax(), - |_| tr(Default::default()), - imports_mixing, - r#" -import foo, {baz as xyz} from "foo"; - -foo; -xyz; - -"#, - r#" -define(["require", "foo"], function (require, _foo) { - "use strict"; - - _foo = _interopRequireWildcard(_foo); - _foo.default; - _foo.baz; -}); - -"# -); - -// export_default_9 -test!( - syntax(), - |_| tr(Default::default()), - export_default_9, - r#" -var foo; -export { foo as default }; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var foo; - _exports.default = foo; -}); - -"# -); - -// noInterop_export_from - -// amd - -// export_default -test!( - syntax(), - |_| tr(Default::default()), - export_default, - r#" -export default 42; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var _default = 42; - _exports.default = _default; -}); - -"# -); - -// export_default_2 -test!( - syntax(), - |_| tr(Default::default()), - export_default_2, - r#" -export default {}; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var _default = {}; - _exports.default = _default; -}); - -"# -); - -// export_from_4 -test!( - syntax(), - |_| tr(Default::default()), - export_from_4, - r#" -export {foo as bar} from "foo"; - -"#, - r#" -define(["require", "exports", "foo"], function (require, _exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "bar", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); -}); - -"# -); - -// export_named -test!( - syntax(), - |_| tr(Default::default()), - export_named, - r#" -var foo; -export {foo}; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.foo = void 0; - var foo; - _exports.foo = foo; -}); - -"# -); - -// noInterop_import_default_only - -// export_from -test!( - syntax(), - |_| tr(Default::default()), - export_from, - r#" -export * from "foo"; - -"#, - r#" -define(["require", "exports", "foo"], function (require, _exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.keys(_foo).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (key in _exports && _exports[key] === _foo[key]) return; - Object.defineProperty(_exports, key, { - enumerable: true, - get: function () { - return _foo[key]; - } - }); - }); -}); - -"# -); - -// export_default_7 -test!( - syntax(), - |_| tr(Default::default()), - export_default_7, - r#" -export default function foo () {} - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = foo; - - function foo() {} -}); - -"# -); - -// export_named_4 -test!( - syntax(), - |_| tr(Default::default()), - export_named_4, - r#" -var foo; -export {foo as default}; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var foo; - _exports.default = foo; -}); - -"# -); - -// imports_glob -test!( - syntax(), - |_| tr(Default::default()), - imports_glob, - r#" -import * as foo from "foo"; - -foo; - -"#, - r#" -define(["require", "foo"], function (require, foo) { - "use strict"; - - foo = _interopRequireWildcard(foo); - foo; -}); - -"# -); - -// ㅁap -test!( - syntax(), - |_| tr(Default::default()), - remap, - r#" -export var test = 2; -test = 5; -test++; - -(function () { - var test = 2; - test = 3; - test++; -})(); - -var a = 2; -export { a }; -a = 3; - -var b = 2; -export { b as c }; -b = 3; - -var d = 3; -export { d as e, d as f }; -d = 4; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - var ref; - _exports.f = _exports.e = _exports.c = _exports.a = _exports.test = void 0; - var test = 2; - _exports.test = test; - _exports.test = test = 5; - ref = test++, _exports.test = test, ref; - - (function () { - var test = 2; - test = 3; - test++; - })(); - - var a = 2; - _exports.a = a; - _exports.a = a = 3; - var b = 2; - _exports.c = b; - _exports.c = b = 3; - var d = 3; - _exports.e = d; - _exports.f = d; - _exports.f = _exports.e = d = 4; -}); - -"# -); - -// regression_4192 - -// imports -test!( - syntax(), - |_| tr(Default::default()), - imports, - r#" -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; - -"#, - r#" -define(["require", "foo", "foo-bar", "./directory/foo-bar"], function (require, _foo, _fooBar, _fooBar1) { - "use strict"; -}); - -"# -); - -// export_from_3 -test!( - syntax(), - |_| tr(Default::default()), - export_from_3, - r#" -export {foo, bar} from "foo"; - -"#, - r#" -define(["require", "exports", "foo"], function (require, _exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "foo", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); - Object.defineProperty(_exports, "bar", { - enumerable: true, - get: function () { - return _foo.bar; - } - }); -}); - -"# -); - -// export_default_5 -test!( - syntax(), - |_| tr(Default::default()), - export_default_5, - r#" -export default function () {} - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = _default; - - function _default() {} -}); - -"# -); - -// export_default_10 -test!( - syntax(), - |_| tr(Default::default()), - export_default_10, - r#" -export default (function(){return "foo"})(); - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - - var _default = function () { - return "foo"; - }(); - - _exports.default = _default; -}); - -"# -); - -// export_named_3 -test!( - syntax(), - |_| tr(Default::default()), - export_named_3, - r#" -var foo; -export {foo as bar}; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.bar = void 0; - var foo; - _exports.bar = foo; -}); - -"# -); - -// overview -test!( - syntax(), - |_| tr(Default::default()), - overview, - r#" -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; -import foo from "foo"; -import * as foo2 from "foo"; -import {bar} from "foo"; -import {foo as bar2} from "foo"; - -var test; -export {test}; -export var test2 = 5; - -export default test; - -foo; -foo2; -bar; -bar2; - -"#, - r#" -define(["require", "exports", "foo", "foo-bar", "./directory/foo-bar"], -function (require, _exports, foo2, _fooBar, _fooBar1) { - "use strict"; - - foo2 = _interopRequireWildcard(foo2); - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = _exports.test2 = _exports.test = void 0; - var test; - _exports.test = test; - var test2 = 5; - _exports.test2 = test2; - var _default = test; - _exports.default = _default; - foo2.default; - foo2; - foo2.bar; - foo2.foo; -}); - -"# -); - -// export_from_6 -test!( - syntax(), - |_| tr(Default::default()), - export_from_6, - r#" -export {foo as default, bar} from "foo"; - -"#, - r#" -define(["require", "exports", "foo"], function (require, _exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "default", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); - Object.defineProperty(_exports, "bar", { - enumerable: true, - get: function () { - return _foo.bar; - } - }); -}); - -"# -); - -// hoist_function_exports -test!( - syntax(), - |_| tr(Default::default()), - hoist_function_exports, - r#" -import { isEven } from "./evens"; - -export function nextOdd(n) { - return isEven(n) ? n + 1 : n + 2; + test_fixture( + if is_ts { ts_syntax() } else { syntax() }, + &|_| tr(config.clone(), is_ts), + &input, + &output, + ); } -export var isOdd = (function (isEven) { - return function (n) { - return !isEven(n); - }; -})(isEven); - -"#, - r#" -define(["require", "exports", "./evens"], function (require, _exports, _evens) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.nextOdd = nextOdd; - _exports.isOdd = void 0; - - function nextOdd(n) { - return (0, _evens).isEven(n) ? n + 1 : n + 2; - } - - var isOdd = function (isEven) { - return function (n) { - return !isEven(n); - }; - }(_evens.isEven); - - _exports.isOdd = isOdd; -}); - -"# -); - -// export_default_8 -test!( - syntax(), - |_| tr(Default::default()), - export_default_8, - r#" -export default class Foo {} - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - - class Foo {} - - _exports.default = Foo; -}); - -"# -); - -// export_from_5 -test!( - syntax(), - |_| tr(Default::default()), - export_from_5, - r#" -export {foo as default} from "foo"; - -"#, - r#" -define(["require", "exports", "foo"], function (require, _exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "default", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); -}); - -"# -); - -// export_default_3 -test!( - syntax(), - |_| tr(Default::default()), - export_default_3, - r#" -export default []; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var _default = []; - _exports.default = _default; -}); - -"# -); - -// import_order -test!( - syntax(), - |_| tr(Default::default()), - import_order, - r#" -import './foo'; -import bar from './bar'; -import './derp'; -import { qux } from './qux'; - -"#, - r#" -define(["require", "./foo", "./bar", "./derp", "./qux"], function (require, _foo, _bar, _derp, _qux) { - "use strict"; - - _bar = _interopRequireDefault(_bar); -}); - -"# -); - -// export_specifier_default -test!( - syntax(), - |_| tr(Default::default()), - export_specifier_default, - r#" -var a = 1; -export { a as default }; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var a = 1; - _exports.default = a; -}); - -"# -); - -// exports_variable -test!( - syntax(), - |_| tr(Default::default()), - exports_variable, - r#" -export var foo = 1; -export var foo2 = 1, bar = 2; -export var foo3 = function () {}; -export var foo4; -export let foo5 = 2; -export let foo6; -export const foo7 = 3; -export function foo8 () {} -export class foo9 {} - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.foo8 = foo8; - _exports.foo7 = _exports.foo6 = _exports.foo5 = _exports.foo4 = _exports.foo3 = _exports.bar = _exports.foo2 = _exports.foo = void 0; - var foo = 1; - _exports.foo = foo; - var foo2 = 1, - bar = 2; - _exports.foo2 = foo2; - _exports.bar = bar; - - var foo3 = function () {}; - - _exports.foo3 = foo3; - var foo4; - _exports.foo4 = foo4; - let foo5 = 2; - _exports.foo5 = foo5; - let foo6; - _exports.foo6 = foo6; - const foo7 = 3; - _exports.foo7 = foo7; - - function foo8() {} - - class foo9 {} - - _exports.foo9 = foo9; -}); - -"# -); - -// imports_named -test!( - syntax(), - |_| tr(Default::default()), - imports_named, - r#" -import {bar} from "foo"; -import {bar2, baz} from "foo"; -import {bar as baz2} from "foo"; -import {bar as baz3, xyz} from "foo"; - -bar; -bar2; -baz; -baz2; -baz3; -xyz; - -"#, - r#" -define(["require", "foo"], function (require, _foo) { - "use strict"; - - _foo.bar; - _foo.bar2; - _foo.baz; - _foo.bar; - _foo.bar; - _foo.xyz; -}); - -"# -); - -// export_default_6 -test!( - syntax(), - |_| tr(Default::default()), - export_default_6, - r#" -export default class {} - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - - class _default {} - - _exports.default = _default; -}); - -"# -); - -// get_module_name_option - -// module_name - -// export_named_5 -test!( - syntax(), - |_| tr(Default::default()), - export_named_5, - r#" -var foo, bar; -export {foo as default, bar}; - -"#, - r#" -define(["require", "exports"], function (require, _exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.bar = _exports.default = void 0; - var foo, bar; - _exports.default = foo; - _exports.bar = bar; -}); - -"# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_456_1, - "import { join as e } from 'path'; -export const foo = function () { - function e(t) {} - return A(e, {}), e -}();", - "define([\"require\", \"exports\", \"path\"], function(require, _exports, _path) { - \"use strict\"; - Object.defineProperty(_exports, \"__esModule\", { - value: true - }); - _exports.foo = void 0; - const foo = function() { - function e(t) { - } - return A(e, { - }), e; - }(); - _exports.foo = foo; -});" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_456_2, - "import { join as e } from 'path'; -export const foo = function () { - var e = 1; - return A(e, {}), e -}();", - "define([\"require\", \"exports\", \"path\"], function(require, _exports, _path) { - \"use strict\"; - Object.defineProperty(_exports, \"__esModule\", { - value: true - }); - _exports.foo = void 0; - const foo = function() { - var e = 1; - return A(e, { - }), e; - }(); - _exports.foo = foo; -}); -" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_1018_1, - "async function foo() { - await import('foo'); - }", - "define([], function() { - \"use strict\"; - async function foo() { - await new Promise(function(resolve, reject) { - require([ - \"foo\" - ], function(dep) { - resolve(dep); - }, function(err) { - reject(err); - }); - }); - } - });" -); - -// for_of_as_array_for_of_import_amd test!( syntax(), |_| chain!( for_of(for_of::Config { assume_array: true }), - amd(Default::default()) + tr(Default::default(), false) ), for_of_as_array_for_of_import_amd, r#" -import { array } from "foo"; + import { array } from "foo"; -for (const elm of array) { -console.log(elm); -} - -"#, - r#" -define(["require", "foo"], function (require, _foo) { -"use strict"; - -for(let _i = 0; _i < _foo.array.length; _i++){ - const elm = _foo.array[_i]; - console.log(elm); -} -}); - -"# -); - -// function_name_export_default_arrow_renaming_module_amd -test!( - ignore, - Default::default(), - |_| chain!( - function_name(), - shorthand(), - arrow(), - amd(Default::default()) - ), - function_name_export_default_arrow_renaming_module_amd, - r#" -export default (a) => { -return { a() { return a } }; -} - -"#, - r#" -define(["exports"], function (_exports) { -"use strict"; - -Object.defineProperty(_exports, "__esModule", { - value: true -}); -_exports.default = void 0; - -var _default = function _default(_a) { - return { - a: function a() { - return _a; + for (const elm of array) { + console.log(elm); } - }; -}; - -_exports.default = _default; -}); - +"#, + r#" + define([ + "require", + "exports", + "foo" + ], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + for(let _i = 0; _i < _foo.array.length; _i++){ + const elm = _foo.array[_i]; + console.log(elm); + } + }); "# ); diff --git a/crates/swc_ecma_transforms_module/tests/common_js.rs b/crates/swc_ecma_transforms_module/tests/common_js.rs index 0390d7dd2d6..475b72caa78 100644 --- a/crates/swc_ecma_transforms_module/tests/common_js.rs +++ b/crates/swc_ecma_transforms_module/tests/common_js.rs @@ -1,5467 +1,86 @@ -use std::{cell::RefCell, path::PathBuf, rc::Rc}; +use std::{fs::File, path::PathBuf}; -use swc_cached::regex::CachedRegex; use swc_common::{chain, Mark}; -use swc_ecma_parser::{EsConfig, Syntax, TsConfig}; -use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene, resolver}; -use swc_ecma_transforms_compat::{ - es2015::{ - block_scoped_functions, block_scoping, classes, destructuring, for_of, parameters, - regenerator, spread, - }, - es2018::object_rest_spread, -}; -use swc_ecma_transforms_module::{ - common_js::common_js, - hoist::module_hoister, - import_analysis::import_analyzer, - util::{Config, Lazy, LazyObjectConfig, Scope}, -}; -use swc_ecma_transforms_testing::{test, test_exec, test_fixture}; +use swc_ecma_parser::{Syntax, TsConfig}; +use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; +use swc_ecma_transforms_compat::es2015::for_of; +use swc_ecma_transforms_module::common_js::{self, common_js}; +use swc_ecma_transforms_testing::{test, test_fixture}; use swc_ecma_visit::Fold; fn syntax() -> Syntax { - Syntax::Es(EsConfig { - ..Default::default() - }) -} -fn ts_syntax() -> Syntax { - Syntax::Typescript(TsConfig { - ..Default::default() - }) + Default::default() } -fn tr(config: Config) -> impl Fold { +fn ts_syntax() -> Syntax { + Syntax::Typescript(TsConfig::default()) +} + +fn tr(config: common_js::Config, typescript: bool) -> impl Fold { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); + let avalible_set = FeatureFlag::all(); + chain!( - resolver(unresolved_mark, top_level_mark, false), - module_hoister(), - common_js(unresolved_mark, config, None) + resolver(unresolved_mark, top_level_mark, typescript), + common_js(unresolved_mark, config, avalible_set), ) } -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_369, - "export function input(name) { - return `${name}.md?render`; -} +#[testing::fixture("tests/fixture/common/**/input.js")] +#[testing::fixture("tests/fixture/common/**/input.ts")] +#[testing::fixture("tests/fixture/common/**/input.cts")] +fn esm_to_cjs(input: PathBuf) { + let is_ts = input + .file_name() + .map(|x| x.to_string_lossy()) + .map(|x| x.ends_with(".ts") || x.ends_with(".mts") || x.ends_with(".cts")) + .unwrap_or_default(); -export default function({ - name, input: inp, -}) { - inp = inp || input(name); - return {input: inp}; -}", - "\"use strict\"; -Object.defineProperty(exports, \"__esModule\", { - value: true -}); -exports.input = input; -exports.default = _default; -function input(name) { - return `${name}.md?render`; -} -function _default({ name , input: inp }) { - inp = inp || input(name); - return { - input: inp - }; -} -" -); - -test!( - syntax(), - |_| common_js(Mark::fresh(Mark::root()), Default::default(), None), - issue_389_1, - " -import Foo from 'foo'; -Foo.bar = true; -", - " -\"use strict\"; -var _foo = _interopRequireDefault(require(\"foo\")); -_foo.default.bar = true; -" -); - -test!( - syntax(), - |_| { - let unresolved_mark = Mark::new(); - let top_level_mark = Mark::new(); - - let scope = Rc::new(RefCell::new(Scope::default())); - chain!( - resolver(unresolved_mark, top_level_mark, false), - // Optional::new(typescript::strip(mark), syntax.typescript()), - import_analyzer(Rc::clone(&scope)), - common_js(unresolved_mark, Default::default(), Some(scope)), - hygiene(), - fixer(None) - ) - }, - issue_389_2, - " -import Foo from 'foo'; -Foo.bar = true; -", - " -\"use strict\"; -var _foo = _interopRequireDefault(require(\"foo\")); -_foo.default.bar = true; -" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_335, - "import bar from 'bar'; - -obj[bar('bas')] = '123'", - "\"use strict\"; -var _bar = _interopRequireDefault(require(\"bar\")); -obj[(0, _bar).default('bas')] = '123';" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_332, - "import foo from 'foo'; - -export const bar = { foo }", - " -\"use strict\"; -Object.defineProperty(exports, \"__esModule\", { - value: true -}); -exports.bar = void 0; -var _foo = _interopRequireDefault(require(\"foo\")); -const bar = { - foo: _foo.default -}; -exports.bar = bar;" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_326, - "import foo from 'foo'; -import bar from '../foo'; -foo, bar", - "\"use strict\"; -var _foo = _interopRequireDefault(require(\"foo\")); -var _foo1 = _interopRequireDefault(require(\"../foo\")); - -_foo.default, _foo1.default" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_235, - "import {Foo as Bar} from 'something'; -export const fn = ({a = new Bar()}) => a;", - " -\"use strict\"; -Object.defineProperty(exports, \"__esModule\", { - value: true -}); -exports.fn = void 0; -var _something = require(\"something\"); -const fn = ({ a =new _something.Foo() })=>a -; -exports.fn = fn; -" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - custom_usage, - r#" -import React from 'react' -window.React = React; - "#, - r#" -"use strict"; -var _react = _interopRequireDefault(require("react")); -window.React = _react.default; -"# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - custom_01, - r#" -var foo = 1; -export var foo = 2; -foo = 3; -"#, - r#" -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); - -exports.foo = void 0; -var foo = 1; -var foo = 2; -exports.foo = foo; -exports.foo = foo = 3; - -"# -); -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - custom_02, - r#" -export const good = { - a(bad1) { - (...bad2) => { }; - } -};"#, - r#" -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.good = void 0; -const good = { - a (bad1) { - (...bad2)=>{}; - } -}; -exports.good = good; - -"# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_176, - r#" -"use strict"; - -let x = 4;"#, - r#" -"use strict"; - -let x = 4; -"# -); - -// strict_export_2 -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_2, - r#" -var foo; -export { foo as default }; - -"#, - r#" -"use strict"; - -exports.default = void 0; -var foo; -exports.default = foo; - -"# -); - -// interop_hoist_function_exports -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_hoist_function_exports, - r#" -import { isEven } from "./evens"; - -export function nextOdd(n) { - return isEven(n) ? n + 1 : n + 2; -} - -export var isOdd = (function (isEven) { - return function (n) { - return !isEven(n); - }; -})(isEven); - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.nextOdd = nextOdd; -exports.isOdd = void 0; - -var _evens = require("./evens"); - -function nextOdd(n) { - return (0, _evens).isEven(n) ? n + 1 : n + 2; -} - -var isOdd = function (isEven) { - return function (n) { - return !isEven(n); - }; -}(_evens.isEven); - -exports.isOdd = isOdd; - -"# -); - -// regression_t7199 - -// misc_undefined_this_root_declaration -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - misc_undefined_this_root_declaration, - r#" -var self = this; - -"#, - r#" -"use strict"; - -var self = void 0; - -"# -); - -// interop_export_default_3 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_3, - r#" -export default []; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; -var _default = []; -exports.default = _default; - -"# -); - -// misc_copy_getters_setters -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - misc_copy_getters_setters, - r#" -import Foo, { baz } from "./moduleWithGetter"; - -export { Foo, baz }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "Foo", { - enumerable: true, - get: function () { - return _moduleWithGetter.default; - } -}); -Object.defineProperty(exports, "baz", { - enumerable: true, - get: function () { - return _moduleWithGetter.baz; - } -}); -var _moduleWithGetter = _interopRequireWildcard(require("./moduleWithGetter")); - -"# -); - -// source_map - -// regression_t7165 - -// regression_lazy_7176 - -// interop_multi_load - -// update_expression_positive_suffix -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - update_expression_positive_suffix, - r#" -export let diffLevel = 0; - -export function diff() { - if (!++diffLevel) { - console.log("hey"); - } -} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.diff = diff; -exports.diffLevel = void 0; -let diffLevel = 0; -exports.diffLevel = diffLevel; - -function diff() { - if (!(exports.diffLevel = ++diffLevel)) { - console.log("hey"); - } -} - -"# -); - -// interop_export_default_11 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_11, - r#" -export default new Cachier() - -export function Cachier(databaseName) {} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -exports.Cachier = Cachier; -exports.default = void 0; - -var _default = new Cachier(); - -exports.default = _default; - -function Cachier(databaseName) {} -"# -); - -// interop_export_named_5 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_named_5, - r#" -var foo, bar; -export {foo as default, bar}; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.bar = exports.default = void 0; -var foo, bar; -exports.default = foo; -exports.bar = bar; - -"# -); - -// interop_exports_variable -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_exports_variable, - r#" -export var foo = 1; -export var foo2 = 1, bar = 2; -export var foo3 = function () {}; -export var foo4; -export let foo5 = 2; -export let foo6; -export const foo7 = 3; -export function foo8 () {} -export class foo9 {} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.foo8 = foo8; -exports.foo7 = exports.foo6 = exports.foo5 = exports.foo4 = exports.foo3 = exports.bar = exports.foo2 = exports.foo = void 0; - -var foo = 1; -exports.foo = foo; -var foo2 = 1, bar = 2; -exports.foo2 = foo2; -exports.bar = bar; - -var foo3 = function () {}; - -exports.foo3 = foo3; -var foo4; -exports.foo4 = foo4; -let foo5 = 2; -exports.foo5 = foo5; -let foo6; -exports.foo6 = foo6; -const foo7 = 3; -exports.foo7 = foo7; - -function foo8() {} - -class foo9 {} -exports.foo9 = foo9; - -"# -); - -// interop_export_from_2 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_from_2, - r#" -export {foo} from "foo"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "foo", { - enumerable: true, - get: function () { - return _foo.foo; - } -}); - -var _foo = require("foo"); -"# -); - -// lazy_local_reexport_default -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_local_reexport_default, - r#" -import foo from "./foo"; -export { foo as default }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "default", { - enumerable: true, - get: function () { - return _foo.default; - } -}); - -var _foo = _interopRequireDefault(require("./foo")); - -"# -); - -// lazy_local_reexport_namespace -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_local_reexport_namespace, - r#" -import * as namespace from "./foo"; -export { namespace }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.namespace = void 0; -var namespace = _interopRequireWildcard(require("./foo")); -exports.namespace = namespace; - -"# -); - -// regression_es3_compatibility_function - -// regression_es3_compatibility_named_function - -// interop_export_default_6 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_6, - r#" -export default class {} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -class _default {} - -exports.default = _default; - -"# -); - -// no_interop_import_default_only -test!( - syntax(), - |_| tr(Config { - no_interop: true, - ..Default::default() - }), - no_interop_import_default_only, - r#" -import foo from "foo"; - -foo(); - -"#, - r#" -"use strict"; - -var _foo = require("foo"); - -(0, _foo).default(); - -"# -); - -// regression_4462_T7565 - -// interop_export_from_7 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_from_7, - r#" -export {default as foo} from "foo"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "foo", { - enumerable: true, - get: function () { - return _foo.default; - } -}); - -var _foo = _interopRequireDefault(require("foo")); - -"# -); - -// interop_remap -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_remap, - r#" -export var test = 2; -test = 5; -test++; - -(function () { - var test = 2; - test = 3; - test++; -})(); - -var a = 2; -export { a }; -a = 3; - -var b = 2; -export { b as c }; -b = 3; - -var d = 3; -export { d as e, d as f }; -d = 4; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.f = exports.e = exports.c = exports.a = exports.test = void 0; -var ref; -var test = 2; -exports.test = test; -exports.test = test = 5; -ref = test++, exports.test = test, ref; - -(function () { - var test = 2; - test = 3; - test++; -})(); - -var a = 2; -exports.a = a = 3; -var b = 2; -exports.c = b = 3; -var d = 3; -exports.f = exports.e = d = 4; -exports.a = a; -exports.c = b; -exports.e = d; -exports.f = d; - -"# -); - -// regression_es3_compatibility_class - -// lazy_dep_reexport_all -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_dep_reexport_all, - r#" -export * from "foo"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _foo = require("foo"); - -Object.keys(_foo).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (key in exports && exports[key] === _foo[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return _foo[key]; - } - }); -}); - -"# -); - -// misc_copy_getters_setters_star - -// regression_t7160 - -// lazy_local_sideeffect -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_local_sideeffect, - r#" -import "./a"; - -"#, - r#" -"use strict"; - -require("./a"); - -"# -); - -// strict_export_const_destructuring_deep -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_const_destructuring_deep, - r#" -export const { foo: { bar: [baz, qux] } } = {}; - -"#, - r#" -"use strict"; - -exports.qux = exports.baz = void 0; -const { - foo: { - bar: [baz, qux] - } -} = {}; -exports.baz = baz; -exports.qux = qux; - -"# -); - -// lazy_local_reexport_all -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_local_reexport_all, - r#" -export * from "./foo"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _foo = require("./foo"); - -Object.keys(_foo).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (key in exports && exports[key] === _foo[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return _foo[key]; - } - }); -}); - -"# -); - -// interop_illegal_export_esmodule_2 - -// interop_export_from_4 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_from_4, - r#" -export {foo as bar} from "foo"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "bar", { - enumerable: true, - get: function () { - return _foo.foo; - } -}); - -var _foo = require("foo"); - -"# -); - -// interop_export_destructured -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_destructured, - r#" -export let x = 0; -export let y = 0; - -export function f1 () { - ({x} = { x: 1 }); -} - -export function f2 () { - ({x, y} = { x: 2, y: 3 }); -} - -export function f3 () { - [x, y, z] = [3, 4, 5] -} - -export function f4 () { - [x, , y] = [3, 4, 5] -} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.f1 = f1; -exports.f2 = f2; -exports.f3 = f3; -exports.f4 = f4; -exports.y = exports.x = void 0; -let x = 0; -exports.x = x; -let y = 0; -exports.y = y; - -function f1() { - ({ - x - } = { - x: 1 - }), exports.x = x; -} - -function f2() { - ({ - x, - y - } = { - x: 2, - y: 3 - }), exports.x = x, exports.y = y; -} - -function f3() { - [x, y, z] = [3, 4, 5], exports.x = x, exports.y = y; -} - -function f4() { - [x,, y] = [3, 4, 5], exports.x = x, exports.y = y; -} - -"# -); - -// strict_export_const_destructuring_array -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_const_destructuring_array, - r#" -export const [foo, bar] = []; - -"#, - r#" -"use strict"; - -exports.bar = exports.foo = void 0; -const [foo, bar] = []; -exports.foo = foo; -exports.bar = bar; - -"# -); - -// interop_export_named_3 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_named_3, - r#" -var foo; -export {foo as bar}; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.bar = void 0; -var foo; -exports.bar = foo; - -"# -); - -// strict_import_source - -// interop_imports_glob -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_imports_glob, - r#" -import * as foo from "foo"; - -"#, - r#" -"use strict"; - -var foo = _interopRequireWildcard(require("foo")); - -"# -); - -// misc - -// strict_export_all - -// strict_export -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export, - r#" -export function foo() {} - -"#, - r#" -"use strict"; - -exports.foo = foo; - -function foo() {} - -"# -); - -// no_interop_import_wildcard -test!( - syntax(), - |_| tr(Config { - no_interop: true, - ..Default::default() - }), - no_interop_import_wildcard, - r#" -import * as foo from 'foo'; - -foo.bar(); -foo.baz(); - -"#, - r#" -"use strict"; - -var foo = require("foo"); - -foo.bar(); -foo.baz(); - -"# -); - -// interop_export_default_5 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_5, - r#" -export default function () {} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -exports.default = _default; -function _default() {} - -"# -); - -// strict_export_const_destructuring_object_default_params -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_const_destructuring_object_default_params, - r#" -export const { foo, bar = 1 } = {}; - -"#, - r#" -"use strict"; - -exports.bar = exports.foo = void 0; -const { - foo, - bar = 1 -} = {}; -exports.foo = foo; -exports.bar = bar; - -"# -); - -// lazy_whitelist_reexport_all -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - }), - lazy_whitelist_reexport_all, - r#" -export * from "white"; - -export * from "black"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -var _exportNames = { -}; - -var _white = require("white"); - -Object.keys(_white).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _white[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return _white[key]; - } - }); -}); - -var _black = require("black"); - -Object.keys(_black).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _black[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return _black[key]; - } - }); -}); - -"# -); - -// misc_reference_source_map - -// lazy_dep_import_namespace -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_dep_import_namespace, - r#" -import * as foo from "foo"; - -function use() { - console.log(foo); -} -"#, - r#" -"use strict"; - -function foo() { - const data = _interopRequireWildcard(require("foo")); - - foo = function () { - return data; - }; - - return data; -} - -function use() { - console.log(foo()); -} - -"# -); - -// lazy_whitelist_reexport_default -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - }), - lazy_whitelist_reexport_default, - r#" -import foo from "white"; -export { foo as default }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "default", { - enumerable: true, - get: function () { - return _white().default; - } -}); - -function _white() { - const data = _interopRequireDefault(require("white")); - _white = function() { - return data; - }; - return data; -} - -"# -); - -// misc_local_exports_decl - -// interop_export_default_8 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_8, - r#" -export default class Foo {} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -class Foo {} - -exports.default = Foo; - -"# -); - -// strict_export_1 -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_1, - r#" -export default foo; - -"#, - r#" -"use strict"; - -exports.default = void 0; -var _default = foo; -exports.default = _default; - -"# -); - -// lazy_local_import_named -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_local_import_named, - r#" -import { foo } from "./foo"; - -console.log(foo); - -"#, - r#" -"use strict"; - -var _foo = require("./foo"); - -console.log(_foo.foo); - -"# -); - -// interop_export_default_2 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_2, - r#" -export default {}; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; -var _default = {}; -exports.default = _default; - -"# -); - -// interop_export_named -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_named_1, - r#" -var foo; -export {foo}; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.foo = void 0; -var foo; -exports.foo = foo; - -"# -); - -// interop_imports_ordering -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_imports_ordering, - r#" -import './foo'; -import bar from './bar'; -import './derp'; -import { qux } from './qux'; - -"#, - r#" -"use strict"; - -require("./foo"); - -var _bar = _interopRequireDefault(require("./bar")); - -require("./derp"); - -var _qux = require("./qux"); - -"# -); - -// strict_export_3 -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_3, - r#" -export {}; - -export {} from 'foo'; - -"#, - r#" -"use strict"; - -require("foo"); - -"# -); - -// interop_export_named_4 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_named_4, - r#" -var foo; -export {foo as default}; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; -var foo; -exports.default = foo; - -"# -); - -// misc_import_const_throw -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - misc_import_const_throw, - r#" -import Foo from "foo"; - -import * as Bar from "bar"; - -import { Baz } from "baz"; - -Foo = 42; -Bar = 43; -Baz = 44; - -({Foo} = {}); -({Bar} = {}); -({Baz} = {}); - -({prop: Foo} = {}); -({prop: Bar} = {}); -({prop: Baz} = {}); - -"#, - r#" -"use strict"; - -var _foo = _interopRequireDefault(require("foo")); - -var Bar = _interopRequireWildcard(require("bar")); - -var _baz = require("baz"); - -_foo.default = (42, function() { - throw new Error("'" + "Foo" + "' is read-only."); -}()); -Bar = (43, function() { - throw new Error("'" + "Bar" + "' is read-only."); -}()); -_baz.Baz = (44, function() { - throw new Error("'" + "Baz" + "' is read-only."); -}()); -({ Foo } = ( { -}, function() { - throw new Error("'" + "Foo" + "' is read-only."); -}())); -({ Bar } = ( { -}, function() { - throw new Error("'" + "Bar" + "' is read-only."); -}())); -({ Baz } = ( { -}, function() { - throw new Error("'" + "Baz" + "' is read-only."); -}())); -({ prop: Foo } = ( { -}, function() { - throw new Error("'" + "Foo" + "' is read-only."); -}())); -({ prop: Bar } = ( { -}, function() { - throw new Error("'" + "Bar" + "' is read-only."); -}())); -({ prop: Baz } = ( { -}, function() { - throw new Error("'" + "Baz" + "' is read-only."); -}())); -"# -); - -// lazy_local_import_default -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_local_import_default, - r#" -import foo from "./foo"; - -console.log(foo); - -"#, - r#" -"use strict"; - -var _foo = _interopRequireDefault(require("./foo")); - -console.log(_foo.default); - -"# -); - -// lazy_whitelist_reexport_namespace -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - }), - lazy_whitelist_reexport_namespace, - r#" -import * as namespace1 from "white"; -export { namespace1 }; - -import * as namespace2 from "black"; -export { namespace2 }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "namespace1", { - enumerable: true, - get: function () { - return namespace1(); - } -}); - -exports.namespace2 = void 0; -function namespace1() { - const data = _interopRequireWildcard(require("white")); - - namespace1 = function () { - return data; - }; - - return data; -} - - -var namespace2 = _interopRequireWildcard(require("black")); -exports.namespace2 = namespace2; - -"# -); - -// interop_export_from_3 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_from_3, - r#" -export {foo, bar} from "foo"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "foo", { - enumerable: true, - get: function () { - return _foo.foo; - } -}); -Object.defineProperty(exports, "bar", { - enumerable: true, - get: function () { - return _foo.bar; - } -}); - -var _foo = require("foo"); - -"# -); - -// lazy_dep_reexport_named -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_dep_reexport_named, - r#" -import { named } from "foo"; -export { named }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "named", { - enumerable: true, - get: function () { - return _foo().named; - } -}); -function _foo() { - const data = require("foo"); - - _foo = function () { - return data; - }; - - return data; -} - - -"# -); - -// auxiliary_comment_overview -test!( - // Comment is not supported yet - ignore, - syntax(), - |_| tr(Config { - ..Default::default() - }), - auxiliary_comment_overview, - r#" -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; -import foo from "foo2"; -import * as foo2 from "foo3"; -import {bar} from "foo4"; -import {foo as bar2} from "foo5"; - -var test; -export {test}; -export var test2 = 5; - -bar(foo, bar2); - -/* my comment */ -bar2; -foo; - -"#, - r#" -/*before*/ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.test2 = exports.test = void 0; - -/*after*/ - -/*before*/ -require("foo") -/*after*/ -; - -/*before*/ -require("foo-bar") -/*after*/ -; - -/*before*/ -require("./directory/foo-bar") -/*after*/ -; - -var -/*before*/ -_foo2 = _interopRequireDefault(require("foo2")) -/*after*/ -; - -var -/*before*/ -foo2 = _interopRequireDefault(require("foo3")) -/*after*/ -; - -var -/*before*/ -_foo4 = require("foo4") -/*after*/ -; - -var -/*before*/ -_foo5 = require("foo5") -/*after*/ -; - -var test; - -/*before*/ -exports.test = test; - -/*after*/ -var test2 = 5; - -/*before*/ -exports.test2 = test2; - -/*after*/ - -/*before*/ -(0, -/*after*/ - -/*before*/ -_foo4 -/*after*/ -. -/*before*/ -bar) -/*after*/ -( -/*before*/ -_foo2 -/*after*/ -. -/*before*/ -default -/*after*/ -, -/*before*/ -_foo5 -/*after*/ -. -/*before*/ -foo -/*after*/ -); -/* my comment */ - -/*before*/ -_foo5 -/*after*/ -. -/*before*/ -foo -/*after*/ -; - -/*before*/ -_foo2 -/*after*/ -. -/*before*/ -default -/*after*/ -; - -"# -); - -// misc_module_exports - -// interop_imports_default -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_imports_default, - r#" -import foo from "foo"; -import {default as foo2} from "foo"; - -foo; -foo2; - -"#, - r#" -"use strict"; - -var _foo = _interopRequireDefault(require("foo")); - -_foo.default; -_foo.default; - -"# -); - -// misc_undefined_this_root_reference -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - misc_undefined_this_root_reference, - r#" -this; - -"#, - r#" -"use strict"; - -void 0; - -"# -); - -// regression_t7272 - -// interop_export_default_10 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_10, - r#" -export default (function(){return "foo"})(); - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _default = function () { - return "foo"; -}(); - -exports.default = _default; - -"# -); - -// lazy_whitelist_import_named -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - }), - lazy_whitelist_import_named, - r#" -import { foo1 } from "white"; - -function use1() { - console.log(foo1); -} - -import { foo2 } from "black"; - -function use2() { - console.log(foo2); -} - -"#, - r#" -"use strict"; - -function _white() { - const data = require("white"); - - _white = function () { - return data; - }; - - return data; -} - -var _black = require("black"); - -function use1() { - console.log(_white().foo1); -} -function use2() { - console.log(_black.foo2); -} - -"# -); - -// interop_export_default -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default, - r#" -export default 42; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; -var _default = 42; -exports.default = _default; - -"# -); - -// strict - -// lazy_local_import_namespace -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_local_import_namespace, - r#" -import * as foo from "./foo"; - -console.log(foo); - -"#, - r#" -"use strict"; - -var foo = _interopRequireWildcard(require("./foo")); -console.log(foo); - -"# -); - -// interop - -// interop_export_default_7 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_7, - r#" -export default function foo () {} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -exports.default = foo; - -function foo() {} - -"# -); - -// lazy_whitelist_reexport_named -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - }), - lazy_whitelist_reexport_named, - r#" -import { named1 } from "white"; -export { named1 }; - -import { named2 } from "black"; -export { named2 }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "named1", { - enumerable: true, - get: function () { - return _white().named1; - } -}); -Object.defineProperty(exports, "named2", { - enumerable: true, - get: function () { - return _black.named2; - } -}); - -function _white() { - const data = require("white"); - - _white = function () { - return data; - }; - - return data; -} - -var _black = require("black"); - - -"# -); - -// lazy_dep - -// interop_export_from -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_from_1, - r#" -export * from "foo"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _foo = require("foo"); - -Object.keys(_foo).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (key in exports && exports[key] === _foo[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return _foo[key]; - } - }); -}); - -"# -); - -// disable_strict_mode_strict_mode_false -test!( - syntax(), - |_| tr(Config { - strict_mode: false, - ..Default::default() - }), - disable_strict_mode_strict_mode_false, - r#" -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; - -"#, - r#" -require("foo"); - -require("foo-bar"); - -require("./directory/foo-bar"); - -"# -); - -// interop_export_from_6 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_from_6, - r#" -export {foo as default, bar} from "foo"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "default", { - enumerable: true, - get: function () { - return _foo.foo; - } -}); -Object.defineProperty(exports, "bar", { - enumerable: true, - get: function () { - return _foo.bar; - } -}); - -var _foo = require("foo"); - -"# -); - -// interop_export_from_5 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_from_5, - r#" -export {foo as default} from "foo"; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "default", { - enumerable: true, - get: function () { - return _foo.foo; - } -}); - -var _foo = require("foo"); - -"# -); - -// strict_import -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_import, - r#" -import foo from "foo"; -import { default as foo2 } from "foo"; -import { foo3 } from "foo"; -import * as foo4 from "foo"; - -foo; -foo2; -foo3; -foo3(); - -"#, - r#" -"use strict"; - -var foo4 = _interopRequireWildcard(require("foo")); -foo4.default; -foo4.default; -foo4.foo3; -(0, foo4).foo3(); - -"# -); - -// interop_export_named_2 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_named_2, - r#" -var foo, bar; -export {foo, bar}; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.bar = exports.foo = void 0; -var foo, bar; -exports.foo = foo; -exports.bar = bar; - -"# -); - -// lazy_whitelist_import_default -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - }), - lazy_whitelist_import_default, - r#" -import foo1 from "white"; - -console.log(foo1); - -import foo2 from "black"; - -console.log(foo2); - -"#, - r#" -"use strict"; - -var _white = _interopRequireDefault(require("white")); -var _black = _interopRequireDefault(require("black")); - -console.log(_white.default); -console.log(_black.default); - -"# -); - -// interop_imports -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_imports, - r#" -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; - -"#, - r#" -"use strict"; - -require("foo"); - -require("foo-bar"); - -require("./directory/foo-bar"); - -"# -); - -// lazy_local - -// strict_export_const_destructuring_object -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_const_destructuring_object, - r#" -export const { foo: bar, baz } = {}; - -"#, - r#" -"use strict"; - -exports.baz = exports.bar = void 0; -const { - foo: bar, - baz -} = {}; -exports.bar = bar; -exports.baz = baz; - -"# -); - -// regression_issue_9155 - -// update_expression_negative_suffix -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - update_expression_negative_suffix, - r#" -export let diffLevel = 0; - -export function diff() { - if (!--diffLevel) { - console.log("hey"); - } -} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.diff = diff; -exports.diffLevel = void 0; -let diffLevel = 0; -exports.diffLevel = diffLevel; - -function diff() { - if (!(exports.diffLevel = --diffLevel)) { - console.log("hey"); - } -} - -"# -); - -// interop_module_shadow -test!( - // TODO(kdy1): Unignore this - ignore, - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_module_shadow, - r#" -export function module() { - -} - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.module = _module; - -function _module() {} - -"# -); - -// strict_export_const_destructuring_object_rest -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_const_destructuring_object_rest, - r#" -export const { foo, ...bar } = {}; - -"#, - r#" -"use strict"; - -exports.bar = exports.foo = void 0; -const { - foo, - ...bar -} = {}; -exports.foo = foo; -exports.bar = bar; - -"# -); - -// lazy_whitelist_sideeffect -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - }), - lazy_whitelist_sideeffect, - r#" -import "white"; -import "black"; - -"#, - r#" -"use strict"; - -require("white"); - -require("black"); - -"# -); - -// lazy_issue_3081_1 -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_issue_3081_1, - r#" -import { spawn } from "child_process"; - -function log() { console.log(spawn); } - -const other = () => { - const nestedClosure = () => { spawn("ls"); }; -} -"#, - r#" -"use strict"; -function _childProcess() { - const data = require("child_process"); - _childProcess = function() { - return data; - }; - return data; -} -function log() { - console.log(_childProcess().spawn); -} -const other = ()=>{ - const nestedClosure = () => { - _childProcess().spawn("ls"); - } -} -"# -); - -// lazy_issue_3081_2 -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_issue_3081_2, - r#" -import { fn, Klass } from "lib"; - -function myFn() { - fn() -} -class MyClass extends Klass {} -"#, - r#" -"use strict"; -var _lib = require("lib"); -function myFn() { - (0, _lib).fn(); -} -class MyClass extends _lib.Klass { -} -"# -); - -// lazy_computed_prop_name -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_computed_prop_name, - r#" -import { x } from "libx"; -import { y } from "liby"; - -class F { - get[x]() { } - get y() { y() } -} -"#, - r#" -"use strict"; -var _libx = require("libx"); -function _liby() { - const data = require("liby"); - _liby = function() { - return data; - }; - return data; -} - -class F { - get[_libx.x]() { } - get y() { _liby().y(); } -} -"# -); - -// lazy_not_shadowed_by_labels -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_not_shadowed_by_labels, - r#" -import { x } from "lib"; - -function fn() { - x() -} - -x: -console.log(1); - -continue x; - -"#, - r#" -"use strict"; -function _lib() { - const data = require("lib"); - _lib = function() { - return data; - }; - return data; -} - -function fn() { - _lib().x(); -} -x: -console.log(1); - -continue x; -"# -); - -// lazy_dep_reexport_namespace -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_dep_reexport_namespace, - r#" -import * as namespace from "foo"; -export { namespace }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "namespace", { - enumerable: true, - get: function () { - return namespace(); - } -}); - -function namespace() { - const data = _interopRequireWildcard(require("foo")); - - namespace = function () { - return data; - }; - - return data; -} - - -"# -); - -// interop_export_default_4 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_4, - r#" -export default foo; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; -var _default = foo; -exports.default = _default; - -"# -); - -// no_interop_export_from -test!( - syntax(), - |_| tr(Config { - no_interop: true, - ..Default::default() - }), - no_interop_export_from, - r#" -export { default } from 'foo'; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "default", { - enumerable: true, - get: function () { - return _foo.default; - } -}); -var _foo = require("foo"); - -"# -); - -// regression_es3_compatibility - -// lazy_dep_sideeffect -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_dep_sideeffect, - r#" -import "foo"; - -"#, - r#" -"use strict"; - -require("foo"); - -"# -); - -// interop_export_from_8 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_from_8, - r#" -import { foo, foo1, foo2, foo3, foo4, foo5, foo6, foo7, foo8, foo9, foo10, foo11, foo12, - foo13, foo14, foo15, foo16, foo17, foo18, foo19, foo20, foo21, foo22, foo23, foo24, foo25, - foo26, foo27, foo28, foo29, foo30, foo31, foo32, foo33, foo34, foo35, foo36, foo37, foo38, - foo39, foo40, foo41, foo42, foo43, foo44, foo45, foo46, foo47, foo48, foo49, foo50, foo51, - foo52, foo53, foo54, foo55, foo56, foo57, foo58, foo59, foo60, foo61, foo62, foo63, foo64, - foo65, foo66, foo67, foo68, foo69, foo70, foo71, foo72, foo73, foo74, foo75, foo76, foo77, - foo78, foo79, foo80, foo81, foo82, foo83, foo84, foo85, foo86, foo87, foo88, foo89, foo90, - foo91, foo92, foo93, foo94, foo95, foo96, foo97, foo98, foo99, foo100 } from "foo"; -export { foo, foo1, foo2, foo3, foo4, foo5, foo6, foo7, foo8, foo9, foo10, foo11, foo12, - foo13, foo14, foo15, foo16, foo17, foo18, foo19, foo20, foo21, foo22, foo23, foo24, foo25, - foo26, foo27, foo28, foo29, foo30, foo31, foo32, foo33, foo34, foo35, foo36, foo37, foo38, - foo39, foo40, foo41, foo42, foo43, foo44, foo45, foo46, foo47, foo48, foo49, foo50, foo51, - foo52, foo53, foo54, foo55, foo56, foo57, foo58, foo59, foo60, foo61, foo62, foo63, foo64, - foo65, foo66, foo67, foo68, foo69, foo70, foo71, foo72, foo73, foo74, foo75, foo76, foo77, - foo78, foo79, foo80, foo81, foo82, foo83, foo84, foo85, foo86, foo87, foo88, foo89, foo90, - foo91, foo92, foo93, foo94, foo95, foo96, foo97, foo98, foo99, foo100 } -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "foo", { - enumerable: true, - get: function () { - return _foo.foo; - } -}); -Object.defineProperty(exports, "foo1", { - enumerable: true, - get: function () { - return _foo.foo1; - } -}); -Object.defineProperty(exports, "foo2", { - enumerable: true, - get: function () { - return _foo.foo2; - } -}); -Object.defineProperty(exports, "foo3", { - enumerable: true, - get: function () { - return _foo.foo3; - } -}); -Object.defineProperty(exports, "foo4", { - enumerable: true, - get: function () { - return _foo.foo4; - } -}); -Object.defineProperty(exports, "foo5", { - enumerable: true, - get: function () { - return _foo.foo5; - } -}); -Object.defineProperty(exports, "foo6", { - enumerable: true, - get: function () { - return _foo.foo6; - } -}); -Object.defineProperty(exports, "foo7", { - enumerable: true, - get: function () { - return _foo.foo7; - } -}); -Object.defineProperty(exports, "foo8", { - enumerable: true, - get: function () { - return _foo.foo8; - } -}); -Object.defineProperty(exports, "foo9", { - enumerable: true, - get: function () { - return _foo.foo9; - } -}); -Object.defineProperty(exports, "foo10", { - enumerable: true, - get: function () { - return _foo.foo10; - } -}); -Object.defineProperty(exports, "foo11", { - enumerable: true, - get: function () { - return _foo.foo11; - } -}); -Object.defineProperty(exports, "foo12", { - enumerable: true, - get: function () { - return _foo.foo12; - } -}); -Object.defineProperty(exports, "foo13", { - enumerable: true, - get: function () { - return _foo.foo13; - } -}); -Object.defineProperty(exports, "foo14", { - enumerable: true, - get: function () { - return _foo.foo14; - } -}); -Object.defineProperty(exports, "foo15", { - enumerable: true, - get: function () { - return _foo.foo15; - } -}); -Object.defineProperty(exports, "foo16", { - enumerable: true, - get: function () { - return _foo.foo16; - } -}); -Object.defineProperty(exports, "foo17", { - enumerable: true, - get: function () { - return _foo.foo17; - } -}); -Object.defineProperty(exports, "foo18", { - enumerable: true, - get: function () { - return _foo.foo18; - } -}); -Object.defineProperty(exports, "foo19", { - enumerable: true, - get: function () { - return _foo.foo19; - } -}); -Object.defineProperty(exports, "foo20", { - enumerable: true, - get: function () { - return _foo.foo20; - } -}); -Object.defineProperty(exports, "foo21", { - enumerable: true, - get: function () { - return _foo.foo21; - } -}); -Object.defineProperty(exports, "foo22", { - enumerable: true, - get: function () { - return _foo.foo22; - } -}); -Object.defineProperty(exports, "foo23", { - enumerable: true, - get: function () { - return _foo.foo23; - } -}); -Object.defineProperty(exports, "foo24", { - enumerable: true, - get: function () { - return _foo.foo24; - } -}); -Object.defineProperty(exports, "foo25", { - enumerable: true, - get: function () { - return _foo.foo25; - } -}); -Object.defineProperty(exports, "foo26", { - enumerable: true, - get: function () { - return _foo.foo26; - } -}); -Object.defineProperty(exports, "foo27", { - enumerable: true, - get: function () { - return _foo.foo27; - } -}); -Object.defineProperty(exports, "foo28", { - enumerable: true, - get: function () { - return _foo.foo28; - } -}); -Object.defineProperty(exports, "foo29", { - enumerable: true, - get: function () { - return _foo.foo29; - } -}); -Object.defineProperty(exports, "foo30", { - enumerable: true, - get: function () { - return _foo.foo30; - } -}); -Object.defineProperty(exports, "foo31", { - enumerable: true, - get: function () { - return _foo.foo31; - } -}); -Object.defineProperty(exports, "foo32", { - enumerable: true, - get: function () { - return _foo.foo32; - } -}); -Object.defineProperty(exports, "foo33", { - enumerable: true, - get: function () { - return _foo.foo33; - } -}); -Object.defineProperty(exports, "foo34", { - enumerable: true, - get: function () { - return _foo.foo34; - } -}); -Object.defineProperty(exports, "foo35", { - enumerable: true, - get: function () { - return _foo.foo35; - } -}); -Object.defineProperty(exports, "foo36", { - enumerable: true, - get: function () { - return _foo.foo36; - } -}); -Object.defineProperty(exports, "foo37", { - enumerable: true, - get: function () { - return _foo.foo37; - } -}); -Object.defineProperty(exports, "foo38", { - enumerable: true, - get: function () { - return _foo.foo38; - } -}); -Object.defineProperty(exports, "foo39", { - enumerable: true, - get: function () { - return _foo.foo39; - } -}); -Object.defineProperty(exports, "foo40", { - enumerable: true, - get: function () { - return _foo.foo40; - } -}); -Object.defineProperty(exports, "foo41", { - enumerable: true, - get: function () { - return _foo.foo41; - } -}); -Object.defineProperty(exports, "foo42", { - enumerable: true, - get: function () { - return _foo.foo42; - } -}); -Object.defineProperty(exports, "foo43", { - enumerable: true, - get: function () { - return _foo.foo43; - } -}); -Object.defineProperty(exports, "foo44", { - enumerable: true, - get: function () { - return _foo.foo44; - } -}); -Object.defineProperty(exports, "foo45", { - enumerable: true, - get: function () { - return _foo.foo45; - } -}); -Object.defineProperty(exports, "foo46", { - enumerable: true, - get: function () { - return _foo.foo46; - } -}); -Object.defineProperty(exports, "foo47", { - enumerable: true, - get: function () { - return _foo.foo47; - } -}); -Object.defineProperty(exports, "foo48", { - enumerable: true, - get: function () { - return _foo.foo48; - } -}); -Object.defineProperty(exports, "foo49", { - enumerable: true, - get: function () { - return _foo.foo49; - } -}); -Object.defineProperty(exports, "foo50", { - enumerable: true, - get: function () { - return _foo.foo50; - } -}); -Object.defineProperty(exports, "foo51", { - enumerable: true, - get: function () { - return _foo.foo51; - } -}); -Object.defineProperty(exports, "foo52", { - enumerable: true, - get: function () { - return _foo.foo52; - } -}); -Object.defineProperty(exports, "foo53", { - enumerable: true, - get: function () { - return _foo.foo53; - } -}); -Object.defineProperty(exports, "foo54", { - enumerable: true, - get: function () { - return _foo.foo54; - } -}); -Object.defineProperty(exports, "foo55", { - enumerable: true, - get: function () { - return _foo.foo55; - } -}); -Object.defineProperty(exports, "foo56", { - enumerable: true, - get: function () { - return _foo.foo56; - } -}); -Object.defineProperty(exports, "foo57", { - enumerable: true, - get: function () { - return _foo.foo57; - } -}); -Object.defineProperty(exports, "foo58", { - enumerable: true, - get: function () { - return _foo.foo58; - } -}); -Object.defineProperty(exports, "foo59", { - enumerable: true, - get: function () { - return _foo.foo59; - } -}); -Object.defineProperty(exports, "foo60", { - enumerable: true, - get: function () { - return _foo.foo60; - } -}); -Object.defineProperty(exports, "foo61", { - enumerable: true, - get: function () { - return _foo.foo61; - } -}); -Object.defineProperty(exports, "foo62", { - enumerable: true, - get: function () { - return _foo.foo62; - } -}); -Object.defineProperty(exports, "foo63", { - enumerable: true, - get: function () { - return _foo.foo63; - } -}); -Object.defineProperty(exports, "foo64", { - enumerable: true, - get: function () { - return _foo.foo64; - } -}); -Object.defineProperty(exports, "foo65", { - enumerable: true, - get: function () { - return _foo.foo65; - } -}); -Object.defineProperty(exports, "foo66", { - enumerable: true, - get: function () { - return _foo.foo66; - } -}); -Object.defineProperty(exports, "foo67", { - enumerable: true, - get: function () { - return _foo.foo67; - } -}); -Object.defineProperty(exports, "foo68", { - enumerable: true, - get: function () { - return _foo.foo68; - } -}); -Object.defineProperty(exports, "foo69", { - enumerable: true, - get: function () { - return _foo.foo69; - } -}); -Object.defineProperty(exports, "foo70", { - enumerable: true, - get: function () { - return _foo.foo70; - } -}); -Object.defineProperty(exports, "foo71", { - enumerable: true, - get: function () { - return _foo.foo71; - } -}); -Object.defineProperty(exports, "foo72", { - enumerable: true, - get: function () { - return _foo.foo72; - } -}); -Object.defineProperty(exports, "foo73", { - enumerable: true, - get: function () { - return _foo.foo73; - } -}); -Object.defineProperty(exports, "foo74", { - enumerable: true, - get: function () { - return _foo.foo74; - } -}); -Object.defineProperty(exports, "foo75", { - enumerable: true, - get: function () { - return _foo.foo75; - } -}); -Object.defineProperty(exports, "foo76", { - enumerable: true, - get: function () { - return _foo.foo76; - } -}); -Object.defineProperty(exports, "foo77", { - enumerable: true, - get: function () { - return _foo.foo77; - } -}); -Object.defineProperty(exports, "foo78", { - enumerable: true, - get: function () { - return _foo.foo78; - } -}); -Object.defineProperty(exports, "foo79", { - enumerable: true, - get: function () { - return _foo.foo79; - } -}); -Object.defineProperty(exports, "foo80", { - enumerable: true, - get: function () { - return _foo.foo80; - } -}); -Object.defineProperty(exports, "foo81", { - enumerable: true, - get: function () { - return _foo.foo81; - } -}); -Object.defineProperty(exports, "foo82", { - enumerable: true, - get: function () { - return _foo.foo82; - } -}); -Object.defineProperty(exports, "foo83", { - enumerable: true, - get: function () { - return _foo.foo83; - } -}); -Object.defineProperty(exports, "foo84", { - enumerable: true, - get: function () { - return _foo.foo84; - } -}); -Object.defineProperty(exports, "foo85", { - enumerable: true, - get: function () { - return _foo.foo85; - } -}); -Object.defineProperty(exports, "foo86", { - enumerable: true, - get: function () { - return _foo.foo86; - } -}); -Object.defineProperty(exports, "foo87", { - enumerable: true, - get: function () { - return _foo.foo87; - } -}); -Object.defineProperty(exports, "foo88", { - enumerable: true, - get: function () { - return _foo.foo88; - } -}); -Object.defineProperty(exports, "foo89", { - enumerable: true, - get: function () { - return _foo.foo89; - } -}); -Object.defineProperty(exports, "foo90", { - enumerable: true, - get: function () { - return _foo.foo90; - } -}); -Object.defineProperty(exports, "foo91", { - enumerable: true, - get: function () { - return _foo.foo91; - } -}); -Object.defineProperty(exports, "foo92", { - enumerable: true, - get: function () { - return _foo.foo92; - } -}); -Object.defineProperty(exports, "foo93", { - enumerable: true, - get: function () { - return _foo.foo93; - } -}); -Object.defineProperty(exports, "foo94", { - enumerable: true, - get: function () { - return _foo.foo94; - } -}); -Object.defineProperty(exports, "foo95", { - enumerable: true, - get: function () { - return _foo.foo95; - } -}); -Object.defineProperty(exports, "foo96", { - enumerable: true, - get: function () { - return _foo.foo96; - } -}); -Object.defineProperty(exports, "foo97", { - enumerable: true, - get: function () { - return _foo.foo97; - } -}); -Object.defineProperty(exports, "foo98", { - enumerable: true, - get: function () { - return _foo.foo98; - } -}); -Object.defineProperty(exports, "foo99", { - enumerable: true, - get: function () { - return _foo.foo99; - } -}); -Object.defineProperty(exports, "foo100", { - enumerable: true, - get: function () { - return _foo.foo100; - } -}); - -var _foo = require("foo"); - -"# -); - -// strict_export_const_destructuring_array_default_params -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_const_destructuring_array_default_params, - r#" -export const [foo, bar = 2] = []; - -"#, - r#" -"use strict"; - -exports.bar = exports.foo = void 0; -const [foo, bar = 2] = []; -exports.foo = foo; -exports.bar = bar; - -"# -); - -// interop_imports_named -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_imports_named, - r#" -import {bar} from "foo"; -import {bar2, baz} from "foo"; -import {bar as baz2} from "foo"; -import {bar as baz3, xyz} from "foo"; - -bar; -bar2; -baz; -baz2; -baz3; -xyz; - -"#, - r#" -"use strict"; - -var _foo = require("foo"); - -_foo.bar; -_foo.bar2; -_foo.baz; -_foo.bar; -_foo.bar; -_foo.xyz; - -"# -); - -// regression_es3_compatibility_named_class - -// disable_strict_mode - -// lazy_whitelist_import_namespace -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::List(vec!["white".into()]), - ..Default::default() - }), - lazy_whitelist_import_namespace, - r#" -import * as foo1 from "white"; - -function use1(){ - console.log(foo1); -} - -import * as foo2 from "black"; - -function use2(){ - console.log(foo2); -} - -"#, - r#" -"use strict"; - -function foo1() { - const data = _interopRequireWildcard(require("white")); - - foo1 = function () { - return data; - }; - - return data; -} -var foo2 = _interopRequireWildcard(require("black")); - -function use1() { - console.log(foo1()); -} -function use2() { - console.log(foo2); -} - -"# -); - -// lazy_dep_import_named -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_dep_import_named, - r#" -import { foo } from "foo"; - -function use() { - console.log(foo); -} - -"#, - r#" -"use strict"; - -function _foo() { - const data = require("foo"); - - _foo = function () { - return data; - }; - - return data; -} - -function use() { - console.log(_foo().foo); -} - -"# -); - -// lazy_dep_reexport_default -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_dep_reexport_default, - r#" -import foo from "foo"; -export { foo as default }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "default", { - enumerable: true, - get: function () { - return _foo().default; - } -}); - -function _foo() { - const data = _interopRequireDefault(require("foo")); - - _foo = function () { - return data; - }; - - return data; -} - -"# -); - -// interop_export_default_9 -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_default_9, - r#" -var foo; -export { foo as default }; - - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; -var foo; -exports.default = foo; - -"# -); - -// misc_undefined_this_arrow_function -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - misc_undefined_this_arrow_function, - r#" -var foo = () => this; -"#, - r#" -"use strict"; - -var foo = () => void 0; -"# -); - -// misc_undefined_this_root_call -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - misc_undefined_this_root_call, - r#" -this.foo(); - -"#, - r#" -"use strict"; - -(void 0).foo(); - -"# -); - -// strict_import_wildcard -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_import_wildcard, - r#" -import * as foo from 'foo'; - -foo.bar(); -foo.baz(); - -"#, - r#" -"use strict"; - -var foo = _interopRequireWildcard(require("foo")); -foo.bar(); -foo.baz(); - -"# -); - -// lazy_dep_import_default -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_dep_import_default, - r#" -import foo from "foo"; - -function use() { - console.log(foo); -} -"#, - r#" -"use strict"; - -function _foo() { - const data = _interopRequireDefault(require("foo")); - - _foo = function () { - return data; - }; - - return data; -} - -function use() { - console.log(_foo().default); -} -"# -); - -// lazy_import_all_from_object_config -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Object(LazyObjectConfig { - patterns: vec![CachedRegex::new(".").unwrap()], - }), - ..Default::default() - }), - lazy_import_all_from_object_config, - r#" -import { local } from "./local"; -import { external } from "external"; - -function use() { - local(external); -} -"#, - r#" -"use strict"; - -function _local() { - const data = require("./local"); - _local = function () { - return data; - }; - return data; -} - -function _external() { - const data = require("external"); - _external = function () { - return data; - }; - return data; -} - -function use() { - _local().local(_external().external); -} -"# -); - -// lazy_import_only_allowed_from_object_config -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Object(LazyObjectConfig { - patterns: vec![CachedRegex::new("^test$").unwrap()], - }), - ..Default::default() - }), - lazy_import_only_allowed_from_object_config, - r#" -import { local } from "./local"; -import { external } from "external_test"; -import { test } from "test"; - -function use() { - local(external(test)); -} -"#, - r#" -"use strict"; -var _local = require("./local"); -var _externalTest = require("external_test"); - -function _test() { - const data = require("test"); - _test = function () { - return data; - }; - return data; -} - -function use() { - (0, _local).local((0, _externalTest).external(_test().test)); -} -"# -); - -// lazy_export_named -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_export_named, - r#" -export { named1 } from "external"; -"#, - r#" -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "named1", { - enumerable: true, - get: function() { - return _external().named1; - } -}); -function _external() { - const data = require("external"); - _external = function() { - return data; - }; - return data; -} -"# -); - -// lazy_local_reexport_named -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - lazy_local_reexport_named, - r#" -import { named } from "./foo"; -export { named }; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -Object.defineProperty(exports, "named", { - enumerable: true, - get: function () { - return _foo.named; - } -}); - -var _foo = require("./foo"); -"# -); - -// strict_export_const_destructuring_array_rest -test!( - syntax(), - |_| tr(Config { - strict: true, - ..Default::default() - }), - strict_export_const_destructuring_array_rest, - r#" -export const [foo, bar, ...baz] = []; - -"#, - r#" -"use strict"; - -exports.baz = exports.bar = exports.foo = void 0; -const [foo, bar, ...baz] = []; -exports.foo = foo; -exports.bar = bar; -exports.baz = baz; - -"# -); - -// update_expression - -// misc_reference_source_map_source - -// interop_illegal_export_esmodule - -// interop_imports_mixing -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_imports_mixing, - r#" -import foo, {baz as xyz} from "foo"; - -foo; -xyz; - -"#, - r#" -"use strict"; - -var _foo = _interopRequireWildcard(require("foo")); - -_foo.default; -_foo.baz; - -"# -); - -// interop_overview -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_overview, - r#" -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; -import foo from "foo2"; -import * as foo2 from "foo3"; -import {bar} from "foo4"; -import {foo as bar2} from "foo5"; - -var test; -export {test}; -export var test2 = 5; - -bar; -bar2; -foo; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.test2 = exports.test = void 0; - -require("foo"); - -require("foo-bar"); - -require("./directory/foo-bar"); - -var _foo2 = _interopRequireDefault(require("foo2")); - -var foo2 = _interopRequireWildcard(require("foo3")); - -var _foo4 = require("foo4"); - -var _foo5 = require("foo5"); - -var test; -var test2 = 5; -exports.test2 = test2; -_foo4.bar; -_foo5.foo; -_foo2.default; -exports.test = test; - -"# -); - -// interop_imports_hoisting - -// interop_export_all -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - interop_export_all, - r#" -// The fact that this exports both a normal default, and all of the names via -// re-export is an edge case that is important not to miss. See -// https://github.com/babel/babel/issues/8306 as an example. -import _default from 'react'; -export default _default; -export * from 'react'; - -"#, - r#" -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -exports.default = void 0; -var _react = _interopRequireWildcard(require("react")); - -Object.keys(_react).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (key in exports && exports[key] === _react[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return _react[key]; - } - }); -}); - -// The fact that this exports both a normal default, and all of the names via -// re-export is an edge case that is important not to miss. See -// https://github.com/babel/babel/issues/8306 as an example. -var _default = _react.default; -exports.default = _default; - -"# -); - -// lazy_whitelist - -// auxiliary_comment - -// source_map_exec -test_exec!( - // We cannot inject transform at this time. - ignore, - syntax(), - |_| tr(Default::default()), - source_map_exec, - r#" -var tests = [ - 'import "foo";', - 'import foo from "foo";', - 'import {default as foo2} from "foo";', - 'import * as foo from "foo";', - 'import {bar} from "foo";', - 'import {bar2, baz} from "foo";', - 'import {bar as baz2} from "foo";', - 'import {bar as baz3, xyz} from "foo";', - 'import bar, * as bar2 from "foo";', - 'import bar, {bar2, bar3 as bar4} from "foo";', - - 'export var a;', - 'export default function(){};', - 'export default function f(){};', - 'export default 42;', - 'export {foo}; var foo;', - 'export { foo as default }; var foo;', - 'export * from "foo";', - 'export {foo} from "foo";', - 'export {default as foo} from "foo";', -]; - -tests.forEach(function (code) { - var res = transform(code, { - sourceMap: true, - plugins: opts.plugins - }); - - // Should create mapping - expect(res.map.mappings).not.toBe(''); -}); - -"# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_396_1, - " -function foo() { - bar; - function bar() {} -} -", - " -\"use strict\"; -function foo() { - bar; - function bar() { - } -} -" -); - -test!( - syntax(), - |_| { - let unresolved_mark = Mark::new(); - let top_level_mark = Mark::new(); - - chain!( - resolver(unresolved_mark, top_level_mark, false), - block_scoped_functions(), - block_scoping(), - common_js(unresolved_mark, Default::default(), None), - ) - }, - issue_396_2, - " -function foo() { - bar; - function bar() {} -} -", - " -\"use strict\"; -function foo() { - var bar = function bar() { - }; - bar; -} -" -); - -test!( - syntax(), - |_| tr(Config { - strict: false, - strict_mode: true, - no_interop: true, - ..Default::default() - }), - issue_456_1, - "import { join as e } from 'path'; -export const foo = function () { - function e(t) {} - return A(e, {}), e -}();", - "\"use strict\"; -Object.defineProperty(exports, \"__esModule\", { - value: true -}); -exports.foo = void 0; -var _path = require(\"path\"); -const foo = function() { - function e(t) { - } - return A(e, {}), e; -}(); -exports.foo = foo; -" -); - -test!( - syntax(), - |_| tr(Config { - strict: false, - strict_mode: true, - no_interop: true, - ..Default::default() - }), - issue_456_2, - "import { join as e } from 'path'; -export const foo = function () { - var e = 1; - return A(e, {}), e -}();", - "\"use strict\"; -Object.defineProperty(exports, \"__esModule\", { - value: true -}); -exports.foo = void 0; -var _path = require(\"path\"); -const foo = function() { - var e = 1; - return A(e, { - }), e; -}(); -exports.foo = foo;" -); - -test!( - syntax(), - |_| tr(Config { - strict: false, - strict_mode: true, - no_interop: true, - ..Default::default() - }), - issue_605, - "export * from 'c';", - "\"use strict\"; -Object.defineProperty(exports, \"__esModule\", { - value: true -}); -var _c = require(\"c\"); -Object.keys(_c).forEach(function(key) { - if (key === \"default\" || key === \"__esModule\") return; - if (key in exports && exports[key] === _c[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _c[key]; - } - }); -}); -" -); - -test!( - syntax(), - |_| tr(Config { - strict: false, - strict_mode: true, - no_interop: true, - ..Default::default() - }), - issue_724, - "import { MongoClient, Db } from 'mongodb' - require('foo');", - "\"use strict\"; - var _mongodb = require(\"mongodb\"); - require('foo');" -); - -test!( - syntax(), - |_| tr(Config { - strict: false, - strict_mode: true, - ..Default::default() - }), - issue_763, - "import { - INSTAGRAM_CHECK_PATTERN, - RESOURCE_FACEBOOK, - RESOURCE_INSTAGRAM, - RESOURCE_WEBSITE, -} from '../../../../consts' - -const resources = [ - { - value: RESOURCE_WEBSITE, - label: 'Webové stránky', - }, - { - value: RESOURCE_FACEBOOK, - label: 'Facebook', - }, - { - value: RESOURCE_INSTAGRAM, - label: 'Instagram', - }, -]", - "\"use strict\"; - var _consts = require(\"../../../../consts\"); - const resources = [ - { - value: _consts.RESOURCE_WEBSITE, - label: 'Webové stránky' - }, - { - value: _consts.RESOURCE_FACEBOOK, - label: 'Facebook' - }, - { - value: _consts.RESOURCE_INSTAGRAM, - label: 'Instagram' - } - ];" -); - -test!( - ts_syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_895, - "import { queryString } from './url' - -export function setup(url: string, obj: any) { - const _queryString = queryString(obj) - const _url = url + '?' + _queryString - return _url -}", - "\"use strict\"; -Object.defineProperty(exports, \"__esModule\", { - value: true -}); -exports.setup = setup; -var _url = require(\"./url\"); -function setup(url: string, obj: any) { - const _queryString = (0, _url).queryString(obj); - const _url1 = url + '?' + _queryString; - return _url1; -}" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_962, - "import root from './_root.js'; - import stubFalse from './stubFalse.js'; - - var freeExports = typeof exports == \"object\" && exports && !exports.nodeType && exports; - var freeModule = freeExports && typeof module == \"object\" && module && !module.nodeType && \ - module; - - var moduleExports = freeModule && freeModule.exports === freeExports; - - var Buffer = moduleExports ? root.Buffer : undefined; - - var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined; - - var isBuffer = nativeIsBuffer || stubFalse; - - export default isBuffer", - r#" - "use strict"; - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.default = void 0; - var _rootJs = _interopRequireDefault(require("./_root.js")); - var _stubFalseJs = _interopRequireDefault(require("./stubFalse.js")); - var freeExports = typeof exports == "object" && exports && !exports.nodeType && exports; - var freeModule = freeExports && typeof module == "object" && module && !module.nodeType && module; - var moduleExports = freeModule && freeModule.exports === freeExports; - var Buffer = moduleExports ? _rootJs.default.Buffer : undefined; - var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined; - var isBuffer = nativeIsBuffer || _stubFalseJs.default; - var _default = isBuffer; - exports.default = _default; -"# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_1018_1, - "async function foo() { - await import('foo'); - }", - " - \"use strict\"; - async function foo() { - await Promise.resolve().then(function() { - return _interopRequireWildcard(require(\"foo\")); - }); - } - " -); -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_3246_1, - "import { foo } from 'bar'; - - import(foo); - ", - r#""use strict"; - var _bar = require("bar"); - Promise.resolve(`${_bar.foo}`).then(function(s) { - return _interopRequireWildcard(require(s)); - }); - "# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_3246_2, - "import foo from 'bar'; - - import(foo); - ", - r#""use strict"; - var _bar = _interopRequireDefault(require("bar")); - Promise.resolve(`${_bar.default}`).then(function(s) { - return _interopRequireWildcard(require(s)); - }); - "# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_3438, - "import { foo } from 'bar'; - - import(`world/${foo(baz)}.js`); - ", - r#""use strict"; - var _bar = require("bar"); - Promise.resolve(`world/${(0, _bar).foo(baz)}.js`).then(function(s) { - return _interopRequireWildcard(require(s)); - }); - "# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_1043_1, - " - export * from './http'; - export { Scope } from './interfaces' - ", - r#" -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -var _exportNames = { - Scope: true -}; -Object.defineProperty(exports, "Scope", { - enumerable: true, - get: function() { - return _interfaces.Scope; - } -}); -var _http = require("./http"); -Object.keys(_http).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _http[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _http[key]; - } - }); -}); -var _interfaces = require("./interfaces"); - "# -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_1043_2, - " -import 'reflect-metadata'; - -export * from './http'; -export { id } from './interfaces'; -export * from './pipes'; -", - r#" - "use strict"; - Object.defineProperty(exports, "__esModule", { - value: true - }); - var _exportNames = { - id: true - }; - Object.defineProperty(exports, "id", { - enumerable: true, - get: function() { - return _interfaces.id; - } - }); - require("reflect-metadata"); - var _http = require("./http"); - Object.keys(_http).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _http[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _http[key]; - } - }); - }); - var _interfaces = require("./interfaces"); - var _pipes = require("./pipes"); - Object.keys(_pipes).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _pipes[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _pipes[key]; - } - }); - }); - "# -); - -test!( - syntax(), - |t| { - let unresolved_mark = Mark::new(); - let top_level_mark = Mark::new(); - - chain!( - resolver(unresolved_mark, top_level_mark, false), - block_scoping(), - classes(Some(t.comments.clone()), Default::default()), - destructuring(Default::default()), - common_js(unresolved_mark, Default::default(), None) - ) - }, - issue_578_2, - " -import { myFunction } from './dep.js' - -class SomeClass { - constructor(properties) { - this.props = properties; - } - call () { - const {myFunction} = this.props - if (myFunction) { - myFunction() - } else { - console.log('DID NOT WORK!') - } - } -} - -let instance = new SomeClass({ - myFunction: () => { - console.log('CORRECT FUNCTION CALLED') - } -}); - -instance.call()", - "\"use strict\"; -var _depJs = require(\"./dep.js\"); -let SomeClass = function() { - \"use strict\"; - function SomeClass(properties) { - _classCallCheck(this, SomeClass); - this.props = properties; - } - _createClass(SomeClass, [{ - key: \"call\", - value: function call() { - var myFunction = this.props.myFunction; - if (myFunction) { - myFunction(); - } else { - console.log('DID NOT WORK!'); - } - } - }]); - return SomeClass; -}(); -var instance = new SomeClass({ - myFunction: ()=>{ - console.log('CORRECT FUNCTION CALLED'); - } -}); -instance.call();", - ok_if_code_eq -); - -// for_of_as_array_for_of_import_commonjs -test!( - syntax(), - |_| chain!( - for_of(for_of::Config { assume_array: true }), - common_js(Mark::fresh(Mark::root()), Default::default(), None) - ), - for_of_as_array_for_of_import_commonjs, - r#" -import { array } from "foo"; - -for (const elm of array) { -console.log(elm); -} - -"#, - r#" -"use strict"; - -var _foo = require("foo"); - -for(let _i = 0; _i < _foo.array.length; _i++){ -const elm = _foo.array[_i]; -console.log(elm); -} - -"# -); - -// regression_t7178 -test!( - syntax(), - |_| { - let unresolved_mark = Mark::new(); - let top_level_mark = Mark::new(); - - chain!( - resolver(unresolved_mark, top_level_mark, false), - object_rest_spread(Default::default()), - destructuring(destructuring::Config { loose: false }), - common_js(unresolved_mark, Default::default(), None), - ) - }, - regression_t7178, - r#" -import props from "props"; - -console.log(props); - -(function(){ -const { ...props } = this.props; - -console.log(props); -})(); - -"#, - r#" -"use strict"; - -var _props = _interopRequireDefault(require("props")); - -console.log(_props.default); - -(function () { -const props = _extends({}, this.props); -console.log(props); -})(); - -"# -); - -// regression_4209 -test!( - syntax(), - |t| { - let unresolved_mark = Mark::new(); - let top_level_mark = Mark::new(); - chain!( - resolver(unresolved_mark, top_level_mark, false), - classes(Some(t.comments.clone()), Default::default()), - parameters(Default::default(), unresolved_mark), - destructuring(Default::default()), - block_scoping(), - common_js(Mark::fresh(Mark::root()), Default::default(), None), - ) - }, - regression_4209, - r#" -import { copy } from './copyPaste'; - -class Thing { -handleCopySomething() { - copy(); -} - -completelyUnrelated(copy = 123) { -} -} - -"#, - r#" -"use strict"; - -var _copyPaste = require("./copyPaste"); - -var Thing = -/*#__PURE__*/ -function () { -"use strict"; -function Thing() { - _classCallCheck(this, Thing); -} - -_createClass(Thing, [{ - key: "handleCopySomething", - value: function handleCopySomething() { - (0, _copyPaste).copy(); - } -}, { - key: "completelyUnrelated", - value: function completelyUnrelated() { - var copy = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 123; - } -}]); - -return Thing; -}(); - -"# -); - -// regression_6647 -test!( - syntax(), - |_| chain!( - spread(spread::Config { - ..Default::default() - }), - common_js(Mark::fresh(Mark::root()), Default::default(), None) - ), - regression_6647, - r#" -import a from 'a'; -a.preview(...c); - -"#, - r#" -"use strict"; -var _a = _interopRequireDefault(require("a")); -var _a1; -(_a1 = _a.default).preview.apply(_a1, _toConsumableArray(c)); -"# -); - -// regression_6733 -test!( - syntax(), - |_| { - let unresolved_mark = Mark::new(); - let top_level_mark = Mark::new(); - - chain!( - resolver(unresolved_mark, top_level_mark, false), - regenerator(Default::default(), Mark::fresh(Mark::root())), - common_js(unresolved_mark, Default::default(), None) - ) - }, - regression_6733, - r#" -export default function * () { -var x = yield 5; -return 5; -} - -"#, - r#" - "use strict"; - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.default = _callee; - var _regeneratorRuntime = _interopRequireDefault(require("regenerator-runtime")); - function _callee() { - var x; - return _regeneratorRuntime.default.wrap(function _callee$(_ctx) { - while(1)switch(_ctx.prev = _ctx.next){ - case 0: - _ctx.next = 2; - return 5; - case 2: - x = _ctx.sent; - return _ctx.abrupt("return", 5); - case 4: - case "end": - return _ctx.stop(); - } - }, _callee); - } -"# -); - -// test interop between cjs module and regenerator -test!( - syntax(), - |_| { - let unresolved_mark = Mark::new(); - - chain!( - regenerator(Default::default(), unresolved_mark), - common_js(unresolved_mark, Default::default(), None), - ) - }, - issue_831_2, - "export function* myGenerator() { - yield* [1,2,3]; - }", - "\"use strict\"; -Object.defineProperty(exports, \"__esModule\", { - value: true -}); -exports.myGenerator = myGenerator; -var _regeneratorRuntime = _interopRequireDefault(require(\"regenerator-runtime\")); -var _marked = _regeneratorRuntime.default.mark(myGenerator); -function myGenerator() { - return _regeneratorRuntime.default.wrap(function myGenerator$(_ctx) { - while(1)switch(_ctx.prev = _ctx.next){ - case 0: - return _ctx.delegateYield([ - 1, - 2, - 3 - ], \"t0\", 1); - case 1: - case \"end\": - return _ctx.stop(); - } - }, _marked); -}" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_1213, - " - import foo from 'foo'; - - class OK { - constructor() { - console.log(foo); - } - } - - export default class NotOK { - constructor() { - console.log(foo); - } - } - ", - " - \"use strict\"; - Object.defineProperty(exports, \"__esModule\", { - value: true - }); - exports.default = void 0; - - var _foo = _interopRequireDefault(require(\"foo\")); - - class NotOK { - constructor() { - console.log(_foo.default); - } - } - exports.default = NotOK; - - class OK { - constructor() { - console.log(_foo.default); - } - } - " -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_1423_1, - " - 'use strict'; - import { arrayUtilities } from 'necessary'; - - const { second } = arrayUtilities; - - const elements = [1, 2, 3], - secondElement = second(elements); - - console.log(secondElement) - ", - " - 'use strict'; - var _necessary = require(\"necessary\"); - const { second } = _necessary.arrayUtilities; - const elements = [ - 1, - 2, - 3 - ], secondElement = second(elements); - console.log(secondElement); - " -); - -test!( - syntax(), - |_| tr(Config { - no_interop: false, - strict: true, - strict_mode: true, - lazy: Lazy::Bool(false), - ..Default::default() - }), - issue_1480_1, - " - const { default: ora } = await import('ora') - ", - " - \"use strict\"; - const { default: ora } = await Promise.resolve().then(function() { - return _interopRequireWildcard(require(\"ora\")); - }); - " -); - -test!( - syntax(), - |_| tr(Config { - no_interop: false, - strict: true, - strict_mode: true, - lazy: Lazy::Bool(false), - ..Default::default() - }), - issue_1480_2, - " - import * as ora from 'ora' -", - " - \"use strict\"; - var ora = _interopRequireWildcard(require(\"ora\")); - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_1568_1, - " - export default function get(key) { - console.log(key); - } - ", - " - \"use strict\"; - Object.defineProperty(exports, \"__esModule\", { - value: true - }); - - exports.default = get; - - function get(key) { - console.log(key); - } - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_1568_2, - " - export function get(key) { - console.log(key); - } - - export default a; - ", - " - \"use strict\"; - Object.defineProperty(exports, \"__esModule\", { - value: true - }); - exports.get = get; - exports.default = void 0; - - function get(key) { - console.log(key); - } - - var _default = a; - exports.default = _default; - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_1588_1, - " - import { Component, default as React } from 'react'; - - class X extends Component { - } - - React.render(); - ", - " - \"use strict\"; - var _react = _interopRequireWildcard(require(\"react\")); - class X extends _react.Component { - } - _react.default.render(); - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_1614_1, - " - (async () => { - const example = await import('./example'); - console.log(example.foo) - })() - ", - " - \"use strict\"; - (async ()=>{ - const example = await Promise.resolve().then(function() { - return _interopRequireWildcard(require(\"./example\")); - }); - console.log(example.foo); - })(); - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_1780_1, - " - export const BIZ = 'biz'; - export * from './File1'; - export * from './File2'; - ", - " - \"use strict\"; - Object.defineProperty(exports, \"__esModule\", { - value: true - }); - var _exportNames = { - BIZ: true - }; - exports.BIZ = void 0; - var _file1 = require(\"./File1\"); - Object.keys(_file1).forEach(function(key) { - if (key === \"default\" || key === \"__esModule\") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _file1[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _file1[key]; - } - }); - }); - var _file2 = require(\"./File2\"); - Object.keys(_file2).forEach(function(key) { - if (key === \"default\" || key === \"__esModule\") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _file2[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _file2[key]; - } - }); - }); - const BIZ = 'biz'; - exports.BIZ = BIZ; - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_4064, - " - export * from './File1'; - export * from './File2'; - - export const BIZ = 'biz'; - ", - " - \"use strict\"; - Object.defineProperty(exports, \"__esModule\", { - value: true - }); - var _exportNames = { - BIZ: true - }; - exports.BIZ = void 0; - var _file1 = require(\"./File1\"); - Object.keys(_file1).forEach(function(key) { - if (key === \"default\" || key === \"__esModule\") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _file1[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _file1[key]; - } - }); - }); - var _file2 = require(\"./File2\"); - Object.keys(_file2).forEach(function(key) { - if (key === \"default\" || key === \"__esModule\") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _file2[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _file2[key]; - } - }); - }); - const BIZ = 'biz'; - exports.BIZ = BIZ; - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_1757_1, - " - import 'testlibrary'; - import { aFunc } from 'testlibrary'; - - console.log('aFunc: ', aFunc(1,2)); - ", - " - \"use strict\"; - var _testlibrary = require(\"testlibrary\"); - console.log('aFunc: ', (0, _testlibrary).aFunc(1, 2)); - " -); -test!( - syntax(), - |_| { - let scope = Rc::new(RefCell::new(Scope::default())); - chain!( - import_analyzer(Rc::clone(&scope)), - common_js(Mark::fresh(Mark::root()), Default::default(), Some(scope)), - hygiene(), - fixer(None) - ) - }, - issue_1786_1, - " - import Foo from 'foo'; - export {Foo} from 'foo'; - ", - " - \"use strict\"; - Object.defineProperty(exports, \"__esModule\", { - value: true - }); - Object.defineProperty(exports, \"Foo\", { - enumerable: true, - get: function() { - return _foo.Foo; - } - }); - var _foo = _interopRequireWildcard(require(\"foo\")); - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_1787_1, - " - import bar from './bar/foo'; - import baz from './baz/foo'; - const a = [baz, bar]; - ", - " - \"use strict\"; - var _foo = _interopRequireDefault(require(\"./bar/foo\")); - var _foo1 = _interopRequireDefault(require(\"./baz/foo\")); - const a = [_foo1.default, _foo.default]; - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_1799_1, - " - export default function Foo() { - return 500; - } - ", - " - \"use strict\"; - Object.defineProperty(exports, \"__esModule\", { - value: true - }); - exports.default = Foo; - function Foo() { - return 500; - } - " -); - -test!( - syntax(), - |_| tr(Default::default()), - issue_1799_2, - " - export default function () { - return 500; - } - ", - " - \"use strict\"; - Object.defineProperty(exports, \"__esModule\", { - value: true - }); - exports.default = _default; - function _default() { - return 500; - } - " -); - -test!( - syntax(), - |_| tr(Config { - ignore_dynamic: true, - ..Default::default() - }), - ignore_dynamic_1, - " - import foo from 'foo'; - - - function foo() { - await import('foo'); - - callback(() => import('foo')); - } - - import('side-effect') - - await import('awaited') - ", - " - \"use strict\"; - var _foo = _interopRequireDefault(require(\"foo\")); - function foo() { - await import('foo'); - callback(()=>import('foo') - ); - } - import('side-effect'); - await import('awaited'); - " -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_2344_1, - " - class LoggingButton extends React.Component { - handleClick = () => { - console.log('this is:', this); - } - m() { this } - static a = () => this - } - ", - " - \"use strict\"; - class LoggingButton extends React.Component { - handleClick = () => { - console.log('this is:', this); - } - m() { this } - static a = () => this - } - " -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_2344_2, - " - class A { - // this is weird I know - [(() => this)()] = 123 - } - class B { - // this is weird too I know - [(() => this)()]() {} - } - class C { - static [(() => this)()] = 1 - } - class D { - static d = class { - [(() => this)()]() {} - } - } - ", - " - \"use strict\"; - class A { - [(() => void 0)()] = 123 - } - class B { - [(() => void 0)()]() {} - } - class C { - static [(() => void 0)()] = 1 - } - class D { - static d = class { - [(() => this)()]() {} - } - } - " -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_2344_3, - " - class A { - static { this.a = 123 } - } - ", - " - \"use strict\"; - class A { - static { this.a = 123 } - } - " -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - issue_4253, - "let pipeline = await import(await resolve(file))", - " -\"use strict\"; -let pipeline = await Promise.resolve(`${await resolve(file)}`).then(function(s) { - return _interopRequireWildcard(require(s)); -}); -" -); - -test!( - syntax(), - |_| tr(Config { - ..Default::default() - }), - pull_4688, - "export var format; -export default function defaultLocale(definition) { - locale = formatLocale(definition); - format = locale.format; - return locale; -} -format = '123';", - r#" -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = defaultLocale; -exports.format = void 0; -function defaultLocale(definition) { - locale = formatLocale(definition); - exports.format = format = locale.format; - return locale; -} -var format; -exports.format = format; -exports.format = format = '123'; -"# -); - -test!( - syntax(), - |_| tr(Config { - lazy: Lazy::Bool(true), - ..Default::default() - }), - issue_4799, - r#" - export { createP } from './St'; -"#, - r#" - "use strict"; - Object.defineProperty(exports, "__esModule", { - value: true - }); - Object.defineProperty(exports, "createP", { - enumerable: true, - get: function() { - return _st.createP; - } - }); - var _st = require("./St"); -"# -); - -#[testing::fixture("tests/fixture/commonjs/**/input.js")] -fn fixture(input: PathBuf) { let dir = input.parent().unwrap().to_path_buf(); - let output = dir.join("output.js"); + let output = dir + .join("output.js") + .with_extension(if is_ts { "cts" } else { "cjs" }); + + let config_path = dir.join("module.json"); + let config: common_js::Config = match File::open(config_path) { + Ok(file) => serde_json::from_reader(file).unwrap(), + Err(..) => Default::default(), + }; test_fixture( - Default::default(), - &|_| tr(Default::default()), + if is_ts { ts_syntax() } else { syntax() }, + &|_| tr(config.clone(), is_ts), &input, &output, ); } + +test!( + syntax(), + |_| chain!( + for_of(for_of::Config { assume_array: true }), + tr(Default::default(), false) + ), + for_of_as_array_for_of_import_commonjs, + r#" + import { array } from "foo"; + + for (const elm of array) { + console.log(elm); + } +"#, + r#" + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const _foo = require("foo"); + for(let _i = 0; _i < _foo.array.length; _i++){ + const elm = _foo.array[_i]; + console.log(elm); + } +"# +); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/class-property/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/class-property/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/class-property/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.amd.js new file mode 100644 index 00000000000..3ca1647dda7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports", + "./files_with_swcrc/simple" +], function(require, exports, _simple) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "Foo", { + get: ()=>Foo, + enumerable: true + }); + class Foo { + static prop = _simple.a; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.cjs new file mode 100644 index 00000000000..4ac644257fd --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.cjs @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "Foo", { + get: ()=>Foo, + enumerable: true +}); +const _simple = require("./files_with_swcrc/simple"); +class Foo { + static prop = _simple.a; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.umd.js new file mode 100644 index 00000000000..745d9dbc69b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-property/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./files_with_swcrc/simple")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./files_with_swcrc/simple" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.simple); +})(this, function(exports, _simple) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "Foo", { + get: ()=>Foo, + enumerable: true + }); + class Foo { + static prop = _simple.a; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/input.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/input.cts new file mode 100644 index 00000000000..438ee4bf2e6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/input.cts @@ -0,0 +1,3 @@ +import foo = require("foo"); + +export = foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.amd.ts new file mode 100644 index 00000000000..1556db75f59 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.amd.ts @@ -0,0 +1,7 @@ +define([ + "require", + "foo" +], function(require, _foo) { + "use strict"; + return _foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.cts new file mode 100644 index 00000000000..28ca36aa1b0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.cts @@ -0,0 +1,3 @@ +"use strict"; +const _foo = require("foo"); +module.exports = _foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.umd.ts new file mode 100644 index 00000000000..33922044464 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-assign/output.umd.ts @@ -0,0 +1,10 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") module.exports = factory(require("foo")); + else if (typeof define === "function" && define.amd) define([ + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) module.exports = factory(global.foo); +})(this, function(_foo) { + "use strict"; + return _foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/input.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/input.cts new file mode 100644 index 00000000000..5d65bc9ec58 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/input.cts @@ -0,0 +1 @@ +export import foo = require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.amd.ts new file mode 100644 index 00000000000..745bc9c5603 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.amd.ts @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>_foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.cts new file mode 100644 index 00000000000..14a0d365776 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.cts @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "foo", { + get: ()=>_foo, + enumerable: true +}); +const _foo = require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.umd.ts new file mode 100644 index 00000000000..121ee0cea7a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/export-import/output.umd.ts @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>_foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/input.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/input.cts new file mode 100644 index 00000000000..6b16970f477 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/input.cts @@ -0,0 +1,5 @@ +import foo from "foo"; +import bar = require("foo"); + +foo(); +bar(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.amd.ts new file mode 100644 index 00000000000..aaeecb27108 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.amd.ts @@ -0,0 +1,13 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const _foo1 = _interopRequireDefault(_foo); + (0, _foo1.default)(); + _foo(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.cts new file mode 100644 index 00000000000..11a82e05ed3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.cts @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = require("foo"); +const _foo1 = _interopRequireDefault(require("foo")); +(0, _foo1.default)(); +_foo(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.umd.ts new file mode 100644 index 00000000000..199e8ee5aaf --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/cts-import-export/mixed/output.umd.ts @@ -0,0 +1,16 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const _foo1 = _interopRequireDefault(_foo); + (0, _foo1.default)(); + _foo(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/input.js new file mode 100644 index 00000000000..c37d205168b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/input.js @@ -0,0 +1,3 @@ +var foo = 1; +export var foo = 2; +foo = 3; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.amd.js new file mode 100644 index 00000000000..641feeb9ea9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + var foo = 1; + var foo = 2; + foo = 3; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.cjs new file mode 100644 index 00000000000..4da5bd38369 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true +}); +var foo = 1; +var foo = 2; +foo = 3; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.umd.js new file mode 100644 index 00000000000..f2d4c261a8d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/01/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + var foo = 1; + var foo = 2; + foo = 3; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/input.js new file mode 100644 index 00000000000..c9f2aa063c2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/input.js @@ -0,0 +1,5 @@ +export const good = { + a(bad1) { + ((...bad2) => {}); + }, +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.amd.js new file mode 100644 index 00000000000..061e43e096d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.amd.js @@ -0,0 +1,18 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "good", { + get: ()=>good, + enumerable: true + }); + const good = { + a (bad1) { + (...bad2)=>{}; + } + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.cjs new file mode 100644 index 00000000000..02bcedd511a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.cjs @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "good", { + get: ()=>good, + enumerable: true +}); +const good = { + a (bad1) { + (...bad2)=>{}; + } +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.umd.js new file mode 100644 index 00000000000..62a13387bc3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/02/output.umd.js @@ -0,0 +1,21 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "good", { + get: ()=>good, + enumerable: true + }); + const good = { + a (bad1) { + (...bad2)=>{}; + } + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/input.js new file mode 100644 index 00000000000..4832b637fec --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/input.js @@ -0,0 +1,2 @@ +import { foo } from "src"; +export { foo }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/module.amd.json b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/module.amd.json new file mode 100644 index 00000000000..8cddd310130 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/module.amd.json @@ -0,0 +1,3 @@ +{ + "moduleId": "moduleId" +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.amd.js new file mode 100644 index 00000000000..13cfc9b20bc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.amd.js @@ -0,0 +1,14 @@ +define("moduleId", [ + "require", + "exports", + "src" +], function(require, exports, _src) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>_src.foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.cjs new file mode 100644 index 00000000000..2be5dc10de7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "foo", { + get: ()=>_src.foo, + enumerable: true +}); +const _src = require("src"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.umd.js new file mode 100644 index 00000000000..2bb89864fd0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/named-define/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("src")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "src" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.src); +})(this, function(exports, _src) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>_src.foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/input.js new file mode 100644 index 00000000000..f99d4277774 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/input.js @@ -0,0 +1 @@ +export function foo() {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/module.json new file mode 100644 index 00000000000..57ee09bce1f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/module.json @@ -0,0 +1,3 @@ +{ + "strictMode": false +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.amd.js new file mode 100644 index 00000000000..1e4ad2e24c5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.amd.js @@ -0,0 +1,13 @@ +define([ + "require", + "exports" +], function(require, exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + function foo() {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.cjs new file mode 100644 index 00000000000..2c722f204ec --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.cjs @@ -0,0 +1,8 @@ +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true +}); +function foo() {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.umd.js new file mode 100644 index 00000000000..d210bd201d4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/non-strict-mode/output.umd.js @@ -0,0 +1,16 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + function foo() {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/input.js new file mode 100644 index 00000000000..766c8ce7796 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/input.js @@ -0,0 +1,2 @@ +import React from "react"; +window.React = React; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.amd.js new file mode 100644 index 00000000000..c32bc7227f2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.amd.js @@ -0,0 +1,12 @@ +define([ + "require", + "exports", + "react" +], function(require, exports, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _react = _interopRequireDefault(_react); + window.React = _react.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.cjs new file mode 100644 index 00000000000..3b217e2f0ed --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _react = _interopRequireDefault(require("react")); +window.React = _react.default; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.umd.js new file mode 100644 index 00000000000..aa1b09e1212 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/custom/usage/output.umd.js @@ -0,0 +1,15 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("react")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "react" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.react); +})(this, function(exports, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _react = _interopRequireDefault(_react); + window.React = _react.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/input.js new file mode 100644 index 00000000000..222b6885ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/input.js @@ -0,0 +1,3 @@ +import "foo"; +import "foo-bar"; +import "./directory/foo-bar"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/module.json new file mode 100644 index 00000000000..57ee09bce1f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/module.json @@ -0,0 +1,3 @@ +{ + "strictMode": false +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.amd.js new file mode 100644 index 00000000000..1e91f0f2cc3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "foo", + "foo-bar", + "./directory/foo-bar" +], function(require, exports, _foo, _fooBar, _fooBar1) { + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.cjs new file mode 100644 index 00000000000..4183e61cdb6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.cjs @@ -0,0 +1,6 @@ +Object.defineProperty(exports, "__esModule", { + value: true +}); +require("foo"); +require("foo-bar"); +require("./directory/foo-bar"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.umd.js new file mode 100644 index 00000000000..d9e7f7afb3e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/disable-strict-mode-strict-mode-false/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo", + "foo-bar", + "./directory/foo-bar" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo, global.fooBar, global.fooBar); +})(this, function(exports, _foo, _fooBar, _fooBar1) { + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/export-update/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/input.js similarity index 67% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/export-update/1/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/input.js index 79db45e7663..e0d774b0242 100644 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/export-update/1/input.js +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/input.js @@ -5,6 +5,6 @@ export let bar = ++foo; export let baz = bar--; -export { foo as foobar, baz as bazbar }; +export { baz as bazbar, foo as foobar }; --bar; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.amd.js new file mode 100644 index 00000000000..9b3d841be07 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.amd.js @@ -0,0 +1,27 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + baz: ()=>baz, + bazbar: ()=>baz, + foo: ()=>foo, + foobar: ()=>foo + }); + let foo = 1n; + foo++; + let bar = ++foo; + let baz = bar--; + --bar; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.cjs new file mode 100644 index 00000000000..9cf8944d2fa --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.cjs @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + baz: ()=>baz, + bazbar: ()=>baz, + foo: ()=>foo, + foobar: ()=>foo +}); +let foo = 1n; +foo++; +let bar = ++foo; +let baz = bar--; +--bar; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.umd.js new file mode 100644 index 00000000000..ee470477a9b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/export-update/1/output.umd.js @@ -0,0 +1,30 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + baz: ()=>baz, + bazbar: ()=>baz, + foo: ()=>foo, + foobar: ()=>foo + }); + let foo = 1n; + foo++; + let bar = ++foo; + let baz = bar--; + --bar; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/input.js new file mode 100644 index 00000000000..c83aab3eb3b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/input.js @@ -0,0 +1,11 @@ +import foo from "foo"; + +async function foo() { + await import("foo"); + + callback(() => import("foo")); +} + +import("side-effect"); + +await import("awaited"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/module.json new file mode 100644 index 00000000000..799e2bd6b15 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/module.json @@ -0,0 +1,3 @@ +{ + "ignoreDynamic": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.amd.js new file mode 100644 index 00000000000..0c54bd89dc7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + async function foo() { + await import("foo"); + callback(()=>import("foo")); + } + import("side-effect"); + await import("awaited"); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.cjs new file mode 100644 index 00000000000..5bbf1d7e14f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireDefault(require("foo")); +async function foo() { + await import("foo"); + callback(()=>import("foo")); +} +import("side-effect"); +await import("awaited"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.umd.js new file mode 100644 index 00000000000..9b82f7290fc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/ignore-dynamic/1/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + async function foo() { + await import("foo"); + callback(()=>import("foo")); + } + import("side-effect"); + await import("awaited"); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/input.js new file mode 100644 index 00000000000..c9776e87f23 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/input.js @@ -0,0 +1,6 @@ +// The fact that this exports both a normal default, and all of the names via +// re-export is an edge case that is important not to miss. See +// https://github.com/babel/babel/issues/8306 as an example. +import _default from "react"; +export default _default; +export * from "react"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.amd.js new file mode 100644 index 00000000000..4c941b3fd99 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports", + "react" +], function(require, exports, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + _react = _interopRequireDefault(_exportStar(_react, exports)); + var _default = _react.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.cjs new file mode 100644 index 00000000000..417c5b7cc4d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +const _react = _interopRequireDefault(_exportStar(require("react"), exports)); +var _default = _react.default; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.umd.js new file mode 100644 index 00000000000..fba7fa5ce64 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-all/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("react")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "react" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.react); +})(this, function(exports, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + _react = _interopRequireDefault(_exportStar(_react, exports)); + var _default = _react.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/input.js new file mode 100644 index 00000000000..c0279bb6cff --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/input.js @@ -0,0 +1,3 @@ +export default (function () { + return "foo"; +})(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.amd.js new file mode 100644 index 00000000000..11fe86cdebc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = function() { + return "foo"; + }(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.cjs new file mode 100644 index 00000000000..f4232e4bb64 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +var _default = function() { + return "foo"; +}(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.umd.js new file mode 100644 index 00000000000..503c431cc32 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-10/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = function() { + return "foo"; + }(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/input.js new file mode 100644 index 00000000000..8c9172656db --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/input.js @@ -0,0 +1,3 @@ +export default new Cachier(); + +export function Cachier(databaseName) {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.amd.js new file mode 100644 index 00000000000..ca8cb0b3b6e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.amd.js @@ -0,0 +1,21 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + Cachier: ()=>Cachier, + default: ()=>_default + }); + var _default = new Cachier(); + function Cachier(databaseName) {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.cjs new file mode 100644 index 00000000000..52613117ed7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.cjs @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + Cachier: ()=>Cachier, + default: ()=>_default +}); +var _default = new Cachier(); +function Cachier(databaseName) {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.umd.js new file mode 100644 index 00000000000..1d00d5db7f1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-11/output.umd.js @@ -0,0 +1,24 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + Cachier: ()=>Cachier, + default: ()=>_default + }); + var _default = new Cachier(); + function Cachier(databaseName) {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/input.js new file mode 100644 index 00000000000..ff8b4c56321 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/input.js @@ -0,0 +1 @@ +export default {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.amd.js new file mode 100644 index 00000000000..0819898574f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.cjs new file mode 100644 index 00000000000..9c2784082a3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +var _default = {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.umd.js new file mode 100644 index 00000000000..c435daab8da --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-2/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/input.js new file mode 100644 index 00000000000..d6d1738de67 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/input.js @@ -0,0 +1 @@ +export default []; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.amd.js new file mode 100644 index 00000000000..bf953445521 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = []; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.cjs new file mode 100644 index 00000000000..23b515f0c42 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +var _default = []; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.umd.js new file mode 100644 index 00000000000..d4bbb18aa23 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-3/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = []; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/input.js new file mode 100644 index 00000000000..f7b318b3f63 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/input.js @@ -0,0 +1 @@ +export default foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.amd.js new file mode 100644 index 00000000000..10ec510642a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.cjs new file mode 100644 index 00000000000..affcffa4589 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +var _default = foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.umd.js new file mode 100644 index 00000000000..5f2c76f74b3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-4/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/input.js new file mode 100644 index 00000000000..ea9b101e1c2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/input.js @@ -0,0 +1 @@ +export default function () {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.amd.js new file mode 100644 index 00000000000..efa0e34a00b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + function _default() {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.cjs new file mode 100644 index 00000000000..74ba6b93319 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +function _default() {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.umd.js new file mode 100644 index 00000000000..bef3422103f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-5/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + function _default() {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/input.js new file mode 100644 index 00000000000..a6e68e98389 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/input.js @@ -0,0 +1 @@ +export default class {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.amd.js new file mode 100644 index 00000000000..0ceec52f4dc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + class _default { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.cjs new file mode 100644 index 00000000000..83d73b8c59e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +class _default { +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.umd.js new file mode 100644 index 00000000000..31a889e3783 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-6/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + class _default { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/input.js new file mode 100644 index 00000000000..386baca1731 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/input.js @@ -0,0 +1 @@ +export default function foo() {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.amd.js new file mode 100644 index 00000000000..031fb64edde --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true + }); + function foo() {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.cjs new file mode 100644 index 00000000000..f421f248a4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true +}); +function foo() {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.umd.js new file mode 100644 index 00000000000..43747ef1819 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-7/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true + }); + function foo() {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/input.js new file mode 100644 index 00000000000..7804111002d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/input.js @@ -0,0 +1 @@ +export default class Foo {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.amd.js new file mode 100644 index 00000000000..510871f3c90 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true + }); + class Foo { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.cjs new file mode 100644 index 00000000000..02d2a193fbd --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true +}); +class Foo { +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.umd.js new file mode 100644 index 00000000000..02ee94a386b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-8/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true + }); + class Foo { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/input.js new file mode 100644 index 00000000000..f52d2a90308 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/input.js @@ -0,0 +1,2 @@ +var foo; +export { foo as default }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.amd.js new file mode 100644 index 00000000000..e1f186c6312 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.cjs new file mode 100644 index 00000000000..ce965f7bd96 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true +}); +var foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.umd.js new file mode 100644 index 00000000000..9228b25dc09 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default-9/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/input.js new file mode 100644 index 00000000000..7a4e8a723a4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/input.js @@ -0,0 +1 @@ +export default 42; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.amd.js new file mode 100644 index 00000000000..021c462eeb3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = 42; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.cjs new file mode 100644 index 00000000000..d38bfcc24fb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +var _default = 42; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.umd.js new file mode 100644 index 00000000000..aee902a2c6e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-default/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = 42; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/input.js new file mode 100644 index 00000000000..bb4978ee76c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/input.js @@ -0,0 +1,18 @@ +export let x = 0; +export let y = 0; + +export function f1() { + ({ x } = { x: 1 }); +} + +export function f2() { + ({ x, y } = { x: 2, y: 3 }); +} + +export function f3() { + [x, y, z] = [3, 4, 5]; +} + +export function f4() { + [x, , y] = [3, 4, 5]; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.amd.js new file mode 100644 index 00000000000..dfdcc420438 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.amd.js @@ -0,0 +1,50 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + f1: ()=>f1, + f2: ()=>f2, + f3: ()=>f3, + f4: ()=>f4, + x: ()=>x, + y: ()=>y + }); + let x = 0; + let y = 0; + function f1() { + ({ x } = { + x: 1 + }); + } + function f2() { + ({ x , y } = { + x: 2, + y: 3 + }); + } + function f3() { + [x, y, z] = [ + 3, + 4, + 5 + ]; + } + function f4() { + [x, , y] = [ + 3, + 4, + 5 + ]; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.cjs new file mode 100644 index 00000000000..02594087c75 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.cjs @@ -0,0 +1,45 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + f1: ()=>f1, + f2: ()=>f2, + f3: ()=>f3, + f4: ()=>f4, + x: ()=>x, + y: ()=>y +}); +let x = 0; +let y = 0; +function f1() { + ({ x } = { + x: 1 + }); +} +function f2() { + ({ x , y } = { + x: 2, + y: 3 + }); +} +function f3() { + [x, y, z] = [ + 3, + 4, + 5 + ]; +} +function f4() { + [x, , y] = [ + 3, + 4, + 5 + ]; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.umd.js new file mode 100644 index 00000000000..5ed1b183a9f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-destructured/output.umd.js @@ -0,0 +1,53 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + f1: ()=>f1, + f2: ()=>f2, + f3: ()=>f3, + f4: ()=>f4, + x: ()=>x, + y: ()=>y + }); + let x = 0; + let y = 0; + function f1() { + ({ x } = { + x: 1 + }); + } + function f2() { + ({ x , y } = { + x: 2, + y: 3 + }); + } + function f3() { + [x, y, z] = [ + 3, + 4, + 5 + ]; + } + function f4() { + [x, , y] = [ + 3, + 4, + 5 + ]; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/input.js new file mode 100644 index 00000000000..9ec8f63ab2f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/input.js @@ -0,0 +1 @@ +export * from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.amd.js new file mode 100644 index 00000000000..2e1b4256446 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _exportStar(_foo, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.cjs new file mode 100644 index 00000000000..59c1df1a18a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +_exportStar(require("foo"), exports); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.umd.js new file mode 100644 index 00000000000..81a0ab21d12 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-1/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _exportStar(_foo, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/input.js new file mode 100644 index 00000000000..d5296d83cd3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/input.js @@ -0,0 +1 @@ +export { foo } from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.amd.js new file mode 100644 index 00000000000..6313bf4a6e6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>_foo.foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.cjs new file mode 100644 index 00000000000..d70df1ef584 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "foo", { + get: ()=>_foo.foo, + enumerable: true +}); +const _foo = require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.umd.js new file mode 100644 index 00000000000..56bdfa8a97d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-2/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>_foo.foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/input.js new file mode 100644 index 00000000000..ca2bf4e4b83 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/input.js @@ -0,0 +1 @@ +export { bar, foo } from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.amd.js new file mode 100644 index 00000000000..2947cadd8da --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>_foo.bar, + foo: ()=>_foo.foo + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.cjs new file mode 100644 index 00000000000..0812e41ac04 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>_foo.bar, + foo: ()=>_foo.foo +}); +const _foo = require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.umd.js new file mode 100644 index 00000000000..3351e1a30cb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-3/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>_foo.bar, + foo: ()=>_foo.foo + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/input.js new file mode 100644 index 00000000000..01da91b9e35 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/input.js @@ -0,0 +1 @@ +export { foo as bar } from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.amd.js new file mode 100644 index 00000000000..de3a71674c5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "bar", { + get: ()=>_foo.foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.cjs new file mode 100644 index 00000000000..f14fa6ef218 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "bar", { + get: ()=>_foo.foo, + enumerable: true +}); +const _foo = require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.umd.js new file mode 100644 index 00000000000..77ad92047bb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-4/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "bar", { + get: ()=>_foo.foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/input.js new file mode 100644 index 00000000000..d998b734003 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/input.js @@ -0,0 +1 @@ +export { foo as default } from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.amd.js new file mode 100644 index 00000000000..717706435f7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_foo.foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.cjs new file mode 100644 index 00000000000..a0c6ed2e707 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_foo.foo, + enumerable: true +}); +const _foo = require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.umd.js new file mode 100644 index 00000000000..e64415a7081 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-5/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_foo.foo, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/input.js new file mode 100644 index 00000000000..326896216fc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/input.js @@ -0,0 +1 @@ +export { bar, foo as default } from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.amd.js new file mode 100644 index 00000000000..fa12d5352ba --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>_foo.bar, + default: ()=>_foo.foo + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.cjs new file mode 100644 index 00000000000..a1cb4967024 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>_foo.bar, + default: ()=>_foo.foo +}); +const _foo = require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.umd.js new file mode 100644 index 00000000000..e899a309546 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-6/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>_foo.bar, + default: ()=>_foo.foo + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/input.js new file mode 100644 index 00000000000..9e092bc2893 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/input.js @@ -0,0 +1 @@ +export { default as foo } from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.amd.js new file mode 100644 index 00000000000..534ad9c18c1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>_foo.default, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.cjs new file mode 100644 index 00000000000..f6af058c1e3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "foo", { + get: ()=>_foo.default, + enumerable: true +}); +const _foo = _interopRequireDefault(require("foo")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.umd.js new file mode 100644 index 00000000000..47b2292b1e5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-7/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>_foo.default, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/input.js new file mode 100644 index 00000000000..bf256e3a191 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/input.js @@ -0,0 +1,206 @@ +import { + foo, + foo1, + foo10, + foo100, + foo11, + foo12, + foo13, + foo14, + foo15, + foo16, + foo17, + foo18, + foo19, + foo2, + foo20, + foo21, + foo22, + foo23, + foo24, + foo25, + foo26, + foo27, + foo28, + foo29, + foo3, + foo30, + foo31, + foo32, + foo33, + foo34, + foo35, + foo36, + foo37, + foo38, + foo39, + foo4, + foo40, + foo41, + foo42, + foo43, + foo44, + foo45, + foo46, + foo47, + foo48, + foo49, + foo5, + foo50, + foo51, + foo52, + foo53, + foo54, + foo55, + foo56, + foo57, + foo58, + foo59, + foo6, + foo60, + foo61, + foo62, + foo63, + foo64, + foo65, + foo66, + foo67, + foo68, + foo69, + foo7, + foo70, + foo71, + foo72, + foo73, + foo74, + foo75, + foo76, + foo77, + foo78, + foo79, + foo8, + foo80, + foo81, + foo82, + foo83, + foo84, + foo85, + foo86, + foo87, + foo88, + foo89, + foo9, + foo90, + foo91, + foo92, + foo93, + foo94, + foo95, + foo96, + foo97, + foo98, + foo99, +} from "foo"; +export { + foo, + foo1, + foo10, + foo100, + foo11, + foo12, + foo13, + foo14, + foo15, + foo16, + foo17, + foo18, + foo19, + foo2, + foo20, + foo21, + foo22, + foo23, + foo24, + foo25, + foo26, + foo27, + foo28, + foo29, + foo3, + foo30, + foo31, + foo32, + foo33, + foo34, + foo35, + foo36, + foo37, + foo38, + foo39, + foo4, + foo40, + foo41, + foo42, + foo43, + foo44, + foo45, + foo46, + foo47, + foo48, + foo49, + foo5, + foo50, + foo51, + foo52, + foo53, + foo54, + foo55, + foo56, + foo57, + foo58, + foo59, + foo6, + foo60, + foo61, + foo62, + foo63, + foo64, + foo65, + foo66, + foo67, + foo68, + foo69, + foo7, + foo70, + foo71, + foo72, + foo73, + foo74, + foo75, + foo76, + foo77, + foo78, + foo79, + foo8, + foo80, + foo81, + foo82, + foo83, + foo84, + foo85, + foo86, + foo87, + foo88, + foo89, + foo9, + foo90, + foo91, + foo92, + foo93, + foo94, + foo95, + foo96, + foo97, + foo98, + foo99, +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.amd.js new file mode 100644 index 00000000000..89a924e066f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.amd.js @@ -0,0 +1,119 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + foo: ()=>_foo.foo, + foo1: ()=>_foo.foo1, + foo10: ()=>_foo.foo10, + foo100: ()=>_foo.foo100, + foo11: ()=>_foo.foo11, + foo12: ()=>_foo.foo12, + foo13: ()=>_foo.foo13, + foo14: ()=>_foo.foo14, + foo15: ()=>_foo.foo15, + foo16: ()=>_foo.foo16, + foo17: ()=>_foo.foo17, + foo18: ()=>_foo.foo18, + foo19: ()=>_foo.foo19, + foo2: ()=>_foo.foo2, + foo20: ()=>_foo.foo20, + foo21: ()=>_foo.foo21, + foo22: ()=>_foo.foo22, + foo23: ()=>_foo.foo23, + foo24: ()=>_foo.foo24, + foo25: ()=>_foo.foo25, + foo26: ()=>_foo.foo26, + foo27: ()=>_foo.foo27, + foo28: ()=>_foo.foo28, + foo29: ()=>_foo.foo29, + foo3: ()=>_foo.foo3, + foo30: ()=>_foo.foo30, + foo31: ()=>_foo.foo31, + foo32: ()=>_foo.foo32, + foo33: ()=>_foo.foo33, + foo34: ()=>_foo.foo34, + foo35: ()=>_foo.foo35, + foo36: ()=>_foo.foo36, + foo37: ()=>_foo.foo37, + foo38: ()=>_foo.foo38, + foo39: ()=>_foo.foo39, + foo4: ()=>_foo.foo4, + foo40: ()=>_foo.foo40, + foo41: ()=>_foo.foo41, + foo42: ()=>_foo.foo42, + foo43: ()=>_foo.foo43, + foo44: ()=>_foo.foo44, + foo45: ()=>_foo.foo45, + foo46: ()=>_foo.foo46, + foo47: ()=>_foo.foo47, + foo48: ()=>_foo.foo48, + foo49: ()=>_foo.foo49, + foo5: ()=>_foo.foo5, + foo50: ()=>_foo.foo50, + foo51: ()=>_foo.foo51, + foo52: ()=>_foo.foo52, + foo53: ()=>_foo.foo53, + foo54: ()=>_foo.foo54, + foo55: ()=>_foo.foo55, + foo56: ()=>_foo.foo56, + foo57: ()=>_foo.foo57, + foo58: ()=>_foo.foo58, + foo59: ()=>_foo.foo59, + foo6: ()=>_foo.foo6, + foo60: ()=>_foo.foo60, + foo61: ()=>_foo.foo61, + foo62: ()=>_foo.foo62, + foo63: ()=>_foo.foo63, + foo64: ()=>_foo.foo64, + foo65: ()=>_foo.foo65, + foo66: ()=>_foo.foo66, + foo67: ()=>_foo.foo67, + foo68: ()=>_foo.foo68, + foo69: ()=>_foo.foo69, + foo7: ()=>_foo.foo7, + foo70: ()=>_foo.foo70, + foo71: ()=>_foo.foo71, + foo72: ()=>_foo.foo72, + foo73: ()=>_foo.foo73, + foo74: ()=>_foo.foo74, + foo75: ()=>_foo.foo75, + foo76: ()=>_foo.foo76, + foo77: ()=>_foo.foo77, + foo78: ()=>_foo.foo78, + foo79: ()=>_foo.foo79, + foo8: ()=>_foo.foo8, + foo80: ()=>_foo.foo80, + foo81: ()=>_foo.foo81, + foo82: ()=>_foo.foo82, + foo83: ()=>_foo.foo83, + foo84: ()=>_foo.foo84, + foo85: ()=>_foo.foo85, + foo86: ()=>_foo.foo86, + foo87: ()=>_foo.foo87, + foo88: ()=>_foo.foo88, + foo89: ()=>_foo.foo89, + foo9: ()=>_foo.foo9, + foo90: ()=>_foo.foo90, + foo91: ()=>_foo.foo91, + foo92: ()=>_foo.foo92, + foo93: ()=>_foo.foo93, + foo94: ()=>_foo.foo94, + foo95: ()=>_foo.foo95, + foo96: ()=>_foo.foo96, + foo97: ()=>_foo.foo97, + foo98: ()=>_foo.foo98, + foo99: ()=>_foo.foo99 + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.cjs new file mode 100644 index 00000000000..a92a7093664 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.cjs @@ -0,0 +1,114 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + foo: ()=>_foo.foo, + foo1: ()=>_foo.foo1, + foo10: ()=>_foo.foo10, + foo100: ()=>_foo.foo100, + foo11: ()=>_foo.foo11, + foo12: ()=>_foo.foo12, + foo13: ()=>_foo.foo13, + foo14: ()=>_foo.foo14, + foo15: ()=>_foo.foo15, + foo16: ()=>_foo.foo16, + foo17: ()=>_foo.foo17, + foo18: ()=>_foo.foo18, + foo19: ()=>_foo.foo19, + foo2: ()=>_foo.foo2, + foo20: ()=>_foo.foo20, + foo21: ()=>_foo.foo21, + foo22: ()=>_foo.foo22, + foo23: ()=>_foo.foo23, + foo24: ()=>_foo.foo24, + foo25: ()=>_foo.foo25, + foo26: ()=>_foo.foo26, + foo27: ()=>_foo.foo27, + foo28: ()=>_foo.foo28, + foo29: ()=>_foo.foo29, + foo3: ()=>_foo.foo3, + foo30: ()=>_foo.foo30, + foo31: ()=>_foo.foo31, + foo32: ()=>_foo.foo32, + foo33: ()=>_foo.foo33, + foo34: ()=>_foo.foo34, + foo35: ()=>_foo.foo35, + foo36: ()=>_foo.foo36, + foo37: ()=>_foo.foo37, + foo38: ()=>_foo.foo38, + foo39: ()=>_foo.foo39, + foo4: ()=>_foo.foo4, + foo40: ()=>_foo.foo40, + foo41: ()=>_foo.foo41, + foo42: ()=>_foo.foo42, + foo43: ()=>_foo.foo43, + foo44: ()=>_foo.foo44, + foo45: ()=>_foo.foo45, + foo46: ()=>_foo.foo46, + foo47: ()=>_foo.foo47, + foo48: ()=>_foo.foo48, + foo49: ()=>_foo.foo49, + foo5: ()=>_foo.foo5, + foo50: ()=>_foo.foo50, + foo51: ()=>_foo.foo51, + foo52: ()=>_foo.foo52, + foo53: ()=>_foo.foo53, + foo54: ()=>_foo.foo54, + foo55: ()=>_foo.foo55, + foo56: ()=>_foo.foo56, + foo57: ()=>_foo.foo57, + foo58: ()=>_foo.foo58, + foo59: ()=>_foo.foo59, + foo6: ()=>_foo.foo6, + foo60: ()=>_foo.foo60, + foo61: ()=>_foo.foo61, + foo62: ()=>_foo.foo62, + foo63: ()=>_foo.foo63, + foo64: ()=>_foo.foo64, + foo65: ()=>_foo.foo65, + foo66: ()=>_foo.foo66, + foo67: ()=>_foo.foo67, + foo68: ()=>_foo.foo68, + foo69: ()=>_foo.foo69, + foo7: ()=>_foo.foo7, + foo70: ()=>_foo.foo70, + foo71: ()=>_foo.foo71, + foo72: ()=>_foo.foo72, + foo73: ()=>_foo.foo73, + foo74: ()=>_foo.foo74, + foo75: ()=>_foo.foo75, + foo76: ()=>_foo.foo76, + foo77: ()=>_foo.foo77, + foo78: ()=>_foo.foo78, + foo79: ()=>_foo.foo79, + foo8: ()=>_foo.foo8, + foo80: ()=>_foo.foo80, + foo81: ()=>_foo.foo81, + foo82: ()=>_foo.foo82, + foo83: ()=>_foo.foo83, + foo84: ()=>_foo.foo84, + foo85: ()=>_foo.foo85, + foo86: ()=>_foo.foo86, + foo87: ()=>_foo.foo87, + foo88: ()=>_foo.foo88, + foo89: ()=>_foo.foo89, + foo9: ()=>_foo.foo9, + foo90: ()=>_foo.foo90, + foo91: ()=>_foo.foo91, + foo92: ()=>_foo.foo92, + foo93: ()=>_foo.foo93, + foo94: ()=>_foo.foo94, + foo95: ()=>_foo.foo95, + foo96: ()=>_foo.foo96, + foo97: ()=>_foo.foo97, + foo98: ()=>_foo.foo98, + foo99: ()=>_foo.foo99 +}); +const _foo = require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.umd.js new file mode 100644 index 00000000000..2f8c72af287 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-from-8/output.umd.js @@ -0,0 +1,122 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + foo: ()=>_foo.foo, + foo1: ()=>_foo.foo1, + foo10: ()=>_foo.foo10, + foo100: ()=>_foo.foo100, + foo11: ()=>_foo.foo11, + foo12: ()=>_foo.foo12, + foo13: ()=>_foo.foo13, + foo14: ()=>_foo.foo14, + foo15: ()=>_foo.foo15, + foo16: ()=>_foo.foo16, + foo17: ()=>_foo.foo17, + foo18: ()=>_foo.foo18, + foo19: ()=>_foo.foo19, + foo2: ()=>_foo.foo2, + foo20: ()=>_foo.foo20, + foo21: ()=>_foo.foo21, + foo22: ()=>_foo.foo22, + foo23: ()=>_foo.foo23, + foo24: ()=>_foo.foo24, + foo25: ()=>_foo.foo25, + foo26: ()=>_foo.foo26, + foo27: ()=>_foo.foo27, + foo28: ()=>_foo.foo28, + foo29: ()=>_foo.foo29, + foo3: ()=>_foo.foo3, + foo30: ()=>_foo.foo30, + foo31: ()=>_foo.foo31, + foo32: ()=>_foo.foo32, + foo33: ()=>_foo.foo33, + foo34: ()=>_foo.foo34, + foo35: ()=>_foo.foo35, + foo36: ()=>_foo.foo36, + foo37: ()=>_foo.foo37, + foo38: ()=>_foo.foo38, + foo39: ()=>_foo.foo39, + foo4: ()=>_foo.foo4, + foo40: ()=>_foo.foo40, + foo41: ()=>_foo.foo41, + foo42: ()=>_foo.foo42, + foo43: ()=>_foo.foo43, + foo44: ()=>_foo.foo44, + foo45: ()=>_foo.foo45, + foo46: ()=>_foo.foo46, + foo47: ()=>_foo.foo47, + foo48: ()=>_foo.foo48, + foo49: ()=>_foo.foo49, + foo5: ()=>_foo.foo5, + foo50: ()=>_foo.foo50, + foo51: ()=>_foo.foo51, + foo52: ()=>_foo.foo52, + foo53: ()=>_foo.foo53, + foo54: ()=>_foo.foo54, + foo55: ()=>_foo.foo55, + foo56: ()=>_foo.foo56, + foo57: ()=>_foo.foo57, + foo58: ()=>_foo.foo58, + foo59: ()=>_foo.foo59, + foo6: ()=>_foo.foo6, + foo60: ()=>_foo.foo60, + foo61: ()=>_foo.foo61, + foo62: ()=>_foo.foo62, + foo63: ()=>_foo.foo63, + foo64: ()=>_foo.foo64, + foo65: ()=>_foo.foo65, + foo66: ()=>_foo.foo66, + foo67: ()=>_foo.foo67, + foo68: ()=>_foo.foo68, + foo69: ()=>_foo.foo69, + foo7: ()=>_foo.foo7, + foo70: ()=>_foo.foo70, + foo71: ()=>_foo.foo71, + foo72: ()=>_foo.foo72, + foo73: ()=>_foo.foo73, + foo74: ()=>_foo.foo74, + foo75: ()=>_foo.foo75, + foo76: ()=>_foo.foo76, + foo77: ()=>_foo.foo77, + foo78: ()=>_foo.foo78, + foo79: ()=>_foo.foo79, + foo8: ()=>_foo.foo8, + foo80: ()=>_foo.foo80, + foo81: ()=>_foo.foo81, + foo82: ()=>_foo.foo82, + foo83: ()=>_foo.foo83, + foo84: ()=>_foo.foo84, + foo85: ()=>_foo.foo85, + foo86: ()=>_foo.foo86, + foo87: ()=>_foo.foo87, + foo88: ()=>_foo.foo88, + foo89: ()=>_foo.foo89, + foo9: ()=>_foo.foo9, + foo90: ()=>_foo.foo90, + foo91: ()=>_foo.foo91, + foo92: ()=>_foo.foo92, + foo93: ()=>_foo.foo93, + foo94: ()=>_foo.foo94, + foo95: ()=>_foo.foo95, + foo96: ()=>_foo.foo96, + foo97: ()=>_foo.foo97, + foo98: ()=>_foo.foo98, + foo99: ()=>_foo.foo99 + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/input.js new file mode 100644 index 00000000000..c87700dd666 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/input.js @@ -0,0 +1,2 @@ +var foo; +export { foo }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.amd.js new file mode 100644 index 00000000000..4e41599ea2d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.cjs new file mode 100644 index 00000000000..dc4f0fc8a3b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true +}); +var foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.umd.js new file mode 100644 index 00000000000..9389b665075 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-1/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/input.js new file mode 100644 index 00000000000..d65163a2cb0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/input.js @@ -0,0 +1,2 @@ +var foo, bar; +export { bar, foo }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.amd.js new file mode 100644 index 00000000000..66f33255428 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + var foo, bar; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.cjs new file mode 100644 index 00000000000..ca8f7de8f4a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + foo: ()=>foo +}); +var foo, bar; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.umd.js new file mode 100644 index 00000000000..4683a3ab21c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-2/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + var foo, bar; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/input.js new file mode 100644 index 00000000000..4d05fa005de --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/input.js @@ -0,0 +1,2 @@ +var foo; +export { foo as bar }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.amd.js new file mode 100644 index 00000000000..a7495229ed1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "bar", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.cjs new file mode 100644 index 00000000000..454b611bd8f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "bar", { + get: ()=>foo, + enumerable: true +}); +var foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.umd.js new file mode 100644 index 00000000000..6eea3216098 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-3/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "bar", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/input.js new file mode 100644 index 00000000000..f52d2a90308 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/input.js @@ -0,0 +1,2 @@ +var foo; +export { foo as default }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.amd.js new file mode 100644 index 00000000000..e1f186c6312 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.cjs new file mode 100644 index 00000000000..ce965f7bd96 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true +}); +var foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.umd.js new file mode 100644 index 00000000000..9228b25dc09 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-4/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/input.js new file mode 100644 index 00000000000..93be378132f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/input.js @@ -0,0 +1,2 @@ +var foo, bar; +export { bar, foo as default }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.amd.js new file mode 100644 index 00000000000..8e4b61e0b93 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + default: ()=>foo + }); + var foo, bar; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.cjs new file mode 100644 index 00000000000..50330a024e6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + default: ()=>foo +}); +var foo, bar; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.umd.js new file mode 100644 index 00000000000..48d4e8d79ac --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/export-named-5/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + default: ()=>foo + }); + var foo, bar; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/input.js new file mode 100644 index 00000000000..0e3bfeb8a53 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/input.js @@ -0,0 +1,9 @@ +export var foo = 1; +export var foo2 = 1, bar = 2; +export var foo3 = function () {}; +export var foo4; +export let foo5 = 2; +export let foo6; +export const foo7 = 3; +export function foo8() {} +export class foo9 {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.amd.js new file mode 100644 index 00000000000..0ddf61d8f98 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.amd.js @@ -0,0 +1,37 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo, + foo2: ()=>foo2, + foo3: ()=>foo3, + foo4: ()=>foo4, + foo5: ()=>foo5, + foo6: ()=>foo6, + foo7: ()=>foo7, + foo8: ()=>foo8, + foo9: ()=>foo9 + }); + var foo = 1; + var foo2 = 1, bar = 2; + var foo3 = function() {}; + var foo4; + let foo5 = 2; + let foo6; + const foo7 = 3; + function foo8() {} + class foo9 { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.cjs new file mode 100644 index 00000000000..a737fa364cf --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.cjs @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + foo: ()=>foo, + foo2: ()=>foo2, + foo3: ()=>foo3, + foo4: ()=>foo4, + foo5: ()=>foo5, + foo6: ()=>foo6, + foo7: ()=>foo7, + foo8: ()=>foo8, + foo9: ()=>foo9 +}); +var foo = 1; +var foo2 = 1, bar = 2; +var foo3 = function() {}; +var foo4; +let foo5 = 2; +let foo6; +const foo7 = 3; +function foo8() {} +class foo9 { +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.umd.js new file mode 100644 index 00000000000..9bb41d04c7d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/exports-variable/output.umd.js @@ -0,0 +1,40 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo, + foo2: ()=>foo2, + foo3: ()=>foo3, + foo4: ()=>foo4, + foo5: ()=>foo5, + foo6: ()=>foo6, + foo7: ()=>foo7, + foo8: ()=>foo8, + foo9: ()=>foo9 + }); + var foo = 1; + var foo2 = 1, bar = 2; + var foo3 = function() {}; + var foo4; + let foo5 = 2; + let foo6; + const foo7 = 3; + function foo8() {} + class foo9 { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/input.js new file mode 100644 index 00000000000..3e38b8aa194 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/input.js @@ -0,0 +1,11 @@ +import { isEven } from "./evens"; + +export function nextOdd(n) { + return isEven(n) ? n + 1 : n + 2; +} + +export var isOdd = (function (isEven) { + return function (n) { + return !isEven(n); + }; +})(isEven); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.amd.js new file mode 100644 index 00000000000..9d078c9bc46 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.amd.js @@ -0,0 +1,28 @@ +define([ + "require", + "exports", + "./evens" +], function(require, exports, _evens) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + isOdd: ()=>isOdd, + nextOdd: ()=>nextOdd + }); + function nextOdd(n) { + return (0, _evens.isEven)(n) ? n + 1 : n + 2; + } + var isOdd = function(isEven) { + return function(n) { + return !isEven(n); + }; + }(_evens.isEven); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.cjs new file mode 100644 index 00000000000..4b982f5ba18 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.cjs @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + isOdd: ()=>isOdd, + nextOdd: ()=>nextOdd +}); +const _evens = require("./evens"); +function nextOdd(n) { + return (0, _evens.isEven)(n) ? n + 1 : n + 2; +} +var isOdd = function(isEven) { + return function(n) { + return !isEven(n); + }; +}(_evens.isEven); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.umd.js new file mode 100644 index 00000000000..e799113cd56 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/hoist-function-exports/output.umd.js @@ -0,0 +1,31 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./evens")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./evens" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.evens); +})(this, function(exports, _evens) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + isOdd: ()=>isOdd, + nextOdd: ()=>nextOdd + }); + function nextOdd(n) { + return (0, _evens.isEven)(n) ? n + 1 : n + 2; + } + var isOdd = function(isEven) { + return function(n) { + return !isEven(n); + }; + }(_evens.isEven); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/input.js new file mode 100644 index 00000000000..ed26d97f258 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/input.js @@ -0,0 +1,5 @@ +import foo from "foo"; +import { default as foo2 } from "foo"; + +foo; +foo2; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.amd.js new file mode 100644 index 00000000000..eed04f25d05 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.amd.js @@ -0,0 +1,13 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo.default; + _foo.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.cjs new file mode 100644 index 00000000000..25510ab90b1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.cjs @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireDefault(require("foo")); +_foo.default; +_foo.default; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.umd.js new file mode 100644 index 00000000000..cc347765267 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-default/output.umd.js @@ -0,0 +1,16 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo.default; + _foo.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/input.js new file mode 100644 index 00000000000..e55c0775003 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/input.js @@ -0,0 +1 @@ +import * as foo from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.amd.js new file mode 100644 index 00000000000..3cb7c32887f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.cjs new file mode 100644 index 00000000000..1d1436427a5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireWildcard(require("foo")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.umd.js new file mode 100644 index 00000000000..af404b242ae --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-glob/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/input.js new file mode 100644 index 00000000000..307db99257e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/input.js @@ -0,0 +1,4 @@ +import foo, { baz as xyz } from "foo"; + +foo; +xyz; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.amd.js new file mode 100644 index 00000000000..57eea86ac63 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.amd.js @@ -0,0 +1,13 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + _foo.default; + _foo.baz; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.cjs new file mode 100644 index 00000000000..d7bc1c177b7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.cjs @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireWildcard(require("foo")); +_foo.default; +_foo.baz; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.umd.js new file mode 100644 index 00000000000..590b1013d65 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-mixing/output.umd.js @@ -0,0 +1,16 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + _foo.default; + _foo.baz; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/input.js new file mode 100644 index 00000000000..01900566f69 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/input.js @@ -0,0 +1,11 @@ +import { bar } from "foo"; +import { bar2, baz } from "foo"; +import { bar as baz2 } from "foo"; +import { bar as baz3, xyz } from "foo"; + +bar; +bar2; +baz; +baz2; +baz3; +xyz; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.amd.js new file mode 100644 index 00000000000..46d4272c363 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo.bar; + _foo.bar2; + _foo.baz; + _foo.bar; + _foo.bar; + _foo.xyz; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.cjs new file mode 100644 index 00000000000..fe7cf14ec8b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = require("foo"); +_foo.bar; +_foo.bar2; +_foo.baz; +_foo.bar; +_foo.bar; +_foo.xyz; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.umd.js new file mode 100644 index 00000000000..2c43045680c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-named/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo.bar; + _foo.bar2; + _foo.baz; + _foo.bar; + _foo.bar; + _foo.xyz; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/input.js new file mode 100644 index 00000000000..d89ed3d8782 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/input.js @@ -0,0 +1,4 @@ +import "./foo"; +import bar from "./bar"; +import "./derp"; +import { qux } from "./qux"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.amd.js new file mode 100644 index 00000000000..262f3567821 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "./foo", + "./bar", + "./derp", + "./qux" +], function(require, exports, _foo, _bar, _derp, _qux) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _bar = _interopRequireDefault(_bar); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.cjs new file mode 100644 index 00000000000..5e8bcfe5756 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.cjs @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +require("./foo"); +const _bar = _interopRequireDefault(require("./bar")); +require("./derp"); +const _qux = require("./qux"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.umd.js new file mode 100644 index 00000000000..d9f569c192e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports-ordering/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./foo"), require("./bar"), require("./derp"), require("./qux")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./foo", + "./bar", + "./derp", + "./qux" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo, global.bar, global.derp, global.qux); +})(this, function(exports, _foo, _bar, _derp, _qux) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _bar = _interopRequireDefault(_bar); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/input.js new file mode 100644 index 00000000000..222b6885ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/input.js @@ -0,0 +1,3 @@ +import "foo"; +import "foo-bar"; +import "./directory/foo-bar"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.amd.js new file mode 100644 index 00000000000..807a0078943 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.amd.js @@ -0,0 +1,12 @@ +define([ + "require", + "exports", + "foo", + "foo-bar", + "./directory/foo-bar" +], function(require, exports, _foo, _fooBar, _fooBar1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.cjs new file mode 100644 index 00000000000..54dbaf082e7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.cjs @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +require("foo"); +require("foo-bar"); +require("./directory/foo-bar"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.umd.js new file mode 100644 index 00000000000..7ab5cfbdfd8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/imports/output.umd.js @@ -0,0 +1,15 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo", + "foo-bar", + "./directory/foo-bar" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo, global.fooBar, global.fooBar); +})(this, function(exports, _foo, _fooBar, _fooBar1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/input.js new file mode 100644 index 00000000000..afb183fef5d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/input.js @@ -0,0 +1,15 @@ +import "foo"; +import "foo-bar"; +import "./directory/foo-bar"; +import foo from "foo2"; +import * as foo2 from "foo3"; +import { bar } from "foo4"; +import { foo as bar2 } from "foo5"; + +var test; +export { test }; +export var test2 = 5; + +bar; +bar2; +foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.amd.js new file mode 100644 index 00000000000..f3d8a94e391 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.amd.js @@ -0,0 +1,33 @@ +define([ + "require", + "exports", + "foo", + "foo-bar", + "./directory/foo-bar", + "foo2", + "foo3", + "foo4", + "foo5" +], function(require, exports, _foo, _fooBar, _fooBar1, _foo2, _foo3, _foo4, _foo5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + test: ()=>test, + test2: ()=>test2 + }); + _foo2 = _interopRequireDefault(_foo2); + _foo3 = _interopRequireWildcard(_foo3); + var test; + var test2 = 5; + _foo4.bar; + _foo5.foo; + _foo2.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.cjs new file mode 100644 index 00000000000..cb5187d5fc8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.cjs @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + test: ()=>test, + test2: ()=>test2 +}); +require("foo"); +require("foo-bar"); +require("./directory/foo-bar"); +const _foo2 = _interopRequireDefault(require("foo2")); +const _foo3 = _interopRequireWildcard(require("foo3")); +const _foo4 = require("foo4"); +const _foo5 = require("foo5"); +var test; +var test2 = 5; +_foo4.bar; +_foo5.foo; +_foo2.default; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.umd.js new file mode 100644 index 00000000000..c9e34ac40f3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/overview/output.umd.js @@ -0,0 +1,36 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar"), require("foo2"), require("foo3"), require("foo4"), require("foo5")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo", + "foo-bar", + "./directory/foo-bar", + "foo2", + "foo3", + "foo4", + "foo5" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo, global.fooBar, global.fooBar, global.foo2, global.foo3, global.foo4, global.foo5); +})(this, function(exports, _foo, _fooBar, _fooBar1, _foo2, _foo3, _foo4, _foo5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + test: ()=>test, + test2: ()=>test2 + }); + _foo2 = _interopRequireDefault(_foo2); + _foo3 = _interopRequireWildcard(_foo3); + var test; + var test2 = 5; + _foo4.bar; + _foo5.foo; + _foo2.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/input.js new file mode 100644 index 00000000000..5031e9d4b75 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/input.js @@ -0,0 +1,21 @@ +export var test = 2; +test = 5; +test++; + +(function () { + var test = 2; + test = 3; + test++; +})(); + +var a = 2; +export { a }; +a = 3; + +var b = 2; +export { b as c }; +b = 3; + +var d = 3; +export { d as e, d as f }; +d = 4; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.amd.js new file mode 100644 index 00000000000..d31e145f078 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.amd.js @@ -0,0 +1,36 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + a: ()=>a, + c: ()=>b, + e: ()=>d, + f: ()=>d, + test: ()=>test + }); + var test = 2; + test = 5; + test++; + (function() { + var test = 2; + test = 3; + test++; + })(); + var a = 2; + a = 3; + var b = 2; + b = 3; + var d = 3; + d = 4; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.cjs new file mode 100644 index 00000000000..fc85e8d69f8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.cjs @@ -0,0 +1,31 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + a: ()=>a, + c: ()=>b, + e: ()=>d, + f: ()=>d, + test: ()=>test +}); +var test = 2; +test = 5; +test++; +(function() { + var test = 2; + test = 3; + test++; +})(); +var a = 2; +a = 3; +var b = 2; +b = 3; +var d = 3; +d = 4; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.umd.js new file mode 100644 index 00000000000..0704bfa857f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/interop/remap/output.umd.js @@ -0,0 +1,39 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + a: ()=>a, + c: ()=>b, + e: ()=>d, + f: ()=>d, + test: ()=>test + }); + var test = 2; + test = 5; + test++; + (function() { + var test = 2; + test = 3; + test++; + })(); + var a = 2; + a = 3; + var b = 2; + b = 3; + var d = 3; + d = 4; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/input.js new file mode 100644 index 00000000000..1f5fc83af2d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/input.js @@ -0,0 +1,3 @@ +async function foo() { + await import("foo"); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.amd.js new file mode 100644 index 00000000000..1fd73b7ba08 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.amd.js @@ -0,0 +1,10 @@ +define([ + "require" +], function(require) { + "use strict"; + async function foo() { + await new Promise((resolve, reject)=>require([ + "foo" + ], (m)=>resolve(_interopRequireWildcard(m)), reject)); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.cjs new file mode 100644 index 00000000000..4e35d1733e5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.cjs @@ -0,0 +1,4 @@ +"use strict"; +async function foo() { + await Promise.resolve("foo").then((p)=>_interopRequireWildcard(require(p))); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.umd.js new file mode 100644 index 00000000000..83cf8132772 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1018/1/output.umd.js @@ -0,0 +1,10 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + async function foo() { + await import("foo"); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/input.js new file mode 100644 index 00000000000..29ba93785fe --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/input.js @@ -0,0 +1,2 @@ +export * from "./http"; +export { Scope } from "./interfaces"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.amd.js new file mode 100644 index 00000000000..2d042d88556 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports", + "./http", + "./interfaces" +], function(require, exports, _http, _interfaces) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "Scope", { + get: ()=>_interfaces.Scope, + enumerable: true + }); + _exportStar(_http, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.cjs new file mode 100644 index 00000000000..0c7877558a8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "Scope", { + get: ()=>_interfaces.Scope, + enumerable: true +}); +_exportStar(require("./http"), exports); +const _interfaces = require("./interfaces"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.umd.js new file mode 100644 index 00000000000..12243b564c6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/1/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./http"), require("./interfaces")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./http", + "./interfaces" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.http, global.interfaces); +})(this, function(exports, _http, _interfaces) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "Scope", { + get: ()=>_interfaces.Scope, + enumerable: true + }); + _exportStar(_http, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/input.js new file mode 100644 index 00000000000..60c41a0f1d7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/input.js @@ -0,0 +1,5 @@ +import "reflect-metadata"; + +export * from "./http"; +export { id } from "./interfaces"; +export * from "./pipes"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.amd.js new file mode 100644 index 00000000000..81569a72f18 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.amd.js @@ -0,0 +1,19 @@ +define([ + "require", + "exports", + "reflect-metadata", + "./http", + "./interfaces", + "./pipes" +], function(require, exports, _reflectMetadata, _http, _interfaces, _pipes) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "id", { + get: ()=>_interfaces.id, + enumerable: true + }); + _exportStar(_http, exports); + _exportStar(_pipes, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.cjs new file mode 100644 index 00000000000..eefb7752ad4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.cjs @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "id", { + get: ()=>_interfaces.id, + enumerable: true +}); +require("reflect-metadata"); +_exportStar(require("./http"), exports); +const _interfaces = require("./interfaces"); +_exportStar(require("./pipes"), exports); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.umd.js new file mode 100644 index 00000000000..2c27f49ce60 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1043/2/output.umd.js @@ -0,0 +1,22 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("reflect-metadata"), require("./http"), require("./interfaces"), require("./pipes")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "reflect-metadata", + "./http", + "./interfaces", + "./pipes" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.reflectMetadata, global.http, global.interfaces, global.pipes); +})(this, function(exports, _reflectMetadata, _http, _interfaces, _pipes) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "id", { + get: ()=>_interfaces.id, + enumerable: true + }); + _exportStar(_http, exports); + _exportStar(_pipes, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-1201/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-1201/1/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.amd.js new file mode 100644 index 00000000000..60e7811917a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.amd.js @@ -0,0 +1,7 @@ +define([ + "require", + "module" +], function(require, module) { + "use strict"; + console.log(new URL(module.uri, document.baseURI).href); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-1201/1/output.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.cjs similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-1201/1/output.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.cjs diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.umd.js new file mode 100644 index 00000000000..1f5090b5094 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1201/1/output.umd.js @@ -0,0 +1,8 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + console.log(import.meta.url); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/input.js new file mode 100644 index 00000000000..0b18064d7fa --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/input.js @@ -0,0 +1,13 @@ +import foo from "foo"; + +class OK { + constructor() { + console.log(foo); + } +} + +export default class NotOK { + constructor() { + console.log(foo); + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.amd.js new file mode 100644 index 00000000000..76003e3f5a9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.amd.js @@ -0,0 +1,25 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>NotOK, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); + class OK { + constructor(){ + console.log(_foo.default); + } + } + class NotOK { + constructor(){ + console.log(_foo.default); + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.cjs new file mode 100644 index 00000000000..c93aa4084d4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.cjs @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>NotOK, + enumerable: true +}); +const _foo = _interopRequireDefault(require("foo")); +class OK { + constructor(){ + console.log(_foo.default); + } +} +class NotOK { + constructor(){ + console.log(_foo.default); + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.umd.js new file mode 100644 index 00000000000..57f69112237 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1213/output.umd.js @@ -0,0 +1,28 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>NotOK, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); + class OK { + constructor(){ + console.log(_foo.default); + } + } + class NotOK { + constructor(){ + console.log(_foo.default); + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/input.js new file mode 100644 index 00000000000..7892334d0ee --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/input.js @@ -0,0 +1,9 @@ +"use strict"; +import { arrayUtilities } from "necessary"; + +const { second } = arrayUtilities; + +const elements = [1, 2, 3], + secondElement = second(elements); + +console.log(secondElement); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.amd.js new file mode 100644 index 00000000000..3e9209a20f3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports", + "necessary" +], function(require, exports, _necessary) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const { second } = _necessary.arrayUtilities; + const elements = [ + 1, + 2, + 3 + ], secondElement = second(elements); + console.log(secondElement); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.cjs new file mode 100644 index 00000000000..155bdd5f0a9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.cjs @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _necessary = require("necessary"); +const { second } = _necessary.arrayUtilities; +const elements = [ + 1, + 2, + 3 +], secondElement = second(elements); +console.log(secondElement); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.umd.js new file mode 100644 index 00000000000..0ed8330be99 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1423/1/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("necessary")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "necessary" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.necessary); +})(this, function(exports, _necessary) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const { second } = _necessary.arrayUtilities; + const elements = [ + 1, + 2, + 3 + ], secondElement = second(elements); + console.log(secondElement); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/input.js new file mode 100644 index 00000000000..7457ac63cf9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/input.js @@ -0,0 +1 @@ +const { default: ora } = await import("ora"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/module.json new file mode 100644 index 00000000000..e1bd594ec66 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/module.json @@ -0,0 +1,6 @@ +{ + "noInterop": false, + "strict": true, + "strictMode": true, + "lazy": false +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.amd.js new file mode 100644 index 00000000000..eaef05e7180 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.amd.js @@ -0,0 +1,8 @@ +define([ + "require" +], function(require) { + "use strict"; + const { default: ora } = await new Promise((resolve, reject)=>require([ + "ora" + ], (m)=>resolve(_interopRequireWildcard(m)), reject)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.cjs new file mode 100644 index 00000000000..b56fec40cd0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.cjs @@ -0,0 +1,2 @@ +"use strict"; +const { default: ora } = await Promise.resolve("ora").then((p)=>_interopRequireWildcard(require(p))); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.umd.js new file mode 100644 index 00000000000..82e833db3bf --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/1/output.umd.js @@ -0,0 +1,8 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + const { default: ora } = await import("ora"); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/input.js new file mode 100644 index 00000000000..5c1385d9a97 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/input.js @@ -0,0 +1 @@ +import * as ora from "ora"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/module.json new file mode 100644 index 00000000000..e1bd594ec66 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/module.json @@ -0,0 +1,6 @@ +{ + "noInterop": false, + "strict": true, + "strictMode": true, + "lazy": false +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.amd.js new file mode 100644 index 00000000000..354b148d709 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "ora" +], function(require, exports, _ora) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _ora = _interopRequireWildcard(_ora); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.cjs new file mode 100644 index 00000000000..c0b0b9ae4e5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _ora = _interopRequireWildcard(require("ora")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.umd.js new file mode 100644 index 00000000000..198d66cd44f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1480/2/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("ora")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "ora" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.ora); +})(this, function(exports, _ora) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _ora = _interopRequireWildcard(_ora); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/input.js new file mode 100644 index 00000000000..f63f18f210e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/input.js @@ -0,0 +1,3 @@ +export default function get(key) { + console.log(key); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.amd.js new file mode 100644 index 00000000000..94d1bd41598 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>get, + enumerable: true + }); + function get(key) { + console.log(key); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.cjs new file mode 100644 index 00000000000..65b333b83c0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>get, + enumerable: true +}); +function get(key) { + console.log(key); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.umd.js new file mode 100644 index 00000000000..4a404cf09a0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/1/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>get, + enumerable: true + }); + function get(key) { + console.log(key); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/input.js new file mode 100644 index 00000000000..ed7b9af293c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/input.js @@ -0,0 +1,5 @@ +export function get(key) { + console.log(key); +} + +export default a; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.amd.js new file mode 100644 index 00000000000..63b843a4f13 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.amd.js @@ -0,0 +1,23 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + default: ()=>_default, + get: ()=>get + }); + function get(key) { + console.log(key); + } + var _default = a; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.cjs new file mode 100644 index 00000000000..5a6811f70d4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.cjs @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + default: ()=>_default, + get: ()=>get +}); +function get(key) { + console.log(key); +} +var _default = a; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.umd.js new file mode 100644 index 00000000000..bed40eb30a8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1568/2/output.umd.js @@ -0,0 +1,26 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + default: ()=>_default, + get: ()=>get + }); + function get(key) { + console.log(key); + } + var _default = a; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/input.js new file mode 100644 index 00000000000..a0aaec54f80 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/input.js @@ -0,0 +1,5 @@ +import { Component, default as React } from "react"; + +class X extends Component {} + +React.render(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.amd.js new file mode 100644 index 00000000000..4ddf051242f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "react" +], function(require, exports, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _react = _interopRequireWildcard(_react); + class X extends _react.Component { + } + _react.default.render(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.cjs new file mode 100644 index 00000000000..fbb65a3bc74 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.cjs @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _react = _interopRequireWildcard(require("react")); +class X extends _react.Component { +} +_react.default.render(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.umd.js new file mode 100644 index 00000000000..726c6785d4b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1588/1/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("react")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "react" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.react); +})(this, function(exports, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _react = _interopRequireWildcard(_react); + class X extends _react.Component { + } + _react.default.render(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/input.js new file mode 100644 index 00000000000..68e21918027 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/input.js @@ -0,0 +1,4 @@ +(async () => { + const example = await import("./example"); + console.log(example.foo); +})(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.amd.js new file mode 100644 index 00000000000..6f4e91383e0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require" +], function(require) { + "use strict"; + (async ()=>{ + const example = await new Promise((resolve, reject)=>require([ + "./example" + ], (m)=>resolve(_interopRequireWildcard(m)), reject)); + console.log(example.foo); + })(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.cjs new file mode 100644 index 00000000000..ee6a569e6a7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +(async ()=>{ + const example = await Promise.resolve("./example").then((p)=>_interopRequireWildcard(require(p))); + console.log(example.foo); +})(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.umd.js new file mode 100644 index 00000000000..f601a26d484 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1614/1/output.umd.js @@ -0,0 +1,11 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + (async ()=>{ + const example = await import("./example"); + console.log(example.foo); + })(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/input.js new file mode 100644 index 00000000000..933556081a9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/input.js @@ -0,0 +1,4 @@ +import "testlibrary"; +import { aFunc } from "testlibrary"; + +console.log("aFunc: ", aFunc(1, 2)); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.amd.js new file mode 100644 index 00000000000..a966bd28a8c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "testlibrary" +], function(require, exports, _testlibrary) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + console.log("aFunc: ", (0, _testlibrary.aFunc)(1, 2)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.cjs new file mode 100644 index 00000000000..96d1f439c73 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _testlibrary = require("testlibrary"); +console.log("aFunc: ", (0, _testlibrary.aFunc)(1, 2)); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.umd.js new file mode 100644 index 00000000000..5524bd824c9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1757/1/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("testlibrary")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "testlibrary" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.testlibrary); +})(this, function(exports, _testlibrary) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + console.log("aFunc: ", (0, _testlibrary.aFunc)(1, 2)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/input.js new file mode 100644 index 00000000000..612687bece7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/input.js @@ -0,0 +1,3 @@ +"use strict"; + +let x = 4; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.amd.js new file mode 100644 index 00000000000..4f684e721ed --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.amd.js @@ -0,0 +1,6 @@ +define([ + "require" +], function(require) { + "use strict"; + let x = 4; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.cjs new file mode 100644 index 00000000000..cceff819cfc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.cjs @@ -0,0 +1,2 @@ +"use strict"; +let x = 4; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.umd.js new file mode 100644 index 00000000000..5154283f329 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-176/output.umd.js @@ -0,0 +1,8 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + let x = 4; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/input.js new file mode 100644 index 00000000000..2d17766d20d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/input.js @@ -0,0 +1,3 @@ +export const BIZ = "biz"; +export * from "./File1"; +export * from "./File2"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.amd.js new file mode 100644 index 00000000000..c4b17f756a5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.amd.js @@ -0,0 +1,18 @@ +define([ + "require", + "exports", + "./File1", + "./File2" +], function(require, exports, _file1, _file2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "BIZ", { + get: ()=>BIZ, + enumerable: true + }); + _exportStar(_file1, exports); + _exportStar(_file2, exports); + const BIZ = "biz"; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.cjs new file mode 100644 index 00000000000..2fc54819e7e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "BIZ", { + get: ()=>BIZ, + enumerable: true +}); +_exportStar(require("./File1"), exports); +_exportStar(require("./File2"), exports); +const BIZ = "biz"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.umd.js new file mode 100644 index 00000000000..a8ff55ea7e2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1780/1/output.umd.js @@ -0,0 +1,21 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./File1"), require("./File2")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./File1", + "./File2" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.file1, global.file2); +})(this, function(exports, _file1, _file2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "BIZ", { + get: ()=>BIZ, + enumerable: true + }); + _exportStar(_file1, exports); + _exportStar(_file2, exports); + const BIZ = "biz"; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/input.js new file mode 100644 index 00000000000..69437cb6f71 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/input.js @@ -0,0 +1,2 @@ +import Foo from "foo"; +export { Foo } from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.amd.js new file mode 100644 index 00000000000..33c80626086 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "Foo", { + get: ()=>_foo.Foo, + enumerable: true + }); + _foo = _interopRequireWildcard(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.cjs new file mode 100644 index 00000000000..f49524d884b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "Foo", { + get: ()=>_foo.Foo, + enumerable: true +}); +const _foo = _interopRequireWildcard(require("foo")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.umd.js new file mode 100644 index 00000000000..a4ff2be5db2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1786/1/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "Foo", { + get: ()=>_foo.Foo, + enumerable: true + }); + _foo = _interopRequireWildcard(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/input.js new file mode 100644 index 00000000000..7d389678605 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/input.js @@ -0,0 +1,3 @@ +import bar from "./bar/foo"; +import baz from "./baz/foo"; +const a = [baz, bar]; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.amd.js new file mode 100644 index 00000000000..5de72088eae --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports", + "./bar/foo", + "./baz/foo" +], function(require, exports, _foo, _foo1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo1 = _interopRequireDefault(_foo1); + const a = [ + _foo1.default, + _foo.default + ]; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.cjs new file mode 100644 index 00000000000..7df247199e1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireDefault(require("./bar/foo")); +const _foo1 = _interopRequireDefault(require("./baz/foo")); +const a = [ + _foo1.default, + _foo.default +]; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.umd.js new file mode 100644 index 00000000000..d49b2ef8398 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1787/1/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./bar/foo"), require("./baz/foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./bar/foo", + "./baz/foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo, global.foo); +})(this, function(exports, _foo, _foo1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo1 = _interopRequireDefault(_foo1); + const a = [ + _foo1.default, + _foo.default + ]; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/input.js new file mode 100644 index 00000000000..cba22570c2b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/input.js @@ -0,0 +1,3 @@ +export default function Foo() { + return 500; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.amd.js new file mode 100644 index 00000000000..7005e9d5400 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true + }); + function Foo() { + return 500; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.cjs new file mode 100644 index 00000000000..dc7f890ceab --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true +}); +function Foo() { + return 500; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.umd.js new file mode 100644 index 00000000000..dbebee1d7ab --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/1/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true + }); + function Foo() { + return 500; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/input.js new file mode 100644 index 00000000000..03f90b2d583 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/input.js @@ -0,0 +1,3 @@ +export default function () { + return 500; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.amd.js new file mode 100644 index 00000000000..f145b79cd9c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + function _default() { + return 500; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.cjs new file mode 100644 index 00000000000..c8baaa327f7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +function _default() { + return 500; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.umd.js new file mode 100644 index 00000000000..dd019daf9e3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-1799/2/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + function _default() { + return 500; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/1/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.amd.js new file mode 100644 index 00000000000..6b32c35fafa --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports", + "./customRender", + "@testing-library/react" +], function(require, exports, _customRender, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "render", { + get: ()=>_customRender.customRender, + enumerable: true + }); + _exportStar(_react, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.cjs new file mode 100644 index 00000000000..40dde8681f5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "render", { + get: ()=>_customRender.customRender, + enumerable: true +}); +const _customRender = require("./customRender"); +_exportStar(require("@testing-library/react"), exports); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.umd.js new file mode 100644 index 00000000000..c70e48cedec --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/1/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./customRender"), require("@testing-library/react")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./customRender", + "@testing-library/react" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.customRender, global.react); +})(this, function(exports, _customRender, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "render", { + get: ()=>_customRender.customRender, + enumerable: true + }); + _exportStar(_react, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/2/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.amd.js new file mode 100644 index 00000000000..6b32c35fafa --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports", + "./customRender", + "@testing-library/react" +], function(require, exports, _customRender, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "render", { + get: ()=>_customRender.customRender, + enumerable: true + }); + _exportStar(_react, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.cjs new file mode 100644 index 00000000000..40dde8681f5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "render", { + get: ()=>_customRender.customRender, + enumerable: true +}); +const _customRender = require("./customRender"); +_exportStar(require("@testing-library/react"), exports); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.umd.js new file mode 100644 index 00000000000..c70e48cedec --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2101/2/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./customRender"), require("@testing-library/react")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./customRender", + "@testing-library/react" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.customRender, global.react); +})(this, function(exports, _customRender, _react) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "render", { + get: ()=>_customRender.customRender, + enumerable: true + }); + _exportStar(_react, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/1/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.amd.js new file mode 100644 index 00000000000..573bffca9b0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports", + "./bar" +], function(require, exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const makeX = ()=>{ + const _bar1 = ()=>(0, _bar.bar)(); + return { + _bar: _bar1 + }; + }; + makeX()._bar(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.cjs new file mode 100644 index 00000000000..2cbe0806ed3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.cjs @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _bar = require("./bar"); +const makeX = ()=>{ + const _bar1 = ()=>(0, _bar.bar)(); + return { + _bar: _bar1 + }; +}; +makeX()._bar(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.umd.js new file mode 100644 index 00000000000..7f6a419113d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/1/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./bar")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./bar" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.bar); +})(this, function(exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const makeX = ()=>{ + const _bar1 = ()=>(0, _bar.bar)(); + return { + _bar: _bar1 + }; + }; + makeX()._bar(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/2/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.amd.js new file mode 100644 index 00000000000..1b48ed58626 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports", + "./bar" +], function(require, exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const makeX = ()=>{ + const _bar1 = ()=>(0, _bar.bar)(); + const alfa = ()=>_bar1(); + return { + alfa + }; + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.cjs new file mode 100644 index 00000000000..b3cecb16f73 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.cjs @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _bar = require("./bar"); +const makeX = ()=>{ + const _bar1 = ()=>(0, _bar.bar)(); + const alfa = ()=>_bar1(); + return { + alfa + }; +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.umd.js new file mode 100644 index 00000000000..3abe23744b2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2211/2/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./bar")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./bar" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.bar); +})(this, function(exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const makeX = ()=>{ + const _bar1 = ()=>(0, _bar.bar)(); + const alfa = ()=>_bar1(); + return { + alfa + }; + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2297/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2297/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.amd.js new file mode 100644 index 00000000000..7d94cfe403d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "./Bar" +], function(require, exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const makeX = (props)=>{ + const _bar1 = props.bar; + const { list } = _bar1; + return list.map(()=>_bar.bar); + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.cjs new file mode 100644 index 00000000000..24d33abdebc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _bar = require("./Bar"); +const makeX = (props)=>{ + const _bar1 = props.bar; + const { list } = _bar1; + return list.map(()=>_bar.bar); +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.umd.js new file mode 100644 index 00000000000..f28e518e210 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2297/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./Bar")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./Bar" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.bar); +})(this, function(exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const makeX = (props)=>{ + const _bar1 = props.bar; + const { list } = _bar1; + return list.map(()=>_bar.bar); + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/input.js new file mode 100644 index 00000000000..431934de976 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/input.js @@ -0,0 +1,9 @@ +class LoggingButton extends React.Component { + handleClick = () => { + console.log("this is:", this); + }; + m() { + this; + } + static a = () => this; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.amd.js new file mode 100644 index 00000000000..7fdecda5bc5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require" +], function(require) { + "use strict"; + class LoggingButton extends React.Component { + handleClick = ()=>{ + console.log("this is:", this); + }; + m() { + this; + } + static a = ()=>this; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.cjs new file mode 100644 index 00000000000..694a1b9e3c6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +class LoggingButton extends React.Component { + handleClick = ()=>{ + console.log("this is:", this); + }; + m() { + this; + } + static a = ()=>this; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.umd.js new file mode 100644 index 00000000000..7c45ba9e638 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/1/output.umd.js @@ -0,0 +1,16 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + class LoggingButton extends React.Component { + handleClick = ()=>{ + console.log("this is:", this); + }; + m() { + this; + } + static a = ()=>this; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/input.js new file mode 100644 index 00000000000..07e35102062 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/input.js @@ -0,0 +1,16 @@ +class A { + // this is weird I know + [(() => this)()] = 123; +} +class B { + // this is weird too I know + [(() => this)()]() {} +} +class C { + static [(() => this)()] = 1; +} +class D { + static d = class { + [(() => this)()]() {} + }; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.amd.js new file mode 100644 index 00000000000..1ed0ca8af6d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.amd.js @@ -0,0 +1,21 @@ +define([ + "require" +], function(require) { + "use strict"; + class A { + // this is weird I know + [(()=>void 0)()] = 123; + } + class B { + // this is weird too I know + [(()=>void 0)()]() {} + } + class C { + static [(()=>void 0)()] = 1; + } + class D { + static d = class { + [(()=>this)()]() {} + }; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.cjs new file mode 100644 index 00000000000..9211b852044 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.cjs @@ -0,0 +1,17 @@ +"use strict"; +class A { + // this is weird I know + [(()=>void 0)()] = 123; +} +class B { + // this is weird too I know + [(()=>void 0)()]() {} +} +class C { + static [(()=>void 0)()] = 1; +} +class D { + static d = class { + [(()=>this)()]() {} + }; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.umd.js new file mode 100644 index 00000000000..fb1d96f41e9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/2/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + class A { + // this is weird I know + [(()=>void 0)()] = 123; + } + class B { + // this is weird too I know + [(()=>void 0)()]() {} + } + class C { + static [(()=>void 0)()] = 1; + } + class D { + static d = class { + [(()=>this)()]() {} + }; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/input.js new file mode 100644 index 00000000000..eaec75d86b1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/input.js @@ -0,0 +1,5 @@ +class A { + static { + this.a = 123; + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.amd.js new file mode 100644 index 00000000000..143a02364ed --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.amd.js @@ -0,0 +1,10 @@ +define([ + "require" +], function(require) { + "use strict"; + class A { + static{ + this.a = 123; + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.cjs new file mode 100644 index 00000000000..359a0232bb2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +class A { + static{ + this.a = 123; + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.umd.js new file mode 100644 index 00000000000..10a96f22174 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2344/3/output.umd.js @@ -0,0 +1,12 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + class A { + static{ + this.a = 123; + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/input.js new file mode 100644 index 00000000000..2afe0f8d923 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/input.js @@ -0,0 +1,2 @@ +import { Foo as Bar } from "something"; +export const fn = ({ a = new Bar() }) => a; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.amd.js new file mode 100644 index 00000000000..91c692fb261 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "something" +], function(require, exports, _something) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "fn", { + get: ()=>fn, + enumerable: true + }); + const fn = ({ a =new _something.Foo() })=>a; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.cjs new file mode 100644 index 00000000000..8e67b933b55 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "fn", { + get: ()=>fn, + enumerable: true +}); +const _something = require("something"); +const fn = ({ a =new _something.Foo() })=>a; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.umd.js new file mode 100644 index 00000000000..345c943b6a5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-235/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("something")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "something" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.something); +})(this, function(exports, _something) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "fn", { + get: ()=>fn, + enumerable: true + }); + const fn = ({ a =new _something.Foo() })=>a; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/input/index.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/input/index.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.amd.js new file mode 100644 index 00000000000..14da3d20f10 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "./Z" +], function(require, exports, _z) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "X", { + get: ()=>_z.default, + enumerable: true + }); + _z = _interopRequireDefault(_z); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.cjs new file mode 100644 index 00000000000..8b63ff4cde3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "X", { + get: ()=>_z.default, + enumerable: true +}); +const _z = _interopRequireDefault(require("./Z")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.umd.js new file mode 100644 index 00000000000..2f65cbb6bf5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case1/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./Z")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./Z" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.z); +})(this, function(exports, _z) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "X", { + get: ()=>_z.default, + enumerable: true + }); + _z = _interopRequireDefault(_z); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/input/index.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/input/index.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.amd.js new file mode 100644 index 00000000000..7e068fce153 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "./Z" +], function(require, exports, _z) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "X", { + get: ()=>_z.default, + enumerable: true + }); + _z = _interopRequireDefault(_exportStar(_z, exports)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.cjs new file mode 100644 index 00000000000..08205d4bc1e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "X", { + get: ()=>_z.default, + enumerable: true +}); +const _z = _interopRequireDefault(_exportStar(require("./Z"), exports)); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.umd.js new file mode 100644 index 00000000000..b15986f015d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case2/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./Z")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./Z" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.z); +})(this, function(exports, _z) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "X", { + get: ()=>_z.default, + enumerable: true + }); + _z = _interopRequireDefault(_exportStar(_z, exports)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/input.js new file mode 100644 index 00000000000..e543fd7773a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/input.js @@ -0,0 +1,2 @@ +export { default as X, X2, Y } from "./Z"; +export * from "./Z"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.amd.js new file mode 100644 index 00000000000..4748c984992 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.amd.js @@ -0,0 +1,22 @@ +define([ + "require", + "exports", + "./Z" +], function(require, exports, _z) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + X: ()=>_z.default, + X2: ()=>_z.X2, + Y: ()=>_z.Y + }); + _z = _interopRequireWildcard(_exportStar(_z, exports)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.cjs new file mode 100644 index 00000000000..1b7179c4d82 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.cjs @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + X: ()=>_z.default, + X2: ()=>_z.X2, + Y: ()=>_z.Y +}); +const _z = _interopRequireWildcard(_exportStar(require("./Z"), exports)); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.umd.js new file mode 100644 index 00000000000..a482a33ea5c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2548/case3/output.umd.js @@ -0,0 +1,25 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./Z")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./Z" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.z); +})(this, function(exports, _z) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + X: ()=>_z.default, + X2: ()=>_z.X2, + Y: ()=>_z.Y + }); + _z = _interopRequireWildcard(_exportStar(_z, exports)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2549/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2549/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.amd.js new file mode 100644 index 00000000000..df7057a4322 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.amd.js @@ -0,0 +1,58 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + addOne: ()=>addOne, + errors: ()=>errors, + noassign: ()=>noassign, + someFunc: ()=>someFunc, + test: ()=>test, + warn: ()=>warn + }); + function log() { + console.log("unexported"); + } + function noassign() { + console.log("stub"); + } + function warn() { + throw new Error("this should not be called"); + } + const errors = { + a: 1 + }; + const addOne = (x)=>`${x + 1}`; + const someFunc = (x)=>`The answer is : ${addOne(x)}`; + const test = {}; + Object.defineProperty(test, "log", { + get: function get() { + return log; + }, + set: function set(v) { + log = v; + } + }); + Object.defineProperty(test, "warn", { + get: ()=>warn, + set: (v)=>{ + warn = v; + } + }); + Object.defineProperty(test, "errors", { + get: ()=>errors, + set: (v)=>{ + errors = v; + } + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2549/output.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.cjs similarity index 54% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2549/output.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.cjs index 476fc0cc6f5..412c46c8f9a 100644 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2549/output.js +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.cjs @@ -2,9 +2,20 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.noassign = noassign; -exports.warn = warn; -exports.test = exports.someFunc = exports.addOne = exports.errors = void 0; +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + addOne: ()=>addOne, + errors: ()=>errors, + noassign: ()=>noassign, + someFunc: ()=>someFunc, + test: ()=>test, + warn: ()=>warn +}); function log() { console.log("unexported"); } @@ -17,15 +28,9 @@ function warn() { const errors = { a: 1 }; -exports.errors = errors; -const addOne = (x)=>`${x + 1}` -; -exports.addOne = addOne; -const someFunc = (x)=>`The answer is : ${addOne(x)}` -; -exports.someFunc = someFunc; +const addOne = (x)=>`${x + 1}`; +const someFunc = (x)=>`The answer is : ${addOne(x)}`; const test = {}; -exports.test = test; Object.defineProperty(test, "log", { get: function get() { return log; @@ -35,16 +40,14 @@ Object.defineProperty(test, "log", { } }); Object.defineProperty(test, "warn", { - get: ()=>warn - , + get: ()=>warn, set: (v)=>{ - exports.warn = warn = v; + warn = v; } }); Object.defineProperty(test, "errors", { - get: ()=>errors - , + get: ()=>errors, set: (v)=>{ - exports.errors = errors = v; + errors = v; } }); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.umd.js new file mode 100644 index 00000000000..4e95419a12f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2549/output.umd.js @@ -0,0 +1,61 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + addOne: ()=>addOne, + errors: ()=>errors, + noassign: ()=>noassign, + someFunc: ()=>someFunc, + test: ()=>test, + warn: ()=>warn + }); + function log() { + console.log("unexported"); + } + function noassign() { + console.log("stub"); + } + function warn() { + throw new Error("this should not be called"); + } + const errors = { + a: 1 + }; + const addOne = (x)=>`${x + 1}`; + const someFunc = (x)=>`The answer is : ${addOne(x)}`; + const test = {}; + Object.defineProperty(test, "log", { + get: function get() { + return log; + }, + set: function set(v) { + log = v; + } + }); + Object.defineProperty(test, "warn", { + get: ()=>warn, + set: (v)=>{ + warn = v; + } + }); + Object.defineProperty(test, "errors", { + get: ()=>errors, + set: (v)=>{ + errors = v; + } + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2678/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2678/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.amd.js new file mode 100644 index 00000000000..a3c9b1bdfe4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.amd.js @@ -0,0 +1,38 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + default: ()=>someCall, + test: ()=>test, + warn: ()=>warn + }); + function someCall() { + throw new Error("this should not be called"); + } + function warn() { + throw new Error("this should not be called"); + } + const test = {}; + Object.defineProperty(test, "someCall", { + set: (v)=>{ + someCall = v; + } + }); + Object.defineProperty(test, "warn", { + get: ()=>warn, + set: (v)=>{ + warn = v; + } + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2678/output.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.cjs similarity index 55% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2678/output.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.cjs index d0166579fca..db3959523b0 100644 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2678/output.js +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.cjs @@ -2,9 +2,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = someCall; -exports.warn = warn; -exports.test = void 0; +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + default: ()=>someCall, + test: ()=>test, + warn: ()=>warn +}); function someCall() { throw new Error("this should not be called"); } @@ -12,16 +20,14 @@ function warn() { throw new Error("this should not be called"); } const test = {}; -exports.test = test; Object.defineProperty(test, "someCall", { set: (v)=>{ - exports.default = someCall = v; + someCall = v; } }); Object.defineProperty(test, "warn", { - get: ()=>warn - , + get: ()=>warn, set: (v)=>{ - exports.warn = warn = v; + warn = v; } }); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.umd.js new file mode 100644 index 00000000000..1500e33875c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-2678/output.umd.js @@ -0,0 +1,41 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + default: ()=>someCall, + test: ()=>test, + warn: ()=>warn + }); + function someCall() { + throw new Error("this should not be called"); + } + function warn() { + throw new Error("this should not be called"); + } + const test = {}; + Object.defineProperty(test, "someCall", { + set: (v)=>{ + someCall = v; + } + }); + Object.defineProperty(test, "warn", { + get: ()=>warn, + set: (v)=>{ + warn = v; + } + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/input.js new file mode 100644 index 00000000000..544222e5d41 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/input.js @@ -0,0 +1,3 @@ +import { foo } from "bar"; + +import(foo); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.amd.js new file mode 100644 index 00000000000..942c04f2b86 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.amd.js @@ -0,0 +1,13 @@ +define([ + "require", + "exports", + "bar" +], function(require, exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + new Promise((resolve, reject)=>require([ + _bar.foo + ], (m)=>resolve(_interopRequireWildcard(m)), reject)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.cjs new file mode 100644 index 00000000000..25d840c7657 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _bar = require("bar"); +Promise.resolve(_bar.foo).then((p)=>_interopRequireWildcard(require(p))); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.umd.js new file mode 100644 index 00000000000..500cb30b86f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/1/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("bar")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "bar" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.bar); +})(this, function(exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + import(_bar.foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/input.js new file mode 100644 index 00000000000..f7c7c69ffc2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/input.js @@ -0,0 +1,3 @@ +import foo from "bar"; + +import(foo); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.amd.js new file mode 100644 index 00000000000..2f2556c723c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "bar" +], function(require, exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _bar = _interopRequireDefault(_bar); + new Promise((resolve, reject)=>require([ + _bar.default + ], (m)=>resolve(_interopRequireWildcard(m)), reject)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.cjs new file mode 100644 index 00000000000..0027d52f708 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _bar = _interopRequireDefault(require("bar")); +Promise.resolve(_bar.default).then((p)=>_interopRequireWildcard(require(p))); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.umd.js new file mode 100644 index 00000000000..1023d51986a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3246/2/output.umd.js @@ -0,0 +1,15 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("bar")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "bar" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.bar); +})(this, function(exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _bar = _interopRequireDefault(_bar); + import(_bar.default); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/input.js new file mode 100644 index 00000000000..8a7f08b039b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/input.js @@ -0,0 +1,3 @@ +import foo from "foo"; +import bar from "../foo"; +foo, bar; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.amd.js new file mode 100644 index 00000000000..ca674cd86f2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "foo", + "../foo" +], function(require, exports, _foo, _foo1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo1 = _interopRequireDefault(_foo1); + _foo.default, _foo1.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.cjs new file mode 100644 index 00000000000..4d78e926e1b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.cjs @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireDefault(require("foo")); +const _foo1 = _interopRequireDefault(require("../foo")); +_foo.default, _foo1.default; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.umd.js new file mode 100644 index 00000000000..c6ec58529f1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-326/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo"), require("../foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo", + "../foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo, global.foo); +})(this, function(exports, _foo, _foo1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo1 = _interopRequireDefault(_foo1); + _foo.default, _foo1.default; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/input.js new file mode 100644 index 00000000000..f344ef0e3f5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/input.js @@ -0,0 +1,3 @@ +import foo from "foo"; + +export const bar = { foo }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.amd.js new file mode 100644 index 00000000000..140958eae6f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.amd.js @@ -0,0 +1,18 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "bar", { + get: ()=>bar, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); + const bar = { + foo + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.cjs new file mode 100644 index 00000000000..f323d599df8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.cjs @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "bar", { + get: ()=>bar, + enumerable: true +}); +const _foo = _interopRequireDefault(require("foo")); +const bar = { + foo +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.umd.js new file mode 100644 index 00000000000..fcf11c5653a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-332/output.umd.js @@ -0,0 +1,21 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "bar", { + get: ()=>bar, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); + const bar = { + foo + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/input.js new file mode 100644 index 00000000000..0f70e97eaf8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/input.js @@ -0,0 +1,3 @@ +import bar from "bar"; + +obj[bar("bas")] = "123"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.amd.js new file mode 100644 index 00000000000..9ff9f4156a2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.amd.js @@ -0,0 +1,12 @@ +define([ + "require", + "exports", + "bar" +], function(require, exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _bar = _interopRequireDefault(_bar); + obj[(0, _bar.default)("bas")] = "123"; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.cjs new file mode 100644 index 00000000000..844f6f65548 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _bar = _interopRequireDefault(require("bar")); +obj[(0, _bar.default)("bas")] = "123"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.umd.js new file mode 100644 index 00000000000..98af445e923 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-335/output.umd.js @@ -0,0 +1,15 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("bar")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "bar" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.bar); +})(this, function(exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _bar = _interopRequireDefault(_bar); + obj[(0, _bar.default)("bas")] = "123"; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/input.js new file mode 100644 index 00000000000..7a2e481aba7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/input.js @@ -0,0 +1,3 @@ +import { foo } from "bar"; + +import(`world/${foo(baz)}.js`); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.amd.js new file mode 100644 index 00000000000..78483875a07 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.amd.js @@ -0,0 +1,13 @@ +define([ + "require", + "exports", + "bar" +], function(require, exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + new Promise((resolve, reject)=>require([ + `world/${(0, _bar.foo)(baz)}.js` + ], (m)=>resolve(_interopRequireWildcard(m)), reject)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.cjs new file mode 100644 index 00000000000..34bced1ec8a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _bar = require("bar"); +Promise.resolve(`world/${(0, _bar.foo)(baz)}.js`).then((p)=>_interopRequireWildcard(require(p))); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.umd.js new file mode 100644 index 00000000000..ab7064e9828 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3438/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("bar")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "bar" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.bar); +})(this, function(exports, _bar) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + import(`world/${(0, _bar.foo)(baz)}.js`); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/input.js similarity index 78% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/1/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/input.js index e39fc3d70b5..c255b75ad30 100644 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/1/input.js +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/input.js @@ -1,6 +1,6 @@ export { a }; let a = 1; a = 2; -use((a = 3)); +use(a = 3); ({ a = 4 } = {}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.amd.js new file mode 100644 index 00000000000..6e929ec1729 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "a", { + get: ()=>a, + enumerable: true + }); + let a = 1; + a = 2; + use(a = 3); + ({ a =4 } = {}); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.cjs new file mode 100644 index 00000000000..388d2ef513c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.cjs @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "a", { + get: ()=>a, + enumerable: true +}); +let a = 1; +a = 2; +use(a = 3); +({ a =4 } = {}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.umd.js new file mode 100644 index 00000000000..ff06a86ba04 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/1/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "a", { + get: ()=>a, + enumerable: true + }); + let a = 1; + a = 2; + use(a = 3); + ({ a =4 } = {}); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/input.js similarity index 50% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/2/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/input.js index 00da511ff5d..1068301c1c9 100644 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/2/input.js +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/input.js @@ -1,5 +1,5 @@ -export { foo as foo1, bar }; -export { foo, bar as bar2 }; +export { bar, foo as foo1 }; +export { bar as bar2, foo }; const foo = 1; let bar = 2; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.amd.js new file mode 100644 index 00000000000..a269bbd9ca0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.amd.js @@ -0,0 +1,26 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + bar2: ()=>bar, + default: ()=>_default, + foo: ()=>foo, + foo1: ()=>foo + }); + const foo = 1; + let bar = 2; + var _default = bar; + bar = 3; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.cjs new file mode 100644 index 00000000000..a53d53968d3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.cjs @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + bar2: ()=>bar, + default: ()=>_default, + foo: ()=>foo, + foo1: ()=>foo +}); +const foo = 1; +let bar = 2; +var _default = bar; +bar = 3; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.umd.js new file mode 100644 index 00000000000..60976353c4a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/2/output.umd.js @@ -0,0 +1,29 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + bar2: ()=>bar, + default: ()=>_default, + foo: ()=>foo, + foo1: ()=>foo + }); + const foo = 1; + let bar = 2; + var _default = bar; + bar = 3; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/3/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/input.js similarity index 53% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/3/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/input.js index b93d4fafc65..fc8d1cfda8f 100644 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/3/input.js +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/input.js @@ -1,5 +1,5 @@ -export { foo as foo1, bar }; -export { foo, bar as bar2 }; +export { bar, foo as foo1 }; +export { bar as bar2, foo }; const foo = 1; let bar = 2; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.amd.js new file mode 100644 index 00000000000..7b91e484d89 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.amd.js @@ -0,0 +1,25 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + bar2: ()=>bar, + default: ()=>bar, + foo: ()=>foo, + foo1: ()=>foo + }); + const foo = 1; + let bar = 2; + bar = 3; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.cjs new file mode 100644 index 00000000000..7af9e48af2e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.cjs @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + bar2: ()=>bar, + default: ()=>bar, + foo: ()=>foo, + foo1: ()=>foo +}); +const foo = 1; +let bar = 2; +bar = 3; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.umd.js new file mode 100644 index 00000000000..9b1486f17e0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/3/output.umd.js @@ -0,0 +1,28 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + bar2: ()=>bar, + default: ()=>bar, + foo: ()=>foo, + foo1: ()=>foo + }); + const foo = 1; + let bar = 2; + bar = 3; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/4/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/4/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.amd.js new file mode 100644 index 00000000000..0f930be8e18 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.amd.js @@ -0,0 +1,22 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>foo, + default: ()=>foo + }); + foo = 1; + function foo() {} + foo = 2; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.cjs new file mode 100644 index 00000000000..76cbeaca209 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.cjs @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>foo, + default: ()=>foo +}); +foo = 1; +function foo() {} +foo = 2; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.umd.js new file mode 100644 index 00000000000..25cb1154101 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/4/output.umd.js @@ -0,0 +1,25 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>foo, + default: ()=>foo + }); + foo = 1; + function foo() {} + foo = 2; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/5/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/5/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.amd.js new file mode 100644 index 00000000000..0664fbdeafb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.amd.js @@ -0,0 +1,23 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>foo, + default: ()=>foo + }); + foo = 1; + class foo { + } + foo = 2; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.cjs new file mode 100644 index 00000000000..dfbf71eca60 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.cjs @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>foo, + default: ()=>foo +}); +foo = 1; +class foo { +} +foo = 2; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.umd.js new file mode 100644 index 00000000000..6db0db713ee --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3439/5/output.umd.js @@ -0,0 +1,26 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>foo, + default: ()=>foo + }); + foo = 1; + class foo { + } + foo = 2; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/input.js new file mode 100644 index 00000000000..2a58ad9b293 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/input.js @@ -0,0 +1,11 @@ +export function input(name) { + return `${name}.md?render`; +} + +export default function ({ + name, + input: inp, +}) { + inp = inp || input(name); + return { input: inp }; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.amd.js new file mode 100644 index 00000000000..8a98d03f69a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.amd.js @@ -0,0 +1,28 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + default: ()=>_default, + input: ()=>input + }); + function input(name) { + return `${name}.md?render`; + } + function _default({ name , input: inp , }) { + inp = inp || input(name); + return { + input: inp + }; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.cjs new file mode 100644 index 00000000000..ac7064341fc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.cjs @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + default: ()=>_default, + input: ()=>input +}); +function input(name) { + return `${name}.md?render`; +} +function _default({ name , input: inp , }) { + inp = inp || input(name); + return { + input: inp + }; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.umd.js new file mode 100644 index 00000000000..de3fcbe3ab2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-369/output.umd.js @@ -0,0 +1,31 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + default: ()=>_default, + input: ()=>input + }); + function input(name) { + return `${name}.md?render`; + } + function _default({ name , input: inp , }) { + inp = inp || input(name); + return { + input: inp + }; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3732/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3732/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.amd.js new file mode 100644 index 00000000000..3de97e2b8b3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.amd.js @@ -0,0 +1,27 @@ +define([ + "require", + "exports", + "./get" +], function(require, exports, _get) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + byID: ()=>byID, + get: ()=>_get + }); + _get = _interopRequireWildcard(_get); + const byID = (id)=>{ + // Do some async stuff + return new Promise((resolve)=>setTimeout(()=>{ + resolve("result"); + }, 2000)); + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.cjs new file mode 100644 index 00000000000..f7e7d3f962f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.cjs @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + byID: ()=>byID, + get: ()=>_get +}); +const _get = _interopRequireWildcard(require("./get")); +const byID = (id)=>{ + // Do some async stuff + return new Promise((resolve)=>setTimeout(()=>{ + resolve("result"); + }, 2000)); +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.umd.js new file mode 100644 index 00000000000..c04dcc642be --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3732/output.umd.js @@ -0,0 +1,30 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./get")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./get" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.get); +})(this, function(exports, _get) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + byID: ()=>byID, + get: ()=>_get + }); + _get = _interopRequireWildcard(_get); + const byID = (id)=>{ + // Do some async stuff + return new Promise((resolve)=>setTimeout(()=>{ + resolve("result"); + }, 2000)); + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/input.js new file mode 100644 index 00000000000..58451e50077 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/input.js @@ -0,0 +1,2 @@ +import Foo from "foo"; +Foo.bar = true; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.amd.js new file mode 100644 index 00000000000..ec14ad6b55d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.amd.js @@ -0,0 +1,12 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo.default.bar = true; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.cjs new file mode 100644 index 00000000000..d4bc64d0cac --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireDefault(require("foo")); +_foo.default.bar = true; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.umd.js new file mode 100644 index 00000000000..7fccc67eccc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/1/output.umd.js @@ -0,0 +1,15 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo.default.bar = true; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/input.js new file mode 100644 index 00000000000..58451e50077 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/input.js @@ -0,0 +1,2 @@ +import Foo from "foo"; +Foo.bar = true; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.amd.js new file mode 100644 index 00000000000..ec14ad6b55d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.amd.js @@ -0,0 +1,12 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo.default.bar = true; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.cjs new file mode 100644 index 00000000000..d4bc64d0cac --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireDefault(require("foo")); +_foo.default.bar = true; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.umd.js new file mode 100644 index 00000000000..7fccc67eccc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-389/2/output.umd.js @@ -0,0 +1,15 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _foo.default.bar = true; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3898/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3898/1/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.amd.js new file mode 100644 index 00000000000..5d26ac65dce --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.amd.js @@ -0,0 +1,37 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + let foo = 1; + foo = 2; + foo += 2; + foo -= 2; + foo *= 2; + foo /= 2; + foo %= 2; + foo <<= 2; + foo >>= 2; + foo >>>= 2; + foo |= 2; + foo ^= 2; + foo &= 2; + foo **= 2; + foo &&= 2; + foo ||= 2; + foo ??= 2; + [foo] = [ + 2 + ]; + [foo = 3] = []; + ({ bar: foo } = { + bar: 2 + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.cjs new file mode 100644 index 00000000000..f4d952e8792 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.cjs @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true +}); +let foo = 1; +foo = 2; +foo += 2; +foo -= 2; +foo *= 2; +foo /= 2; +foo %= 2; +foo <<= 2; +foo >>= 2; +foo >>>= 2; +foo |= 2; +foo ^= 2; +foo &= 2; +foo **= 2; +foo &&= 2; +foo ||= 2; +foo ??= 2; +[foo] = [ + 2 +]; +[foo = 3] = []; +({ bar: foo } = { + bar: 2 +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.umd.js new file mode 100644 index 00000000000..4bb02f0bbc7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-3898/1/output.umd.js @@ -0,0 +1,40 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + let foo = 1; + foo = 2; + foo += 2; + foo -= 2; + foo *= 2; + foo /= 2; + foo %= 2; + foo <<= 2; + foo >>= 2; + foo >>>= 2; + foo |= 2; + foo ^= 2; + foo &= 2; + foo **= 2; + foo &&= 2; + foo ||= 2; + foo ??= 2; + [foo] = [ + 2 + ]; + [foo = 3] = []; + ({ bar: foo } = { + bar: 2 + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/input.js new file mode 100644 index 00000000000..d5faeaee9b2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/input.js @@ -0,0 +1,4 @@ +function foo() { + bar; + function bar() {} +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.amd.js new file mode 100644 index 00000000000..a092da146fb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.amd.js @@ -0,0 +1,9 @@ +define([ + "require" +], function(require) { + "use strict"; + function foo() { + bar; + function bar() {} + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.cjs new file mode 100644 index 00000000000..1d6ce3d5ace --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +function foo() { + bar; + function bar() {} +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.umd.js new file mode 100644 index 00000000000..fa0c2f82ab0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/1/output.umd.js @@ -0,0 +1,11 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + function foo() { + bar; + function bar() {} + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/input.js new file mode 100644 index 00000000000..d5faeaee9b2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/input.js @@ -0,0 +1,4 @@ +function foo() { + bar; + function bar() {} +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.amd.js new file mode 100644 index 00000000000..a092da146fb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.amd.js @@ -0,0 +1,9 @@ +define([ + "require" +], function(require) { + "use strict"; + function foo() { + bar; + function bar() {} + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.cjs new file mode 100644 index 00000000000..1d6ce3d5ace --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +function foo() { + bar; + function bar() {} +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.umd.js new file mode 100644 index 00000000000..fa0c2f82ab0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-396/2/output.umd.js @@ -0,0 +1,11 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + function foo() { + bar; + function bar() {} + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/input.js new file mode 100644 index 00000000000..743353aacbd --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/input.js @@ -0,0 +1,4 @@ +export * from "./File1"; +export * from "./File2"; + +export const BIZ = "biz"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.amd.js new file mode 100644 index 00000000000..c4b17f756a5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.amd.js @@ -0,0 +1,18 @@ +define([ + "require", + "exports", + "./File1", + "./File2" +], function(require, exports, _file1, _file2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "BIZ", { + get: ()=>BIZ, + enumerable: true + }); + _exportStar(_file1, exports); + _exportStar(_file2, exports); + const BIZ = "biz"; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.cjs new file mode 100644 index 00000000000..2fc54819e7e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "BIZ", { + get: ()=>BIZ, + enumerable: true +}); +_exportStar(require("./File1"), exports); +_exportStar(require("./File2"), exports); +const BIZ = "biz"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.umd.js new file mode 100644 index 00000000000..a8ff55ea7e2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4064/output.umd.js @@ -0,0 +1,21 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./File1"), require("./File2")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./File1", + "./File2" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.file1, global.file2); +})(this, function(exports, _file1, _file2) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "BIZ", { + get: ()=>BIZ, + enumerable: true + }); + _exportStar(_file1, exports); + _exportStar(_file2, exports); + const BIZ = "biz"; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/input.js new file mode 100644 index 00000000000..70030a0c12a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/input.js @@ -0,0 +1 @@ +let pipeline = await import(await resolve(file)); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.amd.js new file mode 100644 index 00000000000..a0aebff6068 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.amd.js @@ -0,0 +1,8 @@ +define([ + "require" +], function(require) { + "use strict"; + let pipeline = await new Promise((resolve1, reject)=>require([ + await resolve(file) + ], (m)=>resolve1(_interopRequireWildcard(m)), reject)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.cjs new file mode 100644 index 00000000000..6b250dbc51e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.cjs @@ -0,0 +1,2 @@ +"use strict"; +let pipeline = await Promise.resolve(await resolve(file)).then((p)=>_interopRequireWildcard(require(p))); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.umd.js new file mode 100644 index 00000000000..74d506a12d1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4253/output.umd.js @@ -0,0 +1,8 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + let pipeline = await import(await resolve(file)); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/input.js new file mode 100644 index 00000000000..8e100198518 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/input.js @@ -0,0 +1,3 @@ +export default { + foo: "bar", +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.amd.js new file mode 100644 index 00000000000..95000c3397d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = { + foo: "bar" + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.cjs new file mode 100644 index 00000000000..ff4ae5c9d6d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +var _default = { + foo: "bar" +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.umd.js new file mode 100644 index 00000000000..ceb0ca397df --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4313/1/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = { + foo: "bar" + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/input.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/input.ts new file mode 100644 index 00000000000..f309c1e522d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/input.ts @@ -0,0 +1,16 @@ +import "."; + +import emotionStyled from "@emotion/styled"; + +import { breakpoinstUtils } from "@eduzz/houston-tokens/variables/breakpoints"; + +export { cx, cx as clsx, keyframes } from "@emotion/css"; + +export interface IStyledProp { + className?: string; +} + +export const breakpoints = breakpoinstUtils; + +const styled = emotionStyled; +export default styled; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.amd.ts new file mode 100644 index 00000000000..6772712699b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.amd.ts @@ -0,0 +1,33 @@ +define([ + "require", + "exports", + ".", + "@emotion/styled", + "@eduzz/houston-tokens/variables/breakpoints", + "@emotion/css" +], function(require, exports, _, _styled, _breakpoints, _css) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + breakpoints: ()=>breakpoints, + clsx: ()=>_css.cx, + cx: ()=>_css.cx, + default: ()=>_default, + keyframes: ()=>_css.keyframes + }); + _styled = _interopRequireDefault(_styled); + interface IStyledProp { + className?: string; + } + const breakpoints = _breakpoints.breakpoinstUtils; + const styled = _styled.default; + var _default = styled; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.cts new file mode 100644 index 00000000000..d632bc1ba51 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.cts @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + breakpoints: ()=>breakpoints, + clsx: ()=>_css.cx, + cx: ()=>_css.cx, + default: ()=>_default, + keyframes: ()=>_css.keyframes +}); +require("."); +const _styled = _interopRequireDefault(require("@emotion/styled")); +const _breakpoints = require("@eduzz/houston-tokens/variables/breakpoints"); +const _css = require("@emotion/css"); +interface IStyledProp { + className?: string; +} +const breakpoints = _breakpoints.breakpoinstUtils; +const styled = _styled.default; +var _default = styled; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.umd.ts new file mode 100644 index 00000000000..7c5a040b11e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4456/1/output.umd.ts @@ -0,0 +1,36 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("."), require("@emotion/styled"), require("@eduzz/houston-tokens/variables/breakpoints"), require("@emotion/css")); + else if (typeof define === "function" && define.amd) define([ + "exports", + ".", + "@emotion/styled", + "@eduzz/houston-tokens/variables/breakpoints", + "@emotion/css" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global[""], global.styled, global.breakpoints, global.css); +})(this, function(exports, _, _styled, _breakpoints, _css) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + breakpoints: ()=>breakpoints, + clsx: ()=>_css.cx, + cx: ()=>_css.cx, + default: ()=>_default, + keyframes: ()=>_css.keyframes + }); + _styled = _interopRequireDefault(_styled); + interface IStyledProp { + className?: string; + } + const breakpoints = _breakpoints.breakpoinstUtils; + const styled = _styled.default; + var _default = styled; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/input.js new file mode 100644 index 00000000000..1303b9ae65e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/input.js @@ -0,0 +1,4 @@ +import * as A from "./A"; +import * as B from "./A"; + +export { A, B }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.amd.js new file mode 100644 index 00000000000..da2629f4b25 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.amd.js @@ -0,0 +1,21 @@ +define([ + "require", + "exports", + "./A" +], function(require, exports, _a) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + A: ()=>_a, + B: ()=>_a + }); + _a = _interopRequireWildcard(_a); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.cjs new file mode 100644 index 00000000000..38ee95d8afb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + A: ()=>_a, + B: ()=>_a +}); +const _a = _interopRequireWildcard(require("./A")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.umd.js new file mode 100644 index 00000000000..f9f654a1f8c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4534/1/output.umd.js @@ -0,0 +1,24 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./A")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./A" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.a); +})(this, function(exports, _a) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + A: ()=>_a, + B: ()=>_a + }); + _a = _interopRequireWildcard(_a); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/input.js new file mode 100644 index 00000000000..b3931b3da3e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/input.js @@ -0,0 +1,5 @@ +import { join as e } from "path"; +export const foo = function () { + function e(t) {} + return A(e, {}), e; +}(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/module.json new file mode 100644 index 00000000000..7e82b0a247e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/module.json @@ -0,0 +1,5 @@ +{ + "strict": false, + "strictMode": true, + "noInterop": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.amd.js new file mode 100644 index 00000000000..1c0e55261cb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "path" +], function(require, exports, _path) { + "use strict"; + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + const foo = function() { + function e(t) {} + return A(e, {}), e; + }(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.cjs new file mode 100644 index 00000000000..b4bdd22192f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true +}); +const _path = require("path"); +const foo = function() { + function e(t) {} + return A(e, {}), e; +}(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.umd.js new file mode 100644 index 00000000000..61439aef1de --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/1/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("path")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "path" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.path); +})(this, function(exports, _path) { + "use strict"; + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + const foo = function() { + function e(t) {} + return A(e, {}), e; + }(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/input.js new file mode 100644 index 00000000000..bdec523de14 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/input.js @@ -0,0 +1,5 @@ +import { join as e } from "path"; +export const foo = function () { + var e = 1; + return A(e, {}), e; +}(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/module.json new file mode 100644 index 00000000000..7e82b0a247e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/module.json @@ -0,0 +1,5 @@ +{ + "strict": false, + "strictMode": true, + "noInterop": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.amd.js new file mode 100644 index 00000000000..e4bb806647d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "path" +], function(require, exports, _path) { + "use strict"; + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + const foo = function() { + var e = 1; + return A(e, {}), e; + }(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.cjs new file mode 100644 index 00000000000..a5fa1a5ccb8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true +}); +const _path = require("path"); +const foo = function() { + var e = 1; + return A(e, {}), e; +}(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.umd.js new file mode 100644 index 00000000000..449f81c2402 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-456/2/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("path")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "path" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.path); +})(this, function(exports, _path) { + "use strict"; + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + const foo = function() { + var e = 1; + return A(e, {}), e; + }(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/input.js new file mode 100644 index 00000000000..a5c6573bc84 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/input.js @@ -0,0 +1,3 @@ +const Base = getBase(""); + +export default class Foo extends Base {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.amd.js new file mode 100644 index 00000000000..19ec9ab586f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true + }); + const Base = getBase(""); + class Foo extends Base { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.cjs new file mode 100644 index 00000000000..da2dd29c4ff --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true +}); +const Base = getBase(""); +class Foo extends Base { +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.umd.js new file mode 100644 index 00000000000..388897cc0a6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4567/1/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>Foo, + enumerable: true + }); + const Base = getBase(""); + class Foo extends Base { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-4700/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-4700/1/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.amd.js new file mode 100644 index 00000000000..8ff0d68b708 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.amd.js @@ -0,0 +1,19 @@ +define([ + "require", + "exports", + "another-module" +], function(require, exports, _anotherModule) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "whatever", { + get: ()=>whatever, + enumerable: true + }); + _exportStar(_anotherModule, exports); + function whatever(notExportName) { + const shouldNotBeExportNameAsWell = 123; + return shouldNotBeExportNameAsWell + notExportName; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.cjs new file mode 100644 index 00000000000..034b8ebae63 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.cjs @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "whatever", { + get: ()=>whatever, + enumerable: true +}); +_exportStar(require("another-module"), exports); +function whatever(notExportName) { + const shouldNotBeExportNameAsWell = 123; + return shouldNotBeExportNameAsWell + notExportName; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.umd.js new file mode 100644 index 00000000000..81a9b8e76d7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4700/1/output.umd.js @@ -0,0 +1,22 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("another-module")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "another-module" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.anotherModule); +})(this, function(exports, _anotherModule) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "whatever", { + get: ()=>whatever, + enumerable: true + }); + _exportStar(_anotherModule, exports); + function whatever(notExportName) { + const shouldNotBeExportNameAsWell = 123; + return shouldNotBeExportNameAsWell + notExportName; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/input.js new file mode 100644 index 00000000000..dc33845acad --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/input.js @@ -0,0 +1,3 @@ +function fff() { + require.toUrl(""); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.amd.js new file mode 100644 index 00000000000..576f60b303c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.amd.js @@ -0,0 +1,8 @@ +define([ + "require" +], function(require) { + "use strict"; + function fff() { + require.toUrl(""); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.cjs new file mode 100644 index 00000000000..5c599d9add5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.cjs @@ -0,0 +1,4 @@ +"use strict"; +function fff() { + require.toUrl(""); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.umd.js new file mode 100644 index 00000000000..1ab65d414e8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4718/1/output.umd.js @@ -0,0 +1,10 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + function fff() { + require.toUrl(""); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/input.js new file mode 100644 index 00000000000..aa8fd63260a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/input.js @@ -0,0 +1,2 @@ +import { getPathFromAmdModule } from "vs/base/test/node/testUtils"; +const fixturesFolder = getPathFromAmdModule(require, "./fixtures"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.amd.js new file mode 100644 index 00000000000..8fe48169b27 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "vs/base/test/node/testUtils" +], function(require, exports, _testUtils) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const fixturesFolder = (0, _testUtils.getPathFromAmdModule)(require, "./fixtures"); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.cjs new file mode 100644 index 00000000000..54d29ad6139 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _testUtils = require("vs/base/test/node/testUtils"); +const fixturesFolder = (0, _testUtils.getPathFromAmdModule)(require, "./fixtures"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.umd.js new file mode 100644 index 00000000000..bbc5a73ae1c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4798/1/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("vs/base/test/node/testUtils")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "vs/base/test/node/testUtils" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.testUtils); +})(this, function(exports, _testUtils) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const fixturesFolder = (0, _testUtils.getPathFromAmdModule)(require, "./fixtures"); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/input.js new file mode 100644 index 00000000000..194e8f1505a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/input.js @@ -0,0 +1 @@ +export { createP } from "./St"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.amd.js new file mode 100644 index 00000000000..1241b0c9ab8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "./St" +], function(require, exports, _st) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "createP", { + get: ()=>_st.createP, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.cjs new file mode 100644 index 00000000000..91d32605384 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "createP", { + get: ()=>_st.createP, + enumerable: true +}); +const _st = require("./St"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.umd.js new file mode 100644 index 00000000000..1b129e51abb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4799/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./St")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./St" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.st); +})(this, function(exports, _st) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "createP", { + get: ()=>_st.createP, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/input.js new file mode 100644 index 00000000000..70bc5302694 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/input.js @@ -0,0 +1,2 @@ +export let a, b; +console.log([a, b] = [1, 2]); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.amd.js new file mode 100644 index 00000000000..a585eb8a232 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.amd.js @@ -0,0 +1,24 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + a: ()=>a, + b: ()=>b + }); + let a, b; + console.log([a, b] = [ + 1, + 2 + ]); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.cjs new file mode 100644 index 00000000000..abc37423411 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.cjs @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + a: ()=>a, + b: ()=>b +}); +let a, b; +console.log([a, b] = [ + 1, + 2 +]); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.umd.js new file mode 100644 index 00000000000..64b5978b80a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4866/1/output.umd.js @@ -0,0 +1,27 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + a: ()=>a, + b: ()=>b + }); + let a, b; + console.log([a, b] = [ + 1, + 2 + ]); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/input.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/input.ts new file mode 100644 index 00000000000..0922ad260fe --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/input.ts @@ -0,0 +1,3 @@ +import assert = require("assert"); + +assert(true); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.amd.ts new file mode 100644 index 00000000000..d9079d463a8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.amd.ts @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "assert" +], function(require, exports, _assert) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _assert(true); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.cts new file mode 100644 index 00000000000..919586ddab4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.cts @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _assert = require("assert"); +_assert(true); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.umd.ts new file mode 100644 index 00000000000..35356e2f1a9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/1/output.umd.ts @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("assert")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "assert" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.assert); +})(this, function(exports, _assert) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _assert(true); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/input.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/input.ts new file mode 100644 index 00000000000..ab339d2a3af --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/input.ts @@ -0,0 +1,5 @@ +import assert = require("assert"); +import assert2 from "assert"; + +assert(true); +assert2(true); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.amd.ts new file mode 100644 index 00000000000..921add0e126 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.amd.ts @@ -0,0 +1,13 @@ +define([ + "require", + "exports", + "assert" +], function(require, exports, _assert) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const _assert1 = _interopRequireDefault(_assert); + _assert(true); + (0, _assert1.default)(true); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.cts new file mode 100644 index 00000000000..bb35ea2602a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.cts @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _assert = require("assert"); +const _assert1 = _interopRequireDefault(require("assert")); +_assert(true); +(0, _assert1.default)(true); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.umd.ts new file mode 100644 index 00000000000..168f18dea1a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4898/2/output.umd.ts @@ -0,0 +1,16 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("assert")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "assert" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.assert); +})(this, function(exports, _assert) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const _assert1 = _interopRequireDefault(_assert); + _assert(true); + (0, _assert1.default)(true); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/input.js new file mode 100644 index 00000000000..42a4de553a7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/input.js @@ -0,0 +1,5 @@ +export var a = 1, + b = 2; + +var c = 3; +export { c }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.amd.js new file mode 100644 index 00000000000..cad85151e8e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.amd.js @@ -0,0 +1,22 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + a: ()=>a, + b: ()=>b, + c: ()=>c + }); + var a = 1, b = 2; + var c = 3; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.cjs new file mode 100644 index 00000000000..8e1f6bac13d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.cjs @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + a: ()=>a, + b: ()=>b, + c: ()=>c +}); +var a = 1, b = 2; +var c = 3; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.umd.js new file mode 100644 index 00000000000..c38cb521c5d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4981/1/output.umd.js @@ -0,0 +1,25 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + a: ()=>a, + b: ()=>b, + c: ()=>c + }); + var a = 1, b = 2; + var c = 3; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/input.js new file mode 100644 index 00000000000..e5538a68d9a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/input.js @@ -0,0 +1,5 @@ +const VALUE = "hello"; + +export default class MyClass { + static MEMBER = VALUE; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.amd.js new file mode 100644 index 00000000000..631dd25f36e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>MyClass, + enumerable: true + }); + const VALUE = "hello"; + class MyClass { + static MEMBER = VALUE; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.cjs new file mode 100644 index 00000000000..34d894b67bb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.cjs @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>MyClass, + enumerable: true +}); +const VALUE = "hello"; +class MyClass { + static MEMBER = VALUE; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.umd.js new file mode 100644 index 00000000000..4e005bfdf51 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-4984/1/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>MyClass, + enumerable: true + }); + const VALUE = "hello"; + class MyClass { + static MEMBER = VALUE; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/input.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/input.ts new file mode 100644 index 00000000000..f3ce83fb401 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/input.ts @@ -0,0 +1,5 @@ +export import $ = require("jquery"); + +$(".hello"); + +export { $ as jquery }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.amd.ts new file mode 100644 index 00000000000..fae0a12c9c1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.amd.ts @@ -0,0 +1,21 @@ +define([ + "require", + "exports", + "jquery" +], function(require, exports, _jquery) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + "$": ()=>_jquery, + jquery: ()=>_jquery + }); + _jquery(".hello"); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.cts new file mode 100644 index 00000000000..20cbfbd54ea --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.cts @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + "$": ()=>_jquery, + jquery: ()=>_jquery +}); +const _jquery = require("jquery"); +_jquery(".hello"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.umd.ts new file mode 100644 index 00000000000..8e12dee5364 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/1/output.umd.ts @@ -0,0 +1,24 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("jquery")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "jquery" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.jquery); +})(this, function(exports, _jquery) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + "$": ()=>_jquery, + jquery: ()=>_jquery + }); + _jquery(".hello"); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/input.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/input.ts new file mode 100644 index 00000000000..9d8f847da3a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/input.ts @@ -0,0 +1,7 @@ +import foo = require("foo"); + +foo.bar = 1; + +export = foo; + +foo.bar = 2; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.amd.ts new file mode 100644 index 00000000000..49523228ced --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.amd.ts @@ -0,0 +1,9 @@ +define([ + "require", + "foo" +], function(require, _foo) { + "use strict"; + _foo.bar = 1; + _foo.bar = 2; + return _foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.cts new file mode 100644 index 00000000000..d317270e640 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.cts @@ -0,0 +1,5 @@ +"use strict"; +const _foo = require("foo"); +_foo.bar = 1; +_foo.bar = 2; +module.exports = _foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.umd.ts new file mode 100644 index 00000000000..afd50cda083 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/2/output.umd.ts @@ -0,0 +1,12 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") module.exports = factory(require("foo")); + else if (typeof define === "function" && define.amd) define([ + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) module.exports = factory(global.foo); +})(this, function(_foo) { + "use strict"; + _foo.bar = 1; + _foo.bar = 2; + return _foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/input.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/input.ts new file mode 100644 index 00000000000..eb833ab7af4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/input.ts @@ -0,0 +1,2 @@ +import * as testUtils from "vs/base/test/common/testUtils"; +export var flakySuite = testUtils.flakySuite; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.amd.ts new file mode 100644 index 00000000000..d5b7e620389 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.amd.ts @@ -0,0 +1,16 @@ +define([ + "require", + "exports", + "vs/base/test/common/testUtils" +], function(require, exports, _testUtils) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "flakySuite", { + get: ()=>flakySuite, + enumerable: true + }); + _testUtils = _interopRequireWildcard(_testUtils); + var flakySuite = _testUtils.flakySuite; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.cts new file mode 100644 index 00000000000..c5ef5891f66 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.cts @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "flakySuite", { + get: ()=>flakySuite, + enumerable: true +}); +const _testUtils = _interopRequireWildcard(require("vs/base/test/common/testUtils")); +var flakySuite = _testUtils.flakySuite; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.umd.ts new file mode 100644 index 00000000000..a4905cbdf14 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5042/3/output.umd.ts @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("vs/base/test/common/testUtils")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "vs/base/test/common/testUtils" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.testUtils); +})(this, function(exports, _testUtils) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "flakySuite", { + get: ()=>flakySuite, + enumerable: true + }); + _testUtils = _interopRequireWildcard(_testUtils); + var flakySuite = _testUtils.flakySuite; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/input.js new file mode 100644 index 00000000000..1974d7f25b0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/input.js @@ -0,0 +1,23 @@ +import { myFunction } from "./dep.js"; + +class SomeClass { + constructor(properties) { + this.props = properties; + } + call() { + const { myFunction } = this.props; + if (myFunction) { + myFunction(); + } else { + console.log("DID NOT WORK!"); + } + } +} + +let instance = new SomeClass({ + myFunction: () => { + console.log("CORRECT FUNCTION CALLED"); + }, +}); + +instance.call(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.amd.js new file mode 100644 index 00000000000..da0c360bff2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.amd.js @@ -0,0 +1,29 @@ +define([ + "require", + "exports", + "./dep.js" +], function(require, exports, _depJs) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + class SomeClass { + constructor(properties){ + this.props = properties; + } + call() { + const { myFunction } = this.props; + if (myFunction) { + myFunction(); + } else { + console.log("DID NOT WORK!"); + } + } + } + let instance = new SomeClass({ + myFunction: ()=>{ + console.log("CORRECT FUNCTION CALLED"); + } + }); + instance.call(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.cjs new file mode 100644 index 00000000000..62b3a2e1678 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.cjs @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _depJs = require("./dep.js"); +class SomeClass { + constructor(properties){ + this.props = properties; + } + call() { + const { myFunction } = this.props; + if (myFunction) { + myFunction(); + } else { + console.log("DID NOT WORK!"); + } + } +} +let instance = new SomeClass({ + myFunction: ()=>{ + console.log("CORRECT FUNCTION CALLED"); + } +}); +instance.call(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.umd.js new file mode 100644 index 00000000000..78434a6170a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-578/2/output.umd.js @@ -0,0 +1,32 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./dep.js")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./dep.js" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.depJs); +})(this, function(exports, _depJs) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + class SomeClass { + constructor(properties){ + this.props = properties; + } + call() { + const { myFunction } = this.props; + if (myFunction) { + myFunction(); + } else { + console.log("DID NOT WORK!"); + } + } + } + let instance = new SomeClass({ + myFunction: ()=>{ + console.log("CORRECT FUNCTION CALLED"); + } + }); + instance.call(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/input.js new file mode 100644 index 00000000000..51be603ee07 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/input.js @@ -0,0 +1 @@ +export * from "c"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/module.json new file mode 100644 index 00000000000..7e82b0a247e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/module.json @@ -0,0 +1,5 @@ +{ + "strict": false, + "strictMode": true, + "noInterop": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.amd.js new file mode 100644 index 00000000000..2264621f695 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.amd.js @@ -0,0 +1,8 @@ +define([ + "require", + "exports", + "c" +], function(require, exports, _c) { + "use strict"; + _exportStar(_c, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.cjs new file mode 100644 index 00000000000..670ab6488ba --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.cjs @@ -0,0 +1,2 @@ +"use strict"; +_exportStar(require("c"), exports); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.umd.js new file mode 100644 index 00000000000..0afd2348b91 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-605/output.umd.js @@ -0,0 +1,11 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("c")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "c" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.c); +})(this, function(exports, _c) { + "use strict"; + _exportStar(_c, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/input.js new file mode 100644 index 00000000000..550328b7bbc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/input.js @@ -0,0 +1,2 @@ +import { Db, MongoClient } from "mongodb"; +require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/module.json new file mode 100644 index 00000000000..7e82b0a247e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/module.json @@ -0,0 +1,5 @@ +{ + "strict": false, + "strictMode": true, + "noInterop": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.amd.js new file mode 100644 index 00000000000..cfc59ae546d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.amd.js @@ -0,0 +1,7 @@ +define([ + "require", + "mongodb" +], function(require, _mongodb) { + "use strict"; + require("foo"); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.cjs new file mode 100644 index 00000000000..7ea92822910 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.cjs @@ -0,0 +1,3 @@ +"use strict"; +const _mongodb = require("mongodb"); +require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.umd.js new file mode 100644 index 00000000000..2fe7d28e81d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-724/output.umd.js @@ -0,0 +1,10 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(require("mongodb")); + else if (typeof define === "function" && define.amd) define([ + "mongodb" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.mongodb); +})(this, function(_mongodb) { + "use strict"; + require("foo"); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/input.js new file mode 100644 index 00000000000..28e47e260cf --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/input.js @@ -0,0 +1,21 @@ +import { + INSTAGRAM_CHECK_PATTERN, + RESOURCE_FACEBOOK, + RESOURCE_INSTAGRAM, + RESOURCE_WEBSITE, +} from "../../../../consts"; + +const resources = [ + { + value: RESOURCE_WEBSITE, + label: "Webové stránky", + }, + { + value: RESOURCE_FACEBOOK, + label: "Facebook", + }, + { + value: RESOURCE_INSTAGRAM, + label: "Instagram", + }, +]; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/module.json new file mode 100644 index 00000000000..9ce347c897b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/module.json @@ -0,0 +1,4 @@ +{ + "strict": false, + "strictMode": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.amd.js new file mode 100644 index 00000000000..ab871e3343d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.amd.js @@ -0,0 +1,24 @@ +define([ + "require", + "exports", + "../../../../consts" +], function(require, exports, _consts) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const resources = [ + { + value: _consts.RESOURCE_WEBSITE, + label: "Webové stránky" + }, + { + value: _consts.RESOURCE_FACEBOOK, + label: "Facebook" + }, + { + value: _consts.RESOURCE_INSTAGRAM, + label: "Instagram" + }, + ]; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.cjs new file mode 100644 index 00000000000..54b1669d621 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.cjs @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _consts = require("../../../../consts"); +const resources = [ + { + value: _consts.RESOURCE_WEBSITE, + label: "Webové stránky" + }, + { + value: _consts.RESOURCE_FACEBOOK, + label: "Facebook" + }, + { + value: _consts.RESOURCE_INSTAGRAM, + label: "Instagram" + }, +]; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.umd.js new file mode 100644 index 00000000000..9f928794880 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-763/output.umd.js @@ -0,0 +1,27 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("../../../../consts")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "../../../../consts" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.consts); +})(this, function(exports, _consts) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + const resources = [ + { + value: _consts.RESOURCE_WEBSITE, + label: "Webové stránky" + }, + { + value: _consts.RESOURCE_FACEBOOK, + label: "Facebook" + }, + { + value: _consts.RESOURCE_INSTAGRAM, + label: "Instagram" + }, + ]; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/input.js new file mode 100644 index 00000000000..c85492315c6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/input.js @@ -0,0 +1,3 @@ +export function* myGenerator() { + yield* [1, 2, 3]; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.amd.js new file mode 100644 index 00000000000..a4d8182d9a1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "myGenerator", { + get: ()=>myGenerator, + enumerable: true + }); + function* myGenerator() { + yield* [ + 1, + 2, + 3 + ]; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.cjs new file mode 100644 index 00000000000..1911a575cb8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "myGenerator", { + get: ()=>myGenerator, + enumerable: true +}); +function* myGenerator() { + yield* [ + 1, + 2, + 3 + ]; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.umd.js new file mode 100644 index 00000000000..0235f1876a4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-831/2/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "myGenerator", { + get: ()=>myGenerator, + enumerable: true + }); + function* myGenerator() { + yield* [ + 1, + 2, + 3 + ]; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/input.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/input.ts new file mode 100644 index 00000000000..055bdb97d63 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/input.ts @@ -0,0 +1,7 @@ +import { queryString } from "./url"; + +export function setup(url: string, obj: any) { + const _queryString = queryString(obj); + const _url = url + "?" + _queryString; + return _url; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.amd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.amd.ts new file mode 100644 index 00000000000..4c72528816a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.amd.ts @@ -0,0 +1,19 @@ +define([ + "require", + "exports", + "./url" +], function(require, exports, _url) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "setup", { + get: ()=>setup, + enumerable: true + }); + function setup(url: string, obj: any) { + const _queryString = (0, _url.queryString)(obj); + const _url1 = url + "?" + _queryString; + return _url1; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.cts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.cts new file mode 100644 index 00000000000..7313e688a70 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.cts @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "setup", { + get: ()=>setup, + enumerable: true +}); +const _url = require("./url"); +function setup(url: string, obj: any) { + const _queryString = (0, _url.queryString)(obj); + const _url1 = url + "?" + _queryString; + return _url1; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.umd.ts b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.umd.ts new file mode 100644 index 00000000000..69ec5ffa84f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-895/output.umd.ts @@ -0,0 +1,22 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./url")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./url" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.url); +})(this, function(exports, _url) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "setup", { + get: ()=>setup, + enumerable: true + }); + function setup(url: string, obj: any) { + const _queryString = (0, _url.queryString)(obj); + const _url1 = url + "?" + _queryString; + return _url1; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/input.js new file mode 100644 index 00000000000..40be8a272a7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/input.js @@ -0,0 +1,17 @@ +import root from "./_root.js"; +import stubFalse from "./stubFalse.js"; + +var freeExports = typeof exports == "object" && exports && !exports.nodeType && + exports; +var freeModule = freeExports && typeof module == "object" && module && + !module.nodeType && module; + +var moduleExports = freeModule && freeModule.exports === freeExports; + +var Buffer = moduleExports ? root.Buffer : undefined; + +var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined; + +var isBuffer = nativeIsBuffer || stubFalse; + +export default isBuffer; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.amd.js new file mode 100644 index 00000000000..3bd24c3aa7a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.amd.js @@ -0,0 +1,24 @@ +define([ + "require", + "exports", + "./_root.js", + "./stubFalse.js" +], function(require, exports1, _rootJs, _stubFalseJs) { + "use strict"; + Object.defineProperty(exports1, "__esModule", { + value: true + }); + Object.defineProperty(exports1, "default", { + get: ()=>_default, + enumerable: true + }); + _rootJs = _interopRequireDefault(_rootJs); + _stubFalseJs = _interopRequireDefault(_stubFalseJs); + var freeExports = typeof exports == "object" && exports && !exports.nodeType && exports; + var freeModule = freeExports && typeof module == "object" && module && !module.nodeType && module; + var moduleExports = freeModule && freeModule.exports === freeExports; + var Buffer = moduleExports ? _rootJs.default.Buffer : undefined; + var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined; + var isBuffer = nativeIsBuffer || _stubFalseJs.default; + var _default = isBuffer; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.cjs new file mode 100644 index 00000000000..9fbab64f43e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.cjs @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +const _rootJs = _interopRequireDefault(require("./_root.js")); +const _stubFalseJs = _interopRequireDefault(require("./stubFalse.js")); +var freeExports = typeof exports == "object" && exports && !exports.nodeType && exports; +var freeModule = freeExports && typeof module == "object" && module && !module.nodeType && module; +var moduleExports = freeModule && freeModule.exports === freeExports; +var Buffer = moduleExports ? _rootJs.default.Buffer : undefined; +var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined; +var isBuffer = nativeIsBuffer || _stubFalseJs.default; +var _default = isBuffer; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.umd.js new file mode 100644 index 00000000000..daa3486ff2c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-962/output.umd.js @@ -0,0 +1,27 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./_root.js"), require("./stubFalse.js")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./_root.js", + "./stubFalse.js" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.rootJs, global.stubFalseJs); +})(this, function(exports1, _rootJs, _stubFalseJs) { + "use strict"; + Object.defineProperty(exports1, "__esModule", { + value: true + }); + Object.defineProperty(exports1, "default", { + get: ()=>_default, + enumerable: true + }); + _rootJs = _interopRequireDefault(_rootJs); + _stubFalseJs = _interopRequireDefault(_stubFalseJs); + var freeExports = typeof exports == "object" && exports && !exports.nodeType && exports; + var freeModule = freeExports && typeof module == "object" && module && !module.nodeType && module; + var moduleExports = freeModule && freeModule.exports === freeExports; + var Buffer = moduleExports ? _rootJs.default.Buffer : undefined; + var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined; + var isBuffer = nativeIsBuffer || _stubFalseJs.default; + var _default = isBuffer; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/input.js new file mode 100644 index 00000000000..9f7e1178c41 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/input.js @@ -0,0 +1,9 @@ +import { x } from "libx"; +import { y } from "liby"; + +class F { + get [x]() {} + get y() { + y(); + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.amd.js new file mode 100644 index 00000000000..de034eecc57 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports", + "libx", + "liby" +], function(require, exports, _libx, _liby) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + class F { + get [_libx.x]() {} + get y() { + (0, _liby.y)(); + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.cjs new file mode 100644 index 00000000000..fc2ab46b6b2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.cjs @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _libx() { + const data = require("libx"); + _libx = function() { + return data; + }; + return data; +} +function _liby() { + const data = require("liby"); + _liby = function() { + return data; + }; + return data; +} +class F { + get [_libx().x]() {} + get y() { + _liby().y(); + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.umd.js new file mode 100644 index 00000000000..14c0e8f9f26 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/computed-prop-name/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("libx"), require("liby")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "libx", + "liby" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.libx, global.liby); +})(this, function(exports, _libx, _liby) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + class F { + get [_libx.x]() {} + get y() { + (0, _liby.y)(); + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/input.js new file mode 100644 index 00000000000..444e30b8ed2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/input.js @@ -0,0 +1,5 @@ +import foo from "foo"; + +function use() { + console.log(foo); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.amd.js new file mode 100644 index 00000000000..d7aab21099f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + function use() { + console.log(_foo.default); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.cjs new file mode 100644 index 00000000000..dbeb8fbb1aa --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.cjs @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _foo() { + const data = _interopRequireDefault(require("foo")); + _foo = function() { + return data; + }; + return data; +} +function use() { + console.log(_foo().default); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.umd.js new file mode 100644 index 00000000000..f42876b671e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-default/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + function use() { + console.log(_foo.default); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/input.js new file mode 100644 index 00000000000..4152a22cfc0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/input.js @@ -0,0 +1,5 @@ +import { foo } from "foo"; + +function use() { + console.log(foo); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.amd.js new file mode 100644 index 00000000000..f1ea3df5978 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.amd.js @@ -0,0 +1,13 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function use() { + console.log(_foo.foo); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.cjs new file mode 100644 index 00000000000..79193757e1f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.cjs @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _foo() { + const data = require("foo"); + _foo = function() { + return data; + }; + return data; +} +function use() { + console.log(_foo().foo); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.umd.js new file mode 100644 index 00000000000..7edfbec9e2f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-named/output.umd.js @@ -0,0 +1,16 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function use() { + console.log(_foo.foo); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/input.js new file mode 100644 index 00000000000..b2eb558f5eb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/input.js @@ -0,0 +1,5 @@ +import * as foo from "foo"; + +function use() { + console.log(foo); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.amd.js new file mode 100644 index 00000000000..f2d504e83e9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + function use() { + console.log(_foo); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.cjs new file mode 100644 index 00000000000..1675c99bbb8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.cjs @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _foo() { + const data = _interopRequireWildcard(require("foo")); + _foo = function() { + return data; + }; + return data; +} +function use() { + console.log(_foo()); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.umd.js new file mode 100644 index 00000000000..cc26ca8cd18 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-import-namespace/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + function use() { + console.log(_foo); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/input.js new file mode 100644 index 00000000000..9ec8f63ab2f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/input.js @@ -0,0 +1 @@ +export * from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.amd.js new file mode 100644 index 00000000000..2e1b4256446 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _exportStar(_foo, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.cjs new file mode 100644 index 00000000000..59c1df1a18a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +_exportStar(require("foo"), exports); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.umd.js new file mode 100644 index 00000000000..81a0ab21d12 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-all/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _exportStar(_foo, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/input.js new file mode 100644 index 00000000000..e69b23b83be --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/input.js @@ -0,0 +1,2 @@ +import foo from "foo"; +export { foo as default }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.amd.js new file mode 100644 index 00000000000..a778959dcc7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_foo.default, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.cjs new file mode 100644 index 00000000000..3596ca2c8a6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_foo().default, + enumerable: true +}); +function _foo() { + const data = _interopRequireDefault(require("foo")); + _foo = function() { + return data; + }; + return data; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.umd.js new file mode 100644 index 00000000000..7b8953ea116 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-default/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_foo.default, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/input.js new file mode 100644 index 00000000000..f799a47e3b5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/input.js @@ -0,0 +1,2 @@ +import { named } from "foo"; +export { named }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.amd.js new file mode 100644 index 00000000000..69757653728 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "named", { + get: ()=>_foo.named, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.cjs new file mode 100644 index 00000000000..49026210acc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "named", { + get: ()=>_foo().named, + enumerable: true +}); +function _foo() { + const data = require("foo"); + _foo = function() { + return data; + }; + return data; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.umd.js new file mode 100644 index 00000000000..f0a4d767a4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-named/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "named", { + get: ()=>_foo.named, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/input.js new file mode 100644 index 00000000000..c10ecafc51c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/input.js @@ -0,0 +1,2 @@ +import * as namespace from "foo"; +export { namespace }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.amd.js new file mode 100644 index 00000000000..a3e6cd9e387 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "namespace", { + get: ()=>_foo, + enumerable: true + }); + _foo = _interopRequireWildcard(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.cjs new file mode 100644 index 00000000000..a4d7e5ab5fe --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "namespace", { + get: ()=>_foo(), + enumerable: true +}); +function _foo() { + const data = _interopRequireWildcard(require("foo")); + _foo = function() { + return data; + }; + return data; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.umd.js new file mode 100644 index 00000000000..79e04f72a9a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-reexport-namespace/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "namespace", { + get: ()=>_foo, + enumerable: true + }); + _foo = _interopRequireWildcard(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/input.js new file mode 100644 index 00000000000..c0748305d53 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/input.js @@ -0,0 +1 @@ +import "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.amd.js new file mode 100644 index 00000000000..ff2bfa7b564 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.amd.js @@ -0,0 +1,10 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.cjs new file mode 100644 index 00000000000..43930bc8425 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.umd.js new file mode 100644 index 00000000000..71329065375 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/dep-sideeffect/output.umd.js @@ -0,0 +1,13 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/input.js new file mode 100644 index 00000000000..a61f72ca261 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/input.js @@ -0,0 +1 @@ +export { named1 } from "external"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.amd.js new file mode 100644 index 00000000000..ef785154283 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "external" +], function(require, exports, _external) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "named1", { + get: ()=>_external.named1, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.cjs new file mode 100644 index 00000000000..39c09900fce --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "named1", { + get: ()=>_external.named1, + enumerable: true +}); +function _external() { + const data = require("external"); + _external = function() { + return data; + }; + return data; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.umd.js new file mode 100644 index 00000000000..dc4e54f1a29 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/export-named/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("external")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "external" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.external); +})(this, function(exports, _external) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "named1", { + get: ()=>_external.named1, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/input.js new file mode 100644 index 00000000000..8128e9d3e47 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/input.js @@ -0,0 +1,6 @@ +import { local } from "./local"; +import { external } from "external"; + +function use() { + local(external); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/module.json new file mode 100644 index 00000000000..1f8576b0ec5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/module.json @@ -0,0 +1,7 @@ +{ + "lazy": { + "patterns": [ + "." + ] + } +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.amd.js new file mode 100644 index 00000000000..eec990b8d65 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "./local", + "external" +], function(require, exports, _local, _external) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function use() { + (0, _local.local)(_external.external); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.cjs new file mode 100644 index 00000000000..e0de3fadd66 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.cjs @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _local() { + const data = require("./local"); + _local = function() { + return data; + }; + return data; +} +function _external() { + const data = require("external"); + _external = function() { + return data; + }; + return data; +} +function use() { + _local().local(_external().external); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.umd.js new file mode 100644 index 00000000000..3d6074a0283 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-all-from-object-config/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./local"), require("external")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./local", + "external" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.local, global.external); +})(this, function(exports, _local, _external) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function use() { + (0, _local.local)(_external.external); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/input.js new file mode 100644 index 00000000000..a7bc0041a50 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/input.js @@ -0,0 +1,7 @@ +import { local } from "./local"; +import { external } from "external_test"; +import { test } from "test"; + +function use() { + local(external(test)); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/module.json new file mode 100644 index 00000000000..10a78d98a0f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/module.json @@ -0,0 +1,7 @@ +{ + "lazy": { + "patterns": [ + "^test$" + ] + } +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.amd.js new file mode 100644 index 00000000000..04cc2ad64f0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "./local", + "external_test", + "test" +], function(require, exports, _local, _externalTest, _test) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function use() { + (0, _local.local)((0, _externalTest.external)(_test.test)); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.cjs new file mode 100644 index 00000000000..cc07c369785 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.cjs @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _local = require("./local"); +const _externalTest = require("external_test"); +function _test() { + const data = require("test"); + _test = function() { + return data; + }; + return data; +} +function use() { + (0, _local.local)((0, _externalTest.external)(_test().test)); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.umd.js new file mode 100644 index 00000000000..4f7ab9bd468 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/import-only-allowed-from-object-config/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./local"), require("external_test"), require("test")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./local", + "external_test", + "test" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.local, global.externalTest, global.test); +})(this, function(exports, _local, _externalTest, _test) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function use() { + (0, _local.local)((0, _externalTest.external)(_test.test)); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/input.js new file mode 100644 index 00000000000..ee601dfe038 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/input.js @@ -0,0 +1,11 @@ +import { spawn } from "child_process"; + +function log() { + console.log(spawn); +} + +const other = () => { + const nestedClosure = () => { + spawn("ls"); + }; +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.amd.js new file mode 100644 index 00000000000..00d0c6a8861 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.amd.js @@ -0,0 +1,18 @@ +define([ + "require", + "exports", + "child_process" +], function(require, exports, _childProcess) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function log() { + console.log(_childProcess.spawn); + } + const other = ()=>{ + const nestedClosure = ()=>{ + (0, _childProcess.spawn)("ls"); + }; + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.cjs new file mode 100644 index 00000000000..6400c96ba63 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.cjs @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _childProcess() { + const data = require("child_process"); + _childProcess = function() { + return data; + }; + return data; +} +function log() { + console.log(_childProcess().spawn); +} +const other = ()=>{ + const nestedClosure = ()=>{ + _childProcess().spawn("ls"); + }; +}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.umd.js new file mode 100644 index 00000000000..cdeff46a50d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/1/output.umd.js @@ -0,0 +1,21 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("child_process")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "child_process" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.childProcess); +})(this, function(exports, _childProcess) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function log() { + console.log(_childProcess.spawn); + } + const other = ()=>{ + const nestedClosure = ()=>{ + (0, _childProcess.spawn)("ls"); + }; + }; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/input.js new file mode 100644 index 00000000000..821d06d19b8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/input.js @@ -0,0 +1,6 @@ +import { fn, Klass } from "lib"; + +function myFn() { + fn(); +} +class MyClass extends Klass {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.amd.js new file mode 100644 index 00000000000..32a30726718 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "lib" +], function(require, exports, _lib) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function myFn() { + (0, _lib.fn)(); + } + class MyClass extends _lib.Klass { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.cjs new file mode 100644 index 00000000000..8308bb868ae --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.cjs @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _lib() { + const data = require("lib"); + _lib = function() { + return data; + }; + return data; +} +function myFn() { + _lib().fn(); +} +class MyClass extends _lib().Klass { +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.umd.js new file mode 100644 index 00000000000..9681d4be00d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/issue-3081/2/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("lib")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "lib" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.lib); +})(this, function(exports, _lib) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function myFn() { + (0, _lib.fn)(); + } + class MyClass extends _lib.Klass { + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/input.js new file mode 100644 index 00000000000..4ff175b4985 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/input.js @@ -0,0 +1,3 @@ +import foo from "./foo"; + +console.log(foo); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.amd.js new file mode 100644 index 00000000000..d3d11e1da80 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.amd.js @@ -0,0 +1,12 @@ +define([ + "require", + "exports", + "./foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + console.log(_foo.default); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.cjs new file mode 100644 index 00000000000..0f29dd9dd30 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireDefault(require("./foo")); +console.log(_foo.default); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.umd.js new file mode 100644 index 00000000000..fcbd4a3bcb4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-default/output.umd.js @@ -0,0 +1,15 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + console.log(_foo.default); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/input.js new file mode 100644 index 00000000000..0fe883ae12b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/input.js @@ -0,0 +1,3 @@ +import { foo } from "./foo"; + +console.log(foo); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.amd.js new file mode 100644 index 00000000000..e12fde03ec8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "./foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + console.log(_foo.foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.cjs new file mode 100644 index 00000000000..86a458694ba --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = require("./foo"); +console.log(_foo.foo); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.umd.js new file mode 100644 index 00000000000..abacabdaa48 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-named/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + console.log(_foo.foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/input.js new file mode 100644 index 00000000000..3ed8b5bd70c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/input.js @@ -0,0 +1,3 @@ +import * as foo from "./foo"; + +console.log(foo); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.amd.js new file mode 100644 index 00000000000..46e94e1a8f9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.amd.js @@ -0,0 +1,12 @@ +define([ + "require", + "exports", + "./foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + console.log(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.cjs new file mode 100644 index 00000000000..34ca51092bc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireWildcard(require("./foo")); +console.log(_foo); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.umd.js new file mode 100644 index 00000000000..17b46a6d51f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-import-namespace/output.umd.js @@ -0,0 +1,15 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + console.log(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/input.js new file mode 100644 index 00000000000..5567e8d73a1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/input.js @@ -0,0 +1 @@ +export * from "./foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.amd.js new file mode 100644 index 00000000000..a9e63326bc4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "./foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _exportStar(_foo, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.cjs new file mode 100644 index 00000000000..fe19ca33e26 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +_exportStar(require("./foo"), exports); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.umd.js new file mode 100644 index 00000000000..8f7fc65be30 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-all/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _exportStar(_foo, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/input.js new file mode 100644 index 00000000000..2aede48ba85 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/input.js @@ -0,0 +1,2 @@ +import foo from "./foo"; +export { foo as default }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.amd.js new file mode 100644 index 00000000000..0d3b1177aa8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "./foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_foo.default, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.cjs new file mode 100644 index 00000000000..85020b7c440 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_foo.default, + enumerable: true +}); +const _foo = _interopRequireDefault(require("./foo")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.umd.js new file mode 100644 index 00000000000..2154e3a2f69 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-default/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_foo.default, + enumerable: true + }); + _foo = _interopRequireDefault(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/input.js new file mode 100644 index 00000000000..7855dc48bfe --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/input.js @@ -0,0 +1,2 @@ +import { named } from "./foo"; +export { named }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.amd.js new file mode 100644 index 00000000000..5fdfac250bf --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports", + "./foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "named", { + get: ()=>_foo.named, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.cjs new file mode 100644 index 00000000000..0c822fbdcc7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "named", { + get: ()=>_foo.named, + enumerable: true +}); +const _foo = require("./foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.umd.js new file mode 100644 index 00000000000..033220acb0a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-named/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "named", { + get: ()=>_foo.named, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/input.js new file mode 100644 index 00000000000..b44913ff896 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/input.js @@ -0,0 +1,2 @@ +import * as namespace from "./foo"; +export { namespace }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.amd.js new file mode 100644 index 00000000000..1b149e27b79 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "./foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "namespace", { + get: ()=>_foo, + enumerable: true + }); + _foo = _interopRequireWildcard(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.cjs new file mode 100644 index 00000000000..ca86f6aac77 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "namespace", { + get: ()=>_foo, + enumerable: true +}); +const _foo = _interopRequireWildcard(require("./foo")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.umd.js new file mode 100644 index 00000000000..fe7b322457f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-reexport-namespace/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "namespace", { + get: ()=>_foo, + enumerable: true + }); + _foo = _interopRequireWildcard(_foo); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/input.js new file mode 100644 index 00000000000..3a0ce29651f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/input.js @@ -0,0 +1 @@ +import "./a"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.amd.js new file mode 100644 index 00000000000..85f08edf1da --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.amd.js @@ -0,0 +1,10 @@ +define([ + "require", + "exports", + "./a" +], function(require, exports, _a) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.cjs new file mode 100644 index 00000000000..842f7dee901 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +require("./a"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.umd.js new file mode 100644 index 00000000000..aff2e96977e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/local-sideeffect/output.umd.js @@ -0,0 +1,13 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./a")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./a" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.a); +})(this, function(exports, _a) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/not-shadowed-by-labels/.input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/not-shadowed-by-labels/.input.js new file mode 100644 index 00000000000..2270a643f13 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/not-shadowed-by-labels/.input.js @@ -0,0 +1,10 @@ +import { x } from "lib"; + +function fn() { + x(); +} + +x: +console.log(1); + +continue x; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/not-shadowed-by-labels/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/not-shadowed-by-labels/module.json new file mode 100644 index 00000000000..e94b79a2ac8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/not-shadowed-by-labels/module.json @@ -0,0 +1,3 @@ +{ + "lazy": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/input.js new file mode 100644 index 00000000000..d82c2f5f598 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/input.js @@ -0,0 +1,7 @@ +import foo1 from "white"; + +console.log(foo1); + +import foo2 from "black"; + +console.log(foo2); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/module.json new file mode 100644 index 00000000000..639bb8f6fc6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/module.json @@ -0,0 +1,5 @@ +{ + "lazy": [ + "white" + ] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.amd.js new file mode 100644 index 00000000000..8526300ecbd --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "white", + "black" +], function(require, exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _white = _interopRequireDefault(_white); + _black = _interopRequireDefault(_black); + console.log(_white.default); + console.log(_black.default); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.cjs new file mode 100644 index 00000000000..653867523fb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.cjs @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _white() { + const data = _interopRequireDefault(require("white")); + _white = function() { + return data; + }; + return data; +} +const _black = _interopRequireDefault(require("black")); +console.log(_white().default); +console.log(_black.default); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.umd.js new file mode 100644 index 00000000000..6f555d66d8c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-default/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("white"), require("black")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "white", + "black" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.white, global.black); +})(this, function(exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _white = _interopRequireDefault(_white); + _black = _interopRequireDefault(_black); + console.log(_white.default); + console.log(_black.default); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/input.js new file mode 100644 index 00000000000..7971daffaf4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/input.js @@ -0,0 +1,11 @@ +import { foo1 } from "white"; + +function use1() { + console.log(foo1); +} + +import { foo2 } from "black"; + +function use2() { + console.log(foo2); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/module.json new file mode 100644 index 00000000000..639bb8f6fc6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/module.json @@ -0,0 +1,5 @@ +{ + "lazy": [ + "white" + ] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.amd.js new file mode 100644 index 00000000000..7f3fb9d3b14 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports", + "white", + "black" +], function(require, exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function use1() { + console.log(_white.foo1); + } + function use2() { + console.log(_black.foo2); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.cjs new file mode 100644 index 00000000000..d7ce7c4ddc2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.cjs @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _white() { + const data = require("white"); + _white = function() { + return data; + }; + return data; +} +const _black = require("black"); +function use1() { + console.log(_white().foo1); +} +function use2() { + console.log(_black.foo2); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.umd.js new file mode 100644 index 00000000000..1bf7b043264 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-named/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("white"), require("black")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "white", + "black" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.white, global.black); +})(this, function(exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function use1() { + console.log(_white.foo1); + } + function use2() { + console.log(_black.foo2); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/input.js new file mode 100644 index 00000000000..5e85cff79f3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/input.js @@ -0,0 +1,11 @@ +import * as foo1 from "white"; + +function use1() { + console.log(foo1); +} + +import * as foo2 from "black"; + +function use2() { + console.log(foo2); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/module.json new file mode 100644 index 00000000000..639bb8f6fc6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/module.json @@ -0,0 +1,5 @@ +{ + "lazy": [ + "white" + ] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.amd.js new file mode 100644 index 00000000000..989e4e8f645 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.amd.js @@ -0,0 +1,19 @@ +define([ + "require", + "exports", + "white", + "black" +], function(require, exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _white = _interopRequireWildcard(_white); + _black = _interopRequireWildcard(_black); + function use1() { + console.log(_white); + } + function use2() { + console.log(_black); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.cjs new file mode 100644 index 00000000000..3868a7bac44 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.cjs @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _white() { + const data = _interopRequireWildcard(require("white")); + _white = function() { + return data; + }; + return data; +} +const _black = _interopRequireWildcard(require("black")); +function use1() { + console.log(_white()); +} +function use2() { + console.log(_black); +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.umd.js new file mode 100644 index 00000000000..8bd8035bee1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/import-namespace/output.umd.js @@ -0,0 +1,22 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("white"), require("black")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "white", + "black" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.white, global.black); +})(this, function(exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _white = _interopRequireWildcard(_white); + _black = _interopRequireWildcard(_black); + function use1() { + console.log(_white); + } + function use2() { + console.log(_black); + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/input.js new file mode 100644 index 00000000000..c70969c6ae2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/input.js @@ -0,0 +1,3 @@ +export * from "white"; + +export * from "black"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/module.json new file mode 100644 index 00000000000..639bb8f6fc6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/module.json @@ -0,0 +1,5 @@ +{ + "lazy": [ + "white" + ] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.amd.js new file mode 100644 index 00000000000..42915499589 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.amd.js @@ -0,0 +1,13 @@ +define([ + "require", + "exports", + "white", + "black" +], function(require, exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _exportStar(_white, exports); + _exportStar(_black, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.cjs new file mode 100644 index 00000000000..507c13dab1a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +_exportStar(require("white"), exports); +_exportStar(require("black"), exports); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.umd.js new file mode 100644 index 00000000000..310b4d0e80c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-all/output.umd.js @@ -0,0 +1,16 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("white"), require("black")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "white", + "black" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.white, global.black); +})(this, function(exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _exportStar(_white, exports); + _exportStar(_black, exports); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/input.js new file mode 100644 index 00000000000..1aade34dee9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/input.js @@ -0,0 +1,2 @@ +import foo from "white"; +export { foo as default }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/module.json new file mode 100644 index 00000000000..639bb8f6fc6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/module.json @@ -0,0 +1,5 @@ +{ + "lazy": [ + "white" + ] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.amd.js new file mode 100644 index 00000000000..91c6a12662b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "white" +], function(require, exports, _white) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_white.default, + enumerable: true + }); + _white = _interopRequireDefault(_white); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.cjs new file mode 100644 index 00000000000..d82a9be8907 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_white().default, + enumerable: true +}); +function _white() { + const data = _interopRequireDefault(require("white")); + _white = function() { + return data; + }; + return data; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.umd.js new file mode 100644 index 00000000000..b18f56e25c9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-default/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("white")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "white" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.white); +})(this, function(exports, _white) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_white.default, + enumerable: true + }); + _white = _interopRequireDefault(_white); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/input.js new file mode 100644 index 00000000000..d119bdd2152 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/input.js @@ -0,0 +1,5 @@ +import { named1 } from "white"; +export { named1 }; + +import { named2 } from "black"; +export { named2 }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/module.json new file mode 100644 index 00000000000..639bb8f6fc6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/module.json @@ -0,0 +1,5 @@ +{ + "lazy": [ + "white" + ] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.amd.js new file mode 100644 index 00000000000..2bd7c0ef5fd --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.amd.js @@ -0,0 +1,21 @@ +define([ + "require", + "exports", + "white", + "black" +], function(require, exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + named1: ()=>_white.named1, + named2: ()=>_black.named2 + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.cjs new file mode 100644 index 00000000000..bc8259398bf --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.cjs @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + named1: ()=>_white().named1, + named2: ()=>_black.named2 +}); +function _white() { + const data = require("white"); + _white = function() { + return data; + }; + return data; +} +const _black = require("black"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.umd.js new file mode 100644 index 00000000000..57ad3156d56 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-named/output.umd.js @@ -0,0 +1,24 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("white"), require("black")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "white", + "black" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.white, global.black); +})(this, function(exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + named1: ()=>_white.named1, + named2: ()=>_black.named2 + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/input.js new file mode 100644 index 00000000000..608fac6689b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/input.js @@ -0,0 +1,5 @@ +import * as namespace1 from "white"; +export { namespace1 }; + +import * as namespace2 from "black"; +export { namespace2 }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/module.json new file mode 100644 index 00000000000..639bb8f6fc6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/module.json @@ -0,0 +1,5 @@ +{ + "lazy": [ + "white" + ] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.amd.js new file mode 100644 index 00000000000..f7105c80c7d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.amd.js @@ -0,0 +1,23 @@ +define([ + "require", + "exports", + "white", + "black" +], function(require, exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + namespace1: ()=>_white, + namespace2: ()=>_black + }); + _white = _interopRequireWildcard(_white); + _black = _interopRequireWildcard(_black); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.cjs new file mode 100644 index 00000000000..a24c9b52562 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.cjs @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + namespace1: ()=>_white(), + namespace2: ()=>_black +}); +function _white() { + const data = _interopRequireWildcard(require("white")); + _white = function() { + return data; + }; + return data; +} +const _black = _interopRequireWildcard(require("black")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.umd.js new file mode 100644 index 00000000000..044ec21126c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/reexport-namespace/output.umd.js @@ -0,0 +1,26 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("white"), require("black")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "white", + "black" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.white, global.black); +})(this, function(exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + namespace1: ()=>_white, + namespace2: ()=>_black + }); + _white = _interopRequireWildcard(_white); + _black = _interopRequireWildcard(_black); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/input.js new file mode 100644 index 00000000000..88280a23685 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/input.js @@ -0,0 +1,2 @@ +import "white"; +import "black"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/module.json new file mode 100644 index 00000000000..639bb8f6fc6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/module.json @@ -0,0 +1,5 @@ +{ + "lazy": [ + "white" + ] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.amd.js new file mode 100644 index 00000000000..66cd707c246 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "white", + "black" +], function(require, exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.cjs new file mode 100644 index 00000000000..08ae067bf1b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +require("white"); +require("black"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.umd.js new file mode 100644 index 00000000000..337353e9a5b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/lazy/whitelist/sideeffect/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("white"), require("black")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "white", + "black" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.white, global.black); +})(this, function(exports, _white, _black) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/many-exports-chunked/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/input.js similarity index 100% rename from crates/swc_ecma_transforms_module/tests/fixture/commonjs/many-exports-chunked/1/input.js rename to crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/input.js diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.amd.js new file mode 100644 index 00000000000..61628ece6e3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.amd.js @@ -0,0 +1,517 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + a000: ()=>a000, + a001: ()=>a001, + a002: ()=>a002, + a003: ()=>a003, + a004: ()=>a004, + a005: ()=>a005, + a006: ()=>a006, + a007: ()=>a007, + a008: ()=>a008, + a009: ()=>a009, + a010: ()=>a010, + a011: ()=>a011, + a012: ()=>a012, + a013: ()=>a013, + a014: ()=>a014, + a015: ()=>a015, + a016: ()=>a016, + a017: ()=>a017, + a018: ()=>a018, + a019: ()=>a019, + a020: ()=>a020, + a021: ()=>a021, + a022: ()=>a022, + a023: ()=>a023, + a024: ()=>a024, + a025: ()=>a025, + a026: ()=>a026, + a027: ()=>a027, + a028: ()=>a028, + a029: ()=>a029, + a030: ()=>a030, + a031: ()=>a031, + a032: ()=>a032, + a033: ()=>a033, + a034: ()=>a034, + a035: ()=>a035, + a036: ()=>a036, + a037: ()=>a037, + a038: ()=>a038, + a039: ()=>a039, + a040: ()=>a040, + a041: ()=>a041, + a042: ()=>a042, + a043: ()=>a043, + a044: ()=>a044, + a045: ()=>a045, + a046: ()=>a046, + a047: ()=>a047, + a048: ()=>a048, + a049: ()=>a049, + a050: ()=>a050, + a051: ()=>a051, + a052: ()=>a052, + a053: ()=>a053, + a054: ()=>a054, + a055: ()=>a055, + a056: ()=>a056, + a057: ()=>a057, + a058: ()=>a058, + a059: ()=>a059, + a060: ()=>a060, + a061: ()=>a061, + a062: ()=>a062, + a063: ()=>a063, + a064: ()=>a064, + a065: ()=>a065, + a066: ()=>a066, + a067: ()=>a067, + a068: ()=>a068, + a069: ()=>a069, + a070: ()=>a070, + a071: ()=>a071, + a072: ()=>a072, + a073: ()=>a073, + a074: ()=>a074, + a075: ()=>a075, + a076: ()=>a076, + a077: ()=>a077, + a078: ()=>a078, + a079: ()=>a079, + a080: ()=>a080, + a081: ()=>a081, + a082: ()=>a082, + a083: ()=>a083, + a084: ()=>a084, + a085: ()=>a085, + a086: ()=>a086, + a087: ()=>a087, + a088: ()=>a088, + a089: ()=>a089, + a090: ()=>a090, + a091: ()=>a091, + a092: ()=>a092, + a093: ()=>a093, + a094: ()=>a094, + a095: ()=>a095, + a096: ()=>a096, + a097: ()=>a097, + a098: ()=>a098, + a099: ()=>a099, + a100: ()=>a100, + a101: ()=>a101, + a102: ()=>a102, + a103: ()=>a103, + a104: ()=>a104, + a105: ()=>a105, + a106: ()=>a106, + a107: ()=>a107, + a108: ()=>a108, + a109: ()=>a109, + a110: ()=>a110, + a111: ()=>a111, + a112: ()=>a112, + a113: ()=>a113, + a114: ()=>a114, + a115: ()=>a115, + a116: ()=>a116, + a117: ()=>a117, + a118: ()=>a118, + a119: ()=>a119, + a120: ()=>a120, + a121: ()=>a121, + a122: ()=>a122, + a123: ()=>a123, + a124: ()=>a124, + a125: ()=>a125, + a126: ()=>a126, + a127: ()=>a127, + a128: ()=>a128, + a129: ()=>a129, + a130: ()=>a130, + a131: ()=>a131, + a132: ()=>a132, + a133: ()=>a133, + a134: ()=>a134, + a135: ()=>a135, + a136: ()=>a136, + a137: ()=>a137, + a138: ()=>a138, + a139: ()=>a139, + a140: ()=>a140, + a141: ()=>a141, + a142: ()=>a142, + a143: ()=>a143, + a144: ()=>a144, + a145: ()=>a145, + a146: ()=>a146, + a147: ()=>a147, + a148: ()=>a148, + a149: ()=>a149, + a150: ()=>a150, + a151: ()=>a151, + a152: ()=>a152, + a153: ()=>a153, + a154: ()=>a154, + a155: ()=>a155, + a156: ()=>a156, + a157: ()=>a157, + a158: ()=>a158, + a159: ()=>a159, + a160: ()=>a160, + a161: ()=>a161, + a162: ()=>a162, + a163: ()=>a163, + a164: ()=>a164, + a165: ()=>a165, + a166: ()=>a166, + a167: ()=>a167, + a168: ()=>a168, + a169: ()=>a169, + a170: ()=>a170, + a171: ()=>a171, + a172: ()=>a172, + a173: ()=>a173, + a174: ()=>a174, + a175: ()=>a175, + a176: ()=>a176, + a177: ()=>a177, + a178: ()=>a178, + a179: ()=>a179, + a180: ()=>a180, + a181: ()=>a181, + a182: ()=>a182, + a183: ()=>a183, + a184: ()=>a184, + a185: ()=>a185, + a186: ()=>a186, + a187: ()=>a187, + a188: ()=>a188, + a189: ()=>a189, + a190: ()=>a190, + a191: ()=>a191, + a192: ()=>a192, + a193: ()=>a193, + a194: ()=>a194, + a195: ()=>a195, + a196: ()=>a196, + a197: ()=>a197, + a198: ()=>a198, + a199: ()=>a199, + a200: ()=>a200, + a201: ()=>a201, + a202: ()=>a202, + a203: ()=>a203, + a204: ()=>a204, + a205: ()=>a205, + a206: ()=>a206, + a207: ()=>a207, + a208: ()=>a208, + a209: ()=>a209, + a210: ()=>a210, + a211: ()=>a211, + a212: ()=>a212, + a213: ()=>a213, + a214: ()=>a214, + a215: ()=>a215, + a216: ()=>a216, + a217: ()=>a217, + a218: ()=>a218, + a219: ()=>a219, + a220: ()=>a220, + a221: ()=>a221, + a222: ()=>a222, + a223: ()=>a223, + a224: ()=>a224, + a225: ()=>a225, + a226: ()=>a226, + a227: ()=>a227, + a228: ()=>a228, + a229: ()=>a229, + a230: ()=>a230, + a231: ()=>a231, + a232: ()=>a232, + a233: ()=>a233, + a234: ()=>a234, + a235: ()=>a235, + a236: ()=>a236, + a237: ()=>a237, + a238: ()=>a238, + a239: ()=>a239, + a240: ()=>a240, + a241: ()=>a241, + a242: ()=>a242, + a243: ()=>a243, + a244: ()=>a244, + a245: ()=>a245, + a246: ()=>a246, + a247: ()=>a247, + a248: ()=>a248, + a249: ()=>a249 + }); + const a000 = 0; + const a001 = 1; + const a002 = 2; + const a003 = 3; + const a004 = 4; + const a005 = 5; + const a006 = 6; + const a007 = 7; + const a008 = 8; + const a009 = 9; + const a010 = 10; + const a011 = 11; + const a012 = 12; + const a013 = 13; + const a014 = 14; + const a015 = 15; + const a016 = 16; + const a017 = 17; + const a018 = 18; + const a019 = 19; + const a020 = 20; + const a021 = 21; + const a022 = 22; + const a023 = 23; + const a024 = 24; + const a025 = 25; + const a026 = 26; + const a027 = 27; + const a028 = 28; + const a029 = 29; + const a030 = 30; + const a031 = 31; + const a032 = 32; + const a033 = 33; + const a034 = 34; + const a035 = 35; + const a036 = 36; + const a037 = 37; + const a038 = 38; + const a039 = 39; + const a040 = 40; + const a041 = 41; + const a042 = 42; + const a043 = 43; + const a044 = 44; + const a045 = 45; + const a046 = 46; + const a047 = 47; + const a048 = 48; + const a049 = 49; + const a050 = 50; + const a051 = 51; + const a052 = 52; + const a053 = 53; + const a054 = 54; + const a055 = 55; + const a056 = 56; + const a057 = 57; + const a058 = 58; + const a059 = 59; + const a060 = 60; + const a061 = 61; + const a062 = 62; + const a063 = 63; + const a064 = 64; + const a065 = 65; + const a066 = 66; + const a067 = 67; + const a068 = 68; + const a069 = 69; + const a070 = 70; + const a071 = 71; + const a072 = 72; + const a073 = 73; + const a074 = 74; + const a075 = 75; + const a076 = 76; + const a077 = 77; + const a078 = 78; + const a079 = 79; + const a080 = 80; + const a081 = 81; + const a082 = 82; + const a083 = 83; + const a084 = 84; + const a085 = 85; + const a086 = 86; + const a087 = 87; + const a088 = 88; + const a089 = 89; + const a090 = 90; + const a091 = 91; + const a092 = 92; + const a093 = 93; + const a094 = 94; + const a095 = 95; + const a096 = 96; + const a097 = 97; + const a098 = 98; + const a099 = 99; + const a100 = 100; + const a101 = 101; + const a102 = 102; + const a103 = 103; + const a104 = 104; + const a105 = 105; + const a106 = 106; + const a107 = 107; + const a108 = 108; + const a109 = 109; + const a110 = 110; + const a111 = 111; + const a112 = 112; + const a113 = 113; + const a114 = 114; + const a115 = 115; + const a116 = 116; + const a117 = 117; + const a118 = 118; + const a119 = 119; + const a120 = 120; + const a121 = 121; + const a122 = 122; + const a123 = 123; + const a124 = 124; + const a125 = 125; + const a126 = 126; + const a127 = 127; + const a128 = 128; + const a129 = 129; + const a130 = 130; + const a131 = 131; + const a132 = 132; + const a133 = 133; + const a134 = 134; + const a135 = 135; + const a136 = 136; + const a137 = 137; + const a138 = 138; + const a139 = 139; + const a140 = 140; + const a141 = 141; + const a142 = 142; + const a143 = 143; + const a144 = 144; + const a145 = 145; + const a146 = 146; + const a147 = 147; + const a148 = 148; + const a149 = 149; + const a150 = 150; + const a151 = 151; + const a152 = 152; + const a153 = 153; + const a154 = 154; + const a155 = 155; + const a156 = 156; + const a157 = 157; + const a158 = 158; + const a159 = 159; + const a160 = 160; + const a161 = 161; + const a162 = 162; + const a163 = 163; + const a164 = 164; + const a165 = 165; + const a166 = 166; + const a167 = 167; + const a168 = 168; + const a169 = 169; + const a170 = 170; + const a171 = 171; + const a172 = 172; + const a173 = 173; + const a174 = 174; + const a175 = 175; + const a176 = 176; + const a177 = 177; + const a178 = 178; + const a179 = 179; + const a180 = 180; + const a181 = 181; + const a182 = 182; + const a183 = 183; + const a184 = 184; + const a185 = 185; + const a186 = 186; + const a187 = 187; + const a188 = 188; + const a189 = 189; + const a190 = 190; + const a191 = 191; + const a192 = 192; + const a193 = 193; + const a194 = 194; + const a195 = 195; + const a196 = 196; + const a197 = 197; + const a198 = 198; + const a199 = 199; + const a200 = 200; + const a201 = 201; + const a202 = 202; + const a203 = 203; + const a204 = 204; + const a205 = 205; + const a206 = 206; + const a207 = 207; + const a208 = 208; + const a209 = 209; + const a210 = 210; + const a211 = 211; + const a212 = 212; + const a213 = 213; + const a214 = 214; + const a215 = 215; + const a216 = 216; + const a217 = 217; + const a218 = 218; + const a219 = 219; + const a220 = 220; + const a221 = 221; + const a222 = 222; + const a223 = 223; + const a224 = 224; + const a225 = 225; + const a226 = 226; + const a227 = 227; + const a228 = 228; + const a229 = 229; + const a230 = 230; + const a231 = 231; + const a232 = 232; + const a233 = 233; + const a234 = 234; + const a235 = 235; + const a236 = 236; + const a237 = 237; + const a238 = 238; + const a239 = 239; + const a240 = 240; + const a241 = 241; + const a242 = 242; + const a243 = 243; + const a244 = 244; + const a245 = 245; + const a246 = 246; + const a247 = 247; + const a248 = 248; + const a249 = 249; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.cjs new file mode 100644 index 00000000000..d3b65a04821 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.cjs @@ -0,0 +1,512 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + a000: ()=>a000, + a001: ()=>a001, + a002: ()=>a002, + a003: ()=>a003, + a004: ()=>a004, + a005: ()=>a005, + a006: ()=>a006, + a007: ()=>a007, + a008: ()=>a008, + a009: ()=>a009, + a010: ()=>a010, + a011: ()=>a011, + a012: ()=>a012, + a013: ()=>a013, + a014: ()=>a014, + a015: ()=>a015, + a016: ()=>a016, + a017: ()=>a017, + a018: ()=>a018, + a019: ()=>a019, + a020: ()=>a020, + a021: ()=>a021, + a022: ()=>a022, + a023: ()=>a023, + a024: ()=>a024, + a025: ()=>a025, + a026: ()=>a026, + a027: ()=>a027, + a028: ()=>a028, + a029: ()=>a029, + a030: ()=>a030, + a031: ()=>a031, + a032: ()=>a032, + a033: ()=>a033, + a034: ()=>a034, + a035: ()=>a035, + a036: ()=>a036, + a037: ()=>a037, + a038: ()=>a038, + a039: ()=>a039, + a040: ()=>a040, + a041: ()=>a041, + a042: ()=>a042, + a043: ()=>a043, + a044: ()=>a044, + a045: ()=>a045, + a046: ()=>a046, + a047: ()=>a047, + a048: ()=>a048, + a049: ()=>a049, + a050: ()=>a050, + a051: ()=>a051, + a052: ()=>a052, + a053: ()=>a053, + a054: ()=>a054, + a055: ()=>a055, + a056: ()=>a056, + a057: ()=>a057, + a058: ()=>a058, + a059: ()=>a059, + a060: ()=>a060, + a061: ()=>a061, + a062: ()=>a062, + a063: ()=>a063, + a064: ()=>a064, + a065: ()=>a065, + a066: ()=>a066, + a067: ()=>a067, + a068: ()=>a068, + a069: ()=>a069, + a070: ()=>a070, + a071: ()=>a071, + a072: ()=>a072, + a073: ()=>a073, + a074: ()=>a074, + a075: ()=>a075, + a076: ()=>a076, + a077: ()=>a077, + a078: ()=>a078, + a079: ()=>a079, + a080: ()=>a080, + a081: ()=>a081, + a082: ()=>a082, + a083: ()=>a083, + a084: ()=>a084, + a085: ()=>a085, + a086: ()=>a086, + a087: ()=>a087, + a088: ()=>a088, + a089: ()=>a089, + a090: ()=>a090, + a091: ()=>a091, + a092: ()=>a092, + a093: ()=>a093, + a094: ()=>a094, + a095: ()=>a095, + a096: ()=>a096, + a097: ()=>a097, + a098: ()=>a098, + a099: ()=>a099, + a100: ()=>a100, + a101: ()=>a101, + a102: ()=>a102, + a103: ()=>a103, + a104: ()=>a104, + a105: ()=>a105, + a106: ()=>a106, + a107: ()=>a107, + a108: ()=>a108, + a109: ()=>a109, + a110: ()=>a110, + a111: ()=>a111, + a112: ()=>a112, + a113: ()=>a113, + a114: ()=>a114, + a115: ()=>a115, + a116: ()=>a116, + a117: ()=>a117, + a118: ()=>a118, + a119: ()=>a119, + a120: ()=>a120, + a121: ()=>a121, + a122: ()=>a122, + a123: ()=>a123, + a124: ()=>a124, + a125: ()=>a125, + a126: ()=>a126, + a127: ()=>a127, + a128: ()=>a128, + a129: ()=>a129, + a130: ()=>a130, + a131: ()=>a131, + a132: ()=>a132, + a133: ()=>a133, + a134: ()=>a134, + a135: ()=>a135, + a136: ()=>a136, + a137: ()=>a137, + a138: ()=>a138, + a139: ()=>a139, + a140: ()=>a140, + a141: ()=>a141, + a142: ()=>a142, + a143: ()=>a143, + a144: ()=>a144, + a145: ()=>a145, + a146: ()=>a146, + a147: ()=>a147, + a148: ()=>a148, + a149: ()=>a149, + a150: ()=>a150, + a151: ()=>a151, + a152: ()=>a152, + a153: ()=>a153, + a154: ()=>a154, + a155: ()=>a155, + a156: ()=>a156, + a157: ()=>a157, + a158: ()=>a158, + a159: ()=>a159, + a160: ()=>a160, + a161: ()=>a161, + a162: ()=>a162, + a163: ()=>a163, + a164: ()=>a164, + a165: ()=>a165, + a166: ()=>a166, + a167: ()=>a167, + a168: ()=>a168, + a169: ()=>a169, + a170: ()=>a170, + a171: ()=>a171, + a172: ()=>a172, + a173: ()=>a173, + a174: ()=>a174, + a175: ()=>a175, + a176: ()=>a176, + a177: ()=>a177, + a178: ()=>a178, + a179: ()=>a179, + a180: ()=>a180, + a181: ()=>a181, + a182: ()=>a182, + a183: ()=>a183, + a184: ()=>a184, + a185: ()=>a185, + a186: ()=>a186, + a187: ()=>a187, + a188: ()=>a188, + a189: ()=>a189, + a190: ()=>a190, + a191: ()=>a191, + a192: ()=>a192, + a193: ()=>a193, + a194: ()=>a194, + a195: ()=>a195, + a196: ()=>a196, + a197: ()=>a197, + a198: ()=>a198, + a199: ()=>a199, + a200: ()=>a200, + a201: ()=>a201, + a202: ()=>a202, + a203: ()=>a203, + a204: ()=>a204, + a205: ()=>a205, + a206: ()=>a206, + a207: ()=>a207, + a208: ()=>a208, + a209: ()=>a209, + a210: ()=>a210, + a211: ()=>a211, + a212: ()=>a212, + a213: ()=>a213, + a214: ()=>a214, + a215: ()=>a215, + a216: ()=>a216, + a217: ()=>a217, + a218: ()=>a218, + a219: ()=>a219, + a220: ()=>a220, + a221: ()=>a221, + a222: ()=>a222, + a223: ()=>a223, + a224: ()=>a224, + a225: ()=>a225, + a226: ()=>a226, + a227: ()=>a227, + a228: ()=>a228, + a229: ()=>a229, + a230: ()=>a230, + a231: ()=>a231, + a232: ()=>a232, + a233: ()=>a233, + a234: ()=>a234, + a235: ()=>a235, + a236: ()=>a236, + a237: ()=>a237, + a238: ()=>a238, + a239: ()=>a239, + a240: ()=>a240, + a241: ()=>a241, + a242: ()=>a242, + a243: ()=>a243, + a244: ()=>a244, + a245: ()=>a245, + a246: ()=>a246, + a247: ()=>a247, + a248: ()=>a248, + a249: ()=>a249 +}); +const a000 = 0; +const a001 = 1; +const a002 = 2; +const a003 = 3; +const a004 = 4; +const a005 = 5; +const a006 = 6; +const a007 = 7; +const a008 = 8; +const a009 = 9; +const a010 = 10; +const a011 = 11; +const a012 = 12; +const a013 = 13; +const a014 = 14; +const a015 = 15; +const a016 = 16; +const a017 = 17; +const a018 = 18; +const a019 = 19; +const a020 = 20; +const a021 = 21; +const a022 = 22; +const a023 = 23; +const a024 = 24; +const a025 = 25; +const a026 = 26; +const a027 = 27; +const a028 = 28; +const a029 = 29; +const a030 = 30; +const a031 = 31; +const a032 = 32; +const a033 = 33; +const a034 = 34; +const a035 = 35; +const a036 = 36; +const a037 = 37; +const a038 = 38; +const a039 = 39; +const a040 = 40; +const a041 = 41; +const a042 = 42; +const a043 = 43; +const a044 = 44; +const a045 = 45; +const a046 = 46; +const a047 = 47; +const a048 = 48; +const a049 = 49; +const a050 = 50; +const a051 = 51; +const a052 = 52; +const a053 = 53; +const a054 = 54; +const a055 = 55; +const a056 = 56; +const a057 = 57; +const a058 = 58; +const a059 = 59; +const a060 = 60; +const a061 = 61; +const a062 = 62; +const a063 = 63; +const a064 = 64; +const a065 = 65; +const a066 = 66; +const a067 = 67; +const a068 = 68; +const a069 = 69; +const a070 = 70; +const a071 = 71; +const a072 = 72; +const a073 = 73; +const a074 = 74; +const a075 = 75; +const a076 = 76; +const a077 = 77; +const a078 = 78; +const a079 = 79; +const a080 = 80; +const a081 = 81; +const a082 = 82; +const a083 = 83; +const a084 = 84; +const a085 = 85; +const a086 = 86; +const a087 = 87; +const a088 = 88; +const a089 = 89; +const a090 = 90; +const a091 = 91; +const a092 = 92; +const a093 = 93; +const a094 = 94; +const a095 = 95; +const a096 = 96; +const a097 = 97; +const a098 = 98; +const a099 = 99; +const a100 = 100; +const a101 = 101; +const a102 = 102; +const a103 = 103; +const a104 = 104; +const a105 = 105; +const a106 = 106; +const a107 = 107; +const a108 = 108; +const a109 = 109; +const a110 = 110; +const a111 = 111; +const a112 = 112; +const a113 = 113; +const a114 = 114; +const a115 = 115; +const a116 = 116; +const a117 = 117; +const a118 = 118; +const a119 = 119; +const a120 = 120; +const a121 = 121; +const a122 = 122; +const a123 = 123; +const a124 = 124; +const a125 = 125; +const a126 = 126; +const a127 = 127; +const a128 = 128; +const a129 = 129; +const a130 = 130; +const a131 = 131; +const a132 = 132; +const a133 = 133; +const a134 = 134; +const a135 = 135; +const a136 = 136; +const a137 = 137; +const a138 = 138; +const a139 = 139; +const a140 = 140; +const a141 = 141; +const a142 = 142; +const a143 = 143; +const a144 = 144; +const a145 = 145; +const a146 = 146; +const a147 = 147; +const a148 = 148; +const a149 = 149; +const a150 = 150; +const a151 = 151; +const a152 = 152; +const a153 = 153; +const a154 = 154; +const a155 = 155; +const a156 = 156; +const a157 = 157; +const a158 = 158; +const a159 = 159; +const a160 = 160; +const a161 = 161; +const a162 = 162; +const a163 = 163; +const a164 = 164; +const a165 = 165; +const a166 = 166; +const a167 = 167; +const a168 = 168; +const a169 = 169; +const a170 = 170; +const a171 = 171; +const a172 = 172; +const a173 = 173; +const a174 = 174; +const a175 = 175; +const a176 = 176; +const a177 = 177; +const a178 = 178; +const a179 = 179; +const a180 = 180; +const a181 = 181; +const a182 = 182; +const a183 = 183; +const a184 = 184; +const a185 = 185; +const a186 = 186; +const a187 = 187; +const a188 = 188; +const a189 = 189; +const a190 = 190; +const a191 = 191; +const a192 = 192; +const a193 = 193; +const a194 = 194; +const a195 = 195; +const a196 = 196; +const a197 = 197; +const a198 = 198; +const a199 = 199; +const a200 = 200; +const a201 = 201; +const a202 = 202; +const a203 = 203; +const a204 = 204; +const a205 = 205; +const a206 = 206; +const a207 = 207; +const a208 = 208; +const a209 = 209; +const a210 = 210; +const a211 = 211; +const a212 = 212; +const a213 = 213; +const a214 = 214; +const a215 = 215; +const a216 = 216; +const a217 = 217; +const a218 = 218; +const a219 = 219; +const a220 = 220; +const a221 = 221; +const a222 = 222; +const a223 = 223; +const a224 = 224; +const a225 = 225; +const a226 = 226; +const a227 = 227; +const a228 = 228; +const a229 = 229; +const a230 = 230; +const a231 = 231; +const a232 = 232; +const a233 = 233; +const a234 = 234; +const a235 = 235; +const a236 = 236; +const a237 = 237; +const a238 = 238; +const a239 = 239; +const a240 = 240; +const a241 = 241; +const a242 = 242; +const a243 = 243; +const a244 = 244; +const a245 = 245; +const a246 = 246; +const a247 = 247; +const a248 = 248; +const a249 = 249; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.umd.js new file mode 100644 index 00000000000..db4b9915e7c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/many-exports-chunked/1/output.umd.js @@ -0,0 +1,520 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + a000: ()=>a000, + a001: ()=>a001, + a002: ()=>a002, + a003: ()=>a003, + a004: ()=>a004, + a005: ()=>a005, + a006: ()=>a006, + a007: ()=>a007, + a008: ()=>a008, + a009: ()=>a009, + a010: ()=>a010, + a011: ()=>a011, + a012: ()=>a012, + a013: ()=>a013, + a014: ()=>a014, + a015: ()=>a015, + a016: ()=>a016, + a017: ()=>a017, + a018: ()=>a018, + a019: ()=>a019, + a020: ()=>a020, + a021: ()=>a021, + a022: ()=>a022, + a023: ()=>a023, + a024: ()=>a024, + a025: ()=>a025, + a026: ()=>a026, + a027: ()=>a027, + a028: ()=>a028, + a029: ()=>a029, + a030: ()=>a030, + a031: ()=>a031, + a032: ()=>a032, + a033: ()=>a033, + a034: ()=>a034, + a035: ()=>a035, + a036: ()=>a036, + a037: ()=>a037, + a038: ()=>a038, + a039: ()=>a039, + a040: ()=>a040, + a041: ()=>a041, + a042: ()=>a042, + a043: ()=>a043, + a044: ()=>a044, + a045: ()=>a045, + a046: ()=>a046, + a047: ()=>a047, + a048: ()=>a048, + a049: ()=>a049, + a050: ()=>a050, + a051: ()=>a051, + a052: ()=>a052, + a053: ()=>a053, + a054: ()=>a054, + a055: ()=>a055, + a056: ()=>a056, + a057: ()=>a057, + a058: ()=>a058, + a059: ()=>a059, + a060: ()=>a060, + a061: ()=>a061, + a062: ()=>a062, + a063: ()=>a063, + a064: ()=>a064, + a065: ()=>a065, + a066: ()=>a066, + a067: ()=>a067, + a068: ()=>a068, + a069: ()=>a069, + a070: ()=>a070, + a071: ()=>a071, + a072: ()=>a072, + a073: ()=>a073, + a074: ()=>a074, + a075: ()=>a075, + a076: ()=>a076, + a077: ()=>a077, + a078: ()=>a078, + a079: ()=>a079, + a080: ()=>a080, + a081: ()=>a081, + a082: ()=>a082, + a083: ()=>a083, + a084: ()=>a084, + a085: ()=>a085, + a086: ()=>a086, + a087: ()=>a087, + a088: ()=>a088, + a089: ()=>a089, + a090: ()=>a090, + a091: ()=>a091, + a092: ()=>a092, + a093: ()=>a093, + a094: ()=>a094, + a095: ()=>a095, + a096: ()=>a096, + a097: ()=>a097, + a098: ()=>a098, + a099: ()=>a099, + a100: ()=>a100, + a101: ()=>a101, + a102: ()=>a102, + a103: ()=>a103, + a104: ()=>a104, + a105: ()=>a105, + a106: ()=>a106, + a107: ()=>a107, + a108: ()=>a108, + a109: ()=>a109, + a110: ()=>a110, + a111: ()=>a111, + a112: ()=>a112, + a113: ()=>a113, + a114: ()=>a114, + a115: ()=>a115, + a116: ()=>a116, + a117: ()=>a117, + a118: ()=>a118, + a119: ()=>a119, + a120: ()=>a120, + a121: ()=>a121, + a122: ()=>a122, + a123: ()=>a123, + a124: ()=>a124, + a125: ()=>a125, + a126: ()=>a126, + a127: ()=>a127, + a128: ()=>a128, + a129: ()=>a129, + a130: ()=>a130, + a131: ()=>a131, + a132: ()=>a132, + a133: ()=>a133, + a134: ()=>a134, + a135: ()=>a135, + a136: ()=>a136, + a137: ()=>a137, + a138: ()=>a138, + a139: ()=>a139, + a140: ()=>a140, + a141: ()=>a141, + a142: ()=>a142, + a143: ()=>a143, + a144: ()=>a144, + a145: ()=>a145, + a146: ()=>a146, + a147: ()=>a147, + a148: ()=>a148, + a149: ()=>a149, + a150: ()=>a150, + a151: ()=>a151, + a152: ()=>a152, + a153: ()=>a153, + a154: ()=>a154, + a155: ()=>a155, + a156: ()=>a156, + a157: ()=>a157, + a158: ()=>a158, + a159: ()=>a159, + a160: ()=>a160, + a161: ()=>a161, + a162: ()=>a162, + a163: ()=>a163, + a164: ()=>a164, + a165: ()=>a165, + a166: ()=>a166, + a167: ()=>a167, + a168: ()=>a168, + a169: ()=>a169, + a170: ()=>a170, + a171: ()=>a171, + a172: ()=>a172, + a173: ()=>a173, + a174: ()=>a174, + a175: ()=>a175, + a176: ()=>a176, + a177: ()=>a177, + a178: ()=>a178, + a179: ()=>a179, + a180: ()=>a180, + a181: ()=>a181, + a182: ()=>a182, + a183: ()=>a183, + a184: ()=>a184, + a185: ()=>a185, + a186: ()=>a186, + a187: ()=>a187, + a188: ()=>a188, + a189: ()=>a189, + a190: ()=>a190, + a191: ()=>a191, + a192: ()=>a192, + a193: ()=>a193, + a194: ()=>a194, + a195: ()=>a195, + a196: ()=>a196, + a197: ()=>a197, + a198: ()=>a198, + a199: ()=>a199, + a200: ()=>a200, + a201: ()=>a201, + a202: ()=>a202, + a203: ()=>a203, + a204: ()=>a204, + a205: ()=>a205, + a206: ()=>a206, + a207: ()=>a207, + a208: ()=>a208, + a209: ()=>a209, + a210: ()=>a210, + a211: ()=>a211, + a212: ()=>a212, + a213: ()=>a213, + a214: ()=>a214, + a215: ()=>a215, + a216: ()=>a216, + a217: ()=>a217, + a218: ()=>a218, + a219: ()=>a219, + a220: ()=>a220, + a221: ()=>a221, + a222: ()=>a222, + a223: ()=>a223, + a224: ()=>a224, + a225: ()=>a225, + a226: ()=>a226, + a227: ()=>a227, + a228: ()=>a228, + a229: ()=>a229, + a230: ()=>a230, + a231: ()=>a231, + a232: ()=>a232, + a233: ()=>a233, + a234: ()=>a234, + a235: ()=>a235, + a236: ()=>a236, + a237: ()=>a237, + a238: ()=>a238, + a239: ()=>a239, + a240: ()=>a240, + a241: ()=>a241, + a242: ()=>a242, + a243: ()=>a243, + a244: ()=>a244, + a245: ()=>a245, + a246: ()=>a246, + a247: ()=>a247, + a248: ()=>a248, + a249: ()=>a249 + }); + const a000 = 0; + const a001 = 1; + const a002 = 2; + const a003 = 3; + const a004 = 4; + const a005 = 5; + const a006 = 6; + const a007 = 7; + const a008 = 8; + const a009 = 9; + const a010 = 10; + const a011 = 11; + const a012 = 12; + const a013 = 13; + const a014 = 14; + const a015 = 15; + const a016 = 16; + const a017 = 17; + const a018 = 18; + const a019 = 19; + const a020 = 20; + const a021 = 21; + const a022 = 22; + const a023 = 23; + const a024 = 24; + const a025 = 25; + const a026 = 26; + const a027 = 27; + const a028 = 28; + const a029 = 29; + const a030 = 30; + const a031 = 31; + const a032 = 32; + const a033 = 33; + const a034 = 34; + const a035 = 35; + const a036 = 36; + const a037 = 37; + const a038 = 38; + const a039 = 39; + const a040 = 40; + const a041 = 41; + const a042 = 42; + const a043 = 43; + const a044 = 44; + const a045 = 45; + const a046 = 46; + const a047 = 47; + const a048 = 48; + const a049 = 49; + const a050 = 50; + const a051 = 51; + const a052 = 52; + const a053 = 53; + const a054 = 54; + const a055 = 55; + const a056 = 56; + const a057 = 57; + const a058 = 58; + const a059 = 59; + const a060 = 60; + const a061 = 61; + const a062 = 62; + const a063 = 63; + const a064 = 64; + const a065 = 65; + const a066 = 66; + const a067 = 67; + const a068 = 68; + const a069 = 69; + const a070 = 70; + const a071 = 71; + const a072 = 72; + const a073 = 73; + const a074 = 74; + const a075 = 75; + const a076 = 76; + const a077 = 77; + const a078 = 78; + const a079 = 79; + const a080 = 80; + const a081 = 81; + const a082 = 82; + const a083 = 83; + const a084 = 84; + const a085 = 85; + const a086 = 86; + const a087 = 87; + const a088 = 88; + const a089 = 89; + const a090 = 90; + const a091 = 91; + const a092 = 92; + const a093 = 93; + const a094 = 94; + const a095 = 95; + const a096 = 96; + const a097 = 97; + const a098 = 98; + const a099 = 99; + const a100 = 100; + const a101 = 101; + const a102 = 102; + const a103 = 103; + const a104 = 104; + const a105 = 105; + const a106 = 106; + const a107 = 107; + const a108 = 108; + const a109 = 109; + const a110 = 110; + const a111 = 111; + const a112 = 112; + const a113 = 113; + const a114 = 114; + const a115 = 115; + const a116 = 116; + const a117 = 117; + const a118 = 118; + const a119 = 119; + const a120 = 120; + const a121 = 121; + const a122 = 122; + const a123 = 123; + const a124 = 124; + const a125 = 125; + const a126 = 126; + const a127 = 127; + const a128 = 128; + const a129 = 129; + const a130 = 130; + const a131 = 131; + const a132 = 132; + const a133 = 133; + const a134 = 134; + const a135 = 135; + const a136 = 136; + const a137 = 137; + const a138 = 138; + const a139 = 139; + const a140 = 140; + const a141 = 141; + const a142 = 142; + const a143 = 143; + const a144 = 144; + const a145 = 145; + const a146 = 146; + const a147 = 147; + const a148 = 148; + const a149 = 149; + const a150 = 150; + const a151 = 151; + const a152 = 152; + const a153 = 153; + const a154 = 154; + const a155 = 155; + const a156 = 156; + const a157 = 157; + const a158 = 158; + const a159 = 159; + const a160 = 160; + const a161 = 161; + const a162 = 162; + const a163 = 163; + const a164 = 164; + const a165 = 165; + const a166 = 166; + const a167 = 167; + const a168 = 168; + const a169 = 169; + const a170 = 170; + const a171 = 171; + const a172 = 172; + const a173 = 173; + const a174 = 174; + const a175 = 175; + const a176 = 176; + const a177 = 177; + const a178 = 178; + const a179 = 179; + const a180 = 180; + const a181 = 181; + const a182 = 182; + const a183 = 183; + const a184 = 184; + const a185 = 185; + const a186 = 186; + const a187 = 187; + const a188 = 188; + const a189 = 189; + const a190 = 190; + const a191 = 191; + const a192 = 192; + const a193 = 193; + const a194 = 194; + const a195 = 195; + const a196 = 196; + const a197 = 197; + const a198 = 198; + const a199 = 199; + const a200 = 200; + const a201 = 201; + const a202 = 202; + const a203 = 203; + const a204 = 204; + const a205 = 205; + const a206 = 206; + const a207 = 207; + const a208 = 208; + const a209 = 209; + const a210 = 210; + const a211 = 211; + const a212 = 212; + const a213 = 213; + const a214 = 214; + const a215 = 215; + const a216 = 216; + const a217 = 217; + const a218 = 218; + const a219 = 219; + const a220 = 220; + const a221 = 221; + const a222 = 222; + const a223 = 223; + const a224 = 224; + const a225 = 225; + const a226 = 226; + const a227 = 227; + const a228 = 228; + const a229 = 229; + const a230 = 230; + const a231 = 231; + const a232 = 232; + const a233 = 233; + const a234 = 234; + const a235 = 235; + const a236 = 236; + const a237 = 237; + const a238 = 238; + const a239 = 239; + const a240 = 240; + const a241 = 241; + const a242 = 242; + const a243 = 243; + const a244 = 244; + const a245 = 245; + const a246 = 246; + const a247 = 247; + const a248 = 248; + const a249 = 249; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/input.js new file mode 100644 index 00000000000..e27e71f87ce --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/input.js @@ -0,0 +1,3 @@ +import Foo, { baz } from "./moduleWithGetter"; + +export { baz, Foo }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.amd.js new file mode 100644 index 00000000000..7081d8e97bd --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.amd.js @@ -0,0 +1,21 @@ +define([ + "require", + "exports", + "./moduleWithGetter" +], function(require, exports, _moduleWithGetter) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + Foo: ()=>_moduleWithGetter.default, + baz: ()=>_moduleWithGetter.baz + }); + _moduleWithGetter = _interopRequireWildcard(_moduleWithGetter); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.cjs new file mode 100644 index 00000000000..7bded0ce40a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + Foo: ()=>_moduleWithGetter.default, + baz: ()=>_moduleWithGetter.baz +}); +const _moduleWithGetter = _interopRequireWildcard(require("./moduleWithGetter")); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.umd.js new file mode 100644 index 00000000000..189d37e7c26 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/copy-getters-setters/output.umd.js @@ -0,0 +1,24 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./moduleWithGetter")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./moduleWithGetter" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.moduleWithGetter); +})(this, function(exports, _moduleWithGetter) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + Foo: ()=>_moduleWithGetter.default, + baz: ()=>_moduleWithGetter.baz + }); + _moduleWithGetter = _interopRequireWildcard(_moduleWithGetter); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/input.js new file mode 100644 index 00000000000..2b6d8c761a2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/input.js @@ -0,0 +1,17 @@ +import Foo from "foo"; + +import * as Bar from "bar"; + +import { Baz } from "baz"; + +Foo = 42; +Bar = 43; +Baz = 44; + +({ Foo } = {}); +({ Bar } = {}); +({ Baz } = {}); + +({ prop: Foo } = {}); +({ prop: Bar } = {}); +({ prop: Baz } = {}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.amd.js new file mode 100644 index 00000000000..5e264973b19 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.amd.js @@ -0,0 +1,23 @@ +define([ + "require", + "exports", + "foo", + "bar", + "baz" +], function(require, exports, _foo, _bar, _baz) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _bar = _interopRequireWildcard(_bar); + Foo = 42; + Bar = 43; + Baz = 44; + ({ Foo } = {}); + ({ Bar } = {}); + ({ Baz } = {}); + ({ prop: Foo } = {}); + ({ prop: Bar } = {}); + ({ prop: Baz } = {}); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.cjs new file mode 100644 index 00000000000..4cb635cdf12 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.cjs @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireDefault(require("foo")); +const _bar = _interopRequireWildcard(require("bar")); +const _baz = require("baz"); +Foo = 42; +Bar = 43; +Baz = 44; +({ Foo } = {}); +({ Bar } = {}); +({ Baz } = {}); +({ prop: Foo } = {}); +({ prop: Bar } = {}); +({ prop: Baz } = {}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.umd.js new file mode 100644 index 00000000000..b30b627b0d5 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/import-const-throw/output.umd.js @@ -0,0 +1,26 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo"), require("bar"), require("baz")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo", + "bar", + "baz" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo, global.bar, global.baz); +})(this, function(exports, _foo, _bar, _baz) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireDefault(_foo); + _bar = _interopRequireWildcard(_bar); + Foo = 42; + Bar = 43; + Baz = 44; + ({ Foo } = {}); + ({ Bar } = {}); + ({ Baz } = {}); + ({ prop: Foo } = {}); + ({ prop: Bar } = {}); + ({ prop: Baz } = {}); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/input.js new file mode 100644 index 00000000000..608cf2d314f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/input.js @@ -0,0 +1 @@ +var foo = () => this; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.amd.js new file mode 100644 index 00000000000..6f305d19aa9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.amd.js @@ -0,0 +1,6 @@ +define([ + "require" +], function(require) { + "use strict"; + var foo = ()=>void 0; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.cjs new file mode 100644 index 00000000000..a74b1a9a70f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.cjs @@ -0,0 +1,2 @@ +"use strict"; +var foo = ()=>void 0; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.umd.js new file mode 100644 index 00000000000..ad1af4925ac --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-arrow-function/output.umd.js @@ -0,0 +1,8 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + var foo = ()=>void 0; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/input.js new file mode 100644 index 00000000000..6fcdaabcee6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/input.js @@ -0,0 +1 @@ +this.foo(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.amd.js new file mode 100644 index 00000000000..b6d05e7cb01 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.amd.js @@ -0,0 +1,6 @@ +define([ + "require" +], function(require) { + "use strict"; + (void 0).foo(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.cjs new file mode 100644 index 00000000000..46bffadaac1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.cjs @@ -0,0 +1,2 @@ +"use strict"; +(void 0).foo(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.umd.js new file mode 100644 index 00000000000..fd3ce6fbb10 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-call/output.umd.js @@ -0,0 +1,8 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + (void 0).foo(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/input.js new file mode 100644 index 00000000000..466a452f665 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/input.js @@ -0,0 +1 @@ +var self = this; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.amd.js new file mode 100644 index 00000000000..87c9437d65c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.amd.js @@ -0,0 +1,6 @@ +define([ + "require" +], function(require) { + "use strict"; + var self = void 0; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.cjs new file mode 100644 index 00000000000..a7008f4b78b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.cjs @@ -0,0 +1,2 @@ +"use strict"; +var self = void 0; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.umd.js new file mode 100644 index 00000000000..53b638ac1a7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-declaration/output.umd.js @@ -0,0 +1,8 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + var self1 = void 0; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/input.js new file mode 100644 index 00000000000..b251f26b7af --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/input.js @@ -0,0 +1 @@ +this; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.amd.js new file mode 100644 index 00000000000..cd140fbe420 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.amd.js @@ -0,0 +1,6 @@ +define([ + "require" +], function(require) { + "use strict"; + void 0; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.cjs new file mode 100644 index 00000000000..83b36061683 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.cjs @@ -0,0 +1,2 @@ +"use strict"; +void 0; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.umd.js new file mode 100644 index 00000000000..266470d1b08 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-root-reference/output.umd.js @@ -0,0 +1,8 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(); + else if (typeof define === "function" && define.amd) define([], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(); +})(this, function() { + "use strict"; + void 0; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/input.js new file mode 100644 index 00000000000..276ac00beb0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/input.js @@ -0,0 +1 @@ +export { default } from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/module.json new file mode 100644 index 00000000000..4e94b82c521 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/module.json @@ -0,0 +1,3 @@ +{ + "noInterop": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.amd.js new file mode 100644 index 00000000000..159f0945d3b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.amd.js @@ -0,0 +1,11 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "default", { + get: ()=>_foo.default, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.cjs new file mode 100644 index 00000000000..1e79d8618ab --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "default", { + get: ()=>_foo.default, + enumerable: true +}); +const _foo = require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.umd.js new file mode 100644 index 00000000000..c1af82b851e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/export-from/output.umd.js @@ -0,0 +1,14 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "default", { + get: ()=>_foo.default, + enumerable: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/input.js new file mode 100644 index 00000000000..65b75b7293b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/input.js @@ -0,0 +1,3 @@ +import foo from "foo"; + +foo(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/module.json new file mode 100644 index 00000000000..4e94b82c521 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/module.json @@ -0,0 +1,3 @@ +{ + "noInterop": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.amd.js new file mode 100644 index 00000000000..d45b9b18dab --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.amd.js @@ -0,0 +1,7 @@ +define([ + "require", + "foo" +], function(require, _foo) { + "use strict"; + (0, _foo.default)(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.cjs new file mode 100644 index 00000000000..3a3c9ef3ccc --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.cjs @@ -0,0 +1,3 @@ +"use strict"; +const _foo = require("foo"); +(0, _foo.default)(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.umd.js new file mode 100644 index 00000000000..25c7b0d5ef2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-default-only/output.umd.js @@ -0,0 +1,10 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(require("foo")); + else if (typeof define === "function" && define.amd) define([ + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.foo); +})(this, function(_foo) { + "use strict"; + (0, _foo.default)(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/input.js new file mode 100644 index 00000000000..9d8f42d1016 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/input.js @@ -0,0 +1,4 @@ +import * as foo from "foo"; + +foo.bar(); +foo.baz(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/module.json new file mode 100644 index 00000000000..4e94b82c521 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/module.json @@ -0,0 +1,3 @@ +{ + "noInterop": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.amd.js new file mode 100644 index 00000000000..1b9ae1de53b --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.amd.js @@ -0,0 +1,8 @@ +define([ + "require", + "foo" +], function(require, _foo) { + "use strict"; + _foo.bar(); + _foo.baz(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.cjs new file mode 100644 index 00000000000..174880518ff --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.cjs @@ -0,0 +1,4 @@ +"use strict"; +const _foo = require("foo"); +_foo.bar(); +_foo.baz(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.umd.js new file mode 100644 index 00000000000..162faa0b762 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/no-interop/import-wildcard/output.umd.js @@ -0,0 +1,11 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(require("foo")); + else if (typeof define === "function" && define.amd) define([ + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.foo); +})(this, function(_foo) { + "use strict"; + _foo.bar(); + _foo.baz(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/input.js new file mode 100644 index 00000000000..8dbb5e4fb02 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/input.js @@ -0,0 +1,7 @@ +export var format; +export default function defaultLocale(definition) { + locale = formatLocale(definition); + format = locale.format; + return locale; +} +format = "123"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.amd.js new file mode 100644 index 00000000000..3fce675926a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.amd.js @@ -0,0 +1,26 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + default: ()=>defaultLocale, + format: ()=>format + }); + var format; + function defaultLocale(definition) { + locale = formatLocale(definition); + format = locale.format; + return locale; + } + format = "123"; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.cjs new file mode 100644 index 00000000000..61e48f9b9d0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.cjs @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + default: ()=>defaultLocale, + format: ()=>format +}); +var format; +function defaultLocale(definition) { + locale = formatLocale(definition); + format = locale.format; + return locale; +} +format = "123"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.umd.js new file mode 100644 index 00000000000..00294465a7a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/pull-4688/output.umd.js @@ -0,0 +1,29 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + default: ()=>defaultLocale, + format: ()=>format + }); + var format; + function defaultLocale(definition) { + locale = formatLocale(definition); + format = locale.format; + return locale; + } + format = "123"; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/input.js new file mode 100644 index 00000000000..770e7551a4e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/input.js @@ -0,0 +1,10 @@ +import { copy } from "./copyPaste"; + +class Thing { + handleCopySomething() { + copy(); + } + + completelyUnrelated(copy = 123) { + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.amd.js new file mode 100644 index 00000000000..c5ad6f0539c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports", + "./copyPaste" +], function(require, exports, _copyPaste) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + class Thing { + handleCopySomething() { + (0, _copyPaste.copy)(); + } + completelyUnrelated(copy = 123) {} + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.cjs new file mode 100644 index 00000000000..14a000dc3d0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.cjs @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _copyPaste = require("./copyPaste"); +class Thing { + handleCopySomething() { + (0, _copyPaste.copy)(); + } + completelyUnrelated(copy = 123) {} +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.umd.js new file mode 100644 index 00000000000..620c430fbd9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/4209/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("./copyPaste")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "./copyPaste" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.copyPaste); +})(this, function(exports, _copyPaste) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + class Thing { + handleCopySomething() { + (0, _copyPaste.copy)(); + } + completelyUnrelated(copy = 123) {} + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/input.js new file mode 100644 index 00000000000..0ebfa2fee64 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/input.js @@ -0,0 +1,2 @@ +import a from "a"; +a.preview(...c); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.amd.js new file mode 100644 index 00000000000..ef594d74fe8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.amd.js @@ -0,0 +1,12 @@ +define([ + "require", + "exports", + "a" +], function(require, exports, _a) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _a = _interopRequireDefault(_a); + _a.default.preview(...c); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.cjs new file mode 100644 index 00000000000..818e7433acd --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.cjs @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _a = _interopRequireDefault(require("a")); +_a.default.preview(...c); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.umd.js new file mode 100644 index 00000000000..5a81d4e8ea9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6647/output.umd.js @@ -0,0 +1,15 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("a")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "a" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.a); +})(this, function(exports, _a) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _a = _interopRequireDefault(_a); + _a.default.preview(...c); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/input.js new file mode 100644 index 00000000000..9ebe0f80ad1 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/input.js @@ -0,0 +1,4 @@ +export default function* () { + var x = yield 5; + return 5; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.amd.js new file mode 100644 index 00000000000..3b9e59c0805 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.amd.js @@ -0,0 +1,17 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + function* _default() { + var x = yield 5; + return 5; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.cjs new file mode 100644 index 00000000000..72bc7af9fad --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.cjs @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +function* _default() { + var x = yield 5; + return 5; +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.umd.js new file mode 100644 index 00000000000..9c5d60242b6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/6733/output.umd.js @@ -0,0 +1,20 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + function* _default() { + var x = yield 5; + return 5; + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/input.js new file mode 100644 index 00000000000..744ee1ca4b6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/input.js @@ -0,0 +1,9 @@ +import props from "props"; + +console.log(props); + +(function () { + const { ...props } = this.props; + + console.log(props); +})(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.amd.js new file mode 100644 index 00000000000..78bd7da66bb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.amd.js @@ -0,0 +1,16 @@ +define([ + "require", + "exports", + "props" +], function(require, exports, _props) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _props = _interopRequireDefault(_props); + console.log(_props.default); + (function() { + const { ...props } = this.props; + console.log(props); + })(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.cjs new file mode 100644 index 00000000000..182688b6a8a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.cjs @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _props = _interopRequireDefault(require("props")); +console.log(_props.default); +(function() { + const { ...props } = this.props; + console.log(props); +})(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.umd.js new file mode 100644 index 00000000000..167db12f1d6 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/regression/t-7178/output.umd.js @@ -0,0 +1,19 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("props")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "props" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.props); +})(this, function(exports, _props) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _props = _interopRequireDefault(_props); + console.log(_props.default); + (function() { + const { ...props } = this.props; + console.log(props); + })(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/input.js new file mode 100644 index 00000000000..f7b318b3f63 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/input.js @@ -0,0 +1 @@ +export default foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.amd.js new file mode 100644 index 00000000000..10ec510642a --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.cjs new file mode 100644 index 00000000000..affcffa4589 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true +}); +var _default = foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.umd.js new file mode 100644 index 00000000000..5f2c76f74b3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-1/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>_default, + enumerable: true + }); + var _default = foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/input.js new file mode 100644 index 00000000000..f52d2a90308 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/input.js @@ -0,0 +1,2 @@ +var foo; +export { foo as default }; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.amd.js new file mode 100644 index 00000000000..e1f186c6312 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.cjs new file mode 100644 index 00000000000..ce965f7bd96 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true +}); +var foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.umd.js new file mode 100644 index 00000000000..9228b25dc09 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-2/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "default", { + get: ()=>foo, + enumerable: true + }); + var foo; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/input.js new file mode 100644 index 00000000000..8c653891761 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/input.js @@ -0,0 +1,3 @@ +export {}; + +export {} from "foo"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.amd.js new file mode 100644 index 00000000000..ff2bfa7b564 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.amd.js @@ -0,0 +1,10 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.cjs new file mode 100644 index 00000000000..43930bc8425 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.cjs @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +require("foo"); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.umd.js new file mode 100644 index 00000000000..71329065375 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-3/output.umd.js @@ -0,0 +1,13 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/input.js new file mode 100644 index 00000000000..f99d4277774 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/input.js @@ -0,0 +1 @@ +export function foo() {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.amd.js new file mode 100644 index 00000000000..074575fc748 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.amd.js @@ -0,0 +1,14 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + function foo() {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.cjs new file mode 100644 index 00000000000..393923fbcb7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true +}); +function foo() {} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.umd.js new file mode 100644 index 00000000000..023e4b564bd --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-4/output.umd.js @@ -0,0 +1,17 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + get: ()=>foo, + enumerable: true + }); + function foo() {} +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/input.js new file mode 100644 index 00000000000..15f05d97e48 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/input.js @@ -0,0 +1 @@ +export const [foo, bar = 2] = []; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.amd.js new file mode 100644 index 00000000000..a3ed87a6857 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + const [foo, bar = 2] = []; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.cjs new file mode 100644 index 00000000000..6fafe6daa37 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + foo: ()=>foo +}); +const [foo, bar = 2] = []; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.umd.js new file mode 100644 index 00000000000..fda7ae33728 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-default-params/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + const [foo, bar = 2] = []; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/input.js new file mode 100644 index 00000000000..0a9d393da86 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/input.js @@ -0,0 +1 @@ +export const [foo, bar, ...baz] = []; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.amd.js new file mode 100644 index 00000000000..3c417b1ca92 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.amd.js @@ -0,0 +1,21 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + baz: ()=>baz, + foo: ()=>foo + }); + const [foo, bar, ...baz] = []; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.cjs new file mode 100644 index 00000000000..a49a50852c8 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.cjs @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + baz: ()=>baz, + foo: ()=>foo +}); +const [foo, bar, ...baz] = []; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.umd.js new file mode 100644 index 00000000000..01d5a2faab3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array-rest/output.umd.js @@ -0,0 +1,24 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + baz: ()=>baz, + foo: ()=>foo + }); + const [foo, bar, ...baz] = []; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/input.js new file mode 100644 index 00000000000..17971b0e117 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/input.js @@ -0,0 +1 @@ +export const [foo, bar] = []; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.amd.js new file mode 100644 index 00000000000..f3767b74866 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + const [foo, bar] = []; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.cjs new file mode 100644 index 00000000000..0b0f0e5dafa --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + foo: ()=>foo +}); +const [foo, bar] = []; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.umd.js new file mode 100644 index 00000000000..363d69a3985 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-array/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + const [foo, bar] = []; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/input.js new file mode 100644 index 00000000000..7687ffa2214 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/input.js @@ -0,0 +1 @@ +export const { foo: { bar: [baz, qux] } } = {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.amd.js new file mode 100644 index 00000000000..3a2dfb29832 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + baz: ()=>baz, + qux: ()=>qux + }); + const { foo: { bar: [baz, qux] } } = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.cjs new file mode 100644 index 00000000000..136bd277b7f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + baz: ()=>baz, + qux: ()=>qux +}); +const { foo: { bar: [baz, qux] } } = {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.umd.js new file mode 100644 index 00000000000..9f7e3a04c2f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-deep/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + baz: ()=>baz, + qux: ()=>qux + }); + const { foo: { bar: [baz, qux] } } = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/input.js new file mode 100644 index 00000000000..03958a07094 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/input.js @@ -0,0 +1 @@ +export const { foo, bar = 1 } = {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.amd.js new file mode 100644 index 00000000000..475e23f76b3 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + const { foo , bar =1 } = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.cjs new file mode 100644 index 00000000000..1ad8f173e68 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + foo: ()=>foo +}); +const { foo , bar =1 } = {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.umd.js new file mode 100644 index 00000000000..4cd5aa9f138 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-default-params/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + const { foo , bar =1 } = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/input.js new file mode 100644 index 00000000000..d4d52568ceb --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/input.js @@ -0,0 +1 @@ +export const { foo, ...bar } = {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.amd.js new file mode 100644 index 00000000000..57ac4041ba9 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + const { foo , ...bar } = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.cjs new file mode 100644 index 00000000000..6e73ab656de --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + foo: ()=>foo +}); +const { foo , ...bar } = {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.umd.js new file mode 100644 index 00000000000..da32c04c685 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object-rest/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + foo: ()=>foo + }); + const { foo , ...bar } = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/input.js new file mode 100644 index 00000000000..f5714936049 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/input.js @@ -0,0 +1 @@ +export const { foo: bar, baz } = {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.amd.js new file mode 100644 index 00000000000..7a67a2ee9c2 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.amd.js @@ -0,0 +1,20 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + baz: ()=>baz + }); + const { foo: bar , baz } = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.cjs new file mode 100644 index 00000000000..74bcd1a2617 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.cjs @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + bar: ()=>bar, + baz: ()=>baz +}); +const { foo: bar , baz } = {}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.umd.js new file mode 100644 index 00000000000..611e3fff1e7 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/export-const/destructuring-object/output.umd.js @@ -0,0 +1,23 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + bar: ()=>bar, + baz: ()=>baz + }); + const { foo: bar , baz } = {}; +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/input.js new file mode 100644 index 00000000000..9d8f42d1016 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/input.js @@ -0,0 +1,4 @@ +import * as foo from "foo"; + +foo.bar(); +foo.baz(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.amd.js new file mode 100644 index 00000000000..c1e0d26054d --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.amd.js @@ -0,0 +1,13 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + _foo.bar(); + _foo.baz(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.cjs new file mode 100644 index 00000000000..1947f1277de --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.cjs @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireWildcard(require("foo")); +_foo.bar(); +_foo.baz(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.umd.js new file mode 100644 index 00000000000..3a9a04de0e4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import-wildcard/output.umd.js @@ -0,0 +1,16 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + _foo.bar(); + _foo.baz(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/input.js new file mode 100644 index 00000000000..5b84f44e665 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/input.js @@ -0,0 +1,9 @@ +import foo from "foo"; +import { default as foo2 } from "foo"; +import { foo3 } from "foo"; +import * as foo4 from "foo"; + +foo; +foo2; +foo3; +foo3(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/module.json b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/module.json new file mode 100644 index 00000000000..65b6a35fc4c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/module.json @@ -0,0 +1,3 @@ +{ + "strict": true +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.amd.js new file mode 100644 index 00000000000..dedf38f641c --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.amd.js @@ -0,0 +1,15 @@ +define([ + "require", + "exports", + "foo" +], function(require, exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + _foo.default; + _foo.default; + _foo.foo3; + (0, _foo.foo3)(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.cjs new file mode 100644 index 00000000000..38a7ee687a4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.cjs @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +const _foo = _interopRequireWildcard(require("foo")); +_foo.default; +_foo.default; +_foo.foo3; +(0, _foo.foo3)(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.umd.js new file mode 100644 index 00000000000..fde8edbb7bf --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/strict/import/output.umd.js @@ -0,0 +1,18 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("foo")); + else if (typeof define === "function" && define.amd) define([ + "exports", + "foo" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.foo); +})(this, function(exports, _foo) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _foo = _interopRequireWildcard(_foo); + _foo.default; + _foo.default; + _foo.foo3; + (0, _foo.foo3)(); +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/input.js new file mode 100644 index 00000000000..43d41ddf01f --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/input.js @@ -0,0 +1,7 @@ +export let diffLevel = 0; + +export function diff() { + if (!--diffLevel) { + console.log("hey"); + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.amd.js new file mode 100644 index 00000000000..8623d6de532 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.amd.js @@ -0,0 +1,25 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + diff: ()=>diff, + diffLevel: ()=>diffLevel + }); + let diffLevel = 0; + function diff() { + if (!--diffLevel) { + console.log("hey"); + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.cjs new file mode 100644 index 00000000000..28bc35a2f4e --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.cjs @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + diff: ()=>diff, + diffLevel: ()=>diffLevel +}); +let diffLevel = 0; +function diff() { + if (!--diffLevel) { + console.log("hey"); + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.umd.js new file mode 100644 index 00000000000..470e65e7eb0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/negative-suffix/output.umd.js @@ -0,0 +1,28 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + diff: ()=>diff, + diffLevel: ()=>diffLevel + }); + let diffLevel = 0; + function diff() { + if (!--diffLevel) { + console.log("hey"); + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/input.js new file mode 100644 index 00000000000..90b7d5341ce --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/input.js @@ -0,0 +1,7 @@ +export let diffLevel = 0; + +export function diff() { + if (!++diffLevel) { + console.log("hey"); + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.amd.js new file mode 100644 index 00000000000..640d4a8b0b0 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.amd.js @@ -0,0 +1,25 @@ +define([ + "require", + "exports" +], function(require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + diff: ()=>diff, + diffLevel: ()=>diffLevel + }); + let diffLevel = 0; + function diff() { + if (!++diffLevel) { + console.log("hey"); + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.cjs new file mode 100644 index 00000000000..c4ce0fba211 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.cjs @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); +} +_export(exports, { + diff: ()=>diff, + diffLevel: ()=>diffLevel +}); +let diffLevel = 0; +function diff() { + if (!++diffLevel) { + console.log("hey"); + } +} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.umd.js new file mode 100644 index 00000000000..033b43e83c4 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/fixture/common/update-expression/positive-suffix/output.umd.js @@ -0,0 +1,28 @@ +(function(global, factory) { + if (typeof module === "object" && typeof module.exports === "object") factory(exports); + else if (typeof define === "function" && define.amd) define([ + "exports" + ], factory); + else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}); +})(this, function(exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + get: all[name], + enumerable: true + }); + } + _export(exports, { + diff: ()=>diff, + diffLevel: ()=>diffLevel + }); + let diffLevel = 0; + function diff() { + if (!++diffLevel) { + console.log("hey"); + } + } +}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/class-property/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/class-property/output.js deleted file mode 100644 index 628a7c93c1c..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/class-property/output.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -var _simple = require("./files_with_swcrc/simple"); -class Foo { - static prop = _simple.a; -} -exports.Foo = Foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/export-update/1/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/export-update/1/output.js deleted file mode 100644 index 97458ba65e1..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/export-update/1/output.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.bazbar = exports.foobar = exports.baz = exports.bar = exports.foo = void 0; -var ref, ref1; -let foo = 1n; -exports.foo = foo; -ref = foo++, exports.foo = foo, ref; -let bar = exports.foo = ++foo; -exports.bar = bar; -let baz = (ref1 = bar--, exports.bar = bar, ref1); -exports.baz = baz; -exports.bar = --bar; -exports.foobar = foo; -exports.bazbar = baz; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/1/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/1/output.js deleted file mode 100644 index ee41fe4853e..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/1/output.js +++ /dev/null @@ -1,27 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "render", { - enumerable: true, - get: function() { - return _customRender.customRender; - } -}); -var _exportNames = { - render: true -}; -var _customRender = require("./customRender"); -var _react = require("@testing-library/react"); -// re-export everything -Object.keys(_react).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _react[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _react[key]; - } - }); -}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/2/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/2/output.js deleted file mode 100644 index ceba76b7c78..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2101/2/output.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "render", { - enumerable: true, - get: function() { - return _customRender.customRender; - } -}); -var _exportNames = { - render: true -}; -var _customRender = require("./customRender"); -var _react = require("@testing-library/react"); -// re-ordering the export wildcard from case 1 should make no difference to output -// re-export everything -Object.keys(_react).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _react[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _react[key]; - } - }); -}); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/1/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/1/output.js deleted file mode 100644 index 618b0d7665d..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/1/output.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; -var _bar = require("./bar"); -const makeX = ()=>{ - const _bar1 = ()=>(0, _bar).bar() - ; - return { - _bar: _bar1 - }; -}; -makeX()._bar(); diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/2/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/2/output.js deleted file mode 100644 index 59179d489e7..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2211/2/output.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -var _bar = require("./bar"); -const makeX = ()=>{ - const _bar1 = ()=>(0, _bar).bar() - ; - const alfa = ()=>_bar1() - ; - return { - alfa - }; -}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2297/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2297/output.js deleted file mode 100644 index 80d0a0eb268..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2297/output.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -var _bar = require("./Bar"); -const makeX = (props)=>{ - const _bar1 = props.bar; - const { list } = _bar1; - return list.map(()=>_bar.bar - ); -}; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/input/.swcrc b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/input/.swcrc deleted file mode 100644 index 536ca3af1e6..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/input/.swcrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "module": { - "type": "commonjs" - } -} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/output/index.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/output/index.js deleted file mode 100644 index c2e99752f5d..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case1/output/index.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "X", { - enumerable: true, - get: function() { - return _z.default; - } -}); -var _z = _interopRequireDefault(require("./Z")); -function _interopRequireDefault(obj) { - return obj && obj.__esModule ? obj : { - default: obj - }; -} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/input/.swcrc b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/input/.swcrc deleted file mode 100644 index 536ca3af1e6..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/input/.swcrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "module": { - "type": "commonjs" - } -} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/output/index.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/output/index.js deleted file mode 100644 index ef469be6d9c..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case2/output/index.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "X", { - enumerable: true, - get: function() { - return _z.default; - } -}); -var _exportNames = { - X: true -}; -var _z = _interopRequireWildcard(require("./Z")); -Object.keys(_z).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _z[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _z[key]; - } - }); -}); -function _interopRequireWildcard(obj) { - if (obj && obj.__esModule) { - return obj; - } else { - var newObj = { - }; - if (obj != null) { - for(var key in obj){ - if (Object.prototype.hasOwnProperty.call(obj, key)) { - var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : { - }; - if (desc.get || desc.set) { - Object.defineProperty(newObj, key, desc); - } else { - newObj[key] = obj[key]; - } - } - } - } - newObj.default = obj; - return newObj; - } -} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/input/.swcrc b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/input/.swcrc deleted file mode 100644 index 536ca3af1e6..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/input/.swcrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "module": { - "type": "commonjs" - } -} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/input/index.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/input/index.js deleted file mode 100644 index 4987d8909c3..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/input/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { default as X, Y, X2 } from "./Z"; -export * from "./Z"; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/output/index.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/output/index.js deleted file mode 100644 index ad4ab29c5a8..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-2548/case3/output/index.js +++ /dev/null @@ -1,62 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "X", { - enumerable: true, - get: function() { - return _z.default; - } -}); -Object.defineProperty(exports, "Y", { - enumerable: true, - get: function() { - return _z.Y; - } -}); -Object.defineProperty(exports, "X2", { - enumerable: true, - get: function() { - return _z.X2; - } -}); -var _exportNames = { - X: true, - Y: true, - X2: true -}; -var _z = _interopRequireWildcard(require("./Z")); -Object.keys(_z).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _z[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _z[key]; - } - }); -}); -function _interopRequireWildcard(obj) { - if (obj && obj.__esModule) { - return obj; - } else { - var newObj = { - }; - if (obj != null) { - for(var key in obj){ - if (Object.prototype.hasOwnProperty.call(obj, key)) { - var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : { - }; - if (desc.get || desc.set) { - Object.defineProperty(newObj, key, desc); - } else { - newObj[key] = obj[key]; - } - } - } - } - newObj.default = obj; - return newObj; - } -} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/1/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/1/output.js deleted file mode 100644 index d1a058d2625..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/1/output.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.a = void 0; -let a = 1; -exports.a = a = 2; -use(exports.a = a = 3); -({ a =4 } = {}), exports.a = a; -exports.a = a; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/2/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/2/output.js deleted file mode 100644 index 733f5907cf8..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/2/output.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = exports.bar2 = exports.bar = exports.foo = exports.foo1 = void 0; -const foo = 1; -let bar = 2; -var _default = bar; -exports.default = _default; -exports.bar2 = exports.bar = bar = 3; -exports.foo1 = foo; -exports.foo = foo; -exports.bar = bar; -exports.bar2 = bar; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/3/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/3/output.js deleted file mode 100644 index 6bb3485175e..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/3/output.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = exports.bar2 = exports.bar = exports.foo = exports.foo1 = void 0; -const foo = 1; -let bar = 2; -exports.default = exports.bar2 = exports.bar = bar = 3; -exports.foo1 = foo; -exports.foo = foo; -exports.bar = bar; -exports.bar2 = bar; -exports.default = bar; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/4/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/4/output.js deleted file mode 100644 index 365d5e1a0bc..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/4/output.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = foo; -exports.bar = void 0; -function foo() {} -exports.bar = exports.default = foo = 1; -exports.bar = exports.default = foo = 2; -exports.bar = foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/5/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/5/output.js deleted file mode 100644 index eb37ff8bb6d..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3439/5/output.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.bar = exports.default = void 0; -class foo { -} -exports.default = foo; -exports.bar = foo = 1; -exports.bar = foo = 2; -exports.bar = foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3732/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3732/output.js deleted file mode 100644 index 3e887277efd..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3732/output.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.byID = exports.get = void 0; -var _get = _interopRequireWildcard(require("./get")); -exports.get = _get; -const byID = (id)=>{ - // Do some async stuff - return new Promise((resolve)=>setTimeout(()=>{ - resolve("result"); - }, 2000) - ); -}; -exports.byID = byID; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3898/1/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3898/1/output.js deleted file mode 100644 index eb3c41dab72..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-3898/1/output.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.foo = void 0; -let foo = 1; -exports.foo = foo; -exports.foo = foo = 2; -exports.foo = foo += 2; -exports.foo = foo -= 2; -exports.foo = foo *= 2; -exports.foo = foo /= 2; -exports.foo = foo %= 2; -exports.foo = foo <<= 2; -exports.foo = foo >>= 2; -exports.foo = foo >>>= 2; -exports.foo = foo |= 2; -exports.foo = foo ^= 2; -exports.foo = foo &= 2; -exports.foo = foo **= 2; -exports.foo = foo &&= 2; -exports.foo = foo ||= 2; -exports.foo = foo ??= 2; -[foo] = [ - 2 -], exports.foo = foo; -[foo = 3] = [], exports.foo = foo; -({ bar: foo } = { - bar: 2 -}), exports.foo = foo; diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-4700/1/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-4700/1/output.js deleted file mode 100644 index e13b8269d3e..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/issue-4700/1/output.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -var _exportNames = { - whatever: true -}; -exports.whatever = whatever; -var _anotherModule = require("another-module"); -Object.keys(_anotherModule).forEach(function(key) { - if (key === "default" || key === "__esModule") return; - if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; - if (key in exports && exports[key] === _anotherModule[key]) return; - Object.defineProperty(exports, key, { - enumerable: true, - get: function() { - return _anotherModule[key]; - } - }); -}); -function whatever(notExportName) { - const shouldNotBeExportNameAsWell = 123; - return shouldNotBeExportNameAsWell + notExportName; -} diff --git a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/many-exports-chunked/1/output.js b/crates/swc_ecma_transforms_module/tests/fixture/commonjs/many-exports-chunked/1/output.js deleted file mode 100644 index 97c78f4f150..00000000000 --- a/crates/swc_ecma_transforms_module/tests/fixture/commonjs/many-exports-chunked/1/output.js +++ /dev/null @@ -1,508 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.a063 = exports.a062 = exports.a061 = exports.a060 = exports.a059 = exports.a058 = exports.a057 = exports.a056 = exports.a055 = exports.a054 = exports.a053 = exports.a052 = exports.a051 = exports.a050 = exports.a049 = exports.a048 = exports.a047 = exports.a046 = exports.a045 = exports.a044 = exports.a043 = exports.a042 = exports.a041 = exports.a040 = exports.a039 = exports.a038 = exports.a037 = exports.a036 = exports.a035 = exports.a034 = exports.a033 = exports.a032 = exports.a031 = exports.a030 = exports.a029 = exports.a028 = exports.a027 = exports.a026 = exports.a025 = exports.a024 = exports.a023 = exports.a022 = exports.a021 = exports.a020 = exports.a019 = exports.a018 = exports.a017 = exports.a016 = exports.a015 = exports.a014 = exports.a013 = exports.a012 = exports.a011 = exports.a010 = exports.a009 = exports.a008 = exports.a007 = exports.a006 = exports.a005 = exports.a004 = exports.a003 = exports.a002 = exports.a001 = exports.a000 = void 0; -exports.a127 = exports.a126 = exports.a125 = exports.a124 = exports.a123 = exports.a122 = exports.a121 = exports.a120 = exports.a119 = exports.a118 = exports.a117 = exports.a116 = exports.a115 = exports.a114 = exports.a113 = exports.a112 = exports.a111 = exports.a110 = exports.a109 = exports.a108 = exports.a107 = exports.a106 = exports.a105 = exports.a104 = exports.a103 = exports.a102 = exports.a101 = exports.a100 = exports.a099 = exports.a098 = exports.a097 = exports.a096 = exports.a095 = exports.a094 = exports.a093 = exports.a092 = exports.a091 = exports.a090 = exports.a089 = exports.a088 = exports.a087 = exports.a086 = exports.a085 = exports.a084 = exports.a083 = exports.a082 = exports.a081 = exports.a080 = exports.a079 = exports.a078 = exports.a077 = exports.a076 = exports.a075 = exports.a074 = exports.a073 = exports.a072 = exports.a071 = exports.a070 = exports.a069 = exports.a068 = exports.a067 = exports.a066 = exports.a065 = exports.a064 = void 0; -exports.a191 = exports.a190 = exports.a189 = exports.a188 = exports.a187 = exports.a186 = exports.a185 = exports.a184 = exports.a183 = exports.a182 = exports.a181 = exports.a180 = exports.a179 = exports.a178 = exports.a177 = exports.a176 = exports.a175 = exports.a174 = exports.a173 = exports.a172 = exports.a171 = exports.a170 = exports.a169 = exports.a168 = exports.a167 = exports.a166 = exports.a165 = exports.a164 = exports.a163 = exports.a162 = exports.a161 = exports.a160 = exports.a159 = exports.a158 = exports.a157 = exports.a156 = exports.a155 = exports.a154 = exports.a153 = exports.a152 = exports.a151 = exports.a150 = exports.a149 = exports.a148 = exports.a147 = exports.a146 = exports.a145 = exports.a144 = exports.a143 = exports.a142 = exports.a141 = exports.a140 = exports.a139 = exports.a138 = exports.a137 = exports.a136 = exports.a135 = exports.a134 = exports.a133 = exports.a132 = exports.a131 = exports.a130 = exports.a129 = exports.a128 = void 0; -exports.a249 = exports.a248 = exports.a247 = exports.a246 = exports.a245 = exports.a244 = exports.a243 = exports.a242 = exports.a241 = exports.a240 = exports.a239 = exports.a238 = exports.a237 = exports.a236 = exports.a235 = exports.a234 = exports.a233 = exports.a232 = exports.a231 = exports.a230 = exports.a229 = exports.a228 = exports.a227 = exports.a226 = exports.a225 = exports.a224 = exports.a223 = exports.a222 = exports.a221 = exports.a220 = exports.a219 = exports.a218 = exports.a217 = exports.a216 = exports.a215 = exports.a214 = exports.a213 = exports.a212 = exports.a211 = exports.a210 = exports.a209 = exports.a208 = exports.a207 = exports.a206 = exports.a205 = exports.a204 = exports.a203 = exports.a202 = exports.a201 = exports.a200 = exports.a199 = exports.a198 = exports.a197 = exports.a196 = exports.a195 = exports.a194 = exports.a193 = exports.a192 = void 0; -const a000 = 0; -exports.a000 = a000; -const a001 = 1; -exports.a001 = a001; -const a002 = 2; -exports.a002 = a002; -const a003 = 3; -exports.a003 = a003; -const a004 = 4; -exports.a004 = a004; -const a005 = 5; -exports.a005 = a005; -const a006 = 6; -exports.a006 = a006; -const a007 = 7; -exports.a007 = a007; -const a008 = 8; -exports.a008 = a008; -const a009 = 9; -exports.a009 = a009; -const a010 = 10; -exports.a010 = a010; -const a011 = 11; -exports.a011 = a011; -const a012 = 12; -exports.a012 = a012; -const a013 = 13; -exports.a013 = a013; -const a014 = 14; -exports.a014 = a014; -const a015 = 15; -exports.a015 = a015; -const a016 = 16; -exports.a016 = a016; -const a017 = 17; -exports.a017 = a017; -const a018 = 18; -exports.a018 = a018; -const a019 = 19; -exports.a019 = a019; -const a020 = 20; -exports.a020 = a020; -const a021 = 21; -exports.a021 = a021; -const a022 = 22; -exports.a022 = a022; -const a023 = 23; -exports.a023 = a023; -const a024 = 24; -exports.a024 = a024; -const a025 = 25; -exports.a025 = a025; -const a026 = 26; -exports.a026 = a026; -const a027 = 27; -exports.a027 = a027; -const a028 = 28; -exports.a028 = a028; -const a029 = 29; -exports.a029 = a029; -const a030 = 30; -exports.a030 = a030; -const a031 = 31; -exports.a031 = a031; -const a032 = 32; -exports.a032 = a032; -const a033 = 33; -exports.a033 = a033; -const a034 = 34; -exports.a034 = a034; -const a035 = 35; -exports.a035 = a035; -const a036 = 36; -exports.a036 = a036; -const a037 = 37; -exports.a037 = a037; -const a038 = 38; -exports.a038 = a038; -const a039 = 39; -exports.a039 = a039; -const a040 = 40; -exports.a040 = a040; -const a041 = 41; -exports.a041 = a041; -const a042 = 42; -exports.a042 = a042; -const a043 = 43; -exports.a043 = a043; -const a044 = 44; -exports.a044 = a044; -const a045 = 45; -exports.a045 = a045; -const a046 = 46; -exports.a046 = a046; -const a047 = 47; -exports.a047 = a047; -const a048 = 48; -exports.a048 = a048; -const a049 = 49; -exports.a049 = a049; -const a050 = 50; -exports.a050 = a050; -const a051 = 51; -exports.a051 = a051; -const a052 = 52; -exports.a052 = a052; -const a053 = 53; -exports.a053 = a053; -const a054 = 54; -exports.a054 = a054; -const a055 = 55; -exports.a055 = a055; -const a056 = 56; -exports.a056 = a056; -const a057 = 57; -exports.a057 = a057; -const a058 = 58; -exports.a058 = a058; -const a059 = 59; -exports.a059 = a059; -const a060 = 60; -exports.a060 = a060; -const a061 = 61; -exports.a061 = a061; -const a062 = 62; -exports.a062 = a062; -const a063 = 63; -exports.a063 = a063; -const a064 = 64; -exports.a064 = a064; -const a065 = 65; -exports.a065 = a065; -const a066 = 66; -exports.a066 = a066; -const a067 = 67; -exports.a067 = a067; -const a068 = 68; -exports.a068 = a068; -const a069 = 69; -exports.a069 = a069; -const a070 = 70; -exports.a070 = a070; -const a071 = 71; -exports.a071 = a071; -const a072 = 72; -exports.a072 = a072; -const a073 = 73; -exports.a073 = a073; -const a074 = 74; -exports.a074 = a074; -const a075 = 75; -exports.a075 = a075; -const a076 = 76; -exports.a076 = a076; -const a077 = 77; -exports.a077 = a077; -const a078 = 78; -exports.a078 = a078; -const a079 = 79; -exports.a079 = a079; -const a080 = 80; -exports.a080 = a080; -const a081 = 81; -exports.a081 = a081; -const a082 = 82; -exports.a082 = a082; -const a083 = 83; -exports.a083 = a083; -const a084 = 84; -exports.a084 = a084; -const a085 = 85; -exports.a085 = a085; -const a086 = 86; -exports.a086 = a086; -const a087 = 87; -exports.a087 = a087; -const a088 = 88; -exports.a088 = a088; -const a089 = 89; -exports.a089 = a089; -const a090 = 90; -exports.a090 = a090; -const a091 = 91; -exports.a091 = a091; -const a092 = 92; -exports.a092 = a092; -const a093 = 93; -exports.a093 = a093; -const a094 = 94; -exports.a094 = a094; -const a095 = 95; -exports.a095 = a095; -const a096 = 96; -exports.a096 = a096; -const a097 = 97; -exports.a097 = a097; -const a098 = 98; -exports.a098 = a098; -const a099 = 99; -exports.a099 = a099; -const a100 = 100; -exports.a100 = a100; -const a101 = 101; -exports.a101 = a101; -const a102 = 102; -exports.a102 = a102; -const a103 = 103; -exports.a103 = a103; -const a104 = 104; -exports.a104 = a104; -const a105 = 105; -exports.a105 = a105; -const a106 = 106; -exports.a106 = a106; -const a107 = 107; -exports.a107 = a107; -const a108 = 108; -exports.a108 = a108; -const a109 = 109; -exports.a109 = a109; -const a110 = 110; -exports.a110 = a110; -const a111 = 111; -exports.a111 = a111; -const a112 = 112; -exports.a112 = a112; -const a113 = 113; -exports.a113 = a113; -const a114 = 114; -exports.a114 = a114; -const a115 = 115; -exports.a115 = a115; -const a116 = 116; -exports.a116 = a116; -const a117 = 117; -exports.a117 = a117; -const a118 = 118; -exports.a118 = a118; -const a119 = 119; -exports.a119 = a119; -const a120 = 120; -exports.a120 = a120; -const a121 = 121; -exports.a121 = a121; -const a122 = 122; -exports.a122 = a122; -const a123 = 123; -exports.a123 = a123; -const a124 = 124; -exports.a124 = a124; -const a125 = 125; -exports.a125 = a125; -const a126 = 126; -exports.a126 = a126; -const a127 = 127; -exports.a127 = a127; -const a128 = 128; -exports.a128 = a128; -const a129 = 129; -exports.a129 = a129; -const a130 = 130; -exports.a130 = a130; -const a131 = 131; -exports.a131 = a131; -const a132 = 132; -exports.a132 = a132; -const a133 = 133; -exports.a133 = a133; -const a134 = 134; -exports.a134 = a134; -const a135 = 135; -exports.a135 = a135; -const a136 = 136; -exports.a136 = a136; -const a137 = 137; -exports.a137 = a137; -const a138 = 138; -exports.a138 = a138; -const a139 = 139; -exports.a139 = a139; -const a140 = 140; -exports.a140 = a140; -const a141 = 141; -exports.a141 = a141; -const a142 = 142; -exports.a142 = a142; -const a143 = 143; -exports.a143 = a143; -const a144 = 144; -exports.a144 = a144; -const a145 = 145; -exports.a145 = a145; -const a146 = 146; -exports.a146 = a146; -const a147 = 147; -exports.a147 = a147; -const a148 = 148; -exports.a148 = a148; -const a149 = 149; -exports.a149 = a149; -const a150 = 150; -exports.a150 = a150; -const a151 = 151; -exports.a151 = a151; -const a152 = 152; -exports.a152 = a152; -const a153 = 153; -exports.a153 = a153; -const a154 = 154; -exports.a154 = a154; -const a155 = 155; -exports.a155 = a155; -const a156 = 156; -exports.a156 = a156; -const a157 = 157; -exports.a157 = a157; -const a158 = 158; -exports.a158 = a158; -const a159 = 159; -exports.a159 = a159; -const a160 = 160; -exports.a160 = a160; -const a161 = 161; -exports.a161 = a161; -const a162 = 162; -exports.a162 = a162; -const a163 = 163; -exports.a163 = a163; -const a164 = 164; -exports.a164 = a164; -const a165 = 165; -exports.a165 = a165; -const a166 = 166; -exports.a166 = a166; -const a167 = 167; -exports.a167 = a167; -const a168 = 168; -exports.a168 = a168; -const a169 = 169; -exports.a169 = a169; -const a170 = 170; -exports.a170 = a170; -const a171 = 171; -exports.a171 = a171; -const a172 = 172; -exports.a172 = a172; -const a173 = 173; -exports.a173 = a173; -const a174 = 174; -exports.a174 = a174; -const a175 = 175; -exports.a175 = a175; -const a176 = 176; -exports.a176 = a176; -const a177 = 177; -exports.a177 = a177; -const a178 = 178; -exports.a178 = a178; -const a179 = 179; -exports.a179 = a179; -const a180 = 180; -exports.a180 = a180; -const a181 = 181; -exports.a181 = a181; -const a182 = 182; -exports.a182 = a182; -const a183 = 183; -exports.a183 = a183; -const a184 = 184; -exports.a184 = a184; -const a185 = 185; -exports.a185 = a185; -const a186 = 186; -exports.a186 = a186; -const a187 = 187; -exports.a187 = a187; -const a188 = 188; -exports.a188 = a188; -const a189 = 189; -exports.a189 = a189; -const a190 = 190; -exports.a190 = a190; -const a191 = 191; -exports.a191 = a191; -const a192 = 192; -exports.a192 = a192; -const a193 = 193; -exports.a193 = a193; -const a194 = 194; -exports.a194 = a194; -const a195 = 195; -exports.a195 = a195; -const a196 = 196; -exports.a196 = a196; -const a197 = 197; -exports.a197 = a197; -const a198 = 198; -exports.a198 = a198; -const a199 = 199; -exports.a199 = a199; -const a200 = 200; -exports.a200 = a200; -const a201 = 201; -exports.a201 = a201; -const a202 = 202; -exports.a202 = a202; -const a203 = 203; -exports.a203 = a203; -const a204 = 204; -exports.a204 = a204; -const a205 = 205; -exports.a205 = a205; -const a206 = 206; -exports.a206 = a206; -const a207 = 207; -exports.a207 = a207; -const a208 = 208; -exports.a208 = a208; -const a209 = 209; -exports.a209 = a209; -const a210 = 210; -exports.a210 = a210; -const a211 = 211; -exports.a211 = a211; -const a212 = 212; -exports.a212 = a212; -const a213 = 213; -exports.a213 = a213; -const a214 = 214; -exports.a214 = a214; -const a215 = 215; -exports.a215 = a215; -const a216 = 216; -exports.a216 = a216; -const a217 = 217; -exports.a217 = a217; -const a218 = 218; -exports.a218 = a218; -const a219 = 219; -exports.a219 = a219; -const a220 = 220; -exports.a220 = a220; -const a221 = 221; -exports.a221 = a221; -const a222 = 222; -exports.a222 = a222; -const a223 = 223; -exports.a223 = a223; -const a224 = 224; -exports.a224 = a224; -const a225 = 225; -exports.a225 = a225; -const a226 = 226; -exports.a226 = a226; -const a227 = 227; -exports.a227 = a227; -const a228 = 228; -exports.a228 = a228; -const a229 = 229; -exports.a229 = a229; -const a230 = 230; -exports.a230 = a230; -const a231 = 231; -exports.a231 = a231; -const a232 = 232; -exports.a232 = a232; -const a233 = 233; -exports.a233 = a233; -const a234 = 234; -exports.a234 = a234; -const a235 = 235; -exports.a235 = a235; -const a236 = 236; -exports.a236 = a236; -const a237 = 237; -exports.a237 = a237; -const a238 = 238; -exports.a238 = a238; -const a239 = 239; -exports.a239 = a239; -const a240 = 240; -exports.a240 = a240; -const a241 = 241; -exports.a241 = a241; -const a242 = 242; -exports.a242 = a242; -const a243 = 243; -exports.a243 = a243; -const a244 = 244; -exports.a244 = a244; -const a245 = 245; -exports.a245 = a245; -const a246 = 246; -exports.a246 = a246; -const a247 = 247; -exports.a247 = a247; -const a248 = 248; -exports.a248 = a248; -const a249 = 249; -exports.a249 = a249; diff --git a/crates/swc_ecma_transforms_module/tests/umd.rs b/crates/swc_ecma_transforms_module/tests/umd.rs index 39890f8aa9a..cbbaf1d59ed 100644 --- a/crates/swc_ecma_transforms_module/tests/umd.rs +++ b/crates/swc_ecma_transforms_module/tests/umd.rs @@ -1,1983 +1,59 @@ +use std::{fs::File, path::PathBuf}; + use swc_common::{chain, Mark}; -use swc_ecma_parser::{EsConfig, Syntax}; -use swc_ecma_transforms_base::resolver; -use swc_ecma_transforms_compat::es2015::{arrow, function_name, shorthand}; -use swc_ecma_transforms_module::{ - hoist::module_hoister, - umd::{umd, Config}, - util, -}; -use swc_ecma_transforms_testing::{test, Tester}; +use swc_ecma_parser::{Syntax, TsConfig}; +use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; +use swc_ecma_transforms_module::umd::{umd, Config}; +use swc_ecma_transforms_testing::{test_fixture, Tester}; use swc_ecma_visit::Fold; fn syntax() -> Syntax { - Syntax::Es(EsConfig { - ..Default::default() - }) + Default::default() } -fn tr(tester: &mut Tester<'_>, config: Config) -> impl Fold { +fn ts_syntax() -> Syntax { + Syntax::Typescript(TsConfig::default()) +} + +fn tr(tester: &mut Tester<'_>, config: Config, typescript: bool) -> impl Fold { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); + let avalible_set = FeatureFlag::all(); + chain!( - resolver(unresolved_mark, top_level_mark, false), - module_hoister(), - umd(tester.cm.clone(), unresolved_mark, config) + resolver(unresolved_mark, top_level_mark, typescript), + umd(tester.cm.clone(), unresolved_mark, config, avalible_set), ) } -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - issue_335, - "import bar from 'bar'; +#[testing::fixture("tests/fixture/common/**/input.js")] +#[testing::fixture("tests/fixture/common/**/input.ts")] +#[testing::fixture("tests/fixture/common/**/input.cts")] +fn esm_to_umd(input: PathBuf) { + let is_ts = input + .file_name() + .map(|x| x.to_string_lossy()) + .map(|x| x.ends_with(".ts") || x.ends_with(".mts") || x.ends_with(".cts")) + .unwrap_or_default(); -obj[bar('bas')] = '123'", - "(function(global, factory) { - if (typeof define === \"function\" && define.amd) { - define([\"bar\"], factory); - } else if (typeof exports !== \"undefined\") { - factory(require(\"bar\")); - } else { - var mod = { - exports: { - } - }; - factory(global.bar); - global.input = mod.exports; - } -})(this, function(_bar) { - \"use strict\"; - _bar = _interopRequireDefault(_bar); - obj[(0, _bar).default('bas')] = '123'; -});" -); + let dir = input.parent().unwrap().to_path_buf(); -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - issue_332, - "import foo from 'foo'; + let output = dir + .join("output.umd.js") + .with_extension(if is_ts { "ts" } else { "js" }); -export const bar = { foo }", - " - (function(global, factory) { - if (typeof define === \"function\" && define.amd) { - define([\"exports\", \"foo\"], factory); - } else if (typeof exports !== \"undefined\") { - factory(exports, require(\"foo\")); - } else { - var mod = { - exports: { - } - }; - factory(mod.exports, global.foo); - global.input = mod.exports; - } -})(this, function(_exports, _foo) { - \"use strict\"; - _foo = _interopRequireDefault(_foo); - Object.defineProperty(_exports, \"__esModule\", { - value: true - }); - _exports.bar = void 0; - const bar = { - foo: _foo.default + let umd_config_path = dir.join("module.umd.json"); + let config_path = dir.join("module.json"); + let config: Config = match File::open(umd_config_path).or_else(|_| File::open(config_path)) { + Ok(file) => serde_json::from_reader(file).unwrap(), + Err(..) => Default::default(), }; - _exports.bar = bar; -}); -" -); -test!( - syntax(), - |tester| tr( - tester, - Config { - config: util::Config { - strict: true, - ..Default::default() - }, - ..Default::default() - } - ), - custom_strict, - r#"export function foo(){}"#, - r#" -(function(global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: { - } - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function(_exports) { - "use strict"; - _exports.foo = foo; - function foo() { - } -}); - -"# -); - -test!( - syntax(), - |tester| tr( - tester, - Config { - config: util::Config { - strict_mode: false, - ..Default::default() - }, - ..Default::default() - } - ), - custom_non_strict_mode, - r#"export function foo(){}"#, - r#" -(function(global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: { - } - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function(_exports) { - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.foo = foo; - function foo() { - } -}); - -"# -); - -test!( - syntax(), - |tester| tr( - tester, - Config { - config: util::Config { - no_interop: true, - ..Default::default() - }, - ..Default::default() - } - ), - custom_no_interop, - r#"import * as foo from 'foo'; - import bar from 'bar';"#, - r#" -(function(global, factory) { - if (typeof define === "function" && define.amd) { - define(["foo", "bar"], factory); - } else if (typeof exports !== "undefined") { - factory(require("foo"), require("bar")); - } else { - var mod = { - exports: { - } - }; - factory(global.foo, global.bar); - global.input = mod.exports; - } -})(this, function(foo, _bar) { - "use strict"; -}); -"# -); - -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - custom_usage, - r#" -import React from 'react' -window.React = React; - "#, - r#" -(function(global, factory) { - if (typeof define === "function" && define.amd) { - define(["react"], factory); - } else if (typeof exports !== "undefined") { - factory(require("react")); - } else { - var mod = { - exports: { - } - }; - factory(global.react); - global.input = mod.exports; - } -})(this, function(_react) { - "use strict"; - _react = _interopRequireDefault(_react); - window.React = _react.default; -}); -"# -); - -// exports_variable -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - exports_variable, - r#" -export var foo = 1; -export var foo2 = 1, bar = 2; -export var foo3 = function () {}; -export var foo4; -export let foo5 = 2; -export let foo6; -export const foo7 = 3; -export function foo8 () {} -export class foo9 {} - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.foo8 = foo8; - _exports.foo7 = _exports.foo6 = _exports.foo5 = _exports.foo4 = _exports.foo3 = _exports.bar = _exports.foo2 = _exports.foo = void 0; - var foo = 1; - _exports.foo = foo; - var foo2 = 1, - bar = 2; - _exports.foo2 = foo2; - _exports.bar = bar; - - var foo3 = function () {}; - - _exports.foo3 = foo3; - var foo4; - _exports.foo4 = foo4; - let foo5 = 2; - _exports.foo5 = foo5; - let foo6; - _exports.foo6 = foo6; - const foo7 = 3; - _exports.foo7 = foo7; - - function foo8() {} - - class foo9 {} - - _exports.foo9 = foo9; -}); - -"# -); - -// export_named -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_named, - r#" -var foo; -export {foo}; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.foo = void 0; - var foo; - _exports.foo = foo; -}); - -"# -); - -// export_default_11 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_11, - r#" -export default new Cachier() - -export function Cachier(databaseName) {} - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.Cachier = Cachier; - _exports.default = void 0; - - var _default = new Cachier(); - - _exports.default = _default; - - function Cachier(databaseName) {} -}); - -"# -); - -// module_id_with_overridden_global - -// export_from_4 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_from_4, - r#" -export {foo as bar} from "foo"; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); - } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); - } else { - var mod = { - exports: {} - }; - factory(mod.exports, global.foo); - global.input = mod.exports; - } -})(this, function (_exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "bar", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); -}); - -"# -); - -// override_import_name - -// export_default_3 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_3, - r#" -export default []; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var _default = []; - _exports.default = _default; -}); - -"# -); - -// imports_exact_globals_false_with_overrides - -// imports_exact_globals_true_with_overrides - -// imports_default -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - imports_default, - r#" -import foo from "foo"; -import {default as foo2} from "foo"; - -foo; -foo2; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["foo"], factory); - } else if (typeof exports !== "undefined") { - factory(require("foo")); - } else { - var mod = { - exports: {} - }; - factory(global.foo); - global.input = mod.exports; - } -})(this, function (_foo) { - "use strict"; - - _foo = _interopRequireDefault(_foo); - _foo.default; - _foo.default; -}); - -"# -); - -// export_named_3 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_named_3, - r#" -var foo, bar; -export {foo as default, bar}; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.bar = _exports.default = void 0; - var foo, bar; - _exports.default = foo; - _exports.bar = bar; -}); - -"# -); - -// imports_glob -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - imports_glob, - r#" -import * as foo from "foo"; - -foo; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["foo"], factory); - } else if (typeof exports !== "undefined") { - factory(require("foo")); - } else { - var mod = { - exports: {} - }; - factory(global.foo); - global.input = mod.exports; - } -})(this, function (foo) { - "use strict"; - - foo = _interopRequireWildcard(foo); - foo; -}); - -"# -); - -// export_default_6 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_6, - r#" -export default class {} - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - - class _default {} - - _exports.default = _default; -}); - -"# -); - -// export_default_5 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_5, - r#" -export default function () {} - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - function _default() {} - _exports.default = _default; -}); - -"# -); - -// hoist_function_exports -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - hoist_function_exports, - r#" -import { isEven } from "./evens"; - -export function nextOdd(n) { - return isEven(n) ? n + 1 : n + 2; + test_fixture( + if is_ts { ts_syntax() } else { syntax() }, + &|tester| tr(tester, config.clone(), is_ts), + &input, + &output, + ); } - -export var isOdd = (function (isEven) { - return function (n) { - return !isEven(n); - }; -})(isEven); - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports", "./evens"], factory); - } else if (typeof exports !== "undefined") { - factory(exports, require("./evens")); - } else { - var mod = { - exports: {} - }; - factory(mod.exports, global.evens); - global.input = mod.exports; - } -})(this, function (_exports, _evens) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.nextOdd = nextOdd; - _exports.isOdd = void 0; - - function nextOdd(n) { - return (0, _evens).isEven(n) ? n + 1 : n + 2; - } - - var isOdd = function (isEven) { - return function (n) { - return !isEven(n); - }; - }(_evens.isEven); - - _exports.isOdd = isOdd; -}); - -"# -); - -// export_from_2 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_from_2, - r#" -export {foo as default} from "foo"; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); - } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); - } else { - var mod = { - exports: {} - }; - factory(mod.exports, global.foo); - global.input = mod.exports; - } -})(this, function (_exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "default", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); -}); - -"# -); - -// imports_exact_globals_true - -// export_default_8 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_8, - r#" -export default class Foo {} - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - - class Foo {} - - _exports.default = Foo; -}); - -"# -); - -// module_name - -// module_id - -// export_named_5 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_named_5, - r#" -var foo, bar; -export {foo, bar}; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.bar = _exports.foo = void 0; - var foo, bar; - _exports.foo = foo; - _exports.bar = bar; -}); - -"# -); - -// imports_exact_globals_false -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - imports_exact_globals_false, - r#" -import fooBar1 from "foo-bar"; -import fooBar2 from "./mylib/foo-bar"; -import fizzBuzz from "fizzbuzz"; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["foo-bar", "./mylib/foo-bar", "fizzbuzz"], factory); - } else if (typeof exports !== "undefined") { - factory(require("foo-bar"), require("./mylib/foo-bar"), require("fizzbuzz")); - } else { - var mod = { - exports: {} - }; - factory(global.fooBar, global.fooBar, global.fizzbuzz); - global.input = mod.exports; - } -})(this, function (_fooBar, _fooBar1, _fizzbuzz) { - "use strict"; - - _fooBar = _interopRequireDefault(_fooBar); - _fooBar1 = _interopRequireDefault(_fooBar1); - _fizzbuzz = _interopRequireDefault(_fizzbuzz); -}); - -"# -); - -// module_id_with_overridden_global_in_namespace - -// regression_4192 - -// export_default_10 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_10, - r#" -export default (function(){return "foo"})(); - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - - var _default = function () { - return "foo"; - }(); - - _exports.default = _default; -}); - -"# -); - -// export_from -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_from, - r#" -export {foo} from "foo"; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); - } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); - } else { - var mod = { - exports: {} - }; - factory(mod.exports, global.foo); - global.input = mod.exports; - } -})(this, function (_exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "foo", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); -}); - -"# -); - -// export_from_5 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_from_5, - r#" -export {foo, bar} from "foo"; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); - } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); - } else { - var mod = { - exports: {} - }; - factory(mod.exports, global.foo); - global.input = mod.exports; - } -})(this, function (_exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "foo", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); - Object.defineProperty(_exports, "bar", { - enumerable: true, - get: function () { - return _foo.bar; - } - }); -}); - -"# -); - -// module_name_with_overridden_global - -// export_default_2 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_2, - r#" -export default {}; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var _default = {}; - _exports.default = _default; -}); - -"# -); - -// imports_named -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - imports_named, - r#" -import {bar} from "foo"; -import {bar2, baz} from "foo"; -import {bar as baz2} from "foo"; -import {bar as baz3, xyz} from "foo"; - -bar; -bar2; -baz; -baz2; -baz3; -xyz; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["foo"], factory); - } else if (typeof exports !== "undefined") { - factory(require("foo")); - } else { - var mod = { - exports: {} - }; - factory(global.foo); - global.input = mod.exports; - } -})(this, function (_foo) { - "use strict"; - - _foo.bar; - _foo.bar2; - _foo.baz; - _foo.bar; - _foo.bar; - _foo.xyz; -}); - -"# -); - -// imports_mixing -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - imports_mixing, - r#" -import foo, {baz as xyz} from "foo"; -xyz; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["foo"], factory); - } else if (typeof exports !== "undefined") { - factory(require("foo")); - } else { - var mod = { - exports: {} - }; - factory(global.foo); - global.input = mod.exports; - } -})(this, function (_foo) { - "use strict"; - - _foo = _interopRequireWildcard(_foo); - _foo.baz; -}); - -"# -); - -// remap -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - remap, - r#" -export var test = 2; -test = 5; -test++; - -(function () { - var test = 2; - test = 3; - test++; -})(); - -var a = 2; -export { a }; -a = 3; - -var b = 2; -export { b as c }; -b = 3; - -var d = 3; -export { d as e, d as f }; -d = 4; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - var ref; - _exports.f = _exports.e = _exports.c = _exports.a = _exports.test = void 0 - var test = 2; - _exports.test = test; - _exports.test = test = 5; - ref = test++, _exports.test = test, ref; - - (function () { - var test = 2; - test = 3; - test++; - })(); - - var a = 2; - _exports.a = a; - _exports.a = a = 3; - var b = 2; - _exports.c = b; - _exports.c = b = 3; - var d = 3; - _exports.e = d; - _exports.f = d; - _exports.f = _exports.e = d = 4; -}); - -"# -); - -// get_module_name_option - -// export_named_2 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_named_2, - r#" -var foo; -export {foo as default}; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var foo; - _exports.default = foo; -}); - -"# -); - -// export_default_7 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_7, - r#" -export default function foo () {} - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - function foo() {} - _exports.default = foo; - -}); - -"# -); - -// override_export_name - -// non_default_imports -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - non_default_imports, - r#" -import { render } from "./lib/render"; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["./lib/render"], factory); - } else if (typeof exports !== "undefined") { - factory(require("./lib/render")); - } else { - var mod = { - exports: {} - }; - factory(global.render); - global.input = mod.exports; - } -})(this, function (_render) { - "use strict"; -}); - -"# -); - -// imports -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - imports, - r#" -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["foo", "foo-bar", "./directory/foo-bar"], factory); - } else if (typeof exports !== "undefined") { - factory(require("foo"), require("foo-bar"), require("./directory/foo-bar")); - } else { - var mod = { - exports: {} - }; - factory(global.foo, global.fooBar, global.fooBar); - global.input = mod.exports; - } -})(this, function (_foo, _fooBar, _fooBar1) { - "use strict"; -}); - -"# -); - -// export_default -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default, - r#" -export default 42; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var _default = 42; - _exports.default = _default; -}); - -"# -); - -// export_default_4 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_4, - r#" -export default foo; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var _default = foo; - _exports.default = _default; -}); - -"# -); - -// export_from_3 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_from_3, - r#" -export {foo as default, bar} from "foo"; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); - } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); - } else { - var mod = { - exports: {} - }; - factory(mod.exports, global.foo); - global.input = mod.exports; - } -})(this, function (_exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.defineProperty(_exports, "default", { - enumerable: true, - get: function () { - return _foo.foo; - } - }); - Object.defineProperty(_exports, "bar", { - enumerable: true, - get: function () { - return _foo.bar; - } - }); -}); - -"# -); - -// export_default_9 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_default_9, - r#" -var foo; -export { foo as default }; - - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = void 0; - var foo; - _exports.default = foo; -}); - -"# -); - -// overview -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - overview, - r#" -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; -import foo from "foo"; -import * as foo2 from "foo"; -import {bar} from "foo"; -import {foo as bar2} from "foo"; - -var test; -export {test}; -export var test2 = 5; - -export default test; - -bar; -bar2; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports", "foo", "foo-bar", "./directory/foo-bar"], factory); - } else if (typeof exports !== "undefined") { - factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar")); - } else { - var mod = { - exports: {} - }; - factory(mod.exports, global.foo, global.fooBar, global.fooBar); - global.input = mod.exports; - } -})(this, function (_exports, foo2, _fooBar, _fooBar1) { - "use strict"; - foo2 = _interopRequireWildcard(foo2); - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.default = _exports.test2 = _exports.test = void 0; - var test; - _exports.test = test; - var test2 = 5; - _exports.test2 = test2; - var _default = test; - _exports.default = _default; - foo2.bar; - foo2.foo; -}); - -"# -); - -// module_id_with_overridden_global_in_very_nested_namespace - -// export_named_4 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_named_4, - r#" -var foo; -export {foo as bar}; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports"], factory); - } else if (typeof exports !== "undefined") { - factory(exports); - } else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; - } -})(this, function (_exports) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - _exports.bar = void 0; - var foo; - _exports.bar = foo; -}); - -"# -); - -// export_from_6 -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - export_from_6, - r#" -export * from "foo"; - -"#, - r#" -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); - } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); - } else { - var mod = { - exports: {} - }; - factory(mod.exports, global.foo); - global.input = mod.exports; - } -})(this, function (_exports, _foo) { - "use strict"; - - Object.defineProperty(_exports, "__esModule", { - value: true - }); - Object.keys(_foo).forEach(function (key) { - if (key === "default" || key === "__esModule") return; - if (key in _exports && _exports[key] === _foo[key]) return; - Object.defineProperty(_exports, key, { - enumerable: true, - get: function () { - return _foo[key]; - } - }); - }); -}); - -"# -); - -// umd - -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - issue_456_1, - "import { join as e } from 'path'; -export const foo = function () { - function e(t) {} - return A(e, {}), e -}();", - "\ -(function(global, factory) { - if (typeof define === \"function\" && define.amd) { - define([\"exports\", \"path\"], factory); - } else if (typeof exports !== \"undefined\") { - factory(exports, require(\"path\")); - } else { - var mod = { - exports: { - } - }; - factory(mod.exports, global.path); - global.input = mod.exports; - } -})(this, function(_exports, _path) { - \"use strict\"; - Object.defineProperty(_exports, \"__esModule\", { - value: true - }); - _exports.foo = void 0; - const foo = function() { - function e(t) { - } - return A(e, {}), e; - }(); - _exports.foo = foo; -}); -" -); - -test!( - syntax(), - |tester| tr( - tester, - Config { - ..Default::default() - } - ), - issue_456_2, - "import { join as e } from 'path'; -export const foo = function () { - var e = 1; - return A(e, {}), e -}();", - "(function(global, factory) { - if (typeof define === \"function\" && define.amd) { - define([\"exports\", \"path\"], factory); - } else if (typeof exports !== \"undefined\") { - factory(exports, require(\"path\")); - } else { - var mod = { - exports: { - } - }; - factory(mod.exports, global.path); - global.input = mod.exports; - } -})(this, function(_exports, _path) { - \"use strict\"; - Object.defineProperty(_exports, \"__esModule\", { - value: true - }); - _exports.foo = void 0; - const foo = function() { - var e = 1; - return A(e, { - }), e; - }(); - _exports.foo = foo; -});" -); - -test!( - syntax(), - |t| tr( - t, - Config { - ..Default::default() - } - ), - issue_1018_1, - "async function foo() { - await import('foo'); - }", - " - (function(global, factory) { - if (typeof define === \"function\" && define.amd) { - define([], factory); - } else if (typeof exports !== \"undefined\") { - factory(); - } else { - var mod = { - exports: { - } - }; - factory(); - global.input = mod.exports; - } - })(this, function() { - \"use strict\"; - async function foo() { - await (exports === undefined ? new Promise(function(resolve, reject) { - require([ - \"foo\" - ], function(dep) { - resolve(dep); - }, function(err) { - reject(err); - }); - }) : Promise.resolve().then(function() { - return _interopRequireWildcard(require(\"foo\")); - })); - } - }); - ", - ok_if_code_eq -); - -// function_name_export_default_arrow_renaming_module_umd -test!( - ignore, - syntax(), - |tester| { - let unresolved_mark = Mark::new(); - let top_level_mark = Mark::new(); - - chain!( - resolver(unresolved_mark, top_level_mark, false), - function_name(), - shorthand(), - arrow(), - umd(tester.cm.clone(), unresolved_mark, Default::default()) - ) - }, - function_name_export_default_arrow_renaming_module_umd, - r#" -export default (a) => { -return { a() { return a } }; -} - -"#, - r#" -(function (global, factory) { -if (typeof define === "function" && define.amd) { - define(["exports"], factory); -} else if (typeof exports !== "undefined") { - factory(exports); -} else { - var mod = { - exports: {} - }; - factory(mod.exports); - global.input = mod.exports; -} -})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { -"use strict"; - -Object.defineProperty(_exports, "__esModule", { - value: true -}); -_exports.default = void 0; - -var _default = function _default(_a) { - return { - a: function a() { - return _a; - } - }; -}; - -_exports.default = _default; -}); - -"# -); diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify.rs b/crates/swc_ecma_transforms_optimization/tests/simplify.rs index bcc1b9a5f92..d961984f3c2 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify.rs @@ -2,15 +2,11 @@ #![deny(warnings)] -use std::{cell::RefCell, rc::Rc}; - use swc_common::{chain, pass::Repeat, Mark}; use swc_ecma_parser::{EsConfig, Syntax, TsConfig}; use swc_ecma_transforms_base::{helpers::inject_helpers, resolver}; use swc_ecma_transforms_compat::{es2015, es2016, es2017, es2018, es2022::class_properties, es3}; -use swc_ecma_transforms_module::{ - common_js::common_js, import_analysis::import_analyzer, util::Scope, -}; +use swc_ecma_transforms_module::{common_js::common_js, import_analysis::import_analyzer}; use swc_ecma_transforms_optimization::simplify::{ dce::dce, dead_branch_remover, expr_simplifier, inlining::inlining, simplifier, }; @@ -569,7 +565,6 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - let scope = Rc::new(RefCell::new(Scope::default())); chain!( decorators(Default::default()), resolver(unresolved_mark, top_level_mark, false), @@ -585,9 +580,13 @@ test!( Default::default() ), es3(true), - import_analyzer(Rc::clone(&scope)), + import_analyzer(false, false), inject_helpers(), - common_js(Mark::fresh(Mark::root()), Default::default(), Some(scope)), + common_js( + Mark::fresh(Mark::root()), + Default::default(), + Default::default() + ), ) }, issue_389_3, @@ -597,6 +596,9 @@ Foo.bar = true; ", " \"use strict\"; +Object.defineProperty(exports, \"__esModule\", { + value: true +}); var _foo = _interopRequireDefault(require(\"foo\")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { diff --git a/crates/swc_ecma_transforms_react/src/jsx/tests.rs b/crates/swc_ecma_transforms_react/src/jsx/tests.rs index e19712427c3..9722310bc4b 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/tests.rs @@ -1235,7 +1235,7 @@ test!( }, top_level_mark ), - common_js(top_level_mark, Default::default(), None) + common_js(top_level_mark, Default::default(), Default::default()) ) }, issue_351, @@ -1243,6 +1243,9 @@ test!(
;", "\"use strict\"; +Object.defineProperty(exports, \"__esModule\", { + value: true +}); var _react = _interopRequireDefault(require(\"react\")); _react.default.createElement(\"div\", null);" ); @@ -1282,13 +1285,20 @@ test!( }, top_level_mark ), - common_js(Mark::fresh(Mark::root()), Default::default(), None) + common_js( + Mark::fresh(Mark::root()), + Default::default(), + Default::default(), + ) ) }, issue_517, "import React from 'react';
Hello World
;", "\"use strict\"; +Object.defineProperty(exports, \"__esModule\", { + value: true +}); var _react = _interopRequireDefault(require(\"react\")); _react.default.createElement(\"div\", { style: \"white-space: pre\" diff --git a/crates/swc_ecma_transforms_react/src/refresh/tests.rs b/crates/swc_ecma_transforms_react/src/refresh/tests.rs index e21b4fa5f28..625ed7c49bd 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/tests.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/tests.rs @@ -1130,7 +1130,7 @@ test!( Some(t.comments.clone()), top_level_mark ), - common_js(unresolved_mark, Default::default(), None) + common_js(unresolved_mark, Default::default(), Default::default()) ) }, include_hook_signature_in_commonjs, @@ -1147,24 +1147,29 @@ test!( "use strict"; Object.defineProperty(exports, "__esModule", { - value: true + value: true + }); + Object.defineProperty(exports, "default", { + get: function() { + return App; + }, + enumerable: true }); - exports.default = App; var _hooks = require("./hooks"); var _foo = _interopRequireDefault(require("./foo")); var _s = $RefreshSig$(); function App() { - _s(); + _s(); - const bar = (0, _hooks).useFancyState(); - const foo = (0, _foo).default(); - return

{bar}

; + const bar = (0, _hooks.useFancyState)(); + const foo = (0, _foo.default)(); + return

{bar}

; } _s(App, "useFancyState{bar}\nuseFoo{foo}", false, function () { - return [_hooks.useFancyState, _foo.default]; + return [_hooks.useFancyState, _foo.default]; }); _c = App; diff --git a/crates/swc_ecma_transforms_testing/src/lib.rs b/crates/swc_ecma_transforms_testing/src/lib.rs index 2d2802de911..59a7f990909 100644 --- a/crates/swc_ecma_transforms_testing/src/lib.rs +++ b/crates/swc_ecma_transforms_testing/src/lib.rs @@ -160,7 +160,12 @@ impl<'a> Tester<'a> { .new_source_file(FileName::Real(name.into()), src.into()); let module = { - let mut p = Parser::new(syntax, StringInput::from(&*fm), Some(&self.comments)); + let mut p = Parser::new_from(Lexer::new( + syntax, + EsVersion::latest(), + StringInput::from(&*fm), + Some(&self.comments), + )); let res = p .parse_module() .map_err(|e| e.into_diagnostic(self.handler).emit()); diff --git a/crates/swc_ecma_transforms_typescript/src/import_export_assign.rs b/crates/swc_ecma_transforms_typescript/src/import_export_assign.rs new file mode 100644 index 00000000000..da9166f9e8d --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/src/import_export_assign.rs @@ -0,0 +1,226 @@ +use swc_common::{Mark, DUMMY_SP}; +use swc_ecma_ast::*; +use swc_ecma_utils::{member_expr, private_ident, quote_ident, quote_str, ExprFactory}; +use swc_ecma_visit::{ + as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitWith, +}; + +use crate::TsImportExportAssignConfig; + +pub fn import_export_assign( + unresolved_mark: Mark, + config: TsImportExportAssignConfig, +) -> impl Fold + VisitMut { + as_folder(ImportExportAssign { + unresolved_mark, + config, + export_assign: None, + found_import_assign: false, + found_export_assign: false, + }) +} + +struct ImportExportAssign { + unresolved_mark: Mark, + config: TsImportExportAssignConfig, + export_assign: Option, + found_import_assign: bool, + found_export_assign: bool, +} + +impl VisitMut for ImportExportAssign { + noop_visit_mut_type!(); + + fn visit_mut_module_items(&mut self, n: &mut Vec) { + n.visit_with(self); + + if !self.found_import_assign && !self.found_export_assign { + return; + } + + let mut stmts: Vec = Vec::with_capacity(n.len() + 2); + + let create_require = private_ident!("_createRequire"); + let require = private_ident!("__require"); + + if self.found_import_assign && self.config == TsImportExportAssignConfig::NodeNext { + stmts.push( + ModuleDecl::Import(ImportDecl { + span: DUMMY_SP, + specifiers: vec![ImportNamedSpecifier { + span: DUMMY_SP, + local: create_require.clone(), + imported: Some(quote_ident!("createRequire").into()), + is_type_only: false, + } + .into()], + src: quote_str!("module"), + type_only: false, + asserts: None, + }) + .into(), + ); + + // const __require = _createRequire(import.meta.url); + stmts.push( + Stmt::Decl( + create_require + .as_call( + DUMMY_SP, + vec![MetaPropExpr { + span: DUMMY_SP, + kind: MetaPropKind::ImportMeta, + } + .make_member(quote_ident!("url")) + .as_arg()], + ) + .into_var_decl(VarDeclKind::Const, require.clone().into()) + .into(), + ) + .into(), + ); + } + + let cjs_require = quote_ident!(DUMMY_SP.apply_mark(self.unresolved_mark), "require"); + + for item in n.drain(..) { + match item { + ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals(TsImportEqualsDecl { + span, + declare: false, + is_export, + is_type_only: false, + id, + module_ref: TsModuleRef::TsExternalModuleRef(TsExternalModuleRef { expr, .. }), + })) if self.config != TsImportExportAssignConfig::Preserve => match self.config { + TsImportExportAssignConfig::Classic => { + // const foo = require("foo") + let mut var_decl = cjs_require + .clone() + .as_call(DUMMY_SP, vec![expr.as_arg()]) + .into_var_decl(VarDeclKind::Const, id.clone().into()); + var_decl.span = span; + + stmts.push(Stmt::Decl(var_decl.into()).into()); + + // exports.foo = foo; + if is_export { + stmts.push( + id.make_assign_to( + op!("="), + member_expr!(DUMMY_SP, exports.foo).into(), + ) + .into_stmt() + .into(), + ) + } + } + TsImportExportAssignConfig::NodeNext => { + // const foo = __require("foo") + stmts.push( + Stmt::Decl( + require + .clone() + .as_call(span, vec![expr.as_arg()]) + .into_var_decl(VarDeclKind::Const, id.clone().into()) + .into(), + ) + .into(), + ); + + // export { foo } + if is_export { + stmts.push(ModuleItem::ModuleDecl( + NamedExport { + span, + specifiers: vec![ExportNamedSpecifier { + span, + orig: id.into(), + exported: None, + is_type_only: false, + } + .into()], + src: None, + type_only: false, + asserts: None, + } + .into(), + )) + } + } + TsImportExportAssignConfig::Preserve => unreachable!(), + }, + ModuleItem::ModuleDecl(ModuleDecl::TsExportAssignment(export_assign)) => { + self.export_assign.get_or_insert(export_assign); + } + _ => { + stmts.push(item); + } + } + } + + if let Some(export_assign) = self.export_assign.take() { + if self.config == TsImportExportAssignConfig::Classic { + let TsExportAssignment { expr, span } = export_assign; + + stmts.push( + Stmt::Expr(ExprStmt { + span, + expr: Box::new( + expr.make_assign_to( + op!("="), + member_expr!( + DUMMY_SP.apply_mark(self.unresolved_mark), + module.exports + ) + .as_pat_or_expr(), + ), + ), + }) + .into(), + ) + } else { + stmts.push(ModuleDecl::TsExportAssignment(export_assign).into()) + } + } + + *n = stmts; + } +} + +impl Visit for ImportExportAssign { + noop_visit_type!(); + + fn visit_module_items(&mut self, n: &[ModuleItem]) { + // `export =` is usually at the end of the code, let's scan from both sides + for item in AlternateEndIterator(n.iter(), false) { + match item { + ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals(..)) => { + self.found_import_assign = true + } + ModuleItem::ModuleDecl(ModuleDecl::TsExportAssignment(..)) => { + self.found_export_assign = true; + } + _ => { + if self.found_import_assign && self.found_export_assign { + return; + } + } + } + } + } +} + +struct AlternateEndIterator(T, bool); +impl Iterator for AlternateEndIterator { + type Item = T::Item; + + fn next(&mut self) -> Option { + self.1 = !self.1; + if self.1 { + self.0.next() + } else { + self.0.next_back() + } + } +} diff --git a/crates/swc_ecma_transforms_typescript/src/inline_enum.rs b/crates/swc_ecma_transforms_typescript/src/inline_enum.rs index 6dd2fed6049..d38e3c7b7c2 100644 --- a/crates/swc_ecma_transforms_typescript/src/inline_enum.rs +++ b/crates/swc_ecma_transforms_typescript/src/inline_enum.rs @@ -8,13 +8,13 @@ use swc_ecma_ast::{ }; use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; -use crate::TSEnumConfig; +use crate::TsEnumConfig; pub(crate) type TSEnumLit = Rc>>>; pub(crate) fn inline_enum( ts_enum_lit: TSEnumLit, - ts_enum_config: TSEnumConfig, + ts_enum_config: TsEnumConfig, ) -> impl Fold + VisitMut { as_folder(InlineEnum { ts_enum_lit, @@ -25,7 +25,7 @@ pub(crate) fn inline_enum( struct InlineEnum { ts_enum_lit: TSEnumLit, - ts_enum_config: TSEnumConfig, + ts_enum_config: TsEnumConfig, is_lhs: bool, } @@ -108,7 +108,7 @@ impl InlineEnum { fn skip(&self) -> bool { let Self { ts_enum_config: - TSEnumConfig { + TsEnumConfig { treat_const_enum_as_enum, ts_enum_is_readonly, }, diff --git a/crates/swc_ecma_transforms_typescript/src/lib.rs b/crates/swc_ecma_transforms_typescript/src/lib.rs index 95ebf29c260..bae50e038cc 100644 --- a/crates/swc_ecma_transforms_typescript/src/lib.rs +++ b/crates/swc_ecma_transforms_typescript/src/lib.rs @@ -2,5 +2,6 @@ #![allow(clippy::vec_box)] pub use self::strip::*; +mod import_export_assign; mod inline_enum; pub mod strip; diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs index 70e27e38f66..1112c6819a1 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip.rs @@ -13,15 +13,18 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_transforms_react::{parse_expr_for_jsx, JsxDirectives}; use swc_ecma_utils::{ - alias_ident_for, constructor::inject_after_super, is_literal, member_expr, prepend_stmt, - private_ident, prop_name_to_expr, quote_ident, var::VarCollector, ExprFactory, + alias_ident_for, constructor::inject_after_super, is_literal, prepend_stmt, private_ident, + prop_name_to_expr, var::VarCollector, ExprFactory, }; use swc_ecma_visit::{ as_folder, noop_visit_mut_type, visit_obj_and_computed, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; -use crate::inline_enum::{inline_enum, TSEnumLit}; +use crate::{ + import_export_assign::import_export_assign, + inline_enum::{inline_enum, TSEnumLit}, +}; /// Value does not contain TsLit::Bool type EnumValues = AHashMap>; @@ -84,17 +87,14 @@ pub struct Config { pub pragma_frag: Option, #[serde(default)] - pub ts_enum_config: TSEnumConfig, + pub ts_enum_config: TsEnumConfig, - /// If this is true, the following codes will be preserved. - /// - `import foo = require()` - /// - `export = expr` #[serde(default)] - pub preserve_import_export_assign: bool, + pub import_export_assign_config: TsImportExportAssignConfig, } #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)] -pub struct TSEnumConfig { +pub struct TsEnumConfig { /// Note: `const enum` will be inlined if this is false(default) /// All `const enum` *should be* inlined since it's align to tsc behavior. /// This option exists to allow you to roll back the old behavior of swc. @@ -108,7 +108,31 @@ pub struct TSEnumConfig { pub ts_enum_is_readonly: bool, } -impl TSEnumConfig { +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum TsImportExportAssignConfig { + /// - Rewrite `import foo = require("foo")` to `var foo = require("foo")` + /// - Rewrite `export =` to `module.exports = ` + /// Note: This option is deprecated as all CJS/AMD/UMD can handle it + /// themselves. + Classic, + /// preserve for CJS/AMD/UMD + Preserve, + /// Rewrite `import foo = require("foo")` to + /// ```javascript + /// import { createRequire as _createRequire } from "module"; + /// const __require = _createRequire(import.meta.url); + /// const foo = __require("foo"); + /// ``` + NodeNext, +} + +impl Default for TsImportExportAssignConfig { + fn default() -> Self { + Self::Classic + } +} + +impl TsEnumConfig { pub fn should_collect_enum(&self, is_const: bool) -> bool { self.ts_enum_is_readonly || (!self.treat_const_enum_as_enum && is_const) } @@ -984,7 +1008,7 @@ where items.visit_with(self); let mut stmts = Vec::with_capacity(items.len()); - let mut export_assign = None; + for mut item in items { self.is_side_effect_import = false; match item { @@ -1073,34 +1097,6 @@ where continue } - ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals(TsImportEqualsDecl { - span, - declare: false, - is_export: false, - is_type_only: false, - id, - module_ref: - TsModuleRef::TsExternalModuleRef(TsExternalModuleRef { span: _, expr }), - })) if !self.config.preserve_import_export_assign => { - let default = VarDeclarator { - span: DUMMY_SP, - name: id.into(), - init: Some(Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: quote_ident!("require").as_callee(), - args: vec![expr.as_arg()], - type_args: None, - }))), - definite: false, - }; - stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl { - span, - kind: VarDeclKind::Const, - declare: false, - decls: vec![default], - })))) - } - // Always strip type only import / exports ModuleItem::Stmt(Stmt::Empty(..)) | ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { @@ -1110,10 +1106,18 @@ where type_only: true, .. })) - | ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals(TsImportEqualsDecl { - is_type_only: true, - .. - })) => continue, + | ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals( + TsImportEqualsDecl { + is_type_only: true, + module_ref: TsModuleRef::TsExternalModuleRef(..), + .. + } + | TsImportEqualsDecl { + declare: true, + module_ref: TsModuleRef::TsExternalModuleRef(..), + .. + }, + )) => continue, ModuleItem::ModuleDecl(ModuleDecl::Import(mut i)) => { i.visit_mut_with(self); @@ -1217,26 +1221,6 @@ where } } - ModuleItem::ModuleDecl(ModuleDecl::TsExportAssignment(mut export)) => { - export.expr.visit_mut_with(self); - - let stmt = if self.config.preserve_import_export_assign { - ModuleDecl::TsExportAssignment(export).into() - } else { - ModuleItem::Stmt(Stmt::Expr(ExprStmt { - span: export.span, - expr: Box::new(Expr::Assign(AssignExpr { - span: export.span, - left: PatOrExpr::Expr(member_expr!(DUMMY_SP, module.exports)), - op: op!("="), - right: export.expr, - })), - })) - }; - - export_assign = Some(stmt); - } - ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(mut export)) => { // if specifier become empty, we remove export statement. @@ -1418,10 +1402,6 @@ where }))); } - if let Some(export_assign) = export_assign { - stmts.push(export_assign); - } - stmts } @@ -2050,6 +2030,12 @@ where } module.visit_mut_children_with(self); + + module.visit_mut_with(&mut import_export_assign( + self.top_level_ctxt.outer(), + self.config.import_export_assign_config, + )); + if !self.uninitialized_vars.is_empty() { prepend_stmt( &mut module.body, @@ -2098,7 +2084,7 @@ where items.visit_with(self); let mut stmts = Vec::with_capacity(items.len()); - let mut export_assign = None; + for mut item in take(items) { self.is_side_effect_import = false; match item { @@ -2205,34 +2191,6 @@ where stmts.push(item); } - ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals(TsImportEqualsDecl { - span, - declare: false, - is_export: false, - is_type_only: false, - id, - module_ref: - TsModuleRef::TsExternalModuleRef(TsExternalModuleRef { span: _, expr }), - })) if !self.config.preserve_import_export_assign => { - let default = VarDeclarator { - span: DUMMY_SP, - name: id.into(), - init: Some(Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: quote_ident!("require").as_callee(), - args: vec![expr.as_arg()], - type_args: None, - }))), - definite: false, - }; - stmts.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl { - span, - kind: VarDeclKind::Const, - declare: false, - decls: vec![default], - })))) - } - // Always strip type only import / exports ModuleItem::Stmt(Stmt::Empty(..)) | ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { @@ -2242,10 +2200,18 @@ where type_only: true, .. })) - | ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals(TsImportEqualsDecl { - is_type_only: true, - .. - })) => continue, + | ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals( + TsImportEqualsDecl { + is_type_only: true, + module_ref: TsModuleRef::TsExternalModuleRef(..), + .. + } + | TsImportEqualsDecl { + declare: true, + module_ref: TsModuleRef::TsExternalModuleRef(..), + .. + }, + )) => continue, ModuleItem::ModuleDecl(ModuleDecl::Import(mut i)) => { i.visit_mut_with(self); @@ -2334,26 +2300,6 @@ where } } - ModuleItem::ModuleDecl(ModuleDecl::TsExportAssignment(mut export)) => { - export.expr.visit_mut_with(self); - - let stmt = if self.config.preserve_import_export_assign { - ModuleDecl::TsExportAssignment(export).into() - } else { - ModuleItem::Stmt(Stmt::Expr(ExprStmt { - span: export.span, - expr: Box::new(Expr::Assign(AssignExpr { - span: export.span, - left: PatOrExpr::Expr(member_expr!(DUMMY_SP, module.exports)), - op: op!("="), - right: export.expr, - })), - })) - }; - - export_assign = Some(stmt); - } - ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(mut export)) => { // if specifier become empty, we remove export statement. @@ -2409,8 +2355,6 @@ where ) } - stmts.extend(export_assign); - self.keys = orig_keys; *items = stmts; diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index e9f34dc3dfc..86a1ec37079 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -11,7 +11,7 @@ use swc_ecma_transforms_compat::{ }; use swc_ecma_transforms_proposal::decorators; use swc_ecma_transforms_testing::{test, test_exec, test_fixture, Tester}; -use swc_ecma_transforms_typescript::{strip, strip::strip_with_config}; +use swc_ecma_transforms_typescript::{strip, strip::strip_with_config, TsImportExportAssignConfig}; use swc_ecma_visit::Fold; fn tr() -> impl Fold { @@ -4558,3 +4558,68 @@ let b = (_key = console.log(456), class { }); " ); + +test!( + Syntax::Typescript(TsConfig::default()), + |_| tr_config(None, None), + export_import_assign, + r#" + export import foo = require("foo"); + + foo(); + "#, + r#" + const foo = require("foo"); + exports.foo = foo; + foo(); + "# +); + +test!( + Syntax::Typescript(TsConfig::default()), + |_| tr_config( + Some(strip::Config { + import_export_assign_config: TsImportExportAssignConfig::NodeNext, + ..Default::default() + }), + None + ), + node_next_1, + r#" + import foo = require("foo"); + + foo(); + "#, + r#" + import { createRequire as _createRequire } from "module"; + const __require = _createRequire(import.meta.url); + const foo = __require("foo"); + + foo(); + "# +); + +test!( + Syntax::Typescript(TsConfig::default()), + |_| tr_config( + Some(strip::Config { + import_export_assign_config: TsImportExportAssignConfig::NodeNext, + ..Default::default() + }), + None + ), + node_next_2, + r#" + export import foo = require("foo"); + + foo(); + "#, + r#" + import { createRequire as _createRequire } from "module"; + const __require = _createRequire(import.meta.url); + const foo = __require("foo"); + export { foo }; + + foo(); + "# +); diff --git a/crates/swc_ecma_utils/Cargo.toml b/crates/swc_ecma_utils/Cargo.toml index 161631abafe..a3cecdb4d35 100644 --- a/crates/swc_ecma_utils/Cargo.toml +++ b/crates/swc_ecma_utils/Cargo.toml @@ -28,6 +28,7 @@ swc_common = {version = "0.18.0", path = "../swc_common"} swc_ecma_ast = {version = "0.79.0", path = "../swc_ecma_ast"} swc_ecma_visit = {version = "0.65.0", path = "../swc_ecma_visit"} tracing = "0.1.32" +unicode-id = "0.3" [dev-dependencies] swc_ecma_parser = {version = "0.105.0", path = "../swc_ecma_parser"} diff --git a/crates/swc_ecma_utils/src/factory.rs b/crates/swc_ecma_utils/src/factory.rs index 0952e0f0224..cf7ba2766e5 100644 --- a/crates/swc_ecma_utils/src/factory.rs +++ b/crates/swc_ecma_utils/src/factory.rs @@ -43,6 +43,11 @@ pub trait ExprFactory: Into { } } + #[cfg_attr(not(debug_assertions), inline(always))] + fn as_pat_or_expr(self) -> PatOrExpr { + PatOrExpr::Expr(Box::new(self.into())) + } + /// Creates an expression statement with `self`. #[cfg_attr(not(debug_assertions), inline(always))] fn into_stmt(self) -> Stmt { @@ -52,6 +57,15 @@ pub trait ExprFactory: Into { }) } + /// Creates a statement whcih return `self`. + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_return_stmt(self) -> ReturnStmt { + ReturnStmt { + span: DUMMY_SP, + arg: Some(Box::new(self.into())), + } + } + #[cfg_attr(not(debug_assertions), inline(always))] fn as_callee(self) -> Callee { Callee::Expr(Box::new(self.into())) @@ -67,6 +81,80 @@ pub trait ExprFactory: Into { } } + /// create a ArrowExpr which return self + /// - `(params) => $self` + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_lazy_arrow(self, params: Vec) -> ArrowExpr { + ArrowExpr { + span: DUMMY_SP, + params, + body: BlockStmtOrExpr::from(self), + is_async: false, + is_generator: false, + type_params: None, + return_type: None, + } + } + + /// create a Function which return self + /// - `function(params) { return $self; }` + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_lazy_fn(self, params: Vec) -> Function { + Function { + params, + decorators: Default::default(), + span: DUMMY_SP, + body: Some(BlockStmt { + span: DUMMY_SP, + stmts: vec![self.into_return_stmt().into()], + }), + is_generator: false, + is_async: false, + type_params: None, + return_type: None, + } + } + + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_lazy_auto(self, params: Vec, support_arrow: bool) -> Expr { + if support_arrow { + self.into_lazy_arrow(params).into() + } else { + self.into_lazy_fn(params.into_iter().map(Into::into).collect()) + .into_fn_expr(None) + .into() + } + } + + /// create a var declartor using self as init + /// - `var name = expr` + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_var_decl(self, kind: VarDeclKind, name: Pat) -> VarDecl { + let var_declarator = VarDeclarator { + span: DUMMY_SP, + name, + init: Some(Box::new(self.into())), + definite: false, + }; + + VarDecl { + span: DUMMY_SP, + kind, + declare: false, + decls: vec![var_declarator], + } + } + + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_new_expr(self, span: Span, args: Option>) -> NewExpr { + NewExpr { + span, + callee: Box::new(self.into()), + args, + type_args: None, + } + } + #[cfg_attr(not(debug_assertions), inline(always))] fn apply(self, span: Span, this: Box, args: Vec) -> Expr { let apply = self.make_member(Ident::new(js_word!("apply"), span)); @@ -101,6 +189,36 @@ pub trait ExprFactory: Into { }) } + #[cfg_attr(not(debug_assertions), inline(always))] + fn as_fn_decl(self) -> Option { + match self.into() { + Expr::Fn(FnExpr { + ident: Some(ident), + function, + }) => Some(FnDecl { + ident, + declare: false, + function, + }), + _ => None, + } + } + + #[cfg_attr(not(debug_assertions), inline(always))] + fn as_class_decl(self) -> Option { + match self.into() { + Expr::Class(ClassExpr { + ident: Some(ident), + class, + }) => Some(ClassDecl { + ident, + declare: false, + class, + }), + _ => None, + } + } + #[cfg_attr(not(debug_assertions), inline(always))] fn wrap_with_paren(self) -> Expr { let expr = Box::new(self.into()); @@ -133,6 +251,19 @@ pub trait ExprFactory: Into { }) } + /// Creates a assign expr `$lhs $op $self` + #[cfg_attr(not(debug_assertions), inline(always))] + fn make_assign_to(self, op: AssignOp, left: PatOrExpr) -> Expr { + let right = Box::new(self.into()); + + Expr::Assign(AssignExpr { + span: DUMMY_SP, + left, + op, + right, + }) + } + #[cfg_attr(not(debug_assertions), inline(always))] fn make_member(self, prop: T) -> Expr where @@ -163,18 +294,63 @@ pub trait ExprFactory: Into { impl> ExprFactory for T {} -pub trait IntoIndirectCall: Into { +pub trait IntoIndirectCall +where + Self: std::marker::Sized, +{ + type Item; + fn into_indirect(self) -> Self::Item; +} + +impl IntoIndirectCall for CallExpr { + type Item = CallExpr; + #[cfg_attr(not(debug_assertions), inline(always))] fn into_indirect(self) -> CallExpr { - let s = self.into(); + let callee = self.callee.into_indirect(); - let callee = Callee::Expr(Box::new(Expr::Seq(SeqExpr { - span: DUMMY_SP, - exprs: vec![0f64.into(), s.callee.expect_expr()], - }))); - - CallExpr { callee, ..s } + CallExpr { callee, ..self } } } -impl> IntoIndirectCall for T {} +impl IntoIndirectCall for Callee { + type Item = Callee; + + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_indirect(self) -> Callee { + SeqExpr { + span: DUMMY_SP, + exprs: vec![0f64.into(), self.expect_expr()], + } + .as_callee() + } +} + +pub trait FunctionFactory: Into { + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_fn_expr(self, ident: Option) -> FnExpr { + FnExpr { + ident, + function: self.into(), + } + } + + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_fn_decl(self, ident: Ident) -> FnDecl { + FnDecl { + ident, + declare: false, + function: self.into(), + } + } + + #[cfg_attr(not(debug_assertions), inline(always))] + fn into_method_prop(self, key: PropName) -> MethodProp { + MethodProp { + key, + function: self.into(), + } + } +} + +impl> FunctionFactory for T {} diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs index ec1d3ce7ab8..bf75a761c48 100644 --- a/crates/swc_ecma_utils/src/lib.rs +++ b/crates/swc_ecma_utils/src/lib.rs @@ -20,10 +20,11 @@ use swc_ecma_visit::{ Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::trace; +use unicode_id::UnicodeID; #[allow(deprecated)] pub use self::{ - factory::{ExprFactory, IntoIndirectCall}, + factory::{ExprFactory, FunctionFactory, IntoIndirectCall}, value::{ Type::{ self, Bool as BoolType, Null as NullType, Num as NumberType, Obj as ObjectType, @@ -2031,6 +2032,10 @@ pub fn is_valid_ident(s: &JsWord) -> bool { Ident::verify_symbol(s).is_ok() } +pub fn is_valid_prop_ident(s: &str) -> bool { + s.starts_with(|c: char| c.is_id_start()) && s.chars().all(|c: char| c.is_id_continue()) +} + pub fn drop_span(mut t: T) -> T where T: VisitMutWith, diff --git a/node-swc/__tests__/module_test.js b/node-swc/__tests__/module_test.js index 2f28fc0d403..27b196de9ad 100644 --- a/node-swc/__tests__/module_test.js +++ b/node-swc/__tests__/module_test.js @@ -24,7 +24,7 @@ it("should emit _interopRequireWildcard", () => { expect(out.code).toContain(`function _interopRequireWildcard`); expect(out.code).toContain( - `var foo = _interopRequireWildcard(require("foo"))` + `_interopRequireWildcard(require("foo"))` ); }); @@ -46,6 +46,6 @@ it("should work with amd and external helpers", () => { expect(out.map).toBeFalsy(); expect(out.code).toContain(`define("a",`); - expect(out.code).toContain(`_class_call_check(this, Foo);`); + expect(out.code).toContain(`_classCallCheck(this, Foo);`); expect(out.code).toContain(`_inherits(Bar, Foo);`); }); diff --git a/node-swc/__tests__/transform/issue_4606_test.mjs b/node-swc/__tests__/transform/issue_4606_test.mjs index bc6f2b793bb..1e417a70da9 100644 --- a/node-swc/__tests__/transform/issue_4606_test.mjs +++ b/node-swc/__tests__/transform/issue_4606_test.mjs @@ -5,91 +5,111 @@ import { fileURLToPath } from "url"; const __dirname = dirname(fileURLToPath(import.meta.url)); - it("should override react", async () => { - const { code } = await swc.transform(`export default function foo() { + const { code } = await swc.transform( + `export default function foo() { return
Hello
; -}`, { - "jsc": { - "target": "es2017", - "transform": { - "react": { - "runtime": "automatic" +}`, + { + jsc: { + target: "es2017", + transform: { + react: { + runtime: "automatic", + }, + }, + parser: { + syntax: "typescript", + tsx: true, + dts: true, + dynamicImport: true, + }, + externalHelpers: true, + }, + module: { + type: "es6", + }, } - }, - "parser": { - "syntax": "typescript", - "tsx": true, - "dts": true, - "dynamicImport": true - }, - "externalHelpers": true - }, - "module": { - "type": "es6" - } - }); - expect(code).toMatchInlineSnapshot(` -"import { jsx as _jsx } from \\"react/jsx-runtime\\"; -export default function foo() { - return /*#__PURE__*/ _jsx(\\"div\\", { - children: \\"Hello\\" - }); -}; -" -`); + ); + expect(code).toMatchInlineSnapshot(` + "import { jsx as _jsx } from \\"react/jsx-runtime\\"; + export default function foo() { + return /*#__PURE__*/ _jsx(\\"div\\", { + children: \\"Hello\\" + }); + }; + " + `); }); it("should merge correctly", async () => { - const filename = join(__dirname, "..", '..', 'tests', 'issue-4606', '1', 'index.tsx'); - console.log(filename); - const { code } = await swc.transformFile(filename, { - "jsc": { - "parser": { - "syntax": "typescript", - "tsx": true, - "dts": true, - "dynamicImport": true - } - }, - "module": { - "type": "es6" - } - }); - // It should transpile react jsx with automatic runtime - expect(code).toMatchInlineSnapshot(` -"import { jsx as _jsx } from \\"react/jsx-runtime\\"; -export default function foo() { - return /*#__PURE__*/ _jsx(\\"div\\", { - children: \\"Hello\\" + const filename = join( + __dirname, + "..", + "..", + "tests", + "issue-4606", + "1", + "index.tsx" + ); + console.log(filename); + const { code } = await swc.transformFile(filename, { + jsc: { + parser: { + syntax: "typescript", + tsx: true, + dts: true, + dynamicImport: true, + }, + }, + module: { + type: "es6", + }, }); -}; -" -`); + // It should transpile react jsx with automatic runtime + expect(code).toMatchInlineSnapshot(` + "import { jsx as _jsx } from \\"react/jsx-runtime\\"; + export default function foo() { + return /*#__PURE__*/ _jsx(\\"div\\", { + children: \\"Hello\\" + }); + }; + " + `); }); - it("module config should merged correctly", async () => { - const filename = join(__dirname, "..", '..', 'tests', 'issue-4606', '2', 'index.tsx'); - console.log(filename); - const { code } = await swc.transformFile(filename, { - "module": { - "type": "commonjs" - } - }); - // It should transpile react jsx with automatic runtime - expect(code).toMatchInlineSnapshot(` + const filename = join( + __dirname, + "..", + "..", + "tests", + "issue-4606", + "2", + "index.tsx" + ); + console.log(filename); + const { code } = await swc.transformFile(filename, { + module: { + type: "commonjs", + }, + }); + // It should transpile react jsx with automatic runtime + expect(code).toMatchInlineSnapshot(` "\\"use strict\\"; Object.defineProperty(exports, \\"__esModule\\", { value: true }); -exports.default = foo; -var _jsxRuntime = require(\\"react/jsx-runtime\\"); +Object.defineProperty(exports, \\"default\\", { + get: ()=>foo, + enumerable: true +}); +const _jsxRuntime = require(\\"react/jsx-runtime\\"); function foo() { - return /*#__PURE__*/ (0, _jsxRuntime).jsx(\\"div\\", { + return /*#__PURE__*/ (0, _jsxRuntime.jsx)(\\"div\\", { children: \\"Hello\\" }); } " `); -}); \ No newline at end of file +}); diff --git a/node-swc/__tests__/transform/issue_4730_test.mjs b/node-swc/__tests__/transform/issue_4730_test.mjs index d016da6a5de..6456978c818 100644 --- a/node-swc/__tests__/transform/issue_4730_test.mjs +++ b/node-swc/__tests__/transform/issue_4730_test.mjs @@ -32,17 +32,18 @@ it("should work", async () => { }, }); expect(code).toMatchInlineSnapshot(` -"\\"use strict\\"; -var _interop_require_wildcard = require(\\"@swc/helpers/lib/_interop_require_wildcard.js\\").default; -var _b = require(\\"../packages/b/src/index\\"); -async function display() { - const displayA = await Promise.resolve().then(function() { - return _interop_require_wildcard(require(\\"../packages/a/src/index\\")); - }).then((c)=>c.displayA); - console.log(displayA()); - console.log((0, _b).displayB()); -} -display(); -" -`); + "\\"use strict\\"; + Object.defineProperty(exports, \\"__esModule\\", { + value: true + }); + const _interopRequireWildcard = require(\\"@swc/helpers/lib/_interop_require_wildcard.js\\").default; + const _b = require(\\"../packages/b/src/index\\"); + async function display() { + const displayA = await Promise.resolve(\\"../packages/a/src/index\\").then((p)=>_interopRequireWildcard(require(p))).then((c)=>c.displayA); + console.log(displayA()); + console.log((0, _b.displayB)()); + } + display(); + " + `); }); diff --git a/packages/swc-helpers/src/_export_star.mjs b/packages/swc-helpers/src/_export_star.mjs new file mode 100644 index 00000000000..58df26743d3 --- /dev/null +++ b/packages/swc-helpers/src/_export_star.mjs @@ -0,0 +1,12 @@ +export default function _exportStar(from, to) { + Object.keys(from).forEach(function (k) { + if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) + Object.defineProperty(to, k, { + enumerable: true, + get: function () { + return from[k]; + }, + }); + }); + return from; +}