From cc541fb25260f7315d3e223d368cfad80c99f25a Mon Sep 17 00:00:00 2001 From: Arsalan Khattak <37709578+eKhattak@users.noreply.github.com> Date: Fri, 24 Jul 2020 21:35:39 +0500 Subject: [PATCH 01/90] Add Sitemap Example (#15047) * Add with-sitemap Example * Update README * Update examples/with-sitemap/scripts/generate-sitemap.js Co-authored-by: Luis Alvarez D. * Update examples/with-sitemap/package.json Co-authored-by: Luis Alvarez D. * Update examples/with-sitemap/public/sitemap.xml Co-authored-by: Luis Alvarez D. * Update README * Add .env Info to README * Update examples/with-sitemap/README.md Co-authored-by: Luis Alvarez D. * Update examples/with-sitemap/README.md Co-authored-by: Luis Alvarez D. * Update examples/with-sitemap/README.md Co-authored-by: Luis Alvarez D. * Update examples/with-sitemap/README.md Co-authored-by: Luis Alvarez D. Co-authored-by: Luis Alvarez D. --- examples/with-sitemap/.env | 2 + examples/with-sitemap/README.md | 51 +++++ examples/with-sitemap/next.config.js | 9 + examples/with-sitemap/package.json | 18 ++ examples/with-sitemap/pages/contact.js | 128 +++++++++++ examples/with-sitemap/pages/index.js | 209 ++++++++++++++++++ examples/with-sitemap/public/favicon.ico | Bin 0 -> 15086 bytes examples/with-sitemap/public/sitemap.xml | 10 + examples/with-sitemap/public/vercel.svg | 4 + .../with-sitemap/scripts/generate-sitemap.js | 28 +++ 10 files changed, 459 insertions(+) create mode 100644 examples/with-sitemap/.env create mode 100644 examples/with-sitemap/README.md create mode 100644 examples/with-sitemap/next.config.js create mode 100644 examples/with-sitemap/package.json create mode 100644 examples/with-sitemap/pages/contact.js create mode 100644 examples/with-sitemap/pages/index.js create mode 100644 examples/with-sitemap/public/favicon.ico create mode 100644 examples/with-sitemap/public/sitemap.xml create mode 100644 examples/with-sitemap/public/vercel.svg create mode 100644 examples/with-sitemap/scripts/generate-sitemap.js diff --git a/examples/with-sitemap/.env b/examples/with-sitemap/.env new file mode 100644 index 0000000000000..8d8ccb6fca0e4 --- /dev/null +++ b/examples/with-sitemap/.env @@ -0,0 +1,2 @@ +# Used to add the domain to sitemap.xml, replace it with a real domain in production +WEBSITE_URL=http://localhost:3000 \ No newline at end of file diff --git a/examples/with-sitemap/README.md b/examples/with-sitemap/README.md new file mode 100644 index 0000000000000..a6d6d7b56b76b --- /dev/null +++ b/examples/with-sitemap/README.md @@ -0,0 +1,51 @@ +# With Sitemap example + +This example shows how to generate a `sitemap.xml` file based on the pages in your [Next.js](https://nextjs.org/) app. The sitemap will be generated and saved in the `public` directory after starting the development server or by making a build. + +## Deploy your own + +Deploy the example using [Vercel](https://vercel.com): + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/hello-world) + +## How to use + +### Using `create-next-app` + +Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: + +```bash +npx create-next-app --example with-sitemap with-sitemap-app +# or +yarn create next-app --example with-sitemap with-sitemap-app +``` + +### Download manually + +Download the example: + +```bash +curl https://codeload.github.com/vercel/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-sitemap +cd with-sitemap +``` + +Install it and run: + +```bash +npm install +npm run dev +# or +yarn +yarn dev +``` + +Your app should be up and running on [http://localhost:3000](http://localhost:3000) and the sitemap should now be available in [http://localhost:3000/sitemap.xml](http://localhost:3000/sitemap.xml)! If it doesn't work, post on [GitHub discussions](https://github.com/vercel/next.js/discussions). + +To change the website URL used by `sitemap.xml`, open the file `.env` and change the `WEBSITE_URL` environment variable: + +```bash +# Used to add the domain to sitemap.xml, replace it with a real domain in production +WEBSITE_URL=https://my-domain.com +``` + +Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). diff --git a/examples/with-sitemap/next.config.js b/examples/with-sitemap/next.config.js new file mode 100644 index 0000000000000..08a972d01c6d6 --- /dev/null +++ b/examples/with-sitemap/next.config.js @@ -0,0 +1,9 @@ +module.exports = { + webpack: (config, { isServer }) => { + if (isServer) { + require('./scripts/generate-sitemap') + } + + return config + }, +} diff --git a/examples/with-sitemap/package.json b/examples/with-sitemap/package.json new file mode 100644 index 0000000000000..beb83580fa2e2 --- /dev/null +++ b/examples/with-sitemap/package.json @@ -0,0 +1,18 @@ +{ + "name": "with-sitemap", + "version": "0.1.0", + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start" + }, + "dependencies": { + "next": "latest", + "react": "^16.13.1", + "react-dom": "^16.13.1" + }, + "devDependencies": { + "globby": "^11.0.1" + }, + "license": "MIT" +} diff --git a/examples/with-sitemap/pages/contact.js b/examples/with-sitemap/pages/contact.js new file mode 100644 index 0000000000000..0d718f02d5fc9 --- /dev/null +++ b/examples/with-sitemap/pages/contact.js @@ -0,0 +1,128 @@ +import Head from 'next/head' + +export default function Home() { + return ( +
+ + Create Next App + + + +
+

+ Welcome to Next.js! +

+ +

Contact Page

+
+ + + + + + +
+ ) +} diff --git a/examples/with-sitemap/pages/index.js b/examples/with-sitemap/pages/index.js new file mode 100644 index 0000000000000..1379c5f92dabb --- /dev/null +++ b/examples/with-sitemap/pages/index.js @@ -0,0 +1,209 @@ +import Head from 'next/head' + +export default function Home() { + return ( +
+ + Create Next App + + + +
+

+ Welcome to Next.js! +

+ +

+ Get started by editing pages/index.js +

+ + +
+ + + + + + +
+ ) +} diff --git a/examples/with-sitemap/public/favicon.ico b/examples/with-sitemap/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..4965832f2c9b0605eaa189b7c7fb11124d24e48a GIT binary patch literal 15086 zcmeHOOH5Q(7(R0cc?bh2AT>N@1PWL!LLfZKyG5c!MTHoP7_p!sBz0k$?pjS;^lmgJ zU6^i~bWuZYHL)9$wuvEKm~qo~(5=Lvx5&Hv;?X#m}i|`yaGY4gX+&b>tew;gcnRQA1kp zBbm04SRuuE{Hn+&1wk%&g;?wja_Is#1gKoFlI7f`Gt}X*-nsMO30b_J@)EFNhzd1QM zdH&qFb9PVqQOx@clvc#KAu}^GrN`q5oP(8>m4UOcp`k&xwzkTio*p?kI4BPtIwX%B zJN69cGsm=x90<;Wmh-bs>43F}ro$}Of@8)4KHndLiR$nW?*{Rl72JPUqRr3ta6e#A z%DTEbi9N}+xPtd1juj8;(CJt3r9NOgb>KTuK|z7!JB_KsFW3(pBN4oh&M&}Nb$Ee2 z$-arA6a)CdsPj`M#1DS>fqj#KF%0q?w50GN4YbmMZIoF{e1yTR=4ablqXHBB2!`wM z1M1ke9+<);|AI;f=2^F1;G6Wfpql?1d5D4rMr?#f(=hkoH)U`6Gb)#xDLjoKjp)1;Js@2Iy5yk zMXUqj+gyk1i0yLjWS|3sM2-1ECc;MAz<4t0P53%7se$$+5Ex`L5TQO_MMXXi04UDIU+3*7Ez&X|mj9cFYBXqM{M;mw_ zpw>azP*qjMyNSD4hh)XZt$gqf8f?eRSFX8VQ4Y+H3jAtvyTrXr`qHAD6`m;aYmH2zOhJC~_*AuT} zvUxC38|JYN94i(05R)dVKgUQF$}#cxV7xZ4FULqFCNX*Forhgp*yr6;DsIk=ub0Hv zpk2L{9Q&|uI^b<6@i(Y+iSxeO_n**4nRLc`P!3ld5jL=nZRw6;DEJ*1z6Pvg+eW|$lnnjO zjd|8>6l{i~UxI244CGn2kK@cJ|#ecwgSyt&HKA2)z zrOO{op^o*- + + http://localhost:3000/contact + hourly + + + http://localhost:3000 + hourly + + \ No newline at end of file diff --git a/examples/with-sitemap/public/vercel.svg b/examples/with-sitemap/public/vercel.svg new file mode 100644 index 0000000000000..fbf0e25a651c2 --- /dev/null +++ b/examples/with-sitemap/public/vercel.svg @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/examples/with-sitemap/scripts/generate-sitemap.js b/examples/with-sitemap/scripts/generate-sitemap.js new file mode 100644 index 0000000000000..4bd49377b2c50 --- /dev/null +++ b/examples/with-sitemap/scripts/generate-sitemap.js @@ -0,0 +1,28 @@ +const fs = require('fs') +const globby = require('globby') + +function addPage(page) { + const path = page.replace('pages', '').replace('.js', '').replace('.mdx', '') + const route = path === '/index' ? '' : path + + return ` + ${`${process.env.WEBSITE_URL}${route}`} + hourly + ` +} + +async function generateSitemap() { + // Ignore Next.js specific files (e.g., _app.js) and API routes. + const pages = await globby([ + 'pages/**/*{.js,.mdx}', + '!pages/_*.js', + '!pages/api', + ]) + const sitemap = ` +${pages.map(addPage).join('\n')} +` + + fs.writeFileSync('public/sitemap.xml', sitemap) +} + +generateSitemap() From c5f29b76ea125d122d443c975896399f44c428f0 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 24 Jul 2020 21:23:23 +0200 Subject: [PATCH 02/90] Update webpack to land chokidar patch for all Next.js users (#15460) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Forces all Next.js users to have this patch installed: https://twitter.com/timneutkens/status/1282129714627448832 Huge thanks to @paulmillr and @sokra 🙏 --- packages/next/package.json | 2 +- yarn.lock | 53 +++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/packages/next/package.json b/packages/next/package.json index bada05e57c3a2..3004bc9753eba 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -107,7 +107,7 @@ "use-subscription": "1.4.1", "watchpack": "2.0.0-beta.13", "web-vitals": "0.2.1", - "webpack": "4.43.0", + "webpack": "4.44.0", "webpack-sources": "1.4.3" }, "peerDependencies": { diff --git a/yarn.lock b/yarn.lock index 5ba1dacc9ea3a..b154883c4e116 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4104,7 +4104,7 @@ browserify-zlib@^0.2.0: dependencies: pako "~1.0.5" -browserslist@4.13.0, browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6, browserslist@^4.0.0, browserslist@^4.11.1, browserslist@^4.13.0, browserslist@^4.3.6, browserslist@^4.6.4, browserslist@^4.8.3, browserslist@^4.8.5: +browserslist@4.13.0, browserslist@^4.0.0, browserslist@^4.11.1, browserslist@^4.13.0, browserslist@^4.3.6, browserslist@^4.6.4, browserslist@^4.8.3, browserslist@^4.8.5: version "4.13.0" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.13.0.tgz#42556cba011e1b0a2775b611cba6a8eca18e940d" integrity sha512-MINatJ5ZNrLnQ6blGvePd/QOz9Xtu+Ne+x29iQSCHfkU5BugKVJwZKn/iiL8UbpIpa3JhviKjz+XxMo0m2caFQ== @@ -4114,6 +4114,14 @@ browserslist@4.13.0, browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7 escalade "^3.0.1" node-releases "^1.1.58" +browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6: + version "1.7.7" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.7.7.tgz#0bd76704258be829b2398bb50e4b62d1a166b0b9" + integrity sha1-C9dnBCWL6CmyOYu1Dkti0aFmsLk= + dependencies: + caniuse-db "^1.0.30000639" + electron-to-chromium "^1.2.7" + browserstack-local@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/browserstack-local/-/browserstack-local-1.4.0.tgz#d979cac056f57b9af159b3bcd7fdc09b4354537c" @@ -4412,11 +4420,21 @@ caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634: version "1.0.30001023" resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001023.tgz#f856f71af16a5a44e81f1fcefc1673912a43da72" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001019, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001093: +caniuse-db@^1.0.30000639: + version "1.0.30001105" + resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001105.tgz#5cc03239a9d4540b3fa9a1dc8b5e3bda50226e96" + integrity sha512-GZytZn8lOiru/Tw+/X5sFxrFt2uPdSvkxVKzRMJyX20JGwfwOuTiRg5IMVF9II8Lao/7C4YeHR8YnZzpTvYXdQ== + +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001019, caniuse-lite@^1.0.30001020: version "1.0.30001066" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001066.tgz#0a8a58a10108f2b9bf38e7b65c237b12fd9c5f04" integrity sha512-Gfj/WAastBtfxLws0RCh2sDbTK/8rJuSeZMecrSkNGYxPcv7EzblmDGfWQCFEQcSqYE2BRgQiJh8HOD07N5hIw== +caniuse-lite@^1.0.30001093: + version "1.0.30001105" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001105.tgz#d2cb0b31e5cf2f3ce845033b61c5c01566549abf" + integrity sha512-JupOe6+dGMr7E20siZHIZQwYqrllxotAhiaej96y6x00b/48rPt42o+SzOSCPbrpsDWvRja40Hwrj0g0q6LZJg== + capitalize@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/capitalize/-/capitalize-1.0.0.tgz#dc802c580aee101929020d2ca14b4ca8a0ae44be" @@ -4590,7 +4608,7 @@ chokidar@^1.7.0: optionalDependencies: fsevents "^1.0.0" -chokidar@^3.4.0: +chokidar@^3.4.1: version "3.4.1" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.1.tgz#e905bdecf10eaa0a0b1db0c664481cc4cbc22ba1" integrity sha512-TQTJyr2stihpC4Sya9hs2Xh+O2wf+igjL36Y75xx2WdHuiICcn/XJza46Jwt0eT5hVpQOzo3FpY3cj3RVYLX0g== @@ -6138,6 +6156,11 @@ ejs@^2.6.1: version "2.7.4" resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba" +electron-to-chromium@^1.2.7: + version "1.3.506" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.506.tgz#74bd3e1fb31285b3247f165d4958da74d70ae4e4" + integrity sha512-k0PHtv4gD6KJu1k6lp8pvQOe12uZriOwS2x66Vnxkq0NOBucsNrItOj/ehomvcZ3S4K1ueqUCv+fsLhXBs6Zyw== + electron-to-chromium@^1.3.488: version "1.3.501" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.501.tgz#faa17a2cb0105ee30d5e1ca87eae7d8e85dd3175" @@ -6192,7 +6215,7 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1: dependencies: once "^1.4.0" -enhanced-resolve@^4.1.0: +enhanced-resolve@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.3.0.tgz#3b806f3bfafc1ec7de69551ef93cca46c1704126" integrity sha512-3e87LvavsdxyoCfGusJnrZ5G8SLPOFeHSNpZI/ATL9a5leXo2k0w6MKnbqhdBad9qTobSfB20Ld7UmgoNbAZkQ== @@ -15999,15 +16022,15 @@ watchpack@2.0.0-beta.13: glob-to-regexp "^0.4.1" graceful-fs "^4.1.2" -watchpack@^1.6.1: - version "1.7.2" - resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.7.2.tgz#c02e4d4d49913c3e7e122c3325365af9d331e9aa" - integrity sha512-ymVbbQP40MFTp+cNMvpyBpBtygHnPzPkHqoIwRRj/0B8KhqQwV8LaKjtbaxF2lK4vl8zN9wCxS46IFCU5K4W0g== +watchpack@^1.7.4: + version "1.7.4" + resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.7.4.tgz#6e9da53b3c80bb2d6508188f5b200410866cd30b" + integrity sha512-aWAgTW4MoSJzZPAicljkO1hsi1oKj/RRq/OJQh2PKI2UKL04c2Bs+MBOB+BBABHTXJpf9mCwHN7ANCvYsvY2sg== dependencies: graceful-fs "^4.1.2" neo-async "^2.5.0" optionalDependencies: - chokidar "^3.4.0" + chokidar "^3.4.1" watchpack-chokidar2 "^2.0.0" wcwidth@^1.0.0, wcwidth@^1.0.1: @@ -16062,10 +16085,10 @@ webpack-sources@1.4.3, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-s source-list-map "^2.0.0" source-map "~0.6.1" -webpack@4.43.0: - version "4.43.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.43.0.tgz#c48547b11d563224c561dad1172c8aa0b8a678e6" - integrity sha512-GW1LjnPipFW2Y78OOab8NJlCflB7EFskMih2AHdvjbpKMeDJqEgSx24cXXXiPS65+WSwVyxtDsJH6jGX2czy+g== +webpack@4.44.0: + version "4.44.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.44.0.tgz#3b08f88a89470175f036f4a9496b8a0428668802" + integrity sha512-wAuJxK123sqAw31SpkPiPW3iKHgFUiKvO7E7UZjtdExcsRe3fgav4mvoMM7vvpjLHVoJ6a0Mtp2fzkoA13e0Zw== dependencies: "@webassemblyjs/ast" "1.9.0" "@webassemblyjs/helper-module-context" "1.9.0" @@ -16075,7 +16098,7 @@ webpack@4.43.0: ajv "^6.10.2" ajv-keywords "^3.4.1" chrome-trace-event "^1.0.2" - enhanced-resolve "^4.1.0" + enhanced-resolve "^4.3.0" eslint-scope "^4.0.3" json-parse-better-errors "^1.0.2" loader-runner "^2.4.0" @@ -16088,7 +16111,7 @@ webpack@4.43.0: schema-utils "^1.0.0" tapable "^1.1.3" terser-webpack-plugin "^1.4.3" - watchpack "^1.6.1" + watchpack "^1.7.4" webpack-sources "^1.4.1" websocket-driver@>=0.5.1: From e6e2722b117976d6233f5c72c337a3b03a3906c9 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Fri, 24 Jul 2020 22:04:53 +0200 Subject: [PATCH 03/90] Tweak test retries for invalid-href suite (#15459) - Reduce jest retries to 2 for a total of 3 attempts - Disable retries in `invalid-href` test. I noticed jest retries don't help when this test fails (see log output of https://github.com/vercel/next.js/runs/904147534). --- run-tests.js | 2 +- test/integration/invalid-href/test/index.test.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/run-tests.js b/run-tests.js index df5991493e6f4..5dd3964ab57cd 100644 --- a/run-tests.js +++ b/run-tests.js @@ -136,7 +136,7 @@ const TIMINGS_API = `https://next-timings.jjsweb.site/api/timings` { stdio: 'inherit', env: { - JEST_RETRY_TIMES: 3, + JEST_RETRY_TIMES: 2, ...process.env, ...(isAzure ? { diff --git a/test/integration/invalid-href/test/index.test.js b/test/integration/invalid-href/test/index.test.js index e80edc99d00b6..b612671d88a38 100644 --- a/test/integration/invalid-href/test/index.test.js +++ b/test/integration/invalid-href/test/index.test.js @@ -14,7 +14,7 @@ import { import webdriver from 'next-webdriver' import { join } from 'path' -jest.setTimeout(1000 * 60 * 2) +jest.setTimeout(1000 * 60 * 1) let app let appPort @@ -23,6 +23,10 @@ const appDir = join(__dirname, '..') const firstErrorRegex = /Invalid href passed to router: mailto:idk@idk.com.*invalid-href-passed/ const secondErrorRegex = /Invalid href passed to router: .*google\.com.*invalid-href-passed/ +// This test doesn't seem to benefit from retries, let's disable them until the test gets fixed +// to prevent long running times +jest.retryTimes(0) + const showsError = async (pathname, regex, click = false, isWarn = false) => { const browser = await webdriver(appPort, pathname) try { From 1a34b237b62eeb9424983794dc31820f713e02a0 Mon Sep 17 00:00:00 2001 From: Robin Tom <31811117+robintom@users.noreply.github.com> Date: Sat, 25 Jul 2020 08:08:58 +0530 Subject: [PATCH 04/90] Example for Rewrites (Custom routes) (#15403) This PR adds example for #15073 > - [ ] `rewrites` For [docs/api-reference/next.config.js/rewrites.md](https://github.com/vercel/next.js/blob/canary/docs/api-reference/next.config.js/rewrites.md) --- docs/api-reference/next.config.js/rewrites.md | 7 +++ examples/rewrites/.gitignore | 34 ++++++++++++ examples/rewrites/README.md | 23 ++++++++ examples/rewrites/next.config.js | 29 ++++++++++ examples/rewrites/package.json | 15 ++++++ examples/rewrites/pages/about.js | 32 +++++++++++ examples/rewrites/pages/index.js | 54 +++++++++++++++++++ examples/rewrites/pages/news/[...slug].js | 35 ++++++++++++ examples/rewrites/styles.module.css | 51 ++++++++++++++++++ 9 files changed, 280 insertions(+) create mode 100644 examples/rewrites/.gitignore create mode 100644 examples/rewrites/README.md create mode 100644 examples/rewrites/next.config.js create mode 100644 examples/rewrites/package.json create mode 100644 examples/rewrites/pages/about.js create mode 100644 examples/rewrites/pages/index.js create mode 100644 examples/rewrites/pages/news/[...slug].js create mode 100644 examples/rewrites/styles.module.css diff --git a/docs/api-reference/next.config.js/rewrites.md b/docs/api-reference/next.config.js/rewrites.md index f922daaebf2cd..29d99b460ad98 100644 --- a/docs/api-reference/next.config.js/rewrites.md +++ b/docs/api-reference/next.config.js/rewrites.md @@ -4,6 +4,13 @@ description: Add rewrites to your Next.js app. # Rewrites +
+ Examples + +
+ Rewrites allow you to map an incoming request path to a different destination path. Rewrites are only available on the Node.js environment and do not affect client-side routing. diff --git a/examples/rewrites/.gitignore b/examples/rewrites/.gitignore new file mode 100644 index 0000000000000..1437c53f70bc2 --- /dev/null +++ b/examples/rewrites/.gitignore @@ -0,0 +1,34 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env.local +.env.development.local +.env.test.local +.env.production.local + +# vercel +.vercel diff --git a/examples/rewrites/README.md b/examples/rewrites/README.md new file mode 100644 index 0000000000000..4e02089b55fb9 --- /dev/null +++ b/examples/rewrites/README.md @@ -0,0 +1,23 @@ +# Rewrites Example + +This example shows how to use [rewrites in Next.js](https://nextjs.org/docs/api-reference/next.config.js/rewrites) to map an incoming request path to a different destination path. + +The index page ([`pages/index.js`](pages/index.js)) has a list of links that match the rewrites defined in [`next.config.js`](next.config.js). Run or deploy the app to see how it works! + +## Deploy your own + +Deploy the example using [Vercel](https://vercel.com): + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/rewrites) + +## How to use + +Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: + +```bash +npx create-next-app --example rewrites rewrites-app +# or +yarn create next-app --example rewrites rewrites-app +``` + +Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). diff --git a/examples/rewrites/next.config.js b/examples/rewrites/next.config.js new file mode 100644 index 0000000000000..be6f24b054da1 --- /dev/null +++ b/examples/rewrites/next.config.js @@ -0,0 +1,29 @@ +module.exports = { + async rewrites() { + return [ + { + source: '/team', + destination: '/about', + }, + { + source: '/about-us', + destination: '/about', + }, + // Path Matching - will match `/post/a` but not `/post/a/b` + { + source: '/post/:slug', + destination: '/news/:slug', + }, + // Wildcard Path Matching - will match `/news/a` and `/news/a/b` + { + source: '/blog/:slug*', + destination: '/news/:slug*', + }, + // Rewriting to an external URL + { + source: '/docs/:slug', + destination: 'http://example.com/docs/:slug', + }, + ] + }, +} diff --git a/examples/rewrites/package.json b/examples/rewrites/package.json new file mode 100644 index 0000000000000..460cf0fcad9ff --- /dev/null +++ b/examples/rewrites/package.json @@ -0,0 +1,15 @@ +{ + "name": "rewrites", + "version": "1.0.0", + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start" + }, + "dependencies": { + "next": "9.4.5-canary.43", + "react": "^16.13.1", + "react-dom": "^16.13.1" + }, + "license": "MIT" +} diff --git a/examples/rewrites/pages/about.js b/examples/rewrites/pages/about.js new file mode 100644 index 0000000000000..4e4ce29213362 --- /dev/null +++ b/examples/rewrites/pages/about.js @@ -0,0 +1,32 @@ +import { useState, useEffect } from 'react' +import { useRouter } from 'next/router' +import Link from 'next/link' +import styles from '../styles.module.css' + +const Code = (p) => + +export default function About() { + const { asPath, route } = useRouter() + const [path, setPath] = useState() + + // `asPath` is always `/about` in Node.js (server render), because the page is statically generated + // so we wait for the browser to load, and use the updated `asPath`, which may be a path + // other than `/about` when using a rewrite. This way we can avoid a content mismatch + useEffect(() => setPath(asPath), [asPath]) + + return ( +
+
+

Path: {path}

+
+

+ {' '} + This page was rendered by {`pages${route}.js`}. +

+ + ← Back home + +
+
+ ) +} diff --git a/examples/rewrites/pages/index.js b/examples/rewrites/pages/index.js new file mode 100644 index 0000000000000..6baeb6afce252 --- /dev/null +++ b/examples/rewrites/pages/index.js @@ -0,0 +1,54 @@ +import styles from '../styles.module.css' +import Link from 'next/link' + +const Code = (p) => + +const Index = () => ( +
+
+

Rewrites with Next.js

+
+

+ The links below are{' '} + + custom rewrites + {' '} + that map an incoming request path to a different destination path. +

+ +

+ Open next.config.js to learn more about the rewrites that + match the links above. +

+
+
+
+) + +export default Index diff --git a/examples/rewrites/pages/news/[...slug].js b/examples/rewrites/pages/news/[...slug].js new file mode 100644 index 0000000000000..1b537cf69be27 --- /dev/null +++ b/examples/rewrites/pages/news/[...slug].js @@ -0,0 +1,35 @@ +import { useRouter } from 'next/router' +import Link from 'next/link' +import styles from '../../styles.module.css' + +const Code = (p) => + +export default function News() { + const { asPath, route, query } = useRouter() + + return ( +
+
+

Path: {asPath}

+
+

+ This page was rendered by {`pages${route}.js`}. +

+

+ The query slug for this page is:{' '} + {JSON.stringify(query.slug)} +

+ + ← Back home + +
+
+ ) +} + +// Use SSR for this page as currently rewrites don't work with dynamic pages without SSR +export async function getServerSideProps(context) { + return { + props: {}, + } +} diff --git a/examples/rewrites/styles.module.css b/examples/rewrites/styles.module.css new file mode 100644 index 0000000000000..cd7bec9b86a9b --- /dev/null +++ b/examples/rewrites/styles.module.css @@ -0,0 +1,51 @@ +.container { + padding: 4rem 1rem; + font-family: -apple-system, BlinkMacSystemFont, sans-serif; +} + +.container p { + margin: 1.5rem 0; +} + +.card { + max-width: 50rem; + box-shadow: -10px 10px 80px rgba(0, 0, 0, 0.12); + border: 1px solid #eee; + border-radius: 8px; + padding: 2rem; + margin: 0 auto; +} + +.inlineCode { + color: #be00ff; + font-size: 16px; + white-space: pre-wrap; +} + +.inlineCode::before, +.inlineCode::after { + content: '`'; +} + +.hr { + border: 0; + border-top: 1px solid #eaeaea; + margin: 1.5rem 0; +} + +.list { + padding-left: 1.5rem; + margin: 1.25rem 0; + list-style-type: none; +} + +.list li { + margin-bottom: 0.75rem; +} + +.list li:before { + content: '-'; + color: #999999; + position: absolute; + margin-left: -1rem; +} From 1509465f25169444454276074397466e1f73447e Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Fri, 24 Jul 2020 23:07:42 -0400 Subject: [PATCH 05/90] Update lockfile --- yarn.lock | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/yarn.lock b/yarn.lock index b154883c4e116..fa0589cc1b5e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4104,7 +4104,7 @@ browserify-zlib@^0.2.0: dependencies: pako "~1.0.5" -browserslist@4.13.0, browserslist@^4.0.0, browserslist@^4.11.1, browserslist@^4.13.0, browserslist@^4.3.6, browserslist@^4.6.4, browserslist@^4.8.3, browserslist@^4.8.5: +browserslist@4.13.0, browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6, browserslist@^4.0.0, browserslist@^4.11.1, browserslist@^4.13.0, browserslist@^4.3.6, browserslist@^4.6.4, browserslist@^4.8.3, browserslist@^4.8.5: version "4.13.0" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.13.0.tgz#42556cba011e1b0a2775b611cba6a8eca18e940d" integrity sha512-MINatJ5ZNrLnQ6blGvePd/QOz9Xtu+Ne+x29iQSCHfkU5BugKVJwZKn/iiL8UbpIpa3JhviKjz+XxMo0m2caFQ== @@ -4114,14 +4114,6 @@ browserslist@4.13.0, browserslist@^4.0.0, browserslist@^4.11.1, browserslist@^4. escalade "^3.0.1" node-releases "^1.1.58" -browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6: - version "1.7.7" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.7.7.tgz#0bd76704258be829b2398bb50e4b62d1a166b0b9" - integrity sha1-C9dnBCWL6CmyOYu1Dkti0aFmsLk= - dependencies: - caniuse-db "^1.0.30000639" - electron-to-chromium "^1.2.7" - browserstack-local@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/browserstack-local/-/browserstack-local-1.4.0.tgz#d979cac056f57b9af159b3bcd7fdc09b4354537c" @@ -4420,21 +4412,11 @@ caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634: version "1.0.30001023" resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001023.tgz#f856f71af16a5a44e81f1fcefc1673912a43da72" -caniuse-db@^1.0.30000639: - version "1.0.30001105" - resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001105.tgz#5cc03239a9d4540b3fa9a1dc8b5e3bda50226e96" - integrity sha512-GZytZn8lOiru/Tw+/X5sFxrFt2uPdSvkxVKzRMJyX20JGwfwOuTiRg5IMVF9II8Lao/7C4YeHR8YnZzpTvYXdQ== - -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001019, caniuse-lite@^1.0.30001020: +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001019, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001093: version "1.0.30001066" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001066.tgz#0a8a58a10108f2b9bf38e7b65c237b12fd9c5f04" integrity sha512-Gfj/WAastBtfxLws0RCh2sDbTK/8rJuSeZMecrSkNGYxPcv7EzblmDGfWQCFEQcSqYE2BRgQiJh8HOD07N5hIw== -caniuse-lite@^1.0.30001093: - version "1.0.30001105" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001105.tgz#d2cb0b31e5cf2f3ce845033b61c5c01566549abf" - integrity sha512-JupOe6+dGMr7E20siZHIZQwYqrllxotAhiaej96y6x00b/48rPt42o+SzOSCPbrpsDWvRja40Hwrj0g0q6LZJg== - capitalize@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/capitalize/-/capitalize-1.0.0.tgz#dc802c580aee101929020d2ca14b4ca8a0ae44be" @@ -6156,11 +6138,6 @@ ejs@^2.6.1: version "2.7.4" resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba" -electron-to-chromium@^1.2.7: - version "1.3.506" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.506.tgz#74bd3e1fb31285b3247f165d4958da74d70ae4e4" - integrity sha512-k0PHtv4gD6KJu1k6lp8pvQOe12uZriOwS2x66Vnxkq0NOBucsNrItOj/ehomvcZ3S4K1ueqUCv+fsLhXBs6Zyw== - electron-to-chromium@^1.3.488: version "1.3.501" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.501.tgz#faa17a2cb0105ee30d5e1ca87eae7d8e85dd3175" From c9836676542e6aed8c833307853489838a8672fe Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Sat, 25 Jul 2020 05:28:18 +0200 Subject: [PATCH 06/90] Link with-polyfills example to updated polyfill docs (#13943) * Link to updated polyfill docs Ref: https://github.com/vercel/next.js/pull/13766 * Update examples/with-polyfills/README.md Co-authored-by: Joe Haddad --- examples/with-polyfills/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/with-polyfills/README.md b/examples/with-polyfills/README.md index 360159375bb82..0ac052ada46a3 100644 --- a/examples/with-polyfills/README.md +++ b/examples/with-polyfills/README.md @@ -1,5 +1,7 @@ # Example app with polyfills +> ❗️ Warning: This example is not the suggested way to add polyfills and is known to cause issues with bundling. See [the browser support docs](https://nextjs.org/docs/basic-features/supported-browsers-features#custom-polyfills) for the correct way to load polyfills. + Next.js supports modern browsers and IE 11. It loads required polyfills automatically. If you need to add custom polyfills, you can follow this example. ## Deploy your own From f22f88fd733518299b9941c2a2e9747b837e47f1 Mon Sep 17 00:00:00 2001 From: James Mosier <2854919+jamesmosier@users.noreply.github.com> Date: Sat, 25 Jul 2020 00:36:43 -0400 Subject: [PATCH 07/90] Always resolve after router.prefetch() (#15448) In development or with an invalid href, `await router.prefetch()` would not resolve the promise. This PR ensures that `await router.prefetch()` always resolves, no matter if it succeeds or not. Fixes: https://github.com/vercel/next.js/issues/15436 Relevant discussion: https://github.com/vercel/next.js/discussions/15431#discussioncomment-41264 --- .../next/next-server/lib/router/router.ts | 29 ++++----- .../build-output/test/index.test.js | 2 +- .../router-prefetch/pages/another-page.js | 3 + .../router-prefetch/pages/index.js | 22 +++++++ .../router-prefetch/test/index.test.js | 65 +++++++++++++++++++ 5 files changed, 105 insertions(+), 16 deletions(-) create mode 100644 test/integration/router-prefetch/pages/another-page.js create mode 100644 test/integration/router-prefetch/pages/index.js create mode 100644 test/integration/router-prefetch/test/index.test.js diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 56e5fa0efda50..1e256d190aac2 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -802,28 +802,27 @@ export default class Router implements BaseRouter { * @param url the href of prefetched page * @param asPath the as path of the prefetched page */ - prefetch( + async prefetch( url: string, asPath: string = url, options: PrefetchOptions = {} ): Promise { - return new Promise((resolve, reject) => { - const parsed = tryParseRelativeUrl(url) + const parsed = tryParseRelativeUrl(url) - if (!parsed) return + if (!parsed) return - const { pathname } = parsed + const { pathname } = parsed - // Prefetch is not supported in development mode because it would trigger on-demand-entries - if (process.env.NODE_ENV !== 'production') { - return - } - const route = removePathTrailingSlash(pathname) - Promise.all([ - this.pageLoader.prefetchData(url, asPath), - this.pageLoader[options.priority ? 'loadPage' : 'prefetch'](route), - ]).then(() => resolve(), reject) - }) + // Prefetch is not supported in development mode because it would trigger on-demand-entries + if (process.env.NODE_ENV !== 'production') { + return + } + + const route = removePathTrailingSlash(pathname) + await Promise.all([ + this.pageLoader.prefetchData(url, asPath), + this.pageLoader[options.priority ? 'loadPage' : 'prefetch'](route), + ]) } async fetchComponent(route: string): Promise { diff --git a/test/integration/build-output/test/index.test.js b/test/integration/build-output/test/index.test.js index fc148ee0066de..fb864ecf43991 100644 --- a/test/integration/build-output/test/index.test.js +++ b/test/integration/build-output/test/index.test.js @@ -104,7 +104,7 @@ describe('Build Output', () => { expect(parseFloat(err404FirstLoad) - 63).toBeLessThanOrEqual(0) expect(err404FirstLoad.endsWith('kB')).toBe(true) - expect(parseFloat(sharedByAll) - 59.2).toBeLessThanOrEqual(0) + expect(parseFloat(sharedByAll) - 59.3).toBeLessThanOrEqual(0) expect(sharedByAll.endsWith('kB')).toBe(true) if (_appSize.endsWith('kB')) { diff --git a/test/integration/router-prefetch/pages/another-page.js b/test/integration/router-prefetch/pages/another-page.js new file mode 100644 index 0000000000000..00812ffc7c611 --- /dev/null +++ b/test/integration/router-prefetch/pages/another-page.js @@ -0,0 +1,3 @@ +export default function AnotherPage() { + return null +} diff --git a/test/integration/router-prefetch/pages/index.js b/test/integration/router-prefetch/pages/index.js new file mode 100644 index 0000000000000..9bedf8703bc64 --- /dev/null +++ b/test/integration/router-prefetch/pages/index.js @@ -0,0 +1,22 @@ +import { useState } from 'react' +import { useRouter } from 'next/router' + +export default function RouterPrefetch() { + const router = useRouter() + const [visible, setVisible] = useState(false) + const handleClick = async () => { + await router.prefetch( + process.env.NODE_ENV === 'development' ? '/another-page' : 'vercel.com' + ) + setVisible(true) + } + + return ( +
+ + {visible &&
visible
} +
+ ) +} diff --git a/test/integration/router-prefetch/test/index.test.js b/test/integration/router-prefetch/test/index.test.js new file mode 100644 index 0000000000000..ba8335c0141bc --- /dev/null +++ b/test/integration/router-prefetch/test/index.test.js @@ -0,0 +1,65 @@ +/* eslint-env jest */ + +import { join } from 'path' +import webdriver from 'next-webdriver' +import { + findPort, + launchApp, + killApp, + nextStart, + nextBuild, +} from 'next-test-utils' + +jest.setTimeout(1000 * 60 * 5) +let app +let appPort +const appDir = join(__dirname, '..') + +const didResolveAfterPrefetch = async () => { + const browser = await webdriver(appPort, '/') + const text = await browser + .elementByCss('#prefetch-button') + .click() + .waitForElementByCss('#hidden-until-click') + .text() + expect(text).toBe('visible') + await browser.close() +} + +describe('Router prefetch', () => { + describe('dev mode', () => { + beforeAll(async () => { + appPort = await findPort() + app = await launchApp(appDir, appPort) + }) + afterAll(() => killApp(app)) + + it('should not prefetch', async () => { + const browser = await webdriver(appPort, '/') + const links = await browser + .elementByCss('#prefetch-button') + .click() + .elementsByCss('link[rel=prefetch]') + + expect(links.length).toBe(0) + await browser.close() + }) + + it('should resolve prefetch promise', async () => { + await didResolveAfterPrefetch() + }) + }) + + describe('production mode', () => { + beforeAll(async () => { + await nextBuild(appDir) + appPort = await findPort() + app = await nextStart(appDir, appPort) + }) + afterAll(() => killApp(app)) + + it('should resolve prefetch promise with invalid href', async () => { + await didResolveAfterPrefetch() + }) + }) +}) From 574fe0b582d5cc1b13663121fd47a3d82deaaa17 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Sat, 25 Jul 2020 07:11:42 +0200 Subject: [PATCH 08/90] Make dynamic routes case-sensitive (#15444) Fixes https://github.com/vercel/next.js/issues/15377 Closes https://github.com/vercel/next.js/pull/15394 --- .../lib/router/utils/route-regex.ts | 4 ++-- .../pages/dynamic/[slug]/route.js | 13 +++++++++++ .../client-navigation/test/index.test.js | 22 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/integration/client-navigation/pages/dynamic/[slug]/route.js diff --git a/packages/next/next-server/lib/router/utils/route-regex.ts b/packages/next/next-server/lib/router/utils/route-regex.ts index b0f74bef7480a..be5c3865e2da7 100644 --- a/packages/next/next-server/lib/router/utils/route-regex.ts +++ b/packages/next/next-server/lib/router/utils/route-regex.ts @@ -107,7 +107,7 @@ export function getRouteRegex( .join('') return { - re: new RegExp(`^${parameterizedRoute}(?:/)?$`, 'i'), + re: new RegExp(`^${parameterizedRoute}(?:/)?$`), groups, routeKeys, namedRegex: `^${namedParameterizedRoute}(?:/)?$`, @@ -115,7 +115,7 @@ export function getRouteRegex( } return { - re: new RegExp(`^${parameterizedRoute}(?:/)?$`, 'i'), + re: new RegExp(`^${parameterizedRoute}(?:/)?$`), groups, } } diff --git a/test/integration/client-navigation/pages/dynamic/[slug]/route.js b/test/integration/client-navigation/pages/dynamic/[slug]/route.js new file mode 100644 index 0000000000000..0f1da367eac78 --- /dev/null +++ b/test/integration/client-navigation/pages/dynamic/[slug]/route.js @@ -0,0 +1,13 @@ +import React from 'react' + +export default class DynamicRoute extends React.Component { + static async getInitialProps({ query = { slug: 'default' } }) { + return { + query, + } + } + + render() { + return

{this.props.query.slug}

+ } +} diff --git a/test/integration/client-navigation/test/index.test.js b/test/integration/client-navigation/test/index.test.js index 482d3d5a9cee5..12d3cf648e93f 100644 --- a/test/integration/client-navigation/test/index.test.js +++ b/test/integration/client-navigation/test/index.test.js @@ -43,6 +43,7 @@ describe('Client Navigation', () => { '/url-prop-override', '/dynamic/ssr', + '/dynamic/[slug]/route', '/nav', '/nav/about', @@ -1002,6 +1003,27 @@ describe('Client Navigation', () => { await browser.close() }) + it('should get url dynamic param', async () => { + const browser = await webdriver( + context.appPort, + '/dynamic/dynamic-part/route' + ) + expect(await browser.elementByCss('p').text()).toBe('dynamic-part') + await browser.close() + }) + + it('should 404 on wrong casing of url dynamic param', async () => { + const browser = await webdriver( + context.appPort, + '/dynamic/dynamic-part/RoUtE' + ) + expect(await browser.elementByCss('h1').text()).toBe('404') + expect(await browser.elementByCss('h2').text()).toBe( + 'This page could not be found.' + ) + await browser.close() + }) + it('should not 404 for /', async () => { const browser = await webdriver(context.appPort, '/nav/about/') const text = await browser.elementByCss('p').text() From ebe4bb1ee4fb79fa78bf7ef5ee23f3c035becf75 Mon Sep 17 00:00:00 2001 From: David Stotijn Date: Sat, 25 Jul 2020 23:16:20 +0200 Subject: [PATCH 09/90] Upgrade Apollo Client to 3.0 in `examples/api-routes-apollo-server-and-client-auth` (#15272) --- .../apollo/client.js | 7 +++---- .../apollo/type-defs.js | 2 +- .../package.json | 9 +-------- .../pages/_app.js | 2 +- .../pages/index.js | 3 +-- .../pages/signin.js | 4 ++-- .../pages/signout.js | 3 +-- .../pages/signup.js | 3 +-- 8 files changed, 11 insertions(+), 22 deletions(-) diff --git a/examples/api-routes-apollo-server-and-client-auth/apollo/client.js b/examples/api-routes-apollo-server-and-client-auth/apollo/client.js index 26ae378500bdc..a25caf6efc987 100644 --- a/examples/api-routes-apollo-server-and-client-auth/apollo/client.js +++ b/examples/api-routes-apollo-server-and-client-auth/apollo/client.js @@ -1,16 +1,15 @@ import { useMemo } from 'react' -import { ApolloClient } from 'apollo-client' -import { InMemoryCache } from 'apollo-cache-inmemory' +import { ApolloClient, InMemoryCache } from '@apollo/client' let apolloClient function createIsomorphLink() { if (typeof window === 'undefined') { - const { SchemaLink } = require('apollo-link-schema') + const { SchemaLink } = require('@apollo/client/link/schema') const { schema } = require('./schema') return new SchemaLink({ schema }) } else { - const { HttpLink } = require('apollo-link-http') + const { HttpLink } = require('@apollo/client/link/http') return new HttpLink({ uri: '/api/graphql', credentials: 'same-origin', diff --git a/examples/api-routes-apollo-server-and-client-auth/apollo/type-defs.js b/examples/api-routes-apollo-server-and-client-auth/apollo/type-defs.js index bea78a284e80b..e9ae131763228 100644 --- a/examples/api-routes-apollo-server-and-client-auth/apollo/type-defs.js +++ b/examples/api-routes-apollo-server-and-client-auth/apollo/type-defs.js @@ -1,4 +1,4 @@ -import gql from 'graphql-tag' +import { gql } from '@apollo/client' export const typeDefs = gql` type User { diff --git a/examples/api-routes-apollo-server-and-client-auth/package.json b/examples/api-routes-apollo-server-and-client-auth/package.json index d0ccec797752a..5eb3bf2467176 100644 --- a/examples/api-routes-apollo-server-and-client-auth/package.json +++ b/examples/api-routes-apollo-server-and-client-auth/package.json @@ -7,18 +7,11 @@ "start": "next start" }, "dependencies": { - "@apollo/react-common": "^3.1.4", - "@apollo/react-hooks": "^3.1.5", + "@apollo/client": "^3.0.2", "@hapi/iron": "6.0.0", - "apollo-cache-inmemory": "^1.6.6", - "apollo-client": "^2.6.10", - "apollo-link-http": "^1.5.17", - "apollo-link-schema": "^1.2.5", "apollo-server-micro": "^2.14.2", - "apollo-utilities": "^1.3.2", "cookie": "^0.4.1", "graphql": "^14.0.2", - "graphql-tag": "^2.10.3", "next": "latest", "prop-types": "^15.6.2", "react": "^16.7.0", diff --git a/examples/api-routes-apollo-server-and-client-auth/pages/_app.js b/examples/api-routes-apollo-server-and-client-auth/pages/_app.js index 0345a86b23ea3..482728ae76e6d 100644 --- a/examples/api-routes-apollo-server-and-client-auth/pages/_app.js +++ b/examples/api-routes-apollo-server-and-client-auth/pages/_app.js @@ -1,4 +1,4 @@ -import { ApolloProvider } from '@apollo/react-hooks' +import { ApolloProvider } from '@apollo/client' import { useApollo } from '../apollo/client' export default function App({ Component, pageProps }) { diff --git a/examples/api-routes-apollo-server-and-client-auth/pages/index.js b/examples/api-routes-apollo-server-and-client-auth/pages/index.js index 11ed53b934dee..34d1186744cfc 100644 --- a/examples/api-routes-apollo-server-and-client-auth/pages/index.js +++ b/examples/api-routes-apollo-server-and-client-auth/pages/index.js @@ -1,8 +1,7 @@ import { useEffect } from 'react' import { useRouter } from 'next/router' import Link from 'next/link' -import gql from 'graphql-tag' -import { useQuery } from '@apollo/react-hooks' +import { gql, useQuery } from '@apollo/client' const ViewerQuery = gql` query ViewerQuery { diff --git a/examples/api-routes-apollo-server-and-client-auth/pages/signin.js b/examples/api-routes-apollo-server-and-client-auth/pages/signin.js index 34bc49d790b26..0e652164cffef 100644 --- a/examples/api-routes-apollo-server-and-client-auth/pages/signin.js +++ b/examples/api-routes-apollo-server-and-client-auth/pages/signin.js @@ -1,8 +1,8 @@ import { useState } from 'react' import { useRouter } from 'next/router' import Link from 'next/link' -import gql from 'graphql-tag' -import { useMutation, useApolloClient } from '@apollo/react-hooks' +import { gql } from '@apollo/client' +import { useMutation, useApolloClient } from '@apollo/client' import { getErrorMessage } from '../lib/form' import Field from '../components/field' diff --git a/examples/api-routes-apollo-server-and-client-auth/pages/signout.js b/examples/api-routes-apollo-server-and-client-auth/pages/signout.js index 11e67f9e99d09..046310db75e77 100644 --- a/examples/api-routes-apollo-server-and-client-auth/pages/signout.js +++ b/examples/api-routes-apollo-server-and-client-auth/pages/signout.js @@ -1,7 +1,6 @@ import { useEffect } from 'react' import { useRouter } from 'next/router' -import { useMutation, useApolloClient } from '@apollo/react-hooks' -import gql from 'graphql-tag' +import { gql, useMutation, useApolloClient } from '@apollo/client' const SignOutMutation = gql` mutation SignOutMutation { diff --git a/examples/api-routes-apollo-server-and-client-auth/pages/signup.js b/examples/api-routes-apollo-server-and-client-auth/pages/signup.js index 70db989347a4f..ce16f159e4c94 100644 --- a/examples/api-routes-apollo-server-and-client-auth/pages/signup.js +++ b/examples/api-routes-apollo-server-and-client-auth/pages/signup.js @@ -1,8 +1,7 @@ import { useState } from 'react' import { useRouter } from 'next/router' import Link from 'next/link' -import gql from 'graphql-tag' -import { useMutation } from '@apollo/react-hooks' +import { gql, useMutation } from '@apollo/client' import { getErrorMessage } from '../lib/form' import Field from '../components/field' From d3955cdf514e7d5032d5929e551796106ede21c7 Mon Sep 17 00:00:00 2001 From: Kaic Bastidas Date: Sat, 25 Jul 2020 22:36:36 -0300 Subject: [PATCH 10/90] TypeScript documentation for _document.tsx (#15386) - Update the [Custom Document page](https://nextjs.org/docs/advanced-features/custom-document) to include an example using `DocumentContext`. --- docs/advanced-features/custom-document.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/advanced-features/custom-document.md b/docs/advanced-features/custom-document.md index a3e02877b2988..1e1605044fcb9 100644 --- a/docs/advanced-features/custom-document.md +++ b/docs/advanced-features/custom-document.md @@ -85,3 +85,21 @@ class MyDocument extends Document { export default MyDocument ``` + +## TypeScript + +You can use the built-in `DocumentContext` type and change the file name to `./pages/_document.tsx` like so: + +```tsx +import Document, { DocumentContext } from 'next/document' + +class MyDocument extends Document { + static async getInitialProps(ctx: DocumentContext) { + const initialProps = await Document.getInitialProps(ctx) + + return initialProps + } +} + +export default MyDocument +``` From 2f50f1f8c948b5766a783adfba5e05d129deb624 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Sun, 26 Jul 2020 06:57:06 +0200 Subject: [PATCH 11/90] Stabilize more tests (#15470) jest retries seem to be masking test failures, like the `auto-export` one (and maybe others). I turned it off for now. The `auto-export` test fails when retries are turned off. the output of this test failure was a bit unhelpful so I also improved it. Many tests have anonymous page functions. --- package.json | 4 +- run-tests.js | 2 +- test/integration/amphtml/pages/only-amp.js | 12 ++- .../auto-export/pages/[post]/[cmnt].js | 6 +- .../auto-export/pages/[post]/index.js | 2 +- .../auto-export/test/index.test.js | 5 +- test/integration/build-indicator/pages/a.js | 4 +- test/integration/build-indicator/pages/b.js | 4 +- .../build-indicator/pages/index.js | 22 +++-- .../test/index.test.js | 38 +++---- .../error-in-error/test/index.test.js | 2 +- test/integration/invalid-href/pages/third.js | 2 +- .../invalid-href/test/index.test.js | 23 ++--- .../query-with-encoding/test/index.test.js | 76 +++++--------- .../scroll-back-restoration/pages/another.js | 18 ++-- .../serverless-runtime-configs/pages/_app.js | 14 +-- test/lib/wd-chain.js | 8 ++ yarn.lock | 98 ++++++++++--------- 18 files changed, 167 insertions(+), 173 deletions(-) diff --git a/package.json b/package.json index 661cb0b35b35d..0e6df064ec978 100644 --- a/package.json +++ b/package.json @@ -112,8 +112,8 @@ "release": "6.0.1", "request-promise-core": "1.1.2", "rimraf": "2.6.3", - "selenium-standalone": "6.17.0", - "selenium-webdriver": "4.0.0-alpha.5", + "selenium-standalone": "6.18.0", + "selenium-webdriver": "4.0.0-alpha.7", "shell-quote": "1.7.2", "styled-components": "5.1.0", "styled-jsx-plugin-postcss": "2.0.1", diff --git a/run-tests.js b/run-tests.js index 5dd3964ab57cd..c37091b807d66 100644 --- a/run-tests.js +++ b/run-tests.js @@ -136,7 +136,7 @@ const TIMINGS_API = `https://next-timings.jjsweb.site/api/timings` { stdio: 'inherit', env: { - JEST_RETRY_TIMES: 2, + JEST_RETRY_TIMES: 0, ...process.env, ...(isAzure ? { diff --git a/test/integration/amphtml/pages/only-amp.js b/test/integration/amphtml/pages/only-amp.js index 653dbecd541d5..41866b35c52c3 100644 --- a/test/integration/amphtml/pages/only-amp.js +++ b/test/integration/amphtml/pages/only-amp.js @@ -1,7 +1,9 @@ export const config = { amp: true } -export default () => ( -
-

Only AMP for me...

-
-) +export default function Page() { + return ( +
+

Only AMP for me...

+
+ ) +} diff --git a/test/integration/auto-export/pages/[post]/[cmnt].js b/test/integration/auto-export/pages/[post]/[cmnt].js index 6c7af1c61ca1a..0982164d25db0 100644 --- a/test/integration/auto-export/pages/[post]/[cmnt].js +++ b/test/integration/auto-export/pages/[post]/[cmnt].js @@ -5,17 +5,17 @@ if (typeof window !== 'undefined') { const origWarn = window.console.warn const origError = window.console.error window.console.warn = function (...args) { - window.caughtWarns.push(1) + window.caughtWarns.push(args) origWarn(...args) } window.console.error = function (...args) { - window.caughtWarns.push(1) + window.caughtWarns.push(args) origError(...args) } window.pathnames = [] } -export default () => { +export default function Page() { if (typeof window !== 'undefined') { window.pathnames.push(window.location.pathname) } diff --git a/test/integration/auto-export/pages/[post]/index.js b/test/integration/auto-export/pages/[post]/index.js index 94492b467fa51..f3aee05d5bb12 100644 --- a/test/integration/auto-export/pages/[post]/index.js +++ b/test/integration/auto-export/pages/[post]/index.js @@ -1,6 +1,6 @@ import { useRouter } from 'next/router' -export default () => { +export default function Page() { const { query } = useRouter() return

post: {query.post}

diff --git a/test/integration/auto-export/test/index.test.js b/test/integration/auto-export/test/index.test.js index 6407b174dbc2e..edaff678a19d5 100644 --- a/test/integration/auto-export/test/index.test.js +++ b/test/integration/auto-export/test/index.test.js @@ -81,9 +81,8 @@ describe('Auto Export', () => { it('should not show hydration warning from mismatching asPath', async () => { const browser = await webdriver(appPort, '/zeit/cmnt-1') - - const numCaught = await browser.eval(`window.caughtWarns.length`) - expect(numCaught).toBe(0) + const caughtWarns = await browser.eval(`window.caughtWarns`) + expect(caughtWarns).toEqual([]) }) }) }) diff --git a/test/integration/build-indicator/pages/a.js b/test/integration/build-indicator/pages/a.js index f87a684893418..45361f18d6af3 100644 --- a/test/integration/build-indicator/pages/a.js +++ b/test/integration/build-indicator/pages/a.js @@ -1 +1,3 @@ -export default () =>

Hello from a

+export default function Page() { + return

Hello from a

+} diff --git a/test/integration/build-indicator/pages/b.js b/test/integration/build-indicator/pages/b.js index 6226f2d97f20a..fb38aab0d4496 100644 --- a/test/integration/build-indicator/pages/b.js +++ b/test/integration/build-indicator/pages/b.js @@ -1 +1,3 @@ -export default () =>

Hello from b

+export default function Page() { + return

Hello from b

+} diff --git a/test/integration/build-indicator/pages/index.js b/test/integration/build-indicator/pages/index.js index 9f630e36e417e..b810ac290b56c 100644 --- a/test/integration/build-indicator/pages/index.js +++ b/test/integration/build-indicator/pages/index.js @@ -1,12 +1,14 @@ import Link from 'next/link' -export default () => ( - <> - - Go to a - - - Go to b - - -) +export default function Page() { + return ( + <> + + Go to a + + + Go to b + + + ) +} diff --git a/test/integration/dynamic-optional-routing/test/index.test.js b/test/integration/dynamic-optional-routing/test/index.test.js index 90dcb70c9e138..c17bd9168bf55 100644 --- a/test/integration/dynamic-optional-routing/test/index.test.js +++ b/test/integration/dynamic-optional-routing/test/index.test.js @@ -10,7 +10,7 @@ import { nextBuild, nextStart, renderViaHTTP, - waitFor, + check, } from 'next-test-utils' import { join } from 'path' @@ -18,6 +18,7 @@ jest.setTimeout(1000 * 60 * 2) let app let appPort +let stderr const appDir = join(__dirname, '../') const DUMMY_PAGE = 'export default () => null' @@ -187,9 +188,10 @@ function runInvalidPagesTests(buildFn) { const invalidRoute = appDir + 'pages/index.js' try { await fs.outputFile(invalidRoute, DUMMY_PAGE, 'utf-8') - const { stderr } = await buildFn(appDir) - await expect(stderr).toMatch( - 'You cannot define a route with the same specificity as a optional catch-all route' + await buildFn(appDir) + await check( + () => stderr, + /You cannot define a route with the same specificity as a optional catch-all route/ ) } finally { await fs.unlink(invalidRoute) @@ -200,9 +202,10 @@ function runInvalidPagesTests(buildFn) { const invalidRoute = appDir + 'pages/nested.js' try { await fs.outputFile(invalidRoute, DUMMY_PAGE, 'utf-8') - const { stderr } = await buildFn(appDir) - await expect(stderr).toMatch( - 'You cannot define a route with the same specificity as a optional catch-all route' + await buildFn(appDir) + await check( + () => stderr, + /You cannot define a route with the same specificity as a optional catch-all route/ ) } finally { await fs.unlink(invalidRoute) @@ -213,8 +216,8 @@ function runInvalidPagesTests(buildFn) { const invalidRoute = appDir + 'pages/nested/[...param].js' try { await fs.outputFile(invalidRoute, DUMMY_PAGE, 'utf-8') - const { stderr } = await buildFn(appDir) - await expect(stderr).toMatch(/You cannot use both .+ at the same level/) + await buildFn(appDir) + await check(() => stderr, /You cannot use both .+ at the same level/) } finally { await fs.unlink(invalidRoute) } @@ -224,9 +227,10 @@ function runInvalidPagesTests(buildFn) { const invalidRoute = appDir + 'pages/invalid/[[param]].js' try { await fs.outputFile(invalidRoute, DUMMY_PAGE, 'utf-8') - const { stderr } = await buildFn(appDir) - await expect(stderr).toMatch( - 'Optional route parameters are not yet supported' + await buildFn(appDir) + await check( + () => stderr, + /Optional route parameters are not yet supported/ ) } finally { await fs.unlink(invalidRoute) @@ -245,14 +249,12 @@ describe('Dynamic Optional Routing', () => { runTests() runInvalidPagesTests(async (appDir) => { - let stderr = '' + stderr = '' await launchApp(appDir, await findPort(), { onStderr: (msg) => { stderr += msg }, }) - await waitFor(1000) - return { stderr } }) }) @@ -272,9 +274,9 @@ describe('Dynamic Optional Routing', () => { runTests() - runInvalidPagesTests(async (appDir) => - nextBuild(appDir, [], { stderr: true }) - ) + runInvalidPagesTests(async (appDir) => { + ;({ stderr } = await nextBuild(appDir, [], { stderr: true })) + }) it('should fail to build when param is not explicitly defined', async () => { const invalidRoute = appDir + 'pages/invalid/[[...slug]].js' diff --git a/test/integration/error-in-error/test/index.test.js b/test/integration/error-in-error/test/index.test.js index 2b4bee2991071..4443aec17bc33 100644 --- a/test/integration/error-in-error/test/index.test.js +++ b/test/integration/error-in-error/test/index.test.js @@ -31,7 +31,7 @@ describe('Handles an Error in _error', () => { it('Handles error during client transition', async () => { const browser = await webdriver(port, '/') - await browser.elementByCss('a').click() + await browser.waitForElementByCss('a').click() await waitFor(1000) const html = await browser.eval('document.body.innerHTML') expect(html).toMatch(/internal server error/i) diff --git a/test/integration/invalid-href/pages/third.js b/test/integration/invalid-href/pages/third.js index 12daa43427166..509367eab393d 100644 --- a/test/integration/invalid-href/pages/third.js +++ b/test/integration/invalid-href/pages/third.js @@ -3,7 +3,7 @@ import { useState } from 'react' const invalidLink = 'https://vercel.com/' -export default () => { +export default function Page() { const { query, ...router } = useRouter() const [isDone, setIsDone] = useState(false) const { method = 'push' } = query diff --git a/test/integration/invalid-href/test/index.test.js b/test/integration/invalid-href/test/index.test.js index b612671d88a38..cb95ed64945cd 100644 --- a/test/integration/invalid-href/test/index.test.js +++ b/test/integration/invalid-href/test/index.test.js @@ -30,24 +30,18 @@ jest.retryTimes(0) const showsError = async (pathname, regex, click = false, isWarn = false) => { const browser = await webdriver(appPort, pathname) try { + // wait for page to be built and navigated to + await browser.waitForElementByCss('#click-me') if (isWarn) { await browser.eval(`(function() { window.warnLogs = [] var origWarn = window.console.warn - window.console.warn = function() { - var warnStr = '' - for (var i = 0; i < arguments.length; i++) { - if (i > 0) warnStr += ' '; - warnStr += arguments[i] - } - window.warnLogs.push(warnStr) - origWarn.apply(undefined, arguments) + window.console.warn = (...args) => { + window.warnLogs.push(args.join(' ')) + origWarn.apply(window.console, args) } })()`) } - // wait for page to be built and navigated to - await waitFor(3000) - await browser.waitForElementByCss('#click-me') if (click) { await browser.elementByCss('#click-me').click() await waitFor(500) @@ -70,6 +64,11 @@ const showsError = async (pathname, regex, click = false, isWarn = false) => { const noError = async (pathname, click = false) => { const browser = await webdriver(appPort, '/') try { + await check(async () => { + const appReady = await browser.eval('!!window.next.router') + console.log('app ready: ', appReady) + return appReady ? 'ready' : 'nope' + }, 'ready') await browser.eval(`(function() { window.caughtErrors = [] window.addEventListener('error', function (error) { @@ -80,8 +79,6 @@ const noError = async (pathname, click = false) => { }) window.next.router.replace('${pathname}') })()`) - // wait for page to be built and navigated to - await waitFor(3000) await browser.waitForElementByCss('#click-me') if (click) { await browser.elementByCss('#click-me').click() diff --git a/test/integration/query-with-encoding/test/index.test.js b/test/integration/query-with-encoding/test/index.test.js index 237a054c152a1..3b25cc0e53016 100644 --- a/test/integration/query-with-encoding/test/index.test.js +++ b/test/integration/query-with-encoding/test/index.test.js @@ -1,12 +1,6 @@ /* eslint-env jest */ -import { - nextBuild, - nextServer, - startApp, - stopApp, - waitFor, -} from 'next-test-utils' +import { nextBuild, nextServer, startApp, stopApp } from 'next-test-utils' import webdriver from 'next-webdriver' import { join } from 'path' @@ -46,12 +40,11 @@ describe('Query String with Encoding', () => { it('should have correct query on Router#push', async () => { const browser = await webdriver(appPort, '/') try { - await waitFor(2000) + await browser.waitForCondition('!!window.next.router') await browser.eval( `window.next.router.push({pathname:'/',query:{abc:'def\\n'}})` ) - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"abc":"def\\n"}') } finally { await browser.close() @@ -61,10 +54,8 @@ describe('Query String with Encoding', () => { it('should have correct query on simple client-side ', async () => { const browser = await webdriver(appPort, '/newline') try { - await waitFor(2000) - await browser.elementByCss('#hello-lf').click() - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + await browser.waitForElementByCss('#hello-lf').click() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"another":"hello\\n"}') } finally { await browser.close() @@ -74,10 +65,8 @@ describe('Query String with Encoding', () => { it('should have correct query on complex client-side ', async () => { const browser = await webdriver(appPort, '/newline') try { - await waitFor(2000) - await browser.elementByCss('#hello-complex').click() - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + await browser.waitForElementByCss('#hello-complex').click() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"complex":"yes\\n"}') } finally { await browser.close() @@ -99,12 +88,11 @@ describe('Query String with Encoding', () => { it('should have correct query on Router#push', async () => { const browser = await webdriver(appPort, '/') try { - await waitFor(2000) + await browser.waitForCondition('!!window.next.router') await browser.eval( `window.next.router.push({pathname:'/',query:{abc:'def '}})` ) - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"abc":"def "}') } finally { await browser.close() @@ -114,10 +102,8 @@ describe('Query String with Encoding', () => { it('should have correct query on simple client-side ', async () => { const browser = await webdriver(appPort, '/space') try { - await waitFor(2000) - await browser.elementByCss('#hello-space').click() - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + await browser.waitForElementByCss('#hello-space').click() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"another":"hello "}') } finally { await browser.close() @@ -127,10 +113,8 @@ describe('Query String with Encoding', () => { it('should have correct query on complex client-side ', async () => { const browser = await webdriver(appPort, '/space') try { - await waitFor(2000) - await browser.elementByCss('#hello-complex').click() - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + await browser.waitForElementByCss('#hello-complex').click() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"complex":"yes "}') } finally { await browser.close() @@ -152,12 +136,11 @@ describe('Query String with Encoding', () => { it('should have correct query on Router#push', async () => { const browser = await webdriver(appPort, '/') try { - await waitFor(2000) + await browser.waitForCondition('!!window.next.router') await browser.eval( `window.next.router.push({pathname:'/',query:{abc:'def%'}})` ) - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"abc":"def%"}') } finally { await browser.close() @@ -167,10 +150,8 @@ describe('Query String with Encoding', () => { it('should have correct query on simple client-side ', async () => { const browser = await webdriver(appPort, '/percent') try { - await waitFor(2000) - await browser.elementByCss('#hello-percent').click() - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + await browser.waitForElementByCss('#hello-percent').click() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"another":"hello%"}') } finally { await browser.close() @@ -180,10 +161,8 @@ describe('Query String with Encoding', () => { it('should have correct query on complex client-side ', async () => { const browser = await webdriver(appPort, '/percent') try { - await waitFor(2000) - await browser.elementByCss('#hello-complex').click() - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + await browser.waitForElementByCss('#hello-complex').click() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"complex":"yes%"}') } finally { await browser.close() @@ -205,12 +184,11 @@ describe('Query String with Encoding', () => { it('should have correct query on Router#push', async () => { const browser = await webdriver(appPort, '/') try { - await waitFor(2000) + await browser.waitForCondition('!!window.next.router') await browser.eval( `window.next.router.push({pathname:'/',query:{abc:'def+'}})` ) - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"abc":"def+"}') } finally { await browser.close() @@ -220,10 +198,8 @@ describe('Query String with Encoding', () => { it('should have correct query on simple client-side ', async () => { const browser = await webdriver(appPort, '/plus') try { - await waitFor(2000) - await browser.elementByCss('#hello-plus').click() - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + await browser.waitForElementByCss('#hello-plus').click() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"another":"hello+"}') } finally { await browser.close() @@ -233,10 +209,8 @@ describe('Query String with Encoding', () => { it('should have correct query on complex client-side ', async () => { const browser = await webdriver(appPort, '/plus') try { - await waitFor(2000) - await browser.elementByCss('#hello-complex').click() - await waitFor(1000) - const text = await browser.elementByCss('#query-content').text() + await browser.waitForElementByCss('#hello-complex').click() + const text = await browser.waitForElementByCss('#query-content').text() expect(text).toBe('{"complex":"yes+"}') } finally { await browser.close() diff --git a/test/integration/scroll-back-restoration/pages/another.js b/test/integration/scroll-back-restoration/pages/another.js index a37308e7d8779..340b4403e3d80 100644 --- a/test/integration/scroll-back-restoration/pages/another.js +++ b/test/integration/scroll-back-restoration/pages/another.js @@ -1,10 +1,12 @@ import Link from 'next/link' -export default () => ( - <> -

hi from another

- - to index - - -) +export default function Page() { + return ( + <> +

hi from another

+ + to index + + + ) +} diff --git a/test/integration/serverless-runtime-configs/pages/_app.js b/test/integration/serverless-runtime-configs/pages/_app.js index 9d7f9f03f9d3b..de64911781767 100644 --- a/test/integration/serverless-runtime-configs/pages/_app.js +++ b/test/integration/serverless-runtime-configs/pages/_app.js @@ -2,9 +2,11 @@ import getConfig from 'next/config' const config = getConfig() -export default ({ Component, pageProps }) => ( - <> -

{JSON.stringify(config)}

- - -) +export default function App({ Component, pageProps }) { + return ( + <> +

{JSON.stringify(config)}

+ + + ) +} diff --git a/test/lib/wd-chain.js b/test/lib/wd-chain.js index fc807464183a7..af562bf313771 100644 --- a/test/lib/wd-chain.js +++ b/test/lib/wd-chain.js @@ -92,6 +92,14 @@ export default class Chain { ) } + waitForCondition(condition) { + return this.updateChain(() => + this.browser.wait(async (driver) => { + return driver.executeScript('return ' + condition).catch(() => false) + }) + ) + } + eval(snippet) { if (typeof snippet === 'string' && !snippet.startsWith('return')) { snippet = `return ${snippet}` diff --git a/yarn.lock b/yarn.lock index fa0589cc1b5e3..8668aa6810881 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3917,19 +3917,21 @@ bindings@^1.5.0: dependencies: file-uri-to-path "1.0.0" -bl@^2.2.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/bl/-/bl-2.2.0.tgz#e1a574cdf528e4053019bb800b041c0ac88da493" - dependencies: - readable-stream "^2.3.5" - safe-buffer "^5.1.1" - bl@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/bl/-/bl-3.0.0.tgz#3611ec00579fd18561754360b21e9f784500ff88" dependencies: readable-stream "^3.0.1" +bl@^4.0.1: + version "4.0.2" + resolved "https://registry.yarnpkg.com/bl/-/bl-4.0.2.tgz#52b71e9088515d0606d9dd9cc7aa48dc1f98e73a" + integrity sha512-j4OH8f6Qg2bGuWfRiltT2HYGx0e1QcBTrK9KAHNMwMZdQnDZFk0ZSYIpADjYCB3U12nicC5tVJwSIhwOWjb4RQ== + dependencies: + buffer "^5.5.0" + inherits "^2.0.4" + readable-stream "^3.4.0" + block-stream@*: version "0.0.9" resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a" @@ -4177,6 +4179,14 @@ buffer@^4.3.0: ieee754 "^1.1.4" isarray "^1.0.0" +buffer@^5.5.0: + version "5.6.0" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.6.0.tgz#a31749dc7d81d84db08abf937b6b8c4033f62786" + integrity sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw== + dependencies: + base64-js "^1.0.2" + ieee754 "^1.1.4" + builtin-modules@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484" @@ -9509,9 +9519,10 @@ jsx-ast-utils@^2.2.3: array-includes "^3.0.3" object.assign "^4.1.0" -jszip@^3.1.5: - version "3.2.2" - resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.2.2.tgz#b143816df7e106a9597a94c77493385adca5bd1d" +jszip@^3.2.2: + version "3.5.0" + resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.5.0.tgz#b4fd1f368245346658e781fec9675802489e15f6" + integrity sha512-WRtu7TPCmYePR1nazfrtuF216cIVon/3GWOvHS9QR5bIwSbnxtdpma6un3jyGGNhHsKCSzn5Ypk+EkDRvTGiFA== dependencies: lie "~3.3.0" pako "~1.0.2" @@ -13267,7 +13278,7 @@ read@1, read@~1.0.1: string_decoder "^1.1.1" util-deprecate "^1.0.1" -readable-stream@^3.6.0: +readable-stream@^3.4.0, readable-stream@^3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== @@ -13638,9 +13649,9 @@ request@2.85.0: tunnel-agent "^0.6.0" uuid "^3.1.0" -request@2.88.0, request@^2.86.0, request@^2.87.0, request@^2.88.0: - version "2.88.0" - resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" +request@2.88.2, request@^2.88.2: + version "2.88.2" + resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3" dependencies: aws-sign2 "~0.7.0" aws4 "^1.8.0" @@ -13649,7 +13660,7 @@ request@2.88.0, request@^2.86.0, request@^2.87.0, request@^2.88.0: extend "~3.0.2" forever-agent "~0.6.1" form-data "~2.3.2" - har-validator "~5.1.0" + har-validator "~5.1.3" http-signature "~1.2.0" is-typedarray "~1.0.0" isstream "~0.1.2" @@ -13659,13 +13670,13 @@ request@2.88.0, request@^2.86.0, request@^2.87.0, request@^2.88.0: performance-now "^2.1.0" qs "~6.5.2" safe-buffer "^5.1.2" - tough-cookie "~2.4.3" + tough-cookie "~2.5.0" tunnel-agent "^0.6.0" uuid "^3.3.2" -request@^2.88.2: - version "2.88.2" - resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3" +request@^2.86.0, request@^2.87.0, request@^2.88.0: + version "2.88.0" + resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" dependencies: aws-sign2 "~0.7.0" aws4 "^1.8.0" @@ -13674,7 +13685,7 @@ request@^2.88.2: extend "~3.0.2" forever-agent "~0.6.1" form-data "~2.3.2" - har-validator "~5.1.3" + har-validator "~5.1.0" http-signature "~1.2.0" is-typedarray "~1.0.0" isstream "~0.1.2" @@ -13684,7 +13695,7 @@ request@^2.88.2: performance-now "^2.1.0" qs "~6.5.2" safe-buffer "^5.1.2" - tough-cookie "~2.5.0" + tough-cookie "~2.4.3" tunnel-agent "^0.6.0" uuid "^3.3.2" @@ -14122,7 +14133,7 @@ sass-loader@8.0.2: schema-utils "^2.6.1" semver "^6.3.0" -sax@>=0.6.0, sax@^1.2.4, sax@~1.2.1, sax@~1.2.4: +sax@^1.2.4, sax@~1.2.1, sax@~1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" @@ -14169,9 +14180,10 @@ scss-tokenizer@^0.2.3: js-base64 "^2.1.8" source-map "^0.4.2" -selenium-standalone@6.17.0: - version "6.17.0" - resolved "https://registry.yarnpkg.com/selenium-standalone/-/selenium-standalone-6.17.0.tgz#0f24b691836205ee9bc3d7a6f207ebcb28170cd9" +selenium-standalone@6.18.0: + version "6.18.0" + resolved "https://registry.yarnpkg.com/selenium-standalone/-/selenium-standalone-6.18.0.tgz#011e0672b1b86893f77244a86ddea1b6baadfb87" + integrity sha512-JfuJZoPPhnRuOXPM60wElwzzf3f92VkHa/W1f0QLBxSMKy6K/CTICfPo75aSro8X5wf6pa2npjD/CQmZjUqsoA== dependencies: async "^2.6.2" commander "^2.19.0" @@ -14181,20 +14193,20 @@ selenium-standalone@6.17.0: minimist "^1.2.0" mkdirp "^0.5.1" progress "2.0.3" - request "2.88.0" - tar-stream "2.0.0" + request "2.88.2" + tar-stream "2.1.3" urijs "^1.19.1" which "^1.3.1" yauzl "^2.10.0" -selenium-webdriver@4.0.0-alpha.5: - version "4.0.0-alpha.5" - resolved "https://registry.yarnpkg.com/selenium-webdriver/-/selenium-webdriver-4.0.0-alpha.5.tgz#e4683b3dbf827d70df09a7e43bf02ebad20fa7c1" +selenium-webdriver@4.0.0-alpha.7: + version "4.0.0-alpha.7" + resolved "https://registry.yarnpkg.com/selenium-webdriver/-/selenium-webdriver-4.0.0-alpha.7.tgz#e3879d8457fd7ad8e4424094b7dc0540d99e6797" + integrity sha512-D4qnTsyTr91jT8f7MfN+OwY0IlU5+5FmlO5xlgRUV6hDEV8JyYx2NerdTEqDDkNq7RZDYc4VoPALk8l578RBHw== dependencies: - jszip "^3.1.5" - rimraf "^2.6.3" + jszip "^3.2.2" + rimraf "^2.7.1" tmp "0.0.30" - xml2js "^0.4.19" semver-compare@^1.0.0: version "1.0.0" @@ -15087,11 +15099,12 @@ tar-fs@^2.0.0: pump "^3.0.0" tar-stream "^2.0.0" -tar-stream@2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-2.0.0.tgz#8829bbf83067bc0288a9089db49c56be395b6aea" +tar-stream@2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-2.1.3.tgz#1e2022559221b7866161660f118255e20fa79e41" + integrity sha512-Z9yri56Dih8IaK8gncVPx4Wqt86NDmQTSh49XLZgjWpGZL9GK9HKParS2scqHCC4w6X9Gh2jwaU45V47XTKwVA== dependencies: - bl "^2.2.0" + bl "^4.0.1" end-of-stream "^1.4.1" fs-constants "^1.0.0" inherits "^2.0.3" @@ -16325,17 +16338,6 @@ xml-name-validator@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a" -xml2js@^0.4.19: - version "0.4.23" - resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.23.tgz#a0c69516752421eb2ac758ee4d4ccf58843eac66" - dependencies: - sax ">=0.6.0" - xmlbuilder "~11.0.0" - -xmlbuilder@~11.0.0: - version "11.0.1" - resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3" - xmlchars@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb" From f98e38c9b634b85e6679e7b5f953a9d98074cfc3 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 26 Jul 2020 16:51:11 +0200 Subject: [PATCH 12/90] Add static tweet link (#15493) --- docs/basic-features/data-fetching.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/basic-features/data-fetching.md b/docs/basic-features/data-fetching.md index 887a3a1e94839..b09a724798835 100644 --- a/docs/basic-features/data-fetching.md +++ b/docs/basic-features/data-fetching.md @@ -326,6 +326,13 @@ export default Post #### `fallback: true` +
+ Examples + +
+ If `fallback` is `true`, then the behavior of `getStaticProps` changes: - The paths returned from `getStaticPaths` will be rendered to HTML at build time. From e837c2253db07124ccc5c8cd79070d3c05fba824 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Sun, 26 Jul 2020 23:56:36 -0400 Subject: [PATCH 13/90] Upgrade cssnano-simple dependency (#15488) --- packages/next/package.json | 2 +- .../css-customization/test/index.test.js | 10 ++-- .../css-features/test/index.test.js | 2 +- .../next-issue-15468/pages/_app.js | 12 +++++ .../next-issue-15468/pages/index.js | 8 ++++ .../next-issue-15468/styles/global.css | 16 +++++++ test/integration/css/test/index.test.js | 48 +++++++++++++++++-- test/integration/scss/test/index.test.js | 8 ++-- yarn.lock | 18 +++---- 9 files changed, 100 insertions(+), 24 deletions(-) create mode 100644 test/integration/css-fixtures/next-issue-15468/pages/_app.js create mode 100644 test/integration/css-fixtures/next-issue-15468/pages/index.js create mode 100644 test/integration/css-fixtures/next-issue-15468/styles/global.css diff --git a/packages/next/package.json b/packages/next/package.json index 3004bc9753eba..b35b4f3d0d4bc 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -85,7 +85,7 @@ "cacache": "13.0.1", "chokidar": "2.1.8", "css-loader": "3.5.3", - "cssnano-simple": "1.0.4", + "cssnano-simple": "1.0.5", "find-cache-dir": "3.3.1", "jest-worker": "24.9.0", "loader-utils": "2.0.0", diff --git a/test/integration/css-customization/test/index.test.js b/test/integration/css-customization/test/index.test.js index 91dadc829310e..015d5bfd20dcb 100644 --- a/test/integration/css-customization/test/index.test.js +++ b/test/integration/css-customization/test/index.test.js @@ -33,7 +33,7 @@ describe('CSS Customization', () => { expect(cssFiles.length).toBe(1) const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot( - `"@media (480px <= width < 768px){::placeholder{color:green}}.video{max-height:300px;max-width:400px}"` + `"@media (480px <= width < 768px){::placeholder{color:green}}.video{max-width:400px;max-height:300px}"` ) // Contains a source map @@ -54,7 +54,7 @@ describe('CSS Customization', () => { const { version, mappings, sourcesContent } = JSON.parse(cssMapContent) expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(` Object { - "mappings": "AACA,gCACE,cACE,WACF,CACF,CAGA,OACE,gBAA0B,CAA1B,eACF", + "mappings": "AACA,gCACE,cACE,WACF,CACF,CAGA,OACE,eAA0B,CAA1B,gBACF", "sourcesContent": Array [ "/* this should pass through untransformed */ @media (480px <= width < 768px) { @@ -132,7 +132,7 @@ describe('CSS Customization Array', () => { expect(cssFiles.length).toBe(1) const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot( - `"@media (480px <= width < 768px){a:before{content:\\"\\"}::placeholder{color:green}}.video{max-height:4800px;max-height:300rem;max-width:6400px;max-width:400rem}"` + `"@media (480px <= width < 768px){a:before{content:\\"\\"}::placeholder{color:green}}.video{max-width:6400px;max-height:4800px;max-width:400rem;max-height:300rem}"` ) // Contains a source map @@ -153,7 +153,7 @@ describe('CSS Customization Array', () => { const { version, mappings, sourcesContent } = JSON.parse(cssMapContent) expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(` Object { - "mappings": "AACA,gCACE,SACE,UACF,CACA,cACE,WACF,CACF,CAGA,OACE,iBAA4B,CAA5B,iBAA4B,CAA5B,gBAA4B,CAA5B,gBACF", + "mappings": "AACA,gCACE,SACE,UACF,CACA,cACE,WACF,CACF,CAGA,OACE,gBAA4B,CAA5B,iBAA4B,CAA5B,gBAA4B,CAA5B,iBACF", "sourcesContent": Array [ "/* this should pass through untransformed */ @media (480px <= width < 768px) { @@ -213,7 +213,7 @@ describe('Bad CSS Customization', () => { expect(cssFiles.length).toBe(1) const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot( - `".video{max-height:300px;max-width:400px}"` + `".video{max-width:400px;max-height:300px}"` ) // Contains a source map diff --git a/test/integration/css-features/test/index.test.js b/test/integration/css-features/test/index.test.js index de03cfea945fe..2fc3055c4112e 100644 --- a/test/integration/css-features/test/index.test.js +++ b/test/integration/css-features/test/index.test.js @@ -35,7 +35,7 @@ describe('Browserslist: Old', () => { const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot( - `"a{clip:auto;grid-column-gap:normal;all:initial;-webkit-animation:none 0s ease 0s 1 normal none running;animation:none 0s ease 0s 1 normal none running;-webkit-backface-visibility:visible;backface-visibility:visible;background:transparent none repeat 0 0/auto auto padding-box border-box scroll;border:none;border-collapse:separate;-webkit-border-image:none;border-image:none;-webkit-border-radius:0;border-radius:0;border-spacing:0;bottom:auto;-webkit-box-shadow:none;box-shadow:none;-webkit-box-sizing:content-box;box-sizing:content-box;caption-side:top;clear:none;color:#000;column-fill:balance;-webkit-columns:auto;-webkit-column-count:auto;-webkit-column-fill:balance;-webkit-column-gap:normal;column-gap:normal;-webkit-column-rule:medium none currentColor;column-rule:medium none currentColor;-webkit-column-span:1;column-span:1;-webkit-column-width:auto;columns:auto;content:normal;counter-increment:none;counter-reset:none;cursor:auto;direction:ltr;display:inline;empty-cells:show;float:none;font-family:serif;-webkit-font-feature-settings:normal;font-feature-settings:normal;font-size:medium;font-stretch:normal;font-style:normal;font-variant:normal;font-weight:400;height:auto;-ms-hyphens:none;hyphens:none;left:auto;letter-spacing:normal;line-height:normal;list-style:disc none outside;margin:0;max-height:none;max-width:none;min-height:0;min-width:0;opacity:1;orphans:2;outline:medium none invert;overflow:visible;overflow-x:visible;overflow-y:visible;padding:0;page-break-after:auto;page-break-before:auto;page-break-inside:auto;-webkit-perspective:none;perspective:none;-webkit-perspective-origin:50% 50%;perspective-origin:50% 50%;position:static;right:auto;tab-size:8;table-layout:auto;text-align:left;text-align-last:auto;text-decoration:none;text-indent:0;text-shadow:none;text-transform:none;top:auto;-webkit-transform:none;transform:none;-webkit-transform-origin:50% 50% 0;transform-origin:50% 50% 0;-webkit-transform-style:flat;transform-style:flat;-webkit-transition:none 0s ease 0s;transition:none 0s ease 0s;unicode-bidi:normal;vertical-align:baseline;visibility:visible;white-space:normal;widows:2;width:auto;word-spacing:normal;z-index:auto}@media (-webkit-min-device-pixel-ratio:2),(min-resolution:2dppx){.image{background-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)}}"` + `"a{-webkit-animation:none 0s ease 0s 1 normal none running;animation:none 0s ease 0s 1 normal none running;-webkit-backface-visibility:visible;backface-visibility:visible;background:transparent none repeat 0 0/auto auto padding-box border-box scroll;border:none;border-collapse:separate;-webkit-border-image:none;border-image:none;-webkit-border-radius:0;border-radius:0;border-spacing:0;bottom:auto;-webkit-box-shadow:none;box-shadow:none;-webkit-box-sizing:content-box;box-sizing:content-box;caption-side:top;clear:none;clip:auto;color:#000;-webkit-columns:auto;-webkit-column-count:auto;-webkit-column-fill:balance;column-fill:balance;grid-column-gap:normal;-webkit-column-gap:normal;column-gap:normal;-webkit-column-rule:medium none currentColor;column-rule:medium none currentColor;-webkit-column-span:1;column-span:1;-webkit-column-width:auto;columns:auto;content:normal;counter-increment:none;counter-reset:none;cursor:auto;direction:ltr;display:inline;empty-cells:show;float:none;font-family:serif;font-size:medium;font-style:normal;-webkit-font-feature-settings:normal;font-feature-settings:normal;font-variant:normal;font-weight:400;font-stretch:normal;line-height:normal;height:auto;-ms-hyphens:none;hyphens:none;left:auto;letter-spacing:normal;list-style:disc none outside;margin:0;max-height:none;max-width:none;min-height:0;min-width:0;opacity:1;orphans:2;outline:medium none invert;overflow:visible;overflow-x:visible;overflow-y:visible;padding:0;page-break-after:auto;page-break-before:auto;page-break-inside:auto;-webkit-perspective:none;perspective:none;-webkit-perspective-origin:50% 50%;perspective-origin:50% 50%;position:static;right:auto;tab-size:8;table-layout:auto;text-align:left;text-align-last:auto;text-decoration:none;text-indent:0;text-shadow:none;text-transform:none;top:auto;-webkit-transform:none;transform:none;-webkit-transform-origin:50% 50% 0;transform-origin:50% 50% 0;-webkit-transform-style:flat;transform-style:flat;-webkit-transition:none 0s ease 0s;transition:none 0s ease 0s;unicode-bidi:normal;vertical-align:baseline;visibility:visible;white-space:normal;widows:2;width:auto;word-spacing:normal;z-index:auto;all:initial}@media (-webkit-min-device-pixel-ratio:2),(min-resolution:2dppx){.image{background-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)}}"` ) }) }) diff --git a/test/integration/css-fixtures/next-issue-15468/pages/_app.js b/test/integration/css-fixtures/next-issue-15468/pages/_app.js new file mode 100644 index 0000000000000..e8acb08dfbe7f --- /dev/null +++ b/test/integration/css-fixtures/next-issue-15468/pages/_app.js @@ -0,0 +1,12 @@ +import App from 'next/app' +import React from 'react' +import '../styles/global.css' + +class MyApp extends App { + render() { + const { Component, pageProps } = this.props + return + } +} + +export default MyApp diff --git a/test/integration/css-fixtures/next-issue-15468/pages/index.js b/test/integration/css-fixtures/next-issue-15468/pages/index.js new file mode 100644 index 0000000000000..4bcfb2a059744 --- /dev/null +++ b/test/integration/css-fixtures/next-issue-15468/pages/index.js @@ -0,0 +1,8 @@ +export default function Home() { + return ( +
+
Hello
+
Hello
+
+ ) +} diff --git a/test/integration/css-fixtures/next-issue-15468/styles/global.css b/test/integration/css-fixtures/next-issue-15468/styles/global.css new file mode 100644 index 0000000000000..b5dd37a902c21 --- /dev/null +++ b/test/integration/css-fixtures/next-issue-15468/styles/global.css @@ -0,0 +1,16 @@ +:root { + --blk: #000000; + --five: 5px; +} + +.test1 { + border: 1px solid var(--blk); + border-radius: var(--five); + border-width: 0; +} + +.test2 { + border: 0px solid var(--blk); + border-radius: var(--five); + border-width: 5px; +} diff --git a/test/integration/css/test/index.test.js b/test/integration/css/test/index.test.js index 098057079228a..19c2d238e2dd5 100644 --- a/test/integration/css/test/index.test.js +++ b/test/integration/css/test/index.test.js @@ -132,7 +132,7 @@ describe('CSS Support', () => { expect( cssContent.replace(/\/\*.*?\*\//g, '').trim() ).toMatchInlineSnapshot( - `".red-text{color:purple;color:red;font-weight:bolder}.blue-text{color:orange;color:#00f;font-weight:bolder}"` + `".red-text{color:purple;font-weight:bolder;color:red}.blue-text{color:orange;font-weight:bolder;color:#00f}"` ) }) }) @@ -564,7 +564,7 @@ describe('CSS Support', () => { expect(cssFiles.length).toBe(1) const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatch( - /^\.red-text\{background-image:url\(\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\);color:red\}\.blue-text\{background-image:url\(\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:orange;color:#00f;font-weight:bolder\}$/ + /^\.red-text\{color:red;background-image:url\(\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\)\}\.blue-text\{color:orange;font-weight:bolder;background-image:url\(\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:#00f\}$/ ) const mediaFiles = await readdir(mediaFolder) @@ -610,7 +610,7 @@ describe('CSS Support', () => { expect(cssFiles.length).toBe(1) const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatch( - /^\.red-text\{background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\);color:red\}\.blue-text\{background-image:url\(\/foo\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:orange;color:#00f;font-weight:bolder\}$/ + /^\.red-text\{color:red;background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\)\}\.blue-text\{color:orange;font-weight:bolder;background-image:url\(\/foo\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:#00f\}$/ ) const mediaFiles = await readdir(mediaFolder) @@ -656,7 +656,7 @@ describe('CSS Support', () => { expect(cssFiles.length).toBe(1) const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatch( - /^\.red-text\{background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\);color:red\}\.blue-text\{background-image:url\(\/foo\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:orange;color:#00f;font-weight:bolder\}$/ + /^\.red-text\{color:red;background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\)\}\.blue-text\{color:orange;font-weight:bolder;background-image:url\(\/foo\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:#00f\}$/ ) const mediaFiles = await readdir(mediaFolder) @@ -924,6 +924,46 @@ describe('CSS Support', () => { }) }) + // https://github.com/vercel/next.js/issues/15468 + describe('CSS Property Ordering', () => { + const appDir = join(fixturesDir, 'next-issue-15468') + + let appPort + let app + let stdout + let code + beforeAll(async () => { + await remove(join(appDir, '.next')) + ;({ code, stdout } = await nextBuild(appDir, [], { + stdout: true, + })) + appPort = await findPort() + app = await nextStart(appDir, appPort) + }) + afterAll(async () => { + await killApp(app) + }) + + it('should have compiled successfully', () => { + expect(code).toBe(0) + expect(stdout).toMatch(/Compiled successfully/) + }) + + it('should have the border width (property ordering)', async () => { + const browser = await webdriver(appPort, '/') + + const width1 = await browser.eval( + `window.getComputedStyle(document.querySelector('.test1')).borderWidth` + ) + expect(width1).toMatchInlineSnapshot(`"0px"`) + + const width2 = await browser.eval( + `window.getComputedStyle(document.querySelector('.test2')).borderWidth` + ) + expect(width2).toMatchInlineSnapshot(`"5px"`) + }) + }) + describe('Basic Tailwind CSS', () => { const appDir = join(fixturesDir, 'with-tailwindcss') diff --git a/test/integration/scss/test/index.test.js b/test/integration/scss/test/index.test.js index dc6d1e1fea481..1993f83d9b8a7 100644 --- a/test/integration/scss/test/index.test.js +++ b/test/integration/scss/test/index.test.js @@ -217,7 +217,7 @@ describe('SCSS Support', () => { expect( cssContent.replace(/\/\*.*?\*\//g, '').trim() ).toMatchInlineSnapshot( - `".red-text{color:purple;color:red;font-weight:bolder}.blue-text{color:orange;color:#00f;font-weight:bolder}"` + `".red-text{color:purple;font-weight:bolder;color:red}.blue-text{color:orange;font-weight:bolder;color:#00f}"` ) }) }) @@ -640,7 +640,7 @@ describe('SCSS Support', () => { expect(cssFiles.length).toBe(1) const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatch( - /^\.red-text\{background-image:url\(\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\);color:red\}\.blue-text\{background-image:url\(\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:orange;color:#00f;font-weight:bolder\}$/ + /^\.red-text\{color:red;background-image:url\(\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\)\}\.blue-text\{color:orange;font-weight:bolder;background-image:url\(\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:#00f\}$/ ) const mediaFiles = await readdir(mediaFolder) @@ -686,7 +686,7 @@ describe('SCSS Support', () => { expect(cssFiles.length).toBe(1) const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatch( - /^\.red-text\{background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\);color:red\}\.blue-text\{background-image:url\(\/foo\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:orange;color:#00f;font-weight:bolder\}$/ + /^\.red-text\{color:red;background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\)\}\.blue-text\{color:orange;font-weight:bolder;background-image:url\(\/foo\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:#00f\}$/ ) const mediaFiles = await readdir(mediaFolder) @@ -732,7 +732,7 @@ describe('SCSS Support', () => { expect(cssFiles.length).toBe(1) const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8') expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatch( - /^\.red-text\{background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\);color:red\}\.blue-text\{background-image:url\(\/foo\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:orange;color:#00f;font-weight:bolder\}$/ + /^\.red-text\{color:red;background-image:url\(\/foo\/_next\/static\/media\/dark\.[a-z0-9]{32}\.svg\) url\(\/foo\/_next\/static\/media\/dark2\.[a-z0-9]{32}\.svg\)\}\.blue-text\{color:orange;font-weight:bolder;background-image:url\(\/foo\/_next\/static\/media\/light\.[a-z0-9]{32}\.svg\);color:#00f\}$/ ) const mediaFiles = await readdir(mediaFolder) diff --git a/yarn.lock b/yarn.lock index 8668aa6810881..ab08dabd16f10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5561,19 +5561,19 @@ cssnano-preset-default@^4.0.7: postcss-svgo "^4.0.2" postcss-unique-selectors "^4.0.1" -cssnano-preset-simple@^1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/cssnano-preset-simple/-/cssnano-preset-simple-1.1.3.tgz#c185f915afcfb803e78e357df48cc77f949eb1d4" - integrity sha512-7iDiM+OSkDlTrH/xGw748mr7FdQtFAy6qFRlTjJevAsG536DPOMeaDucJMqWzyAhcem0VQkTGveUk3bo3ux6hA== +cssnano-preset-simple@1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/cssnano-preset-simple/-/cssnano-preset-simple-1.1.4.tgz#7b287a31df786348565d02342df71af8f758ac82" + integrity sha512-EYKDo65W+AxMViUijv/hvhbEnxUjmu3V7omcH1MatPOwjRLrAgVArUOE8wTUyc1ePFEtvV8oCT4/QSRJDorm/A== dependencies: postcss "^7.0.32" -cssnano-simple@1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/cssnano-simple/-/cssnano-simple-1.0.4.tgz#2d56225795f4afbbb9c21df953cb43df6c589ae1" - integrity sha512-Em/QujEpiqfjT3wksbyHTYpBF2l7lfYuUiLjtCwurc6NqRFb4N/VZjC3djNuO7poFpO410tTcpJ38Qn8xWadcA== +cssnano-simple@1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/cssnano-simple/-/cssnano-simple-1.0.5.tgz#66ee528f3a4e60754e2625ea9f51ac315f5f0a92" + integrity sha512-NJjx2Er1C3pa75v1GwMKm0w6xAp1GsW2Ql1As4CWPNFxTgYFN5e8wblYeHfna13sANAhyIdSIPqKJjBO4CU5Eg== dependencies: - cssnano-preset-simple "^1.1.3" + cssnano-preset-simple "1.1.4" postcss "^7.0.32" cssnano-util-get-arguments@^4.0.0: From 3accce37a7486b51b43a45908697876f01f7a1ca Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 27 Jul 2020 00:23:23 -0400 Subject: [PATCH 14/90] v9.4.5-canary.44 --- lerna.json | 2 +- packages/create-next-app/package.json | 2 +- packages/eslint-plugin-next/package.json | 2 +- packages/next-bundle-analyzer/package.json | 2 +- packages/next-mdx/package.json | 2 +- packages/next-plugin-google-analytics/package.json | 2 +- packages/next-plugin-sentry/package.json | 2 +- packages/next-plugin-storybook/package.json | 2 +- packages/next-polyfill-nomodule/package.json | 2 +- packages/next/package.json | 8 ++++---- packages/react-dev-overlay/package.json | 2 +- packages/react-refresh-utils/package.json | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lerna.json b/lerna.json index b5e56c956ce19..b76e3e9aecc28 100644 --- a/lerna.json +++ b/lerna.json @@ -17,5 +17,5 @@ "registry": "https://registry.npmjs.org/" } }, - "version": "9.4.5-canary.43" + "version": "9.4.5-canary.44" } diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index 5bcc40563d929..ddf4c53a8a436 100644 --- a/packages/create-next-app/package.json +++ b/packages/create-next-app/package.json @@ -1,6 +1,6 @@ { "name": "create-next-app", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "keywords": [ "react", "next", diff --git a/packages/eslint-plugin-next/package.json b/packages/eslint-plugin-next/package.json index dfede47bd5050..baad5adba2b29 100644 --- a/packages/eslint-plugin-next/package.json +++ b/packages/eslint-plugin-next/package.json @@ -1,6 +1,6 @@ { "name": "@next/eslint-plugin-next", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "description": "ESLint plugin for NextJS.", "main": "lib/index.js", "license": "MIT", diff --git a/packages/next-bundle-analyzer/package.json b/packages/next-bundle-analyzer/package.json index d49537298fb78..6f19b4c77a64d 100644 --- a/packages/next-bundle-analyzer/package.json +++ b/packages/next-bundle-analyzer/package.json @@ -1,6 +1,6 @@ { "name": "@next/bundle-analyzer", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index 811a68d5908cb..283e50f4e8fbe 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@next/mdx", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-plugin-google-analytics/package.json b/packages/next-plugin-google-analytics/package.json index f9e282660e2ca..7e9520a2f2789 100644 --- a/packages/next-plugin-google-analytics/package.json +++ b/packages/next-plugin-google-analytics/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-google-analytics", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-google-analytics" diff --git a/packages/next-plugin-sentry/package.json b/packages/next-plugin-sentry/package.json index f0b58d01fdeb7..a64db289c8d6b 100644 --- a/packages/next-plugin-sentry/package.json +++ b/packages/next-plugin-sentry/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-sentry", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-sentry" diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index fe265828f3817..33fdd1e832ad9 100644 --- a/packages/next-plugin-storybook/package.json +++ b/packages/next-plugin-storybook/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-storybook", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-storybook" diff --git a/packages/next-polyfill-nomodule/package.json b/packages/next-polyfill-nomodule/package.json index ff63b0de438dd..5103bc8cd37df 100644 --- a/packages/next-polyfill-nomodule/package.json +++ b/packages/next-polyfill-nomodule/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-nomodule", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "description": "A polyfill for non-dead, nomodule browsers.", "main": "dist/polyfill-nomodule.js", "license": "MIT", diff --git a/packages/next/package.json b/packages/next/package.json index b35b4f3d0d4bc..5633b38df0998 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "description": "The React Framework", "main": "./dist/server/next.js", "license": "MIT", @@ -76,8 +76,8 @@ "@babel/preset-typescript": "7.9.0", "@babel/runtime": "7.9.6", "@babel/types": "7.9.6", - "@next/react-dev-overlay": "9.4.5-canary.43", - "@next/react-refresh-utils": "9.4.5-canary.43", + "@next/react-dev-overlay": "9.4.5-canary.44", + "@next/react-refresh-utils": "9.4.5-canary.44", "babel-plugin-syntax-jsx": "6.18.0", "babel-plugin-transform-define": "2.0.0", "babel-plugin-transform-react-remove-prop-types": "0.4.24", @@ -115,7 +115,7 @@ "react-dom": "^16.6.0" }, "devDependencies": { - "@next/polyfill-nomodule": "9.4.5-canary.43", + "@next/polyfill-nomodule": "9.4.5-canary.44", "@taskr/clear": "1.1.0", "@taskr/esnext": "1.1.0", "@taskr/watch": "1.1.0", diff --git a/packages/react-dev-overlay/package.json b/packages/react-dev-overlay/package.json index 4ad6238fc484d..bf82ea35f4c31 100644 --- a/packages/react-dev-overlay/package.json +++ b/packages/react-dev-overlay/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-dev-overlay", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "description": "A development-only overlay for developing React applications.", "repository": { "url": "vercel/next.js", diff --git a/packages/react-refresh-utils/package.json b/packages/react-refresh-utils/package.json index 0e02459b5dd64..919fa9e239062 100644 --- a/packages/react-refresh-utils/package.json +++ b/packages/react-refresh-utils/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-refresh-utils", - "version": "9.4.5-canary.43", + "version": "9.4.5-canary.44", "description": "An experimental package providing utilities for React Refresh.", "repository": { "url": "vercel/next.js", From ac12c07ce55f5d1566be43b884818ec9387eabee Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 27 Jul 2020 01:58:36 -0400 Subject: [PATCH 15/90] Fix peer dependency (#15511) --- packages/react-dev-overlay/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-dev-overlay/package.json b/packages/react-dev-overlay/package.json index bf82ea35f4c31..fb949417744e2 100644 --- a/packages/react-dev-overlay/package.json +++ b/packages/react-dev-overlay/package.json @@ -30,6 +30,6 @@ "peerDependencies": { "react": "^16.9.0", "react-dom": "^16.9.0", - "webpack": "^4|^5" + "webpack": "^4 || ^5" } } From 1ee151640efe857593228c142c115bbe338eeb60 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 27 Jul 2020 01:59:19 -0400 Subject: [PATCH 16/90] v9.4.5-canary.45 --- lerna.json | 2 +- packages/create-next-app/package.json | 2 +- packages/eslint-plugin-next/package.json | 2 +- packages/next-bundle-analyzer/package.json | 2 +- packages/next-mdx/package.json | 2 +- packages/next-plugin-google-analytics/package.json | 2 +- packages/next-plugin-sentry/package.json | 2 +- packages/next-plugin-storybook/package.json | 2 +- packages/next-polyfill-nomodule/package.json | 2 +- packages/next/package.json | 8 ++++---- packages/react-dev-overlay/package.json | 2 +- packages/react-refresh-utils/package.json | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lerna.json b/lerna.json index b76e3e9aecc28..dba8bc8556b77 100644 --- a/lerna.json +++ b/lerna.json @@ -17,5 +17,5 @@ "registry": "https://registry.npmjs.org/" } }, - "version": "9.4.5-canary.44" + "version": "9.4.5-canary.45" } diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index ddf4c53a8a436..63d136e41e911 100644 --- a/packages/create-next-app/package.json +++ b/packages/create-next-app/package.json @@ -1,6 +1,6 @@ { "name": "create-next-app", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "keywords": [ "react", "next", diff --git a/packages/eslint-plugin-next/package.json b/packages/eslint-plugin-next/package.json index baad5adba2b29..f2416a6353ddc 100644 --- a/packages/eslint-plugin-next/package.json +++ b/packages/eslint-plugin-next/package.json @@ -1,6 +1,6 @@ { "name": "@next/eslint-plugin-next", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "description": "ESLint plugin for NextJS.", "main": "lib/index.js", "license": "MIT", diff --git a/packages/next-bundle-analyzer/package.json b/packages/next-bundle-analyzer/package.json index 6f19b4c77a64d..9d82d6666adcb 100644 --- a/packages/next-bundle-analyzer/package.json +++ b/packages/next-bundle-analyzer/package.json @@ -1,6 +1,6 @@ { "name": "@next/bundle-analyzer", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index 283e50f4e8fbe..f70a81bef4e00 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@next/mdx", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-plugin-google-analytics/package.json b/packages/next-plugin-google-analytics/package.json index 7e9520a2f2789..1abad8e389ba3 100644 --- a/packages/next-plugin-google-analytics/package.json +++ b/packages/next-plugin-google-analytics/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-google-analytics", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-google-analytics" diff --git a/packages/next-plugin-sentry/package.json b/packages/next-plugin-sentry/package.json index a64db289c8d6b..dcab7dfaf3c76 100644 --- a/packages/next-plugin-sentry/package.json +++ b/packages/next-plugin-sentry/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-sentry", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-sentry" diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index 33fdd1e832ad9..1555d929d3c87 100644 --- a/packages/next-plugin-storybook/package.json +++ b/packages/next-plugin-storybook/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-storybook", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-storybook" diff --git a/packages/next-polyfill-nomodule/package.json b/packages/next-polyfill-nomodule/package.json index 5103bc8cd37df..10df83dda8e8c 100644 --- a/packages/next-polyfill-nomodule/package.json +++ b/packages/next-polyfill-nomodule/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-nomodule", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "description": "A polyfill for non-dead, nomodule browsers.", "main": "dist/polyfill-nomodule.js", "license": "MIT", diff --git a/packages/next/package.json b/packages/next/package.json index 5633b38df0998..861389de4f7f2 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "description": "The React Framework", "main": "./dist/server/next.js", "license": "MIT", @@ -76,8 +76,8 @@ "@babel/preset-typescript": "7.9.0", "@babel/runtime": "7.9.6", "@babel/types": "7.9.6", - "@next/react-dev-overlay": "9.4.5-canary.44", - "@next/react-refresh-utils": "9.4.5-canary.44", + "@next/react-dev-overlay": "9.4.5-canary.45", + "@next/react-refresh-utils": "9.4.5-canary.45", "babel-plugin-syntax-jsx": "6.18.0", "babel-plugin-transform-define": "2.0.0", "babel-plugin-transform-react-remove-prop-types": "0.4.24", @@ -115,7 +115,7 @@ "react-dom": "^16.6.0" }, "devDependencies": { - "@next/polyfill-nomodule": "9.4.5-canary.44", + "@next/polyfill-nomodule": "9.4.5-canary.45", "@taskr/clear": "1.1.0", "@taskr/esnext": "1.1.0", "@taskr/watch": "1.1.0", diff --git a/packages/react-dev-overlay/package.json b/packages/react-dev-overlay/package.json index fb949417744e2..97de776788c17 100644 --- a/packages/react-dev-overlay/package.json +++ b/packages/react-dev-overlay/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-dev-overlay", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "description": "A development-only overlay for developing React applications.", "repository": { "url": "vercel/next.js", diff --git a/packages/react-refresh-utils/package.json b/packages/react-refresh-utils/package.json index 919fa9e239062..de3d434d7759f 100644 --- a/packages/react-refresh-utils/package.json +++ b/packages/react-refresh-utils/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-refresh-utils", - "version": "9.4.5-canary.44", + "version": "9.4.5-canary.45", "description": "An experimental package providing utilities for React Refresh.", "repository": { "url": "vercel/next.js", From a3eec3bf038909d76ff6ea4809064417aee07c49 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 27 Jul 2020 11:46:17 +0200 Subject: [PATCH 17/90] Update custom webpack config docs to mention existing features (#15517) --- .../next.config.js/custom-webpack-config.md | 18 ++++---- examples/with-ant-design/next.config.js | 45 ++----------------- 2 files changed, 13 insertions(+), 50 deletions(-) diff --git a/docs/api-reference/next.config.js/custom-webpack-config.md b/docs/api-reference/next.config.js/custom-webpack-config.md index 618bafe42790a..c9b71fcd0f7bb 100644 --- a/docs/api-reference/next.config.js/custom-webpack-config.md +++ b/docs/api-reference/next.config.js/custom-webpack-config.md @@ -4,12 +4,18 @@ description: Extend the default webpack config added by Next.js. # Custom Webpack Config +Before continuing to add custom webpack configuration your application make sure Next.js doesn't already support your use-case: + +- [CSS imports](/docs/basic-features/built-in-css-support#adding-a-global-stylesheet) +- [CSS modules](/docs/basic-features/built-in-css-support#adding-component-level-css) +- [Sass/SCSS imports](/docs/basic-features/built-in-css-support#sass-support) +- [Sass/SCSS modules](/docs/basic-features/built-in-css-support#sass-support) +- [preact](https://github.com/vercel/next.js/tree/canary/examples/using-preact) +- [Customizing babel configuration](/docs/advanced-features/customizing-babel-config) + Some commonly asked for features are available as plugins: -- [@zeit/next-sass](https://github.com/zeit/next-plugins/tree/master/packages/next-sass) - [@zeit/next-less](https://github.com/zeit/next-plugins/tree/master/packages/next-less) -- [@zeit/next-stylus](https://github.com/zeit/next-plugins/tree/master/packages/next-stylus) -- [@zeit/next-preact](https://github.com/zeit/next-plugins/tree/master/packages/next-preact) - [@next/mdx](https://github.com/vercel/next.js/tree/canary/packages/next-mdx) - [@next/bundle-analyzer](https://github.com/vercel/next.js/tree/canary/packages/next-bundle-analyzer) @@ -20,12 +26,8 @@ module.exports = { webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => { // Note: we provide webpack above so you should not `require` it // Perform customizations to webpack config - // Important: return the modified config config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//)) - return config - }, - webpackDevMiddleware: (config) => { - // Perform customizations to webpack dev middleware config + // Important: return the modified config return config }, diff --git a/examples/with-ant-design/next.config.js b/examples/with-ant-design/next.config.js index 8188ce8128a27..5e149d4f542d9 100644 --- a/examples/with-ant-design/next.config.js +++ b/examples/with-ant-design/next.config.js @@ -1,44 +1,5 @@ -const compose = (plugins) => ({ - webpack(config, options) { - return plugins.reduce((config, plugin) => { - if (plugin instanceof Array) { - const [_plugin, ...args] = plugin - plugin = _plugin(...args) - } - if (plugin instanceof Function) { - plugin = plugin() - } - if (plugin && plugin.webpack instanceof Function) { - return plugin.webpack(config, options) - } - return config - }, config) - }, - - webpackDevMiddleware(config) { - return plugins.reduce((config, plugin) => { - if (plugin instanceof Array) { - const [_plugin, ...args] = plugin - plugin = _plugin(...args) - } - if (plugin instanceof Function) { - plugin = plugin() - } - if (plugin && plugin.webpackDevMiddleware instanceof Function) { - return plugin.webpackDevMiddleware(config) - } - return config - }, config) - }, +const withBundleAnalyzer = require('@next/bundle-analyzer')({ + enabled: process.env.ANALYZE === 'true', }) -const withBundleAnalyzer = require('@next/bundle-analyzer') - -module.exports = compose([ - [ - withBundleAnalyzer, - { - enabled: process.env.ANALYZE === 'true', - }, - ], -]) +module.exports = withBundleAnalyzer() From d33dbea8dc684003a8d7babce58b60140089c6e1 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 27 Jul 2020 16:55:16 +0200 Subject: [PATCH 18/90] v9.5.0 --- lerna.json | 2 +- packages/create-next-app/package.json | 2 +- packages/eslint-plugin-next/package.json | 2 +- packages/next-bundle-analyzer/package.json | 2 +- packages/next-mdx/package.json | 2 +- packages/next-plugin-google-analytics/package.json | 2 +- packages/next-plugin-sentry/package.json | 2 +- packages/next-plugin-storybook/package.json | 2 +- packages/next-polyfill-nomodule/package.json | 2 +- packages/next/package.json | 8 ++++---- packages/react-dev-overlay/package.json | 2 +- packages/react-refresh-utils/package.json | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lerna.json b/lerna.json index dba8bc8556b77..1659ef19d8196 100644 --- a/lerna.json +++ b/lerna.json @@ -17,5 +17,5 @@ "registry": "https://registry.npmjs.org/" } }, - "version": "9.4.5-canary.45" + "version": "9.5.0" } diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index 63d136e41e911..d852aff667614 100644 --- a/packages/create-next-app/package.json +++ b/packages/create-next-app/package.json @@ -1,6 +1,6 @@ { "name": "create-next-app", - "version": "9.4.5-canary.45", + "version": "9.5.0", "keywords": [ "react", "next", diff --git a/packages/eslint-plugin-next/package.json b/packages/eslint-plugin-next/package.json index f2416a6353ddc..9d5654b6b6c51 100644 --- a/packages/eslint-plugin-next/package.json +++ b/packages/eslint-plugin-next/package.json @@ -1,6 +1,6 @@ { "name": "@next/eslint-plugin-next", - "version": "9.4.5-canary.45", + "version": "9.5.0", "description": "ESLint plugin for NextJS.", "main": "lib/index.js", "license": "MIT", diff --git a/packages/next-bundle-analyzer/package.json b/packages/next-bundle-analyzer/package.json index 9d82d6666adcb..7076967589cea 100644 --- a/packages/next-bundle-analyzer/package.json +++ b/packages/next-bundle-analyzer/package.json @@ -1,6 +1,6 @@ { "name": "@next/bundle-analyzer", - "version": "9.4.5-canary.45", + "version": "9.5.0", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index f70a81bef4e00..eba024b924eb0 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@next/mdx", - "version": "9.4.5-canary.45", + "version": "9.5.0", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-plugin-google-analytics/package.json b/packages/next-plugin-google-analytics/package.json index 1abad8e389ba3..493b900bc24f7 100644 --- a/packages/next-plugin-google-analytics/package.json +++ b/packages/next-plugin-google-analytics/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-google-analytics", - "version": "9.4.5-canary.45", + "version": "9.5.0", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-google-analytics" diff --git a/packages/next-plugin-sentry/package.json b/packages/next-plugin-sentry/package.json index dcab7dfaf3c76..ef16e76bc6d08 100644 --- a/packages/next-plugin-sentry/package.json +++ b/packages/next-plugin-sentry/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-sentry", - "version": "9.4.5-canary.45", + "version": "9.5.0", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-sentry" diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index 1555d929d3c87..8dbed4219e7c2 100644 --- a/packages/next-plugin-storybook/package.json +++ b/packages/next-plugin-storybook/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-storybook", - "version": "9.4.5-canary.45", + "version": "9.5.0", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-storybook" diff --git a/packages/next-polyfill-nomodule/package.json b/packages/next-polyfill-nomodule/package.json index 10df83dda8e8c..e126e4d4edfd6 100644 --- a/packages/next-polyfill-nomodule/package.json +++ b/packages/next-polyfill-nomodule/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-nomodule", - "version": "9.4.5-canary.45", + "version": "9.5.0", "description": "A polyfill for non-dead, nomodule browsers.", "main": "dist/polyfill-nomodule.js", "license": "MIT", diff --git a/packages/next/package.json b/packages/next/package.json index 861389de4f7f2..29434b38575de 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "9.4.5-canary.45", + "version": "9.5.0", "description": "The React Framework", "main": "./dist/server/next.js", "license": "MIT", @@ -76,8 +76,8 @@ "@babel/preset-typescript": "7.9.0", "@babel/runtime": "7.9.6", "@babel/types": "7.9.6", - "@next/react-dev-overlay": "9.4.5-canary.45", - "@next/react-refresh-utils": "9.4.5-canary.45", + "@next/react-dev-overlay": "9.5.0", + "@next/react-refresh-utils": "9.5.0", "babel-plugin-syntax-jsx": "6.18.0", "babel-plugin-transform-define": "2.0.0", "babel-plugin-transform-react-remove-prop-types": "0.4.24", @@ -115,7 +115,7 @@ "react-dom": "^16.6.0" }, "devDependencies": { - "@next/polyfill-nomodule": "9.4.5-canary.45", + "@next/polyfill-nomodule": "9.5.0", "@taskr/clear": "1.1.0", "@taskr/esnext": "1.1.0", "@taskr/watch": "1.1.0", diff --git a/packages/react-dev-overlay/package.json b/packages/react-dev-overlay/package.json index 97de776788c17..dc5251883216e 100644 --- a/packages/react-dev-overlay/package.json +++ b/packages/react-dev-overlay/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-dev-overlay", - "version": "9.4.5-canary.45", + "version": "9.5.0", "description": "A development-only overlay for developing React applications.", "repository": { "url": "vercel/next.js", diff --git a/packages/react-refresh-utils/package.json b/packages/react-refresh-utils/package.json index de3d434d7759f..ef994d9f20405 100644 --- a/packages/react-refresh-utils/package.json +++ b/packages/react-refresh-utils/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-refresh-utils", - "version": "9.4.5-canary.45", + "version": "9.5.0", "description": "An experimental package providing utilities for React Refresh.", "repository": { "url": "vercel/next.js", From 56367487085e3bef0bf86eebc1ebe662bf4b2337 Mon Sep 17 00:00:00 2001 From: Sebastian Benz Date: Mon, 27 Jul 2020 20:12:33 +0200 Subject: [PATCH 19/90] upgrade @ampproject/toolbox-optimizer to 2.5.14 (#15463) --- packages/next/compiled/terser/bundle.min.js | 2 +- packages/next/package.json | 2 +- yarn.lock | 81 ++++++++++----------- 3 files changed, 39 insertions(+), 46 deletions(-) diff --git a/packages/next/compiled/terser/bundle.min.js b/packages/next/compiled/terser/bundle.min.js index 7677047b6136e..67a46b82cf7e7 100644 --- a/packages/next/compiled/terser/bundle.min.js +++ b/packages/next/compiled/terser/bundle.min.js @@ -1 +1 @@ -module.exports=function(e,t){"use strict";var n={};function __webpack_require__(t){if(n[t]){return n[t].exports}var i=n[t]={i:t,l:false,exports:{}};e[t].call(i.exports,i,i.exports,__webpack_require__);i.l=true;return i.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(838)}return startup()}({241:function(e){e.exports=require("next/dist/compiled/source-map")},838:function(e,t,n){!function(e,i){true?i(t,n(241)):undefined}(this,function(C,O){"use strict";function n(e){return e.split("")}function i(e,t){return t.includes(e)}O=O&&O.hasOwnProperty("default")?O.default:O;class r extends Error{constructor(e,t){super(),this.name="DefaultsError",this.message=e,this.defs=t}}function o(e,t,n){!0===e&&(e={});var i=e||{};if(n)for(var o in i)if(D(i,o)&&!D(t,o))throw new r("`"+o+"` is not a supported option",t);for(var o in t)D(t,o)&&(i[o]=e&&D(e,o)?e[o]:t[o]);return i}function a(){}function s(){return!1}function u(){return!0}function c(){return this}function l(){return null}var F=function(){function e(e,o,a){var s,u=[],c=[];function l(){var l=o(e[s],s),f=l instanceof r;return f&&(l=l.v),l instanceof n?(l=l.v)instanceof i?c.push.apply(c,a?l.v.slice().reverse():l.v):c.push(l):l!==t&&(l instanceof i?u.push.apply(u,a?l.v.slice().reverse():l.v):u.push(l)),f}if(Array.isArray(e))if(a){for(s=e.length;--s>=0&&!l(););u.reverse(),c.reverse()}else for(s=0;s=0;)e[n]===t&&e.splice(n,1)}function m(t,n){if(t.length<2)return t.slice();return function e(t){if(t.length<=1)return t;var i=Math.floor(t.length/2),r=t.slice(0,i),o=t.slice(i);return function(e,t){for(var i=[],r=0,o=0,a=0;r!?|~^")),de=/[0-9a-f]/i,me=/^0x[0-9a-f]+$/i,De=/^0[0-7]+$/,ge=/^0o[0-7]+$/i,Se=/^0b[01]+$/i,ve=/^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i,Te=/^(0[xob])?[0-9a-f]+n$/i,be=E(["in","instanceof","typeof","new","void","delete","++","--","+","-","!","~","&","|","^","*","**","/","%",">>","<<",">>>","<",">","<=",">=","==","===","!=","!==","?","=","+=","-=","/=","*=","**=","%=",">>=","<<=",">>>=","|=","^=","&=","&&","||"]),ye=E(n("  \n\r\t\f\v​           \u2028\u2029   \ufeff")),Ce=E(n("\n\r\u2028\u2029")),Oe=E(n(";]),:")),Fe=E(n("[{(,;:")),Me=E(n("[]{}(),;:")),Re={ID_Start:/[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,ID_Continue:/[0-9A-Z_a-z\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/};function X(e,t){var n=e.charAt(t);if(z(n)){var i=e.charAt(t+1);if(W(i))return n+i}if(W(n)){var r=e.charAt(t-1);if(z(r))return r+n}return n}function z(e){return"string"==typeof e&&(e=e.charCodeAt(0)),e>=55296&&e<=56319}function W(e){return"string"==typeof e&&(e=e.charCodeAt(0)),e>=56320&&e<=57343}function Y(e){return e>=48&&e<=57}function q(e){var t=e.charCodeAt(0);return Re.ID_Start.test(e)||36==t||95==t}function $(e){var t=e.charCodeAt(0);return Re.ID_Continue.test(e)||36==t||95==t||8204==t||8205==t}function j(e){return/^[a-z_$][a-z0-9_$]*$/i.test(e)}function Z(e){if(me.test(e))return parseInt(e.substr(2),16);if(De.test(e))return parseInt(e.substr(1),8);if(ge.test(e))return parseInt(e.substr(2),8);if(Se.test(e))return parseInt(e.substr(2),2);if(ve.test(e))return parseFloat(e);var t=parseFloat(e);return t==e?t:void 0}class J extends Error{constructor(e,t,n,i,r){super(),this.name="SyntaxError",this.message=e,this.filename=t,this.line=n,this.col=i,this.pos=r}}function Q(e,t,n,i,r){throw new J(e,t,n,i,r)}function ee(e,t,n){return e.type==t&&(null==n||e.value==n)}var Ne={};function ne(t,n,i,r){var f={text:t,filename:n,pos:0,tokpos:0,line:1,tokline:0,col:0,tokcol:0,newline_before:!1,regex_allowed:!1,brace_counter:0,template_braces:[],comments_before:[],directives:{},directive_stack:[]};function o(){return X(f.text,f.pos)}function a(e,t){var n=X(f.text,f.pos++);if(e&&!n)throw Ne;return Ce.has(n)?(f.newline_before=f.newline_before||!t,++f.line,f.col=0,"\r"==n&&"\n"==o()&&(++f.pos,n="\n")):(n.length>1&&(++f.pos,++f.col),++f.col),n}function s(e){for(;e-- >0;)a()}function u(e){return f.text.substr(f.pos,e.length)==e}function c(e,t){var n=f.text.indexOf(e,f.pos);if(t&&-1==n)throw Ne;return n}function l(){f.tokline=f.line,f.tokcol=f.col,f.tokpos=f.pos}var p=!1,A=null;function _(e,i,r){f.regex_allowed="operator"==e&&!xe.has(i)||"keyword"==e&&fe.has(i)||"punc"==e&&Fe.has(i)||"arrow"==e,"punc"==e&&"."==i?p=!0:r||(p=!1);var o={type:e,value:i,line:f.tokline,col:f.tokcol,pos:f.tokpos,endline:f.line,endcol:f.col,endpos:f.pos,nlb:f.newline_before,file:n};return/^(?:num|string|regexp)$/i.test(e)&&(o.raw=t.substring(o.pos,o.endpos)),r||(o.comments_before=f.comments_before,o.comments_after=f.comments_before=[]),f.newline_before=!1,o=new Ve(o),r||(A=o),o}function d(){for(;ye.has(o());)a()}function m(e){Q(e,n,f.tokline,f.tokcol,f.tokpos)}function E(e){var t=!1,n=!1,i=!1,r="."==e,s=!1,u=function(e){for(var t,n="",i=0;(t=o())&&e(t,i++);)n+=a();return n}(function(o,a){if(s)return!1;switch(o.charCodeAt(0)){case 98:case 66:return i=!0;case 111:case 79:case 120:case 88:return!i&&(i=!0);case 101:case 69:return!!i||!t&&(t=n=!0);case 45:return n||0==a&&!e;case 43:return n;case n=!1,46:return!(r||i||t)&&(r=!0)}return"n"===o?(s=!0,!0):de.test(o)});if(e&&(u=e+u),De.test(u)&&K.has_directive("use strict")&&m("Legacy octal literals are not allowed in strict mode"),u.endsWith("n")){const e=Z(u.slice(0,-1));if(!r&&Te.test(u)&&!isNaN(e))return _("big_int",u.replace("n",""));m("Invalid or unexpected token")}var c=Z(u);if(!isNaN(c))return _("num",c);m("Invalid syntax: "+u)}function h(e){return e>="0"&&e<="7"}function D(e,t,n){var i,r=a(!0,e);switch(r.charCodeAt(0)){case 110:return"\n";case 114:return"\r";case 116:return"\t";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 120:return String.fromCharCode(g(2,t));case 117:if("{"==o()){for(a(!0),"}"===o()&&m("Expecting hex-character between {}");"0"==o();)a(!0);var s,u=c("}",!0)-f.pos;return(u>6||(s=g(u,t))>1114111)&&m("Unicode reference out of bounds"),a(!0),(i=s)>65535?(i-=65536,String.fromCharCode(55296+(i>>10))+String.fromCharCode(i%1024+56320)):String.fromCharCode(i)}return String.fromCharCode(g(4,t));case 10:return"";case 13:if("\n"==o())return a(!0,e),""}if(h(r)){if(n&&t){"0"===r&&!h(o())||m("Octal escape sequences are not allowed in template strings")}return function(e,t){var n=o();n>="0"&&n<="7"&&(e+=a(!0))[0]<="3"&&(n=o())>="0"&&n<="7"&&(e+=a(!0));if("0"===e)return"\0";e.length>0&&K.has_directive("use strict")&&t&&m("Legacy octal escape sequences are not allowed in strict mode");return String.fromCharCode(parseInt(e,8))}(r,t)}return r}function g(e,t){for(var n=0;e>0;--e){if(!t&&isNaN(parseInt(o(),16)))return parseInt(n,16)||"";var i=a(!0);isNaN(parseInt(i,16))&&m("Invalid hex-character pattern in string"),n+=i}return parseInt(n,16)}var S=I("Unterminated string constant",function(){for(var e=a(),t="";;){var n=a(!0,!0);if("\\"==n)n=D(!0,!0);else if("\r"==n||"\n"==n)m("Unterminated string constant");else if(n==e)break;t+=n}var i=_("string",t);return i.quote=e,i}),T=I("Unterminated template",function(e){e&&f.template_braces.push(f.brace_counter);var t,n,i="",r="";for(a(!0,!0);"`"!=(t=a(!0,!0));){if("\r"==t)"\n"==o()&&++f.pos,t="\n";else if("$"==t&&"{"==o())return a(!0,!0),f.brace_counter++,(n=_(e?"template_head":"template_substitution",i)).raw=r,n;if(r+=t,"\\"==t){var s=f.pos;t=D(!0,!(A&&("name"===A.type||"punc"===A.type&&(")"===A.value||"]"===A.value))),!0),r+=f.text.substr(s,f.pos-s)}i+=t}return f.template_braces.pop(),(n=_(e?"template_head":"template_substitution",i)).raw=r,n.end=!0,n});function v(e){var t,n=f.regex_allowed,i=function(){for(var e=f.text,t=f.pos,n=f.text.length;t"===o()?(a(),_("arrow","=>")):x("=");case 96:return T(!0);case 123:f.brace_counter++;break;case 125:if(f.brace_counter--,f.template_braces.length>0&&f.template_braces[f.template_braces.length-1]===f.brace_counter)return T(!1)}if(Y(n))return E();if(Me.has(t))return _("punc",a());if(_e.has(t))return x();if(92==n||q(t))return h=void 0,h=y(),p?_("name",h):ae.has(h)?_("atom",h):oe.has(h)?be.has(h)?_("operator",h):_("keyword",h):_("name",h);break}var h;m("Unexpected character '"+t+"'")}return K.next=a,K.peek=o,K.context=function(e){return e&&(f=e),f},K.add_directive=function(e){f.directive_stack[f.directive_stack.length-1].push(e),void 0===f.directives[e]?f.directives[e]=1:f.directives[e]++},K.push_directives_stack=function(){f.directive_stack.push([])},K.pop_directives_stack=function(){for(var e=f.directive_stack[f.directive_stack.length-1],t=0;t0},K}var we=E(["typeof","void","delete","--","++","!","~","-","+"]),xe=E(["--","++"]),ke=E(["=","+=","-=","/=","*=","**=","%=",">>=","<<=",">>>=","|=","^=","&="]),Ie=function(e,t){for(var n=0;n","<=",">=","in","instanceof"],[">>","<<",">>>"],["+","-"],["*","/","%"],["**"]],{}),Le=E(["atom","num","big_int","string","regexp","name"]);function ue(e,n){const i=new Map;n=o(n,{bare_returns:!1,ecma:8,expression:!1,filename:null,html5_comments:!0,module:!1,shebang:!0,strict:!1,toplevel:null},!0);var v={input:"string"==typeof e?ne(e,n.filename,n.html5_comments,n.shebang):e,token:null,prev:null,peeked:null,in_function:0,in_async:-1,in_generator:-1,in_directives:!0,in_loop:0,labels:[]};function r(e,t){return ee(v.token,e,t)}function a(){return v.peeked||(v.peeked=v.input())}function s(){return v.prev=v.token,v.peeked||a(),v.token=v.peeked,v.peeked=null,v.in_directives=v.in_directives&&("string"==v.token.type||r("punc",";")),v.token}function u(){return v.prev}function c(e,t,n,i){var r=v.input.context();Q(e,r.filename,null!=t?t:r.tokline,null!=n?n:r.tokcol,null!=i?i:r.tokpos)}function l(e,t){c(t,e.line,e.col)}function f(e){null==e&&(e=v.token),l(e,"Unexpected token: "+e.type+" ("+e.value+")")}function p(e,t){if(r(e,t))return s();l(v.token,"Unexpected token "+v.token.type+" «"+v.token.value+"», expected "+e+" «"+t+"»")}function _(e){return p("punc",e)}function d(e){return e.nlb||!e.comments_before.every(e=>!e.nlb)}function m(){return!n.strict&&(r("eof")||r("punc","}")||d(v.token))}function E(){return v.in_generator===v.in_function}function h(){return v.in_async===v.in_function}function D(e){r("punc",";")?s():e||m()||f()}function g(){_("(");var e=fe(!0);return _(")"),e}function S(e){return function(...t){const n=v.token,i=e(...t);return i.start=n,i.end=u(),i}}function A(){(r("operator","/")||r("operator","/="))&&(v.peeked=null,v.token=v.input(v.token.value.substr(1)))}v.token=s();var C=S(function(e,t,i){switch(A(),v.token.type){case"string":if(v.in_directives){var o=a();!v.token.raw.includes("\\")&&(ee(o,"punc",";")||ee(o,"punc","}")||d(o)||ee(o,"eof"))?v.input.add_directive(v.token.value):v.in_directives=!1}var E=v.in_directives,S=T();return E&&S.body instanceof Xn?new Ue(S.body):S;case"template_head":case"num":case"big_int":case"regexp":case"operator":case"atom":return T();case"name":if("async"==v.token.value&&ee(a(),"keyword","function"))return s(),s(),t&&c("functions are not allowed as the body of a loop"),F(ft,!1,!0,e);if("import"==v.token.value&&!ee(a(),"punc","(")){s();var b=function(){var e,t,n=u();r("name")&&(e=le(Cn));r("punc",",")&&s();((t=J(!0))||e)&&p("name","from");var i=v.token;"string"!==i.type&&f();return s(),new Vt({start:n,imported_name:e,imported_names:t,module_name:new Xn({start:i,value:i.value,quote:i.quote,end:i}),end:v.token})}();return D(),b}return ee(a(),"punc",":")?function(){var e=le(Nn);"await"===e.name&&h()&&l(v.prev,"await cannot be used as label inside async function");v.labels.some(t=>t.name===e.name)&&c("Label "+e.name+" defined twice");_(":"),v.labels.push(e);var t=C();v.labels.pop(),t instanceof je||e.references.forEach(function(t){t instanceof Tt&&(t=t.label.start,c("Continue label `"+e.name+"` refers to non-IterationStatement.",t.line,t.col,t.pos))});return new $e({body:t,label:e})}():T();case"punc":switch(v.token.value){case"{":return new We({start:v.token,body:x(),end:u()});case"[":case"(":return T();case";":return v.in_directives=!1,s(),new Ye;default:f()}case"keyword":switch(v.token.value){case"break":return s(),y(vt);case"continue":return s(),y(Tt);case"debugger":return s(),D(),new Ke;case"do":s();var O=Dt(C);p("keyword","while");var M=g();return D(!0),new Qe({body:O,condition:M});case"while":return s(),new Je({condition:g(),body:Dt(function(){return C(!1,!0)})});case"for":return s(),function(){var e="`for await` invalid in this context",t=v.token;"name"==t.type&&"await"==t.value?(h()||l(t,e),s()):t=!1;_("(");var n=null;if(r("punc",";"))t&&l(t,e);else{n=r("keyword","var")?(s(),L(!0)):r("keyword","let")?(s(),V(!0)):r("keyword","const")?(s(),P(!0)):fe(!0,!0);var i=r("operator","in"),o=r("name","of");if(t&&!o&&l(t,e),i||o)return n instanceof wt?n.definitions.length>1&&l(n.start,"Only one variable declaration allowed in for..in loop"):He(n)||(n=Xe(n))instanceof pt||l(n.start,"Invalid left-hand side in for..in loop"),s(),i?function(e){var t=fe(!0);return _(")"),new tt({init:e,object:t,body:Dt(function(){return C(!1,!0)})})}(n):function(e,t){var n=e instanceof wt?e.definitions[0].name:null,i=fe(!0);return _(")"),new nt({await:t,init:e,name:n,object:i,body:Dt(function(){return C(!1,!0)})})}(n,!!t)}return function(e){_(";");var t=r("punc",";")?null:fe(!0);_(";");var n=r("punc",")")?null:fe(!0);return _(")"),new et({init:e,condition:t,step:n,body:Dt(function(){return C(!1,!0)})})}(n)}();case"class":return s(),t&&c("classes are not allowed as the body of a loop"),i&&c("classes are not allowed as the body of an if"),q(un);case"function":return s(),t&&c("functions are not allowed as the body of a loop"),F(ft,!1,!1,e);case"if":return s(),function(){var e=g(),t=C(!1,!1,!0),n=null;r("keyword","else")&&(s(),n=C(!1,!1,!0));return new bt({condition:e,body:t,alternative:n})}();case"return":0!=v.in_function||n.bare_returns||c("'return' outside of function"),s();var N=null;return r("punc",";")?s():m()||(N=fe(!0),D()),new gt({value:N});case"switch":return s(),new yt({expression:g(),body:Dt(k)});case"throw":s(),d(v.token)&&c("Illegal newline after 'throw'");N=fe(!0);return D(),new At({value:N});case"try":return s(),function(){var e=x(),t=null,n=null;if(r("keyword","catch")){var i=v.token;if(s(),r("punc","{"))var o=null;else{_("(");o=R(void 0,yn);_(")")}t=new Rt({start:i,argname:o,body:x(),end:u()})}if(r("keyword","finally")){i=v.token;s(),n=new Nt({start:i,body:x(),end:u()})}t||n||c("Missing catch/finally blocks");return new Mt({body:e,bcatch:t,bfinally:n})}();case"var":s();b=L();return D(),b;case"let":s();b=V();return D(),b;case"const":s();b=P();return D(),b;case"with":return v.input.has_directive("use strict")&&c("Strict mode may not include a with statement"),s(),new it({expression:g(),body:C()});case"export":if(!ee(a(),"punc","(")){s();b=function(){var e,t,n,i,o,c=v.token;if(r("keyword","default"))e=!0,s();else if(t=J(!1)){if(r("name","from")){s();var l=v.token;return"string"!==l.type&&f(),s(),new Pt({start:c,is_default:e,exported_names:t,module_name:new Xn({start:l,value:l.value,quote:l.quote,end:l}),end:u()})}return new Pt({start:c,is_default:e,exported_names:t,end:u()})}r("punc","{")||e&&(r("keyword","class")||r("keyword","function"))&&ee(a(),"punc")?(i=fe(!1),D()):(n=C(e))instanceof wt&&e?f(n.start):n instanceof wt||n instanceof st||n instanceof un?o=n:n instanceof Ge?i=n.body:f(n.start);return new Pt({start:c,is_default:e,exported_value:i,exported_definition:o,end:u()})}();return r("punc",";")&&D(),b}}}f()});function T(e){return new Ge({body:(e=fe(!0),D(),e)})}function y(e){var t,n=null;m()||(n=le(Vn,!0)),null!=n?((t=v.labels.find(e=>e.name===n.name))||c("Undefined label "+n.name),n.thedef=t):0==v.in_loop&&c(e.TYPE+" not inside a loop or switch"),D();var i=new e({label:n});return t&&t.references.push(i),i}var O=function(e,t,n){d(v.token)&&c("Unexpected newline before arrow (=>)"),p("arrow","=>");var i=w(r("punc","{"),!1,n),o=i instanceof Array&&i.length?i[i.length-1].end:i instanceof Array?e:i.end;return new lt({start:e,end:o,async:n,argnames:t,body:i})},F=function(e,t,n,i){var o=e===ft,a=r("operator","*");a&&s();var c=r("name")?le(o?Dn:Sn):null;o&&!c&&(i?e=ct:f()),!c||e===ut||c instanceof pn||f(u());var l=[],p=w(!0,a||t,n,c,l);return new e({start:l.start,end:p.end,is_generator:a,async:n,name:c,argnames:l,body:p})};function M(e,t){var n=new Set,i=!1,r=!1,o=!1,a=!!t,s={add_parameter:function(t){if(n.has(t.value))!1===i&&(i=t),s.check_strict();else if(n.add(t.value),e)switch(t.value){case"arguments":case"eval":case"yield":a&&l(t,"Unexpected "+t.value+" identifier as parameter inside strict mode");break;default:se.has(t.value)&&f()}},mark_default_assignment:function(e){!1===r&&(r=e)},mark_spread:function(e){!1===o&&(o=e)},mark_strict_mode:function(){a=!0},is_strict:function(){return!1!==r||!1!==o||a},check_strict:function(){s.is_strict()&&!1!==i&&l(i,"Parameter "+i.value+" was used already")}};return s}function R(e,t){var n,i=!1;return void 0===e&&(e=M(!0,v.input.has_directive("use strict"))),r("expand","...")&&(i=v.token,e.mark_spread(v.token),s()),n=N(e,t),r("operator","=")&&!1===i&&(e.mark_default_assignment(v.token),s(),n=new Qt({start:n.start,left:n,operator:"=",right:fe(!1),end:v.token})),!1!==i&&(r("punc",")")||f(),n=new at({start:i,expression:n,end:i})),e.check_strict(),n}function N(e,t){var n,i=[],o=!0,l=!1,p=v.token;if(void 0===e&&(e=M(!1,v.input.has_directive("use strict"))),t=void 0===t?hn:t,r("punc","[")){for(s();!r("punc","]");){if(o?o=!1:_(","),r("expand","...")&&(l=!0,n=v.token,e.mark_spread(v.token),s()),r("punc"))switch(v.token.value){case",":i.push(new Qn({start:v.token,end:v.token}));continue;case"]":break;case"[":case"{":i.push(N(e,t));break;default:f()}else r("name")?(e.add_parameter(v.token),i.push(le(t))):c("Invalid function parameter");r("operator","=")&&!1===l&&(e.mark_default_assignment(v.token),s(),i[i.length-1]=new Qt({start:i[i.length-1].start,left:i[i.length-1],operator:"=",right:fe(!1),end:v.token})),l&&(r("punc","]")||c("Rest element must be last element"),i[i.length-1]=new at({start:n,expression:i[i.length-1],end:n}))}return _("]"),e.check_strict(),new pt({start:p,names:i,is_array:!0,end:u()})}if(r("punc","{")){for(s();!r("punc","}");){if(o?o=!1:_(","),r("expand","...")&&(l=!0,n=v.token,e.mark_spread(v.token),s()),r("name")&&(ee(a(),"punc")||ee(a(),"operator"))&&[",","}","="].includes(a().value)){e.add_parameter(v.token);var d=u(),m=le(t);l?i.push(new at({start:n,expression:m,end:m.end})):i.push(new nn({start:d,key:m.name,value:m,end:m.end}))}else{if(r("punc","}"))continue;var E=v.token,h=te();null===h?f(u()):"name"!==u().type||r("punc",":")?(_(":"),i.push(new nn({start:E,quote:E.quote,key:h,value:N(e,t),end:u()}))):i.push(new nn({start:u(),key:h,value:new t({start:u(),name:h,end:u()}),end:u()}))}l?r("punc","}")||c("Rest element must be last element"):r("operator","=")&&(e.mark_default_assignment(v.token),s(),i[i.length-1].value=new Qt({start:i[i.length-1].value.start,left:i[i.length-1].value,operator:"=",right:fe(!1),end:v.token}))}return _("}"),e.check_strict(),new pt({start:p,names:i,is_array:!1,end:u()})}if(r("name"))return e.add_parameter(v.token),le(t);c("Invalid function parameter")}function w(e,t,i,o,a){var u=v.in_loop,c=v.labels,l=v.in_generator,p=v.in_async;if(++v.in_function,t&&(v.in_generator=v.in_function),i&&(v.in_async=v.in_function),a&&function(e){var t=M(!0,v.input.has_directive("use strict"));for(_("(");!r("punc",")");){var i=R(t);if(e.push(i),r("punc",")")||(_(","),r("punc",")")&&n.ecma<8&&f()),i instanceof at)break}s()}(a),e&&(v.in_directives=!0),v.in_loop=0,v.labels=[],e){v.input.push_directives_stack();var d=x();o&&ce(o),a&&a.forEach(ce),v.input.pop_directives_stack()}else d=fe(!1);return--v.in_function,v.in_loop=u,v.labels=c,v.in_generator=l,v.in_async=p,d}function x(){_("{");for(var e=[];!r("punc","}");)r("eof")&&f(),e.push(C());return s(),e}function k(){_("{");for(var e,t=[],n=null,i=null;!r("punc","}");)r("eof")&&f(),r("keyword","case")?(i&&(i.end=u()),n=[],i=new Ft({start:(e=v.token,s(),e),expression:fe(!0),body:n}),t.push(i),_(":")):r("keyword","default")?(i&&(i.end=u()),n=[],i=new Ot({start:(e=v.token,s(),_(":"),e),body:n}),t.push(i)):(n||f(),n.push(C()));return i&&(i.end=u()),s(),t}function I(e,t){for(var n,i=[];;){var o="var"===t?_n:"const"===t?mn:"let"===t?En:null;if(r("punc","{")||r("punc","[")?n=new Bt({start:v.token,name:N(void 0,o),value:r("operator","=")?(p("operator","="),fe(!1,e)):null,end:u()}):"import"==(n=new Bt({start:v.token,name:le(o),value:r("operator","=")?(s(),fe(!1,e)):e||"const"!==t?null:c("Missing initializer in const declaration"),end:u()})).name.name&&c("Unexpected token: import"),i.push(n),!r("punc",","))break;s()}return i}var L=function(e){return new xt({start:u(),definitions:I(e,"var"),end:u()})},V=function(e){return new kt({start:u(),definitions:I(e,"let"),end:u()})},P=function(e){return new It({start:u(),definitions:I(e,"const"),end:u()})};function B(){var e,t=v.token;switch(t.type){case"name":e=ue(wn);break;case"num":e=new zn({start:t,end:t,value:t.value});break;case"big_int":e=new Wn({start:t,end:t,value:t.value});break;case"string":e=new Xn({start:t,end:t,value:t.value,quote:t.quote});break;case"regexp":e=new Yn({start:t,end:t,value:t.value});break;case"atom":switch(t.value){case"false":e=new Si({start:t,end:t});break;case"true":e=new vi({start:t,end:t});break;case"null":e=new $n({start:t,end:t})}}return s(),e}function U(e,t,n,i){var r=function(e,t){return t?new Qt({start:e.start,left:e,operator:"=",right:t,end:t.end}):e};return e instanceof en?r(new pt({start:e.start,end:e.end,is_array:!1,names:e.properties.map(U)}),i):e instanceof nn?(e.value=U(e.value,0,[e.key]),r(e,i)):e instanceof Qn?e:e instanceof pt?(e.names=e.names.map(U),r(e,i)):e instanceof wn?r(new hn({name:e.name,start:e.start,end:e.end}),i):e instanceof at?(e.expression=U(e.expression),r(e,i)):e instanceof Jt?r(new pt({start:e.start,end:e.end,is_array:!0,names:e.elements.map(U)}),i):e instanceof Zt?r(U(e.left,void 0,void 0,e.right),i):e instanceof Qt?(e.left=U(e.left,0,[e.left]),e):void c("Invalid function parameter",e.start.line,e.start.col)}var K=function(e,t){if(r("operator","new"))return function(e){var t=v.token;if(p("operator","new"),r("punc","."))return s(),p("name","target"),Y(new fn({start:t,end:u()}),e);var i,o=K(!1);r("punc","(")?(s(),i=X(")",n.ecma>=8)):i=[];var a=new Ut({start:t,expression:o,args:i,end:u()});return pe(a),Y(a,e)}(e);var o,c=v.token,l=r("name","async")&&"["!=(o=a()).value&&"arrow"!=o.type&&B();if(r("punc")){switch(v.token.value){case"(":if(l&&!e)break;var d=function(e,t){var i,o,a,c=[];for(_("(");!r("punc",")");)i&&f(i),r("expand","...")?(i=v.token,t&&(o=v.token),s(),c.push(new at({start:u(),expression:fe(),end:v.token}))):c.push(fe()),r("punc",")")||(_(","),r("punc",")")&&(n.ecma<8&&f(),a=u(),t&&(o=a)));return _(")"),e&&r("arrow","=>")?i&&a&&f(a):o&&f(o),c}(t,!l);if(t&&r("arrow","=>"))return O(c,d.map(U),!!l);var m=l?new Kt({expression:l,args:d}):1==d.length?d[0]:new Gt({expressions:d});if(m.start){const e=c.comments_before.length;if(i.set(c,e),m.start.comments_before.unshift(...c.comments_before),c.comments_before=m.start.comments_before,0==e&&c.comments_before.length>0){var E=c.comments_before[0];E.nlb||(E.nlb=c.nlb,c.nlb=!1)}c.comments_after=m.start.comments_after}m.start=c;var h=u();return m.end&&(h.comments_before=m.end.comments_before,m.end.comments_after.push(...h.comments_after),h.comments_after=m.end.comments_after),m.end=h,m instanceof Kt&&pe(m),Y(m,e);case"[":return Y(G(),e);case"{":return Y(W(),e)}l||f()}if(t&&r("name")&&ee(a(),"arrow")){var D=new hn({name:v.token.value,start:c,end:c});return s(),O(c,[D],!!l)}if(r("keyword","function")){s();var g=F(ct,!1,!!l);return g.start=c,g.end=u(),Y(g,e)}if(l)return Y(l,e);if(r("keyword","class")){s();var A=q(cn);return A.start=c,A.end=u(),Y(A,e)}return r("template_head")?Y(H(),e):Le.has(v.token.type)?Y(B(),e):void f()};function H(e){var t=[],n=v.token;for(t.push(new mt({start:v.token,raw:v.token.raw,value:v.token.value,end:v.token}));!v.token.end;)s(),A(),t.push(fe(!0)),ee("template_substitution")||f(),t.push(new mt({start:v.token,raw:v.token.raw,value:v.token.value,end:v.token}));return s(),new dt({start:n,segments:t,end:v.token})}function X(e,t,n){for(var i=!0,o=[];!r("punc",e)&&(i?i=!1:_(","),!t||!r("punc",e));)r("punc",",")&&n?o.push(new Qn({start:v.token,end:v.token})):r("expand","...")?(s(),o.push(new at({start:u(),expression:fe(),end:v.token}))):o.push(fe(!1));return s(),o}var G=S(function(){return _("["),new Jt({elements:X("]",!n.strict,!0)})}),z=S((e,t)=>F(ut,e,t)),W=S(function(){var e=v.token,t=!0,i=[];for(_("{");!r("punc","}")&&(t?t=!1:_(","),n.strict||!r("punc","}"));)if("expand"!=(e=v.token).type){var o,a=te();if(r("punc",":"))null===a?f(u()):(s(),o=fe(!1));else{var c=$(a,e);if(c){i.push(c);continue}o=new wn({start:u(),name:a,end:u()})}r("operator","=")&&(s(),o=new Zt({start:e,left:o,operator:"=",right:fe(!1),end:u()})),i.push(new nn({start:e,quote:e.quote,key:a instanceof Pe?a:""+a,value:o,end:u()}))}else s(),i.push(new at({start:e,expression:fe(!1),end:u()}));return s(),new en({properties:i})});function q(e){var t,n,i,o,a=[];for(v.input.push_directives_stack(),v.input.add_directive("use strict"),"name"==v.token.type&&"extends"!=v.token.value&&(i=le(e===un?Tn:bn)),e!==un||i||f(),"extends"==v.token.value&&(s(),o=fe(!0)),_("{");r("punc",";");)s();for(;!r("punc","}");)for(t=v.token,(n=$(te(),t,!0))||f(),a.push(n);r("punc",";");)s();return v.input.pop_directives_stack(),s(),new e({start:t,name:i,extends:o,properties:a,end:u()})}function $(e,t,n){var i=function(e,t){return"string"==typeof e||"number"==typeof e?new gn({start:t,name:""+e,end:u()}):(null===e&&f(),e)},o=!1,a=!1,s=!1,c=t;if(n&&"static"===e&&!r("punc","(")&&(a=!0,c=v.token,e=te()),"async"!==e||r("punc","(")||r("punc",",")||r("punc","}")||r("operator","=")||(o=!0,c=v.token,e=te()),null===e&&(s=!0,c=v.token,null===(e=te())&&f()),r("punc","("))return e=i(e,t),new an({start:t,static:a,is_generator:s,async:o,key:e,quote:e instanceof gn?c.quote:void 0,value:z(s,o),end:u()});if(c=v.token,"get"==e){if(!r("punc")||r("punc","["))return e=i(te(),t),new on({start:t,static:a,key:e,quote:e instanceof gn?c.quote:void 0,value:z(),end:u()})}else if("set"==e&&(!r("punc")||r("punc","[")))return e=i(te(),t),new rn({start:t,static:a,key:e,quote:e instanceof gn?c.quote:void 0,value:z(),end:u()})}function j(e){function t(e){return new e({name:te(),start:u(),end:u()})}var n,i,o=e?Rn:Ln,a=e?Cn:xn,c=v.token;return e?n=t(o):i=t(a),r("name","as")?(s(),e?i=t(a):n=t(o)):e?i=new a(n):n=new o(i),new Lt({start:c,foreign_name:n,name:i,end:u()})}function Z(e,t){var n,i=e?Rn:Ln,r=e?Cn:xn,o=v.token,a=u();return t=t||new r({name:"*",start:o,end:a}),n=new i({name:"*",start:o,end:a}),new Lt({start:o,foreign_name:n,name:t,end:a})}function J(e){var t;if(r("punc","{")){for(s(),t=[];!r("punc","}");)t.push(j(e)),r("punc",",")&&s();s()}else if(r("operator","*")){var n;s(),e&&r("name","as")&&(s(),n=le(e?Cn:Ln)),t=[Z(e,n)]}return t}function te(){var e=v.token;switch(e.type){case"punc":if("["===e.value){s();var t=fe(!1);return _("]"),t}f(e);case"operator":if("*"===e.value)return s(),null;["delete","in","instanceof","new","typeof","void"].includes(e.value)||f(e);case"name":"yield"==e.value&&(E()?l(e,"Yield cannot be used as identifier inside generators"):ee(a(),"punc",":")||ee(a(),"punc","(")||!v.input.has_directive("use strict")||l(e,"Unexpected yield identifier inside strict mode"));case"string":case"num":case"big_int":case"keyword":case"atom":return s(),e.value;default:f(e)}}function ue(e){var t=v.token.value;return new("this"==t?Pn:"super"==t?Gn:e)({name:String(t),start:v.token,end:v.token})}function ce(e){var t=e.name;E()&&"yield"==t&&l(e.start,"Yield cannot be used as identifier inside generators"),v.input.has_directive("use strict")&&("yield"==t&&l(e.start,"Unexpected yield identifier inside strict mode"),e instanceof pn&&("arguments"==t||"eval"==t)&&l(e.start,"Unexpected "+t+" in strict mode"))}function le(e,t){if(!r("name"))return t||c("Name expected"),null;var n=ue(e);return ce(n),s(),n}function pe(e){var t=e.start,n=t.comments_before;const r=i.get(t);for(var o=null!=r?r:n.length;--o>=0;){var a=n[o];if(/[@#]__/.test(a.value)){if(/[@#]__PURE__/.test(a.value)){b(e,Ii);break}if(/[@#]__INLINE__/.test(a.value)){b(e,Li);break}if(/[@#]__NOINLINE__/.test(a.value)){b(e,Vi);break}}}}var Y=function(e,t){var n,i=e.start;if(r("punc","."))return s(),Y(new Xt({start:i,expression:e,property:(n=v.token,"name"!=n.type&&f(),s(),n.value),end:u()}),t);if(r("punc","[")){s();var o=fe(!0);return _("]"),Y(new zt({start:i,expression:e,property:o,end:u()}),t)}if(t&&r("punc","(")){s();var a=new Kt({start:i,expression:e,args:he(),end:u()});return pe(a),Y(a,!0)}return r("template_head")?Y(new _t({start:i,prefix:e,template_string:H(),end:u()}),t):e};function he(){for(var e=[];!r("punc",")");)r("expand","...")?(s(),e.push(new at({start:u(),expression:fe(!1),end:u()}))):e.push(fe(!1)),r("punc",")")||(_(","),r("punc",")")&&n.ecma<8&&f());return s(),e}var ie=function(e,t){var n=v.token;if("name"==n.type&&"await"==n.value){if(h())return s(),h()||c("Unexpected await expression outside async function",v.prev.line,v.prev.col,v.prev.pos),new Fi({start:u(),end:v.token,expression:ie(!0)});v.input.has_directive("use strict")&&l(v.token,"Unexpected await identifier inside strict mode")}if(r("operator")&&we.has(n.value)){s(),A();var i=Ae(Yt,n,ie(e));return i.start=n,i.end=u(),i}for(var o=K(e,t);r("operator")&&xe.has(v.token.value)&&!d(v.token);)o instanceof lt&&f(),(o=Ae(qt,v.token,o)).start=n,o.end=v.token,s();return o};function Ae(e,t,n){var i=t.value;switch(i){case"++":case"--":He(n)||c("Invalid use of "+i+" operator",t.line,t.col,t.pos);break;case"delete":n instanceof wn&&v.input.has_directive("use strict")&&c("Calling delete on expression not allowed in strict mode",n.start.line,n.start.col,n.start.pos)}return new e({operator:i,expression:n})}var re=function(e,t,n){var i=r("operator")?v.token.value:null;"in"==i&&n&&(i=null),"**"==i&&e instanceof Yt&&!ee(e.start,"punc","(")&&"--"!==e.operator&&"++"!==e.operator&&f(e.start);var o=null!=i?Ie[i]:null;if(null!=o&&(o>t||"**"===i&&t===o)){s();var a=re(ie(!0),o,n);return re(new $t({start:e.start,left:e,operator:i,right:a,end:a.end}),t,n)}return e};var oe=function(e){var t=v.token,n=function(e){return re(ie(!0,!0),0,e)}(e);if(r("operator","?")){s();var i=fe(!1);return _(":"),new jt({start:t,condition:n,consequent:i,alternative:fe(!1,e),end:u()})}return n};function He(e){return e instanceof Ht||e instanceof wn}function Xe(e){if(e instanceof en)e=new pt({start:e.start,names:e.properties.map(Xe),is_array:!1,end:e.end});else if(e instanceof Jt){for(var t=[],n=0;n=0;)o+="this."+t[a]+" = props."+t[a]+";";const s=i&&Object.create(i.prototype);(s&&s.initialize||n&&n.initialize)&&(o+="this.initialize();"),o+="}",o+="this.flags = 0;",o+="}";var u=new Function(o)();if(s&&(u.prototype=s,u.BASE=i),i&&i.SUBCLASSES.push(u),u.prototype.CTOR=u,u.PROPS=t||null,u.SELF_PROPS=r,u.SUBCLASSES=[],e&&(u.prototype.TYPE=u.TYPE=e),n)for(a in n)D(n,a)&&("$"===a[0]?u[a.substr(1)]=n[a]:u.prototype[a]=n[a]);return u.DEFMETHOD=function(e,t){this.prototype[e]=t},u}var Ve=ce("Token","type value line col pos endline endcol endpos nlb comments_before comments_after file raw quote end",{},null),Pe=ce("Node","start end",{_clone:function(e){if(e){var t=this.clone();return t.transform(new vn(function(e){if(e!==t)return e.clone(!0)}))}return new this.CTOR(this)},clone:function(e){return this._clone(e)},$documentation:"Base class of all AST nodes",$propdoc:{start:"[AST_Token] The first token of this node",end:"[AST_Token] The last token of this node"},_walk:function(e){return e._visit(this)},walk:function(e){return this._walk(e)}},null);Pe.warn_function=null,Pe.warn=function(e,t){Pe.warn_function&&Pe.warn_function(_(e,t))};var Be=ce("Statement",null,{$documentation:"Base class of all statements"}),Ke=ce("Debugger",null,{$documentation:"Represents a debugger statement"},Be),Ue=ce("Directive","value quote",{$documentation:'Represents a directive, like "use strict";',$propdoc:{value:"[string] The value of this directive as a plain string (it's not an AST_String!)",quote:"[string] the original quote character"}},Be),Ge=ce("SimpleStatement","body",{$documentation:"A statement consisting of an expression, i.e. a = 1 + 2",$propdoc:{body:"[AST_Node] an expression node (should not be instanceof AST_Statement)"},_walk:function(e){return e._visit(this,function(){this.body._walk(e)})}},Be);function Ee(e,t){var n=e.body;if(n instanceof Pe)n._walk(t);else for(var i=0,r=n.length;i SymbolDef for all variables/functions defined in this scope",functions:"[Map/S] like `variables`, but only lists function declarations",uses_with:"[boolean/S] tells whether this scope uses the `with` statement",uses_eval:"[boolean/S] tells whether this scope contains a direct call to the global `eval`",parent_scope:"[AST_Scope?/S] link to the parent scope",enclosed:"[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",cname:"[integer/S] current index for mangling variables (used internally by the mangler)"},get_defun_scope:function(){for(var e=this;e.is_block_scope();)e=e.parent_scope;return e},clone:function(e){var t=this._clone(e);return this.variables&&(t.variables=new Map(this.variables)),this.functions&&(t.functions=new Map(this.functions)),this.enclosed&&(t.enclosed=this.enclosed.slice()),t},pinned:function(){return this.uses_eval||this.uses_with}},ze),ot=ce("Toplevel","globals",{$documentation:"The toplevel scope",$propdoc:{globals:"[Map/S] a map of name -> SymbolDef for all undeclared names"},wrap_commonjs:function(e){var t=this.body,n="(function(exports){'$ORIG';})(typeof "+e+"=='undefined'?("+e+"={}):"+e+");";return n=(n=ue(n)).transform(new vn(function(e){if(e instanceof Ue&&"$ORIG"==e.value)return F.splice(t)}))},wrap_enclose:function(e){"string"!=typeof e&&(e="");var t=e.indexOf(":");t<0&&(t=e.length);var n=this.body;return ue(["(function(",e.slice(0,t),'){"$ORIG"})(',e.slice(t+1),")"].join("")).transform(new vn(function(e){if(e instanceof Ue&&"$ORIG"==e.value)return F.splice(n)}))}},rt),at=ce("Expansion","expression",{$documentation:"An expandible argument, such as ...rest, a splat, such as [1,2,...all], or an expansion in a variable declaration, such as var [first, ...rest] = list",$propdoc:{expression:"[AST_Node] the thing to be expanded"},_walk:function(e){var t=this;return e._visit(this,function(){t.expression.walk(e)})}}),st=ce("Lambda","name argnames uses_arguments is_generator async",{$documentation:"Base class for functions",$propdoc:{name:"[AST_SymbolDeclaration?] the name of this function",argnames:"[AST_SymbolFunarg|AST_Destructuring|AST_Expansion|AST_DefaultAssign*] array of function arguments, destructurings, or expanding arguments",uses_arguments:"[boolean/S] tells whether this function accesses the arguments array",is_generator:"[boolean] is this a generator method",async:"[boolean] is this method async"},args_as_names:function(){for(var e=[],t=0;t b)"},st),ft=ce("Defun",null,{$documentation:"A function definition"},st),pt=ce("Destructuring","names is_array",{$documentation:"A destructuring of several names. Used in destructuring assignment and with destructuring function argument names",$propdoc:{names:"[AST_Node*] Array of properties or elements",is_array:"[Boolean] Whether the destructuring represents an object or array"},_walk:function(e){return e._visit(this,function(){this.names.forEach(function(t){t._walk(e)})})},all_symbols:function(){var e=[];return this.walk(new An(function(t){t instanceof ln&&e.push(t)})),e}}),_t=ce("PrefixedTemplateString","template_string prefix",{$documentation:"A templatestring with a prefix, such as String.raw`foobarbaz`",$propdoc:{template_string:"[AST_TemplateString] The template string",prefix:"[AST_SymbolRef|AST_PropAccess] The prefix, which can be a symbol such as `foo` or a dotted expression such as `String.raw`."},_walk:function(e){this.prefix._walk(e),this.template_string._walk(e)}}),dt=ce("TemplateString","segments",{$documentation:"A template string literal",$propdoc:{segments:"[AST_Node*] One or more segments, starting with AST_TemplateSegment. AST_Node may follow AST_TemplateSegment, but each AST_Node must be followed by AST_TemplateSegment."},_walk:function(e){return e._visit(this,function(){this.segments.forEach(function(t){t._walk(e)})})}}),mt=ce("TemplateSegment","value raw",{$documentation:"A segment of a template string literal",$propdoc:{value:"Content of the segment",raw:"Raw content of the segment"}}),Et=ce("Jump",null,{$documentation:"Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"},Be),ht=ce("Exit","value",{$documentation:"Base class for “exits” (`return` and `throw`)",$propdoc:{value:"[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"},_walk:function(e){return e._visit(this,this.value&&function(){this.value._walk(e)})}},Et),gt=ce("Return",null,{$documentation:"A `return` statement"},ht),At=ce("Throw",null,{$documentation:"A `throw` statement"},ht),St=ce("LoopControl","label",{$documentation:"Base class for loop control statements (`break` and `continue`)",$propdoc:{label:"[AST_LabelRef?] the label, or null if none"},_walk:function(e){return e._visit(this,this.label&&function(){this.label._walk(e)})}},Et),vt=ce("Break",null,{$documentation:"A `break` statement"},St),Tt=ce("Continue",null,{$documentation:"A `continue` statement"},St),bt=ce("If","condition alternative",{$documentation:"A `if` statement",$propdoc:{condition:"[AST_Node] the `if` condition",alternative:"[AST_Statement?] the `else` part, or null if not present"},_walk:function(e){return e._visit(this,function(){this.condition._walk(e),this.body._walk(e),this.alternative&&this.alternative._walk(e)})}},qe),yt=ce("Switch","expression",{$documentation:"A `switch` statement",$propdoc:{expression:"[AST_Node] the `switch` “discriminant”"},_walk:function(e){return e._visit(this,function(){this.expression._walk(e),Ee(this,e)})}},ze),Ct=ce("SwitchBranch",null,{$documentation:"Base class for `switch` branches"},ze),Ot=ce("Default",null,{$documentation:"A `default` switch branch"},Ct),Ft=ce("Case","expression",{$documentation:"A `case` switch branch",$propdoc:{expression:"[AST_Node] the `case` expression"},_walk:function(e){return e._visit(this,function(){this.expression._walk(e),Ee(this,e)})}},Ct),Mt=ce("Try","bcatch bfinally",{$documentation:"A `try` statement",$propdoc:{bcatch:"[AST_Catch?] the catch block, or null if not present",bfinally:"[AST_Finally?] the finally block, or null if not present"},_walk:function(e){return e._visit(this,function(){Ee(this,e),this.bcatch&&this.bcatch._walk(e),this.bfinally&&this.bfinally._walk(e)})}},ze),Rt=ce("Catch","argname",{$documentation:"A `catch` node; only makes sense as part of a `try` statement",$propdoc:{argname:"[AST_SymbolCatch|AST_Destructuring|AST_Expansion|AST_DefaultAssign] symbol for the exception"},_walk:function(e){return e._visit(this,function(){this.argname&&this.argname._walk(e),Ee(this,e)})}},ze),Nt=ce("Finally",null,{$documentation:"A `finally` node; only makes sense as part of a `try` statement"},ze),wt=ce("Definitions","definitions",{$documentation:"Base class for `var` or `const` nodes (variable declarations/initializations)",$propdoc:{definitions:"[AST_VarDef*] array of variable definitions"},_walk:function(e){return e._visit(this,function(){for(var t=this.definitions,n=0,i=t.length;n a`"},$t),Jt=ce("Array","elements",{$documentation:"An array literal",$propdoc:{elements:"[AST_Node*] array of elements"},_walk:function(e){return e._visit(this,function(){for(var t=this.elements,n=0,i=t.length;nt._walk(e))})}},rt),un=ce("DefClass",null,{$documentation:"A class definition"},sn),cn=ce("ClassExpression",null,{$documentation:"A class expression."},sn),ln=ce("Symbol","scope name thedef",{$propdoc:{name:"[string] name of this symbol",scope:"[AST_Scope/S] the current scope (not necessarily the definition scope)",thedef:"[SymbolDef/S] the definition of this symbol"},$documentation:"Base class for all symbols"}),fn=ce("NewTarget",null,{$documentation:"A reference to new.target"}),pn=ce("SymbolDeclaration","init",{$documentation:"A declaration symbol (symbol in var/const, function name or argument, symbol in catch)"},ln),_n=ce("SymbolVar",null,{$documentation:"Symbol defining a variable"},pn),dn=ce("SymbolBlockDeclaration",null,{$documentation:"Base class for block-scoped declaration symbols"},pn),mn=ce("SymbolConst",null,{$documentation:"A constant declaration"},dn),En=ce("SymbolLet",null,{$documentation:"A block-scoped `let` declaration"},dn),hn=ce("SymbolFunarg",null,{$documentation:"Symbol naming a function argument"},_n),Dn=ce("SymbolDefun",null,{$documentation:"Symbol defining a function"},pn),gn=ce("SymbolMethod",null,{$documentation:"Symbol in an object defining a method"},ln),Sn=ce("SymbolLambda",null,{$documentation:"Symbol naming a function expression"},pn),Tn=ce("SymbolDefClass",null,{$documentation:"Symbol naming a class's name in a class declaration. Lexically scoped to its containing scope, and accessible within the class."},dn),bn=ce("SymbolClass",null,{$documentation:"Symbol naming a class's name. Lexically scoped to the class."},pn),yn=ce("SymbolCatch",null,{$documentation:"Symbol naming the exception in catch"},dn),Cn=ce("SymbolImport",null,{$documentation:"Symbol referring to an imported name"},dn),Rn=ce("SymbolImportForeign",null,{$documentation:"A symbol imported from a module, but it is defined in the other module, and its real name is irrelevant for this module's purposes"},ln),Nn=ce("Label","references",{$documentation:"Symbol naming a label (declaration)",$propdoc:{references:"[AST_LoopControl*] a list of nodes referring to this label"},initialize:function(){this.references=[],this.thedef=this}},ln),wn=ce("SymbolRef",null,{$documentation:"Reference to some symbol (not definition/declaration)"},ln),xn=ce("SymbolExport",null,{$documentation:"Symbol referring to a name to export"},wn),Ln=ce("SymbolExportForeign",null,{$documentation:"A symbol exported from this module, but it is used in the other module, and its real name is irrelevant for this module's purposes"},ln),Vn=ce("LabelRef",null,{$documentation:"Reference to a label symbol"},ln),Pn=ce("This",null,{$documentation:"The `this` symbol"},ln),Gn=ce("Super",null,{$documentation:"The `super` symbol"},Pn),Hn=ce("Constant",null,{$documentation:"Base class for all constants",getValue:function(){return this.value}}),Xn=ce("String","value quote",{$documentation:"A string literal",$propdoc:{value:"[string] the contents of this string",quote:"[string] the original quote character"}},Hn),zn=ce("Number","value literal",{$documentation:"A number literal",$propdoc:{value:"[number] the numeric value",literal:"[string] numeric value as string (optional)"}},Hn),Wn=ce("BigInt","value",{$documentation:"A big int literal",$propdoc:{value:"[string] big int value"}},Hn),Yn=ce("RegExp","value",{$documentation:"A regexp literal",$propdoc:{value:"[RegExp] the actual regexp"}},Hn),qn=ce("Atom",null,{$documentation:"Base class for atoms"},Hn),$n=ce("Null",null,{$documentation:"The `null` atom",value:null},qn),jn=ce("NaN",null,{$documentation:"The impossible value",value:NaN},qn),Zn=ce("Undefined",null,{$documentation:"The `undefined` value",value:void 0},qn),Qn=ce("Hole",null,{$documentation:"A hole in an array",value:void 0},qn),Jn=ce("Infinity",null,{$documentation:"The `Infinity` value",value:1/0},qn),Ai=ce("Boolean",null,{$documentation:"Base class for booleans"},qn),Si=ce("False",null,{$documentation:"The `false` atom",value:!1},Ai),vi=ce("True",null,{$documentation:"The `true` atom",value:!0},Ai),Fi=ce("Await","expression",{$documentation:"An `await` statement",$propdoc:{expression:"[AST_Node] the mandatory expression being awaited"},_walk:function(e){return e._visit(this,function(){this.expression._walk(e)})}}),Mi=ce("Yield","expression is_star",{$documentation:"A `yield` statement",$propdoc:{expression:"[AST_Node?] the value returned or thrown by this statement; could be null (representing undefined) but only when is_star is set to false",is_star:"[Boolean] Whether this is a yield or yield* statement"},_walk:function(e){return e._visit(this,this.expression&&function(){this.expression._walk(e)})}});class An{constructor(e){this.visit=e,this.stack=[],this.directives=Object.create(null)}_visit(e,t){this.push(e);var n=this.visit(e,t?function(){t.call(e)}:a);return!n&&t&&t.call(e),this.pop(),n}parent(e){return this.stack[this.stack.length-2-(e||0)]}push(e){e instanceof st?this.directives=Object.create(this.directives):e instanceof Ue&&!this.directives[e.value]?this.directives[e.value]=e:e instanceof sn&&(this.directives=Object.create(this.directives),this.directives["use strict"]||(this.directives["use strict"]=e)),this.stack.push(e)}pop(){var e=this.stack.pop();(e instanceof st||e instanceof sn)&&(this.directives=Object.getPrototypeOf(this.directives))}self(){return this.stack[this.stack.length-1]}find_parent(e){for(var t=this.stack,n=t.length;--n>=0;){var i=t[n];if(i instanceof e)return i}}has_directive(e){var t=this.directives[e];if(t)return t;var n=this.stack[this.stack.length-1];if(n instanceof rt&&n.body)for(var i=0;i=0;){if((i=t[n])instanceof $e&&i.label.name==e.label.name)return i.body}else for(n=t.length;--n>=0;){var i;if((i=t[n])instanceof je||e instanceof vt&&i instanceof yt)return i}}}class vn extends An{constructor(e,t){super(),this.before=e,this.after=t}}const Ii=1,Li=2,Vi=4;var Pi=Object.freeze({__proto__:null,AST_Accessor:ut,AST_Array:Jt,AST_Arrow:lt,AST_Assign:Zt,AST_Atom:qn,AST_Await:Fi,AST_BigInt:Wn,AST_Binary:$t,AST_Block:ze,AST_BlockStatement:We,AST_Boolean:Ai,AST_Break:vt,AST_Call:Kt,AST_Case:Ft,AST_Catch:Rt,AST_Class:sn,AST_ClassExpression:cn,AST_ConciseMethod:an,AST_Conditional:jt,AST_Const:It,AST_Constant:Hn,AST_Continue:Tt,AST_Debugger:Ke,AST_Default:Ot,AST_DefaultAssign:Qt,AST_DefClass:un,AST_Definitions:wt,AST_Defun:ft,AST_Destructuring:pt,AST_Directive:Ue,AST_Do:Qe,AST_Dot:Xt,AST_DWLoop:Ze,AST_EmptyStatement:Ye,AST_Exit:ht,AST_Expansion:at,AST_Export:Pt,AST_False:Si,AST_Finally:Nt,AST_For:et,AST_ForIn:tt,AST_ForOf:nt,AST_Function:ct,AST_Hole:Qn,AST_If:bt,AST_Import:Vt,AST_Infinity:Jn,AST_IterationStatement:je,AST_Jump:Et,AST_Label:Nn,AST_LabeledStatement:$e,AST_LabelRef:Vn,AST_Lambda:st,AST_Let:kt,AST_LoopControl:St,AST_NameMapping:Lt,AST_NaN:jn,AST_New:Ut,AST_NewTarget:fn,AST_Node:Pe,AST_Null:$n,AST_Number:zn,AST_Object:en,AST_ObjectGetter:on,AST_ObjectKeyVal:nn,AST_ObjectProperty:tn,AST_ObjectSetter:rn,AST_PrefixedTemplateString:_t,AST_PropAccess:Ht,AST_RegExp:Yn,AST_Return:gt,AST_Scope:rt,AST_Sequence:Gt,AST_SimpleStatement:Ge,AST_Statement:Be,AST_StatementWithBody:qe,AST_String:Xn,AST_Sub:zt,AST_Super:Gn,AST_Switch:yt,AST_SwitchBranch:Ct,AST_Symbol:ln,AST_SymbolBlockDeclaration:dn,AST_SymbolCatch:yn,AST_SymbolClass:bn,AST_SymbolConst:mn,AST_SymbolDeclaration:pn,AST_SymbolDefClass:Tn,AST_SymbolDefun:Dn,AST_SymbolExport:xn,AST_SymbolExportForeign:Ln,AST_SymbolFunarg:hn,AST_SymbolImport:Cn,AST_SymbolImportForeign:Rn,AST_SymbolLambda:Sn,AST_SymbolLet:En,AST_SymbolMethod:gn,AST_SymbolRef:wn,AST_SymbolVar:_n,AST_TemplateSegment:mt,AST_TemplateString:dt,AST_This:Pn,AST_Throw:At,AST_Token:Ve,AST_Toplevel:ot,AST_True:vi,AST_Try:Mt,AST_Unary:Wt,AST_UnaryPostfix:qt,AST_UnaryPrefix:Yt,AST_Undefined:Zn,AST_Var:xt,AST_VarDef:Bt,AST_While:Je,AST_With:it,AST_Yield:Mi,TreeTransformer:vn,TreeWalker:An,walk_body:Ee,_INLINE:Li,_NOINLINE:Vi,_PURE:Ii});function On(e,t){e.DEFMETHOD("transform",function(e,n){let i=void 0;if(e.push(this),e.before&&(i=e.before(this,t,n)),void 0===i&&(t(i=this,e),e.after)){const t=e.after(i,n);void 0!==t&&(i=t)}return e.pop(),i})}function Fn(e,t){return F(e,function(e){return e.transform(t,!0)})}function Mn(e){let t=e.parent(-1);for(let n,i=0;n=e.parent(i);i++){if(n instanceof Be&&n.body===t)return!0;if(!(n instanceof Gt&&n.expressions[0]===t||"Call"===n.TYPE&&n.expression===t||n instanceof _t&&n.prefix===t||n instanceof Xt&&n.expression===t||n instanceof zt&&n.expression===t||n instanceof jt&&n.condition===t||n instanceof $t&&n.left===t||n instanceof qt&&n.expression===t))return!1;t=n}}On(Pe,a),On($e,function(e,t){e.label=e.label.transform(t),e.body=e.body.transform(t)}),On(Ge,function(e,t){e.body=e.body.transform(t)}),On(ze,function(e,t){e.body=Fn(e.body,t)}),On(Qe,function(e,t){e.body=e.body.transform(t),e.condition=e.condition.transform(t)}),On(Je,function(e,t){e.condition=e.condition.transform(t),e.body=e.body.transform(t)}),On(et,function(e,t){e.init&&(e.init=e.init.transform(t)),e.condition&&(e.condition=e.condition.transform(t)),e.step&&(e.step=e.step.transform(t)),e.body=e.body.transform(t)}),On(tt,function(e,t){e.init=e.init.transform(t),e.object=e.object.transform(t),e.body=e.body.transform(t)}),On(it,function(e,t){e.expression=e.expression.transform(t),e.body=e.body.transform(t)}),On(ht,function(e,t){e.value&&(e.value=e.value.transform(t))}),On(St,function(e,t){e.label&&(e.label=e.label.transform(t))}),On(bt,function(e,t){e.condition=e.condition.transform(t),e.body=e.body.transform(t),e.alternative&&(e.alternative=e.alternative.transform(t))}),On(yt,function(e,t){e.expression=e.expression.transform(t),e.body=Fn(e.body,t)}),On(Ft,function(e,t){e.expression=e.expression.transform(t),e.body=Fn(e.body,t)}),On(Mt,function(e,t){e.body=Fn(e.body,t),e.bcatch&&(e.bcatch=e.bcatch.transform(t)),e.bfinally&&(e.bfinally=e.bfinally.transform(t))}),On(Rt,function(e,t){e.argname&&(e.argname=e.argname.transform(t)),e.body=Fn(e.body,t)}),On(wt,function(e,t){e.definitions=Fn(e.definitions,t)}),On(Bt,function(e,t){e.name=e.name.transform(t),e.value&&(e.value=e.value.transform(t))}),On(pt,function(e,t){e.names=Fn(e.names,t)}),On(st,function(e,t){e.name&&(e.name=e.name.transform(t)),e.argnames=Fn(e.argnames,t),e.body instanceof Pe?e.body=e.body.transform(t):e.body=Fn(e.body,t)}),On(Kt,function(e,t){e.expression=e.expression.transform(t),e.args=Fn(e.args,t)}),On(Gt,function(e,t){const n=Fn(e.expressions,t);e.expressions=n.length?n:[new zn({value:0})]}),On(Xt,function(e,t){e.expression=e.expression.transform(t)}),On(zt,function(e,t){e.expression=e.expression.transform(t),e.property=e.property.transform(t)}),On(Mi,function(e,t){e.expression&&(e.expression=e.expression.transform(t))}),On(Fi,function(e,t){e.expression=e.expression.transform(t)}),On(Wt,function(e,t){e.expression=e.expression.transform(t)}),On($t,function(e,t){e.left=e.left.transform(t),e.right=e.right.transform(t)}),On(jt,function(e,t){e.condition=e.condition.transform(t),e.consequent=e.consequent.transform(t),e.alternative=e.alternative.transform(t)}),On(Jt,function(e,t){e.elements=Fn(e.elements,t)}),On(en,function(e,t){e.properties=Fn(e.properties,t)}),On(tn,function(e,t){e.key instanceof Pe&&(e.key=e.key.transform(t)),e.value=e.value.transform(t)}),On(sn,function(e,t){e.name&&(e.name=e.name.transform(t)),e.extends&&(e.extends=e.extends.transform(t)),e.properties=Fn(e.properties,t)}),On(at,function(e,t){e.expression=e.expression.transform(t)}),On(Lt,function(e,t){e.foreign_name=e.foreign_name.transform(t),e.name=e.name.transform(t)}),On(Vt,function(e,t){e.imported_name&&(e.imported_name=e.imported_name.transform(t)),e.imported_names&&Fn(e.imported_names,t),e.module_name=e.module_name.transform(t)}),On(Pt,function(e,t){e.exported_definition&&(e.exported_definition=e.exported_definition.transform(t)),e.exported_value&&(e.exported_value=e.exported_value.transform(t)),e.exported_names&&Fn(e.exported_names,t),e.module_name&&(e.module_name=e.module_name.transform(t))}),On(dt,function(e,t){e.segments=Fn(e.segments,t)}),On(_t,function(e,t){e.prefix=e.prefix.transform(t),e.template_string=e.template_string.transform(t)});const Bi=/^$|[;{][\s\n]*$/,Ui=10,Hi=32,Wi=/[@#]__(PURE|INLINE|NOINLINE)__/g;function kn(e){return"comment2"==e.type&&/@preserve|@lic|@cc_on|^\**!/i.test(e.value)}function In(e){var t=!e;void 0===(e=o(e,{ascii_only:!1,beautify:!1,braces:!1,comments:"some",ecma:5,ie8:!1,indent_level:4,indent_start:0,inline_script:!0,keep_quoted_props:!1,max_line_len:!1,preamble:null,quote_keys:!1,quote_style:0,safari10:!1,semicolons:!0,shebang:!0,shorthand:void 0,source_map:null,webkit:!1,width:80,wrap_iife:!1,wrap_func_args:!0},!0)).shorthand&&(e.shorthand=e.ecma>5);var n=s;if(e.comments){let t=e.comments;if("string"==typeof e.comments&&/^\/.*\/[a-zA-Z]*$/.test(e.comments)){var i=e.comments.lastIndexOf("/");t=new RegExp(e.comments.substr(1,i-1),e.comments.substr(i+1))}n=t instanceof RegExp?function(e){return"comment5"!=e.type&&t.test(e.value)}:"function"==typeof t?function(e){return"comment5"!=e.type&&t(this,e)}:"some"===t?kn:u}var r=0,c=0,l=1,f=0,p="";let _=new Set;var d=e.ascii_only?function(t,n){return e.ecma>=6&&(t=t.replace(/[\ud800-\udbff][\udc00-\udfff]/g,function(e){return"\\u{"+function(e,t){return z(e.charAt(t))?65536+(e.charCodeAt(t)-55296<<10)+e.charCodeAt(t+1)-56320:e.charCodeAt(t)}(e,0).toString(16)+"}"})),t.replace(/[\u0000-\u001f\u007f-\uffff]/g,function(e){var t=e.charCodeAt(0).toString(16);if(t.length<=2&&!n){for(;t.length<2;)t="0"+t;return"\\x"+t}for(;t.length<4;)t="0"+t;return"\\u"+t})}:function(e){for(var t="",n=0,i=e.length;nr?o():a()}}(t,n);return e.inline_script&&(i=(i=(i=i.replace(/<\x2f(script)([>\/\t\n\f\r ])/gi,"<\\/$1$2")).replace(/\x3c!--/g,"\\x3c!--")).replace(/--\x3e/g,"--\\x3e")),i}var h,D,g=!1,A=!1,S=!1,v=0,T=!1,b=!1,y=-1,C="",O=e.source_map&&[],F=O?function(){O.forEach(function(t){try{e.source_map.add(t.token.file,t.line,t.col,t.token.line,t.token.col,t.name||"name"!=t.token.type?t.name:t.token.value)}catch(e){null!=t.token.file&&Pe.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]",{file:t.token.file,line:t.token.line,col:t.token.col,cline:t.line,ccol:t.col,name:t.name||""})}}),O=[]}:a,M=e.max_line_len?function(){if(c>e.max_line_len){if(v){var t=p.slice(0,v),n=p.slice(v);if(O){var i=n.length-c;O.forEach(function(e){e.line++,e.col+=i})}p=t+"\n"+n,l++,f++,c=n.length}c>e.max_line_len&&Pe.warn("Output exceeds {max_line_len} characters",e)}v&&(v=0,F())}:a,R=E("( [ + * / - , . `");function N(t){var n=X(t=String(t),0);T&&n&&(T=!1,"\n"!==n&&(N("\n"),x())),b&&n&&(b=!1,/[\s;})]/.test(n)||w()),y=-1;var i=C.charAt(C.length-1);S&&(S=!1,(":"!==i||"}"!==n)&&(n&&";}".includes(n)||";"===i)||(e.semicolons||R.has(n)?(p+=";",c++,f++):(M(),c>0&&(p+="\n",f++,l++,c=0),/^\s+$/.test(t)&&(S=!0)),e.beautify||(A=!1))),A&&(($(i)&&($(n)||"\\"==n)||"/"==n&&n==i||("+"==n||"-"==n)&&n==C)&&(p+=" ",c++,f++),A=!1),h&&(O.push({token:h,name:D,line:l,col:c}),h=!1,v||F()),p+=t,g="("==t[t.length-1],f+=t.length;var r=t.split(/\r?\n/),o=r.length-1;l+=o,c+=r[0].length,o>0&&(M(),c=r[o].length),C=t}var w=e.beautify?function(){N(" ")}:function(){A=!0},x=e.beautify?function(t){var n;e.beautify&&N((n=t?.5:0," ".repeat(e.indent_start+r-n*e.indent_level)))}:a,k=e.beautify?function(e,t){!0===e&&(e=P());var n=r;r=e;var i=t();return r=n,i}:function(e,t){return t()},I=e.beautify?function(){if(y<0)return N("\n");"\n"!=p[y]&&(p=p.slice(0,y)+"\n"+p.slice(y),f++,l++),y++}:e.max_line_len?function(){M(),v=p.length}:a,L=e.beautify?function(){N(";")}:function(){S=!0};function V(){S=!1,N(";")}function P(){return r+e.indent_level}function B(){return v&&M(),p}function K(){let e=p.length-1;for(;e>=0;){const t=p.charCodeAt(e);if(t===Ui)return!0;if(t!==Hi)return!1;e--}return!0}var U=[];return{get:B,toString:B,indent:x,indentation:function(){return r},current_width:function(){return c-r},should_break:function(){return e.width&&this.current_width()>=e.width},has_parens:function(){return g},newline:I,print:N,star:function(){N("*")},space:w,comma:function(){N(","),w()},colon:function(){N(":"),w()},last:function(){return C},semicolon:L,force_semicolon:V,to_utf8:d,print_name:function(e){N(function(e){return e=e.toString(),e=d(e,!0)}(e))},print_string:function(e,t,n){var i=m(e,t);!0!==n||i.includes("\\")||(Bi.test(p)||V(),V()),N(i)},print_template_string_chars:function(e){var t=m(e,"`").replace(/\${/g,"\\${");return N(t.substr(1,t.length-2))},encode_string:m,next_indent:P,with_indent:k,with_block:function(e){var t;return N("{"),I(),k(P(),function(){t=e()}),x(),N("}"),t},with_parens:function(e){N("(");var t=e();return N(")"),t},with_square:function(e){N("[");var t=e();return N("]"),t},add_mapping:O?function(e,t){h=e,D=t}:a,option:function(t){return e[t]},printed_comments:_,prepend_comments:t?a:function(t){var i=t.start;if(i){var r=this.printed_comments;if(!i.comments_before||!r.has(i.comments_before)){var o=i.comments_before;if(o||(o=i.comments_before=[]),r.add(o),t instanceof ht&&t.value){var a=new An(function(e){var t=a.parent();if(!(t instanceof ht||t instanceof $t&&t.left===e||"Call"==t.TYPE&&t.expression===e||t instanceof jt&&t.condition===e||t instanceof Xt&&t.expression===e||t instanceof Gt&&t.expressions[0]===e||t instanceof zt&&t.expression===e||t instanceof qt))return!0;if(e.start){var n=e.start.comments_before;n&&!r.has(n)&&(r.add(n),o=o.concat(n))}});a.push(t),t.value.walk(a)}if(0==f){o.length>0&&e.shebang&&"comment5"===o[0].type&&!r.has(o[0])&&(N("#!"+o.shift().value+"\n"),x());var s=e.preamble;s&&N(s.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g,"\n"))}if(0!=(o=o.filter(n,t).filter(e=>!r.has(e))).length){var u=K();o.forEach(function(e,t){r.add(e),u||(e.nlb?(N("\n"),x(),u=!0):t>0&&w()),/comment[134]/.test(e.type)?(N("//"+e.value.replace(Wi," ")+"\n"),x(),u=!0):"comment2"==e.type&&(N("/*"+e.value.replace(Wi," ")+"*/"),u=!1)}),u||(i.nlb?(N("\n"),x()):w())}}}},append_comments:t||n===s?a:function(e,t){var i=e.end;if(i){var r=this.printed_comments,o=i[t?"comments_before":"comments_after"];if(o&&!r.has(o)&&(e instanceof Be||o.every(e=>!/comment[134]/.test(e.type)))){r.add(o);var a=p.length;o.filter(n,e).forEach(function(e,n){r.has(e)||(r.add(e),b=!1,T?(N("\n"),x(),T=!1):e.nlb&&(n>0||!K())?(N("\n"),x()):(n>0||!t)&&w(),/comment[134]/.test(e.type)?(N("//"+e.value.replace(Wi," ")),T=!0):"comment2"==e.type&&(N("/*"+e.value.replace(Wi," ")+"*/"),b=!0))}),p.length>a&&(y=a)}}},line:function(){return l},col:function(){return c},pos:function(){return f},push_node:function(e){U.push(e)},pop_node:function(){return U.pop()},parent:function(e){return U[U.length-2-(e||0)]}}}!function(){function e(e,t){e.DEFMETHOD("_codegen",t)}var t=!1,i=null,E=null;function r(e,t){Array.isArray(e)?e.forEach(function(e){r(e,t)}):e.DEFMETHOD("needs_parens",t)}function o(e,n,i,r){var o=e.length-1;t=r,e.forEach(function(e,r){!0!==t||e instanceof Ue||e instanceof Ye||e instanceof Ge&&e.body instanceof Xn||(t=!1),e instanceof Ye||(i.indent(),e.print(i),r==o&&n||(i.newline(),n&&i.newline())),!0===t&&e instanceof Ge&&e.body instanceof Xn&&(t=!1)}),t=!1}function u(e,t){t.print("{"),t.with_indent(t.next_indent(),function(){t.append_comments(e,!0)}),t.print("}")}function c(e,t,n){e.body.length>0?t.with_block(function(){o(e.body,!1,t,n)}):u(e,t)}function l(e,t,n){var i=!1;n&&e.walk(new An(function(e){return!!(i||e instanceof rt)||(e instanceof $t&&"in"==e.operator?(i=!0,!0):void 0)})),e.print(t,i)}function f(e,t,n){n.option("quote_keys")?n.print_string(e):""+ +e==e&&e>=0?n.print(_(e)):(se.has(e)?!n.option("ie8"):j(e))?t&&n.option("keep_quoted_props")?n.print_string(e,t):n.print_name(e):n.print_string(e,t)}function p(e,t){t.option("braces")?d(e,t):!e||e instanceof Ye?t.force_semicolon():e.print(t)}function _(e){var t,n,i,r=e.toString(10).replace(/^0\./,".").replace("e+","e"),o=[r];return Math.floor(e)===e&&(e<0?o.push("-0x"+(-e).toString(16).toLowerCase()):o.push("0x"+e.toString(16).toLowerCase())),(t=/^\.0+/.exec(r))?(n=t[0].length,i=r.slice(n),o.push(i+"e-"+(i.length+n-1))):(t=/0+$/.exec(r))?(n=t[0].length,o.push(r.slice(0,-n)+"e"+n)):(t=/^(\d)\.(\d+)e(-?\d+)$/.exec(r))&&o.push(t[1]+t[2]+"e"+(t[3]-t[2].length)),function(e){for(var t=e[0],n=t.length,i=1;io||i==o&&(this===t.right||"**"==n))return!0}}),r(Mi,function(e){var t=e.parent();return t instanceof $t&&"="!==t.operator||(t instanceof Kt&&t.expression===this||(t instanceof jt&&t.condition===this||(t instanceof Wt||(t instanceof Ht&&t.expression===this||void 0))))}),r(Ht,function(e){var t=e.parent();if(t instanceof Ut&&t.expression===this){var n=!1;return this.walk(new An(function(e){return!!(n||e instanceof rt)||(e instanceof Kt?(n=!0,!0):void 0)})),n}}),r(Kt,function(e){var t,n=e.parent();return!!(n instanceof Ut&&n.expression===this||n instanceof Pt&&n.is_default&&this.expression instanceof ct)||this.expression instanceof ct&&n instanceof Ht&&n.expression===this&&(t=e.parent(1))instanceof Zt&&t.left===n}),r(Ut,function(e){var t=e.parent();if(0===this.args.length&&(t instanceof Ht||t instanceof Kt&&t.expression===this))return!0}),r(zn,function(e){var t=e.parent();if(t instanceof Ht&&t.expression===this){var n=this.getValue();if(n<0||/^0/.test(_(n)))return!0}}),r(Wn,function(e){var t=e.parent();if(t instanceof Ht&&t.expression===this&&this.getValue().startsWith("-"))return!0}),r([Zt,jt],function(e){var t=e.parent();return t instanceof Wt||(t instanceof $t&&!(t instanceof Zt)||(t instanceof Kt&&t.expression===this||(t instanceof jt&&t.condition===this||(t instanceof Ht&&t.expression===this||(this instanceof Zt&&this.left instanceof pt&&!1===this.left.is_array||void 0)))))}),e(Ue,function(e,t){t.print_string(e.value,e.quote),t.semicolon()}),e(at,function(e,t){t.print("..."),e.expression.print(t)}),e(pt,function(e,t){t.print(e.is_array?"[":"{");var n=e.names.length;e.names.forEach(function(e,i){i>0&&t.comma(),e.print(t),i==n-1&&e instanceof Qn&&t.comma()}),t.print(e.is_array?"]":"}")}),e(Ke,function(e,t){t.print("debugger"),t.semicolon()}),qe.DEFMETHOD("_do_print_body",function(e){p(this.body,e)}),e(Be,function(e,t){e.body.print(t),t.semicolon()}),e(ot,function(e,t){o(e.body,!0,t,!0),t.print("")}),e($e,function(e,t){e.label.print(t),t.colon(),e.body.print(t)}),e(Ge,function(e,t){e.body.print(t),t.semicolon()}),e(We,function(e,t){c(e,t)}),e(Ye,function(e,t){t.semicolon()}),e(Qe,function(e,t){t.print("do"),t.space(),d(e.body,t),t.space(),t.print("while"),t.space(),t.with_parens(function(){e.condition.print(t)}),t.semicolon()}),e(Je,function(e,t){t.print("while"),t.space(),t.with_parens(function(){e.condition.print(t)}),t.space(),e._do_print_body(t)}),e(et,function(e,t){t.print("for"),t.space(),t.with_parens(function(){e.init?(e.init instanceof wt?e.init.print(t):l(e.init,t,!0),t.print(";"),t.space()):t.print(";"),e.condition?(e.condition.print(t),t.print(";"),t.space()):t.print(";"),e.step&&e.step.print(t)}),t.space(),e._do_print_body(t)}),e(tt,function(e,t){t.print("for"),e.await&&(t.space(),t.print("await")),t.space(),t.with_parens(function(){e.init.print(t),t.space(),t.print(e instanceof nt?"of":"in"),t.space(),e.object.print(t)}),t.space(),e._do_print_body(t)}),e(it,function(e,t){t.print("with"),t.space(),t.with_parens(function(){e.expression.print(t)}),t.space(),e._do_print_body(t)}),st.DEFMETHOD("_do_print",function(e,t){var n=this;t||(n.async&&(e.print("async"),e.space()),e.print("function"),n.is_generator&&e.star(),n.name&&e.space()),n.name instanceof ln?n.name.print(e):t&&n.name instanceof Pe&&e.with_square(function(){n.name.print(e)}),e.with_parens(function(){n.argnames.forEach(function(t,n){n&&e.comma(),t.print(e)})}),e.space(),c(n,e,!0)}),e(st,function(e,t){e._do_print(t)}),e(_t,function(e,t){var n=e.prefix,i=n instanceof st||n instanceof $t||n instanceof jt||n instanceof Gt||n instanceof Wt||n instanceof Xt&&n.expression instanceof en;i&&t.print("("),e.prefix.print(t),i&&t.print(")"),e.template_string.print(t)}),e(dt,function(e,t){var n=t.parent()instanceof _t;t.print("`");for(var i=0;i"),e.space(),t.body instanceof Pe?t.body.print(e):c(t,e),i&&e.print(")")}),ht.DEFMETHOD("_do_print",function(e,t){if(e.print(t),this.value){e.space();const t=this.value.start.comments_before;t&&t.length&&!e.printed_comments.has(t)?(e.print("("),this.value.print(e),e.print(")")):this.value.print(e)}e.semicolon()}),e(gt,function(e,t){e._do_print(t,"return")}),e(At,function(e,t){e._do_print(t,"throw")}),e(Mi,function(e,t){var n=e.is_star?"*":"";t.print("yield"+n),e.expression&&(t.space(),e.expression.print(t))}),e(Fi,function(e,t){t.print("await"),t.space();var n=e.expression,i=!(n instanceof Kt||n instanceof wn||n instanceof Ht||n instanceof Wt||n instanceof Hn);i&&t.print("("),e.expression.print(t),i&&t.print(")")}),St.DEFMETHOD("_do_print",function(e,t){e.print(t),this.label&&(e.space(),this.label.print(e)),e.semicolon()}),e(vt,function(e,t){e._do_print(t,"break")}),e(Tt,function(e,t){e._do_print(t,"continue")}),e(bt,function(e,t){t.print("if"),t.space(),t.with_parens(function(){e.condition.print(t)}),t.space(),e.alternative?(!function(e,t){var n=e.body;if(t.option("braces")||t.option("ie8")&&n instanceof Qe)return d(n,t);if(!n)return t.force_semicolon();for(;;)if(n instanceof bt){if(!n.alternative)return void d(e.body,t);n=n.alternative}else{if(!(n instanceof qe))break;n=n.body}p(e.body,t)}(e,t),t.space(),t.print("else"),t.space(),e.alternative instanceof bt?e.alternative.print(t):p(e.alternative,t)):e._do_print_body(t)}),e(yt,function(e,t){t.print("switch"),t.space(),t.with_parens(function(){e.expression.print(t)}),t.space();var n=e.body.length-1;n<0?u(e,t):t.with_block(function(){e.body.forEach(function(e,i){t.indent(!0),e.print(t),i0&&t.newline()})})}),Ct.DEFMETHOD("_do_print_body",function(e){e.newline(),this.body.forEach(function(t){e.indent(),t.print(e),e.newline()})}),e(Ot,function(e,t){t.print("default:"),e._do_print_body(t)}),e(Ft,function(e,t){t.print("case"),t.space(),e.expression.print(t),t.print(":"),e._do_print_body(t)}),e(Mt,function(e,t){t.print("try"),t.space(),c(e,t),e.bcatch&&(t.space(),e.bcatch.print(t)),e.bfinally&&(t.space(),e.bfinally.print(t))}),e(Rt,function(e,t){t.print("catch"),e.argname&&(t.space(),t.with_parens(function(){e.argname.print(t)})),t.space(),c(e,t)}),e(Nt,function(e,t){t.print("finally"),t.space(),c(e,t)}),wt.DEFMETHOD("_do_print",function(e,t){e.print(t),e.space(),this.definitions.forEach(function(t,n){n&&e.comma(),t.print(e)});var n=e.parent();(!(n instanceof et||n instanceof tt)||n&&n.init!==this)&&e.semicolon()}),e(kt,function(e,t){e._do_print(t,"let")}),e(xt,function(e,t){e._do_print(t,"var")}),e(It,function(e,t){e._do_print(t,"const")}),e(Vt,function(e,t){t.print("import"),t.space(),e.imported_name&&e.imported_name.print(t),e.imported_name&&e.imported_names&&(t.print(","),t.space()),e.imported_names&&(1===e.imported_names.length&&"*"===e.imported_names[0].foreign_name.name?e.imported_names[0].print(t):(t.print("{"),e.imported_names.forEach(function(n,i){t.space(),n.print(t),i0&&(e.comma(),e.should_break()&&(e.newline(),e.indent())),t.print(e)})}),e(Gt,function(e,t){e._do_print(t)}),e(Xt,function(e,t){var n=e.expression;n.print(t);var i=e.property;t.option("ie8")&&se.has(i)?(t.print("["),t.add_mapping(e.end),t.print_string(i),t.print("]")):(n instanceof zn&&n.getValue()>=0&&(/[xa-f.)]/i.test(t.last())||t.print(".")),t.print("."),t.add_mapping(e.end),t.print_name(i))}),e(zt,function(e,t){e.expression.print(t),t.print("["),e.property.print(t),t.print("]")}),e(Yt,function(e,t){var n=e.operator;t.print(n),(/^[a-z]/i.test(n)||/[+-]$/.test(n)&&e.expression instanceof Yt&&/^[+-]/.test(e.expression.operator))&&t.space(),e.expression.print(t)}),e(qt,function(e,t){e.expression.print(t),t.print(e.operator)}),e($t,function(e,t){var n=e.operator;e.left.print(t),">"==n[0]&&e.left instanceof qt&&"--"==e.left.operator?t.print(" "):t.space(),t.print(n),("<"==n||"<<"==n)&&e.right instanceof Yt&&"!"==e.right.operator&&e.right.expression instanceof Yt&&"--"==e.right.expression.operator?t.print(" "):t.space(),e.right.print(t)}),e(jt,function(e,t){e.condition.print(t),t.space(),t.print("?"),t.space(),e.consequent.print(t),t.space(),t.colon(),e.alternative.print(t)}),e(Jt,function(e,t){t.with_square(function(){var n=e.elements,i=n.length;i>0&&t.space(),n.forEach(function(e,n){n&&t.comma(),e.print(t),n===i-1&&e instanceof Qn&&t.comma()}),i>0&&t.space()})}),e(en,function(e,t){e.properties.length>0?t.with_block(function(){e.properties.forEach(function(e,n){n&&(t.print(","),t.newline()),t.indent(),e.print(t)}),t.newline()}):u(e,t)}),e(sn,function(e,t){if(t.print("class"),t.space(),e.name&&(e.name.print(t),t.space()),e.extends){var n=!(e.extends instanceof wn||e.extends instanceof Ht||e.extends instanceof cn||e.extends instanceof ct);t.print("extends"),n?t.print("("):t.space(),e.extends.print(t),n?t.print(")"):t.space()}e.properties.length>0?t.with_block(function(){e.properties.forEach(function(e,n){n&&t.newline(),t.indent(),e.print(t)}),t.newline()}):t.print("{}")}),e(fn,function(e,t){t.print("new.target")}),e(nn,function(e,t){function n(e){var t=e.definition();return t?t.mangled_name||t.name:e.name}var i=t.option("shorthand");i&&e.value instanceof ln&&j(e.key)&&n(e.value)===e.key&&!se.has(e.key)?f(e.key,e.quote,t):i&&e.value instanceof Qt&&e.value.left instanceof ln&&j(e.key)&&n(e.value.left)===e.key?(f(e.key,e.quote,t),t.space(),t.print("="),t.space(),e.value.right.print(t)):(e.key instanceof Pe?t.with_square(function(){e.key.print(t)}):f(e.key,e.quote,t),t.colon(),e.value.print(t))}),tn.DEFMETHOD("_print_getter_setter",function(e,t){var n=this;n.static&&(t.print("static"),t.space()),e&&(t.print(e),t.space()),n.key instanceof gn?f(n.key.name,n.quote,t):t.with_square(function(){n.key.print(t)}),n.value._do_print(t,!0)}),e(rn,function(e,t){e._print_getter_setter("set",t)}),e(on,function(e,t){e._print_getter_setter("get",t)}),e(an,function(e,t){var n;e.is_generator&&e.async?n="async*":e.is_generator?n="*":e.async&&(n="async"),e._print_getter_setter(n,t)}),ln.DEFMETHOD("_do_print",function(e){var t=this.definition();e.print_name(t?t.mangled_name||t.name:this.name)}),e(ln,function(e,t){e._do_print(t)}),e(Qn,a),e(Pn,function(e,t){t.print("this")}),e(Gn,function(e,t){t.print("super")}),e(Hn,function(e,t){t.print(e.getValue())}),e(Xn,function(e,n){n.print_string(e.getValue(),e.quote,t)}),e(zn,function(e,t){E&&e.start&&null!=e.start.raw?t.print(e.start.raw):t.print(_(e.getValue()))}),e(Wn,function(e,t){t.print(e.getValue()+"n")}),e(Yn,function(e,t){let{source:n,flags:i}=e.getValue();n=A(n),i=i?function(e){const t=new Set(e.split(""));let n="";for(const e of re)t.has(e)&&(n+=e,t.delete(e));return t.size&&t.forEach(e=>{n+=e}),n}(i):"",t.print(t.to_utf8(`/${n}/${i}`));const r=t.parent();r instanceof $t&&/^\w/.test(r.operator)&&r.left===e&&t.print(" ")}),m([Pe,$e,ot],a),m([Jt,We,Rt,sn,Hn,Ke,wt,Ue,Nt,Et,st,Ut,en,qe,ln,yt,Ct,dt,mt,Mt],function(e){e.add_mapping(this.start)}),m([on,rn],function(e){e.add_mapping(this.start,this.key.name)}),m([tn],function(e){e.add_mapping(this.start,this.key)})}();const ji=1,Zi=2;let nr=null;class Bn{constructor(e,t,n){this.name=t.name,this.orig=[t],this.init=n,this.eliminated=0,this.assignments=0,this.scope=e,this.references=[],this.replaced=0,this.global=!1,this.export=0,this.mangled_name=null,this.undeclared=!1,this.id=Bn.next_id++,this.chained=!1,this.direct_access=!1,this.escaped=0,this.recursive_refs=0,this.references=[],this.should_replace=void 0,this.single_use=!1,this.fixed=!1,Object.seal(this)}unmangleable(e){return e||(e={}),!!(nr&&nr.has(this.id)&&g(e.keep_fnames,this.orig[0].name))||(this.global&&!e.toplevel||this.export&ji||this.undeclared||!e.eval&&this.scope.pinned()||(this.orig[0]instanceof Sn||this.orig[0]instanceof Dn)&&g(e.keep_fnames,this.orig[0].name)||this.orig[0]instanceof gn||(this.orig[0]instanceof bn||this.orig[0]instanceof Tn)&&g(e.keep_classnames,this.orig[0].name))}mangle(e){const t=e.cache&&e.cache.props;if(this.global&&t&&t.has(this.name))this.mangled_name=t.get(this.name);else if(!this.mangled_name&&!this.unmangleable(e)){var n=this.scope,i=this.orig[0];e.ie8&&i instanceof Sn&&(n=n.parent_scope);const r=Kn(this);this.mangled_name=r?r.mangled_name||r.name:n.next_mangled(e,this),this.global&&t&&t.set(this.name,this.mangled_name)}}}function Kn(e){if(e.orig[0]instanceof yn&&e.scope.is_block_scope())return e.scope.get_defun_scope().variables.get(e.name)}function Un(e,t){var n=e.enclosed;e:for(;;){var i=ar(++e.cname);if(!se.has(i)&&!t.reserved.has(i)){for(var r=n.length;--r>=0;){var o=n[r];if(i==(o.mangled_name||o.unmangleable(t)&&o.name))continue e}return i}}}Bn.next_id=1,ot.DEFMETHOD("figure_out_scope",function(e){e=o(e,{cache:null,ie8:!1,safari10:!1});var t=this,n=t.parent_scope=null,i=new Map,r=null,a=null,s=[],u=new An(function(t,o){if(t.is_block_scope()){const i=n;t.block_scope=n=new rt(t);const r=t instanceof Rt?i.parent_scope:i;if(n.init_scope_vars(r),n.uses_with=i.uses_with,n.uses_eval=i.uses_eval,e.safari10&&(t instanceof et||t instanceof tt)&&s.push(n),t instanceof yt){const e=n;n=i,t.expression.walk(u),n=e;for(let e=0;ee===t||(t instanceof dn?e instanceof Sn:!(e instanceof En||e instanceof mn)))||Q(`"${t.name}" is redeclared`,t.start.file,t.start.line,t.start.col,t.start.pos),t instanceof hn||h(m,2),r!==n){t.mark_enclosed(e);var m=n.find_variable(t);t.thedef!==m&&(t.thedef=m,t.reference(e))}}else if(t instanceof Vn){var E=i.get(t.name);if(!E)throw new Error(_("Undefined label {name} [{line},{col}]",{name:t.name,line:t.start.line,col:t.start.col}));t.thedef=E}n instanceof ot||!(t instanceof Pt||t instanceof Vt)||Q(`"${t.TYPE}" statement may only appear at the top level`,t.start.file,t.start.line,t.start.col,t.start.pos)}function h(e,t){if(a){var n=0;do{t++}while(u.parent(n++)!==a)}var i=u.parent(t);if(e.export=i instanceof Pt?ji:0){var r=i.exported_definition;(r instanceof ft||r instanceof un)&&i.is_default&&(e.export=Zi)}}});t.walk(u),t.globals=new Map;u=new An(function(n,i){if(n instanceof St&&n.label)return n.label.thedef.references.push(n),!0;if(n instanceof wn){var r,o=n.name;if("eval"==o&&u.parent()instanceof Kt)for(var a=n.scope;a&&!a.uses_eval;a=a.parent_scope)a.uses_eval=!0;return u.parent()instanceof Lt&&u.parent(1).module_name||!(r=n.scope.find_variable(o))?(r=t.def_global(n),n instanceof xn&&(r.export=ji)):r.scope instanceof st&&"arguments"==o&&(r.scope.uses_arguments=!0),n.thedef=r,n.reference(e),!n.scope.is_block_scope()||r.orig[0]instanceof dn||(n.scope=n.scope.get_defun_scope()),!0}var s;if(n instanceof yn&&(s=Kn(n.definition())))for(a=n.scope;a&&(p(a.enclosed,s),a!==s.scope);)a=a.parent_scope});if(t.walk(u),(e.ie8||e.safari10)&&t.walk(new An(function(n,i){if(n instanceof yn){var r=n.name,o=n.thedef.references,a=n.scope.get_defun_scope(),s=a.find_variable(r)||t.globals.get(r)||a.def_variable(n);return o.forEach(function(t){t.thedef=s,t.reference(e)}),n.thedef=s,n.reference(e),!0}})),e.safari10)for(const e of s)e.parent_scope.variables.forEach(function(t){p(e.enclosed,t)})}),ot.DEFMETHOD("def_global",function(e){var t=this.globals,n=e.name;if(t.has(n))return t.get(n);var i=new Bn(this,e);return i.undeclared=!0,i.global=!0,t.set(n,i),i}),rt.DEFMETHOD("init_scope_vars",function(e){this.variables=new Map,this.functions=new Map,this.uses_with=!1,this.uses_eval=!1,this.parent_scope=e,this.enclosed=[],this.cname=-1,this._var_name_cache=null}),rt.DEFMETHOD("var_names",function e(){var t=this._var_name_cache;return t||(this._var_name_cache=t=new Set(this.parent_scope?e.call(this.parent_scope):null),this._added_var_names&&this._added_var_names.forEach(e=>{t.add(e)}),this.enclosed.forEach(function(e){t.add(e.name)}),this.variables.forEach(function(e,n){t.add(n)})),t}),rt.DEFMETHOD("add_var_name",function(e){this._added_var_names||(this._added_var_names=new Set),this._added_var_names.add(e),this._var_name_cache||this.var_names(),this._var_name_cache.add(e)}),rt.DEFMETHOD("add_child_scope",function(e){if(e.parent_scope===this)return;e.parent_scope=this,e._var_name_cache=null,e._added_var_names&&e._added_var_names.forEach(t=>e.add_var_name(t));const t=new Set(e.enclosed),n=(()=>{const e=[];let t=this;do{e.push(t)}while(t=t.parent_scope);return e.reverse(),e})(),i=[];for(const e of n){i.forEach(t=>p(e.enclosed,t));for(const n of e.variables.values())t.has(n)&&(p(i,n),p(e.enclosed,n))}}),Pe.DEFMETHOD("is_block_scope",s),sn.DEFMETHOD("is_block_scope",s),st.DEFMETHOD("is_block_scope",s),ot.DEFMETHOD("is_block_scope",s),Ct.DEFMETHOD("is_block_scope",s),ze.DEFMETHOD("is_block_scope",u),je.DEFMETHOD("is_block_scope",u),st.DEFMETHOD("init_scope_vars",function(){rt.prototype.init_scope_vars.apply(this,arguments),this.uses_arguments=!1,this.def_variable(new hn({name:"arguments",start:this.start,end:this.end}))}),lt.DEFMETHOD("init_scope_vars",function(){rt.prototype.init_scope_vars.apply(this,arguments),this.uses_arguments=!1}),ln.DEFMETHOD("mark_enclosed",function(e){for(var t=this.definition(),n=this.scope;n&&(p(n.enclosed,t),e.keep_fnames&&n.functions.forEach(function(n){g(e.keep_fnames,n.name)&&p(t.scope.enclosed,n)}),n!==t.scope);)n=n.parent_scope}),ln.DEFMETHOD("reference",function(e){this.definition().references.push(this),this.mark_enclosed(e)}),rt.DEFMETHOD("find_variable",function(e){return e instanceof ln&&(e=e.name),this.variables.get(e)||this.parent_scope&&this.parent_scope.find_variable(e)}),rt.DEFMETHOD("def_function",function(e,t){var n=this.def_variable(e,t);return(!n.init||n.init instanceof ft)&&(n.init=t),this.functions.set(e.name,n),n}),rt.DEFMETHOD("def_variable",function(e,t){var n=this.variables.get(e.name);return n?(n.orig.push(e),n.init&&(n.scope!==e.scope||n.init instanceof ct)&&(n.init=t)):(n=new Bn(this,e,t),this.variables.set(e.name,n),n.global=!this.parent_scope),e.thedef=n}),rt.DEFMETHOD("next_mangled",function(e){return Un(this,e)}),ot.DEFMETHOD("next_mangled",function(e){let t;const n=this.mangled_names;do{t=Un(this,e)}while(n.has(t));return t}),ct.DEFMETHOD("next_mangled",function(e,t){for(var n=t.orig[0]instanceof hn&&this.name&&this.name.definition(),i=n?n.mangled_name||n.name:null;;){var r=Un(this,e);if(!i||i!=r)return r}}),ln.DEFMETHOD("unmangleable",function(e){var t=this.definition();return!t||t.unmangleable(e)}),Nn.DEFMETHOD("unmangleable",s),ln.DEFMETHOD("unreferenced",function(){return!this.definition().references.length&&!this.scope.pinned()}),ln.DEFMETHOD("definition",function(){return this.thedef}),ln.DEFMETHOD("global",function(){return this.definition().global}),ot.DEFMETHOD("_default_mangler_options",function(e){return(e=o(e,{eval:!1,ie8:!1,keep_classnames:!1,keep_fnames:!1,module:!1,reserved:[],toplevel:!1})).module&&(e.toplevel=!0),Array.isArray(e.reserved)||e.reserved instanceof Set||(e.reserved=[]),e.reserved=new Set(e.reserved),e.reserved.add("arguments"),e}),ot.DEFMETHOD("mangle_names",function(e){e=this._default_mangler_options(e);var t=-1,n=[];e.keep_fnames&&(nr=new Set);const i=this.mangled_names=new Set;e.cache&&(this.globals.forEach(o),e.cache.props&&e.cache.props.forEach(function(e){i.add(e)}));var r=new An(function(i,r){if(i instanceof $e){var a=t;return r(),t=a,!0}if(i instanceof rt)i.variables.forEach(o);else if(i.is_block_scope())i.block_scope.variables.forEach(o);else if(nr&&i instanceof Bt&&i.value instanceof st&&!i.value.name&&g(e.keep_fnames,i.name.name))nr.add(i.name.definition().id);else{if(i instanceof Nn){let e;do{e=ar(++t)}while(se.has(e));return i.mangled_name=e,!0}!e.ie8&&!e.safari10&&i instanceof yn&&n.push(i.definition())}});function o(t){!(e.reserved.has(t.name)||t.export&ji)&&n.push(t)}this.walk(r),n.forEach(t=>{t.mangle(e)}),nr=null}),ot.DEFMETHOD("find_colliding_names",function(e){const t=e.cache&&e.cache.props,n=new Set;return e.reserved.forEach(i),this.globals.forEach(r),this.walk(new An(function(e){e instanceof rt&&e.variables.forEach(r),e instanceof yn&&r(e.definition())})),n;function i(e){n.add(e)}function r(n){var r=n.name;if(n.global&&t&&t.has(r))r=t.get(r);else if(!n.unmangleable(e))return;i(r)}}),ot.DEFMETHOD("expand_names",function(e){ar.reset(),ar.sort(),e=this._default_mangler_options(e);var t=this.find_colliding_names(e),n=0;function i(i){if(i.global&&e.cache)return;if(i.unmangleable(e))return;if(e.reserved.has(i.name))return;const r=Kn(i),o=i.name=r?r.name:function(){var e;do{e=ar(n++)}while(t.has(e)||se.has(e));return e}();i.orig.forEach(function(e){e.name=o}),i.references.forEach(function(e){e.name=o})}this.globals.forEach(i),this.walk(new An(function(e){e instanceof rt&&e.variables.forEach(i),e instanceof yn&&i(e.definition())}))}),Pe.DEFMETHOD("tail_node",c),Gt.DEFMETHOD("tail_node",function(){return this.expressions[this.expressions.length-1]}),ot.DEFMETHOD("compute_char_frequency",function(e){e=this._default_mangler_options(e);try{Pe.prototype.print=function(t,n){this._print(t,n),this instanceof ln&&!this.unmangleable(e)?ar.consider(this.name,-1):e.properties&&(this instanceof Xt?ar.consider(this.property,-1):this instanceof zt&&function e(t){t instanceof Xn?ar.consider(t.value,-1):t instanceof jt?(e(t.consequent),e(t.alternative)):t instanceof Gt&&e(t.tail_node())}(this.property))},ar.consider(this.print_to_string(),1)}finally{Pe.prototype.print=Pe.prototype._print}ar.sort()});const ar=(()=>{const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_".split(""),t="0123456789".split("");let n,i;function r(){i=new Map,e.forEach(function(e){i.set(e,0)}),t.forEach(function(e){i.set(e,0)})}function o(e,t){return i.get(t)-i.get(e)}function a(e){var t="",i=54;e++;do{t+=n[--e%i],e=Math.floor(e/i),i=64}while(e>0);return t}return a.consider=function(e,t){for(var n=e.length;--n>=0;)i.set(e[n],i.get(e[n])+t)},a.sort=function(){n=m(e,o).concat(m(t,o))},a.reset=r,r(),a})(),sr=1,_r=8,dr=16,mr=32,Er=256,hr=512,Dr=1024,gr=Er|hr|Dr,Ar=(e,t)=>e.flags&t,Sr=(e,t)=>{e.flags|=t},vr=(e,t)=>{e.flags&=~t};class ei extends An{constructor(e,t){super(),void 0===e.defaults||e.defaults||(t=!0),this.options=o(e,{arguments:!1,arrows:!t,booleans:!t,booleans_as_integers:!1,collapse_vars:!t,comparisons:!t,computed_props:!t,conditionals:!t,dead_code:!t,defaults:!0,directives:!t,drop_console:!1,drop_debugger:!t,ecma:5,evaluate:!t,expression:!1,global_defs:!1,hoist_funs:!1,hoist_props:!t,hoist_vars:!1,ie8:!1,if_return:!t,inline:!t,join_vars:!t,keep_classnames:!1,keep_fargs:!0,keep_fnames:!1,keep_infinity:!1,loops:!t,module:!1,negate_iife:!t,passes:1,properties:!t,pure_getters:!t&&"strict",pure_funcs:null,reduce_funcs:null,reduce_vars:!t,sequences:!t,side_effects:!t,switches:!t,top_retain:null,toplevel:!(!e||!e.top_retain),typeofs:!t,unsafe:!1,unsafe_arrows:!1,unsafe_comps:!1,unsafe_Function:!1,unsafe_math:!1,unsafe_methods:!1,unsafe_proto:!1,unsafe_regexp:!1,unsafe_undefined:!1,unused:!t,warnings:!1},!0);var n=this.options.global_defs;if("object"==typeof n)for(var i in n)"@"===i[0]&&D(n,i)&&(n[i.slice(1)]=ue(n[i],{expression:!0}));!0===this.options.inline&&(this.options.inline=3);var r=this.options.pure_funcs;this.pure_funcs="function"==typeof r?r:r?function(e){return!r.includes(e.expression.print_to_string())}:u;var a=this.options.top_retain;a instanceof RegExp?this.top_retain=function(e){return a.test(e.name)}:"function"==typeof a?this.top_retain=a:a&&("string"==typeof a&&(a=a.split(/,/)),this.top_retain=function(e){return a.includes(e.name)}),this.options.module&&(this.directives["use strict"]=!0,this.options.toplevel=!0);var s=this.options.toplevel;this.toplevel="string"==typeof s?{funcs:/funcs/.test(s),vars:/vars/.test(s)}:{funcs:s,vars:s};var c=this.options.sequences;this.sequences_limit=1==c?800:0|c,this.warnings_produced={},this.evaluated_regexps=new Map}option(e){return this.options[e]}exposed(e){if(e.export)return!0;if(e.global)for(var t=0,n=e.orig.length;t0||this.option("reduce_vars"))&&e.reset_opt_flags(this),e=e.transform(this),t>1){var a=0;if(e.walk(new An(function(){a++})),this.info("pass "+o+": last_count: "+n+", count: "+a),a=0;){if(!(r[o]instanceof nn))return;n||r[o].key!==t||(n=r[o].value)}}return n instanceof wn&&n.fixed_value()||n}}function ii(e,t,n,i,r,o){var a=t.parent(r),s=Ri(n,a);if(s)return s;if(!o&&a instanceof Kt&&a.expression===n&&!(i instanceof lt)&&!(i instanceof sn)&&!a.is_expr_pure(e)&&(!(i instanceof ct)||!(a instanceof Ut)&&i.contains_this()))return!0;if(a instanceof Jt)return ii(e,t,a,a,r+1);if(a instanceof nn&&n===a.value){var u=t.parent(r+1);return ii(e,t,u,u,r+2)}if(a instanceof Ht&&a.expression===n){var c=ni(i,a.property);return!o&&ii(e,t,a,c,r+1)}}function ri(e){return e instanceof lt||e instanceof ct}function oi(e){if(e instanceof Pn)return!0;if(e instanceof wn)return e.definition().orig[0]instanceof Sn;if(e instanceof Ht){if((e=e.expression)instanceof wn){if(e.is_immutable())return!1;e=e.fixed_value()}return!e||!(e instanceof Yn)&&(e instanceof Hn||oi(e))}return!1}function ai(e,t){if(!(e instanceof wn))return!1;for(var n=e.definition().orig,i=n.length;--i>=0;)if(n[i]instanceof t)return!0}function si(e,t){for(let n=0;;n++){const i=e.parent(n);if(i instanceof ot)return t?i:void 0;if(i instanceof st)return i;if(i.block_scope)return i.block_scope}}function ui(e,t){for(var n,i=0;(n=e.parent(i++))&&!(n instanceof rt);)if(n instanceof Rt&&n.argname){n=n.argname.definition().scope;break}return n.find_variable(t)}function ci(e,t,n){return n||(n={}),t&&(n.start||(n.start=t.start),n.end||(n.end=t.end)),new e(n)}function li(e,t){if(1==t.length)return t[0];if(0==t.length)throw new Error("trying to create a sequence with length zero!");return ci(Gt,e,{expressions:t.reduce(_i,[])})}function fi(e,t){switch(typeof e){case"string":return ci(Xn,t,{value:e});case"number":return isNaN(e)?ci(jn,t):isFinite(e)?1/e<0?ci(Yt,t,{operator:"-",expression:ci(zn,t,{value:-e})}):ci(zn,t,{value:e}):e<0?ci(Yt,t,{operator:"-",expression:ci(Jn,t)}):ci(Jn,t);case"boolean":return ci(e?vi:Si,t);case"undefined":return ci(Zn,t);default:if(null===e)return ci($n,t,{value:null});if(e instanceof RegExp)return ci(Yn,t,{value:{source:A(e.source),flags:e.flags}});throw new Error(_("Can't handle constant of type: {type}",{type:typeof e}))}}function pi(e,t,n){return e instanceof Yt&&"delete"==e.operator||e instanceof Kt&&e.expression===t&&(n instanceof Ht||n instanceof wn&&"eval"==n.name)?li(t,[ci(zn,t,{value:0}),n]):n}function _i(e,t){return t instanceof Gt?e.push(...t.expressions):e.push(t),e}function di(e){if(null===e)return[];if(e instanceof We)return e.body;if(e instanceof Ye)return[];if(e instanceof Be)return[e];throw new Error("Can't convert thing to statement array")}function mi(e){return null===e||(e instanceof Ye||e instanceof We&&0==e.body.length)}function Ei(e){return!(e instanceof un||e instanceof ft||e instanceof kt||e instanceof It||e instanceof Pt||e instanceof Vt)}function hi(e){return e instanceof je&&e.body instanceof We?e.body:e}function Di(e){return"Call"==e.TYPE&&(e.expression instanceof ct||Di(e.expression))}function gi(e){return e instanceof wn&&e.definition().undeclared}ti(Pe,function(e,t){return e}),ot.DEFMETHOD("drop_console",function(){return this.transform(new vn(function(e){if("Call"==e.TYPE){var t=e.expression;if(t instanceof Ht){for(var n=t.expression;n.expression;)n=n.expression;if(gi(n)&&"console"==n.name)return ci(Zn,e)}}}))}),Pe.DEFMETHOD("equivalent_to",function(e){return this.TYPE==e.TYPE&&this.print_to_string()==e.print_to_string()}),rt.DEFMETHOD("process_expression",function(e,t){var n=this,i=new vn(function(r){if(e&&r instanceof Ge)return ci(gt,r,{value:r.body});if(!e&&r instanceof gt){if(t){var o=r.value&&r.value.drop_side_effect_free(t,!0);return o?ci(Ge,r,{body:o}):ci(Ye,r)}return ci(Ge,r,{body:r.value||ci(Yt,r,{operator:"void",expression:ci(zn,r,{value:0})})})}if(r instanceof sn||r instanceof st&&r!==n)return r;if(r instanceof ze){var a=r.body.length-1;a>=0&&(r.body[a]=r.body[a].transform(i))}else r instanceof bt?(r.body=r.body.transform(i),r.alternative&&(r.alternative=r.alternative.transform(i))):r instanceof it&&(r.body=r.body.transform(i));return r});n.transform(i)}),function(e){function t(e,t){t.assignments=0,t.chained=!1,t.direct_access=!1,t.escaped=0,t.recursive_refs=0,t.references=[],t.should_replace=void 0,t.single_use=void 0,t.scope.pinned()?t.fixed=!1:t.orig[0]instanceof mn||!e.exposed(t)?t.fixed=t.init:t.fixed=!1}function n(e,n,i){i.variables.forEach(function(i){t(n,i),null===i.fixed?(e.defs_to_safe_ids.set(i,e.safe_ids),s(e,i,!0)):i.fixed&&(e.loop_ids.set(i.id,e.in_loop),s(e,i,!0))})}function i(e,n){n.block_scope&&n.block_scope.variables.forEach(function(n){t(e,n)})}function r(e){e.safe_ids=Object.create(e.safe_ids)}function o(e){e.safe_ids=Object.getPrototypeOf(e.safe_ids)}function s(e,t,n){e.safe_ids[t.id]=n}function u(e,t){if("m"==t.single_use)return!1;if(e.safe_ids[t.id]){if(null==t.fixed){var n=t.orig[0];if(n instanceof hn||"arguments"==n.name)return!1;t.fixed=ci(Zn,n)}return!0}return t.fixed instanceof ft}function c(e,t,n,i){if(void 0===t.fixed)return!0;let r;return null===t.fixed&&(r=e.defs_to_safe_ids.get(t))?(r[t.id]=!1,e.defs_to_safe_ids.delete(t),!0):!!D(e.safe_ids,t.id)&&(!!u(e,t)&&(!1!==t.fixed&&(!(null!=t.fixed&&(!i||t.references.length>t.assignments))&&(t.fixed instanceof ft?i instanceof Pe&&t.fixed.parent_scope===n:t.orig.every(e=>!(e instanceof mn||e instanceof Dn||e instanceof Sn))))))}function l(e,t,n,i,r,o,a){var s=e.parent(o);if(r){if(r.is_constant())return;if(r instanceof cn)return}if(s instanceof Zt&&"="==s.operator&&i===s.right||s instanceof Kt&&(i!==s.expression||s instanceof Ut)||s instanceof ht&&i===s.value&&i.scope!==t.scope||s instanceof Bt&&i===s.value||s instanceof Mi&&i===s.value&&i.scope!==t.scope)return!(a>1)||r&&r.is_constant_expression(n)||(a=1),void((!t.escaped||t.escaped>a)&&(t.escaped=a));if(s instanceof Jt||s instanceof Fi||s instanceof $t&&Cr.has(s.operator)||s instanceof jt&&i!==s.condition||s instanceof at||s instanceof Gt&&i===s.tail_node())l(e,t,n,s,s,o+1,a);else if(s instanceof nn&&i===s.value){var u=e.parent(o+1);l(e,t,n,u,u,o+2,a)}else if(s instanceof Ht&&i===s.expression&&(l(e,t,n,s,r=ni(r,s.property),o+1,a+1),r))return;o>0||s instanceof Gt&&i!==s.tail_node()||s instanceof Ge||(t.direct_access=!0)}e(Pe,a);var f=new An(function(e){if(e instanceof ln){var t=e.definition();t&&(e instanceof wn&&t.references.push(e),t.fixed=!1)}});function p(e,t,i){vr(this,dr);const r=e.safe_ids;return e.safe_ids=Object.create(null),n(e,i,this),t(),e.safe_ids=r,!0}function _(e,t,i){var a,u=this;return vr(this,dr),r(e),n(e,i,u),u.uses_arguments?(t(),void o(e)):(!u.name&&(a=e.parent())instanceof Kt&&a.expression===u&&!a.args.some(e=>e instanceof at)&&u.argnames.every(e=>e instanceof ln)&&u.argnames.forEach(function(t,n){if(t.definition){var i=t.definition();i.orig.length>1||(void 0!==i.fixed||u.uses_arguments&&!e.has_directive("use strict")?i.fixed=!1:(i.fixed=function(){return a.args[n]||ci(Zn,a)},e.loop_ids.set(i.id,e.in_loop),s(e,i,!0)))}}),t(),o(e),!0)}e(ut,function(e,t,i){return r(e),n(e,i,this),t(),o(e),!0}),e(Zt,function(e,t,n){var i=this;if(i.left instanceof pt)i.left.walk(f);else{var r=i.left;if(r instanceof wn){var o=r.definition(),a=c(e,o,r.scope,i.right);if(o.assignments++,a){var u=o.fixed;if(u||"="==i.operator){var p="="==i.operator,_=p?i.right:i;if(!ii(n,e,i,_,0))return o.references.push(r),p||(o.chained=!0),o.fixed=p?function(){return i.right}:function(){return ci($t,i,{operator:i.operator.slice(0,-1),left:u instanceof Pe?u:u(),right:i.right})},s(e,o,!1),i.right.walk(e),s(e,o,!0),l(e,o,r.scope,i,_,0,1),!0}}}}}),e($t,function(e){if(Cr.has(this.operator))return this.left.walk(e),r(e),this.right.walk(e),o(e),!0}),e(ze,function(e,t,n){i(n,this)}),e(Ft,function(e){return r(e),this.expression.walk(e),o(e),r(e),Ee(this,e),o(e),!0}),e(cn,function(e,t){return vr(this,dr),r(e),t(),o(e),!0}),e(jt,function(e){return this.condition.walk(e),r(e),this.consequent.walk(e),o(e),r(e),this.alternative.walk(e),o(e),!0}),e(Ot,function(e,t){return r(e),t(),o(e),!0}),e(un,p),e(ft,p),e(Qe,function(e,t,n){i(n,this);const a=e.in_loop;return e.in_loop=this,r(e),this.body.walk(e),Xi(this)&&(o(e),r(e)),this.condition.walk(e),o(e),e.in_loop=a,!0}),e(et,function(e,t,n){i(n,this),this.init&&this.init.walk(e);const a=e.in_loop;return e.in_loop=this,r(e),this.condition&&this.condition.walk(e),this.body.walk(e),this.step&&(Xi(this)&&(o(e),r(e)),this.step.walk(e)),o(e),e.in_loop=a,!0}),e(tt,function(e,t,n){i(n,this),this.init.walk(f),this.object.walk(e);const a=e.in_loop;return e.in_loop=this,r(e),this.body.walk(e),o(e),e.in_loop=a,!0}),e(ct,_),e(lt,_),e(bt,function(e){return this.condition.walk(e),r(e),this.body.walk(e),o(e),this.alternative&&(r(e),this.alternative.walk(e),o(e)),!0}),e($e,function(e){return r(e),this.body.walk(e),o(e),!0}),e(yn,function(){this.definition().fixed=!1}),e(wn,function(e,t,n){var i,r,o=this.definition();o.references.push(this),1==o.references.length&&!o.fixed&&o.orig[0]instanceof Dn&&e.loop_ids.set(o.id,e.in_loop),void 0!==o.fixed&&u(e,o)?o.fixed&&((i=this.fixed_value())instanceof st&&Yi(e,o)?o.recursive_refs++:i&&!n.exposed(o)&&function(e,t,n){return t.option("unused")&&!n.scope.pinned()&&n.references.length-n.recursive_refs==1&&e.loop_ids.get(n.id)===e.in_loop}(e,n,o)?o.single_use=!(i instanceof st&&function(e,t,n){let i=si(e);const r=t.enclosed.filter(e=>!t.variables.has(e.name)).map(e=>e.name);if(!r.length)return!1;for(;i&&!(i instanceof ot)&&i!==n;){if(r.some(e=>i.variables.has(e)))return!0;i=i.parent_scope}return!1}(e,i,o.scope))&&(i instanceof st&&!i.pinned()||i instanceof sn||o.scope===this.scope&&i.is_constant_expression()):o.single_use=!1,ii(n,e,this,i,0,!!(r=i)&&(r.is_constant()||r instanceof st||r instanceof Pn))&&(o.single_use?o.single_use="m":o.fixed=!1)):o.fixed=!1,l(e,o,this.scope,this,i,0,1)}),e(ot,function(e,i,r){this.globals.forEach(function(e){t(r,e)}),n(e,r,this)}),e(Mt,function(e,t,n){return i(n,this),r(e),Ee(this,e),o(e),this.bcatch&&(r(e),this.bcatch.walk(e),o(e)),this.bfinally&&this.bfinally.walk(e),!0}),e(Wt,function(e,t){var n=this;if("++"===n.operator||"--"===n.operator){var i=n.expression;if(i instanceof wn){var r=i.definition(),o=c(e,r,i.scope,!0);if(r.assignments++,o){var a=r.fixed;if(a)return r.references.push(i),r.chained=!0,r.fixed=function(){return ci($t,n,{operator:n.operator.slice(0,-1),left:ci(Yt,n,{operator:"+",expression:a instanceof Pe?a:a()}),right:ci(zn,n,{value:1})})},s(e,r,!0),!0}}}}),e(Bt,function(e,t){var n=this;if(n.name instanceof pt)n.name.walk(f);else{var i=n.name.definition();if(n.value){if(c(e,i,n.name.scope,n.value))return i.fixed=function(){return n.value},e.loop_ids.set(i.id,e.in_loop),s(e,i,!1),t(),s(e,i,!0),!0;i.fixed=!1}}}),e(Je,function(e,t,n){i(n,this);const a=e.in_loop;return e.in_loop=this,r(e),t(),o(e),e.in_loop=a,!0})}(function(e,t){e.DEFMETHOD("reduce_vars",t)}),ot.DEFMETHOD("reset_opt_flags",function(e){const t=this,n=e.option("reduce_vars"),i=new An(function(r,o){if(vr(r,gr),n)return e.top_retain&&r instanceof ft&&i.parent()===t&&Sr(r,Dr),r.reduce_vars(i,o,e)});i.safe_ids=Object.create(null),i.in_loop=null,i.loop_ids=new Map,i.defs_to_safe_ids=new Map,t.walk(i)}),ln.DEFMETHOD("fixed_value",function(){var e=this.definition().fixed;return!e||e instanceof Pe?e:e()}),wn.DEFMETHOD("is_immutable",function(){var e=this.definition().orig;return 1==e.length&&e[0]instanceof Sn});var Tr=E("Array Boolean clearInterval clearTimeout console Date decodeURI decodeURIComponent encodeURI encodeURIComponent Error escape eval EvalError Function isFinite isNaN JSON Math Number parseFloat parseInt RangeError ReferenceError RegExp Object setInterval setTimeout String SyntaxError TypeError unescape URIError");wn.DEFMETHOD("is_declared",function(e){return!this.definition().undeclared||e.option("unsafe")&&Tr.has(this.name)});var br,yr=E("Infinity NaN undefined");function Ti(e){return e instanceof Jn||e instanceof jn||e instanceof Zn}function bi(t,r){var o,a,s=r.find_parent(rt).get_defun_scope();!function(){var e=r.self(),t=0;do{if(e instanceof Rt||e instanceof Nt)t++;else if(e instanceof je)o=!0;else{if(e instanceof rt){s=e;break}e instanceof Mt&&(a=!0)}}while(e=r.parent(t++))}();var f,A=10;do{f=!1,c(t),r.option("dead_code")&&p(t,r),r.option("if_return")&&l(t,r),r.sequences_limit>0&&(m(t,r),h(t,r)),r.option("join_vars")&&g(t),r.option("collapse_vars")&&u(t,r)}while(f&&A-- >0);function u(t,n){if(s.pinned())return t;for(var r,u=[],c=t.length,l=new vn(function(e,t){if(O)return e;if(!C)return e!==_[d]?e:++d<_.length?x(e):(C=!0,(h=function e(t,n,i){var r=l.parent(n);if(r instanceof Zt)return i&&!(r.left instanceof Ht||A.has(r.left.name))?e(r,n+1,i):t;if(r instanceof $t)return!i||Cr.has(r.operator)&&r.left!==t?t:e(r,n+1,i);if(r instanceof Kt)return t;if(r instanceof Ft)return t;if(r instanceof jt)return i&&r.condition===t?e(r,n+1,i):t;if(r instanceof wt)return e(r,n+1,!0);if(r instanceof ht)return i?e(r,n+1,i):t;if(r instanceof bt)return i&&r.condition===t?e(r,n+1,i):t;if(r instanceof je)return t;if(r instanceof Gt)return e(r,n+1,r.tail_node()!==t);if(r instanceof Ge)return e(r,n+1,!0);if(r instanceof yt)return t;if(r instanceof Bt)return t;return null}(e,0))===e&&(O=!0),e);var i,r=l.parent();if(e instanceof Zt&&"="!=e.operator&&g.equivalent_to(e.left)||e instanceof Fi||e instanceof Kt&&g instanceof Ht&&g.equivalent_to(e.expression)||e instanceof Ke||e instanceof pt||e instanceof at&&e.expression instanceof ln&&e.expression.definition().references.length>1||e instanceof je&&!(e instanceof et)||e instanceof St||e instanceof Mt||e instanceof it||e instanceof Mi||e instanceof Pt||r instanceof et&&e!==r.init||!T&&e instanceof wn&&!e.is_declared(n)&&!wr.has(e))return O=!0,e;if(D||S&&T||!(r instanceof $t&&Cr.has(r.operator)&&r.left!==e||r instanceof jt&&r.condition!==e||r instanceof bt&&r.condition!==e)||(D=r),R&&!(e instanceof pn)&&g.equivalent_to(e)){if(D)return O=!0,e;if(Ri(e,r))return E&&M++,e;if(M++,E&&m instanceof Bt)return e;if(f=O=!0,n.info("Collapsing {name} [{file}:{line},{col}]",{name:e.print_to_string(),file:e.start.file,line:e.start.line,col:e.start.col}),m instanceof qt)return ci(Yt,m,m);if(m instanceof Bt){var o=m.name.definition(),u=m.value;return o.references.length-o.replaced!=1||n.exposed(o)?ci(Zt,m,{operator:"=",left:ci(wn,m.name,m.name),right:u}):(o.replaced++,y&&Ti(u)?u.transform(n):pi(r,e,u))}return vr(m,mr),m}return(e instanceof Kt||e instanceof ht&&(v||g instanceof Ht||X(g))||e instanceof Ht&&(v||e.expression.may_throw_on_access(n))||e instanceof wn&&(A.get(e.name)||v&&X(e))||e instanceof Bt&&e.value&&(A.has(e.name.name)||v&&X(e.name))||(i=Ri(e.left,e))&&(i instanceof Ht||A.has(i.name))||b&&(a?e.has_side_effects(n):function e(t,n){if(t instanceof Zt)return e(t.left,!0);if(t instanceof Wt)return e(t.expression,!0);if(t instanceof Bt)return t.value&&e(t.value);if(n){if(t instanceof Xt)return e(t.expression,!0);if(t instanceof zt)return e(t.expression,!0);if(t instanceof wn)return t.definition().scope!==s}return!1}(e)))&&(h=e,e instanceof rt&&(O=!0)),x(e)},function(e){O||(h===e&&(O=!0),D===e&&(D=null))}),p=new vn(function(e){if(O)return e;if(!C){if(e!==_[d])return e;if(++d<_.length)return;return C=!0,e}return e instanceof wn&&e.name==z.name?(--M||(O=!0),Ri(e,p.parent())?e:(z.replaced++,E.replaced--,m.value)):e instanceof Ot||e instanceof rt?e:void 0});--c>=0;){0==c&&n.option("unused")&&I();var _=[];for(L(t[c]);u.length>0;){_=u.pop();var d=0,m=_[_.length-1],E=null,h=null,D=null,g=V(m);if(g&&!oi(g)&&!g.has_side_effects(n)){var A=B(m),S=U(g);g instanceof wn&&A.set(g.name,!1);var v=G(m),T=H(),b=m.may_throw(n),y=m.name instanceof hn,C=y,O=!1,M=0,R=!r||!C;if(!R){for(var N=n.self().argnames.lastIndexOf(m.name)+1;!O&&NM)M=!1;else{O=!1,d=0,C=y;for(w=c;!O&&w!(e instanceof at))){var o=n.has_directive("use strict");o&&!i(o,t.body)&&(o=!1);var a=t.argnames.length;r=e.args.slice(a);for(var s=new Set,c=a;--c>=0;){var l=t.argnames[c],f=e.args[c];const i=l.definition&&l.definition();if(!(i&&i.orig.length>1)&&(r.unshift(ci(Bt,l,{name:l,value:f})),!s.has(l.name)))if(s.add(l.name),l instanceof at){var p=e.args.slice(c);p.every(e=>!k(t,e,o))&&u.unshift([ci(Bt,l,{name:l.expression,value:ci(Jt,e,{elements:p})})])}else f?(f instanceof st&&f.pinned()||k(t,f,o))&&(f=null):f=ci(Zn,l).transform(n),f&&u.unshift([ci(Bt,l,{name:l,value:f})])}}}function L(e){if(_.push(e),e instanceof Zt)e.left.has_side_effects(n)||u.push(_.slice()),L(e.right);else if(e instanceof $t)L(e.left),L(e.right);else if(e instanceof Kt)L(e.expression),e.args.forEach(L);else if(e instanceof Ft)L(e.expression);else if(e instanceof jt)L(e.condition),L(e.consequent),L(e.alternative);else if(!(e instanceof wt)||!n.option("unused")&&e instanceof It)e instanceof Ze?(L(e.condition),e.body instanceof ze||L(e.body)):e instanceof ht?e.value&&L(e.value):e instanceof et?(e.init&&L(e.init),e.condition&&L(e.condition),e.step&&L(e.step),e.body instanceof ze||L(e.body)):e instanceof tt?(L(e.object),e.body instanceof ze||L(e.body)):e instanceof bt?(L(e.condition),e.body instanceof ze||L(e.body),!e.alternative||e.alternative instanceof ze||L(e.alternative)):e instanceof Gt?e.expressions.forEach(L):e instanceof Ge?L(e.body):e instanceof yt?(L(e.expression),e.body.forEach(L)):e instanceof Wt?"++"!=e.operator&&"--"!=e.operator||u.push(_.slice()):e instanceof Bt&&e.value&&(u.push(_.slice()),L(e.value));else{var t=e.definitions.length,i=t-200;for(i<0&&(i=0);i1&&!(e.name instanceof hn)||(r>1?function(e){var t=e.value;if(t instanceof wn&&"arguments"!=t.name){var n=t.definition();if(!n.undeclared)return E=n}}(e):!n.exposed(t))?ci(wn,e.name,e.name):void 0}}function P(e){return e[e instanceof Zt?"right":"value"]}function B(e){var t=new Map;if(e instanceof Wt)return t;var i=new An(function(e,r){for(var o=e;o instanceof Ht;)o=o.expression;(o instanceof wn||o instanceof Pn)&&t.set(o.name,t.get(o.name)||ii(n,i,e,e,0))});return P(e).walk(i),t}function K(e){if(e.name instanceof hn){var i=n.parent(),r=n.self().argnames,o=r.indexOf(e.name);if(o<0)i.args.length=Math.min(i.args.length,r.length-1);else{var a=i.args;a[o]&&(a[o]=ci(zn,a[o],{value:0}))}return!0}var s=!1;return t[c].transform(new vn(function(t,n,i){return s?t:t===e||t.body===e?(s=!0,t instanceof Bt?(t.value=null,t):i?F.skip:null):void 0},function(e){if(e instanceof Gt)switch(e.expressions.length){case 0:return null;case 1:return e.expressions[0]}}))}function U(e){for(;e instanceof Ht;)e=e.expression;return e instanceof wn&&e.definition().scope===s&&!(o&&(A.has(e.name)||m instanceof Wt||m instanceof Zt&&"="!=m.operator))}function G(e){return e instanceof Wt?Or.has(e.operator):P(e).has_side_effects(n)}function H(){if(v)return!1;if(E)return!0;if(g instanceof wn){var e=g.definition();if(e.references.length-e.replaced==(m instanceof Bt?1:2))return!0}return!1}function X(e){if(!e.definition)return!0;var t=e.definition();return!(1==t.orig.length&&t.orig[0]instanceof Dn)&&(t.scope.get_defun_scope()!==s||!t.references.every(e=>{var t=e.scope.get_defun_scope();return"Scope"==t.TYPE&&(t=t.parent_scope),t===s}))}}function c(e){for(var t=[],n=0;n=0;){var i=e[n];if(i instanceof bt&&i.body instanceof gt&&++t>1)return!0}return!1}(e),r=n instanceof st,o=e.length;--o>=0;){var a=e[o],s=g(o),u=e[s];if(r&&!u&&a instanceof gt){if(!a.value){f=!0,e.splice(o,1);continue}if(a.value instanceof Yt&&"void"==a.value.operator){f=!0,e[o]=ci(Ge,a,{body:a.value.expression});continue}}if(a instanceof bt){var c;if(E(c=Ki(a.body))){c.label&&d(c.label.thedef.references,c),f=!0,(a=a.clone()).condition=a.condition.negate(t);var l=D(a.body,c);a.body=ci(We,a,{body:di(a.alternative).concat(h())}),a.alternative=ci(We,a,{body:l}),e[o]=a.transform(t);continue}if(E(c=Ki(a.alternative))){c.label&&d(c.label.thedef.references,c),f=!0,(a=a.clone()).body=ci(We,a.body,{body:di(a.body).concat(h())});l=D(a.alternative,c);a.alternative=ci(We,a.alternative,{body:l}),e[o]=a.transform(t);continue}}if(a instanceof bt&&a.body instanceof gt){var p=a.body.value;if(!p&&!a.alternative&&(r&&!u||u instanceof gt&&!u.value)){f=!0,e[o]=ci(Ge,a.condition,{body:a.condition});continue}if(p&&!a.alternative&&u instanceof gt&&u.value){f=!0,(a=a.clone()).alternative=u,e[o]=a.transform(t),e.splice(s,1);continue}if(p&&!a.alternative&&(!u&&r&&i||u instanceof gt)){f=!0,(a=a.clone()).alternative=u||ci(gt,a,{value:null}),e[o]=a.transform(t),u&&e.splice(s,1);continue}var m=e[S(o)];if(t.option("sequences")&&r&&!a.alternative&&m instanceof bt&&m.body instanceof gt&&g(s)==e.length&&u instanceof Ge){f=!0,(a=a.clone()).alternative=ci(We,u,{body:[u,ci(gt,u,{value:null})]}),e[o]=a.transform(t),e.splice(s,1);continue}}}function E(i){if(!i)return!1;for(var a=o+1,s=e.length;a=0;){var i=e[n];if(!(i instanceof xt&&_(i)))break}return n}}function p(e,t){for(var n,i=t.self(),r=0,o=0,a=e.length;r!e.value)}function m(e,t){if(!(e.length<2)){for(var n=[],i=0,r=0,o=e.length;r=t.sequences_limit&&c();var s=a.body;n.length>0&&(s=s.drop_side_effect_free(t)),s&&_i(n,s)}else a instanceof wt&&_(a)||a instanceof ft?e[i++]=a:(c(),e[i++]=a)}c(),e.length=i,i!=o&&(f=!0)}function c(){if(n.length){var t=li(n[0],n);e[i++]=ci(Ge,t,{body:t}),n=[]}}}function E(e,t){if(!(e instanceof We))return e;for(var n=null,i=0,r=e.body.length;i0){var p=u.length;u.push(ci(bt,a,{condition:a.condition,body:c||ci(Ye,a.body),alternative:l})),u.unshift(r,1),[].splice.apply(e,u),o+=p,r+=p+1,i=null,f=!0;continue}}e[r++]=a,i=a instanceof Ge?a:null}e.length=r}function D(e,t){if(e instanceof wt){var n,i=e.definitions[e.definitions.length-1];if(i.value instanceof en)if(t instanceof Zt?n=[t]:t instanceof Gt&&(n=t.expressions.slice()),n){var o=!1;do{var a=n[0];if(!(a instanceof Zt))break;if("="!=a.operator)break;if(!(a.left instanceof Ht))break;var u=a.left.expression;if(!(u instanceof wn))break;if(i.name.name!=u.name)break;if(!a.right.is_constant_expression(s))break;var c=a.left.property;if(c instanceof Pe&&(c=c.evaluate(r)),c instanceof Pe)break;c=""+c;var l=r.option("ecma")<6&&r.has_directive("use strict")?function(e){return e.key!=c&&e.key&&e.key.name!=c}:function(e){return e.key&&e.key.name!=c};if(!i.value.properties.every(l))break;var f=i.value.properties.filter(function(e){return e.key===c})[0];f?f.value=new Gt({start:f.start,expressions:[f.value.clone(),a.right.clone()],end:f.end}):i.value.properties.push(ci(nn,a,{key:c,value:a.right})),n.shift(),o=!0}while(n.length);return o&&n}}}function g(e){for(var t,n=0,i=-1,r=e.length;n=0;)if(this.properties[n]._dot_throw(e))return!0;return!1}),e(tn,s),e(on,u),e(at,function(e){return this.expression._dot_throw(e)}),e(ct,s),e(lt,s),e(qt,s),e(Yt,function(){return"void"==this.operator}),e($t,function(e){return("&&"==this.operator||"||"==this.operator)&&(this.left._dot_throw(e)||this.right._dot_throw(e))}),e(Zt,function(e){return"="==this.operator&&this.right._dot_throw(e)}),e(jt,function(e){return this.consequent._dot_throw(e)||this.alternative._dot_throw(e)}),e(Xt,function(e){return!!t(e)&&!(this.expression instanceof ct&&"prototype"==this.property)}),e(Gt,function(e){return this.tail_node()._dot_throw(e)}),e(wn,function(e){if(Ar(this,_r))return!0;if(!t(e))return!1;if(gi(this)&&this.is_declared(e))return!1;if(this.is_immutable())return!1;var n=this.fixed_value();return!n||n._dot_throw(e)})}(function(e,t){e.DEFMETHOD("_dot_throw",t)}),function(e){const t=E("! delete"),n=E("in instanceof == != === !== < <= >= >");e(Pe,s),e(Yt,function(){return t.has(this.operator)}),e($t,function(){return n.has(this.operator)||Cr.has(this.operator)&&this.left.is_boolean()&&this.right.is_boolean()}),e(jt,function(){return this.consequent.is_boolean()&&this.alternative.is_boolean()}),e(Zt,function(){return"="==this.operator&&this.right.is_boolean()}),e(Gt,function(){return this.tail_node().is_boolean()}),e(vi,u),e(Si,u)}(function(e,t){e.DEFMETHOD("is_boolean",t)}),function(e){e(Pe,s),e(zn,u);var t=E("+ - ~ ++ --");e(Wt,function(){return t.has(this.operator)});var n=E("- * / % & | ^ << >> >>>");e($t,function(e){return n.has(this.operator)||"+"==this.operator&&this.left.is_number(e)&&this.right.is_number(e)}),e(Zt,function(e){return n.has(this.operator.slice(0,-1))||"="==this.operator&&this.right.is_number(e)}),e(Gt,function(e){return this.tail_node().is_number(e)}),e(jt,function(e){return this.consequent.is_number(e)&&this.alternative.is_number(e)})}(function(e,t){e.DEFMETHOD("is_number",t)}),(br=function(e,t){e.DEFMETHOD("is_string",t)})(Pe,s),br(Xn,u),br(dt,function(){return 1===this.segments.length}),br(Yt,function(){return"typeof"==this.operator}),br($t,function(e){return"+"==this.operator&&(this.left.is_string(e)||this.right.is_string(e))}),br(Zt,function(e){return("="==this.operator||"+="==this.operator)&&this.right.is_string(e)}),br(Gt,function(e){return this.tail_node().is_string(e)}),br(jt,function(e){return this.consequent.is_string(e)&&this.alternative.is_string(e)});var Cr=E("&& ||"),Or=E("delete ++ --");function Ri(e,t){return t instanceof Wt&&Or.has(t.operator)?t.expression:t instanceof Zt&&t.left===e?e:void 0}function Ni(e,t){return e.print_to_string().length>t.print_to_string().length?t:e}function wi(e,t){return Ni(ci(Ge,e,{body:e}),ci(Ge,t,{body:t})).body}function xi(e,t,n){return(Mn(e)?wi:Ni)(t,n)}function ki(e){const t=new Map;for(var n of Object.keys(e))t.set(n,E(e[n]));return t}!function(e){function t(e,t){e.warn("global_defs "+t.print_to_string()+" redefined [{file}:{line},{col}]",t.start)}ot.DEFMETHOD("resolve_defines",function(e){return e.option("global_defs")?(this.figure_out_scope({ie8:e.option("ie8")}),this.transform(new vn(function(n){var i=n._find_defs(e,"");if(i){for(var r,o=0,a=n;(r=this.parent(o++))&&r instanceof Ht&&r.expression===a;)a=r;if(!Ri(a,r))return i;t(e,n)}}))):this}),e(Pe,a),e(Xt,function(e,t){return this.expression._find_defs(e,"."+this.property+t)}),e(pn,function(e){this.global()&&D(e.option("global_defs"),this.name)&&t(e,this)}),e(wn,function(e,t){if(this.global()){var n=e.option("global_defs"),i=this.name+t;return D(n,i)?function e(t,n){if(t instanceof Pe)return ci(t.CTOR,n,t);if(Array.isArray(t))return ci(Jt,n,{elements:t.map(function(t){return e(t,n)})});if(t&&"object"==typeof t){var i=[];for(var r in t)D(t,r)&&i.push(ci(nn,n,{key:r,value:e(t[r],n)}));return ci(en,n,{properties:i})}return fi(t,n)}(n[i],this):void 0}})}(function(e,t){e.DEFMETHOD("_find_defs",t)});var Fr=["constructor","toString","valueOf"],Mr=ki({Array:["indexOf","join","lastIndexOf","slice"].concat(Fr),Boolean:Fr,Function:Fr,Number:["toExponential","toFixed","toPrecision"].concat(Fr),Object:Fr,RegExp:["test"].concat(Fr),String:["charAt","charCodeAt","concat","indexOf","italics","lastIndexOf","match","replace","search","slice","split","substr","substring","toLowerCase","toUpperCase","trim"].concat(Fr)}),Rr=ki({Array:["isArray"],Math:["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan","atan2","pow","max","min"],Number:["isFinite","isNaN"],Object:["create","getOwnPropertyDescriptor","getOwnPropertyNames","getPrototypeOf","isExtensible","isFrozen","isSealed","keys"],String:["fromCharCode"]});!function(e){Pe.DEFMETHOD("evaluate",function(e){if(!e.option("evaluate"))return this;var t=this._eval(e,1);return!t||t instanceof RegExp?t:"function"==typeof t||"object"==typeof t?this:t});var t=E("! ~ - + void");Pe.DEFMETHOD("is_constant",function(){return this instanceof Hn?!(this instanceof Yn):this instanceof Yt&&this.expression instanceof Hn&&t.has(this.operator)}),e(Be,function(){throw new Error(_("Cannot evaluate a statement [{file}:{line},{col}]",this.start))}),e(st,c),e(sn,c),e(Pe,c),e(Hn,function(){return this.getValue()}),e(Yn,function(e){let t=e.evaluated_regexps.get(this);if(void 0===t){try{t=(0,eval)(this.print_to_string())}catch(e){t=null}e.evaluated_regexps.set(this,t)}return t||this}),e(dt,function(){return 1!==this.segments.length?this:this.segments[0].value}),e(ct,function(e){if(e.option("unsafe")){var t=function(){};return t.node=this,t.toString=function(){return this.node.print_to_string()},t}return this}),e(Jt,function(e,t){if(e.option("unsafe")){for(var n=[],i=0,r=this.elements.length;i>":r=n>>o;break;case">>>":r=n>>>o;break;case"==":r=n==o;break;case"===":r=n===o;break;case"!=":r=n!=o;break;case"!==":r=n!==o;break;case"<":r=n":r=n>o;break;case">=":r=n>=o;break;default:return this}return isNaN(r)&&e.find_parent(it)?this:r}),e(jt,function(e,t){var n=this.condition._eval(e,t);if(n===this.condition)return this;var i=n?this.consequent:this.alternative,r=i._eval(e,t);return r===i?this:r}),e(wn,function(e,t){var n,i=this.fixed_value();if(!i)return this;if(D(i,"_eval"))n=i._eval();else{if(this._eval=c,n=i._eval(e,t),delete this._eval,n===i)return this;i._eval=function(){return n}}if(n&&"object"==typeof n){var r=this.definition().escaped;if(r&&t>r)return this}return n});var r={Array:Array,Math:Math,Number:Number,Object:Object,String:String},o=ki({Math:["E","LN10","LN2","LOG2E","LOG10E","PI","SQRT1_2","SQRT2"],Number:["MAX_VALUE","MIN_VALUE","NaN","NEGATIVE_INFINITY","POSITIVE_INFINITY"]});e(Ht,function(e,t){if(e.option("unsafe")){var n=this.property;if(n instanceof Pe&&(n=n._eval(e,t))===this.property)return this;var i,a=this.expression;if(gi(a)){var s,u="hasOwnProperty"===a.name&&"call"===n&&(s=e.parent()&&e.parent().args)&&s&&s[0]&&s[0].evaluate(e);if(null==(u=u instanceof Xt?u.expression:u)||u.thedef&&u.thedef.undeclared)return this.clone();var c=o.get(a.name);if(!c||!c.has(n))return this;i=r[a.name]}else{if(!(i=a._eval(e,t+1))||i===a||!D(i,n))return this;if("function"==typeof i)switch(n){case"name":return i.node.name?i.node.name.name:"";case"length":return i.node.argnames.length;default:return this}}return i[n]}return this}),e(Kt,function(e,t){var n=this.expression;if(e.option("unsafe")&&n instanceof Ht){var i,o=n.property;if(o instanceof Pe&&(o=o._eval(e,t))===n.property)return this;var a=n.expression;if(gi(a)){var s="hasOwnProperty"===a.name&&"call"===o&&this.args[0]&&this.args[0].evaluate(e);if(null==(s=s instanceof Xt?s.expression:s)||s.thedef&&s.thedef.undeclared)return this.clone();var u=Rr.get(a.name);if(!u||!u.has(o))return this;i=r[a.name]}else{if((i=a._eval(e,t+1))===a||!i)return this;var c=Mr.get(i.constructor.name);if(!c||!c.has(o))return this}for(var l=[],f=0,p=this.args.length;f=":return r.operator="<",r;case">":return r.operator="<=",r}switch(o){case"==":return r.operator="!=",r;case"!=":return r.operator="==",r;case"===":return r.operator="!==",r;case"!==":return r.operator="===",r;case"&&":return r.operator="||",r.left=r.left.negate(e,i),r.right=r.right.negate(e),n(this,r,i);case"||":return r.operator="&&",r.left=r.left.negate(e,i),r.right=r.right.negate(e),n(this,r,i)}return t(this)})}(function(e,t){e.DEFMETHOD("negate",function(e,n){return t.call(this,e,n)})});var Nr=E("Boolean decodeURI decodeURIComponent Date encodeURI encodeURIComponent Error escape EvalError isFinite isNaN Number Object parseFloat parseInt RangeError ReferenceError String SyntaxError TypeError unescape URIError");Kt.DEFMETHOD("is_expr_pure",function(e){if(e.option("unsafe")){var t=this.expression,n=this.args&&this.args[0]&&this.args[0].evaluate(e);if(t.expression&&"hasOwnProperty"===t.expression.name&&(null==n||n.thedef&&n.thedef.undeclared))return!1;if(gi(t)&&Nr.has(t.name))return!0;let i;if(t instanceof Xt&&gi(t.expression)&&(i=Rr.get(t.expression.name))&&i.has(t.property))return!0}return!!T(this,Ii)||!e.pure_funcs(this)}),Pe.DEFMETHOD("is_call_pure",s),Xt.DEFMETHOD("is_call_pure",function(e){if(!e.option("unsafe"))return;const t=this.expression;let n;return t instanceof Jt?n=Mr.get("Array"):t.is_boolean()?n=Mr.get("Boolean"):t.is_number(e)?n=Mr.get("Number"):t instanceof Yn?n=Mr.get("RegExp"):t.is_string(e)?n=Mr.get("String"):this.may_throw_on_access(e)||(n=Mr.get("Object")),n&&n.has(this.property)});const wr=new Set(["Number","String","Array","Object","Function","Promise"]);function Ki(e){return e&&e.aborts()}!function(e){function t(e,t){for(var n=e.length;--n>=0;)if(e[n].has_side_effects(t))return!0;return!1}e(Pe,u),e(Ye,s),e(Hn,s),e(Pn,s),e(ze,function(e){return t(this.body,e)}),e(Kt,function(e){return!(this.is_expr_pure(e)||this.expression.is_call_pure(e)&&!this.expression.has_side_effects(e))||t(this.args,e)}),e(yt,function(e){return this.expression.has_side_effects(e)||t(this.body,e)}),e(Ft,function(e){return this.expression.has_side_effects(e)||t(this.body,e)}),e(Mt,function(e){return t(this.body,e)||this.bcatch&&this.bcatch.has_side_effects(e)||this.bfinally&&this.bfinally.has_side_effects(e)}),e(bt,function(e){return this.condition.has_side_effects(e)||this.body&&this.body.has_side_effects(e)||this.alternative&&this.alternative.has_side_effects(e)}),e($e,function(e){return this.body.has_side_effects(e)}),e(Ge,function(e){return this.body.has_side_effects(e)}),e(st,s),e(sn,function(e){return!!this.extends&&this.extends.has_side_effects(e)}),e(un,u),e($t,function(e){return this.left.has_side_effects(e)||this.right.has_side_effects(e)}),e(Zt,u),e(jt,function(e){return this.condition.has_side_effects(e)||this.consequent.has_side_effects(e)||this.alternative.has_side_effects(e)}),e(Wt,function(e){return Or.has(this.operator)||this.expression.has_side_effects(e)}),e(wn,function(e){return!this.is_declared(e)&&!wr.has(this.name)}),e(pn,s),e(en,function(e){return t(this.properties,e)}),e(tn,function(e){return!!(this instanceof nn&&this.key instanceof Pe&&this.key.has_side_effects(e))||this.value.has_side_effects(e)}),e(Jt,function(e){return t(this.elements,e)}),e(Xt,function(e){return this.expression.may_throw_on_access(e)||this.expression.has_side_effects(e)}),e(zt,function(e){return this.expression.may_throw_on_access(e)||this.expression.has_side_effects(e)||this.property.has_side_effects(e)}),e(Gt,function(e){return t(this.expressions,e)}),e(wt,function(e){return t(this.definitions,e)}),e(Bt,function(e){return this.value}),e(mt,s),e(dt,function(e){return t(this.segments,e)})}(function(e,t){e.DEFMETHOD("has_side_effects",t)}),function(e){function t(e,t){for(var n=e.length;--n>=0;)if(e[n].may_throw(t))return!0;return!1}e(Pe,u),e(sn,s),e(Hn,s),e(Ye,s),e(st,s),e(pn,s),e(Pn,s),e(Jt,function(e){return t(this.elements,e)}),e(Zt,function(e){return!!this.right.may_throw(e)||!(!e.has_directive("use strict")&&"="==this.operator&&this.left instanceof wn)&&this.left.may_throw(e)}),e($t,function(e){return this.left.may_throw(e)||this.right.may_throw(e)}),e(ze,function(e){return t(this.body,e)}),e(Kt,function(e){return!!t(this.args,e)||!this.is_expr_pure(e)&&(!!this.expression.may_throw(e)||(!(this.expression instanceof st)||t(this.expression.body,e)))}),e(Ft,function(e){return this.expression.may_throw(e)||t(this.body,e)}),e(jt,function(e){return this.condition.may_throw(e)||this.consequent.may_throw(e)||this.alternative.may_throw(e)}),e(wt,function(e){return t(this.definitions,e)}),e(Xt,function(e){return this.expression.may_throw_on_access(e)||this.expression.may_throw(e)}),e(bt,function(e){return this.condition.may_throw(e)||this.body&&this.body.may_throw(e)||this.alternative&&this.alternative.may_throw(e)}),e($e,function(e){return this.body.may_throw(e)}),e(en,function(e){return t(this.properties,e)}),e(tn,function(e){return this.value.may_throw(e)}),e(gt,function(e){return this.value&&this.value.may_throw(e)}),e(Gt,function(e){return t(this.expressions,e)}),e(Ge,function(e){return this.body.may_throw(e)}),e(zt,function(e){return this.expression.may_throw_on_access(e)||this.expression.may_throw(e)||this.property.may_throw(e)}),e(yt,function(e){return this.expression.may_throw(e)||t(this.body,e)}),e(wn,function(e){return!this.is_declared(e)&&!wr.has(this.name)}),e(Mt,function(e){return this.bcatch?this.bcatch.may_throw(e):t(this.body,e)||this.bfinally&&this.bfinally.may_throw(e)}),e(Wt,function(e){return!("typeof"==this.operator&&this.expression instanceof wn)&&this.expression.may_throw(e)}),e(Bt,function(e){return!!this.value&&this.value.may_throw(e)})}(function(e,t){e.DEFMETHOD("may_throw",t)}),function(e){function t(e){var t=this,n=!0;return t.walk(new An(function(r){if(!n)return!0;if(r instanceof wn){if(Ar(t,dr))return n=!1,!0;var o=r.definition();if(i(o,t.enclosed)&&!t.variables.has(o.name)){if(e){var a=e.find_variable(r);if(o.undeclared?!a:a===o)return n="f",!0}n=!1}return!0}return r instanceof Pn&&t instanceof lt?(n=!1,!0):void 0})),n}e(Pe,s),e(Hn,u),e(sn,function(e){return!(this.extends&&!this.extends.is_constant_expression(e))&&t.call(this,e)}),e(st,t),e(Wt,function(){return this.expression.is_constant_expression()}),e($t,function(){return this.left.is_constant_expression()&&this.right.is_constant_expression()}),e(Jt,function(){return this.elements.every(e=>e.is_constant_expression())}),e(en,function(){return this.properties.every(e=>e.is_constant_expression())}),e(tn,function(){return!(this.key instanceof Pe)&&this.value.is_constant_expression()})}(function(e,t){e.DEFMETHOD("is_constant_expression",t)}),function(e){function t(){for(var e=0;e1)&&(s.name=null),s instanceof st&&!(s instanceof ut))for(var h=!e.option("keep_fargs"),D=s.argnames,A=D.length;--A>=0;){var S=D[A];S instanceof at&&(S=S.expression),S instanceof Qt&&(S=S.left),S instanceof pt||o.has(S.definition().id)?h=!1:(Sr(S,sr),h&&(D.pop(),e[S.unreferenced()?"warn":"info"]("Dropping unused function argument {name} [{file}:{line},{col}]",M(S))))}if((s instanceof ft||s instanceof un)&&s!==t){const t=s.name.definition();if(!(t.global&&!n||o.has(t.id))){if(e[s.name.unreferenced()?"warn":"info"]("Dropping unused function {name} [{file}:{line},{col}]",M(s.name)),t.eliminated++,s instanceof un){const t=s.drop_side_effect_free(e);if(t)return ci(Ge,s,{body:t})}return f?F.skip:ci(Ye,s)}}if(s instanceof wt&&!(_ instanceof tt&&_.init===s)){var v=!(_ instanceof ot||s instanceof xt),T=[],b=[],y=[],C=[];switch(s.definitions.forEach(function(t){t.value&&(t.value=t.value.transform(p));var n=t.name instanceof pt,r=n?new Bn(null,{name:""}):t.name.definition();if(v&&r.global)return y.push(t);if(!i&&!v||n&&(t.name.names.length||t.name.is_array||1!=e.option("pure_getters"))||o.has(r.id)){if(t.value&&a.has(r.id)&&a.get(r.id)!==t&&(t.value=t.value.drop_side_effect_free(e)),t.name instanceof _n){var c=u.get(r.id);if(c.length>1&&(!t.value||r.orig.indexOf(t.name)>r.eliminated)){if(e.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]",M(t.name)),t.value){var l=ci(wn,t.name,t.name);r.references.push(l);var f=ci(Zt,t,{operator:"=",left:l,right:t.value});a.get(r.id)===t&&a.set(r.id,f),C.push(f.transform(p))}return d(c,t),void r.eliminated++}}t.value?(C.length>0&&(y.length>0?(C.push(t.value),t.value=li(t.value,C)):T.push(ci(Ge,s,{body:li(s,C)})),C=[]),y.push(t)):b.push(t)}else if(r.orig[0]instanceof yn){(_=t.value&&t.value.drop_side_effect_free(e))&&C.push(_),t.value=null,b.push(t)}else{var _;(_=t.value&&t.value.drop_side_effect_free(e))?(n||e.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]",M(t.name)),C.push(_)):n||e[t.name.unreferenced()?"warn":"info"]("Dropping unused variable {name} [{file}:{line},{col}]",M(t.name)),r.eliminated++}}),(b.length>0||y.length>0)&&(s.definitions=b.concat(y),T.push(s)),C.length>0&&T.push(ci(Ge,s,{body:li(s,C)})),T.length){case 0:return f?F.skip:ci(Ye,s);case 1:return T[0];default:return f?F.splice(T):ci(We,s,{body:T})}}if(s instanceof et)return c(s,this),s.init instanceof We&&(O=s.init,s.init=O.body.pop(),O.body.push(s)),s.init instanceof Ge?s.init=s.init.body:mi(s.init)&&(s.init=null),O?f?F.splice(O.body):O:s;if(s instanceof $e&&s.body instanceof et){if(c(s,this),s.body instanceof We){var O=s.body;return s.body=O.body.pop(),O.body.push(s),f?F.splice(O.body):O}return s}if(s instanceof We)return c(s,this),f&&s.body.every(Ei)?F.splice(s.body):s;if(s instanceof rt){const e=l;return l=s,c(s,this),l=e,s}}function M(e){return{name:e.name,file:e.start.file,line:e.start.line,col:e.start.col}}});function m(e,n){var i;const s=r(e);if(s instanceof wn&&!ai(e.left,dn)&&t.variables.get(s.name)===(i=s.definition()))return e instanceof Zt&&(e.right.walk(f),i.chained||e.left.fixed_value()!==e.right||a.set(i.id,e)),!0;if(e instanceof wn){if(i=e.definition(),!o.has(i.id)&&(o.set(i.id,i),i.orig[0]instanceof yn)){const e=i.scope.is_block_scope()&&i.scope.get_defun_scope().variables.get(i.name);e&&o.set(e.id,e)}return!0}if(e instanceof rt){var u=l;return l=e,n(),l=u,!0}}t.transform(p)}),rt.DEFMETHOD("hoist_declarations",function(e){var t=this;if(e.has_directive("use asm"))return t;if(!Array.isArray(t.body))return t;var n=e.option("hoist_funs"),i=e.option("hoist_vars");if(n||i){var r=[],o=[],a=new Map,s=0,u=0;t.walk(new An(function(e){return e instanceof rt&&e!==t||(e instanceof xt?(++u,!0):void 0)})),i=i&&u>1;var c=new vn(function(u){if(u!==t){if(u instanceof Ue)return r.push(u),ci(Ye,u);if(n&&u instanceof ft&&!(c.parent()instanceof Pt)&&c.parent()===t)return o.push(u),ci(Ye,u);if(i&&u instanceof xt){u.definitions.forEach(function(e){e.name instanceof pt||(a.set(e.name.name,e),++s)});var l=u.to_assignments(e),f=c.parent();if(f instanceof tt&&f.init===u){if(null==l){var p=u.definitions[0].name;return ci(wn,p,p)}return l}return f instanceof et&&f.init===u?l:l?ci(Ge,u,{body:l}):ci(Ye,u)}if(u instanceof rt)return u}});if(t=t.transform(c),s>0){var l=[];const e=t instanceof st,n=e?t.args_as_names():null;if(a.forEach((t,i)=>{e&&n.some(e=>e.name===t.name.name)?a.delete(i):((t=t.clone()).value=null,l.push(t),a.set(i,t))}),l.length>0){for(var f=0;f"string"==typeof e.key)){a(o,this);const e=new Map,t=[];return c.properties.forEach(function(n){t.push(ci(Bt,o,{name:s(r,n.key,e),value:n.value}))}),i.set(u.id,e),F.splice(t)}}else if(o instanceof Ht&&o.expression instanceof wn){const e=i.get(o.expression.definition().id);if(e){const t=e.get(String(Ci(o.property))),n=ci(wn,o,{name:t.name,scope:o.expression.scope,thedef:t});return n.reference({}),n}}function s(e,n,i){const r=ci(e.CTOR,e,{name:t.make_var_name(e.name+"_"+n),scope:t}),o=t.def_variable(r);return i.set(String(n),o),t.enclosed.push(o),r}});return t.transform(r)}),function(e){function t(e,t,n){var i=e.length;if(!i)return null;for(var r=[],o=!1,a=0;a0&&(u[0].body=s.concat(u[0].body)),e.body=u;n=u[u.length-1];){var _=n.body[n.body.length-1];if(_ instanceof vt&&t.loopcontrol_target(_)===e&&n.body.pop(),n.body.length||n instanceof Ft&&(o||n.expression.has_side_effects(t)))break;u.pop()===o&&(o=null)}if(0==u.length)return ci(We,e,{body:s.concat(ci(Ge,e.expression,{body:e.expression}))}).optimize(t);if(1==u.length&&(u[0]===a||u[0]===o)){var d=!1,m=new An(function(t){if(d||t instanceof st||t instanceof Ge)return!0;t instanceof vt&&m.loopcontrol_target(t)===e&&(d=!0)});if(e.walk(m),!d){var E,h=u[0].body.slice();return(E=u[0].expression)&&h.unshift(ci(Ge,E,{body:E})),h.unshift(ci(Ge,e.expression,{body:e.expression})),ci(We,e,{body:h}).optimize(t)}}return e;function D(e,n){n&&!Ki(n)?n.body=n.body.concat(e.body):yi(t,e,s)}}),ti(Mt,function(e,t){if(bi(e.body,t),e.bcatch&&e.bfinally&&e.bfinally.body.every(mi)&&(e.bfinally=null),t.option("dead_code")&&e.body.every(mi)){var n=[];return e.bcatch&&yi(t,e.bcatch,n),e.bfinally&&n.push(...e.bfinally.body),ci(We,e,{body:n}).optimize(t)}return e}),wt.DEFMETHOD("remove_initializers",function(){var e=[];this.definitions.forEach(function(t){t.name instanceof pn?(t.value=null,e.push(t)):t.name.walk(new An(function(n){n instanceof pn&&e.push(ci(Bt,t,{name:n,value:null}))}))}),this.definitions=e}),wt.DEFMETHOD("to_assignments",function(e){var t=e.option("reduce_vars"),n=this.definitions.reduce(function(e,n){if(!n.value||n.name instanceof pt){if(n.value){var i=ci(Bt,n,{name:n.name,value:n.value}),r=ci(xt,n,{definitions:[i]});e.push(r)}}else{var o=ci(wn,n.name,n.name);e.push(ci(Zt,n,{operator:"=",left:o,right:n.value})),t&&(o.definition().fixed=!1)}return(n=n.name.definition()).eliminated++,n.replaced--,e},[]);return 0==n.length?null:li(this,n)}),ti(wt,function(e,t){return 0==e.definitions.length?ci(Ye,e):e}),ti(Vt,function(e,t){return e}),ti(Kt,function(e,t){var n=e.expression,i=n;er(e,t,e.args);var r=e.args.every(e=>!(e instanceof at));if(t.option("reduce_vars")&&i instanceof wn&&!T(e,Vi)){const e=i.fixed_value();zi(e,t)||(i=e)}var o=i instanceof st;if(t.option("unused")&&r&&o&&!i.uses_arguments&&!i.pinned()){for(var a=0,s=0,u=0,c=e.args.length;u=i.argnames.length;if(l||Ar(i.argnames[u],sr)){if(D=e.args[u].drop_side_effect_free(t))e.args[a++]=D;else if(!l){e.args[a++]=ci(zn,e.args[u],{value:0});continue}}else e.args[a++]=e.args[u];s=a}e.args.length=s}if(t.option("unsafe"))if(gi(n))switch(n.name){case"Array":if(1!=e.args.length)return ci(Jt,e,{elements:e.args}).optimize(t);if(e.args[0]instanceof zn&&e.args[0].value<=11){const t=[];for(let n=0;n=1&&e.args.length<=2&&e.args.every(e=>{var n=e.evaluate(t);return f.push(n),e!==n})){const[n,i]=f,r=ci(Yn,e,{value:{source:n,flags:i}});if(r._eval(t)!==r)return r;t.warn("Error converting {expr} [{file}:{line},{col}]",{expr:e.print_to_string(),file:e.start.file,line:e.start.line,col:e.start.col})}}else if(n instanceof Xt)switch(n.property){case"toString":if(0==e.args.length&&!n.expression.may_throw_on_access(t))return ci($t,e,{left:ci(Xn,e,{value:""}),operator:"+",right:n.expression}).optimize(t);break;case"join":if(n.expression instanceof Jt)e:{var p;if(!(e.args.length>0&&(p=e.args[0].evaluate(t))===e.args[0])){var _,d=[],m=[];for(u=0,c=n.expression.elements.length;u0&&(d.push(ci(Xn,e,{value:m.join(p)})),m.length=0),d.push(E))}return m.length>0&&d.push(ci(Xn,e,{value:m.join(p)})),0==d.length?ci(Xn,e,{value:""}):1==d.length?d[0].is_string(t)?d[0]:ci($t,d[0],{operator:"+",left:ci(Xn,e,{value:""}),right:d[0]}):""==p?(_=d[0].is_string(t)||d[1].is_string(t)?d.shift():ci(Xn,e,{value:""}),d.reduce(function(e,t){return ci($t,t,{operator:"+",left:e,right:t})},_).optimize(t)):((D=e.clone()).expression=D.expression.clone(),D.expression.expression=D.expression.expression.clone(),D.expression.expression.elements=d,xi(t,e,D));var D}}break;case"charAt":if(n.expression.is_string(t)){var g=e.args[0],A=g?g.evaluate(t):0;if(A!==g)return ci(zt,n,{expression:n.expression,property:fi(0|A,g||n)}).optimize(t)}break;case"apply":if(2==e.args.length&&e.args[1]instanceof Jt)return(N=e.args[1].elements.slice()).unshift(e.args[0]),ci(Kt,e,{expression:ci(Xt,n,{expression:n.expression,property:"call"}),args:N}).optimize(t);break;case"call":var S=n.expression;if(S instanceof wn&&(S=S.fixed_value()),S instanceof st&&!S.contains_this())return(e.args.length?li(this,[e.args[0],ci(Kt,e,{expression:n.expression,args:e.args.slice(1)})]):ci(Kt,e,{expression:n.expression,args:[]})).optimize(t)}if(t.option("unsafe_Function")&&gi(n)&&"Function"==n.name){if(0==e.args.length)return ci(ct,e,{argnames:[],body:[]}).optimize(t);if(e.args.every(e=>e instanceof Xn))try{var v=ue(O="n(function("+e.args.slice(0,-1).map(function(e){return e.value}).join(",")+"){"+e.args[e.args.length-1].value+"})"),b={ie8:t.option("ie8")};v.figure_out_scope(b);var y,C=new ei(t.options);(v=v.transform(C)).figure_out_scope(b),ar.reset(),v.compute_char_frequency(b),v.mangle_names(b),v.walk(new An(function(e){return!!y||(ri(e)?(y=e,!0):void 0)})),y.body instanceof Pe&&(y.body=[ci(gt,y.body,{value:y.body})]);var O=In();return We.prototype._codegen.call(y,y,O),e.args=[ci(Xn,e,{value:y.argnames.map(function(e){return e.print_to_string()}).join(",")}),ci(Xn,e.args[e.args.length-1],{value:O.get().replace(/^{|}$/g,"")})],e}catch(n){if(!(n instanceof J))throw n;t.warn("Error parsing code passed to new Function [{file}:{line},{col}]",e.args[e.args.length-1].start),t.warn(n.toString())}}var F=o&&i.body;F instanceof Pe?F=ci(gt,F,{value:F}):F&&(F=F[0]);var M=o&&!i.is_generator&&!i.async,R=M&&t.option("inline")&&!e.is_expr_pure(t);if(R&&F instanceof gt){let n=F.value;if(!n||n.is_constant_expression()){n=n?n.clone(!0):ci(Zn,e);var N=e.args.concat(n);return li(e,N).optimize(t)}if(1===i.argnames.length&&i.argnames[0]instanceof hn&&e.args.length<2&&"name"===n.start.type&&n.name===i.argnames[0].name)return(e.args[0]||ci(Zn)).optimize(t)}if(R){var w,x,k=-1;let o,a;if(r&&!i.uses_arguments&&!i.pinned()&&!(t.parent()instanceof sn)&&!(i.name&&i instanceof ct)&&(!(t.find_parent(st)instanceof lt)||0==i.argnames.length&&(i.body instanceof Pe||1==i.body.length))&&(a=function(e){var n=i.body instanceof Pe?[i.body]:i.body,r=n.length;if(t.option("inline")<3)return 1==r&&L(e);e=null;for(var o=0;o!e.value))return!1}else{if(e)return!1;a instanceof Ye||(e=a)}}return L(e)}(F))&&(n===i||T(e,Li)||t.option("unused")&&1==(o=n.definition()).references.length&&!Yi(t,o)&&i.is_constant_expression(n.scope))&&!T(e,Ii|Vi)&&!i.contains_this()&&function(){var n=new Set;do{if(!(w=t.parent(++k)).is_block_scope()||t.parent(k-1)instanceof rt||w.block_scope&&w.block_scope.variables.forEach(function(e){n.add(e.name)}),w instanceof Rt)w.argname&&n.add(w.argname.name);else if(w instanceof je)x=[];else if(w instanceof wn&&w.fixed_value()instanceof rt)return!1}while(!(w instanceof rt)||w instanceof lt);var r=!(w instanceof ot)||t.toplevel.vars,o=t.option("inline");return!!function(e,t){for(var n=i.body.length,r=0;r=0;){var s=o.definitions[a].name;if(s instanceof pt||e.has(s.name)||yr.has(s.name)||w.var_names().has(s.name))return!1;x&&x.push(s.definition())}}}return!0}(n,o>=3&&r)&&(!!function(e,t){for(var n=0,r=i.argnames.length;n=2&&r)&&(!!function(){var t=new Set,n=new An(function(e){if(e instanceof rt){var n=new Set;return e.enclosed.forEach(function(e){n.add(e.name)}),e.variables.forEach(function(e){n.delete(e)}),n.forEach(function(e){t.add(e)}),!0}return!1});if(e.args.forEach(function(e){e.walk(n)}),0==t.size)return!0;for(var r=0,o=i.argnames.length;r=0;){var c=s.definitions[u].name;if(c instanceof pt||t.has(c.name))return!1}}return!0}()&&(!x||0==x.length||!$i(i,x))))}()&&!(w instanceof sn))return Sr(i,Er),si(t,!0).add_child_scope(i),li(e,function(n){var r=[],o=[];(function(t,n){for(var r=i.argnames.length,o=e.args.length;--o>=r;)n.push(e.args[o]);for(o=r;--o>=0;){var a=i.argnames[o],s=e.args[o];if(Ar(a,sr)||!a.name||w.var_names().has(a.name))s&&n.push(s);else{var u=ci(_n,a,a);a.definition().orig.push(u),!s&&x&&(s=ci(Zn,e)),V(t,n,u,s)}}t.reverse(),n.reverse()})(r,o),function(e,t){for(var n=t.length,r=0,o=i.body.length;re.name!=l.name)){var f=i.variables.get(l.name),p=ci(wn,l,l);f.references.push(p),t.splice(n++,0,ci(Zt,c,{operator:"=",left:p,right:ci(Zn,l)}))}}}}(r,o),o.push(n),r.length&&(u=w.body.indexOf(t.parent(k-1))+1,w.body.splice(u,0,ci(xt,i,{definitions:r})));return o.map(e=>e.clone(!0))}(a)).optimize(t)}if(M&&t.option("side_effects")&&!(i.body instanceof Pe)&&i.body.every(mi)){N=e.args.concat(ci(Zn,e));return li(e,N).optimize(t)}if(t.option("negate_iife")&&t.parent()instanceof Ge&&Di(e))return e.negate(t,!0);var I=e.evaluate(t);return I!==e?(I=fi(I,e).optimize(t),xi(t,I,e)):e;function L(t){return t?t instanceof gt?t.value?t.value.clone(!0):ci(Zn,e):t instanceof Ge?ci(Yt,t,{operator:"void",expression:t.body.clone(!0)}):void 0:ci(Zn,e)}function V(t,n,i,r){var o=i.definition();w.variables.set(i.name,o),w.enclosed.push(o),w.var_names().has(i.name)||(w.add_var_name(i.name),t.push(ci(Bt,i,{name:i,value:null})));var a=ci(wn,i,i);o.references.push(a),r&&n.push(ci(Zt,e,{operator:"=",left:a,right:r.clone()}))}}),ti(Ut,function(e,t){return t.option("unsafe")&&gi(e.expression)&&["Object","RegExp","Function","Error","Array"].includes(e.expression.name)?ci(Kt,e,e).transform(t):e}),ti(Gt,function(e,t){if(!t.option("side_effects"))return e;var n,i,r=[];n=Mn(t),i=e.expressions.length-1,e.expressions.forEach(function(e,o){o0&&Oi(r[o],t);)o--;o0)return(n=this.clone()).right=li(this.right,t.slice(o)),(t=t.slice(0,o)).push(n),li(this,t).optimize(e)}}return this});var Ir=E("== === != !== * & | ^");function Yi(e,t){for(var n,i=0;n=e.parent(i);i++)if(n instanceof st){var r=n.name;if(r&&r.definition()===t)break}return n}function qi(e,t){return e instanceof wn||e.TYPE===t.TYPE}function $i(e,t){var n=!1,r=new An(function(e){return!!n||(e instanceof wn&&i(e.definition(),t)?n=!0:void 0)}),o=new An(function(t){if(n)return!0;if(t instanceof rt&&t!==e){var i=o.parent();if(i instanceof Kt&&i.expression===t)return;return t.walk(r),!0}});return e.walk(o),n}ti($t,function(e,t){function n(){return e.left.is_constant()||e.right.is_constant()||!e.left.has_side_effects(t)&&!e.right.has_side_effects(t)}function i(t){if(n()){t&&(e.operator=t);var i=e.left;e.left=e.right,e.right=i}}if(Ir.has(e.operator)&&e.right.is_constant()&&!e.left.is_constant()&&(e.left instanceof $t&&Ie[e.left.operator]>=Ie[e.operator]||i()),e=e.lift_sequences(t),t.option("comparisons"))switch(e.operator){case"===":case"!==":var r=!0;(e.left.is_string(t)&&e.right.is_string(t)||e.left.is_number(t)&&e.right.is_number(t)||e.left.is_boolean()&&e.right.is_boolean()||e.left.equivalent_to(e.right))&&(e.operator=e.operator.substr(0,2));case"==":case"!=":if(!r&&Oi(e.left,t))e.left=ci($n,e.left);else if(t.option("typeofs")&&e.left instanceof Xn&&"undefined"==e.left.value&&e.right instanceof Yt&&"typeof"==e.right.operator){var o=e.right.expression;(o instanceof wn?!o.is_declared(t):o instanceof Ht&&t.option("ie8"))||(e.right=o,e.left=ci(Zn,e.left).optimize(t),2==e.operator.length&&(e.operator+="="))}else if(e.left instanceof wn&&e.right instanceof wn&&e.left.definition()===e.right.definition()&&((u=e.left.fixed_value())instanceof Jt||u instanceof st||u instanceof en||u instanceof sn))return ci("="==e.operator[0]?vi:Si,e);break;case"&&":case"||":var a=e.left;if(a.operator==e.operator&&(a=a.right),a instanceof $t&&a.operator==("&&"==e.operator?"!==":"===")&&e.right instanceof $t&&a.operator==e.right.operator&&(Oi(a.left,t)&&e.right.left instanceof $n||a.left instanceof $n&&Oi(e.right.left,t))&&!a.right.has_side_effects(t)&&a.right.equivalent_to(e.right.right)){var s=ci($t,e,{operator:a.operator.slice(0,-1),left:ci($n,e),right:a.right});return a!==e.left&&(s=ci($t,e,{operator:e.operator,left:e.left.left,right:s})),s}}var u;if("+"==e.operator&&t.in_boolean_context()){var c=e.left.evaluate(t),l=e.right.evaluate(t);if(c&&"string"==typeof c)return t.warn("+ in boolean context always true [{file}:{line},{col}]",e.start),li(e,[e.right,ci(vi,e)]).optimize(t);if(l&&"string"==typeof l)return t.warn("+ in boolean context always true [{file}:{line},{col}]",e.start),li(e,[e.left,ci(vi,e)]).optimize(t)}if(t.option("comparisons")&&e.is_boolean()){if(!(t.parent()instanceof $t)||t.parent()instanceof Zt){var f=ci(Yt,e,{operator:"!",expression:e.negate(t,Mn(t))});e=xi(t,e,f)}if(t.option("unsafe_comps"))switch(e.operator){case"<":i(">");break;case"<=":i(">=")}}if("+"==e.operator){if(e.right instanceof Xn&&""==e.right.getValue()&&e.left.is_string(t))return e.left;if(e.left instanceof Xn&&""==e.left.getValue()&&e.right.is_string(t))return e.right;if(e.left instanceof $t&&"+"==e.left.operator&&e.left.left instanceof Xn&&""==e.left.left.getValue()&&e.right.is_string(t))return e.left=e.left.right,e.transform(t)}if(t.option("evaluate")){switch(e.operator){case"&&":if(!(c=!!Ar(e.left,2)||!Ar(e.left,4)&&e.left.evaluate(t)))return t.warn("Condition left of && always false [{file}:{line},{col}]",e.start),pi(t.parent(),t.self(),e.left).optimize(t);if(!(c instanceof Pe))return t.warn("Condition left of && always true [{file}:{line},{col}]",e.start),li(e,[e.left,e.right]).optimize(t);if(l=e.right.evaluate(t)){if(!(l instanceof Pe)){if("&&"==(p=t.parent()).operator&&p.left===t.self()||t.in_boolean_context())return t.warn("Dropping side-effect-free && [{file}:{line},{col}]",e.start),e.left.optimize(t)}}else{if(t.in_boolean_context())return t.warn("Boolean && always false [{file}:{line},{col}]",e.start),li(e,[e.left,ci(Si,e)]).optimize(t);Sr(e,4)}if("||"==e.left.operator)if(!(_=e.left.right.evaluate(t)))return ci(jt,e,{condition:e.left.left,consequent:e.right,alternative:e.left.right}).optimize(t);break;case"||":var p,_;if(!(c=!!Ar(e.left,2)||!Ar(e.left,4)&&e.left.evaluate(t)))return t.warn("Condition left of || always false [{file}:{line},{col}]",e.start),li(e,[e.left,e.right]).optimize(t);if(!(c instanceof Pe))return t.warn("Condition left of || always true [{file}:{line},{col}]",e.start),pi(t.parent(),t.self(),e.left).optimize(t);if(l=e.right.evaluate(t)){if(!(l instanceof Pe)){if(t.in_boolean_context())return t.warn("Boolean || always true [{file}:{line},{col}]",e.start),li(e,[e.left,ci(vi,e)]).optimize(t);Sr(e,2)}}else if("||"==(p=t.parent()).operator&&p.left===t.self()||t.in_boolean_context())return t.warn("Dropping side-effect-free || [{file}:{line},{col}]",e.start),e.left.optimize(t);if("&&"==e.left.operator)if((_=e.left.right.evaluate(t))&&!(_ instanceof Pe))return ci(jt,e,{condition:e.left.left,consequent:e.left.right,alternative:e.right}).optimize(t)}var d=!0;switch(e.operator){case"+":if(e.left instanceof Hn&&e.right instanceof $t&&"+"==e.right.operator&&e.right.left instanceof Hn&&e.right.is_string(t)&&(e=ci($t,e,{operator:"+",left:ci(Xn,e.left,{value:""+e.left.getValue()+e.right.left.getValue(),start:e.left.start,end:e.right.left.end}),right:e.right.right})),e.right instanceof Hn&&e.left instanceof $t&&"+"==e.left.operator&&e.left.right instanceof Hn&&e.left.is_string(t)&&(e=ci($t,e,{operator:"+",left:e.left.left,right:ci(Xn,e.right,{value:""+e.left.right.getValue()+e.right.getValue(),start:e.left.right.start,end:e.right.end})})),e.left instanceof $t&&"+"==e.left.operator&&e.left.is_string(t)&&e.left.right instanceof Hn&&e.right instanceof $t&&"+"==e.right.operator&&e.right.left instanceof Hn&&e.right.is_string(t)&&(e=ci($t,e,{operator:"+",left:ci($t,e.left,{operator:"+",left:e.left.left,right:ci(Xn,e.left.right,{value:""+e.left.right.getValue()+e.right.left.getValue(),start:e.left.right.start,end:e.right.left.end})}),right:e.right.right})),e.right instanceof Yt&&"-"==e.right.operator&&e.left.is_number(t)){e=ci($t,e,{operator:"-",left:e.left,right:e.right.expression});break}if(e.left instanceof Yt&&"-"==e.left.operator&&n()&&e.right.is_number(t)){e=ci($t,e,{operator:"-",left:e.right,right:e.left.expression});break}case"*":d=t.option("unsafe_math");case"&":case"|":case"^":if(e.left.is_number(t)&&e.right.is_number(t)&&n()&&!(e.left instanceof $t&&e.left.operator!=e.operator&&Ie[e.left.operator]>=Ie[e.operator])){var m=ci($t,e,{operator:e.operator,left:e.right,right:e.left});e=e.right instanceof Hn&&!(e.left instanceof Hn)?xi(t,m,e):xi(t,e,m)}d&&e.is_number(t)&&(e.right instanceof $t&&e.right.operator==e.operator&&(e=ci($t,e,{operator:e.operator,left:ci($t,e.left,{operator:e.operator,left:e.left,right:e.right.left,start:e.left.start,end:e.right.left.end}),right:e.right.right})),e.right instanceof Hn&&e.left instanceof $t&&e.left.operator==e.operator&&(e.left.left instanceof Hn?e=ci($t,e,{operator:e.operator,left:ci($t,e.left,{operator:e.operator,left:e.left.left,right:e.right,start:e.left.left.start,end:e.right.end}),right:e.left.right}):e.left.right instanceof Hn&&(e=ci($t,e,{operator:e.operator,left:ci($t,e.left,{operator:e.operator,left:e.left.right,right:e.right,start:e.left.right.start,end:e.right.end}),right:e.left.left}))),e.left instanceof $t&&e.left.operator==e.operator&&e.left.right instanceof Hn&&e.right instanceof $t&&e.right.operator==e.operator&&e.right.left instanceof Hn&&(e=ci($t,e,{operator:e.operator,left:ci($t,e.left,{operator:e.operator,left:ci($t,e.left.left,{operator:e.operator,left:e.left.right,right:e.right.left,start:e.left.right.start,end:e.right.left.end}),right:e.left.left}),right:e.right.right})))}}if(e.right instanceof $t&&e.right.operator==e.operator&&(Cr.has(e.operator)||"+"==e.operator&&(e.right.left.is_string(t)||e.left.is_string(t)&&e.right.right.is_string(t))))return e.left=ci($t,e.left,{operator:e.operator,left:e.left,right:e.right.left}),e.right=e.right.right,e.transform(t);var E=e.evaluate(t);return E!==e?(E=fi(E,e).optimize(t),xi(t,E,e)):e}),ti(xn,function(e,t){return e}),ti(wn,function(e,t){if(!t.option("ie8")&&gi(e)&&(!e.scope.uses_with||!t.find_parent(it)))switch(e.name){case"undefined":return ci(Zn,e).optimize(t);case"NaN":return ci(jn,e).optimize(t);case"Infinity":return ci(Jn,e).optimize(t)}var n,i=t.parent();if(t.option("reduce_vars")&&Ri(e,i)!==e){const p=e.definition();if(t.top_retain&&p.global&&t.top_retain(p))return p.fixed=!1,p.should_replace=!1,p.single_use=!1,e;var r=e.fixed_value(),o=p.single_use&&!(i instanceof Kt&&i.is_expr_pure(t));if(o&&(r instanceof st||r instanceof sn))if(zi(r,t))o=!1;else if(p.scope!==e.scope&&(1==p.escaped||Ar(r,dr)||function(e){for(var t,n=0;t=e.parent(n++);){if(t instanceof Be)return!1;if(t instanceof Jt||t instanceof nn||t instanceof en)return!0}return!1}(t)))o=!1;else if(Yi(t,p))o=!1;else if((p.scope!==e.scope||p.orig[0]instanceof hn)&&"f"==(o=r.is_constant_expression(e.scope))){var a=e.scope;do{(a instanceof ft||ri(a))&&Sr(a,dr)}while(a=a.parent_scope)}if(o&&r instanceof st&&(o=p.scope===e.scope||i instanceof Kt&&i.expression===e),o&&r instanceof sn&&r.extends&&(o=!r.extends.may_throw(t)&&(!(r.extends instanceof Kt)||r.extends.is_expr_pure(t))),o&&r){if(r instanceof un&&(r=ci(cn,r,r)),r instanceof ft&&(Sr(r,Er),r=ci(ct,r,r)),p.recursive_refs>0&&r.name instanceof Dn){const e=r.name.definition();let t=r.variables.get(r.name.name),n=t&&t.orig[0];n instanceof Sn||((n=ci(Sn,r.name,r.name)).scope=r,r.name=n,t=r.def_function(n)),r.walk(new An(function(n){n instanceof wn&&n.definition()===e&&(n.thedef=t,t.references.push(n))}))}return(r instanceof st||r instanceof sn)&&si(t,!0).add_child_scope(r),r.optimize(t)}if(r&&void 0===p.should_replace){let e;if(r instanceof Pn)p.orig[0]instanceof hn||!p.references.every(e=>p.scope===e.scope)||(e=r);else{var s=r.evaluate(t);s===r||!t.option("unsafe_regexp")&&s instanceof RegExp||(e=fi(s,r))}if(e){var u,c=e.optimize(t).print_to_string().length;r.walk(new An(function(e){if(e instanceof wn&&(n=!0),n)return!0})),n?u=function(){var n=e.optimize(t);return n===e?n.clone(!0):n}:(c=Math.min(c,r.print_to_string().length),u=function(){var n=Ni(e.optimize(t),r);return n===e||n===r?n.clone(!0):n});var l=p.name.length,f=0;t.option("unused")&&!t.exposed(p)&&(f=(l+2+c)/(p.references.length-p.assignments)),p.should_replace=c<=l+f&&u}else p.should_replace=!1}if(p.should_replace)return p.should_replace()}return e}),ti(Zn,function(e,t){if(t.option("unsafe_undefined")){var n=ui(t,"undefined");if(n){var i=ci(wn,e,{name:"undefined",scope:n.scope,thedef:n});return Sr(i,_r),i}}var r=Ri(t.self(),t.parent());return r&&qi(r,e)?e:ci(Yt,e,{operator:"void",expression:ci(zn,e,{value:0})})}),ti(Jn,function(e,t){var n=Ri(t.self(),t.parent());return n&&qi(n,e)?e:!t.option("keep_infinity")||n&&!qi(n,e)||ui(t,"Infinity")?ci($t,e,{operator:"/",left:ci(zn,e,{value:1}),right:ci(zn,e,{value:0})}):e}),ti(jn,function(e,t){var n=Ri(t.self(),t.parent());return n&&!qi(n,e)||ui(t,"NaN")?ci($t,e,{operator:"/",left:ci(zn,e,{value:0}),right:ci(zn,e,{value:0})}):e});const Lr=E("+ - / * % >> << >>> | ^ &"),Vr=E("* | ^ &");function Ji(e,t){return e instanceof wn&&(e=e.fixed_value()),!!e&&(!(e instanceof st||e instanceof sn)||t.parent()instanceof Ut||!e.contains_this())}function Qi(e,t){return t.in_boolean_context()?xi(t,e,li(e,[e,ci(vi,e)]).optimize(t)):e}function er(e,t,n){for(var i=0;i0&&s.args.length==u.args.length&&s.expression.equivalent_to(u.expression)&&!e.condition.has_side_effects(t)&&!s.expression.has_side_effects(t)&&"number"==typeof(o=function(){for(var e=s.args,t=u.args,n=0,i=e.length;n1)&&(p=null)}else if(!p&&!t.option("keep_fargs")&&s=n.argnames.length;)p=ci(hn,n,{name:n.make_var_name("argument_"+n.argnames.length),scope:n}),n.argnames.push(p),n.enclosed.push(n.def_variable(p));if(p){var d=ci(wn,e,p);return d.reference({}),vr(p,sr),d}}if(Ri(e,t.parent()))return e;if(o!==r){var m=e.flatten_object(a,t);m&&(i=e.expression=m.expression,r=e.property=m.property)}if(t.option("properties")&&t.option("side_effects")&&r instanceof zn&&i instanceof Jt){s=r.getValue();var E=i.elements,h=E[s];e:if(Ji(h,t)){for(var D=!0,g=[],A=E.length;--A>s;){(S=E[A].drop_side_effect_free(t))&&(g.unshift(S),D&&S.has_side_effects(t)&&(D=!1))}if(h instanceof at)break e;for(h=h instanceof Qn?ci(Zn,h):h,D||g.unshift(h);--A>=0;){var S;if((S=E[A])instanceof at)break e;(S=S.drop_side_effect_free(t))?g.unshift(S):s--}return D?(g.push(h),li(e,g).optimize(t)):ci(zt,e,{expression:ci(Jt,i,{elements:g}),property:ci(zn,r,{value:s})})}}var v=e.evaluate(t);return v!==e?xi(t,v=fi(v,e).optimize(t),e):e}),st.DEFMETHOD("contains_this",function(){var e,t=this;return t.walk(new An(function(n){return!!e||(n instanceof Pn?e=!0:n!==t&&n instanceof rt&&!(n instanceof lt)||void 0)})),e}),Ht.DEFMETHOD("flatten_object",function(e,t){if(t.option("properties")){var n=t.option("unsafe_arrows")&&t.option("ecma")>=6,i=this.expression;if(i instanceof en)for(var r=i.properties,o=r.length;--o>=0;){var a=r[o];if(""+(a instanceof an?a.key.name:a.key)==e){if(!r.every(e=>e instanceof nn||n&&e instanceof an&&!e.is_generator))break;if(!Ji(a.value,t))break;return ci(zt,this,{expression:ci(Jt,i,{elements:r.map(function(e){var t=e.value;t instanceof ut&&(t=ci(ct,t,t));var n=e.key;return n instanceof Pe&&!(n instanceof gn)?li(e,[n,t]):t})}),property:ci(zn,this,{value:o})})}}}}),ti(Xt,function(e,t){if("arguments"!=e.property&&"caller"!=e.property||t.warn("Function.prototype.{prop} not supported [{file}:{line},{col}]",{prop:e.property,file:e.start.file,line:e.start.line,col:e.start.col}),Ri(e,t.parent()))return e;if(t.option("unsafe_proto")&&e.expression instanceof Xt&&"prototype"==e.expression.property){var n=e.expression.expression;if(gi(n))switch(n.name){case"Array":e.expression=ci(Jt,e.expression,{elements:[]});break;case"Function":e.expression=ci(ct,e.expression,{argnames:[],body:[]});break;case"Number":e.expression=ci(zn,e.expression,{value:0});break;case"Object":e.expression=ci(en,e.expression,{properties:[]});break;case"RegExp":e.expression=ci(Yn,e.expression,{value:{source:"t",flags:""}});break;case"String":e.expression=ci(Xn,e.expression,{value:""})}}var i=e.flatten_object(e.property,t);if(i)return i.optimize(t);var r=e.evaluate(t);return r!==e?xi(t,r=fi(r,e).optimize(t),e):e}),ti(Jt,function(e,t){var n=Qi(e,t);return n!==e?n:er(e,0,e.elements)}),ti(en,function(e,t){var n=Qi(e,t);if(n!==e)return n;for(var i=e.properties,r=0;r=6&&!e.name&&!e.is_generator&&!e.uses_arguments&&!e.pinned()){var n=!1;if(e.walk(new An(function(e){return!!n||(e instanceof Pn?(n=!0,!0):void 0)})),!n)return ci(lt,e,e).optimize(t)}return e}),ti(sn,function(e,t){return e}),ti(Mi,function(e,t){return e.expression&&!e.is_star&&Oi(e.expression,t)&&(e.expression=null),e}),ti(dt,function(e,t){if(!t.option("evaluate")||t.parent()instanceof _t)return e;for(var n=[],i=0;i=6&&(!(n instanceof RegExp)||n.test(e.key+""))){var i=e.key,r=e.value;if((r instanceof lt&&Array.isArray(r.body)&&!r.contains_this()||r instanceof ct)&&!r.name)return ci(an,e,{async:r.async,is_generator:r.is_generator,key:i instanceof Pe?i:ci(gn,e,{name:i}),value:ci(ut,r,r),quote:e.quote})}return e}),ti(pt,function(e,t){if(1==t.option("pure_getters")&&t.option("unused")&&!e.is_array&&Array.isArray(e.names)&&!function(e){for(var t=[/^VarDef$/,/^(Const|Let|Var)$/,/^Export$/],n=0,i=0,r=t.length;n1)throw new Error("inline source map only works with singular input");t.sourceMap.content=(n=e[l],i=void 0,(i=/(?:^|[^.])\/\/# sourceMappingURL=data:application\/json(;[\w=-]*)?;base64,([+/0-9A-Za-z]*=*)\s*$/.exec(n))?Br(i[2]):(Pe.warn("inline source map not found"),null))}u=t.parse.toplevel}a&&"strict"!==t.mangle.properties.keep_quoted&&ir(u,a),t.wrap&&(u=u.wrap_commonjs(t.wrap)),t.enclose&&(u=u.wrap_enclose(t.enclose)),s&&(s.rename=Date.now()),s&&(s.compress=Date.now()),t.compress&&(u=new ei(t.compress).compress(u)),s&&(s.scope=Date.now()),t.mangle&&u.figure_out_scope(t.mangle),s&&(s.mangle=Date.now()),t.mangle&&(ar.reset(),u.compute_char_frequency(t.mangle),u.mangle_names(t.mangle)),s&&(s.properties=Date.now()),t.mangle&&t.mangle.properties&&(u=or(u,t.mangle.properties)),s&&(s.output=Date.now());var f={};if(t.output.ast&&(f.ast=u),!D(t.output,"code")||t.output.code){if(t.sourceMap&&("string"==typeof t.sourceMap.content&&(t.sourceMap.content=JSON.parse(t.sourceMap.content)),t.output.source_map=function(e){e=o(e,{file:null,root:null,orig:null,orig_line_diff:0,dest_line_diff:0});var t=new O.SourceMapGenerator({file:e.file,sourceRoot:e.root}),n=e.orig&&new O.SourceMapConsumer(e.orig);return n&&n.sources.forEach(function(e){var i=n.sourceContentFor(e,!0);i&&t.setSourceContent(e,i)}),{add:function(i,r,o,a,s,u){if(n){var c=n.originalPositionFor({line:a,column:s});if(null===c.source)return;i=c.source,a=c.line,s=c.column,u=c.name||u}t.addMapping({generated:{line:r+e.dest_line_diff,column:o},original:{line:a+e.orig_line_diff,column:s},source:i,name:u})},get:function(){return t},toString:function(){return JSON.stringify(t.toJSON())}}}({file:t.sourceMap.filename,orig:t.sourceMap.content,root:t.sourceMap.root}),t.sourceMap.includeSources)){if(e instanceof ot)throw new Error("original source content unavailable");for(var l in e)D(e,l)&&t.output.source_map.get().setSourceContent(l,e[l])}delete t.output.ast,delete t.output.code;var p=In(t.output);if(u.print(p),f.code=p.get(),t.sourceMap)if(t.sourceMap.asObject?f.map=t.output.source_map.get().toJSON():f.map=t.output.source_map.toString(),"inline"==t.sourceMap.url){var _="object"==typeof f.map?JSON.stringify(f.map):f.map;f.code+="\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,"+Kr(_)}else t.sourceMap.url&&(f.code+="\n//# sourceMappingURL="+t.sourceMap.url)}return t.nameCache&&t.mangle&&(t.mangle.cache&&(t.nameCache.vars=lr(t.mangle.cache)),t.mangle.properties&&t.mangle.properties.cache&&(t.nameCache.props=lr(t.mangle.properties.cache))),s&&(s.end=Date.now(),f.timings={parse:.001*(s.rename-s.parse),rename:.001*(s.compress-s.rename),compress:.001*(s.scope-s.compress),scope:.001*(s.mangle-s.scope),mangle:.001*(s.properties-s.mangle),properties:.001*(s.output-s.properties),output:.001*(s.end-s.output),total:.001*(s.end-s.start)}),c.length&&(f.warnings=c),f}catch(e){return{error:e}}finally{Pe.warn_function=r}}function pr(e){var t=fr("",e);return t.error&&t.error.defs}!function(){var e=function(e){for(var t=!0,n=0;n2){var n=a[a.length-2];"FunctionDeclaration"!==n.type&&"FunctionExpression"!==n.type&&"ArrowFunctionExpression"!==n.type||(t=Qt)}return new t({start:i(e),end:r(e),left:s(e.left),operator:"=",right:s(e.right)})},SpreadElement:function(e){return new at({start:i(e),end:r(e),expression:s(e.argument)})},RestElement:function(e){return new at({start:i(e),end:r(e),expression:s(e.argument)})},TemplateElement:function(e){return new mt({start:i(e),end:r(e),value:e.value.cooked,raw:e.value.raw})},TemplateLiteral:function(e){for(var t=[],n=0;n1||e.guardedHandlers&&e.guardedHandlers.length)throw new Error("Multiple catch clauses are not supported.");return new Mt({start:i(e),end:r(e),body:s(e.block).body,bcatch:s(t[0]),bfinally:e.finalizer?new Nt(s(e.finalizer)):null})},Property:function(e){var t=e.key,n={start:i(t||e.value),end:r(e.value),key:"Identifier"==t.type?t.name:t.value,value:s(e.value)};return e.computed&&(n.key=s(e.key)),e.method?(n.is_generator=e.value.generator,n.async=e.value.async,e.computed?n.key=s(e.key):n.key=new gn({name:n.key}),new an(n)):"init"==e.kind?("Identifier"!=t.type&&"Literal"!=t.type&&(n.key=s(t)),new nn(n)):("string"!=typeof n.key&&"number"!=typeof n.key||(n.key=new gn({name:n.key})),n.value=new ut(n.value),"get"==e.kind?new on(n):"set"==e.kind?new rn(n):"method"==e.kind?(n.async=e.value.async,n.is_generator=e.value.generator,n.quote=e.computed?'"':null,new an(n)):void 0)},MethodDefinition:function(e){var t={start:i(e),end:r(e),key:e.computed?s(e.key):new gn({name:e.key.name||e.key.value}),value:s(e.value),static:e.static};return"get"==e.kind?new on(t):"set"==e.kind?new rn(t):(t.is_generator=e.value.generator,t.async=e.value.async,new an(t))},ArrayExpression:function(e){return new Jt({start:i(e),end:r(e),elements:e.elements.map(function(e){return null===e?new Qn:s(e)})})},ObjectExpression:function(e){return new en({start:i(e),end:r(e),properties:e.properties.map(function(e){return"SpreadElement"===e.type?s(e):(e.type="Property",s(e))})})},SequenceExpression:function(e){return new Gt({start:i(e),end:r(e),expressions:e.expressions.map(s)})},MemberExpression:function(e){return new(e.computed?zt:Xt)({start:i(e),end:r(e),property:e.computed?s(e.property):e.property.name,expression:s(e.object)})},SwitchCase:function(e){return new(e.test?Ft:Ot)({start:i(e),end:r(e),expression:s(e.test),body:e.consequent.map(s)})},VariableDeclaration:function(e){return new("const"===e.kind?It:"let"===e.kind?kt:xt)({start:i(e),end:r(e),definitions:e.declarations.map(s)})},ImportDeclaration:function(e){var t=null,n=null;return e.specifiers.forEach(function(e){"ImportSpecifier"===e.type?(n||(n=[]),n.push(new Lt({start:i(e),end:r(e),foreign_name:s(e.imported),name:s(e.local)}))):"ImportDefaultSpecifier"===e.type?t=s(e.local):"ImportNamespaceSpecifier"===e.type&&(n||(n=[]),n.push(new Lt({start:i(e),end:r(e),foreign_name:new Rn({name:"*"}),name:s(e.local)})))}),new Vt({start:i(e),end:r(e),imported_name:t,imported_names:n,module_name:s(e.source)})},ExportAllDeclaration:function(e){return new Pt({start:i(e),end:r(e),exported_names:[new Lt({name:new Ln({name:"*"}),foreign_name:new Ln({name:"*"})})],module_name:s(e.source)})},ExportNamedDeclaration:function(e){return new Pt({start:i(e),end:r(e),exported_definition:s(e.declaration),exported_names:e.specifiers&&e.specifiers.length?e.specifiers.map(function(e){return new Lt({foreign_name:s(e.exported),name:s(e.local)})}):null,module_name:s(e.source)})},ExportDefaultDeclaration:function(e){return new Pt({start:i(e),end:r(e),exported_value:s(e.declaration),is_default:!0})},Literal:function(e){var t=e.value,n={start:i(e),end:r(e)},o=e.regex;if(o&&o.pattern)return n.value={source:o.pattern,flags:o.flags},new Yn(n);if(o){const i=e.raw||t,r=i.match(/^\/(.*)\/(\w*)$/);if(!r)throw new Error("Invalid regex source "+i);const[o,a,s]=r;return n.value={source:a,flags:s},new Yn(n)}if(null===t)return new $n(n);switch(typeof t){case"string":return n.value=t,new Xn(n);case"number":return n.value=t,new zn(n);case"boolean":return new(t?vi:Si)(n)}},MetaProperty:function(e){if("new"===e.meta.name&&"target"===e.property.name)return new fn({start:i(e),end:r(e)})},Identifier:function(e){var t=a[a.length-2];return new("LabeledStatement"==t.type?Nn:"VariableDeclarator"==t.type&&t.id===e?"const"==t.kind?mn:"let"==t.kind?En:_n:/Import.*Specifier/.test(t.type)?t.local===e?Cn:Rn:"ExportSpecifier"==t.type?t.local===e?xn:Ln:"FunctionExpression"==t.type?t.id===e?Sn:hn:"FunctionDeclaration"==t.type?t.id===e?Dn:hn:"ArrowFunctionExpression"==t.type?t.params.includes(e)?hn:wn:"ClassExpression"==t.type?t.id===e?bn:wn:"Property"==t.type?t.key===e&&t.computed||t.value===e?wn:gn:"ClassDeclaration"==t.type?t.id===e?Tn:wn:"MethodDefinition"==t.type?t.computed?wn:gn:"CatchClause"==t.type?yn:"BreakStatement"==t.type||"ContinueStatement"==t.type?Vn:wn)({start:i(e),end:r(e),name:e.name})},BigIntLiteral:e=>new Wn({start:i(e),end:r(e),value:e.value})};function n(e){if("Literal"==e.type)return null!=e.raw?e.raw:e.value+""}function i(e){var t=e.loc,i=t&&t.start,r=e.range;return new Ve({file:t&&t.source,line:i&&i.line,col:i&&i.column,pos:r?r[0]:e.start,endline:i&&i.line,endcol:i&&i.column,endpos:r?r[0]:e.start,raw:n(e)})}function r(e){var t=e.loc,i=t&&t.end,r=e.range;return new Ve({file:t&&t.source,line:i&&i.line,col:i&&i.column,pos:r?r[1]:e.end,endline:i&&i.line,endcol:i&&i.column,endpos:r?r[1]:e.end,raw:n(e)})}function o(e,n,o){var a="function From_Moz_"+e+"(M){\n";a+="return new U2."+n.name+"({\nstart: my_start_token(M),\nend: my_end_token(M)";var c="function To_Moz_"+e+"(M){\n";c+="return {\ntype: "+JSON.stringify(e),o&&o.split(/\s*,\s*/).forEach(function(e){var t=/([a-z0-9$_]+)([=@>%])([a-z0-9$_]+)/i.exec(e);if(!t)throw new Error("Can't understand property map: "+e);var n=t[1],i=t[2],r=t[3];switch(a+=",\n"+r+": ",c+=",\n"+n+": ",i){case"@":a+="M."+n+".map(from_moz)",c+="M."+r+".map(to_moz)";break;case">":a+="from_moz(M."+n+")",c+="to_moz(M."+r+")";break;case"=":a+="M."+n,c+="M."+r;break;case"%":a+="from_moz(M."+n+").body",c+="to_moz_block(M)";break;default:throw new Error("Can't understand operator in propmap: "+e)}}),a+="\n})\n}",c+="\n}\n}",a=new Function("U2","my_start_token","my_end_token","from_moz","return("+a+")")(Pi,i,r,s),c=new Function("to_moz","to_moz_block","to_moz_scope","return("+c+")")(l,p,_),t[e]=a,u(n,c)}t.UpdateExpression=t.UnaryExpression=function(e){return new(("prefix"in e?e.prefix:"UnaryExpression"==e.type)?Yt:qt)({start:i(e),end:r(e),operator:e.operator,expression:s(e.argument)})},t.ClassDeclaration=t.ClassExpression=function(e){return new("ClassDeclaration"===e.type?un:cn)({start:i(e),end:r(e),name:s(e.id),extends:s(e.superClass),properties:e.body.body.map(s)})},o("EmptyStatement",Ye),o("BlockStatement",We,"body@body"),o("IfStatement",bt,"test>condition, consequent>body, alternate>alternative"),o("LabeledStatement",$e,"label>label, body>body"),o("BreakStatement",vt,"label>label"),o("ContinueStatement",Tt,"label>label"),o("WithStatement",it,"object>expression, body>body"),o("SwitchStatement",yt,"discriminant>expression, cases@body"),o("ReturnStatement",gt,"argument>value"),o("ThrowStatement",At,"argument>value"),o("WhileStatement",Je,"test>condition, body>body"),o("DoWhileStatement",Qe,"test>condition, body>body"),o("ForStatement",et,"init>init, test>condition, update>step, body>body"),o("ForInStatement",tt,"left>init, right>object, body>body"),o("ForOfStatement",nt,"left>init, right>object, body>body, await=await"),o("AwaitExpression",Fi,"argument>expression"),o("YieldExpression",Mi,"argument>expression, delegate=is_star"),o("DebuggerStatement",Ke),o("VariableDeclarator",Bt,"id>name, init>value"),o("CatchClause",Rt,"param>argname, body%body"),o("ThisExpression",Pn),o("Super",Gn),o("BinaryExpression",$t,"operator=operator, left>left, right>right"),o("LogicalExpression",$t,"operator=operator, left>left, right>right"),o("AssignmentExpression",Zt,"operator=operator, left>left, right>right"),o("ConditionalExpression",jt,"test>condition, consequent>consequent, alternate>alternative"),o("NewExpression",Ut,"callee>expression, arguments@args"),o("CallExpression",Kt,"callee>expression, arguments@args"),u(ot,function(e){return _("Program",e)}),u(at,function(e,t){return{type:f()?"RestElement":"SpreadElement",argument:l(e.expression)}}),u(_t,function(e){return{type:"TaggedTemplateExpression",tag:l(e.prefix),quasi:l(e.template_string)}}),u(dt,function(e){for(var t=[],n=[],i=0;i({type:"BigIntLiteral",value:e.value})),Ai.DEFMETHOD("to_mozilla_ast",Hn.prototype.to_mozilla_ast),$n.DEFMETHOD("to_mozilla_ast",Hn.prototype.to_mozilla_ast),Qn.DEFMETHOD("to_mozilla_ast",function(){return null}),ze.DEFMETHOD("to_mozilla_ast",We.prototype.to_mozilla_ast),st.DEFMETHOD("to_mozilla_ast",ct.prototype.to_mozilla_ast);var a=null;function s(e){a.push(e);var n=null!=e?t[e.type](e):null;return a.pop(),n}function u(e,t){e.DEFMETHOD("to_mozilla_ast",function(e){return n=this,i=t(this,e),r=n.start,o=n.end,r&&o?(null!=r.pos&&null!=o.endpos&&(i.range=[r.pos,o.endpos]),r.line&&(i.loc={start:{line:r.line,column:r.col},end:o.endline?{line:o.endline,column:o.endcol}:null},r.file&&(i.loc.source=r.file)),i):i;var n,i,r,o})}Pe.from_mozilla_ast=function(e){var t=a;a=[];var n=s(e);return a=t,n};var c=null;function l(e){null===c&&(c=[]),c.push(e);var t=null!=e?e.to_mozilla_ast(c[c.length-2]):null;return c.pop(),0===c.length&&(c=null),t}function f(){for(var e=c.length;e--;)if(c[e]instanceof pt)return!0;return!1}function p(e){return{type:"BlockStatement",body:e.body.map(l)}}function _(e,t){var n=t.body.map(l);return t.body[0]instanceof Ge&&t.body[0].body instanceof Xn&&n.unshift(l(new Ye(t.body[0]))),{type:e,body:n}}}(),C.AST_Accessor=ut,C.AST_Array=Jt,C.AST_Arrow=lt,C.AST_Assign=Zt,C.AST_Atom=qn,C.AST_Await=Fi,C.AST_Binary=$t,C.AST_Block=ze,C.AST_BlockStatement=We,C.AST_Boolean=Ai,C.AST_Break=vt,C.AST_Call=Kt,C.AST_Case=Ft,C.AST_Catch=Rt,C.AST_Class=sn,C.AST_ClassExpression=cn,C.AST_ConciseMethod=an,C.AST_Conditional=jt,C.AST_Const=It,C.AST_Constant=Hn,C.AST_Continue=Tt,C.AST_DWLoop=Ze,C.AST_Debugger=Ke,C.AST_DefClass=un,C.AST_Default=Ot,C.AST_DefaultAssign=Qt,C.AST_Definitions=wt,C.AST_Defun=ft,C.AST_Destructuring=pt,C.AST_Directive=Ue,C.AST_Do=Qe,C.AST_Dot=Xt,C.AST_EmptyStatement=Ye,C.AST_Exit=ht,C.AST_Expansion=at,C.AST_Export=Pt,C.AST_False=Si,C.AST_Finally=Nt,C.AST_For=et,C.AST_ForIn=tt,C.AST_ForOf=nt,C.AST_Function=ct,C.AST_Hole=Qn,C.AST_If=bt,C.AST_Import=Vt,C.AST_Infinity=Jn,C.AST_IterationStatement=je,C.AST_Jump=Et,C.AST_Label=Nn,C.AST_LabelRef=Vn,C.AST_LabeledStatement=$e,C.AST_Lambda=st,C.AST_Let=kt,C.AST_LoopControl=St,C.AST_NaN=jn,C.AST_NameMapping=Lt,C.AST_New=Ut,C.AST_NewTarget=fn,C.AST_Node=Pe,C.AST_Null=$n,C.AST_Number=zn,C.AST_Object=en,C.AST_ObjectGetter=on,C.AST_ObjectKeyVal=nn,C.AST_ObjectProperty=tn,C.AST_ObjectSetter=rn,C.AST_PrefixedTemplateString=_t,C.AST_PropAccess=Ht,C.AST_RegExp=Yn,C.AST_Return=gt,C.AST_Scope=rt,C.AST_Sequence=Gt,C.AST_SimpleStatement=Ge,C.AST_Statement=Be,C.AST_StatementWithBody=qe,C.AST_String=Xn,C.AST_Sub=zt,C.AST_Super=Gn,C.AST_Switch=yt,C.AST_SwitchBranch=Ct,C.AST_Symbol=ln,C.AST_SymbolBlockDeclaration=dn,C.AST_SymbolCatch=yn,C.AST_SymbolClass=bn,C.AST_SymbolConst=mn,C.AST_SymbolDeclaration=pn,C.AST_SymbolDefClass=Tn,C.AST_SymbolDefun=Dn,C.AST_SymbolExport=xn,C.AST_SymbolExportForeign=Ln,C.AST_SymbolFunarg=hn,C.AST_SymbolImport=Cn,C.AST_SymbolImportForeign=Rn,C.AST_SymbolLambda=Sn,C.AST_SymbolLet=En,C.AST_SymbolMethod=gn,C.AST_SymbolRef=wn,C.AST_SymbolVar=_n,C.AST_TemplateSegment=mt,C.AST_TemplateString=dt,C.AST_This=Pn,C.AST_Throw=At,C.AST_Token=Ve,C.AST_Toplevel=ot,C.AST_True=vi,C.AST_Try=Mt,C.AST_Unary=Wt,C.AST_UnaryPostfix=qt,C.AST_UnaryPrefix=Yt,C.AST_Undefined=Zn,C.AST_Var=xt,C.AST_VarDef=Bt,C.AST_While=Je,C.AST_With=it,C.AST_Yield=Mi,C.Compressor=ei,C.OutputStream=In,C.TreeTransformer=vn,C.TreeWalker=An,C._INLINE=Li,C._JS_Parse_Error=J,C._NOINLINE=Vi,C._PURE=Ii,C._has_annotation=T,C._tokenizer=ne,C.base54=ar,C.default_options=function(){const e={};return Object.keys(pr({0:0})).forEach(t=>{const n=pr({[t]:{0:0}});n&&(e[t]=n)}),e},C.defaults=o,C.mangle_properties=or,C.minify=fr,C.parse=ue,C.push_uniq=p,C.reserve_quoted_keys=ir,C.string_template=_,C.to_ascii=Br})}}); \ No newline at end of file +module.exports=function(e,t){"use strict";var n={};function __webpack_require__(t){if(n[t]){return n[t].exports}var i=n[t]={i:t,l:false,exports:{}};e[t].call(i.exports,i,i.exports,__webpack_require__);i.l=true;return i.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(542)}return startup()}({241:function(e){e.exports=require("next/dist/compiled/source-map")},542:function(e,t,n){!function(e,i){true?i(t,n(241)):undefined}(this,function(C,O){"use strict";function n(e){return e.split("")}function i(e,t){return t.includes(e)}O=O&&O.hasOwnProperty("default")?O.default:O;class r extends Error{constructor(e,t){super(),this.name="DefaultsError",this.message=e,this.defs=t}}function o(e,t,n){!0===e&&(e={});var i=e||{};if(n)for(var o in i)if(D(i,o)&&!D(t,o))throw new r("`"+o+"` is not a supported option",t);for(var o in t)D(t,o)&&(i[o]=e&&D(e,o)?e[o]:t[o]);return i}function a(){}function s(){return!1}function u(){return!0}function c(){return this}function l(){return null}var F=function(){function e(e,o,a){var s,u=[],c=[];function l(){var l=o(e[s],s),f=l instanceof r;return f&&(l=l.v),l instanceof n?(l=l.v)instanceof i?c.push.apply(c,a?l.v.slice().reverse():l.v):c.push(l):l!==t&&(l instanceof i?u.push.apply(u,a?l.v.slice().reverse():l.v):u.push(l)),f}if(Array.isArray(e))if(a){for(s=e.length;--s>=0&&!l(););u.reverse(),c.reverse()}else for(s=0;s=0;)e[n]===t&&e.splice(n,1)}function m(t,n){if(t.length<2)return t.slice();return function e(t){if(t.length<=1)return t;var i=Math.floor(t.length/2),r=t.slice(0,i),o=t.slice(i);return function(e,t){for(var i=[],r=0,o=0,a=0;r!?|~^")),de=/[0-9a-f]/i,me=/^0x[0-9a-f]+$/i,De=/^0[0-7]+$/,ge=/^0o[0-7]+$/i,Se=/^0b[01]+$/i,ve=/^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i,Te=/^(0[xob])?[0-9a-f]+n$/i,be=E(["in","instanceof","typeof","new","void","delete","++","--","+","-","!","~","&","|","^","*","**","/","%",">>","<<",">>>","<",">","<=",">=","==","===","!=","!==","?","=","+=","-=","/=","*=","**=","%=",">>=","<<=",">>>=","|=","^=","&=","&&","||"]),ye=E(n("  \n\r\t\f\v​           \u2028\u2029   \ufeff")),Ce=E(n("\n\r\u2028\u2029")),Oe=E(n(";]),:")),Fe=E(n("[{(,;:")),Me=E(n("[]{}(),;:")),Re={ID_Start:/[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,ID_Continue:/[0-9A-Z_a-z\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/};function X(e,t){var n=e.charAt(t);if(z(n)){var i=e.charAt(t+1);if(W(i))return n+i}if(W(n)){var r=e.charAt(t-1);if(z(r))return r+n}return n}function z(e){return"string"==typeof e&&(e=e.charCodeAt(0)),e>=55296&&e<=56319}function W(e){return"string"==typeof e&&(e=e.charCodeAt(0)),e>=56320&&e<=57343}function Y(e){return e>=48&&e<=57}function q(e){var t=e.charCodeAt(0);return Re.ID_Start.test(e)||36==t||95==t}function $(e){var t=e.charCodeAt(0);return Re.ID_Continue.test(e)||36==t||95==t||8204==t||8205==t}function j(e){return/^[a-z_$][a-z0-9_$]*$/i.test(e)}function Z(e){if(me.test(e))return parseInt(e.substr(2),16);if(De.test(e))return parseInt(e.substr(1),8);if(ge.test(e))return parseInt(e.substr(2),8);if(Se.test(e))return parseInt(e.substr(2),2);if(ve.test(e))return parseFloat(e);var t=parseFloat(e);return t==e?t:void 0}class J extends Error{constructor(e,t,n,i,r){super(),this.name="SyntaxError",this.message=e,this.filename=t,this.line=n,this.col=i,this.pos=r}}function Q(e,t,n,i,r){throw new J(e,t,n,i,r)}function ee(e,t,n){return e.type==t&&(null==n||e.value==n)}var Ne={};function ne(t,n,i,r){var f={text:t,filename:n,pos:0,tokpos:0,line:1,tokline:0,col:0,tokcol:0,newline_before:!1,regex_allowed:!1,brace_counter:0,template_braces:[],comments_before:[],directives:{},directive_stack:[]};function o(){return X(f.text,f.pos)}function a(e,t){var n=X(f.text,f.pos++);if(e&&!n)throw Ne;return Ce.has(n)?(f.newline_before=f.newline_before||!t,++f.line,f.col=0,"\r"==n&&"\n"==o()&&(++f.pos,n="\n")):(n.length>1&&(++f.pos,++f.col),++f.col),n}function s(e){for(;e-- >0;)a()}function u(e){return f.text.substr(f.pos,e.length)==e}function c(e,t){var n=f.text.indexOf(e,f.pos);if(t&&-1==n)throw Ne;return n}function l(){f.tokline=f.line,f.tokcol=f.col,f.tokpos=f.pos}var p=!1,A=null;function _(e,i,r){f.regex_allowed="operator"==e&&!xe.has(i)||"keyword"==e&&fe.has(i)||"punc"==e&&Fe.has(i)||"arrow"==e,"punc"==e&&"."==i?p=!0:r||(p=!1);var o={type:e,value:i,line:f.tokline,col:f.tokcol,pos:f.tokpos,endline:f.line,endcol:f.col,endpos:f.pos,nlb:f.newline_before,file:n};return/^(?:num|string|regexp)$/i.test(e)&&(o.raw=t.substring(o.pos,o.endpos)),r||(o.comments_before=f.comments_before,o.comments_after=f.comments_before=[]),f.newline_before=!1,o=new Ve(o),r||(A=o),o}function d(){for(;ye.has(o());)a()}function m(e){Q(e,n,f.tokline,f.tokcol,f.tokpos)}function E(e){var t=!1,n=!1,i=!1,r="."==e,s=!1,u=function(e){for(var t,n="",i=0;(t=o())&&e(t,i++);)n+=a();return n}(function(o,a){if(s)return!1;switch(o.charCodeAt(0)){case 98:case 66:return i=!0;case 111:case 79:case 120:case 88:return!i&&(i=!0);case 101:case 69:return!!i||!t&&(t=n=!0);case 45:return n||0==a&&!e;case 43:return n;case n=!1,46:return!(r||i||t)&&(r=!0)}return"n"===o?(s=!0,!0):de.test(o)});if(e&&(u=e+u),De.test(u)&&K.has_directive("use strict")&&m("Legacy octal literals are not allowed in strict mode"),u.endsWith("n")){const e=Z(u.slice(0,-1));if(!r&&Te.test(u)&&!isNaN(e))return _("big_int",u.replace("n",""));m("Invalid or unexpected token")}var c=Z(u);if(!isNaN(c))return _("num",c);m("Invalid syntax: "+u)}function h(e){return e>="0"&&e<="7"}function D(e,t,n){var i,r=a(!0,e);switch(r.charCodeAt(0)){case 110:return"\n";case 114:return"\r";case 116:return"\t";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 120:return String.fromCharCode(g(2,t));case 117:if("{"==o()){for(a(!0),"}"===o()&&m("Expecting hex-character between {}");"0"==o();)a(!0);var s,u=c("}",!0)-f.pos;return(u>6||(s=g(u,t))>1114111)&&m("Unicode reference out of bounds"),a(!0),(i=s)>65535?(i-=65536,String.fromCharCode(55296+(i>>10))+String.fromCharCode(i%1024+56320)):String.fromCharCode(i)}return String.fromCharCode(g(4,t));case 10:return"";case 13:if("\n"==o())return a(!0,e),""}if(h(r)){if(n&&t){"0"===r&&!h(o())||m("Octal escape sequences are not allowed in template strings")}return function(e,t){var n=o();n>="0"&&n<="7"&&(e+=a(!0))[0]<="3"&&(n=o())>="0"&&n<="7"&&(e+=a(!0));if("0"===e)return"\0";e.length>0&&K.has_directive("use strict")&&t&&m("Legacy octal escape sequences are not allowed in strict mode");return String.fromCharCode(parseInt(e,8))}(r,t)}return r}function g(e,t){for(var n=0;e>0;--e){if(!t&&isNaN(parseInt(o(),16)))return parseInt(n,16)||"";var i=a(!0);isNaN(parseInt(i,16))&&m("Invalid hex-character pattern in string"),n+=i}return parseInt(n,16)}var S=I("Unterminated string constant",function(){for(var e=a(),t="";;){var n=a(!0,!0);if("\\"==n)n=D(!0,!0);else if("\r"==n||"\n"==n)m("Unterminated string constant");else if(n==e)break;t+=n}var i=_("string",t);return i.quote=e,i}),T=I("Unterminated template",function(e){e&&f.template_braces.push(f.brace_counter);var t,n,i="",r="";for(a(!0,!0);"`"!=(t=a(!0,!0));){if("\r"==t)"\n"==o()&&++f.pos,t="\n";else if("$"==t&&"{"==o())return a(!0,!0),f.brace_counter++,(n=_(e?"template_head":"template_substitution",i)).raw=r,n;if(r+=t,"\\"==t){var s=f.pos;t=D(!0,!(A&&("name"===A.type||"punc"===A.type&&(")"===A.value||"]"===A.value))),!0),r+=f.text.substr(s,f.pos-s)}i+=t}return f.template_braces.pop(),(n=_(e?"template_head":"template_substitution",i)).raw=r,n.end=!0,n});function v(e){var t,n=f.regex_allowed,i=function(){for(var e=f.text,t=f.pos,n=f.text.length;t"===o()?(a(),_("arrow","=>")):x("=");case 96:return T(!0);case 123:f.brace_counter++;break;case 125:if(f.brace_counter--,f.template_braces.length>0&&f.template_braces[f.template_braces.length-1]===f.brace_counter)return T(!1)}if(Y(n))return E();if(Me.has(t))return _("punc",a());if(_e.has(t))return x();if(92==n||q(t))return h=void 0,h=y(),p?_("name",h):ae.has(h)?_("atom",h):oe.has(h)?be.has(h)?_("operator",h):_("keyword",h):_("name",h);break}var h;m("Unexpected character '"+t+"'")}return K.next=a,K.peek=o,K.context=function(e){return e&&(f=e),f},K.add_directive=function(e){f.directive_stack[f.directive_stack.length-1].push(e),void 0===f.directives[e]?f.directives[e]=1:f.directives[e]++},K.push_directives_stack=function(){f.directive_stack.push([])},K.pop_directives_stack=function(){for(var e=f.directive_stack[f.directive_stack.length-1],t=0;t0},K}var we=E(["typeof","void","delete","--","++","!","~","-","+"]),xe=E(["--","++"]),ke=E(["=","+=","-=","/=","*=","**=","%=",">>=","<<=",">>>=","|=","^=","&="]),Ie=function(e,t){for(var n=0;n","<=",">=","in","instanceof"],[">>","<<",">>>"],["+","-"],["*","/","%"],["**"]],{}),Le=E(["atom","num","big_int","string","regexp","name"]);function ue(e,n){const i=new Map;n=o(n,{bare_returns:!1,ecma:8,expression:!1,filename:null,html5_comments:!0,module:!1,shebang:!0,strict:!1,toplevel:null},!0);var v={input:"string"==typeof e?ne(e,n.filename,n.html5_comments,n.shebang):e,token:null,prev:null,peeked:null,in_function:0,in_async:-1,in_generator:-1,in_directives:!0,in_loop:0,labels:[]};function r(e,t){return ee(v.token,e,t)}function a(){return v.peeked||(v.peeked=v.input())}function s(){return v.prev=v.token,v.peeked||a(),v.token=v.peeked,v.peeked=null,v.in_directives=v.in_directives&&("string"==v.token.type||r("punc",";")),v.token}function u(){return v.prev}function c(e,t,n,i){var r=v.input.context();Q(e,r.filename,null!=t?t:r.tokline,null!=n?n:r.tokcol,null!=i?i:r.tokpos)}function l(e,t){c(t,e.line,e.col)}function f(e){null==e&&(e=v.token),l(e,"Unexpected token: "+e.type+" ("+e.value+")")}function p(e,t){if(r(e,t))return s();l(v.token,"Unexpected token "+v.token.type+" «"+v.token.value+"», expected "+e+" «"+t+"»")}function _(e){return p("punc",e)}function d(e){return e.nlb||!e.comments_before.every(e=>!e.nlb)}function m(){return!n.strict&&(r("eof")||r("punc","}")||d(v.token))}function E(){return v.in_generator===v.in_function}function h(){return v.in_async===v.in_function}function D(e){r("punc",";")?s():e||m()||f()}function g(){_("(");var e=fe(!0);return _(")"),e}function S(e){return function(...t){const n=v.token,i=e(...t);return i.start=n,i.end=u(),i}}function A(){(r("operator","/")||r("operator","/="))&&(v.peeked=null,v.token=v.input(v.token.value.substr(1)))}v.token=s();var C=S(function(e,t,i){switch(A(),v.token.type){case"string":if(v.in_directives){var o=a();!v.token.raw.includes("\\")&&(ee(o,"punc",";")||ee(o,"punc","}")||d(o)||ee(o,"eof"))?v.input.add_directive(v.token.value):v.in_directives=!1}var E=v.in_directives,S=T();return E&&S.body instanceof Xn?new Ue(S.body):S;case"template_head":case"num":case"big_int":case"regexp":case"operator":case"atom":return T();case"name":if("async"==v.token.value&&ee(a(),"keyword","function"))return s(),s(),t&&c("functions are not allowed as the body of a loop"),F(ft,!1,!0,e);if("import"==v.token.value&&!ee(a(),"punc","(")){s();var b=function(){var e,t,n=u();r("name")&&(e=le(Cn));r("punc",",")&&s();((t=J(!0))||e)&&p("name","from");var i=v.token;"string"!==i.type&&f();return s(),new Vt({start:n,imported_name:e,imported_names:t,module_name:new Xn({start:i,value:i.value,quote:i.quote,end:i}),end:v.token})}();return D(),b}return ee(a(),"punc",":")?function(){var e=le(Nn);"await"===e.name&&h()&&l(v.prev,"await cannot be used as label inside async function");v.labels.some(t=>t.name===e.name)&&c("Label "+e.name+" defined twice");_(":"),v.labels.push(e);var t=C();v.labels.pop(),t instanceof je||e.references.forEach(function(t){t instanceof Tt&&(t=t.label.start,c("Continue label `"+e.name+"` refers to non-IterationStatement.",t.line,t.col,t.pos))});return new $e({body:t,label:e})}():T();case"punc":switch(v.token.value){case"{":return new We({start:v.token,body:x(),end:u()});case"[":case"(":return T();case";":return v.in_directives=!1,s(),new Ye;default:f()}case"keyword":switch(v.token.value){case"break":return s(),y(vt);case"continue":return s(),y(Tt);case"debugger":return s(),D(),new Ke;case"do":s();var O=Dt(C);p("keyword","while");var M=g();return D(!0),new Qe({body:O,condition:M});case"while":return s(),new Je({condition:g(),body:Dt(function(){return C(!1,!0)})});case"for":return s(),function(){var e="`for await` invalid in this context",t=v.token;"name"==t.type&&"await"==t.value?(h()||l(t,e),s()):t=!1;_("(");var n=null;if(r("punc",";"))t&&l(t,e);else{n=r("keyword","var")?(s(),L(!0)):r("keyword","let")?(s(),V(!0)):r("keyword","const")?(s(),P(!0)):fe(!0,!0);var i=r("operator","in"),o=r("name","of");if(t&&!o&&l(t,e),i||o)return n instanceof wt?n.definitions.length>1&&l(n.start,"Only one variable declaration allowed in for..in loop"):He(n)||(n=Xe(n))instanceof pt||l(n.start,"Invalid left-hand side in for..in loop"),s(),i?function(e){var t=fe(!0);return _(")"),new tt({init:e,object:t,body:Dt(function(){return C(!1,!0)})})}(n):function(e,t){var n=e instanceof wt?e.definitions[0].name:null,i=fe(!0);return _(")"),new nt({await:t,init:e,name:n,object:i,body:Dt(function(){return C(!1,!0)})})}(n,!!t)}return function(e){_(";");var t=r("punc",";")?null:fe(!0);_(";");var n=r("punc",")")?null:fe(!0);return _(")"),new et({init:e,condition:t,step:n,body:Dt(function(){return C(!1,!0)})})}(n)}();case"class":return s(),t&&c("classes are not allowed as the body of a loop"),i&&c("classes are not allowed as the body of an if"),q(un);case"function":return s(),t&&c("functions are not allowed as the body of a loop"),F(ft,!1,!1,e);case"if":return s(),function(){var e=g(),t=C(!1,!1,!0),n=null;r("keyword","else")&&(s(),n=C(!1,!1,!0));return new bt({condition:e,body:t,alternative:n})}();case"return":0!=v.in_function||n.bare_returns||c("'return' outside of function"),s();var N=null;return r("punc",";")?s():m()||(N=fe(!0),D()),new gt({value:N});case"switch":return s(),new yt({expression:g(),body:Dt(k)});case"throw":s(),d(v.token)&&c("Illegal newline after 'throw'");N=fe(!0);return D(),new At({value:N});case"try":return s(),function(){var e=x(),t=null,n=null;if(r("keyword","catch")){var i=v.token;if(s(),r("punc","{"))var o=null;else{_("(");o=R(void 0,yn);_(")")}t=new Rt({start:i,argname:o,body:x(),end:u()})}if(r("keyword","finally")){i=v.token;s(),n=new Nt({start:i,body:x(),end:u()})}t||n||c("Missing catch/finally blocks");return new Mt({body:e,bcatch:t,bfinally:n})}();case"var":s();b=L();return D(),b;case"let":s();b=V();return D(),b;case"const":s();b=P();return D(),b;case"with":return v.input.has_directive("use strict")&&c("Strict mode may not include a with statement"),s(),new it({expression:g(),body:C()});case"export":if(!ee(a(),"punc","(")){s();b=function(){var e,t,n,i,o,c=v.token;if(r("keyword","default"))e=!0,s();else if(t=J(!1)){if(r("name","from")){s();var l=v.token;return"string"!==l.type&&f(),s(),new Pt({start:c,is_default:e,exported_names:t,module_name:new Xn({start:l,value:l.value,quote:l.quote,end:l}),end:u()})}return new Pt({start:c,is_default:e,exported_names:t,end:u()})}r("punc","{")||e&&(r("keyword","class")||r("keyword","function"))&&ee(a(),"punc")?(i=fe(!1),D()):(n=C(e))instanceof wt&&e?f(n.start):n instanceof wt||n instanceof st||n instanceof un?o=n:n instanceof Ge?i=n.body:f(n.start);return new Pt({start:c,is_default:e,exported_value:i,exported_definition:o,end:u()})}();return r("punc",";")&&D(),b}}}f()});function T(e){return new Ge({body:(e=fe(!0),D(),e)})}function y(e){var t,n=null;m()||(n=le(Vn,!0)),null!=n?((t=v.labels.find(e=>e.name===n.name))||c("Undefined label "+n.name),n.thedef=t):0==v.in_loop&&c(e.TYPE+" not inside a loop or switch"),D();var i=new e({label:n});return t&&t.references.push(i),i}var O=function(e,t,n){d(v.token)&&c("Unexpected newline before arrow (=>)"),p("arrow","=>");var i=w(r("punc","{"),!1,n),o=i instanceof Array&&i.length?i[i.length-1].end:i instanceof Array?e:i.end;return new lt({start:e,end:o,async:n,argnames:t,body:i})},F=function(e,t,n,i){var o=e===ft,a=r("operator","*");a&&s();var c=r("name")?le(o?Dn:Sn):null;o&&!c&&(i?e=ct:f()),!c||e===ut||c instanceof pn||f(u());var l=[],p=w(!0,a||t,n,c,l);return new e({start:l.start,end:p.end,is_generator:a,async:n,name:c,argnames:l,body:p})};function M(e,t){var n=new Set,i=!1,r=!1,o=!1,a=!!t,s={add_parameter:function(t){if(n.has(t.value))!1===i&&(i=t),s.check_strict();else if(n.add(t.value),e)switch(t.value){case"arguments":case"eval":case"yield":a&&l(t,"Unexpected "+t.value+" identifier as parameter inside strict mode");break;default:se.has(t.value)&&f()}},mark_default_assignment:function(e){!1===r&&(r=e)},mark_spread:function(e){!1===o&&(o=e)},mark_strict_mode:function(){a=!0},is_strict:function(){return!1!==r||!1!==o||a},check_strict:function(){s.is_strict()&&!1!==i&&l(i,"Parameter "+i.value+" was used already")}};return s}function R(e,t){var n,i=!1;return void 0===e&&(e=M(!0,v.input.has_directive("use strict"))),r("expand","...")&&(i=v.token,e.mark_spread(v.token),s()),n=N(e,t),r("operator","=")&&!1===i&&(e.mark_default_assignment(v.token),s(),n=new Qt({start:n.start,left:n,operator:"=",right:fe(!1),end:v.token})),!1!==i&&(r("punc",")")||f(),n=new at({start:i,expression:n,end:i})),e.check_strict(),n}function N(e,t){var n,i=[],o=!0,l=!1,p=v.token;if(void 0===e&&(e=M(!1,v.input.has_directive("use strict"))),t=void 0===t?hn:t,r("punc","[")){for(s();!r("punc","]");){if(o?o=!1:_(","),r("expand","...")&&(l=!0,n=v.token,e.mark_spread(v.token),s()),r("punc"))switch(v.token.value){case",":i.push(new Qn({start:v.token,end:v.token}));continue;case"]":break;case"[":case"{":i.push(N(e,t));break;default:f()}else r("name")?(e.add_parameter(v.token),i.push(le(t))):c("Invalid function parameter");r("operator","=")&&!1===l&&(e.mark_default_assignment(v.token),s(),i[i.length-1]=new Qt({start:i[i.length-1].start,left:i[i.length-1],operator:"=",right:fe(!1),end:v.token})),l&&(r("punc","]")||c("Rest element must be last element"),i[i.length-1]=new at({start:n,expression:i[i.length-1],end:n}))}return _("]"),e.check_strict(),new pt({start:p,names:i,is_array:!0,end:u()})}if(r("punc","{")){for(s();!r("punc","}");){if(o?o=!1:_(","),r("expand","...")&&(l=!0,n=v.token,e.mark_spread(v.token),s()),r("name")&&(ee(a(),"punc")||ee(a(),"operator"))&&[",","}","="].includes(a().value)){e.add_parameter(v.token);var d=u(),m=le(t);l?i.push(new at({start:n,expression:m,end:m.end})):i.push(new nn({start:d,key:m.name,value:m,end:m.end}))}else{if(r("punc","}"))continue;var E=v.token,h=te();null===h?f(u()):"name"!==u().type||r("punc",":")?(_(":"),i.push(new nn({start:E,quote:E.quote,key:h,value:N(e,t),end:u()}))):i.push(new nn({start:u(),key:h,value:new t({start:u(),name:h,end:u()}),end:u()}))}l?r("punc","}")||c("Rest element must be last element"):r("operator","=")&&(e.mark_default_assignment(v.token),s(),i[i.length-1].value=new Qt({start:i[i.length-1].value.start,left:i[i.length-1].value,operator:"=",right:fe(!1),end:v.token}))}return _("}"),e.check_strict(),new pt({start:p,names:i,is_array:!1,end:u()})}if(r("name"))return e.add_parameter(v.token),le(t);c("Invalid function parameter")}function w(e,t,i,o,a){var u=v.in_loop,c=v.labels,l=v.in_generator,p=v.in_async;if(++v.in_function,t&&(v.in_generator=v.in_function),i&&(v.in_async=v.in_function),a&&function(e){var t=M(!0,v.input.has_directive("use strict"));for(_("(");!r("punc",")");){var i=R(t);if(e.push(i),r("punc",")")||(_(","),r("punc",")")&&n.ecma<8&&f()),i instanceof at)break}s()}(a),e&&(v.in_directives=!0),v.in_loop=0,v.labels=[],e){v.input.push_directives_stack();var d=x();o&&ce(o),a&&a.forEach(ce),v.input.pop_directives_stack()}else d=fe(!1);return--v.in_function,v.in_loop=u,v.labels=c,v.in_generator=l,v.in_async=p,d}function x(){_("{");for(var e=[];!r("punc","}");)r("eof")&&f(),e.push(C());return s(),e}function k(){_("{");for(var e,t=[],n=null,i=null;!r("punc","}");)r("eof")&&f(),r("keyword","case")?(i&&(i.end=u()),n=[],i=new Ft({start:(e=v.token,s(),e),expression:fe(!0),body:n}),t.push(i),_(":")):r("keyword","default")?(i&&(i.end=u()),n=[],i=new Ot({start:(e=v.token,s(),_(":"),e),body:n}),t.push(i)):(n||f(),n.push(C()));return i&&(i.end=u()),s(),t}function I(e,t){for(var n,i=[];;){var o="var"===t?_n:"const"===t?mn:"let"===t?En:null;if(r("punc","{")||r("punc","[")?n=new Bt({start:v.token,name:N(void 0,o),value:r("operator","=")?(p("operator","="),fe(!1,e)):null,end:u()}):"import"==(n=new Bt({start:v.token,name:le(o),value:r("operator","=")?(s(),fe(!1,e)):e||"const"!==t?null:c("Missing initializer in const declaration"),end:u()})).name.name&&c("Unexpected token: import"),i.push(n),!r("punc",","))break;s()}return i}var L=function(e){return new xt({start:u(),definitions:I(e,"var"),end:u()})},V=function(e){return new kt({start:u(),definitions:I(e,"let"),end:u()})},P=function(e){return new It({start:u(),definitions:I(e,"const"),end:u()})};function B(){var e,t=v.token;switch(t.type){case"name":e=ue(wn);break;case"num":e=new zn({start:t,end:t,value:t.value});break;case"big_int":e=new Wn({start:t,end:t,value:t.value});break;case"string":e=new Xn({start:t,end:t,value:t.value,quote:t.quote});break;case"regexp":e=new Yn({start:t,end:t,value:t.value});break;case"atom":switch(t.value){case"false":e=new Si({start:t,end:t});break;case"true":e=new vi({start:t,end:t});break;case"null":e=new $n({start:t,end:t})}}return s(),e}function U(e,t,n,i){var r=function(e,t){return t?new Qt({start:e.start,left:e,operator:"=",right:t,end:t.end}):e};return e instanceof en?r(new pt({start:e.start,end:e.end,is_array:!1,names:e.properties.map(U)}),i):e instanceof nn?(e.value=U(e.value,0,[e.key]),r(e,i)):e instanceof Qn?e:e instanceof pt?(e.names=e.names.map(U),r(e,i)):e instanceof wn?r(new hn({name:e.name,start:e.start,end:e.end}),i):e instanceof at?(e.expression=U(e.expression),r(e,i)):e instanceof Jt?r(new pt({start:e.start,end:e.end,is_array:!0,names:e.elements.map(U)}),i):e instanceof Zt?r(U(e.left,void 0,void 0,e.right),i):e instanceof Qt?(e.left=U(e.left,0,[e.left]),e):void c("Invalid function parameter",e.start.line,e.start.col)}var K=function(e,t){if(r("operator","new"))return function(e){var t=v.token;if(p("operator","new"),r("punc","."))return s(),p("name","target"),Y(new fn({start:t,end:u()}),e);var i,o=K(!1);r("punc","(")?(s(),i=X(")",n.ecma>=8)):i=[];var a=new Ut({start:t,expression:o,args:i,end:u()});return pe(a),Y(a,e)}(e);var o,c=v.token,l=r("name","async")&&"["!=(o=a()).value&&"arrow"!=o.type&&B();if(r("punc")){switch(v.token.value){case"(":if(l&&!e)break;var d=function(e,t){var i,o,a,c=[];for(_("(");!r("punc",")");)i&&f(i),r("expand","...")?(i=v.token,t&&(o=v.token),s(),c.push(new at({start:u(),expression:fe(),end:v.token}))):c.push(fe()),r("punc",")")||(_(","),r("punc",")")&&(n.ecma<8&&f(),a=u(),t&&(o=a)));return _(")"),e&&r("arrow","=>")?i&&a&&f(a):o&&f(o),c}(t,!l);if(t&&r("arrow","=>"))return O(c,d.map(U),!!l);var m=l?new Kt({expression:l,args:d}):1==d.length?d[0]:new Gt({expressions:d});if(m.start){const e=c.comments_before.length;if(i.set(c,e),m.start.comments_before.unshift(...c.comments_before),c.comments_before=m.start.comments_before,0==e&&c.comments_before.length>0){var E=c.comments_before[0];E.nlb||(E.nlb=c.nlb,c.nlb=!1)}c.comments_after=m.start.comments_after}m.start=c;var h=u();return m.end&&(h.comments_before=m.end.comments_before,m.end.comments_after.push(...h.comments_after),h.comments_after=m.end.comments_after),m.end=h,m instanceof Kt&&pe(m),Y(m,e);case"[":return Y(G(),e);case"{":return Y(W(),e)}l||f()}if(t&&r("name")&&ee(a(),"arrow")){var D=new hn({name:v.token.value,start:c,end:c});return s(),O(c,[D],!!l)}if(r("keyword","function")){s();var g=F(ct,!1,!!l);return g.start=c,g.end=u(),Y(g,e)}if(l)return Y(l,e);if(r("keyword","class")){s();var A=q(cn);return A.start=c,A.end=u(),Y(A,e)}return r("template_head")?Y(H(),e):Le.has(v.token.type)?Y(B(),e):void f()};function H(e){var t=[],n=v.token;for(t.push(new mt({start:v.token,raw:v.token.raw,value:v.token.value,end:v.token}));!v.token.end;)s(),A(),t.push(fe(!0)),ee("template_substitution")||f(),t.push(new mt({start:v.token,raw:v.token.raw,value:v.token.value,end:v.token}));return s(),new dt({start:n,segments:t,end:v.token})}function X(e,t,n){for(var i=!0,o=[];!r("punc",e)&&(i?i=!1:_(","),!t||!r("punc",e));)r("punc",",")&&n?o.push(new Qn({start:v.token,end:v.token})):r("expand","...")?(s(),o.push(new at({start:u(),expression:fe(),end:v.token}))):o.push(fe(!1));return s(),o}var G=S(function(){return _("["),new Jt({elements:X("]",!n.strict,!0)})}),z=S((e,t)=>F(ut,e,t)),W=S(function(){var e=v.token,t=!0,i=[];for(_("{");!r("punc","}")&&(t?t=!1:_(","),n.strict||!r("punc","}"));)if("expand"!=(e=v.token).type){var o,a=te();if(r("punc",":"))null===a?f(u()):(s(),o=fe(!1));else{var c=$(a,e);if(c){i.push(c);continue}o=new wn({start:u(),name:a,end:u()})}r("operator","=")&&(s(),o=new Zt({start:e,left:o,operator:"=",right:fe(!1),end:u()})),i.push(new nn({start:e,quote:e.quote,key:a instanceof Pe?a:""+a,value:o,end:u()}))}else s(),i.push(new at({start:e,expression:fe(!1),end:u()}));return s(),new en({properties:i})});function q(e){var t,n,i,o,a=[];for(v.input.push_directives_stack(),v.input.add_directive("use strict"),"name"==v.token.type&&"extends"!=v.token.value&&(i=le(e===un?Tn:bn)),e!==un||i||f(),"extends"==v.token.value&&(s(),o=fe(!0)),_("{");r("punc",";");)s();for(;!r("punc","}");)for(t=v.token,(n=$(te(),t,!0))||f(),a.push(n);r("punc",";");)s();return v.input.pop_directives_stack(),s(),new e({start:t,name:i,extends:o,properties:a,end:u()})}function $(e,t,n){var i=function(e,t){return"string"==typeof e||"number"==typeof e?new gn({start:t,name:""+e,end:u()}):(null===e&&f(),e)},o=!1,a=!1,s=!1,c=t;if(n&&"static"===e&&!r("punc","(")&&(a=!0,c=v.token,e=te()),"async"!==e||r("punc","(")||r("punc",",")||r("punc","}")||r("operator","=")||(o=!0,c=v.token,e=te()),null===e&&(s=!0,c=v.token,null===(e=te())&&f()),r("punc","("))return e=i(e,t),new an({start:t,static:a,is_generator:s,async:o,key:e,quote:e instanceof gn?c.quote:void 0,value:z(s,o),end:u()});if(c=v.token,"get"==e){if(!r("punc")||r("punc","["))return e=i(te(),t),new on({start:t,static:a,key:e,quote:e instanceof gn?c.quote:void 0,value:z(),end:u()})}else if("set"==e&&(!r("punc")||r("punc","[")))return e=i(te(),t),new rn({start:t,static:a,key:e,quote:e instanceof gn?c.quote:void 0,value:z(),end:u()})}function j(e){function t(e){return new e({name:te(),start:u(),end:u()})}var n,i,o=e?Rn:Ln,a=e?Cn:xn,c=v.token;return e?n=t(o):i=t(a),r("name","as")?(s(),e?i=t(a):n=t(o)):e?i=new a(n):n=new o(i),new Lt({start:c,foreign_name:n,name:i,end:u()})}function Z(e,t){var n,i=e?Rn:Ln,r=e?Cn:xn,o=v.token,a=u();return t=t||new r({name:"*",start:o,end:a}),n=new i({name:"*",start:o,end:a}),new Lt({start:o,foreign_name:n,name:t,end:a})}function J(e){var t;if(r("punc","{")){for(s(),t=[];!r("punc","}");)t.push(j(e)),r("punc",",")&&s();s()}else if(r("operator","*")){var n;s(),e&&r("name","as")&&(s(),n=le(e?Cn:Ln)),t=[Z(e,n)]}return t}function te(){var e=v.token;switch(e.type){case"punc":if("["===e.value){s();var t=fe(!1);return _("]"),t}f(e);case"operator":if("*"===e.value)return s(),null;["delete","in","instanceof","new","typeof","void"].includes(e.value)||f(e);case"name":"yield"==e.value&&(E()?l(e,"Yield cannot be used as identifier inside generators"):ee(a(),"punc",":")||ee(a(),"punc","(")||!v.input.has_directive("use strict")||l(e,"Unexpected yield identifier inside strict mode"));case"string":case"num":case"big_int":case"keyword":case"atom":return s(),e.value;default:f(e)}}function ue(e){var t=v.token.value;return new("this"==t?Pn:"super"==t?Gn:e)({name:String(t),start:v.token,end:v.token})}function ce(e){var t=e.name;E()&&"yield"==t&&l(e.start,"Yield cannot be used as identifier inside generators"),v.input.has_directive("use strict")&&("yield"==t&&l(e.start,"Unexpected yield identifier inside strict mode"),e instanceof pn&&("arguments"==t||"eval"==t)&&l(e.start,"Unexpected "+t+" in strict mode"))}function le(e,t){if(!r("name"))return t||c("Name expected"),null;var n=ue(e);return ce(n),s(),n}function pe(e){var t=e.start,n=t.comments_before;const r=i.get(t);for(var o=null!=r?r:n.length;--o>=0;){var a=n[o];if(/[@#]__/.test(a.value)){if(/[@#]__PURE__/.test(a.value)){b(e,Ii);break}if(/[@#]__INLINE__/.test(a.value)){b(e,Li);break}if(/[@#]__NOINLINE__/.test(a.value)){b(e,Vi);break}}}}var Y=function(e,t){var n,i=e.start;if(r("punc","."))return s(),Y(new Xt({start:i,expression:e,property:(n=v.token,"name"!=n.type&&f(),s(),n.value),end:u()}),t);if(r("punc","[")){s();var o=fe(!0);return _("]"),Y(new zt({start:i,expression:e,property:o,end:u()}),t)}if(t&&r("punc","(")){s();var a=new Kt({start:i,expression:e,args:he(),end:u()});return pe(a),Y(a,!0)}return r("template_head")?Y(new _t({start:i,prefix:e,template_string:H(),end:u()}),t):e};function he(){for(var e=[];!r("punc",")");)r("expand","...")?(s(),e.push(new at({start:u(),expression:fe(!1),end:u()}))):e.push(fe(!1)),r("punc",")")||(_(","),r("punc",")")&&n.ecma<8&&f());return s(),e}var ie=function(e,t){var n=v.token;if("name"==n.type&&"await"==n.value){if(h())return s(),h()||c("Unexpected await expression outside async function",v.prev.line,v.prev.col,v.prev.pos),new Fi({start:u(),end:v.token,expression:ie(!0)});v.input.has_directive("use strict")&&l(v.token,"Unexpected await identifier inside strict mode")}if(r("operator")&&we.has(n.value)){s(),A();var i=Ae(Yt,n,ie(e));return i.start=n,i.end=u(),i}for(var o=K(e,t);r("operator")&&xe.has(v.token.value)&&!d(v.token);)o instanceof lt&&f(),(o=Ae(qt,v.token,o)).start=n,o.end=v.token,s();return o};function Ae(e,t,n){var i=t.value;switch(i){case"++":case"--":He(n)||c("Invalid use of "+i+" operator",t.line,t.col,t.pos);break;case"delete":n instanceof wn&&v.input.has_directive("use strict")&&c("Calling delete on expression not allowed in strict mode",n.start.line,n.start.col,n.start.pos)}return new e({operator:i,expression:n})}var re=function(e,t,n){var i=r("operator")?v.token.value:null;"in"==i&&n&&(i=null),"**"==i&&e instanceof Yt&&!ee(e.start,"punc","(")&&"--"!==e.operator&&"++"!==e.operator&&f(e.start);var o=null!=i?Ie[i]:null;if(null!=o&&(o>t||"**"===i&&t===o)){s();var a=re(ie(!0),o,n);return re(new $t({start:e.start,left:e,operator:i,right:a,end:a.end}),t,n)}return e};var oe=function(e){var t=v.token,n=function(e){return re(ie(!0,!0),0,e)}(e);if(r("operator","?")){s();var i=fe(!1);return _(":"),new jt({start:t,condition:n,consequent:i,alternative:fe(!1,e),end:u()})}return n};function He(e){return e instanceof Ht||e instanceof wn}function Xe(e){if(e instanceof en)e=new pt({start:e.start,names:e.properties.map(Xe),is_array:!1,end:e.end});else if(e instanceof Jt){for(var t=[],n=0;n=0;)o+="this."+t[a]+" = props."+t[a]+";";const s=i&&Object.create(i.prototype);(s&&s.initialize||n&&n.initialize)&&(o+="this.initialize();"),o+="}",o+="this.flags = 0;",o+="}";var u=new Function(o)();if(s&&(u.prototype=s,u.BASE=i),i&&i.SUBCLASSES.push(u),u.prototype.CTOR=u,u.PROPS=t||null,u.SELF_PROPS=r,u.SUBCLASSES=[],e&&(u.prototype.TYPE=u.TYPE=e),n)for(a in n)D(n,a)&&("$"===a[0]?u[a.substr(1)]=n[a]:u.prototype[a]=n[a]);return u.DEFMETHOD=function(e,t){this.prototype[e]=t},u}var Ve=ce("Token","type value line col pos endline endcol endpos nlb comments_before comments_after file raw quote end",{},null),Pe=ce("Node","start end",{_clone:function(e){if(e){var t=this.clone();return t.transform(new vn(function(e){if(e!==t)return e.clone(!0)}))}return new this.CTOR(this)},clone:function(e){return this._clone(e)},$documentation:"Base class of all AST nodes",$propdoc:{start:"[AST_Token] The first token of this node",end:"[AST_Token] The last token of this node"},_walk:function(e){return e._visit(this)},walk:function(e){return this._walk(e)}},null);Pe.warn_function=null,Pe.warn=function(e,t){Pe.warn_function&&Pe.warn_function(_(e,t))};var Be=ce("Statement",null,{$documentation:"Base class of all statements"}),Ke=ce("Debugger",null,{$documentation:"Represents a debugger statement"},Be),Ue=ce("Directive","value quote",{$documentation:'Represents a directive, like "use strict";',$propdoc:{value:"[string] The value of this directive as a plain string (it's not an AST_String!)",quote:"[string] the original quote character"}},Be),Ge=ce("SimpleStatement","body",{$documentation:"A statement consisting of an expression, i.e. a = 1 + 2",$propdoc:{body:"[AST_Node] an expression node (should not be instanceof AST_Statement)"},_walk:function(e){return e._visit(this,function(){this.body._walk(e)})}},Be);function Ee(e,t){var n=e.body;if(n instanceof Pe)n._walk(t);else for(var i=0,r=n.length;i SymbolDef for all variables/functions defined in this scope",functions:"[Map/S] like `variables`, but only lists function declarations",uses_with:"[boolean/S] tells whether this scope uses the `with` statement",uses_eval:"[boolean/S] tells whether this scope contains a direct call to the global `eval`",parent_scope:"[AST_Scope?/S] link to the parent scope",enclosed:"[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",cname:"[integer/S] current index for mangling variables (used internally by the mangler)"},get_defun_scope:function(){for(var e=this;e.is_block_scope();)e=e.parent_scope;return e},clone:function(e){var t=this._clone(e);return this.variables&&(t.variables=new Map(this.variables)),this.functions&&(t.functions=new Map(this.functions)),this.enclosed&&(t.enclosed=this.enclosed.slice()),t},pinned:function(){return this.uses_eval||this.uses_with}},ze),ot=ce("Toplevel","globals",{$documentation:"The toplevel scope",$propdoc:{globals:"[Map/S] a map of name -> SymbolDef for all undeclared names"},wrap_commonjs:function(e){var t=this.body,n="(function(exports){'$ORIG';})(typeof "+e+"=='undefined'?("+e+"={}):"+e+");";return n=(n=ue(n)).transform(new vn(function(e){if(e instanceof Ue&&"$ORIG"==e.value)return F.splice(t)}))},wrap_enclose:function(e){"string"!=typeof e&&(e="");var t=e.indexOf(":");t<0&&(t=e.length);var n=this.body;return ue(["(function(",e.slice(0,t),'){"$ORIG"})(',e.slice(t+1),")"].join("")).transform(new vn(function(e){if(e instanceof Ue&&"$ORIG"==e.value)return F.splice(n)}))}},rt),at=ce("Expansion","expression",{$documentation:"An expandible argument, such as ...rest, a splat, such as [1,2,...all], or an expansion in a variable declaration, such as var [first, ...rest] = list",$propdoc:{expression:"[AST_Node] the thing to be expanded"},_walk:function(e){var t=this;return e._visit(this,function(){t.expression.walk(e)})}}),st=ce("Lambda","name argnames uses_arguments is_generator async",{$documentation:"Base class for functions",$propdoc:{name:"[AST_SymbolDeclaration?] the name of this function",argnames:"[AST_SymbolFunarg|AST_Destructuring|AST_Expansion|AST_DefaultAssign*] array of function arguments, destructurings, or expanding arguments",uses_arguments:"[boolean/S] tells whether this function accesses the arguments array",is_generator:"[boolean] is this a generator method",async:"[boolean] is this method async"},args_as_names:function(){for(var e=[],t=0;t b)"},st),ft=ce("Defun",null,{$documentation:"A function definition"},st),pt=ce("Destructuring","names is_array",{$documentation:"A destructuring of several names. Used in destructuring assignment and with destructuring function argument names",$propdoc:{names:"[AST_Node*] Array of properties or elements",is_array:"[Boolean] Whether the destructuring represents an object or array"},_walk:function(e){return e._visit(this,function(){this.names.forEach(function(t){t._walk(e)})})},all_symbols:function(){var e=[];return this.walk(new An(function(t){t instanceof ln&&e.push(t)})),e}}),_t=ce("PrefixedTemplateString","template_string prefix",{$documentation:"A templatestring with a prefix, such as String.raw`foobarbaz`",$propdoc:{template_string:"[AST_TemplateString] The template string",prefix:"[AST_SymbolRef|AST_PropAccess] The prefix, which can be a symbol such as `foo` or a dotted expression such as `String.raw`."},_walk:function(e){this.prefix._walk(e),this.template_string._walk(e)}}),dt=ce("TemplateString","segments",{$documentation:"A template string literal",$propdoc:{segments:"[AST_Node*] One or more segments, starting with AST_TemplateSegment. AST_Node may follow AST_TemplateSegment, but each AST_Node must be followed by AST_TemplateSegment."},_walk:function(e){return e._visit(this,function(){this.segments.forEach(function(t){t._walk(e)})})}}),mt=ce("TemplateSegment","value raw",{$documentation:"A segment of a template string literal",$propdoc:{value:"Content of the segment",raw:"Raw content of the segment"}}),Et=ce("Jump",null,{$documentation:"Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"},Be),ht=ce("Exit","value",{$documentation:"Base class for “exits” (`return` and `throw`)",$propdoc:{value:"[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"},_walk:function(e){return e._visit(this,this.value&&function(){this.value._walk(e)})}},Et),gt=ce("Return",null,{$documentation:"A `return` statement"},ht),At=ce("Throw",null,{$documentation:"A `throw` statement"},ht),St=ce("LoopControl","label",{$documentation:"Base class for loop control statements (`break` and `continue`)",$propdoc:{label:"[AST_LabelRef?] the label, or null if none"},_walk:function(e){return e._visit(this,this.label&&function(){this.label._walk(e)})}},Et),vt=ce("Break",null,{$documentation:"A `break` statement"},St),Tt=ce("Continue",null,{$documentation:"A `continue` statement"},St),bt=ce("If","condition alternative",{$documentation:"A `if` statement",$propdoc:{condition:"[AST_Node] the `if` condition",alternative:"[AST_Statement?] the `else` part, or null if not present"},_walk:function(e){return e._visit(this,function(){this.condition._walk(e),this.body._walk(e),this.alternative&&this.alternative._walk(e)})}},qe),yt=ce("Switch","expression",{$documentation:"A `switch` statement",$propdoc:{expression:"[AST_Node] the `switch` “discriminant”"},_walk:function(e){return e._visit(this,function(){this.expression._walk(e),Ee(this,e)})}},ze),Ct=ce("SwitchBranch",null,{$documentation:"Base class for `switch` branches"},ze),Ot=ce("Default",null,{$documentation:"A `default` switch branch"},Ct),Ft=ce("Case","expression",{$documentation:"A `case` switch branch",$propdoc:{expression:"[AST_Node] the `case` expression"},_walk:function(e){return e._visit(this,function(){this.expression._walk(e),Ee(this,e)})}},Ct),Mt=ce("Try","bcatch bfinally",{$documentation:"A `try` statement",$propdoc:{bcatch:"[AST_Catch?] the catch block, or null if not present",bfinally:"[AST_Finally?] the finally block, or null if not present"},_walk:function(e){return e._visit(this,function(){Ee(this,e),this.bcatch&&this.bcatch._walk(e),this.bfinally&&this.bfinally._walk(e)})}},ze),Rt=ce("Catch","argname",{$documentation:"A `catch` node; only makes sense as part of a `try` statement",$propdoc:{argname:"[AST_SymbolCatch|AST_Destructuring|AST_Expansion|AST_DefaultAssign] symbol for the exception"},_walk:function(e){return e._visit(this,function(){this.argname&&this.argname._walk(e),Ee(this,e)})}},ze),Nt=ce("Finally",null,{$documentation:"A `finally` node; only makes sense as part of a `try` statement"},ze),wt=ce("Definitions","definitions",{$documentation:"Base class for `var` or `const` nodes (variable declarations/initializations)",$propdoc:{definitions:"[AST_VarDef*] array of variable definitions"},_walk:function(e){return e._visit(this,function(){for(var t=this.definitions,n=0,i=t.length;n a`"},$t),Jt=ce("Array","elements",{$documentation:"An array literal",$propdoc:{elements:"[AST_Node*] array of elements"},_walk:function(e){return e._visit(this,function(){for(var t=this.elements,n=0,i=t.length;nt._walk(e))})}},rt),un=ce("DefClass",null,{$documentation:"A class definition"},sn),cn=ce("ClassExpression",null,{$documentation:"A class expression."},sn),ln=ce("Symbol","scope name thedef",{$propdoc:{name:"[string] name of this symbol",scope:"[AST_Scope/S] the current scope (not necessarily the definition scope)",thedef:"[SymbolDef/S] the definition of this symbol"},$documentation:"Base class for all symbols"}),fn=ce("NewTarget",null,{$documentation:"A reference to new.target"}),pn=ce("SymbolDeclaration","init",{$documentation:"A declaration symbol (symbol in var/const, function name or argument, symbol in catch)"},ln),_n=ce("SymbolVar",null,{$documentation:"Symbol defining a variable"},pn),dn=ce("SymbolBlockDeclaration",null,{$documentation:"Base class for block-scoped declaration symbols"},pn),mn=ce("SymbolConst",null,{$documentation:"A constant declaration"},dn),En=ce("SymbolLet",null,{$documentation:"A block-scoped `let` declaration"},dn),hn=ce("SymbolFunarg",null,{$documentation:"Symbol naming a function argument"},_n),Dn=ce("SymbolDefun",null,{$documentation:"Symbol defining a function"},pn),gn=ce("SymbolMethod",null,{$documentation:"Symbol in an object defining a method"},ln),Sn=ce("SymbolLambda",null,{$documentation:"Symbol naming a function expression"},pn),Tn=ce("SymbolDefClass",null,{$documentation:"Symbol naming a class's name in a class declaration. Lexically scoped to its containing scope, and accessible within the class."},dn),bn=ce("SymbolClass",null,{$documentation:"Symbol naming a class's name. Lexically scoped to the class."},pn),yn=ce("SymbolCatch",null,{$documentation:"Symbol naming the exception in catch"},dn),Cn=ce("SymbolImport",null,{$documentation:"Symbol referring to an imported name"},dn),Rn=ce("SymbolImportForeign",null,{$documentation:"A symbol imported from a module, but it is defined in the other module, and its real name is irrelevant for this module's purposes"},ln),Nn=ce("Label","references",{$documentation:"Symbol naming a label (declaration)",$propdoc:{references:"[AST_LoopControl*] a list of nodes referring to this label"},initialize:function(){this.references=[],this.thedef=this}},ln),wn=ce("SymbolRef",null,{$documentation:"Reference to some symbol (not definition/declaration)"},ln),xn=ce("SymbolExport",null,{$documentation:"Symbol referring to a name to export"},wn),Ln=ce("SymbolExportForeign",null,{$documentation:"A symbol exported from this module, but it is used in the other module, and its real name is irrelevant for this module's purposes"},ln),Vn=ce("LabelRef",null,{$documentation:"Reference to a label symbol"},ln),Pn=ce("This",null,{$documentation:"The `this` symbol"},ln),Gn=ce("Super",null,{$documentation:"The `super` symbol"},Pn),Hn=ce("Constant",null,{$documentation:"Base class for all constants",getValue:function(){return this.value}}),Xn=ce("String","value quote",{$documentation:"A string literal",$propdoc:{value:"[string] the contents of this string",quote:"[string] the original quote character"}},Hn),zn=ce("Number","value literal",{$documentation:"A number literal",$propdoc:{value:"[number] the numeric value",literal:"[string] numeric value as string (optional)"}},Hn),Wn=ce("BigInt","value",{$documentation:"A big int literal",$propdoc:{value:"[string] big int value"}},Hn),Yn=ce("RegExp","value",{$documentation:"A regexp literal",$propdoc:{value:"[RegExp] the actual regexp"}},Hn),qn=ce("Atom",null,{$documentation:"Base class for atoms"},Hn),$n=ce("Null",null,{$documentation:"The `null` atom",value:null},qn),jn=ce("NaN",null,{$documentation:"The impossible value",value:NaN},qn),Zn=ce("Undefined",null,{$documentation:"The `undefined` value",value:void 0},qn),Qn=ce("Hole",null,{$documentation:"A hole in an array",value:void 0},qn),Jn=ce("Infinity",null,{$documentation:"The `Infinity` value",value:1/0},qn),Ai=ce("Boolean",null,{$documentation:"Base class for booleans"},qn),Si=ce("False",null,{$documentation:"The `false` atom",value:!1},Ai),vi=ce("True",null,{$documentation:"The `true` atom",value:!0},Ai),Fi=ce("Await","expression",{$documentation:"An `await` statement",$propdoc:{expression:"[AST_Node] the mandatory expression being awaited"},_walk:function(e){return e._visit(this,function(){this.expression._walk(e)})}}),Mi=ce("Yield","expression is_star",{$documentation:"A `yield` statement",$propdoc:{expression:"[AST_Node?] the value returned or thrown by this statement; could be null (representing undefined) but only when is_star is set to false",is_star:"[Boolean] Whether this is a yield or yield* statement"},_walk:function(e){return e._visit(this,this.expression&&function(){this.expression._walk(e)})}});class An{constructor(e){this.visit=e,this.stack=[],this.directives=Object.create(null)}_visit(e,t){this.push(e);var n=this.visit(e,t?function(){t.call(e)}:a);return!n&&t&&t.call(e),this.pop(),n}parent(e){return this.stack[this.stack.length-2-(e||0)]}push(e){e instanceof st?this.directives=Object.create(this.directives):e instanceof Ue&&!this.directives[e.value]?this.directives[e.value]=e:e instanceof sn&&(this.directives=Object.create(this.directives),this.directives["use strict"]||(this.directives["use strict"]=e)),this.stack.push(e)}pop(){var e=this.stack.pop();(e instanceof st||e instanceof sn)&&(this.directives=Object.getPrototypeOf(this.directives))}self(){return this.stack[this.stack.length-1]}find_parent(e){for(var t=this.stack,n=t.length;--n>=0;){var i=t[n];if(i instanceof e)return i}}has_directive(e){var t=this.directives[e];if(t)return t;var n=this.stack[this.stack.length-1];if(n instanceof rt&&n.body)for(var i=0;i=0;){if((i=t[n])instanceof $e&&i.label.name==e.label.name)return i.body}else for(n=t.length;--n>=0;){var i;if((i=t[n])instanceof je||e instanceof vt&&i instanceof yt)return i}}}class vn extends An{constructor(e,t){super(),this.before=e,this.after=t}}const Ii=1,Li=2,Vi=4;var Pi=Object.freeze({__proto__:null,AST_Accessor:ut,AST_Array:Jt,AST_Arrow:lt,AST_Assign:Zt,AST_Atom:qn,AST_Await:Fi,AST_BigInt:Wn,AST_Binary:$t,AST_Block:ze,AST_BlockStatement:We,AST_Boolean:Ai,AST_Break:vt,AST_Call:Kt,AST_Case:Ft,AST_Catch:Rt,AST_Class:sn,AST_ClassExpression:cn,AST_ConciseMethod:an,AST_Conditional:jt,AST_Const:It,AST_Constant:Hn,AST_Continue:Tt,AST_Debugger:Ke,AST_Default:Ot,AST_DefaultAssign:Qt,AST_DefClass:un,AST_Definitions:wt,AST_Defun:ft,AST_Destructuring:pt,AST_Directive:Ue,AST_Do:Qe,AST_Dot:Xt,AST_DWLoop:Ze,AST_EmptyStatement:Ye,AST_Exit:ht,AST_Expansion:at,AST_Export:Pt,AST_False:Si,AST_Finally:Nt,AST_For:et,AST_ForIn:tt,AST_ForOf:nt,AST_Function:ct,AST_Hole:Qn,AST_If:bt,AST_Import:Vt,AST_Infinity:Jn,AST_IterationStatement:je,AST_Jump:Et,AST_Label:Nn,AST_LabeledStatement:$e,AST_LabelRef:Vn,AST_Lambda:st,AST_Let:kt,AST_LoopControl:St,AST_NameMapping:Lt,AST_NaN:jn,AST_New:Ut,AST_NewTarget:fn,AST_Node:Pe,AST_Null:$n,AST_Number:zn,AST_Object:en,AST_ObjectGetter:on,AST_ObjectKeyVal:nn,AST_ObjectProperty:tn,AST_ObjectSetter:rn,AST_PrefixedTemplateString:_t,AST_PropAccess:Ht,AST_RegExp:Yn,AST_Return:gt,AST_Scope:rt,AST_Sequence:Gt,AST_SimpleStatement:Ge,AST_Statement:Be,AST_StatementWithBody:qe,AST_String:Xn,AST_Sub:zt,AST_Super:Gn,AST_Switch:yt,AST_SwitchBranch:Ct,AST_Symbol:ln,AST_SymbolBlockDeclaration:dn,AST_SymbolCatch:yn,AST_SymbolClass:bn,AST_SymbolConst:mn,AST_SymbolDeclaration:pn,AST_SymbolDefClass:Tn,AST_SymbolDefun:Dn,AST_SymbolExport:xn,AST_SymbolExportForeign:Ln,AST_SymbolFunarg:hn,AST_SymbolImport:Cn,AST_SymbolImportForeign:Rn,AST_SymbolLambda:Sn,AST_SymbolLet:En,AST_SymbolMethod:gn,AST_SymbolRef:wn,AST_SymbolVar:_n,AST_TemplateSegment:mt,AST_TemplateString:dt,AST_This:Pn,AST_Throw:At,AST_Token:Ve,AST_Toplevel:ot,AST_True:vi,AST_Try:Mt,AST_Unary:Wt,AST_UnaryPostfix:qt,AST_UnaryPrefix:Yt,AST_Undefined:Zn,AST_Var:xt,AST_VarDef:Bt,AST_While:Je,AST_With:it,AST_Yield:Mi,TreeTransformer:vn,TreeWalker:An,walk_body:Ee,_INLINE:Li,_NOINLINE:Vi,_PURE:Ii});function On(e,t){e.DEFMETHOD("transform",function(e,n){let i=void 0;if(e.push(this),e.before&&(i=e.before(this,t,n)),void 0===i&&(t(i=this,e),e.after)){const t=e.after(i,n);void 0!==t&&(i=t)}return e.pop(),i})}function Fn(e,t){return F(e,function(e){return e.transform(t,!0)})}function Mn(e){let t=e.parent(-1);for(let n,i=0;n=e.parent(i);i++){if(n instanceof Be&&n.body===t)return!0;if(!(n instanceof Gt&&n.expressions[0]===t||"Call"===n.TYPE&&n.expression===t||n instanceof _t&&n.prefix===t||n instanceof Xt&&n.expression===t||n instanceof zt&&n.expression===t||n instanceof jt&&n.condition===t||n instanceof $t&&n.left===t||n instanceof qt&&n.expression===t))return!1;t=n}}On(Pe,a),On($e,function(e,t){e.label=e.label.transform(t),e.body=e.body.transform(t)}),On(Ge,function(e,t){e.body=e.body.transform(t)}),On(ze,function(e,t){e.body=Fn(e.body,t)}),On(Qe,function(e,t){e.body=e.body.transform(t),e.condition=e.condition.transform(t)}),On(Je,function(e,t){e.condition=e.condition.transform(t),e.body=e.body.transform(t)}),On(et,function(e,t){e.init&&(e.init=e.init.transform(t)),e.condition&&(e.condition=e.condition.transform(t)),e.step&&(e.step=e.step.transform(t)),e.body=e.body.transform(t)}),On(tt,function(e,t){e.init=e.init.transform(t),e.object=e.object.transform(t),e.body=e.body.transform(t)}),On(it,function(e,t){e.expression=e.expression.transform(t),e.body=e.body.transform(t)}),On(ht,function(e,t){e.value&&(e.value=e.value.transform(t))}),On(St,function(e,t){e.label&&(e.label=e.label.transform(t))}),On(bt,function(e,t){e.condition=e.condition.transform(t),e.body=e.body.transform(t),e.alternative&&(e.alternative=e.alternative.transform(t))}),On(yt,function(e,t){e.expression=e.expression.transform(t),e.body=Fn(e.body,t)}),On(Ft,function(e,t){e.expression=e.expression.transform(t),e.body=Fn(e.body,t)}),On(Mt,function(e,t){e.body=Fn(e.body,t),e.bcatch&&(e.bcatch=e.bcatch.transform(t)),e.bfinally&&(e.bfinally=e.bfinally.transform(t))}),On(Rt,function(e,t){e.argname&&(e.argname=e.argname.transform(t)),e.body=Fn(e.body,t)}),On(wt,function(e,t){e.definitions=Fn(e.definitions,t)}),On(Bt,function(e,t){e.name=e.name.transform(t),e.value&&(e.value=e.value.transform(t))}),On(pt,function(e,t){e.names=Fn(e.names,t)}),On(st,function(e,t){e.name&&(e.name=e.name.transform(t)),e.argnames=Fn(e.argnames,t),e.body instanceof Pe?e.body=e.body.transform(t):e.body=Fn(e.body,t)}),On(Kt,function(e,t){e.expression=e.expression.transform(t),e.args=Fn(e.args,t)}),On(Gt,function(e,t){const n=Fn(e.expressions,t);e.expressions=n.length?n:[new zn({value:0})]}),On(Xt,function(e,t){e.expression=e.expression.transform(t)}),On(zt,function(e,t){e.expression=e.expression.transform(t),e.property=e.property.transform(t)}),On(Mi,function(e,t){e.expression&&(e.expression=e.expression.transform(t))}),On(Fi,function(e,t){e.expression=e.expression.transform(t)}),On(Wt,function(e,t){e.expression=e.expression.transform(t)}),On($t,function(e,t){e.left=e.left.transform(t),e.right=e.right.transform(t)}),On(jt,function(e,t){e.condition=e.condition.transform(t),e.consequent=e.consequent.transform(t),e.alternative=e.alternative.transform(t)}),On(Jt,function(e,t){e.elements=Fn(e.elements,t)}),On(en,function(e,t){e.properties=Fn(e.properties,t)}),On(tn,function(e,t){e.key instanceof Pe&&(e.key=e.key.transform(t)),e.value=e.value.transform(t)}),On(sn,function(e,t){e.name&&(e.name=e.name.transform(t)),e.extends&&(e.extends=e.extends.transform(t)),e.properties=Fn(e.properties,t)}),On(at,function(e,t){e.expression=e.expression.transform(t)}),On(Lt,function(e,t){e.foreign_name=e.foreign_name.transform(t),e.name=e.name.transform(t)}),On(Vt,function(e,t){e.imported_name&&(e.imported_name=e.imported_name.transform(t)),e.imported_names&&Fn(e.imported_names,t),e.module_name=e.module_name.transform(t)}),On(Pt,function(e,t){e.exported_definition&&(e.exported_definition=e.exported_definition.transform(t)),e.exported_value&&(e.exported_value=e.exported_value.transform(t)),e.exported_names&&Fn(e.exported_names,t),e.module_name&&(e.module_name=e.module_name.transform(t))}),On(dt,function(e,t){e.segments=Fn(e.segments,t)}),On(_t,function(e,t){e.prefix=e.prefix.transform(t),e.template_string=e.template_string.transform(t)});const Bi=/^$|[;{][\s\n]*$/,Ui=10,Hi=32,Wi=/[@#]__(PURE|INLINE|NOINLINE)__/g;function kn(e){return"comment2"==e.type&&/@preserve|@lic|@cc_on|^\**!/i.test(e.value)}function In(e){var t=!e;void 0===(e=o(e,{ascii_only:!1,beautify:!1,braces:!1,comments:"some",ecma:5,ie8:!1,indent_level:4,indent_start:0,inline_script:!0,keep_quoted_props:!1,max_line_len:!1,preamble:null,quote_keys:!1,quote_style:0,safari10:!1,semicolons:!0,shebang:!0,shorthand:void 0,source_map:null,webkit:!1,width:80,wrap_iife:!1,wrap_func_args:!0},!0)).shorthand&&(e.shorthand=e.ecma>5);var n=s;if(e.comments){let t=e.comments;if("string"==typeof e.comments&&/^\/.*\/[a-zA-Z]*$/.test(e.comments)){var i=e.comments.lastIndexOf("/");t=new RegExp(e.comments.substr(1,i-1),e.comments.substr(i+1))}n=t instanceof RegExp?function(e){return"comment5"!=e.type&&t.test(e.value)}:"function"==typeof t?function(e){return"comment5"!=e.type&&t(this,e)}:"some"===t?kn:u}var r=0,c=0,l=1,f=0,p="";let _=new Set;var d=e.ascii_only?function(t,n){return e.ecma>=6&&(t=t.replace(/[\ud800-\udbff][\udc00-\udfff]/g,function(e){return"\\u{"+function(e,t){return z(e.charAt(t))?65536+(e.charCodeAt(t)-55296<<10)+e.charCodeAt(t+1)-56320:e.charCodeAt(t)}(e,0).toString(16)+"}"})),t.replace(/[\u0000-\u001f\u007f-\uffff]/g,function(e){var t=e.charCodeAt(0).toString(16);if(t.length<=2&&!n){for(;t.length<2;)t="0"+t;return"\\x"+t}for(;t.length<4;)t="0"+t;return"\\u"+t})}:function(e){for(var t="",n=0,i=e.length;nr?o():a()}}(t,n);return e.inline_script&&(i=(i=(i=i.replace(/<\x2f(script)([>\/\t\n\f\r ])/gi,"<\\/$1$2")).replace(/\x3c!--/g,"\\x3c!--")).replace(/--\x3e/g,"--\\x3e")),i}var h,D,g=!1,A=!1,S=!1,v=0,T=!1,b=!1,y=-1,C="",O=e.source_map&&[],F=O?function(){O.forEach(function(t){try{e.source_map.add(t.token.file,t.line,t.col,t.token.line,t.token.col,t.name||"name"!=t.token.type?t.name:t.token.value)}catch(e){null!=t.token.file&&Pe.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]",{file:t.token.file,line:t.token.line,col:t.token.col,cline:t.line,ccol:t.col,name:t.name||""})}}),O=[]}:a,M=e.max_line_len?function(){if(c>e.max_line_len){if(v){var t=p.slice(0,v),n=p.slice(v);if(O){var i=n.length-c;O.forEach(function(e){e.line++,e.col+=i})}p=t+"\n"+n,l++,f++,c=n.length}c>e.max_line_len&&Pe.warn("Output exceeds {max_line_len} characters",e)}v&&(v=0,F())}:a,R=E("( [ + * / - , . `");function N(t){var n=X(t=String(t),0);T&&n&&(T=!1,"\n"!==n&&(N("\n"),x())),b&&n&&(b=!1,/[\s;})]/.test(n)||w()),y=-1;var i=C.charAt(C.length-1);S&&(S=!1,(":"!==i||"}"!==n)&&(n&&";}".includes(n)||";"===i)||(e.semicolons||R.has(n)?(p+=";",c++,f++):(M(),c>0&&(p+="\n",f++,l++,c=0),/^\s+$/.test(t)&&(S=!0)),e.beautify||(A=!1))),A&&(($(i)&&($(n)||"\\"==n)||"/"==n&&n==i||("+"==n||"-"==n)&&n==C)&&(p+=" ",c++,f++),A=!1),h&&(O.push({token:h,name:D,line:l,col:c}),h=!1,v||F()),p+=t,g="("==t[t.length-1],f+=t.length;var r=t.split(/\r?\n/),o=r.length-1;l+=o,c+=r[0].length,o>0&&(M(),c=r[o].length),C=t}var w=e.beautify?function(){N(" ")}:function(){A=!0},x=e.beautify?function(t){var n;e.beautify&&N((n=t?.5:0," ".repeat(e.indent_start+r-n*e.indent_level)))}:a,k=e.beautify?function(e,t){!0===e&&(e=P());var n=r;r=e;var i=t();return r=n,i}:function(e,t){return t()},I=e.beautify?function(){if(y<0)return N("\n");"\n"!=p[y]&&(p=p.slice(0,y)+"\n"+p.slice(y),f++,l++),y++}:e.max_line_len?function(){M(),v=p.length}:a,L=e.beautify?function(){N(";")}:function(){S=!0};function V(){S=!1,N(";")}function P(){return r+e.indent_level}function B(){return v&&M(),p}function K(){let e=p.length-1;for(;e>=0;){const t=p.charCodeAt(e);if(t===Ui)return!0;if(t!==Hi)return!1;e--}return!0}var U=[];return{get:B,toString:B,indent:x,indentation:function(){return r},current_width:function(){return c-r},should_break:function(){return e.width&&this.current_width()>=e.width},has_parens:function(){return g},newline:I,print:N,star:function(){N("*")},space:w,comma:function(){N(","),w()},colon:function(){N(":"),w()},last:function(){return C},semicolon:L,force_semicolon:V,to_utf8:d,print_name:function(e){N(function(e){return e=e.toString(),e=d(e,!0)}(e))},print_string:function(e,t,n){var i=m(e,t);!0!==n||i.includes("\\")||(Bi.test(p)||V(),V()),N(i)},print_template_string_chars:function(e){var t=m(e,"`").replace(/\${/g,"\\${");return N(t.substr(1,t.length-2))},encode_string:m,next_indent:P,with_indent:k,with_block:function(e){var t;return N("{"),I(),k(P(),function(){t=e()}),x(),N("}"),t},with_parens:function(e){N("(");var t=e();return N(")"),t},with_square:function(e){N("[");var t=e();return N("]"),t},add_mapping:O?function(e,t){h=e,D=t}:a,option:function(t){return e[t]},printed_comments:_,prepend_comments:t?a:function(t){var i=t.start;if(i){var r=this.printed_comments;if(!i.comments_before||!r.has(i.comments_before)){var o=i.comments_before;if(o||(o=i.comments_before=[]),r.add(o),t instanceof ht&&t.value){var a=new An(function(e){var t=a.parent();if(!(t instanceof ht||t instanceof $t&&t.left===e||"Call"==t.TYPE&&t.expression===e||t instanceof jt&&t.condition===e||t instanceof Xt&&t.expression===e||t instanceof Gt&&t.expressions[0]===e||t instanceof zt&&t.expression===e||t instanceof qt))return!0;if(e.start){var n=e.start.comments_before;n&&!r.has(n)&&(r.add(n),o=o.concat(n))}});a.push(t),t.value.walk(a)}if(0==f){o.length>0&&e.shebang&&"comment5"===o[0].type&&!r.has(o[0])&&(N("#!"+o.shift().value+"\n"),x());var s=e.preamble;s&&N(s.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g,"\n"))}if(0!=(o=o.filter(n,t).filter(e=>!r.has(e))).length){var u=K();o.forEach(function(e,t){r.add(e),u||(e.nlb?(N("\n"),x(),u=!0):t>0&&w()),/comment[134]/.test(e.type)?(N("//"+e.value.replace(Wi," ")+"\n"),x(),u=!0):"comment2"==e.type&&(N("/*"+e.value.replace(Wi," ")+"*/"),u=!1)}),u||(i.nlb?(N("\n"),x()):w())}}}},append_comments:t||n===s?a:function(e,t){var i=e.end;if(i){var r=this.printed_comments,o=i[t?"comments_before":"comments_after"];if(o&&!r.has(o)&&(e instanceof Be||o.every(e=>!/comment[134]/.test(e.type)))){r.add(o);var a=p.length;o.filter(n,e).forEach(function(e,n){r.has(e)||(r.add(e),b=!1,T?(N("\n"),x(),T=!1):e.nlb&&(n>0||!K())?(N("\n"),x()):(n>0||!t)&&w(),/comment[134]/.test(e.type)?(N("//"+e.value.replace(Wi," ")),T=!0):"comment2"==e.type&&(N("/*"+e.value.replace(Wi," ")+"*/"),b=!0))}),p.length>a&&(y=a)}}},line:function(){return l},col:function(){return c},pos:function(){return f},push_node:function(e){U.push(e)},pop_node:function(){return U.pop()},parent:function(e){return U[U.length-2-(e||0)]}}}!function(){function e(e,t){e.DEFMETHOD("_codegen",t)}var t=!1,i=null,E=null;function r(e,t){Array.isArray(e)?e.forEach(function(e){r(e,t)}):e.DEFMETHOD("needs_parens",t)}function o(e,n,i,r){var o=e.length-1;t=r,e.forEach(function(e,r){!0!==t||e instanceof Ue||e instanceof Ye||e instanceof Ge&&e.body instanceof Xn||(t=!1),e instanceof Ye||(i.indent(),e.print(i),r==o&&n||(i.newline(),n&&i.newline())),!0===t&&e instanceof Ge&&e.body instanceof Xn&&(t=!1)}),t=!1}function u(e,t){t.print("{"),t.with_indent(t.next_indent(),function(){t.append_comments(e,!0)}),t.print("}")}function c(e,t,n){e.body.length>0?t.with_block(function(){o(e.body,!1,t,n)}):u(e,t)}function l(e,t,n){var i=!1;n&&e.walk(new An(function(e){return!!(i||e instanceof rt)||(e instanceof $t&&"in"==e.operator?(i=!0,!0):void 0)})),e.print(t,i)}function f(e,t,n){n.option("quote_keys")?n.print_string(e):""+ +e==e&&e>=0?n.print(_(e)):(se.has(e)?!n.option("ie8"):j(e))?t&&n.option("keep_quoted_props")?n.print_string(e,t):n.print_name(e):n.print_string(e,t)}function p(e,t){t.option("braces")?d(e,t):!e||e instanceof Ye?t.force_semicolon():e.print(t)}function _(e){var t,n,i,r=e.toString(10).replace(/^0\./,".").replace("e+","e"),o=[r];return Math.floor(e)===e&&(e<0?o.push("-0x"+(-e).toString(16).toLowerCase()):o.push("0x"+e.toString(16).toLowerCase())),(t=/^\.0+/.exec(r))?(n=t[0].length,i=r.slice(n),o.push(i+"e-"+(i.length+n-1))):(t=/0+$/.exec(r))?(n=t[0].length,o.push(r.slice(0,-n)+"e"+n)):(t=/^(\d)\.(\d+)e(-?\d+)$/.exec(r))&&o.push(t[1]+t[2]+"e"+(t[3]-t[2].length)),function(e){for(var t=e[0],n=t.length,i=1;io||i==o&&(this===t.right||"**"==n))return!0}}),r(Mi,function(e){var t=e.parent();return t instanceof $t&&"="!==t.operator||(t instanceof Kt&&t.expression===this||(t instanceof jt&&t.condition===this||(t instanceof Wt||(t instanceof Ht&&t.expression===this||void 0))))}),r(Ht,function(e){var t=e.parent();if(t instanceof Ut&&t.expression===this){var n=!1;return this.walk(new An(function(e){return!!(n||e instanceof rt)||(e instanceof Kt?(n=!0,!0):void 0)})),n}}),r(Kt,function(e){var t,n=e.parent();return!!(n instanceof Ut&&n.expression===this||n instanceof Pt&&n.is_default&&this.expression instanceof ct)||this.expression instanceof ct&&n instanceof Ht&&n.expression===this&&(t=e.parent(1))instanceof Zt&&t.left===n}),r(Ut,function(e){var t=e.parent();if(0===this.args.length&&(t instanceof Ht||t instanceof Kt&&t.expression===this))return!0}),r(zn,function(e){var t=e.parent();if(t instanceof Ht&&t.expression===this){var n=this.getValue();if(n<0||/^0/.test(_(n)))return!0}}),r(Wn,function(e){var t=e.parent();if(t instanceof Ht&&t.expression===this&&this.getValue().startsWith("-"))return!0}),r([Zt,jt],function(e){var t=e.parent();return t instanceof Wt||(t instanceof $t&&!(t instanceof Zt)||(t instanceof Kt&&t.expression===this||(t instanceof jt&&t.condition===this||(t instanceof Ht&&t.expression===this||(this instanceof Zt&&this.left instanceof pt&&!1===this.left.is_array||void 0)))))}),e(Ue,function(e,t){t.print_string(e.value,e.quote),t.semicolon()}),e(at,function(e,t){t.print("..."),e.expression.print(t)}),e(pt,function(e,t){t.print(e.is_array?"[":"{");var n=e.names.length;e.names.forEach(function(e,i){i>0&&t.comma(),e.print(t),i==n-1&&e instanceof Qn&&t.comma()}),t.print(e.is_array?"]":"}")}),e(Ke,function(e,t){t.print("debugger"),t.semicolon()}),qe.DEFMETHOD("_do_print_body",function(e){p(this.body,e)}),e(Be,function(e,t){e.body.print(t),t.semicolon()}),e(ot,function(e,t){o(e.body,!0,t,!0),t.print("")}),e($e,function(e,t){e.label.print(t),t.colon(),e.body.print(t)}),e(Ge,function(e,t){e.body.print(t),t.semicolon()}),e(We,function(e,t){c(e,t)}),e(Ye,function(e,t){t.semicolon()}),e(Qe,function(e,t){t.print("do"),t.space(),d(e.body,t),t.space(),t.print("while"),t.space(),t.with_parens(function(){e.condition.print(t)}),t.semicolon()}),e(Je,function(e,t){t.print("while"),t.space(),t.with_parens(function(){e.condition.print(t)}),t.space(),e._do_print_body(t)}),e(et,function(e,t){t.print("for"),t.space(),t.with_parens(function(){e.init?(e.init instanceof wt?e.init.print(t):l(e.init,t,!0),t.print(";"),t.space()):t.print(";"),e.condition?(e.condition.print(t),t.print(";"),t.space()):t.print(";"),e.step&&e.step.print(t)}),t.space(),e._do_print_body(t)}),e(tt,function(e,t){t.print("for"),e.await&&(t.space(),t.print("await")),t.space(),t.with_parens(function(){e.init.print(t),t.space(),t.print(e instanceof nt?"of":"in"),t.space(),e.object.print(t)}),t.space(),e._do_print_body(t)}),e(it,function(e,t){t.print("with"),t.space(),t.with_parens(function(){e.expression.print(t)}),t.space(),e._do_print_body(t)}),st.DEFMETHOD("_do_print",function(e,t){var n=this;t||(n.async&&(e.print("async"),e.space()),e.print("function"),n.is_generator&&e.star(),n.name&&e.space()),n.name instanceof ln?n.name.print(e):t&&n.name instanceof Pe&&e.with_square(function(){n.name.print(e)}),e.with_parens(function(){n.argnames.forEach(function(t,n){n&&e.comma(),t.print(e)})}),e.space(),c(n,e,!0)}),e(st,function(e,t){e._do_print(t)}),e(_t,function(e,t){var n=e.prefix,i=n instanceof st||n instanceof $t||n instanceof jt||n instanceof Gt||n instanceof Wt||n instanceof Xt&&n.expression instanceof en;i&&t.print("("),e.prefix.print(t),i&&t.print(")"),e.template_string.print(t)}),e(dt,function(e,t){var n=t.parent()instanceof _t;t.print("`");for(var i=0;i"),e.space(),t.body instanceof Pe?t.body.print(e):c(t,e),i&&e.print(")")}),ht.DEFMETHOD("_do_print",function(e,t){if(e.print(t),this.value){e.space();const t=this.value.start.comments_before;t&&t.length&&!e.printed_comments.has(t)?(e.print("("),this.value.print(e),e.print(")")):this.value.print(e)}e.semicolon()}),e(gt,function(e,t){e._do_print(t,"return")}),e(At,function(e,t){e._do_print(t,"throw")}),e(Mi,function(e,t){var n=e.is_star?"*":"";t.print("yield"+n),e.expression&&(t.space(),e.expression.print(t))}),e(Fi,function(e,t){t.print("await"),t.space();var n=e.expression,i=!(n instanceof Kt||n instanceof wn||n instanceof Ht||n instanceof Wt||n instanceof Hn);i&&t.print("("),e.expression.print(t),i&&t.print(")")}),St.DEFMETHOD("_do_print",function(e,t){e.print(t),this.label&&(e.space(),this.label.print(e)),e.semicolon()}),e(vt,function(e,t){e._do_print(t,"break")}),e(Tt,function(e,t){e._do_print(t,"continue")}),e(bt,function(e,t){t.print("if"),t.space(),t.with_parens(function(){e.condition.print(t)}),t.space(),e.alternative?(!function(e,t){var n=e.body;if(t.option("braces")||t.option("ie8")&&n instanceof Qe)return d(n,t);if(!n)return t.force_semicolon();for(;;)if(n instanceof bt){if(!n.alternative)return void d(e.body,t);n=n.alternative}else{if(!(n instanceof qe))break;n=n.body}p(e.body,t)}(e,t),t.space(),t.print("else"),t.space(),e.alternative instanceof bt?e.alternative.print(t):p(e.alternative,t)):e._do_print_body(t)}),e(yt,function(e,t){t.print("switch"),t.space(),t.with_parens(function(){e.expression.print(t)}),t.space();var n=e.body.length-1;n<0?u(e,t):t.with_block(function(){e.body.forEach(function(e,i){t.indent(!0),e.print(t),i0&&t.newline()})})}),Ct.DEFMETHOD("_do_print_body",function(e){e.newline(),this.body.forEach(function(t){e.indent(),t.print(e),e.newline()})}),e(Ot,function(e,t){t.print("default:"),e._do_print_body(t)}),e(Ft,function(e,t){t.print("case"),t.space(),e.expression.print(t),t.print(":"),e._do_print_body(t)}),e(Mt,function(e,t){t.print("try"),t.space(),c(e,t),e.bcatch&&(t.space(),e.bcatch.print(t)),e.bfinally&&(t.space(),e.bfinally.print(t))}),e(Rt,function(e,t){t.print("catch"),e.argname&&(t.space(),t.with_parens(function(){e.argname.print(t)})),t.space(),c(e,t)}),e(Nt,function(e,t){t.print("finally"),t.space(),c(e,t)}),wt.DEFMETHOD("_do_print",function(e,t){e.print(t),e.space(),this.definitions.forEach(function(t,n){n&&e.comma(),t.print(e)});var n=e.parent();(!(n instanceof et||n instanceof tt)||n&&n.init!==this)&&e.semicolon()}),e(kt,function(e,t){e._do_print(t,"let")}),e(xt,function(e,t){e._do_print(t,"var")}),e(It,function(e,t){e._do_print(t,"const")}),e(Vt,function(e,t){t.print("import"),t.space(),e.imported_name&&e.imported_name.print(t),e.imported_name&&e.imported_names&&(t.print(","),t.space()),e.imported_names&&(1===e.imported_names.length&&"*"===e.imported_names[0].foreign_name.name?e.imported_names[0].print(t):(t.print("{"),e.imported_names.forEach(function(n,i){t.space(),n.print(t),i0&&(e.comma(),e.should_break()&&(e.newline(),e.indent())),t.print(e)})}),e(Gt,function(e,t){e._do_print(t)}),e(Xt,function(e,t){var n=e.expression;n.print(t);var i=e.property;t.option("ie8")&&se.has(i)?(t.print("["),t.add_mapping(e.end),t.print_string(i),t.print("]")):(n instanceof zn&&n.getValue()>=0&&(/[xa-f.)]/i.test(t.last())||t.print(".")),t.print("."),t.add_mapping(e.end),t.print_name(i))}),e(zt,function(e,t){e.expression.print(t),t.print("["),e.property.print(t),t.print("]")}),e(Yt,function(e,t){var n=e.operator;t.print(n),(/^[a-z]/i.test(n)||/[+-]$/.test(n)&&e.expression instanceof Yt&&/^[+-]/.test(e.expression.operator))&&t.space(),e.expression.print(t)}),e(qt,function(e,t){e.expression.print(t),t.print(e.operator)}),e($t,function(e,t){var n=e.operator;e.left.print(t),">"==n[0]&&e.left instanceof qt&&"--"==e.left.operator?t.print(" "):t.space(),t.print(n),("<"==n||"<<"==n)&&e.right instanceof Yt&&"!"==e.right.operator&&e.right.expression instanceof Yt&&"--"==e.right.expression.operator?t.print(" "):t.space(),e.right.print(t)}),e(jt,function(e,t){e.condition.print(t),t.space(),t.print("?"),t.space(),e.consequent.print(t),t.space(),t.colon(),e.alternative.print(t)}),e(Jt,function(e,t){t.with_square(function(){var n=e.elements,i=n.length;i>0&&t.space(),n.forEach(function(e,n){n&&t.comma(),e.print(t),n===i-1&&e instanceof Qn&&t.comma()}),i>0&&t.space()})}),e(en,function(e,t){e.properties.length>0?t.with_block(function(){e.properties.forEach(function(e,n){n&&(t.print(","),t.newline()),t.indent(),e.print(t)}),t.newline()}):u(e,t)}),e(sn,function(e,t){if(t.print("class"),t.space(),e.name&&(e.name.print(t),t.space()),e.extends){var n=!(e.extends instanceof wn||e.extends instanceof Ht||e.extends instanceof cn||e.extends instanceof ct);t.print("extends"),n?t.print("("):t.space(),e.extends.print(t),n?t.print(")"):t.space()}e.properties.length>0?t.with_block(function(){e.properties.forEach(function(e,n){n&&t.newline(),t.indent(),e.print(t)}),t.newline()}):t.print("{}")}),e(fn,function(e,t){t.print("new.target")}),e(nn,function(e,t){function n(e){var t=e.definition();return t?t.mangled_name||t.name:e.name}var i=t.option("shorthand");i&&e.value instanceof ln&&j(e.key)&&n(e.value)===e.key&&!se.has(e.key)?f(e.key,e.quote,t):i&&e.value instanceof Qt&&e.value.left instanceof ln&&j(e.key)&&n(e.value.left)===e.key?(f(e.key,e.quote,t),t.space(),t.print("="),t.space(),e.value.right.print(t)):(e.key instanceof Pe?t.with_square(function(){e.key.print(t)}):f(e.key,e.quote,t),t.colon(),e.value.print(t))}),tn.DEFMETHOD("_print_getter_setter",function(e,t){var n=this;n.static&&(t.print("static"),t.space()),e&&(t.print(e),t.space()),n.key instanceof gn?f(n.key.name,n.quote,t):t.with_square(function(){n.key.print(t)}),n.value._do_print(t,!0)}),e(rn,function(e,t){e._print_getter_setter("set",t)}),e(on,function(e,t){e._print_getter_setter("get",t)}),e(an,function(e,t){var n;e.is_generator&&e.async?n="async*":e.is_generator?n="*":e.async&&(n="async"),e._print_getter_setter(n,t)}),ln.DEFMETHOD("_do_print",function(e){var t=this.definition();e.print_name(t?t.mangled_name||t.name:this.name)}),e(ln,function(e,t){e._do_print(t)}),e(Qn,a),e(Pn,function(e,t){t.print("this")}),e(Gn,function(e,t){t.print("super")}),e(Hn,function(e,t){t.print(e.getValue())}),e(Xn,function(e,n){n.print_string(e.getValue(),e.quote,t)}),e(zn,function(e,t){E&&e.start&&null!=e.start.raw?t.print(e.start.raw):t.print(_(e.getValue()))}),e(Wn,function(e,t){t.print(e.getValue()+"n")}),e(Yn,function(e,t){let{source:n,flags:i}=e.getValue();n=A(n),i=i?function(e){const t=new Set(e.split(""));let n="";for(const e of re)t.has(e)&&(n+=e,t.delete(e));return t.size&&t.forEach(e=>{n+=e}),n}(i):"",t.print(t.to_utf8(`/${n}/${i}`));const r=t.parent();r instanceof $t&&/^\w/.test(r.operator)&&r.left===e&&t.print(" ")}),m([Pe,$e,ot],a),m([Jt,We,Rt,sn,Hn,Ke,wt,Ue,Nt,Et,st,Ut,en,qe,ln,yt,Ct,dt,mt,Mt],function(e){e.add_mapping(this.start)}),m([on,rn],function(e){e.add_mapping(this.start,this.key.name)}),m([tn],function(e){e.add_mapping(this.start,this.key)})}();const ji=1,Zi=2;let nr=null;class Bn{constructor(e,t,n){this.name=t.name,this.orig=[t],this.init=n,this.eliminated=0,this.assignments=0,this.scope=e,this.references=[],this.replaced=0,this.global=!1,this.export=0,this.mangled_name=null,this.undeclared=!1,this.id=Bn.next_id++,this.chained=!1,this.direct_access=!1,this.escaped=0,this.recursive_refs=0,this.references=[],this.should_replace=void 0,this.single_use=!1,this.fixed=!1,Object.seal(this)}unmangleable(e){return e||(e={}),!!(nr&&nr.has(this.id)&&g(e.keep_fnames,this.orig[0].name))||(this.global&&!e.toplevel||this.export&ji||this.undeclared||!e.eval&&this.scope.pinned()||(this.orig[0]instanceof Sn||this.orig[0]instanceof Dn)&&g(e.keep_fnames,this.orig[0].name)||this.orig[0]instanceof gn||(this.orig[0]instanceof bn||this.orig[0]instanceof Tn)&&g(e.keep_classnames,this.orig[0].name))}mangle(e){const t=e.cache&&e.cache.props;if(this.global&&t&&t.has(this.name))this.mangled_name=t.get(this.name);else if(!this.mangled_name&&!this.unmangleable(e)){var n=this.scope,i=this.orig[0];e.ie8&&i instanceof Sn&&(n=n.parent_scope);const r=Kn(this);this.mangled_name=r?r.mangled_name||r.name:n.next_mangled(e,this),this.global&&t&&t.set(this.name,this.mangled_name)}}}function Kn(e){if(e.orig[0]instanceof yn&&e.scope.is_block_scope())return e.scope.get_defun_scope().variables.get(e.name)}function Un(e,t){var n=e.enclosed;e:for(;;){var i=ar(++e.cname);if(!se.has(i)&&!t.reserved.has(i)){for(var r=n.length;--r>=0;){var o=n[r];if(i==(o.mangled_name||o.unmangleable(t)&&o.name))continue e}return i}}}Bn.next_id=1,ot.DEFMETHOD("figure_out_scope",function(e){e=o(e,{cache:null,ie8:!1,safari10:!1});var t=this,n=t.parent_scope=null,i=new Map,r=null,a=null,s=[],u=new An(function(t,o){if(t.is_block_scope()){const i=n;t.block_scope=n=new rt(t);const r=t instanceof Rt?i.parent_scope:i;if(n.init_scope_vars(r),n.uses_with=i.uses_with,n.uses_eval=i.uses_eval,e.safari10&&(t instanceof et||t instanceof tt)&&s.push(n),t instanceof yt){const e=n;n=i,t.expression.walk(u),n=e;for(let e=0;ee===t||(t instanceof dn?e instanceof Sn:!(e instanceof En||e instanceof mn)))||Q(`"${t.name}" is redeclared`,t.start.file,t.start.line,t.start.col,t.start.pos),t instanceof hn||h(m,2),r!==n){t.mark_enclosed(e);var m=n.find_variable(t);t.thedef!==m&&(t.thedef=m,t.reference(e))}}else if(t instanceof Vn){var E=i.get(t.name);if(!E)throw new Error(_("Undefined label {name} [{line},{col}]",{name:t.name,line:t.start.line,col:t.start.col}));t.thedef=E}n instanceof ot||!(t instanceof Pt||t instanceof Vt)||Q(`"${t.TYPE}" statement may only appear at the top level`,t.start.file,t.start.line,t.start.col,t.start.pos)}function h(e,t){if(a){var n=0;do{t++}while(u.parent(n++)!==a)}var i=u.parent(t);if(e.export=i instanceof Pt?ji:0){var r=i.exported_definition;(r instanceof ft||r instanceof un)&&i.is_default&&(e.export=Zi)}}});t.walk(u),t.globals=new Map;u=new An(function(n,i){if(n instanceof St&&n.label)return n.label.thedef.references.push(n),!0;if(n instanceof wn){var r,o=n.name;if("eval"==o&&u.parent()instanceof Kt)for(var a=n.scope;a&&!a.uses_eval;a=a.parent_scope)a.uses_eval=!0;return u.parent()instanceof Lt&&u.parent(1).module_name||!(r=n.scope.find_variable(o))?(r=t.def_global(n),n instanceof xn&&(r.export=ji)):r.scope instanceof st&&"arguments"==o&&(r.scope.uses_arguments=!0),n.thedef=r,n.reference(e),!n.scope.is_block_scope()||r.orig[0]instanceof dn||(n.scope=n.scope.get_defun_scope()),!0}var s;if(n instanceof yn&&(s=Kn(n.definition())))for(a=n.scope;a&&(p(a.enclosed,s),a!==s.scope);)a=a.parent_scope});if(t.walk(u),(e.ie8||e.safari10)&&t.walk(new An(function(n,i){if(n instanceof yn){var r=n.name,o=n.thedef.references,a=n.scope.get_defun_scope(),s=a.find_variable(r)||t.globals.get(r)||a.def_variable(n);return o.forEach(function(t){t.thedef=s,t.reference(e)}),n.thedef=s,n.reference(e),!0}})),e.safari10)for(const e of s)e.parent_scope.variables.forEach(function(t){p(e.enclosed,t)})}),ot.DEFMETHOD("def_global",function(e){var t=this.globals,n=e.name;if(t.has(n))return t.get(n);var i=new Bn(this,e);return i.undeclared=!0,i.global=!0,t.set(n,i),i}),rt.DEFMETHOD("init_scope_vars",function(e){this.variables=new Map,this.functions=new Map,this.uses_with=!1,this.uses_eval=!1,this.parent_scope=e,this.enclosed=[],this.cname=-1,this._var_name_cache=null}),rt.DEFMETHOD("var_names",function e(){var t=this._var_name_cache;return t||(this._var_name_cache=t=new Set(this.parent_scope?e.call(this.parent_scope):null),this._added_var_names&&this._added_var_names.forEach(e=>{t.add(e)}),this.enclosed.forEach(function(e){t.add(e.name)}),this.variables.forEach(function(e,n){t.add(n)})),t}),rt.DEFMETHOD("add_var_name",function(e){this._added_var_names||(this._added_var_names=new Set),this._added_var_names.add(e),this._var_name_cache||this.var_names(),this._var_name_cache.add(e)}),rt.DEFMETHOD("add_child_scope",function(e){if(e.parent_scope===this)return;e.parent_scope=this,e._var_name_cache=null,e._added_var_names&&e._added_var_names.forEach(t=>e.add_var_name(t));const t=new Set(e.enclosed),n=(()=>{const e=[];let t=this;do{e.push(t)}while(t=t.parent_scope);return e.reverse(),e})(),i=[];for(const e of n){i.forEach(t=>p(e.enclosed,t));for(const n of e.variables.values())t.has(n)&&(p(i,n),p(e.enclosed,n))}}),Pe.DEFMETHOD("is_block_scope",s),sn.DEFMETHOD("is_block_scope",s),st.DEFMETHOD("is_block_scope",s),ot.DEFMETHOD("is_block_scope",s),Ct.DEFMETHOD("is_block_scope",s),ze.DEFMETHOD("is_block_scope",u),je.DEFMETHOD("is_block_scope",u),st.DEFMETHOD("init_scope_vars",function(){rt.prototype.init_scope_vars.apply(this,arguments),this.uses_arguments=!1,this.def_variable(new hn({name:"arguments",start:this.start,end:this.end}))}),lt.DEFMETHOD("init_scope_vars",function(){rt.prototype.init_scope_vars.apply(this,arguments),this.uses_arguments=!1}),ln.DEFMETHOD("mark_enclosed",function(e){for(var t=this.definition(),n=this.scope;n&&(p(n.enclosed,t),e.keep_fnames&&n.functions.forEach(function(n){g(e.keep_fnames,n.name)&&p(t.scope.enclosed,n)}),n!==t.scope);)n=n.parent_scope}),ln.DEFMETHOD("reference",function(e){this.definition().references.push(this),this.mark_enclosed(e)}),rt.DEFMETHOD("find_variable",function(e){return e instanceof ln&&(e=e.name),this.variables.get(e)||this.parent_scope&&this.parent_scope.find_variable(e)}),rt.DEFMETHOD("def_function",function(e,t){var n=this.def_variable(e,t);return(!n.init||n.init instanceof ft)&&(n.init=t),this.functions.set(e.name,n),n}),rt.DEFMETHOD("def_variable",function(e,t){var n=this.variables.get(e.name);return n?(n.orig.push(e),n.init&&(n.scope!==e.scope||n.init instanceof ct)&&(n.init=t)):(n=new Bn(this,e,t),this.variables.set(e.name,n),n.global=!this.parent_scope),e.thedef=n}),rt.DEFMETHOD("next_mangled",function(e){return Un(this,e)}),ot.DEFMETHOD("next_mangled",function(e){let t;const n=this.mangled_names;do{t=Un(this,e)}while(n.has(t));return t}),ct.DEFMETHOD("next_mangled",function(e,t){for(var n=t.orig[0]instanceof hn&&this.name&&this.name.definition(),i=n?n.mangled_name||n.name:null;;){var r=Un(this,e);if(!i||i!=r)return r}}),ln.DEFMETHOD("unmangleable",function(e){var t=this.definition();return!t||t.unmangleable(e)}),Nn.DEFMETHOD("unmangleable",s),ln.DEFMETHOD("unreferenced",function(){return!this.definition().references.length&&!this.scope.pinned()}),ln.DEFMETHOD("definition",function(){return this.thedef}),ln.DEFMETHOD("global",function(){return this.definition().global}),ot.DEFMETHOD("_default_mangler_options",function(e){return(e=o(e,{eval:!1,ie8:!1,keep_classnames:!1,keep_fnames:!1,module:!1,reserved:[],toplevel:!1})).module&&(e.toplevel=!0),Array.isArray(e.reserved)||e.reserved instanceof Set||(e.reserved=[]),e.reserved=new Set(e.reserved),e.reserved.add("arguments"),e}),ot.DEFMETHOD("mangle_names",function(e){e=this._default_mangler_options(e);var t=-1,n=[];e.keep_fnames&&(nr=new Set);const i=this.mangled_names=new Set;e.cache&&(this.globals.forEach(o),e.cache.props&&e.cache.props.forEach(function(e){i.add(e)}));var r=new An(function(i,r){if(i instanceof $e){var a=t;return r(),t=a,!0}if(i instanceof rt)i.variables.forEach(o);else if(i.is_block_scope())i.block_scope.variables.forEach(o);else if(nr&&i instanceof Bt&&i.value instanceof st&&!i.value.name&&g(e.keep_fnames,i.name.name))nr.add(i.name.definition().id);else{if(i instanceof Nn){let e;do{e=ar(++t)}while(se.has(e));return i.mangled_name=e,!0}!e.ie8&&!e.safari10&&i instanceof yn&&n.push(i.definition())}});function o(t){!(e.reserved.has(t.name)||t.export&ji)&&n.push(t)}this.walk(r),n.forEach(t=>{t.mangle(e)}),nr=null}),ot.DEFMETHOD("find_colliding_names",function(e){const t=e.cache&&e.cache.props,n=new Set;return e.reserved.forEach(i),this.globals.forEach(r),this.walk(new An(function(e){e instanceof rt&&e.variables.forEach(r),e instanceof yn&&r(e.definition())})),n;function i(e){n.add(e)}function r(n){var r=n.name;if(n.global&&t&&t.has(r))r=t.get(r);else if(!n.unmangleable(e))return;i(r)}}),ot.DEFMETHOD("expand_names",function(e){ar.reset(),ar.sort(),e=this._default_mangler_options(e);var t=this.find_colliding_names(e),n=0;function i(i){if(i.global&&e.cache)return;if(i.unmangleable(e))return;if(e.reserved.has(i.name))return;const r=Kn(i),o=i.name=r?r.name:function(){var e;do{e=ar(n++)}while(t.has(e)||se.has(e));return e}();i.orig.forEach(function(e){e.name=o}),i.references.forEach(function(e){e.name=o})}this.globals.forEach(i),this.walk(new An(function(e){e instanceof rt&&e.variables.forEach(i),e instanceof yn&&i(e.definition())}))}),Pe.DEFMETHOD("tail_node",c),Gt.DEFMETHOD("tail_node",function(){return this.expressions[this.expressions.length-1]}),ot.DEFMETHOD("compute_char_frequency",function(e){e=this._default_mangler_options(e);try{Pe.prototype.print=function(t,n){this._print(t,n),this instanceof ln&&!this.unmangleable(e)?ar.consider(this.name,-1):e.properties&&(this instanceof Xt?ar.consider(this.property,-1):this instanceof zt&&function e(t){t instanceof Xn?ar.consider(t.value,-1):t instanceof jt?(e(t.consequent),e(t.alternative)):t instanceof Gt&&e(t.tail_node())}(this.property))},ar.consider(this.print_to_string(),1)}finally{Pe.prototype.print=Pe.prototype._print}ar.sort()});const ar=(()=>{const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_".split(""),t="0123456789".split("");let n,i;function r(){i=new Map,e.forEach(function(e){i.set(e,0)}),t.forEach(function(e){i.set(e,0)})}function o(e,t){return i.get(t)-i.get(e)}function a(e){var t="",i=54;e++;do{t+=n[--e%i],e=Math.floor(e/i),i=64}while(e>0);return t}return a.consider=function(e,t){for(var n=e.length;--n>=0;)i.set(e[n],i.get(e[n])+t)},a.sort=function(){n=m(e,o).concat(m(t,o))},a.reset=r,r(),a})(),sr=1,_r=8,dr=16,mr=32,Er=256,hr=512,Dr=1024,gr=Er|hr|Dr,Ar=(e,t)=>e.flags&t,Sr=(e,t)=>{e.flags|=t},vr=(e,t)=>{e.flags&=~t};class ei extends An{constructor(e,t){super(),void 0===e.defaults||e.defaults||(t=!0),this.options=o(e,{arguments:!1,arrows:!t,booleans:!t,booleans_as_integers:!1,collapse_vars:!t,comparisons:!t,computed_props:!t,conditionals:!t,dead_code:!t,defaults:!0,directives:!t,drop_console:!1,drop_debugger:!t,ecma:5,evaluate:!t,expression:!1,global_defs:!1,hoist_funs:!1,hoist_props:!t,hoist_vars:!1,ie8:!1,if_return:!t,inline:!t,join_vars:!t,keep_classnames:!1,keep_fargs:!0,keep_fnames:!1,keep_infinity:!1,loops:!t,module:!1,negate_iife:!t,passes:1,properties:!t,pure_getters:!t&&"strict",pure_funcs:null,reduce_funcs:null,reduce_vars:!t,sequences:!t,side_effects:!t,switches:!t,top_retain:null,toplevel:!(!e||!e.top_retain),typeofs:!t,unsafe:!1,unsafe_arrows:!1,unsafe_comps:!1,unsafe_Function:!1,unsafe_math:!1,unsafe_methods:!1,unsafe_proto:!1,unsafe_regexp:!1,unsafe_undefined:!1,unused:!t,warnings:!1},!0);var n=this.options.global_defs;if("object"==typeof n)for(var i in n)"@"===i[0]&&D(n,i)&&(n[i.slice(1)]=ue(n[i],{expression:!0}));!0===this.options.inline&&(this.options.inline=3);var r=this.options.pure_funcs;this.pure_funcs="function"==typeof r?r:r?function(e){return!r.includes(e.expression.print_to_string())}:u;var a=this.options.top_retain;a instanceof RegExp?this.top_retain=function(e){return a.test(e.name)}:"function"==typeof a?this.top_retain=a:a&&("string"==typeof a&&(a=a.split(/,/)),this.top_retain=function(e){return a.includes(e.name)}),this.options.module&&(this.directives["use strict"]=!0,this.options.toplevel=!0);var s=this.options.toplevel;this.toplevel="string"==typeof s?{funcs:/funcs/.test(s),vars:/vars/.test(s)}:{funcs:s,vars:s};var c=this.options.sequences;this.sequences_limit=1==c?800:0|c,this.warnings_produced={},this.evaluated_regexps=new Map}option(e){return this.options[e]}exposed(e){if(e.export)return!0;if(e.global)for(var t=0,n=e.orig.length;t0||this.option("reduce_vars"))&&e.reset_opt_flags(this),e=e.transform(this),t>1){var a=0;if(e.walk(new An(function(){a++})),this.info("pass "+o+": last_count: "+n+", count: "+a),a=0;){if(!(r[o]instanceof nn))return;n||r[o].key!==t||(n=r[o].value)}}return n instanceof wn&&n.fixed_value()||n}}function ii(e,t,n,i,r,o){var a=t.parent(r),s=Ri(n,a);if(s)return s;if(!o&&a instanceof Kt&&a.expression===n&&!(i instanceof lt)&&!(i instanceof sn)&&!a.is_expr_pure(e)&&(!(i instanceof ct)||!(a instanceof Ut)&&i.contains_this()))return!0;if(a instanceof Jt)return ii(e,t,a,a,r+1);if(a instanceof nn&&n===a.value){var u=t.parent(r+1);return ii(e,t,u,u,r+2)}if(a instanceof Ht&&a.expression===n){var c=ni(i,a.property);return!o&&ii(e,t,a,c,r+1)}}function ri(e){return e instanceof lt||e instanceof ct}function oi(e){if(e instanceof Pn)return!0;if(e instanceof wn)return e.definition().orig[0]instanceof Sn;if(e instanceof Ht){if((e=e.expression)instanceof wn){if(e.is_immutable())return!1;e=e.fixed_value()}return!e||!(e instanceof Yn)&&(e instanceof Hn||oi(e))}return!1}function ai(e,t){if(!(e instanceof wn))return!1;for(var n=e.definition().orig,i=n.length;--i>=0;)if(n[i]instanceof t)return!0}function si(e,t){for(let n=0;;n++){const i=e.parent(n);if(i instanceof ot)return t?i:void 0;if(i instanceof st)return i;if(i.block_scope)return i.block_scope}}function ui(e,t){for(var n,i=0;(n=e.parent(i++))&&!(n instanceof rt);)if(n instanceof Rt&&n.argname){n=n.argname.definition().scope;break}return n.find_variable(t)}function ci(e,t,n){return n||(n={}),t&&(n.start||(n.start=t.start),n.end||(n.end=t.end)),new e(n)}function li(e,t){if(1==t.length)return t[0];if(0==t.length)throw new Error("trying to create a sequence with length zero!");return ci(Gt,e,{expressions:t.reduce(_i,[])})}function fi(e,t){switch(typeof e){case"string":return ci(Xn,t,{value:e});case"number":return isNaN(e)?ci(jn,t):isFinite(e)?1/e<0?ci(Yt,t,{operator:"-",expression:ci(zn,t,{value:-e})}):ci(zn,t,{value:e}):e<0?ci(Yt,t,{operator:"-",expression:ci(Jn,t)}):ci(Jn,t);case"boolean":return ci(e?vi:Si,t);case"undefined":return ci(Zn,t);default:if(null===e)return ci($n,t,{value:null});if(e instanceof RegExp)return ci(Yn,t,{value:{source:A(e.source),flags:e.flags}});throw new Error(_("Can't handle constant of type: {type}",{type:typeof e}))}}function pi(e,t,n){return e instanceof Yt&&"delete"==e.operator||e instanceof Kt&&e.expression===t&&(n instanceof Ht||n instanceof wn&&"eval"==n.name)?li(t,[ci(zn,t,{value:0}),n]):n}function _i(e,t){return t instanceof Gt?e.push(...t.expressions):e.push(t),e}function di(e){if(null===e)return[];if(e instanceof We)return e.body;if(e instanceof Ye)return[];if(e instanceof Be)return[e];throw new Error("Can't convert thing to statement array")}function mi(e){return null===e||(e instanceof Ye||e instanceof We&&0==e.body.length)}function Ei(e){return!(e instanceof un||e instanceof ft||e instanceof kt||e instanceof It||e instanceof Pt||e instanceof Vt)}function hi(e){return e instanceof je&&e.body instanceof We?e.body:e}function Di(e){return"Call"==e.TYPE&&(e.expression instanceof ct||Di(e.expression))}function gi(e){return e instanceof wn&&e.definition().undeclared}ti(Pe,function(e,t){return e}),ot.DEFMETHOD("drop_console",function(){return this.transform(new vn(function(e){if("Call"==e.TYPE){var t=e.expression;if(t instanceof Ht){for(var n=t.expression;n.expression;)n=n.expression;if(gi(n)&&"console"==n.name)return ci(Zn,e)}}}))}),Pe.DEFMETHOD("equivalent_to",function(e){return this.TYPE==e.TYPE&&this.print_to_string()==e.print_to_string()}),rt.DEFMETHOD("process_expression",function(e,t){var n=this,i=new vn(function(r){if(e&&r instanceof Ge)return ci(gt,r,{value:r.body});if(!e&&r instanceof gt){if(t){var o=r.value&&r.value.drop_side_effect_free(t,!0);return o?ci(Ge,r,{body:o}):ci(Ye,r)}return ci(Ge,r,{body:r.value||ci(Yt,r,{operator:"void",expression:ci(zn,r,{value:0})})})}if(r instanceof sn||r instanceof st&&r!==n)return r;if(r instanceof ze){var a=r.body.length-1;a>=0&&(r.body[a]=r.body[a].transform(i))}else r instanceof bt?(r.body=r.body.transform(i),r.alternative&&(r.alternative=r.alternative.transform(i))):r instanceof it&&(r.body=r.body.transform(i));return r});n.transform(i)}),function(e){function t(e,t){t.assignments=0,t.chained=!1,t.direct_access=!1,t.escaped=0,t.recursive_refs=0,t.references=[],t.should_replace=void 0,t.single_use=void 0,t.scope.pinned()?t.fixed=!1:t.orig[0]instanceof mn||!e.exposed(t)?t.fixed=t.init:t.fixed=!1}function n(e,n,i){i.variables.forEach(function(i){t(n,i),null===i.fixed?(e.defs_to_safe_ids.set(i,e.safe_ids),s(e,i,!0)):i.fixed&&(e.loop_ids.set(i.id,e.in_loop),s(e,i,!0))})}function i(e,n){n.block_scope&&n.block_scope.variables.forEach(function(n){t(e,n)})}function r(e){e.safe_ids=Object.create(e.safe_ids)}function o(e){e.safe_ids=Object.getPrototypeOf(e.safe_ids)}function s(e,t,n){e.safe_ids[t.id]=n}function u(e,t){if("m"==t.single_use)return!1;if(e.safe_ids[t.id]){if(null==t.fixed){var n=t.orig[0];if(n instanceof hn||"arguments"==n.name)return!1;t.fixed=ci(Zn,n)}return!0}return t.fixed instanceof ft}function c(e,t,n,i){if(void 0===t.fixed)return!0;let r;return null===t.fixed&&(r=e.defs_to_safe_ids.get(t))?(r[t.id]=!1,e.defs_to_safe_ids.delete(t),!0):!!D(e.safe_ids,t.id)&&(!!u(e,t)&&(!1!==t.fixed&&(!(null!=t.fixed&&(!i||t.references.length>t.assignments))&&(t.fixed instanceof ft?i instanceof Pe&&t.fixed.parent_scope===n:t.orig.every(e=>!(e instanceof mn||e instanceof Dn||e instanceof Sn))))))}function l(e,t,n,i,r,o,a){var s=e.parent(o);if(r){if(r.is_constant())return;if(r instanceof cn)return}if(s instanceof Zt&&"="==s.operator&&i===s.right||s instanceof Kt&&(i!==s.expression||s instanceof Ut)||s instanceof ht&&i===s.value&&i.scope!==t.scope||s instanceof Bt&&i===s.value||s instanceof Mi&&i===s.value&&i.scope!==t.scope)return!(a>1)||r&&r.is_constant_expression(n)||(a=1),void((!t.escaped||t.escaped>a)&&(t.escaped=a));if(s instanceof Jt||s instanceof Fi||s instanceof $t&&Cr.has(s.operator)||s instanceof jt&&i!==s.condition||s instanceof at||s instanceof Gt&&i===s.tail_node())l(e,t,n,s,s,o+1,a);else if(s instanceof nn&&i===s.value){var u=e.parent(o+1);l(e,t,n,u,u,o+2,a)}else if(s instanceof Ht&&i===s.expression&&(l(e,t,n,s,r=ni(r,s.property),o+1,a+1),r))return;o>0||s instanceof Gt&&i!==s.tail_node()||s instanceof Ge||(t.direct_access=!0)}e(Pe,a);var f=new An(function(e){if(e instanceof ln){var t=e.definition();t&&(e instanceof wn&&t.references.push(e),t.fixed=!1)}});function p(e,t,i){vr(this,dr);const r=e.safe_ids;return e.safe_ids=Object.create(null),n(e,i,this),t(),e.safe_ids=r,!0}function _(e,t,i){var a,u=this;return vr(this,dr),r(e),n(e,i,u),u.uses_arguments?(t(),void o(e)):(!u.name&&(a=e.parent())instanceof Kt&&a.expression===u&&!a.args.some(e=>e instanceof at)&&u.argnames.every(e=>e instanceof ln)&&u.argnames.forEach(function(t,n){if(t.definition){var i=t.definition();i.orig.length>1||(void 0!==i.fixed||u.uses_arguments&&!e.has_directive("use strict")?i.fixed=!1:(i.fixed=function(){return a.args[n]||ci(Zn,a)},e.loop_ids.set(i.id,e.in_loop),s(e,i,!0)))}}),t(),o(e),!0)}e(ut,function(e,t,i){return r(e),n(e,i,this),t(),o(e),!0}),e(Zt,function(e,t,n){var i=this;if(i.left instanceof pt)i.left.walk(f);else{var r=i.left;if(r instanceof wn){var o=r.definition(),a=c(e,o,r.scope,i.right);if(o.assignments++,a){var u=o.fixed;if(u||"="==i.operator){var p="="==i.operator,_=p?i.right:i;if(!ii(n,e,i,_,0))return o.references.push(r),p||(o.chained=!0),o.fixed=p?function(){return i.right}:function(){return ci($t,i,{operator:i.operator.slice(0,-1),left:u instanceof Pe?u:u(),right:i.right})},s(e,o,!1),i.right.walk(e),s(e,o,!0),l(e,o,r.scope,i,_,0,1),!0}}}}}),e($t,function(e){if(Cr.has(this.operator))return this.left.walk(e),r(e),this.right.walk(e),o(e),!0}),e(ze,function(e,t,n){i(n,this)}),e(Ft,function(e){return r(e),this.expression.walk(e),o(e),r(e),Ee(this,e),o(e),!0}),e(cn,function(e,t){return vr(this,dr),r(e),t(),o(e),!0}),e(jt,function(e){return this.condition.walk(e),r(e),this.consequent.walk(e),o(e),r(e),this.alternative.walk(e),o(e),!0}),e(Ot,function(e,t){return r(e),t(),o(e),!0}),e(un,p),e(ft,p),e(Qe,function(e,t,n){i(n,this);const a=e.in_loop;return e.in_loop=this,r(e),this.body.walk(e),Xi(this)&&(o(e),r(e)),this.condition.walk(e),o(e),e.in_loop=a,!0}),e(et,function(e,t,n){i(n,this),this.init&&this.init.walk(e);const a=e.in_loop;return e.in_loop=this,r(e),this.condition&&this.condition.walk(e),this.body.walk(e),this.step&&(Xi(this)&&(o(e),r(e)),this.step.walk(e)),o(e),e.in_loop=a,!0}),e(tt,function(e,t,n){i(n,this),this.init.walk(f),this.object.walk(e);const a=e.in_loop;return e.in_loop=this,r(e),this.body.walk(e),o(e),e.in_loop=a,!0}),e(ct,_),e(lt,_),e(bt,function(e){return this.condition.walk(e),r(e),this.body.walk(e),o(e),this.alternative&&(r(e),this.alternative.walk(e),o(e)),!0}),e($e,function(e){return r(e),this.body.walk(e),o(e),!0}),e(yn,function(){this.definition().fixed=!1}),e(wn,function(e,t,n){var i,r,o=this.definition();o.references.push(this),1==o.references.length&&!o.fixed&&o.orig[0]instanceof Dn&&e.loop_ids.set(o.id,e.in_loop),void 0!==o.fixed&&u(e,o)?o.fixed&&((i=this.fixed_value())instanceof st&&Yi(e,o)?o.recursive_refs++:i&&!n.exposed(o)&&function(e,t,n){return t.option("unused")&&!n.scope.pinned()&&n.references.length-n.recursive_refs==1&&e.loop_ids.get(n.id)===e.in_loop}(e,n,o)?o.single_use=!(i instanceof st&&function(e,t,n){let i=si(e);const r=t.enclosed.filter(e=>!t.variables.has(e.name)).map(e=>e.name);if(!r.length)return!1;for(;i&&!(i instanceof ot)&&i!==n;){if(r.some(e=>i.variables.has(e)))return!0;i=i.parent_scope}return!1}(e,i,o.scope))&&(i instanceof st&&!i.pinned()||i instanceof sn||o.scope===this.scope&&i.is_constant_expression()):o.single_use=!1,ii(n,e,this,i,0,!!(r=i)&&(r.is_constant()||r instanceof st||r instanceof Pn))&&(o.single_use?o.single_use="m":o.fixed=!1)):o.fixed=!1,l(e,o,this.scope,this,i,0,1)}),e(ot,function(e,i,r){this.globals.forEach(function(e){t(r,e)}),n(e,r,this)}),e(Mt,function(e,t,n){return i(n,this),r(e),Ee(this,e),o(e),this.bcatch&&(r(e),this.bcatch.walk(e),o(e)),this.bfinally&&this.bfinally.walk(e),!0}),e(Wt,function(e,t){var n=this;if("++"===n.operator||"--"===n.operator){var i=n.expression;if(i instanceof wn){var r=i.definition(),o=c(e,r,i.scope,!0);if(r.assignments++,o){var a=r.fixed;if(a)return r.references.push(i),r.chained=!0,r.fixed=function(){return ci($t,n,{operator:n.operator.slice(0,-1),left:ci(Yt,n,{operator:"+",expression:a instanceof Pe?a:a()}),right:ci(zn,n,{value:1})})},s(e,r,!0),!0}}}}),e(Bt,function(e,t){var n=this;if(n.name instanceof pt)n.name.walk(f);else{var i=n.name.definition();if(n.value){if(c(e,i,n.name.scope,n.value))return i.fixed=function(){return n.value},e.loop_ids.set(i.id,e.in_loop),s(e,i,!1),t(),s(e,i,!0),!0;i.fixed=!1}}}),e(Je,function(e,t,n){i(n,this);const a=e.in_loop;return e.in_loop=this,r(e),t(),o(e),e.in_loop=a,!0})}(function(e,t){e.DEFMETHOD("reduce_vars",t)}),ot.DEFMETHOD("reset_opt_flags",function(e){const t=this,n=e.option("reduce_vars"),i=new An(function(r,o){if(vr(r,gr),n)return e.top_retain&&r instanceof ft&&i.parent()===t&&Sr(r,Dr),r.reduce_vars(i,o,e)});i.safe_ids=Object.create(null),i.in_loop=null,i.loop_ids=new Map,i.defs_to_safe_ids=new Map,t.walk(i)}),ln.DEFMETHOD("fixed_value",function(){var e=this.definition().fixed;return!e||e instanceof Pe?e:e()}),wn.DEFMETHOD("is_immutable",function(){var e=this.definition().orig;return 1==e.length&&e[0]instanceof Sn});var Tr=E("Array Boolean clearInterval clearTimeout console Date decodeURI decodeURIComponent encodeURI encodeURIComponent Error escape eval EvalError Function isFinite isNaN JSON Math Number parseFloat parseInt RangeError ReferenceError RegExp Object setInterval setTimeout String SyntaxError TypeError unescape URIError");wn.DEFMETHOD("is_declared",function(e){return!this.definition().undeclared||e.option("unsafe")&&Tr.has(this.name)});var br,yr=E("Infinity NaN undefined");function Ti(e){return e instanceof Jn||e instanceof jn||e instanceof Zn}function bi(t,r){var o,a,s=r.find_parent(rt).get_defun_scope();!function(){var e=r.self(),t=0;do{if(e instanceof Rt||e instanceof Nt)t++;else if(e instanceof je)o=!0;else{if(e instanceof rt){s=e;break}e instanceof Mt&&(a=!0)}}while(e=r.parent(t++))}();var f,A=10;do{f=!1,c(t),r.option("dead_code")&&p(t,r),r.option("if_return")&&l(t,r),r.sequences_limit>0&&(m(t,r),h(t,r)),r.option("join_vars")&&g(t),r.option("collapse_vars")&&u(t,r)}while(f&&A-- >0);function u(t,n){if(s.pinned())return t;for(var r,u=[],c=t.length,l=new vn(function(e,t){if(O)return e;if(!C)return e!==_[d]?e:++d<_.length?x(e):(C=!0,(h=function e(t,n,i){var r=l.parent(n);if(r instanceof Zt)return i&&!(r.left instanceof Ht||A.has(r.left.name))?e(r,n+1,i):t;if(r instanceof $t)return!i||Cr.has(r.operator)&&r.left!==t?t:e(r,n+1,i);if(r instanceof Kt)return t;if(r instanceof Ft)return t;if(r instanceof jt)return i&&r.condition===t?e(r,n+1,i):t;if(r instanceof wt)return e(r,n+1,!0);if(r instanceof ht)return i?e(r,n+1,i):t;if(r instanceof bt)return i&&r.condition===t?e(r,n+1,i):t;if(r instanceof je)return t;if(r instanceof Gt)return e(r,n+1,r.tail_node()!==t);if(r instanceof Ge)return e(r,n+1,!0);if(r instanceof yt)return t;if(r instanceof Bt)return t;return null}(e,0))===e&&(O=!0),e);var i,r=l.parent();if(e instanceof Zt&&"="!=e.operator&&g.equivalent_to(e.left)||e instanceof Fi||e instanceof Kt&&g instanceof Ht&&g.equivalent_to(e.expression)||e instanceof Ke||e instanceof pt||e instanceof at&&e.expression instanceof ln&&e.expression.definition().references.length>1||e instanceof je&&!(e instanceof et)||e instanceof St||e instanceof Mt||e instanceof it||e instanceof Mi||e instanceof Pt||r instanceof et&&e!==r.init||!T&&e instanceof wn&&!e.is_declared(n)&&!wr.has(e))return O=!0,e;if(D||S&&T||!(r instanceof $t&&Cr.has(r.operator)&&r.left!==e||r instanceof jt&&r.condition!==e||r instanceof bt&&r.condition!==e)||(D=r),R&&!(e instanceof pn)&&g.equivalent_to(e)){if(D)return O=!0,e;if(Ri(e,r))return E&&M++,e;if(M++,E&&m instanceof Bt)return e;if(f=O=!0,n.info("Collapsing {name} [{file}:{line},{col}]",{name:e.print_to_string(),file:e.start.file,line:e.start.line,col:e.start.col}),m instanceof qt)return ci(Yt,m,m);if(m instanceof Bt){var o=m.name.definition(),u=m.value;return o.references.length-o.replaced!=1||n.exposed(o)?ci(Zt,m,{operator:"=",left:ci(wn,m.name,m.name),right:u}):(o.replaced++,y&&Ti(u)?u.transform(n):pi(r,e,u))}return vr(m,mr),m}return(e instanceof Kt||e instanceof ht&&(v||g instanceof Ht||X(g))||e instanceof Ht&&(v||e.expression.may_throw_on_access(n))||e instanceof wn&&(A.get(e.name)||v&&X(e))||e instanceof Bt&&e.value&&(A.has(e.name.name)||v&&X(e.name))||(i=Ri(e.left,e))&&(i instanceof Ht||A.has(i.name))||b&&(a?e.has_side_effects(n):function e(t,n){if(t instanceof Zt)return e(t.left,!0);if(t instanceof Wt)return e(t.expression,!0);if(t instanceof Bt)return t.value&&e(t.value);if(n){if(t instanceof Xt)return e(t.expression,!0);if(t instanceof zt)return e(t.expression,!0);if(t instanceof wn)return t.definition().scope!==s}return!1}(e)))&&(h=e,e instanceof rt&&(O=!0)),x(e)},function(e){O||(h===e&&(O=!0),D===e&&(D=null))}),p=new vn(function(e){if(O)return e;if(!C){if(e!==_[d])return e;if(++d<_.length)return;return C=!0,e}return e instanceof wn&&e.name==z.name?(--M||(O=!0),Ri(e,p.parent())?e:(z.replaced++,E.replaced--,m.value)):e instanceof Ot||e instanceof rt?e:void 0});--c>=0;){0==c&&n.option("unused")&&I();var _=[];for(L(t[c]);u.length>0;){_=u.pop();var d=0,m=_[_.length-1],E=null,h=null,D=null,g=V(m);if(g&&!oi(g)&&!g.has_side_effects(n)){var A=B(m),S=U(g);g instanceof wn&&A.set(g.name,!1);var v=G(m),T=H(),b=m.may_throw(n),y=m.name instanceof hn,C=y,O=!1,M=0,R=!r||!C;if(!R){for(var N=n.self().argnames.lastIndexOf(m.name)+1;!O&&NM)M=!1;else{O=!1,d=0,C=y;for(w=c;!O&&w!(e instanceof at))){var o=n.has_directive("use strict");o&&!i(o,t.body)&&(o=!1);var a=t.argnames.length;r=e.args.slice(a);for(var s=new Set,c=a;--c>=0;){var l=t.argnames[c],f=e.args[c];const i=l.definition&&l.definition();if(!(i&&i.orig.length>1)&&(r.unshift(ci(Bt,l,{name:l,value:f})),!s.has(l.name)))if(s.add(l.name),l instanceof at){var p=e.args.slice(c);p.every(e=>!k(t,e,o))&&u.unshift([ci(Bt,l,{name:l.expression,value:ci(Jt,e,{elements:p})})])}else f?(f instanceof st&&f.pinned()||k(t,f,o))&&(f=null):f=ci(Zn,l).transform(n),f&&u.unshift([ci(Bt,l,{name:l,value:f})])}}}function L(e){if(_.push(e),e instanceof Zt)e.left.has_side_effects(n)||u.push(_.slice()),L(e.right);else if(e instanceof $t)L(e.left),L(e.right);else if(e instanceof Kt)L(e.expression),e.args.forEach(L);else if(e instanceof Ft)L(e.expression);else if(e instanceof jt)L(e.condition),L(e.consequent),L(e.alternative);else if(!(e instanceof wt)||!n.option("unused")&&e instanceof It)e instanceof Ze?(L(e.condition),e.body instanceof ze||L(e.body)):e instanceof ht?e.value&&L(e.value):e instanceof et?(e.init&&L(e.init),e.condition&&L(e.condition),e.step&&L(e.step),e.body instanceof ze||L(e.body)):e instanceof tt?(L(e.object),e.body instanceof ze||L(e.body)):e instanceof bt?(L(e.condition),e.body instanceof ze||L(e.body),!e.alternative||e.alternative instanceof ze||L(e.alternative)):e instanceof Gt?e.expressions.forEach(L):e instanceof Ge?L(e.body):e instanceof yt?(L(e.expression),e.body.forEach(L)):e instanceof Wt?"++"!=e.operator&&"--"!=e.operator||u.push(_.slice()):e instanceof Bt&&e.value&&(u.push(_.slice()),L(e.value));else{var t=e.definitions.length,i=t-200;for(i<0&&(i=0);i1&&!(e.name instanceof hn)||(r>1?function(e){var t=e.value;if(t instanceof wn&&"arguments"!=t.name){var n=t.definition();if(!n.undeclared)return E=n}}(e):!n.exposed(t))?ci(wn,e.name,e.name):void 0}}function P(e){return e[e instanceof Zt?"right":"value"]}function B(e){var t=new Map;if(e instanceof Wt)return t;var i=new An(function(e,r){for(var o=e;o instanceof Ht;)o=o.expression;(o instanceof wn||o instanceof Pn)&&t.set(o.name,t.get(o.name)||ii(n,i,e,e,0))});return P(e).walk(i),t}function K(e){if(e.name instanceof hn){var i=n.parent(),r=n.self().argnames,o=r.indexOf(e.name);if(o<0)i.args.length=Math.min(i.args.length,r.length-1);else{var a=i.args;a[o]&&(a[o]=ci(zn,a[o],{value:0}))}return!0}var s=!1;return t[c].transform(new vn(function(t,n,i){return s?t:t===e||t.body===e?(s=!0,t instanceof Bt?(t.value=null,t):i?F.skip:null):void 0},function(e){if(e instanceof Gt)switch(e.expressions.length){case 0:return null;case 1:return e.expressions[0]}}))}function U(e){for(;e instanceof Ht;)e=e.expression;return e instanceof wn&&e.definition().scope===s&&!(o&&(A.has(e.name)||m instanceof Wt||m instanceof Zt&&"="!=m.operator))}function G(e){return e instanceof Wt?Or.has(e.operator):P(e).has_side_effects(n)}function H(){if(v)return!1;if(E)return!0;if(g instanceof wn){var e=g.definition();if(e.references.length-e.replaced==(m instanceof Bt?1:2))return!0}return!1}function X(e){if(!e.definition)return!0;var t=e.definition();return!(1==t.orig.length&&t.orig[0]instanceof Dn)&&(t.scope.get_defun_scope()!==s||!t.references.every(e=>{var t=e.scope.get_defun_scope();return"Scope"==t.TYPE&&(t=t.parent_scope),t===s}))}}function c(e){for(var t=[],n=0;n=0;){var i=e[n];if(i instanceof bt&&i.body instanceof gt&&++t>1)return!0}return!1}(e),r=n instanceof st,o=e.length;--o>=0;){var a=e[o],s=g(o),u=e[s];if(r&&!u&&a instanceof gt){if(!a.value){f=!0,e.splice(o,1);continue}if(a.value instanceof Yt&&"void"==a.value.operator){f=!0,e[o]=ci(Ge,a,{body:a.value.expression});continue}}if(a instanceof bt){var c;if(E(c=Ki(a.body))){c.label&&d(c.label.thedef.references,c),f=!0,(a=a.clone()).condition=a.condition.negate(t);var l=D(a.body,c);a.body=ci(We,a,{body:di(a.alternative).concat(h())}),a.alternative=ci(We,a,{body:l}),e[o]=a.transform(t);continue}if(E(c=Ki(a.alternative))){c.label&&d(c.label.thedef.references,c),f=!0,(a=a.clone()).body=ci(We,a.body,{body:di(a.body).concat(h())});l=D(a.alternative,c);a.alternative=ci(We,a.alternative,{body:l}),e[o]=a.transform(t);continue}}if(a instanceof bt&&a.body instanceof gt){var p=a.body.value;if(!p&&!a.alternative&&(r&&!u||u instanceof gt&&!u.value)){f=!0,e[o]=ci(Ge,a.condition,{body:a.condition});continue}if(p&&!a.alternative&&u instanceof gt&&u.value){f=!0,(a=a.clone()).alternative=u,e[o]=a.transform(t),e.splice(s,1);continue}if(p&&!a.alternative&&(!u&&r&&i||u instanceof gt)){f=!0,(a=a.clone()).alternative=u||ci(gt,a,{value:null}),e[o]=a.transform(t),u&&e.splice(s,1);continue}var m=e[S(o)];if(t.option("sequences")&&r&&!a.alternative&&m instanceof bt&&m.body instanceof gt&&g(s)==e.length&&u instanceof Ge){f=!0,(a=a.clone()).alternative=ci(We,u,{body:[u,ci(gt,u,{value:null})]}),e[o]=a.transform(t),e.splice(s,1);continue}}}function E(i){if(!i)return!1;for(var a=o+1,s=e.length;a=0;){var i=e[n];if(!(i instanceof xt&&_(i)))break}return n}}function p(e,t){for(var n,i=t.self(),r=0,o=0,a=e.length;r!e.value)}function m(e,t){if(!(e.length<2)){for(var n=[],i=0,r=0,o=e.length;r=t.sequences_limit&&c();var s=a.body;n.length>0&&(s=s.drop_side_effect_free(t)),s&&_i(n,s)}else a instanceof wt&&_(a)||a instanceof ft?e[i++]=a:(c(),e[i++]=a)}c(),e.length=i,i!=o&&(f=!0)}function c(){if(n.length){var t=li(n[0],n);e[i++]=ci(Ge,t,{body:t}),n=[]}}}function E(e,t){if(!(e instanceof We))return e;for(var n=null,i=0,r=e.body.length;i0){var p=u.length;u.push(ci(bt,a,{condition:a.condition,body:c||ci(Ye,a.body),alternative:l})),u.unshift(r,1),[].splice.apply(e,u),o+=p,r+=p+1,i=null,f=!0;continue}}e[r++]=a,i=a instanceof Ge?a:null}e.length=r}function D(e,t){if(e instanceof wt){var n,i=e.definitions[e.definitions.length-1];if(i.value instanceof en)if(t instanceof Zt?n=[t]:t instanceof Gt&&(n=t.expressions.slice()),n){var o=!1;do{var a=n[0];if(!(a instanceof Zt))break;if("="!=a.operator)break;if(!(a.left instanceof Ht))break;var u=a.left.expression;if(!(u instanceof wn))break;if(i.name.name!=u.name)break;if(!a.right.is_constant_expression(s))break;var c=a.left.property;if(c instanceof Pe&&(c=c.evaluate(r)),c instanceof Pe)break;c=""+c;var l=r.option("ecma")<6&&r.has_directive("use strict")?function(e){return e.key!=c&&e.key&&e.key.name!=c}:function(e){return e.key&&e.key.name!=c};if(!i.value.properties.every(l))break;var f=i.value.properties.filter(function(e){return e.key===c})[0];f?f.value=new Gt({start:f.start,expressions:[f.value.clone(),a.right.clone()],end:f.end}):i.value.properties.push(ci(nn,a,{key:c,value:a.right})),n.shift(),o=!0}while(n.length);return o&&n}}}function g(e){for(var t,n=0,i=-1,r=e.length;n=0;)if(this.properties[n]._dot_throw(e))return!0;return!1}),e(tn,s),e(on,u),e(at,function(e){return this.expression._dot_throw(e)}),e(ct,s),e(lt,s),e(qt,s),e(Yt,function(){return"void"==this.operator}),e($t,function(e){return("&&"==this.operator||"||"==this.operator)&&(this.left._dot_throw(e)||this.right._dot_throw(e))}),e(Zt,function(e){return"="==this.operator&&this.right._dot_throw(e)}),e(jt,function(e){return this.consequent._dot_throw(e)||this.alternative._dot_throw(e)}),e(Xt,function(e){return!!t(e)&&!(this.expression instanceof ct&&"prototype"==this.property)}),e(Gt,function(e){return this.tail_node()._dot_throw(e)}),e(wn,function(e){if(Ar(this,_r))return!0;if(!t(e))return!1;if(gi(this)&&this.is_declared(e))return!1;if(this.is_immutable())return!1;var n=this.fixed_value();return!n||n._dot_throw(e)})}(function(e,t){e.DEFMETHOD("_dot_throw",t)}),function(e){const t=E("! delete"),n=E("in instanceof == != === !== < <= >= >");e(Pe,s),e(Yt,function(){return t.has(this.operator)}),e($t,function(){return n.has(this.operator)||Cr.has(this.operator)&&this.left.is_boolean()&&this.right.is_boolean()}),e(jt,function(){return this.consequent.is_boolean()&&this.alternative.is_boolean()}),e(Zt,function(){return"="==this.operator&&this.right.is_boolean()}),e(Gt,function(){return this.tail_node().is_boolean()}),e(vi,u),e(Si,u)}(function(e,t){e.DEFMETHOD("is_boolean",t)}),function(e){e(Pe,s),e(zn,u);var t=E("+ - ~ ++ --");e(Wt,function(){return t.has(this.operator)});var n=E("- * / % & | ^ << >> >>>");e($t,function(e){return n.has(this.operator)||"+"==this.operator&&this.left.is_number(e)&&this.right.is_number(e)}),e(Zt,function(e){return n.has(this.operator.slice(0,-1))||"="==this.operator&&this.right.is_number(e)}),e(Gt,function(e){return this.tail_node().is_number(e)}),e(jt,function(e){return this.consequent.is_number(e)&&this.alternative.is_number(e)})}(function(e,t){e.DEFMETHOD("is_number",t)}),(br=function(e,t){e.DEFMETHOD("is_string",t)})(Pe,s),br(Xn,u),br(dt,function(){return 1===this.segments.length}),br(Yt,function(){return"typeof"==this.operator}),br($t,function(e){return"+"==this.operator&&(this.left.is_string(e)||this.right.is_string(e))}),br(Zt,function(e){return("="==this.operator||"+="==this.operator)&&this.right.is_string(e)}),br(Gt,function(e){return this.tail_node().is_string(e)}),br(jt,function(e){return this.consequent.is_string(e)&&this.alternative.is_string(e)});var Cr=E("&& ||"),Or=E("delete ++ --");function Ri(e,t){return t instanceof Wt&&Or.has(t.operator)?t.expression:t instanceof Zt&&t.left===e?e:void 0}function Ni(e,t){return e.print_to_string().length>t.print_to_string().length?t:e}function wi(e,t){return Ni(ci(Ge,e,{body:e}),ci(Ge,t,{body:t})).body}function xi(e,t,n){return(Mn(e)?wi:Ni)(t,n)}function ki(e){const t=new Map;for(var n of Object.keys(e))t.set(n,E(e[n]));return t}!function(e){function t(e,t){e.warn("global_defs "+t.print_to_string()+" redefined [{file}:{line},{col}]",t.start)}ot.DEFMETHOD("resolve_defines",function(e){return e.option("global_defs")?(this.figure_out_scope({ie8:e.option("ie8")}),this.transform(new vn(function(n){var i=n._find_defs(e,"");if(i){for(var r,o=0,a=n;(r=this.parent(o++))&&r instanceof Ht&&r.expression===a;)a=r;if(!Ri(a,r))return i;t(e,n)}}))):this}),e(Pe,a),e(Xt,function(e,t){return this.expression._find_defs(e,"."+this.property+t)}),e(pn,function(e){this.global()&&D(e.option("global_defs"),this.name)&&t(e,this)}),e(wn,function(e,t){if(this.global()){var n=e.option("global_defs"),i=this.name+t;return D(n,i)?function e(t,n){if(t instanceof Pe)return ci(t.CTOR,n,t);if(Array.isArray(t))return ci(Jt,n,{elements:t.map(function(t){return e(t,n)})});if(t&&"object"==typeof t){var i=[];for(var r in t)D(t,r)&&i.push(ci(nn,n,{key:r,value:e(t[r],n)}));return ci(en,n,{properties:i})}return fi(t,n)}(n[i],this):void 0}})}(function(e,t){e.DEFMETHOD("_find_defs",t)});var Fr=["constructor","toString","valueOf"],Mr=ki({Array:["indexOf","join","lastIndexOf","slice"].concat(Fr),Boolean:Fr,Function:Fr,Number:["toExponential","toFixed","toPrecision"].concat(Fr),Object:Fr,RegExp:["test"].concat(Fr),String:["charAt","charCodeAt","concat","indexOf","italics","lastIndexOf","match","replace","search","slice","split","substr","substring","toLowerCase","toUpperCase","trim"].concat(Fr)}),Rr=ki({Array:["isArray"],Math:["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan","atan2","pow","max","min"],Number:["isFinite","isNaN"],Object:["create","getOwnPropertyDescriptor","getOwnPropertyNames","getPrototypeOf","isExtensible","isFrozen","isSealed","keys"],String:["fromCharCode"]});!function(e){Pe.DEFMETHOD("evaluate",function(e){if(!e.option("evaluate"))return this;var t=this._eval(e,1);return!t||t instanceof RegExp?t:"function"==typeof t||"object"==typeof t?this:t});var t=E("! ~ - + void");Pe.DEFMETHOD("is_constant",function(){return this instanceof Hn?!(this instanceof Yn):this instanceof Yt&&this.expression instanceof Hn&&t.has(this.operator)}),e(Be,function(){throw new Error(_("Cannot evaluate a statement [{file}:{line},{col}]",this.start))}),e(st,c),e(sn,c),e(Pe,c),e(Hn,function(){return this.getValue()}),e(Yn,function(e){let t=e.evaluated_regexps.get(this);if(void 0===t){try{t=(0,eval)(this.print_to_string())}catch(e){t=null}e.evaluated_regexps.set(this,t)}return t||this}),e(dt,function(){return 1!==this.segments.length?this:this.segments[0].value}),e(ct,function(e){if(e.option("unsafe")){var t=function(){};return t.node=this,t.toString=function(){return this.node.print_to_string()},t}return this}),e(Jt,function(e,t){if(e.option("unsafe")){for(var n=[],i=0,r=this.elements.length;i>":r=n>>o;break;case">>>":r=n>>>o;break;case"==":r=n==o;break;case"===":r=n===o;break;case"!=":r=n!=o;break;case"!==":r=n!==o;break;case"<":r=n":r=n>o;break;case">=":r=n>=o;break;default:return this}return isNaN(r)&&e.find_parent(it)?this:r}),e(jt,function(e,t){var n=this.condition._eval(e,t);if(n===this.condition)return this;var i=n?this.consequent:this.alternative,r=i._eval(e,t);return r===i?this:r}),e(wn,function(e,t){var n,i=this.fixed_value();if(!i)return this;if(D(i,"_eval"))n=i._eval();else{if(this._eval=c,n=i._eval(e,t),delete this._eval,n===i)return this;i._eval=function(){return n}}if(n&&"object"==typeof n){var r=this.definition().escaped;if(r&&t>r)return this}return n});var r={Array:Array,Math:Math,Number:Number,Object:Object,String:String},o=ki({Math:["E","LN10","LN2","LOG2E","LOG10E","PI","SQRT1_2","SQRT2"],Number:["MAX_VALUE","MIN_VALUE","NaN","NEGATIVE_INFINITY","POSITIVE_INFINITY"]});e(Ht,function(e,t){if(e.option("unsafe")){var n=this.property;if(n instanceof Pe&&(n=n._eval(e,t))===this.property)return this;var i,a=this.expression;if(gi(a)){var s,u="hasOwnProperty"===a.name&&"call"===n&&(s=e.parent()&&e.parent().args)&&s&&s[0]&&s[0].evaluate(e);if(null==(u=u instanceof Xt?u.expression:u)||u.thedef&&u.thedef.undeclared)return this.clone();var c=o.get(a.name);if(!c||!c.has(n))return this;i=r[a.name]}else{if(!(i=a._eval(e,t+1))||i===a||!D(i,n))return this;if("function"==typeof i)switch(n){case"name":return i.node.name?i.node.name.name:"";case"length":return i.node.argnames.length;default:return this}}return i[n]}return this}),e(Kt,function(e,t){var n=this.expression;if(e.option("unsafe")&&n instanceof Ht){var i,o=n.property;if(o instanceof Pe&&(o=o._eval(e,t))===n.property)return this;var a=n.expression;if(gi(a)){var s="hasOwnProperty"===a.name&&"call"===o&&this.args[0]&&this.args[0].evaluate(e);if(null==(s=s instanceof Xt?s.expression:s)||s.thedef&&s.thedef.undeclared)return this.clone();var u=Rr.get(a.name);if(!u||!u.has(o))return this;i=r[a.name]}else{if((i=a._eval(e,t+1))===a||!i)return this;var c=Mr.get(i.constructor.name);if(!c||!c.has(o))return this}for(var l=[],f=0,p=this.args.length;f=":return r.operator="<",r;case">":return r.operator="<=",r}switch(o){case"==":return r.operator="!=",r;case"!=":return r.operator="==",r;case"===":return r.operator="!==",r;case"!==":return r.operator="===",r;case"&&":return r.operator="||",r.left=r.left.negate(e,i),r.right=r.right.negate(e),n(this,r,i);case"||":return r.operator="&&",r.left=r.left.negate(e,i),r.right=r.right.negate(e),n(this,r,i)}return t(this)})}(function(e,t){e.DEFMETHOD("negate",function(e,n){return t.call(this,e,n)})});var Nr=E("Boolean decodeURI decodeURIComponent Date encodeURI encodeURIComponent Error escape EvalError isFinite isNaN Number Object parseFloat parseInt RangeError ReferenceError String SyntaxError TypeError unescape URIError");Kt.DEFMETHOD("is_expr_pure",function(e){if(e.option("unsafe")){var t=this.expression,n=this.args&&this.args[0]&&this.args[0].evaluate(e);if(t.expression&&"hasOwnProperty"===t.expression.name&&(null==n||n.thedef&&n.thedef.undeclared))return!1;if(gi(t)&&Nr.has(t.name))return!0;let i;if(t instanceof Xt&&gi(t.expression)&&(i=Rr.get(t.expression.name))&&i.has(t.property))return!0}return!!T(this,Ii)||!e.pure_funcs(this)}),Pe.DEFMETHOD("is_call_pure",s),Xt.DEFMETHOD("is_call_pure",function(e){if(!e.option("unsafe"))return;const t=this.expression;let n;return t instanceof Jt?n=Mr.get("Array"):t.is_boolean()?n=Mr.get("Boolean"):t.is_number(e)?n=Mr.get("Number"):t instanceof Yn?n=Mr.get("RegExp"):t.is_string(e)?n=Mr.get("String"):this.may_throw_on_access(e)||(n=Mr.get("Object")),n&&n.has(this.property)});const wr=new Set(["Number","String","Array","Object","Function","Promise"]);function Ki(e){return e&&e.aborts()}!function(e){function t(e,t){for(var n=e.length;--n>=0;)if(e[n].has_side_effects(t))return!0;return!1}e(Pe,u),e(Ye,s),e(Hn,s),e(Pn,s),e(ze,function(e){return t(this.body,e)}),e(Kt,function(e){return!(this.is_expr_pure(e)||this.expression.is_call_pure(e)&&!this.expression.has_side_effects(e))||t(this.args,e)}),e(yt,function(e){return this.expression.has_side_effects(e)||t(this.body,e)}),e(Ft,function(e){return this.expression.has_side_effects(e)||t(this.body,e)}),e(Mt,function(e){return t(this.body,e)||this.bcatch&&this.bcatch.has_side_effects(e)||this.bfinally&&this.bfinally.has_side_effects(e)}),e(bt,function(e){return this.condition.has_side_effects(e)||this.body&&this.body.has_side_effects(e)||this.alternative&&this.alternative.has_side_effects(e)}),e($e,function(e){return this.body.has_side_effects(e)}),e(Ge,function(e){return this.body.has_side_effects(e)}),e(st,s),e(sn,function(e){return!!this.extends&&this.extends.has_side_effects(e)}),e(un,u),e($t,function(e){return this.left.has_side_effects(e)||this.right.has_side_effects(e)}),e(Zt,u),e(jt,function(e){return this.condition.has_side_effects(e)||this.consequent.has_side_effects(e)||this.alternative.has_side_effects(e)}),e(Wt,function(e){return Or.has(this.operator)||this.expression.has_side_effects(e)}),e(wn,function(e){return!this.is_declared(e)&&!wr.has(this.name)}),e(pn,s),e(en,function(e){return t(this.properties,e)}),e(tn,function(e){return!!(this instanceof nn&&this.key instanceof Pe&&this.key.has_side_effects(e))||this.value.has_side_effects(e)}),e(Jt,function(e){return t(this.elements,e)}),e(Xt,function(e){return this.expression.may_throw_on_access(e)||this.expression.has_side_effects(e)}),e(zt,function(e){return this.expression.may_throw_on_access(e)||this.expression.has_side_effects(e)||this.property.has_side_effects(e)}),e(Gt,function(e){return t(this.expressions,e)}),e(wt,function(e){return t(this.definitions,e)}),e(Bt,function(e){return this.value}),e(mt,s),e(dt,function(e){return t(this.segments,e)})}(function(e,t){e.DEFMETHOD("has_side_effects",t)}),function(e){function t(e,t){for(var n=e.length;--n>=0;)if(e[n].may_throw(t))return!0;return!1}e(Pe,u),e(sn,s),e(Hn,s),e(Ye,s),e(st,s),e(pn,s),e(Pn,s),e(Jt,function(e){return t(this.elements,e)}),e(Zt,function(e){return!!this.right.may_throw(e)||!(!e.has_directive("use strict")&&"="==this.operator&&this.left instanceof wn)&&this.left.may_throw(e)}),e($t,function(e){return this.left.may_throw(e)||this.right.may_throw(e)}),e(ze,function(e){return t(this.body,e)}),e(Kt,function(e){return!!t(this.args,e)||!this.is_expr_pure(e)&&(!!this.expression.may_throw(e)||(!(this.expression instanceof st)||t(this.expression.body,e)))}),e(Ft,function(e){return this.expression.may_throw(e)||t(this.body,e)}),e(jt,function(e){return this.condition.may_throw(e)||this.consequent.may_throw(e)||this.alternative.may_throw(e)}),e(wt,function(e){return t(this.definitions,e)}),e(Xt,function(e){return this.expression.may_throw_on_access(e)||this.expression.may_throw(e)}),e(bt,function(e){return this.condition.may_throw(e)||this.body&&this.body.may_throw(e)||this.alternative&&this.alternative.may_throw(e)}),e($e,function(e){return this.body.may_throw(e)}),e(en,function(e){return t(this.properties,e)}),e(tn,function(e){return this.value.may_throw(e)}),e(gt,function(e){return this.value&&this.value.may_throw(e)}),e(Gt,function(e){return t(this.expressions,e)}),e(Ge,function(e){return this.body.may_throw(e)}),e(zt,function(e){return this.expression.may_throw_on_access(e)||this.expression.may_throw(e)||this.property.may_throw(e)}),e(yt,function(e){return this.expression.may_throw(e)||t(this.body,e)}),e(wn,function(e){return!this.is_declared(e)&&!wr.has(this.name)}),e(Mt,function(e){return this.bcatch?this.bcatch.may_throw(e):t(this.body,e)||this.bfinally&&this.bfinally.may_throw(e)}),e(Wt,function(e){return!("typeof"==this.operator&&this.expression instanceof wn)&&this.expression.may_throw(e)}),e(Bt,function(e){return!!this.value&&this.value.may_throw(e)})}(function(e,t){e.DEFMETHOD("may_throw",t)}),function(e){function t(e){var t=this,n=!0;return t.walk(new An(function(r){if(!n)return!0;if(r instanceof wn){if(Ar(t,dr))return n=!1,!0;var o=r.definition();if(i(o,t.enclosed)&&!t.variables.has(o.name)){if(e){var a=e.find_variable(r);if(o.undeclared?!a:a===o)return n="f",!0}n=!1}return!0}return r instanceof Pn&&t instanceof lt?(n=!1,!0):void 0})),n}e(Pe,s),e(Hn,u),e(sn,function(e){return!(this.extends&&!this.extends.is_constant_expression(e))&&t.call(this,e)}),e(st,t),e(Wt,function(){return this.expression.is_constant_expression()}),e($t,function(){return this.left.is_constant_expression()&&this.right.is_constant_expression()}),e(Jt,function(){return this.elements.every(e=>e.is_constant_expression())}),e(en,function(){return this.properties.every(e=>e.is_constant_expression())}),e(tn,function(){return!(this.key instanceof Pe)&&this.value.is_constant_expression()})}(function(e,t){e.DEFMETHOD("is_constant_expression",t)}),function(e){function t(){for(var e=0;e1)&&(s.name=null),s instanceof st&&!(s instanceof ut))for(var h=!e.option("keep_fargs"),D=s.argnames,A=D.length;--A>=0;){var S=D[A];S instanceof at&&(S=S.expression),S instanceof Qt&&(S=S.left),S instanceof pt||o.has(S.definition().id)?h=!1:(Sr(S,sr),h&&(D.pop(),e[S.unreferenced()?"warn":"info"]("Dropping unused function argument {name} [{file}:{line},{col}]",M(S))))}if((s instanceof ft||s instanceof un)&&s!==t){const t=s.name.definition();if(!(t.global&&!n||o.has(t.id))){if(e[s.name.unreferenced()?"warn":"info"]("Dropping unused function {name} [{file}:{line},{col}]",M(s.name)),t.eliminated++,s instanceof un){const t=s.drop_side_effect_free(e);if(t)return ci(Ge,s,{body:t})}return f?F.skip:ci(Ye,s)}}if(s instanceof wt&&!(_ instanceof tt&&_.init===s)){var v=!(_ instanceof ot||s instanceof xt),T=[],b=[],y=[],C=[];switch(s.definitions.forEach(function(t){t.value&&(t.value=t.value.transform(p));var n=t.name instanceof pt,r=n?new Bn(null,{name:""}):t.name.definition();if(v&&r.global)return y.push(t);if(!i&&!v||n&&(t.name.names.length||t.name.is_array||1!=e.option("pure_getters"))||o.has(r.id)){if(t.value&&a.has(r.id)&&a.get(r.id)!==t&&(t.value=t.value.drop_side_effect_free(e)),t.name instanceof _n){var c=u.get(r.id);if(c.length>1&&(!t.value||r.orig.indexOf(t.name)>r.eliminated)){if(e.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]",M(t.name)),t.value){var l=ci(wn,t.name,t.name);r.references.push(l);var f=ci(Zt,t,{operator:"=",left:l,right:t.value});a.get(r.id)===t&&a.set(r.id,f),C.push(f.transform(p))}return d(c,t),void r.eliminated++}}t.value?(C.length>0&&(y.length>0?(C.push(t.value),t.value=li(t.value,C)):T.push(ci(Ge,s,{body:li(s,C)})),C=[]),y.push(t)):b.push(t)}else if(r.orig[0]instanceof yn){(_=t.value&&t.value.drop_side_effect_free(e))&&C.push(_),t.value=null,b.push(t)}else{var _;(_=t.value&&t.value.drop_side_effect_free(e))?(n||e.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]",M(t.name)),C.push(_)):n||e[t.name.unreferenced()?"warn":"info"]("Dropping unused variable {name} [{file}:{line},{col}]",M(t.name)),r.eliminated++}}),(b.length>0||y.length>0)&&(s.definitions=b.concat(y),T.push(s)),C.length>0&&T.push(ci(Ge,s,{body:li(s,C)})),T.length){case 0:return f?F.skip:ci(Ye,s);case 1:return T[0];default:return f?F.splice(T):ci(We,s,{body:T})}}if(s instanceof et)return c(s,this),s.init instanceof We&&(O=s.init,s.init=O.body.pop(),O.body.push(s)),s.init instanceof Ge?s.init=s.init.body:mi(s.init)&&(s.init=null),O?f?F.splice(O.body):O:s;if(s instanceof $e&&s.body instanceof et){if(c(s,this),s.body instanceof We){var O=s.body;return s.body=O.body.pop(),O.body.push(s),f?F.splice(O.body):O}return s}if(s instanceof We)return c(s,this),f&&s.body.every(Ei)?F.splice(s.body):s;if(s instanceof rt){const e=l;return l=s,c(s,this),l=e,s}}function M(e){return{name:e.name,file:e.start.file,line:e.start.line,col:e.start.col}}});function m(e,n){var i;const s=r(e);if(s instanceof wn&&!ai(e.left,dn)&&t.variables.get(s.name)===(i=s.definition()))return e instanceof Zt&&(e.right.walk(f),i.chained||e.left.fixed_value()!==e.right||a.set(i.id,e)),!0;if(e instanceof wn){if(i=e.definition(),!o.has(i.id)&&(o.set(i.id,i),i.orig[0]instanceof yn)){const e=i.scope.is_block_scope()&&i.scope.get_defun_scope().variables.get(i.name);e&&o.set(e.id,e)}return!0}if(e instanceof rt){var u=l;return l=e,n(),l=u,!0}}t.transform(p)}),rt.DEFMETHOD("hoist_declarations",function(e){var t=this;if(e.has_directive("use asm"))return t;if(!Array.isArray(t.body))return t;var n=e.option("hoist_funs"),i=e.option("hoist_vars");if(n||i){var r=[],o=[],a=new Map,s=0,u=0;t.walk(new An(function(e){return e instanceof rt&&e!==t||(e instanceof xt?(++u,!0):void 0)})),i=i&&u>1;var c=new vn(function(u){if(u!==t){if(u instanceof Ue)return r.push(u),ci(Ye,u);if(n&&u instanceof ft&&!(c.parent()instanceof Pt)&&c.parent()===t)return o.push(u),ci(Ye,u);if(i&&u instanceof xt){u.definitions.forEach(function(e){e.name instanceof pt||(a.set(e.name.name,e),++s)});var l=u.to_assignments(e),f=c.parent();if(f instanceof tt&&f.init===u){if(null==l){var p=u.definitions[0].name;return ci(wn,p,p)}return l}return f instanceof et&&f.init===u?l:l?ci(Ge,u,{body:l}):ci(Ye,u)}if(u instanceof rt)return u}});if(t=t.transform(c),s>0){var l=[];const e=t instanceof st,n=e?t.args_as_names():null;if(a.forEach((t,i)=>{e&&n.some(e=>e.name===t.name.name)?a.delete(i):((t=t.clone()).value=null,l.push(t),a.set(i,t))}),l.length>0){for(var f=0;f"string"==typeof e.key)){a(o,this);const e=new Map,t=[];return c.properties.forEach(function(n){t.push(ci(Bt,o,{name:s(r,n.key,e),value:n.value}))}),i.set(u.id,e),F.splice(t)}}else if(o instanceof Ht&&o.expression instanceof wn){const e=i.get(o.expression.definition().id);if(e){const t=e.get(String(Ci(o.property))),n=ci(wn,o,{name:t.name,scope:o.expression.scope,thedef:t});return n.reference({}),n}}function s(e,n,i){const r=ci(e.CTOR,e,{name:t.make_var_name(e.name+"_"+n),scope:t}),o=t.def_variable(r);return i.set(String(n),o),t.enclosed.push(o),r}});return t.transform(r)}),function(e){function t(e,t,n){var i=e.length;if(!i)return null;for(var r=[],o=!1,a=0;a0&&(u[0].body=s.concat(u[0].body)),e.body=u;n=u[u.length-1];){var _=n.body[n.body.length-1];if(_ instanceof vt&&t.loopcontrol_target(_)===e&&n.body.pop(),n.body.length||n instanceof Ft&&(o||n.expression.has_side_effects(t)))break;u.pop()===o&&(o=null)}if(0==u.length)return ci(We,e,{body:s.concat(ci(Ge,e.expression,{body:e.expression}))}).optimize(t);if(1==u.length&&(u[0]===a||u[0]===o)){var d=!1,m=new An(function(t){if(d||t instanceof st||t instanceof Ge)return!0;t instanceof vt&&m.loopcontrol_target(t)===e&&(d=!0)});if(e.walk(m),!d){var E,h=u[0].body.slice();return(E=u[0].expression)&&h.unshift(ci(Ge,E,{body:E})),h.unshift(ci(Ge,e.expression,{body:e.expression})),ci(We,e,{body:h}).optimize(t)}}return e;function D(e,n){n&&!Ki(n)?n.body=n.body.concat(e.body):yi(t,e,s)}}),ti(Mt,function(e,t){if(bi(e.body,t),e.bcatch&&e.bfinally&&e.bfinally.body.every(mi)&&(e.bfinally=null),t.option("dead_code")&&e.body.every(mi)){var n=[];return e.bcatch&&yi(t,e.bcatch,n),e.bfinally&&n.push(...e.bfinally.body),ci(We,e,{body:n}).optimize(t)}return e}),wt.DEFMETHOD("remove_initializers",function(){var e=[];this.definitions.forEach(function(t){t.name instanceof pn?(t.value=null,e.push(t)):t.name.walk(new An(function(n){n instanceof pn&&e.push(ci(Bt,t,{name:n,value:null}))}))}),this.definitions=e}),wt.DEFMETHOD("to_assignments",function(e){var t=e.option("reduce_vars"),n=this.definitions.reduce(function(e,n){if(!n.value||n.name instanceof pt){if(n.value){var i=ci(Bt,n,{name:n.name,value:n.value}),r=ci(xt,n,{definitions:[i]});e.push(r)}}else{var o=ci(wn,n.name,n.name);e.push(ci(Zt,n,{operator:"=",left:o,right:n.value})),t&&(o.definition().fixed=!1)}return(n=n.name.definition()).eliminated++,n.replaced--,e},[]);return 0==n.length?null:li(this,n)}),ti(wt,function(e,t){return 0==e.definitions.length?ci(Ye,e):e}),ti(Vt,function(e,t){return e}),ti(Kt,function(e,t){var n=e.expression,i=n;er(e,t,e.args);var r=e.args.every(e=>!(e instanceof at));if(t.option("reduce_vars")&&i instanceof wn&&!T(e,Vi)){const e=i.fixed_value();zi(e,t)||(i=e)}var o=i instanceof st;if(t.option("unused")&&r&&o&&!i.uses_arguments&&!i.pinned()){for(var a=0,s=0,u=0,c=e.args.length;u=i.argnames.length;if(l||Ar(i.argnames[u],sr)){if(D=e.args[u].drop_side_effect_free(t))e.args[a++]=D;else if(!l){e.args[a++]=ci(zn,e.args[u],{value:0});continue}}else e.args[a++]=e.args[u];s=a}e.args.length=s}if(t.option("unsafe"))if(gi(n))switch(n.name){case"Array":if(1!=e.args.length)return ci(Jt,e,{elements:e.args}).optimize(t);if(e.args[0]instanceof zn&&e.args[0].value<=11){const t=[];for(let n=0;n=1&&e.args.length<=2&&e.args.every(e=>{var n=e.evaluate(t);return f.push(n),e!==n})){const[n,i]=f,r=ci(Yn,e,{value:{source:n,flags:i}});if(r._eval(t)!==r)return r;t.warn("Error converting {expr} [{file}:{line},{col}]",{expr:e.print_to_string(),file:e.start.file,line:e.start.line,col:e.start.col})}}else if(n instanceof Xt)switch(n.property){case"toString":if(0==e.args.length&&!n.expression.may_throw_on_access(t))return ci($t,e,{left:ci(Xn,e,{value:""}),operator:"+",right:n.expression}).optimize(t);break;case"join":if(n.expression instanceof Jt)e:{var p;if(!(e.args.length>0&&(p=e.args[0].evaluate(t))===e.args[0])){var _,d=[],m=[];for(u=0,c=n.expression.elements.length;u0&&(d.push(ci(Xn,e,{value:m.join(p)})),m.length=0),d.push(E))}return m.length>0&&d.push(ci(Xn,e,{value:m.join(p)})),0==d.length?ci(Xn,e,{value:""}):1==d.length?d[0].is_string(t)?d[0]:ci($t,d[0],{operator:"+",left:ci(Xn,e,{value:""}),right:d[0]}):""==p?(_=d[0].is_string(t)||d[1].is_string(t)?d.shift():ci(Xn,e,{value:""}),d.reduce(function(e,t){return ci($t,t,{operator:"+",left:e,right:t})},_).optimize(t)):((D=e.clone()).expression=D.expression.clone(),D.expression.expression=D.expression.expression.clone(),D.expression.expression.elements=d,xi(t,e,D));var D}}break;case"charAt":if(n.expression.is_string(t)){var g=e.args[0],A=g?g.evaluate(t):0;if(A!==g)return ci(zt,n,{expression:n.expression,property:fi(0|A,g||n)}).optimize(t)}break;case"apply":if(2==e.args.length&&e.args[1]instanceof Jt)return(N=e.args[1].elements.slice()).unshift(e.args[0]),ci(Kt,e,{expression:ci(Xt,n,{expression:n.expression,property:"call"}),args:N}).optimize(t);break;case"call":var S=n.expression;if(S instanceof wn&&(S=S.fixed_value()),S instanceof st&&!S.contains_this())return(e.args.length?li(this,[e.args[0],ci(Kt,e,{expression:n.expression,args:e.args.slice(1)})]):ci(Kt,e,{expression:n.expression,args:[]})).optimize(t)}if(t.option("unsafe_Function")&&gi(n)&&"Function"==n.name){if(0==e.args.length)return ci(ct,e,{argnames:[],body:[]}).optimize(t);if(e.args.every(e=>e instanceof Xn))try{var v=ue(O="n(function("+e.args.slice(0,-1).map(function(e){return e.value}).join(",")+"){"+e.args[e.args.length-1].value+"})"),b={ie8:t.option("ie8")};v.figure_out_scope(b);var y,C=new ei(t.options);(v=v.transform(C)).figure_out_scope(b),ar.reset(),v.compute_char_frequency(b),v.mangle_names(b),v.walk(new An(function(e){return!!y||(ri(e)?(y=e,!0):void 0)})),y.body instanceof Pe&&(y.body=[ci(gt,y.body,{value:y.body})]);var O=In();return We.prototype._codegen.call(y,y,O),e.args=[ci(Xn,e,{value:y.argnames.map(function(e){return e.print_to_string()}).join(",")}),ci(Xn,e.args[e.args.length-1],{value:O.get().replace(/^{|}$/g,"")})],e}catch(n){if(!(n instanceof J))throw n;t.warn("Error parsing code passed to new Function [{file}:{line},{col}]",e.args[e.args.length-1].start),t.warn(n.toString())}}var F=o&&i.body;F instanceof Pe?F=ci(gt,F,{value:F}):F&&(F=F[0]);var M=o&&!i.is_generator&&!i.async,R=M&&t.option("inline")&&!e.is_expr_pure(t);if(R&&F instanceof gt){let n=F.value;if(!n||n.is_constant_expression()){n=n?n.clone(!0):ci(Zn,e);var N=e.args.concat(n);return li(e,N).optimize(t)}if(1===i.argnames.length&&i.argnames[0]instanceof hn&&e.args.length<2&&"name"===n.start.type&&n.name===i.argnames[0].name)return(e.args[0]||ci(Zn)).optimize(t)}if(R){var w,x,k=-1;let o,a;if(r&&!i.uses_arguments&&!i.pinned()&&!(t.parent()instanceof sn)&&!(i.name&&i instanceof ct)&&(!(t.find_parent(st)instanceof lt)||0==i.argnames.length&&(i.body instanceof Pe||1==i.body.length))&&(a=function(e){var n=i.body instanceof Pe?[i.body]:i.body,r=n.length;if(t.option("inline")<3)return 1==r&&L(e);e=null;for(var o=0;o!e.value))return!1}else{if(e)return!1;a instanceof Ye||(e=a)}}return L(e)}(F))&&(n===i||T(e,Li)||t.option("unused")&&1==(o=n.definition()).references.length&&!Yi(t,o)&&i.is_constant_expression(n.scope))&&!T(e,Ii|Vi)&&!i.contains_this()&&function(){var n=new Set;do{if(!(w=t.parent(++k)).is_block_scope()||t.parent(k-1)instanceof rt||w.block_scope&&w.block_scope.variables.forEach(function(e){n.add(e.name)}),w instanceof Rt)w.argname&&n.add(w.argname.name);else if(w instanceof je)x=[];else if(w instanceof wn&&w.fixed_value()instanceof rt)return!1}while(!(w instanceof rt)||w instanceof lt);var r=!(w instanceof ot)||t.toplevel.vars,o=t.option("inline");return!!function(e,t){for(var n=i.body.length,r=0;r=0;){var s=o.definitions[a].name;if(s instanceof pt||e.has(s.name)||yr.has(s.name)||w.var_names().has(s.name))return!1;x&&x.push(s.definition())}}}return!0}(n,o>=3&&r)&&(!!function(e,t){for(var n=0,r=i.argnames.length;n=2&&r)&&(!!function(){var t=new Set,n=new An(function(e){if(e instanceof rt){var n=new Set;return e.enclosed.forEach(function(e){n.add(e.name)}),e.variables.forEach(function(e){n.delete(e)}),n.forEach(function(e){t.add(e)}),!0}return!1});if(e.args.forEach(function(e){e.walk(n)}),0==t.size)return!0;for(var r=0,o=i.argnames.length;r=0;){var c=s.definitions[u].name;if(c instanceof pt||t.has(c.name))return!1}}return!0}()&&(!x||0==x.length||!$i(i,x))))}()&&!(w instanceof sn))return Sr(i,Er),si(t,!0).add_child_scope(i),li(e,function(n){var r=[],o=[];(function(t,n){for(var r=i.argnames.length,o=e.args.length;--o>=r;)n.push(e.args[o]);for(o=r;--o>=0;){var a=i.argnames[o],s=e.args[o];if(Ar(a,sr)||!a.name||w.var_names().has(a.name))s&&n.push(s);else{var u=ci(_n,a,a);a.definition().orig.push(u),!s&&x&&(s=ci(Zn,e)),V(t,n,u,s)}}t.reverse(),n.reverse()})(r,o),function(e,t){for(var n=t.length,r=0,o=i.body.length;re.name!=l.name)){var f=i.variables.get(l.name),p=ci(wn,l,l);f.references.push(p),t.splice(n++,0,ci(Zt,c,{operator:"=",left:p,right:ci(Zn,l)}))}}}}(r,o),o.push(n),r.length&&(u=w.body.indexOf(t.parent(k-1))+1,w.body.splice(u,0,ci(xt,i,{definitions:r})));return o.map(e=>e.clone(!0))}(a)).optimize(t)}if(M&&t.option("side_effects")&&!(i.body instanceof Pe)&&i.body.every(mi)){N=e.args.concat(ci(Zn,e));return li(e,N).optimize(t)}if(t.option("negate_iife")&&t.parent()instanceof Ge&&Di(e))return e.negate(t,!0);var I=e.evaluate(t);return I!==e?(I=fi(I,e).optimize(t),xi(t,I,e)):e;function L(t){return t?t instanceof gt?t.value?t.value.clone(!0):ci(Zn,e):t instanceof Ge?ci(Yt,t,{operator:"void",expression:t.body.clone(!0)}):void 0:ci(Zn,e)}function V(t,n,i,r){var o=i.definition();w.variables.set(i.name,o),w.enclosed.push(o),w.var_names().has(i.name)||(w.add_var_name(i.name),t.push(ci(Bt,i,{name:i,value:null})));var a=ci(wn,i,i);o.references.push(a),r&&n.push(ci(Zt,e,{operator:"=",left:a,right:r.clone()}))}}),ti(Ut,function(e,t){return t.option("unsafe")&&gi(e.expression)&&["Object","RegExp","Function","Error","Array"].includes(e.expression.name)?ci(Kt,e,e).transform(t):e}),ti(Gt,function(e,t){if(!t.option("side_effects"))return e;var n,i,r=[];n=Mn(t),i=e.expressions.length-1,e.expressions.forEach(function(e,o){o0&&Oi(r[o],t);)o--;o0)return(n=this.clone()).right=li(this.right,t.slice(o)),(t=t.slice(0,o)).push(n),li(this,t).optimize(e)}}return this});var Ir=E("== === != !== * & | ^");function Yi(e,t){for(var n,i=0;n=e.parent(i);i++)if(n instanceof st){var r=n.name;if(r&&r.definition()===t)break}return n}function qi(e,t){return e instanceof wn||e.TYPE===t.TYPE}function $i(e,t){var n=!1,r=new An(function(e){return!!n||(e instanceof wn&&i(e.definition(),t)?n=!0:void 0)}),o=new An(function(t){if(n)return!0;if(t instanceof rt&&t!==e){var i=o.parent();if(i instanceof Kt&&i.expression===t)return;return t.walk(r),!0}});return e.walk(o),n}ti($t,function(e,t){function n(){return e.left.is_constant()||e.right.is_constant()||!e.left.has_side_effects(t)&&!e.right.has_side_effects(t)}function i(t){if(n()){t&&(e.operator=t);var i=e.left;e.left=e.right,e.right=i}}if(Ir.has(e.operator)&&e.right.is_constant()&&!e.left.is_constant()&&(e.left instanceof $t&&Ie[e.left.operator]>=Ie[e.operator]||i()),e=e.lift_sequences(t),t.option("comparisons"))switch(e.operator){case"===":case"!==":var r=!0;(e.left.is_string(t)&&e.right.is_string(t)||e.left.is_number(t)&&e.right.is_number(t)||e.left.is_boolean()&&e.right.is_boolean()||e.left.equivalent_to(e.right))&&(e.operator=e.operator.substr(0,2));case"==":case"!=":if(!r&&Oi(e.left,t))e.left=ci($n,e.left);else if(t.option("typeofs")&&e.left instanceof Xn&&"undefined"==e.left.value&&e.right instanceof Yt&&"typeof"==e.right.operator){var o=e.right.expression;(o instanceof wn?!o.is_declared(t):o instanceof Ht&&t.option("ie8"))||(e.right=o,e.left=ci(Zn,e.left).optimize(t),2==e.operator.length&&(e.operator+="="))}else if(e.left instanceof wn&&e.right instanceof wn&&e.left.definition()===e.right.definition()&&((u=e.left.fixed_value())instanceof Jt||u instanceof st||u instanceof en||u instanceof sn))return ci("="==e.operator[0]?vi:Si,e);break;case"&&":case"||":var a=e.left;if(a.operator==e.operator&&(a=a.right),a instanceof $t&&a.operator==("&&"==e.operator?"!==":"===")&&e.right instanceof $t&&a.operator==e.right.operator&&(Oi(a.left,t)&&e.right.left instanceof $n||a.left instanceof $n&&Oi(e.right.left,t))&&!a.right.has_side_effects(t)&&a.right.equivalent_to(e.right.right)){var s=ci($t,e,{operator:a.operator.slice(0,-1),left:ci($n,e),right:a.right});return a!==e.left&&(s=ci($t,e,{operator:e.operator,left:e.left.left,right:s})),s}}var u;if("+"==e.operator&&t.in_boolean_context()){var c=e.left.evaluate(t),l=e.right.evaluate(t);if(c&&"string"==typeof c)return t.warn("+ in boolean context always true [{file}:{line},{col}]",e.start),li(e,[e.right,ci(vi,e)]).optimize(t);if(l&&"string"==typeof l)return t.warn("+ in boolean context always true [{file}:{line},{col}]",e.start),li(e,[e.left,ci(vi,e)]).optimize(t)}if(t.option("comparisons")&&e.is_boolean()){if(!(t.parent()instanceof $t)||t.parent()instanceof Zt){var f=ci(Yt,e,{operator:"!",expression:e.negate(t,Mn(t))});e=xi(t,e,f)}if(t.option("unsafe_comps"))switch(e.operator){case"<":i(">");break;case"<=":i(">=")}}if("+"==e.operator){if(e.right instanceof Xn&&""==e.right.getValue()&&e.left.is_string(t))return e.left;if(e.left instanceof Xn&&""==e.left.getValue()&&e.right.is_string(t))return e.right;if(e.left instanceof $t&&"+"==e.left.operator&&e.left.left instanceof Xn&&""==e.left.left.getValue()&&e.right.is_string(t))return e.left=e.left.right,e.transform(t)}if(t.option("evaluate")){switch(e.operator){case"&&":if(!(c=!!Ar(e.left,2)||!Ar(e.left,4)&&e.left.evaluate(t)))return t.warn("Condition left of && always false [{file}:{line},{col}]",e.start),pi(t.parent(),t.self(),e.left).optimize(t);if(!(c instanceof Pe))return t.warn("Condition left of && always true [{file}:{line},{col}]",e.start),li(e,[e.left,e.right]).optimize(t);if(l=e.right.evaluate(t)){if(!(l instanceof Pe)){if("&&"==(p=t.parent()).operator&&p.left===t.self()||t.in_boolean_context())return t.warn("Dropping side-effect-free && [{file}:{line},{col}]",e.start),e.left.optimize(t)}}else{if(t.in_boolean_context())return t.warn("Boolean && always false [{file}:{line},{col}]",e.start),li(e,[e.left,ci(Si,e)]).optimize(t);Sr(e,4)}if("||"==e.left.operator)if(!(_=e.left.right.evaluate(t)))return ci(jt,e,{condition:e.left.left,consequent:e.right,alternative:e.left.right}).optimize(t);break;case"||":var p,_;if(!(c=!!Ar(e.left,2)||!Ar(e.left,4)&&e.left.evaluate(t)))return t.warn("Condition left of || always false [{file}:{line},{col}]",e.start),li(e,[e.left,e.right]).optimize(t);if(!(c instanceof Pe))return t.warn("Condition left of || always true [{file}:{line},{col}]",e.start),pi(t.parent(),t.self(),e.left).optimize(t);if(l=e.right.evaluate(t)){if(!(l instanceof Pe)){if(t.in_boolean_context())return t.warn("Boolean || always true [{file}:{line},{col}]",e.start),li(e,[e.left,ci(vi,e)]).optimize(t);Sr(e,2)}}else if("||"==(p=t.parent()).operator&&p.left===t.self()||t.in_boolean_context())return t.warn("Dropping side-effect-free || [{file}:{line},{col}]",e.start),e.left.optimize(t);if("&&"==e.left.operator)if((_=e.left.right.evaluate(t))&&!(_ instanceof Pe))return ci(jt,e,{condition:e.left.left,consequent:e.left.right,alternative:e.right}).optimize(t)}var d=!0;switch(e.operator){case"+":if(e.left instanceof Hn&&e.right instanceof $t&&"+"==e.right.operator&&e.right.left instanceof Hn&&e.right.is_string(t)&&(e=ci($t,e,{operator:"+",left:ci(Xn,e.left,{value:""+e.left.getValue()+e.right.left.getValue(),start:e.left.start,end:e.right.left.end}),right:e.right.right})),e.right instanceof Hn&&e.left instanceof $t&&"+"==e.left.operator&&e.left.right instanceof Hn&&e.left.is_string(t)&&(e=ci($t,e,{operator:"+",left:e.left.left,right:ci(Xn,e.right,{value:""+e.left.right.getValue()+e.right.getValue(),start:e.left.right.start,end:e.right.end})})),e.left instanceof $t&&"+"==e.left.operator&&e.left.is_string(t)&&e.left.right instanceof Hn&&e.right instanceof $t&&"+"==e.right.operator&&e.right.left instanceof Hn&&e.right.is_string(t)&&(e=ci($t,e,{operator:"+",left:ci($t,e.left,{operator:"+",left:e.left.left,right:ci(Xn,e.left.right,{value:""+e.left.right.getValue()+e.right.left.getValue(),start:e.left.right.start,end:e.right.left.end})}),right:e.right.right})),e.right instanceof Yt&&"-"==e.right.operator&&e.left.is_number(t)){e=ci($t,e,{operator:"-",left:e.left,right:e.right.expression});break}if(e.left instanceof Yt&&"-"==e.left.operator&&n()&&e.right.is_number(t)){e=ci($t,e,{operator:"-",left:e.right,right:e.left.expression});break}case"*":d=t.option("unsafe_math");case"&":case"|":case"^":if(e.left.is_number(t)&&e.right.is_number(t)&&n()&&!(e.left instanceof $t&&e.left.operator!=e.operator&&Ie[e.left.operator]>=Ie[e.operator])){var m=ci($t,e,{operator:e.operator,left:e.right,right:e.left});e=e.right instanceof Hn&&!(e.left instanceof Hn)?xi(t,m,e):xi(t,e,m)}d&&e.is_number(t)&&(e.right instanceof $t&&e.right.operator==e.operator&&(e=ci($t,e,{operator:e.operator,left:ci($t,e.left,{operator:e.operator,left:e.left,right:e.right.left,start:e.left.start,end:e.right.left.end}),right:e.right.right})),e.right instanceof Hn&&e.left instanceof $t&&e.left.operator==e.operator&&(e.left.left instanceof Hn?e=ci($t,e,{operator:e.operator,left:ci($t,e.left,{operator:e.operator,left:e.left.left,right:e.right,start:e.left.left.start,end:e.right.end}),right:e.left.right}):e.left.right instanceof Hn&&(e=ci($t,e,{operator:e.operator,left:ci($t,e.left,{operator:e.operator,left:e.left.right,right:e.right,start:e.left.right.start,end:e.right.end}),right:e.left.left}))),e.left instanceof $t&&e.left.operator==e.operator&&e.left.right instanceof Hn&&e.right instanceof $t&&e.right.operator==e.operator&&e.right.left instanceof Hn&&(e=ci($t,e,{operator:e.operator,left:ci($t,e.left,{operator:e.operator,left:ci($t,e.left.left,{operator:e.operator,left:e.left.right,right:e.right.left,start:e.left.right.start,end:e.right.left.end}),right:e.left.left}),right:e.right.right})))}}if(e.right instanceof $t&&e.right.operator==e.operator&&(Cr.has(e.operator)||"+"==e.operator&&(e.right.left.is_string(t)||e.left.is_string(t)&&e.right.right.is_string(t))))return e.left=ci($t,e.left,{operator:e.operator,left:e.left,right:e.right.left}),e.right=e.right.right,e.transform(t);var E=e.evaluate(t);return E!==e?(E=fi(E,e).optimize(t),xi(t,E,e)):e}),ti(xn,function(e,t){return e}),ti(wn,function(e,t){if(!t.option("ie8")&&gi(e)&&(!e.scope.uses_with||!t.find_parent(it)))switch(e.name){case"undefined":return ci(Zn,e).optimize(t);case"NaN":return ci(jn,e).optimize(t);case"Infinity":return ci(Jn,e).optimize(t)}var n,i=t.parent();if(t.option("reduce_vars")&&Ri(e,i)!==e){const p=e.definition();if(t.top_retain&&p.global&&t.top_retain(p))return p.fixed=!1,p.should_replace=!1,p.single_use=!1,e;var r=e.fixed_value(),o=p.single_use&&!(i instanceof Kt&&i.is_expr_pure(t));if(o&&(r instanceof st||r instanceof sn))if(zi(r,t))o=!1;else if(p.scope!==e.scope&&(1==p.escaped||Ar(r,dr)||function(e){for(var t,n=0;t=e.parent(n++);){if(t instanceof Be)return!1;if(t instanceof Jt||t instanceof nn||t instanceof en)return!0}return!1}(t)))o=!1;else if(Yi(t,p))o=!1;else if((p.scope!==e.scope||p.orig[0]instanceof hn)&&"f"==(o=r.is_constant_expression(e.scope))){var a=e.scope;do{(a instanceof ft||ri(a))&&Sr(a,dr)}while(a=a.parent_scope)}if(o&&r instanceof st&&(o=p.scope===e.scope||i instanceof Kt&&i.expression===e),o&&r instanceof sn&&r.extends&&(o=!r.extends.may_throw(t)&&(!(r.extends instanceof Kt)||r.extends.is_expr_pure(t))),o&&r){if(r instanceof un&&(r=ci(cn,r,r)),r instanceof ft&&(Sr(r,Er),r=ci(ct,r,r)),p.recursive_refs>0&&r.name instanceof Dn){const e=r.name.definition();let t=r.variables.get(r.name.name),n=t&&t.orig[0];n instanceof Sn||((n=ci(Sn,r.name,r.name)).scope=r,r.name=n,t=r.def_function(n)),r.walk(new An(function(n){n instanceof wn&&n.definition()===e&&(n.thedef=t,t.references.push(n))}))}return(r instanceof st||r instanceof sn)&&si(t,!0).add_child_scope(r),r.optimize(t)}if(r&&void 0===p.should_replace){let e;if(r instanceof Pn)p.orig[0]instanceof hn||!p.references.every(e=>p.scope===e.scope)||(e=r);else{var s=r.evaluate(t);s===r||!t.option("unsafe_regexp")&&s instanceof RegExp||(e=fi(s,r))}if(e){var u,c=e.optimize(t).print_to_string().length;r.walk(new An(function(e){if(e instanceof wn&&(n=!0),n)return!0})),n?u=function(){var n=e.optimize(t);return n===e?n.clone(!0):n}:(c=Math.min(c,r.print_to_string().length),u=function(){var n=Ni(e.optimize(t),r);return n===e||n===r?n.clone(!0):n});var l=p.name.length,f=0;t.option("unused")&&!t.exposed(p)&&(f=(l+2+c)/(p.references.length-p.assignments)),p.should_replace=c<=l+f&&u}else p.should_replace=!1}if(p.should_replace)return p.should_replace()}return e}),ti(Zn,function(e,t){if(t.option("unsafe_undefined")){var n=ui(t,"undefined");if(n){var i=ci(wn,e,{name:"undefined",scope:n.scope,thedef:n});return Sr(i,_r),i}}var r=Ri(t.self(),t.parent());return r&&qi(r,e)?e:ci(Yt,e,{operator:"void",expression:ci(zn,e,{value:0})})}),ti(Jn,function(e,t){var n=Ri(t.self(),t.parent());return n&&qi(n,e)?e:!t.option("keep_infinity")||n&&!qi(n,e)||ui(t,"Infinity")?ci($t,e,{operator:"/",left:ci(zn,e,{value:1}),right:ci(zn,e,{value:0})}):e}),ti(jn,function(e,t){var n=Ri(t.self(),t.parent());return n&&!qi(n,e)||ui(t,"NaN")?ci($t,e,{operator:"/",left:ci(zn,e,{value:0}),right:ci(zn,e,{value:0})}):e});const Lr=E("+ - / * % >> << >>> | ^ &"),Vr=E("* | ^ &");function Ji(e,t){return e instanceof wn&&(e=e.fixed_value()),!!e&&(!(e instanceof st||e instanceof sn)||t.parent()instanceof Ut||!e.contains_this())}function Qi(e,t){return t.in_boolean_context()?xi(t,e,li(e,[e,ci(vi,e)]).optimize(t)):e}function er(e,t,n){for(var i=0;i0&&s.args.length==u.args.length&&s.expression.equivalent_to(u.expression)&&!e.condition.has_side_effects(t)&&!s.expression.has_side_effects(t)&&"number"==typeof(o=function(){for(var e=s.args,t=u.args,n=0,i=e.length;n1)&&(p=null)}else if(!p&&!t.option("keep_fargs")&&s=n.argnames.length;)p=ci(hn,n,{name:n.make_var_name("argument_"+n.argnames.length),scope:n}),n.argnames.push(p),n.enclosed.push(n.def_variable(p));if(p){var d=ci(wn,e,p);return d.reference({}),vr(p,sr),d}}if(Ri(e,t.parent()))return e;if(o!==r){var m=e.flatten_object(a,t);m&&(i=e.expression=m.expression,r=e.property=m.property)}if(t.option("properties")&&t.option("side_effects")&&r instanceof zn&&i instanceof Jt){s=r.getValue();var E=i.elements,h=E[s];e:if(Ji(h,t)){for(var D=!0,g=[],A=E.length;--A>s;){(S=E[A].drop_side_effect_free(t))&&(g.unshift(S),D&&S.has_side_effects(t)&&(D=!1))}if(h instanceof at)break e;for(h=h instanceof Qn?ci(Zn,h):h,D||g.unshift(h);--A>=0;){var S;if((S=E[A])instanceof at)break e;(S=S.drop_side_effect_free(t))?g.unshift(S):s--}return D?(g.push(h),li(e,g).optimize(t)):ci(zt,e,{expression:ci(Jt,i,{elements:g}),property:ci(zn,r,{value:s})})}}var v=e.evaluate(t);return v!==e?xi(t,v=fi(v,e).optimize(t),e):e}),st.DEFMETHOD("contains_this",function(){var e,t=this;return t.walk(new An(function(n){return!!e||(n instanceof Pn?e=!0:n!==t&&n instanceof rt&&!(n instanceof lt)||void 0)})),e}),Ht.DEFMETHOD("flatten_object",function(e,t){if(t.option("properties")){var n=t.option("unsafe_arrows")&&t.option("ecma")>=6,i=this.expression;if(i instanceof en)for(var r=i.properties,o=r.length;--o>=0;){var a=r[o];if(""+(a instanceof an?a.key.name:a.key)==e){if(!r.every(e=>e instanceof nn||n&&e instanceof an&&!e.is_generator))break;if(!Ji(a.value,t))break;return ci(zt,this,{expression:ci(Jt,i,{elements:r.map(function(e){var t=e.value;t instanceof ut&&(t=ci(ct,t,t));var n=e.key;return n instanceof Pe&&!(n instanceof gn)?li(e,[n,t]):t})}),property:ci(zn,this,{value:o})})}}}}),ti(Xt,function(e,t){if("arguments"!=e.property&&"caller"!=e.property||t.warn("Function.prototype.{prop} not supported [{file}:{line},{col}]",{prop:e.property,file:e.start.file,line:e.start.line,col:e.start.col}),Ri(e,t.parent()))return e;if(t.option("unsafe_proto")&&e.expression instanceof Xt&&"prototype"==e.expression.property){var n=e.expression.expression;if(gi(n))switch(n.name){case"Array":e.expression=ci(Jt,e.expression,{elements:[]});break;case"Function":e.expression=ci(ct,e.expression,{argnames:[],body:[]});break;case"Number":e.expression=ci(zn,e.expression,{value:0});break;case"Object":e.expression=ci(en,e.expression,{properties:[]});break;case"RegExp":e.expression=ci(Yn,e.expression,{value:{source:"t",flags:""}});break;case"String":e.expression=ci(Xn,e.expression,{value:""})}}var i=e.flatten_object(e.property,t);if(i)return i.optimize(t);var r=e.evaluate(t);return r!==e?xi(t,r=fi(r,e).optimize(t),e):e}),ti(Jt,function(e,t){var n=Qi(e,t);return n!==e?n:er(e,0,e.elements)}),ti(en,function(e,t){var n=Qi(e,t);if(n!==e)return n;for(var i=e.properties,r=0;r=6&&!e.name&&!e.is_generator&&!e.uses_arguments&&!e.pinned()){var n=!1;if(e.walk(new An(function(e){return!!n||(e instanceof Pn?(n=!0,!0):void 0)})),!n)return ci(lt,e,e).optimize(t)}return e}),ti(sn,function(e,t){return e}),ti(Mi,function(e,t){return e.expression&&!e.is_star&&Oi(e.expression,t)&&(e.expression=null),e}),ti(dt,function(e,t){if(!t.option("evaluate")||t.parent()instanceof _t)return e;for(var n=[],i=0;i=6&&(!(n instanceof RegExp)||n.test(e.key+""))){var i=e.key,r=e.value;if((r instanceof lt&&Array.isArray(r.body)&&!r.contains_this()||r instanceof ct)&&!r.name)return ci(an,e,{async:r.async,is_generator:r.is_generator,key:i instanceof Pe?i:ci(gn,e,{name:i}),value:ci(ut,r,r),quote:e.quote})}return e}),ti(pt,function(e,t){if(1==t.option("pure_getters")&&t.option("unused")&&!e.is_array&&Array.isArray(e.names)&&!function(e){for(var t=[/^VarDef$/,/^(Const|Let|Var)$/,/^Export$/],n=0,i=0,r=t.length;n1)throw new Error("inline source map only works with singular input");t.sourceMap.content=(n=e[l],i=void 0,(i=/(?:^|[^.])\/\/# sourceMappingURL=data:application\/json(;[\w=-]*)?;base64,([+/0-9A-Za-z]*=*)\s*$/.exec(n))?Br(i[2]):(Pe.warn("inline source map not found"),null))}u=t.parse.toplevel}a&&"strict"!==t.mangle.properties.keep_quoted&&ir(u,a),t.wrap&&(u=u.wrap_commonjs(t.wrap)),t.enclose&&(u=u.wrap_enclose(t.enclose)),s&&(s.rename=Date.now()),s&&(s.compress=Date.now()),t.compress&&(u=new ei(t.compress).compress(u)),s&&(s.scope=Date.now()),t.mangle&&u.figure_out_scope(t.mangle),s&&(s.mangle=Date.now()),t.mangle&&(ar.reset(),u.compute_char_frequency(t.mangle),u.mangle_names(t.mangle)),s&&(s.properties=Date.now()),t.mangle&&t.mangle.properties&&(u=or(u,t.mangle.properties)),s&&(s.output=Date.now());var f={};if(t.output.ast&&(f.ast=u),!D(t.output,"code")||t.output.code){if(t.sourceMap&&("string"==typeof t.sourceMap.content&&(t.sourceMap.content=JSON.parse(t.sourceMap.content)),t.output.source_map=function(e){e=o(e,{file:null,root:null,orig:null,orig_line_diff:0,dest_line_diff:0});var t=new O.SourceMapGenerator({file:e.file,sourceRoot:e.root}),n=e.orig&&new O.SourceMapConsumer(e.orig);return n&&n.sources.forEach(function(e){var i=n.sourceContentFor(e,!0);i&&t.setSourceContent(e,i)}),{add:function(i,r,o,a,s,u){if(n){var c=n.originalPositionFor({line:a,column:s});if(null===c.source)return;i=c.source,a=c.line,s=c.column,u=c.name||u}t.addMapping({generated:{line:r+e.dest_line_diff,column:o},original:{line:a+e.orig_line_diff,column:s},source:i,name:u})},get:function(){return t},toString:function(){return JSON.stringify(t.toJSON())}}}({file:t.sourceMap.filename,orig:t.sourceMap.content,root:t.sourceMap.root}),t.sourceMap.includeSources)){if(e instanceof ot)throw new Error("original source content unavailable");for(var l in e)D(e,l)&&t.output.source_map.get().setSourceContent(l,e[l])}delete t.output.ast,delete t.output.code;var p=In(t.output);if(u.print(p),f.code=p.get(),t.sourceMap)if(t.sourceMap.asObject?f.map=t.output.source_map.get().toJSON():f.map=t.output.source_map.toString(),"inline"==t.sourceMap.url){var _="object"==typeof f.map?JSON.stringify(f.map):f.map;f.code+="\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,"+Kr(_)}else t.sourceMap.url&&(f.code+="\n//# sourceMappingURL="+t.sourceMap.url)}return t.nameCache&&t.mangle&&(t.mangle.cache&&(t.nameCache.vars=lr(t.mangle.cache)),t.mangle.properties&&t.mangle.properties.cache&&(t.nameCache.props=lr(t.mangle.properties.cache))),s&&(s.end=Date.now(),f.timings={parse:.001*(s.rename-s.parse),rename:.001*(s.compress-s.rename),compress:.001*(s.scope-s.compress),scope:.001*(s.mangle-s.scope),mangle:.001*(s.properties-s.mangle),properties:.001*(s.output-s.properties),output:.001*(s.end-s.output),total:.001*(s.end-s.start)}),c.length&&(f.warnings=c),f}catch(e){return{error:e}}finally{Pe.warn_function=r}}function pr(e){var t=fr("",e);return t.error&&t.error.defs}!function(){var e=function(e){for(var t=!0,n=0;n2){var n=a[a.length-2];"FunctionDeclaration"!==n.type&&"FunctionExpression"!==n.type&&"ArrowFunctionExpression"!==n.type||(t=Qt)}return new t({start:i(e),end:r(e),left:s(e.left),operator:"=",right:s(e.right)})},SpreadElement:function(e){return new at({start:i(e),end:r(e),expression:s(e.argument)})},RestElement:function(e){return new at({start:i(e),end:r(e),expression:s(e.argument)})},TemplateElement:function(e){return new mt({start:i(e),end:r(e),value:e.value.cooked,raw:e.value.raw})},TemplateLiteral:function(e){for(var t=[],n=0;n1||e.guardedHandlers&&e.guardedHandlers.length)throw new Error("Multiple catch clauses are not supported.");return new Mt({start:i(e),end:r(e),body:s(e.block).body,bcatch:s(t[0]),bfinally:e.finalizer?new Nt(s(e.finalizer)):null})},Property:function(e){var t=e.key,n={start:i(t||e.value),end:r(e.value),key:"Identifier"==t.type?t.name:t.value,value:s(e.value)};return e.computed&&(n.key=s(e.key)),e.method?(n.is_generator=e.value.generator,n.async=e.value.async,e.computed?n.key=s(e.key):n.key=new gn({name:n.key}),new an(n)):"init"==e.kind?("Identifier"!=t.type&&"Literal"!=t.type&&(n.key=s(t)),new nn(n)):("string"!=typeof n.key&&"number"!=typeof n.key||(n.key=new gn({name:n.key})),n.value=new ut(n.value),"get"==e.kind?new on(n):"set"==e.kind?new rn(n):"method"==e.kind?(n.async=e.value.async,n.is_generator=e.value.generator,n.quote=e.computed?'"':null,new an(n)):void 0)},MethodDefinition:function(e){var t={start:i(e),end:r(e),key:e.computed?s(e.key):new gn({name:e.key.name||e.key.value}),value:s(e.value),static:e.static};return"get"==e.kind?new on(t):"set"==e.kind?new rn(t):(t.is_generator=e.value.generator,t.async=e.value.async,new an(t))},ArrayExpression:function(e){return new Jt({start:i(e),end:r(e),elements:e.elements.map(function(e){return null===e?new Qn:s(e)})})},ObjectExpression:function(e){return new en({start:i(e),end:r(e),properties:e.properties.map(function(e){return"SpreadElement"===e.type?s(e):(e.type="Property",s(e))})})},SequenceExpression:function(e){return new Gt({start:i(e),end:r(e),expressions:e.expressions.map(s)})},MemberExpression:function(e){return new(e.computed?zt:Xt)({start:i(e),end:r(e),property:e.computed?s(e.property):e.property.name,expression:s(e.object)})},SwitchCase:function(e){return new(e.test?Ft:Ot)({start:i(e),end:r(e),expression:s(e.test),body:e.consequent.map(s)})},VariableDeclaration:function(e){return new("const"===e.kind?It:"let"===e.kind?kt:xt)({start:i(e),end:r(e),definitions:e.declarations.map(s)})},ImportDeclaration:function(e){var t=null,n=null;return e.specifiers.forEach(function(e){"ImportSpecifier"===e.type?(n||(n=[]),n.push(new Lt({start:i(e),end:r(e),foreign_name:s(e.imported),name:s(e.local)}))):"ImportDefaultSpecifier"===e.type?t=s(e.local):"ImportNamespaceSpecifier"===e.type&&(n||(n=[]),n.push(new Lt({start:i(e),end:r(e),foreign_name:new Rn({name:"*"}),name:s(e.local)})))}),new Vt({start:i(e),end:r(e),imported_name:t,imported_names:n,module_name:s(e.source)})},ExportAllDeclaration:function(e){return new Pt({start:i(e),end:r(e),exported_names:[new Lt({name:new Ln({name:"*"}),foreign_name:new Ln({name:"*"})})],module_name:s(e.source)})},ExportNamedDeclaration:function(e){return new Pt({start:i(e),end:r(e),exported_definition:s(e.declaration),exported_names:e.specifiers&&e.specifiers.length?e.specifiers.map(function(e){return new Lt({foreign_name:s(e.exported),name:s(e.local)})}):null,module_name:s(e.source)})},ExportDefaultDeclaration:function(e){return new Pt({start:i(e),end:r(e),exported_value:s(e.declaration),is_default:!0})},Literal:function(e){var t=e.value,n={start:i(e),end:r(e)},o=e.regex;if(o&&o.pattern)return n.value={source:o.pattern,flags:o.flags},new Yn(n);if(o){const i=e.raw||t,r=i.match(/^\/(.*)\/(\w*)$/);if(!r)throw new Error("Invalid regex source "+i);const[o,a,s]=r;return n.value={source:a,flags:s},new Yn(n)}if(null===t)return new $n(n);switch(typeof t){case"string":return n.value=t,new Xn(n);case"number":return n.value=t,new zn(n);case"boolean":return new(t?vi:Si)(n)}},MetaProperty:function(e){if("new"===e.meta.name&&"target"===e.property.name)return new fn({start:i(e),end:r(e)})},Identifier:function(e){var t=a[a.length-2];return new("LabeledStatement"==t.type?Nn:"VariableDeclarator"==t.type&&t.id===e?"const"==t.kind?mn:"let"==t.kind?En:_n:/Import.*Specifier/.test(t.type)?t.local===e?Cn:Rn:"ExportSpecifier"==t.type?t.local===e?xn:Ln:"FunctionExpression"==t.type?t.id===e?Sn:hn:"FunctionDeclaration"==t.type?t.id===e?Dn:hn:"ArrowFunctionExpression"==t.type?t.params.includes(e)?hn:wn:"ClassExpression"==t.type?t.id===e?bn:wn:"Property"==t.type?t.key===e&&t.computed||t.value===e?wn:gn:"ClassDeclaration"==t.type?t.id===e?Tn:wn:"MethodDefinition"==t.type?t.computed?wn:gn:"CatchClause"==t.type?yn:"BreakStatement"==t.type||"ContinueStatement"==t.type?Vn:wn)({start:i(e),end:r(e),name:e.name})},BigIntLiteral:e=>new Wn({start:i(e),end:r(e),value:e.value})};function n(e){if("Literal"==e.type)return null!=e.raw?e.raw:e.value+""}function i(e){var t=e.loc,i=t&&t.start,r=e.range;return new Ve({file:t&&t.source,line:i&&i.line,col:i&&i.column,pos:r?r[0]:e.start,endline:i&&i.line,endcol:i&&i.column,endpos:r?r[0]:e.start,raw:n(e)})}function r(e){var t=e.loc,i=t&&t.end,r=e.range;return new Ve({file:t&&t.source,line:i&&i.line,col:i&&i.column,pos:r?r[1]:e.end,endline:i&&i.line,endcol:i&&i.column,endpos:r?r[1]:e.end,raw:n(e)})}function o(e,n,o){var a="function From_Moz_"+e+"(M){\n";a+="return new U2."+n.name+"({\nstart: my_start_token(M),\nend: my_end_token(M)";var c="function To_Moz_"+e+"(M){\n";c+="return {\ntype: "+JSON.stringify(e),o&&o.split(/\s*,\s*/).forEach(function(e){var t=/([a-z0-9$_]+)([=@>%])([a-z0-9$_]+)/i.exec(e);if(!t)throw new Error("Can't understand property map: "+e);var n=t[1],i=t[2],r=t[3];switch(a+=",\n"+r+": ",c+=",\n"+n+": ",i){case"@":a+="M."+n+".map(from_moz)",c+="M."+r+".map(to_moz)";break;case">":a+="from_moz(M."+n+")",c+="to_moz(M."+r+")";break;case"=":a+="M."+n,c+="M."+r;break;case"%":a+="from_moz(M."+n+").body",c+="to_moz_block(M)";break;default:throw new Error("Can't understand operator in propmap: "+e)}}),a+="\n})\n}",c+="\n}\n}",a=new Function("U2","my_start_token","my_end_token","from_moz","return("+a+")")(Pi,i,r,s),c=new Function("to_moz","to_moz_block","to_moz_scope","return("+c+")")(l,p,_),t[e]=a,u(n,c)}t.UpdateExpression=t.UnaryExpression=function(e){return new(("prefix"in e?e.prefix:"UnaryExpression"==e.type)?Yt:qt)({start:i(e),end:r(e),operator:e.operator,expression:s(e.argument)})},t.ClassDeclaration=t.ClassExpression=function(e){return new("ClassDeclaration"===e.type?un:cn)({start:i(e),end:r(e),name:s(e.id),extends:s(e.superClass),properties:e.body.body.map(s)})},o("EmptyStatement",Ye),o("BlockStatement",We,"body@body"),o("IfStatement",bt,"test>condition, consequent>body, alternate>alternative"),o("LabeledStatement",$e,"label>label, body>body"),o("BreakStatement",vt,"label>label"),o("ContinueStatement",Tt,"label>label"),o("WithStatement",it,"object>expression, body>body"),o("SwitchStatement",yt,"discriminant>expression, cases@body"),o("ReturnStatement",gt,"argument>value"),o("ThrowStatement",At,"argument>value"),o("WhileStatement",Je,"test>condition, body>body"),o("DoWhileStatement",Qe,"test>condition, body>body"),o("ForStatement",et,"init>init, test>condition, update>step, body>body"),o("ForInStatement",tt,"left>init, right>object, body>body"),o("ForOfStatement",nt,"left>init, right>object, body>body, await=await"),o("AwaitExpression",Fi,"argument>expression"),o("YieldExpression",Mi,"argument>expression, delegate=is_star"),o("DebuggerStatement",Ke),o("VariableDeclarator",Bt,"id>name, init>value"),o("CatchClause",Rt,"param>argname, body%body"),o("ThisExpression",Pn),o("Super",Gn),o("BinaryExpression",$t,"operator=operator, left>left, right>right"),o("LogicalExpression",$t,"operator=operator, left>left, right>right"),o("AssignmentExpression",Zt,"operator=operator, left>left, right>right"),o("ConditionalExpression",jt,"test>condition, consequent>consequent, alternate>alternative"),o("NewExpression",Ut,"callee>expression, arguments@args"),o("CallExpression",Kt,"callee>expression, arguments@args"),u(ot,function(e){return _("Program",e)}),u(at,function(e,t){return{type:f()?"RestElement":"SpreadElement",argument:l(e.expression)}}),u(_t,function(e){return{type:"TaggedTemplateExpression",tag:l(e.prefix),quasi:l(e.template_string)}}),u(dt,function(e){for(var t=[],n=[],i=0;i({type:"BigIntLiteral",value:e.value})),Ai.DEFMETHOD("to_mozilla_ast",Hn.prototype.to_mozilla_ast),$n.DEFMETHOD("to_mozilla_ast",Hn.prototype.to_mozilla_ast),Qn.DEFMETHOD("to_mozilla_ast",function(){return null}),ze.DEFMETHOD("to_mozilla_ast",We.prototype.to_mozilla_ast),st.DEFMETHOD("to_mozilla_ast",ct.prototype.to_mozilla_ast);var a=null;function s(e){a.push(e);var n=null!=e?t[e.type](e):null;return a.pop(),n}function u(e,t){e.DEFMETHOD("to_mozilla_ast",function(e){return n=this,i=t(this,e),r=n.start,o=n.end,r&&o?(null!=r.pos&&null!=o.endpos&&(i.range=[r.pos,o.endpos]),r.line&&(i.loc={start:{line:r.line,column:r.col},end:o.endline?{line:o.endline,column:o.endcol}:null},r.file&&(i.loc.source=r.file)),i):i;var n,i,r,o})}Pe.from_mozilla_ast=function(e){var t=a;a=[];var n=s(e);return a=t,n};var c=null;function l(e){null===c&&(c=[]),c.push(e);var t=null!=e?e.to_mozilla_ast(c[c.length-2]):null;return c.pop(),0===c.length&&(c=null),t}function f(){for(var e=c.length;e--;)if(c[e]instanceof pt)return!0;return!1}function p(e){return{type:"BlockStatement",body:e.body.map(l)}}function _(e,t){var n=t.body.map(l);return t.body[0]instanceof Ge&&t.body[0].body instanceof Xn&&n.unshift(l(new Ye(t.body[0]))),{type:e,body:n}}}(),C.AST_Accessor=ut,C.AST_Array=Jt,C.AST_Arrow=lt,C.AST_Assign=Zt,C.AST_Atom=qn,C.AST_Await=Fi,C.AST_Binary=$t,C.AST_Block=ze,C.AST_BlockStatement=We,C.AST_Boolean=Ai,C.AST_Break=vt,C.AST_Call=Kt,C.AST_Case=Ft,C.AST_Catch=Rt,C.AST_Class=sn,C.AST_ClassExpression=cn,C.AST_ConciseMethod=an,C.AST_Conditional=jt,C.AST_Const=It,C.AST_Constant=Hn,C.AST_Continue=Tt,C.AST_DWLoop=Ze,C.AST_Debugger=Ke,C.AST_DefClass=un,C.AST_Default=Ot,C.AST_DefaultAssign=Qt,C.AST_Definitions=wt,C.AST_Defun=ft,C.AST_Destructuring=pt,C.AST_Directive=Ue,C.AST_Do=Qe,C.AST_Dot=Xt,C.AST_EmptyStatement=Ye,C.AST_Exit=ht,C.AST_Expansion=at,C.AST_Export=Pt,C.AST_False=Si,C.AST_Finally=Nt,C.AST_For=et,C.AST_ForIn=tt,C.AST_ForOf=nt,C.AST_Function=ct,C.AST_Hole=Qn,C.AST_If=bt,C.AST_Import=Vt,C.AST_Infinity=Jn,C.AST_IterationStatement=je,C.AST_Jump=Et,C.AST_Label=Nn,C.AST_LabelRef=Vn,C.AST_LabeledStatement=$e,C.AST_Lambda=st,C.AST_Let=kt,C.AST_LoopControl=St,C.AST_NaN=jn,C.AST_NameMapping=Lt,C.AST_New=Ut,C.AST_NewTarget=fn,C.AST_Node=Pe,C.AST_Null=$n,C.AST_Number=zn,C.AST_Object=en,C.AST_ObjectGetter=on,C.AST_ObjectKeyVal=nn,C.AST_ObjectProperty=tn,C.AST_ObjectSetter=rn,C.AST_PrefixedTemplateString=_t,C.AST_PropAccess=Ht,C.AST_RegExp=Yn,C.AST_Return=gt,C.AST_Scope=rt,C.AST_Sequence=Gt,C.AST_SimpleStatement=Ge,C.AST_Statement=Be,C.AST_StatementWithBody=qe,C.AST_String=Xn,C.AST_Sub=zt,C.AST_Super=Gn,C.AST_Switch=yt,C.AST_SwitchBranch=Ct,C.AST_Symbol=ln,C.AST_SymbolBlockDeclaration=dn,C.AST_SymbolCatch=yn,C.AST_SymbolClass=bn,C.AST_SymbolConst=mn,C.AST_SymbolDeclaration=pn,C.AST_SymbolDefClass=Tn,C.AST_SymbolDefun=Dn,C.AST_SymbolExport=xn,C.AST_SymbolExportForeign=Ln,C.AST_SymbolFunarg=hn,C.AST_SymbolImport=Cn,C.AST_SymbolImportForeign=Rn,C.AST_SymbolLambda=Sn,C.AST_SymbolLet=En,C.AST_SymbolMethod=gn,C.AST_SymbolRef=wn,C.AST_SymbolVar=_n,C.AST_TemplateSegment=mt,C.AST_TemplateString=dt,C.AST_This=Pn,C.AST_Throw=At,C.AST_Token=Ve,C.AST_Toplevel=ot,C.AST_True=vi,C.AST_Try=Mt,C.AST_Unary=Wt,C.AST_UnaryPostfix=qt,C.AST_UnaryPrefix=Yt,C.AST_Undefined=Zn,C.AST_Var=xt,C.AST_VarDef=Bt,C.AST_While=Je,C.AST_With=it,C.AST_Yield=Mi,C.Compressor=ei,C.OutputStream=In,C.TreeTransformer=vn,C.TreeWalker=An,C._INLINE=Li,C._JS_Parse_Error=J,C._NOINLINE=Vi,C._PURE=Ii,C._has_annotation=T,C._tokenizer=ne,C.base54=ar,C.default_options=function(){const e={};return Object.keys(pr({0:0})).forEach(t=>{const n=pr({[t]:{0:0}});n&&(e[t]=n)}),e},C.defaults=o,C.mangle_properties=or,C.minify=fr,C.parse=ue,C.push_uniq=p,C.reserve_quoted_keys=ir,C.string_template=_,C.to_ascii=Br})}}); \ No newline at end of file diff --git a/packages/next/package.json b/packages/next/package.json index 29434b38575de..32d06ddea12ab 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -58,7 +58,7 @@ ] }, "dependencies": { - "@ampproject/toolbox-optimizer": "2.5.3", + "@ampproject/toolbox-optimizer": "2.5.14", "@babel/code-frame": "7.8.3", "@babel/core": "7.7.7", "@babel/plugin-proposal-class-properties": "7.8.3", diff --git a/yarn.lock b/yarn.lock index ab08dabd16f10..3d4252ec5323b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,25 +2,25 @@ # yarn lockfile v1 -"@ampproject/toolbox-core@^2.5.1": - version "2.5.1" - resolved "https://registry.yarnpkg.com/@ampproject/toolbox-core/-/toolbox-core-2.5.1.tgz#f01895995a722254807106a3e1422cf1c6c25c13" - integrity sha512-XMt7Y7/Ga5HskqILTNwAmkrQSXM6KJ4Xf3fiEMy/yTldVg51SebAeTSzjKH+oisKhSw00Ogo4VL7AB6a2IrT3g== +"@ampproject/toolbox-core@^2.5.4": + version "2.5.4" + resolved "https://registry.yarnpkg.com/@ampproject/toolbox-core/-/toolbox-core-2.5.4.tgz#8554c5398b6d65d240085a6b0abb94f9a3276dce" + integrity sha512-KjHyR0XpQyloTu59IaatU2NCGT5zOhWJtVXQ4Uj/NUaRriN6LlJlzHBxtXmPIb0YHETdD63ITtDvqZizZPYFag== dependencies: - cross-fetch "3.0.4" + cross-fetch "3.0.5" lru-cache "5.1.1" -"@ampproject/toolbox-optimizer@2.5.3": - version "2.5.3" - resolved "https://registry.yarnpkg.com/@ampproject/toolbox-optimizer/-/toolbox-optimizer-2.5.3.tgz#da24e0bad9350fded8a923c9e1c2402f0fe01e5b" - integrity sha512-D6j7nU02sLRaW+ZKd1UNyUESu9GVLhVrtGHQ/rORj87ZJS5s0DCpoIDbq1slKQDCDHl7RknQ3A6CVm14ihXV2A== +"@ampproject/toolbox-optimizer@2.5.14": + version "2.5.14" + resolved "https://registry.yarnpkg.com/@ampproject/toolbox-optimizer/-/toolbox-optimizer-2.5.14.tgz#3235919e730e017ec4e54718e76ca5db8bd003e9" + integrity sha512-UTXKVwDKn/xsNOHYroFUtQRxnukdZuiYj7iM1rCAvRmDT9MqrtMTVG8boGjxt5aHLgCnrUZEMz+8d61iBYZeDQ== dependencies: - "@ampproject/toolbox-core" "^2.5.1" - "@ampproject/toolbox-runtime-version" "^2.5.1" - "@ampproject/toolbox-script-csp" "^2.3.0" - "@ampproject/toolbox-validator-rules" "^2.3.0" + "@ampproject/toolbox-core" "^2.5.4" + "@ampproject/toolbox-runtime-version" "^2.5.4" + "@ampproject/toolbox-script-csp" "^2.5.4" + "@ampproject/toolbox-validator-rules" "^2.5.4" abort-controller "3.0.0" - cross-fetch "3.0.4" + cross-fetch "3.0.5" cssnano "4.1.10" dom-serializer "1.0.1" domhandler "3.0.0" @@ -31,24 +31,26 @@ normalize-html-whitespace "1.0.0" postcss "7.0.32" postcss-safe-parser "4.0.2" - terser "4.7.0" + terser "4.8.0" -"@ampproject/toolbox-runtime-version@^2.5.1": - version "2.5.1" - resolved "https://registry.yarnpkg.com/@ampproject/toolbox-runtime-version/-/toolbox-runtime-version-2.5.1.tgz#904280984a75925ff1d7a851ab15645efaa5cd90" - integrity sha512-udkXpuJX+f0ogd/GFlpifXg5K+BSyWpou9gg53uxoSpPTlPO4ZPepJ4PLfgdq0oxMq7f/IDN1YN5ZFFNJHbrzw== +"@ampproject/toolbox-runtime-version@^2.5.4": + version "2.5.4" + resolved "https://registry.yarnpkg.com/@ampproject/toolbox-runtime-version/-/toolbox-runtime-version-2.5.4.tgz#ed6e77df3832f551337bca3706b5a4e2f36d66f9" + integrity sha512-7vi/F91Zb+h1CwR8/on/JxZhp3Hhz6xJOOHxRA025aUFEFHV5c35B4QbTdt2MObWZrysogXFOT8M95dgU/hsKw== dependencies: - "@ampproject/toolbox-core" "^2.5.1" + "@ampproject/toolbox-core" "^2.5.4" -"@ampproject/toolbox-script-csp@^2.3.0": - version "2.3.0" - resolved "https://registry.yarnpkg.com/@ampproject/toolbox-script-csp/-/toolbox-script-csp-2.3.0.tgz#374cd0bf69bfdd0f1784064d0de69162722c89af" +"@ampproject/toolbox-script-csp@^2.5.4": + version "2.5.4" + resolved "https://registry.yarnpkg.com/@ampproject/toolbox-script-csp/-/toolbox-script-csp-2.5.4.tgz#d8b7b91a678ae8f263cb36d9b74e441b7d633aad" + integrity sha512-+knTYetI5nWllRZ9wFcj7mYxelkiiFVRAAW/hl0ad8EnKHMH82tRlk40CapEnUHhp6Er5sCYkumQ8dngs3Q4zQ== -"@ampproject/toolbox-validator-rules@^2.3.0": - version "2.3.0" - resolved "https://registry.yarnpkg.com/@ampproject/toolbox-validator-rules/-/toolbox-validator-rules-2.3.0.tgz#047d8a8106ba777f1df308c19f1c1c41ffea4054" +"@ampproject/toolbox-validator-rules@^2.5.4": + version "2.5.4" + resolved "https://registry.yarnpkg.com/@ampproject/toolbox-validator-rules/-/toolbox-validator-rules-2.5.4.tgz#7dee3a3edceefea459d060571db8cc6e7bbf0dd6" + integrity sha512-bS7uF+h0s5aiklc/iRaujiSsiladOsZBLrJ6QImJDXvubCAQtvE7om7ShlGSXixkMAO0OVMDWyuwLlEy8V1Ing== dependencies: - cross-fetch "3.0.4" + cross-fetch "3.0.5" "@babel/code-frame@7.8.3", "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.5.5", "@babel/code-frame@^7.8.3": version "7.8.3" @@ -5286,12 +5288,12 @@ cross-env@6.0.3: dependencies: cross-spawn "^7.0.0" -cross-fetch@3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.4.tgz#7bef7020207e684a7638ef5f2f698e24d9eb283c" +cross-fetch@3.0.5: + version "3.0.5" + resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.5.tgz#2739d2981892e7ab488a7ad03b92df2816e03f4c" + integrity sha512-FFLcLtraisj5eteosnX1gf01qYDCOc4fDy0+euOt8Kn9YBY2NtXL/pCoYPavw24NIQkQqm5ZOLsGD5Zzj0gyew== dependencies: node-fetch "2.6.0" - whatwg-fetch "3.0.0" cross-spawn@6.0.5, cross-spawn@^6.0.0, cross-spawn@^6.0.5: version "6.0.5" @@ -15221,10 +15223,10 @@ terser@4.4.2: source-map "~0.6.1" source-map-support "~0.5.12" -terser@4.7.0: - version "4.7.0" - resolved "https://registry.yarnpkg.com/terser/-/terser-4.7.0.tgz#15852cf1a08e3256a80428e865a2fa893ffba006" - integrity sha512-Lfb0RiZcjRDXCC3OSHJpEkxJ9Qeqs6mp2v4jf2MHfy8vGERmVDuvjXdd/EnP5Deme5F2yBRBymKmKHCBg2echw== +terser@4.8.0, terser@^4.1.2: + version "4.8.0" + resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17" + integrity sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw== dependencies: commander "^2.20.0" source-map "~0.6.1" @@ -15238,15 +15240,6 @@ terser@^3.8.2: source-map "~0.6.1" source-map-support "~0.5.10" -terser@^4.1.2: - version "4.8.0" - resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17" - integrity sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw== - dependencies: - commander "^2.20.0" - source-map "~0.6.1" - source-map-support "~0.5.12" - terser@^4.4.3: version "4.6.11" resolved "https://registry.yarnpkg.com/terser/-/terser-4.6.11.tgz#12ff99fdd62a26de2a82f508515407eb6ccd8a9f" From 63e66ef0b052d366a20052b929e3fa01c93e6368 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 27 Jul 2020 14:47:00 -0400 Subject: [PATCH 20/90] Update `gssp-export` Error (#15529) This pull request updates the `gssp-export` error for clarity. Fixes #15527 --- errors/gssp-export.md | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/errors/gssp-export.md b/errors/gssp-export.md index b9908fadc58d0..62909cabf4e39 100644 --- a/errors/gssp-export.md +++ b/errors/gssp-export.md @@ -2,13 +2,37 @@ #### Why This Error Occurred -You attempted to export a page with `getServerSideProps` which is not allowed. `getServerSideProps` is meant for requesting up to date information on every request which means exporting it defeats the purpose of the method. +You attempted to statically export your application via `next export`, however, one or more of your pages uses `getServerSideProps`. + +The `getServerSideProps` lifecycle is not compatible with `next export`, so you'll need to use `next start` or a [serverless deployment](https://vercel.com). #### Possible Ways to Fix It -If you would like the page be static you can leverage the `getStaticProps` method instead. +1. If you'd like to keep your application static, you can use `getStaticProps` instead of `getServerSideProps`. + +2. If you want to use server-side rendering, update your build command and remove `next export`. For example, in your `package.json`: + + ```diff + diff --git a/bla.json b/bla.json + index b84aa66c4..149e67565 100644 + --- a/bla.json + +++ b/bla.json + @@ -1,7 +1,7 @@ + { + "scripts": { + "dev": "next dev", + - "build": "next build && next export", + + "build": "next build", + "start": "next start" + } + } + ``` + +> **Note**: Removing `next export` does not mean your entire application is no longer static. +> Pages that use `getStaticProps` or [no lifecycle](https://nextjs.org/docs/advanced-features/automatic-static-optimization) **will still be static**! ### Useful Links +- [Automatic Static Optimization](https://nextjs.org/docs/advanced-features/automatic-static-optimization) - [`getStaticProps` documentation](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) - [`exportPathMap` documentation](https://nextjs.org/docs/api-reference/next.config.js/exportPathMap) From 193ffe7616ed1e1578eea817d8808e9f556f6055 Mon Sep 17 00:00:00 2001 From: Christopher Robert Van Wiemeersch Date: Mon, 27 Jul 2020 12:24:29 -0700 Subject: [PATCH 21/90] fix typo in custom-webpack-config docs (#15533) --- docs/api-reference/next.config.js/custom-webpack-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-reference/next.config.js/custom-webpack-config.md b/docs/api-reference/next.config.js/custom-webpack-config.md index c9b71fcd0f7bb..44934f7301e51 100644 --- a/docs/api-reference/next.config.js/custom-webpack-config.md +++ b/docs/api-reference/next.config.js/custom-webpack-config.md @@ -4,7 +4,7 @@ description: Extend the default webpack config added by Next.js. # Custom Webpack Config -Before continuing to add custom webpack configuration your application make sure Next.js doesn't already support your use-case: +Before continuing to add custom webpack configuration to your application make sure Next.js doesn't already support your use-case: - [CSS imports](/docs/basic-features/built-in-css-support#adding-a-global-stylesheet) - [CSS modules](/docs/basic-features/built-in-css-support#adding-component-level-css) From 71bc0db92ad0f75e5f208d04ae36f6810f8f53c6 Mon Sep 17 00:00:00 2001 From: Gerald Monaco Date: Mon, 27 Jul 2020 13:19:30 -0700 Subject: [PATCH 22/90] Combine sendPayload and sendHTML (#15475) --- packages/next/build/entries.ts | 1 + .../webpack/loaders/next-serverless-loader.ts | 9 +++-- .../next/next-server/server/next-server.ts | 21 ++++++++--- packages/next/next-server/server/send-html.ts | 37 ------------------- .../next/next-server/server/send-payload.ts | 21 ++++++++--- 5 files changed, 37 insertions(+), 52 deletions(-) delete mode 100644 packages/next/next-server/server/send-html.ts diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index 7d464a7746bc2..8d6df0482b4b3 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -83,6 +83,7 @@ export function createEntrypoints( buildId, assetPrefix: config.assetPrefix, generateEtags: config.generateEtags, + poweredByHeader: config.poweredByHeader, canonicalBase: config.canonicalBase, basePath: config.basePath, runtimeConfig: hasRuntimeConfig diff --git a/packages/next/build/webpack/loaders/next-serverless-loader.ts b/packages/next/build/webpack/loaders/next-serverless-loader.ts index abcc79c08d186..400bf0304bf88 100644 --- a/packages/next/build/webpack/loaders/next-serverless-loader.ts +++ b/packages/next/build/webpack/loaders/next-serverless-loader.ts @@ -22,6 +22,7 @@ export type ServerlessLoaderQuery = { buildId: string assetPrefix: string generateEtags: string + poweredByHeader: string canonicalBase: string basePath: string runtimeConfig: string @@ -43,6 +44,7 @@ const nextServerlessLoader: loader.Loader = function () { absoluteDocumentPath, absoluteErrorPath, generateEtags, + poweredByHeader, basePath, runtimeConfig, previewProps, @@ -266,7 +268,6 @@ const nextServerlessLoader: loader.Loader = function () { const {parse: parseQs} = require('querystring') const {renderToHTML} = require('next/dist/next-server/server/render'); const { tryGetPreviewData } = require('next/dist/next-server/server/api-utils'); - const {sendHTML} = require('next/dist/next-server/server/send-html'); const {sendPayload} = require('next/dist/next-server/server/send-payload'); const buildManifest = require('${buildManifest}'); const reactLoadableManifest = require('${reactLoadableManifest}'); @@ -494,9 +495,9 @@ const nextServerlessLoader: loader.Loader = function () { await initServer() const html = await renderReqToHTML(req, res) if (html) { - sendHTML(req, res, html, {generateEtags: ${ - generateEtags === 'true' ? true : false - }}) + sendPayload(req, res, html, 'html', {generateEtags: ${JSON.stringify( + generateEtags === 'true' + )}, poweredByHeader: ${JSON.stringify(poweredByHeader === 'true')}}) } } catch(err) { console.error(err) diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index ff0a17ed57e74..ce5005bd6c1d7 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -52,7 +52,6 @@ import Router, { route, Route, } from './router' -import { sendHTML } from './send-html' import { sendPayload } from './send-payload' import { serveStatic } from './serve-static' import { IncrementalCache } from './incremental-cache' @@ -813,7 +812,10 @@ export default class Server { html: string ): Promise { const { generateEtags, poweredByHeader } = this.renderOpts - return sendHTML(req, res, html, { generateEtags, poweredByHeader }) + return sendPayload(req, res, html, 'html', { + generateEtags, + poweredByHeader, + }) } public async render( @@ -996,7 +998,10 @@ export default class Server { res, data, isDataReq ? 'json' : 'html', - this.renderOpts.generateEtags, + { + generateEtags: this.renderOpts.generateEtags, + poweredByHeader: this.renderOpts.poweredByHeader, + }, !this.renderOpts.dev ? { private: isPreviewMode, @@ -1126,7 +1131,10 @@ export default class Server { html = renderResult.html } - sendPayload(req, res, html, 'html', this.renderOpts.generateEtags) + sendPayload(req, res, html, 'html', { + generateEtags: this.renderOpts.generateEtags, + poweredByHeader: this.renderOpts.poweredByHeader, + }) return null } @@ -1141,7 +1149,10 @@ export default class Server { res, isDataReq ? JSON.stringify(pageData) : html, isDataReq ? 'json' : 'html', - this.renderOpts.generateEtags, + { + generateEtags: this.renderOpts.generateEtags, + poweredByHeader: this.renderOpts.poweredByHeader, + }, !this.renderOpts.dev || (isServerProps && !isDataReq) ? { private: isPreviewMode, diff --git a/packages/next/next-server/server/send-html.ts b/packages/next/next-server/server/send-html.ts deleted file mode 100644 index 1a7380215ade2..0000000000000 --- a/packages/next/next-server/server/send-html.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { IncomingMessage, ServerResponse } from 'http' -import generateETag from 'next/dist/compiled/etag' -import fresh from 'next/dist/compiled/fresh' -import { isResSent } from '../lib/utils' - -export function sendHTML( - req: IncomingMessage, - res: ServerResponse, - html: string, - { - generateEtags, - poweredByHeader, - }: { generateEtags: boolean; poweredByHeader: boolean } -) { - if (isResSent(res)) return - const etag = generateEtags ? generateETag(html) : undefined - - if (poweredByHeader) { - res.setHeader('X-Powered-By', 'Next.js') - } - - if (fresh(req.headers, { etag })) { - res.statusCode = 304 - res.end() - return - } - - if (etag) { - res.setHeader('ETag', etag) - } - - if (!res.getHeader('Content-Type')) { - res.setHeader('Content-Type', 'text/html; charset=utf-8') - } - res.setHeader('Content-Length', Buffer.byteLength(html)) - res.end(req.method === 'HEAD' ? null : html) -} diff --git a/packages/next/next-server/server/send-payload.ts b/packages/next/next-server/server/send-payload.ts index e6f2b5a0058cb..6943e0774227d 100644 --- a/packages/next/next-server/server/send-payload.ts +++ b/packages/next/next-server/server/send-payload.ts @@ -8,7 +8,10 @@ export function sendPayload( res: ServerResponse, payload: any, type: 'html' | 'json', - generateEtags: boolean, + { + generateEtags, + poweredByHeader, + }: { generateEtags: boolean; poweredByHeader: boolean }, options?: | { private: true } | { private: boolean; stateful: true } @@ -18,6 +21,10 @@ export function sendPayload( return } + if (poweredByHeader && type === 'html') { + res.setHeader('X-Powered-By', 'Next.js') + } + const etag = generateEtags ? generateETag(payload) : undefined if (fresh(req.headers, { etag })) { @@ -30,10 +37,12 @@ export function sendPayload( res.setHeader('ETag', etag) } - res.setHeader( - 'Content-Type', - type === 'json' ? 'application/json' : 'text/html; charset=utf-8' - ) + if (!res.getHeader('Content-Type')) { + res.setHeader( + 'Content-Type', + type === 'json' ? 'application/json' : 'text/html; charset=utf-8' + ) + } res.setHeader('Content-Length', Buffer.byteLength(payload)) if (options != null) { if (options.private || options.stateful) { @@ -61,5 +70,5 @@ export function sendPayload( ) } } - res.end(payload) + res.end(req.method === 'HEAD' ? null : payload) } From fc942865bfc0456822f93579f1c2436f48b70bea Mon Sep 17 00:00:00 2001 From: ywppp <64980223+ywppp@users.noreply.github.com> Date: Mon, 27 Jul 2020 21:00:22 -0700 Subject: [PATCH 23/90] [update] 'yo' to 'you' (#15545) that's really all there is - it just bugged me. --- examples/with-cxs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-cxs/README.md b/examples/with-cxs/README.md index b3dcbd2e09789..fd8f716b6a7ca 100644 --- a/examples/with-cxs/README.md +++ b/examples/with-cxs/README.md @@ -1,6 +1,6 @@ # Example app with cxs -This example features how yo use a different styling solution than [styled-jsx](https://github.com/zeit/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [cxs](https://github.com/jxnblk/cxs/). +This example shows how to use a different styling solution than [styled-jsx](https://github.com/zeit/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [cxs](https://github.com/jxnblk/cxs/). For this purpose we are extending the `` and injecting the server side rendered styles into the ``. From bf1af6880add6e612c06c42179c2dab5ec372669 Mon Sep 17 00:00:00 2001 From: Luis Alvarez D Date: Mon, 27 Jul 2020 23:16:31 -0500 Subject: [PATCH 24/90] [Docs] Update links that should point to Vercel repos (#15547) From feedback, we still have some links that go to zeit repos instead of vercel --- .../api-reference/next.config.js/custom-webpack-config.md | 2 +- docs/basic-features/built-in-css-support.md | 8 ++++---- docs/routing/dynamic-routes.md | 2 +- docs/upgrading.md | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/api-reference/next.config.js/custom-webpack-config.md b/docs/api-reference/next.config.js/custom-webpack-config.md index 44934f7301e51..28586da21da63 100644 --- a/docs/api-reference/next.config.js/custom-webpack-config.md +++ b/docs/api-reference/next.config.js/custom-webpack-config.md @@ -15,7 +15,7 @@ Before continuing to add custom webpack configuration to your application make s Some commonly asked for features are available as plugins: -- [@zeit/next-less](https://github.com/zeit/next-plugins/tree/master/packages/next-less) +- [@zeit/next-less](https://github.com/vercel/next-plugins/tree/master/packages/next-less) - [@next/mdx](https://github.com/vercel/next.js/tree/canary/packages/next-mdx) - [@next/bundle-analyzer](https://github.com/vercel/next.js/tree/canary/packages/next-bundle-analyzer) diff --git a/docs/basic-features/built-in-css-support.md b/docs/basic-features/built-in-css-support.md index 3743627b0c5da..07cd55fea25b7 100644 --- a/docs/basic-features/built-in-css-support.md +++ b/docs/basic-features/built-in-css-support.md @@ -129,8 +129,8 @@ module.exports = { To support importing `.less` or `.styl` files you can use the following plugins: -- [@zeit/next-less](https://github.com/zeit/next-plugins/tree/master/packages/next-less) -- [@zeit/next-stylus](https://github.com/zeit/next-plugins/tree/master/packages/next-stylus) +- [@zeit/next-less](https://github.com/vercel/next-plugins/tree/master/packages/next-less) +- [@zeit/next-stylus](https://github.com/vercel/next-plugins/tree/master/packages/next-stylus) If using the less plugin, don't forget to add a dependency on less as well, otherwise you'll see an error like: @@ -164,7 +164,7 @@ function HiThere() { export default HiThere ``` -We bundle [styled-jsx](https://github.com/zeit/styled-jsx) to provide support for isolated scoped CSS. +We bundle [styled-jsx](https://github.com/vercel/styled-jsx) to provide support for isolated scoped CSS. The aim is to support "shadow CSS" similar to Web Components, which unfortunately [do not support server-rendering and are JS-only](https://github.com/w3c/webcomponents/issues/71). See the above examples for other popular CSS-in-JS solutions (like Styled Components). @@ -202,7 +202,7 @@ function HelloWorld() { export default HelloWorld ``` -Please see the [styled-jsx documentation](https://github.com/zeit/styled-jsx) for more examples. +Please see the [styled-jsx documentation](https://github.com/vercel/styled-jsx) for more examples. ## FAQ diff --git a/docs/routing/dynamic-routes.md b/docs/routing/dynamic-routes.md index ca1f26e54fd87..e4d85c0244d1b 100644 --- a/docs/routing/dynamic-routes.md +++ b/docs/routing/dynamic-routes.md @@ -99,7 +99,7 @@ The `query` objects are as follows: { "slug": ["a", "b"] } // `GET /post/a/b` (multi-element array) ``` -> A good example of optional catch all routes is the Next.js docs, a single page called [pages/docs/[[...slug]].js](https://github.com/zeit/next-site/blob/master/pages/docs/%5B%5B...slug%5D%5D.js) takes care of all the docs you're currently looking at. +> A good example of optional catch all routes is the Next.js docs, a single page called [pages/docs/[[...slug]].js](https://github.com/vercel/next-site/blob/master/pages/docs/%5B%5B...slug%5D%5D.js) takes care of all the docs you're currently looking at. ## Caveats diff --git a/docs/upgrading.md b/docs/upgrading.md index 1e2497746a83b..3bab07d905248 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -104,7 +104,7 @@ Next.js now has the concept of page-level configuration, so the `withAmp` higher This change can be **automatically migrated by running the following commands in the root of your Next.js project:** ```bash -curl -L https://github.com/zeit/next-codemod/archive/master.tar.gz | tar -xz --strip=2 next-codemod-master/transforms/withamp-to-config.js npx jscodeshift -t ./withamp-to-config.js pages/**/*.js +curl -L https://github.com/vercel/next-codemod/archive/master.tar.gz | tar -xz --strip=2 next-codemod-master/transforms/withamp-to-config.js npx jscodeshift -t ./withamp-to-config.js pages/**/*.js ``` To perform this migration by hand, or view what the codemod will produce, see below: From bf9b96bd81d62d8fe62487ef58509dd958d76bcb Mon Sep 17 00:00:00 2001 From: Omkar Yadav Date: Tue, 28 Jul 2020 09:16:08 +0400 Subject: [PATCH 25/90] Update Apollo example for 9.5 (#15546) --- examples/with-apollo/pages/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-apollo/pages/index.js b/examples/with-apollo/pages/index.js index 184cc530b508e..c2072332ad542 100644 --- a/examples/with-apollo/pages/index.js +++ b/examples/with-apollo/pages/index.js @@ -29,7 +29,7 @@ export async function getStaticProps() { props: { initialApolloState: apolloClient.cache.extract(), }, - unstable_revalidate: 1, + revalidate: 1, } } From e73faa187bfe2bccabbb52f05ea5faf4ad3a85fe Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 28 Jul 2020 01:25:50 -0400 Subject: [PATCH 26/90] Update revalidate examples for 9.5 (#15551) --- examples/with-apollo-and-redux/pages/apollo.js | 2 +- examples/with-apollo-and-redux/pages/index.js | 2 +- examples/with-apollo-and-redux/pages/redux.js | 2 +- examples/with-graphql-hooks/pages/index.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/with-apollo-and-redux/pages/apollo.js b/examples/with-apollo-and-redux/pages/apollo.js index 7d19b38bcd4f2..8c46d6649450e 100644 --- a/examples/with-apollo-and-redux/pages/apollo.js +++ b/examples/with-apollo-and-redux/pages/apollo.js @@ -25,7 +25,7 @@ export async function getStaticProps() { props: { initialApolloState: apolloClient.cache.extract(), }, - unstable_revalidate: 1, + revalidate: 1, } } diff --git a/examples/with-apollo-and-redux/pages/index.js b/examples/with-apollo-and-redux/pages/index.js index d4b28defabd49..a0ae296b30455 100644 --- a/examples/with-apollo-and-redux/pages/index.js +++ b/examples/with-apollo-and-redux/pages/index.js @@ -57,7 +57,7 @@ export async function getStaticProps() { initialReduxState: reduxStore.getState(), initialApolloState: apolloClient.cache.extract(), }, - unstable_revalidate: 1, + revalidate: 1, } } diff --git a/examples/with-apollo-and-redux/pages/redux.js b/examples/with-apollo-and-redux/pages/redux.js index 6b90c1cdbc533..41c373bb139fd 100644 --- a/examples/with-apollo-and-redux/pages/redux.js +++ b/examples/with-apollo-and-redux/pages/redux.js @@ -39,7 +39,7 @@ export async function getStaticProps() { props: { initialReduxState: reduxStore.getState(), }, - unstable_revalidate: 1, + revalidate: 1, } } diff --git a/examples/with-graphql-hooks/pages/index.js b/examples/with-graphql-hooks/pages/index.js index 0f7cd40deaa80..85aa71d251cb4 100644 --- a/examples/with-graphql-hooks/pages/index.js +++ b/examples/with-graphql-hooks/pages/index.js @@ -25,6 +25,6 @@ export async function getStaticProps() { props: { initialGraphQLState: client.cache.getInitialState(), }, - unstable_revalidate: 1, + revalidate: 1, } } From 4dcf94e5c4325669253cc5e67141aaf03a13ee1e Mon Sep 17 00:00:00 2001 From: Luis Alvarez D Date: Tue, 28 Jul 2020 03:19:09 -0500 Subject: [PATCH 27/90] [Docs] Performance time is in milliseconds (#15544) --- docs/advanced-features/measuring-performance.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/advanced-features/measuring-performance.md b/docs/advanced-features/measuring-performance.md index 831c53c87118a..9ed5eaf768987 100644 --- a/docs/advanced-features/measuring-performance.md +++ b/docs/advanced-features/measuring-performance.md @@ -30,8 +30,8 @@ The `metric` object returned to the function consists of a number of properties: - `id`: Unique identifier for the metric in the context of the current page load - `name`: Metric name -- `startTime`: First recorded timestamp of the performance entry (if applicable) -- `value`: Value, or duration, of performance entry +- `startTime`: First recorded timestamp of the performance entry in [milliseconds](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp) (if applicable) +- `value`: Value, or duration in [milliseconds](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp), of the performance entry - `label`: Type of metric (`web-vital` or `custom`) There are two types of metrics that are tracked: From 5b4274a5901134035e4d041b7dd1680f87286ff9 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 28 Jul 2020 04:36:34 -0400 Subject: [PATCH 28/90] De-experimentalize redirects for rosetta example (#15554) Fixes #15552 --- examples/with-i18n-rosetta/next.config.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/with-i18n-rosetta/next.config.js b/examples/with-i18n-rosetta/next.config.js index 3e6c176989606..dff12cbf7f522 100644 --- a/examples/with-i18n-rosetta/next.config.js +++ b/examples/with-i18n-rosetta/next.config.js @@ -1,13 +1,11 @@ module.exports = { - experimental: { - redirects() { - return [ - { - source: '/', - permanent: true, - destination: '/en', - }, - ] - }, + redirects() { + return [ + { + source: '/', + destination: '/en', + permanent: true, + }, + ] }, } From fdfc508a61bd1694892f0f123561d200177e8772 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Tue, 28 Jul 2020 11:33:21 +0200 Subject: [PATCH 29/90] Add polyfill for process and Buffer in webpack 5 (#15499) --- packages/next/build/webpack-config.ts | 8 ++++++ packages/next/package.json | 2 ++ yarn.lock | 37 ++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 7f7665ed44f81..4650bac488056 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -802,6 +802,14 @@ export default async function getBaseWebpackConfig( }, plugins: [ hasReactRefresh && new ReactRefreshWebpackPlugin(), + // Makes sure `Buffer` is polyfilled in client-side bundles (same behavior as webpack 4) + isWebpack5 && + !isServer && + new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }), + // Makes sure `process` is polyfilled in client-side bundles (same behavior as webpack 4) + isWebpack5 && + !isServer && + new webpack.ProvidePlugin({ process: ['process'] }), // This plugin makes sure `output.filename` is used for entry chunks !isWebpack5 && new ChunkNamesPlugin(), new webpack.DefinePlugin({ diff --git a/packages/next/package.json b/packages/next/package.json index 32d06ddea12ab..a6de2b01bf0ba 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -82,6 +82,7 @@ "babel-plugin-transform-define": "2.0.0", "babel-plugin-transform-react-remove-prop-types": "0.4.24", "browserslist": "4.13.0", + "buffer": "5.6.0", "cacache": "13.0.1", "chokidar": "2.1.8", "css-loader": "3.5.3", @@ -95,6 +96,7 @@ "neo-async": "2.6.1", "pnp-webpack-plugin": "1.6.4", "postcss": "7.0.32", + "process": "0.11.10", "prop-types": "15.7.2", "prop-types-exact": "1.2.0", "react-is": "16.13.1", diff --git a/yarn.lock b/yarn.lock index 3d4252ec5323b..b4aded28c727e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4108,7 +4108,7 @@ browserify-zlib@^0.2.0: dependencies: pako "~1.0.5" -browserslist@4.13.0, browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6, browserslist@^4.0.0, browserslist@^4.11.1, browserslist@^4.13.0, browserslist@^4.3.6, browserslist@^4.6.4, browserslist@^4.8.3, browserslist@^4.8.5: +browserslist@4.13.0, browserslist@^4.0.0, browserslist@^4.11.1, browserslist@^4.13.0, browserslist@^4.3.6, browserslist@^4.6.4, browserslist@^4.8.3, browserslist@^4.8.5: version "4.13.0" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.13.0.tgz#42556cba011e1b0a2775b611cba6a8eca18e940d" integrity sha512-MINatJ5ZNrLnQ6blGvePd/QOz9Xtu+Ne+x29iQSCHfkU5BugKVJwZKn/iiL8UbpIpa3JhviKjz+XxMo0m2caFQ== @@ -4118,6 +4118,14 @@ browserslist@4.13.0, browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7 escalade "^3.0.1" node-releases "^1.1.58" +browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6: + version "1.7.7" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.7.7.tgz#0bd76704258be829b2398bb50e4b62d1a166b0b9" + integrity sha1-C9dnBCWL6CmyOYu1Dkti0aFmsLk= + dependencies: + caniuse-db "^1.0.30000639" + electron-to-chromium "^1.2.7" + browserstack-local@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/browserstack-local/-/browserstack-local-1.4.0.tgz#d979cac056f57b9af159b3bcd7fdc09b4354537c" @@ -4172,6 +4180,14 @@ buffer-xor@^1.0.3: resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" integrity sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk= +buffer@5.6.0: + version "5.6.0" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.6.0.tgz#a31749dc7d81d84db08abf937b6b8c4033f62786" + integrity sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw== + dependencies: + base64-js "^1.0.2" + ieee754 "^1.1.4" + buffer@^4.3.0: version "4.9.2" resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.2.tgz#230ead344002988644841ab0244af8c44bbe3ef8" @@ -4424,11 +4440,21 @@ caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634: version "1.0.30001023" resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001023.tgz#f856f71af16a5a44e81f1fcefc1673912a43da72" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001019, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001093: +caniuse-db@^1.0.30000639: + version "1.0.30001107" + resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001107.tgz#39d1b87ce1632a77ad49852144a17a9e7ab8c27e" + integrity sha512-ffbV17yvEamsNm4N4dDDHdj147tWwdKw+mGyeOmvQcnu+gu455xUg8degvUOCB+fIAm7Rv3gXVn7XlTiYKymMQ== + +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001019, caniuse-lite@^1.0.30001020: version "1.0.30001066" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001066.tgz#0a8a58a10108f2b9bf38e7b65c237b12fd9c5f04" integrity sha512-Gfj/WAastBtfxLws0RCh2sDbTK/8rJuSeZMecrSkNGYxPcv7EzblmDGfWQCFEQcSqYE2BRgQiJh8HOD07N5hIw== +caniuse-lite@^1.0.30001093: + version "1.0.30001107" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001107.tgz#809360df7a5b3458f627aa46b0f6ed6d5239da9a" + integrity sha512-86rCH+G8onCmdN4VZzJet5uPELII59cUzDphko3thQFgAQG1RNa+sVLDoALIhRYmflo5iSIzWY3vu1XTWtNMQQ== + capitalize@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/capitalize/-/capitalize-1.0.0.tgz#dc802c580aee101929020d2ca14b4ca8a0ae44be" @@ -6150,6 +6176,11 @@ ejs@^2.6.1: version "2.7.4" resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba" +electron-to-chromium@^1.2.7: + version "1.3.509" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.509.tgz#830fcb89cd66dc2984d18d794973b99e3f00584c" + integrity sha512-cN4lkjNRuTG8rtAqTOVgwpecEC2kbKA04PG6YijcKGHK/kD0xLjiqExcAOmLUwtXZRF8cBeam2I0VZcih919Ug== + electron-to-chromium@^1.3.488: version "1.3.501" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.501.tgz#faa17a2cb0105ee30d5e1ca87eae7d8e85dd3175" @@ -12842,7 +12873,7 @@ process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" -process@^0.11.10: +process@0.11.10, process@^0.11.10: version "0.11.10" resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI= From 17420c785c23e56b82a7fd80490559a292db1c8d Mon Sep 17 00:00:00 2001 From: Jean Helou Date: Tue, 28 Jul 2020 12:00:27 +0200 Subject: [PATCH 30/90] improves baseUrl resolution in typescript monorepos (#13542) --- packages/next/build/webpack-config.ts | 5 +- .../packages/lib/a/api.ts | 5 ++ .../packages/lib/b/api.ts | 4 ++ .../packages/lib/b/b-only.ts | 4 ++ .../www/components/alias-to-d-ts.d.ts | 1 + .../packages/www/components/alias-to-d-ts.tsx | 4 ++ .../packages/www/components/hello.tsx | 5 ++ .../packages/www/components/world.tsx | 5 ++ .../packages/www/next.config.js | 23 +++++++++ .../packages/www/pages/alias-to-d-ts.tsx | 10 ++++ .../packages/www/pages/basic-alias.tsx | 9 ++++ .../packages/www/pages/resolve-fallback.tsx | 5 ++ .../packages/www/pages/resolve-order.tsx | 5 ++ .../packages/www/pages/single-alias.tsx | 9 ++++ .../packages/www/test/index.test.js | 51 +++++++++++++++++++ .../packages/www/tsconfig.json | 6 +++ .../typescript-workspaces-paths/tsconfig.json | 30 +++++++++++ 17 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 test/integration/typescript-workspaces-paths/packages/lib/a/api.ts create mode 100644 test/integration/typescript-workspaces-paths/packages/lib/b/api.ts create mode 100644 test/integration/typescript-workspaces-paths/packages/lib/b/b-only.ts create mode 100644 test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.d.ts create mode 100644 test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.tsx create mode 100644 test/integration/typescript-workspaces-paths/packages/www/components/hello.tsx create mode 100644 test/integration/typescript-workspaces-paths/packages/www/components/world.tsx create mode 100644 test/integration/typescript-workspaces-paths/packages/www/next.config.js create mode 100644 test/integration/typescript-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx create mode 100644 test/integration/typescript-workspaces-paths/packages/www/pages/basic-alias.tsx create mode 100644 test/integration/typescript-workspaces-paths/packages/www/pages/resolve-fallback.tsx create mode 100644 test/integration/typescript-workspaces-paths/packages/www/pages/resolve-order.tsx create mode 100644 test/integration/typescript-workspaces-paths/packages/www/pages/single-alias.tsx create mode 100644 test/integration/typescript-workspaces-paths/packages/www/test/index.test.js create mode 100644 test/integration/typescript-workspaces-paths/packages/www/tsconfig.json create mode 100644 test/integration/typescript-workspaces-paths/tsconfig.json diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 4650bac488056..7968dd59aa0b6 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -15,6 +15,7 @@ import { } from '../lib/constants' import { fileExists } from '../lib/file-exists' import { resolveRequest } from '../lib/resolve-request' +import { getTypeScriptConfiguration } from '../lib/typescript/getTypeScriptConfiguration' import { CLIENT_STATIC_FILES_RUNTIME_MAIN, CLIENT_STATIC_FILES_RUNTIME_POLYFILLS, @@ -261,7 +262,9 @@ export default async function getBaseWebpackConfig( let jsConfig // jsconfig is a subset of tsconfig if (useTypeScript) { - jsConfig = parseJsonFile(tsConfigPath) + const ts = (await import(typeScriptPath)) as typeof import('typescript') + const tsConfig = await getTypeScriptConfiguration(ts, tsConfigPath) + jsConfig = { compilerOptions: tsConfig.options } } const jsConfigPath = path.join(dir, 'jsconfig.json') diff --git a/test/integration/typescript-workspaces-paths/packages/lib/a/api.ts b/test/integration/typescript-workspaces-paths/packages/lib/a/api.ts new file mode 100644 index 0000000000000..6644e65afa29e --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/lib/a/api.ts @@ -0,0 +1,5 @@ +//this line uses typescript specific syntax +//to demonstrate that transpilation occurs +export type API = () => string +const api: API = () => 'Hello from a' +export default api diff --git a/test/integration/typescript-workspaces-paths/packages/lib/b/api.ts b/test/integration/typescript-workspaces-paths/packages/lib/b/api.ts new file mode 100644 index 0000000000000..0d1aa87ee59e5 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/lib/b/api.ts @@ -0,0 +1,4 @@ +import { API } from '@lib/api' + +const b: API = () => 'Hello from b' +export default b diff --git a/test/integration/typescript-workspaces-paths/packages/lib/b/b-only.ts b/test/integration/typescript-workspaces-paths/packages/lib/b/b-only.ts new file mode 100644 index 0000000000000..7837c03d9919d --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/lib/b/b-only.ts @@ -0,0 +1,4 @@ +import { API } from '@lib/api' + +const b: API = () => 'Hello from only b' +export default b diff --git a/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.d.ts b/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.d.ts new file mode 100644 index 0000000000000..02906bf403120 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.d.ts @@ -0,0 +1 @@ +export default () => any diff --git a/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.tsx b/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.tsx new file mode 100644 index 0000000000000..5af0d17928ece --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.tsx @@ -0,0 +1,4 @@ +const Named = () => { + return <>Not aliased to d.ts file +} +export default Named diff --git a/test/integration/typescript-workspaces-paths/packages/www/components/hello.tsx b/test/integration/typescript-workspaces-paths/packages/www/components/hello.tsx new file mode 100644 index 0000000000000..49c8de26f6c50 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/components/hello.tsx @@ -0,0 +1,5 @@ +import React from 'react' + +export function Hello() { + return <>Hello +} diff --git a/test/integration/typescript-workspaces-paths/packages/www/components/world.tsx b/test/integration/typescript-workspaces-paths/packages/www/components/world.tsx new file mode 100644 index 0000000000000..d7d1f66258c77 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/components/world.tsx @@ -0,0 +1,5 @@ +import React from 'react' + +export function World(): JSX.Element { + return <>World +} diff --git a/test/integration/typescript-workspaces-paths/packages/www/next.config.js b/test/integration/typescript-workspaces-paths/packages/www/next.config.js new file mode 100644 index 0000000000000..1de16e790d34b --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/next.config.js @@ -0,0 +1,23 @@ +const path = require('path') +module.exports = { + webpack: function (config, { defaultLoaders }) { + const resolvedBaseUrl = path.resolve(config.context, '../../') + config.module.rules = [ + ...config.module.rules, + { + test: /\.(tsx|ts|js|mjs|jsx)$/, + include: [resolvedBaseUrl], + use: defaultLoaders.babel, + exclude: (excludePath) => { + return /node_modules/.test(excludePath) + }, + }, + ] + return config + }, + + onDemandEntries: { + // Make sure entries are not getting disposed. + maxInactiveAge: 1000 * 60 * 60, + }, +} diff --git a/test/integration/typescript-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx b/test/integration/typescript-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx new file mode 100644 index 0000000000000..d24ac047d2f73 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx @@ -0,0 +1,10 @@ +import React from 'react' +import NotAliasedToDTS from 'd-ts-alias' + +export default function HelloPage(): JSX.Element { + return ( +
+ +
+ ) +} diff --git a/test/integration/typescript-workspaces-paths/packages/www/pages/basic-alias.tsx b/test/integration/typescript-workspaces-paths/packages/www/pages/basic-alias.tsx new file mode 100644 index 0000000000000..f9b23a1829702 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/pages/basic-alias.tsx @@ -0,0 +1,9 @@ +import React from 'react' +import { World } from '@c/world' +export default function HelloPage(): JSX.Element { + return ( +
+ +
+ ) +} diff --git a/test/integration/typescript-workspaces-paths/packages/www/pages/resolve-fallback.tsx b/test/integration/typescript-workspaces-paths/packages/www/pages/resolve-fallback.tsx new file mode 100644 index 0000000000000..8b1dc93cd6bf4 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/pages/resolve-fallback.tsx @@ -0,0 +1,5 @@ +import React from 'react' +import api from '@lib/b-only' +export default function ResolveOrder(): JSX.Element { + return
{api()}
+} diff --git a/test/integration/typescript-workspaces-paths/packages/www/pages/resolve-order.tsx b/test/integration/typescript-workspaces-paths/packages/www/pages/resolve-order.tsx new file mode 100644 index 0000000000000..dd83cd62e8a8a --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/pages/resolve-order.tsx @@ -0,0 +1,5 @@ +import React from 'react' +import api from '@lib/api' +export default function ResolveOrder(): JSX.Element { + return
{api()}
+} diff --git a/test/integration/typescript-workspaces-paths/packages/www/pages/single-alias.tsx b/test/integration/typescript-workspaces-paths/packages/www/pages/single-alias.tsx new file mode 100644 index 0000000000000..df2031b90ae62 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/pages/single-alias.tsx @@ -0,0 +1,9 @@ +import { Hello } from '@mycomponent' + +export default function SingleAlias() { + return ( +
+ +
+ ) +} diff --git a/test/integration/typescript-workspaces-paths/packages/www/test/index.test.js b/test/integration/typescript-workspaces-paths/packages/www/test/index.test.js new file mode 100644 index 0000000000000..30116ff3264fe --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/test/index.test.js @@ -0,0 +1,51 @@ +/* eslint-env jest */ + +import { join } from 'path' +import cheerio from 'cheerio' +import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils' + +jest.setTimeout(1000 * 60 * 2) + +const appDir = join(__dirname, '..') +let appPort +let app + +async function get$(path, query) { + const html = await renderViaHTTP(appPort, path, query) + return cheerio.load(html) +} + +describe('TypeScript Features', () => { + describe('default behavior', () => { + beforeAll(async () => { + appPort = await findPort() + app = await launchApp(appDir, appPort, {}) + }) + afterAll(() => killApp(app)) + + it('should alias components', async () => { + const $ = await get$('/basic-alias') + expect($('body').text()).toMatch(/World/) + }) + + it('should resolve the first item in the array first', async () => { + const $ = await get$('/resolve-order') + expect($('body').text()).toMatch(/Hello from a/) + }) + + it('should resolve the second item in as a fallback', async () => { + const $ = await get$('/resolve-fallback') + expect($('body').text()).toMatch(/Hello from only b/) + }) + + it('should resolve a single matching alias', async () => { + const $ = await get$('/single-alias') + expect($('body').text()).toMatch(/Hello/) + }) + + it('should not resolve to .d.ts files', async () => { + const $ = await get$('/alias-to-d-ts') + expect($('body').text()).toMatch(/Not aliased to d\.ts file/) + }) + }) +}) diff --git a/test/integration/typescript-workspaces-paths/packages/www/tsconfig.json b/test/integration/typescript-workspaces-paths/packages/www/tsconfig.json new file mode 100644 index 0000000000000..72435f3401f72 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/tsconfig.json @@ -0,0 +1,6 @@ +/* This is a single line comment to check if that works */ +{ + "extends": "../../tsconfig.json", + "exclude": ["node_modules"], + "include": ["next-env.d.ts", "components", "pages"] +} diff --git a/test/integration/typescript-workspaces-paths/tsconfig.json b/test/integration/typescript-workspaces-paths/tsconfig.json new file mode 100644 index 0000000000000..2be4d1bba03e6 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/tsconfig.json @@ -0,0 +1,30 @@ +/* This is a single line comment to check if that works */ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "isomorphic-unfetch": ["packages/www/types/unfetch.d.ts"], + "@c/*": ["packages/www/components/*"], + "@lib/*": ["packages/lib/a/*", "packages/lib/b/*"], + "@mycomponent": ["packages/www/components/hello.tsx"], + "d-ts-alias": [ + "packages/www/components/alias-to-d-ts.d.ts", + "packages/www/components/alias-to-d-ts.tsx" + ] + // This is a single line comment to check if that works + }, + "esModuleInterop": true, + "module": "esnext", + "jsx": "preserve", + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true + } +} From 91242ca6d7d8227dff9d2eb7e9c3b8517f5b6fde Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Tue, 28 Jul 2020 12:02:00 +0200 Subject: [PATCH 31/90] Ignore history state not created by next.js (#15379) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../next/next-server/lib/router/router.ts | 7 ++- .../client-navigation/test/index.test.js | 60 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 1e256d190aac2..5475c2399b9d9 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -341,7 +341,11 @@ export default class Router implements BaseRouter { return } - const { url, as, options } = e.state + const { url, as, options, __N } = e.state + if (!__N) { + // this history state wasn't created by next.js so it can be ignored + return + } const { pathname } = parseRelativeUrl(url) // Make sure we don't re-render on initial load, @@ -596,6 +600,7 @@ export default class Router implements BaseRouter { url, as, options, + __N: true, }, // Most browsers currently ignores this parameter, although they may use it in the future. // Passing the empty string here should be safe against future changes to the method. diff --git a/test/integration/client-navigation/test/index.test.js b/test/integration/client-navigation/test/index.test.js index 12d3cf648e93f..e8d59546df887 100644 --- a/test/integration/client-navigation/test/index.test.js +++ b/test/integration/client-navigation/test/index.test.js @@ -1104,6 +1104,66 @@ describe('Client Navigation', () => { }) }) + describe('foreign history manipulation', () => { + it('should ignore history state without options', async () => { + let browser + try { + browser = await webdriver(context.appPort, '/nav') + // push history object without options + await browser.eval( + 'window.history.pushState({ url: "/whatever" }, "", "/whatever")' + ) + await browser.elementByCss('#about-link').click() + await browser.waitForElementByCss('.nav-about') + await browser.back() + await waitFor(1000) + expect(await hasRedbox(browser)).toBe(false) + } finally { + if (browser) { + await browser.close() + } + } + }) + + it('should ignore history state with an invalid url', async () => { + let browser + try { + browser = await webdriver(context.appPort, '/nav') + // push history object wit invalid url (not relative) + await browser.eval( + 'window.history.pushState({ url: "http://google.com" }, "", "/whatever")' + ) + await browser.elementByCss('#about-link').click() + await browser.waitForElementByCss('.nav-about') + await browser.back() + await waitFor(1000) + expect(await hasRedbox(browser)).toBe(false) + } finally { + if (browser) { + await browser.close() + } + } + }) + + it('should ignore foreign history state with missing properties', async () => { + let browser + try { + browser = await webdriver(context.appPort, '/nav') + // push empty history state + await browser.eval('window.history.pushState({}, "", "/whatever")') + await browser.elementByCss('#about-link').click() + await browser.waitForElementByCss('.nav-about') + await browser.back() + await waitFor(1000) + expect(await hasRedbox(browser)).toBe(false) + } finally { + if (browser) { + await browser.close() + } + } + }) + }) + it('should not error on module.exports + polyfills', async () => { let browser try { From 27c207da7b199cbaad6c7340b72323f7501e8879 Mon Sep 17 00:00:00 2001 From: Darsh Patel Date: Tue, 28 Jul 2020 15:42:57 +0530 Subject: [PATCH 32/90] Fix: UnhandledPromiseRejectionWarning when unknown flag provided for cli commands (#15422) --- packages/next/cli/next-dev.ts | 33 ++++--- packages/next/cli/next-export.ts | 35 ++++---- packages/next/cli/next-start.ts | 34 +++++--- packages/next/cli/next-telemetry.ts | 30 ++++--- .../build-warnings/test/index.test.js | 9 -- test/integration/cli/test/index.test.js | 85 +++++++++++++++++++ 6 files changed, 162 insertions(+), 64 deletions(-) diff --git a/packages/next/cli/next-dev.ts b/packages/next/cli/next-dev.ts index e010277ff9f8c..4c9b9ae1962f5 100755 --- a/packages/next/cli/next-dev.ts +++ b/packages/next/cli/next-dev.ts @@ -8,21 +8,26 @@ import { startedDevelopmentServer } from '../build/output' import { cliCommand } from '../bin/next' const nextDev: cliCommand = (argv) => { - const args = arg( - { - // Types - '--help': Boolean, - '--port': Number, - '--hostname': String, - - // Aliases - '-h': '--help', - '-p': '--port', - '-H': '--hostname', - }, - { argv } - ) + const validArgs: arg.Spec = { + // Types + '--help': Boolean, + '--port': Number, + '--hostname': String, + // Aliases + '-h': '--help', + '-p': '--port', + '-H': '--hostname', + } + let args: arg.Result + try { + args = arg(validArgs, { argv }) + } catch (error) { + if (error.code === 'ARG_UNKNOWN_OPTION') { + return printAndExit(error.message, 1) + } + throw error + } if (args['--help']) { // tslint:disable-next-line console.log(` diff --git a/packages/next/cli/next-export.ts b/packages/next/cli/next-export.ts index 29e8085d0ae5f..55a959892ceb1 100755 --- a/packages/next/cli/next-export.ts +++ b/packages/next/cli/next-export.ts @@ -7,22 +7,27 @@ import { printAndExit } from '../server/lib/utils' import { cliCommand } from '../bin/next' const nextExport: cliCommand = (argv) => { - const args = arg( - { - // Types - '--help': Boolean, - '--silent': Boolean, - '--outdir': String, - '--threads': Number, - - // Aliases - '-h': '--help', - '-s': '--silent', - '-o': '--outdir', - }, - { argv } - ) + const validArgs: arg.Spec = { + // Types + '--help': Boolean, + '--silent': Boolean, + '--outdir': String, + '--threads': Number, + // Aliases + '-h': '--help', + '-s': '--silent', + '-o': '--outdir', + } + let args: arg.Result + try { + args = arg(validArgs, { argv }) + } catch (error) { + if (error.code === 'ARG_UNKNOWN_OPTION') { + return printAndExit(error.message, 1) + } + throw error + } if (args['--help']) { // tslint:disable-next-line console.log(` diff --git a/packages/next/cli/next-start.ts b/packages/next/cli/next-start.ts index 90d89d9fcd240..78a71bb95dc9f 100755 --- a/packages/next/cli/next-start.ts +++ b/packages/next/cli/next-start.ts @@ -3,25 +3,31 @@ import { resolve } from 'path' import arg from 'next/dist/compiled/arg/index.js' import startServer from '../server/lib/start-server' +import { printAndExit } from '../server/lib/utils' import { cliCommand } from '../bin/next' import * as Log from '../build/output/log' const nextStart: cliCommand = (argv) => { - const args = arg( - { - // Types - '--help': Boolean, - '--port': Number, - '--hostname': String, - - // Aliases - '-h': '--help', - '-p': '--port', - '-H': '--hostname', - }, - { argv } - ) + const validArgs: arg.Spec = { + // Types + '--help': Boolean, + '--port': Number, + '--hostname': String, + // Aliases + '-h': '--help', + '-p': '--port', + '-H': '--hostname', + } + let args: arg.Result + try { + args = arg(validArgs, { argv }) + } catch (error) { + if (error.code === 'ARG_UNKNOWN_OPTION') { + return printAndExit(error.message, 1) + } + throw error + } if (args['--help']) { // tslint:disable-next-line console.log(` diff --git a/packages/next/cli/next-telemetry.ts b/packages/next/cli/next-telemetry.ts index 58b97ac8bafea..6e53a4bd68219 100755 --- a/packages/next/cli/next-telemetry.ts +++ b/packages/next/cli/next-telemetry.ts @@ -1,22 +1,28 @@ #!/usr/bin/env node import chalk from 'next/dist/compiled/chalk' import arg from 'next/dist/compiled/arg/index.js' - +import { printAndExit } from '../server/lib/utils' import { cliCommand } from '../bin/next' import { Telemetry } from '../telemetry/storage' const nextTelemetry: cliCommand = (argv) => { - const args = arg( - { - // Types - '--help': Boolean, - '--enable': Boolean, - '--disable': Boolean, - // Aliases - '-h': '--help', - }, - { argv } - ) + const validArgs: arg.Spec = { + // Types + '--help': Boolean, + '--enable': Boolean, + '--disable': Boolean, + // Aliases + '-h': '--help', + } + let args: arg.Result + try { + args = arg(validArgs, { argv }) + } catch (error) { + if (error.code === 'ARG_UNKNOWN_OPTION') { + return printAndExit(error.message, 1) + } + throw error + } if (args['--help']) { console.log( diff --git a/test/integration/build-warnings/test/index.test.js b/test/integration/build-warnings/test/index.test.js index 01a2845926934..886aa774fed5b 100644 --- a/test/integration/build-warnings/test/index.test.js +++ b/test/integration/build-warnings/test/index.test.js @@ -87,13 +87,4 @@ describe('Build warnings', () => { })) expect(stdout).not.toContain('no-cache') }) - - it('should warn when unknown argument provided', async () => { - const { stderr } = await nextBuild(appDir, ['--random'], { stderr: true }) - expect(stderr).toEqual('Unknown or unexpected option: --random\n') - }) - it('should not throw UnhandledPromiseRejectionWarning', async () => { - const { stderr } = await nextBuild(appDir, ['--random'], { stderr: true }) - expect(stderr).not.toContain('UnhandledPromiseRejectionWarning') - }) }) diff --git a/test/integration/cli/test/index.test.js b/test/integration/cli/test/index.test.js index b7a3ff177d713..311ad5a4d04ee 100644 --- a/test/integration/cli/test/index.test.js +++ b/test/integration/cli/test/index.test.js @@ -59,6 +59,19 @@ describe('CLI Usage', () => { /Compiles the application for production deployment/ ) }) + + test('should warn when unknown argument provided', async () => { + const { stderr } = await runNextCommand(['build', '--random'], { + stderr: true, + }) + expect(stderr).toEqual('Unknown or unexpected option: --random\n') + }) + test('should not throw UnhandledPromiseRejectionWarning', async () => { + const { stderr } = await runNextCommand(['build', '--random'], { + stderr: true, + }) + expect(stderr).not.toContain('UnhandledPromiseRejectionWarning') + }) }) describe('dev', () => { @@ -121,6 +134,19 @@ describe('CLI Usage', () => { ) expect(output).toMatch(new RegExp(`http://0.0.0.0:${port}`)) }) + + test('should warn when unknown argument provided', async () => { + const { stderr } = await runNextCommand(['dev', '--random'], { + stderr: true, + }) + expect(stderr).toEqual('Unknown or unexpected option: --random\n') + }) + test('should not throw UnhandledPromiseRejectionWarning', async () => { + const { stderr } = await runNextCommand(['dev', '--random'], { + stderr: true, + }) + expect(stderr).not.toContain('UnhandledPromiseRejectionWarning') + }) }) describe('start', () => { @@ -137,6 +163,19 @@ describe('CLI Usage', () => { }) expect(help.stdout).toMatch(/Starts the application in production mode/) }) + + test('should warn when unknown argument provided', async () => { + const { stderr } = await runNextCommand(['start', '--random'], { + stderr: true, + }) + expect(stderr).toEqual('Unknown or unexpected option: --random\n') + }) + test('should not throw UnhandledPromiseRejectionWarning', async () => { + const { stderr } = await runNextCommand(['start', '--random'], { + stderr: true, + }) + expect(stderr).not.toContain('UnhandledPromiseRejectionWarning') + }) }) describe('export', () => { @@ -153,5 +192,51 @@ describe('CLI Usage', () => { }) expect(help.stdout).toMatch(/Exports the application/) }) + + test('should warn when unknown argument provided', async () => { + const { stderr } = await runNextCommand(['export', '--random'], { + stderr: true, + }) + expect(stderr).toEqual('Unknown or unexpected option: --random\n') + }) + test('should not throw UnhandledPromiseRejectionWarning', async () => { + const { stderr } = await runNextCommand(['export', '--random'], { + stderr: true, + }) + expect(stderr).not.toContain('UnhandledPromiseRejectionWarning') + }) + }) + + describe('telemetry', () => { + test('--help', async () => { + const help = await runNextCommand(['telemetry', '--help'], { + stdout: true, + }) + expect(help.stdout).toMatch( + /Allows you to control Next\.js' telemetry collection/ + ) + }) + + test('-h', async () => { + const help = await runNextCommand(['telemetry', '-h'], { + stdout: true, + }) + expect(help.stdout).toMatch( + /Allows you to control Next\.js' telemetry collection/ + ) + }) + + test('should warn when unknown argument provided', async () => { + const { stderr } = await runNextCommand(['telemetry', '--random'], { + stderr: true, + }) + expect(stderr).toEqual('Unknown or unexpected option: --random\n') + }) + test('should not throw UnhandledPromiseRejectionWarning', async () => { + const { stderr } = await runNextCommand(['telemetry', '--random'], { + stderr: true, + }) + expect(stderr).not.toContain('UnhandledPromiseRejectionWarning') + }) }) }) From fb81ecb2bd85167d2676983a2489e29ea42b6b97 Mon Sep 17 00:00:00 2001 From: Prateek Bhatnagar Date: Tue, 28 Jul 2020 03:19:28 -0700 Subject: [PATCH 33/90] Font optimizations (#14746) Co-authored-by: atcastle --- packages/next/build/webpack-config.ts | 9 +- .../webpack/loaders/next-serverless-loader.ts | 13 +- .../font-stylesheet-gathering-plugin.ts | 141 +++++++++++++++ packages/next/export/index.ts | 1 + packages/next/export/worker.ts | 35 +++- packages/next/next-server/lib/constants.ts | 2 + packages/next/next-server/lib/head.tsx | 15 ++ packages/next/next-server/lib/post-process.ts | 161 ++++++++++++++++++ packages/next/next-server/server/config.ts | 1 + .../next/next-server/server/font-utils.ts | 59 +++++++ .../next/next-server/server/next-server.ts | 24 ++- packages/next/next-server/server/render.tsx | 22 +++ packages/next/next-server/server/require.ts | 10 ++ packages/next/package.json | 3 +- packages/next/pages/_document.tsx | 34 +++- .../build-output/test/index.test.js | 2 +- .../font-optimization/pages/_document.js | 30 ++++ .../font-optimization/pages/index.js | 7 + .../font-optimization/pages/stars.js | 26 +++ .../font-optimization/pages/static-head.js | 18 ++ test/integration/font-optimization/server.js | 111 ++++++++++++ .../font-optimization/test/index.test.js | 129 ++++++++++++++ yarn.lock | 12 ++ 23 files changed, 853 insertions(+), 12 deletions(-) create mode 100644 packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts create mode 100644 packages/next/next-server/lib/post-process.ts create mode 100644 packages/next/next-server/server/font-utils.ts create mode 100644 test/integration/font-optimization/pages/_document.js create mode 100644 test/integration/font-optimization/pages/index.js create mode 100644 test/integration/font-optimization/pages/stars.js create mode 100644 test/integration/font-optimization/pages/static-head.js create mode 100644 test/integration/font-optimization/server.js create mode 100644 test/integration/font-optimization/test/index.test.js diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 7968dd59aa0b6..9ccc634070f09 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -53,7 +53,7 @@ import WebpackConformancePlugin, { ReactSyncScriptsConformanceCheck, } from './webpack/plugins/webpack-conformance-plugin' import { WellKnownErrorsPlugin } from './webpack/plugins/wellknown-errors-plugin' - +import FontStylesheetGatheringPlugin from './webpack/plugins/font-stylesheet-gathering-plugin' type ExcludesFalse = (x: T | false) => x is T const isWebpack5 = parseInt(webpack.version!) === 5 @@ -873,6 +873,9 @@ export default async function getBaseWebpackConfig( 'process.env.__NEXT_REACT_MODE': JSON.stringify( config.experimental.reactMode ), + 'process.env.__NEXT_OPTIMIZE_FONTS': JSON.stringify( + config.experimental.optimizeFonts + ), 'process.env.__NEXT_SCROLL_RESTORATION': JSON.stringify( config.experimental.scrollRestoration ), @@ -978,6 +981,10 @@ export default async function getBaseWebpackConfig( inputChunkName.replace(/\.js$/, '.module.js'), }) })(), + config.experimental.optimizeFonts && + !dev && + isServer && + new FontStylesheetGatheringPlugin(), config.experimental.conformance && !isWebpack5 && !dev && diff --git a/packages/next/build/webpack/loaders/next-serverless-loader.ts b/packages/next/build/webpack/loaders/next-serverless-loader.ts index 400bf0304bf88..aecb0f05ec45a 100644 --- a/packages/next/build/webpack/loaders/next-serverless-loader.ts +++ b/packages/next/build/webpack/loaders/next-serverless-loader.ts @@ -6,6 +6,7 @@ import { loader } from 'webpack' import { API_ROUTE } from '../../../lib/constants' import { BUILD_MANIFEST, + FONT_MANIFEST, REACT_LOADABLE_MANIFEST, ROUTES_MANIFEST, } from '../../../next-server/lib/constants' @@ -58,6 +59,10 @@ const nextServerlessLoader: loader.Loader = function () { '/' ) const routesManifest = join(distDir, ROUTES_MANIFEST).replace(/\\/g, '/') + const fontManifest = join(distDir, 'serverless', FONT_MANIFEST).replace( + /\\/g, + '/' + ) const escapedBuildId = escapeRegexp(buildId) const pageIsDynamicRoute = isDynamicRoute(page) @@ -266,7 +271,7 @@ const nextServerlessLoader: loader.Loader = function () { } const {parse} = require('url') const {parse: parseQs} = require('querystring') - const {renderToHTML} = require('next/dist/next-server/server/render'); + const { renderToHTML } = require('next/dist/next-server/server/render'); const { tryGetPreviewData } = require('next/dist/next-server/server/api-utils'); const {sendPayload} = require('next/dist/next-server/server/send-payload'); const buildManifest = require('${buildManifest}'); @@ -274,6 +279,7 @@ const nextServerlessLoader: loader.Loader = function () { const Document = require('${absoluteDocumentPath}').default; const Error = require('${absoluteErrorPath}').default; const App = require('${absoluteAppPath}').default; + ${dynamicRouteImports} ${rewriteImports} @@ -418,6 +424,11 @@ const nextServerlessLoader: loader.Loader = function () { const previewData = tryGetPreviewData(req, res, options.previewProps) const isPreviewMode = previewData !== false + if (process.env.__NEXT_OPTIMIZE_FONTS) { + renderOpts.optimizeFonts = true + renderOpts.fontManifest = require('${fontManifest}') + process.env['__NEXT_OPTIMIZE_FONT'+'S'] = true + } let result = await renderToHTML(req, res, "${page}", Object.assign({}, getStaticProps ? { ...(parsedUrl.query.amp ? { amp: '1' } : {}) } : parsedUrl.query, nowParams ? nowParams : params, _params, isFallback ? { __nextFallback: 'true' } : {}), renderOpts) if (!renderMode) { diff --git a/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts b/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts new file mode 100644 index 0000000000000..3e3efba8d2bfb --- /dev/null +++ b/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts @@ -0,0 +1,141 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { NodePath } from 'ast-types/lib/node-path' +import { compilation as CompilationType, Compiler } from 'webpack' +import { namedTypes } from 'ast-types' +import { RawSource } from 'webpack-sources' +import { + getFontDefinitionFromNetwork, + FontManifest, +} from '../../../next-server/server/font-utils' +// @ts-ignore +import BasicEvaluatedExpression from 'webpack/lib/BasicEvaluatedExpression' +import { OPTIMIZED_FONT_PROVIDERS } from '../../../next-server/lib/constants' + +interface VisitorMap { + [key: string]: (path: NodePath) => void +} + +export default class FontStylesheetGatheringPlugin { + compiler?: Compiler + gatheredStylesheets: Array = [] + + private parserHandler = ( + factory: CompilationType.NormalModuleFactory + ): void => { + const JS_TYPES = ['auto', 'esm', 'dynamic'] + // Do an extra walk per module and add interested visitors to the walk. + for (const type of JS_TYPES) { + factory.hooks.parser + .for('javascript/' + type) + .tap(this.constructor.name, (parser: any) => { + /** + * Webpack fun facts: + * `parser.hooks.call.for` cannot catch calls for user defined identifiers like `__jsx` + * it can only detect calls for native objects like `window`, `this`, `eval` etc. + * In order to be able to catch calls of variables like `__jsx`, first we need to catch them as + * Identifier and then return `BasicEvaluatedExpression` whose `id` and `type` webpack matches to + * invoke hook for call. + * See: https://github.com/webpack/webpack/blob/webpack-4/lib/Parser.js#L1931-L1932. + */ + parser.hooks.evaluate + .for('Identifier') + .tap(this.constructor.name, (node: namedTypes.Identifier) => { + // We will only optimize fonts from first party code. + if (parser?.state?.module?.resource.includes('node_modules')) { + return + } + return node.name === '__jsx' + ? new BasicEvaluatedExpression() + //@ts-ignore + .setRange(node.range) + .setExpression(node) + .setIdentifier('__jsx') + : undefined + }) + + parser.hooks.call + .for('__jsx') + .tap(this.constructor.name, (node: namedTypes.CallExpression) => { + if (node.arguments.length !== 2) { + // A font link tag has only two arguments rel=stylesheet and href='...' + return + } + if (!isNodeCreatingLinkElement(node)) { + return + } + + // node.arguments[0] is the name of the tag and [1] are the props. + const propsNode = node.arguments[1] as namedTypes.ObjectExpression + const props: { [key: string]: string } = {} + propsNode.properties.forEach((prop) => { + if (prop.type !== 'Property') { + return + } + if ( + prop.key.type === 'Identifier' && + prop.value.type === 'Literal' + ) { + props[prop.key.name] = prop.value.value as string + } + }) + if ( + !props.rel || + props.rel !== 'stylesheet' || + !props.href || + !OPTIMIZED_FONT_PROVIDERS.some((url) => + props.href.startsWith(url) + ) + ) { + return false + } + + this.gatheredStylesheets.push(props.href) + }) + }) + } + } + + public apply(compiler: Compiler) { + this.compiler = compiler + compiler.hooks.normalModuleFactory.tap( + this.constructor.name, + this.parserHandler + ) + compiler.hooks.make.tapAsync(this.constructor.name, (compilation, cb) => { + compilation.hooks.finishModules.tapAsync( + this.constructor.name, + async (_: any, modulesFinished: Function) => { + const fontDefinitionPromises = this.gatheredStylesheets.map((url) => + getFontDefinitionFromNetwork(url) + ) + let manifestContent: FontManifest = [] + + for (let promiseIndex in fontDefinitionPromises) { + manifestContent.push({ + url: this.gatheredStylesheets[promiseIndex], + content: await fontDefinitionPromises[promiseIndex], + }) + } + compilation.assets['font-manifest.json'] = new RawSource( + JSON.stringify(manifestContent, null, ' ') + ) + modulesFinished() + } + ) + cb() + }) + } +} + +function isNodeCreatingLinkElement(node: namedTypes.CallExpression) { + const callee = node.callee as namedTypes.Identifier + if (callee.type !== 'Identifier') { + return false + } + const componentNode = node.arguments[0] as namedTypes.Literal + if (componentNode.type !== 'Literal') { + return false + } + // Next has pragma: __jsx. + return callee.name === '__jsx' && componentNode.value === 'link' +} diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index 23d40b0ba0bb7..93cbac6986dfd 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -388,6 +388,7 @@ export default async function exportApp( subFolders, buildExport: options.buildExport, serverless: isTargetLikeServerless(nextConfig.target), + optimizeFonts: nextConfig.experimental.optimizeFonts, }) for (const validation of result.ampValidations || []) { diff --git a/packages/next/export/worker.ts b/packages/next/export/worker.ts index f8159e3b44717..5c600e79b0b20 100644 --- a/packages/next/export/worker.ts +++ b/packages/next/export/worker.ts @@ -13,6 +13,8 @@ import 'next/dist/next-server/server/node-polyfill-fetch' import { IncomingMessage, ServerResponse } from 'http' import { ComponentType } from 'react' import { GetStaticProps } from '../types' +import { requireFontManifest } from '../next-server/server/require' +import { FontManifest } from '../next-server/server/font-utils' const envConfig = require('../next-server/lib/runtime-config') @@ -44,6 +46,7 @@ interface ExportPageInput { serverRuntimeConfig: string subFolders: string serverless: boolean + optimizeFonts: boolean } interface ExportPageResults { @@ -60,6 +63,8 @@ interface RenderOpts { ampSkipValidation?: boolean hybridAmp?: boolean inAmpMode?: boolean + optimizeFonts?: boolean + fontManifest?: FontManifest } type ComponentModule = ComponentType<{}> & { @@ -78,6 +83,7 @@ export default async function exportPage({ serverRuntimeConfig, subFolders, serverless, + optimizeFonts, }: ExportPageInput): Promise { let results: ExportPageResults = { ampValidations: [], @@ -211,7 +217,14 @@ export default async function exportPage({ req, res, 'export', - { ampPath }, + { + ampPath, + /// @ts-ignore + optimizeFonts, + fontManifest: optimizeFonts + ? requireFontManifest(distDir, serverless) + : null, + }, // @ts-ignore params ) @@ -246,7 +259,25 @@ export default async function exportPage({ html = components.Component queryWithAutoExportWarn() } else { - curRenderOpts = { ...components, ...renderOpts, ampPath, params } + /** + * This sets environment variable to be used at the time of static export by head.tsx. + * Using this from process.env allows targetting both serverless and SSR by calling + * `process.env.__NEXT_OPTIMIZE_FONTS`. + * TODO(prateekbh@): Remove this when experimental.optimizeFonts are being clened up. + */ + if (optimizeFonts) { + process.env.__NEXT_OPTIMIZE_FONTS = JSON.stringify(true) + } + curRenderOpts = { + ...components, + ...renderOpts, + ampPath, + params, + optimizeFonts, + fontManifest: optimizeFonts + ? requireFontManifest(distDir, serverless) + : null, + } // @ts-ignore html = await renderMethod(req, res, page, query, curRenderOpts) } diff --git a/packages/next/next-server/lib/constants.ts b/packages/next/next-server/lib/constants.ts index 86cbd01ba1367..665fc9b24f4ac 100644 --- a/packages/next/next-server/lib/constants.ts +++ b/packages/next/next-server/lib/constants.ts @@ -9,6 +9,7 @@ export const EXPORT_DETAIL = 'export-detail.json' export const PRERENDER_MANIFEST = 'prerender-manifest.json' export const ROUTES_MANIFEST = 'routes-manifest.json' export const REACT_LOADABLE_MANIFEST = 'react-loadable-manifest.json' +export const FONT_MANIFEST = 'font-manifest.json' export const SERVER_DIRECTORY = 'server' export const SERVERLESS_DIRECTORY = 'serverless' export const CONFIG_FILE = 'next.config.js' @@ -33,3 +34,4 @@ export const TEMPORARY_REDIRECT_STATUS = 307 export const PERMANENT_REDIRECT_STATUS = 308 export const STATIC_PROPS_ID = '__N_SSG' export const SERVER_PROPS_ID = '__N_SSP' +export const OPTIMIZED_FONT_PROVIDERS = ['https://fonts.googleapis.com/css'] diff --git a/packages/next/next-server/lib/head.tsx b/packages/next/next-server/lib/head.tsx index 4b03b2fc05847..0161711ccbc6b 100644 --- a/packages/next/next-server/lib/head.tsx +++ b/packages/next/next-server/lib/head.tsx @@ -136,6 +136,21 @@ function reduceComponents( .reverse() .map((c: React.ReactElement, i: number) => { const key = c.key || i + if (process.env.__NEXT_OPTIMIZE_FONTS) { + if ( + c.type === 'link' && + c.props['href'] && + // TODO(prateekbh@): Replace this with const from `constants` when the tree shaking works. + ['https://fonts.googleapis.com/css'].some((url) => + c.props['href'].startsWith(url) + ) + ) { + const newProps = { ...(c.props || {}) } + newProps['data-href'] = newProps['href'] + newProps['href'] = undefined + return React.cloneElement(c, newProps) + } + } return React.cloneElement(c, { key }) }) } diff --git a/packages/next/next-server/lib/post-process.ts b/packages/next/next-server/lib/post-process.ts new file mode 100644 index 0000000000000..3c45f2383a3c3 --- /dev/null +++ b/packages/next/next-server/lib/post-process.ts @@ -0,0 +1,161 @@ +import { parse, HTMLElement } from 'node-html-parser' +import { OPTIMIZED_FONT_PROVIDERS } from './constants' + +const MIDDLEWARE_TIME_BUDGET = 10 + +type postProcessOptions = { + optimizeFonts: boolean +} + +type renderOptions = { + getFontDefinition?: (url: string) => string +} + +type postProcessData = { + preloads: { + images: Array + } +} + +interface PostProcessMiddleware { + inspect: ( + originalDom: HTMLElement, + data: postProcessData, + options: renderOptions + ) => void + mutate: ( + markup: string, + data: postProcessData, + options: renderOptions + ) => Promise +} + +type middlewareSignature = { + name: string + middleware: PostProcessMiddleware + condition: ((options: postProcessOptions) => boolean) | null +} + +const middlewareRegistry: Array = [] + +function registerPostProcessor( + name: string, + middleware: PostProcessMiddleware, + condition?: (options: postProcessOptions) => boolean +) { + middlewareRegistry.push({ name, middleware, condition: condition || null }) +} + +async function processHTML( + html: string, + data: renderOptions, + options: postProcessOptions +): Promise { + // Don't parse unless there's at least one processor middleware + if (!middlewareRegistry[0]) { + return html + } + const postProcessData: postProcessData = { + preloads: { + images: [], + }, + } + const root: HTMLElement = parse(html) + let document = html + // Calls the middleware, with some instrumentation and logging + async function callMiddleWare( + middleware: PostProcessMiddleware, + name: string + ) { + let timer = Date.now() + middleware.inspect(root, postProcessData, data) + const inspectTime = Date.now() - timer + document = await middleware.mutate(document, postProcessData, data) + timer = Date.now() - timer + if (timer > MIDDLEWARE_TIME_BUDGET) { + console.warn( + `The postprocess middleware "${name}" took ${timer}ms(${inspectTime}, ${ + timer - inspectTime + }) to complete. This is longer than the ${MIDDLEWARE_TIME_BUDGET} limit.` + ) + } + return + } + + for (let i = 0; i < middlewareRegistry.length; i++) { + let middleware = middlewareRegistry[i] + if (!middleware.condition || middleware.condition(options)) { + await callMiddleWare( + middlewareRegistry[i].middleware, + middlewareRegistry[i].name + ) + } + } + + return document +} + +class FontOptimizerMiddleware implements PostProcessMiddleware { + fontDefinitions: Array = [] + inspect( + originalDom: HTMLElement, + _data: postProcessData, + options: renderOptions + ) { + if (!options.getFontDefinition) { + return + } + // collecting all the requested font definitions + originalDom + .querySelectorAll('link') + .filter( + (tag: HTMLElement) => + tag.getAttribute('rel') === 'stylesheet' && + tag.hasAttribute('data-href') && + OPTIMIZED_FONT_PROVIDERS.some((url) => + tag.getAttribute('data-href').startsWith(url) + ) + ) + .forEach((element: HTMLElement) => { + const url = element.getAttribute('data-href') + this.fontDefinitions.push(url) + }) + } + mutate = async ( + markup: string, + _data: postProcessData, + options: renderOptions + ) => { + let result = markup + if (!options.getFontDefinition) { + return markup + } + for (const key in this.fontDefinitions) { + const url = this.fontDefinitions[key] + if (result.indexOf(`` + ) + } + return result + } +} + +// Initialization +registerPostProcessor( + 'Inline-Fonts', + new FontOptimizerMiddleware(), + // Using process.env because passing Experimental flag through loader is not possible. + // @ts-ignore + (options) => options.optimizeFonts || process.env.__NEXT_OPTIMIZE_FONTS +) + +export default processHTML diff --git a/packages/next/next-server/server/config.ts b/packages/next/next-server/server/config.ts index 005295dc092dc..eed6e1ea2d8ee 100644 --- a/packages/next/next-server/server/config.ts +++ b/packages/next/next-server/server/config.ts @@ -52,6 +52,7 @@ const defaultConfig: { [key: string]: any } = { workerThreads: false, pageEnv: false, productionBrowserSourceMaps: false, + optimizeFonts: false, scrollRestoration: false, }, future: { diff --git a/packages/next/next-server/server/font-utils.ts b/packages/next/next-server/server/font-utils.ts new file mode 100644 index 0000000000000..6120ff10be27b --- /dev/null +++ b/packages/next/next-server/server/font-utils.ts @@ -0,0 +1,59 @@ +const https = require('https') + +const CHROME_UA = + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36' +const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko' + +export type FontManifest = Array<{ + url: string + content: string +}> + +function getFontForUA(url: string, UA: string): Promise { + return new Promise((resolve) => { + let rawData: any = '' + https.get( + url, + { + headers: { + 'user-agent': UA, + }, + }, + (res: any) => { + res.on('data', (chunk: any) => { + rawData += chunk + }) + res.on('end', () => { + resolve(rawData.toString('utf8')) + }) + } + ) + }) +} + +export async function getFontDefinitionFromNetwork( + url: string +): Promise { + let result = '' + /** + * The order of IE -> Chrome is important, other wise chrome starts loading woff1. + * CSS cascading 🤷‍♂️. + */ + result += await getFontForUA(url, IE_UA) + result += await getFontForUA(url, CHROME_UA) + return result +} + +export function getFontDefinitionFromManifest( + url: string, + manifest: FontManifest +): string { + return ( + manifest.find((font) => { + if (font && font.url === url) { + return true + } + return false + })?.content || '' + ) +} diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index ce5005bd6c1d7..3ec96ccf5f1bb 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -43,7 +43,7 @@ import { recursiveReadDirSync } from './lib/recursive-readdir-sync' import { loadComponents, LoadComponentsReturnType } from './load-components' import { normalizePagePath } from './normalize-page-path' import { RenderOpts, RenderOptsPartial, renderToHTML } from './render' -import { getPagePath } from './require' +import { getPagePath, requireFontManifest } from './require' import Router, { DynamicRoutes, PageChecker, @@ -63,6 +63,7 @@ import './node-polyfill-fetch' import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin' import { removePathTrailingSlash } from '../../client/normalize-trailing-slash' import getRouteFromAssetPath from '../lib/router/utils/get-route-from-asset-path' +import { FontManifest } from './font-utils' const getCustomRouteMatcher = pathMatch(true) @@ -119,6 +120,8 @@ export default class Server { customServer?: boolean ampOptimizerConfig?: { [key: string]: any } basePath: string + optimizeFonts: boolean + fontManifest: FontManifest } private compression?: Middleware private onErrorMiddleware?: ({ err }: { err: Error }) => Promise @@ -165,6 +168,10 @@ export default class Server { customServer: customServer === true ? true : undefined, ampOptimizerConfig: this.nextConfig.experimental.amp?.optimizer, basePath: this.nextConfig.basePath, + optimizeFonts: this.nextConfig.experimental.optimizeFonts, + fontManifest: this.nextConfig.experimental.optimizeFonts + ? requireFontManifest(this.distDir, this._isLikeServerless) + : null, } // Only the `publicRuntimeConfig` key is exposed to the client side @@ -219,6 +226,16 @@ export default class Server { ), flushToDisk: this.nextConfig.experimental.sprFlushToDisk, }) + + /** + * This sets environment variable to be used at the time of SSR by head.tsx. + * Using this from process.env allows targetting both serverless and SSR by calling + * `process.env.__NEXT_OPTIMIZE_FONTS`. + * TODO(prateekbh@): Remove this when experimental.optimizeFonts are being clened up. + */ + if (this.renderOpts.optimizeFonts) { + process.env.__NEXT_OPTIMIZE_FONTS = JSON.stringify(true) + } } protected currentPhase(): string { @@ -1044,7 +1061,10 @@ export default class Server { renderResult = await (components.Component as any).renderReqToHTML( req, res, - 'passthrough' + 'passthrough', + { + fontManifest: this.renderOpts.fontManifest, + } ) html = renderResult.html diff --git a/packages/next/next-server/server/render.tsx b/packages/next/next-server/server/render.tsx index ae89757548525..61debbceb48bb 100644 --- a/packages/next/next-server/server/render.tsx +++ b/packages/next/next-server/server/render.tsx @@ -45,6 +45,8 @@ import { tryGetPreviewData, __ApiPreviewProps } from './api-utils' import { getPageFiles } from './get-page-files' import { LoadComponentsReturnType, ManifestItem } from './load-components' import optimizeAmp from './optimize-amp' +import postProcess from '../lib/post-process' +import { FontManifest, getFontDefinitionFromManifest } from './font-utils' function noRouter() { const message = @@ -143,6 +145,8 @@ export type RenderOptsPartial = { previewProps: __ApiPreviewProps basePath: string unstable_runtimeJS?: false + optimizeFonts: boolean + fontManifest?: FontManifest } export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial @@ -269,6 +273,7 @@ export async function renderToHTML( pageConfig = {}, Component, buildManifest, + fontManifest, reactLoadableManifest, ErrorDebug, getStaticProps, @@ -280,6 +285,13 @@ export async function renderToHTML( basePath, } = renderOpts + const getFontDefinition = (url: string): string => { + if (fontManifest) { + return getFontDefinitionFromManifest(url, fontManifest) + } + return '' + } + const callMiddleware = async (method: string, args: any[], props = false) => { let results: any = props ? {} : [] @@ -781,6 +793,16 @@ export async function renderToHTML( } } + html = await postProcess( + html, + { + getFontDefinition, + }, + { + optimizeFonts: renderOpts.optimizeFonts, + } + ) + if (inAmpMode || hybridAmp) { // fix & being escaped for amphtml rel link html = html.replace(/&amp=1/g, '&=1') diff --git a/packages/next/next-server/server/require.ts b/packages/next/next-server/server/require.ts index 5e59f15d0167e..28fca96a2cbc0 100644 --- a/packages/next/next-server/server/require.ts +++ b/packages/next/next-server/server/require.ts @@ -4,6 +4,7 @@ import { PAGES_MANIFEST, SERVER_DIRECTORY, SERVERLESS_DIRECTORY, + FONT_MANIFEST, } from '../lib/constants' import { normalizePagePath, denormalizePagePath } from './normalize-page-path' import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin' @@ -54,3 +55,12 @@ export function requirePage( } return require(pagePath) } + +export function requireFontManifest(distDir: string, serverless: boolean) { + const serverBuildPath = join( + distDir, + serverless ? SERVERLESS_DIRECTORY : SERVER_DIRECTORY + ) + const fontManifest = require(join(serverBuildPath, FONT_MANIFEST)) + return fontManifest +} diff --git a/packages/next/package.json b/packages/next/package.json index a6de2b01bf0ba..0b15314cb8654 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -78,6 +78,7 @@ "@babel/types": "7.9.6", "@next/react-dev-overlay": "9.5.0", "@next/react-refresh-utils": "9.5.0", + "ast-types": "0.13.2", "babel-plugin-syntax-jsx": "6.18.0", "babel-plugin-transform-define": "2.0.0", "babel-plugin-transform-react-remove-prop-types": "0.4.24", @@ -94,6 +95,7 @@ "mkdirp": "0.5.3", "native-url": "0.3.4", "neo-async": "2.6.1", + "node-html-parser": "^1.2.19", "pnp-webpack-plugin": "1.6.4", "postcss": "7.0.32", "process": "0.11.10", @@ -155,7 +157,6 @@ "@zeit/ncc": "0.22.0", "amphtml-validator": "1.0.31", "arg": "4.1.0", - "ast-types": "0.13.2", "async-retry": "1.2.3", "async-sema": "3.0.0", "babel-loader": "8.1.0", diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx index dfb3f391b9974..f2016166521c1 100644 --- a/packages/next/pages/_document.tsx +++ b/packages/next/pages/_document.tsx @@ -1,7 +1,10 @@ import PropTypes from 'prop-types' -import React, { useContext, Component } from 'react' +import React, { useContext, Component, ReactNode } from 'react' import flush from 'styled-jsx/server' -import { AMP_RENDER_TARGET } from '../next-server/lib/constants' +import { + AMP_RENDER_TARGET, + OPTIMIZED_FONT_PROVIDERS, +} from '../next-server/lib/constants' import { DocumentContext as DocumentComponentContext } from '../next-server/lib/document-context' import { DocumentContext, @@ -236,6 +239,24 @@ export class Head extends Component< )) } + makeStylesheetInert(node: ReactNode): ReactNode { + return React.Children.map(node, (c: any) => { + if ( + c.type === 'link' && + c.props['href'] && + OPTIMIZED_FONT_PROVIDERS.some((url) => c.props['href'].startsWith(url)) + ) { + const newProps = { ...(c.props || {}) } + newProps['data-href'] = newProps['href'] + newProps['href'] = undefined + return React.cloneElement(c, newProps) + } else if (c.props && c.props['children']) { + c.props['children'] = this.makeStylesheetInert(c.props['children']) + } + return c + }) + } + render() { const { styles, @@ -278,6 +299,10 @@ export class Head extends Component< ) } + if (process.env.__NEXT_OPTIMIZE_FONTS) { + children = this.makeStylesheetInert(children) + } + let hasAmphtmlRel = false let hasCanonicalRel = false @@ -285,7 +310,6 @@ export class Head extends Component< head = React.Children.map(head || [], (child) => { if (!child) return child const { type, props } = child - if (inAmpMode) { let badProp: string = '' @@ -435,7 +459,9 @@ export class Head extends Component< href={canonicalBase + getAmpPath(ampPath, dangerousAsPath)} /> )} - {this.getCssLinks()} + {process.env.__NEXT_OPTIMIZE_FONTS + ? this.makeStylesheetInert(this.getCssLinks()) + : this.getCssLinks()} {!disableRuntimeJS && this.getPreloadDynamicChunks()} {!disableRuntimeJS && this.getPreloadMainLinks()} {this.context._documentProps.isDevelopment && ( diff --git a/test/integration/build-output/test/index.test.js b/test/integration/build-output/test/index.test.js index fb864ecf43991..2b4f1738042b6 100644 --- a/test/integration/build-output/test/index.test.js +++ b/test/integration/build-output/test/index.test.js @@ -98,7 +98,7 @@ describe('Build Output', () => { expect(parseFloat(indexFirstLoad) - 60).toBeLessThanOrEqual(0) expect(indexFirstLoad.endsWith('kB')).toBe(true) - expect(parseFloat(err404Size) - 3.4).toBeLessThanOrEqual(0) + expect(parseFloat(err404Size) - 3.6).toBeLessThanOrEqual(0) expect(err404Size.endsWith('kB')).toBe(true) expect(parseFloat(err404FirstLoad) - 63).toBeLessThanOrEqual(0) diff --git a/test/integration/font-optimization/pages/_document.js b/test/integration/font-optimization/pages/_document.js new file mode 100644 index 0000000000000..59d8fe75cd4c4 --- /dev/null +++ b/test/integration/font-optimization/pages/_document.js @@ -0,0 +1,30 @@ +import * as React from 'react' +/// @ts-ignore +import Document, { Main, NextScript, Head } from 'next/document' + +export default class MyDocument extends Document { + constructor(props) { + super(props) + const { __NEXT_DATA__, ids } = props + if (ids) { + __NEXT_DATA__.ids = ids + } + } + + render() { + return ( + + + + + +
+ + + + ) + } +} diff --git a/test/integration/font-optimization/pages/index.js b/test/integration/font-optimization/pages/index.js new file mode 100644 index 0000000000000..39cf2d1f7b376 --- /dev/null +++ b/test/integration/font-optimization/pages/index.js @@ -0,0 +1,7 @@ +import React from 'react' + +const Page = () => { + return
Hi!
+} + +export default Page diff --git a/test/integration/font-optimization/pages/stars.js b/test/integration/font-optimization/pages/stars.js new file mode 100644 index 0000000000000..d38e96c4ea4f7 --- /dev/null +++ b/test/integration/font-optimization/pages/stars.js @@ -0,0 +1,26 @@ +import Head from 'next/head' + +function Home({ stars }) { + return ( +
+ + Create Next App + + + + +
+
Next stars: {stars}
+
+
+ ) +} + +Home.getInitialProps = async () => { + return { stars: Math.random() * 1000 } +} + +export default Home diff --git a/test/integration/font-optimization/pages/static-head.js b/test/integration/font-optimization/pages/static-head.js new file mode 100644 index 0000000000000..f56ef406776c3 --- /dev/null +++ b/test/integration/font-optimization/pages/static-head.js @@ -0,0 +1,18 @@ +import React from 'react' +import Head from 'next/head' + +const Page = () => { + return ( + <> + + + +
Hi!
+ + ) +} + +export default Page diff --git a/test/integration/font-optimization/server.js b/test/integration/font-optimization/server.js new file mode 100644 index 0000000000000..6a98fa3d30806 --- /dev/null +++ b/test/integration/font-optimization/server.js @@ -0,0 +1,111 @@ +const http = require('http') +const url = require('url') +const fs = require('fs') +const path = require('path') +const server = http.createServer(async (req, res) => { + let { pathname } = url.parse(req.url) + pathname = pathname.replace(/\/$/, '') + let isDataReq = false + if (pathname.startsWith('/_next/data')) { + isDataReq = true + pathname = pathname + .replace(`/_next/data/${process.env.BUILD_ID}/`, '/') + .replace(/\.json$/, '') + } + console.log('serving', pathname) + + if (pathname === '/favicon.ico') { + res.statusCode = 404 + return res.end() + } + + if (pathname.startsWith('/_next/static/')) { + res.write( + fs.readFileSync( + path.join( + __dirname, + './.next/static/', + decodeURI(pathname.slice('/_next/static/'.length)) + ), + 'utf8' + ) + ) + return res.end() + } else { + const ext = isDataReq ? 'json' : 'html' + if ( + fs.existsSync( + path.join(__dirname, `./.next/serverless/pages${pathname}.${ext}`) + ) + ) { + res.write( + fs.readFileSync( + path.join(__dirname, `./.next/serverless/pages${pathname}.${ext}`), + 'utf8' + ) + ) + return res.end() + } + + let re + try { + re = require(`./.next/serverless/pages${pathname}`) + } catch { + const d = decodeURI(pathname) + if ( + fs.existsSync( + path.join(__dirname, `./.next/serverless/pages${d}.${ext}`) + ) + ) { + res.write( + fs.readFileSync( + path.join(__dirname, `./.next/serverless/pages${d}.${ext}`), + 'utf8' + ) + ) + return res.end() + } + + const routesManifest = require('./.next/routes-manifest.json') + const { dynamicRoutes } = routesManifest + dynamicRoutes.some(({ page, regex }) => { + if (new RegExp(regex).test(pathname)) { + if ( + fs.existsSync( + path.join(__dirname, `./.next/serverless/pages${page}.${ext}`) + ) + ) { + res.write( + fs.readFileSync( + path.join(__dirname, `./.next/serverless/pages${page}.${ext}`), + 'utf8' + ) + ) + res.end() + return true + } + + re = require(`./.next/serverless/pages${page}`) + return true + } + return false + }) + } + if (!res.finished) { + try { + return await (typeof re.render === 'function' + ? re.render(req, res) + : re.default(req, res)) + } catch (e) { + console.log('FAIL_FUNCTION', e) + res.statusCode = 500 + res.write('FAIL_FUNCTION') + res.end() + } + } + } +}) + +server.listen(process.env.PORT, () => { + console.log('ready on', process.env.PORT) +}) diff --git a/test/integration/font-optimization/test/index.test.js b/test/integration/font-optimization/test/index.test.js new file mode 100644 index 0000000000000..49d66ee869f88 --- /dev/null +++ b/test/integration/font-optimization/test/index.test.js @@ -0,0 +1,129 @@ +/* eslint-env jest */ + +import { join } from 'path' +import { + killApp, + findPort, + nextStart, + nextBuild, + renderViaHTTP, + initNextServerScript, +} from 'next-test-utils' +import fs from 'fs-extra' + +jest.setTimeout(1000 * 30) + +const appDir = join(__dirname, '../') +const nextConfig = join(appDir, 'next.config.js') +let builtServerPagesDir +let builtPage +let appPort +let app + +const fsExists = (file) => + fs + .access(file) + .then(() => true) + .catch(() => false) + +async function getBuildId() { + return fs.readFile(join(appDir, '.next', 'BUILD_ID'), 'utf8') +} + +const startServerlessEmulator = async (dir, port) => { + const scriptPath = join(dir, 'server.js') + const env = Object.assign( + {}, + { ...process.env }, + { PORT: port, BUILD_ID: await getBuildId() } + ) + return initNextServerScript(scriptPath, /ready on/i, env) +} + +function runTests() { + it('should inline the google fonts for static pages', async () => { + const html = await renderViaHTTP(appPort, '/index') + expect(await fsExists(builtPage('font-manifest.json'))).toBe(true) + expect(html).toContain( + '' + ) + expect(html).toMatch( + / ) } diff --git a/examples/basic-css/styles.module.css b/examples/basic-css/styles.module.css new file mode 100644 index 0000000000000..b841ef4cfaddb --- /dev/null +++ b/examples/basic-css/styles.module.css @@ -0,0 +1,10 @@ +.hello { + font: 15px Helvetica, Arial, sans-serif; + background: #eee; + padding: 100px; + text-align: center; + transition: 100ms ease-in background; +} +.hello:hover { + background: #ccc; +} diff --git a/examples/with-styled-jsx/.gitignore b/examples/with-styled-jsx/.gitignore new file mode 100644 index 0000000000000..1437c53f70bc2 --- /dev/null +++ b/examples/with-styled-jsx/.gitignore @@ -0,0 +1,34 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env.local +.env.development.local +.env.test.local +.env.production.local + +# vercel +.vercel diff --git a/examples/with-styled-jsx/README.md b/examples/with-styled-jsx/README.md new file mode 100644 index 0000000000000..7a546cd5a6d00 --- /dev/null +++ b/examples/with-styled-jsx/README.md @@ -0,0 +1,21 @@ +# styled-jsx example + +Next.js ships with [styled-jsx](https://github.com/vercel/styled-jsx) allowing you to write scoped styled components with full CSS support. This is important for the modularity and code size of your bundles and also for the learning curve of the framework. If you know CSS you can write `styled-jsx` right away. + +## Deploy your own + +Deploy the example using [Vercel](https://vercel.com): + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/with-styled-jsx) + +## How to use + +Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: + +```bash +npx create-next-app --example with-styled-jsx with-styled-jsx-app +# or +yarn create next-app --example with-styled-jsx with-styled-jsx-app +``` + +Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). diff --git a/examples/with-styled-jsx/package.json b/examples/with-styled-jsx/package.json new file mode 100644 index 0000000000000..277b1ef9e3502 --- /dev/null +++ b/examples/with-styled-jsx/package.json @@ -0,0 +1,15 @@ +{ + "name": "with-styled-jsx", + "version": "1.0.0", + "scripts": { + "dev": "next", + "build": "next build", + "start": "next start" + }, + "dependencies": { + "next": "latest", + "react": "^16.7.0", + "react-dom": "^16.7.0" + }, + "license": "MIT" +} diff --git a/examples/with-styled-jsx/pages/index.js b/examples/with-styled-jsx/pages/index.js new file mode 100644 index 0000000000000..badc024217198 --- /dev/null +++ b/examples/with-styled-jsx/pages/index.js @@ -0,0 +1,20 @@ +export default function Home() { + return ( +
+

Hello World

+ + +
+ ) +} diff --git a/examples/with-tailwindcss-emotion/package.json b/examples/with-tailwindcss-emotion/package.json index 40bfdc65e128d..636be4197868e 100644 --- a/examples/with-tailwindcss-emotion/package.json +++ b/examples/with-tailwindcss-emotion/package.json @@ -22,6 +22,7 @@ "@tailwindcss/ui": "^0.2.2", "@tailwindcssinjs/macro": "^0.3.1", "babel-plugin-macros": "2.8.0", - "tailwindcss": "1.3.5" - } + "tailwindcss": "^1.6.0" + }, + "license": "MIT" } diff --git a/examples/with-tailwindcss-emotion/styles/base.css b/examples/with-tailwindcss-emotion/styles/base.css index db3ac19346bad..37bb774245337 100644 --- a/examples/with-tailwindcss-emotion/styles/base.css +++ b/examples/with-tailwindcss-emotion/styles/base.css @@ -380,7 +380,6 @@ pre { button { background-color: transparent; background-image: none; - padding: 0; } /** @@ -484,11 +483,6 @@ textarea { resize: vertical; } -input::-webkit-input-placeholder, -textarea::-webkit-input-placeholder { - color: #a0aec0; -} - input::-moz-placeholder, textarea::-moz-placeholder { color: #a0aec0; @@ -603,3 +597,101 @@ video { max-width: 100%; height: auto; } + +@-webkit-keyframes spin { + from { + transform: rotate(0deg); + } + + to { + transform: rotate(360deg); + } +} + +@keyframes spin { + from { + transform: rotate(0deg); + } + + to { + transform: rotate(360deg); + } +} + +@-webkit-keyframes ping { + 0% { + transform: scale(1); + opacity: 1; + } + + 75%, + 100% { + transform: scale(2); + opacity: 0; + } +} + +@keyframes ping { + 0% { + transform: scale(1); + opacity: 1; + } + + 75%, + 100% { + transform: scale(2); + opacity: 0; + } +} + +@-webkit-keyframes pulse { + 0%, + 100% { + opacity: 1; + } + + 50% { + opacity: 0.5; + } +} + +@keyframes pulse { + 0%, + 100% { + opacity: 1; + } + + 50% { + opacity: 0.5; + } +} + +@-webkit-keyframes bounce { + 0%, + 100% { + transform: translateY(-25%); + -webkit-animation-timing-function: cubic-bezier(0.8, 0, 1, 1); + animation-timing-function: cubic-bezier(0.8, 0, 1, 1); + } + + 50% { + transform: translateY(0); + -webkit-animation-timing-function: cubic-bezier(0, 0, 0.2, 1); + animation-timing-function: cubic-bezier(0, 0, 0.2, 1); + } +} + +@keyframes bounce { + 0%, + 100% { + transform: translateY(-25%); + -webkit-animation-timing-function: cubic-bezier(0.8, 0, 1, 1); + animation-timing-function: cubic-bezier(0.8, 0, 1, 1); + } + + 50% { + transform: translateY(0); + -webkit-animation-timing-function: cubic-bezier(0, 0, 0.2, 1); + animation-timing-function: cubic-bezier(0, 0, 0.2, 1); + } +} diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index 8c7b129a9d5e7..6aa2bd510adff 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -7,12 +7,14 @@ "start": "next start" }, "dependencies": { - "next": "^9.2.0", - "react": "^16.12.0", - "react-dom": "^16.12.0" + "next": "latest", + "react": "^16.13.1", + "react-dom": "^16.13.1" }, "devDependencies": { + "postcss-flexbugs-fixes": "4.2.1", "postcss-preset-env": "^6.7.0", - "tailwindcss": "^1.4.0" - } + "tailwindcss": "^1.6.0" + }, + "license": "MIT" } diff --git a/examples/with-tailwindcss/pages/index.js b/examples/with-tailwindcss/pages/index.js index 08f65189f1421..bcd5455cdb619 100644 --- a/examples/with-tailwindcss/pages/index.js +++ b/examples/with-tailwindcss/pages/index.js @@ -4,8 +4,10 @@ export default function IndexPage() { return (
- + {close && ( + + )}
) } diff --git a/packages/react-dev-overlay/src/internal/container/Errors.tsx b/packages/react-dev-overlay/src/internal/container/Errors.tsx index 951e414f50a88..d1e0d002ee0c3 100644 --- a/packages/react-dev-overlay/src/internal/container/Errors.tsx +++ b/packages/react-dev-overlay/src/internal/container/Errors.tsx @@ -252,14 +252,14 @@ export const Errors: React.FC = function Errors({ errors }) { type="error" aria-labelledby="nextjs__container_errors_label" aria-describedby="nextjs__container_errors_desc" - onClose={minimize} + onClose={!isServerError && minimize} > 0 ? previous : null} next={activeIdx < readyErrors.length - 1 ? next : null} - close={minimize} + close={!isServerError && minimize} > {activeIdx + 1} of{' '} From dcb69ee92f9d8bac28f7c53d7ded30919931cf3d Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Thu, 30 Jul 2020 02:55:23 -0400 Subject: [PATCH 67/90] Strictly type `react-dev-overlay` (#15669) Fixes #15668 --- packages/react-dev-overlay/src/client.ts | 4 +- .../src/internal/ReactDevOverlay.tsx | 6 +- .../react-dev-overlay/src/internal/bus.ts | 2 +- .../components/CodeFrame/CodeFrame.tsx | 4 +- .../src/internal/components/Dialog/Dialog.tsx | 7 ++- .../LeftRightDialogHeader.tsx | 22 ++++--- .../internal/components/Overlay/Overlay.tsx | 6 +- .../src/internal/components/ShadowPortal.tsx | 2 +- .../src/internal/container/Errors.tsx | 6 +- .../src/internal/container/RuntimeError.tsx | 6 +- .../src/internal/helpers/launchEditor.ts | 63 +++++++------------ .../src/internal/helpers/nodeStackFrames.ts | 2 +- .../src/internal/helpers/parseStack.ts | 4 +- .../src/internal/helpers/stack-frame.ts | 4 +- .../internal/hooks/use-on-click-outside.ts | 12 ++-- packages/react-dev-overlay/src/middleware.ts | 11 +++- packages/react-dev-overlay/tsconfig.json | 1 + 17 files changed, 78 insertions(+), 84 deletions(-) diff --git a/packages/react-dev-overlay/src/client.ts b/packages/react-dev-overlay/src/client.ts index 52104d0b1439b..fa204341d73f1 100644 --- a/packages/react-dev-overlay/src/client.ts +++ b/packages/react-dev-overlay/src/client.ts @@ -15,7 +15,7 @@ function onUnhandledError(ev: ErrorEvent) { Bus.emit({ type: Bus.TYPE_UNHANDLED_ERROR, reason: error, - frames: parseStack(e.stack), + frames: parseStack(e.stack!), }) } @@ -34,7 +34,7 @@ function onUnhandledRejection(ev: PromiseRejectionEvent) { Bus.emit({ type: Bus.TYPE_UNHANDLED_REJECTION, reason: reason, - frames: parseStack(e.stack), + frames: parseStack(e.stack!), }) } diff --git a/packages/react-dev-overlay/src/internal/ReactDevOverlay.tsx b/packages/react-dev-overlay/src/internal/ReactDevOverlay.tsx index baf04aed7a406..7500e15983246 100644 --- a/packages/react-dev-overlay/src/internal/ReactDevOverlay.tsx +++ b/packages/react-dev-overlay/src/internal/ReactDevOverlay.tsx @@ -41,7 +41,9 @@ function reducer(state: OverlayState, ev: Bus.BusEvent): OverlayState { } } -function ReactDevOverlay({ children }) { +const ReactDevOverlay: React.FunctionComponent = function ReactDevOverlay({ + children, +}) { const [state, dispatch] = React.useReducer< React.Reducer >(reducer, { nextId: 1, buildError: null, errors: [] }) @@ -76,7 +78,7 @@ function ReactDevOverlay({ children }) { {hasBuildError ? ( - + ) : hasRuntimeErrors ? ( ) : undefined} diff --git a/packages/react-dev-overlay/src/internal/bus.ts b/packages/react-dev-overlay/src/internal/bus.ts index b2a4fc213c3e3..ebf32812ab695 100644 --- a/packages/react-dev-overlay/src/internal/bus.ts +++ b/packages/react-dev-overlay/src/internal/bus.ts @@ -45,7 +45,7 @@ function drain() { // event(s) Boolean(handlers.size) ) { - const ev = queue.shift() + const ev = queue.shift()! handlers.forEach((handler) => handler(ev)) } }, 1) diff --git a/packages/react-dev-overlay/src/internal/components/CodeFrame/CodeFrame.tsx b/packages/react-dev-overlay/src/internal/components/CodeFrame/CodeFrame.tsx index 0a333b8e2f127..2c4e31b6809ed 100644 --- a/packages/react-dev-overlay/src/internal/components/CodeFrame/CodeFrame.tsx +++ b/packages/react-dev-overlay/src/internal/components/CodeFrame/CodeFrame.tsx @@ -16,7 +16,7 @@ export const CodeFrame: React.FC = function CodeFrame({ const prefixLength = lines .map((line) => /^>? +\d+ +\| ( *)/.exec(stripAnsi(line))) .filter(Boolean) - .map((v) => v.pop()) + .map((v) => v!.pop()!) .reduce((c, n) => (isNaN(c) ? n.length : Math.min(c, n.length)), NaN) if (prefixLength > 1) { @@ -43,7 +43,7 @@ export const CodeFrame: React.FC = function CodeFrame({ const open = React.useCallback(() => { const params = new URLSearchParams() for (const key in stackFrame) { - params.append(key, (stackFrame[key] ?? '').toString()) + params.append(key, ((stackFrame as any)[key] ?? '').toString()) } self diff --git a/packages/react-dev-overlay/src/internal/components/Dialog/Dialog.tsx b/packages/react-dev-overlay/src/internal/components/Dialog/Dialog.tsx index e1891f9e695ac..e01f36c2c3341 100644 --- a/packages/react-dev-overlay/src/internal/components/Dialog/Dialog.tsx +++ b/packages/react-dev-overlay/src/internal/components/Dialog/Dialog.tsx @@ -14,7 +14,7 @@ const Dialog: React.FC = function Dialog({ onClose, ...props }) { - const [dialog, setDialog] = React.useState(null) + const [dialog, setDialog] = React.useState(null) const onDialog = React.useCallback((node) => { setDialog(node) }, []) @@ -47,8 +47,9 @@ const Dialog: React.FC = function Dialog({ } } - shadowRoot.addEventListener('keydown', handler) - return () => shadowRoot.removeEventListener('keydown', handler) + shadowRoot.addEventListener('keydown', handler as EventListener) + return () => + shadowRoot.removeEventListener('keydown', handler as EventListener) }, [dialog]) return ( diff --git a/packages/react-dev-overlay/src/internal/components/LeftRightDialogHeader/LeftRightDialogHeader.tsx b/packages/react-dev-overlay/src/internal/components/LeftRightDialogHeader/LeftRightDialogHeader.tsx index c1bc4d31fc63d..628f8e725c162 100644 --- a/packages/react-dev-overlay/src/internal/components/LeftRightDialogHeader/LeftRightDialogHeader.tsx +++ b/packages/react-dev-overlay/src/internal/components/LeftRightDialogHeader/LeftRightDialogHeader.tsx @@ -14,9 +14,9 @@ const LeftRightDialogHeader: React.FC = function Lef next, close, }) { - const buttonLeft = React.useRef() - const buttonRight = React.useRef() - const buttonClose = React.useRef() + const buttonLeft = React.useRef(null) + const buttonRight = React.useRef(null) + const buttonClose = React.useRef(null) const [nav, setNav] = React.useState(null) const onNav = React.useCallback((el: HTMLElement) => { @@ -54,16 +54,18 @@ const LeftRightDialogHeader: React.FC = function Lef } } - close() + if (close) { + close() + } } } - root.addEventListener('keydown', handler) + root.addEventListener('keydown', handler as EventListener) if (root !== d) { d.addEventListener('keydown', handler) } return function () { - root.removeEventListener('keydown', handler) + root.removeEventListener('keydown', handler as EventListener) if (root !== d) { d.removeEventListener('keydown', handler) } @@ -83,11 +85,11 @@ const LeftRightDialogHeader: React.FC = function Lef const a = root.activeElement if (previous == null) { - if (a === buttonLeft.current) { + if (buttonLeft.current && a === buttonLeft.current) { buttonLeft.current.blur() } } else if (next == null) { - if (a === buttonRight.current) { + if (buttonRight.current && a === buttonRight.current) { buttonRight.current.blur() } } @@ -142,7 +144,7 @@ const LeftRightDialogHeader: React.FC = function Lef   {children} - {close && ( + {close ? ( - )} + ) : null} ) } diff --git a/packages/react-dev-overlay/src/internal/components/Overlay/Overlay.tsx b/packages/react-dev-overlay/src/internal/components/Overlay/Overlay.tsx index 0c6c4db5d3fa1..3d3bdaae39935 100644 --- a/packages/react-dev-overlay/src/internal/components/Overlay/Overlay.tsx +++ b/packages/react-dev-overlay/src/internal/components/Overlay/Overlay.tsx @@ -1,4 +1,6 @@ +// @ts-ignore import allyDisable from 'ally.js/maintain/disabled' +// @ts-ignore import allyTrap from 'ally.js/maintain/tab-focus' import * as React from 'react' import { lock, unlock } from './body-locker' @@ -17,8 +19,8 @@ const Overlay: React.FC = function Overlay({ } }, []) - const [overlay, setOverlay] = React.useState(null) - const onOverlay = React.useCallback((el: HTMLElement) => { + const [overlay, setOverlay] = React.useState(null) + const onOverlay = React.useCallback((el: HTMLDivElement) => { setOverlay(el) }, []) diff --git a/packages/react-dev-overlay/src/internal/components/ShadowPortal.tsx b/packages/react-dev-overlay/src/internal/components/ShadowPortal.tsx index 8de6d76af8edd..228660da6dadb 100644 --- a/packages/react-dev-overlay/src/internal/components/ShadowPortal.tsx +++ b/packages/react-dev-overlay/src/internal/components/ShadowPortal.tsx @@ -14,7 +14,7 @@ export const ShadowPortal: React.FC = function Portal({ let [, forceUpdate] = React.useState() React.useLayoutEffect(() => { - const ownerDocument = mountNode.current.ownerDocument + const ownerDocument = mountNode.current!.ownerDocument! portalNode.current = ownerDocument.createElement('nextjs-portal') shadowNode.current = portalNode.current.attachShadow({ mode: 'open' }) ownerDocument.body.appendChild(portalNode.current) diff --git a/packages/react-dev-overlay/src/internal/container/Errors.tsx b/packages/react-dev-overlay/src/internal/container/Errors.tsx index d1e0d002ee0c3..63d5e911c2d84 100644 --- a/packages/react-dev-overlay/src/internal/container/Errors.tsx +++ b/packages/react-dev-overlay/src/internal/container/Errors.tsx @@ -209,7 +209,7 @@ export const Errors: React.FC = function Errors({ errors }) { // This component shouldn't be rendered with no errors, but if it is, let's // handle it gracefully by rendering nothing. - if (errors.length < 1) { + if (errors.length < 1 || activeError == null) { return null } @@ -252,14 +252,14 @@ export const Errors: React.FC = function Errors({ errors }) { type="error" aria-labelledby="nextjs__container_errors_label" aria-describedby="nextjs__container_errors_desc" - onClose={!isServerError && minimize} + onClose={isServerError ? undefined : minimize} > 0 ? previous : null} next={activeIdx < readyErrors.length - 1 ? next : null} - close={!isServerError && minimize} + close={isServerError ? undefined : minimize} > {activeIdx + 1} of{' '} diff --git a/packages/react-dev-overlay/src/internal/container/RuntimeError.tsx b/packages/react-dev-overlay/src/internal/container/RuntimeError.tsx index 07cecff277b52..e744355a7d168 100644 --- a/packages/react-dev-overlay/src/internal/container/RuntimeError.tsx +++ b/packages/react-dev-overlay/src/internal/container/RuntimeError.tsx @@ -21,7 +21,7 @@ const CallStackFrame: React.FC<{ const params = new URLSearchParams() for (const key in f) { - params.append(key, (f[key] ?? '').toString()) + params.append(key, ((f as any)[key] ?? '').toString()) } self @@ -134,8 +134,8 @@ const RuntimeError: React.FC = function RuntimeError({ /> ))} ) : undefined} diff --git a/packages/react-dev-overlay/src/internal/helpers/launchEditor.ts b/packages/react-dev-overlay/src/internal/helpers/launchEditor.ts index d76ff558678c9..8efcf9d9e8a57 100644 --- a/packages/react-dev-overlay/src/internal/helpers/launchEditor.ts +++ b/packages/react-dev-overlay/src/internal/helpers/launchEditor.ts @@ -26,9 +26,10 @@ import child_process from 'child_process' import fs from 'fs' import os from 'os' import path from 'path' +// @ts-ignore import shellQuote from 'shell-quote' -function isTerminalEditor(editor) { +function isTerminalEditor(editor: string) { switch (editor) { case 'vi': case 'vim': @@ -135,20 +136,12 @@ const COMMON_EDITORS_WIN = [ // alphanumeric characters, periods, dashes, slashes, and underscores. const WINDOWS_FILE_NAME_ACCESS_LIST = /^([A-Za-z]:[/\\])?(?:[\x2D-9A-Z\\_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7B9\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDF00-\uDF1C\uDF27\uDF30-\uDF45]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF1A]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDE9D\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFF1]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D])+$/ -function addWorkspaceToArgumentsIfExists(args, workspace) { - if (workspace) { - args.unshift(workspace) - } - return args -} - function getArgumentsForLineNumber( - editor, - fileName, - lineNumber, - colNumber, - workspace -) { + editor: string, + fileName: string, + lineNumber: number, + colNumber: number +): string[] { const editorBasename = path.basename(editor).replace(/\.(exe|cmd|bat)$/i, '') switch (editorBasename) { case 'atom': @@ -179,7 +172,7 @@ function getArgumentsForLineNumber( case 'rmate': case 'mate': case 'mine': { - return ['--line', lineNumber, fileName] + return ['--line', lineNumber.toString(), fileName] } case 'code': case 'Code': @@ -187,10 +180,7 @@ function getArgumentsForLineNumber( case 'Code - Insiders': case 'vscodium': case 'VSCodium': { - return addWorkspaceToArgumentsIfExists( - ['-g', fileName + ':' + lineNumber + ':' + colNumber], - workspace - ) + return ['-g', fileName + ':' + lineNumber + ':' + colNumber] } case 'appcode': case 'clion': @@ -209,10 +199,7 @@ function getArgumentsForLineNumber( case 'goland64': case 'rider': case 'rider64': { - return addWorkspaceToArgumentsIfExists( - ['--line', lineNumber, fileName], - workspace - ) + return ['--line', lineNumber.toString(), fileName] } default: { // For all others, drop the lineNumber until we have @@ -223,7 +210,7 @@ function getArgumentsForLineNumber( } } -function guessEditor() { +function guessEditor(): string | null { // Explicit config always wins if (process.env.REACT_EDITOR) { return shellQuote.parse(process.env.REACT_EDITOR) @@ -239,7 +226,7 @@ function guessEditor() { for (let i = 0; i < processNames.length; i++) { const processName = processNames[i] if (output.indexOf(processName) !== -1) { - return [COMMON_EDITORS_MACOS[processName]] + return (COMMON_EDITORS_MACOS as any)[processName] } } } else if (process.platform === 'win32') { @@ -255,7 +242,7 @@ function guessEditor() { const processPath = runningProcesses[i].trim() const processName = path.basename(processPath) if (COMMON_EDITORS_WIN.indexOf(processName) !== -1) { - return [processPath] + return processPath } } } else if (process.platform === 'linux') { @@ -269,7 +256,7 @@ function guessEditor() { for (let i = 0; i < processNames.length; i++) { const processName = processNames[i] if (output.indexOf(processName) !== -1) { - return [COMMON_EDITORS_LINUX[processName]] + return (COMMON_EDITORS_LINUX as any)[processName] as string } } } @@ -279,15 +266,15 @@ function guessEditor() { // Last resort, use old skool env vars if (process.env.VISUAL) { - return [process.env.VISUAL] + return process.env.VISUAL } else if (process.env.EDITOR) { - return [process.env.EDITOR] + return process.env.EDITOR } - return [null] + return null } -function printInstructions(fileName, errorMessage) { +function printInstructions(fileName: string, errorMessage: string | null) { console.log() console.log( chalk.red('Could not open ' + path.basename(fileName) + ' in the editor.') @@ -330,7 +317,8 @@ function launchEditor(fileName: string, lineNumber: number, colNumber: number) { colNumber = 1 } - let [editor, ...args] = guessEditor() + const editor = guessEditor() + let args: string[] = [] if (!editor) { printInstructions(fileName, null) @@ -378,22 +366,15 @@ function launchEditor(fileName: string, lineNumber: number, colNumber: number) { return } - let workspace = null if (lineNumber) { args = args.concat( - getArgumentsForLineNumber( - editor, - fileName, - lineNumber, - colNumber, - workspace - ) + getArgumentsForLineNumber(editor, fileName, lineNumber, colNumber) ) } else { args.push(fileName) } - let p: child_process.ChildProcess + let p: child_process.ChildProcess | undefined = undefined if (process.platform === 'win32') { // On Windows, launch the editor in a shell because spawn can only // launch .exe files. diff --git a/packages/react-dev-overlay/src/internal/helpers/nodeStackFrames.ts b/packages/react-dev-overlay/src/internal/helpers/nodeStackFrames.ts index 41aeec9209cd7..0fa8601873221 100644 --- a/packages/react-dev-overlay/src/internal/helpers/nodeStackFrames.ts +++ b/packages/react-dev-overlay/src/internal/helpers/nodeStackFrames.ts @@ -35,7 +35,7 @@ export function getNodeError(error: Error): Error { n.name = error.name try { - n.stack = parse(error.stack) + n.stack = parse(error.stack!) .map(getFilesystemFrame) .map((f) => { let str = ` at ${f.methodName}` diff --git a/packages/react-dev-overlay/src/internal/helpers/parseStack.ts b/packages/react-dev-overlay/src/internal/helpers/parseStack.ts index f329dd61263cf..7e6c1d1826089 100644 --- a/packages/react-dev-overlay/src/internal/helpers/parseStack.ts +++ b/packages/react-dev-overlay/src/internal/helpers/parseStack.ts @@ -6,14 +6,14 @@ export function parseStack(stack: string): StackFrame[] { const frames = parse(stack) return frames.map((frame) => { try { - const url = new URL(frame.file) + const url = new URL(frame.file!) const res = regexNextStatic.exec(url.pathname) if (res) { const distDir = process.env.__NEXT_DIST_DIR ?.replace(/\\/g, '/') ?.replace(/\/$/, '') if (distDir) { - frame.file = 'file://' + distDir.concat(res.pop()) + frame.file = 'file://' + distDir.concat(res.pop()!) } } } catch {} diff --git a/packages/react-dev-overlay/src/internal/helpers/stack-frame.ts b/packages/react-dev-overlay/src/internal/helpers/stack-frame.ts index fb3cda027cc17..37d3392b288f3 100644 --- a/packages/react-dev-overlay/src/internal/helpers/stack-frame.ts +++ b/packages/react-dev-overlay/src/internal/helpers/stack-frame.ts @@ -47,7 +47,7 @@ export function getOriginalStackFrame( const params = new URLSearchParams() params.append('isServerSide', String(isServerSide)) for (const key in source) { - params.append(key, (source[key] ?? '').toString()) + params.append(key, ((source as any)[key] ?? '').toString()) } const controller = new AbortController() @@ -114,7 +114,7 @@ export function getOriginalStackFrame( export function getFrameSource(frame: StackFrame): string { let str = '' try { - const u = new URL(frame.file) + const u = new URL(frame.file!) // Strip the origin for same-origin scripts. if ( diff --git a/packages/react-dev-overlay/src/internal/hooks/use-on-click-outside.ts b/packages/react-dev-overlay/src/internal/hooks/use-on-click-outside.ts index 8c73686882052..fb2add61d53c1 100644 --- a/packages/react-dev-overlay/src/internal/hooks/use-on-click-outside.ts +++ b/packages/react-dev-overlay/src/internal/hooks/use-on-click-outside.ts @@ -2,10 +2,10 @@ import * as React from 'react' export function useOnClickOutside( el: Node | null, - handler: (e: MouseEvent | TouchEvent) => void + handler: ((e: MouseEvent | TouchEvent) => void) | undefined ) { React.useEffect(() => { - if (el == null) { + if (el == null || handler == null) { return } @@ -19,11 +19,11 @@ export function useOnClickOutside( } const root = el.getRootNode() - root.addEventListener('mousedown', listener) - root.addEventListener('touchstart', listener) + root.addEventListener('mousedown', listener as EventListener) + root.addEventListener('touchstart', listener as EventListener) return function () { - root.removeEventListener('mousedown', listener) - root.removeEventListener('touchstart', listener) + root.removeEventListener('mousedown', listener as EventListener) + root.removeEventListener('touchstart', listener as EventListener) } }, [handler, el]) } diff --git a/packages/react-dev-overlay/src/middleware.ts b/packages/react-dev-overlay/src/middleware.ts index 1b02b9363650d..d55364ff91b31 100644 --- a/packages/react-dev-overlay/src/middleware.ts +++ b/packages/react-dev-overlay/src/middleware.ts @@ -10,6 +10,7 @@ import { import { StackFrame } from 'stacktrace-parser' import url from 'url' // eslint-disable-next-line import/no-extraneous-dependencies +// @ts-ignore import webpack from 'webpack' import { getRawSourceMap } from './internal/helpers/getRawSourceMap' import { launchEditor } from './internal/helpers/launchEditor' @@ -97,6 +98,10 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) { const compilation = isServerSide ? options.serverStats()?.compilation : options.stats()?.compilation + if (compilation == null) { + return null + } + const module = [...compilation.modules].find( (searchModule) => searchModule.id === id ) @@ -112,7 +117,7 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) { res: ServerResponse, next: Function ) { - const { pathname, query } = url.parse(req.url, true) + const { pathname, query } = url.parse(req.url!, true) if (pathname === '/__nextjs_original-stack-frame') { const frame = (query as unknown) as StackFrame & { @@ -171,7 +176,7 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) { const consumer = await new SourceMapConsumer(source.map()) pos = consumer.originalPositionFor({ line: frameLine, - column: frameColumn, + column: frameColumn ?? 0, }) if (pos.source) { posSourceContent = @@ -215,7 +220,7 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) { pos.line ? (codeFrameColumns( posSourceContent, - { start: { line: pos.line, column: pos.column } }, + { start: { line: pos.line, column: pos.column ?? 0 } }, { forceColor: true } ) as string) : null diff --git a/packages/react-dev-overlay/tsconfig.json b/packages/react-dev-overlay/tsconfig.json index 198c585c9b657..747a7eb4f1dae 100644 --- a/packages/react-dev-overlay/tsconfig.json +++ b/packages/react-dev-overlay/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "sourceMap": true, + "strict": true, "esModuleInterop": true, "target": "es3", "lib": ["dom"], From 73303a71aef19e2e4578ce5504dadecfb6560179 Mon Sep 17 00:00:00 2001 From: Luis Alvarez D Date: Thu, 30 Jul 2020 10:59:27 -0500 Subject: [PATCH 68/90] [Examples] Fix with-sentry (#15694) --- examples/with-sentry/pages/_error.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/with-sentry/pages/_error.js b/examples/with-sentry/pages/_error.js index 0b38c8d7b7776..5410de207dd19 100644 --- a/examples/with-sentry/pages/_error.js +++ b/examples/with-sentry/pages/_error.js @@ -1,14 +1,12 @@ import NextErrorComponent from 'next/error' import * as Sentry from '@sentry/node' -const MyError = async ({ statusCode, hasGetInitialPropsRun, err }) => { +const MyError = ({ statusCode, hasGetInitialPropsRun, err }) => { if (!hasGetInitialPropsRun && err) { // getInitialProps is not called in case of // https://github.com/vercel/next.js/issues/8592. As a workaround, we pass // err via _app.js so it can be captured Sentry.captureException(err) - // flush is needed after calling captureException to send server side errors to Sentry, otherwise the serverless function will exit before it's sent - await Sentry.flush(2000) } return From 17d7f03f2b82c015ad087d7049b2a7e0a40c1142 Mon Sep 17 00:00:00 2001 From: Luis Alvarez D Date: Thu, 30 Jul 2020 13:44:44 -0500 Subject: [PATCH 69/90] [Docs] Use `next dev` for the getting started page (#15705) --- docs/getting-started.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 32440f9c42cc6..f418bab6d9f1c 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -41,7 +41,7 @@ Open `package.json` and add the following `scripts`: ```json "scripts": { - "dev": "next", + "dev": "next dev", "build": "next build", "start": "next start" } @@ -49,11 +49,11 @@ Open `package.json` and add the following `scripts`: These scripts refer to the different stages of developing an application: -- `dev` - Runs `next` which starts Next.js in development mode -- `build` - Runs `next build` which builds the application for production usage -- `start` - Runs `next start` which starts a Next.js production server +- `dev` - Runs [`next dev`](/docs/api-reference/cli#development) which starts Next.js in development mode +- `build` - Runs [`next build`](/docs/api-reference/cli#build) which builds the application for production usage +- `start` - Runs [`next start`](/docs/api-reference/cli#production) which starts a Next.js production server -Next.js is built around the concept of pages. A page is a [React Component](https://reactjs.org/docs/components-and-props.html) exported from a `.js`, `.jsx`, `.ts`, or `.tsx` file in the `pages` directory. +Next.js is built around the concept of [pages](/docs/basic-features/pages.md). A page is a [React Component](https://reactjs.org/docs/components-and-props.html) exported from a `.js`, `.jsx`, `.ts`, or `.tsx` file in the `pages` directory. Pages are associated with a route based on their file name. For example `pages/about.js` is mapped to `/about`. You can even add dynamic route parameters with the filename. From 9d68a363b6f3757ef8517fd1a303d97dc52378d2 Mon Sep 17 00:00:00 2001 From: matamatanot <39780486+matamatanot@users.noreply.github.com> Date: Fri, 31 Jul 2020 04:14:27 +0900 Subject: [PATCH 70/90] Docs smart-cdn link is dead. (#15707) You have been redirected to the`/home` page. I'm not sure if that's correct, but it's been fixed to move the link to the document. https://vercel.com/smart-cdn https://vercel.com/docs/v2/edge-network/overview --- docs/deployment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/deployment.md b/docs/deployment.md index 9caaad022e82b..eddcc9acd5949 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -40,7 +40,7 @@ By using the DPS workflow, in addition to doing _code reviews_, you can do _depl For example, the [hybrid pages](/docs/basic-features/pages.md) approach is fully supported out of the box. - Every page can either use [Static Generation](/docs/basic-features/pages.md#static-generation) or [Server-Side Rendering](/docs/basic-features/pages.md#server-side-rendering). -- Pages that use [Static Generation](/docs/basic-features/pages.md#static-generation) and assets (JS, CSS, images, fonts, etc) will automatically be served from the [Vercel Smart CDN](https://vercel.com/smart-cdn), which is blazingly fast. +- Pages that use [Static Generation](/docs/basic-features/pages.md#static-generation) and assets (JS, CSS, images, fonts, etc) will automatically be served from the [Vercel's Edge Network](https://vercel.com/docs/v2/edge-network/overview), which is blazingly fast. - Pages that use [Server-Side Rendering](/docs/basic-features/pages.md#server-side-rendering) and [API routes](/docs/api-routes/introduction.md) will automatically become isolated Serverless Functions. This allows page rendering and API requests to scale infinitely. ### Custom Domains, Environment Variables, Automatic HTTPS, and more From 766fef2271475bb2d7e9b9805d505f2dcee17656 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 30 Jul 2020 16:15:29 -0500 Subject: [PATCH 71/90] Document regex support for custom routes (#15714) This adds an example of using regex matching for custom routes Fixes https://github.com/vercel/next.js/issues/15712 --- docs/api-reference/next.config.js/headers.md | 22 +++++++++++++++++++ .../api-reference/next.config.js/redirects.md | 18 +++++++++++++++ docs/api-reference/next.config.js/rewrites.md | 17 ++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/docs/api-reference/next.config.js/headers.md b/docs/api-reference/next.config.js/headers.md index e09c1bba8d5ac..414a93508d4fd 100644 --- a/docs/api-reference/next.config.js/headers.md +++ b/docs/api-reference/next.config.js/headers.md @@ -90,6 +90,28 @@ module.exports = { } ``` +### Regex Path Matching + +To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`: + +```js +module.exports = { + async rewrites() { + return [ + { + source: '/blog/:post(\\d{1,})', + headers: [ + { + key: 'x-post', + value: ':post', + }, + ], + }, + ] + }, +} +``` + ### Headers with basePath support When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with headers each `source` is automatically prefixed with the `basePath` unless you add `basePath: false` to the header: diff --git a/docs/api-reference/next.config.js/redirects.md b/docs/api-reference/next.config.js/redirects.md index a564ab97db679..ba85250140aa4 100644 --- a/docs/api-reference/next.config.js/redirects.md +++ b/docs/api-reference/next.config.js/redirects.md @@ -66,6 +66,24 @@ module.exports = { } ``` +### Regex Path Matching + +To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`: + +```js +module.exports = { + async redirects() { + return [ + { + source: '/old-blog/:post(\\d{1,})', + destination: '/blog/:post', // Matched parameters can be used in the destination + permanent: false, + }, + ] + }, +} +``` + ### Redirects with basePath support When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with redirects each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the redirect: diff --git a/docs/api-reference/next.config.js/rewrites.md b/docs/api-reference/next.config.js/rewrites.md index 297e0579d2ebd..45e784cd15f80 100644 --- a/docs/api-reference/next.config.js/rewrites.md +++ b/docs/api-reference/next.config.js/rewrites.md @@ -69,6 +69,23 @@ module.exports = { } ``` +### Regex Path Matching + +To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`: + +```js +module.exports = { + async rewrites() { + return [ + { + source: '/old-blog/:post(\\d{1,})', + destination: '/blog/:post', // Matched parameters can be used in the destination + }, + ] + }, +} +``` + ## Rewriting to an external URL
From d97d045dfc7bbad53dfee8b092e1d95bcaf099f1 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Fri, 31 Jul 2020 05:22:32 +0200 Subject: [PATCH 72/90] Stabilize another test (#15697) Saw this one fail on azure --- .../test/index.test.js | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/test/integration/empty-object-getInitialProps/test/index.test.js b/test/integration/empty-object-getInitialProps/test/index.test.js index 8f65540e787d3..9a845fe7e92e1 100644 --- a/test/integration/empty-object-getInitialProps/test/index.test.js +++ b/test/integration/empty-object-getInitialProps/test/index.test.js @@ -8,6 +8,7 @@ import { launchApp, killApp, waitFor, + check, } from 'next-test-utils' jest.setTimeout(1000 * 60 * 2) @@ -49,20 +50,24 @@ describe('Empty Project', () => { it('should show empty object warning during client transition', async () => { const browser = await webdriver(appPort, '/static') - await browser.eval(`(function() { - window.gotWarn = false - const origWarn = console.warn - window.console.warn = function () { - if (arguments[0].match(/returned an empty object from \`getInitialProps\`/)) { - window.gotWarn = true + try { + await browser.eval(`(function() { + window.gotWarn = false + const origWarn = console.warn + window.console.warn = function () { + if (arguments[0].match(/returned an empty object from \`getInitialProps\`/)) { + window.gotWarn = true + } + origWarn.apply(this, arguments) } - origWarn.apply(this, arguments) - } - window.next.router.replace('/another') - })()`) - await waitFor(1000) - const gotWarn = await browser.eval(`window.gotWarn`) - expect(gotWarn).toBe(true) - await browser.close() + window.next.router.replace('/another') + })()`) + await check(async () => { + const gotWarn = await browser.eval(`window.gotWarn`) + return gotWarn ? 'pass' : 'fail' + }, 'pass') + } finally { + await browser.close() + } }) }) From 01662f1c79279a1710db5e3c8d2343a0c2f88320 Mon Sep 17 00:00:00 2001 From: Luis Alvarez D Date: Thu, 30 Jul 2020 22:40:40 -0500 Subject: [PATCH 73/90] [Docs] Add upgrade notes for Next.js 9.5 (#15703) Fixes https://github.com/vercel/next.js/issues/15719 --- docs/api-reference/next.config.js/basepath.md | 2 ++ docs/api-reference/next.config.js/headers.md | 2 ++ docs/api-reference/next.config.js/redirects.md | 2 ++ docs/api-reference/next.config.js/rewrites.md | 2 ++ docs/api-reference/next.config.js/trailing-slash.md | 2 ++ 5 files changed, 10 insertions(+) diff --git a/docs/api-reference/next.config.js/basepath.md b/docs/api-reference/next.config.js/basepath.md index 21bb8b032dbd6..3fa27af679389 100644 --- a/docs/api-reference/next.config.js/basepath.md +++ b/docs/api-reference/next.config.js/basepath.md @@ -4,6 +4,8 @@ description: Learn more about setting a base path in Next.js # Base Path +> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out. + To deploy a Next.js application under a sub-path of a domain you can use the `basePath` option. `basePath` allows you to set a path prefix for the application. For example `/docs` instead of `/` (the default). diff --git a/docs/api-reference/next.config.js/headers.md b/docs/api-reference/next.config.js/headers.md index 414a93508d4fd..4b854562e08e0 100644 --- a/docs/api-reference/next.config.js/headers.md +++ b/docs/api-reference/next.config.js/headers.md @@ -4,6 +4,8 @@ description: Add custom HTTP headers to your Next.js app. # Headers +> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out. + Headers allow you to set custom HTTP headers for an incoming request path. To set custom HTTP headers you can use the `headers` key in `next.config.js`: diff --git a/docs/api-reference/next.config.js/redirects.md b/docs/api-reference/next.config.js/redirects.md index ba85250140aa4..d1eb3929e8500 100644 --- a/docs/api-reference/next.config.js/redirects.md +++ b/docs/api-reference/next.config.js/redirects.md @@ -4,6 +4,8 @@ description: Add redirects to your Next.js app. # Redirects +> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out. + Redirects allow you to redirect an incoming request path to a different destination path. Redirects are only available on the Node.js environment and do not affect client-side routing. diff --git a/docs/api-reference/next.config.js/rewrites.md b/docs/api-reference/next.config.js/rewrites.md index 45e784cd15f80..c50bc290724e4 100644 --- a/docs/api-reference/next.config.js/rewrites.md +++ b/docs/api-reference/next.config.js/rewrites.md @@ -4,6 +4,8 @@ description: Add rewrites to your Next.js app. # Rewrites +> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out. +
Examples
    diff --git a/docs/api-reference/next.config.js/trailing-slash.md b/docs/api-reference/next.config.js/trailing-slash.md index c2a95c6cd39d2..4fad79dfcd24a 100644 --- a/docs/api-reference/next.config.js/trailing-slash.md +++ b/docs/api-reference/next.config.js/trailing-slash.md @@ -4,6 +4,8 @@ description: Configure Next.js pages to resolve with or without a trailing slash # Trailing Slash +> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out. + By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash. For example `/about/` will redirect to `/about`. You can configure this behavior to act the opposite way, where urls without trailing slashes are redirected to their counterparts with trailing slashes. Open `next.config.js` and add the `trailingSlash` config: From c9e379c3bf3c028900f0feb7876590cf85fdb199 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Fri, 31 Jul 2020 08:38:39 +0200 Subject: [PATCH 74/90] Fix wrong asPath on 404 (#15728) Caught this while reviewing router code for https://github.com/vercel/next.js/pull/15710 --- packages/next/client/index.js | 2 +- test/integration/basepath/test/index.test.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/client/index.js b/packages/next/client/index.js index 91a723c06738e..fc7d439a8a5f4 100644 --- a/packages/next/client/index.js +++ b/packages/next/client/index.js @@ -58,7 +58,7 @@ if ( page === '/_error' && hydrateProps && hydrateProps.pageProps && - hydrateProps.pageProps.statusCode === '404' + hydrateProps.pageProps.statusCode === 404 ) ) { asPath = delBasePath(asPath) diff --git a/test/integration/basepath/test/index.test.js b/test/integration/basepath/test/index.test.js index 2bddf06d05506..593d9b23e95e7 100644 --- a/test/integration/basepath/test/index.test.js +++ b/test/integration/basepath/test/index.test.js @@ -212,6 +212,7 @@ const runTests = (context, dev = false) => { it('should not update URL for a 404', async () => { const browser = await webdriver(context.appPort, '/missing') const pathname = await browser.eval(() => window.location.pathname) + expect(await browser.eval(() => window.next.router.asPath)).toBe('/missing') expect(pathname).toBe('/missing') }) From 1409cd6e3f098e720a713dcb963c8410b6897408 Mon Sep 17 00:00:00 2001 From: Jon Espen Kvisler Date: Fri, 31 Jul 2020 09:14:37 +0200 Subject: [PATCH 75/90] Update next-transpile-modules in with-react-intl example (#15730) next-transpile-modules needs to be updated to support Next.js 9.5 Closes #15725 --- examples/with-react-intl/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-react-intl/package.json b/examples/with-react-intl/package.json index 8c7ce45c3119b..c097fa35cd980 100644 --- a/examples/with-react-intl/package.json +++ b/examples/with-react-intl/package.json @@ -24,6 +24,6 @@ "license": "ISC", "devDependencies": { "cross-spawn": "7.0.3", - "next-transpile-modules": "^3.2.0" + "next-transpile-modules": "^4.0.2" } } From bcd1ba622e251b264c5b8e5149f7e6218a0df525 Mon Sep 17 00:00:00 2001 From: Rafau Date: Fri, 31 Jul 2020 10:50:54 +0200 Subject: [PATCH 76/90] [webpack5] Complile for ES5 (#15708) I think this is necessary for IE11. via [Webpack docs](https://webpack.js.org/migrate/5/#turn-off-es2015-syntax-in-runtime-code-if-necessary) > By default, webpack's runtime code uses ES2015 syntax to build smaller bundles. If your build targets environments that don't support this syntax (like IE11), you'll need to set output.ecmaVersion: 5 to revert to ES5 syntax. Thank you --- packages/next/build/webpack-config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 8aaad35f4045e..2985e6ecce822 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -710,6 +710,7 @@ export default async function getBaseWebpackConfig( ignored: ['**/.git/**', '**/node_modules/**', '**/.next/**'], }, output: { + ...(isWebpack5 ? { ecmaVersion: 5 } : {}), path: outputPath, // On the server we don't use the chunkhash filename: isServer From 0729394ee18f978e77c4792b4982fe10cb0a8b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20de=20la=20Martini=C3=A8re?= Date: Fri, 31 Jul 2020 17:53:53 +0200 Subject: [PATCH 77/90] Update next-transpile-modules in all examples (#15739) Should prevent some tears when people tries to replicate some example with Next.js 9.5.0 ;) cheers! --- examples/with-patternfly/package.json | 2 +- examples/with-reason-relay/package.json | 2 +- examples/with-reasonml-todo/package.json | 2 +- examples/with-reasonml/package.json | 2 +- examples/with-three-js/package.json | 2 +- examples/with-yarn-workspaces/packages/web-app/package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/with-patternfly/package.json b/examples/with-patternfly/package.json index 1e5f1a89656df..f722ef6fca2dc 100644 --- a/examples/with-patternfly/package.json +++ b/examples/with-patternfly/package.json @@ -10,7 +10,7 @@ "dependencies": { "@patternfly/react-core": "^3.112.3", "next": "latest", - "next-transpile-modules": "^3.0.2", + "next-transpile-modules": "^4.0.2", "react": "^16.7.0", "react-dom": "^16.7.0" }, diff --git a/examples/with-reason-relay/package.json b/examples/with-reason-relay/package.json index 7a0b2ea557c31..efcaff96386b2 100644 --- a/examples/with-reason-relay/package.json +++ b/examples/with-reason-relay/package.json @@ -22,7 +22,7 @@ "graphql": "15.0.0", "isomorphic-unfetch": "^3.0.0", "next": "latest", - "next-transpile-modules": "3.2.0", + "next-transpile-modules": "4.0.2", "react": "^16.13.0", "react-dom": "^16.13.0", "react-relay": "0.0.0-experimental-8cc94ddc", diff --git a/examples/with-reasonml-todo/package.json b/examples/with-reasonml-todo/package.json index 6b136bf3f54c1..10696fddc7599 100644 --- a/examples/with-reasonml-todo/package.json +++ b/examples/with-reasonml-todo/package.json @@ -11,7 +11,7 @@ "license": "ISC", "dependencies": { "next": "latest", - "next-transpile-modules": "^3.0.2", + "next-transpile-modules": "^4.0.2", "react": "^16.8.6", "react-dom": "^16.8.6", "reason-react": "^0.7.0" diff --git a/examples/with-reasonml/package.json b/examples/with-reasonml/package.json index 1dfd20adaba2d..0d165a13ad3a2 100644 --- a/examples/with-reasonml/package.json +++ b/examples/with-reasonml/package.json @@ -11,7 +11,7 @@ "license": "ISC", "dependencies": { "next": "latest", - "next-transpile-modules": "^3.0.2", + "next-transpile-modules": "^4.0.2", "react": "^16.12.0", "react-dom": "^16.12.0", "reason-react": "^0.7.0" diff --git a/examples/with-three-js/package.json b/examples/with-three-js/package.json index b9dd2c70dbde7..066cd94ef1890 100644 --- a/examples/with-three-js/package.json +++ b/examples/with-three-js/package.json @@ -16,6 +16,6 @@ "three": "0.118.3" }, "devDependencies": { - "next-transpile-modules": "3.3.0" + "next-transpile-modules": "4.0.2" } } diff --git a/examples/with-yarn-workspaces/packages/web-app/package.json b/examples/with-yarn-workspaces/packages/web-app/package.json index 9f6ae57268a9b..7b4dccb02539e 100644 --- a/examples/with-yarn-workspaces/packages/web-app/package.json +++ b/examples/with-yarn-workspaces/packages/web-app/package.json @@ -8,7 +8,7 @@ }, "dependencies": { "next": "latest", - "next-transpile-modules": "^3.0.2", + "next-transpile-modules": "^4.0.2", "react": "^16.8.3", "react-dom": "^16.8.3" }, From b3c9737445158fde3f3a000f64a32ef18b96e977 Mon Sep 17 00:00:00 2001 From: Ronald Stevanus Date: Sat, 1 Aug 2020 00:25:17 +0800 Subject: [PATCH 78/90] Fix gh-pages deploy script (#15724) ## What The current `gh-pages` example has issue when deploying. This is how the error looks like: ![image](https://user-images.githubusercontent.com/1008093/88996697-827f0c80-d320-11ea-93bd-48141c321a65.png) ``` ... Export successful The following paths are ignored by one of your .gitignore files: out hint: Use -f if you really want to add them. hint: Turn this message off by running hint: "git config advice.addIgnoredFile false" npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! next@1.0.0 deploy: `rm -rf node_modules/.cache && next build && next export && touch out/.nojekyll && git add out/` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the next@1.0.0 deploy script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: ... ``` It's because `out` folder is added on `.gitignore` and the deploy script runs `git add out/`. The fix is to remove `out` folder from `.gitignore`. ## How was it tested run `npm run deploy`, it should be completed successfully. --- examples/gh-pages/.gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/gh-pages/.gitignore b/examples/gh-pages/.gitignore index 1437c53f70bc2..3b3b2e909de2f 100644 --- a/examples/gh-pages/.gitignore +++ b/examples/gh-pages/.gitignore @@ -10,7 +10,6 @@ # next.js /.next/ -/out/ # production /build From ad5c736798d832f818692f20ae583d349dce7874 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Fri, 31 Jul 2020 19:29:09 +0200 Subject: [PATCH 79/90] Remove unused error (#15748) Irrelevant since https://github.com/vercel/next.js/pull/15379 --- errors/popstate-state-empty.md | 6 +++--- packages/next/next-server/lib/router/router.ts | 7 ------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/errors/popstate-state-empty.md b/errors/popstate-state-empty.md index 1268e15c0b036..ccd98713a557d 100644 --- a/errors/popstate-state-empty.md +++ b/errors/popstate-state-empty.md @@ -2,12 +2,12 @@ #### Why This Error Occurred -When using the browser back button the popstate event is triggered. Next.js sets -`popstate` event triggered but `event.state` did not have `url` or `as`, causing a route change failure +When using the browser back button the popstate event is triggered. Next.js sees a +`popstate` event being triggered but `event.state` did not have `url` or `as`, causing a route change failure. #### Possible Ways to Fix It -The only known cause of this issue is manually manipulating `window.history` instead of using `next/router` +The only known cause of this issue is manually manipulating `window.history` instead of using `next/router`. Starting from version 9.5, Next.js will ignore `popstate` events that contain `event.state` not created by its own router. ### Useful Links diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 5475c2399b9d9..b6ac61c8ee242 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -360,13 +360,6 @@ export default class Router implements BaseRouter { return } - if (process.env.NODE_ENV !== 'production') { - if (typeof url === 'undefined' || typeof as === 'undefined') { - console.warn( - '`popstate` event triggered but `event.state` did not have `url` or `as` https://err.sh/vercel/next.js/popstate-state-empty' - ) - } - } this.change('replaceState', url, as, options) } From 636672755004c756eefcddb5d4ccabbc1855e75a Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Fri, 31 Jul 2020 13:31:49 -0400 Subject: [PATCH 80/90] v9.5.2-canary.1 --- lerna.json | 2 +- packages/create-next-app/package.json | 2 +- packages/eslint-plugin-next/package.json | 2 +- packages/next-bundle-analyzer/package.json | 2 +- packages/next-mdx/package.json | 2 +- packages/next-plugin-google-analytics/package.json | 2 +- packages/next-plugin-sentry/package.json | 2 +- packages/next-plugin-storybook/package.json | 2 +- packages/next-polyfill-nomodule/package.json | 2 +- packages/next/package.json | 8 ++++---- packages/react-dev-overlay/package.json | 2 +- packages/react-refresh-utils/package.json | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lerna.json b/lerna.json index f24fc3d060bec..e7324a9cde96d 100644 --- a/lerna.json +++ b/lerna.json @@ -17,5 +17,5 @@ "registry": "https://registry.npmjs.org/" } }, - "version": "9.5.2-canary.0" + "version": "9.5.2-canary.1" } diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index cb25c60a83a4b..32136c60a7dd0 100644 --- a/packages/create-next-app/package.json +++ b/packages/create-next-app/package.json @@ -1,6 +1,6 @@ { "name": "create-next-app", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "keywords": [ "react", "next", diff --git a/packages/eslint-plugin-next/package.json b/packages/eslint-plugin-next/package.json index 4ac61c9b771d1..46e4bd9c490e7 100644 --- a/packages/eslint-plugin-next/package.json +++ b/packages/eslint-plugin-next/package.json @@ -1,6 +1,6 @@ { "name": "@next/eslint-plugin-next", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "description": "ESLint plugin for NextJS.", "main": "lib/index.js", "license": "MIT", diff --git a/packages/next-bundle-analyzer/package.json b/packages/next-bundle-analyzer/package.json index cbdcd17ad1cf0..92f6ac5c49b6f 100644 --- a/packages/next-bundle-analyzer/package.json +++ b/packages/next-bundle-analyzer/package.json @@ -1,6 +1,6 @@ { "name": "@next/bundle-analyzer", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index 4460832ec19b7..a1d75f28ff3d2 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@next/mdx", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-plugin-google-analytics/package.json b/packages/next-plugin-google-analytics/package.json index 0f94586cf426e..42e7c897544db 100644 --- a/packages/next-plugin-google-analytics/package.json +++ b/packages/next-plugin-google-analytics/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-google-analytics", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-google-analytics" diff --git a/packages/next-plugin-sentry/package.json b/packages/next-plugin-sentry/package.json index b3c3c1db07324..67cab234c6bb0 100644 --- a/packages/next-plugin-sentry/package.json +++ b/packages/next-plugin-sentry/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-sentry", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-sentry" diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index 90dce52338e8b..5f04def1a4552 100644 --- a/packages/next-plugin-storybook/package.json +++ b/packages/next-plugin-storybook/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-storybook", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-storybook" diff --git a/packages/next-polyfill-nomodule/package.json b/packages/next-polyfill-nomodule/package.json index 79f07fa1dee1d..850709719405d 100644 --- a/packages/next-polyfill-nomodule/package.json +++ b/packages/next-polyfill-nomodule/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-nomodule", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "description": "A polyfill for non-dead, nomodule browsers.", "main": "dist/polyfill-nomodule.js", "license": "MIT", diff --git a/packages/next/package.json b/packages/next/package.json index fe078c46ea6e5..c0d77ecca77b9 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "description": "The React Framework", "main": "./dist/server/next.js", "license": "MIT", @@ -76,8 +76,8 @@ "@babel/preset-typescript": "7.9.0", "@babel/runtime": "7.9.6", "@babel/types": "7.9.6", - "@next/react-dev-overlay": "9.5.2-canary.0", - "@next/react-refresh-utils": "9.5.2-canary.0", + "@next/react-dev-overlay": "9.5.2-canary.1", + "@next/react-refresh-utils": "9.5.2-canary.1", "ast-types": "0.13.2", "babel-plugin-syntax-jsx": "6.18.0", "babel-plugin-transform-define": "2.0.0", @@ -119,7 +119,7 @@ "react-dom": "^16.6.0" }, "devDependencies": { - "@next/polyfill-nomodule": "9.5.2-canary.0", + "@next/polyfill-nomodule": "9.5.2-canary.1", "@taskr/clear": "1.1.0", "@taskr/esnext": "1.1.0", "@taskr/watch": "1.1.0", diff --git a/packages/react-dev-overlay/package.json b/packages/react-dev-overlay/package.json index 4227f3edeb721..ccd8025fa2502 100644 --- a/packages/react-dev-overlay/package.json +++ b/packages/react-dev-overlay/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-dev-overlay", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "description": "A development-only overlay for developing React applications.", "repository": { "url": "vercel/next.js", diff --git a/packages/react-refresh-utils/package.json b/packages/react-refresh-utils/package.json index 4fb642878c746..ab870b4344b23 100644 --- a/packages/react-refresh-utils/package.json +++ b/packages/react-refresh-utils/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-refresh-utils", - "version": "9.5.2-canary.0", + "version": "9.5.2-canary.1", "description": "An experimental package providing utilities for React Refresh.", "repository": { "url": "vercel/next.js", From 1b033423dcc43b51752013cb8807051e66917d58 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Sat, 1 Aug 2020 13:51:47 +0200 Subject: [PATCH 81/90] Fix asPath of rewrite without basePath (#15760) Fixes https://github.com/vercel/next.js/issues/15755 --- packages/next/client/index.js | 12 +---- .../next/next-server/lib/router/router.ts | 7 ++- test/integration/basepath/test/index.test.js | 53 +++++++++++++++++++ 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/packages/next/client/index.js b/packages/next/client/index.js index fc7d439a8a5f4..23fe1c7a4c0f1 100644 --- a/packages/next/client/index.js +++ b/packages/next/client/index.js @@ -9,7 +9,7 @@ import { RouterContext } from '../next-server/lib/router-context' import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' import * as envConfig from '../next-server/lib/runtime-config' import { getURL, loadGetInitialProps, ST } from '../next-server/lib/utils' -import { delBasePath } from '../next-server/lib/router/router' +import { hasBasePath, delBasePath } from '../next-server/lib/router/router' import initHeadManager from './head-manager' import PageLoader from './page-loader' import measureWebVitals from './performance-relayer' @@ -52,15 +52,7 @@ envConfig.setConfig({ let asPath = getURL() // make sure not to attempt stripping basePath for 404s -if ( - page !== '/404' && - !( - page === '/_error' && - hydrateProps && - hydrateProps.pageProps && - hydrateProps.pageProps.statusCode === 404 - ) -) { +if (hasBasePath(asPath)) { asPath = delBasePath(asPath) } diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index b6ac61c8ee242..44822b6650289 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -30,6 +30,10 @@ function buildCancellationError() { }) } +export function hasBasePath(path: string): boolean { + return path === basePath || path.startsWith(basePath + '/') +} + export function addBasePath(path: string): string { return basePath ? path === '/' @@ -269,7 +273,6 @@ export default class Router implements BaseRouter { if (as.substr(0, 2) !== '//') { // in order for `e.state` to work on the `onpopstate` event // we have to register the initial route upon initialization - this.changeState( 'replaceState', formatWithValidation({ pathname: addBasePath(pathname), query }), @@ -450,7 +453,7 @@ export default class Router implements BaseRouter { this.abortComponentLoad(this._inFlightRoute) } - const cleanedAs = delBasePath(as) + const cleanedAs = hasBasePath(as) ? delBasePath(as) : as this._inFlightRoute = as // If the url change is only related to a hash change diff --git a/test/integration/basepath/test/index.test.js b/test/integration/basepath/test/index.test.js index 593d9b23e95e7..8eef6545ed35b 100644 --- a/test/integration/basepath/test/index.test.js +++ b/test/integration/basepath/test/index.test.js @@ -141,6 +141,38 @@ const runTests = (context, dev = false) => { expect(html).toContain('getServerSideProps') }) + it('should have correct asPath for rewrite without basePath', async () => { + const browser = await webdriver(context.appPort, '/rewrite-no-basePath') + expect(await browser.eval(() => window.location.pathname)).toBe( + '/rewrite-no-basePath' + ) + expect(await browser.eval(() => window.next.router.asPath)).toBe( + '/rewrite-no-basePath' + ) + expect(await browser.eval(() => window.next.router.pathname)).toBe('/gssp') + }) + + it('should have correct asPath for rewrite without basePath on back()', async () => { + const browser = await webdriver(context.appPort, '/rewrite-no-basePath') + await browser.eval(() => (window.navigationMarker = true)) + await browser.eval(() => window.next.router.push('/hello')) + await check( + () => browser.eval(() => window.location.pathname), + '/docs/hello' + ) + await browser.back() + await check( + () => browser.eval(() => window.location.pathname), + '/rewrite-no-basePath' + ) + await check( + () => browser.eval(() => window.next.router.asPath), + '/rewrite-no-basePath' + ) + expect(await browser.eval(() => window.next.router.pathname)).toBe('/gssp') + expect(await browser.eval(() => window.navigationMarker)).toBe(true) + }) + it('should redirect with basePath by default', async () => { const res = await fetchViaHTTP( context.appPort, @@ -216,6 +248,27 @@ const runTests = (context, dev = false) => { expect(pathname).toBe('/missing') }) + it('should handle 404 urls that start with basePath', async () => { + const browser = await webdriver(context.appPort, '/docshello') + expect(await browser.eval(() => window.next.router.asPath)).toBe( + '/docshello' + ) + expect(await browser.eval(() => window.location.pathname)).toBe( + '/docshello' + ) + }) + + it('should navigating back to a non-basepath 404 that starts with basepath', async () => { + const browser = await webdriver(context.appPort, '/docshello') + await browser.eval(() => window.next.router.push('/hello')) + await browser.waitForElementByCss('#pathname') + await browser.back() + check(() => browser.eval(() => window.location.pathname), '/docshello') + expect(await browser.eval(() => window.next.router.asPath)).toBe( + '/docshello' + ) + }) + it('should update dynamic params after mount correctly', async () => { const browser = await webdriver(context.appPort, '/docs/hello-dynamic') const text = await browser.elementByCss('#slug').text() From d0c57cf6b3473c2a280ab03059a24f20555e9d3f Mon Sep 17 00:00:00 2001 From: Sam Robbins Date: Sat, 1 Aug 2020 13:12:17 +0100 Subject: [PATCH 82/90] Add clarification of routing to a dynamic route (#15771) While it is mentioned in the [link documentation](https://nextjs.org/docs/api-reference/next/link), I think it is useful to also explain in the dynamic route documentation that you need to include the as parameter when routing to a dynamic route/ --- docs/routing/dynamic-routes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/routing/dynamic-routes.md b/docs/routing/dynamic-routes.md index e4d85c0244d1b..304e2ab5913ab 100644 --- a/docs/routing/dynamic-routes.md +++ b/docs/routing/dynamic-routes.md @@ -108,5 +108,6 @@ The `query` objects are as follows: - `pages/post/[pid].js` - Will match `/post/1`, `/post/abc`, etc. But not `/post/create` - `pages/post/[...slug].js` - Will match `/post/1/2`, `/post/a/b/c`, etc. But not `/post/create`, `/post/abc` - Pages that are statically optimized by [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) will be hydrated without their route parameters provided, i.e `query` will be an empty object (`{}`). +- When routing to a dynamic route using `Link` or `router`, you will need to specify the `href` as the dynamic route, for example `/post/[pid]` and `as` as the decorator for the URL, for example `/post/abc`. After hydration, Next.js will trigger an update to your application to provide the route parameters in the `query` object. From 841d4efc517a379d8947f491e3c6a1c4784bbccf Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Sat, 1 Aug 2020 20:13:03 +0200 Subject: [PATCH 83/90] Improve router types (#15775) --- .../next/next-server/lib/router/router.ts | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 44822b6650289..125ee15fdf5b5 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -22,6 +22,18 @@ import { normalizePathTrailingSlash, } from '../../../client/normalize-trailing-slash' +interface TransitionOptions { + shallow?: boolean +} + +interface NextHistoryState { + url: string + as: string + options: TransitionOptions +} + +type HistoryState = null | { __N: false } | ({ __N: true } & NextHistoryState) + const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || '' function buildCancellationError() { @@ -127,7 +139,7 @@ type RouteInfo = { type Subscription = (data: RouteInfo, App?: ComponentType) => Promise -type BeforePopStateCallback = (state: any) => boolean +type BeforePopStateCallback = (state: NextHistoryState) => boolean type ComponentLoadCancel = (() => void) | null @@ -325,7 +337,9 @@ export default class Router implements BaseRouter { } onPopState = (e: PopStateEvent): void => { - if (!e.state) { + const state = e.state as HistoryState + + if (!state) { // We get state as undefined for two reasons. // 1. With older safari (< 8) and older chrome (< 34) // 2. When the URL changed with # @@ -344,11 +358,12 @@ export default class Router implements BaseRouter { return } - const { url, as, options, __N } = e.state - if (!__N) { - // this history state wasn't created by next.js so it can be ignored + if (!state.__N) { return } + + const { url, as, options } = state + const { pathname } = parseRelativeUrl(url) // Make sure we don't re-render on initial load, @@ -359,7 +374,7 @@ export default class Router implements BaseRouter { // If the downstream application returns falsy, return. // They will then be responsible for handling the event. - if (this._bps && !this._bps(e.state)) { + if (this._bps && !this._bps(state)) { return } @@ -408,7 +423,7 @@ export default class Router implements BaseRouter { * @param as masks `url` for the browser * @param options object you can define `shallow` and other options */ - push(url: Url, as: Url = url, options = {}) { + push(url: Url, as: Url = url, options: TransitionOptions = {}) { ;({ url, as } = prepareUrlAs(this, url, as)) return this.change('pushState', url, as, options) } @@ -419,7 +434,7 @@ export default class Router implements BaseRouter { * @param as masks `url` for the browser * @param options object you can define `shallow` and other options */ - replace(url: Url, as: Url = url, options = {}) { + replace(url: Url, as: Url = url, options: TransitionOptions = {}) { ;({ url, as } = prepareUrlAs(this, url, as)) return this.change('replaceState', url, as, options) } @@ -428,9 +443,9 @@ export default class Router implements BaseRouter { method: HistoryMethod, url: string, as: string, - options: any + options: TransitionOptions ): Promise { - if (!options._h) { + if (!(options as any)._h) { this.isSsr = false } // marking route changes as a navigation start entry @@ -462,7 +477,7 @@ export default class Router implements BaseRouter { // WARNING: `_h` is an internal option for handing Next.js client-side // hydration. Your app should _never_ use this property. It may change at // any time without notice. - if (!options._h && this.onlyAHashChange(cleanedAs)) { + if (!(options as any)._h && this.onlyAHashChange(cleanedAs)) { this.asPath = cleanedAs Router.events.emit('hashChangeStart', as) this.changeState(method, url, as, options) @@ -558,7 +573,7 @@ export default class Router implements BaseRouter { if (process.env.__NEXT_SCROLL_RESTORATION) { if (manualScrollRestoration && '_N_X' in options) { - window.scrollTo(options._N_X, options._N_Y) + window.scrollTo((options as any)._N_X, (options as any)._N_Y) } } Router.events.emit('routeChangeComplete', as) @@ -576,7 +591,7 @@ export default class Router implements BaseRouter { method: HistoryMethod, url: string, as: string, - options = {} + options: TransitionOptions = {} ): void { if (process.env.NODE_ENV !== 'production') { if (typeof window.history === 'undefined') { @@ -597,7 +612,7 @@ export default class Router implements BaseRouter { as, options, __N: true, - }, + } as HistoryState, // Most browsers currently ignores this parameter, although they may use it in the future. // Passing the empty string here should be safe against future changes to the method. // https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState @@ -610,7 +625,7 @@ export default class Router implements BaseRouter { async handleRouteInfoError( err: Error & { code: any; cancelled: boolean }, pathname: string, - query: any, + query: ParsedUrlQuery, as: string, loadErrorFail?: boolean ): Promise { @@ -728,7 +743,7 @@ export default class Router implements BaseRouter { set( route: string, pathname: string, - query: any, + query: ParsedUrlQuery, as: string, data: RouteInfo ): Promise { From d0b6026dc508567e4410331c4c626de7c8cffac6 Mon Sep 17 00:00:00 2001 From: David Lemayian <877919+DavidLemayian@users.noreply.github.com> Date: Sun, 2 Aug 2020 11:14:48 +0300 Subject: [PATCH 84/90] examples: Update with-electron .gitignore (#15783) Thank you for the excellent examples. This PR updates the `.gitignore` for [with-electron](https://github.com/vercel/next.js/tree/canary/examples/with-electron) example to ignore the output folders. --- examples/with-electron/.gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/with-electron/.gitignore b/examples/with-electron/.gitignore index 1437c53f70bc2..6165d4ac2abc9 100644 --- a/examples/with-electron/.gitignore +++ b/examples/with-electron/.gitignore @@ -9,11 +9,11 @@ /coverage # next.js -/.next/ -/out/ +/renderer/.next/ +/renderer/out/ # production -/build +/dist # misc .DS_Store From 9f92819742c0138ef90e155feb94224d450f8883 Mon Sep 17 00:00:00 2001 From: sreekumar menon Date: Sun, 2 Aug 2020 12:22:39 -0700 Subject: [PATCH 85/90] Remove dotenv from auth0 Next.js example (#15398) We should remove the dotenv dependency from all Next.js examples (in favor of Next.js environment support): https://github.com/vercel/next.js/issues/15225 --- examples/auth0/.env.local.example | 11 ++++ examples/auth0/.env.template | 6 --- examples/auth0/.gitignore | 3 -- examples/auth0/README.md | 85 +++++++++---------------------- examples/auth0/lib/auth0.js | 21 ++++---- examples/auth0/lib/config.js | 26 ---------- examples/auth0/next.config.js | 17 ------- examples/auth0/package.json | 1 - examples/auth0/vercel.json | 12 ----- 9 files changed, 47 insertions(+), 135 deletions(-) create mode 100644 examples/auth0/.env.local.example delete mode 100644 examples/auth0/.env.template delete mode 100644 examples/auth0/lib/config.js delete mode 100644 examples/auth0/next.config.js delete mode 100644 examples/auth0/vercel.json diff --git a/examples/auth0/.env.local.example b/examples/auth0/.env.local.example new file mode 100644 index 0000000000000..4946e625c14e5 --- /dev/null +++ b/examples/auth0/.env.local.example @@ -0,0 +1,11 @@ +# Public Environment variables that can be used in the browser. +NEXT_PUBLIC_AUTH0_CLIENT_ID= +NEXT_PUBLIC_AUTH0_SCOPE="openid profile" +NEXT_PUBLIC_AUTH0_DOMAIN= +NEXT_PUBLIC_REDIRECT_URI="http://localhost:3000/api/callback" +NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI="http://localhost:3000" + +# Secret environment variables only available to Node.js +AUTH0_CLIENT_SECRET= +SESSION_COOKIE_SECRET= +SESSION_COOKIE_LIFETIME=7200 diff --git a/examples/auth0/.env.template b/examples/auth0/.env.template deleted file mode 100644 index 52f96ccb544fb..0000000000000 --- a/examples/auth0/.env.template +++ /dev/null @@ -1,6 +0,0 @@ -AUTH0_CLIENT_ID= -AUTH0_DOMAIN= -AUTH0_CLIENT_SECRET= -REDIRECT_URI= -POST_LOGOUT_REDIRECT_URI= -SESSION_COOKIE_SECRET= diff --git a/examples/auth0/.gitignore b/examples/auth0/.gitignore index de436342e9529..1437c53f70bc2 100644 --- a/examples/auth0/.gitignore +++ b/examples/auth0/.gitignore @@ -24,9 +24,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -# auth0 env -.env - # local env files .env.local .env.development.local diff --git a/examples/auth0/README.md b/examples/auth0/README.md index 02f9d0df4671a..5368bd1c33145 100644 --- a/examples/auth0/README.md +++ b/examples/auth0/README.md @@ -1,10 +1,17 @@ # Next.js and Auth0 Example -This example shows how you can use `@auth0/nextjs-auth` to easily add authentication support to your Next.js application. +This example shows how you can use `@auth0/nextjs-auth` to easily add authentication support to your Next.js application. It tries to cover a few topics: + +- Signing in +- Signing out +- Loading the user on the server side and adding it as part of SSR ([`pages/advanced/ssr-profile.js`](pages/advanced/ssr-profile.js)) +- Loading the user on the client side and using fast/cached SSR pages ([`pages/index.js`](pages/index.js)) +- API Routes which can load the current user ([`pages/api/me.js`](pages/api/me.js)) +- Using hooks to make the user available throughout the application ([`lib/user.js`](lib/user.js)) Read more: [https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/](https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/) -### Using `create-next-app` +## How to use Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: @@ -25,76 +32,32 @@ yarn create next-app --example auth0 auth0 4. Save the settings -### Configuring Next.js - -In the Next.js configuration file (`next.config.js`) you'll see that different environment variables are being assigned. - -### Local Development +### Set up environment variables -For local development you'll want to create a `.env` file with the necessary settings. +To connect the app with Auth0, you'll need to add the settings from your Auth0 application as environment variables -The required settings can be found on the Auth0 application's settings page: +Copy the `.env.local.example` file in this directory to `.env.local` (which will be ignored by Git): -``` -AUTH0_DOMAIN=YOUR_AUTH0_DOMAIN -AUTH0_CLIENT_ID=YOUR_AUTH0_CLIENT_ID -AUTH0_CLIENT_SECRET=YOUR_AUTH0_CLIENT_SECRET - -SESSION_COOKIE_SECRET=viloxyf_z2GW6K4CT-KQD_MoLEA2wqv5jWuq4Jd0P7ymgG5GJGMpvMneXZzhK3sL (at least 32 characters, used to encrypt the cookie) - -REDIRECT_URI=http://localhost:3000/api/callback -POST_LOGOUT_REDIRECT_URI=http://localhost:3000/ +```bash +cp .env.local.example .env.local ``` -### Hosting on Vercel - -When deploying this example to Vercel you'll want to update the `vercel.json` configuration file. - -```json -{ - "build": { - "env": { - "AUTH0_DOMAIN": "YOUR_AUTH0_DOMAIN", - "AUTH0_CLIENT_ID": "YOUR_AUTH0_CLIENT_ID", - "AUTH0_CLIENT_SECRET": "@auth0_client_secret", - "REDIRECT_URI": "https://my-website.now.sh/api/callback", - "POST_LOGOUT_REDIRECT_URI": "https://my-website.now.sh/", - "SESSION_COOKIE_SECRET": "@session_cookie_secret", - "SESSION_COOKIE_LIFETIME": 7200 - } - } -} -``` +Then, open `.env.local` and add the missing environment variables: -- `AUTH0_DOMAIN` - Can be found in the Auth0 dashboard under `settings`. -- `AUTH0_CLIENT_ID` - Can be found in the Auth0 dashboard under `settings`. +- `NEXT_PUBLIC_AUTH0_DOMAIN` - Can be found in the Auth0 dashboard under `settings`. +- `NEXT_PUBLIC_AUTH0_CLIENT_ID` - Can be found in the Auth0 dashboard under `settings`. - `AUTH0_CLIENT_SECRET` - Can be found in the Auth0 dashboard under `settings`. -- `REDIRECT_URI` - The url where Auth0 redirects back to, make sure a consistent url is used here. -- `POST_LOGOUT_REDIRECT_URI` - Where to redirect after logging out +- `NEXT_PUBLIC_REDIRECT_URI` - The url where Auth0 redirects back to, make sure a consistent url is used here. +- `NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI` - Where to redirect after logging out - `SESSION_COOKIE_SECRET` - A unique secret used to encrypt the cookies, has to be at least 32 characters. You can use [this generator](https://generate-secret.now.sh/32) to generate a value. - `SESSION_COOKIE_LIFETIME` - How long a session lasts in seconds. The default is 2 hours. -The `@auth0_client_secret` and `@session_cookie_secret` are [Vercel environment secrets](https://vercel.com/docs/v2/environment-variables-and-secrets/) +## Deploy on Vercel -You can create the `@auth0_client_secret` by running: +You can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). -``` -now secrets add auth0_client_secret PLACE_YOUR_AUTH0_CLIENT_SECRET -``` - -And create the `session_cookie_secret` by generating a value [here](https://generate-secret.now.sh/32) and running: +### Deploy Your Local Project -``` -now secrets add session_cookie_secret PLACE_YOUR_SESSION_COOKIE_SECRET -``` +To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/import/git?utm_source=github&utm_medium=readme&utm_campaign=next-example). -## About this sample - -This sample tries to cover a few topics: - -- Signing in -- Signing out -- Loading the user on the server side and adding it as part of SSR (`/pages/advanced/ssr-profile.js`) -- Loading the user on the client side and using fast/cached SSR pages (`/pages/index.js`) -- API Routes which can load the current user (`/pages/api/me.js`) -- Using hooks to make the user available throughout the application (`/lib/user.js`) +**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file. diff --git a/examples/auth0/lib/auth0.js b/examples/auth0/lib/auth0.js index c233f803de179..84fe93be3df93 100644 --- a/examples/auth0/lib/auth0.js +++ b/examples/auth0/lib/auth0.js @@ -1,15 +1,18 @@ import { initAuth0 } from '@auth0/nextjs-auth0' -import config from './config' export default initAuth0({ - clientId: config.AUTH0_CLIENT_ID, - clientSecret: config.AUTH0_CLIENT_SECRET, - scope: config.AUTH0_SCOPE, - domain: config.AUTH0_DOMAIN, - redirectUri: config.REDIRECT_URI, - postLogoutRedirectUri: config.POST_LOGOUT_REDIRECT_URI, + clientId: process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID, + clientSecret: process.env.AUTH0_CLIENT_SECRET, + scope: process.env.NEXT_PUBLIC_AUTH0_SCOPE || 'openid profile', + domain: process.env.NEXT_PUBLIC_AUTH0_DOMAIN, + redirectUri: + process.env.NEXT_PUBLIC_REDIRECT_URI || + 'http://localhost:3000/api/callback', + postLogoutRedirectUri: + process.env.NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI || + 'http://localhost:3000/', session: { - cookieSecret: config.SESSION_COOKIE_SECRET, - cookieLifetime: config.SESSION_COOKIE_LIFETIME, + cookieSecret: process.env.SESSION_COOKIE_SECRET, + cookieLifetime: Number(process.env.SESSION_COOKIE_LIFETIME) || 7200, }, }) diff --git a/examples/auth0/lib/config.js b/examples/auth0/lib/config.js deleted file mode 100644 index b7052748b1928..0000000000000 --- a/examples/auth0/lib/config.js +++ /dev/null @@ -1,26 +0,0 @@ -if (typeof window === 'undefined') { - /** - * Settings exposed to the server. - */ - module.exports = { - AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID, - AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET, - AUTH0_SCOPE: process.env.AUTH0_SCOPE, - AUTH0_DOMAIN: process.env.AUTH0_DOMAIN, - REDIRECT_URI: process.env.REDIRECT_URI, - POST_LOGOUT_REDIRECT_URI: process.env.POST_LOGOUT_REDIRECT_URI, - SESSION_COOKIE_SECRET: process.env.SESSION_COOKIE_SECRET, - SESSION_COOKIE_LIFETIME: process.env.SESSION_COOKIE_LIFETIME, - } -} else { - /** - * Settings exposed to the client. - */ - module.exports = { - AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID, - AUTH0_SCOPE: process.env.AUTH0_SCOPE, - AUTH0_DOMAIN: process.env.AUTH0_DOMAIN, - REDIRECT_URI: process.env.REDIRECT_URI, - POST_LOGOUT_REDIRECT_URI: process.env.POST_LOGOUT_REDIRECT_URI, - } -} diff --git a/examples/auth0/next.config.js b/examples/auth0/next.config.js deleted file mode 100644 index 4b804fdd389ff..0000000000000 --- a/examples/auth0/next.config.js +++ /dev/null @@ -1,17 +0,0 @@ -const dotenv = require('dotenv') -dotenv.config() - -module.exports = { - env: { - AUTH0_DOMAIN: process.env.AUTH0_DOMAIN, - AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID, - AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET, - AUTH0_SCOPE: 'openid profile', - REDIRECT_URI: - process.env.REDIRECT_URI || 'http://localhost:3000/api/callback', - POST_LOGOUT_REDIRECT_URI: - process.env.POST_LOGOUT_REDIRECT_URI || 'http://localhost:3000/', - SESSION_COOKIE_SECRET: process.env.SESSION_COOKIE_SECRET, - SESSION_COOKIE_LIFETIME: 7200, // 2 hours - }, -} diff --git a/examples/auth0/package.json b/examples/auth0/package.json index 4c4921d84148b..f1e248e9cef46 100644 --- a/examples/auth0/package.json +++ b/examples/auth0/package.json @@ -9,7 +9,6 @@ "license": "MIT", "dependencies": { "@auth0/nextjs-auth0": "^0.6.0", - "dotenv": "^8.2.0", "next": "latest", "react": "^16.12.0", "react-dom": "^16.12.0" diff --git a/examples/auth0/vercel.json b/examples/auth0/vercel.json deleted file mode 100644 index 7337cfc1c3e79..0000000000000 --- a/examples/auth0/vercel.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "build": { - "env": { - "AUTH0_DOMAIN": "YOUR_AUTH0_DOMAIN", - "AUTH0_CLIENT_ID": "YOUR_AUTH0_CLIENT_ID", - "AUTH0_CLIENT_SECRET": "@auth0_client_secret", - "REDIRECT_URI": "https://my-website.now.sh/api/callback", - "POST_LOGOUT_REDIRECT_URI": "https://my-website.now.sh/", - "SESSION_COOKIE_SECRET": "@session_cookie_secret" - } - } -} From 9dd974dfca1efd0b451065056f95f92747e2dada Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 2 Aug 2020 15:15:11 -0500 Subject: [PATCH 86/90] Fix dotenv loading with cascading values (#15799) Adds additional test cases for cascading env values and corrects behavior Fixes: https://github.com/vercel/next.js/issues/15744 --- packages/next/lib/load-env-config.ts | 14 ++++++++++++-- test/integration/env-config/app/.env | 4 +++- test/integration/env-config/app/.env.local | 1 + .../env-config/app/pages/api/all.js | 2 ++ test/integration/env-config/app/pages/index.js | 2 ++ .../env-config/app/pages/some-ssg.js | 4 +++- .../env-config/app/pages/some-ssp.js | 4 +++- test/integration/env-config/test/index.test.js | 18 ++++++++++++++++-- 8 files changed, 42 insertions(+), 7 deletions(-) diff --git a/packages/next/lib/load-env-config.ts b/packages/next/lib/load-env-config.ts index ebf64ef42d852..d4ceb0707a163 100644 --- a/packages/next/lib/load-env-config.ts +++ b/packages/next/lib/load-env-config.ts @@ -27,6 +27,9 @@ export function processEnv(loadedEnvFiles: LoadedEnvFiles, dir?: string) { // function is re-used or we are running in `next start` mode process.env.__NEXT_PROCESSED_ENV = 'true' + const origEnv = Object.assign({}, process.env) + const parsed: dotenv.DotenvParseOutput = {} + for (const envFile of loadedEnvFiles) { try { let result: DotenvConfigOutput = {} @@ -38,7 +41,14 @@ export function processEnv(loadedEnvFiles: LoadedEnvFiles, dir?: string) { log.info(`Loaded env from ${path.join(dir || '', envFile.path)}`) } - Object.assign(process.env, result.parsed) + for (const key of Object.keys(result.parsed || {})) { + if ( + typeof parsed[key] === 'undefined' && + typeof origEnv[key] === 'undefined' + ) { + parsed[key] = result.parsed?.[key]! + } + } } catch (err) { log.error( `Failed to load env from ${path.join(dir || '', envFile.path)}`, @@ -47,7 +57,7 @@ export function processEnv(loadedEnvFiles: LoadedEnvFiles, dir?: string) { } } - return process.env as Env + return Object.assign(process.env, parsed) } export function loadEnvConfig( diff --git a/test/integration/env-config/app/.env b/test/integration/env-config/app/.env index d50cde61838c9..4313e4592ae8d 100644 --- a/test/integration/env-config/app/.env +++ b/test/integration/env-config/app/.env @@ -1,5 +1,6 @@ PROCESS_ENV_KEY="env" ENV_FILE_KEY=env +ENV_FILE_EMPTY_FIRST= ENV_FILE_LOCAL_OVERRIDE_TEST=env ENV_FILE_DEVELOPMENT_OVERRIDE_TEST=env ENV_FILE_DEVELOPMENT_LOCAL_OVERRIDEOVERRIDE_TEST=env @@ -11,4 +12,5 @@ NEXT_PUBLIC_TEST_DEST=another ENV_FILE_EXPANDED=$ENV_FILE_KEY ENV_FILE_EXPANDED_CONCAT=hello-${ENV_FILE_KEY} ENV_FILE_EXPANDED_ESCAPED=\$ENV_FILE_KEY -ENV_FILE_KEY_EXCLAMATION="hello!" \ No newline at end of file +ENV_FILE_KEY_EXCLAMATION="hello!" +ENV_FILE_PROCESS_ENV="env-file" \ No newline at end of file diff --git a/test/integration/env-config/app/.env.local b/test/integration/env-config/app/.env.local index 077c72362c548..b5cbb5f83c2b1 100644 --- a/test/integration/env-config/app/.env.local +++ b/test/integration/env-config/app/.env.local @@ -1,2 +1,3 @@ LOCAL_ENV_FILE_KEY=localenv +ENV_FILE_EMPTY_FIRST=\$escaped ENV_FILE_LOCAL_OVERRIDE_TEST=localenv \ No newline at end of file diff --git a/test/integration/env-config/app/pages/api/all.js b/test/integration/env-config/app/pages/api/all.js index 71c4968c8cc6c..59dab4c5ccc85 100644 --- a/test/integration/env-config/app/pages/api/all.js +++ b/test/integration/env-config/app/pages/api/all.js @@ -1,6 +1,8 @@ const variables = [ 'PROCESS_ENV_KEY', 'ENV_FILE_KEY', + 'ENV_FILE_EMPTY_FIRST', + 'ENV_FILE_PROCESS_ENV', 'LOCAL_ENV_FILE_KEY', 'ENV_FILE_LOCAL_OVERRIDE_TEST', 'PRODUCTION_ENV_FILE_KEY', diff --git a/test/integration/env-config/app/pages/index.js b/test/integration/env-config/app/pages/index.js index 3f6247d2ce8ef..9381f9094e173 100644 --- a/test/integration/env-config/app/pages/index.js +++ b/test/integration/env-config/app/pages/index.js @@ -1,6 +1,8 @@ const variables = [ 'PROCESS_ENV_KEY', 'ENV_FILE_KEY', + 'ENV_FILE_EMPTY_FIRST', + 'ENV_FILE_PROCESS_ENV', 'LOCAL_ENV_FILE_KEY', 'ENV_FILE_LOCAL_OVERRIDE_TEST', 'PRODUCTION_ENV_FILE_KEY', diff --git a/test/integration/env-config/app/pages/some-ssg.js b/test/integration/env-config/app/pages/some-ssg.js index 3f6247d2ce8ef..31e50123d6750 100644 --- a/test/integration/env-config/app/pages/some-ssg.js +++ b/test/integration/env-config/app/pages/some-ssg.js @@ -1,6 +1,8 @@ const variables = [ 'PROCESS_ENV_KEY', 'ENV_FILE_KEY', + 'ENV_FILE_EMPTY_FIRST', + 'ENV_FILE_PROCESS_ENV', 'LOCAL_ENV_FILE_KEY', 'ENV_FILE_LOCAL_OVERRIDE_TEST', 'PRODUCTION_ENV_FILE_KEY', @@ -25,7 +27,7 @@ export async function getStaticProps() { const items = {} variables.forEach((variable) => { - if (process.env[variable]) { + if (typeof process.env[variable] !== 'undefined') { items[variable] = process.env[variable] } }) diff --git a/test/integration/env-config/app/pages/some-ssp.js b/test/integration/env-config/app/pages/some-ssp.js index 62db07bb4223a..a3ae47cb158db 100644 --- a/test/integration/env-config/app/pages/some-ssp.js +++ b/test/integration/env-config/app/pages/some-ssp.js @@ -1,6 +1,8 @@ const variables = [ 'PROCESS_ENV_KEY', 'ENV_FILE_KEY', + 'ENV_FILE_EMPTY_FIRST', + 'ENV_FILE_PROCESS_ENV', 'LOCAL_ENV_FILE_KEY', 'ENV_FILE_LOCAL_OVERRIDE_TEST', 'PRODUCTION_ENV_FILE_KEY', @@ -25,7 +27,7 @@ export async function getServerSideProps() { const items = {} variables.forEach((variable) => { - if (process.env[variable]) { + if (typeof process.env[variable] !== 'undefined') { items[variable] = process.env[variable] } }) diff --git a/test/integration/env-config/test/index.test.js b/test/integration/env-config/test/index.test.js index 3c3d7222fccaf..04e1705adbc9d 100644 --- a/test/integration/env-config/test/index.test.js +++ b/test/integration/env-config/test/index.test.js @@ -51,6 +51,8 @@ const runTests = (mode = 'dev') => { expect(data.ENV_FILE_EXPANDED_CONCAT).toBe('hello-env') expect(data.ENV_FILE_EXPANDED_ESCAPED).toBe('$ENV_FILE_KEY') expect(data.ENV_FILE_KEY_EXCLAMATION).toBe('hello!') + expect(data.ENV_FILE_EMPTY_FIRST).toBe(isTestEnv ? '' : '$escaped') + expect(data.ENV_FILE_PROCESS_ENV).toBe('env-cli') } it('should have process environment override .env', async () => { @@ -135,6 +137,7 @@ describe('Env Config', () => { app = await launchApp(appDir, appPort, { env: { PROCESS_ENV_KEY: 'processenvironment', + ENV_FILE_PROCESS_ENV: 'env-cli', }, }) }) @@ -150,6 +153,7 @@ describe('Env Config', () => { env: { PROCESS_ENV_KEY: 'processenvironment', NODE_ENV: 'test', + ENV_FILE_PROCESS_ENV: 'env-cli', }, }) }) @@ -163,12 +167,17 @@ describe('Env Config', () => { const { code } = await nextBuild(appDir, [], { env: { PROCESS_ENV_KEY: 'processenvironment', + ENV_FILE_PROCESS_ENV: 'env-cli', }, }) if (code !== 0) throw new Error(`Build failed with exit code ${code}`) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + env: { + ENV_FILE_PROCESS_ENV: 'env-cli', + }, + }) }) afterAll(() => killApp(app)) @@ -201,6 +210,7 @@ describe('Env Config', () => { const { code } = await nextBuild(appDir, [], { env: { PROCESS_ENV_KEY: 'processenvironment', + ENV_FILE_PROCESS_ENV: 'env-cli', }, }) @@ -213,7 +223,11 @@ describe('Env Config', () => { await fs.rename(file, `${file}.bak`) } - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + env: { + ENV_FILE_PROCESS_ENV: 'env-cli', + }, + }) }) afterAll(async () => { for (const file of envFiles) { From ed0a47b1104c718894e1f411e505d6a64f00e792 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 3 Aug 2020 01:47:42 -0400 Subject: [PATCH 87/90] v9.5.2-canary.2 --- lerna.json | 2 +- packages/create-next-app/package.json | 2 +- packages/eslint-plugin-next/package.json | 2 +- packages/next-bundle-analyzer/package.json | 2 +- packages/next-mdx/package.json | 2 +- packages/next-plugin-google-analytics/package.json | 2 +- packages/next-plugin-sentry/package.json | 2 +- packages/next-plugin-storybook/package.json | 2 +- packages/next-polyfill-nomodule/package.json | 2 +- packages/next/package.json | 8 ++++---- packages/react-dev-overlay/package.json | 2 +- packages/react-refresh-utils/package.json | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lerna.json b/lerna.json index e7324a9cde96d..c3f67b050ad6b 100644 --- a/lerna.json +++ b/lerna.json @@ -17,5 +17,5 @@ "registry": "https://registry.npmjs.org/" } }, - "version": "9.5.2-canary.1" + "version": "9.5.2-canary.2" } diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index 32136c60a7dd0..fd91750a1a653 100644 --- a/packages/create-next-app/package.json +++ b/packages/create-next-app/package.json @@ -1,6 +1,6 @@ { "name": "create-next-app", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "keywords": [ "react", "next", diff --git a/packages/eslint-plugin-next/package.json b/packages/eslint-plugin-next/package.json index 46e4bd9c490e7..3b9995e6078cb 100644 --- a/packages/eslint-plugin-next/package.json +++ b/packages/eslint-plugin-next/package.json @@ -1,6 +1,6 @@ { "name": "@next/eslint-plugin-next", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "description": "ESLint plugin for NextJS.", "main": "lib/index.js", "license": "MIT", diff --git a/packages/next-bundle-analyzer/package.json b/packages/next-bundle-analyzer/package.json index 92f6ac5c49b6f..f6a57768a7c3d 100644 --- a/packages/next-bundle-analyzer/package.json +++ b/packages/next-bundle-analyzer/package.json @@ -1,6 +1,6 @@ { "name": "@next/bundle-analyzer", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index a1d75f28ff3d2..d384965ef474f 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@next/mdx", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-plugin-google-analytics/package.json b/packages/next-plugin-google-analytics/package.json index 42e7c897544db..3bba8a6493732 100644 --- a/packages/next-plugin-google-analytics/package.json +++ b/packages/next-plugin-google-analytics/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-google-analytics", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-google-analytics" diff --git a/packages/next-plugin-sentry/package.json b/packages/next-plugin-sentry/package.json index 67cab234c6bb0..e5fcbe2564aea 100644 --- a/packages/next-plugin-sentry/package.json +++ b/packages/next-plugin-sentry/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-sentry", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-sentry" diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index 5f04def1a4552..91c8540463659 100644 --- a/packages/next-plugin-storybook/package.json +++ b/packages/next-plugin-storybook/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-storybook", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-storybook" diff --git a/packages/next-polyfill-nomodule/package.json b/packages/next-polyfill-nomodule/package.json index 850709719405d..28fbf10e9d73f 100644 --- a/packages/next-polyfill-nomodule/package.json +++ b/packages/next-polyfill-nomodule/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-nomodule", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "description": "A polyfill for non-dead, nomodule browsers.", "main": "dist/polyfill-nomodule.js", "license": "MIT", diff --git a/packages/next/package.json b/packages/next/package.json index c0d77ecca77b9..0d86672ede7ac 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "description": "The React Framework", "main": "./dist/server/next.js", "license": "MIT", @@ -76,8 +76,8 @@ "@babel/preset-typescript": "7.9.0", "@babel/runtime": "7.9.6", "@babel/types": "7.9.6", - "@next/react-dev-overlay": "9.5.2-canary.1", - "@next/react-refresh-utils": "9.5.2-canary.1", + "@next/react-dev-overlay": "9.5.2-canary.2", + "@next/react-refresh-utils": "9.5.2-canary.2", "ast-types": "0.13.2", "babel-plugin-syntax-jsx": "6.18.0", "babel-plugin-transform-define": "2.0.0", @@ -119,7 +119,7 @@ "react-dom": "^16.6.0" }, "devDependencies": { - "@next/polyfill-nomodule": "9.5.2-canary.1", + "@next/polyfill-nomodule": "9.5.2-canary.2", "@taskr/clear": "1.1.0", "@taskr/esnext": "1.1.0", "@taskr/watch": "1.1.0", diff --git a/packages/react-dev-overlay/package.json b/packages/react-dev-overlay/package.json index ccd8025fa2502..823b74cbf5077 100644 --- a/packages/react-dev-overlay/package.json +++ b/packages/react-dev-overlay/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-dev-overlay", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "description": "A development-only overlay for developing React applications.", "repository": { "url": "vercel/next.js", diff --git a/packages/react-refresh-utils/package.json b/packages/react-refresh-utils/package.json index ab870b4344b23..88adf331fbd6a 100644 --- a/packages/react-refresh-utils/package.json +++ b/packages/react-refresh-utils/package.json @@ -1,6 +1,6 @@ { "name": "@next/react-refresh-utils", - "version": "9.5.2-canary.1", + "version": "9.5.2-canary.2", "description": "An experimental package providing utilities for React Refresh.", "repository": { "url": "vercel/next.js", From 210a6980d2d630e0ed7c67552a6ebf96921dac15 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 3 Aug 2020 14:26:23 +0200 Subject: [PATCH 88/90] Solve large portion of webpack 5 deprecation warnings (#15806) - Using `namedChunks` where possible, this will also allow for faster access to the chunks as we no longer have to look them up like we did before using `find` - Using the new asset hooks introduced in the latest webpack beta - Using the new externals function signature --- packages/next/build/webpack-config.ts | 275 +++++++++--------- .../webpack/plugins/build-manifest-plugin.ts | 254 +++++++++------- .../webpack/plugins/pages-manifest-plugin.ts | 86 +++--- .../webpack/plugins/react-loadable-plugin.ts | 72 +++-- .../webpack/plugins/serverless-plugin.ts | 11 +- packages/next/server/hot-reloader.ts | 10 +- 6 files changed, 400 insertions(+), 308 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 2985e6ecce822..bdc254196cf69 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -501,153 +501,160 @@ export default async function getBaseWebpackConfig( }, config.conformance ) - let webpackConfig: webpack.Configuration = { - externals: !isServer - ? // make sure importing "next" is handled gracefully for client - // bundles in case a user imported types and it wasn't removed - // TODO: should we warn/error for this instead? - ['next'] - : !isServerless - ? [ - (context, request, callback) => { - if (request === 'next') { - return callback(undefined, `commonjs ${request}`) - } - const notExternalModules = [ - 'next/app', - 'next/document', - 'next/link', - 'next/error', - 'string-hash', - 'next/constants', - ] - - if (notExternalModules.indexOf(request) !== -1) { - return callback() - } + function handleExternals(context: any, request: any, callback: any) { + if (request === 'next') { + return callback(undefined, `commonjs ${request}`) + } - // We need to externalize internal requests for files intended to - // not be bundled. - - const isLocal: boolean = - request.startsWith('.') || - // Always check for unix-style path, as webpack sometimes - // normalizes as posix. - path.posix.isAbsolute(request) || - // When on Windows, we also want to check for Windows-specific - // absolute paths. - (process.platform === 'win32' && path.win32.isAbsolute(request)) - const isLikelyNextExternal = - isLocal && /[/\\]next-server[/\\]/.test(request) - - // Relative requires don't need custom resolution, because they - // are relative to requests we've already resolved here. - // Absolute requires (require('/foo')) are extremely uncommon, but - // also have no need for customization as they're already resolved. - if (isLocal && !isLikelyNextExternal) { - return callback() - } + const notExternalModules = [ + 'next/app', + 'next/document', + 'next/link', + 'next/error', + 'string-hash', + 'next/constants', + ] - // Resolve the import with the webpack provided context, this - // ensures we're resolving the correct version when multiple - // exist. - let res: string - try { - res = resolveRequest(request, `${context}/`) - } catch (err) { - // If the request cannot be resolved, we need to tell webpack to - // "bundle" it so that webpack shows an error (that it cannot be - // resolved). - return callback() - } + if (notExternalModules.indexOf(request) !== -1) { + return callback() + } - // Same as above, if the request cannot be resolved we need to have - // webpack "bundle" it so it surfaces the not found error. - if (!res) { - return callback() - } + // We need to externalize internal requests for files intended to + // not be bundled. + + const isLocal: boolean = + request.startsWith('.') || + // Always check for unix-style path, as webpack sometimes + // normalizes as posix. + path.posix.isAbsolute(request) || + // When on Windows, we also want to check for Windows-specific + // absolute paths. + (process.platform === 'win32' && path.win32.isAbsolute(request)) + const isLikelyNextExternal = + isLocal && /[/\\]next-server[/\\]/.test(request) + + // Relative requires don't need custom resolution, because they + // are relative to requests we've already resolved here. + // Absolute requires (require('/foo')) are extremely uncommon, but + // also have no need for customization as they're already resolved. + if (isLocal && !isLikelyNextExternal) { + return callback() + } - let isNextExternal: boolean = false - if (isLocal) { - // we need to process next-server/lib/router/router so that - // the DefinePlugin can inject process.env values - isNextExternal = /next[/\\]dist[/\\]next-server[/\\](?!lib[/\\]router[/\\]router)/.test( - res - ) + // Resolve the import with the webpack provided context, this + // ensures we're resolving the correct version when multiple + // exist. + let res: string + try { + res = resolveRequest(request, `${context}/`) + } catch (err) { + // If the request cannot be resolved, we need to tell webpack to + // "bundle" it so that webpack shows an error (that it cannot be + // resolved). + return callback() + } - if (!isNextExternal) { - return callback() - } - } + // Same as above, if the request cannot be resolved we need to have + // webpack "bundle" it so it surfaces the not found error. + if (!res) { + return callback() + } - // `isNextExternal` special cases Next.js' internal requires that - // should not be bundled. We need to skip the base resolve routine - // to prevent it from being bundled (assumes Next.js version cannot - // mismatch). - if (!isNextExternal) { - // Bundled Node.js code is relocated without its node_modules tree. - // This means we need to make sure its request resolves to the same - // package that'll be available at runtime. If it's not identical, - // we need to bundle the code (even if it _should_ be external). - let baseRes: string | null - try { - baseRes = resolveRequest(request, `${dir}/`) - } catch (err) { - baseRes = null - } + let isNextExternal: boolean = false + if (isLocal) { + // we need to process next-server/lib/router/router so that + // the DefinePlugin can inject process.env values + isNextExternal = /next[/\\]dist[/\\]next-server[/\\](?!lib[/\\]router[/\\]router)/.test( + res + ) - // Same as above: if the package, when required from the root, - // would be different from what the real resolution would use, we - // cannot externalize it. - if (baseRes !== res) { - return callback() - } - } + if (!isNextExternal) { + return callback() + } + } - // Default pages have to be transpiled - if ( - !res.match(/next[/\\]dist[/\\]next-server[/\\]/) && - (res.match(/[/\\]next[/\\]dist[/\\]/) || - // This is the @babel/plugin-transform-runtime "helpers: true" option - res.match(/node_modules[/\\]@babel[/\\]runtime[/\\]/)) - ) { - return callback() - } + // `isNextExternal` special cases Next.js' internal requires that + // should not be bundled. We need to skip the base resolve routine + // to prevent it from being bundled (assumes Next.js version cannot + // mismatch). + if (!isNextExternal) { + // Bundled Node.js code is relocated without its node_modules tree. + // This means we need to make sure its request resolves to the same + // package that'll be available at runtime. If it's not identical, + // we need to bundle the code (even if it _should_ be external). + let baseRes: string | null + try { + baseRes = resolveRequest(request, `${dir}/`) + } catch (err) { + baseRes = null + } - // Webpack itself has to be compiled because it doesn't always use module relative paths - if ( - res.match(/node_modules[/\\]webpack/) || - res.match(/node_modules[/\\]css-loader/) - ) { - return callback() - } + // Same as above: if the package, when required from the root, + // would be different from what the real resolution would use, we + // cannot externalize it. + if (baseRes !== res) { + return callback() + } + } - // Anything else that is standard JavaScript within `node_modules` - // can be externalized. - if (isNextExternal || res.match(/node_modules[/\\].*\.js$/)) { - const externalRequest = isNextExternal - ? // Generate Next.js external import - path.posix.join( - 'next', - 'dist', - path - .relative( - // Root of Next.js package: - path.join(__dirname, '..'), - res - ) - // Windows path normalization - .replace(/\\/g, '/') - ) - : request + // Default pages have to be transpiled + if ( + !res.match(/next[/\\]dist[/\\]next-server[/\\]/) && + (res.match(/[/\\]next[/\\]dist[/\\]/) || + // This is the @babel/plugin-transform-runtime "helpers: true" option + res.match(/node_modules[/\\]@babel[/\\]runtime[/\\]/)) + ) { + return callback() + } - return callback(undefined, `commonjs ${externalRequest}`) - } + // Webpack itself has to be compiled because it doesn't always use module relative paths + if ( + res.match(/node_modules[/\\]webpack/) || + res.match(/node_modules[/\\]css-loader/) + ) { + return callback() + } - // Default behavior: bundle the code! - callback() - }, + // Anything else that is standard JavaScript within `node_modules` + // can be externalized. + if (isNextExternal || res.match(/node_modules[/\\].*\.js$/)) { + const externalRequest = isNextExternal + ? // Generate Next.js external import + path.posix.join( + 'next', + 'dist', + path + .relative( + // Root of Next.js package: + path.join(__dirname, '..'), + res + ) + // Windows path normalization + .replace(/\\/g, '/') + ) + : request + + return callback(undefined, `commonjs ${externalRequest}`) + } + + // Default behavior: bundle the code! + callback() + } + + let webpackConfig: webpack.Configuration = { + externals: !isServer + ? // make sure importing "next" is handled gracefully for client + // bundles in case a user imported types and it wasn't removed + // TODO: should we warn/error for this instead? + ['next'] + : !isServerless + ? [ + isWebpack5 + ? ({ context, request }, callback) => + handleExternals(context, request, callback) + : (context, request, callback) => + handleExternals(context, request, callback), ] : [ // When the 'serverless' target is used all node_modules will be compiled into the output bundles diff --git a/packages/next/build/webpack/plugins/build-manifest-plugin.ts b/packages/next/build/webpack/plugins/build-manifest-plugin.ts index 62b1d3838f4e8..c530823acca42 100644 --- a/packages/next/build/webpack/plugins/build-manifest-plugin.ts +++ b/packages/next/build/webpack/plugins/build-manifest-plugin.ts @@ -1,5 +1,5 @@ import devalue from 'next/dist/compiled/devalue' -import { Compiler, compilation as CompilationType } from 'webpack' +import webpack, { Compiler, compilation as CompilationType } from 'webpack' import { RawSource } from 'webpack-sources' import { BUILD_MANIFEST, @@ -13,6 +13,8 @@ import { BuildManifest } from '../../../next-server/server/get-page-files' import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint' import { ampFirstEntryNamesMap } from './next-drop-client-page-plugin' +const isWebpack5 = parseInt(webpack.version!) === 5 + // This function takes the asset map generated in BuildManifestPlugin and creates a // reduced version to send to the client. function generateClientManifest( @@ -45,6 +47,17 @@ function isJsFile(file: string): boolean { return !file.endsWith('.hot-update.js') && file.endsWith('.js') } +function getFilesArray(files: any) { + if (!files) { + return [] + } + if (isWebpack5) { + return Array.from(files) + } + + return files +} + // This plugin creates a build-manifest.json for all assets that are being output // It has a mapping of "entry" filename to real filename. Because the real filename can be hashed in production export default class BuildManifestPlugin { @@ -56,143 +69,158 @@ export default class BuildManifestPlugin { this.modern = options.modern } - apply(compiler: Compiler) { - compiler.hooks.emit.tapAsync( - 'NextJsBuildManifest', - (compilation: any, callback: any) => { - const chunks: CompilationType.Chunk[] = compilation.chunks - const assetMap: BuildManifest = { - polyfillFiles: [], - devFiles: [], - ampDevFiles: [], - lowPriorityFiles: [], - pages: { '/_app': [] }, - ampFirstPages: [], - } - - const ampFirstEntryNames = ampFirstEntryNamesMap.get(compilation) - if (ampFirstEntryNames) { - for (const entryName of ampFirstEntryNames) { - const pagePath = getRouteFromEntrypoint(entryName) - if (!pagePath) { - continue - } + createAssets(compilation: any, assets: any) { + const namedChunks: Map = + compilation.namedChunks + const assetMap: BuildManifest = { + polyfillFiles: [], + devFiles: [], + ampDevFiles: [], + lowPriorityFiles: [], + pages: { '/_app': [] }, + ampFirstPages: [], + } - assetMap.ampFirstPages.push(pagePath) - } + const ampFirstEntryNames = ampFirstEntryNamesMap.get(compilation) + if (ampFirstEntryNames) { + for (const entryName of ampFirstEntryNames) { + const pagePath = getRouteFromEntrypoint(entryName) + if (!pagePath) { + continue } - const mainJsChunk = chunks.find( - (c) => c.name === CLIENT_STATIC_FILES_RUNTIME_MAIN - ) - - const mainJsFiles: string[] = mainJsChunk?.files.filter(isJsFile) ?? [] + assetMap.ampFirstPages.push(pagePath) + } + } - const polyfillChunk = chunks.find( - (c) => c.name === CLIENT_STATIC_FILES_RUNTIME_POLYFILLS - ) + const mainJsChunk = namedChunks.get(CLIENT_STATIC_FILES_RUNTIME_MAIN) - // Create a separate entry for polyfills - assetMap.polyfillFiles = polyfillChunk?.files.filter(isJsFile) ?? [] + const mainJsFiles: string[] = getFilesArray(mainJsChunk?.files).filter( + isJsFile + ) - const reactRefreshChunk = chunks.find( - (c) => c.name === CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH - ) - assetMap.devFiles = reactRefreshChunk?.files.filter(isJsFile) ?? [] + const polyfillChunk = namedChunks.get(CLIENT_STATIC_FILES_RUNTIME_POLYFILLS) - for (const entrypoint of compilation.entrypoints.values()) { - const isAmpRuntime = - entrypoint.name === CLIENT_STATIC_FILES_RUNTIME_AMP + // Create a separate entry for polyfills + assetMap.polyfillFiles = getFilesArray(polyfillChunk?.files).filter( + isJsFile + ) - if (isAmpRuntime) { - for (const file of entrypoint.getFiles()) { - if (!(isJsFile(file) || file.endsWith('.css'))) { - continue - } + const reactRefreshChunk = namedChunks.get( + CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH + ) + assetMap.devFiles = getFilesArray(reactRefreshChunk?.files).filter(isJsFile) - assetMap.ampDevFiles.push(file.replace(/\\/g, '/')) - } - continue - } - const pagePath = getRouteFromEntrypoint(entrypoint.name) + for (const entrypoint of compilation.entrypoints.values()) { + const isAmpRuntime = entrypoint.name === CLIENT_STATIC_FILES_RUNTIME_AMP - if (!pagePath) { + if (isAmpRuntime) { + for (const file of entrypoint.getFiles()) { + if (!(isJsFile(file) || file.endsWith('.css'))) { continue } - const filesForEntry: string[] = [] + assetMap.ampDevFiles.push(file.replace(/\\/g, '/')) + } + continue + } + const pagePath = getRouteFromEntrypoint(entrypoint.name) - // getFiles() - helper function to read the files for an entrypoint from stats object - for (const file of entrypoint.getFiles()) { - if (!(isJsFile(file) || file.endsWith('.css'))) { - continue - } + if (!pagePath) { + continue + } - filesForEntry.push(file.replace(/\\/g, '/')) - } + const filesForEntry: string[] = [] - assetMap.pages[pagePath] = [...mainJsFiles, ...filesForEntry] + // getFiles() - helper function to read the files for an entrypoint from stats object + for (const file of entrypoint.getFiles()) { + if (!(isJsFile(file) || file.endsWith('.css'))) { + continue } - // Add the runtime build manifest file (generated later in this file) - // as a dependency for the app. If the flag is false, the file won't be - // downloaded by the client. - assetMap.lowPriorityFiles.push( - `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.js` - ) - if (this.modern) { - assetMap.lowPriorityFiles.push( - `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.module.js` - ) - } + filesForEntry.push(file.replace(/\\/g, '/')) + } - // Add the runtime ssg manifest file as a lazy-loaded file dependency. - // We also stub this file out for development mode (when it is not - // generated). - const srcEmptySsgManifest = `self.__SSG_MANIFEST=new Set;self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()` - - const ssgManifestPath = `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_ssgManifest.js` - assetMap.lowPriorityFiles.push(ssgManifestPath) - compilation.assets[ssgManifestPath] = new RawSource(srcEmptySsgManifest) - - if (this.modern) { - const ssgManifestPathModern = `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_ssgManifest.module.js` - assetMap.lowPriorityFiles.push(ssgManifestPathModern) - compilation.assets[ssgManifestPathModern] = new RawSource( - srcEmptySsgManifest - ) - } + assetMap.pages[pagePath] = [...mainJsFiles, ...filesForEntry] + } - assetMap.pages = Object.keys(assetMap.pages) - .sort() - // eslint-disable-next-line - .reduce((a, c) => ((a[c] = assetMap.pages[c]), a), {} as any) + // Add the runtime build manifest file (generated later in this file) + // as a dependency for the app. If the flag is false, the file won't be + // downloaded by the client. + assetMap.lowPriorityFiles.push( + `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.js` + ) + if (this.modern) { + assetMap.lowPriorityFiles.push( + `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.module.js` + ) + } - compilation.assets[BUILD_MANIFEST] = new RawSource( - JSON.stringify(assetMap, null, 2) - ) + // Add the runtime ssg manifest file as a lazy-loaded file dependency. + // We also stub this file out for development mode (when it is not + // generated). + const srcEmptySsgManifest = `self.__SSG_MANIFEST=new Set;self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()` - const clientManifestPath = `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.js` + const ssgManifestPath = `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_ssgManifest.js` + assetMap.lowPriorityFiles.push(ssgManifestPath) + assets[ssgManifestPath] = new RawSource(srcEmptySsgManifest) - compilation.assets[clientManifestPath] = new RawSource( - `self.__BUILD_MANIFEST = ${generateClientManifest( - assetMap, - false - )};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()` - ) + if (this.modern) { + const ssgManifestPathModern = `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_ssgManifest.module.js` + assetMap.lowPriorityFiles.push(ssgManifestPathModern) + assets[ssgManifestPathModern] = new RawSource(srcEmptySsgManifest) + } - if (this.modern) { - const modernClientManifestPath = `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.module.js` + assetMap.pages = Object.keys(assetMap.pages) + .sort() + // eslint-disable-next-line + .reduce((a, c) => ((a[c] = assetMap.pages[c]), a), {} as any) - compilation.assets[modernClientManifestPath] = new RawSource( - `self.__BUILD_MANIFEST = ${generateClientManifest( - assetMap, - true - )};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()` - ) - } - callback() - } + assets[BUILD_MANIFEST] = new RawSource(JSON.stringify(assetMap, null, 2)) + + const clientManifestPath = `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.js` + + assets[clientManifestPath] = new RawSource( + `self.__BUILD_MANIFEST = ${generateClientManifest( + assetMap, + false + )};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()` ) + + if (this.modern) { + const modernClientManifestPath = `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.module.js` + + assets[modernClientManifestPath] = new RawSource( + `self.__BUILD_MANIFEST = ${generateClientManifest( + assetMap, + true + )};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()` + ) + } + + return assets + } + + apply(compiler: Compiler) { + if (isWebpack5) { + compiler.hooks.make.tap('NextJsBuildManifest', (compilation) => { + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + compilation.hooks.processAssets.tap( + { + name: 'NextJsBuildManifest', + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, + }, + (assets: any) => { + this.createAssets(compilation, assets) + } + ) + }) + return + } + + compiler.hooks.emit.tap('NextJsBuildManifest', (compilation: any) => { + this.createAssets(compilation, compilation.assets) + }) } } diff --git a/packages/next/build/webpack/plugins/pages-manifest-plugin.ts b/packages/next/build/webpack/plugins/pages-manifest-plugin.ts index 53fffe7b1fee1..94557901c74ba 100644 --- a/packages/next/build/webpack/plugins/pages-manifest-plugin.ts +++ b/packages/next/build/webpack/plugins/pages-manifest-plugin.ts @@ -1,10 +1,12 @@ -import { Compiler, Plugin } from 'webpack' +import webpack, { Compiler, Plugin } from 'webpack' import { RawSource } from 'webpack-sources' import { PAGES_MANIFEST } from '../../../next-server/lib/constants' import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint' export type PagesManifest = { [page: string]: string } +const isWebpack5 = parseInt(webpack.version!) === 5 + // This plugin creates a pages-manifest.json from page entrypoints. // This is used for mapping paths like `/` to `.next/server/static//pages/index.js` when doing SSR // It's also used by next export to provide defaultPathMap @@ -15,43 +17,59 @@ export default class PagesManifestPlugin implements Plugin { this.serverless = serverless } - apply(compiler: Compiler): void { - compiler.hooks.emit.tap('NextJsPagesManifest', (compilation) => { - const entrypoints = compilation.entrypoints - const pages: PagesManifest = {} - - for (const entrypoint of entrypoints.values()) { - const pagePath = getRouteFromEntrypoint( - entrypoint.name, - this.serverless + createAssets(compilation: any, assets: any) { + const entrypoints = compilation.entrypoints + const pages: PagesManifest = {} + + for (const entrypoint of entrypoints.values()) { + const pagePath = getRouteFromEntrypoint(entrypoint.name, this.serverless) + + if (!pagePath) { + continue + } + + const files = entrypoint + .getFiles() + .filter( + (file: string) => + !file.includes('webpack-runtime') && file.endsWith('.js') ) - if (!pagePath) { - continue - } - - const files = entrypoint - .getFiles() - .filter( - (file: string) => - !file.includes('webpack-runtime') && file.endsWith('.js') - ) - - if (files.length > 1) { - console.log( - `Found more than one file in server entrypoint ${entrypoint.name}`, - files - ) - continue - } - - // Write filename, replace any backslashes in path (on windows) with forwardslashes for cross-platform consistency. - pages[pagePath] = files[0].replace(/\\/g, '/') + if (files.length > 1) { + console.log( + `Found more than one file in server entrypoint ${entrypoint.name}`, + files + ) + continue } - compilation.assets[PAGES_MANIFEST] = new RawSource( - JSON.stringify(pages, null, 2) - ) + // Write filename, replace any backslashes in path (on windows) with forwardslashes for cross-platform consistency. + pages[pagePath] = files[0].replace(/\\/g, '/') + } + + assets[PAGES_MANIFEST] = new RawSource(JSON.stringify(pages, null, 2)) + } + + apply(compiler: Compiler): void { + if (isWebpack5) { + compiler.hooks.make.tap('NextJsPagesManifest', (compilation) => { + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + compilation.hooks.processAssets.tap( + { + name: 'NextJsPagesManifest', + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, + }, + (assets: any) => { + this.createAssets(compilation, assets) + } + ) + }) + return + } + + compiler.hooks.emit.tap('NextJsPagesManifest', (compilation: any) => { + this.createAssets(compilation, compilation.assets) }) } } diff --git a/packages/next/build/webpack/plugins/react-loadable-plugin.ts b/packages/next/build/webpack/plugins/react-loadable-plugin.ts index afd16f1fe63d3..d39f78a943ed2 100644 --- a/packages/next/build/webpack/plugins/react-loadable-plugin.ts +++ b/packages/next/build/webpack/plugins/react-loadable-plugin.ts @@ -21,12 +21,30 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWAR // Implementation of this PR: https://github.com/jamiebuilds/react-loadable/pull/132 // Modified to strip out unneeded results for Next's specific use case -import { +import webpack, { Compiler, // eslint-disable-next-line @typescript-eslint/no-unused-vars compilation as CompilationType, } from 'webpack' +const isWebpack5 = parseInt(webpack.version!) === 5 + +function getModulesIterable(compilation: any, chunk: any) { + if (isWebpack5) { + return compilation.chunkGraph.getChunkModulesIterable(chunk) + } + + return chunk.modulesIterable +} + +function getModuleId(compilation: any, module: any) { + if (isWebpack5) { + return compilation.chunkGraph.getModuleId(module) + } + + return module.id +} + function buildManifest( _compiler: Compiler, compilation: CompilationType.Compilation @@ -47,8 +65,8 @@ function buildManifest( return } - for (const module of chunk.modulesIterable) { - let id = module.id + for (const module of getModulesIterable(compilation, chunk)) { + let id = getModuleId(compilation, module) if (!manifest[request]) { manifest[request] = [] @@ -88,22 +106,40 @@ export class ReactLoadablePlugin { this.filename = opts.filename } + createAssets(compiler: any, compilation: any, assets: any) { + const manifest = buildManifest(compiler, compilation) + var json = JSON.stringify(manifest, null, 2) + assets[this.filename] = { + source() { + return json + }, + size() { + return json.length + }, + } + return assets + } + apply(compiler: Compiler) { - compiler.hooks.emit.tapAsync( - 'ReactLoadableManifest', - (compilation, callback) => { - const manifest = buildManifest(compiler, compilation) - var json = JSON.stringify(manifest, null, 2) - compilation.assets[this.filename] = { - source() { - return json - }, - size() { - return json.length + if (isWebpack5) { + compiler.hooks.make.tap('ReactLoadableManifest', (compilation) => { + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + compilation.hooks.processAssets.tap( + { + name: 'ReactLoadableManifest', + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, }, - } - callback() - } - ) + (assets: any) => { + this.createAssets(compiler, compilation, assets) + } + ) + }) + return + } + + compiler.hooks.emit.tap('ReactLoadableManifest', (compilation: any) => { + this.createAssets(compiler, compilation, compilation.assets) + }) } } diff --git a/packages/next/build/webpack/plugins/serverless-plugin.ts b/packages/next/build/webpack/plugins/serverless-plugin.ts index 92035a77c8e6d..b8599ba772b91 100644 --- a/packages/next/build/webpack/plugins/serverless-plugin.ts +++ b/packages/next/build/webpack/plugins/serverless-plugin.ts @@ -29,13 +29,18 @@ export class ServerlessPlugin { // Async chunks are usages of import() for example const dynamicChunks = chunk.getAllAsyncChunks() for (const dynamicChunk of dynamicChunks) { - for (const module of dynamicChunk.modulesIterable) { - if (isWebpack5) { + if (isWebpack5) { + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + for (const module of compilation.chunkGraph.getChunkModulesIterable( + chunk + )) { // Add module back into the entry chunk chunk.addModule(module) - continue } + continue + } + for (const module of dynamicChunk.modulesIterable) { // Webpack 4 has separate GraphHelpers GraphHelpers.connectChunkAndModule(chunk, module) } diff --git a/packages/next/server/hot-reloader.ts b/packages/next/server/hot-reloader.ts index c6107375b1926..5c7d8d7b37859 100644 --- a/packages/next/server/hot-reloader.ts +++ b/packages/next/server/hot-reloader.ts @@ -368,9 +368,7 @@ export default class HotReloader { // We only watch `_document` for changes on the server compilation // the rest of the files will be triggered by the client compilation - const documentChunk = compilation.chunks.find( - (c) => c.name === `pages/_document` - ) + const documentChunk = compilation.namedChunks.get('pages/_document') // If the document chunk can't be found we do nothing if (!documentChunk) { console.warn('_document.js chunk not found') @@ -409,9 +407,9 @@ export default class HotReloader { const { compilation } = stats const chunkNames = new Set( - compilation.chunks - .map((c) => c.name) - .filter((name) => !!getRouteFromEntrypoint(name)) + [...compilation.namedChunks.keys()].filter( + (name) => !!getRouteFromEntrypoint(name) + ) ) if (this.prevChunkNames) { From 60f1d58c837ac604ce8fa475bf592457119f82cc Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 3 Aug 2020 14:57:17 +0200 Subject: [PATCH 89/90] Fix some webpack 5 deprecation warnings (#15797) - Use latest terser version (still 1 warning in the stable version which is an open PR) - Add emitOnErrors instead of noEmitOnErrors - Added trace-deprecations for Next.js core development --- package.json | 2 +- packages/next/build/webpack-config.ts | 3 +- .../compiled/terser-webpack-plugin/cjs.js | 2 +- .../{worker.js => minify.js} | 16 +- packages/next/package.json | 4 +- packages/next/taskfile-ncc.js | 4 +- yarn.lock | 175 ++++++++++++++---- 7 files changed, 151 insertions(+), 55 deletions(-) rename packages/next/compiled/terser-webpack-plugin/{worker.js => minify.js} (96%) diff --git a/package.json b/package.json index ebc26531786f3..8f8e504e3c95b 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "publish-canary": "lerna version prerelease --preid canary --force-publish && release --pre --skip-questions", "publish-stable": "lerna version --force-publish", "lint-staged": "lint-staged", - "next": "node packages/next/dist/bin/next", + "next": "node --trace-deprecation packages/next/dist/bin/next", "debug": "node --inspect packages/next/dist/bin/next" }, "pre-commit": "lint-staged", diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index bdc254196cf69..aa1e429c2467b 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -662,7 +662,8 @@ export default async function getBaseWebpackConfig( '@ampproject/toolbox-optimizer', // except this one ], optimization: { - noEmitOnErrors: dev, + // Webpack 5 uses a new property for the same functionality + ...(isWebpack5 ? { emitOnErrors: !dev } : { noEmitOnErrors: dev }), checkWasmTypes: false, nodeEnv: false, splitChunks: isServer ? false : splitChunksConfig, diff --git a/packages/next/compiled/terser-webpack-plugin/cjs.js b/packages/next/compiled/terser-webpack-plugin/cjs.js index d5b36c381641c..dd73011cfd49a 100644 --- a/packages/next/compiled/terser-webpack-plugin/cjs.js +++ b/packages/next/compiled/terser-webpack-plugin/cjs.js @@ -1 +1 @@ -module.exports=function(e,t){"use strict";var r={};function __webpack_require__(t){if(r[t]){return r[t].exports}var n=r[t]={i:t,l:false,exports:{}};e[t].call(n.exports,n,n.exports,__webpack_require__);n.l=true;return n.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(596)}t(__webpack_require__);return startup()}({67:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var n=_interopRequireDefault(r(622));var i=r(241);var s=r(745);var o=_interopRequireDefault(r(432));var a=r(78);var u=_interopRequireDefault(r(134));var c=_interopRequireDefault(r(946));var l=_interopRequireDefault(r(352));var f=_interopRequireDefault(r(916));var p=_interopRequireDefault(r(838));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const d=/\[.+:([0-9]+),([0-9]+)\]/;class TerserPlugin{constructor(e={}){(0,u.default)(f.default,e,{name:"Terser Plugin",baseDataPath:"options"});const{minify:t,terserOptions:r={},test:n=/\.m?js(\?.*)?$/i,chunkFilter:i=(()=>true),warningsFilter:s=(()=>true),extractComments:o=true,sourceMap:a,cache:c=true,cacheKeys:l=(e=>e),parallel:p=true,include:d,exclude:m}=e;this.options={test:n,chunkFilter:i,warningsFilter:s,extractComments:o,sourceMap:a,cache:c,cacheKeys:l,parallel:p,include:d,exclude:m,minify:t,terserOptions:r}}static isSourceMap(e){return Boolean(e&&e.version&&e.sources&&Array.isArray(e.sources)&&typeof e.mappings==="string")}static buildSourceMap(e){if(!e||!TerserPlugin.isSourceMap(e)){return null}return new i.SourceMapConsumer(e)}static buildError(e,t,r,n){if(e.line){const i=r&&r.originalPositionFor({line:e.line,column:e.col});if(i&&i.source&&n){return new Error(`${t} from Terser\n${e.message} [${n.shorten(i.source)}:${i.line},${i.column}][${t}:${e.line},${e.col}]${e.stack?`\n${e.stack.split("\n").slice(1).join("\n")}`:""}`)}return new Error(`${t} from Terser\n${e.message} [${t}:${e.line},${e.col}]${e.stack?`\n${e.stack.split("\n").slice(1).join("\n")}`:""}`)}if(e.stack){return new Error(`${t} from Terser\n${e.stack}`)}return new Error(`${t} from Terser\n${e.message}`)}static buildWarning(e,t,r,n,i){let s=e;let o="";let a=null;if(r){const i=d.exec(e);if(i){const e=+i[1];const u=+i[2];const c=r.originalPositionFor({line:e,column:u});if(c&&c.source&&c.source!==t&&n){({source:a}=c);s=`${s.replace(d,"")}`;o=`[${n.shorten(c.source)}:${c.line},${c.column}]`}}}if(i&&!i(e,a,t)){return null}return`Terser Plugin: ${s}${o}`}static removeQueryString(e){let t=e;const r=t.indexOf("?");if(r>=0){t=t.substr(0,r)}return t}static hasAsset(e,t){const r=Object.keys(t).map(e=>TerserPlugin.removeQueryString(e));return r.includes(TerserPlugin.removeQueryString(e))}static isWebpack4(){return a.version[0]==="4"}*taskGenerator(e,t,i,u){let c;const f=t.assets[u];try{let p;if(this.options.sourceMap&&f.sourceAndMap){const{source:e,map:r}=f.sourceAndMap();p=e;if(TerserPlugin.isSourceMap(r)){c=r}else{c=r;t.warnings.push(new Error(`${u} contains invalid source map`))}}else{p=f.source();c=null}let d=false;if(this.options.extractComments){d=this.options.extractComments.filename||"[file].LICENSE.txt[query]";if(TerserPlugin.isWebpack4()){if(typeof d==="function"){d=d.bind(null,u)}}let e="";let r=u;const n=r.indexOf("?");if(n>=0){e=r.substr(n);r=r.substr(0,n)}const i=r.lastIndexOf("/");const s=i===-1?r:r.substr(i+1);const o={filename:r,basename:s,query:e};d=t.getPath(d,o)}if(d&&TerserPlugin.hasAsset(d,t.assets)){t.warnings.push(new Error(`The comment file "${TerserPlugin.removeQueryString(d)}" conflicts with an existing asset, this may lead to code corruption, please use a different name`))}const m=r=>{let{code:a}=r;const{error:l,map:f,warnings:m}=r;const{extractedComments:h}=r;let g=null;if(l||m&&m.length>0){g=TerserPlugin.buildSourceMap(c)}if(l){t.errors.push(TerserPlugin.buildError(l,u,g,new o.default(e.context)));return}const b=d&&h&&h.length>0;const y=b&&this.options.extractComments.banner!==false;let v;let _;if(b&&y&&a.startsWith("#!")){const e=a.indexOf("\n");_=a.substring(0,e);a=a.substring(e+1)}if(f){v=new s.SourceMapSource(a,u,f,p,c,true)}else{v=new s.RawSource(a)}if(b){if(!i[d]){i[d]=[]}i[d]=i[d].concat(h);if(y){let e=this.options.extractComments.banner||`For license information please see ${n.default.relative(n.default.dirname(u),d).replace(/\\/g,"/")}`;if(typeof e==="function"){e=e(d)}if(e){v=new s.ConcatSource(_?`${_}\n`:"",`/*! ${e} */\n`,v)}}}t.assets[u]=v;if(m&&m.length>0){m.forEach(r=>{const n=TerserPlugin.buildWarning(r,u,g,new o.default(e.context),this.options.warningsFilter);if(n){t.warnings.push(n)}})}};const h={asset:f,file:u,input:p,inputSourceMap:c,commentsFilename:d,extractComments:this.options.extractComments,terserOptions:this.options.terserOptions,minify:this.options.minify,callback:m};if(TerserPlugin.isWebpack4()){const{outputOptions:{hashSalt:e,hashDigest:n,hashDigestLength:i,hashFunction:s}}=t;const o=a.util.createHash(s);if(e){o.update(e)}o.update(p);const c=o.digest(n);if(this.options.cache){const e={terser:l.default.version,"terser-webpack-plugin":r(379).version,"terser-webpack-plugin-options":this.options,nodeVersion:process.version,filename:u,contentHash:c.substr(0,i)};h.cacheKeys=this.options.cacheKeys(e,u)}}else{h.cacheKeys={terser:l.default.version,"terser-webpack-plugin":r(379).version,"terser-webpack-plugin-options":this.options}}yield h}catch(r){t.errors.push(TerserPlugin.buildError(r,u,TerserPlugin.buildSourceMap(c),new o.default(e.context)))}}apply(e){const{devtool:t,output:n,plugins:i}=e.options;this.options.sourceMap=typeof this.options.sourceMap==="undefined"?t&&!t.includes("eval")&&!t.includes("cheap")&&(t.includes("source-map")||t.includes("sourcemap"))||i&&i.some(e=>e instanceof a.SourceMapDevToolPlugin&&e.options&&e.options.columns):Boolean(this.options.sourceMap);if(typeof this.options.terserOptions.module==="undefined"&&typeof n.module!=="undefined"){this.options.terserOptions.module=n.module}if(typeof this.options.terserOptions.ecma==="undefined"&&typeof n.ecmaVersion!=="undefined"){this.options.terserOptions.ecma=n.ecmaVersion}const o=async(t,n)=>{const i=a.ModuleFilenameHelpers.matchObject.bind(undefined,this.options);const o=[].concat(Array.from(t.additionalChunkAssets||[])).concat(Array.from(n).filter(e=>this.options.chunkFilter&&this.options.chunkFilter(e)).reduce((e,t)=>e.concat(Array.from(t.files||[])),[])).filter(e=>i(e));if(o.length===0){return Promise.resolve()}const u=TerserPlugin.isWebpack4()?r(314).default:r(428).default;const c={};const l=this.taskGenerator.bind(this,e,t,c);const f=new p.default({taskGenerator:l,files:o,cache:new u(e,t,this.options),parallel:this.options.parallel});await f.run();await f.exit();Object.keys(c).forEach(e=>{const r=new Set([...c[e].sort()]);t.assets[e]=new s.RawSource(`${Array.from(r).join("\n\n")}\n`)});return Promise.resolve()};const u={name:this.constructor.name};e.hooks.compilation.tap(u,e=>{if(this.options.sourceMap){e.hooks.buildModule.tap(u,e=>{e.useSourceMap=true})}if(!TerserPlugin.isWebpack4()){const t=a.javascript.JavascriptModulesPlugin.getCompilationHooks(e);const r=(0,c.default)({terser:l.default.version,terserOptions:this.options.terserOptions});t.chunkHash.tap(u,(e,t)=>{t.update("TerserPlugin");t.update(r)})}else{const{mainTemplate:t,chunkTemplate:r}=e;const n=(0,c.default)({terser:l.default.version,terserOptions:this.options.terserOptions});for(const e of[t,r]){e.hooks.hashForChunk.tap(u,e=>{e.update("TerserPlugin");e.update(n)})}}e.hooks.optimizeChunkAssets.tapPromise(u,o.bind(this,e))})}}var m=TerserPlugin;t.default=m},78:function(e){e.exports=require("webpack")},87:function(e){e.exports=require("os")},134:function(e){e.exports=require("schema-utils")},240:function(e){e.exports=require("find-cache-dir")},241:function(e){e.exports=require("next/dist/compiled/source-map")},314:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var n=_interopRequireDefault(r(87));var i=_interopRequireDefault(r(635));var s=_interopRequireDefault(r(240));var o=_interopRequireDefault(r(946));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}class Webpack4Cache{constructor(e,t,r){this.options=r;this.cacheDir=r.cache===true?Webpack4Cache.getCacheDirectory():r.cache}static getCacheDirectory(){return(0,s.default)({name:"terser-webpack-plugin"})||n.default.tmpdir()}isEnabled(){return!!this.cacheDir}get(e){e.cacheIdent=e.cacheIdent||(0,o.default)(e.cacheKeys);return i.default.get(this.cacheDir,e.cacheIdent).then(({data:e})=>JSON.parse(e))}store(e,t){return i.default.put(this.cacheDir,e.cacheIdent,JSON.stringify(t))}}t.default=Webpack4Cache},352:function(e){e.exports={name:"terser",description:"JavaScript parser, mangler/compressor and beautifier toolkit for ES6+",homepage:"https://terser.org",author:"Mihai Bazon (http://lisperator.net/)",license:"BSD-2-Clause",version:"4.6.11",engines:{node:">=6.0.0"},maintainers:["Fábio Santos "],repository:"https://github.com/terser/terser",main:"dist/bundle.min.js",types:"tools/terser.d.ts",bin:{terser:"bin/terser"},files:["bin","dist","tools","LICENSE","README.md","CHANGELOG.md","PATRONS.md"],dependencies:{commander:"^2.20.0","source-map":"~0.6.1","source-map-support":"~0.5.12"},devDependencies:{acorn:"^7.1.1",astring:"^1.4.1",eslint:"^6.3.0",eslump:"^2.0.0",mocha:"^7.1.0",mochallel:"^2.0.0","pre-commit":"^1.2.2",rimraf:"^3.0.0",rollup:"2.0.6","rollup-plugin-terser":"5.3.0",semver:"^7.1.3"},scripts:{test:"npm run build -- --configTest && node test/run-tests.js","test:compress":"npm run build -- --configTest && node test/compress.js","test:mocha":"npm run build -- --configTest && node test/mocha.js",lint:"eslint lib","lint-fix":"eslint --fix lib",build:"rimraf dist/* && rollup --config --silent",prepare:"npm run build",postversion:"echo 'Remember to update the changelog!'"},keywords:["uglify","terser","uglify-es","uglify-js","minify","minifier","javascript","ecmascript","es5","es6","es7","es8","es2015","es2016","es2017","async","await"],eslintConfig:{parserOptions:{sourceType:"module"},env:{es6:true},globals:{describe:false,it:false,require:false,global:false,process:false},rules:{"brace-style":["error","1tbs",{allowSingleLine:true}],quotes:["error","double","avoid-escape"],"no-debugger":"error","no-undef":"error","no-unused-vars":["error",{varsIgnorePattern:"^_$"}],"no-tabs":"error",semi:["error","always"],"no-extra-semi":"error","no-irregular-whitespace":"error","space-before-blocks":["error","always"]}},"pre-commit":["lint-fix","test"]}},379:function(e){e.exports={name:"terser-webpack-plugin",version:"2.3.5",description:"Terser plugin for webpack",license:"MIT",author:"webpack Contrib Team",main:"cjs.js",engines:{node:">= 8.9.0"},peerDependencies:{webpack:"^4.0.0 || ^5.0.0"},dependencies:{cacache:"^13.0.1","find-cache-dir":"^3.2.0","jest-worker":"^25.1.0","p-limit":"^2.2.2","schema-utils":"^2.6.4","serialize-javascript":"^2.1.2","source-map":"^0.6.1",terser:"^4.4.3","webpack-sources":"^1.4.3"}}},428:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var n=_interopRequireDefault(r(575));var i=_interopRequireDefault(r(946));var s=r(78);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}class Cache{constructor(e,t,r){this.compiler=e;this.compilation=t;this.options=r}isEnabled(){return!!this.compilation.cache}createCacheIdent(e){const{outputOptions:{hashSalt:t,hashDigest:r,hashDigestLength:n,hashFunction:o}}=this.compilation;const a=s.util.createHash(o);if(t){a.update(t)}a.update((0,i.default)(e.cacheKeys));const u=a.digest(r);const c=u.substr(0,n);return`${this.compilation.compilerPath}/TerserWebpackPlugin/${c}/${e.file}`}get(e){e.cacheIdent=e.cacheIdent||this.createCacheIdent(e);e.cacheETag=e.cacheETag||(0,n.default)(e.asset);return new Promise((t,r)=>{this.compilation.cache.get(e.cacheIdent,e.cacheETag,(e,n)=>{if(e){r(e)}else if(n){t(n)}else{r()}})})}store(e,t){return new Promise((r,n)=>{this.compilation.cache.store(e.cacheIdent,e.cacheETag,t,e=>{if(e){n(e)}else{r(t)}})})}}t.default=Cache},429:function(e){"use strict";const t=(e,...t)=>new Promise(r=>{r(e(...t))});e.exports=t;e.exports.default=t},432:function(e){e.exports=require("webpack/lib/RequestShortener")},466:function(e,t,r){"use strict";e=r.nmd(e);const{minify:n}=r(775);const i=({ecma:e,warnings:t,parse:r={},compress:n={},mangle:i,module:s,output:o,toplevel:a,nameCache:u,ie8:c,keep_classnames:l,keep_fnames:f,safari10:p}={})=>({ecma:e,warnings:t,parse:{...r},compress:typeof n==="boolean"?n:{...n},mangle:i==null?true:typeof i==="boolean"?i:{...i},output:{beautify:false,...o},module:s,sourceMap:null,toplevel:a,nameCache:u,ie8:c,keep_classnames:l,keep_fnames:f,safari10:p});function isObject(e){const t=typeof e;return e!=null&&(t==="object"||t==="function")}const s=(e,t,r)=>{const n={};const i=t.output.comments;const{extractComments:s}=e;n.preserve=typeof i!=="undefined"?i:false;if(typeof s==="boolean"&&s){n.extract="some"}else if(typeof s==="string"||s instanceof RegExp){n.extract=s}else if(typeof s==="function"){n.extract=s}else if(isObject(s)){n.extract=typeof s.condition==="boolean"&&s.condition?"some":typeof s.condition!=="undefined"?s.condition:"some"}else{n.preserve=typeof i!=="undefined"?i:"some";n.extract=false}["preserve","extract"].forEach(e=>{let t;let r;switch(typeof n[e]){case"boolean":n[e]=n[e]?()=>true:()=>false;break;case"function":break;case"string":if(n[e]==="all"){n[e]=(()=>true);break}if(n[e]==="some"){n[e]=((e,t)=>{return t.type==="comment2"&&/@preserve|@lic|@cc_on|^\**!/i.test(t.value)});break}t=n[e];n[e]=((e,r)=>{return new RegExp(t).test(r.value)});break;default:r=n[e];n[e]=((e,t)=>r.test(t.value))}});return(e,t)=>{if(n.extract(e,t)){const e=t.type==="comment2"?`/*${t.value}*/`:`//${t.value}`;if(!r.includes(e)){r.push(e)}}return n.preserve(e,t)}};const o=e=>{const{file:t,input:r,inputSourceMap:o,minify:a}=e;if(a){return a({[t]:r},o)}const u=i(e.terserOptions);if(o){u.sourceMap={asObject:true}}const c=[];u.output.comments=s(e,u,c);const{error:l,map:f,code:p,warnings:d}=n({[t]:r},u);return{error:l,map:f,code:p,warnings:d,extractedComments:c}};function transform(r){r=new Function("exports","require","module","__filename","__dirname",`'use strict'\nreturn ${r}`)(t,require,e,__filename,__dirname);const n=o(r);if(n.error){throw n.error}else{return n}}e.exports.minify=o;e.exports.transform=transform},495:function(e,t,r){"use strict";const n=r(429);const i=e=>{if(!((Number.isInteger(e)||e===Infinity)&&e>0)){return Promise.reject(new TypeError("Expected `concurrency` to be a number from 1 and up"))}const t=[];let r=0;const i=()=>{r--;if(t.length>0){t.shift()()}};const s=(e,t,...s)=>{r++;const o=n(e,...s);t(o);o.then(i,i)};const o=(n,i,...o)=>{if(rnew Promise(r=>o(e,r,...t));Object.defineProperties(a,{activeCount:{get:()=>r},pendingCount:{get:()=>t.length},clearQueue:{value:()=>{t.length=0}}});return a};e.exports=i;e.exports.default=i},575:function(e){e.exports=require("webpack/lib/cache/getLazyHashedEtag")},596:function(e,t,r){"use strict";const n=r(67);e.exports=n.default},622:function(e){e.exports=require("path")},635:function(e){e.exports=require("cacache")},733:function(e){e.exports=require("jest-worker")},745:function(e){e.exports=require("webpack-sources")},775:function(e){e.exports=require("next/dist/compiled/terser")},838:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var n=_interopRequireDefault(r(87));var i=_interopRequireDefault(r(495));var s=_interopRequireDefault(r(733));var o=_interopRequireDefault(r(946));var a=r(466);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const u=r.ab+"worker.js";class TaskRunner{constructor(e={}){this.taskGenerator=e.taskGenerator;this.files=e.files;this.cache=e.cache;this.availableNumberOfCores=TaskRunner.getAvailableNumberOfCores(e.parallel)}static getAvailableNumberOfCores(e){const t=n.default.cpus()||{length:1};return e===true?t.length-1:Math.min(Number(e)||0,t.length-1)}async runTask(e){if(this.worker){return this.worker.transform((0,o.default)(e))}return(0,a.minify)(e)}async run(){const{availableNumberOfCores:e,cache:t,files:n,taskGenerator:o}=this;let a=Infinity;if(e>0){const t=Math.min(n.length,e);a=t;this.worker=new s.default(r.ab+"worker.js",{numWorkers:t});const i=this.worker.getStdout();if(i){i.on("data",e=>{return process.stdout.write(e)})}const o=this.worker.getStderr();if(o){o.on("data",e=>{return process.stderr.write(e)})}}const u=(0,i.default)(a);const c=[];for(const e of n){const r=async e=>{let r;try{r=await this.runTask(e)}catch(e){r={error:e}}if(t.isEnabled()&&!r.error){r=await t.store(e,r).then(()=>r,()=>r)}e.callback(r);return r};c.push(u(()=>{const n=o(e).next().value;if(!n){return Promise.resolve()}if(t.isEnabled()){return t.get(n).then(e=>n.callback(e),()=>r(n))}return r(n)}))}return Promise.all(c)}async exit(){if(!this.worker){return Promise.resolve()}return this.worker.end()}}t.default=TaskRunner},916:function(e){e.exports={additionalProperties:false,definitions:{"file-conditions":{anyOf:[{instanceof:"RegExp"},{type:"string"}]}},properties:{test:{anyOf:[{$ref:"#/definitions/file-conditions"},{items:{anyOf:[{$ref:"#/definitions/file-conditions"}]},type:"array"}]},include:{anyOf:[{$ref:"#/definitions/file-conditions"},{items:{anyOf:[{$ref:"#/definitions/file-conditions"}]},type:"array"}]},exclude:{anyOf:[{$ref:"#/definitions/file-conditions"},{items:{anyOf:[{$ref:"#/definitions/file-conditions"}]},type:"array"}]},chunkFilter:{instanceof:"Function"},cache:{anyOf:[{type:"boolean"},{type:"string"}]},cacheKeys:{instanceof:"Function"},parallel:{anyOf:[{type:"boolean"},{type:"integer"}]},sourceMap:{type:"boolean"},minify:{instanceof:"Function"},terserOptions:{additionalProperties:true,type:"object"},extractComments:{anyOf:[{type:"boolean"},{type:"string"},{instanceof:"RegExp"},{instanceof:"Function"},{additionalProperties:false,properties:{condition:{anyOf:[{type:"boolean"},{type:"string"},{instanceof:"RegExp"},{instanceof:"Function"}]},filename:{anyOf:[{type:"string"},{instanceof:"Function"}]},banner:{anyOf:[{type:"boolean"},{type:"string"},{instanceof:"Function"}]}},type:"object"}]},warningsFilter:{instanceof:"Function"}},type:"object"}},946:function(e){"use strict";var t=Math.floor(Math.random()*1099511627776).toString(16);var r=new RegExp('"@__(F|R|D|M|S|U)-'+t+'-(\\d+)__@"',"g");var n=/\{\s*\[native code\]\s*\}/g;var i=/function.*?\(/;var s=/.*?=>.*?/;var o=/[<>\/\u2028\u2029]/g;var a=["*","async"];var u={"<":"\\u003C",">":"\\u003E","/":"\\u002F","\u2028":"\\u2028","\u2029":"\\u2029"};function escapeUnsafeChars(e){return u[e]}function deleteFunctions(e){var t=[];for(var r in e){if(typeof e[r]==="function"){t.push(r)}}for(var n=0;n0});var u=o.filter(function(e){return a.indexOf(e)===-1});if(u.length>0){return(o.indexOf("async")>-1?"async ":"")+"function"+(o.join("").indexOf("*")>-1?"*":"")+t.substr(r)}return t}if(u.ignoreFunction&&typeof e==="function"){e=undefined}if(e===undefined){return String(e)}var h;if(u.isJSON&&!u.space){h=JSON.stringify(e)}else{h=JSON.stringify(e,u.isJSON?null:replacer,u.space)}if(typeof h!=="string"){return String(h)}if(u.unsafe!==true){h=h.replace(o,escapeUnsafeChars)}if(c.length===0&&l.length===0&&f.length===0&&p.length===0&&d.length===0&&m.length===0){return h}return h.replace(r,function(e,t,r){if(t==="D"){return'new Date("'+f[r].toISOString()+'")'}if(t==="R"){return"new RegExp("+serialize(l[r].source)+', "'+l[r].flags+'")'}if(t==="M"){return"new Map("+serialize(Array.from(p[r].entries()),u)+")"}if(t==="S"){return"new Set("+serialize(Array.from(d[r].values()),u)+")"}if(t==="U"){return"undefined"}var n=c[r];return serializeFunc(n)})}}},function(e){"use strict";!function(){e.nmd=function(e){e.paths=[];if(!e.children)e.children=[];Object.defineProperty(e,"loaded",{enumerable:true,get:function(){return e.l}});Object.defineProperty(e,"id",{enumerable:true,get:function(){return e.i}});return e}}()}); \ No newline at end of file +module.exports=function(e,t){"use strict";var r={};function __webpack_require__(t){if(r[t]){return r[t].exports}var n=r[t]={i:t,l:false,exports:{}};e[t].call(n.exports,n,n.exports,__webpack_require__);n.l=true;return n.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(330)}t(__webpack_require__);return startup()}({78:function(e){e.exports=require("webpack")},87:function(e){e.exports=require("os")},134:function(e){e.exports=require("schema-utils")},240:function(e){e.exports=require("find-cache-dir")},241:function(e){e.exports=require("next/dist/compiled/source-map")},305:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var n=_interopRequireDefault(r(622));var i=_interopRequireDefault(r(87));var s=r(241);var o=r(745);var a=_interopRequireDefault(r(432));var c=r(78);var u=_interopRequireDefault(r(134));var l=_interopRequireDefault(r(946));var f=_interopRequireDefault(r(403));var p=_interopRequireDefault(r(499));var d=_interopRequireDefault(r(733));var m=_interopRequireDefault(r(825));var g=r(726);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const b=/\[.+:([0-9]+),([0-9]+)\]/;class TerserPlugin{constructor(e={}){(0,u.default)(m.default,e,{name:"Terser Plugin",baseDataPath:"options"});const{minify:t,terserOptions:r={},test:n=/\.m?js(\?.*)?$/i,warningsFilter:i=(()=>true),extractComments:s=true,sourceMap:o,cache:a=true,cacheKeys:c=(e=>e),parallel:l=true,include:f,exclude:p}=e;this.options={test:n,warningsFilter:i,extractComments:s,sourceMap:o,cache:a,cacheKeys:c,parallel:l,include:f,exclude:p,minify:t,terserOptions:r}}static isSourceMap(e){return Boolean(e&&e.version&&e.sources&&Array.isArray(e.sources)&&typeof e.mappings==="string")}static buildSourceMap(e){if(!e||!TerserPlugin.isSourceMap(e)){return null}return new s.SourceMapConsumer(e)}static buildError(e,t,r,n){if(e.line){const i=r&&r.originalPositionFor({line:e.line,column:e.col});if(i&&i.source&&n){return new Error(`${t} from Terser\n${e.message} [${n.shorten(i.source)}:${i.line},${i.column}][${t}:${e.line},${e.col}]${e.stack?`\n${e.stack.split("\n").slice(1).join("\n")}`:""}`)}return new Error(`${t} from Terser\n${e.message} [${t}:${e.line},${e.col}]${e.stack?`\n${e.stack.split("\n").slice(1).join("\n")}`:""}`)}if(e.stack){return new Error(`${t} from Terser\n${e.stack}`)}return new Error(`${t} from Terser\n${e.message}`)}static buildWarning(e,t,r,n,i){let s=e;let o="";let a;if(r){const i=b.exec(e);if(i){const e=+i[1];const c=+i[2];const u=r.originalPositionFor({line:e,column:c});if(u&&u.source&&u.source!==t&&n){({source:a}=u);s=`${s.replace(b,"")}`;o=`[${n.shorten(u.source)}:${u.line},${u.column}]`}}}if(i&&!i(e,t,a)){return null}return`Terser Plugin: ${s}${o}`}static removeQueryString(e){let t=e;const r=t.indexOf("?");if(r>=0){t=t.substr(0,r)}return t}static isWebpack4(){return c.version[0]==="4"}static getAvailableNumberOfCores(e){const t=i.default.cpus()||{length:1};return e===true?t.length-1:Math.min(Number(e)||0,t.length-1)}*taskGenerator(e,t,i,s){const u=t.assets[s];let l;let p;if(this.options.sourceMap&&u.sourceAndMap){const{source:e,map:r}=u.sourceAndMap();l=e;if(r){if(TerserPlugin.isSourceMap(r)){p=r}else{p=r;t.warnings.push(new Error(`${s} contains invalid source map`))}}}else{l=u.source();p=null}if(Buffer.isBuffer(l)){l=l.toString()}let d=false;if(this.options.extractComments){d=this.options.extractComments.filename||"[file].LICENSE.txt[query]";let e="";let r=s;const n=r.indexOf("?");if(n>=0){e=r.substr(n);r=r.substr(0,n)}const i=r.lastIndexOf("/");const o=i===-1?r:r.substr(i+1);const a={filename:r,basename:o,query:e};d=t.getPath(d,a)}const m=r=>{let{code:c}=r;const{error:u,map:f,warnings:m}=r;const{extractedComments:g}=r;let b=null;if(u||m&&m.length>0){b=TerserPlugin.buildSourceMap(p)}if(u){t.errors.push(TerserPlugin.buildError(u,s,b,new a.default(e.context)));return}const h=d&&g&&g.length>0;const y=this.options.extractComments.banner!==false;let v;let w;if(h&&y&&c.startsWith("#!")){const e=c.indexOf("\n");w=c.substring(0,e);c=c.substring(e+1)}if(f){v=new o.SourceMapSource(c,s,f,l,p,true)}else{v=new o.RawSource(c)}if(h){let e;if(y){e=this.options.extractComments.banner||`For license information please see ${n.default.relative(n.default.dirname(s),d).replace(/\\/g,"/")}`;if(typeof e==="function"){e=e(d)}if(e){v=new o.ConcatSource(w?`${w}\n`:"",`/*! ${e} */\n`,v)}}if(!i[d]){i[d]=new Set}g.forEach(t=>{if(e&&t===`/*! ${e} */`){return}i[d].add(t)});const r=t.assets[d];if(r){const e=r.source();e.replace(/\n$/,"").split("\n\n").forEach(e=>{i[d].add(e)})}}t.assets[s]=v;if(m&&m.length>0){m.forEach(r=>{const n=TerserPlugin.buildWarning(r,s,b,new a.default(e.context),this.options.warningsFilter);if(n){t.warnings.push(n)}})}};const g={file:s,input:l,inputSourceMap:p,commentsFilename:d,extractComments:this.options.extractComments,terserOptions:this.options.terserOptions,minify:this.options.minify,callback:m};if(TerserPlugin.isWebpack4()){const{outputOptions:{hashSalt:e,hashDigest:n,hashDigestLength:i,hashFunction:o}}=t;const a=c.util.createHash(o);if(e){a.update(e)}a.update(l);const u=a.digest(n);if(this.options.cache){const e={terser:f.default.version,"terser-webpack-plugin":r(379).version,"terser-webpack-plugin-options":this.options,nodeVersion:process.version,filename:s,contentHash:u.substr(0,i)};g.cacheKeys=this.options.cacheKeys(e,s)}}else{g.assetSource=u;g.cacheKeys={terser:f.default.version,"terser-webpack-plugin":r(379).version,"terser-webpack-plugin-options":this.options}}yield g}async runTasks(e,t,n){const i=TerserPlugin.getAvailableNumberOfCores(this.options.parallel);let s=Infinity;let o;if(i>0){const t=Math.min(e.length,i);s=t;o=new d.default(r.ab+"minify.js",{numWorkers:t});const n=o.getStdout();if(n){n.on("data",e=>{return process.stdout.write(e)})}const a=o.getStderr();if(a){a.on("data",e=>{return process.stderr.write(e)})}}const a=(0,p.default)(s);const c=[];for(const r of e){const e=async e=>{let t;try{if(o){t=await o.transform((0,l.default)(e))}else{t=(0,g.minify)(e)}}catch(e){t={error:e}}if(n.isEnabled()&&!t.error){t=await n.store(e,t).then(()=>t,()=>t)}e.callback(t);return t};c.push(a(()=>{const i=t(r).next().value;if(!i){return Promise.resolve()}if(n.isEnabled()){return n.get(i).then(e=>i.callback(e),()=>e(i))}return e(i)}))}return Promise.all(c).then(()=>{if(o){return o.end()}return Promise.resolve()})}apply(e){const{devtool:t,output:n,plugins:i}=e.options;this.options.sourceMap=typeof this.options.sourceMap==="undefined"?t&&!t.includes("eval")&&!t.includes("cheap")&&(t.includes("source-map")||t.includes("sourcemap"))||i&&i.some(e=>e instanceof c.SourceMapDevToolPlugin&&e.options&&e.options.columns):Boolean(this.options.sourceMap);if(typeof this.options.terserOptions.module==="undefined"&&typeof n.module!=="undefined"){this.options.terserOptions.module=n.module}if(typeof this.options.terserOptions.ecma==="undefined"&&typeof n.ecmaVersion!=="undefined"){this.options.terserOptions.ecma=n.ecmaVersion}const s=c.ModuleFilenameHelpers.matchObject.bind(undefined,this.options);const a=async(t,n)=>{let i;if(TerserPlugin.isWebpack4()){i=[].concat(Array.from(t.additionalChunkAssets||[])).concat(Array.from(n).reduce((e,t)=>e.concat(Array.from(t.files||[])),[])).concat(Object.keys(t.assets)).filter((e,t,r)=>r.indexOf(e)===t).filter(e=>s(e))}else{i=[].concat(Object.keys(n)).filter(e=>s(e))}if(i.length===0){return Promise.resolve()}const a={};const c=this.taskGenerator.bind(this,e,t,a);const u=TerserPlugin.isWebpack4()?r(428).default:r(793).default;const l=new u(t,{cache:this.options.cache});await this.runTasks(i,c,l);Object.keys(a).forEach(e=>{const r=Array.from(a[e]).sort().join("\n\n");t.assets[e]=new o.RawSource(`${r}\n`)});return Promise.resolve()};const u={name:this.constructor.name};e.hooks.compilation.tap(u,e=>{if(this.options.sourceMap){e.hooks.buildModule.tap(u,e=>{e.useSourceMap=true})}if(TerserPlugin.isWebpack4()){const{mainTemplate:t,chunkTemplate:r}=e;const n=(0,l.default)({terser:f.default.version,terserOptions:this.options.terserOptions});for(const e of[t,r]){e.hooks.hashForChunk.tap(u,e=>{e.update("TerserPlugin");e.update(n)})}e.hooks.optimizeChunkAssets.tapPromise(u,a.bind(this,e))}else{const t=c.javascript.JavascriptModulesPlugin.getCompilationHooks(e);const r=(0,l.default)({terser:f.default.version,terserOptions:this.options.terserOptions});t.chunkHash.tap(u,(e,t)=>{t.update("TerserPlugin");t.update(r)});e.hooks.optimizeAssets.tapPromise(u,a.bind(this,e))}})}}var h=TerserPlugin;t.default=h},330:function(e,t,r){"use strict";const n=r(305);e.exports=n.default},379:function(e){e.exports={name:"terser-webpack-plugin",version:"3.0.8",description:"Terser plugin for webpack",license:"MIT",repository:"webpack-contrib/terser-webpack-plugin",author:"webpack Contrib Team",homepage:"https://github.com/webpack-contrib/terser-webpack-plugin",bugs:"https://github.com/webpack-contrib/terser-webpack-plugin/issues",funding:{type:"opencollective",url:"https://opencollective.com/webpack"},main:"dist/cjs.js",engines:{node:">= 10.13.0"},scripts:{start:"npm run build -- -w",clean:"del-cli dist",prebuild:"npm run clean",build:"cross-env NODE_ENV=production babel src -d dist --copy-files",commitlint:"commitlint --from=master",security:"npm audit","lint:prettier":"prettier --list-different .","lint:js":"eslint --cache .",lint:'npm-run-all -l -p "lint:**"',"test:only":"cross-env NODE_ENV=test jest","test:watch":"npm run test:only -- --watch","test:coverage":'npm run test:only -- --collectCoverageFrom="src/**/*.js" --coverage',pretest:"npm run lint",test:"npm run test:coverage",prepare:"npm run build",release:"standard-version",defaults:"webpack-defaults"},files:["dist"],peerDependencies:{webpack:"^4.0.0 || ^5.0.0"},dependencies:{cacache:"^15.0.5","find-cache-dir":"^3.3.1","jest-worker":"^26.1.0","p-limit":"^3.0.2","schema-utils":"^2.6.6","serialize-javascript":"^4.0.0","source-map":"^0.6.1",terser:"^4.8.0","webpack-sources":"^1.4.3"},devDependencies:{"@babel/cli":"^7.10.5","@babel/core":"^7.10.5","@babel/preset-env":"^7.10.4","@commitlint/cli":"^9.1.2","@commitlint/config-conventional":"^9.1.1","@webpack-contrib/defaults":"^6.3.0","@webpack-contrib/eslint-config-webpack":"^3.0.0","babel-jest":"^26.1.0","copy-webpack-plugin":"^6.0.3","cross-env":"^7.0.2",del:"^5.1.0","del-cli":"^3.0.1",eslint:"^7.5.0","eslint-config-prettier":"^6.11.0","eslint-plugin-import":"^2.21.2","file-loader":"^6.0.0",husky:"^4.2.5",jest:"^26.0.1","lint-staged":"^10.2.11",memfs:"^3.2.0","npm-run-all":"^4.1.5",prettier:"^2.0.5","standard-version":"^8.0.2","uglify-js":"^3.10.0",webpack:"^4.44.0","worker-loader":"^2.0.0"},keywords:["uglify","uglify-js","uglify-es","terser","webpack","webpack-plugin","minification","compress","compressor","min","minification","minifier","minify","optimize","optimizer"]}},403:function(e){e.exports={name:"terser",description:"JavaScript parser, mangler/compressor and beautifier toolkit for ES6+",homepage:"https://terser.org",author:"Mihai Bazon (http://lisperator.net/)",license:"BSD-2-Clause",version:"4.8.0",engines:{node:">=6.0.0"},maintainers:["Fábio Santos "],repository:"https://github.com/terser/terser",main:"dist/bundle.min.js",types:"tools/terser.d.ts",bin:{terser:"bin/terser"},files:["bin","dist","tools","LICENSE","README.md","CHANGELOG.md","PATRONS.md"],dependencies:{commander:"^2.20.0","source-map":"~0.6.1","source-map-support":"~0.5.12"},devDependencies:{acorn:"^7.1.1",astring:"^1.4.1",eslint:"^6.3.0",eslump:"^2.0.0",mocha:"^7.1.2",mochallel:"^2.0.0","pre-commit":"^1.2.2",rimraf:"^3.0.0",rollup:"2.0.6","rollup-plugin-terser":"5.3.0",semver:"^7.1.3"},scripts:{test:"npm run build -- --configTest && node test/run-tests.js","test:compress":"npm run build -- --configTest && node test/compress.js","test:mocha":"npm run build -- --configTest && node test/mocha.js",lint:"eslint lib","lint-fix":"eslint --fix lib",build:"rimraf dist/* && rollup --config --silent",prepare:"npm run build",postversion:"echo 'Remember to update the changelog!'"},keywords:["uglify","terser","uglify-es","uglify-js","minify","minifier","javascript","ecmascript","es5","es6","es7","es8","es2015","es2016","es2017","async","await"],eslintConfig:{parserOptions:{sourceType:"module"},env:{es6:true},globals:{describe:false,it:false,require:false,global:false,process:false},rules:{"brace-style":["error","1tbs",{allowSingleLine:true}],quotes:["error","double","avoid-escape"],"no-debugger":"error","no-undef":"error","no-unused-vars":["error",{varsIgnorePattern:"^_$"}],"no-tabs":"error",semi:["error","always"],"no-extra-semi":"error","no-irregular-whitespace":"error","space-before-blocks":["error","always"]}},"pre-commit":["lint-fix","test"]}},417:function(e){e.exports=require("crypto")},428:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var n=_interopRequireDefault(r(87));var i=_interopRequireDefault(r(635));var s=_interopRequireDefault(r(240));var o=_interopRequireDefault(r(946));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}class Webpack4Cache{constructor(e,t){this.cacheDir=t.cache===true?Webpack4Cache.getCacheDirectory():t.cache}static getCacheDirectory(){return(0,s.default)({name:"terser-webpack-plugin"})||n.default.tmpdir()}isEnabled(){return Boolean(this.cacheDir)}get(e){e.cacheIdent=e.cacheIdent||(0,o.default)(e.cacheKeys);return i.default.get(this.cacheDir,e.cacheIdent).then(({data:e})=>JSON.parse(e))}store(e,t){return i.default.put(this.cacheDir,e.cacheIdent,JSON.stringify(t))}}t.default=Webpack4Cache},429:function(e){"use strict";const t=(e,...t)=>new Promise(r=>{r(e(...t))});e.exports=t;e.exports.default=t},432:function(e){e.exports=require("webpack/lib/RequestShortener")},499:function(e,t,r){"use strict";const n=r(429);const i=e=>{if(!((Number.isInteger(e)||e===Infinity)&&e>0)){throw new TypeError("Expected `concurrency` to be a number from 1 and up")}const t=[];let r=0;const i=()=>{r--;if(t.length>0){t.shift()()}};const s=async(e,t,...s)=>{r++;const o=n(e,...s);t(o);try{await o}catch{}i()};const o=(n,i,...o)=>{t.push(s.bind(null,n,i,...o));(async()=>{await Promise.resolve();if(r0){t.shift()()}})()};const a=(e,...t)=>new Promise(r=>o(e,r,...t));Object.defineProperties(a,{activeCount:{get:()=>r},pendingCount:{get:()=>t.length},clearQueue:{value:()=>{t.length=0}}});return a};e.exports=i},575:function(e){e.exports=require("webpack/lib/cache/getLazyHashedEtag")},622:function(e){e.exports=require("path")},635:function(e){e.exports=require("cacache")},726:function(e,t,r){"use strict";e=r.nmd(e);const{minify:n}=r(775);const i=({ecma:e,warnings:t,parse:r={},compress:n={},mangle:i,module:s,output:o,toplevel:a,nameCache:c,ie8:u,keep_classnames:l,keep_fnames:f,safari10:p}={})=>({parse:{...r},compress:typeof n==="boolean"?n:{...n},mangle:i==null?true:typeof i==="boolean"?i:{...i},output:{beautify:false,...o},sourceMap:null,ecma:e,keep_classnames:l,keep_fnames:f,ie8:u,module:s,nameCache:c,safari10:p,toplevel:a,warnings:t});function isObject(e){const t=typeof e;return e!=null&&(t==="object"||t==="function")}const s=(e,t,r)=>{const n={};const i=t.output.comments;const{extractComments:s}=e;n.preserve=typeof i!=="undefined"?i:false;if(typeof s==="boolean"&&s){n.extract="some"}else if(typeof s==="string"||s instanceof RegExp){n.extract=s}else if(typeof s==="function"){n.extract=s}else if(isObject(s)){n.extract=typeof s.condition==="boolean"&&s.condition?"some":typeof s.condition!=="undefined"?s.condition:"some"}else{n.preserve=typeof i!=="undefined"?i:"some";n.extract=false}["preserve","extract"].forEach(e=>{let t;let r;switch(typeof n[e]){case"boolean":n[e]=n[e]?()=>true:()=>false;break;case"function":break;case"string":if(n[e]==="all"){n[e]=(()=>true);break}if(n[e]==="some"){n[e]=((e,t)=>{return(t.type==="comment2"||t.type==="comment1")&&/@preserve|@lic|@cc_on|^\**!/i.test(t.value)});break}t=n[e];n[e]=((e,r)=>{return new RegExp(t).test(r.value)});break;default:r=n[e];n[e]=((e,t)=>r.test(t.value))}});return(e,t)=>{if(n.extract(e,t)){const e=t.type==="comment2"?`/*${t.value}*/`:`//${t.value}`;if(!r.includes(e)){r.push(e)}}return n.preserve(e,t)}};const o=e=>{const{file:t,input:r,inputSourceMap:o,minify:a}=e;if(a){return a({[t]:r},o)}const c=i(e.terserOptions);if(o){c.sourceMap={asObject:true}}const u=[];c.output.comments=s(e,c,u);const{error:l,map:f,code:p,warnings:d}=n({[t]:r},c);return{error:l,map:f,code:p,warnings:d,extractedComments:u}};function transform(r){r=new Function("exports","require","module","__filename","__dirname",`'use strict'\nreturn ${r}`)(t,require,e,__filename,__dirname);const n=o(r);if(n.error){throw n.error}else{return n}}e.exports.minify=o;e.exports.transform=transform},733:function(e){e.exports=require("jest-worker")},745:function(e){e.exports=require("webpack-sources")},775:function(e){e.exports=require("next/dist/compiled/terser")},793:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var n=_interopRequireDefault(r(575));var i=_interopRequireDefault(r(946));var s=r(78);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}class Cache{constructor(e,t){this.compilation=e}isEnabled(){return Boolean(this.compilation.cache)}createCacheIdent(e){const{outputOptions:{hashSalt:t,hashDigest:r,hashDigestLength:n,hashFunction:o}}=this.compilation;const a=s.util.createHash(o);if(t){a.update(t)}a.update((0,i.default)(e.cacheKeys));const c=a.digest(r);const u=c.substr(0,n);return`${this.compilation.compilerPath}/TerserWebpackPlugin/${u}/${e.file}`}get(e){e.cacheIdent=e.cacheIdent||this.createCacheIdent(e);e.cacheETag=e.cacheETag||(0,n.default)(e.assetSource);return new Promise((t,r)=>{this.compilation.cache.get(e.cacheIdent,e.cacheETag,(e,n)=>{if(e){r(e)}else if(n){t(n)}else{r()}})})}store(e,t){return new Promise((r,n)=>{this.compilation.cache.store(e.cacheIdent,e.cacheETag,t,e=>{if(e){n(e)}else{r(t)}})})}}t.default=Cache},825:function(e){e.exports={definitions:{Rule:{description:"Filtering rule as regex or string.",anyOf:[{instanceof:"RegExp",tsType:"RegExp"},{type:"string",minLength:1}]},Rules:{description:"Filtering rules.",anyOf:[{type:"array",items:{description:"A rule condition.",oneOf:[{$ref:"#/definitions/Rule"}]}},{$ref:"#/definitions/Rule"}]}},title:"TerserPluginOptions",type:"object",additionalProperties:false,properties:{test:{description:"Include all modules that pass test assertion.",oneOf:[{$ref:"#/definitions/Rules"}]},include:{description:"Include all modules matching any of these conditions.",oneOf:[{$ref:"#/definitions/Rules"}]},exclude:{description:"Exclude all modules matching any of these conditions.",oneOf:[{$ref:"#/definitions/Rules"}]},cache:{description:"Enable file caching. Ignored in webpack 5, for webpack 5 please use https://webpack.js.org/configuration/other-options/#cache.",anyOf:[{type:"boolean"},{type:"string"}]},cacheKeys:{description:"Allows you to override default cache keys. Ignored in webpack 5, for webpack 5 please use https://webpack.js.org/configuration/other-options/#cache.",instanceof:"Function"},parallel:{description:"Use multi-process parallel running to improve the build speed.",anyOf:[{type:"boolean"},{type:"integer"}]},sourceMap:{description:"Enables/Disables generation of source maps.",type:"boolean"},minify:{description:"Allows you to override default minify function.",instanceof:"Function"},terserOptions:{description:"Options for `terser`.",additionalProperties:true,type:"object"},extractComments:{description:"Whether comments shall be extracted to a separate file.",anyOf:[{type:"boolean"},{type:"string"},{instanceof:"RegExp"},{instanceof:"Function"},{additionalProperties:false,properties:{condition:{anyOf:[{type:"boolean"},{type:"string"},{instanceof:"RegExp"},{instanceof:"Function"}]},filename:{anyOf:[{type:"string"},{instanceof:"Function"}]},banner:{anyOf:[{type:"boolean"},{type:"string"},{instanceof:"Function"}]}},type:"object"}]},warningsFilter:{description:"Allow to filter `terser` warnings.",instanceof:"Function"}}}},898:function(e,t,r){e.exports=r(417).randomBytes},946:function(e,t,r){"use strict";var n=r(898);var i=16;var s=generateUID();var o=new RegExp('(\\\\)?"@__(F|R|D|M|S|U|I|B)-'+s+'-(\\d+)__@"',"g");var a=/\{\s*\[native code\]\s*\}/g;var c=/function.*?\(/;var u=/.*?=>.*?/;var l=/[<>\/\u2028\u2029]/g;var f=["*","async"];var p={"<":"\\u003C",">":"\\u003E","/":"\\u002F","\u2028":"\\u2028","\u2029":"\\u2029"};function escapeUnsafeChars(e){return p[e]}function generateUID(){var e=n(i);var t="";for(var r=0;r0});var i=n.filter(function(e){return f.indexOf(e)===-1});if(i.length>0){return(n.indexOf("async")>-1?"async ":"")+"function"+(n.join("").indexOf("*")>-1?"*":"")+t.substr(r)}return t}if(t.ignoreFunction&&typeof e==="function"){e=undefined}if(e===undefined){return String(e)}var h;if(t.isJSON&&!t.space){h=JSON.stringify(e)}else{h=JSON.stringify(e,t.isJSON?null:replacer,t.space)}if(typeof h!=="string"){return String(h)}if(t.unsafe!==true){h=h.replace(l,escapeUnsafeChars)}if(r.length===0&&n.length===0&&i.length===0&&p.length===0&&d.length===0&&m.length===0&&g.length===0&&b.length===0){return h}return h.replace(o,function(e,s,o,a){if(s){return e}if(o==="D"){return'new Date("'+i[a].toISOString()+'")'}if(o==="R"){return"new RegExp("+serialize(n[a].source)+', "'+n[a].flags+'")'}if(o==="M"){return"new Map("+serialize(Array.from(p[a].entries()),t)+")"}if(o==="S"){return"new Set("+serialize(Array.from(d[a].values()),t)+")"}if(o==="U"){return"undefined"}if(o==="I"){return g[a]}if(o==="B"){return'BigInt("'+b[a]+'")'}var c=r[a];return serializeFunc(c)})}}},function(e){"use strict";!function(){e.nmd=function(e){e.paths=[];if(!e.children)e.children=[];Object.defineProperty(e,"loaded",{enumerable:true,get:function(){return e.l}});Object.defineProperty(e,"id",{enumerable:true,get:function(){return e.i}});return e}}()}); \ No newline at end of file diff --git a/packages/next/compiled/terser-webpack-plugin/worker.js b/packages/next/compiled/terser-webpack-plugin/minify.js similarity index 96% rename from packages/next/compiled/terser-webpack-plugin/worker.js rename to packages/next/compiled/terser-webpack-plugin/minify.js index 923b129f8e6db..b70a9392c080a 100644 --- a/packages/next/compiled/terser-webpack-plugin/worker.js +++ b/packages/next/compiled/terser-webpack-plugin/minify.js @@ -23,8 +23,6 @@ const buildTerserOptions = ({ /* eslint-enable camelcase */ safari10 } = {}) => ({ - ecma, - warnings, parse: { ...parse }, compress: typeof compress === 'boolean' ? compress : { ...compress @@ -36,15 +34,17 @@ const buildTerserOptions = ({ beautify: false, ...output }, - module, // Ignoring sourceMap from options sourceMap: null, - toplevel, - nameCache, - ie8, + ecma, keep_classnames, keep_fnames, - safari10 + ie8, + module, + nameCache, + safari10, + toplevel, + warnings }); function isObject(value) { @@ -97,7 +97,7 @@ const buildComments = (options, terserOptions, extractedComments) => { if (condition[key] === 'some') { condition[key] = (astNode, comment) => { - return comment.type === 'comment2' && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value); + return (comment.type === 'comment2' || comment.type === 'comment1') && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value); }; break; diff --git a/packages/next/package.json b/packages/next/package.json index 0d86672ede7ac..b52f546ea8c45 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -111,7 +111,7 @@ "use-subscription": "1.4.1", "watchpack": "2.0.0-beta.13", "web-vitals": "0.2.1", - "webpack": "4.44.0", + "webpack": "4.44.1", "webpack-sources": "1.4.3" }, "peerDependencies": { @@ -205,7 +205,7 @@ "strip-ansi": "6.0.0", "taskr": "1.1.0", "terser": "4.4.2", - "terser-webpack-plugin": "gist:1b826e8b64f73158df99990d1b4624fa", + "terser-webpack-plugin": "3.0.8", "text-table": "0.2.0", "thread-loader": "2.1.3", "typescript": "3.8.3", diff --git a/packages/next/taskfile-ncc.js b/packages/next/taskfile-ncc.js index d67aa387e9e9b..08a2ae5e121a7 100644 --- a/packages/next/taskfile-ncc.js +++ b/packages/next/taskfile-ncc.js @@ -18,7 +18,9 @@ module.exports = function (task) { Object.keys(assets).forEach((key) => { let data = assets[key].source - if (join(file.dir, key).endsWith('terser-webpack-plugin/worker.js')) { + if ( + join(file.dir, key).endsWith('terser-webpack-plugin/dist/minify.js') + ) { data = Buffer.from( data .toString() diff --git a/yarn.lock b/yarn.lock index 39eb5c9375cc7..e7c25019326aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2275,6 +2275,13 @@ version "1.1.3" resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b" +"@npmcli/move-file@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@npmcli/move-file/-/move-file-1.0.1.tgz#de103070dac0f48ce49cf6693c23af59c0f70464" + integrity sha512-Uv6h1sT+0DrblvIrolFtbvM1FgWm+/sy4B3pvLp67Zys+thcukzS5ekn7HsZFGpWP4Q3fYJCljbWQE/XivMRLw== + dependencies: + mkdirp "^1.0.4" + "@octokit/endpoint@^5.5.0": version "5.5.1" resolved "https://registry.yarnpkg.com/@octokit/endpoint/-/endpoint-5.5.1.tgz#2eea81e110ca754ff2de11c79154ccab4ae16b3f" @@ -4197,7 +4204,7 @@ bytes@3.1.0, bytes@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6" -cacache@13.0.1, cacache@^13.0.1: +cacache@13.0.1: version "13.0.1" resolved "https://registry.yarnpkg.com/cacache/-/cacache-13.0.1.tgz#a8000c21697089082f85287a1aec6e382024a71c" dependencies: @@ -4259,6 +4266,29 @@ cacache@^12.0.0, cacache@^12.0.2: unique-filename "^1.1.1" y18n "^4.0.0" +cacache@^15.0.5: + version "15.0.5" + resolved "https://registry.yarnpkg.com/cacache/-/cacache-15.0.5.tgz#69162833da29170d6732334643c60e005f5f17d0" + integrity sha512-lloiL22n7sOjEEXdL8NAjTgv9a1u43xICE9/203qonkZUCj5X1UEWIdf2/Y0d6QcCtMzbKQyhrcDbdvlZTs/+A== + dependencies: + "@npmcli/move-file" "^1.0.1" + chownr "^2.0.0" + fs-minipass "^2.0.0" + glob "^7.1.4" + infer-owner "^1.0.4" + lru-cache "^6.0.0" + minipass "^3.1.1" + minipass-collect "^1.0.2" + minipass-flush "^1.0.5" + minipass-pipeline "^1.2.2" + mkdirp "^1.0.3" + p-map "^4.0.0" + promise-inflight "^1.0.1" + rimraf "^3.0.2" + ssri "^8.0.0" + tar "^6.0.2" + unique-filename "^1.1.1" + cache-base@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" @@ -4600,6 +4630,11 @@ chownr@^1.1.1, chownr@^1.1.2: version "1.1.3" resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.3.tgz#42d837d5239688d55f303003a508230fa6727142" +chownr@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/chownr/-/chownr-2.0.0.tgz#15bfbe53d2eab4cf70f18a8cd68ebe5b3cb1dece" + integrity sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ== + chrome-trace-event@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/chrome-trace-event/-/chrome-trace-event-1.0.2.tgz#234090ee97c7d4ad1a2c4beae27505deffc608a4" @@ -6949,7 +6984,7 @@ finally-polyfill@0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/finally-polyfill/-/finally-polyfill-0.1.0.tgz#2a17b16581d9477db16a703c7b79a898ac0b7d50" -find-cache-dir@3.3.1, find-cache-dir@^3.0.0, find-cache-dir@^3.2.0: +find-cache-dir@3.3.1, find-cache-dir@^3.0.0, find-cache-dir@^3.3.1: version "3.3.1" resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.3.1.tgz#89b33fad4a4670daa94f855f7fbe31d6d84fe880" dependencies: @@ -9267,17 +9302,19 @@ jest-worker@^23.2.0: dependencies: merge-stream "^1.0.1" -jest-worker@^25.1.0: - version "25.2.6" - resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-25.2.6.tgz#d1292625326794ce187c38f51109faced3846c58" +jest-worker@^26.0.0: + version "26.0.0" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.0.0.tgz#4920c7714f0a96c6412464718d0c58a3df3fb066" dependencies: merge-stream "^2.0.0" supports-color "^7.0.0" -jest-worker@^26.0.0: - version "26.0.0" - resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.0.0.tgz#4920c7714f0a96c6412464718d0c58a3df3fb066" +jest-worker@^26.1.0: + version "26.2.1" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.2.1.tgz#5d630ab93f666b53f911615bc13e662b382bd513" + integrity sha512-+XcGMMJDTeEGncRb5M5Zq9P7K4sQ1sirhjdOxsN1462h6lFo9w59bl2LVQmdGEEeU3m+maZCkS2Tcc9SfCHO4A== dependencies: + "@types/node" "*" merge-stream "^2.0.0" supports-color "^7.0.0" @@ -10038,6 +10075,13 @@ lru-cache@^4.0.1: pseudomap "^1.0.2" yallist "^2.1.2" +lru-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" + integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== + dependencies: + yallist "^4.0.0" + lru_map@^0.3.3: version "0.3.3" resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd" @@ -10503,6 +10547,14 @@ minizlib@^1.2.1: dependencies: minipass "^2.9.0" +minizlib@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-2.1.0.tgz#fd52c645301ef09a63a2c209697c294c6ce02cf3" + integrity sha512-EzTZN/fjSvifSX0SlqUERCN39o6T40AMarPbv0MrarSFtIITCBh7bi+dU8nxGFHuqs9jdIAeoYoKuQAAASsPPA== + dependencies: + minipass "^3.0.0" + yallist "^4.0.0" + mississippi@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/mississippi/-/mississippi-3.0.0.tgz#ea0a3291f97e0b5e8776b363d5f0a12d94c67022" @@ -10548,6 +10600,11 @@ mkdirp@0.5.3: dependencies: minimist "^1.2.5" +mkdirp@^1.0.3, mkdirp@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" + integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== + modify-values@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" @@ -11316,12 +11373,19 @@ p-limit@^1.1.0: dependencies: p-try "^1.0.0" -p-limit@^2.0.0, p-limit@^2.2.0, p-limit@^2.2.2: +p-limit@^2.0.0, p-limit@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" dependencies: p-try "^2.0.0" +p-limit@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.0.2.tgz#1664e010af3cadc681baafd3e2a437be7b0fb5fe" + integrity sha512-iwqZSOoWIW+Ew4kAGUlN16J4M7OB3ysMLSZtnhmqx7njIHFPlxWBX8xo3lVTyFVq6mI/lL9qt2IsN1sHwaxJkg== + dependencies: + p-try "^2.0.0" + p-locate@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" @@ -11360,6 +11424,13 @@ p-map@^3.0.0: dependencies: aggregate-error "^3.0.0" +p-map@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/p-map/-/p-map-4.0.0.tgz#bb2f95a5eda2ec168ec9274e06a747c3e2904d2b" + integrity sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ== + dependencies: + aggregate-error "^3.0.0" + p-pipe@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/p-pipe/-/p-pipe-1.2.0.tgz#4b1a11399a11520a67790ee5a0c1d5881d6befe9" @@ -13787,6 +13858,13 @@ rimraf@3.0.0: dependencies: glob "^7.1.3" +rimraf@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" + integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== + dependencies: + glob "^7.1.3" + rimraf@~2.5.2: version "2.5.4" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04" @@ -14065,7 +14143,7 @@ scheduler@^0.18.0: loose-envify "^1.1.0" object-assign "^4.1.1" -schema-utils@2.6.6, schema-utils@^2.0.0, schema-utils@^2.6.1, schema-utils@^2.6.4, schema-utils@^2.6.5, schema-utils@^2.6.6: +schema-utils@2.6.6, schema-utils@^2.0.0, schema-utils@^2.6.1, schema-utils@^2.6.5, schema-utils@^2.6.6: version "2.6.6" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.6.6.tgz#299fe6bd4a3365dc23d99fd446caff8f1d6c330c" dependencies: @@ -14181,10 +14259,6 @@ serialize-javascript@^1.5.0: version "1.9.1" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.9.1.tgz#cfc200aef77b600c47da9bb8149c943e798c2fdb" -serialize-javascript@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-2.1.2.tgz#ecec53b0e0317bdc95ef76ab7074b7384785fa61" - serialize-javascript@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-3.1.0.tgz#8bf3a9170712664ef2561b44b691eafe399214ea" @@ -14192,6 +14266,13 @@ serialize-javascript@^3.1.0: dependencies: randombytes "^2.1.0" +serialize-javascript@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa" + integrity sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw== + dependencies: + randombytes "^2.1.0" + serve-static@1.14.1: version "1.14.1" resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.14.1.tgz#666e636dc4f010f7ef29970a88a674320898b2f9" @@ -14552,6 +14633,13 @@ ssri@^7.0.0: figgy-pudding "^3.5.1" minipass "^3.1.1" +ssri@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/ssri/-/ssri-8.0.0.tgz#79ca74e21f8ceaeddfcb4b90143c458b8d988808" + integrity sha512-aq/pz989nxVYwn16Tsbj1TqFpD5LLrQxHf5zaHuieFV+R0Bbr4y8qUsOA45hXT/N4/9UNXTarBjnjVmjSOVaAA== + dependencies: + minipass "^3.1.1" + stable@^0.1.8: version "0.1.8" resolved "https://registry.yarnpkg.com/stable/-/stable-0.1.8.tgz#836eb3c8382fe2936feaf544631017ce7d47a3cf" @@ -15057,6 +15145,18 @@ tar@^4.4.10, tar@^4.4.8: safe-buffer "^5.1.2" yallist "^3.0.3" +tar@^6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/tar/-/tar-6.0.2.tgz#5df17813468a6264ff14f766886c622b84ae2f39" + integrity sha512-Glo3jkRtPcvpDlAs/0+hozav78yoXKFr+c4wgw62NNMO3oo4AaJdCo21Uu7lcwr55h39W2XD1LMERc64wtbItg== + dependencies: + chownr "^2.0.0" + fs-minipass "^2.0.0" + minipass "^3.0.0" + minizlib "^2.1.0" + mkdirp "^1.0.3" + yallist "^4.0.0" + taskr@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/taskr/-/taskr-1.1.0.tgz#4f29d0ace26f4deae9a478eabf9aa0432e884438" @@ -15089,6 +15189,21 @@ temp-write@^3.4.0: temp-dir "^1.0.0" uuid "^3.0.1" +terser-webpack-plugin@3.0.8: + version "3.0.8" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-3.0.8.tgz#d1a53442a143e09e00c880e8d77c1e79cb05318b" + integrity sha512-ygwK8TYMRTYtSyLB2Mhnt90guQh989CIq/mL/2apwi6rA15Xys4ydNUiH4ah6EZCfQxSk26ZFQilZ4IQ6IZw6A== + dependencies: + cacache "^15.0.5" + find-cache-dir "^3.3.1" + jest-worker "^26.1.0" + p-limit "^3.0.2" + schema-utils "^2.6.6" + serialize-javascript "^4.0.0" + source-map "^0.6.1" + terser "^4.8.0" + webpack-sources "^1.4.3" + terser-webpack-plugin@^1.4.3: version "1.4.4" resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.4.4.tgz#2c63544347324baafa9a56baaddf1634c8abfc2f" @@ -15104,20 +15219,6 @@ terser-webpack-plugin@^1.4.3: webpack-sources "^1.4.0" worker-farm "^1.7.0" -"terser-webpack-plugin@gist:1b826e8b64f73158df99990d1b4624fa": - version "2.3.5" - resolved "https://gist.github.com/1b826e8b64f73158df99990d1b4624fa.git#37ef181f130335ac5c4fc3a129b1245788c755c4" - dependencies: - cacache "^13.0.1" - find-cache-dir "^3.2.0" - jest-worker "^25.1.0" - p-limit "^2.2.2" - schema-utils "^2.6.4" - serialize-javascript "^2.1.2" - source-map "^0.6.1" - terser "^4.4.3" - webpack-sources "^1.4.3" - terser@4.4.2: version "4.4.2" resolved "https://registry.yarnpkg.com/terser/-/terser-4.4.2.tgz#448fffad0245f4c8a277ce89788b458bfd7706e8" @@ -15126,7 +15227,7 @@ terser@4.4.2: source-map "~0.6.1" source-map-support "~0.5.12" -terser@4.8.0, terser@^4.1.2: +terser@4.8.0, terser@^4.1.2, terser@^4.8.0: version "4.8.0" resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17" integrity sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw== @@ -15143,14 +15244,6 @@ terser@^3.8.2: source-map "~0.6.1" source-map-support "~0.5.10" -terser@^4.4.3: - version "4.6.11" - resolved "https://registry.yarnpkg.com/terser/-/terser-4.6.11.tgz#12ff99fdd62a26de2a82f508515407eb6ccd8a9f" - dependencies: - commander "^2.20.0" - source-map "~0.6.1" - source-map-support "~0.5.12" - test-exclude@^5.2.3: version "5.2.3" resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-5.2.3.tgz#c3d3e1e311eb7ee405e092dac10aefd09091eac0" @@ -15959,10 +16052,10 @@ webpack-sources@1.4.3, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-s source-list-map "^2.0.0" source-map "~0.6.1" -webpack@4.44.0: - version "4.44.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.44.0.tgz#3b08f88a89470175f036f4a9496b8a0428668802" - integrity sha512-wAuJxK123sqAw31SpkPiPW3iKHgFUiKvO7E7UZjtdExcsRe3fgav4mvoMM7vvpjLHVoJ6a0Mtp2fzkoA13e0Zw== +webpack@4.44.1: + version "4.44.1" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.44.1.tgz#17e69fff9f321b8f117d1fda714edfc0b939cc21" + integrity sha512-4UOGAohv/VGUNQJstzEywwNxqX417FnjZgZJpJQegddzPmTvph37eBIRbRTfdySXzVtJXLJfbMN3mMYhM6GdmQ== dependencies: "@webassemblyjs/ast" "1.9.0" "@webassemblyjs/helper-module-context" "1.9.0" From ea026151b2e0d09e82e620f277147e9767e05f5c Mon Sep 17 00:00:00 2001 From: Kim T Date: Mon, 3 Aug 2020 06:17:38 -0700 Subject: [PATCH 90/90] with-electron-typescript build error fix (#15803) Fixes #15802 Added Params type to prevent typescript error during build step --- .../with-electron-typescript/renderer/pages/detail/[id].tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/with-electron-typescript/renderer/pages/detail/[id].tsx b/examples/with-electron-typescript/renderer/pages/detail/[id].tsx index b04adb1bd3321..8c249c1dab760 100644 --- a/examples/with-electron-typescript/renderer/pages/detail/[id].tsx +++ b/examples/with-electron-typescript/renderer/pages/detail/[id].tsx @@ -5,6 +5,10 @@ import { findAll, findData } from '../../utils/sample-api' import ListDetail from '../../components/ListDetail' import { GetStaticPaths, GetStaticProps } from 'next' +type Params = { + id?: string +} + type Props = { item?: User errors?: string @@ -37,7 +41,7 @@ export const getStaticPaths: GetStaticPaths = async () => { } export const getStaticProps: GetStaticProps = async ({ params }) => { - const { id } = params + const { id } = params as Params try { const item = await findData(Array.isArray(id) ? id[0] : id)