├── .gitignore ├── LICENSE ├── README.md ├── compare.sh ├── dist ├── hoisted-fn │ ├── esbuild │ │ ├── entry-a.js │ │ └── entry-b.js │ ├── rollup │ │ ├── entry-a.js │ │ └── entry-b.js │ └── webpack │ │ ├── entry-a.js │ │ └── entry-b.js ├── order-of-eval │ ├── esbuild │ │ ├── entry-a.js │ │ └── entry-b.js │ ├── rollup │ │ ├── entry-a.js │ │ └── entry-b.js │ └── webpack │ │ ├── entry-a.js │ │ └── entry-b.js ├── tdz │ ├── esbuild │ │ ├── entry-a.js │ │ └── entry-b.js │ ├── rollup │ │ ├── entry-a.js │ │ └── entry-b.js │ └── webpack │ │ ├── entry-a.js │ │ └── entry-b.js └── treeshaking │ ├── esbuild │ ├── entry-a.js │ └── entry-b.js │ ├── rollup │ ├── entry-a.js │ └── entry-b.js │ └── webpack │ ├── entry-a.js │ └── entry-b.js ├── esbuild.sh ├── package.json ├── rollup.sh ├── src ├── hoisted-fn │ ├── a.mjs │ ├── b.mjs │ ├── entry-a.mjs │ └── entry-b.mjs ├── order-of-eval │ ├── a.mjs │ ├── b.mjs │ ├── entry-a.mjs │ └── entry-b.mjs ├── tdz │ ├── a.mjs │ ├── b.mjs │ ├── entry-a.mjs │ └── entry-b.mjs └── treeshaking │ ├── a.mjs │ ├── b.mjs │ ├── entry-a.mjs │ ├── entry-b.mjs │ └── package.json ├── tsconfig.json └── webpack.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | 93 | # Gatsby files 94 | .cache/ 95 | # Comment in the public line in if your project uses Gatsby and not Next.js 96 | # https://nextjs.org/blog/next-9-1#public-directory-support 97 | # public 98 | 99 | # vuepress build output 100 | .vuepress/dist 101 | 102 | # vuepress v2.x temp and cache directory 103 | .temp 104 | .cache 105 | 106 | # Docusaurus cache and generated files 107 | .docusaurus 108 | 109 | # Serverless directories 110 | .serverless/ 111 | 112 | # FuseBox cache 113 | .fusebox/ 114 | 115 | # DynamoDB Local files 116 | .dynamodb/ 117 | 118 | # TernJS port file 119 | .tern-port 120 | 121 | # Stores VSCode versions used for testing VSCode extensions 122 | .vscode-test 123 | 124 | # yarn v2 125 | .yarn/cache 126 | .yarn/unplugged 127 | .yarn/build-state.yml 128 | .yarn/install-state.gz 129 | .pnp.* 130 | 131 | package-lock.json 132 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 hardfist 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # circular-dependency-cases 2 | show how bundlers deal with circular dependencies 3 | 4 | 1. install using `npm install` 5 | 2. build all bundler output with `npm run build:all` 6 | 3. compare with `node` output using `npm run compare` 7 | -------------------------------------------------------------------------------- /compare.sh: -------------------------------------------------------------------------------- 1 | # set -x 2 | for case in $(ls ./dist | sort); do 3 | for bundler in $(ls "./dist/$case" | sort); do 4 | for entry in $(find "./dist/$case/$bundler" -name "entry*.js" | sort); do 5 | bn="$(basename $entry)" 6 | real="./src/$case/${bn%.js}.mjs" 7 | diff="$( node "$real" 2>&1 | ( node "$entry" 2>&1 | ( diff --changed-group-format="< %<> %>" /dev/fd/3 /dev/fd/4 ) 4<&0 ) 3<&0 )" 8 | diff_code=$? 9 | if [ $diff_code -ne 0 ]; then 10 | echo "$entry differed:" 11 | # some diff commands have slightly different outputs 12 | # only show changed lines 13 | echo "$(printf "$diff" | grep -e "^[<>]")" 14 | fi 15 | done 16 | done 17 | done 18 | -------------------------------------------------------------------------------- /dist/hoisted-fn/esbuild/entry-a.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | (() => { 3 | // src/hoisted-fn/b.mjs 4 | console.log("b.mjs evaluating"); 5 | a_default(); 6 | willTDZ(); 7 | var tdz = Date.now() > 0; 8 | function willTDZ2() { 9 | try { 10 | console.error(`b typeof tdz`, typeof tdz); 11 | } catch (e) { 12 | console.error("b threw on tdz"); 13 | } 14 | } 15 | function b_default() { 16 | console.log("b default()"); 17 | } 18 | 19 | // src/hoisted-fn/a.mjs 20 | console.log("a.mjs evaluating"); 21 | b_default(); 22 | willTDZ2(); 23 | var tdz2 = Date.now() > 0; 24 | function willTDZ() { 25 | try { 26 | console.error(`a typeof tdz`, typeof tdz2); 27 | } catch (e) { 28 | console.error("a did tdz"); 29 | } 30 | } 31 | function a_default() { 32 | console.log("a default()"); 33 | } 34 | })(); 35 | -------------------------------------------------------------------------------- /dist/hoisted-fn/esbuild/entry-b.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | (() => { 3 | // src/hoisted-fn/a.mjs 4 | console.log("a.mjs evaluating"); 5 | b_default(); 6 | willTDZ(); 7 | var tdz = Date.now() > 0; 8 | function willTDZ2() { 9 | try { 10 | console.error(`a typeof tdz`, typeof tdz); 11 | } catch (e) { 12 | console.error("a did tdz"); 13 | } 14 | } 15 | function a_default() { 16 | console.log("a default()"); 17 | } 18 | 19 | // src/hoisted-fn/b.mjs 20 | console.log("b.mjs evaluating"); 21 | a_default(); 22 | willTDZ2(); 23 | var tdz2 = Date.now() > 0; 24 | function willTDZ() { 25 | try { 26 | console.error(`b typeof tdz`, typeof tdz2); 27 | } catch (e) { 28 | console.error("b threw on tdz"); 29 | } 30 | } 31 | function b_default() { 32 | console.log("b default()"); 33 | } 34 | })(); 35 | -------------------------------------------------------------------------------- /dist/hoisted-fn/rollup/entry-a.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // b -> a -> b 4 | console.log('b.mjs evaluating'); 5 | a(); 6 | willTDZ(); 7 | 8 | // prevent inlining tdz as a const 9 | let tdz$1 = Date.now() > 0; 10 | function willTDZ$1() { 11 | try { 12 | console.error(`b typeof tdz`, typeof tdz$1); 13 | } catch (e) { 14 | console.error('b threw on tdz'); 15 | } 16 | } 17 | function b () { 18 | console.log('b default()'); 19 | } 20 | 21 | // a -> b -> a 22 | console.log('a.mjs evaluating'); 23 | b(); 24 | willTDZ$1(); 25 | 26 | // prevent inlining tdz as a const 27 | let tdz = Date.now() > 0; 28 | function willTDZ() { 29 | try { 30 | console.error(`a typeof tdz`, typeof tdz); 31 | } catch (e) { 32 | console.error('a did tdz'); 33 | } 34 | } 35 | function a () { 36 | console.log('a default()'); 37 | } 38 | -------------------------------------------------------------------------------- /dist/hoisted-fn/rollup/entry-b.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // a -> b -> a 4 | console.log('a.mjs evaluating'); 5 | b(); 6 | willTDZ(); 7 | 8 | // prevent inlining tdz as a const 9 | let tdz$1 = Date.now() > 0; 10 | function willTDZ$1() { 11 | try { 12 | console.error(`a typeof tdz`, typeof tdz$1); 13 | } catch (e) { 14 | console.error('a did tdz'); 15 | } 16 | } 17 | function a () { 18 | console.log('a default()'); 19 | } 20 | 21 | // b -> a -> b 22 | console.log('b.mjs evaluating'); 23 | a(); 24 | willTDZ$1(); 25 | 26 | // prevent inlining tdz as a const 27 | let tdz = Date.now() > 0; 28 | function willTDZ() { 29 | try { 30 | console.error(`b typeof tdz`, typeof tdz); 31 | } catch (e) { 32 | console.error('b threw on tdz'); 33 | } 34 | } 35 | function b () { 36 | console.log('b default()'); 37 | } 38 | -------------------------------------------------------------------------------- /dist/hoisted-fn/webpack/entry-a.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ([ 4 | /* 0 */, 5 | /* 1 */ 6 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 7 | 8 | __webpack_require__.r(__webpack_exports__); 9 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 10 | /* harmony export */ "default": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__), 11 | /* harmony export */ "willTDZ": () => (/* binding */ willTDZ) 12 | /* harmony export */ }); 13 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); 14 | // a -> b -> a 15 | 16 | console.log('a.mjs evaluating') 17 | _b_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]() 18 | _b_mjs__WEBPACK_IMPORTED_MODULE_0__.willTDZ() 19 | 20 | // prevent inlining tdz as a const 21 | let tdz = Date.now() > 0; 22 | function willTDZ() { 23 | try { 24 | console.error(`a typeof tdz`, typeof tdz) 25 | } catch (e) { 26 | console.error('a did tdz') 27 | } 28 | } 29 | /* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() { 30 | console.log('a default()'); 31 | } 32 | 33 | 34 | /***/ }), 35 | /* 2 */ 36 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 37 | 38 | __webpack_require__.r(__webpack_exports__); 39 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 40 | /* harmony export */ "default": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__), 41 | /* harmony export */ "willTDZ": () => (/* binding */ willTDZ) 42 | /* harmony export */ }); 43 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 44 | // b -> a -> b 45 | 46 | console.log('b.mjs evaluating') 47 | _a_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]() 48 | _a_mjs__WEBPACK_IMPORTED_MODULE_0__.willTDZ() 49 | 50 | // prevent inlining tdz as a const 51 | let tdz = Date.now() > 0; 52 | function willTDZ() { 53 | try { 54 | console.error(`b typeof tdz`, typeof tdz) 55 | } catch (e) { 56 | console.error('b threw on tdz') 57 | } 58 | } 59 | /* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() { 60 | console.log('b default()'); 61 | } 62 | 63 | 64 | /***/ }) 65 | /******/ ]); 66 | /************************************************************************/ 67 | /******/ // The module cache 68 | /******/ var __webpack_module_cache__ = {}; 69 | /******/ 70 | /******/ // The require function 71 | /******/ function __webpack_require__(moduleId) { 72 | /******/ // Check if module is in cache 73 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 74 | /******/ if (cachedModule !== undefined) { 75 | /******/ return cachedModule.exports; 76 | /******/ } 77 | /******/ // Create a new module (and put it into the cache) 78 | /******/ var module = __webpack_module_cache__[moduleId] = { 79 | /******/ // no module.id needed 80 | /******/ // no module.loaded needed 81 | /******/ exports: {} 82 | /******/ }; 83 | /******/ 84 | /******/ // Execute the module function 85 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 86 | /******/ 87 | /******/ // Return the exports of the module 88 | /******/ return module.exports; 89 | /******/ } 90 | /******/ 91 | /************************************************************************/ 92 | /******/ /* webpack/runtime/define property getters */ 93 | /******/ (() => { 94 | /******/ // define getter functions for harmony exports 95 | /******/ __webpack_require__.d = (exports, definition) => { 96 | /******/ for(var key in definition) { 97 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 98 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 99 | /******/ } 100 | /******/ } 101 | /******/ }; 102 | /******/ })(); 103 | /******/ 104 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 105 | /******/ (() => { 106 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 107 | /******/ })(); 108 | /******/ 109 | /******/ /* webpack/runtime/make namespace object */ 110 | /******/ (() => { 111 | /******/ // define __esModule on exports 112 | /******/ __webpack_require__.r = (exports) => { 113 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 114 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 115 | /******/ } 116 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 117 | /******/ }; 118 | /******/ })(); 119 | /******/ 120 | /************************************************************************/ 121 | var __webpack_exports__ = {}; 122 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 123 | (() => { 124 | __webpack_require__.r(__webpack_exports__); 125 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 126 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); 127 | 128 | 129 | 130 | })(); 131 | 132 | /******/ })() 133 | ; -------------------------------------------------------------------------------- /dist/hoisted-fn/webpack/entry-b.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ([ 4 | /* 0 */, 5 | /* 1 */ 6 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 7 | 8 | __webpack_require__.r(__webpack_exports__); 9 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 10 | /* harmony export */ "default": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__), 11 | /* harmony export */ "willTDZ": () => (/* binding */ willTDZ) 12 | /* harmony export */ }); 13 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); 14 | // b -> a -> b 15 | 16 | console.log('b.mjs evaluating') 17 | _a_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]() 18 | _a_mjs__WEBPACK_IMPORTED_MODULE_0__.willTDZ() 19 | 20 | // prevent inlining tdz as a const 21 | let tdz = Date.now() > 0; 22 | function willTDZ() { 23 | try { 24 | console.error(`b typeof tdz`, typeof tdz) 25 | } catch (e) { 26 | console.error('b threw on tdz') 27 | } 28 | } 29 | /* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() { 30 | console.log('b default()'); 31 | } 32 | 33 | 34 | /***/ }), 35 | /* 2 */ 36 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 37 | 38 | __webpack_require__.r(__webpack_exports__); 39 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 40 | /* harmony export */ "default": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__), 41 | /* harmony export */ "willTDZ": () => (/* binding */ willTDZ) 42 | /* harmony export */ }); 43 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 44 | // a -> b -> a 45 | 46 | console.log('a.mjs evaluating') 47 | _b_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]() 48 | _b_mjs__WEBPACK_IMPORTED_MODULE_0__.willTDZ() 49 | 50 | // prevent inlining tdz as a const 51 | let tdz = Date.now() > 0; 52 | function willTDZ() { 53 | try { 54 | console.error(`a typeof tdz`, typeof tdz) 55 | } catch (e) { 56 | console.error('a did tdz') 57 | } 58 | } 59 | /* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() { 60 | console.log('a default()'); 61 | } 62 | 63 | 64 | /***/ }) 65 | /******/ ]); 66 | /************************************************************************/ 67 | /******/ // The module cache 68 | /******/ var __webpack_module_cache__ = {}; 69 | /******/ 70 | /******/ // The require function 71 | /******/ function __webpack_require__(moduleId) { 72 | /******/ // Check if module is in cache 73 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 74 | /******/ if (cachedModule !== undefined) { 75 | /******/ return cachedModule.exports; 76 | /******/ } 77 | /******/ // Create a new module (and put it into the cache) 78 | /******/ var module = __webpack_module_cache__[moduleId] = { 79 | /******/ // no module.id needed 80 | /******/ // no module.loaded needed 81 | /******/ exports: {} 82 | /******/ }; 83 | /******/ 84 | /******/ // Execute the module function 85 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 86 | /******/ 87 | /******/ // Return the exports of the module 88 | /******/ return module.exports; 89 | /******/ } 90 | /******/ 91 | /************************************************************************/ 92 | /******/ /* webpack/runtime/define property getters */ 93 | /******/ (() => { 94 | /******/ // define getter functions for harmony exports 95 | /******/ __webpack_require__.d = (exports, definition) => { 96 | /******/ for(var key in definition) { 97 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 98 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 99 | /******/ } 100 | /******/ } 101 | /******/ }; 102 | /******/ })(); 103 | /******/ 104 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 105 | /******/ (() => { 106 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 107 | /******/ })(); 108 | /******/ 109 | /******/ /* webpack/runtime/make namespace object */ 110 | /******/ (() => { 111 | /******/ // define __esModule on exports 112 | /******/ __webpack_require__.r = (exports) => { 113 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 114 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 115 | /******/ } 116 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 117 | /******/ }; 118 | /******/ })(); 119 | /******/ 120 | /************************************************************************/ 121 | var __webpack_exports__ = {}; 122 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 123 | (() => { 124 | __webpack_require__.r(__webpack_exports__); 125 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 126 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); 127 | 128 | 129 | 130 | 131 | })(); 132 | 133 | /******/ })() 134 | ; -------------------------------------------------------------------------------- /dist/order-of-eval/esbuild/entry-a.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | (() => { 3 | // src/order-of-eval/b.mjs 4 | console.log("evaluating b.mjs"); 5 | 6 | // src/order-of-eval/a.mjs 7 | console.log("evaluating a.mjs"); 8 | 9 | // src/order-of-eval/entry-a.mjs 10 | console.log("done"); 11 | })(); 12 | -------------------------------------------------------------------------------- /dist/order-of-eval/esbuild/entry-b.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | (() => { 3 | // src/order-of-eval/a.mjs 4 | console.log("evaluating a.mjs"); 5 | 6 | // src/order-of-eval/b.mjs 7 | console.log("evaluating b.mjs"); 8 | 9 | // src/order-of-eval/entry-b.mjs 10 | console.log("done"); 11 | })(); 12 | -------------------------------------------------------------------------------- /dist/order-of-eval/rollup/entry-a.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // b -> a -> b 4 | console.log('evaluating b.mjs'); 5 | 6 | // a -> b -> a 7 | console.log('evaluating a.mjs'); 8 | 9 | console.log('done'); 10 | -------------------------------------------------------------------------------- /dist/order-of-eval/rollup/entry-b.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // a -> b -> a 4 | console.log('evaluating a.mjs'); 5 | 6 | // b -> a -> b 7 | console.log('evaluating b.mjs'); 8 | 9 | console.log('done'); 10 | -------------------------------------------------------------------------------- /dist/order-of-eval/webpack/entry-a.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ([ 4 | /* 0 */, 5 | /* 1 */ 6 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 7 | 8 | __webpack_require__.r(__webpack_exports__); 9 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); 10 | // a -> b -> a 11 | 12 | console.log('evaluating a.mjs'); 13 | 14 | 15 | /***/ }), 16 | /* 2 */ 17 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 18 | 19 | __webpack_require__.r(__webpack_exports__); 20 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 21 | // b -> a -> b 22 | 23 | console.log('evaluating b.mjs'); 24 | 25 | 26 | /***/ }) 27 | /******/ ]); 28 | /************************************************************************/ 29 | /******/ // The module cache 30 | /******/ var __webpack_module_cache__ = {}; 31 | /******/ 32 | /******/ // The require function 33 | /******/ function __webpack_require__(moduleId) { 34 | /******/ // Check if module is in cache 35 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 36 | /******/ if (cachedModule !== undefined) { 37 | /******/ return cachedModule.exports; 38 | /******/ } 39 | /******/ // Create a new module (and put it into the cache) 40 | /******/ var module = __webpack_module_cache__[moduleId] = { 41 | /******/ // no module.id needed 42 | /******/ // no module.loaded needed 43 | /******/ exports: {} 44 | /******/ }; 45 | /******/ 46 | /******/ // Execute the module function 47 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 48 | /******/ 49 | /******/ // Return the exports of the module 50 | /******/ return module.exports; 51 | /******/ } 52 | /******/ 53 | /************************************************************************/ 54 | /******/ /* webpack/runtime/make namespace object */ 55 | /******/ (() => { 56 | /******/ // define __esModule on exports 57 | /******/ __webpack_require__.r = (exports) => { 58 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 59 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 60 | /******/ } 61 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 62 | /******/ }; 63 | /******/ })(); 64 | /******/ 65 | /************************************************************************/ 66 | var __webpack_exports__ = {}; 67 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 68 | (() => { 69 | __webpack_require__.r(__webpack_exports__); 70 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 71 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); 72 | 73 | 74 | console.log('done'); 75 | 76 | })(); 77 | 78 | /******/ })() 79 | ; -------------------------------------------------------------------------------- /dist/order-of-eval/webpack/entry-b.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ([ 4 | /* 0 */, 5 | /* 1 */ 6 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 7 | 8 | __webpack_require__.r(__webpack_exports__); 9 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); 10 | // b -> a -> b 11 | 12 | console.log('evaluating b.mjs'); 13 | 14 | 15 | /***/ }), 16 | /* 2 */ 17 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 18 | 19 | __webpack_require__.r(__webpack_exports__); 20 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 21 | // a -> b -> a 22 | 23 | console.log('evaluating a.mjs'); 24 | 25 | 26 | /***/ }) 27 | /******/ ]); 28 | /************************************************************************/ 29 | /******/ // The module cache 30 | /******/ var __webpack_module_cache__ = {}; 31 | /******/ 32 | /******/ // The require function 33 | /******/ function __webpack_require__(moduleId) { 34 | /******/ // Check if module is in cache 35 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 36 | /******/ if (cachedModule !== undefined) { 37 | /******/ return cachedModule.exports; 38 | /******/ } 39 | /******/ // Create a new module (and put it into the cache) 40 | /******/ var module = __webpack_module_cache__[moduleId] = { 41 | /******/ // no module.id needed 42 | /******/ // no module.loaded needed 43 | /******/ exports: {} 44 | /******/ }; 45 | /******/ 46 | /******/ // Execute the module function 47 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 48 | /******/ 49 | /******/ // Return the exports of the module 50 | /******/ return module.exports; 51 | /******/ } 52 | /******/ 53 | /************************************************************************/ 54 | /******/ /* webpack/runtime/make namespace object */ 55 | /******/ (() => { 56 | /******/ // define __esModule on exports 57 | /******/ __webpack_require__.r = (exports) => { 58 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 59 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 60 | /******/ } 61 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 62 | /******/ }; 63 | /******/ })(); 64 | /******/ 65 | /************************************************************************/ 66 | var __webpack_exports__ = {}; 67 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 68 | (() => { 69 | __webpack_require__.r(__webpack_exports__); 70 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 71 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); 72 | 73 | 74 | console.log('done'); 75 | 76 | })(); 77 | 78 | /******/ })() 79 | ; -------------------------------------------------------------------------------- /dist/tdz/esbuild/entry-a.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | (() => { 3 | // src/tdz/b.mjs 4 | console.log("evaluating b.mjs"); 5 | var b = (() => { 6 | try { 7 | return a; 8 | } catch (e) { 9 | console.error("a is in TDZ"); 10 | process.exit(1); 11 | } 12 | })() + 1; 13 | 14 | // src/tdz/a.mjs 15 | console.log("evaluating a.mjs"); 16 | var a = (() => { 17 | try { 18 | return b; 19 | } catch (e) { 20 | console.error("b is in TDZ"); 21 | process.exit(1); 22 | } 23 | })() + 1; 24 | 25 | // src/tdz/entry-a.mjs 26 | console.log({ a, b }); 27 | })(); 28 | -------------------------------------------------------------------------------- /dist/tdz/esbuild/entry-b.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | (() => { 3 | // src/tdz/a.mjs 4 | console.log("evaluating a.mjs"); 5 | var a = (() => { 6 | try { 7 | return b; 8 | } catch (e) { 9 | console.error("b is in TDZ"); 10 | process.exit(1); 11 | } 12 | })() + 1; 13 | 14 | // src/tdz/b.mjs 15 | console.log("evaluating b.mjs"); 16 | var b = (() => { 17 | try { 18 | return a; 19 | } catch (e) { 20 | console.error("a is in TDZ"); 21 | process.exit(1); 22 | } 23 | })() + 1; 24 | 25 | // src/tdz/entry-b.mjs 26 | console.log({ a, b }); 27 | })(); 28 | -------------------------------------------------------------------------------- /dist/tdz/rollup/entry-a.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // b -> a -> b 4 | console.log('evaluating b.mjs'); 5 | 6 | const b = (() => { 7 | try { 8 | return a 9 | } catch { 10 | console.error('a is in TDZ'); 11 | process.exit(1); 12 | } 13 | })() + 1; 14 | 15 | // a -> b -> a 16 | console.log('evaluating a.mjs'); 17 | 18 | const a = (() => { 19 | try { 20 | return b 21 | } catch { 22 | console.error('b is in TDZ'); 23 | process.exit(1); 24 | } 25 | })() + 1; 26 | 27 | console.log({a, b}); 28 | -------------------------------------------------------------------------------- /dist/tdz/rollup/entry-b.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // a -> b -> a 4 | console.log('evaluating a.mjs'); 5 | 6 | const a = (() => { 7 | try { 8 | return b 9 | } catch { 10 | console.error('b is in TDZ'); 11 | process.exit(1); 12 | } 13 | })() + 1; 14 | 15 | // b -> a -> b 16 | console.log('evaluating b.mjs'); 17 | 18 | const b = (() => { 19 | try { 20 | return a 21 | } catch { 22 | console.error('a is in TDZ'); 23 | process.exit(1); 24 | } 25 | })() + 1; 26 | 27 | console.log({a, b}); 28 | -------------------------------------------------------------------------------- /dist/tdz/webpack/entry-a.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ([ 4 | /* 0 */, 5 | /* 1 */ 6 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 7 | 8 | __webpack_require__.r(__webpack_exports__); 9 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 10 | /* harmony export */ "a": () => (/* binding */ a) 11 | /* harmony export */ }); 12 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); 13 | // a -> b -> a 14 | 15 | console.log('evaluating a.mjs'); 16 | 17 | const a = (() => { 18 | try { 19 | return _b_mjs__WEBPACK_IMPORTED_MODULE_0__.b 20 | } catch { 21 | console.error('b is in TDZ'); 22 | process.exit(1); 23 | } 24 | })() + 1; 25 | 26 | 27 | /***/ }), 28 | /* 2 */ 29 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 30 | 31 | __webpack_require__.r(__webpack_exports__); 32 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 33 | /* harmony export */ "b": () => (/* binding */ b) 34 | /* harmony export */ }); 35 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 36 | // b -> a -> b 37 | 38 | console.log('evaluating b.mjs'); 39 | 40 | const b = (() => { 41 | try { 42 | return _a_mjs__WEBPACK_IMPORTED_MODULE_0__.a 43 | } catch { 44 | console.error('a is in TDZ'); 45 | process.exit(1); 46 | } 47 | })() + 1; 48 | 49 | 50 | /***/ }) 51 | /******/ ]); 52 | /************************************************************************/ 53 | /******/ // The module cache 54 | /******/ var __webpack_module_cache__ = {}; 55 | /******/ 56 | /******/ // The require function 57 | /******/ function __webpack_require__(moduleId) { 58 | /******/ // Check if module is in cache 59 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 60 | /******/ if (cachedModule !== undefined) { 61 | /******/ return cachedModule.exports; 62 | /******/ } 63 | /******/ // Create a new module (and put it into the cache) 64 | /******/ var module = __webpack_module_cache__[moduleId] = { 65 | /******/ // no module.id needed 66 | /******/ // no module.loaded needed 67 | /******/ exports: {} 68 | /******/ }; 69 | /******/ 70 | /******/ // Execute the module function 71 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 72 | /******/ 73 | /******/ // Return the exports of the module 74 | /******/ return module.exports; 75 | /******/ } 76 | /******/ 77 | /************************************************************************/ 78 | /******/ /* webpack/runtime/define property getters */ 79 | /******/ (() => { 80 | /******/ // define getter functions for harmony exports 81 | /******/ __webpack_require__.d = (exports, definition) => { 82 | /******/ for(var key in definition) { 83 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 84 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 85 | /******/ } 86 | /******/ } 87 | /******/ }; 88 | /******/ })(); 89 | /******/ 90 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 91 | /******/ (() => { 92 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 93 | /******/ })(); 94 | /******/ 95 | /******/ /* webpack/runtime/make namespace object */ 96 | /******/ (() => { 97 | /******/ // define __esModule on exports 98 | /******/ __webpack_require__.r = (exports) => { 99 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 100 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 101 | /******/ } 102 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 103 | /******/ }; 104 | /******/ })(); 105 | /******/ 106 | /************************************************************************/ 107 | var __webpack_exports__ = {}; 108 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 109 | (() => { 110 | __webpack_require__.r(__webpack_exports__); 111 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 112 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); 113 | 114 | 115 | console.log({a: _a_mjs__WEBPACK_IMPORTED_MODULE_0__.a, b: _b_mjs__WEBPACK_IMPORTED_MODULE_1__.b}) 116 | 117 | })(); 118 | 119 | /******/ })() 120 | ; -------------------------------------------------------------------------------- /dist/tdz/webpack/entry-b.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ([ 4 | /* 0 */, 5 | /* 1 */ 6 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 7 | 8 | __webpack_require__.r(__webpack_exports__); 9 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 10 | /* harmony export */ "b": () => (/* binding */ b) 11 | /* harmony export */ }); 12 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); 13 | // b -> a -> b 14 | 15 | console.log('evaluating b.mjs'); 16 | 17 | const b = (() => { 18 | try { 19 | return _a_mjs__WEBPACK_IMPORTED_MODULE_0__.a 20 | } catch { 21 | console.error('a is in TDZ'); 22 | process.exit(1); 23 | } 24 | })() + 1; 25 | 26 | 27 | /***/ }), 28 | /* 2 */ 29 | /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { 30 | 31 | __webpack_require__.r(__webpack_exports__); 32 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 33 | /* harmony export */ "a": () => (/* binding */ a) 34 | /* harmony export */ }); 35 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 36 | // a -> b -> a 37 | 38 | console.log('evaluating a.mjs'); 39 | 40 | const a = (() => { 41 | try { 42 | return _b_mjs__WEBPACK_IMPORTED_MODULE_0__.b 43 | } catch { 44 | console.error('b is in TDZ'); 45 | process.exit(1); 46 | } 47 | })() + 1; 48 | 49 | 50 | /***/ }) 51 | /******/ ]); 52 | /************************************************************************/ 53 | /******/ // The module cache 54 | /******/ var __webpack_module_cache__ = {}; 55 | /******/ 56 | /******/ // The require function 57 | /******/ function __webpack_require__(moduleId) { 58 | /******/ // Check if module is in cache 59 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 60 | /******/ if (cachedModule !== undefined) { 61 | /******/ return cachedModule.exports; 62 | /******/ } 63 | /******/ // Create a new module (and put it into the cache) 64 | /******/ var module = __webpack_module_cache__[moduleId] = { 65 | /******/ // no module.id needed 66 | /******/ // no module.loaded needed 67 | /******/ exports: {} 68 | /******/ }; 69 | /******/ 70 | /******/ // Execute the module function 71 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 72 | /******/ 73 | /******/ // Return the exports of the module 74 | /******/ return module.exports; 75 | /******/ } 76 | /******/ 77 | /************************************************************************/ 78 | /******/ /* webpack/runtime/define property getters */ 79 | /******/ (() => { 80 | /******/ // define getter functions for harmony exports 81 | /******/ __webpack_require__.d = (exports, definition) => { 82 | /******/ for(var key in definition) { 83 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 84 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 85 | /******/ } 86 | /******/ } 87 | /******/ }; 88 | /******/ })(); 89 | /******/ 90 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 91 | /******/ (() => { 92 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 93 | /******/ })(); 94 | /******/ 95 | /******/ /* webpack/runtime/make namespace object */ 96 | /******/ (() => { 97 | /******/ // define __esModule on exports 98 | /******/ __webpack_require__.r = (exports) => { 99 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 100 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 101 | /******/ } 102 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 103 | /******/ }; 104 | /******/ })(); 105 | /******/ 106 | /************************************************************************/ 107 | var __webpack_exports__ = {}; 108 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 109 | (() => { 110 | __webpack_require__.r(__webpack_exports__); 111 | /* harmony import */ var _b_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 112 | /* harmony import */ var _a_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); 113 | 114 | 115 | console.log({a: _a_mjs__WEBPACK_IMPORTED_MODULE_1__.a, b: _b_mjs__WEBPACK_IMPORTED_MODULE_0__.b}) 116 | 117 | })(); 118 | 119 | /******/ })() 120 | ; -------------------------------------------------------------------------------- /dist/treeshaking/esbuild/entry-a.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | (() => { 3 | })(); 4 | -------------------------------------------------------------------------------- /dist/treeshaking/esbuild/entry-b.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | (() => { 3 | })(); 4 | -------------------------------------------------------------------------------- /dist/treeshaking/rollup/entry-a.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // b -> a -> b 4 | willTDZ(); 5 | 6 | // prevent inlining tdz as a const 7 | let tdz$1 = Date.now() > 0; 8 | function willTDZ$1() { 9 | try { 10 | console.error(`b typeof tdz`, typeof tdz$1); 11 | } catch (e) { 12 | console.error('b threw on tdz'); 13 | } 14 | } 15 | 16 | willTDZ$1(); 17 | 18 | // prevent inlining tdz as a const 19 | let tdz = Date.now() > 0; 20 | function willTDZ() { 21 | try { 22 | console.error(`a typeof tdz`, typeof tdz); 23 | } catch (e) { 24 | console.error('a did tdz'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dist/treeshaking/rollup/entry-b.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | willTDZ(); 4 | 5 | // prevent inlining tdz as a const 6 | let tdz$1 = Date.now() > 0; 7 | function willTDZ$1() { 8 | try { 9 | console.error(`a typeof tdz`, typeof tdz$1); 10 | } catch (e) { 11 | console.error('a did tdz'); 12 | } 13 | } 14 | 15 | // b -> a -> b 16 | willTDZ$1(); 17 | 18 | // prevent inlining tdz as a const 19 | let tdz = Date.now() > 0; 20 | function willTDZ() { 21 | try { 22 | console.error(`b typeof tdz`, typeof tdz); 23 | } catch (e) { 24 | console.error('b threw on tdz'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dist/treeshaking/webpack/entry-a.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ // The require scope 4 | /******/ var __webpack_require__ = {}; 5 | /******/ 6 | /************************************************************************/ 7 | /******/ /* webpack/runtime/make namespace object */ 8 | /******/ (() => { 9 | /******/ // define __esModule on exports 10 | /******/ __webpack_require__.r = (exports) => { 11 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 12 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 13 | /******/ } 14 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 15 | /******/ }; 16 | /******/ })(); 17 | /******/ 18 | /************************************************************************/ 19 | var __webpack_exports__ = {}; 20 | __webpack_require__.r(__webpack_exports__); 21 | 22 | 23 | 24 | /******/ })() 25 | ; -------------------------------------------------------------------------------- /dist/treeshaking/webpack/entry-b.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ // The require scope 4 | /******/ var __webpack_require__ = {}; 5 | /******/ 6 | /************************************************************************/ 7 | /******/ /* webpack/runtime/make namespace object */ 8 | /******/ (() => { 9 | /******/ // define __esModule on exports 10 | /******/ __webpack_require__.r = (exports) => { 11 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 12 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 13 | /******/ } 14 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 15 | /******/ }; 16 | /******/ })(); 17 | /******/ 18 | /************************************************************************/ 19 | var __webpack_exports__ = {}; 20 | __webpack_require__.r(__webpack_exports__); 21 | 22 | 23 | 24 | 25 | /******/ })() 26 | ; -------------------------------------------------------------------------------- /esbuild.sh: -------------------------------------------------------------------------------- 1 | set -xe 2 | for dir in $(find ./src -name entry-\*.mjs | xargs -n1 dirname | uniq); do 3 | for entry in $dir/entry*.mjs; do 4 | npm exec -- esbuild --target=es6 --bundle --outdir=dist/$(basename "${dir#./src/}")/esbuild $entry 5 | done 6 | done 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "circular-dependency-cases", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "build:all": "pnpm run build:esbuild && pnpm run build:rollup && pnpm run build:webpack", 7 | "build:esbuild": "sh esbuild.sh", 8 | "build:rollup": "sh rollup.sh", 9 | "build:webpack": "sh webpack.sh", 10 | "compare": "sh compare.sh" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "devDependencies": { 16 | "webpack": "5.89.0", 17 | "webpack-cli": "5.1.4", 18 | "rollup": "4.9.2", 19 | "esbuild": "0.19.11" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /rollup.sh: -------------------------------------------------------------------------------- 1 | set -xe 2 | for dir in $(find ./src -name entry-\*.mjs | xargs -n1 dirname | uniq); do 3 | for entry in $dir/entry*.mjs; do 4 | npm exec -- rollup --output.format=cjs --output.dir=dist/$(basename "${dir#./src/}")/rollup $entry 5 | done 6 | done 7 | -------------------------------------------------------------------------------- /src/hoisted-fn/a.mjs: -------------------------------------------------------------------------------- 1 | // a -> b -> a 2 | import * as b from './b.mjs'; 3 | console.log('a.mjs evaluating') 4 | b.default() 5 | b.willTDZ() 6 | 7 | // prevent inlining tdz as a const 8 | let tdz = Date.now() > 0; 9 | export function willTDZ() { 10 | try { 11 | console.error(`a typeof tdz`, typeof tdz) 12 | } catch (e) { 13 | console.error('a did tdz') 14 | } 15 | } 16 | export default function () { 17 | console.log('a default()'); 18 | } 19 | -------------------------------------------------------------------------------- /src/hoisted-fn/b.mjs: -------------------------------------------------------------------------------- 1 | // b -> a -> b 2 | import * as a from './a.mjs'; 3 | console.log('b.mjs evaluating') 4 | a.default() 5 | a.willTDZ() 6 | 7 | // prevent inlining tdz as a const 8 | let tdz = Date.now() > 0; 9 | export function willTDZ() { 10 | try { 11 | console.error(`b typeof tdz`, typeof tdz) 12 | } catch (e) { 13 | console.error('b threw on tdz') 14 | } 15 | } 16 | export default function () { 17 | console.log('b default()'); 18 | } 19 | -------------------------------------------------------------------------------- /src/hoisted-fn/entry-a.mjs: -------------------------------------------------------------------------------- 1 | import * as a from './a.mjs'; 2 | import * as b from './b.mjs'; 3 | -------------------------------------------------------------------------------- /src/hoisted-fn/entry-b.mjs: -------------------------------------------------------------------------------- 1 | import * as b from './b.mjs'; 2 | import * as a from './a.mjs'; 3 | 4 | -------------------------------------------------------------------------------- /src/order-of-eval/a.mjs: -------------------------------------------------------------------------------- 1 | // a -> b -> a 2 | import './b.mjs' 3 | console.log('evaluating a.mjs'); 4 | -------------------------------------------------------------------------------- /src/order-of-eval/b.mjs: -------------------------------------------------------------------------------- 1 | // b -> a -> b 2 | import './a.mjs'; 3 | console.log('evaluating b.mjs'); 4 | -------------------------------------------------------------------------------- /src/order-of-eval/entry-a.mjs: -------------------------------------------------------------------------------- 1 | import './a.mjs'; 2 | import './b.mjs'; 3 | console.log('done'); 4 | -------------------------------------------------------------------------------- /src/order-of-eval/entry-b.mjs: -------------------------------------------------------------------------------- 1 | import './b.mjs'; 2 | import './a.mjs'; 3 | console.log('done'); 4 | -------------------------------------------------------------------------------- /src/tdz/a.mjs: -------------------------------------------------------------------------------- 1 | // a -> b -> a 2 | import { b } from './b.mjs' 3 | console.log('evaluating a.mjs'); 4 | 5 | export const a = (() => { 6 | try { 7 | return b 8 | } catch { 9 | console.error('b is in TDZ'); 10 | process.exit(1); 11 | } 12 | })() + 1; 13 | -------------------------------------------------------------------------------- /src/tdz/b.mjs: -------------------------------------------------------------------------------- 1 | // b -> a -> b 2 | import { a } from './a.mjs'; 3 | console.log('evaluating b.mjs'); 4 | 5 | export const b = (() => { 6 | try { 7 | return a 8 | } catch { 9 | console.error('a is in TDZ'); 10 | process.exit(1); 11 | } 12 | })() + 1; 13 | -------------------------------------------------------------------------------- /src/tdz/entry-a.mjs: -------------------------------------------------------------------------------- 1 | import { a } from './a.mjs'; 2 | import { b } from './b.mjs'; 3 | console.log({a, b}) 4 | -------------------------------------------------------------------------------- /src/tdz/entry-b.mjs: -------------------------------------------------------------------------------- 1 | import { b } from './b.mjs'; 2 | import { a } from './a.mjs'; 3 | console.log({a, b}) 4 | -------------------------------------------------------------------------------- /src/treeshaking/a.mjs: -------------------------------------------------------------------------------- 1 | import * as b from './b.mjs'; 2 | b.willTDZ() 3 | 4 | // prevent inlining tdz as a const 5 | let tdz = Date.now() > 0; 6 | export function willTDZ() { 7 | try { 8 | console.error(`a typeof tdz`, typeof tdz) 9 | } catch (e) { 10 | console.error('a did tdz') 11 | } 12 | } -------------------------------------------------------------------------------- /src/treeshaking/b.mjs: -------------------------------------------------------------------------------- 1 | // b -> a -> b 2 | import * as a from './a.mjs'; 3 | a.willTDZ() 4 | 5 | // prevent inlining tdz as a const 6 | let tdz = Date.now() > 0; 7 | export function willTDZ() { 8 | try { 9 | console.error(`b typeof tdz`, typeof tdz) 10 | } catch (e) { 11 | console.error('b threw on tdz') 12 | } 13 | } -------------------------------------------------------------------------------- /src/treeshaking/entry-a.mjs: -------------------------------------------------------------------------------- 1 | import * as a from './a.mjs'; 2 | import * as b from './b.mjs'; 3 | -------------------------------------------------------------------------------- /src/treeshaking/entry-b.mjs: -------------------------------------------------------------------------------- 1 | import * as b from './b.mjs'; 2 | import * as a from './a.mjs'; 3 | 4 | -------------------------------------------------------------------------------- /src/treeshaking/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "treeshaking", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "keywords": [], 9 | "author": "", 10 | "license": "ISC", 11 | "sideEffects": false, 12 | "description": "" 13 | } 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "commonjs", /* Specify what module code is generated. */ 29 | // "rootDir": "./", /* Specify the root folder within your source files. */ 30 | // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 42 | // "resolveJsonModule": true, /* Enable importing .json files. */ 43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 45 | 46 | /* JavaScript Support */ 47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 50 | 51 | /* Emit */ 52 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 58 | // "outDir": "./", /* Specify an output folder for all emitted files. */ 59 | // "removeComments": true, /* Disable emitting comments. */ 60 | // "noEmit": true, /* Disable emitting files from a compilation. */ 61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 68 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 75 | 76 | /* Interop Constraints */ 77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ 79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 80 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 82 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 83 | 84 | /* Type Checking */ 85 | "strict": true, /* Enable all strict type-checking options. */ 86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 104 | 105 | /* Completeness */ 106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /webpack.sh: -------------------------------------------------------------------------------- 1 | set -xe 2 | for dir in $(find ./src -name entry-\*.mjs | xargs -n1 dirname | uniq); do 3 | for entry in $dir/entry*.mjs; do 4 | npm exec -- webpack build --target=node --mode=none --entry=$entry -o dist/$(basename "${dir#./src/}")/webpack --output-filename $(basename "${entry%.mjs}.js") 5 | done 6 | done 7 | --------------------------------------------------------------------------------