diff --git a/.github/workflows/node-windows.yml b/.github/workflows/node-windows.yml index 934baa0cfb3..f975b346dc6 100644 --- a/.github/workflows/node-windows.yml +++ b/.github/workflows/node-windows.yml @@ -23,7 +23,8 @@ jobs: node-version: ${{ matrix.node }} - name: Check npm version # This is only necessary until we dump Node 6 - run: IF ${{ matrix.node }} LSS 8 npm i npm@5 -g + run: if [ ${{ matrix.node }} -lt 8 ]; then npm i npm@5 -g; fi; + shell: bash - name: Install dependencies run: npm ci --ignore-scripts - name: Run tests diff --git a/LICENSE.md b/LICENSE.md index 5cc0382e517..993c1034873 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -28,6 +28,33 @@ The published Rollup artifact additionally contains code with the following lice MIT, ISC, Apache-2.0 # Bundled dependencies: +## acorn-export-ns-from +License: MIT +By: Adrian Heine +Repository: https://github.com/acornjs/acorn-export-ns-from + +> Copyright (C) 2017-2018 by Adrian Heine +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. + +--------------------------------------- + ## acorn-import-meta License: MIT By: Adrian Heine @@ -150,13 +177,13 @@ Repository: jonschlinkert/fill-range ## hash.js License: MIT By: Fedor Indutny -Repository: git+ssh://git@github.com/indutny/hash.js.git +Repository: git@github.com:indutny/hash.js --------------------------------------- ## inherits License: ISC -Repository: git://github.com/isaacs/inherits.git +Repository: git://github.com/isaacs/inherits > The ISC License > @@ -265,7 +292,7 @@ Repository: micromatch/micromatch ## minimalistic-assert License: ISC -Repository: git+https://github.com/calvinmetcalf/minimalistic-assert.git +Repository: https://github.com/calvinmetcalf/minimalistic-assert.git > Copyright 2015 Calvin Metcalf > diff --git a/package-lock.json b/package-lock.json index 1c7e5a1f9ea..c2d0f5e7682 100644 --- a/package-lock.json +++ b/package-lock.json @@ -245,9 +245,9 @@ "dev": true }, "@types/node": { - "version": "12.11.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.1.tgz", - "integrity": "sha512-TJtwsqZ39pqcljJpajeoofYRfeZ7/I/OMUQ5pR4q5wOKf2ocrUvBAZUMhWsOvKx3dVc/aaV5GluBivt0sWqA5A==" + "version": "12.11.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.7.tgz", + "integrity": "sha512-JNbGaHFCLwgHn/iCckiGSOZ1XYHsKFwREtzPwSGCVld1SGhOlmZw2D4ZI94HQCrBHbADzW9m4LER/8olJTRGHA==" }, "@types/normalize-package-data": { "version": "2.4.0", @@ -292,6 +292,12 @@ "integrity": "sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw==", "dev": true }, + "acorn-export-ns-from": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/acorn-export-ns-from/-/acorn-export-ns-from-0.1.0.tgz", + "integrity": "sha512-QDQJBe2DfxNBIMxs+19XY2i/XXilJn+kPgX30HWNYK4IXoNj3ACNSWPU7szL0SzqjFyOG4zoZxG9P7JfNw5g7A==", + "dev": true + }, "acorn-import-meta": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/acorn-import-meta/-/acorn-import-meta-1.0.0.tgz", @@ -1073,9 +1079,9 @@ "dev": true }, "core-js": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.3.2.tgz", - "integrity": "sha512-S1FfZpeBchkhyoY76YAdFzKS4zz9aOK7EeFaNA2aJlyXyA+sgqz6xdxmLPGXEAf0nF44MVN1kSjrA9Kt3ATDQg==", + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.3.4.tgz", + "integrity": "sha512-BtibooaAmSOptGLRccsuX/dqgPtXwNgqcvYA6kOTTMzonRxZ+pJS4e+6mvVutESfXMeTnK8m3M+aBu3bkJbR+w==", "dev": true }, "core-util-is": { @@ -1378,9 +1384,9 @@ } }, "entities": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", - "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.0.tgz", + "integrity": "sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==", "dev": true }, "error-ex": { @@ -1463,9 +1469,9 @@ "dev": true }, "eslint": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.5.1.tgz", - "integrity": "sha512-32h99BoLYStT1iq1v2P9uwpyznQ4M2jRiFB6acitKz52Gqn+vPaMDUTB1bYi1WN4Nquj2w+t+bimYUG83DC55A==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.6.0.tgz", + "integrity": "sha512-PpEBq7b6qY/qrOmpYQ/jTMDYfuQMELR4g4WI1M/NaSDDD/bdcMb+dj4Hgks7p41kW2caXsPsEZAEAyAgjVVC0g==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -1475,9 +1481,9 @@ "debug": "^4.0.1", "doctrine": "^3.0.0", "eslint-scope": "^5.0.0", - "eslint-utils": "^1.4.2", + "eslint-utils": "^1.4.3", "eslint-visitor-keys": "^1.1.0", - "espree": "^6.1.1", + "espree": "^6.1.2", "esquery": "^1.0.1", "esutils": "^2.0.2", "file-entry-cache": "^5.0.1", @@ -1487,7 +1493,7 @@ "ignore": "^4.0.6", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", - "inquirer": "^6.4.1", + "inquirer": "^7.0.0", "is-glob": "^4.0.0", "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", @@ -1631,12 +1637,12 @@ } }, "eslint-utils": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.2.tgz", - "integrity": "sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==", + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.3.tgz", + "integrity": "sha512-fbBN5W2xdY45KulGXmLHZ3c3FHfVYmKg0IrAKGOkT/464PQsx2UeIzfz1RmEci+KLm1bBaAzZAh8+/E+XAeZ8Q==", "dev": true, "requires": { - "eslint-visitor-keys": "^1.0.0" + "eslint-visitor-keys": "^1.1.0" } }, "eslint-visitor-keys": { @@ -1646,13 +1652,13 @@ "dev": true }, "espree": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-6.1.1.tgz", - "integrity": "sha512-EYbr8XZUhWbYCqQRW0duU5LxzL5bETN6AjKBGy1302qqzPaCH10QbRg3Wvco79Z8x9WbiE8HYB4e75xl6qUYvQ==", + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-6.1.2.tgz", + "integrity": "sha512-2iUPuuPP+yW1PZaMSDM9eyVf8D5P0Hi8h83YtZ5bPc/zHYjII5khoixIUTMO794NOY8F/ThF1Bo8ncZILarUTA==", "dev": true, "requires": { - "acorn": "^7.0.0", - "acorn-jsx": "^5.0.2", + "acorn": "^7.1.0", + "acorn-jsx": "^5.1.0", "eslint-visitor-keys": "^1.1.0" } }, @@ -2581,6 +2587,15 @@ "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", "dev": true }, + "https-proxy-agent": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", + "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", + "dev": true, + "requires": { + "agent-base": "^4.3.0" + } + }, "human-signals": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz", @@ -2813,26 +2828,35 @@ "dev": true }, "inquirer": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.5.2.tgz", - "integrity": "sha512-cntlB5ghuB0iuO65Ovoi8ogLHiWGs/5yNrtUcKjFhSSiVeAIVpD7koaSU9RM8mpXw5YDi9RdYXGQMaOURB7ycQ==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.0.0.tgz", + "integrity": "sha512-rSdC7zelHdRQFkWnhsMu2+2SO41mpv2oF2zy4tMhmiLWkcKbOAs87fWAJhVXttKVwhdZvymvnuM95EyEXg2/tQ==", "dev": true, "requires": { - "ansi-escapes": "^3.2.0", + "ansi-escapes": "^4.2.1", "chalk": "^2.4.2", - "cli-cursor": "^2.1.0", + "cli-cursor": "^3.1.0", "cli-width": "^2.0.0", "external-editor": "^3.0.3", - "figures": "^2.0.0", - "lodash": "^4.17.12", - "mute-stream": "0.0.7", + "figures": "^3.0.0", + "lodash": "^4.17.15", + "mute-stream": "0.0.8", "run-async": "^2.2.0", "rxjs": "^6.4.0", - "string-width": "^2.1.0", + "string-width": "^4.1.0", "strip-ansi": "^5.1.0", "through": "^2.3.6" }, "dependencies": { + "ansi-escapes": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.2.1.tgz", + "integrity": "sha512-Cg3ymMAdN10wOk/VYfLV7KCQyv7EDirJ64500sU7n9UlmioEtDuU5Gd+hj73hXSU/ex7tHJSssmyftDdkMLO8Q==", + "dev": true, + "requires": { + "type-fest": "^0.5.2" + } + }, "ansi-regex": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", @@ -2850,6 +2874,78 @@ "supports-color": "^5.3.0" } }, + "cli-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", + "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", + "dev": true, + "requires": { + "restore-cursor": "^3.1.0" + } + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "figures": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-3.1.0.tgz", + "integrity": "sha512-ravh8VRXqHuMvZt/d8GblBeqDMkdJMBdv/2KntFH+ra5MXkO7nxNKpzQ3n6QD/2da1kH0aWmNISdvhM7gl2gVg==", + "dev": true, + "requires": { + "escape-string-regexp": "^1.0.5" + } + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true + }, + "mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "dev": true + }, + "onetime": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz", + "integrity": "sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==", + "dev": true, + "requires": { + "mimic-fn": "^2.1.0" + } + }, + "restore-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", + "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", + "dev": true, + "requires": { + "onetime": "^5.1.0", + "signal-exit": "^3.0.2" + } + }, + "string-width": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.1.0.tgz", + "integrity": "sha512-NrX+1dVVh+6Y9dnQ19pR0pP4FiEIlUvdTGn8pw6CKTNq5sgib2nIhmUNT5TAmhWmvKr3WcxBcP3E8nWezuipuQ==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^5.2.0" + } + }, "strip-ansi": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", @@ -2858,6 +2954,12 @@ "requires": { "ansi-regex": "^4.1.0" } + }, + "type-fest": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.5.2.tgz", + "integrity": "sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw==", + "dev": true } } }, @@ -3758,31 +3860,31 @@ } }, "markdown-it": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-9.0.1.tgz", - "integrity": "sha512-XC9dMBHg28Xi7y5dPuLjM61upIGPJG8AiHNHYqIaXER2KNnn7eKnM5/sF0ImNnyoV224Ogn9b1Pck8VH4k0bxw==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-10.0.0.tgz", + "integrity": "sha512-YWOP1j7UbDNz+TumYP1kpwnP0aEa711cJjrAQrzd0UXlbJfc5aAq0F/PZHjiioqDC1NKgvIMX+o+9Bk7yuM2dg==", "dev": true, "requires": { "argparse": "^1.0.7", - "entities": "~1.1.1", + "entities": "~2.0.0", "linkify-it": "^2.0.0", "mdurl": "^1.0.1", "uc.micro": "^1.0.5" } }, "markdownlint": { - "version": "0.16.0", - "resolved": "https://registry.npmjs.org/markdownlint/-/markdownlint-0.16.0.tgz", - "integrity": "sha512-Zo+iPezP3eM6lLhKepkUw+X98H44lipIdx4d6faaugfB0+7VuDB3R0hXmx7z9F1N3/ypn46oOFgAD9iF++Ie6A==", + "version": "0.17.2", + "resolved": "https://registry.npmjs.org/markdownlint/-/markdownlint-0.17.2.tgz", + "integrity": "sha512-vsxopn0qEdm0P2XI3S9sVA+jvjKjR8lHZ+0FKlusth+1UK9tI29mRFkKeZPERmbWsMehJcogfMieBUkMgNEFkQ==", "dev": true, "requires": { - "markdown-it": "9.0.1" + "markdown-it": "10.0.0" } }, "markdownlint-cli": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/markdownlint-cli/-/markdownlint-cli-0.18.0.tgz", - "integrity": "sha512-mQ2zvjMLoy0P2kb9Y03SqC24WPH4fTRN0/CyCorB122c4Chg9vWJKgUKBz3KR7swpzqmlI0SYq/7Blbqe4kb2g==", + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/markdownlint-cli/-/markdownlint-cli-0.19.0.tgz", + "integrity": "sha512-5hUEBAmbCVJflws6841HJ0KTZdgGWYaPThoXPI6Wjn1VkoiYWsprNH0r3PvPmyGXtvbHJ7/7eGPde2a6cx8t0w==", "dev": true, "requires": { "commander": "~2.9.0", @@ -3792,7 +3894,8 @@ "js-yaml": "^3.13.1", "lodash.differencewith": "~4.5.0", "lodash.flatten": "~4.4.0", - "markdownlint": "~0.16.0", + "markdownlint": "~0.17.1", + "markdownlint-rule-helpers": "~0.5.0", "minimatch": "~3.0.4", "rc": "~1.2.7" }, @@ -3814,6 +3917,12 @@ } } }, + "markdownlint-rule-helpers": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/markdownlint-rule-helpers/-/markdownlint-rule-helpers-0.5.0.tgz", + "integrity": "sha512-6bJAV4TjUoDDnqxfb6EKTuZlpYI6vn4kerid7WTrZaEjsWuYDeYDAN+r4o+vbUYFZfJkiBU7NPBqPd4QJ1CZzQ==", + "dev": true + }, "matcher-collection": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/matcher-collection/-/matcher-collection-2.0.0.tgz", @@ -4207,9 +4316,9 @@ "dev": true }, "mute-stream": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", - "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, "nan": { @@ -5256,9 +5365,9 @@ } }, "rollup": { - "version": "1.25.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.25.0.tgz", - "integrity": "sha512-tcf5ThhnhOUaNrxBSABvaaX9uC8hNxgyJpJmDIXaCkKHq/nPocaDz/4F/KBDiUpOt/ThvUxFrUq3XkyWiyXQiQ==", + "version": "1.25.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.25.2.tgz", + "integrity": "sha512-+7z6Wab/L45QCPcfpuTZKwKiB0tynj05s/+s2U3F2Bi7rOLPr9UcjUwO7/xpjlPNXA/hwnth6jBExFRGyf3tMg==", "dev": true, "requires": { "@types/estree": "*", @@ -5267,9 +5376,9 @@ } }, "rollup-plugin-alias": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-alias/-/rollup-plugin-alias-2.1.0.tgz", - "integrity": "sha512-fbPLCkulSyNAqMvyvucGxlWCVE/+cqkFsFXN4exCX2Poti/+R0LgkhwOj/zqaytaZ4i1rCSXh+zZkVjgxlUBGg==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-alias/-/rollup-plugin-alias-2.2.0.tgz", + "integrity": "sha512-9ZK410qeFed4gGrHoojBpxLsHF74vPgsheGg9JRW5RbALAxqdvJbd357mSqWBqUrBfRVnZnNUXTZdYLxxQEA5A==", "dev": true, "requires": { "slash": "^3.0.0" @@ -6031,26 +6140,14 @@ "version": "3.2.6", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", - "dev": true, "requires": { "ms": "^2.1.1" } }, - "https-proxy-agent": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", - "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", - "dev": true, - "requires": { - "agent-base": "^4.3.0", - "debug": "^3.1.0" - } - }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" } } }, diff --git a/package.json b/package.json index fa5e7e38791..a06b127913e 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "@types/chokidar": "^2.1.3", "@types/micromatch": "^3.1.0", "@types/minimist": "^1.2.0", + "acorn-export-ns-from": "^0.1.0", "acorn-import-meta": "^1.0.0", "acorn-jsx": "^5.1.0", "acorn-walk": "^7.0.0", @@ -79,12 +80,12 @@ "chokidar": "^2.1.8", "codecov": "^3.6.1", "console-group": "^0.3.3", - "core-js": "^3.3.2", + "core-js": "^3.3.4", "cross-os": "^1.3.0", "date-time": "^3.1.0", "es5-shim": "^4.5.13", "es6-shim": "^0.35.5", - "eslint": "^6.5.1", + "eslint": "^6.6.0", "eslint-plugin-import": "^2.18.2", "execa": "^3.2.0", "fixturify": "^1.2.0", @@ -94,7 +95,7 @@ "lint-staged": "^9.4.2", "locate-character": "^2.0.5", "magic-string": "^0.25.4", - "markdownlint-cli": "^0.18.0", + "markdownlint-cli": "^0.19.0", "micromatch": "^4.0.2", "minimist": "^1.2.0", "mocha": "^6.2.2", @@ -104,8 +105,8 @@ "pretty-ms": "^5.0.0", "require-relative": "^0.8.7", "requirejs": "^2.3.6", - "rollup": "^1.25.0", - "rollup-plugin-alias": "^2.1.0", + "rollup": "^1.25.2", + "rollup-plugin-alias": "^2.2.0", "rollup-plugin-buble": "^0.19.8", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-json": "^4.0.0", diff --git a/src/Chunk.ts b/src/Chunk.ts index e5b69e17544..bd077275922 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -1180,8 +1180,8 @@ export default class Chunk { } } if (module.getOrCreateNamespace().included) { - for (const reexportName of Object.keys(module.reexports)) { - const reexport = module.reexports[reexportName]; + for (const reexportName of Object.keys(module.reexportDescriptions)) { + const reexport = module.reexportDescriptions[reexportName]; const variable = reexport.module.getVariableForExportName(reexport.localName); if ((variable.module as Module).chunk !== this) { this.imports.add(variable); diff --git a/src/Graph.ts b/src/Graph.ts index 6585379e529..0ffa5a11fed 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -1,4 +1,5 @@ import * as acorn from 'acorn'; +import injectExportNsFrom from 'acorn-export-ns-from'; import injectImportMeta from 'acorn-import-meta'; import * as ESTree from 'estree'; import GlobalScope from './ast/scopes/GlobalScope'; @@ -172,7 +173,7 @@ export default class Graph { this.acornOptions = options.acorn ? { ...options.acorn } : {}; const acornPluginsToInject = []; - acornPluginsToInject.push(injectImportMeta); + acornPluginsToInject.push(injectImportMeta, injectExportNsFrom); if (options.experimentalTopLevelAwait) { (this.acornOptions as any).allowAwaitOutsideFunction = true; diff --git a/src/Module.ts b/src/Module.ts index 265b519c240..4f1965c2113 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -4,11 +4,10 @@ import { locate } from 'locate-character'; import MagicString from 'magic-string'; import extractAssignedNames from 'rollup-pluginutils/src/extractAssignedNames'; import { createInclusionContext, InclusionContext } from './ast/ExecutionContext'; -import ClassDeclaration from './ast/nodes/ClassDeclaration'; import ExportAllDeclaration from './ast/nodes/ExportAllDeclaration'; import ExportDefaultDeclaration from './ast/nodes/ExportDefaultDeclaration'; import ExportNamedDeclaration from './ast/nodes/ExportNamedDeclaration'; -import FunctionDeclaration from './ast/nodes/FunctionDeclaration'; +import ExportSpecifier from './ast/nodes/ExportSpecifier'; import Identifier from './ast/nodes/Identifier'; import ImportDeclaration from './ast/nodes/ImportDeclaration'; import ImportExpression from './ast/nodes/ImportExpression'; @@ -170,7 +169,7 @@ const MISSING_EXPORT_SHIM_DESCRIPTION: ExportDescription = { }; export default class Module { - chunk?: Chunk; + chunk: Chunk | null = null; chunkFileNames = new Set(); chunkName: string | null = null; code!: string; @@ -186,8 +185,8 @@ export default class Module { entryPointsHash: Uint8Array = new Uint8Array(10); excludeFromSourcemap: boolean; execIndex = Infinity; - exportAllModules: (Module | ExternalModule)[] = null as any; - exportAllSources: string[] = []; + exportAllModules: (Module | ExternalModule)[] = []; + exportAllSources = new Set(); exports: { [name: string]: ExportDescription } = Object.create(null); exportsAll: { [name: string]: string } = Object.create(null); exportShimVariable: ExportShimVariable = new ExportShimVariable(this); @@ -203,25 +202,25 @@ export default class Module { moduleSideEffects: boolean; originalCode!: string; originalSourcemap!: ExistingDecodedSourceMap | null; - reexports: { [name: string]: ReexportDescription } = Object.create(null); + reexportDescriptions: { [name: string]: ReexportDescription } = Object.create(null); resolvedIds!: ResolvedIdMap; scope!: ModuleScope; sourcemapChain!: DecodedSourceMapOrMissing[]; - sources: string[] = []; + sources = new Set(); transformFiles?: EmittedFile[]; userChunkNames = new Set(); usesTopLevelAwait = false; - private allExportNames?: Set; + private allExportNames: Set | null = null; private ast!: Program; private astContext!: AstContext; private context: string; private esTreeAst!: ESTree.Program; private graph: Graph; private magicString!: MagicString; - private namespaceVariable: NamespaceVariable = undefined as any; + private namespaceVariable: NamespaceVariable | null = null; private transformDependencies: string[] = []; - private transitiveReexports?: string[]; + private transitiveReexports: string[] | null = null; constructor(graph: Graph, id: string, moduleSideEffects: boolean, isEntry: boolean) { this.id = id; @@ -286,7 +285,7 @@ export default class Module { for (const name of Object.keys(this.exports)) { allExportNames.add(name); } - for (const name of Object.keys(this.reexports)) { + for (const name of Object.keys(this.reexportDescriptions)) { allExportNames.add(name); } for (const module of this.exportAllModules) { @@ -360,7 +359,7 @@ export default class Module { this.transitiveReexports = []; const reexports = new Set(); - for (const name in this.reexports) { + for (const name in this.reexportDescriptions) { reexports.add(name); } for (const module of this.exportAllModules) { @@ -406,7 +405,7 @@ export default class Module { } // export { foo } from './other' - const reexportDeclaration = this.reexports[name]; + const reexportDeclaration = this.reexportDescriptions[name]; if (reexportDeclaration) { const declaration = reexportDeclaration.module.getVariableForExportName( reexportDeclaration.localName @@ -507,19 +506,19 @@ export default class Module { } } - this.addModulesToSpecifiers(this.importDescriptions); - this.addModulesToSpecifiers(this.reexports); + this.addModulesToImportDescriptions(this.importDescriptions); + this.addModulesToImportDescriptions(this.reexportDescriptions); - this.exportAllModules = this.exportAllSources - .map(source => { - const id = this.resolvedIds[source].id; - return this.graph.moduleById.get(id) as Module | ExternalModule; - }) - .sort((moduleA, moduleB) => { - const aExternal = moduleA instanceof ExternalModule; - const bExternal = moduleB instanceof ExternalModule; - return aExternal === bExternal ? 0 : aExternal ? 1 : -1; - }); + const externalExportAllModules: ExternalModule[] = []; + for (const source of this.exportAllSources) { + const module = this.graph.moduleById.get(this.resolvedIds[source].id) as + | Module + | ExternalModule; + (module instanceof ExternalModule ? externalExportAllModules : this.exportAllModules).push( + module + ); + } + this.exportAllModules = this.exportAllModules.concat(externalExportAllModules); } render(options: RenderOptions): MagicString { @@ -691,94 +690,57 @@ export default class Module { private addExport( node: ExportAllDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration ) { - const source = - (node as ExportAllDeclaration).source && (node as ExportAllDeclaration).source.value; - - // export { name } from './other' - if (source) { - if (this.sources.indexOf(source) === -1) this.sources.push(source); - - if (node.type === NodeType.ExportAllDeclaration) { - // Store `export * from '...'` statements in an array of delegates. - // When an unknown import is encountered, we see if one of them can satisfy it. - this.exportAllSources.push(source); - } else { - for (const specifier of (node as ExportNamedDeclaration).specifiers) { - const name = specifier.exported.name; - - if (this.exports[name] || this.reexports[name]) { - this.error( - { - code: 'DUPLICATE_EXPORT', - message: `A module cannot have multiple exports with the same name ('${name}')` - }, - specifier.start - ); - } - - this.reexports[name] = { - localName: specifier.local.name, - module: null as any, // filled in later, - source, - start: specifier.start - }; - } - } - } else if (node instanceof ExportDefaultDeclaration) { - // export default function foo () {} + if (node instanceof ExportDefaultDeclaration) { // export default foo; - // export default 42; - if (this.exports.default) { - this.error( - { - code: 'DUPLICATE_EXPORT', - message: `A module can only have one default export` - }, - node.start - ); - } this.exports.default = { identifier: node.variable.getAssignedVariableName(), localName: 'default' }; - } else if ((node as ExportNamedDeclaration).declaration) { - // export var { foo, bar } = ... - // export var foo = 42; - // export var a = 1, b = 2, c = 3; - // export function foo () {} - const declaration = (node as ExportNamedDeclaration).declaration as - | FunctionDeclaration - | ClassDeclaration - | VariableDeclaration; - - if (declaration.type === NodeType.VariableDeclaration) { - for (const decl of declaration.declarations) { - for (const localName of extractAssignedNames(decl.id)) { + } else if (node instanceof ExportAllDeclaration) { + // export * from './other' + + const source = node.source.value; + this.sources.add(source); + this.exportAllSources.add(source); + } else if (node.source !== null) { + // export { name } from './other' + + const source = node.source.value; + this.sources.add(source); + for (const specifier of node.specifiers) { + const name = specifier.exported.name; + this.reexportDescriptions[name] = { + localName: + specifier.type === NodeType.ExportNamespaceSpecifier ? '*' : specifier.local.name, + module: null as any, // filled in later, + source, + start: specifier.start + }; + } + } else if (node.declaration) { + const declaration = node.declaration; + if (declaration instanceof VariableDeclaration) { + // export var { foo, bar } = ... + // export var foo = 1, bar = 2; + + for (const declarator of declaration.declarations) { + for (const localName of extractAssignedNames(declarator.id)) { this.exports[localName] = { identifier: null, localName }; } } } else { // export function foo () {} + const localName = (declaration.id as Identifier).name; this.exports[localName] = { identifier: null, localName }; } } else { // export { foo, bar, baz } - for (const specifier of (node as ExportNamedDeclaration).specifiers) { - const localName = specifier.local.name; - const exportedName = specifier.exported.name; - - if (this.exports[exportedName] || this.reexports[exportedName]) { - this.error( - { - code: 'DUPLICATE_EXPORT', - message: `A module cannot have multiple exports with the same name ('${exportedName}')` - }, - specifier.start - ); - } + for (const specifier of node.specifiers) { + const localName = (specifier as ExportSpecifier).local.name; + const exportedName = specifier.exported.name; this.exports[exportedName] = { identifier: null, localName }; } } @@ -786,9 +748,7 @@ export default class Module { private addImport(node: ImportDeclaration) { const source = node.source.value; - - if (this.sources.indexOf(source) === -1) this.sources.push(source); - + this.sources.add(source); for (const specifier of node.specifiers) { const localName = specifier.local.name; @@ -818,11 +778,11 @@ export default class Module { this.importMetas.push(node); } - private addModulesToSpecifiers(specifiers: { + private addModulesToImportDescriptions(importDescription: { [name: string]: ImportDescription | ReexportDescription; }) { - for (const name of Object.keys(specifiers)) { - const specifier = specifiers[name]; + for (const name of Object.keys(importDescription)) { + const specifier = importDescription[name]; const id = this.resolvedIds[specifier.source].id; specifier.module = this.graph.moduleById.get(id) as Module | ExternalModule | null; } diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 193b1fce733..ab2a8b38983 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -235,9 +235,18 @@ export class ModuleLoader { return getCombinedPromise().then(() => loadNewModulesPromise); } - private fetchAllDependencies(module: Module) { - const fetchDynamicImportsPromise = Promise.all( - module.getDynamicImportExpressions().map((specifier, index) => + private fetchAllDependencies(module: Module): Promise { + return Promise.all([ + ...(Array.from(module.sources).map(async source => + this.fetchResolvedDependency( + source, + module.id, + (module.resolvedIds[source] = + module.resolvedIds[source] || + this.handleMissingImports(await this.resolveId(source, module.id), source, module.id)) + ) + ) as Promise[]), + ...module.getDynamicImportExpressions().map((specifier, index) => this.resolveDynamicImport(module, specifier as string | ESTree.Node, module.id).then( resolvedId => { if (resolvedId === null) return; @@ -256,12 +265,7 @@ export class ModuleLoader { } ) ) - ); - fetchDynamicImportsPromise.catch(() => {}); - - return Promise.all( - module.sources.map(source => this.resolveAndFetchDependency(module, source)) - ).then(() => fetchDynamicImportsPromise); + ]); } private fetchModule( @@ -271,9 +275,7 @@ export class ModuleLoader { isEntry: boolean ): Promise { const existingModule = this.modulesById.get(id); - if (existingModule) { - if (existingModule instanceof ExternalModule) - throw new Error(`Cannot fetch external module ${id}`); + if (existingModule instanceof Module) { existingModule.isEntryPoint = existingModule.isEntryPoint || isEntry; return Promise.resolve(existingModule); } @@ -331,10 +333,10 @@ export class ModuleLoader { module.exportsAll[name] = module.id; } } - module.exportAllSources.forEach(source => { + for (const source of module.exportAllSources) { const id = module.resolvedIds[source].id; const exportAllModule = this.modulesById.get(id); - if (exportAllModule instanceof ExternalModule) return; + if (exportAllModule instanceof ExternalModule) continue; for (const name in (exportAllModule as Module).exportsAll) { if (name in module.exportsAll) { @@ -343,7 +345,7 @@ export class ModuleLoader { module.exportsAll[name] = (exportAllModule as Module).exportsAll[name]; } } - }); + } return module; }); }); @@ -450,19 +452,6 @@ export class ModuleLoader { }; } - private async resolveAndFetchDependency( - module: Module, - source: string - ): Promise { - return this.fetchResolvedDependency( - source, - module.id, - (module.resolvedIds[source] = - module.resolvedIds[source] || - this.handleMissingImports(await this.resolveId(source, module.id), source, module.id)) - ); - } - private async resolveDynamicImport( module: Module, specifier: string | ESTree.Node, diff --git a/src/ast/nodes/ExportAllDeclaration.ts b/src/ast/nodes/ExportAllDeclaration.ts index 6d94846222e..8a21f27ac8f 100644 --- a/src/ast/nodes/ExportAllDeclaration.ts +++ b/src/ast/nodes/ExportAllDeclaration.ts @@ -1,12 +1,8 @@ -import MagicString from 'magic-string'; -import { BLANK } from '../../utils/blank'; -import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; import Literal from './Literal'; import * as NodeType from './NodeType'; import { NodeBase } from './shared/Node'; export default class ExportAllDeclaration extends NodeBase { - needsBoundaries!: true; source!: Literal; type!: NodeType.tExportAllDeclaration; @@ -17,10 +13,4 @@ export default class ExportAllDeclaration extends NodeBase { initialise() { this.context.addExport(this); } - - render(code: MagicString, _options: RenderOptions, { start, end }: NodeRenderOptions = BLANK) { - code.remove(start as number, end as number); - } } - -ExportAllDeclaration.prototype.needsBoundaries = true; diff --git a/src/ast/nodes/ExportDefaultDeclaration.ts b/src/ast/nodes/ExportDefaultDeclaration.ts index cc7a068f7ea..61705583f06 100644 --- a/src/ast/nodes/ExportDefaultDeclaration.ts +++ b/src/ast/nodes/ExportDefaultDeclaration.ts @@ -1,5 +1,4 @@ import MagicString from 'magic-string'; -import { BLANK } from '../../utils/blank'; import { findFirstOccurrenceOutsideComment, NodeRenderOptions, @@ -63,7 +62,8 @@ export default class ExportDefaultDeclaration extends NodeBase { this.context.addExport(this); } - render(code: MagicString, options: RenderOptions, { start, end }: NodeRenderOptions = BLANK) { + render(code: MagicString, options: RenderOptions, nodeRenderOptions?: NodeRenderOptions) { + const { start, end } = nodeRenderOptions as { end: number; start: number }; const declarationStart = getDeclarationStart(code.original, this.start); if (this.declaration instanceof FunctionDeclaration) { @@ -86,12 +86,12 @@ export default class ExportDefaultDeclaration extends NodeBase { // Remove altogether to prevent re-declaring the same variable if (options.format === 'system' && this.variable.exportName) { code.overwrite( - start as number, - end as number, + start, + end, `exports('${this.variable.exportName}', ${this.variable.getName()});` ); } else { - treeshakeNode(this, code, start as number, end as number); + treeshakeNode(this, code, start, end); } return; } else if (this.variable.included) { diff --git a/src/ast/nodes/ExportNamedDeclaration.ts b/src/ast/nodes/ExportNamedDeclaration.ts index 0cdb997ba27..fe311f539f2 100644 --- a/src/ast/nodes/ExportNamedDeclaration.ts +++ b/src/ast/nodes/ExportNamedDeclaration.ts @@ -1,8 +1,8 @@ import MagicString from 'magic-string'; -import { BLANK } from '../../utils/blank'; import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; import { HasEffectsContext } from '../ExecutionContext'; import ClassDeclaration from './ClassDeclaration'; +import ExportNamespaceSpecifier from './ExportNamespaceSpecifier'; import ExportSpecifier from './ExportSpecifier'; import FunctionDeclaration from './FunctionDeclaration'; import Literal from './Literal'; @@ -14,7 +14,7 @@ export default class ExportNamedDeclaration extends NodeBase { declaration!: FunctionDeclaration | ClassDeclaration | VariableDeclaration | null; needsBoundaries!: true; source!: Literal | null; - specifiers!: ExportSpecifier[]; + specifiers!: (ExportSpecifier | ExportNamespaceSpecifier)[]; type!: NodeType.tExportNamedDeclaration; bind() { @@ -30,9 +30,10 @@ export default class ExportNamedDeclaration extends NodeBase { this.context.addExport(this); } - render(code: MagicString, options: RenderOptions, { start, end }: NodeRenderOptions = BLANK) { + render(code: MagicString, options: RenderOptions, nodeRenderOptions?: NodeRenderOptions) { + const { start, end } = nodeRenderOptions as { end: number; start: number }; if (this.declaration === null) { - code.remove(start as number, end as number); + code.remove(start, end); } else { code.remove(this.start, this.declaration.start); (this.declaration as Node).render(code, options, { start, end }); diff --git a/src/ast/nodes/ExportNamespaceSpecifier.ts b/src/ast/nodes/ExportNamespaceSpecifier.ts new file mode 100644 index 00000000000..a62bdb67c78 --- /dev/null +++ b/src/ast/nodes/ExportNamespaceSpecifier.ts @@ -0,0 +1,8 @@ +import Identifier from './Identifier'; +import * as NodeType from './NodeType'; +import { Node } from './shared/Node'; + +export default interface ExportNamespaceSpecifier extends Node { + exported: Identifier; + type: NodeType.tExportNamespaceSpecifier; +} diff --git a/src/ast/nodes/ImportDeclaration.ts b/src/ast/nodes/ImportDeclaration.ts index 9184317c964..6a7de851669 100644 --- a/src/ast/nodes/ImportDeclaration.ts +++ b/src/ast/nodes/ImportDeclaration.ts @@ -1,5 +1,4 @@ import MagicString from 'magic-string'; -import { BLANK } from '../../utils/blank'; import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; import ImportDefaultSpecifier from './ImportDefaultSpecifier'; import ImportNamespaceSpecifier from './ImportNamespaceSpecifier'; @@ -24,8 +23,11 @@ export default class ImportDeclaration extends NodeBase { this.context.addImport(this); } - render(code: MagicString, _options: RenderOptions, { start, end }: NodeRenderOptions = BLANK) { - code.remove(start as number, end as number); + render(code: MagicString, _options: RenderOptions, nodeRenderOptions?: NodeRenderOptions) { + code.remove( + (nodeRenderOptions as NodeRenderOptions).start as number, + (nodeRenderOptions as NodeRenderOptions).end as number + ); } } diff --git a/src/ast/nodes/NodeType.ts b/src/ast/nodes/NodeType.ts index adb6a38d0c4..1d000493825 100644 --- a/src/ast/nodes/NodeType.ts +++ b/src/ast/nodes/NodeType.ts @@ -19,6 +19,7 @@ export type tEmptyStatement = 'EmptyStatement'; export type tExportAllDeclaration = 'ExportAllDeclaration'; export type tExportDefaultDeclaration = 'ExportDefaultDeclaration'; export type tExportNamedDeclaration = 'ExportNamedDeclaration'; +export type tExportNamespaceSpecifier = 'ExportNamespaceSpecifier'; export type tExportSpecifier = 'ExportSpecifier'; export type tExpressionStatement = 'ExpressionStatement'; export type tForStatement = 'ForStatement'; @@ -86,6 +87,7 @@ export const ExportAllDeclaration: tExportAllDeclaration = 'ExportAllDeclaration export const ExportDefaultDeclaration: tExportDefaultDeclaration = 'ExportDefaultDeclaration'; export const ExportNamedDeclaration: tExportNamedDeclaration = 'ExportNamedDeclaration'; export const ExportSpecifier: tExportSpecifier = 'ExportSpecifier'; +export const ExportNamespaceSpecifier: tExportNamespaceSpecifier = 'ExportNamespaceSpecifier'; export const ExpressionStatement: tExpressionStatement = 'ExpressionStatement'; export const ForStatement: tForStatement = 'ForStatement'; export const ForInStatement: tForInStatement = 'ForInStatement'; diff --git a/src/finalisers/esm.ts b/src/finalisers/esm.ts index 217ddd88333..f932af0cbf1 100644 --- a/src/finalisers/esm.ts +++ b/src/finalisers/esm.ts @@ -1,8 +1,7 @@ import { Bundle as MagicStringBundle } from 'magic-string'; -import { FinaliserOptions } from './index'; - -export * from 'magic-string'; +import { ChunkDependencies, ChunkExports, ImportSpecifier, ReexportSpecifier } from '../Chunk'; import { OutputOptions } from '../rollup/types'; +import { FinaliserOptions } from './index'; export default function esm( magicString: MagicStringBundle, @@ -12,24 +11,45 @@ export default function esm( const _ = options.compact ? '' : ' '; const n = options.compact ? '' : '\n'; - const importBlock = dependencies - .map(({ id, reexports, imports, name }) => { - if (!reexports && !imports) { - return `import${_}'${id}';`; - } - let output = ''; - if (imports) { - const defaultImport = imports.find(specifier => specifier.imported === 'default'); - const starImport = imports.find(specifier => specifier.imported === '*'); - if (starImport) { - output += `import${_}*${_}as ${starImport.local} from${_}'${id}';`; - if (imports.length > 1) output += n; + const importBlock = getImportBlock(dependencies, _); + if (importBlock.length > 0) intro += importBlock.join(n) + n + n; + if (intro) magicString.prepend(intro); + + const exportBlock = getExportBlock(exports, _); + if (exportBlock.length) magicString.append(n + n + exportBlock.join(n).trim()); + if (outro) magicString.append(outro); + + return magicString.trim(); +} + +function getImportBlock(dependencies: ChunkDependencies, _: string): string[] { + const importBlock: string[] = []; + for (const { id, reexports, imports, name } of dependencies) { + if (!reexports && !imports) { + importBlock.push(`import${_}'${id}';`); + continue; + } + if (imports) { + let defaultImport: ImportSpecifier | null = null; + let starImport: ImportSpecifier | null = null; + const importedNames: ImportSpecifier[] = []; + for (const specifier of imports) { + if (specifier.imported === 'default') { + defaultImport = specifier; + } else if (specifier.imported === '*') { + starImport = specifier; + } else { + importedNames.push(specifier); } - if (defaultImport && imports.length === 1) { - output += `import ${defaultImport.local} from${_}'${id}';`; - } else if (!starImport || imports.length > 1) { - output += `import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${imports - .filter(specifier => specifier !== defaultImport && specifier !== starImport) + } + if (starImport) { + importBlock.push(`import${_}*${_}as ${starImport.local} from${_}'${id}';`); + } + if (defaultImport && importedNames.length === 0) { + importBlock.push(`import ${defaultImport.local} from${_}'${id}';`); + } else if (importedNames.length > 0) { + importBlock.push( + `import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${importedNames .map(specifier => { if (specifier.imported === specifier.local) { return specifier.imported; @@ -37,59 +57,63 @@ export default function esm( return `${specifier.imported} as ${specifier.local}`; } }) - .join(`,${_}`)}${_}}${_}from${_}'${id}';`; + .join(`,${_}`)}${_}}${_}from${_}'${id}';` + ); + } + } + if (reexports) { + let starExport: ReexportSpecifier | null = null; + const namespaceReexports: ReexportSpecifier[] = []; + const namedReexports: ReexportSpecifier[] = []; + for (const specifier of reexports) { + if (specifier.reexported === '*') { + starExport = specifier; + } else if (specifier.imported === '*') { + namespaceReexports.push(specifier); + } else { + namedReexports.push(specifier); } } - if (reexports) { - if (imports) output += n; - const starExport = reexports.find(specifier => specifier.reexported === '*'); - const namespaceReexport = reexports.find( - specifier => specifier.imported === '*' && specifier.reexported !== '*' - ); - if (starExport) { - output += `export${_}*${_}from${_}'${id}';`; - if (reexports.length === 1) { - return output; - } - output += n; + if (starExport) { + importBlock.push(`export${_}*${_}from${_}'${id}';`); + } + if (namespaceReexports.length > 0) { + if ( + !imports || + !imports.some(specifier => specifier.imported === '*' && specifier.local === name) + ) { + importBlock.push(`import${_}*${_}as ${name} from${_}'${id}';`); } - if (namespaceReexport) { - if ( - !imports || - !imports.some(specifier => specifier.imported === '*' && specifier.local === name) - ) - output += `import${_}*${_}as ${name} from${_}'${id}';${n}`; - output += `export${_}{${_}${ - name === namespaceReexport.reexported - ? name - : `${name} as ${namespaceReexport.reexported}` - } };`; - if (reexports.length === (starExport ? 2 : 1)) { - return output; - } - output += n; + for (const specifier of namespaceReexports) { + importBlock.push( + `export${_}{${_}${ + name === specifier.reexported ? name : `${name} as ${specifier.reexported}` + } };` + ); } - output += `export${_}{${_}${reexports - .filter(specifier => specifier !== starExport && specifier !== namespaceReexport) - .map(specifier => { - if (specifier.imported === specifier.reexported) { - return specifier.imported; - } else { - return `${specifier.imported} as ${specifier.reexported}`; - } - }) - .join(`,${_}`)}${_}}${_}from${_}'${id}';`; } - return output; - }) - .join(n); - - if (importBlock) intro += importBlock + n + n; - if (intro) magicString.prepend(intro); + if (namedReexports.length > 0) { + importBlock.push( + `export${_}{${_}${namedReexports + .map(specifier => { + if (specifier.imported === specifier.reexported) { + return specifier.imported; + } else { + return `${specifier.imported} as ${specifier.reexported}`; + } + }) + .join(`,${_}`)}${_}}${_}from${_}'${id}';` + ); + } + } + } + return importBlock; +} +function getExportBlock(exports: ChunkExports, _: string): string[] { const exportBlock: string[] = []; const exportDeclaration: string[] = []; - exports.forEach(specifier => { + for (const specifier of exports) { if (specifier.exported === 'default') { exportBlock.push(`export default ${specifier.local};`); } else { @@ -99,14 +123,9 @@ export default function esm( : `${specifier.local} as ${specifier.exported}` ); } - }); + } if (exportDeclaration.length) { exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`); } - - if (exportBlock.length) magicString.append(n + n + exportBlock.join(n).trim()); - - if (outro) magicString.append(outro); - - return magicString.trim(); + return exportBlock; } diff --git a/src/finalisers/iife.ts b/src/finalisers/iife.ts index a87a4b535c1..7fc5a6b0950 100644 --- a/src/finalisers/iife.ts +++ b/src/finalisers/iife.ts @@ -37,7 +37,7 @@ export default function iife( if (name && useVariableAssignment && !isLegal(name)) { error({ code: 'ILLEGAL_IDENTIFIER_AS_NAME', - message: `Given name (${name}) is not legal JS identifier. If you need this you can try --extend option` + message: `Given name "${name}" is not a legal JS identifier. If you need this, you can try "output.extend: true".` }); } diff --git a/src/finalisers/shared/getExportBlock.ts b/src/finalisers/shared/getExportBlock.ts index 001b1305d1a..a52f172cd66 100644 --- a/src/finalisers/shared/getExportBlock.ts +++ b/src/finalisers/shared/getExportBlock.ts @@ -32,9 +32,9 @@ export default function getExportBlock( let exportBlock = ''; // star exports must always output first for precedence - dependencies.forEach(({ name, reexports }) => { + for (const { name, reexports } of dependencies) { if (reexports && namedExportsMode) { - reexports.forEach(specifier => { + for (const specifier of reexports) { if (specifier.reexported === '*') { if (exportBlock) exportBlock += n; if (specifier.needsLiveBinding) { @@ -51,9 +51,9 @@ export default function getExportBlock( `${t}if${_}(k${_}!==${_}'default')${_}exports[k]${_}=${_}${name}[k];${n}});`; } } - }); + } } - }); + } for (const { name, diff --git a/src/finalisers/system.ts b/src/finalisers/system.ts index 375143c0188..a11c7f83bcb 100644 --- a/src/finalisers/system.ts +++ b/src/finalisers/system.ts @@ -8,13 +8,14 @@ function getStarExcludes({ dependencies, exports }: ModuleDeclarations): Set expt.exported)); if (!starExcludes.has('default')) starExcludes.add('default'); // also include reexport names - dependencies.forEach(({ reexports }) => { - if (reexports) - reexports.forEach(reexport => { + for (const { reexports } of dependencies) { + if (reexports) { + for (const reexport of reexports) { if (reexport.imported !== '*' && !starExcludes.has(reexport.reexported)) starExcludes.add(reexport.reexported); - }); - }); + } + } + } return starExcludes; } @@ -101,17 +102,17 @@ export default function system( let starExcludes: Set | undefined; const setters: string[] = []; - dependencies.forEach(({ imports, reexports }) => { + for (const { imports, reexports } of dependencies) { const setter: string[] = []; if (imports) { - imports.forEach(specifier => { + for (const specifier of imports) { importBindings.push(specifier.local); if (specifier.imported === '*') { setter.push(`${specifier.local}${_}=${_}module;`); } else { setter.push(`${specifier.local}${_}=${_}module.${specifier.imported};`); } - }); + } } if (reexports) { let createdSetter = false; @@ -122,8 +123,8 @@ export default function system( (reexports[0].reexported === '*' || reexports[0].imported === '*')) ) { // star reexports - reexports.forEach(specifier => { - if (specifier.reexported !== '*') return; + for (const specifier of reexports) { + if (specifier.reexported !== '*') continue; // need own exports list for deduping in star export case if (!starExcludes) { starExcludes = getStarExcludes({ dependencies, exports }); @@ -135,33 +136,33 @@ export default function system( setter.push(`for${_}(var _$p${_}in${_}module)${_}{`); setter.push(`${t}if${_}(!_starExcludes[_$p])${_}_setter[_$p]${_}=${_}module[_$p];`); setter.push('}'); - }); + } // star import reexport - reexports.forEach(specifier => { - if (specifier.imported !== '*' || specifier.reexported === '*') return; + for (const specifier of reexports) { + if (specifier.imported !== '*' || specifier.reexported === '*') continue; setter.push(`exports('${specifier.reexported}',${_}module);`); - }); + } // reexports - reexports.forEach(specifier => { - if (specifier.reexported === '*' || specifier.imported === '*') return; + for (const specifier of reexports) { + if (specifier.reexported === '*' || specifier.imported === '*') continue; if (!createdSetter) { setter.push(`${varOrConst} _setter${_}=${_}{};`); createdSetter = true; } setter.push(`_setter.${specifier.reexported}${_}=${_}module.${specifier.imported};`); - }); + } if (createdSetter) { setter.push('exports(_setter);'); } } else { // single reexport - reexports.forEach(specifier => { + for (const specifier of reexports) { setter.push(`exports('${specifier.reexported}',${_}module.${specifier.imported});`); - }); + } } } setters.push(setter.join(`${n}${t}${t}${t}`)); - }); + } const registeredName = options.name ? `'${options.name}',${_}` : ''; const wrapperParams = accessedGlobals.has('module') diff --git a/src/utils/identifierHelpers.ts b/src/utils/identifierHelpers.ts index 38463f07be5..b03d78dc606 100644 --- a/src/utils/identifierHelpers.ts +++ b/src/utils/identifierHelpers.ts @@ -5,15 +5,14 @@ const builtins = 'Infinity NaN undefined null true false eval uneval isFinite is ' ' ); -const blacklisted = Object.create(null); -reservedWords.concat(builtins).forEach(word => (blacklisted[word] = true)); +const blacklisted = new Set(reservedWords.concat(builtins)); const illegalCharacters = /[^$_a-zA-Z0-9]/g; const startsWithDigit = (str: string) => /\d/.test(str[0]); export function isLegal(str: string): boolean { - if (startsWithDigit(str) || blacklisted[str]) { + if (startsWithDigit(str) || blacklisted.has(str)) { return false; } return !illegalCharacters.test(str); @@ -22,7 +21,7 @@ export function isLegal(str: string): boolean { export function makeLegal(str: string): string { str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(illegalCharacters, '_'); - if (startsWithDigit(str) || blacklisted[str]) str = `_${str}`; + if (startsWithDigit(str) || blacklisted.has(str)) str = `_${str}`; return str || '_'; } diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 3446b8622b8..e9e3b10260e 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -245,7 +245,7 @@ export function createPluginDriver( importedIds: foundModule instanceof ExternalModule ? [] - : foundModule.sources.map(id => foundModule.resolvedIds[id].id), + : Array.from(foundModule.sources).map(id => foundModule.resolvedIds[id].id), isEntry: foundModule instanceof Module && foundModule.isEntryPoint, isExternal: foundModule instanceof ExternalModule }; diff --git a/src/utils/timers.ts b/src/utils/timers.ts index f92c9ff2dab..6683c39c93b 100644 --- a/src/utils/timers.ts +++ b/src/utils/timers.ts @@ -76,9 +76,9 @@ function timeEndImpl(label: string, level = 3) { export function getTimings(): SerializedTimings { const newTimings: SerializedTimings = {}; - Object.keys(timers).forEach(label => { + for (const label of Object.keys(timers)) { newTimings[label] = [timers[label].time, timers[label].memory, timers[label].totalMemory]; - }); + } return newTimings; } diff --git a/src/watch/fileWatchers.ts b/src/watch/fileWatchers.ts index c75bdc4e030..b2d231fdba9 100644 --- a/src/watch/fileWatchers.ts +++ b/src/watch/fileWatchers.ts @@ -107,11 +107,11 @@ export default class FileWatcher { } trigger(id: string) { - this.tasks.forEach(task => { + for (const task of this.tasks) { task.invalidate(id, false); - }); - this.transformDependencyTasks.forEach(task => { + } + for (const task of this.transformDependencyTasks) { task.invalidate(id, true); - }); + } } } diff --git a/test/form/samples/export-internal-namespace-as/_config.js b/test/form/samples/export-internal-namespace-as/_config.js new file mode 100644 index 00000000000..71792b71529 --- /dev/null +++ b/test/form/samples/export-internal-namespace-as/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'supports exporting and resolving internal namespaces as names' +}; diff --git a/test/form/samples/export-internal-namespace-as/_expected.js b/test/form/samples/export-internal-namespace-as/_expected.js new file mode 100644 index 00000000000..69fbd330cad --- /dev/null +++ b/test/form/samples/export-internal-namespace-as/_expected.js @@ -0,0 +1,16 @@ +const foo = 'foo1'; + +const foo$1 = 'foo2'; +const bar = 'bar2'; + +var dep2 = /*#__PURE__*/Object.freeze({ + __proto__: null, + foo: foo$1, + bar: bar +}); + +console.log(foo); +console.log(foo); + +console.log(dep2); +console.log(dep2); diff --git a/test/form/samples/export-internal-namespace-as/dep1.js b/test/form/samples/export-internal-namespace-as/dep1.js new file mode 100644 index 00000000000..010b12bd2ab --- /dev/null +++ b/test/form/samples/export-internal-namespace-as/dep1.js @@ -0,0 +1,2 @@ +export const foo = 'foo1'; +export const bar = 'bar1'; diff --git a/test/form/samples/export-internal-namespace-as/dep2.js b/test/form/samples/export-internal-namespace-as/dep2.js new file mode 100644 index 00000000000..6ef10f0bbf5 --- /dev/null +++ b/test/form/samples/export-internal-namespace-as/dep2.js @@ -0,0 +1,2 @@ +export const foo = 'foo2'; +export const bar = 'bar2'; diff --git a/test/form/samples/export-internal-namespace-as/main.js b/test/form/samples/export-internal-namespace-as/main.js new file mode 100644 index 00000000000..92ea0a05613 --- /dev/null +++ b/test/form/samples/export-internal-namespace-as/main.js @@ -0,0 +1,9 @@ +import * as dep1 from './dep1.js'; +import * as dep2 from './dep2.js'; +import { dep1 as reexportedDep1, dep2 as reexportedDep2 } from './reexport.js'; + +console.log(reexportedDep1.foo); +console.log(dep1.foo); + +console.log(reexportedDep2); +console.log(dep2); diff --git a/test/form/samples/export-internal-namespace-as/reexport.js b/test/form/samples/export-internal-namespace-as/reexport.js new file mode 100644 index 00000000000..ade4cacba9c --- /dev/null +++ b/test/form/samples/export-internal-namespace-as/reexport.js @@ -0,0 +1,2 @@ +export * as dep1 from './dep1.js'; +export * as dep2 from './dep2.js'; diff --git a/test/form/samples/export-namespace-as/_config.js b/test/form/samples/export-namespace-as/_config.js new file mode 100644 index 00000000000..81eb160f2ee --- /dev/null +++ b/test/form/samples/export-namespace-as/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'supports exporting namespaces as names in entry points', + options: { output: { name: 'bundle' } } +}; diff --git a/test/form/samples/export-namespace-as/_expected/amd.js b/test/form/samples/export-namespace-as/_expected/amd.js new file mode 100644 index 00000000000..289423f76bc --- /dev/null +++ b/test/form/samples/export-namespace-as/_expected/amd.js @@ -0,0 +1,16 @@ +define(['exports'], function (exports) { 'use strict'; + + const foo = 'foo1'; + const bar = 'bar1'; + + var dep = /*#__PURE__*/Object.freeze({ + __proto__: null, + foo: foo, + bar: bar + }); + + exports.dep = dep; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/form/samples/export-namespace-as/_expected/cjs.js b/test/form/samples/export-namespace-as/_expected/cjs.js new file mode 100644 index 00000000000..f4d06b1841a --- /dev/null +++ b/test/form/samples/export-namespace-as/_expected/cjs.js @@ -0,0 +1,14 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +const foo = 'foo1'; +const bar = 'bar1'; + +var dep = /*#__PURE__*/Object.freeze({ + __proto__: null, + foo: foo, + bar: bar +}); + +exports.dep = dep; diff --git a/test/form/samples/export-namespace-as/_expected/es.js b/test/form/samples/export-namespace-as/_expected/es.js new file mode 100644 index 00000000000..484e3a8e398 --- /dev/null +++ b/test/form/samples/export-namespace-as/_expected/es.js @@ -0,0 +1,10 @@ +const foo = 'foo1'; +const bar = 'bar1'; + +var dep = /*#__PURE__*/Object.freeze({ + __proto__: null, + foo: foo, + bar: bar +}); + +export { dep }; diff --git a/test/form/samples/export-namespace-as/_expected/iife.js b/test/form/samples/export-namespace-as/_expected/iife.js new file mode 100644 index 00000000000..730fcf7096d --- /dev/null +++ b/test/form/samples/export-namespace-as/_expected/iife.js @@ -0,0 +1,17 @@ +var bundle = (function (exports) { + 'use strict'; + + const foo = 'foo1'; + const bar = 'bar1'; + + var dep = /*#__PURE__*/Object.freeze({ + __proto__: null, + foo: foo, + bar: bar + }); + + exports.dep = dep; + + return exports; + +}({})); diff --git a/test/form/samples/export-namespace-as/_expected/system.js b/test/form/samples/export-namespace-as/_expected/system.js new file mode 100644 index 00000000000..e1e4e1c0131 --- /dev/null +++ b/test/form/samples/export-namespace-as/_expected/system.js @@ -0,0 +1,18 @@ +System.register('bundle', [], function (exports) { + 'use strict'; + return { + execute: function () { + + const foo = 'foo1'; + const bar = 'bar1'; + + var dep = /*#__PURE__*/Object.freeze({ + __proto__: null, + foo: foo, + bar: bar + }); + exports('dep', dep); + + } + }; +}); diff --git a/test/form/samples/export-namespace-as/_expected/umd.js b/test/form/samples/export-namespace-as/_expected/umd.js new file mode 100644 index 00000000000..8ab871d1062 --- /dev/null +++ b/test/form/samples/export-namespace-as/_expected/umd.js @@ -0,0 +1,20 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = global || self, factory(global.bundle = {})); +}(this, (function (exports) { 'use strict'; + + const foo = 'foo1'; + const bar = 'bar1'; + + var dep = /*#__PURE__*/Object.freeze({ + __proto__: null, + foo: foo, + bar: bar + }); + + exports.dep = dep; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/test/form/samples/export-namespace-as/dep.js b/test/form/samples/export-namespace-as/dep.js new file mode 100644 index 00000000000..010b12bd2ab --- /dev/null +++ b/test/form/samples/export-namespace-as/dep.js @@ -0,0 +1,2 @@ +export const foo = 'foo1'; +export const bar = 'bar1'; diff --git a/test/form/samples/export-namespace-as/main.js b/test/form/samples/export-namespace-as/main.js new file mode 100644 index 00000000000..b47aa74e93c --- /dev/null +++ b/test/form/samples/export-namespace-as/main.js @@ -0,0 +1 @@ +export * as dep from './dep.js'; diff --git a/test/form/samples/reexport-external-namespace-as/_config.js b/test/form/samples/reexport-external-namespace-as/_config.js new file mode 100644 index 00000000000..e2705de62c3 --- /dev/null +++ b/test/form/samples/reexport-external-namespace-as/_config.js @@ -0,0 +1,10 @@ +module.exports = { + description: 'reexport external namespace as name', + options: { + external: 'external', + output: { + name: 'bundle', + globals: { external: 'external' } + } + } +}; diff --git a/test/form/samples/reexport-external-namespace-as/_expected/amd.js b/test/form/samples/reexport-external-namespace-as/_expected/amd.js new file mode 100644 index 00000000000..585c68b6bdf --- /dev/null +++ b/test/form/samples/reexport-external-namespace-as/_expected/amd.js @@ -0,0 +1,10 @@ +define(['exports', 'external'], function (exports, external) { 'use strict'; + + + + exports.external = external; + exports.indirect = external; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/form/samples/reexport-external-namespace-as/_expected/cjs.js b/test/form/samples/reexport-external-namespace-as/_expected/cjs.js new file mode 100644 index 00000000000..312e72fe973 --- /dev/null +++ b/test/form/samples/reexport-external-namespace-as/_expected/cjs.js @@ -0,0 +1,10 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var external = require('external'); + + + +exports.external = external; +exports.indirect = external; diff --git a/test/form/samples/reexport-external-namespace-as/_expected/es.js b/test/form/samples/reexport-external-namespace-as/_expected/es.js new file mode 100644 index 00000000000..06b81ff40b7 --- /dev/null +++ b/test/form/samples/reexport-external-namespace-as/_expected/es.js @@ -0,0 +1,3 @@ +import * as external from 'external'; +export { external }; +export { external as indirect }; diff --git a/test/form/samples/reexport-external-namespace-as/_expected/iife.js b/test/form/samples/reexport-external-namespace-as/_expected/iife.js new file mode 100644 index 00000000000..7a521ff16f2 --- /dev/null +++ b/test/form/samples/reexport-external-namespace-as/_expected/iife.js @@ -0,0 +1,11 @@ +var bundle = (function (exports, external) { + 'use strict'; + + + + exports.external = external; + exports.indirect = external; + + return exports; + +}({}, external)); diff --git a/test/form/samples/reexport-external-namespace-as/_expected/system.js b/test/form/samples/reexport-external-namespace-as/_expected/system.js new file mode 100644 index 00000000000..7b2e8f3cd70 --- /dev/null +++ b/test/form/samples/reexport-external-namespace-as/_expected/system.js @@ -0,0 +1,14 @@ +System.register('bundle', ['external'], function (exports) { + 'use strict'; + return { + setters: [function (module) { + exports('external', module); + exports('indirect', module); + }], + execute: function () { + + + + } + }; +}); diff --git a/test/form/samples/reexport-external-namespace-as/_expected/umd.js b/test/form/samples/reexport-external-namespace-as/_expected/umd.js new file mode 100644 index 00000000000..08b7c3f7af7 --- /dev/null +++ b/test/form/samples/reexport-external-namespace-as/_expected/umd.js @@ -0,0 +1,12 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) : + typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) : + (global = global || self, factory(global.bundle = {}, global.external)); +}(this, (function (exports, external) { 'use strict'; + + exports.external = external; + exports.indirect = external; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/test/form/samples/reexport-external-namespace-as/main.js b/test/form/samples/reexport-external-namespace-as/main.js new file mode 100644 index 00000000000..1015a7ff6cf --- /dev/null +++ b/test/form/samples/reexport-external-namespace-as/main.js @@ -0,0 +1,4 @@ +export * as external from 'external'; +import * as indirect from 'external'; + +export { indirect }; diff --git a/test/form/samples/reexport-used-external-namespace-as/_config.js b/test/form/samples/reexport-used-external-namespace-as/_config.js new file mode 100644 index 00000000000..cd50e2c3816 --- /dev/null +++ b/test/form/samples/reexport-used-external-namespace-as/_config.js @@ -0,0 +1,13 @@ +module.exports = { + description: 'reexport external namespace as name if the namespace is also used', + options: { + external: ['external1', 'external2'], + output: { + name: 'bundle', + globals: { + external1: 'external1', + external2: 'external2' + } + } + } +}; diff --git a/test/form/samples/reexport-used-external-namespace-as/_expected/amd.js b/test/form/samples/reexport-used-external-namespace-as/_expected/amd.js new file mode 100644 index 00000000000..04ce76ab32f --- /dev/null +++ b/test/form/samples/reexport-used-external-namespace-as/_expected/amd.js @@ -0,0 +1,10 @@ +define(['exports', 'external1', 'external2'], function (exports, imported1, external2) { 'use strict'; + + console.log(imported1, external2.imported2); + + exports.external1 = imported1; + exports.external2 = external2; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/form/samples/reexport-used-external-namespace-as/_expected/cjs.js b/test/form/samples/reexport-used-external-namespace-as/_expected/cjs.js new file mode 100644 index 00000000000..1704ea3d774 --- /dev/null +++ b/test/form/samples/reexport-used-external-namespace-as/_expected/cjs.js @@ -0,0 +1,11 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var imported1 = require('external1'); +var external2 = require('external2'); + +console.log(imported1, external2.imported2); + +exports.external1 = imported1; +exports.external2 = external2; diff --git a/test/form/samples/reexport-used-external-namespace-as/_expected/es.js b/test/form/samples/reexport-used-external-namespace-as/_expected/es.js new file mode 100644 index 00000000000..94dbfa4eafe --- /dev/null +++ b/test/form/samples/reexport-used-external-namespace-as/_expected/es.js @@ -0,0 +1,7 @@ +import * as imported1 from 'external1'; +export { imported1 as external1 }; +import { imported2 } from 'external2'; +import * as external2 from 'external2'; +export { external2 }; + +console.log(imported1, imported2); diff --git a/test/form/samples/reexport-used-external-namespace-as/_expected/iife.js b/test/form/samples/reexport-used-external-namespace-as/_expected/iife.js new file mode 100644 index 00000000000..1da66341d98 --- /dev/null +++ b/test/form/samples/reexport-used-external-namespace-as/_expected/iife.js @@ -0,0 +1,11 @@ +var bundle = (function (exports, imported1, external2) { + 'use strict'; + + console.log(imported1, external2.imported2); + + exports.external1 = imported1; + exports.external2 = external2; + + return exports; + +}({}, external1, external2)); diff --git a/test/form/samples/reexport-used-external-namespace-as/_expected/system.js b/test/form/samples/reexport-used-external-namespace-as/_expected/system.js new file mode 100644 index 00000000000..35f2fe86301 --- /dev/null +++ b/test/form/samples/reexport-used-external-namespace-as/_expected/system.js @@ -0,0 +1,18 @@ +System.register('bundle', ['external1', 'external2'], function (exports) { + 'use strict'; + var imported1, imported2; + return { + setters: [function (module) { + imported1 = module; + exports('external1', module); + }, function (module) { + imported2 = module.imported2; + exports('external2', module); + }], + execute: function () { + + console.log(imported1, imported2); + + } + }; +}); diff --git a/test/form/samples/reexport-used-external-namespace-as/_expected/umd.js b/test/form/samples/reexport-used-external-namespace-as/_expected/umd.js new file mode 100644 index 00000000000..15c098b0318 --- /dev/null +++ b/test/form/samples/reexport-used-external-namespace-as/_expected/umd.js @@ -0,0 +1,14 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external1'), require('external2')) : + typeof define === 'function' && define.amd ? define(['exports', 'external1', 'external2'], factory) : + (global = global || self, factory(global.bundle = {}, global.external1, global.external2)); +}(this, (function (exports, imported1, external2) { 'use strict'; + + console.log(imported1, external2.imported2); + + exports.external1 = imported1; + exports.external2 = external2; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/test/form/samples/reexport-used-external-namespace-as/main.js b/test/form/samples/reexport-used-external-namespace-as/main.js new file mode 100644 index 00000000000..447cb986a1b --- /dev/null +++ b/test/form/samples/reexport-used-external-namespace-as/main.js @@ -0,0 +1,6 @@ +export * as external1 from 'external1'; +import * as imported1 from 'external1'; +export * as external2 from 'external2'; +import { imported2 } from 'external2'; + +console.log(imported1, imported2); diff --git a/test/form/samples/supports-core-js/_expected.js b/test/form/samples/supports-core-js/_expected.js index 83d69bea095..88a5c136ff4 100644 --- a/test/form/samples/supports-core-js/_expected.js +++ b/test/form/samples/supports-core-js/_expected.js @@ -196,7 +196,7 @@ var shared = createCommonjsModule(function (module) { (module.exports = function (key, value) { return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {}); })('versions', []).push({ - version: '3.3.2', + version: '3.3.4', mode: 'global', copyright: '© 2019 Denis Pushkarev (zloirock.ru)' }); @@ -1876,10 +1876,30 @@ _export({ target: 'Array', stat: true, forced: ISNT_GENERIC }, { } }); +var userAgent = getBuiltIn('navigator', 'userAgent') || ''; + +var process = global_1.process; +var versions = process && process.versions; +var v8 = versions && versions.v8; +var match, version; + +if (v8) { + match = v8.split('.'); + version = match[0] + match[1]; +} else if (userAgent) { + match = userAgent.match(/Chrome\/(\d+)/); + if (match) version = match[1]; +} + +var v8Version = version && +version; + var SPECIES$1 = wellKnownSymbol('species'); var arrayMethodHasSpeciesSupport = function (METHOD_NAME) { - return !fails(function () { + // We can't use this feature detection in V8 since it causes + // deoptimization and serious performance degradation + // https://github.com/zloirock/core-js/issues/677 + return v8Version >= 51 || !fails(function () { var array = []; var constructor = array.constructor = {}; constructor[SPECIES$1] = function () { @@ -2868,15 +2888,22 @@ var fixRegexpWellKnownSymbolLogic = function (KEY, length, exec, sham) { // Symbol-named RegExp methods call .exec var execCalled = false; var re = /a/; - re.exec = function () { execCalled = true; return null; }; if (KEY === 'split') { + // We can't use real regex here since it causes deoptimization + // and serious performance degradation in V8 + // https://github.com/zloirock/core-js/issues/306 + re = {}; // RegExp[@@split] doesn't call the regex's exec method, but first creates // a new one. We need to return the patched regex when creating the new one. re.constructor = {}; re.constructor[SPECIES$4] = function () { return re; }; + re.flags = ''; + re[SYMBOL] = /./[SYMBOL]; } + re.exec = function () { execCalled = true; return null; }; + re[SYMBOL](''); return !execCalled; }); @@ -3125,8 +3152,6 @@ var stringPad = { end: createMethod$5(true) }; -var userAgent = getBuiltIn('navigator', 'userAgent') || ''; - // https://github.com/zloirock/core-js/issues/280 @@ -4505,7 +4530,7 @@ var anInstance = function (it, Constructor, name) { var location = global_1.location; var set$1 = global_1.setImmediate; var clear = global_1.clearImmediate; -var process = global_1.process; +var process$1 = global_1.process; var MessageChannel = global_1.MessageChannel; var Dispatch = global_1.Dispatch; var counter = 0; @@ -4554,9 +4579,9 @@ if (!set$1 || !clear) { delete queue[id]; }; // Node.js 0.8- - if (classofRaw(process) == 'process') { + if (classofRaw(process$1) == 'process') { defer = function (id) { - process.nextTick(runner(id)); + process$1.nextTick(runner(id)); }; // Sphere (JS game engine) Dispatch API } else if (Dispatch && Dispatch.now) { @@ -4602,9 +4627,9 @@ var macrotask = task.set; var MutationObserver = global_1.MutationObserver || global_1.WebKitMutationObserver; -var process$1 = global_1.process; +var process$2 = global_1.process; var Promise = global_1.Promise; -var IS_NODE = classofRaw(process$1) == 'process'; +var IS_NODE = classofRaw(process$2) == 'process'; // Node.js 11 shows ExperimentalWarning on getting `queueMicrotask` var queueMicrotaskDescriptor = getOwnPropertyDescriptor$5(global_1, 'queueMicrotask'); var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value; @@ -4615,7 +4640,7 @@ var flush, head, last, notify, toggle, node, promise, then; if (!queueMicrotask) { flush = function () { var parent, fn; - if (IS_NODE && (parent = process$1.domain)) parent.exit(); + if (IS_NODE && (parent = process$2.domain)) parent.exit(); while (head) { fn = head.fn; head = head.next; @@ -4633,7 +4658,7 @@ if (!queueMicrotask) { // Node.js if (IS_NODE) { notify = function () { - process$1.nextTick(flush); + process$2.nextTick(flush); }; // browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339 } else if (MutationObserver && !/(iphone|ipod|ipad).*applewebkit/i.test(userAgent)) { @@ -4737,13 +4762,11 @@ var getInternalPromiseState = internalState.getterFor(PROMISE); var PromiseConstructor = nativePromiseConstructor; var TypeError$1 = global_1.TypeError; var document$2 = global_1.document; -var process$2 = global_1.process; -var $fetch = global_1.fetch; -var versions = process$2 && process$2.versions; -var v8 = versions && versions.v8 || ''; +var process$3 = global_1.process; +var $fetch = getBuiltIn('fetch'); var newPromiseCapability$1 = newPromiseCapability.f; var newGenericPromiseCapability = newPromiseCapability$1; -var IS_NODE$1 = classofRaw(process$2) == 'process'; +var IS_NODE$1 = classofRaw(process$3) == 'process'; var DISPATCH_EVENT = !!(document$2 && document$2.createEvent && global_1.dispatchEvent); var UNHANDLED_REJECTION = 'unhandledrejection'; var REJECTION_HANDLED = 'rejectionhandled'; @@ -4768,8 +4791,7 @@ var FORCED$e = isForced_1(PROMISE, function () { // v8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables // https://bugs.chromium.org/p/chromium/issues/detail?id=830565 // we can't detect it synchronously, so just check versions - && v8.indexOf('6.6') !== 0 - && userAgent.indexOf('Chrome/66') === -1); + && v8Version !== 66); }); var INCORRECT_ITERATION$1 = FORCED$e || !checkCorrectnessOfIteration(function (iterable) { @@ -4851,7 +4873,7 @@ var onUnhandled = function (promise, state) { if (IS_UNHANDLED) { result = perform(function () { if (IS_NODE$1) { - process$2.emit('unhandledRejection', value, promise); + process$3.emit('unhandledRejection', value, promise); } else dispatchEvent(UNHANDLED_REJECTION, promise, value); }); // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should @@ -4868,7 +4890,7 @@ var isUnhandled = function (state) { var onHandleUnhandled = function (promise, state) { task$1.call(global_1, function () { if (IS_NODE$1) { - process$2.emit('rejectionHandled', promise); + process$3.emit('rejectionHandled', promise); } else dispatchEvent(REJECTION_HANDLED, promise, state.value); }); }; @@ -4952,7 +4974,7 @@ if (FORCED$e) { var reaction = newPromiseCapability$1(speciesConstructor(this, PromiseConstructor)); reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true; reaction.fail = typeof onRejected == 'function' && onRejected; - reaction.domain = IS_NODE$1 ? process$2.domain : undefined; + reaction.domain = IS_NODE$1 ? process$3.domain : undefined; state.parent = true; state.reactions.push(reaction); if (state.state != PENDING) notify$1(this, state, false); @@ -4992,7 +5014,7 @@ if (FORCED$e) { // wrap fetch result if (typeof $fetch == 'function') _export({ global: true, enumerable: true, forced: true }, { // eslint-disable-next-line no-unused-vars - fetch: function fetch(input) { + fetch: function fetch(input /* , init */) { return promiseResolve(PromiseConstructor, $fetch.apply(global_1, arguments)); } }); @@ -5006,7 +5028,7 @@ _export({ global: true, wrap: true, forced: FORCED$e }, { setToStringTag(PromiseConstructor, PROMISE, false); setSpecies(PROMISE); -PromiseWrapper = path[PROMISE]; +PromiseWrapper = getBuiltIn(PROMISE); // statics _export({ target: PROMISE, stat: true, forced: FORCED$e }, { @@ -7526,6 +7548,12 @@ var getIterator = function (it) { + + + + +var $fetch$1 = getBuiltIn('fetch'); +var Headers = getBuiltIn('Headers'); var ITERATOR$7 = wellKnownSymbol('iterator'); var URL_SEARCH_PARAMS = 'URLSearchParams'; var URL_SEARCH_PARAMS_ITERATOR = URL_SEARCH_PARAMS + 'Iterator'; @@ -7816,6 +7844,34 @@ _export({ global: true, forced: !nativeUrl }, { URLSearchParams: URLSearchParamsConstructor }); +// Wrap `fetch` for correct work with polyfilled `URLSearchParams` +// https://github.com/zloirock/core-js/issues/674 +if (!nativeUrl && typeof $fetch$1 == 'function' && typeof Headers == 'function') { + _export({ global: true, enumerable: true, forced: true }, { + fetch: function fetch(input /* , init */) { + var args = [input]; + var init, body, headers; + if (arguments.length > 1) { + init = arguments[1]; + if (isObject(init)) { + body = init.body; + if (classof(body) === URL_SEARCH_PARAMS) { + headers = new Headers(init.headers); + if (!headers.has('content-type')) { + headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); + } + init = objectCreate(init, { + body: createPropertyDescriptor(0, String(body)), + headers: createPropertyDescriptor(0, headers) + }); + } + } + args.push(init); + } return $fetch$1.apply(this, args); + } + }); +} + var web_urlSearchParams = { URLSearchParams: URLSearchParamsConstructor, getState: getInternalParamsState @@ -8082,7 +8138,6 @@ var percentEncode = function (char, set) { var specialSchemes = { ftp: 21, file: null, - gopher: 70, http: 80, https: 443, ws: 80, @@ -10779,6 +10834,7 @@ _export({ target: 'String', proto: true }, { } string = String(O); searchString = String(searchValue); + if (searchString === '') return replaceAll.call(O, /(?:)/g, replaceValue); template = string.split(searchString); if (typeof replaceValue !== 'function') { return template.join(String(replaceValue)); @@ -10884,14 +10940,14 @@ _export({ global: true, bind: true, enumerable: true, forced: FORCED$k }, { clearImmediate: task.clear }); -var process$3 = global_1.process; -var isNode = classofRaw(process$3) == 'process'; +var process$4 = global_1.process; +var isNode = classofRaw(process$4) == 'process'; // `queueMicrotask` method // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-queuemicrotask _export({ global: true, enumerable: true, noTargetGet: true }, { queueMicrotask: function queueMicrotask(fn) { - var domain = isNode && process$3.domain; + var domain = isNode && process$4.domain; microtask(domain ? domain.bind(fn) : fn); } }); diff --git a/test/misc/iife.js b/test/misc/iife.js index d3cb2f50ee3..e38ca68c815 100644 --- a/test/misc/iife.js +++ b/test/misc/iife.js @@ -1,6 +1,7 @@ const rollup = require('../../dist/rollup'); const assert = require('assert'); const { loader } = require('../utils.js'); +const { compareError } = require('../utils.js'); function runTestCode(code, globals) { const globalsWithAssert = Object.assign({}, globals, { assert }); @@ -49,22 +50,14 @@ function runTestsWithCode(code, outputOptions, expectedExports) { it('works with extend=false', () => { const options = Object.assign({ extend: false }, outputOptions); return getIifeCode(code, options).then(code => - assert.deepEqual( - runIifeTest(code, options), - expectedExports, - 'expected exports are returned' - ) + assert.deepEqual(runIifeTest(code, options), expectedExports, 'expected exports are returned') ); }); it('works with extend=true', () => { const options = Object.assign({ extend: true }, outputOptions); return getIifeCode(code, options).then(code => - assert.deepEqual( - runIifeTest(code, options), - expectedExports, - 'expected exports are returned' - ) + assert.deepEqual(runIifeTest(code, options), expectedExports, 'expected exports are returned') ); }); } @@ -102,3 +95,46 @@ function runTestsWithCode(code, outputOptions, expectedExports) { }) ) ); + +describe('The IIFE wrapper with an illegal name', () => { + it('fails if the name starts with a digit', () => + getIifeCode('export const x = 42;', { name: '1name' }) + .then(() => { + throw new Error('Expected an error to be thrown.'); + }) + .catch(error => + compareError(error, { + code: 'ILLEGAL_IDENTIFIER_AS_NAME', + message: + 'Given name "1name" is not a legal JS identifier. If you need this, you can try "output.extend: true".' + }) + )); + + it('fails if the name contains an illegal character', () => + getIifeCode('export const x = 42;', { name: 'my=name' }) + .then(() => { + throw new Error('Expected an error to be thrown.'); + }) + .catch(error => + compareError(error, { + code: 'ILLEGAL_IDENTIFIER_AS_NAME', + message: + 'Given name "my=name" is not a legal JS identifier. If you need this, you can try "output.extend: true".' + }) + )); + + it('does not fail for illegal characters if the extend option is used', () => + getIifeCode('export const x = 42;', { name: 'my=name', extend: true }).then(code => + assert.equal( + code, + '(function (exports) {\n' + + "\t'use strict';\n" + + '\n' + + '\tconst x = 42;\n' + + '\n' + + '\texports.x = x;\n' + + '\n' + + "}(this['my=name'] = this['my=name'] || {}));\n" + ) + )); +}); diff --git a/typings/declarations.d.ts b/typings/declarations.d.ts index 144632ac539..2283bde8795 100644 --- a/typings/declarations.d.ts +++ b/typings/declarations.d.ts @@ -14,3 +14,4 @@ declare module 'locate-character'; declare module 'is-reference'; declare module 'require-relative'; declare module 'acorn-import-meta'; +declare module 'acorn-export-ns-from';