diff --git a/examples/with-apivideo/pages/videos/[videoId].tsx b/examples/with-apivideo/pages/videos/[videoId].tsx index 02fa01165bd33..78109b5b6150d 100644 --- a/examples/with-apivideo/pages/videos/[videoId].tsx +++ b/examples/with-apivideo/pages/videos/[videoId].tsx @@ -63,7 +63,7 @@ const VideoView: NextPage = ({ .
It provides multiple properties to customize your video player.

-

Try 3 of them just bellow 👇

+

Try 3 of them just below 👇

diff --git a/lerna.json b/lerna.json index 8311b6f749e4b..e6fd9823e53f1 100644 --- a/lerna.json +++ b/lerna.json @@ -16,5 +16,5 @@ "registry": "https://registry.npmjs.org/" } }, - "version": "12.3.2-canary.32" + "version": "12.3.2-canary.33" } diff --git a/package.json b/package.json index f35326d372399..0208f74d066cc 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "@types/html-validator": "5.0.3", "@types/http-proxy": "1.17.3", "@types/jest": "24.0.13", - "@types/node": "13.11.0", + "@types/node": "14.14.31", "@types/node-fetch": "2.6.1", "@types/react": "16.9.17", "@types/react-dom": "16.9.4", @@ -178,8 +178,11 @@ "random-seed": "0.3.0", "react": "18.2.0", "react-17": "npm:react@17.0.2", + "react-builtin": "npm:react@0.0.0-experimental-9cdf8a99e-20221018", "react-dom": "18.2.0", "react-dom-17": "npm:react-dom@17.0.2", + "react-dom-builtin": "npm:react-dom@0.0.0-experimental-9cdf8a99e-20221018", + "react-server-dom-webpack": "0.0.0-experimental-9cdf8a99e-20221018", "react-ssr-prepass": "1.0.8", "react-virtualized": "9.22.3", "relay-compiler": "13.0.2", @@ -194,6 +197,7 @@ "shell-quote": "1.7.3", "styled-components": "5.3.3", "styled-jsx-plugin-postcss": "3.0.2", + "swr": "2.0.0-rc.0", "tailwindcss": "1.1.3", "taskr": "1.1.0", "tree-kill": "1.2.2", diff --git a/packages/create-next-app/create-app.ts b/packages/create-next-app/create-app.ts index 67011c80be4b8..c7812759b6222 100644 --- a/packages/create-next-app/create-app.ts +++ b/packages/create-next-app/create-app.ts @@ -29,15 +29,21 @@ export async function createApp({ example, examplePath, typescript, + experimentalApp, }: { appPath: string packageManager: PackageManager example?: string examplePath?: string - typescript?: boolean + typescript: boolean + experimentalApp: boolean }): Promise { let repoInfo: RepoInfo | undefined - const template = typescript ? 'typescript' : 'default' + const template = experimentalApp + ? 'experimental-app' + : typescript + ? 'typescript' + : 'default' if (example) { let repoUrl: URL | undefined @@ -238,7 +244,7 @@ export async function createApp({ /** * TypeScript projects will have type definitions and other devDependencies. */ - if (typescript) { + if (template !== 'default') { devDependencies.push( 'typescript', '@types/react', @@ -273,7 +279,7 @@ export async function createApp({ const devInstallFlags = { devDependencies: true, ...installFlags } await install(root, devDependencies, devInstallFlags) } - console.log() + console.log('\nInitializing project with template: ', template, '\n') /** * Copy the template files to the target directory. */ diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 6a1c6e61f53db..13fffa432cb95 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -24,6 +24,13 @@ const program = new Commander.Command(packageJson.name) ` Initialize as a TypeScript project. +` + ) + .option( + '--experimental-app', + ` + + Initialize as a \`app/\` directory project. ` ) .option( @@ -136,6 +143,7 @@ async function run(): Promise { example: example && example !== 'default' ? example : undefined, examplePath: program.examplePath, typescript: program.typescript, + experimentalApp: program.experimentalApp, }) } catch (reason) { if (!(reason instanceof DownloadError)) { @@ -158,6 +166,7 @@ async function run(): Promise { appPath: resolvedProjectPath, packageManager, typescript: program.typescript, + experimentalApp: program.experimentalApp, }) } } diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index 7b405c0c76170..3d7ec4d6dda82 100644 --- a/packages/create-next-app/package.json +++ b/packages/create-next-app/package.json @@ -1,6 +1,6 @@ { "name": "create-next-app", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "keywords": [ "react", "next", diff --git a/packages/create-next-app/templates/experimental-app/README-template.md b/packages/create-next-app/templates/experimental-app/README-template.md new file mode 100644 index 0000000000000..331172e45f6d0 --- /dev/null +++ b/packages/create-next-app/templates/experimental-app/README-template.md @@ -0,0 +1,34 @@ +This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). + +## Getting Started + +First, run the development server: + +```bash +npm run dev +# or +yarn dev +``` + +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. + +You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. + +[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`. + +The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. + +## Learn More + +To learn more about Next.js, take a look at the following resources: + +- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. +- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. + +You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! + +## Deploy on Vercel + +The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. + +Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. diff --git a/packages/create-next-app/templates/experimental-app/app/layout.tsx b/packages/create-next-app/templates/experimental-app/app/layout.tsx new file mode 100644 index 0000000000000..858c345c77954 --- /dev/null +++ b/packages/create-next-app/templates/experimental-app/app/layout.tsx @@ -0,0 +1,10 @@ +export default function RootLayout({ children }) { + return ( + + + Create Next App + + {children} + + ) +} diff --git a/packages/create-next-app/templates/experimental-app/app/page.tsx b/packages/create-next-app/templates/experimental-app/app/page.tsx new file mode 100644 index 0000000000000..b9e0c47294cc0 --- /dev/null +++ b/packages/create-next-app/templates/experimental-app/app/page.tsx @@ -0,0 +1,7 @@ +export default function Page() { + return ( +

+ Welcome to Next.js! +

+ ) +} diff --git a/packages/create-next-app/templates/experimental-app/eslintrc.json b/packages/create-next-app/templates/experimental-app/eslintrc.json new file mode 100644 index 0000000000000..bffb357a71225 --- /dev/null +++ b/packages/create-next-app/templates/experimental-app/eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "next/core-web-vitals" +} diff --git a/packages/create-next-app/templates/experimental-app/gitignore b/packages/create-next-app/templates/experimental-app/gitignore new file mode 100644 index 0000000000000..c87c9b392c020 --- /dev/null +++ b/packages/create-next-app/templates/experimental-app/gitignore @@ -0,0 +1,36 @@ +# 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* +.pnpm-debug.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts diff --git a/packages/create-next-app/templates/experimental-app/next-env.d.ts b/packages/create-next-app/templates/experimental-app/next-env.d.ts new file mode 100644 index 0000000000000..4f11a03dc6cc3 --- /dev/null +++ b/packages/create-next-app/templates/experimental-app/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/packages/create-next-app/templates/experimental-app/next.config.js b/packages/create-next-app/templates/experimental-app/next.config.js new file mode 100644 index 0000000000000..dafb0c88e961e --- /dev/null +++ b/packages/create-next-app/templates/experimental-app/next.config.js @@ -0,0 +1,8 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + experimental: { + appDir: true, + }, +} + +module.exports = nextConfig diff --git a/packages/create-next-app/templates/experimental-app/pages/api/hello.ts b/packages/create-next-app/templates/experimental-app/pages/api/hello.ts new file mode 100644 index 0000000000000..f8bcc7e5caed1 --- /dev/null +++ b/packages/create-next-app/templates/experimental-app/pages/api/hello.ts @@ -0,0 +1,13 @@ +// Next.js API route support: https://nextjs.org/docs/api-routes/introduction +import type { NextApiRequest, NextApiResponse } from 'next' + +type Data = { + name: string +} + +export default function handler( + req: NextApiRequest, + res: NextApiResponse +) { + res.status(200).json({ name: 'John Doe' }) +} diff --git a/packages/create-next-app/templates/experimental-app/tsconfig.json b/packages/create-next-app/templates/experimental-app/tsconfig.json new file mode 100644 index 0000000000000..6ef5cd577f6ed --- /dev/null +++ b/packages/create-next-app/templates/experimental-app/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "plugins": [ + { + "name": "next" + } + ] + }, + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], + "exclude": ["node_modules"] +} diff --git a/packages/create-next-app/templates/typescript/pages/_app.tsx b/packages/create-next-app/templates/typescript/pages/_app.tsx index 3f5c9d5485860..c055f25c20967 100644 --- a/packages/create-next-app/templates/typescript/pages/_app.tsx +++ b/packages/create-next-app/templates/typescript/pages/_app.tsx @@ -1,8 +1,6 @@ import '../styles/globals.css' import type { AppProps } from 'next/app' -function MyApp({ Component, pageProps }: AppProps) { +export default function App({ Component, pageProps }: AppProps) { return } - -export default MyApp diff --git a/packages/create-next-app/templates/typescript/pages/index.tsx b/packages/create-next-app/templates/typescript/pages/index.tsx index ff4dd21141cf2..cdffa57ca8254 100644 --- a/packages/create-next-app/templates/typescript/pages/index.tsx +++ b/packages/create-next-app/templates/typescript/pages/index.tsx @@ -1,9 +1,8 @@ -import type { NextPage } from 'next' import Head from 'next/head' import Image from 'next/image' import styles from '../styles/Home.module.css' -const Home: NextPage = () => { +export default function Home() { return (
@@ -70,5 +69,3 @@ const Home: NextPage = () => {
) } - -export default Home diff --git a/packages/eslint-config-next/package.json b/packages/eslint-config-next/package.json index 5ecbff7e3719f..918d05b11fc42 100644 --- a/packages/eslint-config-next/package.json +++ b/packages/eslint-config-next/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-next", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "description": "ESLint configuration used by NextJS.", "main": "index.js", "license": "MIT", @@ -9,7 +9,7 @@ "directory": "packages/eslint-config-next" }, "dependencies": { - "@next/eslint-plugin-next": "12.3.2-canary.32", + "@next/eslint-plugin-next": "12.3.2-canary.33", "@rushstack/eslint-patch": "^1.1.3", "@typescript-eslint/parser": "^5.21.0", "eslint-import-resolver-node": "^0.3.6", diff --git a/packages/eslint-plugin-next/package.json b/packages/eslint-plugin-next/package.json index 95b827b7391de..e952469f8794e 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": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "description": "ESLint plugin for NextJS.", "main": "dist/index.js", "license": "MIT", diff --git a/packages/font/google/index.js b/packages/font/google/index.js index f3d7e7c80ab0a..b86140fd452a3 100644 --- a/packages/font/google/index.js +++ b/packages/font/google/index.js @@ -1 +1,7 @@ -throw new Error('@next/font/google is not correctly configured') +let message = '@next/font/google failed to run or is incorrectly configured.' +if (process.env.NODE_ENV === 'development') { + message += + '\nIf you just installed `@next/font`, please try restarting `next dev` and resaving your file.' +} + +throw new Error(message) diff --git a/packages/font/local/index.js b/packages/font/local/index.js index bc2f598aaa23d..c2eda14c0128f 100644 --- a/packages/font/local/index.js +++ b/packages/font/local/index.js @@ -1 +1,7 @@ -throw new Error('@next/font/local is not correctly configured') +let message = '@next/font/local failed to run or is incorrectly configured.' +if (process.env.NODE_ENV === 'development') { + message += + '\nIf you just installed `@next/font`, please try restarting `next dev` and resaving your file.' +} + +throw new Error(message) diff --git a/packages/font/package.json b/packages/font/package.json index 89248b77f6223..6a600bfb4f72c 100644 --- a/packages/font/package.json +++ b/packages/font/package.json @@ -1,6 +1,6 @@ { "name": "@next/font", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "repository": { "url": "vercel/next.js", "directory": "packages/font" diff --git a/packages/font/src/google/loader.ts b/packages/font/src/google/loader.ts index 758815be8c599..173318093543b 100644 --- a/packages/font/src/google/loader.ts +++ b/packages/font/src/google/loader.ts @@ -1,6 +1,10 @@ import type { AdjustFontFallback, FontLoader } from 'next/font' // @ts-ignore import { calculateSizeAdjustValues } from 'next/dist/server/font-utils' +// @ts-ignore +import * as Log from 'next/dist/build/output/log' +// @ts-ignore +import chalk from 'next/dist/compiled/chalk' import { fetchCSSFromGoogleFonts, fetchFontFile, @@ -19,10 +23,15 @@ const downloadGoogleFonts: FontLoader = async ({ emitFontFile, }) => { if (!config?.subsets) { - throw new Error( - 'Please specify subsets for `@next/font/google` in your `next.config.js`' + Log.warn( + `${chalk.bold('@next/font/google')} is missing ${chalk.bold( + 'options.subsets' + )} in your ${chalk.bold( + 'next.config.js' + )}. Please specify subsets, otherwise no fonts will be preloaded.` ) } + const subsets = config?.subsets || [] const { fontFamily, @@ -63,7 +72,7 @@ const downloadGoogleFonts: FontLoader = async ({ if (googleFontFileUrl) { fontFiles.push({ googleFontFileUrl, - preloadFontFile: !!preload && config.subsets.includes(currentSubset), + preloadFontFile: !!preload && subsets.includes(currentSubset), }) } } @@ -121,7 +130,7 @@ const downloadGoogleFonts: FontLoader = async ({ sizeAdjust: `${sizeAdjust}%`, } } catch { - console.error( + Log.error( `Failed to find font override values for font \`${fontFamily}\`` ) } diff --git a/packages/font/src/local/utils.ts b/packages/font/src/local/utils.ts index 541517da28f3c..90cdf807e15d1 100644 --- a/packages/font/src/local/utils.ts +++ b/packages/font/src/local/utils.ts @@ -60,7 +60,7 @@ export function validateData(functionName: string, data: any): FontOptions { throw new Error(`Unexpected file \`${src}\``) } - const family = /.+\/(.+?)\./.exec(src)![1] + const family = /(.*\/)?(.+?)\.(woff|woff2|eot|ttf|otf)$/.exec(src)![2] if (Array.isArray(declarations)) { declarations.forEach((declaration) => { diff --git a/packages/next-bundle-analyzer/package.json b/packages/next-bundle-analyzer/package.json index 35778bd725143..83ce4783aff03 100644 --- a/packages/next-bundle-analyzer/package.json +++ b/packages/next-bundle-analyzer/package.json @@ -1,6 +1,6 @@ { "name": "@next/bundle-analyzer", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "main": "index.js", "types": "index.d.ts", "license": "MIT", diff --git a/packages/next-codemod/package.json b/packages/next-codemod/package.json index 9441b3825c5c4..dc66ef563e734 100644 --- a/packages/next-codemod/package.json +++ b/packages/next-codemod/package.json @@ -1,6 +1,6 @@ { "name": "@next/codemod", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "license": "MIT", "dependencies": { "chalk": "4.1.0", diff --git a/packages/next-env/package.json b/packages/next-env/package.json index 3843a7c2698c1..8034528786fc7 100644 --- a/packages/next-env/package.json +++ b/packages/next-env/package.json @@ -1,6 +1,6 @@ { "name": "@next/env", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "keywords": [ "react", "next", diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index 495644adac794..021d68b228ec3 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@next/mdx", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "main": "index.js", "license": "MIT", "repository": { diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index 571b3ce8b817d..214afbf2ba1cc 100644 --- a/packages/next-plugin-storybook/package.json +++ b/packages/next-plugin-storybook/package.json @@ -1,6 +1,6 @@ { "name": "@next/plugin-storybook", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "repository": { "url": "vercel/next.js", "directory": "packages/next-plugin-storybook" diff --git a/packages/next-polyfill-module/package.json b/packages/next-polyfill-module/package.json index 821b22539cb71..5c31af04e0e30 100644 --- a/packages/next-polyfill-module/package.json +++ b/packages/next-polyfill-module/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-module", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)", "main": "dist/polyfill-module.js", "license": "MIT", diff --git a/packages/next-polyfill-nomodule/package.json b/packages/next-polyfill-nomodule/package.json index d2005e55619f4..9929029063ea7 100644 --- a/packages/next-polyfill-nomodule/package.json +++ b/packages/next-polyfill-nomodule/package.json @@ -1,6 +1,6 @@ { "name": "@next/polyfill-nomodule", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "description": "A polyfill for non-dead, nomodule browsers.", "main": "dist/polyfill-nomodule.js", "license": "MIT", diff --git a/packages/next-swc/Cargo.lock b/packages/next-swc/Cargo.lock index e3c2431017e2a..74f5ef9acb794 100644 --- a/packages/next-swc/Cargo.lock +++ b/packages/next-swc/Cargo.lock @@ -165,9 +165,9 @@ dependencies = [ [[package]] name = "binding_macros" -version = "0.20.40" +version = "0.20.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f0239cba0f7a458f594af9d3dd3b1797fae99ff2082a62932981811491f62b2" +checksum = "ac6b78c495bec96bc6b19121c324cb3919d729245b7f4304cffdb7799e70fe8a" dependencies = [ "anyhow", "console_error_panic_hook", @@ -236,9 +236,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "bytecheck" @@ -315,6 +315,16 @@ dependencies = [ "bitflags", ] +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -519,9 +529,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.23" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" dependencies = [ "quote", "syn", @@ -533,6 +543,50 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" +[[package]] +name = "cxx" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f83d0ebf42c6eafb8d7c52f7e5f2d3003b89c7aa4fd2b79229209459a849af8" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07d050484b55975889284352b0ffc2ecbda25c0c55978017c132b29ba0818a86" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d2199b00553eda8012dfec8d3b1c75fce747cf27c169a270b3b99e3448ab78" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb67a6de1f602736dd7eaead0080cf3435df806c61b24b13328db128c58868f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "darling" version = "0.13.4" @@ -612,7 +666,7 @@ dependencies = [ "hashbrown 0.12.3", "lock_api", "once_cell", - "parking_lot_core 0.9.3", + "parking_lot_core 0.9.4", ] [[package]] @@ -828,42 +882,42 @@ checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" [[package]] name = "futures-channel" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" [[package]] name = "futures-io" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" [[package]] name = "futures-sink" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" [[package]] name = "futures-task" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" +checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" [[package]] name = "futures-util" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ "futures-core", "futures-io", @@ -1107,17 +1161,28 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.50" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0" +checksum = "f5a6ef98976b22b3b7f2f3a806f858cb862044cfa66805aa3ad84cb3d3b785ed" dependencies = [ "android_system_properties", "core-foundation-sys", + "iana-time-zone-haiku", "js-sys", "wasm-bindgen", "winapi", ] +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -1197,9 +1262,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "js-sys" @@ -1309,9 +1374,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.134" +version = "0.2.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" +checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" [[package]] name = "libloading" @@ -1323,6 +1388,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "link-cplusplus" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] + [[package]] name = "lock_api" version = "0.4.9" @@ -1453,9 +1527,9 @@ dependencies = [ [[package]] name = "mimalloc-rust" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc30df9dfdb5bb6cb2470de65ca604c3eaa3e5dc2ad02a9a98f567df5844472" +checksum = "6973866e0bc6504c03a16b6817b7e70839cc8a1dbd5d6dab00c65d8034868d8b" dependencies = [ "cty", "mimalloc-rust-sys", @@ -1463,9 +1537,9 @@ dependencies = [ [[package]] name = "mimalloc-rust-sys" -version = "1.7.3-source" +version = "1.7.6-source" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3adc8731262b982f4e0860770dba118305cafe1b2e7ebe95b29b2c2f46a70666" +checksum = "7a50daf45336b979a202a19f53b4b382f2c4bd50f392a8dbdb4c6c56ba5dfa64" dependencies = [ "cc", "cty", @@ -1506,7 +1580,9 @@ dependencies = [ [[package]] name = "modularize_imports" -version = "0.20.0" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b143d1b92b0d159428b62ca54f9dc86f0d93c6b36b259940f9a0a9b3118117" dependencies = [ "convert_case", "handlebars", @@ -1514,7 +1590,6 @@ dependencies = [ "regex", "serde", "swc_core", - "testing", ] [[package]] @@ -1668,6 +1743,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-bigint" version = "0.4.3" @@ -1799,6 +1884,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "owo-colors" version = "3.5.0" @@ -1812,7 +1903,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.3", + "parking_lot_core 0.9.4", ] [[package]] @@ -1832,15 +1923,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall 0.2.16", "smallvec", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] @@ -2082,9 +2173,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.46" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -2386,9 +2477,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.6" +version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" +checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" dependencies = [ "log", "ring", @@ -2448,6 +2539,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "scratch" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + [[package]] name = "sct" version = "0.7.0" @@ -2633,9 +2730,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.85" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" dependencies = [ "itoa", "ryu", @@ -2898,25 +2995,26 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "styled_components" -version = "0.45.0" +version = "0.52.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa9bb5dc721603ce35225910c0442b552369cf9e7322a6083e0ac101cef37da2" dependencies = [ "Inflector", "once_cell", "regex", "serde", - "serde_json", "swc_core", - "testing", "tracing", ] [[package]] name = "styled_jsx" -version = "0.20.0" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9caea170c8166e302071b1261a4797048df244da30c00560636d70cd0557dd85" dependencies = [ "easy-error", "swc_core", - "testing", "tracing", ] @@ -2956,9 +3054,9 @@ dependencies = [ [[package]] name = "swc" -version = "0.232.40" +version = "0.232.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d35a875a7bcaaaefccd067fdd924c588fbeac786921248d035153436539c52a4" +checksum = "84f43b16267f2c0b456897d801ba48748dcfc606f87898342477c59d8d780e71" dependencies = [ "ahash", "anyhow", @@ -3007,9 +3105,9 @@ dependencies = [ [[package]] name = "swc_atoms" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6692dd18b783106f3cafc2721341c1e59a41d153e06d8d7814c78ad92a6ac11" +checksum = "01b878052680dcec3421ab50384279443dbf93651b05da38e5133e0894a18096" dependencies = [ "once_cell", "rkyv", @@ -3022,9 +3120,9 @@ dependencies = [ [[package]] name = "swc_bundler" -version = "0.192.35" +version = "0.192.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc9093c6983a1701937bd4f936d6c2fa2155f481caf435e4312fc3dcfaa8dd23" +checksum = "8d85b1a0ace7261fa3aebcc488c56d592c579e83b316f72d3adc4cd076d166c0" dependencies = [ "ahash", "anyhow", @@ -3070,9 +3168,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.29.9" +version = "0.29.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d1cc2ff3b5ebf6d91a43b713a8f30dac2e638ea1189658d9cba91e8ba70633a" +checksum = "ebd844dfbd9969a9ef8430e954661de43edde353d65e987f935a328619698883" dependencies = [ "ahash", "anyhow", @@ -3128,9 +3226,9 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.39.7" +version = "0.40.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8bb50afd30d553b9364d4509b2d85cb42bd78640cf269c388953b8b8a81960c" +checksum = "69d6c115328c39ba386f6fbcfc8d07625dc7b7c14b8ffb02afb57ddda3069f1e" dependencies = [ "binding_macros", "swc", @@ -3167,9 +3265,9 @@ dependencies = [ [[package]] name = "swc_css_ast" -version = "0.123.1" +version = "0.124.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac7af2bd6f6123ffea646a416efa49e557508de79afd4f574b3818d5956f2a" +checksum = "f102c8fbf277a0cd1e262df04563307ded645e0cd9fd03eaa00e51e57555de2a" dependencies = [ "is-macro", "serde", @@ -3180,9 +3278,9 @@ dependencies = [ [[package]] name = "swc_css_codegen" -version = "0.133.3" +version = "0.134.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f46885b4c24fae057a4fd322e1c782b823f0e764c014c2bc6be5caae56c15f" +checksum = "abc5e638c707044fe3a854103ae08e10afb1d568bc77a1d2054473b7026f53c2" dependencies = [ "auto_impl", "bitflags", @@ -3210,9 +3308,9 @@ dependencies = [ [[package]] name = "swc_css_parser" -version = "0.132.2" +version = "0.133.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e525a746ae3232aac75de1394aaedd4f7cdee06f15fa4915959b7b2acc66f7a5" +checksum = "9ae780196ceb26122640cce7b0501757a215e0878329cb6c376bd1c842d67a0c" dependencies = [ "bitflags", "lexical", @@ -3224,9 +3322,9 @@ dependencies = [ [[package]] name = "swc_css_prefixer" -version = "0.134.3" +version = "0.135.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8bfe2a20799064eae4d8eee414b6960b5500222598164036f074671d6cb9904" +checksum = "900aee8433e4e7539ddfc486c3fca5d838d0995423616b3f78a3c3dbe30d167d" dependencies = [ "once_cell", "preset_env_base", @@ -3241,9 +3339,9 @@ dependencies = [ [[package]] name = "swc_css_utils" -version = "0.120.1" +version = "0.121.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31926afb46e05e8cf2dc3700b97ab192868e2051d8cfc7e7ff7d790a24278f06" +checksum = "bc534e16b225196edd011e179895bdf9ccbe4d13a7688f3e053ba8202a1fd6e9" dependencies = [ "once_cell", "serde", @@ -3256,9 +3354,9 @@ dependencies = [ [[package]] name = "swc_css_visit" -version = "0.122.1" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa6d37102e3e3763587b789b7eda1664cb163948e32f08741338eb7ae65eeeb0" +checksum = "1015c41b1a193baf396daa02195906f81e9169db18cb8c498e41c8729d3f0306" dependencies = [ "serde", "swc_atoms", @@ -3269,9 +3367,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.94.12" +version = "0.94.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beaafac8e8c6ab204d65ec9761bf7b1513fc7cb3f307fbd12c901219c0a5c20b" +checksum = "973d70c6b38c5bff508933bc71f020ac2ab2e33bb8d7333c4a088114a8e08cef" dependencies = [ "bitflags", "is-macro", @@ -3287,9 +3385,9 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.127.18" +version = "0.127.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aa40ba4f04658482496607b21d64a8f029d163c0f55c8c6fc4a7ac83b08dd6f" +checksum = "5b93741c056969597d68e81785c710558daa46d1cf332c9c95e27518e09c23a4" dependencies = [ "memchr", "num-bigint", @@ -3319,9 +3417,9 @@ dependencies = [ [[package]] name = "swc_ecma_ext_transforms" -version = "0.91.19" +version = "0.91.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "798a2d8b484b0c12e72f9dee4bdcb1718216ceb8d2e6b16c064eab63c03ae8c1" +checksum = "3c2fa21c243b2941f5a2cc025a67f38128ac64c7dfc57fcc6b2dec798c0f8512" dependencies = [ "phf", "swc_atoms", @@ -3333,9 +3431,9 @@ dependencies = [ [[package]] name = "swc_ecma_lints" -version = "0.66.26" +version = "0.66.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abdd91a1c544ed15597151bfa510db41b0490e0b4dd2fb3b9546d1365b055476" +checksum = "5639b86e772fb603a4bcd32d19aec6b515bf4b2a41b2285271fd6486dbe61011" dependencies = [ "ahash", "auto_impl", @@ -3354,9 +3452,9 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "0.41.10" +version = "0.41.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d698974ec9e0676537385f067ee3ebdfbf6d98c08130ce1b28d722db87c5d60" +checksum = "0c0aac15ea4dfdceec8b04389f2d6ff27ea0f0d243aa89904e420a6d0a96e512" dependencies = [ "ahash", "anyhow", @@ -3376,9 +3474,9 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.159.35" +version = "0.159.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aec9d4f8fed9093c778e14b3825b2926a2efa8498cddf9decb49158b40de7fba" +checksum = "69ac661202129bfd12000ae0f51322e1c7d78d66c6cc5333133e611470233512" dependencies = [ "ahash", "arrayvec", @@ -3410,9 +3508,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.122.14" +version = "0.122.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ca8d5fbd704c18ddc699717c7746a68e658cf6de6058d9a380c7df58fed5338" +checksum = "14443e87ad90fe4530c485e7b3e72c36f0c6acabc37dfa8bf61e363d003c96bb" dependencies = [ "either", "enum_kind", @@ -3429,9 +3527,9 @@ dependencies = [ [[package]] name = "swc_ecma_preset_env" -version = "0.174.18" +version = "0.174.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "028e78b81b0ea62841830fe9acc300432654609bdea0d94dca552eda0eaa1791" +checksum = "32f5e3c7987932f0141288ffafc4bc17de0bbb0b4377edf6d1bce8644f5b31b3" dependencies = [ "ahash", "anyhow", @@ -3470,9 +3568,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms" -version = "0.198.18" +version = "0.198.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99839d79b006b52c1df0e86158f1d7eff93cf4efe7ef53c004a1440e423133ff" +checksum = "9c6dfa2cfa8406986b8f60d995b3aa31737a85aa82467ce506e245203cf20717" dependencies = [ "swc_atoms", "swc_common", @@ -3490,9 +3588,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.111.27" +version = "0.111.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993cd3a0be3b5e35e51af8f06700a3fca13861482ba586f9cad12d081ceb0c8e" +checksum = "559daaeb9c55aa30b436c0dc71df092c395f5ad94c3479d9881aae4d1fd36050" dependencies = [ "better_scoped_tls", "bitflags", @@ -3513,9 +3611,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.100.26" +version = "0.100.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c46fdcd9a96380a9b7ad70f8ecdb059c068b76cbdd79ff822ca9e204abb0214" +checksum = "5db5bc5c15ee7b39f686ad05d4e4f76797b5e05a234f79e3a26685d0e2c25d67" dependencies = [ "swc_atoms", "swc_common", @@ -3527,9 +3625,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_compat" -version = "0.136.14" +version = "0.136.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb99f24925b75eae214aa6ff6a4d08badfde1ae006b1be8b17e73a1dc49a422c" +checksum = "4a35f5d6fe2a25590c0596638a040971817f24227f88f5ff5dc1876d435407c7" dependencies = [ "ahash", "arrayvec", @@ -3567,9 +3665,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_module" -version = "0.153.15" +version = "0.153.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45fcd2bf4e6bda9ffe3e1dd54b895f1747550b0fd04f8b463c7982e7694e0680" +checksum = "1b73d5394bf7777f0fe067aec3dfef5322baea2d190fc1f20aad76a5aaef2a14" dependencies = [ "Inflector", "ahash", @@ -3595,9 +3693,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.167.18" +version = "0.167.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e3341d0b52a425bcc0ce4d8b056c3cbea506e78ba7e00962157ca8b65d25c9" +checksum = "1fee8d3c8776554dea73d4179242a91cd2bc6907bff5392308b91d9a46162c96" dependencies = [ "ahash", "dashmap", @@ -3621,9 +3719,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.144.14" +version = "0.144.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32c02eae68857dce8b7b7f063864500b82c4f3130dd7d64c78d637512af0964f" +checksum = "eab720462f222d3902a70197520e8a0008d1dfa8acdb763d5669e86dc1c145a9" dependencies = [ "either", "serde", @@ -3640,9 +3738,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.155.15" +version = "0.155.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6eed61e65e92c3c5db3d5fdbd8433d51909fb1473576fe15b12ea9c63118df22" +checksum = "0bff429559d7e017b5240e3ece5aa957d49891efdfa15f1688604609a70db7d9" dependencies = [ "ahash", "base64", @@ -3667,9 +3765,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_testing" -version = "0.114.13" +version = "0.114.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19c76d4a8b5a8a1f227f9a316a4137ced7b7dc4b140d58d23d10ba0a861ec519" +checksum = "7508e5b892cf62f997a8ed9439a64a0a2f9462d0fc51d53759d67739e38e99be" dependencies = [ "ansi_term", "anyhow", @@ -3693,9 +3791,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.159.16" +version = "0.159.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e59476f30cf62fad5f7183f7f778dbf08dc9821c892bf906b4c3445f4d35b3" +checksum = "95b2f2ad51085d5f8eb29bdeec5a39eeccf3cd6ef10765c56e8a269b8acb0de3" dependencies = [ "serde", "swc_atoms", @@ -3709,9 +3807,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.105.19" +version = "0.105.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f2e4deb0f5cbb491ac3b6d28eb856cc00fd22d0149d10d96f43c658a3239f01" +checksum = "77db4f800571cba479707a4c86135a51befb5b1c200c092671ffce752ae9ccbd" dependencies = [ "indexmap", "num_cpus", @@ -3727,9 +3825,9 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.80.12" +version = "0.80.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d510d7e892a2d23e96813d262fbfbdb984bcd9593c57676f682b1e02fc3eb9" +checksum = "f02b9f5012aa25b66841f44a67ebe6a43ce4ffe10d8fcc08cc67cc598428174a" dependencies = [ "num-bigint", "swc_atoms", @@ -3741,7 +3839,9 @@ dependencies = [ [[package]] name = "swc_emotion" -version = "0.22.0" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "277695628e9adf28202bb6a5c0fb72f3cf0b695f3fc5bcec2fff059a5e56e45b" dependencies = [ "base64", "byteorder", @@ -3750,10 +3850,8 @@ dependencies = [ "radix_fmt", "regex", "serde", - "serde_json", "sourcemap", "swc_core", - "testing", "tracing", ] @@ -3771,9 +3869,9 @@ dependencies = [ [[package]] name = "swc_error_reporters" -version = "0.13.9" +version = "0.13.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df807362a74ecf07439f03c6ec09d72c469a0471eb2b08fc0dc93fb3482507b8" +checksum = "1822db0dfb34c341df0a9ecb18bc8866fc0c6e8c0cf9d1e4cba5ced5b69f8800" dependencies = [ "anyhow", "miette", @@ -3784,9 +3882,9 @@ dependencies = [ [[package]] name = "swc_fast_graph" -version = "0.17.10" +version = "0.17.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdea120688bfd2d7183a8daa8b281daa0717e7e216f79b79548d736294697387" +checksum = "0ed0262f3338afdf976e85290653b9170f4f3272e05f35c2bac3f2cecc8544f2" dependencies = [ "ahash", "indexmap", @@ -3796,9 +3894,9 @@ dependencies = [ [[package]] name = "swc_graph_analyzer" -version = "0.18.10" +version = "0.18.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "908b1807b6744c4d261bba48e9f91346f5a7c5d21c1383aa85df3361af3f8351" +checksum = "085d076c5cf0d27e1b1fedc73d6c356357b8d56e8e1750913906090ffa398e7d" dependencies = [ "ahash", "auto_impl", @@ -3821,9 +3919,9 @@ dependencies = [ [[package]] name = "swc_node_base" -version = "0.5.5" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2771d2e2fe236364f95a4c4e29e41dd82592d047377337401593cade75ef878a" +checksum = "527d43a1eafb036809d47786b1ad69aea0f6be42322f5edcfc0ca3d8b93f6517" dependencies = [ "mimalloc-rust", "tikv-jemallocator", @@ -3831,9 +3929,9 @@ dependencies = [ [[package]] name = "swc_node_comments" -version = "0.16.9" +version = "0.16.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c07978351d9c326e969b5fff58ec844a765fe2367a4b0eaceb1ad18c07984bb" +checksum = "6fec66d33ef26184e7305939347bfdf4a1e18dede5bfdc7d3364b3df614fccfd" dependencies = [ "ahash", "dashmap", @@ -3843,9 +3941,9 @@ dependencies = [ [[package]] name = "swc_nodejs_common" -version = "0.0.1" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a61f704db0d5bbf239312cf2bfdd47ad7c497e407726deff80be2ea4021719c4" +checksum = "e288c3ba8efcbe0132c537b1562940986d386089606f0d0cd383073c440b776b" dependencies = [ "anyhow", "napi", @@ -3858,9 +3956,9 @@ dependencies = [ [[package]] name = "swc_plugin_proxy" -version = "0.22.12" +version = "0.22.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e77ac4bfe3caa221ec0dfd101852da000116d2c458280f9a94d2ec6114f0c660" +checksum = "a7ff92a112fa7f46adc16bb3c7e26147de52a6ca7e4bff3d61c20dee88b20a95" dependencies = [ "better_scoped_tls", "rkyv", @@ -3872,9 +3970,9 @@ dependencies = [ [[package]] name = "swc_plugin_runner" -version = "0.77.19" +version = "0.77.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1317d7c8e50b2fba5e33041216bae79ba20f1e0ac9cf19983bb50974367f8115" +checksum = "72838d4b02fe684c7ae20a38cfe46d63b0bc4aebe9efa7d95a704e49f65abea2" dependencies = [ "anyhow", "enumset", @@ -3895,9 +3993,9 @@ dependencies = [ [[package]] name = "swc_timer" -version = "0.17.9" +version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243bba75c03251238d09f06cc04427e499d0136560a89ab8bf39dd4db89e264f" +checksum = "001a2ff86d52aa13f568b5648600e564268d746c7f052ffa77b2471d982af6e5" dependencies = [ "tracing", ] @@ -3939,9 +4037,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.101" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" +checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1" dependencies = [ "proc-macro2", "quote", @@ -3989,9 +4087,9 @@ dependencies = [ [[package]] name = "testing" -version = "0.31.9" +version = "0.31.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7783ba6ebad3a5c0e50f23c2a24be50995c7d3d9a3bce050fc1a8c640995b261" +checksum = "a4a445627f53435e1d58dce56c77bfcac9605109fec3837320e03e92dc615638" dependencies = [ "ansi_term", "difference", @@ -4065,9 +4163,9 @@ dependencies = [ [[package]] name = "tikv-jemalloc-sys" -version = "0.4.3+5.2.1-patched.2" +version = "0.5.2+5.3.0-patched" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1792ccb507d955b46af42c123ea8863668fae24d03721e40cad6a41773dbb49" +checksum = "ec45c14da997d0925c7835883e4d5c181f196fa142f8c19d7643d1e9af2592c3" dependencies = [ "cc", "fs_extra", @@ -4076,9 +4174,9 @@ dependencies = [ [[package]] name = "tikv-jemallocator" -version = "0.4.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5b7bcecfafe4998587d636f9ae9d55eb9d0499877b88757767c346875067098" +checksum = "20612db8a13a6c06d57ec83953694185a367e16945f66565e8028d2c0bd76979" dependencies = [ "libc", "tikv-jemalloc-sys", @@ -4219,9 +4317,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if 1.0.0", "log", @@ -4232,9 +4330,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", @@ -4254,9 +4352,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", "valuable", @@ -4285,12 +4383,12 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b" +checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" dependencies = [ - "ansi_term", "matchers", + "nu-ansi-term", "once_cell", "regex", "sharded-slab", @@ -4358,9 +4456,9 @@ checksum = "d70b6494226b36008c8366c288d77190b3fad2eb4c10533139c1c1f461127f1a" [[package]] name = "unicode-ident" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-linebreak" @@ -4416,9 +4514,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.1.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f" +checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" dependencies = [ "getrandom", "serde", @@ -5004,6 +5102,27 @@ dependencies = [ "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" version = "0.33.0" @@ -5016,6 +5135,12 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + [[package]] name = "windows_i686_gnu" version = "0.33.0" @@ -5028,6 +5153,12 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + [[package]] name = "windows_i686_msvc" version = "0.33.0" @@ -5040,6 +5171,12 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + [[package]] name = "windows_x86_64_gnu" version = "0.33.0" @@ -5052,6 +5189,18 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + [[package]] name = "windows_x86_64_msvc" version = "0.33.0" @@ -5064,6 +5213,12 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "winreg" version = "0.10.1" diff --git a/packages/next-swc/crates/core/Cargo.toml b/packages/next-swc/crates/core/Cargo.toml index 40e6cc4c8d0da..d676c2658d503 100644 --- a/packages/next-swc/crates/core/Cargo.toml +++ b/packages/next-swc/crates/core/Cargo.toml @@ -19,10 +19,10 @@ pathdiff = "0.2.0" regex = "1.5" serde = "1" serde_json = "1" -swc_emotion = {path="../emotion"} -styled_components = {path="../styled_components"} -styled_jsx = {path="../styled_jsx"} -modularize_imports = {path="../modularize_imports"} +swc_emotion = "0.28.1" +styled_components = "0.52.1" +styled_jsx = "0.29.1" +modularize_imports = "0.25.1" tracing = { version = "0.1.32", features = ["release_max_level_info"] } swc_core = { features = [ @@ -42,9 +42,9 @@ swc_core = { features = [ "ecma_parser_typescript", "cached", "base" -], version = "0.39.7" } +], version = "0.40.7" } [dev-dependencies] -swc_core = { features = ["testing_transform"], version = "0.39.7" } -testing = "0.31.9" +swc_core = { features = ["testing_transform"], version = "0.40.7" } +testing = "0.31.10" walkdir = "2.3.2" diff --git a/packages/next-swc/crates/core/src/lib.rs b/packages/next-swc/crates/core/src/lib.rs index 0c3d6a4d4ccf1..ddc76edec38a8 100644 --- a/packages/next-swc/crates/core/src/lib.rs +++ b/packages/next-swc/crates/core/src/lib.rs @@ -162,7 +162,10 @@ where _ => Either::Right(noop()), }, if opts.styled_jsx { - Either::Left(styled_jsx::styled_jsx(cm.clone(), file.name.clone())) + Either::Left(styled_jsx::visitor::styled_jsx( + cm.clone(), + file.name.clone(), + )) } else { Either::Right(noop()) }, diff --git a/packages/next-swc/crates/core/src/react_server_components.rs b/packages/next-swc/crates/core/src/react_server_components.rs index 7527d43cefb3d..f541d86dcf98b 100644 --- a/packages/next-swc/crates/core/src/react_server_components.rs +++ b/packages/next-swc/crates/core/src/react_server_components.rs @@ -395,7 +395,7 @@ pub fn server_components( JsWord::from("client-only"), JsWord::from("react-dom/client"), JsWord::from("react-dom/server"), - // TODO-APP: JsWord::from("next/router"), + JsWord::from("next/router"), // TODO-APP: Rule out client hooks. ], invalid_client_imports: vec![ diff --git a/packages/next-swc/crates/emotion/Cargo.toml b/packages/next-swc/crates/emotion/Cargo.toml deleted file mode 100644 index d33fab749fc8d..0000000000000 --- a/packages/next-swc/crates/emotion/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -authors = ["강동윤 "] -edition = "2018" -description = "AST Transforms for emotion" -license = "Apache-2.0" -name = "swc_emotion" -repository = "https://github.com/vercel/next.js.git" -version = "0.22.0" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -base64 = "0.13" -byteorder = "1" -fxhash = "0.2.1" -once_cell = "1.13.0" -radix_fmt = "1" -regex = "1.5" -serde = "1" -sourcemap = "6.0.1" -tracing = { version = "0.1.32", features = ["release_max_level_info"] } -swc_core = { features = ["common", "ecma_ast","ecma_codegen", "ecma_utils", "ecma_visit", "trace_macro"], version = "0.39.7" } - -[dev-dependencies] -swc_core = { features = ["testing_transform", "ecma_transforms_react"], version = "0.39.7" } -testing = "0.31.9" -serde_json = "1" diff --git a/packages/next-swc/crates/emotion/src/hash.rs b/packages/next-swc/crates/emotion/src/hash.rs deleted file mode 100644 index 4965e0651c073..0000000000000 --- a/packages/next-swc/crates/emotion/src/hash.rs +++ /dev/null @@ -1,62 +0,0 @@ -// Ported from https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash2.cpp#L37-L86 - -use byteorder::{ByteOrder, LittleEndian}; - -const M: u32 = 0x5bd1_e995; - -pub(crate) fn murmurhash2(key: &[u8], initial_state: u32) -> u32 { - let mut h: u32 = initial_state; - - let mut four_bytes_chunks = key.chunks_exact(4); - for chunk in four_bytes_chunks.by_ref() { - let mut k: u32 = LittleEndian::read_u32(chunk); - k = k.wrapping_mul(M); - k ^= k >> 24; - h = k.wrapping_mul(M) ^ h.wrapping_mul(M); - } - let remainder = four_bytes_chunks.remainder(); - - // Handle the last few bytes of the input array - match remainder.len() { - 3 => { - h ^= u32::from(remainder[2]) << 16; - } - 2 => { - h ^= u32::from(remainder[1]) << 8; - } - 1 => { - h ^= u32::from(remainder[0]); - h = h.wrapping_mul(M); - } - _ => {} - } - h ^= h >> 13; - h = h.wrapping_mul(M); - h ^ (h >> 15) -} - -#[cfg(test)] -mod test { - - use super::murmurhash2; - - #[test] - fn test_murmur2() { - let s1 = "abcdef"; - let s2 = "abcdeg"; - for i in 0..5 { - assert_eq!( - murmurhash2(s1[i..5].as_bytes(), 0), - murmurhash2(s2[i..5].as_bytes(), 0) - ); - } - } - - #[test] - fn verify_hash() { - assert_eq!( - murmurhash2("something".as_bytes(), 0), - u32::from_str_radix("crsxd7", 36).unwrap() - ); - } -} diff --git a/packages/next-swc/crates/emotion/src/import_map.rs b/packages/next-swc/crates/emotion/src/import_map.rs deleted file mode 100644 index 4f832a1dcc3f0..0000000000000 --- a/packages/next-swc/crates/emotion/src/import_map.rs +++ /dev/null @@ -1,81 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use swc_core::{common::collections::AHashMap, ecma::atoms::JsWord}; - -use crate::{EmotionModuleConfig, ExportItem}; - -/// key: `importSource` -pub type ImportMap = AHashMap; - -/// key: `localExportName` -pub type ImportMapValue = AHashMap; - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Config { - canonical_import: ImportItem, -} - -/// `(packageName, exportName)` -#[derive(Debug, Clone, Serialize, Deserialize)] -pub(crate) struct ImportItem(JsWord, JsWord); - -pub(crate) fn expand_import_map( - map: Option<&ImportMap>, - mut imports: Vec, -) -> Vec { - if let Some(map) = map { - map.iter().for_each(|(import_source, value)| { - value - .iter() - .for_each(|(local_export_name, Config { canonical_import })| { - let ImportItem(package_name, export_name) = canonical_import; - - if &**package_name == "@emotion/react" && &**export_name == "jsx" { - return; - } - - let package_transformers = imports - .iter() - .find(|v| v.module_name == *package_name) - .unwrap_or_else(|| { - panic!( - "There is no transformer for the export '{}' in '{}'", - export_name, package_name - ) - }) - .clone(); - - let kind = package_transformers - .exported_names - .iter() - .find(|v| v.name == **export_name) - .map(|v| v.kind) - .or_else(|| { - if export_name == "default" { - package_transformers.default_export - } else { - None - } - }) - .unwrap_or_else(|| { - panic!( - "failed to find export '{}' from package '{}'", - export_name, package_name - ) - }); - - imports.push(EmotionModuleConfig { - module_name: import_source.clone(), - exported_names: vec![ExportItem { - name: local_export_name.to_string(), - kind, - }], - default_export: package_transformers.default_export, - }); - }) - }); - } - - imports -} diff --git a/packages/next-swc/crates/emotion/src/lib.rs b/packages/next-swc/crates/emotion/src/lib.rs deleted file mode 100644 index 7dd8675593110..0000000000000 --- a/packages/next-swc/crates/emotion/src/lib.rs +++ /dev/null @@ -1,845 +0,0 @@ -use std::borrow::Cow; -use std::path::{Path, PathBuf}; -use std::sync::Arc; - -use fxhash::FxHashMap; -use import_map::ImportMap; -use once_cell::sync::Lazy; -use regex::Regex; -use serde::{Deserialize, Serialize}; -use sourcemap::{RawToken, SourceMap as RawSourcemap}; -use swc_core::{ - common::{comments::Comments, util::take::Take, BytePos, SourceMapperDyn, DUMMY_SP}, - ecma::utils::ExprFactory, - ecma::visit::{Fold, FoldWith}, - ecma::{ - ast::{ - ArrayLit, CallExpr, Callee, Expr, ExprOrSpread, Id, Ident, ImportDecl, ImportSpecifier, - JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXAttrValue, JSXElement, JSXElementName, - JSXExpr, JSXExprContainer, JSXObject, KeyValueProp, MemberProp, ModuleExportName, - ObjectLit, Pat, Prop, PropName, PropOrSpread, SourceMapperExt, Tpl, VarDeclarator, - }, - atoms::JsWord, - }, - trace_macro::swc_trace, -}; - -mod hash; -mod import_map; - -static EMOTION_OFFICIAL_LIBRARIES: Lazy> = Lazy::new(|| { - vec![ - EmotionModuleConfig { - module_name: "@emotion/css".into(), - exported_names: vec![ExportItem { - name: "css".to_owned(), - kind: ExprKind::Css, - }], - default_export: Some(ExprKind::Css), - }, - EmotionModuleConfig { - module_name: "@emotion/styled".into(), - exported_names: vec![], - default_export: Some(ExprKind::Styled), - }, - EmotionModuleConfig { - module_name: "@emotion/react".into(), - exported_names: vec![ - ExportItem { - name: "css".to_owned(), - kind: ExprKind::Css, - }, - ExportItem { - name: "keyframes".to_owned(), - kind: ExprKind::Css, - }, - ExportItem { - name: "Global".to_owned(), - kind: ExprKind::GlobalJSX, - }, - ], - ..Default::default() - }, - EmotionModuleConfig { - module_name: "@emotion/primitives".into(), - exported_names: vec![ExportItem { - name: "css".to_owned(), - kind: ExprKind::Css, - }], - default_export: Some(ExprKind::Styled), - }, - EmotionModuleConfig { - module_name: "@emotion/native".into(), - exported_names: vec![ExportItem { - name: "css".to_owned(), - kind: ExprKind::Css, - }], - default_export: Some(ExprKind::Styled), - }, - ] -}); - -static SPACE_AROUND_COLON: Lazy = - Lazy::new(|| Regex::new(r"\s*(?P[:;,\{,\}])\s*").unwrap()); - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct EmotionOptions { - pub enabled: Option, - pub sourcemap: Option, - pub auto_label: Option, - pub label_format: Option, - pub import_map: Option, -} - -impl Default for EmotionOptions { - fn default() -> Self { - EmotionOptions { - enabled: Some(false), - sourcemap: Some(true), - auto_label: Some(true), - label_format: Some("[local]".to_owned()), - import_map: None, - } - } -} - -#[derive(Debug, Clone, Default, Serialize, Deserialize)] -pub struct EmotionModuleConfig { - module_name: JsWord, - exported_names: Vec, - default_export: Option, -} - -#[derive(Debug, Clone, Default, Serialize, Deserialize)] -struct ExportItem { - name: String, - kind: ExprKind, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -enum ImportType { - Named, - Namespace, - Default, -} - -impl Default for ImportType { - fn default() -> Self { - ImportType::Named - } -} - -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] -enum ExprKind { - Css, - Styled, - GlobalJSX, -} - -impl Default for ExprKind { - fn default() -> Self { - ExprKind::Css - } -} - -#[derive(Debug)] -enum PackageMeta { - Named(ExprKind), - Namespace(EmotionModuleConfig), -} - -pub fn emotion( - emotion_options: EmotionOptions, - path: &Path, - cm: Arc, - comments: C, -) -> impl Fold { - EmotionTransformer::new(emotion_options, path, cm, comments) -} - -pub struct EmotionTransformer { - pub options: EmotionOptions, - filepath_hash: Option, - filepath: PathBuf, - dir: Option, - filename: Option, - cm: Arc, - comments: C, - import_packages: FxHashMap, - emotion_target_class_name_count: usize, - current_context: Option, - // skip `css` transformation if it in JSX Element/Attribute - in_jsx_element: bool, - - registered_imports: Vec, -} - -#[swc_trace] -impl EmotionTransformer { - pub fn new( - options: EmotionOptions, - path: &Path, - cm: Arc, - comments: C, - ) -> Self { - let registered_imports = self::import_map::expand_import_map( - options.import_map.as_ref(), - EMOTION_OFFICIAL_LIBRARIES.to_vec(), - ); - - EmotionTransformer { - options, - filepath_hash: None, - filepath: path.to_owned(), - dir: path.parent().and_then(|p| p.to_str()).map(|s| s.to_owned()), - filename: path - .file_name() - .and_then(|filename| filename.to_str()) - .map(|s| s.to_owned()), - cm, - comments, - import_packages: FxHashMap::default(), - emotion_target_class_name_count: 0, - current_context: None, - in_jsx_element: false, - registered_imports, - } - } - - #[inline] - // Compute file hash on demand - // Memorize the hash of the file name - fn get_filename_hash(&mut self) -> u32 { - if self.filepath_hash.is_none() { - self.filepath_hash = Some(hash::murmurhash2( - self.filepath.to_string_lossy().as_bytes(), - 0, - )); - } - self.filepath_hash.unwrap() - } - - fn create_label(&self, with_prefix: bool) -> String { - let prefix = if with_prefix { "label:" } else { "" }; - let mut label = format!( - "{}{}", - prefix, - self.options - .label_format - .clone() - .unwrap_or_else(|| "[local]".to_owned()) - ); - if let Some(current_context) = &self.current_context { - label = label.replace("[local]", current_context); - if let Some(filename) = self.filename.as_ref() { - label = label.replace("[filename]", filename); - } - if let Some(dir) = self.dir.as_ref() { - label = label.replace("[dir]", dir); - }; - } - label - } - - fn create_sourcemap(&mut self, pos: BytePos) -> Option { - if self.options.sourcemap.unwrap_or(false) { - let loc = self.cm.get_code_map().lookup_char_pos(pos); - let filename = self.filepath.to_str().map(|s| s.to_owned()); - let cm = RawSourcemap::new( - filename.clone(), - vec![RawToken { - dst_line: 0, - dst_col: 0, - src_line: loc.line as u32 - 1, - src_col: loc.col_display as u32, - src_id: 0, - name_id: 0, - }], - Vec::new(), - vec![filename.unwrap_or_default()], - Some(vec![Some(loc.file.src.to_string())]), - ); - let mut writer = Vec::new(); - if cm.to_writer(&mut writer).is_ok() { - return Some(format!( - "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,{} */", - base64::encode(writer) - )); - } - } - None - } - - // Find the imported name from modules - // These import statements are supported: - // import styled from '@emotion/styled' - // import { default as whateverStyled } from '@emotion/styled' - // import { css } from '@emotion/react' - // import * as emotionCss from '@emotion/react' - fn generate_import_info(&mut self, expr: &ImportDecl) { - for c in self.registered_imports.iter() { - if expr.src.value == c.module_name { - for specifier in expr.specifiers.iter() { - match specifier { - ImportSpecifier::Named(named) => { - for exported in c.exported_names.iter() { - let matched = match &named.imported { - Some(imported) => match imported { - ModuleExportName::Ident(v) => v.sym == exported.name, - ModuleExportName::Str(v) => v.value == exported.name, - }, - _ => named.local.as_ref() == exported.name, - }; - if matched { - self.import_packages.insert( - named.local.to_id(), - PackageMeta::Named(exported.kind), - ); - } - } - } - ImportSpecifier::Default(default) => { - if let Some(kind) = c.default_export { - self.import_packages - .insert(default.local.to_id(), PackageMeta::Named(kind)); - } - } - ImportSpecifier::Namespace(namespace) => { - self.import_packages - .insert(namespace.local.to_id(), PackageMeta::Namespace(c.clone())); - } - } - } - } - } - } - - fn create_label_prop_node(&mut self, key: &str) -> PropOrSpread { - let stable_class_name = format!( - "e{}{}", - radix_fmt::radix_36(self.get_filename_hash()), - self.emotion_target_class_name_count - ); - self.emotion_target_class_name_count += 1; - PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { - key: PropName::Ident(Ident::new(key.into(), DUMMY_SP)), - value: stable_class_name.into(), - }))) - } - - fn create_args_from_tagged_tpl(&self, tagged_tpl: &mut Tpl) -> Vec { - let args_len = tagged_tpl.exprs.len() + tagged_tpl.quasis.len(); - // 2 more capacity is for `label` and `sourceMap` - let mut args = Vec::with_capacity(args_len + 2); - for index in 0..args_len { - let i = index / 2; - if index % 2 == 0 { - if let Some(q) = tagged_tpl.quasis.get_mut(i) { - let q = q.take(); - let minified = minify_css_string(&q.raw, index == 0, index == args_len - 1); - // Compress one more spaces into one space - if minified.replace(' ', "").is_empty() { - if index != 0 && index != args_len - 1 { - args.push(" ".as_arg()); - } - } else { - args.push(minified.as_arg()) - } - } - } else if let Some(e) = tagged_tpl.exprs.get_mut(i) { - args.push(e.take().as_arg()); - } - } - args - } - - fn rewrite_styles_attr(&mut self, attrs: &mut [JSXAttrOrSpread], pos: BytePos) { - if let Some(attr_value) = attrs.iter_mut().find_map(|attr| { - if let JSXAttrOrSpread::JSXAttr(JSXAttr { - name: JSXAttrName::Ident(i), - value, - .. - }) = attr - { - if i.as_ref() == "styles" { - return value.as_mut(); - } - } - None - }) { - if let Some(raw_attr) = match attr_value { - JSXAttrValue::Lit(lit) => Some(Box::new(Expr::Lit(lit.clone()))), - JSXAttrValue::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(expr), - .. - }) => Some(expr.take()), - _ => None, - } { - *attr_value = self.create_styles_attr(raw_attr, pos); - self.in_jsx_element = true; - } - } - } - - fn create_styles_attr(&mut self, mut raw_attr: Box, pos: BytePos) -> JSXAttrValue { - if let Expr::Array(array_lit) = raw_attr.as_mut() { - if let Some(cm) = self.create_sourcemap(pos) { - array_lit.elems.push(Some(cm.as_arg())); - } - JSXAttrValue::JSXExprContainer(JSXExprContainer { - span: DUMMY_SP, - expr: JSXExpr::Expr(raw_attr), - }) - } else { - JSXAttrValue::JSXExprContainer(JSXExprContainer { - span: DUMMY_SP, - expr: JSXExpr::Expr(Box::new(Expr::Array(ArrayLit { - span: DUMMY_SP, - elems: { - let mut elements = Vec::with_capacity(2); - elements.push(Some(raw_attr.as_arg())); - if let Some(cm) = self.create_sourcemap(pos) { - elements.push(Some(cm.as_arg())); - } - elements - }, - }))), - }) - } - } -} - -impl Fold for EmotionTransformer { - // Collect import modules that indicator if this file need to be transformed - fn fold_import_decl(&mut self, expr: ImportDecl) -> ImportDecl { - if expr.type_only { - return expr; - } - self.generate_import_info(&expr); - expr - } - - fn fold_var_declarator(&mut self, dec: VarDeclarator) -> VarDeclarator { - if let Pat::Ident(i) = &dec.name { - self.current_context = Some(i.id.as_ref().to_owned()); - } - dec.fold_children_with(self) - } - - fn fold_call_expr(&mut self, mut expr: CallExpr) -> CallExpr { - // If no package that we care about is imported, skip the following - // transformation logic. - if self.import_packages.is_empty() { - return expr; - } - if let Callee::Expr(e) = &mut expr.callee { - match e.as_mut() { - // css({}) - Expr::Ident(i) => { - if let Some(package) = self.import_packages.get(&i.to_id()) { - if !expr.args.is_empty() { - if let PackageMeta::Named(kind) = package { - if matches!(kind, ExprKind::Css) && !self.in_jsx_element { - self.comments.add_pure_comment(expr.span.lo()); - if self.options.auto_label.unwrap_or(false) { - expr.args.push(self.create_label(true).as_arg()); - } - if let Some(cm) = self.create_sourcemap(expr.span.lo) { - expr.args.push(cm.as_arg()); - } - } - } - } - } - } - // styled('div')({}) - Expr::Call(c) => { - if let Callee::Expr(callee_exp) = &c.callee { - if let Expr::Ident(i) = callee_exp.as_ref() { - if let Some(PackageMeta::Named(ExprKind::Styled)) = - self.import_packages.get(&i.to_id()) - { - if !c.args.is_empty() { - let mut args_props = Vec::with_capacity(2); - args_props.push(self.create_label_prop_node("target")); - self.comments.add_pure_comment(expr.span.lo()); - if self.options.auto_label.unwrap_or(false) { - args_props.push(PropOrSpread::Prop(Box::new( - Prop::KeyValue(KeyValueProp { - key: PropName::Ident(Ident::new( - "label".into(), - DUMMY_SP, - )), - value: self.create_label(false).into(), - }), - ))); - } - if let Some(cm) = self.create_sourcemap(expr.span.lo()) { - expr.args.push(cm.as_arg()); - } - if let Some(ExprOrSpread { expr, .. }) = c.args.get_mut(1) { - if let Expr::Object(ObjectLit { props, .. }) = expr.as_mut() - { - props.extend(args_props); - } else { - c.args.push( - Expr::Object(ObjectLit { - span: DUMMY_SP, - props: args_props, - }) - .as_arg(), - ); - } - } else { - c.args.push( - Expr::Object(ObjectLit { - span: DUMMY_SP, - props: args_props, - }) - .as_arg(), - ); - } - } - } - } - } - } - // styled.div({}) - // customEmotionReact.css({}) - Expr::Member(m) => { - if let Expr::Ident(i) = m.obj.as_ref() { - if let Some(package) = self.import_packages.get(&i.to_id()) { - if let PackageMeta::Named(kind) = package { - if matches!(kind, ExprKind::Styled) { - if let MemberProp::Ident(prop) = &m.prop { - let mut args_props = Vec::with_capacity(2); - args_props.push(self.create_label_prop_node("target")); - let mut args = vec![prop.sym.as_ref().as_arg()]; - if !self.in_jsx_element { - self.comments.add_pure_comment(expr.span.lo()); - if self.options.auto_label.unwrap_or(false) { - args_props.push(PropOrSpread::Prop(Box::new( - Prop::KeyValue(KeyValueProp { - key: PropName::Ident(Ident::new( - "label".into(), - DUMMY_SP, - )), - value: self.create_label(false).into(), - }), - ))); - } - args.push( - Expr::Object(ObjectLit { - span: DUMMY_SP, - props: args_props, - }) - .as_arg(), - ); - if let Some(cm) = self.create_sourcemap(expr.span.lo()) - { - expr.args.push(cm.as_arg()); - } - } - return CallExpr { - span: expr.span, - type_args: expr.type_args, - args: expr.args, - callee: CallExpr { - span: DUMMY_SP, - type_args: None, - callee: Ident::new(i.sym.clone(), i.span) - .as_callee(), - args, - } - .as_callee(), - }; - } - } - } - if let PackageMeta::Namespace(c) = package { - if c.exported_names - .iter() - .any(|n| match_css_export(n, &m.prop)) - { - self.comments.add_pure_comment(expr.span.lo()); - if self.options.auto_label.unwrap_or(false) { - expr.args.push(self.create_label(true).as_arg()); - } - if let Some(cm) = self.create_sourcemap(expr.span.lo()) { - expr.args.push(cm.as_arg()); - } - } - } - } - } - } - _ => {} - } - } - expr - } - - fn fold_expr(&mut self, mut expr: Expr) -> Expr { - if let Expr::TaggedTpl(tagged_tpl) = &mut expr { - // styled('div')`` - match tagged_tpl.tag.as_mut() { - Expr::Call(call) => { - if let Callee::Expr(callee) = &call.callee { - if let Expr::Ident(i) = callee.as_ref() { - if let Some(PackageMeta::Named(ExprKind::Styled)) = - self.import_packages.get(&i.to_id()) - { - let mut callee = call.take(); - let mut object_props = Vec::with_capacity(2); - object_props.push(self.create_label_prop_node("target")); - self.comments.add_pure_comment(callee.span.lo()); - if self.options.auto_label.unwrap_or(false) { - object_props.push(PropOrSpread::Prop(Box::new( - Prop::KeyValue(KeyValueProp { - key: PropName::Ident(Ident::new( - "label".into(), - DUMMY_SP, - )), - value: self.create_label(false).into(), - }), - ))); - } - if let Some(ExprOrSpread { expr, .. }) = callee.args.get_mut(1) { - if let Expr::Object(ObjectLit { props, .. }) = expr.as_mut() { - props.extend(object_props); - } else { - callee.args.push( - Expr::Object(ObjectLit { - span: DUMMY_SP, - props: object_props, - }) - .as_arg(), - ); - } - } else { - callee.args.push( - Expr::Object(ObjectLit { - span: DUMMY_SP, - props: object_props, - }) - .as_arg(), - ); - } - return Expr::Call(CallExpr { - span: DUMMY_SP, - callee: callee.as_callee(), - args: { - let mut args: Vec = self - .create_args_from_tagged_tpl(&mut tagged_tpl.tpl) - .into_iter() - .map(|exp| exp.fold_children_with(self)) - .collect(); - if let Some(cm) = - self.create_sourcemap(tagged_tpl.span.lo()) - { - args.push(cm.as_arg()); - } - args - }, - type_args: None, - }); - } - } - } - } - // css`` - Expr::Ident(i) => { - if let Some(PackageMeta::Named(ExprKind::Css)) = - self.import_packages.get(&i.to_id()) - { - let mut args = self.create_args_from_tagged_tpl(&mut tagged_tpl.tpl); - if !self.in_jsx_element { - self.comments.add_pure_comment(i.span.lo()); - if self.options.auto_label.unwrap_or(false) { - args.push(self.create_label(false).as_arg()); - } - if let Some(cm) = self.create_sourcemap(tagged_tpl.span.lo()) { - args.push(cm.as_arg()); - } - } - return Expr::Call(CallExpr { - span: DUMMY_SP, - callee: i.take().as_callee(), - args, - type_args: None, - }); - } - } - // styled.div`` - // customEmotionReact.css`` - Expr::Member(member_expr) => { - if let Expr::Ident(i) = member_expr.obj.as_mut() { - if let Some(p) = self.import_packages.get(&i.to_id()) { - match p { - PackageMeta::Named(ExprKind::Styled) => { - if let MemberProp::Ident(prop) = &mut member_expr.prop { - let mut object_props = Vec::with_capacity(2); - object_props.push(self.create_label_prop_node("target")); - if self.options.auto_label.unwrap_or(false) { - object_props.push(PropOrSpread::Prop(Box::new( - Prop::KeyValue(KeyValueProp { - key: PropName::Ident(Ident::new( - "label".into(), - DUMMY_SP, - )), - value: self.create_label(false).into(), - }), - ))); - } - let mut args = - self.create_args_from_tagged_tpl(&mut tagged_tpl.tpl); - - if let Some(cm) = - self.create_sourcemap(tagged_tpl.span.lo()) - { - args.push(cm.as_arg()); - } - - self.comments.add_pure_comment(member_expr.span.lo()); - return Expr::Call(CallExpr { - span: DUMMY_SP, - type_args: None, - callee: CallExpr { - type_args: None, - span: DUMMY_SP, - callee: i.take().as_callee(), - args: vec![ - prop.take().sym.as_arg(), - Expr::Object(ObjectLit { - span: DUMMY_SP, - props: object_props, - }) - .as_arg(), - ], - } - .as_callee(), - args, - }); - } - } - PackageMeta::Namespace(c) => { - if c.exported_names - .iter() - .any(|item| match_css_export(item, &member_expr.prop)) - { - self.comments.add_pure_comment(member_expr.span.lo()); - return Expr::Call(CallExpr { - span: DUMMY_SP, - callee: member_expr.take().as_callee(), - args: { - let mut args = self.create_args_from_tagged_tpl( - &mut tagged_tpl.tpl, - ); - if self.options.auto_label.unwrap_or(false) { - args.push(self.create_label(true).as_arg()); - } - if let Some(cm) = - self.create_sourcemap(tagged_tpl.span.lo()) - { - args.push(cm.as_arg()); - } - args - }, - type_args: None, - }); - } - } - _ => {} - } - } - } - } - _ => {} - } - } - - expr.fold_children_with(self) - } - - fn fold_jsx_element(&mut self, mut expr: JSXElement) -> JSXElement { - match &mut expr.opening.name { - JSXElementName::Ident(i) => { - if let Some(PackageMeta::Named(ExprKind::GlobalJSX)) = - self.import_packages.get(&i.to_id()) - { - self.rewrite_styles_attr(&mut expr.opening.attrs, i.span.lo()); - } - } - JSXElementName::JSXMemberExpr(member_exp) => { - if let JSXObject::Ident(i) = &member_exp.obj { - if let Some(PackageMeta::Namespace(EmotionModuleConfig { - exported_names, - .. - })) = self.import_packages.get(&i.to_id()) - { - if exported_names.iter().any(|item| { - matches!(item.kind, ExprKind::GlobalJSX) - && item.name == member_exp.prop.as_ref() - }) { - self.rewrite_styles_attr(&mut expr.opening.attrs, i.span.lo()); - } - } - } - } - _ => {} - }; - let dest_expr = expr.fold_children_with(self); - self.in_jsx_element = false; - dest_expr - } -} - -fn match_css_export(item: &ExportItem, prop: &MemberProp) -> bool { - if matches!(item.kind, ExprKind::Css) { - if let MemberProp::Ident(prop) = prop { - if item.name.as_str() == prop.sym.as_ref() { - return true; - } - } - } - false -} - -#[inline] -fn minify_css_string(input: &str, is_first_item: bool, is_last_item: bool) -> Cow { - let pattern = |c| c == '\n'; - let pattern_trim_spaces = |c| c == ' ' || c == '\n'; - SPACE_AROUND_COLON.replace_all( - input - .trim_start_matches(if is_first_item { - pattern_trim_spaces - } else { - pattern - }) - .trim_end_matches(if is_last_item { - pattern_trim_spaces - } else { - pattern - }), - "$s", - ) -} - -#[allow(unused_imports)] -mod test_emotion { - use super::minify_css_string; - - #[test] - fn should_not_trim_end_space_in_first_item() { - assert_eq!( - minify_css_string( - r#" - box-shadow: inset 0px 0px 0px "#, - true, - false - ), - "box-shadow:inset 0px 0px 0px " - ); - } -} diff --git a/packages/next-swc/crates/emotion/tests/fixture.rs b/packages/next-swc/crates/emotion/tests/fixture.rs deleted file mode 100644 index 732ba23925569..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture.rs +++ /dev/null @@ -1,64 +0,0 @@ -use std::path::PathBuf; - -use swc_core::{ - common::{chain, comments::SingleThreadedComments, Mark}, - ecma::parser::{Syntax, TsConfig}, - ecma::transforms::react::{jsx, Runtime}, - ecma::transforms::testing::test_fixture, -}; -use swc_emotion::EmotionOptions; -use testing::fixture; - -fn ts_syntax() -> Syntax { - Syntax::Typescript(TsConfig { - tsx: true, - ..Default::default() - }) -} - -#[fixture("tests/fixture/**/input.tsx")] -fn next_emotion_fixture(input: PathBuf) { - let output = input.parent().unwrap().join("output.ts"); - test_fixture( - ts_syntax(), - &|tr| { - let top_level_mark = Mark::fresh(Mark::root()); - let jsx = jsx::( - tr.cm.clone(), - Some(tr.comments.as_ref().clone()), - swc_core::ecma::transforms::react::Options { - next: false.into(), - runtime: Some(Runtime::Automatic), - throw_if_namespace: false.into(), - development: false.into(), - use_builtins: true.into(), - use_spread: true.into(), - ..Default::default() - }, - top_level_mark, - ); - - let test_import_map = - serde_json::from_str(include_str!("./testImportMap.json")).unwrap(); - - chain!( - swc_emotion::emotion( - EmotionOptions { - enabled: Some(true), - sourcemap: Some(true), - auto_label: Some(true), - import_map: Some(test_import_map), - ..Default::default() - }, - &PathBuf::from("input.ts"), - tr.cm.clone(), - tr.comments.as_ref().clone(), - ), - jsx - ) - }, - &input, - &output, - Default::default(), - ); -} diff --git a/packages/next-swc/crates/emotion/tests/fixture/compress/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/compress/input.tsx deleted file mode 100644 index 76a9a96c0187a..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/compress/input.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { css } from '@emotion/react' -import styled from '@emotion/styled' - -const unitNormal = '1rem' -const unitLarge = '2rem' - -const Example = styled.div` - margin: ${unitNormal} ${unitLarge}; -` - -export const Animated = styled.div` - & code { - background-color: linen; - } - animation: ${({ animation }) => animation} 0.2s infinite ease-in-out alternate; -` - -const shadowBorder = ({ width = '1px', color }) => - css` - box-shadow: inset 0px 0px 0px ${width} ${color}; - ` - -const StyledInput = styled.input` - ${shadowBorder({ color: 'red', width: '4px' })} -` diff --git a/packages/next-swc/crates/emotion/tests/fixture/compress/output.ts b/packages/next-swc/crates/emotion/tests/fixture/compress/output.ts deleted file mode 100644 index d6d0477be2491..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/compress/output.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { css } from '@emotion/react'; -import styled from '@emotion/styled'; -const unitNormal = '1rem'; -const unitLarge = '2rem'; -const Example = /*#__PURE__*/ styled("div", { - target: "ekie5mj0", - label: "Example" -})("margin:", unitNormal, " ", unitLarge, ";", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcyB9IGZyb20gJ0BlbW90aW9uL3JlYWN0J1xuaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnXG5cbmNvbnN0IHVuaXROb3JtYWwgPSAnMXJlbSdcbmNvbnN0IHVuaXRMYXJnZSA9ICcycmVtJ1xuXG5jb25zdCBFeGFtcGxlID0gc3R5bGVkLmRpdmBcbiAgbWFyZ2luOiAke3VuaXROb3JtYWx9ICR7dW5pdExhcmdlfTtcbmBcblxuZXhwb3J0IGNvbnN0IEFuaW1hdGVkID0gc3R5bGVkLmRpdmBcbiAgJiBjb2RlIHtcbiAgICBiYWNrZ3JvdW5kLWNvbG9yOiBsaW5lbjtcbiAgfVxuICBhbmltYXRpb246ICR7KHsgYW5pbWF0aW9uIH0pID0+IGFuaW1hdGlvbn0gMC4ycyBpbmZpbml0ZSBlYXNlLWluLW91dCBhbHRlcm5hdGU7XG5gXG5cbmNvbnN0IHNoYWRvd0JvcmRlciA9ICh7IHdpZHRoID0gJzFweCcsIGNvbG9yIH0pID0+XG4gIGNzc2BcbiAgICBib3gtc2hhZG93OiBpbnNldCAwcHggMHB4IDBweCAke3dpZHRofSAke2NvbG9yfTtcbiAgYFxuXG5jb25zdCBTdHlsZWRJbnB1dCA9IHN0eWxlZC5pbnB1dGBcbiAgJHtzaGFkb3dCb3JkZXIoeyBjb2xvcjogJ3JlZCcsIHdpZHRoOiAnNHB4JyB9KX1cbmBcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNZ0IifQ== */"); -export const Animated = /*#__PURE__*/ styled("div", { - target: "ekie5mj1", - label: "Animated" -})("& code{background-color:linen;}animation:", ({ animation })=>animation -, " 0.2s infinite ease-in-out alternate;", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcyB9IGZyb20gJ0BlbW90aW9uL3JlYWN0J1xuaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnXG5cbmNvbnN0IHVuaXROb3JtYWwgPSAnMXJlbSdcbmNvbnN0IHVuaXRMYXJnZSA9ICcycmVtJ1xuXG5jb25zdCBFeGFtcGxlID0gc3R5bGVkLmRpdmBcbiAgbWFyZ2luOiAke3VuaXROb3JtYWx9ICR7dW5pdExhcmdlfTtcbmBcblxuZXhwb3J0IGNvbnN0IEFuaW1hdGVkID0gc3R5bGVkLmRpdmBcbiAgJiBjb2RlIHtcbiAgICBiYWNrZ3JvdW5kLWNvbG9yOiBsaW5lbjtcbiAgfVxuICBhbmltYXRpb246ICR7KHsgYW5pbWF0aW9uIH0pID0+IGFuaW1hdGlvbn0gMC4ycyBpbmZpbml0ZSBlYXNlLWluLW91dCBhbHRlcm5hdGU7XG5gXG5cbmNvbnN0IHNoYWRvd0JvcmRlciA9ICh7IHdpZHRoID0gJzFweCcsIGNvbG9yIH0pID0+XG4gIGNzc2BcbiAgICBib3gtc2hhZG93OiBpbnNldCAwcHggMHB4IDBweCAke3dpZHRofSAke2NvbG9yfTtcbiAgYFxuXG5jb25zdCBTdHlsZWRJbnB1dCA9IHN0eWxlZC5pbnB1dGBcbiAgJHtzaGFkb3dCb3JkZXIoeyBjb2xvcjogJ3JlZCcsIHdpZHRoOiAnNHB4JyB9KX1cbmBcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFVd0IifQ== */"); -const shadowBorder = ({ width ='1px' , color })=>/*#__PURE__*/ css("box-shadow:inset 0px 0px 0px ", width, " ", color, ";", "shadowBorder", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcyB9IGZyb20gJ0BlbW90aW9uL3JlYWN0J1xuaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnXG5cbmNvbnN0IHVuaXROb3JtYWwgPSAnMXJlbSdcbmNvbnN0IHVuaXRMYXJnZSA9ICcycmVtJ1xuXG5jb25zdCBFeGFtcGxlID0gc3R5bGVkLmRpdmBcbiAgbWFyZ2luOiAke3VuaXROb3JtYWx9ICR7dW5pdExhcmdlfTtcbmBcblxuZXhwb3J0IGNvbnN0IEFuaW1hdGVkID0gc3R5bGVkLmRpdmBcbiAgJiBjb2RlIHtcbiAgICBiYWNrZ3JvdW5kLWNvbG9yOiBsaW5lbjtcbiAgfVxuICBhbmltYXRpb246ICR7KHsgYW5pbWF0aW9uIH0pID0+IGFuaW1hdGlvbn0gMC4ycyBpbmZpbml0ZSBlYXNlLWluLW91dCBhbHRlcm5hdGU7XG5gXG5cbmNvbnN0IHNoYWRvd0JvcmRlciA9ICh7IHdpZHRoID0gJzFweCcsIGNvbG9yIH0pID0+XG4gIGNzc2BcbiAgICBib3gtc2hhZG93OiBpbnNldCAwcHggMHB4IDBweCAke3dpZHRofSAke2NvbG9yfTtcbiAgYFxuXG5jb25zdCBTdHlsZWRJbnB1dCA9IHN0eWxlZC5pbnB1dGBcbiAgJHtzaGFkb3dCb3JkZXIoeyBjb2xvcjogJ3JlZCcsIHdpZHRoOiAnNHB4JyB9KX1cbmBcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFrQkUifQ== */") -; -const StyledInput = /*#__PURE__*/ styled("input", { - target: "ekie5mj2", - label: "StyledInput" -})(shadowBorder({ - color: 'red', - width: '4px' -}), "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcyB9IGZyb20gJ0BlbW90aW9uL3JlYWN0J1xuaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnXG5cbmNvbnN0IHVuaXROb3JtYWwgPSAnMXJlbSdcbmNvbnN0IHVuaXRMYXJnZSA9ICcycmVtJ1xuXG5jb25zdCBFeGFtcGxlID0gc3R5bGVkLmRpdmBcbiAgbWFyZ2luOiAke3VuaXROb3JtYWx9ICR7dW5pdExhcmdlfTtcbmBcblxuZXhwb3J0IGNvbnN0IEFuaW1hdGVkID0gc3R5bGVkLmRpdmBcbiAgJiBjb2RlIHtcbiAgICBiYWNrZ3JvdW5kLWNvbG9yOiBsaW5lbjtcbiAgfVxuICBhbmltYXRpb246ICR7KHsgYW5pbWF0aW9uIH0pID0+IGFuaW1hdGlvbn0gMC4ycyBpbmZpbml0ZSBlYXNlLWluLW91dCBhbHRlcm5hdGU7XG5gXG5cbmNvbnN0IHNoYWRvd0JvcmRlciA9ICh7IHdpZHRoID0gJzFweCcsIGNvbG9yIH0pID0+XG4gIGNzc2BcbiAgICBib3gtc2hhZG93OiBpbnNldCAwcHggMHB4IDBweCAke3dpZHRofSAke2NvbG9yfTtcbiAgYFxuXG5jb25zdCBTdHlsZWRJbnB1dCA9IHN0eWxlZC5pbnB1dGBcbiAgJHtzaGFkb3dCb3JkZXIoeyBjb2xvcjogJ3JlZCcsIHdpZHRoOiAnNHB4JyB9KX1cbmBcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFzQm9CIn0= */"); diff --git a/packages/next-swc/crates/emotion/tests/fixture/css-in-callback/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/css-in-callback/input.tsx deleted file mode 100644 index 50ee6094f345e..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/css-in-callback/input.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { css, Global } from '@emotion/react' -import styled from '@emotion/styled' -import { PureComponent } from 'react' -import ReactDOM from 'react-dom' - -const stylesInCallback = (props: any) => - css({ - color: 'red', - background: 'yellow', - width: `${props.scale * 100}px`, - }) - -const styles = css({ - color: 'red', - width: '20px', -}) - -const styles2 = css` - color: red; - width: 20px; -` - -const DivContainer = styled.div({ - background: 'red', -}) - -const DivContainer2 = styled.div` - background: red; -` - -const ContainerWithOptions = styled('div', { - shouldForwardProp: (propertyName: string) => !propertyName.startsWith('$'), -})` - color: hotpink; -` - -const SpanContainer = styled('span')({ - background: 'yellow', -}) - -export const DivContainerExtended = styled(DivContainer)`` -export const DivContainerExtended2 = styled(DivContainer)({}) - -const Container = styled('button')` - background: red; - ${stylesInCallback} - ${() => - css({ - background: 'red', - })} - color: yellow; - font-size: 12px; -` - -const Container2 = styled.div` - background: red; -` - -export class SimpleComponent extends PureComponent { - render() { - return ( - - - hello - - ) - } -} - -ReactDOM.render(, document.querySelector('#app')) diff --git a/packages/next-swc/crates/emotion/tests/fixture/css-in-callback/output.ts b/packages/next-swc/crates/emotion/tests/fixture/css-in-callback/output.ts deleted file mode 100644 index 12bf563dc7801..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/css-in-callback/output.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; -import { css, Global } from '@emotion/react'; -import styled from '@emotion/styled'; -import { PureComponent } from 'react'; -import ReactDOM from 'react-dom'; -const stylesInCallback = (props: any)=>/*#__PURE__*/ css({ - color: 'red', - background: 'yellow', - width: `${props.scale * 100}px` - }, "label:stylesInCallback", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNRSJ9 */"); -const styles = /*#__PURE__*/ css({ - color: 'red', - width: '20px' -}, "label:styles", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFZZSJ9 */"); -const styles2 = /*#__PURE__*/ css("color:red;width:20px;", "styles2", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFpQmdCIn0= */"); -const DivContainer = /*#__PURE__*/ styled("div", { - target: "ekie5mj0", - label: "DivContainer" -})({ - background: 'red' -}, "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFzQnFCIn0= */"); -const DivContainer2 = /*#__PURE__*/ styled("div", { - target: "ekie5mj1", - label: "DivContainer2" -})("background:red;", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUEwQnNCIn0= */"); -const ContainerWithOptions = /*#__PURE__*/ styled('div', { - shouldForwardProp: (propertyName: string)=>!propertyName.startsWith('$'), - target: "ekie5mj2", - label: "ContainerWithOptions" -})("color:hotpink;", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUE4QjZCIn0= */"); -const SpanContainer = /*#__PURE__*/ styled('span', { - target: "ekie5mj3", - label: "SpanContainer" -})({ - background: 'yellow' -}, "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFvQ3NCIn0= */"); -export const DivContainerExtended = /*#__PURE__*/ styled(DivContainer, { - target: "ekie5mj4", - label: "DivContainerExtended" -})("/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUF3Q29DIn0= */"); -export const DivContainerExtended2 = /*#__PURE__*/ styled(DivContainer, { - target: "ekie5mj5", - label: "DivContainerExtended2" -})({}, "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUF5Q3FDIn0= */"); -const Container = /*#__PURE__*/ styled('button', { - target: "ekie5mj6", - label: "Container" -})("background:red;", stylesInCallback, " ", ()=>/*#__PURE__*/ css({ - background: 'red' - }, "label:Container", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUErQ0kifQ== */"), " color:yellow;font-size:12px;", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUEyQ2tCIn0= */"); -const Container2 = /*#__PURE__*/ styled("div", { - target: "ekie5mj7", - label: "Container2" -})("background:red;", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFzRG1CIn0= */"); -export class SimpleComponent extends PureComponent { - render() { - return /*#__PURE__*/ _jsxs(Container, { - css: /*#__PURE__*/ css("color:hotpink;", "Container2", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUE4RGEifQ== */"), - children: [ - /*#__PURE__*/ _jsx(Global, { - styles: [ - css("html,body{padding:3rem 1rem;margin:0;background:papayawhip;min-height:100%;font-family:Helvetica,Arial,sans-serif;font-size:24px;}"), - "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiByZWQ7XG5gXG5cbmNvbnN0IENvbnRhaW5lcldpdGhPcHRpb25zID0gc3R5bGVkKCdkaXYnLCB7XG4gIHNob3VsZEZvcndhcmRQcm9wOiAocHJvcGVydHlOYW1lOiBzdHJpbmcpID0+ICFwcm9wZXJ0eU5hbWUuc3RhcnRzV2l0aCgnJCcpLFxufSlgXG4gIGNvbG9yOiBob3RwaW5rO1xuYFxuXG5jb25zdCBTcGFuQ29udGFpbmVyID0gc3R5bGVkKCdzcGFuJykoe1xuICBiYWNrZ3JvdW5kOiAneWVsbG93Jyxcbn0pXG5cbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZCA9IHN0eWxlZChEaXZDb250YWluZXIpYGBcbmV4cG9ydCBjb25zdCBEaXZDb250YWluZXJFeHRlbmRlZDIgPSBzdHlsZWQoRGl2Q29udGFpbmVyKSh7fSlcblxuY29uc3QgQ29udGFpbmVyID0gc3R5bGVkKCdidXR0b24nKWBcbiAgYmFja2dyb3VuZDogcmVkO1xuICAke3N0eWxlc0luQ2FsbGJhY2t9XG4gICR7KCkgPT5cbiAgICBjc3Moe1xuICAgICAgYmFja2dyb3VuZDogJ3JlZCcsXG4gICAgfSl9XG4gIGNvbG9yOiB5ZWxsb3c7XG4gIGZvbnQtc2l6ZTogMTJweDtcbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFrRVMifQ== */" - ] - }), - /*#__PURE__*/ _jsx("span", { - children: "hello" - }) - ] - }); - } -} -ReactDOM.render(/*#__PURE__*/ _jsx(SimpleComponent, {}), document.querySelector('#app')); diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/global-needs-css/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/import-map/global-needs-css/input.tsx deleted file mode 100644 index 0357e18d214a2..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/global-needs-css/input.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import * as React from 'react' -import { SomeGlobalFromCore } from 'package-two' - -const getBgColor = () => ({ backgroundColor: '#fff' }) - -export default () => ( - -) diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/global-needs-css/output.ts b/packages/next-swc/crates/emotion/tests/fixture/import-map/global-needs-css/output.ts deleted file mode 100644 index 17039ba84355c..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/global-needs-css/output.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { jsx as _jsx } from "react/jsx-runtime"; -import * as React from 'react'; -import { SomeGlobalFromCore } from 'package-two'; -const getBgColor = ()=>({ - backgroundColor: '#fff' - }); -export default (()=>/*#__PURE__*/ _jsx(SomeGlobalFromCore, { - styles: [ - { - color: 'hotpink', - ...getBgColor() - }, - "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCAqIGFzIFJlYWN0IGZyb20gJ3JlYWN0J1xuaW1wb3J0IHsgU29tZUdsb2JhbEZyb21Db3JlIH0gZnJvbSAncGFja2FnZS10d28nXG5cbmNvbnN0IGdldEJnQ29sb3IgPSAoKSA9PiAoeyBiYWNrZ3JvdW5kQ29sb3I6ICcjZmZmJyB9KVxuXG5leHBvcnQgZGVmYXVsdCAoKSA9PiAoXG4gIDxTb21lR2xvYmFsRnJvbUNvcmUgc3R5bGVzPXt7IGNvbG9yOiAnaG90cGluaycsIC4uLmdldEJnQ29sb3IoKSB9fSAvPlxuKVxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1HIn0= */" - ] - })); diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/global/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/import-map/global/input.tsx deleted file mode 100644 index 71cf49659ff9e..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/global/input.tsx +++ /dev/null @@ -1,4 +0,0 @@ -import * as React from 'react' -import { SomeGlobalFromCore } from 'package-two' - -export default () => diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/global/output.ts b/packages/next-swc/crates/emotion/tests/fixture/import-map/global/output.ts deleted file mode 100644 index e288089660b7a..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/global/output.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { jsx as _jsx } from "react/jsx-runtime"; -import * as React from 'react'; -import { SomeGlobalFromCore } from 'package-two'; -export default (()=>/*#__PURE__*/ _jsx(SomeGlobalFromCore, { - styles: [ - { - color: 'hotpink' - }, - "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCAqIGFzIFJlYWN0IGZyb20gJ3JlYWN0J1xuaW1wb3J0IHsgU29tZUdsb2JhbEZyb21Db3JlIH0gZnJvbSAncGFja2FnZS10d28nXG5cbmV4cG9ydCBkZWZhdWx0ICgpID0+IDxTb21lR2xvYmFsRnJvbUNvcmUgc3R5bGVzPXt7IGNvbG9yOiAnaG90cGluaycgfX0gLz5cbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHc0IifQ== */" - ] - })); diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled-aliased/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled-aliased/input.tsx deleted file mode 100644 index c0c75ad33dbab..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled-aliased/input.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import { nonDefaultStyled as someAlias } from 'package-one' - -let SomeComp = someAlias.div({ color: 'hotpink' }) diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled-aliased/output.ts b/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled-aliased/output.ts deleted file mode 100644 index 9190de0d61579..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled-aliased/output.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { nonDefaultStyled as someAlias } from 'package-one'; -let SomeComp = /*#__PURE__*/ someAlias("div", { - target: "ekie5mj0", - label: "SomeComp" -})({ - color: 'hotpink' -}, "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IG5vbkRlZmF1bHRTdHlsZWQgYXMgc29tZUFsaWFzIH0gZnJvbSAncGFja2FnZS1vbmUnXG5cbmxldCBTb21lQ29tcCA9IHNvbWVBbGlhcy5kaXYoeyBjb2xvcjogJ2hvdHBpbmsnIH0pXG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRWUifQ== */"); diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled/input.tsx deleted file mode 100644 index 318dc6ff4c1e4..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled/input.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import { nonDefaultStyled } from 'package-one' - -let SomeComp = nonDefaultStyled.div({ color: 'hotpink' }) diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled/output.ts b/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled/output.ts deleted file mode 100644 index 326b078846b89..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/non-default-styled/output.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { nonDefaultStyled } from 'package-one'; -let SomeComp = /*#__PURE__*/ nonDefaultStyled("div", { - target: "ekie5mj0", - label: "SomeComp" -})({ - color: 'hotpink' -}, "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IG5vbkRlZmF1bHRTdHlsZWQgfSBmcm9tICdwYWNrYWdlLW9uZSdcblxubGV0IFNvbWVDb21wID0gbm9uRGVmYXVsdFN0eWxlZC5kaXYoeyBjb2xvcjogJ2hvdHBpbmsnIH0pXG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRWUifQ== */"); diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/styled-with-base-specified/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/import-map/styled-with-base-specified/input.tsx deleted file mode 100644 index f997bea8056c1..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/styled-with-base-specified/input.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import { nonDefaultStyled } from 'package-four' - -let SomeComp = nonDefaultStyled.div({ color: 'hotpink' }) diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/styled-with-base-specified/output.ts b/packages/next-swc/crates/emotion/tests/fixture/import-map/styled-with-base-specified/output.ts deleted file mode 100644 index d641ba9f7f102..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/styled-with-base-specified/output.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { nonDefaultStyled } from 'package-four'; -let SomeComp = /*#__PURE__*/ nonDefaultStyled("div", { - target: "ekie5mj0", - label: "SomeComp" -})({ - color: 'hotpink' -}, "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IG5vbkRlZmF1bHRTdHlsZWQgfSBmcm9tICdwYWNrYWdlLWZvdXInXG5cbmxldCBTb21lQ29tcCA9IG5vbkRlZmF1bHRTdHlsZWQuZGl2KHsgY29sb3I6ICdob3RwaW5rJyB9KVxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVlIn0= */"); diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/vanilla/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/import-map/vanilla/input.tsx deleted file mode 100644 index 81cfb6b30d920..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/vanilla/input.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import { something } from 'package-three' - -something({ color: 'green' }) diff --git a/packages/next-swc/crates/emotion/tests/fixture/import-map/vanilla/output.ts b/packages/next-swc/crates/emotion/tests/fixture/import-map/vanilla/output.ts deleted file mode 100644 index 899b94e0d1dcf..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/import-map/vanilla/output.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { something } from 'package-three'; -/*#__PURE__*/ something({ - color: 'green' -}, "label:[local]", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IHNvbWV0aGluZyB9IGZyb20gJ3BhY2thZ2UtdGhyZWUnXG5cbnNvbWV0aGluZyh7IGNvbG9yOiAnZ3JlZW4nIH0pXG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEifQ== */"); diff --git a/packages/next-swc/crates/emotion/tests/fixture/issues/39672/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/issues/39672/input.tsx deleted file mode 100644 index cabfa5dfb8da6..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/issues/39672/input.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import styled from '@emotion/styled' - -const SelectedComponent = styled.p` - color: red; - - &:after { - content: ' | '; - } -` diff --git a/packages/next-swc/crates/emotion/tests/fixture/issues/39672/output.ts b/packages/next-swc/crates/emotion/tests/fixture/issues/39672/output.ts deleted file mode 100644 index f98d584f94659..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/issues/39672/output.ts +++ /dev/null @@ -1,5 +0,0 @@ -import styled from '@emotion/styled'; -const SelectedComponent = /*#__PURE__*/ styled("p", { - target: "ekie5mj0", - label: "SelectedComponent" -})("color:red;&:after{content:' | ';}", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBzdHlsZWQgZnJvbSAnQGVtb3Rpb24vc3R5bGVkJ1xuXG5jb25zdCBTZWxlY3RlZENvbXBvbmVudCA9IHN0eWxlZC5wYFxuICBjb2xvcjogcmVkO1xuXG4gICY6YWZ0ZXIge1xuICAgIGNvbnRlbnQ6ICcgfCAnO1xuICB9XG5gXG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRTBCIn0= */"); diff --git a/packages/next-swc/crates/emotion/tests/fixture/namespace-import/input.tsx b/packages/next-swc/crates/emotion/tests/fixture/namespace-import/input.tsx deleted file mode 100644 index 843b2d1d1c6db..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/namespace-import/input.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import * as emotionReact from '@emotion/react' -import { PureComponent } from 'react' -import ReactDOM from 'react-dom' - -const stylesInCallback = (props: any) => - emotionReact.css({ - color: 'red', - background: 'yellow', - width: `${props.scale * 100}px`, - }) - -const styles = emotionReact.css({ - color: 'red', - width: '20px', -}) - -const styles2 = emotionReact.css` - color: red; - width: 20px; -` - -export class SimpleComponent extends PureComponent { - render() { - return ( -
- hello -
- ) - } -} - -ReactDOM.render(, document.querySelector('#app')) diff --git a/packages/next-swc/crates/emotion/tests/fixture/namespace-import/output.ts b/packages/next-swc/crates/emotion/tests/fixture/namespace-import/output.ts deleted file mode 100644 index 9a840020f8aab..0000000000000 --- a/packages/next-swc/crates/emotion/tests/fixture/namespace-import/output.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { jsx as _jsx } from "react/jsx-runtime"; -import * as emotionReact from '@emotion/react'; -import { PureComponent } from 'react'; -import ReactDOM from 'react-dom'; -const stylesInCallback = (props: any)=>/*#__PURE__*/ emotionReact.css({ - color: 'red', - background: 'yellow', - width: `${props.scale * 100}px` - }, "label:stylesInCallback", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCAqIGFzIGVtb3Rpb25SZWFjdCBmcm9tICdAZW1vdGlvbi9yZWFjdCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgZW1vdGlvblJlYWN0LmNzcyh7XG4gICAgY29sb3I6ICdyZWQnLFxuICAgIGJhY2tncm91bmQ6ICd5ZWxsb3cnLFxuICAgIHdpZHRoOiBgJHtwcm9wcy5zY2FsZSAqIDEwMH1weGAsXG4gIH0pXG5cbmNvbnN0IHN0eWxlcyA9IGVtb3Rpb25SZWFjdC5jc3Moe1xuICBjb2xvcjogJ3JlZCcsXG4gIHdpZHRoOiAnMjBweCcsXG59KVxuXG5jb25zdCBzdHlsZXMyID0gZW1vdGlvblJlYWN0LmNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmV4cG9ydCBjbGFzcyBTaW1wbGVDb21wb25lbnQgZXh0ZW5kcyBQdXJlQ29tcG9uZW50IHtcbiAgcmVuZGVyKCkge1xuICAgIHJldHVybiAoXG4gICAgICA8ZGl2IGNsYXNzTmFtZT17c3R5bGVzfT5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L2Rpdj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFLRSJ9 */") -; -const styles = /*#__PURE__*/ emotionReact.css({ - color: 'red', - width: '20px' -}, "label:styles", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCAqIGFzIGVtb3Rpb25SZWFjdCBmcm9tICdAZW1vdGlvbi9yZWFjdCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgZW1vdGlvblJlYWN0LmNzcyh7XG4gICAgY29sb3I6ICdyZWQnLFxuICAgIGJhY2tncm91bmQ6ICd5ZWxsb3cnLFxuICAgIHdpZHRoOiBgJHtwcm9wcy5zY2FsZSAqIDEwMH1weGAsXG4gIH0pXG5cbmNvbnN0IHN0eWxlcyA9IGVtb3Rpb25SZWFjdC5jc3Moe1xuICBjb2xvcjogJ3JlZCcsXG4gIHdpZHRoOiAnMjBweCcsXG59KVxuXG5jb25zdCBzdHlsZXMyID0gZW1vdGlvblJlYWN0LmNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmV4cG9ydCBjbGFzcyBTaW1wbGVDb21wb25lbnQgZXh0ZW5kcyBQdXJlQ29tcG9uZW50IHtcbiAgcmVuZGVyKCkge1xuICAgIHJldHVybiAoXG4gICAgICA8ZGl2IGNsYXNzTmFtZT17c3R5bGVzfT5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L2Rpdj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFXZSJ9 */"); -const styles2 = /*#__PURE__*/ emotionReact.css("color:red;width:20px;", "label:styles2", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCAqIGFzIGVtb3Rpb25SZWFjdCBmcm9tICdAZW1vdGlvbi9yZWFjdCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgZW1vdGlvblJlYWN0LmNzcyh7XG4gICAgY29sb3I6ICdyZWQnLFxuICAgIGJhY2tncm91bmQ6ICd5ZWxsb3cnLFxuICAgIHdpZHRoOiBgJHtwcm9wcy5zY2FsZSAqIDEwMH1weGAsXG4gIH0pXG5cbmNvbnN0IHN0eWxlcyA9IGVtb3Rpb25SZWFjdC5jc3Moe1xuICBjb2xvcjogJ3JlZCcsXG4gIHdpZHRoOiAnMjBweCcsXG59KVxuXG5jb25zdCBzdHlsZXMyID0gZW1vdGlvblJlYWN0LmNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmV4cG9ydCBjbGFzcyBTaW1wbGVDb21wb25lbnQgZXh0ZW5kcyBQdXJlQ29tcG9uZW50IHtcbiAgcmVuZGVyKCkge1xuICAgIHJldHVybiAoXG4gICAgICA8ZGl2IGNsYXNzTmFtZT17c3R5bGVzfT5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L2Rpdj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFnQmdCIn0= */"); -export class SimpleComponent extends PureComponent { - render() { - return /*#__PURE__*/ _jsx("div", { - className: styles, - children: /*#__PURE__*/ _jsx("span", { - children: "hello" - }) - }); - } -} -ReactDOM.render(/*#__PURE__*/ _jsx(SimpleComponent, {}), document.querySelector('#app')); diff --git a/packages/next-swc/crates/emotion/tests/testImportMap.json b/packages/next-swc/crates/emotion/tests/testImportMap.json deleted file mode 100644 index 7fb881123d6cc..0000000000000 --- a/packages/next-swc/crates/emotion/tests/testImportMap.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "package-one": { - "nonDefaultStyled": { "canonicalImport": ["@emotion/styled", "default"] } - }, - "package-two": { - "someJsx": { "canonicalImport": ["@emotion/react", "jsx"] }, - "someCssFromCore": { "canonicalImport": ["@emotion/react", "css"] }, - "SomeGlobalFromCore": { "canonicalImport": ["@emotion/react", "Global"] } - }, - "package-three": { - "something": { "canonicalImport": ["@emotion/css", "css"] } - }, - "package-four": { - "nonDefaultStyled": { - "canonicalImport": ["@emotion/styled", "default"], - "styledBaseImport": ["package-four/base", "something"] - } - } -} diff --git a/packages/next-swc/crates/modularize_imports/Cargo.toml b/packages/next-swc/crates/modularize_imports/Cargo.toml deleted file mode 100644 index ab220afdc4999..0000000000000 --- a/packages/next-swc/crates/modularize_imports/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -authors = ["강동윤 "] -description = "AST Transforms for import modularizer" -edition = "2018" -license = "Apache-2.0" -name = "modularize_imports" -repository = "https://github.com/vercel/next.js.git" -version = "0.20.0" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -convert_case = "0.5.0" -handlebars = "4.2.1" -once_cell = "1.13.0" -regex = "1.5" -serde = "1" -swc_core = { features = ["cached", "ecma_ast", "ecma_visit"], version = "0.39.7" } - -[dev-dependencies] -swc_core = { features = ["testing_transform"], version = "0.39.7" } -testing = "0.31.9" diff --git a/packages/next-swc/crates/modularize_imports/src/lib.rs b/packages/next-swc/crates/modularize_imports/src/lib.rs deleted file mode 100644 index 2d4358b7fe520..0000000000000 --- a/packages/next-swc/crates/modularize_imports/src/lib.rs +++ /dev/null @@ -1,249 +0,0 @@ -use std::collections::HashMap; - -use convert_case::{Case, Casing}; -use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext}; -use once_cell::sync::Lazy; -use regex::{Captures, Regex}; -use serde::{Deserialize, Serialize}; - -use swc_core::{ - cached::regex::CachedRegex, - ecma::ast::*, - ecma::visit::{noop_fold_type, Fold}, -}; - -static DUP_SLASH_REGEX: Lazy = Lazy::new(|| Regex::new(r"//").unwrap()); - -#[derive(Clone, Debug, Deserialize)] -#[serde(transparent)] -pub struct Config { - pub packages: HashMap, -} - -#[derive(Clone, Debug, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct PackageConfig { - pub transform: String, - #[serde(default)] - pub prevent_full_import: bool, - #[serde(default)] - pub skip_default_conversion: bool, -} - -struct FoldImports { - renderer: handlebars::Handlebars<'static>, - packages: Vec<(CachedRegex, PackageConfig)>, -} - -struct Rewriter<'a> { - renderer: &'a handlebars::Handlebars<'static>, - key: &'a str, - config: &'a PackageConfig, - group: Vec<&'a str>, -} - -impl<'a> Rewriter<'a> { - fn rewrite(&self, old_decl: &ImportDecl) -> Vec { - if old_decl.type_only || old_decl.asserts.is_some() { - return vec![old_decl.clone()]; - } - - let mut out: Vec = Vec::with_capacity(old_decl.specifiers.len()); - - for spec in &old_decl.specifiers { - match spec { - ImportSpecifier::Named(named_spec) => { - #[derive(Serialize)] - #[serde(untagged)] - enum Data<'a> { - Plain(&'a str), - Array(&'a [&'a str]), - } - let mut ctx: HashMap<&str, Data> = HashMap::new(); - ctx.insert("matches", Data::Array(&self.group[..])); - ctx.insert( - "member", - Data::Plain( - named_spec - .imported - .as_ref() - .map(|x| match x { - ModuleExportName::Ident(x) => x.as_ref(), - ModuleExportName::Str(x) => x.value.as_ref(), - }) - .unwrap_or_else(|| named_spec.local.as_ref()), - ), - ); - let new_path = self - .renderer - .render_template(&self.config.transform, &ctx) - .unwrap_or_else(|e| { - panic!("error rendering template for '{}': {}", self.key, e); - }); - let new_path = DUP_SLASH_REGEX.replace_all(&new_path, |_: &Captures| "/"); - let specifier = if self.config.skip_default_conversion { - ImportSpecifier::Named(named_spec.clone()) - } else { - ImportSpecifier::Default(ImportDefaultSpecifier { - local: named_spec.local.clone(), - span: named_spec.span, - }) - }; - out.push(ImportDecl { - specifiers: vec![specifier], - src: Box::new(Str::from(new_path.as_ref())), - span: old_decl.span, - type_only: false, - asserts: None, - }); - } - _ => { - if self.config.prevent_full_import { - panic!( - "import {:?} causes the entire module to be imported", - old_decl - ); - } else { - // Give up - return vec![old_decl.clone()]; - } - } - } - } - out - } -} - -impl FoldImports { - fn should_rewrite<'a>(&'a self, name: &'a str) -> Option> { - for (regex, config) in &self.packages { - let group = regex.captures(name); - if let Some(group) = group { - let group = group - .iter() - .map(|x| x.map(|x| x.as_str()).unwrap_or_default()) - .collect::>(); - return Some(Rewriter { - renderer: &self.renderer, - key: name, - config, - group, - }); - } - } - None - } -} - -impl Fold for FoldImports { - noop_fold_type!(); - fn fold_module(&mut self, mut module: Module) -> Module { - let mut new_items: Vec = vec![]; - for item in module.body { - match item { - ModuleItem::ModuleDecl(ModuleDecl::Import(decl)) => { - match self.should_rewrite(&decl.src.value) { - Some(rewriter) => { - let rewritten = rewriter.rewrite(&decl); - new_items.extend( - rewritten - .into_iter() - .map(|x| ModuleItem::ModuleDecl(ModuleDecl::Import(x))), - ); - } - None => new_items.push(ModuleItem::ModuleDecl(ModuleDecl::Import(decl))), - } - } - x => { - new_items.push(x); - } - } - } - module.body = new_items; - module - } -} - -pub fn modularize_imports(config: Config) -> impl Fold { - let mut folder = FoldImports { - renderer: handlebars::Handlebars::new(), - packages: vec![], - }; - folder - .renderer - .register_helper("lowerCase", Box::new(helper_lower_case)); - folder - .renderer - .register_helper("upperCase", Box::new(helper_upper_case)); - folder - .renderer - .register_helper("camelCase", Box::new(helper_camel_case)); - folder - .renderer - .register_helper("kebabCase", Box::new(helper_kebab_case)); - for (mut k, v) in config.packages { - // XXX: Should we keep this hack? - if !k.starts_with('^') && !k.ends_with('$') { - k = format!("^{}$", k); - } - folder.packages.push(( - CachedRegex::new(&k).expect("transform-imports: invalid regex"), - v, - )); - } - folder -} - -fn helper_lower_case( - h: &Helper<'_, '_>, - _: &Handlebars<'_>, - _: &Context, - _: &mut RenderContext<'_, '_>, - out: &mut dyn Output, -) -> HelperResult { - // get parameter from helper or throw an error - let param = h.param(0).and_then(|v| v.value().as_str()).unwrap_or(""); - out.write(param.to_lowercase().as_ref())?; - Ok(()) -} - -fn helper_upper_case( - h: &Helper<'_, '_>, - _: &Handlebars<'_>, - _: &Context, - _: &mut RenderContext<'_, '_>, - out: &mut dyn Output, -) -> HelperResult { - // get parameter from helper or throw an error - let param = h.param(0).and_then(|v| v.value().as_str()).unwrap_or(""); - out.write(param.to_uppercase().as_ref())?; - Ok(()) -} - -fn helper_camel_case( - h: &Helper<'_, '_>, - _: &Handlebars<'_>, - _: &Context, - _: &mut RenderContext<'_, '_>, - out: &mut dyn Output, -) -> HelperResult { - // get parameter from helper or throw an error - let param = h.param(0).and_then(|v| v.value().as_str()).unwrap_or(""); - - out.write(param.to_case(Case::Camel).as_ref())?; - Ok(()) -} - -fn helper_kebab_case( - h: &Helper<'_, '_>, - _: &Handlebars<'_>, - _: &Context, - _: &mut RenderContext<'_, '_>, - out: &mut dyn Output, -) -> HelperResult { - // get parameter from helper or throw an error - let param = h.param(0).and_then(|v| v.value().as_str()).unwrap_or(""); - - out.write(param.to_case(Case::Kebab).as_ref())?; - Ok(()) -} diff --git a/packages/next-swc/crates/modularize_imports/tests/fixture.rs b/packages/next-swc/crates/modularize_imports/tests/fixture.rs deleted file mode 100644 index 5e5c0dbbb5768..0000000000000 --- a/packages/next-swc/crates/modularize_imports/tests/fixture.rs +++ /dev/null @@ -1,68 +0,0 @@ -use std::path::PathBuf; - -use modularize_imports::{modularize_imports, PackageConfig}; -use swc_core::{ - ecma::parser::{EsConfig, Syntax}, - ecma::transforms::testing::{test_fixture, FixtureTestConfig}, -}; -use testing::fixture; - -fn syntax() -> Syntax { - Syntax::Es(EsConfig { - jsx: true, - ..Default::default() - }) -} - -#[fixture("tests/fixture/**/input.js")] -fn modularize_imports_fixture(input: PathBuf) { - let output = input.parent().unwrap().join("output.js"); - test_fixture( - syntax(), - &|_tr| { - modularize_imports(modularize_imports::Config { - packages: vec![ - ( - "react-bootstrap".to_string(), - PackageConfig { - transform: "react-bootstrap/lib/{{member}}".into(), - prevent_full_import: false, - skip_default_conversion: false, - }, - ), - ( - "my-library/?(((\\w*)?/?)*)".to_string(), - PackageConfig { - transform: "my-library/{{ matches.[1] }}/{{member}}".into(), - prevent_full_import: false, - skip_default_conversion: false, - }, - ), - ( - "my-library-2".to_string(), - PackageConfig { - transform: "my-library-2/{{ camelCase member }}".into(), - prevent_full_import: false, - skip_default_conversion: true, - }, - ), - ( - "my-library-3".to_string(), - PackageConfig { - transform: "my-library-3/{{ kebabCase member }}".into(), - prevent_full_import: false, - skip_default_conversion: true, - }, - ), - ] - .into_iter() - .collect(), - }) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} diff --git a/packages/next-swc/crates/modularize_imports/tests/fixture/regex/input.js b/packages/next-swc/crates/modularize_imports/tests/fixture/regex/input.js deleted file mode 100644 index 679eeeb2ddcf5..0000000000000 --- a/packages/next-swc/crates/modularize_imports/tests/fixture/regex/input.js +++ /dev/null @@ -1,3 +0,0 @@ -import { MyModule } from 'my-library'; -import { App } from 'my-library/components'; -import { Header, Footer } from 'my-library/components/App'; diff --git a/packages/next-swc/crates/modularize_imports/tests/fixture/regex/output.js b/packages/next-swc/crates/modularize_imports/tests/fixture/regex/output.js deleted file mode 100644 index d25be0a11cd58..0000000000000 --- a/packages/next-swc/crates/modularize_imports/tests/fixture/regex/output.js +++ /dev/null @@ -1,4 +0,0 @@ -import MyModule from "my-library/MyModule"; -import App from "my-library/components/App"; -import Header from "my-library/components/App/Header"; -import Footer from "my-library/components/App/Footer"; diff --git a/packages/next-swc/crates/modularize_imports/tests/fixture/simple/input.js b/packages/next-swc/crates/modularize_imports/tests/fixture/simple/input.js deleted file mode 100644 index 5b6c7a587c69b..0000000000000 --- a/packages/next-swc/crates/modularize_imports/tests/fixture/simple/input.js +++ /dev/null @@ -1,3 +0,0 @@ -import { Grid, Row, Col as Col1 } from 'react-bootstrap'; -import { MyModule, Widget } from 'my-library-2'; -import { MyModule } from 'my-library-3'; diff --git a/packages/next-swc/crates/modularize_imports/tests/fixture/simple/output.js b/packages/next-swc/crates/modularize_imports/tests/fixture/simple/output.js deleted file mode 100644 index ba5cdf371405a..0000000000000 --- a/packages/next-swc/crates/modularize_imports/tests/fixture/simple/output.js +++ /dev/null @@ -1,6 +0,0 @@ -import Grid from "react-bootstrap/lib/Grid"; -import Row from "react-bootstrap/lib/Row"; -import Col1 from "react-bootstrap/lib/Col"; -import { MyModule } from "my-library-2/myModule"; -import { Widget } from "my-library-2/widget"; -import { MyModule } from "my-library-3/my-module"; diff --git a/packages/next-swc/crates/napi/Cargo.toml b/packages/next-swc/crates/napi/Cargo.toml index b92541b5b479c..218248e8f8479 100644 --- a/packages/next-swc/crates/napi/Cargo.toml +++ b/packages/next-swc/crates/napi/Cargo.toml @@ -50,7 +50,7 @@ swc_core = { features = [ "ecma_transforms_typescript", "ecma_utils", "ecma_visit", -], version = "0.39.7" } +], version = "0.40.7" } tracing = { version = "0.1.32", features = ["release_max_level_info"] } tracing-futures = "0.2.5" tracing-subscriber = "0.3.9" diff --git a/packages/next-swc/crates/styled_components/Cargo.toml b/packages/next-swc/crates/styled_components/Cargo.toml deleted file mode 100644 index f889ae6c631e5..0000000000000 --- a/packages/next-swc/crates/styled_components/Cargo.toml +++ /dev/null @@ -1,33 +0,0 @@ -[package] -authors = ["강동윤 "] -description = "AST Transforms for styled-components" -edition = "2018" -include = ["Cargo.toml", "src/**/*.rs"] -license = "Apache-2.0" -name = "styled_components" -repository = "https://github.com/vercel/next.js.git" -version = "0.45.0" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -Inflector = "0.11.4" -once_cell = "1.13.0" -regex = {version = "1.5.4", features = ["std", "perf"], default-features = false} -serde = {version = "1.0.130", features = ["derive"]} -tracing = "0.1.32" -swc_core = { features = [ - "common", - "ecma_ast", - "ecma_utils", - "ecma_visit" -], version = "0.39.7" } - -[dev-dependencies] -serde_json = "1" -testing = "0.31.9" -swc_core = { features = [ - "ecma_parser", - "ecma_transforms", - "testing_transform" -], version = "0.39.7" } diff --git a/packages/next-swc/crates/styled_components/src/css.rs b/packages/next-swc/crates/styled_components/src/css.rs deleted file mode 100644 index 8b137891791fe..0000000000000 --- a/packages/next-swc/crates/styled_components/src/css.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/next-swc/crates/styled_components/src/lib.rs b/packages/next-swc/crates/styled_components/src/lib.rs deleted file mode 100644 index 975841f84ec3e..0000000000000 --- a/packages/next-swc/crates/styled_components/src/lib.rs +++ /dev/null @@ -1,91 +0,0 @@ -#![deny(unused)] - -pub use crate::{ - utils::{analyze, analyzer, State}, - visitors::{ - display_name_and_id::display_name_and_id, transpile_css_prop::transpile::transpile_css_prop, - }, -}; -use serde::Deserialize; -use std::{cell::RefCell, rc::Rc}; -use swc_core::{ - common::{chain, pass::Optional, FileName}, - ecma::atoms::JsWord, - ecma::visit::{Fold, VisitMut}, -}; - -mod css; -mod utils; -mod visitors; - -#[derive(Debug, Default, Clone, Deserialize)] -#[serde(rename_all = "camelCase", deny_unknown_fields)] -pub struct Config { - #[serde(default = "true_by_default")] - pub display_name: bool, - - #[serde(default = "true_by_default")] - pub ssr: bool, - - #[serde(default = "true_by_default")] - pub file_name: bool, - - #[serde(default = "default_index_file_name")] - pub meaningless_file_names: Vec, - - #[serde(default)] - pub namespace: String, - - #[serde(default)] - pub top_level_import_paths: Vec, - - #[serde(default)] - pub transpile_template_literals: bool, - - #[serde(default)] - pub minify: bool, - - #[serde(default)] - pub pure: bool, - - #[serde(default = "true_by_default")] - pub css_prop: bool, -} - -fn true_by_default() -> bool { - true -} - -fn default_index_file_name() -> Vec { - vec!["index".to_string()] -} - -impl Config { - pub(crate) fn use_namespace(&self) -> String { - if self.namespace.is_empty() { - return String::new(); - } - format!("{}__", self.namespace) - } -} - -/// NOTE: **This is not complete**. -/// -/// Only [analyzer] and [display_name_and_id] is implemented. -pub fn styled_components( - file_name: FileName, - src_file_hash: u128, - config: Config, -) -> impl Fold + VisitMut { - let state: Rc> = Default::default(); - let config = Rc::new(config); - - chain!( - analyzer(config.clone(), state.clone()), - Optional { - enabled: config.css_prop, - visitor: transpile_css_prop(state.clone()) - }, - display_name_and_id(file_name, src_file_hash, config.clone(), state) - ) -} diff --git a/packages/next-swc/crates/styled_components/src/utils/analyzer.rs b/packages/next-swc/crates/styled_components/src/utils/analyzer.rs deleted file mode 100644 index 47adc9970ff71..0000000000000 --- a/packages/next-swc/crates/styled_components/src/utils/analyzer.rs +++ /dev/null @@ -1,131 +0,0 @@ -use super::State; -use crate::Config; -use std::{cell::RefCell, rc::Rc}; -use swc_core::{ - ecma::ast::*, - ecma::visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitWith, - }, -}; - -pub fn analyzer(config: Rc, state: Rc>) -> impl VisitMut + Fold { - as_folder(AsAnalyzer { config, state }) -} - -struct AsAnalyzer { - config: Rc, - state: Rc>, -} - -impl VisitMut for AsAnalyzer { - noop_visit_mut_type!(); - - fn visit_mut_module(&mut self, p: &mut Module) { - let mut v = Analyzer { - config: &self.config, - state: &mut self.state.borrow_mut(), - }; - - p.visit_with(&mut v); - } - - fn visit_mut_script(&mut self, p: &mut Script) { - let mut v = Analyzer { - config: &self.config, - state: &mut self.state.borrow_mut(), - }; - - p.visit_with(&mut v); - } -} - -pub fn analyze(config: &Config, program: &Program) -> State { - let mut state = State::default(); - - let mut v = Analyzer { - config, - state: &mut state, - }; - - program.visit_with(&mut v); - - state -} - -struct Analyzer<'a> { - config: &'a Config, - state: &'a mut State, -} - -impl Visit for Analyzer<'_> { - noop_visit_type!(); - - fn visit_var_declarator(&mut self, v: &VarDeclarator) { - v.visit_children_with(self); - - if let ( - Pat::Ident(name), - Some(Expr::Call(CallExpr { - callee: Callee::Expr(callee), - args, - .. - })), - ) = (&v.name, v.init.as_deref()) - { - if let Expr::Ident(callee) = &**callee { - if &*callee.sym == "require" && args.len() == 1 && args[0].spread.is_none() { - if let Expr::Lit(Lit::Str(v)) = &*args[0].expr { - let is_styled = if self.config.top_level_import_paths.is_empty() { - &*v.value == "styled-components" - || v.value.starts_with("styled-components/") - } else { - self.config.top_level_import_paths.contains(&v.value) - }; - - if is_styled { - self.state.styled_required = Some(name.id.to_id()); - self.state.unresolved_ctxt = Some(callee.span.ctxt); - } - } - } - } - } - } - - fn visit_import_decl(&mut self, i: &ImportDecl) { - let is_custom = !self.config.top_level_import_paths.is_empty(); - - let is_styled = if self.config.top_level_import_paths.is_empty() { - &*i.src.value == "styled-components" || i.src.value.starts_with("styled-components/") - } else { - self.config.top_level_import_paths.contains(&i.src.value) - }; - - if is_styled { - for s in &i.specifiers { - match s { - ImportSpecifier::Named(s) => { - if is_custom - && s.imported - .as_ref() - .map(|v| match v { - ModuleExportName::Ident(v) => &*v.sym, - ModuleExportName::Str(v) => &*v.value, - }) - .unwrap_or(&*s.local.sym) - == "styled" - { - self.state.imported_local_name = Some(s.local.to_id()); - } - } - ImportSpecifier::Default(s) => { - self.state.imported_local_name = Some(s.local.to_id()); - } - ImportSpecifier::Namespace(s) => { - self.state.imported_local_ns = Some(s.local.to_id()); - } - } - } - } - } -} diff --git a/packages/next-swc/crates/styled_components/src/utils/mod.rs b/packages/next-swc/crates/styled_components/src/utils/mod.rs deleted file mode 100644 index cdf498dbc88ce..0000000000000 --- a/packages/next-swc/crates/styled_components/src/utils/mod.rs +++ /dev/null @@ -1,324 +0,0 @@ -pub use self::analyzer::{analyze, analyzer}; -use std::{borrow::Cow, cell::RefCell}; -use swc_core::{ - common::{collections::AHashMap, SyntaxContext}, - ecma::ast::*, - ecma::atoms::js_word, -}; - -mod analyzer; - -pub(crate) fn get_prop_key_as_expr(p: &Prop) -> Cow { - match p { - Prop::Shorthand(p) => Cow::Owned(Expr::Ident(p.clone())), - Prop::KeyValue(p) => prop_name_to_expr(&p.key), - Prop::Assign(p) => Cow::Owned(Expr::Ident(p.key.clone())), - Prop::Getter(p) => prop_name_to_expr(&p.key), - Prop::Setter(p) => prop_name_to_expr(&p.key), - Prop::Method(p) => prop_name_to_expr(&p.key), - } -} - -pub(crate) fn prop_name_to_expr(p: &PropName) -> Cow { - match p { - PropName::Ident(p) => Cow::Owned(Expr::Ident(p.clone())), - PropName::Str(p) => Cow::Owned(Expr::Lit(Lit::Str(p.clone()))), - PropName::Num(p) => Cow::Owned(Expr::Lit(Lit::Num(p.clone()))), - PropName::BigInt(p) => Cow::Owned(Expr::Lit(Lit::BigInt(p.clone()))), - PropName::Computed(e) => Cow::Borrowed(&e.expr), - } -} - -pub(crate) fn get_prop_name(p: &Prop) -> Option<&PropName> { - match p { - Prop::Shorthand(..) => None, - Prop::KeyValue(p) => Some(&p.key), - Prop::Assign(..) => None, - Prop::Getter(p) => Some(&p.key), - Prop::Setter(p) => Some(&p.key), - Prop::Method(p) => Some(&p.key), - } -} - -pub(crate) fn get_prop_name2(p: &Prop) -> PropName { - match p { - Prop::Shorthand(ident) => PropName::Ident(ident.clone()), - Prop::KeyValue(p) => p.key.clone(), - Prop::Assign(x) => PropName::Ident(x.key.clone()), - Prop::Getter(p) => p.key.clone(), - Prop::Setter(p) => p.key.clone(), - Prop::Method(p) => p.key.clone(), - } -} - -/// This is created once per file. -#[derive(Debug, Default)] -pub struct State { - pub(crate) styled_required: Option, - - unresolved_ctxt: Option, - - imported_local_name: Option, - /// Namespace imports - imported_local_ns: Option, - import_name_cache: RefCell>, -} - -impl State { - pub(crate) fn is_styled(&self, tag: &Expr) -> bool { - if let Expr::Call(CallExpr { - callee: Callee::Expr(callee), - .. - }) = tag - { - if let Expr::Member(MemberExpr { - obj, - prop: MemberProp::Ident(prop), - .. - }) = &**callee - { - if prop.sym != js_word!("default") { - return self.is_styled(obj); - } - } - } - - match tag { - Expr::Member(MemberExpr { - obj, - prop: MemberProp::Ident(prop), - .. - }) => { - if let Expr::Ident(obj) = &**obj { - if Some(obj.to_id()) == self.import_local_name("default", Some(obj)) - && !self.is_helper(&Expr::Ident(prop.clone())) - { - return true; - } - } - } - - Expr::Call(CallExpr { - callee: Callee::Expr(callee), - .. - }) => { - if let Expr::Ident(callee) = &**callee { - if Some(callee.to_id()) == self.import_local_name("default", Some(callee)) { - return true; - } - } - } - - _ => {} - } - - // styled-components might be imported using a require() - if let Some(style_required) = self.styled_required.clone() { - match tag { - Expr::Member(MemberExpr { - obj, - prop: MemberProp::Ident(..), - .. - }) => { - if let Expr::Member(MemberExpr { - obj: obj_of_obj, - prop: MemberProp::Ident(prop), - .. - }) = &**obj - { - if let Expr::Ident(obj_of_obj) = &**obj_of_obj { - if prop.sym == js_word!("default") - && obj_of_obj.to_id() == style_required - { - return true; - } - } - } - } - - Expr::Call(CallExpr { - callee: Callee::Expr(callee), - .. - }) => { - if let Expr::Member(MemberExpr { - obj: tag_callee_object, - prop: MemberProp::Ident(tag_callee_property), - .. - }) = &**callee - { - if let Expr::Ident(tag_callee_object) = &**tag_callee_object { - if tag_callee_property.sym == js_word!("default") - && tag_callee_object.to_id() == style_required - { - return true; - } - } - } - } - - _ => {} - } - } - - if let Some(import_local_name) = self.import_local_name("default", None) { - match tag { - Expr::Member(MemberExpr { - obj, - prop: MemberProp::Ident(..), - .. - }) => { - if let Expr::Member(MemberExpr { - obj: obj_of_obj, - prop: MemberProp::Ident(prop), - .. - }) = &**obj - { - if let Expr::Ident(obj_of_obj) = &**obj_of_obj { - if prop.sym == js_word!("default") - && obj_of_obj.to_id() == import_local_name - { - return true; - } - } - } - } - - Expr::Call(CallExpr { - callee: Callee::Expr(callee), - .. - }) => { - if let Expr::Member(MemberExpr { - obj: tag_callee_object, - prop: MemberProp::Ident(tag_callee_property), - .. - }) = &**callee - { - if let Expr::Ident(tag_callee_object) = &**tag_callee_object { - if tag_callee_property.sym == js_word!("default") - && tag_callee_object.to_id() == import_local_name - { - return true; - } - } - } - } - - _ => {} - } - } - - false - } - - pub(crate) fn import_local_name( - &self, - name: &str, - cache_identifier: Option<&Ident>, - ) -> Option { - if name == "default" { - if let Some(cached) = self.imported_local_name.clone() { - return Some(cached); - } - if let Some(cached) = self.imported_local_ns.clone() { - return Some(cached); - } - } - - if let Some(..) = self.imported_local_ns { - return Some((name.into(), Default::default())); - } - - let cache_key = cache_identifier.map(|i| i.to_id()).unwrap_or_default(); - - let ctxt = self.unresolved_ctxt.unwrap_or_default(); - - let local_name = if self.styled_required.is_some() { - Some(if name == "default" { - "styled".into() - } else { - name.into() - }) - } else { - None - }; - - if let Some(cached) = self.import_name_cache.borrow().get(&cache_key) { - return Some(cached.clone()); - } - - let name = local_name.map(|word| (word, ctxt)); - - if let Some(name) = name.clone() { - self.import_name_cache.borrow_mut().insert(cache_key, name); - } - - name - } - - pub(crate) fn set_import_name(&mut self, id: Id) { - self.imported_local_name = Some(id); - } - - fn is_helper(&self, e: &Expr) -> bool { - self.is_create_global_style_helper(e) - || self.is_css_helper(e) - || self.is_inject_global_helper(e) - || self.is_use_theme(e) - || self.is_keyframes_helper(e) - || self.is_with_theme_helper(e) - } - - fn is_css_helper(&self, e: &Expr) -> bool { - match e { - Expr::Ident(e) => Some(e.to_id()) == self.import_local_name("css", None), - _ => false, - } - } - - fn is_create_global_style_helper(&self, e: &Expr) -> bool { - match e { - Expr::Ident(e) => Some(e.to_id()) == self.import_local_name("createGlobalStyle", None), - _ => false, - } - } - - fn is_inject_global_helper(&self, e: &Expr) -> bool { - match e { - Expr::Ident(e) => Some(e.to_id()) == self.import_local_name("injectGlobal", None), - _ => false, - } - } - - fn is_keyframes_helper(&self, e: &Expr) -> bool { - match e { - Expr::Ident(e) => Some(e.to_id()) == self.import_local_name("keyframes", None), - _ => false, - } - } - - fn is_with_theme_helper(&self, e: &Expr) -> bool { - match e { - Expr::Ident(e) => Some(e.to_id()) == self.import_local_name("withTheme", None), - _ => false, - } - } - - fn is_use_theme(&self, e: &Expr) -> bool { - match e { - Expr::Ident(e) => Some(e.to_id()) == self.import_local_name("useTheme", None), - _ => false, - } - } -} - -pub fn prefix_leading_digit(s: &str) -> Cow { - if s.chars() - .next() - .map(|c| c.is_ascii_digit()) - .unwrap_or(false) - { - Cow::Owned(format!("sc-{}", s)) - } else { - Cow::Borrowed(s) - } -} diff --git a/packages/next-swc/crates/styled_components/src/visitors/assign_style_required.rs b/packages/next-swc/crates/styled_components/src/visitors/assign_style_required.rs deleted file mode 100644 index 8b137891791fe..0000000000000 --- a/packages/next-swc/crates/styled_components/src/visitors/assign_style_required.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/next-swc/crates/styled_components/src/visitors/display_name_and_id.rs b/packages/next-swc/crates/styled_components/src/visitors/display_name_and_id.rs deleted file mode 100644 index 12e3cc15be78b..0000000000000 --- a/packages/next-swc/crates/styled_components/src/visitors/display_name_and_id.rs +++ /dev/null @@ -1,469 +0,0 @@ -use crate::{ - utils::{get_prop_name, prefix_leading_digit, State}, - Config, -}; -use once_cell::sync::Lazy; -use regex::Regex; -use std::{cell::RefCell, convert::TryInto, path::Path, rc::Rc}; -use swc_core::{ - common::{util::take::Take, FileName, DUMMY_SP}, - ecma::ast::*, - ecma::atoms::{js_word, JsWord}, - ecma::utils::{quote_ident, ExprFactory}, - ecma::visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}, -}; -use tracing::{debug, span, trace, Level}; - -pub fn display_name_and_id( - file_name: FileName, - src_file_hash: u128, - config: Rc, - state: Rc>, -) -> impl Fold + VisitMut { - as_folder(DisplayNameAndId { - file_name, - src_file_hash, - - config, - state, - cur_display_name: Default::default(), - component_id: 0, - }) -} - -static DISPLAY_NAME_REGEX: Lazy = - Lazy::new(|| Regex::new(r"^[a-zA-Z][a-zA-Z0-9]$").unwrap()); - -#[derive(Debug)] -struct DisplayNameAndId { - file_name: FileName, - src_file_hash: u128, - - config: Rc, - state: Rc>, - - cur_display_name: Option, - - component_id: usize, -} - -impl DisplayNameAndId { - fn get_block_name(&self, p: &Path) -> String { - match p.file_stem().map(|s| s.to_string_lossy()) { - Some(file_stem) - if !self - .config - .meaningless_file_names - .iter() - .any(|meaningless| file_stem.as_ref() == meaningless) => - { - file_stem.into() - } - _ => self.get_block_name( - p.parent() - .expect("path only contains meaningless filenames (e.g. /index/index)?"), - ), - } - } - - fn get_display_name(&mut self, _: &Expr) -> JsWord { - let component_name = self.cur_display_name.clone().unwrap_or(js_word!("")); - - match &self.file_name { - FileName::Real(f) if self.config.file_name => { - let block_name = self.get_block_name(f); - - if block_name == *component_name { - return component_name; - } - - if component_name.is_empty() { - return prefix_leading_digit(&block_name).into(); - } - - format!("{}__{}", prefix_leading_digit(&block_name), component_name).into() - } - - _ => component_name, - } - } - - fn next_id(&mut self) -> usize { - let ret = self.component_id; - self.component_id += 1; - ret - } - - fn get_component_id(&mut self) -> String { - // Prefix the identifier with a character because CSS classes cannot start with - // a number - - let next_id = self.next_id(); - - let hash = { - let base = self.src_file_hash; - let base = base.to_be_bytes(); - let a = u32::from_be_bytes(base[0..4].try_into().unwrap()); - let b = u32::from_be_bytes(base[4..8].try_into().unwrap()); - let c = u32::from_be_bytes(base[8..12].try_into().unwrap()); - let d = u32::from_be_bytes(base[12..16].try_into().unwrap()); - - a ^ b ^ c ^ d - }; - - format!("{}sc-{:x}-{}", self.config.use_namespace(), hash, next_id) - } - - fn add_config( - &mut self, - e: &mut Expr, - display_name: Option, - component_id: Option, - ) { - if display_name.is_none() && component_id.is_none() { - return; - } - - let mut with_config_props = vec![]; - - if let Some(display_name) = display_name { - with_config_props.push(PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { - key: PropName::Ident(quote_ident!("displayName")), - value: Box::new(Expr::Lit(Lit::Str(Str { - span: DUMMY_SP, - value: display_name, - raw: None, - }))), - })))) - } - - if let Some(component_id) = component_id { - with_config_props.push(PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { - key: PropName::Ident(quote_ident!("componentId")), - value: Box::new(Expr::Lit(Lit::Str(Str { - span: DUMMY_SP, - value: component_id, - raw: None, - }))), - })))) - } - - get_existing_config(e, |e| { - if let Expr::Call(CallExpr { args, .. }) = e { - if let Some(Expr::Object(existing_config)) = args.get_mut(0).map(|v| &mut *v.expr) { - if !already_has(existing_config) { - existing_config.props.extend(with_config_props.take()); - } - } - } - }); - - if with_config_props.is_empty() { - return; - } - - if let Expr::Call(CallExpr { - callee: Callee::Expr(callee), - args, - .. - }) = e - { - if let Expr::Member(MemberExpr { - prop: MemberProp::Ident(prop), - .. - }) = &**callee - { - if &*prop.sym == "withConfig" { - if let Some(first_arg) = args.get_mut(0) { - if first_arg.spread.is_none() && first_arg.expr.is_object() { - if let Expr::Object(obj) = &mut *first_arg.expr { - if !already_has(&*obj) { - obj.props.extend(with_config_props); - return; - } - } - } - } - } - } - } - - if let Expr::TaggedTpl(e) = e { - e.tag = Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: e - .tag - .take() - .make_member(quote_ident!("withConfig")) - .as_callee(), - args: vec![ObjectLit { - span: DUMMY_SP, - props: with_config_props, - } - .as_arg()], - type_args: Default::default(), - })); - return; - } - - if let Expr::Call(CallExpr { - callee: Callee::Expr(callee), - .. - }) = e - { - *callee = Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: callee - .take() - .make_member(quote_ident!("withConfig")) - .as_callee(), - args: vec![ObjectLit { - span: DUMMY_SP, - props: with_config_props, - } - .as_arg()], - type_args: Default::default(), - })); - return; - } - - unreachable!("expr should be tagged tpl or call expr"); - } -} - -impl VisitMut for DisplayNameAndId { - noop_visit_mut_type!(); - - fn visit_mut_assign_expr(&mut self, e: &mut AssignExpr) { - let old = self.cur_display_name.clone(); - - if old.is_none() { - self.cur_display_name = e.left.as_ident().map(|v| v.sym.clone()); - } - - e.visit_mut_children_with(self); - - self.cur_display_name = old; - } - - fn visit_mut_class_prop(&mut self, e: &mut ClassProp) { - let old = self.cur_display_name.take(); - - if let PropName::Ident(i) = &e.key { - self.cur_display_name = Some(i.sym.clone()); - } - - e.visit_mut_children_with(self); - - self.cur_display_name = old; - } - - fn visit_mut_expr(&mut self, expr: &mut Expr) { - expr.visit_mut_children_with(self); - - let is_styled = match expr { - Expr::TaggedTpl(e) => self.state.borrow().is_styled(&e.tag), - - Expr::Call(CallExpr { - callee: Callee::Expr(callee), - args, - .. - }) => { - ( - // styled() - self.state.borrow().is_styled(&*callee) - && get_property_as_ident(callee) - .map(|v| v == "withConfig") - .unwrap_or(false) - ) || ( - // styled(x)({}) - self.state.borrow().is_styled(&*callee) - && !get_callee(callee) - .map(|callee| callee.is_member()) - .unwrap_or(false) - ) || ( - // styled(x).attrs()({}) - self.state.borrow().is_styled(callee) - && get_callee(callee) - .map(|callee| { - callee.is_member() - && get_property_as_ident(callee) - .map(|v| v == "withConfig") - .unwrap_or(false) - }) - .unwrap_or(false) - ) || ( - // styled(x).withConfig({}) - self.state.borrow().is_styled(&*callee) - && get_callee(callee) - .map(|callee| { - callee.is_member() - && get_property_as_ident(callee) - .map(|v| v == "withConfig") - .unwrap_or(false) - && !args.is_empty() - && args[0].spread.is_none() - && match &*args[0].expr { - Expr::Object(first_arg) => { - !first_arg.props.iter().any(|prop| match prop { - PropOrSpread::Prop(prop) => { - match get_prop_name(prop) { - Some(PropName::Ident(prop_name)) => { - matches!( - &*prop_name.sym, - "componentId" | "displayName" - ) - } - _ => false, - } - } - _ => false, - }) - } - _ => false, - } - }) - .unwrap_or(false) - ) - } - - _ => false, - }; - - if !is_styled { - return; - } - debug!("Found styled component"); - - let _tracing = if cfg!(debug_assertions) { - Some(span!(Level::ERROR, "display_name_and_id").entered()) - } else { - None - }; - - let display_name = self - .config - .display_name - .then(|| self.get_display_name(expr)); - trace!("display_name: {:?}", display_name); - - let component_id = self.config.ssr.then(|| self.get_component_id().into()); - trace!("component_id: {:?}", display_name); - - self.add_config( - expr, - display_name.map(|s| DISPLAY_NAME_REGEX.replace_all(&s, "").into()), - component_id, - ) - } - - fn visit_mut_key_value_prop(&mut self, e: &mut KeyValueProp) { - let old = self.cur_display_name.take(); - - if let PropName::Ident(name) = &e.key { - self.cur_display_name = Some(name.sym.clone()); - } - - e.visit_mut_children_with(self); - - self.cur_display_name = old; - } - - fn visit_mut_var_declarator(&mut self, v: &mut VarDeclarator) { - let old = self.cur_display_name.take(); - - if let Pat::Ident(name) = &v.name { - self.cur_display_name = Some(name.id.sym.clone()); - } - - v.visit_mut_children_with(self); - - self.cur_display_name = old; - } -} - -fn get_callee(e: &Expr) -> Option<&Expr> { - match e { - Expr::Call(CallExpr { - callee: Callee::Expr(callee), - .. - }) => Some(callee), - _ => None, - } -} - -fn get_property_as_ident(e: &Expr) -> Option<&JsWord> { - if let Expr::Member(MemberExpr { - prop: MemberProp::Ident(p), - .. - }) = e - { - return Some(&p.sym); - } - - None -} - -fn already_has(obj: &ObjectLit) -> bool { - obj.props - .iter() - .filter_map(|v| match v { - PropOrSpread::Prop(p) => Some(p), - _ => None, - }) - .filter_map(|v| get_prop_name(v)) - .any(|prop| match prop { - PropName::Ident(ident) => &*ident.sym == "componentId" || &*ident.sym == "displayName", - _ => false, - }) -} - -fn get_existing_config(e: &mut Expr, op: F) -where - F: FnOnce(&mut Expr), -{ - if let Expr::Call(CallExpr { - callee: Callee::Expr(callee), - .. - }) = e - { - if let Expr::Call(CallExpr { - callee: Callee::Expr(callee_callee), - .. - }) = &mut **callee - { - if let Expr::Member(MemberExpr { - prop: MemberProp::Ident(prop), - .. - }) = &**callee_callee - { - if &*prop.sym == "withConfig" { - return op(callee); - } - } - - if let Expr::Member(MemberExpr { - obj, - prop: MemberProp::Ident(..), - .. - }) = &mut **callee_callee - { - if let Expr::Call(CallExpr { - callee: Callee::Expr(callee), - .. - }) = &**obj - { - if let Expr::Member(MemberExpr { - prop: MemberProp::Ident(prop), - .. - }) = &**callee - { - if &*prop.sym == "withConfig" { - op(obj) - } - } - } - } - } - } -} diff --git a/packages/next-swc/crates/styled_components/src/visitors/minify.rs b/packages/next-swc/crates/styled_components/src/visitors/minify.rs deleted file mode 100644 index 8b137891791fe..0000000000000 --- a/packages/next-swc/crates/styled_components/src/visitors/minify.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/next-swc/crates/styled_components/src/visitors/mod.rs b/packages/next-swc/crates/styled_components/src/visitors/mod.rs deleted file mode 100644 index bf55f0e4cab8e..0000000000000 --- a/packages/next-swc/crates/styled_components/src/visitors/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod assign_style_required; -pub mod display_name_and_id; -pub mod minify; -pub mod transpile_css_prop; diff --git a/packages/next-swc/crates/styled_components/src/visitors/transpile_css_prop/mod.rs b/packages/next-swc/crates/styled_components/src/visitors/transpile_css_prop/mod.rs deleted file mode 100644 index 740abc0a7e03a..0000000000000 --- a/packages/next-swc/crates/styled_components/src/visitors/transpile_css_prop/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod top_level_binding_collector; -pub mod transpile; diff --git a/packages/next-swc/crates/styled_components/src/visitors/transpile_css_prop/top_level_binding_collector.rs b/packages/next-swc/crates/styled_components/src/visitors/transpile_css_prop/top_level_binding_collector.rs deleted file mode 100644 index 78cbf49996d9e..0000000000000 --- a/packages/next-swc/crates/styled_components/src/visitors/transpile_css_prop/top_level_binding_collector.rs +++ /dev/null @@ -1,93 +0,0 @@ -use swc_core::{ - common::collections::AHashSet, - ecma::ast::{ - ArrowExpr, ClassDecl, FnDecl, Function, Id, ImportDefaultSpecifier, ImportNamedSpecifier, - ImportStarAsSpecifier, ObjectPatProp, Pat, VarDeclarator, - }, - ecma::visit::{noop_visit_type, Visit, VisitWith}, -}; - -// Modified from swc_ecma_utils/src/lib.rs:BindingCollector. -pub struct TopLevelBindingCollector { - bindings: AHashSet, - in_pat_decl: bool, -} - -impl TopLevelBindingCollector { - fn add(&mut self, i: &Id) { - self.bindings.insert(i.clone()); - } -} - -impl Visit for TopLevelBindingCollector { - noop_visit_type!(); - - fn visit_class_decl(&mut self, node: &ClassDecl) { - self.add(&node.ident.to_id()); - } - - fn visit_fn_decl(&mut self, node: &FnDecl) { - self.add(&node.ident.to_id()); - } - - fn visit_pat(&mut self, node: &Pat) { - if !self.in_pat_decl { - return; - } - match node { - Pat::Ident(i) => self.add(&i.id.to_id()), - Pat::Object(o) => { - for prop in o.props.iter() { - match prop { - ObjectPatProp::Assign(a) => self.add(&a.key.to_id()), - ObjectPatProp::KeyValue(k) => k.value.visit_with(self), - ObjectPatProp::Rest(_) => {} - } - } - } - Pat::Array(a) => { - for elem in a.elems.iter() { - elem.visit_with(self); - } - } - Pat::Assign(a) => { - a.left.visit_with(self); - } - _ => {} - } - } - - fn visit_arrow_expr(&mut self, _: &ArrowExpr) {} - fn visit_function(&mut self, _: &Function) {} - - fn visit_import_default_specifier(&mut self, node: &ImportDefaultSpecifier) { - self.add(&node.local.to_id()); - } - - fn visit_import_named_specifier(&mut self, node: &ImportNamedSpecifier) { - self.add(&node.local.to_id()); - } - - fn visit_import_star_as_specifier(&mut self, node: &ImportStarAsSpecifier) { - self.add(&node.local.to_id()); - } - - fn visit_var_declarator(&mut self, node: &VarDeclarator) { - let old = self.in_pat_decl; - self.in_pat_decl = true; - node.name.visit_with(self); - self.in_pat_decl = old; - } -} - -pub fn collect_top_level_decls(n: &N) -> AHashSet -where - N: VisitWith, -{ - let mut v = TopLevelBindingCollector { - bindings: Default::default(), - in_pat_decl: false, - }; - n.visit_with(&mut v); - v.bindings -} diff --git a/packages/next-swc/crates/styled_components/src/visitors/transpile_css_prop/transpile.rs b/packages/next-swc/crates/styled_components/src/visitors/transpile_css_prop/transpile.rs deleted file mode 100644 index 8ad2a45d1a8fc..0000000000000 --- a/packages/next-swc/crates/styled_components/src/visitors/transpile_css_prop/transpile.rs +++ /dev/null @@ -1,653 +0,0 @@ -//! Port of https://github.com/styled-components/babel-plugin-styled-components/blob/a20c3033508677695953e7a434de4746168eeb4e/src/visitors/transpileCssProp.js - -use std::cell::RefCell; -use std::rc::Rc; -use std::{borrow::Cow, collections::HashMap}; - -use crate::State; -use inflector::Inflector; -use once_cell::sync::Lazy; -use regex::Regex; -use swc_core::{ - common::{ - collections::{AHashMap, AHashSet}, - util::take::Take, - Spanned, DUMMY_SP, - }, - ecma::ast::*, - ecma::atoms::{js_word, JsWord}, - ecma::utils::{prepend_stmt, private_ident, quote_ident, ExprFactory}, - ecma::visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}, -}; - -use crate::utils::{get_prop_key_as_expr, get_prop_name, get_prop_name2}; - -use super::top_level_binding_collector::collect_top_level_decls; - -static TAG_NAME_REGEX: Lazy = - Lazy::new(|| Regex::new("^[a-z][a-z\\d]*(\\-[a-z][a-z\\d]*)?$").unwrap()); - -pub fn transpile_css_prop(state: Rc>) -> impl Fold + VisitMut { - as_folder(TranspileCssProp { - state, - ..Default::default() - }) -} - -#[derive(Default)] -struct TranspileCssProp { - state: Rc>, - - import_name: Option, - injected_nodes: Vec, - interleaved_injections: AHashMap>, - - identifier_idx: usize, - styled_idx: HashMap, - top_level_decls: Option>, -} - -impl TranspileCssProp { - fn next_styled_idx(&mut self, key: JsWord) -> usize { - let idx = self.styled_idx.entry(key).or_insert(0); - *idx += 1; - *idx - } - #[allow(clippy::wrong_self_convention)] - fn is_top_level_ident(&mut self, ident: &Ident) -> bool { - self.top_level_decls - .as_ref() - .map(|decls| decls.contains(&ident.to_id())) - .unwrap_or(false) - } -} - -impl VisitMut for TranspileCssProp { - noop_visit_mut_type!(); - - fn visit_mut_jsx_element(&mut self, elem: &mut JSXElement) { - elem.visit_mut_children_with(self); - - let mut extra_attrs = vec![]; - - for attr in elem.opening.attrs.iter_mut() { - match &mut *attr { - JSXAttrOrSpread::JSXAttr(attr) => { - if !matches!(&attr.name, JSXAttrName::Ident(i) if &*i.sym == "css") { - continue; - } - - let import_name = if let Some(ident) = self - .state - .borrow() - .import_local_name("default", None) - .map(Ident::from) - { - ident - } else { - self.import_name - .get_or_insert_with(|| private_ident!("_styled")) - .clone() - }; - - let name = get_name_ident(&elem.opening.name); - let id_sym = name.sym.to_class_case(); - - // Match the original plugin's behavior. - let id_sym = id_sym.trim_end_matches(char::is_numeric); - - let id_sym = JsWord::from(id_sym); - let styled_idx = self.next_styled_idx(id_sym.clone()); - let id = quote_ident!( - elem.opening.name.span(), - append_if_gt_one(&format!("_Styled{}", id_sym), styled_idx) - ); - - let (styled, inject_after) = if TAG_NAME_REGEX.is_match(&name.sym) { - ( - (Expr::Call(CallExpr { - span: DUMMY_SP, - callee: import_name.as_callee(), - args: vec![Lit::Str(Str { - span: DUMMY_SP, - value: name.sym, - raw: None, - }) - .as_arg()], - type_args: Default::default(), - })), - None::, - ) - } else { - let name_expr = get_name_expr(&elem.opening.name); - - ( - Expr::Call(CallExpr { - span: DUMMY_SP, - callee: import_name.as_callee(), - args: vec![name_expr.as_arg()], - type_args: Default::default(), - }), - if self.is_top_level_ident(&name) { - Some(name) - } else { - None - }, - ) - }; - - let mut css = match &mut attr.value { - Some(css) => { - // - - match css { - JSXAttrValue::Lit(Lit::Str(v)) => Expr::Tpl(Tpl { - span: DUMMY_SP, - exprs: Default::default(), - quasis: vec![TplElement { - span: DUMMY_SP, - tail: true, - cooked: None, - raw: (&*v.value).into(), - }], - }), - JSXAttrValue::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(v), - .. - }) => match &mut **v { - Expr::Tpl(..) => *v.take(), - Expr::TaggedTpl(v) - if match &*v.tag { - Expr::Ident(i) => &*i.sym == "css", - _ => false, - } => - { - Expr::Tpl(v.tpl.take()) - } - Expr::Object(..) => *v.take(), - _ => Expr::Tpl(Tpl { - span: DUMMY_SP, - exprs: vec![v.take()], - quasis: vec![ - TplElement { - span: DUMMY_SP, - tail: false, - cooked: None, - raw: "".into(), - }, - TplElement { - span: DUMMY_SP, - tail: true, - cooked: None, - raw: "".into(), - }, - ], - }), - }, - - _ => continue, - } - } - None => continue, - }; - - // Remove this attribute - attr.name = JSXAttrName::Ident(Take::dummy()); - - elem.opening.name = JSXElementName::Ident(id.clone()); - - if let Some(closing) = &mut elem.closing { - closing.name = JSXElementName::Ident(id.clone()); - } - - // object syntax - if let Expr::Object(css_obj) = &mut css { - // Original plugin says - // - // - // for objects as CSS props, we have to recurse through the object and - // replace any object key/value scope references with generated props - // similar to how the template literal transform above creates dynamic - // interpolations - let p = quote_ident!("p"); - - let mut reducer = PropertyReducer { - p: p.clone(), - replace_object_with_prop_function: false, - extra_attrs: Default::default(), - identifier_idx: &mut self.identifier_idx, - }; - - css_obj.props = css_obj - .props - .take() - .into_iter() - .fold(vec![], |acc, property| { - reducer.reduce_object_properties(acc, property) - }); - - extra_attrs.extend(reducer.extra_attrs); - - if reducer.replace_object_with_prop_function { - css = Expr::Arrow(ArrowExpr { - span: DUMMY_SP, - params: vec![Pat::Ident(p.clone().into())], - body: BlockStmtOrExpr::Expr(Box::new(css.take())), - is_async: false, - is_generator: false, - type_params: Default::default(), - return_type: Default::default(), - }); - } - } else { - // tagged template literal - let mut tpl = css.expect_tpl(); - - tpl.exprs = - tpl.exprs - .take() - .into_iter() - .fold(vec![], |mut acc, mut expr| { - if expr.is_fn_expr() || expr.is_arrow() { - acc.push(expr); - return acc; - } else if let Some(root) = trace_root_value(&mut expr) { - let direct_access = match root { - Expr::Lit(_) => true, - Expr::Ident(id) if self.is_top_level_ident(id) => true, - _ => false, - }; - if direct_access { - acc.push(expr); - return acc; - } - } - - let identifier = - get_local_identifier(&mut self.identifier_idx, &expr); - let p = quote_ident!("p"); - extra_attrs.push(JSXAttrOrSpread::JSXAttr(JSXAttr { - span: DUMMY_SP, - name: JSXAttrName::Ident(identifier.clone()), - value: Some(JSXAttrValue::JSXExprContainer( - JSXExprContainer { - span: DUMMY_SP, - expr: JSXExpr::Expr(expr.take()), - }, - )), - })); - - acc.push(Box::new(Expr::Arrow(ArrowExpr { - span: DUMMY_SP, - params: vec![Pat::Ident(p.clone().into())], - body: BlockStmtOrExpr::Expr(Box::new( - p.make_member(identifier), - )), - is_async: false, - is_generator: false, - type_params: Default::default(), - return_type: Default::default(), - }))); - - acc - }); - - css = Expr::Tpl(tpl); - } - - let var = VarDeclarator { - span: DUMMY_SP, - name: Pat::Ident(id.clone().into()), - init: Some(match css { - Expr::Object(..) | Expr::Arrow(..) => Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: styled.as_callee(), - args: vec![css.as_arg()], - type_args: Default::default(), - })), - _ => Box::new(Expr::TaggedTpl(TaggedTpl { - span: DUMMY_SP, - tag: Box::new(styled), - type_params: Default::default(), - tpl: css.expect_tpl(), - })), - }), - definite: false, - }; - let stmt = Stmt::Decl(Decl::Var(Box::new(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - declare: false, - decls: vec![var], - }))); - match inject_after { - Some(injector) => { - let id = injector.to_id(); - self.interleaved_injections - .entry(id) - .or_default() - .push(stmt); - } - None => { - self.injected_nodes.push(stmt); - } - } - } - JSXAttrOrSpread::SpreadElement(_) => {} - } - } - - elem.opening.attrs.retain(|attr| { - match attr { - JSXAttrOrSpread::JSXAttr(attr) => { - if matches!( - attr.name, - JSXAttrName::Ident(Ident { - sym: js_word!(""), - .. - }) - ) { - return false; - } - } - JSXAttrOrSpread::SpreadElement(_) => {} - } - true - }); - - elem.opening.attrs.extend(extra_attrs); - } - - fn visit_mut_module(&mut self, n: &mut Module) { - // TODO: Skip if there are no css prop usage - self.top_level_decls = Some(collect_top_level_decls(n)); - n.visit_mut_children_with(self); - self.top_level_decls = None; - - if let Some(import_name) = self.import_name.take() { - self.state.borrow_mut().set_import_name(import_name.to_id()); - let specifier = ImportSpecifier::Default(ImportDefaultSpecifier { - span: DUMMY_SP, - local: import_name, - }); - prepend_stmt( - &mut n.body, - ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { - span: DUMMY_SP, - specifiers: vec![specifier], - src: Box::new(Str { - span: DUMMY_SP, - value: "styled-components".into(), - raw: None, - }), - type_only: Default::default(), - asserts: Default::default(), - })), - ); - } - - let mut serialized_body: Vec = vec![]; - let body = std::mem::take(&mut n.body); - for item in body { - serialized_body.push(item.clone()); - if let ModuleItem::Stmt(Stmt::Decl(Decl::Var(vd))) = &item { - for decl in &vd.decls { - if let Pat::Ident(ident) = &decl.name { - let id = ident.to_id(); - let stmts = self.interleaved_injections.remove(&id); - if let Some(stmts) = stmts { - serialized_body.extend(stmts.into_iter().rev().map(ModuleItem::Stmt)); - } - } - } - } - } - n.body = serialized_body; - - let mut remaining = std::mem::take(&mut self.interleaved_injections) - .into_iter() - .collect::>(); - remaining.sort_by_key(|x| x.0.clone()); - - remaining - .into_iter() - .for_each(|(_, stmts)| n.body.extend(stmts.into_iter().map(ModuleItem::Stmt))); - - n.body - .extend(self.injected_nodes.take().into_iter().map(ModuleItem::Stmt)); - } -} - -fn get_name_expr(name: &JSXElementName) -> Box { - fn get_name_expr_jsx_object(name: &JSXObject) -> Box { - match name { - JSXObject::Ident(n) => Box::new(Expr::Ident(n.clone())), - JSXObject::JSXMemberExpr(n) => Box::new(Expr::Member(MemberExpr { - span: DUMMY_SP, - obj: get_name_expr_jsx_object(&n.obj), - prop: MemberProp::Ident(n.prop.clone()), - })), - } - } - match name { - JSXElementName::Ident(n) => Box::new(Expr::Ident(n.clone())), - JSXElementName::JSXMemberExpr(n) => Box::new(Expr::Member(MemberExpr { - span: DUMMY_SP, - obj: get_name_expr_jsx_object(&n.obj), - prop: MemberProp::Ident(n.prop.clone()), - })), - JSXElementName::JSXNamespacedName(..) => { - unimplemented!("get_name_expr for JSXNamespacedName") - } - } -} - -struct PropertyReducer<'a> { - p: Ident, - replace_object_with_prop_function: bool, - extra_attrs: Vec, - - identifier_idx: &'a mut usize, -} - -impl PropertyReducer<'_> { - fn reduce_object_properties( - &mut self, - mut acc: Vec, - mut property: PropOrSpread, - ) -> Vec { - match property { - PropOrSpread::Spread(ref mut prop) => { - // handle spread variables and such - - if let Expr::Object(arg) = &mut *prop.expr { - arg.props = arg - .props - .take() - .into_iter() - .fold(vec![], |acc, p| self.reduce_object_properties(acc, p)); - } else { - self.replace_object_with_prop_function = true; - - let identifier = get_local_identifier(self.identifier_idx, &prop.expr); - - self.extra_attrs.push(JSXAttrOrSpread::JSXAttr(JSXAttr { - span: DUMMY_SP, - name: JSXAttrName::Ident(identifier.clone()), - value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer { - span: DUMMY_SP, - expr: JSXExpr::Expr(prop.expr.take()), - })), - })); - - prop.expr = Box::new(self.p.clone().make_member(identifier)); - } - - acc.push(property); - } - PropOrSpread::Prop(ref mut prop) => { - let key = get_prop_key_as_expr(prop); - let key_pn = get_prop_name(prop); - - if key.is_member() - || key.is_call() - || (key.is_ident() - && key_pn.is_some() - && key_pn.unwrap().is_computed() - && !matches!(&**prop, Prop::Shorthand(..))) - { - self.replace_object_with_prop_function = true; - - let identifier = get_local_identifier(self.identifier_idx, &key); - - self.extra_attrs.push(JSXAttrOrSpread::JSXAttr(JSXAttr { - span: DUMMY_SP, - name: identifier.clone().into(), - value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer { - span: DUMMY_SP, - // TODO: Perf - expr: JSXExpr::Expr(Box::new(key.clone().into_owned())), - })), - })); - - set_key_of_prop(prop, Box::new(self.p.clone().make_member(identifier))); - } - - let mut value = take_prop_value(prop); - - if let Expr::Object(value_obj) = &mut *value { - value_obj.props = value_obj - .props - .take() - .into_iter() - .fold(vec![], |acc, p| self.reduce_object_properties(acc, p)); - - set_value_of_prop(prop, value); - acc.push(property); - } else if !matches!(&*value, Expr::Lit(..)) { - // if a non-primitive value we have to interpolate it - - self.replace_object_with_prop_function = true; - - let identifier = get_local_identifier(self.identifier_idx, &value); - - self.extra_attrs.push(JSXAttrOrSpread::JSXAttr(JSXAttr { - span: DUMMY_SP, - name: JSXAttrName::Ident(identifier.clone()), - value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer { - span: DUMMY_SP, - expr: JSXExpr::Expr(value.take()), - })), - })); - - let key = get_prop_name2(prop); - - acc.push(PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { - key, - value: Box::new(self.p.clone().make_member(identifier)), - })))); - } else { - set_value_of_prop(prop, value); - acc.push(property); - } - } - } - - acc - } -} - -fn set_value_of_prop(prop: &mut Prop, value: Box) { - match prop { - Prop::Shorthand(p) => { - *prop = Prop::KeyValue(KeyValueProp { - key: PropName::Ident(p.clone()), - value, - }); - } - Prop::KeyValue(p) => { - p.value = value; - } - Prop::Assign(..) => unreachable!("assign property is not allowed for object literals"), - Prop::Getter(_p) => todo!(), - Prop::Setter(_p) => todo!(), - Prop::Method(_p) => todo!(), - } -} - -fn take_prop_value(prop: &mut Prop) -> Box { - match prop { - Prop::Shorthand(p) => Box::new(Expr::Ident(p.clone())), - Prop::KeyValue(p) => p.value.take(), - Prop::Assign(..) => unreachable!("assign property is not allowed for object literals"), - Prop::Getter(_p) => todo!(), - Prop::Setter(_p) => todo!(), - Prop::Method(_p) => todo!(), - } -} - -fn set_key_of_prop(prop: &mut Prop, key: Box) { - let value = take_prop_value(prop); - - *prop = Prop::KeyValue(KeyValueProp { - key: PropName::Computed(ComputedPropName { - span: DUMMY_SP, - expr: key, - }), - value, - }); -} - -fn get_local_identifier(idx: &mut usize, expr: &Expr) -> Ident { - *idx += 1; - - let identifier = quote_ident!(expr.span(), append_if_gt_one("$_css", *idx)); - - // TODO: Unique identifier - - identifier -} - -fn append_if_gt_one(s: &str, suffix: usize) -> Cow { - if suffix > 1 { - Cow::Owned(format!("{}{}", s, suffix)) - } else { - Cow::Borrowed(s) - } -} - -fn get_name_ident(el: &JSXElementName) -> Ident { - match el { - JSXElementName::Ident(v) => v.clone(), - JSXElementName::JSXMemberExpr(e) => Ident { - sym: format!("{}_{}", get_name_of_jsx_obj(&e.obj), e.prop.sym).into(), - span: e.prop.span, - optional: false, - }, - _ => { - unimplemented!("get_name_ident for namespaced jsx element") - } - } -} - -fn get_name_of_jsx_obj(el: &JSXObject) -> JsWord { - match el { - JSXObject::Ident(v) => v.sym.clone(), - JSXObject::JSXMemberExpr(e) => { - format!("{}{}", get_name_of_jsx_obj(&e.obj), e.prop.sym).into() - } - } -} - -fn trace_root_value(e: &mut Expr) -> Option<&mut Expr> { - match e { - Expr::Member(e) => trace_root_value(&mut e.obj), - Expr::Call(e) => match &mut e.callee { - Callee::Expr(e) => trace_root_value(e), - _ => None, - }, - Expr::Ident(_) => Some(e), - Expr::Lit(_) => Some(e), - _ => None, - } -} diff --git a/packages/next-swc/crates/styled_components/tests/fixture.rs b/packages/next-swc/crates/styled_components/tests/fixture.rs deleted file mode 100644 index f2fb43aede468..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixture.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![deny(unused)] - -use std::{fs::read_to_string, path::PathBuf}; -use styled_components::{styled_components, Config}; -use swc_core::{ - common::{chain, Mark}, - ecma::parser::{EsConfig, Syntax}, - ecma::transforms::base::resolver, - ecma::transforms::testing::test_fixture, -}; - -#[testing::fixture("tests/fixtures/**/code.js")] -fn fixture(input: PathBuf) { - let dir = input.parent().unwrap(); - let config = read_to_string(dir.join("config.json")).expect("failed to read config.json"); - println!("---- Config -----\n{}", config); - let config: Config = serde_json::from_str(&config).unwrap(); - - test_fixture( - Syntax::Es(EsConfig { - jsx: true, - ..Default::default() - }), - &|t| { - // - let fm = t.cm.load_file(&input).unwrap(); - - chain!( - resolver(Mark::new(), Mark::new(), false), - styled_components(fm.name.clone(), fm.src_hash, config.clone()) - ) - }, - &input, - &dir.join("output.js"), - Default::default(), - ) -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.allow-chains-of-member-calls/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.allow-chains-of-member-calls/.babelrc deleted file mode 100644 index e9f07f78b2a05..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.allow-chains-of-member-calls/.babelrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "ssr": false, - "fileName": false, - "transpileTemplateLiterals": false - } - ] - ] -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.allow-chains-of-member-calls/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.allow-chains-of-member-calls/code.js deleted file mode 100644 index 70afb5d187828..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.allow-chains-of-member-calls/code.js +++ /dev/null @@ -1,4 +0,0 @@ -import styled from 'styled-components' - -const WithAttrs = styled.div.attrs({ some: 'value' })`` -const WithAttrsWrapped = styled(Inner).attrs({ some: 'value' })`` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.allow-chains-of-member-calls/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.allow-chains-of-member-calls/output.js deleted file mode 100644 index 1800ec79fc3a7..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.allow-chains-of-member-calls/output.js +++ /dev/null @@ -1,11 +0,0 @@ -import styled from 'styled-components'; -const WithAttrs = styled.div.attrs({ - some: 'value' -}).withConfig({ - displayName: "WithAttrs" -})``; -const WithAttrsWrapped = styled(Inner).attrs({ - some: 'value' -}).withConfig({ - displayName: "WithAttrsWrapped" -})``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-create-global-style-with-pure-comments/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-create-global-style-with-pure-comments/.babelrc deleted file mode 100644 index 8232aac0a0177..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-create-global-style-with-pure-comments/.babelrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "pure": true - } - ] - ] -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-create-global-style-with-pure-comments/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-create-global-style-with-pure-comments/code.js deleted file mode 100644 index d246beafe40bb..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-create-global-style-with-pure-comments/code.js +++ /dev/null @@ -1,7 +0,0 @@ -import { createGlobalStyle } from 'styled-components' - -const GlobalStyle = createGlobalStyle` - body { - color: red; - } -` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-create-global-style-with-pure-comments/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-create-global-style-with-pure-comments/output.js deleted file mode 100644 index a067223cd779a..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-create-global-style-with-pure-comments/output.js +++ /dev/null @@ -1,2 +0,0 @@ -import { createGlobalStyle } from 'styled-components'; -const GlobalStyle = /*#__PURE__*/createGlobalStyle(["body{color:red;}"]); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-css-with-pure-comments/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-css-with-pure-comments/.babelrc deleted file mode 100644 index 8232aac0a0177..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-css-with-pure-comments/.babelrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "pure": true - } - ] - ] -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-css-with-pure-comments/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-css-with-pure-comments/code.js deleted file mode 100644 index b4324bd0384a1..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-css-with-pure-comments/code.js +++ /dev/null @@ -1,10 +0,0 @@ -import styled, { css } from 'styled-components' - -const partial = css` - color: red; -` - -const Component = styled.div` - ${partial}; - background: blue; -` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-css-with-pure-comments/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-css-with-pure-comments/output.js deleted file mode 100644 index a2d039574a3c9..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-css-with-pure-comments/output.js +++ /dev/null @@ -1,6 +0,0 @@ -import styled, { css } from 'styled-components'; -const partial = /*#__PURE__*/css(["color:red;"]); -const Component = /*#__PURE__*/styled.div.withConfig({ - displayName: "code__Component", - componentId: "sc-4wpzk3-0" -})(["", ";background:blue;"], partial); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-keyframes-with-pure-comments/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-keyframes-with-pure-comments/.babelrc deleted file mode 100644 index 8232aac0a0177..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-keyframes-with-pure-comments/.babelrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "pure": true - } - ] - ] -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-keyframes-with-pure-comments/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-keyframes-with-pure-comments/code.js deleted file mode 100644 index d22b2782e1c10..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-keyframes-with-pure-comments/code.js +++ /dev/null @@ -1,11 +0,0 @@ -import { keyframes } from 'styled-components' - -const Animation = keyframes` - 0% { - opacity: 0; - } - - 100% { - opacity: 1; - } -` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-keyframes-with-pure-comments/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-keyframes-with-pure-comments/output.js deleted file mode 100644 index f34babf3d526b..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-keyframes-with-pure-comments/output.js +++ /dev/null @@ -1,2 +0,0 @@ -import { keyframes } from 'styled-components'; -const Animation = /*#__PURE__*/keyframes(["0%{opacity:0;}100%{opacity:1;}"]); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-styled-calls-with-pure-comments/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-styled-calls-with-pure-comments/.babelrc deleted file mode 100644 index 8232aac0a0177..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-styled-calls-with-pure-comments/.babelrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "pure": true - } - ] - ] -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-styled-calls-with-pure-comments/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-styled-calls-with-pure-comments/code.js deleted file mode 100644 index 740cb19edf90a..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-styled-calls-with-pure-comments/code.js +++ /dev/null @@ -1,14 +0,0 @@ -import styled from 'styled-components' - -const Test = styled.div` - width: 100%; -` -const Test2 = styled('div')`` -const Test3 = true ? styled.div`` : styled.div`` -const styles = { One: styled.div`` } -let Component -Component = styled.div`` -const WrappedComponent = styled(Inner)`` -const StyledObjectForm = styled.div({ color: red }) -const StyledFunctionForm = styled.div(p => ({ color: p.color || 'red' })) -const normalFunc = add(5, 3) diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-styled-calls-with-pure-comments/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-styled-calls-with-pure-comments/output.js deleted file mode 100644 index 8b81f90aa15e8..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-styled-calls-with-pure-comments/output.js +++ /dev/null @@ -1,44 +0,0 @@ -import styled from 'styled-components'; -const Test = /*#__PURE__*/styled.div.withConfig({ - displayName: "code__Test", - componentId: "sc-u20i28-0" -})(["width:100%;"]); -const Test2 = /*#__PURE__*/styled('div').withConfig({ - displayName: "code__Test2", - componentId: "sc-u20i28-1" -})([""]); -const Test3 = true ? styled.div.withConfig({ - displayName: "code__Test3", - componentId: "sc-u20i28-2" -})([""]) : styled.div.withConfig({ - displayName: "code__Test3", - componentId: "sc-u20i28-3" -})([""]); -const styles = { - One: styled.div.withConfig({ - displayName: "code__One", - componentId: "sc-u20i28-4" - })([""]) -}; -let Component; -Component = styled.div.withConfig({ - displayName: "code__Component", - componentId: "sc-u20i28-5" -})([""]); -const WrappedComponent = /*#__PURE__*/styled(Inner).withConfig({ - displayName: "code__WrappedComponent", - componentId: "sc-u20i28-6" -})([""]); -const StyledObjectForm = /*#__PURE__*/styled.div.withConfig({ - displayName: "code__StyledObjectForm", - componentId: "sc-u20i28-7" -})({ - color: red -}); -const StyledFunctionForm = /*#__PURE__*/styled.div.withConfig({ - displayName: "code__StyledFunctionForm", - componentId: "sc-u20i28-8" -})(p => ({ - color: p.color || 'red' -})); -const normalFunc = add(5, 3); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-withtheme-with-pure-comments/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-withtheme-with-pure-comments/.babelrc deleted file mode 100644 index 8232aac0a0177..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-withtheme-with-pure-comments/.babelrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "pure": true - } - ] - ] -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-withtheme-with-pure-comments/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-withtheme-with-pure-comments/code.js deleted file mode 100644 index e57fd76c13144..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-withtheme-with-pure-comments/code.js +++ /dev/null @@ -1,3 +0,0 @@ -import { withTheme } from 'styled-components' - -const ThemedComponent = withTheme(() => null) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-withtheme-with-pure-comments/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-withtheme-with-pure-comments/output.js deleted file mode 100644 index a2cd31f026404..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.annotate-withtheme-with-pure-comments/output.js +++ /dev/null @@ -1,2 +0,0 @@ -import { withTheme } from 'styled-components'; -const ThemedComponent = /*#__PURE__*/withTheme(() => null); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.css-declared-after-component/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.css-declared-after-component/.babelrc deleted file mode 100644 index 7a2ae60447e57..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.css-declared-after-component/.babelrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "plugins": [ - [ - "../../../src" - ] - ] - } diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.css-declared-after-component/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.css-declared-after-component/code.js deleted file mode 100644 index 5be1a9e9f488b..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.css-declared-after-component/code.js +++ /dev/null @@ -1,10 +0,0 @@ -import React from "react" -import { css } from "styled-components" - -export default function Example() { - return
oops
-} - -const someCss = css` - color: red; -` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.css-declared-after-component/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.css-declared-after-component/output.js deleted file mode 100644 index d5d16344cf56c..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.css-declared-after-component/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _styled from "styled-components"; -import React from "react"; -import { css } from "styled-components"; -export default function Example() { - return <_StyledDiv>oops; -} -const someCss = css(["color:red;"]); - -var _StyledDiv = _styled("div").withConfig({ - displayName: "code___StyledDiv", - componentId: "sc-7mydya-0" -})(["", ""], someCss); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-in-helpers/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-in-helpers/.babelrc deleted file mode 100644 index e170b2be531bd..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-in-helpers/.babelrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": false - } - ] - ] -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-in-helpers/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-in-helpers/code.js deleted file mode 100644 index 4e650896dc313..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-in-helpers/code.js +++ /dev/null @@ -1,17 +0,0 @@ -import { createGlobalStyle, css, keyframes } from 'styled-components' - -const key = keyframes` - to { - transform: rotate(360deg); - } -` - -const color = css` - color: ${theColor}; -` - -const GlobalStyles = createGlobalStyle` - html { - color: red; - } -` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-in-helpers/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-in-helpers/output.js deleted file mode 100644 index 82dbc10057881..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-in-helpers/output.js +++ /dev/null @@ -1,4 +0,0 @@ -import { createGlobalStyle, css, keyframes } from 'styled-components'; -const key = keyframes`to{transform:rotate(360deg);}`; -const color = css`color:${theColor};`; -const GlobalStyles = createGlobalStyle`html{color:red;}`; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-with-transpilation/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-with-transpilation/.babelrc deleted file mode 100644 index 65e9aafd4341d..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-with-transpilation/.babelrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "presets": [ - "@babel/preset-env" - ], - "plugins": [ - [ - "../../../src", - { - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": false - } - ] - ] -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-with-transpilation/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-with-transpilation/code.js deleted file mode 100644 index 92c613e473333..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-with-transpilation/code.js +++ /dev/null @@ -1,24 +0,0 @@ -import styled from 'styled-components'; - -const Simple = styled.div` - width: 100%; -`; - -const Interpolation = styled.div` - content: " ${props => props.text} "; -`; - -const SpecialCharacters = styled.div` - content: " ${props => props.text} ";\n color: red; -`; - -const Comment = styled.div` - // comment - color: red; -` - -const Parens = styled.div` - &:hover { - color: blue; - } -`; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-with-transpilation/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-with-transpilation/output.js deleted file mode 100644 index 9e95d2f248967..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-with-transpilation/output.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; - -var _styledComponents = _interopRequireDefault(require("styled-components")); - -var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } - -function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } - -var Simple = _styledComponents["default"].div(_templateObject || (_templateObject = _taggedTemplateLiteral(["width:100%;"]))); - -var Interpolation = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["content:\" ", " \";"])), function (props) { - return props.text; -}); - -var SpecialCharacters = _styledComponents["default"].div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["content:\" ", " \";color:red;"])), function (props) { - return props.text; -}); - -var Comment = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["color:red;"]))); - -var Parens = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["&:hover{color:blue;}"]))); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-without-transpilation/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-without-transpilation/.babelrc deleted file mode 100644 index e170b2be531bd..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-without-transpilation/.babelrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": false - } - ] - ] -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-without-transpilation/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-without-transpilation/code.js deleted file mode 100644 index 02aa35dc34a84..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-without-transpilation/code.js +++ /dev/null @@ -1,36 +0,0 @@ -import styled from 'styled-components'; - -const Simple = styled.div` - width: 100%; -`; - -const Interpolation = styled.div` - content: "https://test.com/${props => props.endpoint}"; -`; - -const SpecialCharacters = styled.div` - content: " ${props => props.text} ";\n color: red; -`; - -const Comment = styled.div` - width: 100%; - // comment - color: red; -`; - -const Parens = styled.div` - &:hover { - color: blue; - } - color: red; -`; - -const UrlComments = styled.div` - color: red; - /* // */ - background: red; - /* comment 1 */ - /* comment 2 */ - // comment 3 - border: 1px solid green; -`; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-without-transpilation/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-without-transpilation/output.js deleted file mode 100644 index 656e3c57f3b35..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-css-to-use-without-transpilation/output.js +++ /dev/null @@ -1,7 +0,0 @@ -import styled from 'styled-components'; -const Simple = styled.div`width:100%;`; -const Interpolation = styled.div`content:"https://test.com/${props => props.endpoint}";`; -const SpecialCharacters = styled.div`content:" ${props => props.text} ";color:red;`; -const Comment = styled.div`width:100%;color:red;`; -const Parens = styled.div`&:hover{color:blue;}color:red;`; -const UrlComments = styled.div`color:red;background:red;border:1px solid green;`; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-single-line-comments-with-interpolations/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-single-line-comments-with-interpolations/.babelrc deleted file mode 100644 index b64d0b6553ea1..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-single-line-comments-with-interpolations/.babelrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "minify": true - } - ] - ] -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-single-line-comments-with-interpolations/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-single-line-comments-with-interpolations/code.js deleted file mode 100644 index c431ae03b1d60..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-single-line-comments-with-interpolations/code.js +++ /dev/null @@ -1,40 +0,0 @@ -import styled from 'styled-components' - -const Test1 = styled.div` - width: 100%; - // color: ${'red'}; -` - -const Test2 = styled.div` - width: 100%; - // color: pale${'red'}; -` - -const Test3 = styled.div` - width: 100%; - // color - ${'red'}; -` - -const Test4 = styled.div` - width: 100%; - // color: ${'red'}-blue; -` - -const Test5 = styled.div` - width: 100%; - // color: ${'red'}${'blue'}; -` - -const Test6 = styled.div` - background: url("https://google.com"); - width: 100%; - ${'green'} // color: ${'red'}${'blue'}; -` - -const Test7 = styled.div` - background: url("https://google.com"); - width: ${p => p.props.width}; - ${'green'} // color: ${'red'}${'blue'}; - height: ${p => p.props.height}; -` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-single-line-comments-with-interpolations/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.minify-single-line-comments-with-interpolations/output.js deleted file mode 100644 index db4b692d8f7e9..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.minify-single-line-comments-with-interpolations/output.js +++ /dev/null @@ -1,29 +0,0 @@ -import styled from 'styled-components'; -const Test1 = styled.div.withConfig({ - displayName: "code__Test1", - componentId: "sc-kc0mjf-0" -})(["width:100%;"]); -const Test2 = styled.div.withConfig({ - displayName: "code__Test2", - componentId: "sc-kc0mjf-1" -})(["width:100%;"]); -const Test3 = styled.div.withConfig({ - displayName: "code__Test3", - componentId: "sc-kc0mjf-2" -})(["width:100%;", ";"], 'red'); -const Test4 = styled.div.withConfig({ - displayName: "code__Test4", - componentId: "sc-kc0mjf-3" -})(["width:100%;"]); -const Test5 = styled.div.withConfig({ - displayName: "code__Test5", - componentId: "sc-kc0mjf-4" -})(["width:100%;"]); -const Test6 = styled.div.withConfig({ - displayName: "code__Test6", - componentId: "sc-kc0mjf-5" -})(["background:url(\"https://google.com\");width:100%;", " "], 'green'); -const Test7 = styled.div.withConfig({ - displayName: "code__Test7", - componentId: "sc-kc0mjf-6" -})(["background:url(\"https://google.com\");width:", ";", " height:", ";"], p => p.props.width, 'green', p => p.props.height); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.transformed-imports-with-jsx-member-expressions/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.transformed-imports-with-jsx-member-expressions/.babelrc deleted file mode 100644 index 75ba23a68ed5e..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.transformed-imports-with-jsx-member-expressions/.babelrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "plugins": [ - ["@babel/plugin-transform-modules-commonjs"], - [ - "../../../src" - ] - ] - } diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.transformed-imports-with-jsx-member-expressions/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.transformed-imports-with-jsx-member-expressions/code.js deleted file mode 100644 index c6e94d522e7a8..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.transformed-imports-with-jsx-member-expressions/code.js +++ /dev/null @@ -1,11 +0,0 @@ -import React from "react"; -import { css } from "styled-components"; -import Icons from "./icons"; - -const someCss = css` background: purple;`; - -const App1 = () => { return ; }; - -const App2 = () => { return ; }; - -const App3 = () => { return ; }; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.transformed-imports-with-jsx-member-expressions/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.transformed-imports-with-jsx-member-expressions/output.js deleted file mode 100644 index e741877df1efc..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.transformed-imports-with-jsx-member-expressions/output.js +++ /dev/null @@ -1,42 +0,0 @@ -"use strict"; - -var _styledComponents = _interopRequireWildcard(require("styled-components")); - -var _react = _interopRequireDefault(require("react")); - -var _icons = _interopRequireDefault(require("./icons")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } - -function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } - -const someCss = (0, _styledComponents.css)([" background:purple;"]); - -const App1 = () => { - return <_StyledIcons />; -}; - -const App2 = () => { - return <_StyledIconsFoo />; -}; - -const App3 = () => { - return <_StyledIconsFooBar />; -}; - -var _StyledIcons = (0, _styledComponents.default)(_icons.default).withConfig({ - displayName: "code___StyledIcons", - componentId: "sc-1wxehft-0" -})(["", ""], someCss); - -var _StyledIconsFoo = (0, _styledComponents.default)(_icons.default.Foo).withConfig({ - displayName: "code___StyledIconsFoo", - componentId: "sc-1wxehft-1" -})(["", ""], someCss); - -var _StyledIconsFooBar = (0, _styledComponents.default)(_icons.default.Foo.Bar).withConfig({ - displayName: "code___StyledIconsFooBar", - componentId: "sc-1wxehft-2" -})(["", ""], someCss); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-with-config/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-with-config/.babelrc deleted file mode 100644 index 4e78d26f1a33f..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-with-config/.babelrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "presets": ["@babel/preset-env"], - "plugins": [ - [ - "../../../src", - { - "ssr": false, - "displayName": true, - "transpileTemplateLiterals": true, - "minify": false - } - ] - ] -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-with-config/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-with-config/code.js deleted file mode 100644 index c89451dee60e3..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-with-config/code.js +++ /dev/null @@ -1,27 +0,0 @@ -import styled, { css, createGlobalStyle } from 'styled-components' - -const Named = styled.div` - width: 100%; -` - -const NamedWithInterpolation = styled.div` - color: ${color => props.color}; -` - -const Wrapped = styled(Inner)` - color: red; -` - -const Foo = styled.div({ - color: 'green', -}) - -const style = css` - background: green; -` - -const GlobalStyle = createGlobalStyle` - html { - background: silver; - } -` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-with-config/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-with-config/output.js deleted file mode 100644 index 2c5c07a688d86..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-with-config/output.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -var _styledComponents = _interopRequireWildcard(require("styled-components")); - -function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } - -function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } - -var Named = _styledComponents["default"].div.withConfig({ - displayName: "code__Named" -})(["\n width: 100%;\n"]); - -var NamedWithInterpolation = _styledComponents["default"].div.withConfig({ - displayName: "code__NamedWithInterpolation" -})(["\n color: ", ";\n"], function (color) { - return props.color; -}); - -var Wrapped = (0, _styledComponents["default"])(Inner).withConfig({ - displayName: "code__Wrapped" -})(["\n color: red;\n"]); - -var Foo = _styledComponents["default"].div.withConfig({ - displayName: "code__Foo" -})({ - color: 'green' -}); - -var style = (0, _styledComponents.css)(["\n background: green;\n"]); -var GlobalStyle = (0, _styledComponents.createGlobalStyle)(["\n html {\n background: silver;\n }\n"]); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-without-config/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-without-config/.babelrc deleted file mode 100644 index b39aa73018fda..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-without-config/.babelrc +++ /dev/null @@ -1,16 +0,0 @@ -{ - "presets": [ - "@babel/preset-env" - ], - "plugins": [ - [ - "../../../src", - { - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": true, - "minify": false - } - ] - ] -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-without-config/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-without-config/code.js deleted file mode 100644 index 1e9488288d0c4..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-without-config/code.js +++ /dev/null @@ -1,11 +0,0 @@ -import styled from 'styled-components'; - -const Named = styled.div` - width: 100%; -`; - -const NamedWithInterpolation = styled.div` - color: ${color => props.color}; -`; - -const Wrapped = styled(Inner)`color: red;`; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-without-config/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-without-config/output.js deleted file mode 100644 index e14572e4908bf..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.transpile-template-literals-without-config/output.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; - -var _styledComponents = _interopRequireDefault(require("styled-components")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } - -var Named = _styledComponents["default"].div(["\n width: 100%;\n"]); - -var NamedWithInterpolation = _styledComponents["default"].div(["\n color: ", ";\n"], function (color) { - return props.color; -}); - -var Wrapped = (0, _styledComponents["default"])(Inner)(["color: red;"]); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.work-with-hoisted-default-as-import/.babelrc b/packages/next-swc/crates/styled_components/tests/fixtures/.work-with-hoisted-default-as-import/.babelrc deleted file mode 100644 index 158460ca158de..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.work-with-hoisted-default-as-import/.babelrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "transpileTemplateLiterals": false, - "ssr": true - } - ] - ] -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.work-with-hoisted-default-as-import/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/.work-with-hoisted-default-as-import/code.js deleted file mode 100644 index f48662ec51194..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.work-with-hoisted-default-as-import/code.js +++ /dev/null @@ -1,2 +0,0 @@ -const Test = s.div`width: 100%;`; -import { default as s, css } from 'styled-components'; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/.work-with-hoisted-default-as-import/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/.work-with-hoisted-default-as-import/output.js deleted file mode 100644 index 297e05c351782..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/.work-with-hoisted-default-as-import/output.js +++ /dev/null @@ -1,5 +0,0 @@ -const Test = s.div.withConfig({ - displayName: "code__Test", - componentId: "sc-1dds9bl-0" -})`width:100%;`; -import { default as s, css } from 'styled-components'; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-display-names/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-display-names/code.js deleted file mode 100644 index f79c564d86ff3..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-display-names/code.js +++ /dev/null @@ -1,15 +0,0 @@ -import styled from 'styled-components' - -const Test = styled.div` - width: 100%; -` -const Test2 = styled('div')`` -const Test3 = true ? styled.div`` : styled.div`` -const styles = { One: styled.div`` } -let Component -Component = styled.div`` -const WrappedComponent = styled(Inner)`` -class ClassComponent { - static Child = styled.div`` -} -var GoodName = BadName = styled.div``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-display-names/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/add-display-names/config.json deleted file mode 100644 index 82180b0e0f02c..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-display-names/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ssr": false, - "fileName": false, - "transpileTemplateLiterals": false -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-display-names/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-display-names/output.js deleted file mode 100644 index a07fd4eaabc90..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-display-names/output.js +++ /dev/null @@ -1,34 +0,0 @@ -import styled from 'styled-components'; -const Test = styled.div.withConfig({ - displayName: "Test" -})` - width: 100%; -`; -const Test2 = styled('div').withConfig({ - displayName: "Test2" -})``; -const Test3 = true ? styled.div.withConfig({ - displayName: "Test3" -})`` : styled.div.withConfig({ - displayName: "Test3" -})``; -const styles = { - One: styled.div.withConfig({ - displayName: "One" - })`` -}; -let Component; -Component = styled.div.withConfig({ - displayName: "Component" -})``; -const WrappedComponent = styled(Inner).withConfig({ - displayName: "WrappedComponent" -})``; -class ClassComponent { - static Child = styled.div.withConfig({ - displayName: "Child" - })``; -} -var GoodName = BadName = styled.div.withConfig({ - displayName: "GoodName" -})``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-and-display-name/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-and-display-name/code.js deleted file mode 100644 index 2d5143896cbcf..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-and-display-name/code.js +++ /dev/null @@ -1,30 +0,0 @@ -import styled from 'styled-components' - -const Test = styled.div` - width: 100%; -` -const Test2 = true ? styled.div`` : styled.div`` -const styles = { One: styled.div`` } -let Component -Component = styled.div`` -const WrappedComponent = styled(Inner)`` -const WrappedComponent2 = styled.div({}) -const WrappedComponent3 = styled(Inner)({}) -const WrappedComponent4 = styled(Inner).attrs(() => ({ something: 'else' }))({}) -const WrappedComponent5 = styled.div.attrs(() => ({ something: 'else' }))({}) -const WrappedComponent6 = styled.div.attrs(() => ({ something: 'else' }))`` -const WrappedComponent7 = styled.div.withConfig({ - shouldForwardProp: () => {}, -})({}) - -const WrappedComponent8 = styled.div - .withConfig({ - shouldForwardProp: () => {}, - }) - .attrs(() => ({ something: 'else' }))({}) - -const WrappedComponent9 = styled.div - .attrs(() => ({ something: 'else' })) - .withConfig({ - shouldForwardProp: () => {}, - })({}) diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-and-display-name/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-and-display-name/config.json deleted file mode 100644 index e9120a57d99c5..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-and-display-name/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "fileName": false, - "transpileTemplateLiterals": false, - "ssr": true -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-and-display-name/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-and-display-name/output.js deleted file mode 100644 index c433af915c5b9..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-and-display-name/output.js +++ /dev/null @@ -1,71 +0,0 @@ -import styled from 'styled-components'; -const Test = styled.div.withConfig({ - displayName: "Test", - componentId: "sc-e0d5b7ad-0" -})` - width: 100%; -`; -const Test2 = true ? styled.div.withConfig({ - displayName: "Test2", - componentId: "sc-e0d5b7ad-1" -})`` : styled.div.withConfig({ - displayName: "Test2", - componentId: "sc-e0d5b7ad-2" -})``; -const styles = { - One: styled.div.withConfig({ - displayName: "One", - componentId: "sc-e0d5b7ad-3" - })`` -}; -let Component; -Component = styled.div.withConfig({ - displayName: "Component", - componentId: "sc-e0d5b7ad-4" -})``; -const WrappedComponent = styled(Inner).withConfig({ - displayName: "WrappedComponent", - componentId: "sc-e0d5b7ad-5" -})``; -const WrappedComponent2 = styled.div.withConfig({ - displayName: "WrappedComponent2", - componentId: "sc-e0d5b7ad-6" -})({}); -const WrappedComponent3 = styled(Inner).withConfig({ - displayName: "WrappedComponent3", - componentId: "sc-e0d5b7ad-7" -})({}); -const WrappedComponent4 = styled(Inner).attrs(()=>({ - something: 'else' - }) -)({}); -const WrappedComponent5 = styled.div.attrs(()=>({ - something: 'else' - }) -)({}); -const WrappedComponent6 = styled.div.attrs(()=>({ - something: 'else' - }) -).withConfig({ - displayName: "WrappedComponent6", - componentId: "sc-e0d5b7ad-8" -})``; -const WrappedComponent7 = styled.div.withConfig({ - shouldForwardProp: ()=>{}, - displayName: "WrappedComponent7", - componentId: "sc-e0d5b7ad-9" -})({}); -const WrappedComponent8 = styled.div.withConfig({ - shouldForwardProp: ()=>{} -}).attrs(()=>({ - something: 'else' - }) -)({}); -const WrappedComponent9 = styled.div.attrs(()=>({ - something: 'else' - }) -).withConfig({ - shouldForwardProp: ()=>{}, - displayName: "WrappedComponent9", - componentId: "sc-e0d5b7ad-10" -})({}); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths-and-named-import/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths-and-named-import/code.js deleted file mode 100644 index e26d3c7ce3384..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths-and-named-import/code.js +++ /dev/null @@ -1,10 +0,0 @@ -import { styled } from '@example/example' - -const Test = styled.div` - width: 100%; -` -const Test2 = true ? styled.div`` : styled.div`` -const styles = { One: styled.div`` } -let Component -Component = styled.div`` -const WrappedComponent = styled(Inner)`` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths-and-named-import/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths-and-named-import/config.json deleted file mode 100644 index ba50ffd21656c..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths-and-named-import/config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "displayName": true, - "fileName": false, - "ssr": true, - "topLevelImportPaths": ["@example/example"], - "transpileTemplateLiterals": false -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths-and-named-import/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths-and-named-import/output.js deleted file mode 100644 index 3c46bbb613e1f..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths-and-named-import/output.js +++ /dev/null @@ -1,29 +0,0 @@ -import { styled } from '@example/example'; -const Test = styled.div.withConfig({ - displayName: "Test", - componentId: "sc-bd3b1624-0" -})` - width: 100%; -`; -const Test2 = true ? styled.div.withConfig({ - displayName: "Test2", - componentId: "sc-bd3b1624-1" -})`` : styled.div.withConfig({ - displayName: "Test2", - componentId: "sc-bd3b1624-2" -})``; -const styles = { - One: styled.div.withConfig({ - displayName: "One", - componentId: "sc-bd3b1624-3" - })`` -}; -let Component; -Component = styled.div.withConfig({ - displayName: "Component", - componentId: "sc-bd3b1624-4" -})``; -const WrappedComponent = styled(Inner).withConfig({ - displayName: "WrappedComponent", - componentId: "sc-bd3b1624-5" -})``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths/code.js deleted file mode 100644 index b03b6c13307e0..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths/code.js +++ /dev/null @@ -1,10 +0,0 @@ -import styled from '@xstyled/styled-components' - -const Test = styled.div` - width: 100%; -` -const Test2 = true ? styled.div`` : styled.div`` -const styles = { One: styled.div`` } -let Component -Component = styled.div`` -const WrappedComponent = styled(Inner)`` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths/config.json deleted file mode 100644 index 370d536747b00..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths/config.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "displayName": false, - "fileName": false, - "ssr": true, - "topLevelImportPaths": [ - "@xstyled/styled-components", - "@xstyled/styled-components/no-tags", - "@xstyled/styled-components/native", - "@xstyled/styled-components/primitives" - ], - "transpileTemplateLiterals": false -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths/output.js deleted file mode 100644 index 55f99140dfb04..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier-with-top-level-import-paths/output.js +++ /dev/null @@ -1,23 +0,0 @@ -import styled from '@xstyled/styled-components'; -const Test = styled.div.withConfig({ - componentId: "sc-2fd35b87-0" -})` - width: 100%; -`; -const Test2 = true ? styled.div.withConfig({ - componentId: "sc-2fd35b87-1" -})`` : styled.div.withConfig({ - componentId: "sc-2fd35b87-2" -})``; -const styles = { - One: styled.div.withConfig({ - componentId: "sc-2fd35b87-3" - })`` -}; -let Component; -Component = styled.div.withConfig({ - componentId: "sc-2fd35b87-4" -})``; -const WrappedComponent = styled(Inner).withConfig({ - componentId: "sc-2fd35b87-5" -})``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier/code.js deleted file mode 100644 index 3261233fc5958..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier/code.js +++ /dev/null @@ -1,10 +0,0 @@ -import styled from 'styled-components' - -const Test = styled.div` - width: 100%; -` -const Test2 = true ? styled.div`` : styled.div`` -const styles = { One: styled.div`` } -let Component -Component = styled.div`` -const WrappedComponent = styled(Inner)`` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier/config.json deleted file mode 100644 index c525ec53c3415..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier/config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "displayName": false, - "fileName": false, - "transpileTemplateLiterals": false, - "ssr": true -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier/output.js deleted file mode 100644 index 9374f5b3c9655..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/add-identifier/output.js +++ /dev/null @@ -1,23 +0,0 @@ -import styled from 'styled-components'; -const Test = styled.div.withConfig({ - componentId: "sc-bc9ba4b0-0" -})` - width: 100%; -`; -const Test2 = true ? styled.div.withConfig({ - componentId: "sc-bc9ba4b0-1" -})`` : styled.div.withConfig({ - componentId: "sc-bc9ba4b0-2" -})``; -const styles = { - One: styled.div.withConfig({ - componentId: "sc-bc9ba4b0-3" - })`` -}; -let Component; -Component = styled.div.withConfig({ - componentId: "sc-bc9ba4b0-4" -})``; -const WrappedComponent = styled(Inner).withConfig({ - componentId: "sc-bc9ba4b0-5" -})``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-desugar-styled-assignment/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/does-not-desugar-styled-assignment/code.js deleted file mode 100644 index 108f2b49164e4..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-desugar-styled-assignment/code.js +++ /dev/null @@ -1,7 +0,0 @@ -const domElements = ['div'] - -const styled = () => {} - -domElements.forEach(domElement => { - styled[domElement] = styled(domElement) -}) diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-desugar-styled-assignment/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/does-not-desugar-styled-assignment/config.json deleted file mode 100644 index 0967ef424bce6..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-desugar-styled-assignment/config.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-desugar-styled-assignment/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/does-not-desugar-styled-assignment/output.js deleted file mode 100644 index f3c26dd0453bf..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-desugar-styled-assignment/output.js +++ /dev/null @@ -1,7 +0,0 @@ -const domElements = ['div']; - -const styled = () => {}; - -domElements.forEach(domElement => { - styled[domElement] = styled(domElement); -}); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-replace-native-with-no-tags/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/does-not-replace-native-with-no-tags/code.js deleted file mode 100644 index a277ab493126b..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-replace-native-with-no-tags/code.js +++ /dev/null @@ -1,13 +0,0 @@ -const styled_default = require('styled-components/native') - -const TestNormal = styled.div` - width: 100%; -` - -const Test = styled_default.default.div` - width: 100%; -` - -const TestCallExpression = styled_default.default(Test)` - height: 20px; -` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-replace-native-with-no-tags/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/does-not-replace-native-with-no-tags/config.json deleted file mode 100644 index 0967ef424bce6..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-replace-native-with-no-tags/config.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-replace-native-with-no-tags/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/does-not-replace-native-with-no-tags/output.js deleted file mode 100644 index 6e8728945fa38..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/does-not-replace-native-with-no-tags/output.js +++ /dev/null @@ -1,19 +0,0 @@ -const styled_default = require('styled-components/native'); -const TestNormal = styled.div.withConfig({ - displayName: "code__TestNormal", - componentId: "sc-1f1c6df5-0" -})` - width: 100%; -`; -const Test = styled_default.default.div.withConfig({ - displayName: "code__Test", - componentId: "sc-1f1c6df5-1" -})` - width: 100%; -`; -const TestCallExpression = styled_default.default(Test).withConfig({ - displayName: "code__TestCallExpression", - componentId: "sc-1f1c6df5-2" -})` - height: 20px; -`; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/ignore-external-styled-import/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/ignore-external-styled-import/code.js deleted file mode 100644 index a7eeadab76d46..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/ignore-external-styled-import/code.js +++ /dev/null @@ -1,9 +0,0 @@ -import { styled } from '@material/ui' -import s from 'styled-components' - -const Paragraph = s.p` - color: green; -` - -const Foo = p => -const TestNormal = styled(Foo)({ color: red }) diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/ignore-external-styled-import/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/ignore-external-styled-import/config.json deleted file mode 100644 index 0967ef424bce6..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/ignore-external-styled-import/config.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/ignore-external-styled-import/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/ignore-external-styled-import/output.js deleted file mode 100644 index 5ce96a0eae47c..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/ignore-external-styled-import/output.js +++ /dev/null @@ -1,13 +0,0 @@ -import { styled } from '@material/ui'; -import s from 'styled-components'; -const Paragraph = s.p.withConfig({ - displayName: "code__Paragraph", - componentId: "sc-c285d12a-0" -})` - color: green; -`; -const Foo = (p)=> -; -const TestNormal = styled(Foo)({ - color: red -}); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/not-use-private-api-if-not-required/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/not-use-private-api-if-not-required/code.js deleted file mode 100644 index 9fa94bb5973e8..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/not-use-private-api-if-not-required/code.js +++ /dev/null @@ -1,3 +0,0 @@ -import styled from 'styled-components'; - -const Test = styled.div`width: 100%;`; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/not-use-private-api-if-not-required/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/not-use-private-api-if-not-required/config.json deleted file mode 100644 index b174f8d7b3ca2..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/not-use-private-api-if-not-required/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": false -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/not-use-private-api-if-not-required/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/not-use-private-api-if-not-required/output.js deleted file mode 100644 index fe64593595381..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/not-use-private-api-if-not-required/output.js +++ /dev/null @@ -1,2 +0,0 @@ -import styled from 'styled-components'; -const Test = styled.div`width: 100%;`; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/track-the-imported-variable/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/track-the-imported-variable/code.js deleted file mode 100644 index 9fe7111a9d3b9..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/track-the-imported-variable/code.js +++ /dev/null @@ -1,8 +0,0 @@ -import s from "styled-components"; - -const Test = s.div`width: 100%;`; -const Test2 = true ? s.div`` : s.div``; -const styles = { One: s.div`` } -let Component; -Component = s.div``; -const WrappedComponent = s(Inner)``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/track-the-imported-variable/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/track-the-imported-variable/config.json deleted file mode 100644 index e9120a57d99c5..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/track-the-imported-variable/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "fileName": false, - "transpileTemplateLiterals": false, - "ssr": true -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/track-the-imported-variable/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/track-the-imported-variable/output.js deleted file mode 100644 index 07ebdb8f42d49..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/track-the-imported-variable/output.js +++ /dev/null @@ -1,27 +0,0 @@ -import s from "styled-components"; -const Test = s.div.withConfig({ - displayName: "Test", - componentId: "sc-d5028521-0" -})`width: 100%;`; -const Test2 = true ? s.div.withConfig({ - displayName: "Test2", - componentId: "sc-d5028521-1" -})`` : s.div.withConfig({ - displayName: "Test2", - componentId: "sc-d5028521-2" -})``; -const styles = { - One: s.div.withConfig({ - displayName: "One", - componentId: "sc-d5028521-3" - })`` -}; -let Component; -Component = s.div.withConfig({ - displayName: "Component", - componentId: "sc-d5028521-4" -})``; -const WrappedComponent = s(Inner).withConfig({ - displayName: "WrappedComponent", - componentId: "sc-d5028521-5" -})``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-import/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-import/code.js deleted file mode 100644 index 33cbca5a6ac83..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-import/code.js +++ /dev/null @@ -1,21 +0,0 @@ -// @flow -import React from 'react' -import Card from '../../shared/components/Card' -import config from '../../../config' - -export default () => ( -
- -

Login or Sign Up

-

- - Sign up or login with Google - -

-
-
-) diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-import/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-import/config.json deleted file mode 100644 index ca4eac71a785b..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-import/config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": false, - "minify": false, - "cssProp": true -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-import/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-import/output.js deleted file mode 100644 index 04472c4c48ca0..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-import/output.js +++ /dev/null @@ -1,27 +0,0 @@ -// @flow -import _styled from "styled-components"; -import React from 'react'; -import Card from '../../shared/components/Card'; -import config from '../../../config'; -export default (()=><_StyledDiv > - - - -

Login or Sign Up

- -

- - - - Sign up or login with Google - - - -

- -
- - ); -var _StyledDiv = _styled("div")` - width: 35em; - `; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-require/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-require/code.js deleted file mode 100644 index 2047fa75693ef..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-require/code.js +++ /dev/null @@ -1,10 +0,0 @@ -// @flow -import React from 'react' - -export default () => ( -
-) diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-require/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-require/config.json deleted file mode 100644 index ca4eac71a785b..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-require/config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": false, - "minify": false, - "cssProp": true -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-require/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-require/output.js deleted file mode 100644 index 2fb17534060c5..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-add-require/output.js +++ /dev/null @@ -1,7 +0,0 @@ -// @flow -import _styled from "styled-components"; -import React from 'react'; -export default (()=><_StyledDiv />); -var _StyledDiv = _styled("div")` - width: 35em; - `; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-all-options-on/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-all-options-on/code.js deleted file mode 100644 index 4351b8cf07ab2..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-all-options-on/code.js +++ /dev/null @@ -1,271 +0,0 @@ -import styled from 'styled-components' -import SomeComponent from '../SomeComponentPath' -const { SomeOtherComponent } = require('../SomeOtherComponentPath') - -/** - * control - */ - -const Thing = styled.div` - color: red; -` - -const Thing2 = styled(Thing)` - background: blue; -` - -/* - * Basic fixtures - */ - -const StaticString = p =>

A

- -const StaticTemplate = p => ( -

- A -

-) - -const ObjectProp = p =>

A

- -const NoChildren = p =>

- -const CssHelperProp = p => ( -

- A -

-) - -/* - * Dynamic prop - */ - -const CustomComp = p => H - -const DynamicProp = p =>

H

- -const LocalInterpolation = p => ( -

- H -

-) - -const FuncInterpolation = p => ( -

props.theme.a}; - `} - > - H -

-) - -const radius = 10 -const GlobalInterpolation = p => ( -

- H -

-) - -const LocalCssHelperProp = p => ( -

- A -

-) - -const DynamicCssHelperProp = p => ( -

props.theme.color}; - `} - > - A -

-) - -const CustomCompWithDot = p => H - -const NestedCompWithDot = p => ( - H -) - -const CustomCompWithDotLowerCase = p => ( - H -) - -const CustomElement = p => H - -const globalVar = '"foo"' -const getAfterValue = () => '"bar"' - -const ObjectPropMixedInputs = p => { - const color = 'red' - - return ( -

- A -

- ) -} - -const SpreadObjectPropMixedInputs = p => { - const color = 'red' - - return ( -

- A -

- ) -} - -/* styled component defined after function it's used in */ - -const EarlyUsageComponent = p => - -const Thing3 = styled.div` - color: blue; -` - -const EarlyUsageComponent2 = p => - -function Thing4(props) { - return
-} - -/* insert before usage for non-local scope styled HOC targets */ - -const ImportedComponentUsage = p => -const RequiredComponentUsage = p => - -const ObjectInterpolation = p => { - const theme = useTheme() - - return ( -

- H -

- ) -} - -const ObjectInterpolationCustomComponent = p => { - const theme = useTheme() - - return ( - - H - - ) -} - -const ObjectInterpolationInKey = p => { - const theme = useTheme() - - return ( - - H - - ) -} - -const ObjectFnInterpolationInKey = p => { - const theme = useTheme() - - return ( - - H - - ) -} - -const ObjectFnSimpleInterpolationInKey = p => { - const foo = '@media screen and (max-width: 600px)' - - return ( - - H - - ) -} - -const ObjectPropWithSpread = () => { - const css = { color: 'red' } - const playing = true - - return ( -
- ) -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-all-options-on/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-all-options-on/config.json deleted file mode 100644 index ede0eaf297f32..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-all-options-on/config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "ssr": true, - "displayName": true, - "transpileTemplateLiterals": true, - "minify": true, - "cssProp": true -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-all-options-on/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-all-options-on/output.js deleted file mode 100644 index ce524e2f23882..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop-all-options-on/output.js +++ /dev/null @@ -1,329 +0,0 @@ -import styled from 'styled-components'; -import SomeComponent from '../SomeComponentPath'; -const { SomeOtherComponent } = require('../SomeOtherComponentPath'); -/** - * control - */ const Thing = styled.div.withConfig({ - displayName: "code__Thing", - componentId: "sc-867225be-0" -})` - color: red; -`; -const Thing2 = styled(Thing).withConfig({ - displayName: "code__Thing2", - componentId: "sc-867225be-1" -})` - background: blue; -`; -/* - * Basic fixtures - */ const StaticString = (p)=><_StyledP >A; -const StaticTemplate = (p)=><_StyledP2 > - - A - - ; -const ObjectProp = (p)=><_StyledP3 >A; -const NoChildren = (p)=><_StyledP4 />; -const CssHelperProp = (p)=><_StyledP5 > - - A - - ; -/* - * Dynamic prop - */ const CustomComp = (p)=><_StyledParagraph >H; -const DynamicProp = (p)=><_StyledP6 $_css={props.cssText}>H; -const LocalInterpolation = (p)=><_StyledP7 $_css2={props.bg}> - - H - - ; -const FuncInterpolation = (p)=><_StyledP8 > - - H - - ; -const radius = 10; -const GlobalInterpolation = (p)=><_StyledP9 > - - H - - ; -const LocalCssHelperProp = (p)=><_StyledP10 $_css3={p.color}> - - A - - ; -const DynamicCssHelperProp = (p)=><_StyledP11 > - - A - - ; -const CustomCompWithDot = (p)=><_StyledButtonGhost >H; -const NestedCompWithDot = (p)=><_StyledButtonGhostNew >H; -const CustomCompWithDotLowerCase = (p)=><_StyledButtonGhost2 >H; -const CustomElement = (p)=><_StyledButtonGhost3 >H; -const globalVar = '"foo"'; -const getAfterValue = ()=>'"bar"'; -const ObjectPropMixedInputs = (p)=>{ - const color = 'red'; - return <_StyledP12 $_css4={p.background} $_css5={color} $_css6={globalVar} $_css7={getAfterValue()}> - - A - - ; -}; -const SpreadObjectPropMixedInputs = (p)=>{ - const color = 'red'; - return <_StyledP13 $_css8={globalVar} $_css9={getAfterValue()} $_css10={globalVar} $_css11={getAfterValue()} $_css12={p.background} $_css13={globalVar} $_css14={getAfterValue()}> - - A - - ; -}; -/* styled component defined after function it's used in */ const EarlyUsageComponent = (p)=><_StyledThing />; -const Thing3 = styled.div.withConfig({ - displayName: "code__Thing3", - componentId: "sc-867225be-2" -})` - color: blue; -`; -var _StyledThing6 = styled(Thing3).withConfig({ - displayName: "code___StyledThing6", - componentId: "sc-867225be-3" -})((p)=>({ - [p.$_css19]: { - color: 'red' - } - })); -var _StyledThing5 = styled(Thing3).withConfig({ - displayName: "code___StyledThing5", - componentId: "sc-867225be-4" -})((p)=>({ - [p.$_css18]: { - color: 'red' - } - })); -var _StyledThing4 = styled(Thing3).withConfig({ - displayName: "code___StyledThing4", - componentId: "sc-867225be-5" -})((p)=>({ - [p.$_css17]: { - color: 'red' - } - })); -var _StyledThing3 = styled(Thing3).withConfig({ - displayName: "code___StyledThing3", - componentId: "sc-867225be-6" -})((p)=>({ - color: p.$_css16 - })); -var _StyledThing = styled(Thing3).withConfig({ - displayName: "code___StyledThing", - componentId: "sc-867225be-7" -})`color: red;`; -const EarlyUsageComponent2 = (p)=><_StyledThing2 />; -function Thing4(props1) { - return
; -} -/* insert before usage for non-local scope styled HOC targets */ const ImportedComponentUsage = (p)=><_StyledSomeComponent />; -const RequiredComponentUsage = (p)=><_StyledSomeOtherComponent />; -const ObjectInterpolation = (p)=>{ - const theme = useTheme(); - return <_StyledP14 $_css15={theme.colors.red}> - - H - - ; -}; -const ObjectInterpolationCustomComponent = (p)=>{ - const theme = useTheme(); - return <_StyledThing3 $_css16={theme.colors.red}> - - H - - ; -}; -const ObjectInterpolationInKey = (p)=>{ - const theme = useTheme(); - return <_StyledThing4 $_css17={theme.breakpoints.md}> - - H - - ; -}; -const ObjectFnInterpolationInKey = (p)=>{ - const theme = useTheme(); - return <_StyledThing5 $_css18={theme.breakpoints.md()}> - - H - - ; -}; -const ObjectFnSimpleInterpolationInKey = (p)=>{ - const foo = '@media screen and (max-width: 600px)'; - return <_StyledThing6 $_css19={foo}> - - H - - ; -}; -const ObjectPropWithSpread = ()=>{ - const css = { - color: 'red' - }; - const playing = true; - return <_StyledDiv $_css20={css} $_css21={playing ? { - opacity: 0, - bottom: '-100px' - } : {}}/>; -}; -var _StyledSomeComponent = styled(SomeComponent).withConfig({ - displayName: "code___StyledSomeComponent", - componentId: "sc-867225be-8" -})`color: red;`; -var _StyledSomeOtherComponent = styled(SomeOtherComponent).withConfig({ - displayName: "code___StyledSomeOtherComponent", - componentId: "sc-867225be-9" -})`color: red;`; -var _StyledThing2 = styled(Thing4).withConfig({ - displayName: "code___StyledThing2", - componentId: "sc-867225be-10" -})`color: red;`; -var _StyledP = styled("p").withConfig({ - displayName: "code___StyledP", - componentId: "sc-867225be-11" -})`flex: 1;`; -var _StyledP2 = styled("p").withConfig({ - displayName: "code___StyledP2", - componentId: "sc-867225be-12" -})` - flex: 1; - `; -var _StyledP3 = styled("p").withConfig({ - displayName: "code___StyledP3", - componentId: "sc-867225be-13" -})({ - color: 'blue' -}); -var _StyledP4 = styled("p").withConfig({ - displayName: "code___StyledP4", - componentId: "sc-867225be-14" -})`flex: 1;`; -var _StyledP5 = styled("p").withConfig({ - displayName: "code___StyledP5", - componentId: "sc-867225be-15" -})` - color: blue; - `; -var _StyledParagraph = styled(Paragraph).withConfig({ - displayName: "code___StyledParagraph", - componentId: "sc-867225be-16" -})`flex: 1`; -var _StyledP6 = styled("p").withConfig({ - displayName: "code___StyledP6", - componentId: "sc-867225be-17" -})`${(p)=>p.$_css}`; -var _StyledP7 = styled("p").withConfig({ - displayName: "code___StyledP7", - componentId: "sc-867225be-18" -})` - background: ${(p)=>p.$_css2}; - `; -var _StyledP8 = styled("p").withConfig({ - displayName: "code___StyledP8", - componentId: "sc-867225be-19" -})` - color: ${(props1)=>props1.theme.a}; - `; -var _StyledP9 = styled("p").withConfig({ - displayName: "code___StyledP9", - componentId: "sc-867225be-20" -})` - border-radius: ${radius}px; - `; -var _StyledP10 = styled("p").withConfig({ - displayName: "code___StyledP10", - componentId: "sc-867225be-21" -})` - color: ${(p)=>p.$_css3}; - `; -var _StyledP11 = styled("p").withConfig({ - displayName: "code___StyledP11", - componentId: "sc-867225be-22" -})` - color: ${(props1)=>props1.theme.color}; - `; -var _StyledButtonGhost = styled(Button.Ghost).withConfig({ - displayName: "code___StyledButtonGhost", - componentId: "sc-867225be-23" -})`flex: 1`; -var _StyledButtonGhostNew = styled(Button.Ghost.New).withConfig({ - displayName: "code___StyledButtonGhostNew", - componentId: "sc-867225be-24" -})`flex: 1`; -var _StyledButtonGhost2 = styled(button.ghost).withConfig({ - displayName: "code___StyledButtonGhost2", - componentId: "sc-867225be-25" -})`flex: 1`; -var _StyledButtonGhost3 = styled("button-ghost").withConfig({ - displayName: "code___StyledButtonGhost3", - componentId: "sc-867225be-26" -})`flex: 1`; -var _StyledP12 = styled("p").withConfig({ - displayName: "code___StyledP12", - componentId: "sc-867225be-27" -})((p)=>({ - background: p.$_css4, - color: p.$_css5, - textAlign: 'left', - '::before': { - content: p.$_css6 - }, - '::after': { - content: p.$_css7 - } - })); -var _StyledP13 = styled("p").withConfig({ - displayName: "code___StyledP13", - componentId: "sc-867225be-28" -})((p)=>({ - ...{ - '::before': { - content: p.$_css8 - }, - '::after': { - content: p.$_css9 - }, - ...{ - '::before': { - content: p.$_css10 - }, - '::after': { - content: p.$_css11 - } - } - }, - background: p.$_css12, - textAlign: 'left', - '::before': { - content: p.$_css13 - }, - '::after': { - content: p.$_css14 - } - })); -var _StyledP14 = styled("p").withConfig({ - displayName: "code___StyledP14", - componentId: "sc-867225be-29" -})((p)=>({ - color: p.$_css15 - })); -var _StyledDiv = styled("div").withConfig({ - displayName: "code___StyledDiv", - componentId: "sc-867225be-30" -})((p)=>({ - ...p.$_css20, - ...p.$_css21 - })); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop/code.js deleted file mode 100644 index 501bab0522f7f..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop/code.js +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Basic fixtures - */ - -const StaticString = p =>

A

- -const StaticTemplate = p => ( -

- A -

-) - -const ObjectProp = p =>

A

- -const NoChildren = p =>

- -const CssHelperProp = p => ( -

- A -

-) - -/* - * Dynamic prop - */ - -const CustomComp = p => H - -const DynamicProp = p =>

H

- -const LocalInterpolation = p => ( -

- H -

-) - -const FuncInterpolation = p => ( -

props.theme.a}; - `} - > - H -

-) - -const radius = 10 -const GlobalInterpolation = p => ( -

- H -

-) - -const LocalCssHelperProp = p => ( -

- A -

-) - -const DynamicCssHelperProp = p => ( -

props.theme.color}; - `} - > - A -

-) - -const CustomCompWithDot = p => H - -const NestedCompWithDot = p => ( - H -) - -const CustomCompWithDotLowerCase = p => ( - H -) - -const CustomElement = p => H - -/* styled component defined after function it's used in */ - -const EarlyUsageComponent = p => - -const Thing3 = styled.div` - color: blue; -` - -const ObjectInterpolation = p => { - const theme = useTheme() - - return ( -

- H -

- ) -} - -const ObjectInterpolationCustomComponent = p => { - const theme = useTheme() - - return ( - - H - - ) -} - -const ObjectInterpolationInKey = p => { - const theme = useTheme() - - return ( - - H - - ) -} - -const ObjectFnInterpolationInKey = p => { - const theme = useTheme() - - return ( - - H - - ) -} - -const ObjectFnSimpleInterpolationInKey = p => { - const foo = '@media screen and (max-width: 600px)' - - return ( - - H - - ) -} - -const ObjectPropMixedInputs = p => { - const color = 'red' - - return ( -

- A -

- ) -} - -const ObjectPropWithSpread = () => { - const css = { color: 'red' } - const playing = true - - return ( -
- ) -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop/config.json deleted file mode 100644 index ca4eac71a785b..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop/config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": false, - "minify": false, - "cssProp": true -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop/output.js deleted file mode 100644 index 149faa8c81854..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-css-prop/output.js +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Basic fixtures - */ import _styled from "styled-components"; -const StaticString = (p)=><_StyledP >A; -const StaticTemplate = (p)=><_StyledP2 > - - A - - ; -const ObjectProp = (p)=><_StyledP3 >A; -const NoChildren = (p)=><_StyledP4 />; -const CssHelperProp = (p)=><_StyledP5 > - - A - - ; -/* - * Dynamic prop - */ const CustomComp = (p)=><_StyledParagraph >H; -const DynamicProp = (p)=><_StyledP6 $_css={props.cssText}>H; -const LocalInterpolation = (p)=><_StyledP7 $_css2={props.bg}> - - H - - ; -const FuncInterpolation = (p)=><_StyledP8 > - - H - - ; -const radius = 10; -const GlobalInterpolation = (p)=><_StyledP9 > - - H - - ; -const LocalCssHelperProp = (p)=><_StyledP10 $_css3={p.color}> - - A - - ; -const DynamicCssHelperProp = (p)=><_StyledP11 > - - A - - ; -const CustomCompWithDot = (p)=><_StyledButtonGhost >H; -const NestedCompWithDot = (p)=><_StyledButtonGhostNew >H; -const CustomCompWithDotLowerCase = (p)=><_StyledButtonGhost2 >H; -const CustomElement = (p)=><_StyledButtonGhost3 >H; -/* styled component defined after function it's used in */ const EarlyUsageComponent = (p)=><_StyledThing />; -const Thing3 = styled.div` - color: blue; -`; -var _StyledThing5 = _styled(Thing3)((p)=>({ - [p.$_css8]: { - color: 'red' - } - })); -var _StyledThing4 = _styled(Thing3)((p)=>({ - [p.$_css7]: { - color: 'red' - } - })); -var _StyledThing3 = _styled(Thing3)((p)=>({ - [p.$_css6]: { - color: 'red' - } - })); -var _StyledThing2 = _styled(Thing3)((p)=>({ - color: p.$_css5 - })); -var _StyledThing = _styled(Thing3)`color: red;`; -const ObjectInterpolation = (p)=>{ - const theme = useTheme(); - return <_StyledP12 $_css4={theme.colors.red}> - - H - - ; -}; -const ObjectInterpolationCustomComponent = (p)=>{ - const theme = useTheme(); - return <_StyledThing2 $_css5={theme.colors.red}> - - H - - ; -}; -const ObjectInterpolationInKey = (p)=>{ - const theme = useTheme(); - return <_StyledThing3 $_css6={theme.breakpoints.md}> - - H - - ; -}; -const ObjectFnInterpolationInKey = (p)=>{ - const theme = useTheme(); - return <_StyledThing4 $_css7={theme.breakpoints.md()}> - - H - - ; -}; -const ObjectFnSimpleInterpolationInKey = (p)=>{ - const foo = '@media screen and (max-width: 600px)'; - return <_StyledThing5 $_css8={foo}> - - H - - ; -}; -const ObjectPropMixedInputs = (p)=>{ - const color = 'red'; - return <_StyledP13 $_css9={p.background} $_css10={color} $_css11={globalVar} $_css12={getAfterValue()}> - - A - - ; -}; -const ObjectPropWithSpread = ()=>{ - const css = { - color: 'red' - }; - const playing = true; - return <_StyledDiv $_css13={css} $_css14={playing ? { - opacity: 0, - bottom: '-100px' - } : {}}/>; -}; -var _StyledP = _styled("p")`flex: 1;`; -var _StyledP2 = _styled("p")` - flex: 1; - `; -var _StyledP3 = _styled("p")({ - color: 'blue' -}); -var _StyledP4 = _styled("p")`flex: 1;`; -var _StyledP5 = _styled("p")` - color: blue; - `; -var _StyledParagraph = _styled(Paragraph)`flex: 1`; -var _StyledP6 = _styled("p")`${(p)=>p.$_css}`; -var _StyledP7 = _styled("p")` - background: ${(p)=>p.$_css2}; - `; -var _StyledP8 = _styled("p")` - color: ${(props1)=>props1.theme.a}; - `; -var _StyledP9 = _styled("p")` - border-radius: ${radius}px; - `; -var _StyledP10 = _styled("p")` - color: ${(p)=>p.$_css3}; - `; -var _StyledP11 = _styled("p")` - color: ${(props1)=>props1.theme.color}; - `; -var _StyledButtonGhost = _styled(Button.Ghost)`flex: 1`; -var _StyledButtonGhostNew = _styled(Button.Ghost.New)`flex: 1`; -var _StyledButtonGhost2 = _styled(button.ghost)`flex: 1`; -var _StyledButtonGhost3 = _styled("button-ghost")`flex: 1`; -var _StyledP12 = _styled("p")((p)=>({ - color: p.$_css4 - })); -var _StyledP13 = _styled("p")((p)=>({ - background: p.$_css9, - color: p.$_css10, - textAlign: 'left', - '::before': { - content: p.$_css11 - }, - '::after': { - content: p.$_css12 - } - })); -var _StyledDiv = _styled("div")((p)=>({ - ...p.$_css13, - ...p.$_css14 - })); diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-require-default/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-require-default/code.js deleted file mode 100644 index 87ae1495097ed..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-require-default/code.js +++ /dev/null @@ -1,13 +0,0 @@ -const styled_default = require("styled-components"); - -const TestNormal = styled.div` - width: 100%; -` - -const Test = styled_default.default.div` - width: 100%; -` - -const TestCallExpression = styled_default.default(Test)` - height: 20px; -` \ No newline at end of file diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-require-default/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-require-default/config.json deleted file mode 100644 index 0967ef424bce6..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-require-default/config.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-require-default/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/transpile-require-default/output.js deleted file mode 100644 index 3089326d8ead9..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/transpile-require-default/output.js +++ /dev/null @@ -1,19 +0,0 @@ -const styled_default = require("styled-components"); -const TestNormal = styled.div.withConfig({ - displayName: "code__TestNormal", - componentId: "sc-1dd7c523-0" -})` - width: 100%; -`; -const Test = styled_default.default.div.withConfig({ - displayName: "code__Test", - componentId: "sc-1dd7c523-1" -})` - width: 100%; -`; -const TestCallExpression = styled_default.default(Test).withConfig({ - displayName: "code__TestCallExpression", - componentId: "sc-1dd7c523-2" -})` - height: 20px; -`; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/use-file-name/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/use-file-name/code.js deleted file mode 100644 index e656c5d565db3..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/use-file-name/code.js +++ /dev/null @@ -1,6 +0,0 @@ -import styled from "styled-components"; - -const Test = styled.div`color: red;`; -const before = styled.div`color: blue;`; -styled.div``; -export default styled.button``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/use-file-name/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/use-file-name/config.json deleted file mode 100644 index 2c6790858b11d..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/use-file-name/config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "transpileTemplateLiterals": false, - "ssr": true -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/use-file-name/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/use-file-name/output.js deleted file mode 100644 index b382d2770eb61..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/use-file-name/output.js +++ /dev/null @@ -1,17 +0,0 @@ -import styled from "styled-components"; -const Test = styled.div.withConfig({ - displayName: "code__Test", - componentId: "sc-a2611da4-0" -})`color: red;`; -const before = styled.div.withConfig({ - displayName: "code__before", - componentId: "sc-a2611da4-1" -})`color: blue;`; -styled.div.withConfig({ - displayName: "code", - componentId: "sc-a2611da4-2" -})``; -export default styled.button.withConfig({ - displayName: "code", - componentId: "sc-a2611da4-3" -})``; diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/use-namespace/code.js b/packages/next-swc/crates/styled_components/tests/fixtures/use-namespace/code.js deleted file mode 100644 index 85b62c77bf5a8..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/use-namespace/code.js +++ /dev/null @@ -1,23 +0,0 @@ -import * as styled from 'styled-components' - -const css = styled.css` - background: black; -` - -const GlobalStyle = styled.createGlobalStyle` - html { - background: black; - } -` - -const Test = styled.default.div` - color: red; -` - -const before = styled.default.div` - color: blue; -` - -styled.default.div`` - -export default styled.default.button`` diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/use-namespace/config.json b/packages/next-swc/crates/styled_components/tests/fixtures/use-namespace/config.json deleted file mode 100644 index 0a590a53a0356..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/use-namespace/config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "namespace": "test-namespace" -} diff --git a/packages/next-swc/crates/styled_components/tests/fixtures/use-namespace/output.js b/packages/next-swc/crates/styled_components/tests/fixtures/use-namespace/output.js deleted file mode 100644 index 5d9ba2732bfbf..0000000000000 --- a/packages/next-swc/crates/styled_components/tests/fixtures/use-namespace/output.js +++ /dev/null @@ -1,29 +0,0 @@ -import * as styled from 'styled-components'; -const css = styled.css` - background: black; -`; -const GlobalStyle = styled.createGlobalStyle` - html { - background: black; - } -`; -const Test = styled.default.div.withConfig({ - displayName: "code__Test", - componentId: "test-namespace__sc-d9ced075-0" -})` - color: red; -`; -const before = styled.default.div.withConfig({ - displayName: "code__before", - componentId: "test-namespace__sc-d9ced075-1" -})` - color: blue; -`; -styled.default.div.withConfig({ - displayName: "code", - componentId: "test-namespace__sc-d9ced075-2" -})``; -export default styled.default.button.withConfig({ - displayName: "code", - componentId: "test-namespace__sc-d9ced075-3" -})``; diff --git a/packages/next-swc/crates/styled_jsx/Cargo.toml b/packages/next-swc/crates/styled_jsx/Cargo.toml deleted file mode 100644 index cd83659d98db3..0000000000000 --- a/packages/next-swc/crates/styled_jsx/Cargo.toml +++ /dev/null @@ -1,33 +0,0 @@ -[package] -authors = ["강동윤 "] -description = "AST transforms for styled-jsx" -edition = "2018" -license = "Apache-2.0" -name = "styled_jsx" -repository = "https://github.com/vercel/next.js.git" -version = "0.20.0" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -easy-error = "1.0.0" -tracing = "0.1.32" - -swc_core = { features = [ - "common", - "css_ast", - "css_codegen", - "css_parser", - "css_prefixer", - "css_visit", - "ecma_parser", - "ecma_minifier", - "ecma_utils", - "ecma_visit" -], version = "0.39.7" } - -[dev-dependencies] -testing = "0.31.9" -swc_core = { features = [ - "testing_transform" -], version = "0.39.7" } diff --git a/packages/next-swc/crates/styled_jsx/src/lib.rs b/packages/next-swc/crates/styled_jsx/src/lib.rs deleted file mode 100644 index bbf88931d63c4..0000000000000 --- a/packages/next-swc/crates/styled_jsx/src/lib.rs +++ /dev/null @@ -1,935 +0,0 @@ -#![feature(box_patterns)] - -use easy_error::{bail, Error}; -use std::collections::hash_map::DefaultHasher; -use std::hash::{Hash, Hasher}; -use std::mem::take; -use std::sync::Arc; - -use swc_core::{ - common::{collections::AHashSet, errors::HANDLER, FileName, SourceMap, Span, DUMMY_SP}, - ecma::ast::*, - ecma::minifier::{ - eval::{EvalResult, Evaluator}, - marks::Marks, - }, - ecma::utils::{collect_decls, drop_span, prepend_stmt, private_ident}, - ecma::visit::{Fold, FoldWith}, -}; - -//use external::external_styles; -use transform_css::transform_css; -use utils::*; - -mod transform_css; -mod utils; - -pub fn styled_jsx(cm: Arc, file_name: FileName) -> impl Fold { - let file_name = match file_name { - FileName::Real(real_file_name) => real_file_name - .to_str() - .map(|real_file_name| real_file_name.to_string()), - _ => None, - }; - - StyledJSXTransformer { - cm, - file_name, - styles: Default::default(), - static_class_name: Default::default(), - class_name: Default::default(), - file_has_styled_jsx: Default::default(), - has_styled_jsx: Default::default(), - bindings: Default::default(), - nearest_scope_bindings: Default::default(), - func_scope_level: Default::default(), - style_import_name: Default::default(), - external_bindings: Default::default(), - file_has_css_resolve: Default::default(), - external_hash: Default::default(), - add_hash: Default::default(), - add_default_decl: Default::default(), - in_function_params: Default::default(), - evaluator: Default::default(), - visiting_styled_jsx_descendants: Default::default(), - } -} - -struct StyledJSXTransformer { - cm: Arc, - file_name: Option, - styles: Vec, - static_class_name: Option, - class_name: Option, - file_has_styled_jsx: bool, - has_styled_jsx: bool, - bindings: AHashSet, - nearest_scope_bindings: AHashSet, - func_scope_level: u8, - style_import_name: Option, - external_bindings: Vec, - file_has_css_resolve: bool, - external_hash: Option, - add_hash: Option<(Id, String)>, - add_default_decl: Option<(Id, Expr)>, - in_function_params: bool, - evaluator: Option, - visiting_styled_jsx_descendants: bool, -} - -pub struct LocalStyle { - hash: String, - css: String, - css_span: Span, - is_dynamic: bool, - #[allow(clippy::vec_box)] - expressions: Vec>, -} - -pub struct ExternalStyle { - expr: Expr, - identifier: Ident, - is_global: bool, -} - -pub enum JSXStyle { - Local(LocalStyle), - External(ExternalStyle), -} - -enum StyleExpr<'a> { - Str(&'a Str), - Tpl(&'a Tpl, &'a Expr), - Ident(&'a Ident), -} - -impl Fold for StyledJSXTransformer { - fn fold_jsx_element(&mut self, el: JSXElement) -> JSXElement { - if is_styled_jsx(&el) { - if self.visiting_styled_jsx_descendants { - HANDLER.with(|handler| { - handler - .struct_span_err( - el.span, - "Detected nested styled-jsx tag.\nRead more: https://nextjs.org/docs/messages/nested-styled-jsx-tags", - ) - .emit() - }); - return el; - } - - let parent_has_styled_jsx = self.has_styled_jsx; - if !parent_has_styled_jsx && self.check_for_jsx_styles(Some(&el), &el.children).is_err() - { - return el; - } - let el = match self.replace_jsx_style(&el) { - Ok(el) => el, - Err(_) => el, - }; - if !parent_has_styled_jsx { - self.reset_styles_state(); - } - return el; - } - - if self.has_styled_jsx { - self.visiting_styled_jsx_descendants = true; - let el = el.fold_children_with(self); - self.visiting_styled_jsx_descendants = false; - return el; - } - - if self.check_for_jsx_styles(None, &el.children).is_err() { - return el; - } - let el = el.fold_children_with(self); - self.reset_styles_state(); - - el - } - - fn fold_jsx_fragment(&mut self, fragment: JSXFragment) -> JSXFragment { - if self.has_styled_jsx { - self.visiting_styled_jsx_descendants = true; - let fragment = fragment.fold_children_with(self); - self.visiting_styled_jsx_descendants = false; - return fragment; - } - - if self.check_for_jsx_styles(None, &fragment.children).is_err() { - return fragment; - }; - let fragment = fragment.fold_children_with(self); - self.reset_styles_state(); - - fragment - } - - fn fold_jsx_opening_element(&mut self, mut el: JSXOpeningElement) -> JSXOpeningElement { - if !self.has_styled_jsx { - return el; - } - - el.attrs = el.attrs.fold_with(self); - - if let JSXElementName::Ident(Ident { sym, span, .. }) = &el.name { - if sym != "style" - && sym != self.style_import_name.as_ref().unwrap() - && (!is_capitalized(sym) - || self - .nearest_scope_bindings - .contains(&(sym.clone(), span.ctxt))) - { - let (existing_class_name, existing_index, existing_spread_index) = - get_existing_class_name(&el); - - let new_class_name = match (existing_class_name, &self.class_name) { - (Some(existing_class_name), Some(class_name)) => Some(add( - add(class_name.clone(), string_literal_expr(" ")), - existing_class_name, - )), - (Some(existing_class_name), None) => Some(existing_class_name), - (None, Some(class_name)) => Some(class_name.clone()), - _ => None, - }; - - if let Some(new_class_name) = new_class_name { - let class_name_attr = JSXAttrOrSpread::JSXAttr(JSXAttr { - span: DUMMY_SP, - name: JSXAttrName::Ident(ident("className")), - value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(Box::new(new_class_name)), - span: DUMMY_SP, - })), - }); - el.attrs.push(class_name_attr); - } - if let Some(existing_spread_index) = existing_spread_index { - el.attrs.remove(existing_spread_index); - } - if let Some(existing_index) = existing_index { - el.attrs.remove(existing_index); - } - } - } - - el - } - - fn fold_import_decl(&mut self, decl: ImportDecl) -> ImportDecl { - let ImportDecl { - ref src, - ref specifiers, - .. - } = decl; - if &src.value == "styled-jsx/css" { - for specifier in specifiers { - match specifier { - ImportSpecifier::Default(default_specifier) => { - self.external_bindings.push(default_specifier.local.to_id()) - } - ImportSpecifier::Named(named_specifier) => { - self.external_bindings.push(named_specifier.local.to_id()) - } - _ => {} - } - } - } - - decl - } - - fn fold_expr(&mut self, expr: Expr) -> Expr { - let expr = expr.fold_children_with(self); - match expr { - Expr::TaggedTpl(tagged_tpl) => match &*tagged_tpl.tag { - Expr::Ident(identifier) => { - if self.external_bindings.contains(&identifier.to_id()) { - match self.process_tagged_template_expr(&tagged_tpl, &identifier.sym) { - Ok(expr) => expr, - Err(_) => Expr::TaggedTpl(tagged_tpl), - } - } else { - Expr::TaggedTpl(tagged_tpl) - } - } - Expr::Member(MemberExpr { - obj: boxed_ident, .. - }) => { - if let Expr::Ident(identifier) = &**boxed_ident { - if self.external_bindings.contains(&identifier.to_id()) { - match self.process_tagged_template_expr(&tagged_tpl, &identifier.sym) { - Ok(expr) => expr, - Err(_) => Expr::TaggedTpl(tagged_tpl), - } - } else { - Expr::TaggedTpl(tagged_tpl) - } - } else { - Expr::TaggedTpl(tagged_tpl) - } - } - _ => Expr::TaggedTpl(tagged_tpl), - }, - expr => expr, - } - } - - fn fold_var_declarator(&mut self, declarator: VarDeclarator) -> VarDeclarator { - let declarator = declarator.fold_children_with(self); - if let Some(external_hash) = &self.external_hash.take() { - if let Pat::Ident(BindingIdent { - id: Ident { span, sym, .. }, - .. - }) = &declarator.name - { - self.add_hash = Some(((sym.clone(), span.ctxt), external_hash.clone())); - } - } - declarator - } - - fn fold_export_default_expr(&mut self, default_expr: ExportDefaultExpr) -> ExportDefaultExpr { - let default_expr = default_expr.fold_children_with(self); - if let Some(external_hash) = &self.external_hash.take() { - let default_ident = private_ident!("_defaultExport"); - self.add_hash = Some((default_ident.to_id(), external_hash.clone())); - self.add_default_decl = Some((default_ident.to_id(), *default_expr.expr)); - return ExportDefaultExpr { - expr: Box::new(Expr::Ident(default_ident)), - span: DUMMY_SP, - }; - } - default_expr - } - - fn fold_block_stmt(&mut self, mut block: BlockStmt) -> BlockStmt { - let mut new_stmts = vec![]; - for stmt in block.stmts { - new_stmts.push(stmt.fold_children_with(self)); - if let Some(add_hash) = self.add_hash.take() { - new_stmts.push(add_hash_statement(add_hash)); - } - } - - block.stmts = new_stmts; - block - } - - fn fold_module_items(&mut self, items: Vec) -> Vec { - let mut new_items = vec![]; - for item in items { - let new_item = item.fold_children_with(self); - if let Some((default_ident, default_expr)) = &self.add_default_decl { - new_items.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl { - kind: VarDeclKind::Const, - declare: false, - decls: vec![VarDeclarator { - name: Pat::Ident(BindingIdent { - id: Ident { - sym: default_ident.0.clone(), - span: DUMMY_SP.with_ctxt(default_ident.1), - optional: false, - }, - type_ann: None, - }), - init: Some(Box::new(default_expr.clone())), - definite: false, - span: DUMMY_SP, - }], - span: DUMMY_SP, - }))))); - self.add_default_decl = None; - if let Some(add_hash) = self.add_hash.take() { - new_items.push(ModuleItem::Stmt(add_hash_statement(add_hash))); - } - } - if !is_styled_css_import(&new_item) { - new_items.push(new_item); - } - if let Some(add_hash) = self.add_hash.take() { - new_items.push(ModuleItem::Stmt(add_hash_statement(add_hash))); - } - } - - if self.file_has_styled_jsx || self.file_has_css_resolve { - prepend_stmt( - &mut new_items, - styled_jsx_import_decl(self.style_import_name.as_ref().unwrap()), - ); - } - - new_items - } - - fn fold_binding_ident(&mut self, node: BindingIdent) -> BindingIdent { - if self.in_function_params { - self.nearest_scope_bindings.insert(node.id.to_id()); - } - node - } - - fn fold_assign_pat_prop(&mut self, node: AssignPatProp) -> AssignPatProp { - if self.in_function_params { - self.nearest_scope_bindings.insert(node.key.to_id()); - } - node - } - - fn fold_function(&mut self, mut func: Function) -> Function { - self.func_scope_level += 1; - let surrounding_scope_bindings = take(&mut self.nearest_scope_bindings); - self.in_function_params = true; - let mut new_params = vec![]; - for param in func.params { - new_params.push(param.fold_with(self)); - } - func.params = new_params; - self.in_function_params = false; - self.nearest_scope_bindings.extend(collect_decls(&func)); - func.body = func.body.fold_with(self); - self.nearest_scope_bindings = surrounding_scope_bindings; - self.func_scope_level -= 1; - func - } - - fn fold_arrow_expr(&mut self, mut func: ArrowExpr) -> ArrowExpr { - self.func_scope_level += 1; - let surrounding_scope_bindings = take(&mut self.nearest_scope_bindings); - self.in_function_params = true; - let mut new_params = vec![]; - for param in func.params { - new_params.push(param.fold_with(self)); - } - func.params = new_params; - self.in_function_params = false; - self.nearest_scope_bindings.extend(collect_decls(&func)); - func.body = func.body.fold_with(self); - self.nearest_scope_bindings = surrounding_scope_bindings; - self.func_scope_level -= 1; - func - } - - fn fold_module(&mut self, module: Module) -> Module { - self.bindings = collect_decls(&module); - self.evaluator = Some(Evaluator::new(module.clone(), Marks::new())); - self.style_import_name = Some(get_usable_import_specifier(&module.body)); - let module = module.fold_children_with(self); - if self.file_has_css_resolve - && self.file_name.is_some() - && self.file_name.as_ref().unwrap().ends_with(".ts") - { - let file_name: &str = self.file_name.as_ref().unwrap(); - HANDLER.with(|handler| { - handler.err(&format!( - "{} uses `css.resolve`, but ends with `.ts`. The file extension needs to be \ - `.tsx` so that the jsx injected by `css.resolve` will be transformed.", - file_name - )); - }); - } - module - } -} - -impl StyledJSXTransformer { - fn check_for_jsx_styles( - &mut self, - el: Option<&JSXElement>, - children: &[JSXElementChild], - ) -> Result<(), Error> { - let mut styles = vec![]; - let mut process_style = |el: &JSXElement| { - self.file_has_styled_jsx = true; - self.has_styled_jsx = true; - let expr = get_style_expr(el)?; - let style_info = self.get_jsx_style(expr, is_global(el)); - styles.insert(0, style_info); - - Ok(()) - }; - - if el.is_some() && is_styled_jsx(el.unwrap()) { - process_style(el.unwrap())?; - } else { - for i in children { - if let JSXElementChild::JSXElement(child_el) = &i { - if is_styled_jsx(child_el) { - process_style(child_el)?; - } - } - } - }; - - if self.has_styled_jsx { - let (static_class_name, class_name) = - compute_class_names(&styles, self.style_import_name.as_ref().unwrap()); - self.styles = styles; - self.static_class_name = static_class_name; - self.class_name = class_name; - } - - Ok(()) - } - - fn get_jsx_style(&mut self, style_expr: StyleExpr, is_global_jsx_element: bool) -> JSXStyle { - let mut hasher = DefaultHasher::new(); - let css: String; - let css_span: Span; - let is_dynamic; - let mut expressions = vec![]; - match style_expr { - StyleExpr::Str(Str { value, span, .. }) => { - hasher.write(value.as_ref().as_bytes()); - css = value.to_string(); - css_span = *span; - is_dynamic = false; - } - StyleExpr::Tpl( - Tpl { - exprs, - quasis, - span, - }, - expr, - ) => { - if exprs.is_empty() { - hasher.write(quasis[0].raw.as_bytes()); - css = quasis[0].raw.to_string(); - css_span = *span; - is_dynamic = false; - } else { - drop_span(expr.clone()).hash(&mut hasher); - let mut s = String::new(); - for i in 0..quasis.len() { - let placeholder = if i == quasis.len() - 1 { - String::new() - } else { - format!("__styled-jsx-placeholder-{}__", i) - }; - s = format!("{}{}{}", s, quasis[i].raw, placeholder) - } - css = s; - css_span = *span; - is_dynamic = if self.func_scope_level > 0 { - let res = self.evaluator.as_mut().unwrap().eval(expr); - !matches!(res, Some(EvalResult::Lit(_))) - } else { - false - }; - expressions = exprs.clone(); - } - } - StyleExpr::Ident(ident) => { - return JSXStyle::External(ExternalStyle { - expr: Expr::Member(MemberExpr { - obj: Box::new(Expr::Ident(ident.clone())), - prop: MemberProp::Ident(Ident { - sym: "__hash".into(), - span: DUMMY_SP, - optional: false, - }), - span: DUMMY_SP, - }), - identifier: ident.clone(), - is_global: is_global_jsx_element, - }); - } - } - - JSXStyle::Local(LocalStyle { - hash: format!("{:x}", hasher.finish()), - css, - css_span, - is_dynamic, - expressions, - }) - } - - fn replace_jsx_style(&mut self, el: &JSXElement) -> Result { - let style_info = self.styles.pop().unwrap(); - - let is_global = el.opening.attrs.iter().any(|attr| { - if let JSXAttrOrSpread::JSXAttr(JSXAttr { - name: JSXAttrName::Ident(Ident { sym, .. }), - .. - }) = &attr - { - if sym == "global" { - return true; - } - } - false - }); - - match &style_info { - JSXStyle::Local(style_info) => { - let css = transform_css( - self.cm.clone(), - style_info, - is_global, - &self.static_class_name, - )?; - Ok(make_local_styled_jsx_el( - style_info, - css, - self.style_import_name.as_ref().unwrap(), - self.static_class_name.as_ref(), - )) - } - JSXStyle::External(style) => Ok(make_external_styled_jsx_el( - style, - self.style_import_name.as_ref().unwrap(), - )), - } - } - - fn process_tagged_template_expr( - &mut self, - tagged_tpl: &TaggedTpl, - tag: &str, - ) -> Result { - if tag != "resolve" { - // Check whether there are undefined references or - // references to this.something (e.g. props or state). - // We allow dynamic styles only when resolving styles. - } - - let style = self.get_jsx_style( - StyleExpr::Tpl(&tagged_tpl.tpl, &Expr::Tpl(tagged_tpl.tpl.clone())), - false, - ); - let styles = vec![style]; - let (static_class_name, class_name) = - compute_class_names(&styles, self.style_import_name.as_ref().unwrap()); - let tag = match &*tagged_tpl.tag { - Expr::Ident(Ident { sym, .. }) => sym.to_string(), - Expr::Member(MemberExpr { - prop: MemberProp::Ident(Ident { sym, .. }), - .. - }) => sym.to_string(), - _ => String::from("not_styled_jsx_tag"), - }; - let style = if let JSXStyle::Local(style) = &styles[0] { - if tag != "resolve" { - self.external_hash = Some(hash_string(&style.hash.clone())); - } - style - } else { - bail!("This shouldn't happen, we already know that this is a template literal"); - }; - let css = transform_css(self.cm.clone(), style, tag == "global", &static_class_name)?; - if tag == "resolve" { - self.file_has_css_resolve = true; - return Ok(Expr::Object(ObjectLit { - props: vec![ - PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { - key: PropName::Ident(Ident { - sym: "styles".into(), - span: DUMMY_SP, - optional: false, - }), - value: Box::new(Expr::JSXElement(Box::new(make_local_styled_jsx_el( - style, - css, - self.style_import_name.as_ref().unwrap(), - self.static_class_name.as_ref(), - )))), - }))), - PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { - key: PropName::Ident(Ident { - sym: "className".into(), - span: DUMMY_SP, - optional: false, - }), - value: Box::new(class_name.unwrap()), - }))), - ], - span: DUMMY_SP, - })); - } - Ok(Expr::New(NewExpr { - callee: Box::new(Expr::Ident(Ident { - sym: "String".into(), - span: DUMMY_SP, - optional: false, - })), - args: Some(vec![ExprOrSpread { - expr: Box::new(css), - spread: None, - }]), - span: DUMMY_SP, - type_args: None, - })) - } - - fn reset_styles_state(&mut self) { - self.has_styled_jsx = false; - self.static_class_name = None; - self.class_name = None; - self.styles = vec![]; - } -} - -fn is_styled_jsx(el: &JSXElement) -> bool { - if let JSXElementName::Ident(Ident { sym, .. }) = &el.opening.name { - if sym != "style" { - return false; - } - } - - el.opening.attrs.iter().any(|attr| { - if let JSXAttrOrSpread::JSXAttr(JSXAttr { - name: JSXAttrName::Ident(Ident { sym, .. }), - .. - }) = &attr - { - if sym == "jsx" { - return true; - } - } - false - }) -} - -fn is_global(el: &JSXElement) -> bool { - if let JSXElementName::Ident(Ident { sym, .. }) = &el.opening.name { - if sym != "style" { - return false; - } - } - - el.opening.attrs.iter().any(|attr| { - if let JSXAttrOrSpread::JSXAttr(JSXAttr { - name: JSXAttrName::Ident(Ident { sym, .. }), - .. - }) = &attr - { - if sym == "global" { - return true; - } - } - false - }) -} - -fn get_style_expr(el: &JSXElement) -> Result { - let non_whitespace_children: &Vec<&JSXElementChild> = &el - .children - .iter() - .filter(|child| { - if let JSXElementChild::JSXText(txt) = child { - if txt.value.chars().all(char::is_whitespace) { - return false; - } - } - true - }) - .collect(); - - if non_whitespace_children.len() != 1 { - HANDLER.with(|handler| { - handler - .struct_span_err( - el.span, - &format!( - "Expected one child under JSX style tag, but got {}.\nRead more: https://nextjs.org/docs/messages/invalid-styled-jsx-children", - non_whitespace_children.len() - ), - ) - .emit() - }); - bail!("styled-jsx style error"); - } - - if let JSXElementChild::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(expr), - .. - }) = non_whitespace_children[0] - { - return Ok(match &**expr { - Expr::Lit(Lit::Str(str)) => StyleExpr::Str(str), - Expr::Tpl(tpl) => StyleExpr::Tpl(tpl, expr), - Expr::Ident(ident) => StyleExpr::Ident(ident), - _ => { - HANDLER.with(|handler| { - handler - .struct_span_err( - el.span, - "Expected a template literal, string or identifier inside the JSXExpressionContainer.\nRead more: https://nextjs.org/docs/messages/invalid-styled-jsx-children", - ) - .emit() - }); - bail!("wrong jsx expression container type"); - } - }); - } - - HANDLER.with(|handler| { - handler - .struct_span_err( - el.span, - "Expected a single child of type JSXExpressionContainer under JSX Style tag.\nRead more: https://nextjs.org/docs/messages/invalid-styled-jsx-children", - ) - .emit() - }); - bail!("next-swc compilation error"); -} - -fn get_existing_class_name(el: &JSXOpeningElement) -> (Option, Option, Option) { - let mut spreads = vec![]; - let mut class_name_expr = None; - let mut existing_index = None; - let mut existing_spread_index = None; - for i in (0..el.attrs.len()).rev() { - match &el.attrs[i] { - JSXAttrOrSpread::JSXAttr(JSXAttr { - name: JSXAttrName::Ident(Ident { sym, .. }), - value, - .. - }) => { - if sym == "className" { - existing_index = Some(i); - class_name_expr = match value { - Some(JSXAttrValue::Lit(str_lit)) => Some(Expr::Lit(str_lit.clone())), - Some(JSXAttrValue::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(expr), - .. - })) => Some(*expr.clone()), - None => None, - _ => None, - }; - break; - } - } - JSXAttrOrSpread::SpreadElement(SpreadElement { expr, .. }) => { - if let Expr::Object(ObjectLit { props, .. }) = &**expr { - let mut has_spread = false; - let mut has_class_name = false; - for j in 0..props.len() { - if let PropOrSpread::Prop(prop) = &props[j] { - if let Prop::KeyValue(KeyValueProp { - key: PropName::Ident(Ident { sym, .. }), - value, - }) = &**prop - { - if sym == "className" { - has_class_name = true; - class_name_expr = Some(*value.clone()); - if props.len() == 1 { - existing_spread_index = Some(i); - } - } - } - } else { - has_spread = true; - } - } - if has_class_name { - break; - } - if !has_spread { - continue; - } - } - - let valid_spread = matches!(&**expr, Expr::Member(_) | Expr::Ident(_)); - - if valid_spread { - let member_dot_name = Expr::Member(MemberExpr { - obj: Box::new(*expr.clone()), - prop: MemberProp::Ident(ident("className")), - span: DUMMY_SP, - }); - // `${name} && ${name}.className != null && ${name}.className` - spreads.push(and( - and( - *expr.clone(), - not_eq( - member_dot_name.clone(), - Expr::Lit(Lit::Null(Null { span: DUMMY_SP })), - ), - ), - member_dot_name.clone(), - )); - } - } - _ => {} - }; - } - - let spread_expr = match spreads.len() { - 0 => None, - _ => Some(join_spreads(spreads)), - }; - - let class_name_expr = match class_name_expr { - Some(e @ Expr::Tpl(_) | e @ Expr::Lit(Lit::Str(_))) => Some(e), - None => None, - _ => Some(or(class_name_expr.unwrap(), string_literal_expr(""))), - }; - - let existing_class_name_expr = match (spread_expr, class_name_expr) { - (Some(spread_expr), Some(class_name_expr)) => Some(or(spread_expr, class_name_expr)), - (Some(spread_expr), None) => Some(or(spread_expr, string_literal_expr(""))), - (None, Some(class_name_expr)) => Some(class_name_expr), - _ => None, - }; - - ( - existing_class_name_expr, - existing_index, - existing_spread_index, - ) -} - -fn join_spreads(spreads: Vec) -> Expr { - let mut new_expr = spreads[0].clone(); - for i in spreads.iter().skip(1) { - new_expr = Expr::Bin(BinExpr { - op: op!("||"), - left: Box::new(new_expr.clone()), - right: Box::new(i.clone()), - span: DUMMY_SP, - }) - } - new_expr -} - -fn add_hash_statement((id, hash): (Id, String)) -> Stmt { - Stmt::Expr(ExprStmt { - expr: Box::new(Expr::Assign(AssignExpr { - left: PatOrExpr::Expr(Box::new(Expr::Member(MemberExpr { - obj: Box::new(Expr::Ident(Ident { - sym: id.0, - span: DUMMY_SP.with_ctxt(id.1), - optional: false, - })), - prop: MemberProp::Ident(Ident { - sym: "__hash".into(), - span: DUMMY_SP, - optional: false, - }), - span: DUMMY_SP, - }))), - right: Box::new(string_literal_expr(&hash)), - op: op!("="), - span: DUMMY_SP, - })), - span: DUMMY_SP, - }) -} - -fn is_styled_css_import(item: &ModuleItem) -> bool { - if let ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { - src: box Str { value, .. }, - .. - })) = item - { - if value == "styled-jsx/css" { - return true; - } - } - false -} diff --git a/packages/next-swc/crates/styled_jsx/src/transform_css.rs b/packages/next-swc/crates/styled_jsx/src/transform_css.rs deleted file mode 100644 index 93fc1bd6b6ac7..0000000000000 --- a/packages/next-swc/crates/styled_jsx/src/transform_css.rs +++ /dev/null @@ -1,536 +0,0 @@ -use easy_error::{bail, Error}; -use std::panic; -use std::sync::Arc; -use tracing::{debug, trace}; - -use swc_core::{ - common::{ - errors::HANDLER, source_map::Pos, util::take::Take, BytePos, SourceMap, Span, Spanned, - SyntaxContext, DUMMY_SP, - }, - css::prefixer::prefixer, - css::{ - ast::*, - codegen::{ - writer::basic::{BasicCssWriter, BasicCssWriterConfig}, - CodeGenerator, CodegenConfig, Emit, - }, - parser::{ - parse_str, parse_tokens, - parser::{input::Tokens, ParserConfig}, - }, - visit::{VisitMut, VisitMutWith}, - }, - ecma::ast::{Expr, Tpl, TplElement}, - ecma::parser::StringInput, -}; - -use super::{hash_string, string_literal_expr, LocalStyle}; - -pub fn transform_css( - _cm: Arc, - style_info: &LocalStyle, - is_global: bool, - class_name: &Option, -) -> Result { - debug!("CSS: \n{}", style_info.css); - - let result: Result = parse_str( - &style_info.css, - style_info.css_span.lo, - style_info.css_span.hi, - ParserConfig { - allow_wrong_line_comments: true, - ..Default::default() - }, - // We ignore errors because we inject placeholders for expressions which is - // not a valid css. - &mut vec![], - ); - let mut ss = match result { - Ok(ss) => ss, - Err(err) => { - HANDLER.with(|handler| { - // Print css parsing errors - err.to_diagnostics(handler).emit(); - - // TODO(kdy1): We may print css so the user can see the error, and report it. - - handler - .struct_span_err( - style_info.css_span, - "Failed to parse css in styled jsx component", - ) - .note(&format!("Input to the css parser is {}", style_info.css)) - .emit() - }); - bail!("Failed to parse css"); - } - }; - // ? Do we need to support optionally prefixing? - ss.visit_mut_with(&mut prefixer(Default::default())); - ss.visit_mut_with(&mut Namespacer { - class_name: match class_name { - Some(s) => s.clone(), - None => format!("jsx-{}", &hash_string(&style_info.hash)), - }, - is_global, - is_dynamic: style_info.is_dynamic, - }); - - let mut s = String::new(); - { - let mut wr = BasicCssWriter::new(&mut s, None, BasicCssWriterConfig::default()); - let mut gen = CodeGenerator::new(&mut wr, CodegenConfig { minify: true }); - - gen.emit(&ss).unwrap(); - } - - if style_info.expressions.is_empty() { - return Ok(string_literal_expr(&s)); - } - - let mut parts: Vec<&str> = s.split("__styled-jsx-placeholder-").collect(); - let mut final_expressions = vec![]; - for i in parts.iter_mut().skip(1) { - let (num_len, expression_index) = read_number(i); - final_expressions.push(style_info.expressions[expression_index].clone()); - let substr = &i[(num_len + 2)..]; - *i = substr; - } - - Ok(Expr::Tpl(Tpl { - quasis: parts - .iter() - .map(|quasi| { - TplElement { - cooked: None, // ? Do we need cooked as well - raw: quasi.replace('`', "\\`").into(), - span: DUMMY_SP, - tail: false, - } - }) - .collect(), - exprs: final_expressions, - span: DUMMY_SP, - })) -} - -/// Returns `(length, value)` -fn read_number(s: &str) -> (usize, usize) { - for (idx, c) in s.char_indices() { - if c.is_ascii_digit() { - continue; - } - - // For 10, we reach here after `0`. - let value = s[0..idx].parse().expect("failed to parse"); - - return (idx, value); - } - - unreachable!("read_number(`{}`) is invalid because it is empty", s) -} - -struct Namespacer { - class_name: String, - is_global: bool, - is_dynamic: bool, -} - -impl VisitMut for Namespacer { - fn visit_mut_complex_selector(&mut self, node: &mut ComplexSelector) { - #[cfg(debug_assertions)] - let _tracing = { - // This will add information to the log messages, only for debug build. - // Note that we use cargo feature to remove all logging on production builds. - - let mut code = String::new(); - { - let mut wr = BasicCssWriter::new(&mut code, None, BasicCssWriterConfig::default()); - let mut gen = CodeGenerator::new(&mut wr, CodegenConfig { minify: true }); - - gen.emit(&*node).unwrap(); - } - - tracing::span!( - tracing::Level::TRACE, - "Namespacer::visit_mut_complex_selector", - class_name = &*self.class_name, - is_global = self.is_global, - is_dynamic = self.is_dynamic, - input = &*code - ) - .entered() - }; - - let mut new_selectors = vec![]; - let mut combinator = None; - for sel in node.children.take() { - match &sel { - ComplexSelectorChildren::CompoundSelector(selector) => { - match self.get_transformed_selectors(combinator, selector.clone()) { - Ok(transformed_selectors) => new_selectors.extend(transformed_selectors), - Err(_) => { - HANDLER.with(|handler| { - handler - .struct_span_err( - selector.span, - "Failed to transform one off global selector", - ) - .emit() - }); - new_selectors.push(sel); - } - } - - combinator = None; - } - ComplexSelectorChildren::Combinator(v) => { - combinator = Some(v.clone()); - } - }; - } - - node.children = new_selectors; - } -} - -impl Namespacer { - fn get_transformed_selectors( - &mut self, - combinator: Option, - mut node: CompoundSelector, - ) -> Result, Error> { - let mut pseudo_index = None; - let mut arg_tokens; - - for (i, selector) in node.subclass_selectors.iter().enumerate() { - let (name, args) = match selector { - SubclassSelector::PseudoClass(PseudoClassSelector { name, children, .. }) => { - arg_tokens = children - .iter() - .flatten() - .flat_map(|v| match v { - PseudoClassSelectorChildren::PreservedToken(v) => vec![v.clone()], - PseudoClassSelectorChildren::AnPlusB(an_plus_b) => match an_plus_b { - AnPlusB::Ident(v) => to_tokens(v).tokens, - AnPlusB::AnPlusBNotation(v) => to_tokens(v).tokens, - }, - PseudoClassSelectorChildren::Ident(v) => to_tokens(v).tokens, - PseudoClassSelectorChildren::Str(v) => to_tokens(v).tokens, - PseudoClassSelectorChildren::Delimiter(v) => to_tokens(v).tokens, - PseudoClassSelectorChildren::SelectorList(v) => to_tokens(v).tokens, - PseudoClassSelectorChildren::CompoundSelectorList(v) => { - to_tokens(v).tokens - } - PseudoClassSelectorChildren::RelativeSelectorList(v) => { - to_tokens(v).tokens - } - PseudoClassSelectorChildren::CompoundSelector(v) => to_tokens(v).tokens, - PseudoClassSelectorChildren::ForgivingSelectorList(v) => { - to_tokens(v).tokens - } - PseudoClassSelectorChildren::ForgivingRelativeSelectorList(v) => { - to_tokens(v).tokens - } - PseudoClassSelectorChildren::ComplexSelector(v) => to_tokens(v).tokens, - }) - .collect::>(); - - (name, &arg_tokens) - } - SubclassSelector::PseudoElement(PseudoElementSelector { - name, children, .. - }) => { - arg_tokens = children - .iter() - .flatten() - .flat_map(|v| match v { - PseudoElementSelectorChildren::PreservedToken(v) => vec![v.clone()], - PseudoElementSelectorChildren::Ident(v) => to_tokens(v).tokens, - PseudoElementSelectorChildren::CompoundSelector(v) => { - to_tokens(v).tokens - } - PseudoElementSelectorChildren::CustomHighlightName(v) => { - to_tokens(v).tokens - } - }) - .collect::>(); - - (name, &arg_tokens) - } - _ => continue, - }; - - // One off global selector - if &name.value == "global" { - let args = args.clone(); - let mut args = { - let lo = args.first().map(|v| v.span.lo).unwrap_or(BytePos(0)); - let hi = args.last().map(|v| v.span.hi).unwrap_or(BytePos(0)); - - Tokens { - span: Span::new(lo, hi, Default::default()), - tokens: args, - } - }; - - let block_tokens = get_block_tokens(&args); - let mut front_tokens = get_front_selector_tokens(&args); - front_tokens.extend(args.tokens); - front_tokens.extend(block_tokens); - args.tokens = front_tokens; - - let complex_selectors = panic::catch_unwind(|| { - let x: ComplexSelector = parse_tokens( - &args, - ParserConfig { - allow_wrong_line_comments: true, - ..Default::default() - }, - // TODO(kdy1): We might be able to report syntax errors. - &mut vec![], - ) - .unwrap(); - x - }); - - return match complex_selectors { - Ok(complex_selectors) => { - let mut v = complex_selectors.children[1..].to_vec(); - - if let ComplexSelectorChildren::Combinator(Combinator { - value: CombinatorValue::Descendant, - .. - }) = v[0] - { - v.remove(0); - } - - if v.is_empty() { - bail!("Failed to transform one off global selector"); - } - - trace!("Combinator: {:?}", combinator); - trace!("v[0]: {:?}", v[0]); - - let mut result = vec![]; - - if let Some(combinator) = combinator { - match v.get(0) { - // `Descendant` combinator can't be the first because we removed it - // above - Some(ComplexSelectorChildren::Combinator(..)) - if combinator.value == CombinatorValue::Descendant => {} - _ => { - result.push(ComplexSelectorChildren::Combinator(combinator)); - } - } - } - - v.iter_mut().for_each(|sel| { - if i < node.subclass_selectors.len() { - if let ComplexSelectorChildren::CompoundSelector(sel) = sel { - sel.subclass_selectors - .extend(node.subclass_selectors[i + 1..].iter().cloned()); - } - } - }); - - result.extend(v); - - Ok(result) - } - Err(_) => bail!("Failed to transform one off global selector"), - }; - } else if pseudo_index.is_none() { - pseudo_index = Some(i); - } - } - - let subclass_selector = match self.is_dynamic { - true => "__jsx-style-dynamic-selector", - false => &self.class_name, - }; - let insert_index = match pseudo_index { - None => node.subclass_selectors.len(), - Some(i) => i, - }; - if !self.is_global { - node.subclass_selectors.insert( - insert_index, - SubclassSelector::Class(ClassSelector { - span: DUMMY_SP, - text: Ident { - raw: Some(subclass_selector.into()), - value: subclass_selector.into(), - span: DUMMY_SP, - }, - }), - ); - } - - let mut result = vec![]; - - if let Some(combinator) = combinator { - result.push(ComplexSelectorChildren::Combinator(combinator)); - } - - result.push(ComplexSelectorChildren::CompoundSelector(node)); - - Ok(result) - } -} - -fn get_front_selector_tokens(selector_tokens: &Tokens) -> Vec { - let start_pos = selector_tokens.span.lo.to_u32() - 2; - vec![ - TokenAndSpan { - span: Span { - lo: BytePos(start_pos), - hi: BytePos(start_pos + 1), - ctxt: SyntaxContext::empty(), - }, - token: Token::Ident { - raw: "a".into(), - value: "a".into(), - }, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 1), - hi: BytePos(start_pos + 2), - ctxt: SyntaxContext::empty(), - }, - token: Token::WhiteSpace { value: " ".into() }, - }, - ] -} - -fn get_block_tokens(selector_tokens: &Tokens) -> Vec { - let start_pos = selector_tokens.span.hi.to_u32(); - vec![ - TokenAndSpan { - span: Span { - lo: BytePos(start_pos), - hi: BytePos(start_pos + 1), - ctxt: SyntaxContext::empty(), - }, - token: Token::WhiteSpace { value: " ".into() }, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 1), - hi: BytePos(start_pos + 2), - ctxt: SyntaxContext::empty(), - }, - token: Token::LBrace, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 2), - hi: BytePos(start_pos + 3), - ctxt: SyntaxContext::empty(), - }, - token: Token::WhiteSpace { value: " ".into() }, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 3), - hi: BytePos(start_pos + 8), - ctxt: SyntaxContext::empty(), - }, - token: Token::Ident { - value: "color".into(), - raw: "color".into(), - }, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 8), - hi: BytePos(start_pos + 9), - ctxt: SyntaxContext::empty(), - }, - token: Token::Colon, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 9), - hi: BytePos(start_pos + 10), - ctxt: SyntaxContext::empty(), - }, - token: Token::WhiteSpace { value: " ".into() }, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 10), - hi: BytePos(start_pos + 13), - ctxt: SyntaxContext::empty(), - }, - token: Token::Ident { - value: "red".into(), - raw: "red".into(), - }, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 13), - hi: BytePos(start_pos + 14), - ctxt: SyntaxContext::empty(), - }, - token: Token::Semi, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 14), - hi: BytePos(start_pos + 15), - ctxt: SyntaxContext::empty(), - }, - token: Token::WhiteSpace { value: " ".into() }, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 15), - hi: BytePos(start_pos + 16), - ctxt: SyntaxContext::empty(), - }, - token: Token::RBrace, - }, - TokenAndSpan { - span: Span { - lo: BytePos(start_pos + 16), - hi: BytePos(start_pos + 17), - ctxt: SyntaxContext::empty(), - }, - token: Token::WhiteSpace { value: " ".into() }, - }, - ] -} - -fn to_tokens(node: &N) -> Tokens -where - for<'aa> CodeGenerator<&'aa mut BasicCssWriter<'aa, &'aa mut std::string::String>>: Emit, -{ - let mut s = String::new(); - { - let mut wr = BasicCssWriter::new(&mut s, None, BasicCssWriterConfig::default()); - let mut gen = CodeGenerator::new(&mut wr, CodegenConfig { minify: true }); - - gen.emit(node).unwrap(); - } - - let span = node.span(); - let lexer = swc_core::css::parser::lexer::Lexer::new( - StringInput::new(&s, span.lo, span.hi), - ParserConfig { - allow_wrong_line_comments: true, - ..Default::default() - }, - ); - - Tokens { - span: Span::new(span.lo, span.hi, Default::default()), - tokens: lexer.collect(), - } -} diff --git a/packages/next-swc/crates/styled_jsx/src/utils.rs b/packages/next-swc/crates/styled_jsx/src/utils.rs deleted file mode 100644 index e33e8f3cf5802..0000000000000 --- a/packages/next-swc/crates/styled_jsx/src/utils.rs +++ /dev/null @@ -1,370 +0,0 @@ -use std::collections::hash_map::DefaultHasher; -use std::hash::Hasher; -use swc_core::{common::DUMMY_SP, ecma::ast::*}; - -use super::{ExternalStyle, JSXStyle, LocalStyle}; - -fn tpl_element(value: &str) -> TplElement { - TplElement { - raw: value.into(), - cooked: None, - span: DUMMY_SP, - tail: false, - } -} - -pub fn compute_class_names( - styles: &[JSXStyle], - style_import_name: &str, -) -> (Option, Option) { - let mut static_class_name = None; - let mut external_jsx_id = None; - let mut static_hashes = vec![]; - let mut dynamic_styles = vec![]; - let mut external_styles = vec![]; - for style_info in styles { - match style_info { - JSXStyle::Local(style_info) => { - if !style_info.is_dynamic { - static_hashes.push(style_info.hash.clone()); - } else { - dynamic_styles.push(style_info); - } - } - JSXStyle::External(external) => { - if !external.is_global { - external_styles.push(external.expr.clone()); - } - } - } - } - - if !external_styles.is_empty() { - let mut quasis = vec![tpl_element("jsx-")]; - for _i in 1..external_styles.len() { - quasis.push(tpl_element(" jsx-")) - } - quasis.push(tpl_element("")); - external_jsx_id = Some(Expr::Tpl(Tpl { - quasis, - exprs: external_styles - .iter() - .map(|external| Box::new(external.clone())) - .collect(), - span: DUMMY_SP, - })); - } - - if !static_hashes.is_empty() { - static_class_name = Some(format!("jsx-{}", hash_string(&static_hashes.join(",")))); - } - - let dynamic_class_name = match dynamic_styles.len() { - 0 => None, - _ => Some(Expr::Call(CallExpr { - callee: Callee::Expr(Box::new(Expr::Member(MemberExpr { - obj: Box::new(Expr::Ident(Ident { - sym: style_import_name.into(), - span: DUMMY_SP, - optional: false, - })), - prop: MemberProp::Ident(Ident { - sym: "dynamic".into(), - span: DUMMY_SP, - optional: false, - }), - span: DUMMY_SP, - }))), - args: vec![ExprOrSpread { - expr: Box::new(Expr::Array(ArrayLit { - elems: dynamic_styles - .iter() - .map(|style_info| { - let hash_input = match &static_class_name { - Some(class_name) => format!("{}{}", style_info.hash, class_name), - None => style_info.hash.clone(), - }; - Some(ExprOrSpread { - expr: Box::new(Expr::Array(ArrayLit { - elems: vec![ - Some(ExprOrSpread { - expr: Box::new(string_literal_expr(&hash_string( - &hash_input, - ))), - spread: None, - }), - Some(ExprOrSpread { - expr: Box::new(Expr::Array(ArrayLit { - elems: style_info - .expressions - .iter() - .map(|expression| { - Some(ExprOrSpread { - expr: expression.clone(), - spread: None, - }) - }) - .collect(), - span: DUMMY_SP, - })), - spread: None, - }), - ], - span: DUMMY_SP, - })), - spread: None, - }) - }) - .collect(), - span: DUMMY_SP, - })), - spread: None, - }], - span: DUMMY_SP, - type_args: None, - })), - }; - - let class_name_expr = match ( - static_class_name.clone(), - dynamic_class_name, - external_jsx_id, - ) { - (Some(static_class_name), Some(dynamic_class_name), Some(external_jsx_id)) => Some(add( - add( - external_jsx_id, - string_literal_expr(&format!(" {} ", static_class_name)), - ), - dynamic_class_name, - )), - (Some(static_class_name), Some(dynamic_class_name), None) => Some(add( - string_literal_expr(&format!("{} ", static_class_name)), - dynamic_class_name, - )), - (Some(static_class_name), None, Some(external_jsx_id)) => Some(add( - string_literal_expr(&format!("{} ", static_class_name)), - external_jsx_id, - )), - (None, Some(dynamic_class_name), Some(external_jsx_id)) => Some(add( - add(external_jsx_id, string_literal_expr(" ")), - dynamic_class_name, - )), - (Some(static_class_name), None, None) => Some(string_literal_expr(&static_class_name)), - (None, Some(dynamic_class_name), None) => Some(dynamic_class_name), - (None, None, Some(external_jsx_id)) => Some(external_jsx_id), - _ => None, - }; - - (static_class_name, class_name_expr) -} - -pub fn make_external_styled_jsx_el(style: &ExternalStyle, style_import_name: &str) -> JSXElement { - let attrs = vec![JSXAttrOrSpread::JSXAttr(JSXAttr { - name: JSXAttrName::Ident(Ident { - sym: "id".into(), - span: DUMMY_SP, - optional: false, - }), - value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(Box::new(style.expr.clone())), - span: DUMMY_SP, - })), - span: DUMMY_SP, - })]; - let opening = JSXOpeningElement { - name: JSXElementName::Ident(Ident { - sym: style_import_name.into(), - span: DUMMY_SP, - optional: false, - }), - attrs, - span: DUMMY_SP, - self_closing: false, - type_args: None, - }; - - let closing = Some(JSXClosingElement { - name: JSXElementName::Ident(Ident { - sym: style_import_name.into(), - span: DUMMY_SP, - optional: false, - }), - span: DUMMY_SP, - }); - - let children = vec![JSXElementChild::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(Box::new(Expr::Ident(style.identifier.clone()))), - span: DUMMY_SP, - })]; - JSXElement { - opening, - closing, - children, - span: DUMMY_SP, - } -} - -pub fn make_local_styled_jsx_el( - style_info: &LocalStyle, - css_expr: Expr, - style_import_name: &str, - static_class_name: Option<&String>, -) -> JSXElement { - let hash_input = match (&style_info.is_dynamic, &static_class_name) { - (true, Some(class_name)) => format!("{}{}", style_info.hash, class_name), - _ => style_info.hash.clone(), - }; - let mut attrs = vec![JSXAttrOrSpread::JSXAttr(JSXAttr { - name: JSXAttrName::Ident(Ident { - sym: "id".into(), - span: DUMMY_SP, - optional: false, - }), - value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(Box::new(string_literal_expr( - hash_string(&hash_input).as_str(), - ))), - span: DUMMY_SP, - })), - span: DUMMY_SP, - })]; - - if style_info.is_dynamic { - attrs.push(JSXAttrOrSpread::JSXAttr(JSXAttr { - name: JSXAttrName::Ident(Ident { - sym: "dynamic".into(), - span: DUMMY_SP, - optional: false, - }), - value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(Box::new(Expr::Array(ArrayLit { - elems: style_info - .expressions - .iter() - .map(|expression| { - Some(ExprOrSpread { - expr: expression.clone(), - spread: None, - }) - }) - .collect(), - span: DUMMY_SP, - }))), - span: DUMMY_SP, - })), - span: DUMMY_SP, - })); - } - - let opening = JSXOpeningElement { - name: JSXElementName::Ident(Ident { - sym: style_import_name.into(), - span: DUMMY_SP, - optional: false, - }), - attrs, - span: DUMMY_SP, - self_closing: false, - type_args: None, - }; - - let closing = Some(JSXClosingElement { - name: JSXElementName::Ident(Ident { - sym: style_import_name.into(), - span: DUMMY_SP, - optional: false, - }), - span: DUMMY_SP, - }); - - let children = vec![JSXElementChild::JSXExprContainer(JSXExprContainer { - expr: JSXExpr::Expr(Box::new(css_expr)), - span: DUMMY_SP, - })]; - JSXElement { - opening, - closing, - children, - span: DUMMY_SP, - } -} - -pub fn get_usable_import_specifier(_items: &[ModuleItem]) -> String { - // TODO - String::from("_JSXStyle") -} - -pub fn styled_jsx_import_decl(style_import_name: &str) -> ModuleItem { - ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { - asserts: None, - span: DUMMY_SP, - type_only: false, - specifiers: vec![ImportSpecifier::Default(ImportDefaultSpecifier { - local: Ident { - sym: style_import_name.into(), - span: DUMMY_SP, - optional: false, - }, - span: DUMMY_SP, - })], - src: Box::new(Str { - span: DUMMY_SP, - value: "styled-jsx/style".into(), - raw: None, - }), - })) -} - -// TODO: maybe use DJBHasher (need to implement) -pub fn hash_string(str: &str) -> String { - let mut hasher = DefaultHasher::new(); - hasher.write(str.as_bytes()); - let hash_result = hasher.finish(); - format!("{:x}", hash_result) -} - -pub fn string_literal_expr(str: &str) -> Expr { - let str = str.replace("\\`", "`"); - Expr::Lit(Lit::Str(Str { - value: str.into(), - span: DUMMY_SP, - raw: None, - })) -} - -pub fn ident(str: &str) -> Ident { - Ident { - sym: str.into(), - span: DUMMY_SP, - optional: false, - } -} - -pub fn is_capitalized(word: &str) -> bool { - word.chars().next().unwrap().is_uppercase() -} - -pub fn add(left: Expr, right: Expr) -> Expr { - binary_expr(BinaryOp::Add, left, right) -} - -pub fn and(left: Expr, right: Expr) -> Expr { - binary_expr(BinaryOp::LogicalAnd, left, right) -} - -pub fn or(left: Expr, right: Expr) -> Expr { - binary_expr(BinaryOp::LogicalOr, left, right) -} - -pub fn not_eq(left: Expr, right: Expr) -> Expr { - binary_expr(BinaryOp::NotEq, left, right) -} - -pub fn binary_expr(op: BinaryOp, left: Expr, right: Expr) -> Expr { - Expr::Bin(BinExpr { - op, - left: Box::new(left), - right: Box::new(right), - span: DUMMY_SP, - }) -} diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/nested-style-tags/input.js b/packages/next-swc/crates/styled_jsx/tests/errors/nested-style-tags/input.js deleted file mode 100644 index 56f9802d7c8e1..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/nested-style-tags/input.js +++ /dev/null @@ -1,31 +0,0 @@ -const Component = () => ( - <> -
- - - - -

-
-
-

- Welcome! - -

- -
-
- -

- Hello world! - -

-
-
- <> - - - -
- -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/nested-style-tags/output.js b/packages/next-swc/crates/styled_jsx/tests/errors/nested-style-tags/output.js deleted file mode 100644 index 6a801091839c7..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/nested-style-tags/output.js +++ /dev/null @@ -1,31 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -const Component = ()=><> -
- - <_JSXStyle id={styles.__hash}>{styles} - <_JSXStyle id={"b3e1b6a7c9b96113"}>{""} - -

<_JSXStyle id={"b3e1b6a7c9b96113"}>{""}

-
-
-

- Welcome! - -

- <_JSXStyle id={"b3e1b6a7c9b96113"}>{""} -
-
- <_JSXStyle id={"b3e1b6a7c9b96113"}>{""} -

- Hello world! - -

-
-
- <> - - - <_JSXStyle id={"b3e1b6a7c9b96113"}>{""} -
- -; diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/nested-style-tags/output.stderr b/packages/next-swc/crates/styled_jsx/tests/errors/nested-style-tags/output.stderr deleted file mode 100644 index 796ba3e393d76..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/nested-style-tags/output.stderr +++ /dev/null @@ -1,21 +0,0 @@ - - x Detected nested styled-jsx tag. - | Read more: https://nextjs.org/docs/messages/nested-styled-jsx-tags - ,-[input.js:13:9] - 13 | - : ^^^^^^^^^^^^^^^^^^^^^^^ - `---- - - x Detected nested styled-jsx tag. - | Read more: https://nextjs.org/docs/messages/nested-styled-jsx-tags - ,-[input.js:21:9] - 21 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - `---- - - x Detected nested styled-jsx tag. - | Read more: https://nextjs.org/docs/messages/nested-styled-jsx-tags - ,-[input.js:26:9] - 26 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - `---- diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/no-child/input.js b/packages/next-swc/crates/styled_jsx/tests/errors/no-child/input.js deleted file mode 100644 index 9567d0ce5cb1b..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/no-child/input.js +++ /dev/null @@ -1,6 +0,0 @@ -export default () => ( -
- -
-) diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/no-child/output.js b/packages/next-swc/crates/styled_jsx/tests/errors/no-child/output.js deleted file mode 100644 index 90fb7d27831c5..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/no-child/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
- - - -
); diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/no-child/output.stderr b/packages/next-swc/crates/styled_jsx/tests/errors/no-child/output.stderr deleted file mode 100644 index f9789a9d4d850..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/no-child/output.stderr +++ /dev/null @@ -1,7 +0,0 @@ - - x Expected one child under JSX style tag, but got 0. - | Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children - ,-[input.js:3:5] - 3 | ,-> - `---- diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/ts-with-css-resolve/input.js b/packages/next-swc/crates/styled_jsx/tests/errors/ts-with-css-resolve/input.js deleted file mode 100644 index 87474a371846a..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/ts-with-css-resolve/input.js +++ /dev/null @@ -1,10 +0,0 @@ -import css from 'styled-jsx/css' - -export default css.resolve` - .container { - background: #000; - color: white; - font-weight: 700; - height: 100px; - } -` \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/ts-with-css-resolve/output.js b/packages/next-swc/crates/styled_jsx/tests/errors/ts-with-css-resolve/output.js deleted file mode 100644 index 6fbd823e7814a..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/ts-with-css-resolve/output.js +++ /dev/null @@ -1,5 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default { - styles: <_JSXStyle id={"71f03d42ea0ec6"}>{".container.jsx-71f03d42ea0ec6{background:#000;color:white;font-weight:700;height:100px}"}, - className: "jsx-71f03d42ea0ec6" -}; diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/ts-with-css-resolve/output.stderr b/packages/next-swc/crates/styled_jsx/tests/errors/ts-with-css-resolve/output.stderr deleted file mode 100644 index ad7185a0bc3de..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/ts-with-css-resolve/output.stderr +++ /dev/null @@ -1,2 +0,0 @@ - - x /some-project/src/some-file.ts uses `css.resolve`, but ends with `.ts`. The file extension needs to be `.tsx` so that the jsx injected by `css.resolve` will be transformed. diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/two-children/input.js b/packages/next-swc/crates/styled_jsx/tests/errors/two-children/input.js deleted file mode 100644 index a8edd5afd5e13..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/two-children/input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default () => ( -
- -
-) diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/two-children/output.js b/packages/next-swc/crates/styled_jsx/tests/errors/two-children/output.js deleted file mode 100644 index 743be800fcfe7..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/two-children/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
- - - -
); diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/two-children/output.stderr b/packages/next-swc/crates/styled_jsx/tests/errors/two-children/output.stderr deleted file mode 100644 index 333d1d6d9a7a5..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/two-children/output.stderr +++ /dev/null @@ -1,9 +0,0 @@ - - x Expected one child under JSX style tag, but got 2. - | Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children - ,-[input.js:3:5] - 3 | ,-> - `---- diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-child-type/input.js b/packages/next-swc/crates/styled_jsx/tests/errors/wrong-child-type/input.js deleted file mode 100644 index 9e1613eb4c4de..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-child-type/input.js +++ /dev/null @@ -1,7 +0,0 @@ -export default () => ( -
- -
-) diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-child-type/output.js b/packages/next-swc/crates/styled_jsx/tests/errors/wrong-child-type/output.js deleted file mode 100644 index e4317fb3df8e3..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-child-type/output.js +++ /dev/null @@ -1,10 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
- - - -
); diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-child-type/output.stderr b/packages/next-swc/crates/styled_jsx/tests/errors/wrong-child-type/output.stderr deleted file mode 100644 index a524f640c0cda..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-child-type/output.stderr +++ /dev/null @@ -1,8 +0,0 @@ - - x Expected a single child of type JSXExpressionContainer under JSX Style tag. - | Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children - ,-[input.js:3:5] - 3 | ,-> - `---- diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-jsx-expression-type/input.js b/packages/next-swc/crates/styled_jsx/tests/errors/wrong-jsx-expression-type/input.js deleted file mode 100644 index 332f22bf53097..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-jsx-expression-type/input.js +++ /dev/null @@ -1,7 +0,0 @@ -export default () => ( -
- -
-) diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-jsx-expression-type/output.js b/packages/next-swc/crates/styled_jsx/tests/errors/wrong-jsx-expression-type/output.js deleted file mode 100644 index 6769772a88341..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-jsx-expression-type/output.js +++ /dev/null @@ -1,10 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
- - - -
); diff --git a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-jsx-expression-type/output.stderr b/packages/next-swc/crates/styled_jsx/tests/errors/wrong-jsx-expression-type/output.stderr deleted file mode 100644 index 93bcfe2857bc5..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/errors/wrong-jsx-expression-type/output.stderr +++ /dev/null @@ -1,8 +0,0 @@ - - x Expected a template literal, string or identifier inside the JSXExpressionContainer. - | Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children - ,-[input.js:3:5] - 3 | ,-> - `---- diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture.rs b/packages/next-swc/crates/styled_jsx/tests/fixture.rs deleted file mode 100644 index 6e87c8297345d..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture.rs +++ /dev/null @@ -1,89 +0,0 @@ -use std::path::PathBuf; - -use styled_jsx::styled_jsx; -use swc_core::{ - common::{chain, FileName, Mark, Span, DUMMY_SP}, - ecma::parser::{EsConfig, Syntax}, - ecma::transforms::testing::test_fixture, - ecma::transforms::{base::resolver, testing::FixtureTestConfig}, -}; -use testing::fixture; - -fn syntax() -> Syntax { - Syntax::Es(EsConfig { - jsx: true, - ..Default::default() - }) -} - -#[fixture("tests/fixture/**/input.js")] -fn styled_jsx_fixture(input: PathBuf) { - let output = input.parent().unwrap().join("output.js"); - test_fixture( - syntax(), - &|t| { - chain!( - resolver(Mark::new(), Mark::new(), false), - styled_jsx( - t.cm.clone(), - FileName::Real(PathBuf::from("/some-project/src/some-file.js")) - ) - ) - }, - &input, - &output, - Default::default(), - ); - - test_fixture( - syntax(), - &|t| { - // `resolver` uses `Mark` which is stored in a thread-local storage (namely - // swc_common::GLOBALS), and this loop will make `Mark` to be different from the - // invocation above. - // - // 1000 is used because in future I (kdy1) may optimize logic of resolver. - for _ in 0..1000 { - let _mark = Mark::fresh(Mark::root()); - } - - chain!( - resolver(Mark::new(), Mark::new(), false), - styled_jsx( - t.cm.clone(), - FileName::Real(PathBuf::from("/some-project/src/some-file.js")) - ) - ) - }, - &input, - &output, - Default::default(), - ); -} - -pub struct DropSpan; -impl swc_core::ecma::visit::VisitMut for DropSpan { - fn visit_mut_span(&mut self, span: &mut Span) { - *span = DUMMY_SP - } -} - -#[fixture("tests/errors/**/input.js")] -fn styled_jsx_errors(input: PathBuf) { - let output = input.parent().unwrap().join("output.js"); - let file_name = match input.to_str().unwrap().contains("ts-with-css-resolve") { - true => FileName::Real(PathBuf::from("/some-project/src/some-file.ts")), - false => FileName::Real(PathBuf::from("/some-project/src/some-file.js")), - }; - - test_fixture( - syntax(), - &|t| styled_jsx(t.cm.clone(), file_name.clone()), - &input, - &output, - FixtureTestConfig { - allow_error: true, - ..Default::default() - }, - ); -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/absent/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/absent/input.js deleted file mode 100644 index bb4af7a545e89..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/absent/input.js +++ /dev/null @@ -1,6 +0,0 @@ -const a = () => ( -
-

hi

- -
-) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/absent/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/absent/output.js deleted file mode 100644 index 244ca2a7511a8..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/absent/output.js +++ /dev/null @@ -1,7 +0,0 @@ -const a = ()=>
- -

hi

- - - -
; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-classname-rewriting/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-classname-rewriting/input.js deleted file mode 100644 index 47691510e3a07..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-classname-rewriting/input.js +++ /dev/null @@ -1,55 +0,0 @@ -export default () => { - const Element = 'div' - return ( -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - - - -
- ) -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-classname-rewriting/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-classname-rewriting/output.js deleted file mode 100644 index 939e06090f38d..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-classname-rewriting/output.js +++ /dev/null @@ -1,112 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>{ - const Element = 'div'; - return
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- - - - - - - - <_JSXStyle id={"abb4c2202db1a207"}>{"div.jsx-abb4c2202db1a207{color:red}"} - -
; -}); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-modes/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-modes/input.js deleted file mode 100644 index 1454a4c30cda1..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-modes/input.js +++ /dev/null @@ -1,166 +0,0 @@ -import styles from './styles' - -const styles2 = require('./styles2') - -// external only -export const Test1 = () => ( -
-

external only

- - -
-) - -// external and static -export const Test2 = () => ( -
-

external and static

- - -
-) - -// external and dynamic -export const Test3 = ({ color }) => ( -
-

external and dynamic

- - -
-) - -// external, static and dynamic -export const Test4 = ({ color }) => ( -
-

external, static and dynamic

- - - -
-) - -// static only -export const Test5 = () => ( -
-

static only

- - -
-) - -// static and dynamic -export const Test6 = ({ color }) => ( -
-

static and dynamic

- - -
-) - -// dynamic only -export const Test7 = ({ color }) => ( -
-

dynamic only

- -
-) - -// dynamic with scoped compound variable -export const Test8 = ({ color }) => { - if (color) { - const innerProps = { color } - - return ( -
-

dynamic with scoped compound variable

- -
- ) - } -} - -// dynamic with compound variable -export const Test9 = ({ color }) => { - const innerProps = { color } - - return ( -
-

dynamic with compound variable

- -
- ) -} - -const foo = 'red' - -// dynamic with constant variable -export const Test10 = () => ( -
-

dynamic with constant variable

- -
-) - -// dynamic with complex scope -export const Test11 = ({ color }) => { - const items = Array.from({ length: 5 }).map((item, i) => ( -
  • - - Item #{i + 1} -
  • - )) - - return
      {items}
    -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-modes/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-modes/output.js deleted file mode 100644 index 92e7f7bfe84c1..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/attribute-generation-modes/output.js +++ /dev/null @@ -1,228 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -import styles from './styles'; -const styles2 = require('./styles2'); -// external only -export const Test1 = ()=>
    - -

    external only

    - - <_JSXStyle id={styles.__hash}>{styles} - - <_JSXStyle id={styles2.__hash}>{styles2} - -
    ; -// external and static -export const Test2 = ()=>
    - -

    external and static

    - - <_JSXStyle id={"81a68341e430a972"}>{"p.jsx-81a68341e430a972{color:red}"} - - <_JSXStyle id={styles.__hash}>{styles} - -
    ; -// external and dynamic -export const Test3 = ({ color })=>
    - -

    external and dynamic

    - - <_JSXStyle id={"f08108daf927b99d"} dynamic={[ - color - ]}>{`p.__jsx-style-dynamic-selector{color:${color}}`} - - <_JSXStyle id={styles.__hash}>{styles} - -
    ; -// external, static and dynamic -export const Test4 = ({ color })=>
    - -

    external, static and dynamic

    - - <_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c{display:inline-block}"} - - <_JSXStyle id={"9779eebad83219f8"} dynamic={[ - color - ]}>{`p.__jsx-style-dynamic-selector{color:${color}}`} - - <_JSXStyle id={styles.__hash}>{styles} - -
    ; -// static only -export const Test5 = ()=>
    - -

    static only

    - - <_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-df0159ebd3f9fb6f{display:inline-block}"} - - <_JSXStyle id={"81a68341e430a972"}>{"p.jsx-df0159ebd3f9fb6f{color:red}"} - -
    ; -// static and dynamic -export const Test6 = ({ color })=>
    - -

    static and dynamic

    - - <_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c{display:inline-block}"} - - <_JSXStyle id={"9779eebad83219f8"} dynamic={[ - color - ]}>{`p.__jsx-style-dynamic-selector{color:${color}}`} - -
    ; -// dynamic only -export const Test7 = ({ color })=>
    - -

    dynamic only

    - - <_JSXStyle id={"f08108daf927b99d"} dynamic={[ - color - ]}>{`p.__jsx-style-dynamic-selector{color:${color}}`} - -
    ; -// dynamic with scoped compound variable -export const Test8 = ({ color })=>{ - if (color) { - const innerProps = { - color - }; - return
    - -

    dynamic with scoped compound variable

    - - <_JSXStyle id={"62256c563b89bfae"} dynamic={[ - innerProps.color - ]}>{`p.__jsx-style-dynamic-selector{color:${innerProps.color}}`} - -
    ; - } -}; -// dynamic with compound variable -export const Test9 = ({ color })=>{ - const innerProps = { - color - }; - return
    - -

    dynamic with compound variable

    - - <_JSXStyle id={"708723e452f192e4"} dynamic={[ - innerProps.color - ]}>{`p.__jsx-style-dynamic-selector{color:${innerProps.color}}`} - -
    ; -}; -const foo = 'red'; -// dynamic with constant variable -export const Test10 = ()=>
    - -

    dynamic with constant variable

    - - <_JSXStyle id={"f849b7a02be96503"}>{`p.jsx-f849b7a02be96503{color:${foo}}`} - -
    ; -// dynamic with complex scope -export const Test11 = ({ color })=>{ - const items = Array.from({ - length: 5 - }).map((item, i)=>
  • - - <_JSXStyle id={"a2585dff420632b1"} dynamic={[ - color - ]}>{`.item.__jsx-style-dynamic-selector{color:${color}}`} - - Item #{i + 1} - -
  • ); - return
      {items}
    ; -}; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/class/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/class/input.js deleted file mode 100644 index 7488d661bc84c..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/class/input.js +++ /dev/null @@ -1,14 +0,0 @@ -export default class { - render() { - return ( -
    -

    test

    - -
    - ) - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/class/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/class/output.js deleted file mode 100644 index cc8252d40c17c..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/class/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"b2b86d63f35d25ee"}>{"p.jsx-b2b86d63f35d25ee{color:red}"} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/comments/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/comments/input.js deleted file mode 100644 index 0ba7a187731c1..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/comments/input.js +++ /dev/null @@ -1,18 +0,0 @@ -export default class { - render() { - return ( -
    -

    test

    - -
    - ) - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/comments/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/comments/output.js deleted file mode 100644 index 7e87f083a0a79..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/comments/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"1952086b0a5ae64c"}>{"p.jsx-1952086b0a5ae64c{color:red}"} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/component-attribute/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/component-attribute/input.js deleted file mode 100644 index 7531db885849b..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/component-attribute/input.js +++ /dev/null @@ -1,11 +0,0 @@ -const Test = () => ( -
    - test - - -
    -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/component-attribute/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/component-attribute/output.js deleted file mode 100644 index cdc5e031093f8..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/component-attribute/output.js +++ /dev/null @@ -1,10 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -const Test = ()=>
    - - test - - - - <_JSXStyle id={"a9535d7d5f32c3c4"}>{"span.jsx-a9535d7d5f32c3c4{color:red}"} - -
    ; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/conflicts/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/conflicts/input.js deleted file mode 100644 index ba7ab50bfe80c..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/conflicts/input.js +++ /dev/null @@ -1,16 +0,0 @@ - -// TODO - -// export const _JSXStyle = '_JSXStyle-literal' -// export default function() { -// return ( -//
    -//

    test

    -// -//
    -// ) -// } diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/conflicts/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/conflicts/output.js deleted file mode 100644 index 874cf34f5305b..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/conflicts/output.js +++ /dev/null @@ -1,14 +0,0 @@ -// TODO -// export const _JSXStyle = '_JSXStyle-literal' -// export default function() { -// return ( -//
    -//

    test

    -// -//
    -// ) -// } diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/css-selector-after-pseudo/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/css-selector-after-pseudo/input.js deleted file mode 100644 index a2e54d09b1cb5..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/css-selector-after-pseudo/input.js +++ /dev/null @@ -1,18 +0,0 @@ -function NavigationItem({ - active, - className, -}) { - return ( - - - - ); -} - -export default NavigationItem; \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/css-selector-after-pseudo/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/css-selector-after-pseudo/output.js deleted file mode 100644 index 038e73e4b66f8..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/css-selector-after-pseudo/output.js +++ /dev/null @@ -1,11 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -function NavigationItem({ active , className }) { - return - - <_JSXStyle id={"2342aae4628612c6"}>{'.navigation-item.jsx-2342aae4628612c6 a::after{content:attr(data-text);content:attr(data-text)/""}'} - - ; -} -export default NavigationItem; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/css-tag-same-file/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/css-tag-same-file/input.js deleted file mode 100644 index a455a91246b58..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/css-tag-same-file/input.js +++ /dev/null @@ -1,25 +0,0 @@ -import css from 'styled-jsx/css' - -export default ({ children }) => ( -
    -

    {children}

    - -
    -) - -const styles = css` - p { - color: red; - } -` - -class Test extends React.Component { - render() { - return ( -
    -

    {this.props.children}

    - -
    - ) - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/css-tag-same-file/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/css-tag-same-file/output.js deleted file mode 100644 index ffc1a2bf670fb..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/css-tag-same-file/output.js +++ /dev/null @@ -1,21 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (({ children })=>
    - -

    {children}

    - - <_JSXStyle id={styles.__hash}>{styles} - -
    ); -const styles = new String("p.jsx-556239d258b6d66a{color:red}"); -styles.__hash = "556239d258b6d66a"; -class Test extends React.Component { - render() { - return
    - -

    {this.props.children}

    - - <_JSXStyle id={styles.__hash}>{styles} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/different-jsx-ids/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/different-jsx-ids/input.js deleted file mode 100644 index d5769d3e9c1f4..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/different-jsx-ids/input.js +++ /dev/null @@ -1,23 +0,0 @@ -const color = 'red' -const otherColor = 'green' - -const A = () => ( -
    -

    test

    - -
    -) - -const B = () => ( -
    -

    test

    - -
    -) - -export default () => ( - -) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/different-jsx-ids/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/different-jsx-ids/output.js deleted file mode 100644 index 09f34b112c95a..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/different-jsx-ids/output.js +++ /dev/null @@ -1,24 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -const color = 'red'; -const otherColor = 'green'; -const A = ()=>
    - -

    test

    - - <_JSXStyle id={"8522d6f4b7f930d2"}>{`p.jsx-8522d6f4b7f930d2{color:${color}}`} - -
    ; -const B = ()=>
    - -

    test

    - - <_JSXStyle id={"d1ed441bb35f699d"}>{`p.jsx-d1ed441bb35f699d{color:${otherColor}}`} - -
    ; -export default (()=>
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-class/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-class/input.js deleted file mode 100644 index 5b8abce8c999f..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-class/input.js +++ /dev/null @@ -1,32 +0,0 @@ -export default class { - render() { - const Element = 'div' - - return ( - -

    dynamic element

    - -
    - ) - } -} - -const Element2 = 'div' -export const Test2 = class { - render() { - return ( - -

    dynamic element

    - -
    - ) - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-class/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-class/output.js deleted file mode 100644 index 310fcb426c5d7..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-class/output.js +++ /dev/null @@ -1,25 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - const Element = 'div'; - return - -

    dynamic element

    - - <_JSXStyle id={"f825b24bbab5b83b"}>{".root.jsx-f825b24bbab5b83b{background:red}"} - -
    ; - } -} -const Element2 = 'div'; -export const Test2 = class { - render() { - return - -

    dynamic element

    - - <_JSXStyle id={"f825b24bbab5b83b"}>{".root.jsx-f825b24bbab5b83b{background:red}"} - -
    ; - } -}; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-external/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-external/input.js deleted file mode 100644 index 128078563e40b..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-external/input.js +++ /dev/null @@ -1,12 +0,0 @@ -import styles from './styles2' - -export default ({ level = 1 }) => { - const Element = `h${level}` - - return ( - -

    dynamic element

    - -
    - ) -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-external/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-external/output.js deleted file mode 100644 index e96530e253354..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element-external/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -import styles from './styles2'; -export default (({ level =1 })=>{ - const Element = `h${level}`; - return - -

    dynamic element

    - - <_JSXStyle id={styles.__hash}>{styles} - -
    ; -}); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element/input.js deleted file mode 100644 index 17854bdd2bbae..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element/input.js +++ /dev/null @@ -1,56 +0,0 @@ -export default ({ level = 1 }) => { - const Element = `h${level}` - - return ( - -

    dynamic element

    - -
    - ) -} - -export const TestLowerCase = ({ level = 1 }) => { - const element = `h${level}` - - return ( - -

    dynamic element

    - -
    - ) -} - -const Element2 = 'div' -export const Test2 = () => { - return ( - -

    dynamic element

    - -
    - ) -} - -export const Test3 = ({Component = 'div'}) => { - return ( - -

    dynamic element

    - -
    - ); -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element/output.js deleted file mode 100644 index fe05a5238005d..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-element/output.js +++ /dev/null @@ -1,40 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (({ level =1 })=>{ - const Element = `h${level}`; - return - -

    dynamic element

    - - <_JSXStyle id={"fca64cc3f069b519"}>{".root.jsx-fca64cc3f069b519{background:red}"} - -
    ; -}); -export const TestLowerCase = ({ level =1 })=>{ - const element = `h${level}`; - return - -

    dynamic element

    - - <_JSXStyle id={"fca64cc3f069b519"}>{".root.jsx-fca64cc3f069b519{background:red}"} - -
    ; -}; -const Element2 = 'div'; -export const Test2 = ()=>{ - return - -

    dynamic element

    - - <_JSXStyle id={"fca64cc3f069b519"}>{".root.jsx-fca64cc3f069b519{background:red}"} - -
    ; -}; -export const Test3 = ({ Component ='div' })=>{ - return - -

    dynamic element

    - - <_JSXStyle id={"f825b24bbab5b83b"}>{".root.jsx-f825b24bbab5b83b{background:red}"} - -
    ; -}; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-this-in-arrow/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-this-in-arrow/input.js deleted file mode 100644 index 1a3c67dc60869..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-this-in-arrow/input.js +++ /dev/null @@ -1,41 +0,0 @@ -// TODO -// import React, { Component } from 'react' - -// export default class Index extends Component { -// static getInitialProps() { -// return { color: 'aquamarine' } -// } - -// render() { -// return ( -//
    -// {[1, 2].map(idx => ( -//
    -// {[3, 4].map(idx2 => ( -//
    {this.props.color}
    -// ))} -//
    -// ))} -// {[1, 2].map(idx => ( -//
    -//
    -// {this.props.color} -//
    -// -//
    -//
    {this.props.color} hello there
    -//
    -//
    -//
    -//
    -//
    -// ))} -// -//
    -// ) -// } -// } diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-this-in-arrow/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-this-in-arrow/output.js deleted file mode 100644 index 11fc44ff6c8a5..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/dynamic-this-in-arrow/output.js +++ /dev/null @@ -1,39 +0,0 @@ -// TODO -// import React, { Component } from 'react' -// export default class Index extends Component { -// static getInitialProps() { -// return { color: 'aquamarine' } -// } -// render() { -// return ( -//
    -// {[1, 2].map(idx => ( -//
    -// {[3, 4].map(idx2 => ( -//
    {this.props.color}
    -// ))} -//
    -// ))} -// {[1, 2].map(idx => ( -//
    -//
    -// {this.props.color} -//
    -// -//
    -//
    {this.props.color} hello there
    -//
    -//
    -//
    -//
    -//
    -// ))} -// -//
    -// ) -// } -// } diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/exported-jsx-style/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/exported-jsx-style/input.js deleted file mode 100644 index 119d097f61c55..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/exported-jsx-style/input.js +++ /dev/null @@ -1 +0,0 @@ -// module.exports = () =>

    \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/exported-jsx-style/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/exported-jsx-style/output.js deleted file mode 100644 index 79908ec112773..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/exported-jsx-style/output.js +++ /dev/null @@ -1 +0,0 @@ -// module.exports = () =>

    diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/exported-non-jsx-style/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/exported-non-jsx-style/input.js deleted file mode 100644 index 5539580cf93a7..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/exported-non-jsx-style/input.js +++ /dev/null @@ -1 +0,0 @@ -// module.exports = () =>

    \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/exported-non-jsx-style/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/exported-non-jsx-style/output.js deleted file mode 100644 index 42b1f9876f857..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/exported-non-jsx-style/output.js +++ /dev/null @@ -1 +0,0 @@ -// module.exports = () =>

    diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/expressions/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/expressions/input.js deleted file mode 100644 index d7c579f19102f..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/expressions/input.js +++ /dev/null @@ -1,90 +0,0 @@ -const darken = c => c -const color = 'red' -const otherColor = 'green' -const mediumScreen = '680px' -const animationDuration = '200ms' -const animationName = 'my-cool-animation' -const obj = { display: 'block' } - -export default ({ display }) => ( -
    -

    test

    - - - - - // TODO: the next two should have the same hash - - - - - - - - - - // TODO: causes bad syntax - {/* */} -
    -) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/expressions/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/expressions/output.js deleted file mode 100644 index b7d0155346bde..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/expressions/output.js +++ /dev/null @@ -1,91 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -const darken = (c)=>c; -const color = 'red'; -const otherColor = 'green'; -const mediumScreen = '680px'; -const animationDuration = '200ms'; -const animationName = 'my-cool-animation'; -const obj = { - display: 'block' -}; -export default (({ display })=>
    - -

    test

    - - <_JSXStyle id={"cb56eab0db38d266"}>{`p.${color}.jsx-b452af554142d27{color:${otherColor};display:${obj.display}}`} - - <_JSXStyle id={"94239b6d6b42c9b5"}>{"p.jsx-b452af554142d27{color:red}"} - - <_JSXStyle id={"e66306ac259712aa"}>{`body{background:${color}}`} - - <_JSXStyle id={"e66306ac259712aa"}>{`body{background:${color}}`} - - // TODO: the next two should have the same hash - - <_JSXStyle id={"f08108daf927b99d"}>{`p.jsx-b452af554142d27{color:${color}}`} - - <_JSXStyle id={"f08108daf927b99d"}>{`p.jsx-b452af554142d27{color:${color}}`} - - <_JSXStyle id={"72e421eb2017491a"} dynamic={[ - darken(color) - ]}>{`p.__jsx-style-dynamic-selector{color:${darken(color)}}`} - - <_JSXStyle id={"d05e300c372f73ee"} dynamic={[ - darken(color) + 2 - ]}>{`p.__jsx-style-dynamic-selector{color:${darken(color) + 2}}`} - - <_JSXStyle id={"7c5c5bde49d6c65d"}>{`@media(min-width:${mediumScreen}){p.jsx-b452af554142d27{color:green}p.jsx-b452af554142d27{color:${`red`}}}p.jsx-b452af554142d27{color:red}`} - - <_JSXStyle id={"c5506be0b4762e0b"}>{`p.jsx-b452af554142d27{-webkit-animation-duration:${animationDuration};-moz-animation-duration:${animationDuration};-o-animation-duration:${animationDuration};animation-duration:${animationDuration}}`} - - <_JSXStyle id={"ed798aa885be9084"}>{`p.jsx-b452af554142d27{-webkit-animation:${animationDuration} forwards ${animationName};-moz-animation:${animationDuration} forwards ${animationName};-o-animation:${animationDuration} forwards ${animationName};animation:${animationDuration} forwards ${animationName}}div.jsx-b452af554142d27{background:${color}}`} - - - - <_JSXStyle id={"469c0b1cc43512b8"} dynamic={[ - display ? 'block' : 'none' - ]}>{`span.__jsx-style-dynamic-selector{display:${display ? 'block' : 'none'}}`} - - // TODO: causes bad syntax - - {} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/external-nested-scope/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/external-nested-scope/input.js deleted file mode 100644 index a6f92b0c0ab90..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/external-nested-scope/input.js +++ /dev/null @@ -1,5 +0,0 @@ -import css from 'styled-jsx/css' - -function test() { - css.resolve`div { color: red }` -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/external-nested-scope/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/external-nested-scope/output.js deleted file mode 100644 index ec88815709af2..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/external-nested-scope/output.js +++ /dev/null @@ -1,7 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -function test() { - ({ - styles: <_JSXStyle id={"abb4c2202db1a207"}>{"div.jsx-abb4c2202db1a207{color:red}"}, - className: "jsx-abb4c2202db1a207" - }); -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-global/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-global/input.js deleted file mode 100644 index 67fdae9bb899b..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-global/input.js +++ /dev/null @@ -1,19 +0,0 @@ -import styles, { foo as styles3 } from './styles' - -const styles2 = require('./styles2') - -export default () => -
    -

    test

    -
    woot
    -

    woot

    - - - -
    diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-global/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-global/output.js deleted file mode 100644 index 862421061d48d..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-global/output.js +++ /dev/null @@ -1,18 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -import styles, { foo as styles3 } from './styles'; -const styles2 = require('./styles2'); -export default (()=>
    - -

    test

    - -
    woot
    - -

    woot

    - - <_JSXStyle id={styles2.__hash}>{styles2} - - <_JSXStyle id={styles3.__hash}>{styles3} - - <_JSXStyle id={styles.__hash}>{styles} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-multi-line/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-multi-line/input.js deleted file mode 100644 index 89c6b449a2946..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-multi-line/input.js +++ /dev/null @@ -1,9 +0,0 @@ -import styles from './styles' - -export default () => -
    -

    test

    - -
    diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-multi-line/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-multi-line/output.js deleted file mode 100644 index f8b2e5133e5e7..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet-multi-line/output.js +++ /dev/null @@ -1,9 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -import styles from './styles'; -export default (()=>
    - -

    test

    - - <_JSXStyle id={styles.__hash}>{styles} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet/input.js deleted file mode 100644 index 4b820d12c1675..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet/input.js +++ /dev/null @@ -1,41 +0,0 @@ -import styles from './styles' -const styles2 = require('./styles2') -import { foo as styles3 } from './styles' - -export default () => ( -
    -

    test

    -

    woot

    - - -
    woot
    - - -
    -) - -export const Test = () => ( -
    -

    test

    -

    woot

    - -
    woot
    - -
    -) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet/output.js deleted file mode 100644 index c22231857c55b..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/external-stylesheet/output.js +++ /dev/null @@ -1,34 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -import styles from './styles'; -const styles2 = require('./styles2'); -import { foo as styles3 } from './styles'; -export default (()=>
    - -

    test

    - -

    woot

    - - <_JSXStyle id={styles2.__hash}>{styles2} - - <_JSXStyle id={styles3.__hash}>{styles3} - -
    woot
    - - <_JSXStyle id={"bee92b62eadf8a14"}>{"p.jsx-bee92b62eadf8a14{color:red}div.jsx-bee92b62eadf8a14{color:green}"} - - <_JSXStyle id={styles.__hash}>{styles} - -
    ); -export const Test = ()=>
    - -

    test

    - -

    woot

    - - <_JSXStyle id={styles3.__hash}>{styles3} - -
    woot
    - - <_JSXStyle id={"bee92b62eadf8a14"}>{"p.jsx-bee92b62eadf8a14{color:red}div.jsx-bee92b62eadf8a14{color:green}"} - -
    ; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/fragment/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/fragment/input.js deleted file mode 100644 index fc5a60bf569bf..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/fragment/input.js +++ /dev/null @@ -1,51 +0,0 @@ -import React from 'react' - -export default () => ( - <> -

    Testing!!!

    -

    Bar

    - <> - - -

    hello

    - <> -

    foo

    -

    bar

    - -

    world

    -
    - - - -) - -function Component1() { - return ( - <> -
    test
    - - ) -} - -function Component2() { - return ( -
    - -
    - ) -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/fragment/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/fragment/output.js deleted file mode 100644 index a0946ccb7bcae..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/fragment/output.js +++ /dev/null @@ -1,47 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -import React from 'react'; -export default (()=><> - -

    Testing!!!

    - -

    Bar

    - - <> - - - - - -

    hello

    - - <> - -

    foo

    - -

    bar

    - - - -

    world

    - -
    - - - - <_JSXStyle id={"6dd5f97e085c0297"}>{"p.jsx-6dd5f97e085c0297{color:cyan}.foo.jsx-6dd5f97e085c0297{font-size:18px;color:hotpink}#head.jsx-6dd5f97e085c0297{text-decoration:underline}"} - - ); -function Component1() { - return <> - -
    test
    - - ; -} -function Component2() { - return
    - - <_JSXStyle id={"678f41ca6d3b294b"}>{"div.jsx-678f41ca6d3b294b{color:red}"} - -
    ; -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/global-child-selector/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/global-child-selector/input.js deleted file mode 100644 index e3cdeef058a8a..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/global-child-selector/input.js +++ /dev/null @@ -1,10 +0,0 @@ -const Test = () => ( -
    - test - -
    -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/global-child-selector/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/global-child-selector/output.js deleted file mode 100644 index 521e38dde02be..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/global-child-selector/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -const Test = ()=>
    - - test - - <_JSXStyle id={"5a206f122d1cb32e"}>{"div.jsx-5a206f122d1cb32e>span{color:red}"} - -
    ; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/global-redundant/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/global-redundant/input.js deleted file mode 100644 index 645ca01c3e9df..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/global-redundant/input.js +++ /dev/null @@ -1,12 +0,0 @@ -export default function IndexPage() { - return ( -
    - should be blue. - -
    - ); -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/global-redundant/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/global-redundant/output.js deleted file mode 100644 index 82762e584a3eb..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/global-redundant/output.js +++ /dev/null @@ -1,10 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default function IndexPage() { - return
    - - should be blue. - - <_JSXStyle id={"b6abd0684ba81871"}>{"div{color:blue}"} - -
    ; -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/global/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/global/input.js deleted file mode 100644 index 75178bdb77c46..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/global/input.js +++ /dev/null @@ -1,22 +0,0 @@ -const Test = () => ( -
    - -
    -) - -const Test2 = () => diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/global/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/global/output.js deleted file mode 100644 index 0e54f9efefe19..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/global/output.js +++ /dev/null @@ -1,7 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -const Test = ()=>
    - - <_JSXStyle id={"d47d6adadf14e957"}>{"body{color:red}:hover{color:red;display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;-webkit-animation:foo 1s ease-out;-moz-animation:foo 1s ease-out;-o-animation:foo 1s ease-out;animation:foo 1s ease-out}div a{display:none}[data-test]>div{color:red}"} - -
    ; -const Test2 = ()=><_JSXStyle id={"94239b6d6b42c9b5"}>{"p{color:red}"}; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30480/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30480/input.js deleted file mode 100644 index c9a5fb9504616..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30480/input.js +++ /dev/null @@ -1,7 +0,0 @@ - - -export default ({ breakPoint }) => ( -
    - -
    -) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30480/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30480/output.js deleted file mode 100644 index a199bc3ffbe34..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30480/output.js +++ /dev/null @@ -1,15 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (({ breakPoint })=>
    - - <_JSXStyle id={"5d2a0e645566ce9c"} dynamic={[ - breakPoint - ]}>{`@media(${breakPoint}){}`} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30570/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30570/input.js deleted file mode 100644 index 30339e7991704..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30570/input.js +++ /dev/null @@ -1,15 +0,0 @@ -export default function IndexPage() { - return ( -
    -

    Hello World.

    - - -
    - ); - } \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30570/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30570/output.js deleted file mode 100644 index 8a59df276c308..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-30570/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default function IndexPage() { - return
    - -

    Hello World.

    - - - - <_JSXStyle id={"bbdada4ef17d18ef"}>{"@supports((display:flex)or (display:-webkit-box)or (display:-webkit-flex)or (display:-moz-box)or (display:-ms-flexbox)){h1{color:hotpink}}"} - -
    ; -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-31562-interpolation-in-mdea/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/issue-31562-interpolation-in-mdea/input.js deleted file mode 100644 index 39b930b9c7c20..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-31562-interpolation-in-mdea/input.js +++ /dev/null @@ -1,30 +0,0 @@ - - - -export default class { - render() { - return ( -
    -

    test

    - -
    - ) - } - } - \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-31562-interpolation-in-mdea/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/issue-31562-interpolation-in-mdea/output.js deleted file mode 100644 index c82016f21c0b6..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/issue-31562-interpolation-in-mdea/output.js +++ /dev/null @@ -1,43 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"60bda1963c17b640"} dynamic={[ - Typography.base.size.default, - Typography.base.lineHeight, - Target.mediumPlus, - Typography.base.size.mediumPlus, - Target.largePlus, - Typography.base.size.largePlus - ]}>{`html{font-size:${Typography.base.size.default};line-height:${Typography.base.lineHeight}}@media ${Target.mediumPlus}{html{font-size:${Typography.base.size.mediumPlus}}}@media ${Target.largePlus}{html{font-size:${Typography.base.size.largePlus}}}`} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/mixed-global-scoped/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/mixed-global-scoped/input.js deleted file mode 100644 index 403ed46ac292f..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/mixed-global-scoped/input.js +++ /dev/null @@ -1,9 +0,0 @@ -const Test = () => - -export default () => ( -
    -

    test

    - - -
    -) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/mixed-global-scoped/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/mixed-global-scoped/output.js deleted file mode 100644 index bb98a20afbc34..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/mixed-global-scoped/output.js +++ /dev/null @@ -1,11 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -const Test = ()=><_JSXStyle id={"94239b6d6b42c9b5"}>{"p{color:red}"}; -export default (()=>
    - -

    test

    - - <_JSXStyle id={"b7efb453c85593c1"}>{"body{background:red}"} - - <_JSXStyle id={"94239b6d6b42c9b5"}>{"p.jsx-3822e6e1fb9fa41a{color:red}"} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/multiple-jsx/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/multiple-jsx/input.js deleted file mode 100644 index 0b1de33780068..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/multiple-jsx/input.js +++ /dev/null @@ -1,43 +0,0 @@ -const attrs = { - id: 'test' -} - -const Test1 = () => ( -
    - test - - -
    -) - -const Test2 = () => test - -const Test3 = () => ( -
    - test - -
    -) - -export default class { - render () { - return ( -
    -

    test

    - -
    - ) - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/multiple-jsx/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/multiple-jsx/output.js deleted file mode 100644 index 5efae23c519e4..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/multiple-jsx/output.js +++ /dev/null @@ -1,32 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -const attrs = { - id: 'test' -}; -const Test1 = ()=>
    - - test - - - - <_JSXStyle id={"a9535d7d5f32c3c4"}>{"span.jsx-a9535d7d5f32c3c4{color:red}"} - -
    ; -const Test2 = ()=>test; -const Test3 = ()=>
    - - test - - <_JSXStyle id={"a9535d7d5f32c3c4"}>{"span.jsx-a9535d7d5f32c3c4{color:red}"} - -
    ; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"b2b86d63f35d25ee"}>{"p.jsx-b2b86d63f35d25ee{color:red}"} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/nested-style-tags/index.js b/packages/next-swc/crates/styled_jsx/tests/fixture/nested-style-tags/index.js deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/nested-style-tags/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/nested-style-tags/output.js deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/non-styled-jsx-style/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/non-styled-jsx-style/input.js deleted file mode 100644 index d4a7da9eec1a8..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/non-styled-jsx-style/input.js +++ /dev/null @@ -1,7 +0,0 @@ -export default () => ( -
    -

    woot

    - - -
    -) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/non-styled-jsx-style/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/non-styled-jsx-style/output.js deleted file mode 100644 index 5977ac8dd5cd8..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/non-styled-jsx-style/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    woot

    - - - - <_JSXStyle id={"94239b6d6b42c9b5"}>{"p.jsx-94239b6d6b42c9b5{color:red}"} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/not-styled-jsx-tagged-templates/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/not-styled-jsx-tagged-templates/input.js deleted file mode 100644 index 212202d499a3a..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/not-styled-jsx-tagged-templates/input.js +++ /dev/null @@ -1,30 +0,0 @@ -import css from 'hell' - -const color = 'red' - -const bar = css` - div { - font-size: 3em; - } -` -export const uh = bar - -export const foo = css`div { color: ${color}}` - -export default css` - div { - font-size: 3em; - } - p { - color: ${color}; - } -` - -const Title = styled.h1` - color: red; - font-size: 50px; -` - -const AnotherTitle = Title.extend`color: blue;` - -export const Component = () => My page diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/not-styled-jsx-tagged-templates/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/not-styled-jsx-tagged-templates/output.js deleted file mode 100644 index 4d147784a9f4c..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/not-styled-jsx-tagged-templates/output.js +++ /dev/null @@ -1,24 +0,0 @@ -import css from 'hell'; -const color = 'red'; -const bar = css` - div { - font-size: 3em; - } -`; -export const uh = bar; -export const foo = css`div { color: ${color}}`; -export default css` - div { - font-size: 3em; - } - p { - color: ${color}; - } -`; -const Title = styled.h1` - color: red; - font-size: 50px; -`; -const AnotherTitle = Title.extend`color: blue;`; -export const Component = ()=>My page -; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/number-after-placeholder/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/number-after-placeholder/input.js deleted file mode 100644 index 99aecf43d93d8..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/number-after-placeholder/input.js +++ /dev/null @@ -1,17 +0,0 @@ -import Link from "next/link"; - -export default function IndexPage() { - return ( -
    - Hello World.{" "} - - Abound - - -
    - ); -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/number-after-placeholder/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/number-after-placeholder/output.js deleted file mode 100644 index babf14f306ed8..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/number-after-placeholder/output.js +++ /dev/null @@ -1,17 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -import Link from "next/link"; -export default function IndexPage() { - return
    - - Hello World.{" "} - - - - Abound - - - - <_JSXStyle id={"9a4b3442d519aae9"}>{`a.jsx-9a4b3442d519aae9{color:${"#abcdef"}12}`} - -
    ; -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/one-off-global-selectors/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/one-off-global-selectors/input.js deleted file mode 100644 index 96aca2778f692..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/one-off-global-selectors/input.js +++ /dev/null @@ -1,10 +0,0 @@ -export default () => ( -
    -

    test

    - -
    -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/one-off-global-selectors/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/one-off-global-selectors/output.js deleted file mode 100644 index 479aff6f659b5..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/one-off-global-selectors/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    test

    - - <_JSXStyle id={"c7c3a8e231c9215a"}>{".container.jsx-c7c3a8e231c9215a>*{color:red}"} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/source-maps/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/source-maps/input.js deleted file mode 100644 index e14ced8ae0f78..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/source-maps/input.js +++ /dev/null @@ -1,8 +0,0 @@ -// TODO: needs sourcemaps -// export default () => ( -//
    -//

    test

    -//

    woot

    -// -//
    -// ) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/source-maps/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/source-maps/output.js deleted file mode 100644 index e14ced8ae0f78..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/source-maps/output.js +++ /dev/null @@ -1,8 +0,0 @@ -// TODO: needs sourcemaps -// export default () => ( -//
    -//

    test

    -//

    woot

    -// -//
    -// ) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/stateless/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/stateless/input.js deleted file mode 100644 index e00df987c1d57..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/stateless/input.js +++ /dev/null @@ -1,8 +0,0 @@ -export default () => ( -
    -

    test

    -

    woot

    -

    woot

    - -
    -) diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/stateless/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/stateless/output.js deleted file mode 100644 index 53d2bfccf343d..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/stateless/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    test

    - -

    woot

    - -

    woot

    - - <_JSXStyle id={"94239b6d6b42c9b5"}>{"p.jsx-94239b6d6b42c9b5{color:red}"} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid/input.js deleted file mode 100644 index 5842604db3a6b..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid/input.js +++ /dev/null @@ -1,13 +0,0 @@ -// TODO -// import css from 'styled-jsx/css' - -// const color = 'red' - -// export const foo = css`div { color: ${color}}` - -// const props = { color: 'red ' } - -// export default css` -// div { font-size: 3em; color: ${props.color} } -// p { color: ${this.props.color};} -// ` diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid/output.js deleted file mode 100644 index 587369e43fc16..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid/output.js +++ /dev/null @@ -1,9 +0,0 @@ -// TODO -// import css from 'styled-jsx/css' -// const color = 'red' -// export const foo = css`div { color: ${color}}` -// const props = { color: 'red ' } -// export default css` -// div { font-size: 3em; color: ${props.color} } -// p { color: ${this.props.color};} -// ` diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid2/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid2/input.js deleted file mode 100644 index 82b0f957c0483..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid2/input.js +++ /dev/null @@ -1,11 +0,0 @@ -// TODO -// import css from 'styled-jsx/css' - -// const color = 'red' - -// export const foo = css`div { color: ${color}}` - -// export default css` -// div { font-size: 3em } -// p { color: ${props.color};} -// ` diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid2/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid2/output.js deleted file mode 100644 index 8f616ffc69542..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/styles-external-invalid2/output.js +++ /dev/null @@ -1,8 +0,0 @@ -// TODO -// import css from 'styled-jsx/css' -// const color = 'red' -// export const foo = css`div { color: ${color}}` -// export default css` -// div { font-size: 3em } -// p { color: ${props.color};} -// ` diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/styles/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/styles/input.js deleted file mode 100644 index 7cbd27576cf26..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/styles/input.js +++ /dev/null @@ -1,57 +0,0 @@ -import css, { resolve, global } from 'styled-jsx/css' -import colors, { size } from './constants' -const color = 'red' - -const bar = css` - div { - font-size: 3em; - } -` - -const baz = css.global` - div { - font-size: 3em; - } -` - -const a = global` - div { - font-size: ${size}em; - } -` - -export const uh = bar - -export const foo = css`div { color: ${color}}` - -css.resolve` - div { - color: ${colors.green.light}; - } - a { color: red } -` - -const b = resolve` - div { - color: ${colors.green.light}; - } - a { color: red } -` - -const dynamic = colors => { - const b = resolve` - div { - color: ${colors.green.light}; - } - a { color: red } - ` -} - -export default css.resolve` - div { - font-size: 3em; - } - p { - color: ${color}; - } -` diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/styles/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/styles/output.js deleted file mode 100644 index ca761e9026328..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/styles/output.js +++ /dev/null @@ -1,39 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -import colors, { size } from './constants'; -const color = 'red'; -const bar = new String("div.jsx-aaed0341accea8f{font-size:3em}"); -bar.__hash = "aaed0341accea8f"; -const baz = new String("div{font-size:3em}"); -baz.__hash = "aaed0341accea8f"; -const a = new String(`div{font-size:${size}em}`); -a.__hash = "b4e02b3e84cc50c"; -export const uh = bar; -export const foo = new String(`div.jsx-1a001e3709d54ba4{color:${color}}`); -foo.__hash = "1a001e3709d54ba4"; -({ - styles: <_JSXStyle id={"38ae14c4ec5e0907"}>{`div.jsx-38ae14c4ec5e0907{color:${colors.green.light}}a.jsx-38ae14c4ec5e0907{color:red}`}, - className: "jsx-38ae14c4ec5e0907" -}); -const b = { - styles: <_JSXStyle id={"38ae14c4ec5e0907"}>{`div.jsx-38ae14c4ec5e0907{color:${colors.green.light}}a.jsx-38ae14c4ec5e0907{color:red}`}, - className: "jsx-38ae14c4ec5e0907" -}; -const dynamic = (colors)=>{ - const b = { - styles: <_JSXStyle id={"b68d3b38146e2a7d"} dynamic={[ - colors.green.light - ]}>{`div.__jsx-style-dynamic-selector{color:${colors.green.light}}a.__jsx-style-dynamic-selector{color:red}`}, - className: _JSXStyle.dynamic([ - [ - "b68d3b38146e2a7d", - [ - colors.green.light - ] - ] - ]) - }; -}; -export default { - styles: <_JSXStyle id={"e14aa5a1efa47449"}>{`div.jsx-e14aa5a1efa47449{font-size:3em}p.jsx-e14aa5a1efa47449{color:${color}}`}, - className: "jsx-e14aa5a1efa47449" -}; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/styles2/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/styles2/input.js deleted file mode 100644 index 6e82bca12d972..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/styles2/input.js +++ /dev/null @@ -1,6 +0,0 @@ -// TODO: support common js -// import css from 'styled-jsx/css' - -// module.exports = css` -// div { font-size: 3em } -// ` \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/styles2/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/styles2/output.js deleted file mode 100644 index cd7ba2952ca51..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/styles2/output.js +++ /dev/null @@ -1,5 +0,0 @@ -// TODO: support common js -// import css from 'styled-jsx/css' -// module.exports = css` -// div { font-size: 3em } -// ` diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/too-many/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/too-many/input.js deleted file mode 100644 index 86905e5ffd65f..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/too-many/input.js +++ /dev/null @@ -1,35 +0,0 @@ - - -export const Red = ({ - Component = 'button', -}) => { - - return ( - - - {/* Dynamic Styles */} - - - ); -}; - diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/too-many/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/too-many/output.js deleted file mode 100644 index 4a79e8cbc9b52..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/too-many/output.js +++ /dev/null @@ -1,49 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export const Red = ({ Component ='button' })=>{ - return - - - - {} - - <_JSXStyle id={"1a9f9e2fa701f7ec"} dynamic={[ - e1, - e2, - e3, - e4, - e5, - e6, - e7, - e8, - e9, - e10, - e11, - e12, - e13, - e14, - e15 - ]}>{`.button.__jsx-style-dynamic-selector{--button-1:${e1};--button-2:${e2};--button-3:${e3};--button-4:${e4};--button-5:${e5};--button-6:${e6};--button-7:${e7};--button-8:${e8};--button-9:${e9};--button-10:${e10};--button-11:${e11};--button-12:${e12};--button-13:${e13};--button-14:${e14};--button-15:${e15}}`} - - ; -}; diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-1/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-1/input.js deleted file mode 100644 index f01a4f41211d1..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-1/input.js +++ /dev/null @@ -1,14 +0,0 @@ -export default class { - render() { - return ( -
    -

    test

    - -
    - ) - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-1/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-1/output.js deleted file mode 100644 index 47b810056b46a..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-1/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"1f6cef12199c3a8f"}>{'p.jsx-1f6cef12199c3a8f{content:"`"}'} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-2/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-2/input.js deleted file mode 100644 index d6ddd44472ad9..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-2/input.js +++ /dev/null @@ -1,17 +0,0 @@ -export default function Home({ fontFamily }) { - return ( -
    - -
    - ) -} \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-2/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-2/output.js deleted file mode 100644 index afa05a46883cc..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-escape-2/output.js +++ /dev/null @@ -1,17 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default function Home({ fontFamily }) { - return
    - - <_JSXStyle id={"3892513b52a23034"} dynamic={[ - fontFamily - ]}>{`body{font-family:${fontFamily}}code:before,code:after{content:"\`"}`} - -
    ; -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-1-as-property/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-1-as-property/input.js deleted file mode 100644 index 578f25c5578ed..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-1-as-property/input.js +++ /dev/null @@ -1,17 +0,0 @@ -export default class { - render() { - return ( -
    -

    test

    - -
    - ) - } - } - \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-1-as-property/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-1-as-property/output.js deleted file mode 100644 index 9f0e2f459754c..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-1-as-property/output.js +++ /dev/null @@ -1,29 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"fc144a5ba38f1ea7"} dynamic={[ - inputSize ? 'height: calc(2 * var(--a)) !important;' : '' - ]}>{`@media only screen{a.__jsx-style-dynamic-selector{${inputSize ? 'height: calc(2 * var(--a)) !important;' : ''} - }}`} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-2-as-part-of-value/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-2-as-part-of-value/input.js deleted file mode 100644 index 3524c05ce1bf3..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-2-as-part-of-value/input.js +++ /dev/null @@ -1,21 +0,0 @@ -export default class { - render() { - return ( -
    -

    test

    - -
    - ) - } - } - \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-2-as-part-of-value/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-2-as-part-of-value/output.js deleted file mode 100644 index 99940aee33e0c..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-2-as-part-of-value/output.js +++ /dev/null @@ -1,34 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"73606d02cbadabf"} dynamic={[ - a[b], - -1 * (c || 0), - d - ]}>{`.a:hover .b.__jsx-style-dynamic-selector{a:${a[b]}px!important;b:translate3d(0,${-1 * (c || 0)}px,-${d}px)scale(1)!important}`} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-3-as-value/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-3-as-value/input.js deleted file mode 100644 index 4528b59e6d23e..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-3-as-value/input.js +++ /dev/null @@ -1,17 +0,0 @@ -export default class { - render() { - return ( -
    -

    test

    - -
    - ) - } - } - \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-3-as-value/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-3-as-value/output.js deleted file mode 100644 index d30c5e9bcc888..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-3-as-value/output.js +++ /dev/null @@ -1,28 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"e37942245bf0eb35"} dynamic={[ - a - ]}>{`@media only screen{a.__jsx-style-dynamic-selector{color:${a}}}`} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-4-as-part-of-value-in-multiple/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-4-as-part-of-value-in-multiple/input.js deleted file mode 100644 index 492bf86a32be4..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-4-as-part-of-value-in-multiple/input.js +++ /dev/null @@ -1,17 +0,0 @@ -export default class { - render() { - return ( -
    -

    test

    - -
    - ) - } - } - \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-4-as-part-of-value-in-multiple/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-4-as-part-of-value-in-multiple/output.js deleted file mode 100644 index 3a6fd3fbbe32d..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-4-as-part-of-value-in-multiple/output.js +++ /dev/null @@ -1,31 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"b9b97de593829e6"} dynamic={[ - a || 'var(--c)', - b || 'inherit' - ]}>{`.a:hover .b.__jsx-style-dynamic-selector{display:inline-block;padding:0 ${a || 'var(--c)'};color:${b || 'inherit'}}`} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-5-values-of-multiple-properties/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-5-values-of-multiple-properties/input.js deleted file mode 100644 index bd1739e0be203..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-5-values-of-multiple-properties/input.js +++ /dev/null @@ -1,16 +0,0 @@ -export default class { - render() { - return ( -
    -

    test

    - -
    - ) - } - } - \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-5-values-of-multiple-properties/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-5-values-of-multiple-properties/output.js deleted file mode 100644 index 58f95cabf3159..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/tpl-placeholder-5-values-of-multiple-properties/output.js +++ /dev/null @@ -1,31 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default class { - render() { - return
    - -

    test

    - - <_JSXStyle id={"23692842dc904882"} dynamic={[ - a ? '100%' : '200px', - b ? '0' : '8px 20px' - ]}>{`.item.__jsx-style-dynamic-selector{max-width:${a ? '100%' : '200px'};padding:${b ? '0' : '8px 20px'}}`} - -
    ; - } -} diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-complex-selector/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-complex-selector/input.js deleted file mode 100644 index 5f3e7a94daf51..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-complex-selector/input.js +++ /dev/null @@ -1,116 +0,0 @@ -export default () => ( -
    -

    test

    - -
    -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-complex-selector/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-complex-selector/output.js deleted file mode 100644 index 37a9d1b4826cf..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-complex-selector/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    test

    - - <_JSXStyle id={"713499aa363d6373"}>{"p.jsx-713499aa363d6373 a.jsx-713499aa363d6373 span.jsx-713499aa363d6373{color:red}p.jsx-713499aa363d6373 span{background:blue}p.jsx-713499aa363d6373 a[title=\"'w ' ' t'\"].jsx-713499aa363d6373{margin:auto}p.jsx-713499aa363d6373 span:not(.test){color:green}p.jsx-713499aa363d6373,h1.jsx-713499aa363d6373{color:blue;-webkit-animation:hahaha 3s ease forwards infinite;-moz-animation:hahaha 3s ease forwards infinite;-o-animation:hahaha 3s ease forwards infinite;animation:hahaha 3s ease forwards infinite;-webkit-animation-name:hahaha;-moz-animation-name:hahaha;-o-animation-name:hahaha;animation-name:hahaha;-webkit-animation-delay:100ms;-moz-animation-delay:100ms;-o-animation-delay:100ms;animation-delay:100ms}p.jsx-713499aa363d6373{-webkit-animation:hahaha 1s,hehehe 2s;-moz-animation:hahaha 1s,hehehe 2s;-o-animation:hahaha 1s,hehehe 2s;animation:hahaha 1s,hehehe 2s}p.jsx-713499aa363d6373:hover{color:red}p.jsx-713499aa363d6373::before{color:red}.jsx-713499aa363d6373:hover{color:red}.jsx-713499aa363d6373::before{color:red}.jsx-713499aa363d6373:hover p.jsx-713499aa363d6373{color:red}p.jsx-713499aa363d6373+a.jsx-713499aa363d6373{color:red}p.jsx-713499aa363d6373~a.jsx-713499aa363d6373{color:red}p.jsx-713499aa363d6373>a.jsx-713499aa363d6373{color:red}@-webkit-keyframes hahaha{from{top:0}to{top:100}}@-moz-keyframes hahaha{from{top:0}to{top:100}}@-o-keyframes hahaha{from{top:0}to{top:100}}@keyframes hahaha{from{top:0}to{top:100}}@-webkit-keyframes hehehe{from{left:0}to{left:100}}@-moz-keyframes hehehe{from{left:0}to{left:100}}@-o-keyframes hehehe{from{left:0}to{left:100}}@keyframes hehehe{from{left:0}to{left:100}}@media(min-width:500px){.test.jsx-713499aa363d6373{color:red}}.test.jsx-713499aa363d6373{display:block}.inline-flex.jsx-713499aa363d6373{display:-webkit-inline-box;display:-webkit-inline-flex;display:-moz-inline-box;display:-ms-inline-flexbox;display:inline-flex}.flex.jsx-713499aa363d6373{display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex}.test.jsx-713499aa363d6373{-webkit-box-shadow:0 0 10px black,inset 0 0 5px black;-moz-box-shadow:0 0 10px black,inset 0 0 5px black;box-shadow:0 0 10px black,inset 0 0 5px black}.test[title=\",\"].jsx-713499aa363d6373{display:inline-block}.test.is-status.jsx-713499aa363d6373 .test.jsx-713499aa363d6373{color:red}.a-selector.jsx-713499aa363d6373:hover,.a-selector.jsx-713499aa363d6373:focus{outline:none}"} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-global/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-global/input.js deleted file mode 100644 index b5c87c4b95bdd..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-global/input.js +++ /dev/null @@ -1,32 +0,0 @@ -export default () => ( -
    -

    test

    - -
    -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-global/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-global/output.js deleted file mode 100644 index a9e2480b87afc..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-global/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    test

    - - <_JSXStyle id={"53fd644ab080300c"}>{'html.jsx-53fd644ab080300c{background-image:-webkit-linear-gradient(bottom,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg);background-image:-moz-linear-gradient(bottom,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg);background-image:-o-linear-gradient(bottom,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg);background-image:linear-gradient(0deg,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg)}p{color:blue}p{color:blue}p,a.jsx-53fd644ab080300c{color:blue}.foo+a{color:red}body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif}'} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-media-query/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-media-query/input.js deleted file mode 100644 index 978d21aacb43f..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-media-query/input.js +++ /dev/null @@ -1,24 +0,0 @@ -export default () => ( -
    -

    test

    - -
    -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-media-query/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-media-query/output.js deleted file mode 100644 index 555929a70b252..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-media-query/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    test

    - - <_JSXStyle id={"1f7963ae04c6466a"}>{'@media(min-width:1px)and (max-width:768px){[class*="grid__col--"].jsx-1f7963ae04c6466a{margin-top:12px;margin-bottom:12px}}@media(max-width:64em){.test.jsx-1f7963ae04c6466a{margin-bottom:1em}@supports(-moz-appearance:none)and (display:contents){.test.jsx-1f7963ae04c6466a{margin-bottom:2rem}}}'} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-normal/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-normal/input.js deleted file mode 100644 index c1964abbf0b2c..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-normal/input.js +++ /dev/null @@ -1,22 +0,0 @@ -export default () => ( -
    -

    test

    - -
    -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-normal/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-normal/output.js deleted file mode 100644 index 6efb20adad800..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-normal/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    test

    - - <_JSXStyle id={"1a19bb4817c105dd"}>{'p.jsx-1a19bb4817c105dd{color:red}p.jsx-1a19bb4817c105dd{color:red}*.jsx-1a19bb4817c105dd{color:blue}[href="woot"].jsx-1a19bb4817c105dd{color:red}'} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-nth-1/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-nth-1/input.js deleted file mode 100644 index 1a119aab50846..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-nth-1/input.js +++ /dev/null @@ -1,10 +0,0 @@ -export default () => ( -
    -

    test

    - -
    - ) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-nth-1/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-nth-1/output.js deleted file mode 100644 index 5351dd0980a28..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css-nth-1/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    test

    - - <_JSXStyle id={"938ca197692ef624"}>{"li.jsx-938ca197692ef624:nth-child(2){color:lime}"} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css/input.js deleted file mode 100644 index 410a080a9924a..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css/input.js +++ /dev/null @@ -1,176 +0,0 @@ -export default () => ( -
    -

    test

    - -
    -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css/output.js deleted file mode 100644 index 1420b4c3e9530..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/transform-css/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    test

    - - <_JSXStyle id={"768337a97aceabd1"}>{'html.jsx-768337a97aceabd1{background-image:-webkit-linear-gradient(bottom,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg);background-image:-moz-linear-gradient(bottom,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg);background-image:-o-linear-gradient(bottom,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg);background-image:linear-gradient(0deg,rgba(255,255,255,.8),rgba(255,255,255,.8)),url(/static/background.svg)}p{color:blue}p{color:blue}p,a.jsx-768337a97aceabd1{color:blue}.foo+a{color:red}body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif}p.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1{color:red}*.jsx-768337a97aceabd1{color:blue}[href="woot"].jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1 a.jsx-768337a97aceabd1 span.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1 span{background:blue}p.jsx-768337a97aceabd1 a[title="\'w \' \' t\'"].jsx-768337a97aceabd1{margin:auto}p.jsx-768337a97aceabd1 span:not(.test){color:green}p.jsx-768337a97aceabd1,h1.jsx-768337a97aceabd1{color:blue;-webkit-animation:hahaha 3s ease forwards infinite;-moz-animation:hahaha 3s ease forwards infinite;-o-animation:hahaha 3s ease forwards infinite;animation:hahaha 3s ease forwards infinite;-webkit-animation-name:hahaha;-moz-animation-name:hahaha;-o-animation-name:hahaha;animation-name:hahaha;-webkit-animation-delay:100ms;-moz-animation-delay:100ms;-o-animation-delay:100ms;animation-delay:100ms}p.jsx-768337a97aceabd1{-webkit-animation:hahaha 1s,hehehe 2s;-moz-animation:hahaha 1s,hehehe 2s;-o-animation:hahaha 1s,hehehe 2s;animation:hahaha 1s,hehehe 2s}p.jsx-768337a97aceabd1:hover{color:red}p.jsx-768337a97aceabd1::before{color:red}.jsx-768337a97aceabd1:hover{color:red}.jsx-768337a97aceabd1::before{color:red}.jsx-768337a97aceabd1:hover p.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1+a.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1~a.jsx-768337a97aceabd1{color:red}p.jsx-768337a97aceabd1>a.jsx-768337a97aceabd1{color:red}@-webkit-keyframes hahaha{from{top:0}to{top:100}}@-moz-keyframes hahaha{from{top:0}to{top:100}}@-o-keyframes hahaha{from{top:0}to{top:100}}@keyframes hahaha{from{top:0}to{top:100}}@-webkit-keyframes hehehe{from{left:0}to{left:100}}@-moz-keyframes hehehe{from{left:0}to{left:100}}@-o-keyframes hehehe{from{left:0}to{left:100}}@keyframes hehehe{from{left:0}to{left:100}}@media(min-width:500px){.test.jsx-768337a97aceabd1{color:red}}.test.jsx-768337a97aceabd1{display:block}.inline-flex.jsx-768337a97aceabd1{display:-webkit-inline-box;display:-webkit-inline-flex;display:-moz-inline-box;display:-ms-inline-flexbox;display:inline-flex}.flex.jsx-768337a97aceabd1{display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex}.test.jsx-768337a97aceabd1{-webkit-box-shadow:0 0 10px black,inset 0 0 5px black;-moz-box-shadow:0 0 10px black,inset 0 0 5px black;box-shadow:0 0 10px black,inset 0 0 5px black}.test[title=","].jsx-768337a97aceabd1{display:inline-block}.test.is-status.jsx-768337a97aceabd1 .test.jsx-768337a97aceabd1{color:red}.a-selector.jsx-768337a97aceabd1:hover,.a-selector.jsx-768337a97aceabd1:focus{outline:none}@media(min-width:1px)and (max-width:768px){[class*="grid__col--"].jsx-768337a97aceabd1{margin-top:12px;margin-bottom:12px}}@media(max-width:64em){.test.jsx-768337a97aceabd1{margin-bottom:1em}@supports(-moz-appearance:none)and (display:contents){.test.jsx-768337a97aceabd1{margin-bottom:2rem}}}'} - -
    ); diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/whitespace/input.js b/packages/next-swc/crates/styled_jsx/tests/fixture/whitespace/input.js deleted file mode 100644 index 8a6d778285d88..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/whitespace/input.js +++ /dev/null @@ -1,12 +0,0 @@ -export default () => ( -
    -

    test

    -

    woot

    -

    woot

    - -
    -) \ No newline at end of file diff --git a/packages/next-swc/crates/styled_jsx/tests/fixture/whitespace/output.js b/packages/next-swc/crates/styled_jsx/tests/fixture/whitespace/output.js deleted file mode 100644 index 53d2bfccf343d..0000000000000 --- a/packages/next-swc/crates/styled_jsx/tests/fixture/whitespace/output.js +++ /dev/null @@ -1,12 +0,0 @@ -import _JSXStyle from "styled-jsx/style"; -export default (()=>
    - -

    test

    - -

    woot

    - -

    woot

    - - <_JSXStyle id={"94239b6d6b42c9b5"}>{"p.jsx-94239b6d6b42c9b5{color:red}"} - -
    ); diff --git a/packages/next-swc/crates/wasm/Cargo.toml b/packages/next-swc/crates/wasm/Cargo.toml index 6a46d53d82317..3ffccc38cf603 100644 --- a/packages/next-swc/crates/wasm/Cargo.toml +++ b/packages/next-swc/crates/wasm/Cargo.toml @@ -45,7 +45,7 @@ swc_core = { features = [ "ecma_parser_typescript", "ecma_utils", "ecma_visit" -], version = "0.39.7" } +], version = "0.40.7" } # Workaround a bug diff --git a/packages/next-swc/package.json b/packages/next-swc/package.json index a2eb7579095e1..d84f7b905268b 100644 --- a/packages/next-swc/package.json +++ b/packages/next-swc/package.json @@ -1,6 +1,6 @@ { "name": "@next/swc", - "version": "12.3.2-canary.32", + "version": "12.3.2-canary.33", "private": true, "scripts": { "build-native": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi --features plugin --js false native", diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index ca99f1eb8d164..b35b6dfab2641 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -207,7 +207,7 @@ export function getEdgeServerEntry(opts: { // The Edge bundle includes the server in its entrypoint, so it has to // be in the SSR layer — we later convert the page request to the RSC layer // via a webpack rule. - layer: undefined, + layer: WEBPACK_LAYERS.client, } } diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index f5bee9cdc7f73..7bb43e991ab93 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -303,10 +303,9 @@ export default async function build( const publicDir = path.join(dir, 'public') const isAppDirEnabled = !!config.experimental.appDir if (isAppDirEnabled) { - process.env.HAS_APP_DIR = '1' + process.env.NEXT_PREBUNDLED_REACT = '1' } const { pagesDir, appDir } = findPagesDir(dir, isAppDirEnabled) - const hasPublicDir = await fileExists(publicDir) telemetry.record( @@ -1365,148 +1364,152 @@ export default async function build( if (pageType === 'app' && originalAppPath) { appNormalizedPaths.set(originalAppPath, page) - // TODO-APP: handle prerendering with edge - // runtime if (pageRuntime === 'experimental-edge') { - return - } - - if ( - workerResult.encodedPrerenderRoutes && - workerResult.prerenderRoutes - ) { - appStaticPaths.set( - originalAppPath, + isStatic = false + isSsg = false + } else { + if ( + workerResult.encodedPrerenderRoutes && workerResult.prerenderRoutes - ) - appStaticPathsEncoded.set( + ) { + appStaticPaths.set( + originalAppPath, + workerResult.prerenderRoutes + ) + appStaticPathsEncoded.set( + originalAppPath, + workerResult.encodedPrerenderRoutes + ) + ssgPageRoutes = workerResult.prerenderRoutes + isSsg = true + } + if ( + !isDynamicRoute(page) && + workerResult.appConfig?.revalidate !== 0 + ) { + appStaticPaths.set(originalAppPath, [page]) + appStaticPathsEncoded.set(originalAppPath, [page]) + isStatic = true + } + if (workerResult.prerenderFallback) { + // whether or not to allow requests for paths not + // returned from generateStaticParams + appDynamicParamPaths.add(originalAppPath) + } + appDefaultConfigs.set( originalAppPath, - workerResult.encodedPrerenderRoutes + workerResult.appConfig || {} ) } - if (!isDynamicRoute(page)) { - appStaticPaths.set(originalAppPath, [page]) - appStaticPathsEncoded.set(originalAppPath, [page]) - } - if (workerResult.prerenderFallback) { - // whether or not to allow requests for paths not - // returned from generateStaticParams - appDynamicParamPaths.add(originalAppPath) + } else { + if (pageRuntime === SERVER_RUNTIME.edge) { + if (workerResult.hasStaticProps) { + console.warn( + `"getStaticProps" is not yet supported fully with "experimental-edge", detected on ${page}` + ) + } + // TODO: add handling for statically rendering edge + // pages and allow edge with Prerender outputs + workerResult.isStatic = false + workerResult.hasStaticProps = false } - appDefaultConfigs.set( - originalAppPath, - workerResult.appConfig || {} - ) - return - } - if (pageRuntime === SERVER_RUNTIME.edge) { - if (workerResult.hasStaticProps) { - console.warn( - `"getStaticProps" is not yet supported fully with "experimental-edge", detected on ${page}` + if (config.outputFileTracing) { + pageTraceIncludes.set( + page, + workerResult.traceIncludes || [] + ) + pageTraceExcludes.set( + page, + workerResult.traceExcludes || [] ) } - // TODO: add handling for statically rendering edge - // pages and allow edge with Prerender outputs - workerResult.isStatic = false - workerResult.hasStaticProps = false - } - if (config.outputFileTracing) { - pageTraceIncludes.set( - page, - workerResult.traceIncludes || [] - ) - pageTraceExcludes.set( - page, - workerResult.traceExcludes || [] - ) - } - - if ( - workerResult.isStatic === false && - (workerResult.isHybridAmp || workerResult.isAmpOnly) - ) { - hasSsrAmpPages = true - } + if ( + workerResult.isStatic === false && + (workerResult.isHybridAmp || workerResult.isAmpOnly) + ) { + hasSsrAmpPages = true + } - if (workerResult.isHybridAmp) { - isHybridAmp = true - hybridAmpPages.add(page) - } + if (workerResult.isHybridAmp) { + isHybridAmp = true + hybridAmpPages.add(page) + } - if (workerResult.isNextImageImported) { - isNextImageImported = true - } + if (workerResult.isNextImageImported) { + isNextImageImported = true + } - if (workerResult.hasStaticProps) { - ssgPages.add(page) - isSsg = true + if (workerResult.hasStaticProps) { + ssgPages.add(page) + isSsg = true - if ( - workerResult.prerenderRoutes && - workerResult.encodedPrerenderRoutes - ) { - additionalSsgPaths.set( - page, - workerResult.prerenderRoutes - ) - additionalSsgPathsEncoded.set( - page, + if ( + workerResult.prerenderRoutes && workerResult.encodedPrerenderRoutes - ) - ssgPageRoutes = workerResult.prerenderRoutes + ) { + additionalSsgPaths.set( + page, + workerResult.prerenderRoutes + ) + additionalSsgPathsEncoded.set( + page, + workerResult.encodedPrerenderRoutes + ) + ssgPageRoutes = workerResult.prerenderRoutes + } + + if (workerResult.prerenderFallback === 'blocking') { + ssgBlockingFallbackPages.add(page) + } else if (workerResult.prerenderFallback === true) { + ssgStaticFallbackPages.add(page) + } + } else if (workerResult.hasServerProps) { + serverPropsPages.add(page) + } else if ( + workerResult.isStatic && + !isServerComponent && + (await customAppGetInitialPropsPromise) === false + ) { + staticPages.add(page) + isStatic = true + } else if (isServerComponent) { + // This is a static server component page that doesn't have + // gSP or gSSP. We still treat it as a SSG page. + ssgPages.add(page) + isSsg = true } - if (workerResult.prerenderFallback === 'blocking') { - ssgBlockingFallbackPages.add(page) - } else if (workerResult.prerenderFallback === true) { - ssgStaticFallbackPages.add(page) + if (hasPages404 && page === '/404') { + if ( + !workerResult.isStatic && + !workerResult.hasStaticProps + ) { + throw new Error( + `\`pages/404\` ${STATIC_STATUS_PAGE_GET_INITIAL_PROPS_ERROR}` + ) + } + // we need to ensure the 404 lambda is present since we use + // it when _app has getInitialProps + if ( + (await customAppGetInitialPropsPromise) && + !workerResult.hasStaticProps + ) { + staticPages.delete(page) + } } - } else if (workerResult.hasServerProps) { - serverPropsPages.add(page) - } else if ( - workerResult.isStatic && - !isServerComponent && - (await customAppGetInitialPropsPromise) === false - ) { - staticPages.add(page) - isStatic = true - } else if (isServerComponent) { - // This is a static server component page that doesn't have - // gSP or gSSP. We still treat it as a SSG page. - ssgPages.add(page) - isSsg = true - } - if (hasPages404 && page === '/404') { if ( + STATIC_STATUS_PAGES.includes(page) && !workerResult.isStatic && !workerResult.hasStaticProps ) { throw new Error( - `\`pages/404\` ${STATIC_STATUS_PAGE_GET_INITIAL_PROPS_ERROR}` + `\`pages${page}\` ${STATIC_STATUS_PAGE_GET_INITIAL_PROPS_ERROR}` ) } - // we need to ensure the 404 lambda is present since we use - // it when _app has getInitialProps - if ( - (await customAppGetInitialPropsPromise) && - !workerResult.hasStaticProps - ) { - staticPages.delete(page) - } - } - - if ( - STATIC_STATUS_PAGES.includes(page) && - !workerResult.isStatic && - !workerResult.hasStaticProps - ) { - throw new Error( - `\`pages${page}\` ${STATIC_STATUS_PAGE_GET_INITIAL_PROPS_ERROR}` - ) } } catch (err) { if ( @@ -2151,6 +2154,13 @@ export default async function build( } } else { hasDynamicData = true + // we might have determined during prerendering that this page + // used dynamic data + pageInfos.set(route, { + ...(pageInfos.get(route) as PageInfo), + isSsg: false, + static: false, + }) } }) diff --git a/packages/next/build/utils.ts b/packages/next/build/utils.ts index 8165f4a417f21..f30bd6143dc46 100644 --- a/packages/next/build/utils.ts +++ b/packages/next/build/utils.ts @@ -54,7 +54,7 @@ import { } from './webpack/require-hook' loadRequireHook() -if (process.env.HAS_APP_DIR) { +if (process.env.NEXT_PREBUNDLED_REACT) { overrideBuiltInReactPackages() } @@ -412,7 +412,7 @@ export async function printTreeView( (pageInfo?.ssgPageDurations?.reduce((a, b) => a + (b || 0), 0) || 0) const symbol = - routerType === 'app' || item === '/_app' || item === '/_app.server' + item === '/_app' || item === '/_app.server' ? ' ' : pageInfo?.static ? '○' @@ -427,7 +427,7 @@ export async function printTreeView( if (pageInfo?.initialRevalidateSeconds) usedSymbols.add('ISR') messages.push([ - `${border} ${routerType === 'pages' ? `${symbol} ` : ''}${ + `${border} ${symbol} ${ pageInfo?.initialRevalidateSeconds ? `${item} (ISR: ${pageInfo?.initialRevalidateSeconds} Seconds)` : item diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 375f2c760c338..be420d888ab33 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -125,9 +125,11 @@ function isResourceInPackages(resource: string, packageNames?: string[]) { ) } -const builtInReactImports = [ +const bundledReactImports = [ 'react', 'react/jsx-runtime', + 'react/jsx-dev-runtime', + // 'react-dom', 'next/dist/compiled/react-server-dom-webpack/server.browser', ] @@ -593,6 +595,11 @@ export default async function getBaseWebpackConfig( 'You are using the experimental Node.js Runtime with `experimental.runtime`.' ) } + if (config.experimental.appDir) { + Log.warn( + 'You are using the experimental app directory with `experimental.appDir`, the API might change.' + ) + } } const babelConfigFile = await BABEL_CONFIG_FILES.reduce( @@ -1013,7 +1020,7 @@ export default async function getBaseWebpackConfig( const crossOrigin = config.crossOrigin const looseEsmExternals = config.experimental?.esmExternals === 'loose' - const optoutBundlingPackages = EXTERNAL_PACKAGES.concat( + const optOutBundlingPackages = EXTERNAL_PACKAGES.concat( ...(config.experimental.serverComponentsExternalPackages || []) ) @@ -1048,7 +1055,7 @@ export default async function getBaseWebpackConfig( // Special internal modules that must be bundled for Server Components. if (layer === WEBPACK_LAYERS.server) { - if (builtInReactImports.includes(request)) { + if (bundledReactImports.includes(request)) { return } } @@ -1183,18 +1190,31 @@ export default async function getBaseWebpackConfig( if (layer === WEBPACK_LAYERS.server) { // All packages should be bundled for the server layer if they're not opted out. // This option takes priority over the transpilePackages option. - if ( - isResourceInPackages( - res, - config.experimental.serverComponentsExternalPackages - ) - ) { + if (isResourceInPackages(res, optOutBundlingPackages)) { return `${externalType} ${request}` } return } + // Treat react packages as external for SSR layer, + // then let require-hook mapping them to internals. + if (layer === WEBPACK_LAYERS.client) { + if ( + [ + 'react', + 'react/jsx-runtime', + 'react/jsx-dev-runtime', + 'react-dom', + 'scheduler', + ].includes(request) + ) { + return `commonjs next/dist/compiled/${request}` + } else { + return + } + } + if (shouldBeBundled) return // Anything else that is standard JavaScript within `node_modules` @@ -1541,30 +1561,7 @@ export default async function getBaseWebpackConfig( }, module: { rules: [ - // TODO: FIXME: do NOT webpack 5 support with this - // x-ref: https://github.com/webpack/webpack/issues/11467 - ...(!config.experimental.fullySpecified - ? [ - { - test: /\.m?js/, - resolve: { - fullySpecified: false, - }, - } as any, - ] - : []), - ...(hasAppDir && isEdgeServer - ? [ - // The Edge bundle includes the server in its entrypoint, so it has to - // be in the SSR layer — here we convert the actual page request to - // the RSC layer via a webpack rule. - { - resourceQuery: /__edge_ssr_entry__/, - layer: WEBPACK_LAYERS.server, - }, - ] - : []), - ...(hasAppDir && !isClient + ...(hasAppDir && !isClient && !isEdgeServer ? [ { issuerLayer: WEBPACK_LAYERS.server, @@ -1573,7 +1570,10 @@ export default async function getBaseWebpackConfig( // bundling, don't resolve it. if ( !codeCondition.test.test(req) || - isResourceInPackages(req, optoutBundlingPackages) + isResourceInPackages( + req, + config.experimental.serverComponentsExternalPackages + ) ) { return false } @@ -1586,13 +1586,39 @@ export default async function getBaseWebpackConfig( // If missing the alias override here, the default alias will be used which aliases // react to the direct file path, not the package name. In that case the condition // will be ignored completely. - react: 'react', - 'react-dom': 'react-dom', + react: 'next/dist/compiled/react', + 'react-dom$': isClient + ? 'next/dist/compiled/react-dom/index' + : 'next/dist/compiled/react-dom/server-rendering-stub', + 'react-dom/client$': 'next/dist/compiled/react-dom/client', }, }, }, ] : []), + // TODO: FIXME: do NOT webpack 5 support with this + // x-ref: https://github.com/webpack/webpack/issues/11467 + ...(!config.experimental.fullySpecified + ? [ + { + test: /\.m?js/, + resolve: { + fullySpecified: false, + }, + } as any, + ] + : []), + ...(hasAppDir && isEdgeServer + ? [ + // The Edge bundle includes the server in its entrypoint, so it has to + // be in the SSR layer — here we convert the actual page request to + // the RSC layer via a webpack rule. + { + resourceQuery: /__edge_ssr_entry__/, + layer: WEBPACK_LAYERS.server, + }, + ] + : []), ...(hasServerComponents && !isClient ? [ // RSC server compilation loaders @@ -1615,7 +1641,12 @@ export default async function getBaseWebpackConfig( ? [ { test: codeCondition.test, - include: [appDir], + issuerLayer(layer: string) { + return ( + layer === WEBPACK_LAYERS.client || + layer === WEBPACK_LAYERS.server + ) + }, resolve: { alias: { // Alias `next/dynamic` to React.lazy implementation for RSC @@ -1632,12 +1663,12 @@ export default async function getBaseWebpackConfig( { // test: codeCondition.test, issuerLayer: WEBPACK_LAYERS.server, - test: (req: string) => { + test(req: string) { // If it's not a source code file, or has been opted out of // bundling, don't resolve it. if ( !codeCondition.test.test(req) || - isResourceInPackages(req, optoutBundlingPackages) + isResourceInPackages(req, optOutBundlingPackages) ) { return false } diff --git a/packages/next/build/webpack/loaders/next-font-loader/index.ts b/packages/next/build/webpack/loaders/next-font-loader/index.ts index 6edc12b4dddc6..de340cddd0d55 100644 --- a/packages/next/build/webpack/loaders/next-font-loader/index.ts +++ b/packages/next/build/webpack/loaders/next-font-loader/index.ts @@ -1,10 +1,12 @@ import type { FontLoader } from '../../../../font' +import { promises as fs } from 'fs' import path from 'path' import loaderUtils from 'next/dist/compiled/loader-utils3' import postcssFontLoaderPlugn from './postcss-font-loader' import { promisify } from 'util' import chalk from 'next/dist/compiled/chalk' +import { CONFIG_FILES } from '../../../../shared/lib/constants' export default async function nextFontLoader(this: any) { const fontLoaderSpan = this.currentTraceSpan.traceChild('next-font-loader') @@ -17,6 +19,24 @@ export default async function nextFontLoader(this: any) { postcss: getPostcss, } = this.getOptions() + const nextConfigPaths = CONFIG_FILES.map((config) => + path.join(this.rootContext, config) + ) + // Add next.config.js as a dependency, loaders must rerun in case options changed + await Promise.all( + nextConfigPaths.map(async (configPath) => { + const hasConfig = await fs.access(configPath).then( + () => true, + () => false + ) + if (hasConfig) { + this.addDependency(configPath) + } else { + this.addMissingDependency(configPath) + } + }) + ) + const emitFontFile = (content: Buffer, ext: string, preload: boolean) => { const opts = { context: this.rootContext, content } const interpolatedName = loaderUtils.interpolateName( @@ -55,7 +75,7 @@ export default async function nextFontLoader(this: any) { path.dirname( path.join(this.rootContext, relativeFilePathFromRoot) ), - src + src.startsWith('.') ? src : `./${src}` ), fs: this.fs, }) diff --git a/packages/next/build/webpack/loaders/next-serverless-loader/utils.ts b/packages/next/build/webpack/loaders/next-serverless-loader/utils.ts index c1973f7341eaf..98e4834a59159 100644 --- a/packages/next/build/webpack/loaders/next-serverless-loader/utils.ts +++ b/packages/next/build/webpack/loaders/next-serverless-loader/utils.ts @@ -108,19 +108,19 @@ export function interpolateDynamicPath( if (paramIdx > -1) { let paramValue: string + const value = params[param] - if (Array.isArray(params[param])) { - paramValue = (params[param] as string[]) - .map((v) => v && encodeURIComponent(v)) - .join('/') + if (Array.isArray(value)) { + paramValue = value.map((v) => v && encodeURIComponent(v)).join('/') + } else if (value) { + paramValue = encodeURIComponent(value) } else { - paramValue = - params[param] && encodeURIComponent(params[param] as string) + paramValue = '' } pathname = pathname.slice(0, paramIdx) + - (paramValue || '') + + paramValue + pathname.slice(paramIdx + builtParam.length) } } @@ -293,7 +293,7 @@ export function getUtils({ // favor named matches if available const routeKeyNames = Object.keys(routeKeys || {}) - const filterLocaleItem = (val: string | string[]) => { + const filterLocaleItem = (val: string | string[] | undefined) => { if (i18n) { // locale items can be included in route-matches // for fallback SSG pages so ensure they are @@ -604,7 +604,7 @@ export function getUtils({ ), interpolateDynamicPath: ( pathname: string, - params: Record + params: Record ) => interpolateDynamicPath(pathname, params, defaultRouteRegex), } } diff --git a/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts b/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts index 4427f89bd3d7e..41c983490cdca 100644 --- a/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts +++ b/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts @@ -67,6 +67,7 @@ export class FlightClientEntryPlugin { compiler.hooks.afterCompile.tap(PLUGIN_NAME, (compilation) => { traverseModules(compilation, (mod) => { + // const modId = compilation.chunkGraph.getModuleId(mod) + '' // The module must has request, and resource so it's not a new entry created with loader. // Using the client layer module, which doesn't have `rsc` tag in buildInfo. if (mod.request && mod.resource && !mod.buildInfo.rsc) { @@ -76,17 +77,17 @@ export class FlightClientEntryPlugin { } }) - const recordModule = (id: number | string, mod: any) => { + const recordModule = (modId: string, mod: any) => { const modResource = mod.resourceResolveData?.path || mod.resource if ( - mod.resourceResolveData?.context?.issuerLayer === - WEBPACK_LAYERS.server + mod.resourceResolveData?.context?.issuerLayer !== + WEBPACK_LAYERS.client ) { return } - if (typeof id !== 'undefined' && modResource) { + if (typeof modId !== 'undefined' && modResource) { // Note that this isn't that reliable as webpack is still possible to assign // additional queries to make sure there's no conflict even using the `named` // module ID strategy. @@ -99,16 +100,16 @@ export class FlightClientEntryPlugin { if (this.isEdgeServer) { edgeServerModuleIds.set( ssrNamedModuleId.replace(/\/next\/dist\/esm\//, '/next/dist/'), - id + modId ) } else { - serverModuleIds.set(ssrNamedModuleId, id) + serverModuleIds.set(ssrNamedModuleId, modId) } } } traverseModules(compilation, (mod, _chunk, _chunkGroup, modId) => { - recordModule(modId, mod) + recordModule(modId + '', mod) }) }) } @@ -230,9 +231,10 @@ export class FlightClientEntryPlugin { function collectModule(entryName: string, mod: any) { const resource = mod.resource - if (resource) { - if (regexCSS.test(resource)) { - cssImportsForChunk[entryName].push(resource) + const modId = resource // compilation.chunkGraph.getModuleId(mod) + '' + if (modId) { + if (regexCSS.test(modId)) { + cssImportsForChunk[entryName].push(modId) } } } @@ -348,18 +350,20 @@ export class FlightClientEntryPlugin { // native or installed js module: -> raw request, e.g. next/head // client js or css: -> user request const rawRequest = mod.rawRequest - // Request could be undefined or '' if (!rawRequest) return const isCSS = regexCSS.test(rawRequest) - const modRequest: string | undefined = + const isLocal = !isCSS && !rawRequest.startsWith('.') && !rawRequest.startsWith('/') && !rawRequest.startsWith(APP_DIR_ALIAS) - ? rawRequest - : mod.resourceResolveData?.path + mod.resourceResolveData?.query + + const modRequest: string | undefined = isLocal + ? rawRequest // compilation.chunkGraph.getModuleId(mod) + '' + : mod.resourceResolveData?.path + mod.resourceResolveData?.query + // console.log('modId:after', modRequest) // Ensure module is not walked again if it's already been visited if (!visitedBySegment[layoutOrPageRequest]) { @@ -501,9 +505,9 @@ export class FlightClientEntryPlugin { { // By using the same entry name name: entryName, - // Layer should be undefined for the SSR modules - // This ensures the client components are - layer: undefined, + // Layer should be client for the SSR modules + // This ensures the client components are bundled on client layer + layer: WEBPACK_LAYERS.client, } ) diff --git a/packages/next/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/build/webpack/plugins/flight-manifest-plugin.ts index 89ec15471bcd2..81dc53caeaada 100644 --- a/packages/next/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/build/webpack/plugins/flight-manifest-plugin.ts @@ -186,6 +186,8 @@ export class FlightManifestPlugin { context, mod.resourceResolveData?.path || resource ) + // if (resource.includes('script')) + // console.log('ssrNamedModuleId', ssrNamedModuleId, modId) if (!ssrNamedModuleId.startsWith('.')) // TODO use getModuleId instead ssrNamedModuleId = `./${ssrNamedModuleId.replace(/\\/g, '/')}` @@ -317,7 +319,7 @@ export class FlightManifestPlugin { // TODO: Update type so that it doesn't have to be cast. ) as Iterable for (const mod of chunkModules) { - const modId = compilation.chunkGraph.getModuleId(mod) + const modId: string = compilation.chunkGraph.getModuleId(mod) + '' recordModule(chunk, modId, mod) diff --git a/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts b/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts index a33478e7d5de5..ee0c0627c1fc9 100644 --- a/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts +++ b/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts @@ -85,7 +85,7 @@ export async function getNotFoundError( .filter( (name) => name && - !/next-(middleware|client-pages|flight-(client|server))-loader\.js/.test( + !/next-(middleware|client-pages|flight-(client|server|client-entry))-loader\.js/.test( name ) ) diff --git a/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts b/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts index 7995032ac9726..0c78ff1d82f6d 100644 --- a/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts +++ b/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts @@ -25,14 +25,20 @@ export function formatRSCErrorMessage( '\n\nMaybe one of these should be marked as a client entry with "use client":\n' } else if (NEXT_RSC_ERR_SERVER_IMPORT.test(message)) { const matches = message.match(NEXT_RSC_ERR_SERVER_IMPORT) - if (matches && matches[1] === 'react-dom/server') { - // If importing "react-dom/server", we should show a different error. - formattedMessage = `\n\nYou're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.` - } else { - formattedMessage = message.replace( - NEXT_RSC_ERR_SERVER_IMPORT, - `\n\nYou're importing a component that imports $1. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.\n\n` - ) + switch (matches && matches[1]) { + case 'react-dom/server': + // If importing "react-dom/server", we should show a different error. + formattedMessage = `\n\nYou're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.` + break + case 'next/router': + // If importing "next/router", we should tell them to use "next/navigation". + formattedMessage = `\n\nYou have a Server Component that imports next/router. Use next/navigation instead.` + break + default: + formattedMessage = message.replace( + NEXT_RSC_ERR_SERVER_IMPORT, + `\n\nYou're importing a component that imports $1. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.\n\n` + ) } formattedVerboseMessage = '\n\nMaybe one of these should be marked as a client entry "use client":\n' diff --git a/packages/next/client/app-index.tsx b/packages/next/client/app-index.tsx index 7578677a474e7..d4d3bf13fe0c1 100644 --- a/packages/next/client/app-index.tsx +++ b/packages/next/client/app-index.tsx @@ -8,7 +8,8 @@ import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-we import measureWebVitals from './performance-relayer' import { HeadManagerContext } from '../shared/lib/head-manager-context' -import HotReload from './components/react-dev-overlay/hot-reloader' +import HotReload from './components/react-dev-overlay/hot-reloader-client' +import { GlobalLayoutRouterContext } from '../shared/lib/app-router-context' /// @@ -186,15 +187,24 @@ export function hydrate() { const reactRoot = (ReactDOMClient as any).createRoot(reactRootElement) reactRoot.render( - {}, + focusAndScrollRef: { + apply: false, }, }} - initialTree={rootLayoutMissingTagsError.tree} - /> + > + + ) return diff --git a/packages/next/client/components/app-router.tsx b/packages/next/client/components/app-router.tsx index 024dd1ab77b08..09491dc8a7c60 100644 --- a/packages/next/client/components/app-router.tsx +++ b/packages/next/client/components/app-router.tsx @@ -37,12 +37,12 @@ function urlToUrlWithoutFlightMarker(url: string): URL { } const HotReloader: - | typeof import('./react-dev-overlay/hot-reloader').default + | typeof import('./react-dev-overlay/hot-reloader-client').default | null = process.env.NODE_ENV === 'production' ? null - : (require('./react-dev-overlay/hot-reloader') - .default as typeof import('./react-dev-overlay/hot-reloader').default) + : (require('./react-dev-overlay/hot-reloader-client') + .default as typeof import('./react-dev-overlay/hot-reloader-client').default) /** * Fetch the flight data for the provided url. Takes in the current router state to decide what to render server-side. diff --git a/packages/next/client/components/react-dev-overlay/client.ts b/packages/next/client/components/react-dev-overlay/client.ts deleted file mode 100644 index 726747a8346ce..0000000000000 --- a/packages/next/client/components/react-dev-overlay/client.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { Dispatch, ReducerAction } from 'react' -import type { errorOverlayReducer } from './internal/error-overlay-reducer' -import { - ACTION_BUILD_OK, - ACTION_BUILD_ERROR, - ACTION_REFRESH, - ACTION_UNHANDLED_ERROR, - ACTION_UNHANDLED_REJECTION, -} from './internal/error-overlay-reducer' -import { parseStack } from './internal/helpers/parseStack' - -export type DispatchFn = Dispatch> - -export function onUnhandledError(dispatch: DispatchFn, ev: ErrorEvent) { - const error = ev?.error - if (!error || !(error instanceof Error) || typeof error.stack !== 'string') { - // A non-error was thrown, we don't have anything to show. :-( - return - } - - if ( - error.message.match(/(hydration|content does not match|did not match)/i) - ) { - error.message += `\n\nSee more info here: https://nextjs.org/docs/messages/react-hydration-error` - } - - const e = error - dispatch({ - type: ACTION_UNHANDLED_ERROR, - reason: error, - frames: parseStack(e.stack!), - }) -} - -export function onUnhandledRejection( - dispatch: DispatchFn, - ev: PromiseRejectionEvent -) { - const reason = ev?.reason - if ( - !reason || - !(reason instanceof Error) || - typeof reason.stack !== 'string' - ) { - // A non-error was thrown, we don't have anything to show. :-( - return - } - - const e = reason - dispatch({ - type: ACTION_UNHANDLED_REJECTION, - reason: reason, - frames: parseStack(e.stack!), - }) -} - -export function onBuildOk(dispatch: DispatchFn) { - dispatch({ type: ACTION_BUILD_OK }) -} - -export function onBuildError(dispatch: DispatchFn, message: string) { - dispatch({ type: ACTION_BUILD_ERROR, message }) -} - -export function onRefresh(dispatch: DispatchFn) { - dispatch({ type: ACTION_REFRESH }) -} - -export { getErrorByType } from './internal/helpers/getErrorByType' -export { getServerError } from './internal/helpers/nodeStackFrames' -export { default as ReactDevOverlay } from './internal/ReactDevOverlay' diff --git a/packages/next/client/components/react-dev-overlay/hot-reloader.tsx b/packages/next/client/components/react-dev-overlay/hot-reloader-client.tsx similarity index 52% rename from packages/next/client/components/react-dev-overlay/hot-reloader.tsx rename to packages/next/client/components/react-dev-overlay/hot-reloader-client.tsx index 128507a72a5bd..750fb7da79ac4 100644 --- a/packages/next/client/components/react-dev-overlay/hot-reloader.tsx +++ b/packages/next/client/components/react-dev-overlay/hot-reloader-client.tsx @@ -1,76 +1,52 @@ import type { ReactNode } from 'react' -import type { FlightRouterState } from '../../../server/app-render' import React, { useCallback, - useContext, useEffect, - useRef, + useReducer, + useMemo, // @ts-expect-error TODO-APP: startTransition exists startTransition, } from 'react' -import { GlobalLayoutRouterContext } from '../../../shared/lib/app-router-context' -import { - onBuildError, - onBuildOk, - onRefresh, - onUnhandledError, - onUnhandledRejection, - ReactDevOverlay, -} from './client' -import type { DispatchFn } from './client' import stripAnsi from 'next/dist/compiled/strip-ansi' import formatWebpackMessages from '../../dev/error-overlay/format-webpack-messages' import { useRouter } from '../navigation' +import { errorOverlayReducer } from './internal/error-overlay-reducer' import { - errorOverlayReducer, - OverlayState, + ACTION_BUILD_OK, + ACTION_BUILD_ERROR, + ACTION_REFRESH, + ACTION_UNHANDLED_ERROR, + ACTION_UNHANDLED_REJECTION, } from './internal/error-overlay-reducer' - -function getSocketProtocol(assetPrefix: string): string { - let protocol = window.location.protocol - - try { - // assetPrefix is a url - protocol = new URL(assetPrefix).protocol - } catch (_) {} - - return protocol === 'http:' ? 'ws' : 'wss' +import { parseStack } from './internal/helpers/parseStack' +import ReactDevOverlay from './internal/ReactDevOverlay' +import { useErrorHandler } from './internal/helpers/use-error-handler' +import { + useSendMessage, + useWebsocket, + useWebsocketPing, +} from './internal/helpers/use-websocket' + +interface Dispatcher { + onBuildOk(): void + onBuildError(message: string): void + onRefresh(): void } -// const TIMEOUT = 5000 - // TODO-APP: add actual type type PongEvent = any let mostRecentCompilationHash: any = null let __nextDevClientId = Math.round(Math.random() * 100 + Date.now()) let hadRuntimeError = false -let hadRootlayoutError = false // let startLatency = undefined -function onFastRefresh(dispatch: DispatchFn, hasUpdates: boolean) { - onBuildOk(dispatch) +function onFastRefresh(dispatcher: Dispatcher, hasUpdates: boolean) { + dispatcher.onBuildOk() if (hasUpdates) { - onRefresh(dispatch) + dispatcher.onRefresh() } - - // if (startLatency) { - // const endLatency = Date.now() - // const latency = endLatency - startLatency - // console.log(`[Fast Refresh] done in ${latency}ms`) - // sendMessage( - // JSON.stringify({ - // event: 'client-hmr-latency', - // id: __nextDevClientId, - // startTime: startLatency, - // endTime: endLatency, - // }) - // ) - // // if (self.__NEXT_HMR_LATENCY_CB) { - // // self.__NEXT_HMR_LATENCY_CB(latency) - // // } - // } } // There is a newer version of the code available. @@ -93,21 +69,21 @@ function canApplyUpdates() { // @ts-expect-error module.hot exists return module.hot.status() === 'idle' } -// function afterApplyUpdates(fn: any) { -// if (canApplyUpdates()) { -// fn() -// } else { -// function handler(status: any) { -// if (status === 'idle') { -// // @ts-expect-error module.hot exists -// module.hot.removeStatusHandler(handler) -// fn() -// } -// } -// // @ts-expect-error module.hot exists -// module.hot.addStatusHandler(handler) -// } -// } +function afterApplyUpdates(fn: any) { + if (canApplyUpdates()) { + fn() + } else { + function handler(status: any) { + if (status === 'idle') { + // @ts-expect-error module.hot exists + module.hot.removeStatusHandler(handler) + fn() + } + } + // @ts-expect-error module.hot exists + module.hot.addStatusHandler(handler) + } +} function performFullReload(err: any, sendMessage: any) { const stackTrace = @@ -130,23 +106,15 @@ function performFullReload(err: any, sendMessage: any) { function tryApplyUpdates( onHotUpdateSuccess: (hasUpdates: boolean) => void, sendMessage: any, - dispatch: DispatchFn + dispatcher: Dispatcher ) { - // @ts-expect-error module.hot exists - if (!module.hot) { - // HotModuleReplacementPlugin is not in Webpack configuration. - console.error('HotModuleReplacementPlugin is not in Webpack configuration.') - // window.location.reload(); - return - } - if (!isUpdateAvailable() || !canApplyUpdates()) { - onBuildOk(dispatch) + dispatcher.onBuildOk() return } function handleApplyUpdates(err: any, updatedModules: any) { - if (err || hadRuntimeError || hadRootlayoutError || !updatedModules) { + if (err || hadRuntimeError || !updatedModules) { if (err) { console.warn( '[Fast Refresh] performing full reload\n\n' + @@ -174,20 +142,20 @@ function tryApplyUpdates( if (isUpdateAvailable()) { // While we were updating, there was a new update! Do it again. tryApplyUpdates( - hasUpdates ? () => onBuildOk(dispatch) : onHotUpdateSuccess, + hasUpdates ? () => dispatcher.onBuildOk() : onHotUpdateSuccess, sendMessage, - dispatch + dispatcher ) } else { - onBuildOk(dispatch) - // if (process.env.__NEXT_TEST_MODE) { - // afterApplyUpdates(() => { - // if (self.__NEXT_HMR_CB) { - // self.__NEXT_HMR_CB() - // self.__NEXT_HMR_CB = null - // } - // }) - // } + dispatcher.onBuildOk() + if (process.env.__NEXT_TEST_MODE) { + afterApplyUpdates(() => { + if (self.__NEXT_HMR_CB) { + self.__NEXT_HMR_CB() + self.__NEXT_HMR_CB = null + } + }) + } } } @@ -207,13 +175,12 @@ function processMessage( e: any, sendMessage: any, router: ReturnType, - dispatch: DispatchFn + dispatcher: Dispatcher ) { const obj = JSON.parse(e.data) switch (obj.action) { case 'building': { - // startLatency = Date.now() console.log('[Fast Refresh] rebuilding') break } @@ -242,7 +209,7 @@ function processMessage( }) // Only show the first error. - onBuildError(dispatch, formatted.errors[0]) + dispatcher.onBuildError(formatted.errors[0]) // Also log them to the console. for (let i = 0; i < formatted.errors.length; i++) { @@ -251,12 +218,12 @@ function processMessage( // Do not attempt to reload now. // We will reload on next success instead. - // if (process.env.__NEXT_TEST_MODE) { - // if (self.__NEXT_HMR_CB) { - // self.__NEXT_HMR_CB(formatted.errors[0]) - // self.__NEXT_HMR_CB = null - // } - // } + if (process.env.__NEXT_TEST_MODE) { + if (self.__NEXT_HMR_CB) { + self.__NEXT_HMR_CB(formatted.errors[0]) + self.__NEXT_HMR_CB = null + } + } return } @@ -296,10 +263,10 @@ function processMessage( function onSuccessfulHotUpdate(hasUpdates: any) { // Only dismiss it when we're sure it's a hot update. // Otherwise it would flicker right before the reload. - onFastRefresh(dispatch, hasUpdates) + onFastRefresh(dispatcher, hasUpdates) }, sendMessage, - dispatch + dispatcher ) } return @@ -323,10 +290,10 @@ function processMessage( function onSuccessfulHotUpdate(hasUpdates: any) { // Only dismiss it when we're sure it's a hot update. // Otherwise it would flicker right before the reload. - onFastRefresh(dispatch, hasUpdates) + onFastRefresh(dispatcher, hasUpdates) }, sendMessage, - dispatch + dispatcher ) } return @@ -339,12 +306,12 @@ function processMessage( clientId: __nextDevClientId, }) ) - if (hadRuntimeError || hadRootlayoutError) { + if (hadRuntimeError) { return window.location.reload() } startTransition(() => { router.refresh() - onRefresh(dispatch) + dispatcher.onRefresh() }) return @@ -359,34 +326,13 @@ function processMessage( return window.location.reload() } case 'removedPage': { - // const [page] = obj.data - // if (page === window.next.router.pathname) { - // sendMessage( - // JSON.stringify({ - // event: 'client-removed-page', - // clientId: window.__nextDevClientId, - // page, - // }) - // ) - // return window.location.reload() - // } + // TODO-APP: potentially only refresh if the currently viewed page was removed. + router.refresh() return } case 'addedPage': { - // const [page] = obj.data - // if ( - // page === window.next.router.pathname && - // typeof window.next.router.components[page] === 'undefined' - // ) { - // sendMessage( - // JSON.stringify({ - // event: 'client-added-page', - // clientId: window.__nextDevClientId, - // page, - // }) - // ) - // return window.location.reload() - // } + // TODO-APP: potentially only refresh if the currently viewed page was added. + router.refresh() return } case 'pong': { @@ -394,25 +340,7 @@ function processMessage( if (invalid) { // Payload can be invalid even if the page does exist. // So, we check if it can be created. - fetch(location.href, { - credentials: 'same-origin', - }).then((pageRes) => { - if (pageRes.status === 200) { - // Page exists now, reload - location.reload() - } else { - // TODO-APP: fix this - // Page doesn't exist - // if ( - // self.__NEXT_DATA__.page === Router.pathname && - // Router.pathname !== '/_error' - // ) { - // // We are still on the page, - // // reload to show 404 error page - // location.reload() - // } - } - }) + router.refresh() } return } @@ -425,115 +353,96 @@ function processMessage( export default function HotReload({ assetPrefix, children, - initialState, - initialTree, }: { assetPrefix: string children?: ReactNode - initialState?: Partial - initialTree?: FlightRouterState }) { - if (initialState?.rootLayoutMissingTagsError) { - hadRootlayoutError = true - } - const stacktraceLimitRef = useRef() - const [state, dispatch] = React.useReducer(errorOverlayReducer, { + const [state, dispatch] = useReducer(errorOverlayReducer, { nextId: 1, buildError: null, errors: [], - ...initialState, }) - - const handleOnUnhandledError = useCallback((ev) => { - if ( - ev.error && - ev.error.digest && - (ev.error.digest.startsWith('NEXT_REDIRECT') || - ev.error.digest === 'NEXT_NOT_FOUND') - ) { - ev.preventDefault() - return + const dispatcher = useMemo((): Dispatcher => { + return { + onBuildOk(): void { + dispatch({ type: ACTION_BUILD_OK }) + }, + onBuildError(message: string): void { + dispatch({ type: ACTION_BUILD_ERROR, message }) + }, + onRefresh(): void { + dispatch({ type: ACTION_REFRESH }) + }, } + }, [dispatch]) - hadRuntimeError = true - onUnhandledError(dispatch, ev) - }, []) - const handleOnUnhandledRejection = useCallback((ev) => { - hadRuntimeError = true - onUnhandledRejection(dispatch, ev) - }, []) - - const { tree } = useContext(GlobalLayoutRouterContext) ?? { - tree: initialTree, - } - const router = useRouter() - - const webSocketRef = useRef() - const sendMessage = useCallback((data) => { - const socket = webSocketRef.current - if (!socket || socket.readyState !== socket.OPEN) return - return socket.send(data) - }, []) - - useEffect(() => { - try { - const limit = Error.stackTraceLimit - Error.stackTraceLimit = 50 - stacktraceLimitRef.current = limit - } catch {} - - window.addEventListener('error', handleOnUnhandledError) - window.addEventListener('unhandledrejection', handleOnUnhandledRejection) - return () => { - if (stacktraceLimitRef.current !== undefined) { - try { - Error.stackTraceLimit = stacktraceLimitRef.current - } catch {} - stacktraceLimitRef.current = undefined + const handleOnUnhandledError = useCallback( + (ev: WindowEventMap['error']): void => { + if ( + ev.error && + ev.error.digest && + (ev.error.digest.startsWith('NEXT_REDIRECT') || + ev.error.digest === 'NEXT_NOT_FOUND') + ) { + ev.preventDefault() + return } - window.removeEventListener('error', handleOnUnhandledError) - window.removeEventListener( - 'unhandledrejection', - handleOnUnhandledRejection - ) - } - }, [handleOnUnhandledError, handleOnUnhandledRejection]) + hadRuntimeError = true + const error = ev?.error + if ( + !error || + !(error instanceof Error) || + typeof error.stack !== 'string' + ) { + // A non-error was thrown, we don't have anything to show. :-( + return + } - useEffect(() => { - if (webSocketRef.current) { - return - } + if ( + error.message.match(/(hydration|content does not match|did not match)/i) + ) { + error.message += `\n\nSee more info here: https://nextjs.org/docs/messages/react-hydration-error` + } - const { hostname, port } = window.location - const protocol = getSocketProtocol(assetPrefix) - const normalizedAssetPrefix = assetPrefix.replace(/^\/+/, '') + const e = error + dispatch({ + type: ACTION_UNHANDLED_ERROR, + reason: error, + frames: parseStack(e.stack!), + }) + }, + [] + ) + const handleOnUnhandledRejection = useCallback( + (ev: WindowEventMap['unhandledrejection']): void => { + hadRuntimeError = true + const reason = ev?.reason + if ( + !reason || + !(reason instanceof Error) || + typeof reason.stack !== 'string' + ) { + // A non-error was thrown, we don't have anything to show. :-( + return + } - let url = `${protocol}://${hostname}:${port}${ - normalizedAssetPrefix ? `/${normalizedAssetPrefix}` : '' - }` + const e = reason + dispatch({ + type: ACTION_UNHANDLED_REJECTION, + reason: reason, + frames: parseStack(e.stack!), + }) + }, + [] + ) + useErrorHandler(handleOnUnhandledError, handleOnUnhandledRejection) - if (normalizedAssetPrefix.startsWith('http')) { - url = `${protocol}://${normalizedAssetPrefix.split('://')[1]}` - } + const webSocketRef = useWebsocket(assetPrefix) + useWebsocketPing(webSocketRef) + const sendMessage = useSendMessage(webSocketRef) - webSocketRef.current = new window.WebSocket(`${url}/_next/webpack-hmr`) - }, [assetPrefix]) - useEffect(() => { - // Taken from on-demand-entries-client.js - // TODO-APP: check 404 case - const interval = setInterval(() => { - sendMessage( - JSON.stringify({ - event: 'ping', - // TODO-APP: fix case for dynamic parameters, this will be resolved wrong currently. - tree, - appDirRoute: true, - }) - ) - }, 2500) - return () => clearInterval(interval) - }, [tree, sendMessage]) + const router = useRouter() useEffect(() => { const handler = (event: MessageEvent) => { if ( @@ -545,32 +454,19 @@ export default function HotReload({ } try { - processMessage(event, sendMessage, router, dispatch) + processMessage(event, sendMessage, router, dispatcher) } catch (ex) { console.warn('Invalid HMR message: ' + event.data + '\n', ex) } } - if (webSocketRef.current) { - webSocketRef.current.addEventListener('message', handler) + const websocket = webSocketRef.current + if (websocket) { + websocket.addEventListener('message', handler) } - return () => - webSocketRef.current && - webSocketRef.current.removeEventListener('message', handler) - }, [sendMessage, router]) - // useEffect(() => { - // const interval = setInterval(function () { - // if ( - // lastActivityRef.current && - // Date.now() - lastActivityRef.current > TIMEOUT - // ) { - // handleDisconnect() - // } - // }, 2500) - - // return () => clearInterval(interval) - // }) + return () => websocket && websocket.removeEventListener('message', handler) + }, [sendMessage, router, webSocketRef, dispatcher]) return {children} } diff --git a/packages/next/client/components/react-dev-overlay/internal/helpers/get-socket-protocol.ts b/packages/next/client/components/react-dev-overlay/internal/helpers/get-socket-protocol.ts new file mode 100644 index 0000000000000..a8a13cdc2bf76 --- /dev/null +++ b/packages/next/client/components/react-dev-overlay/internal/helpers/get-socket-protocol.ts @@ -0,0 +1,10 @@ +export function getSocketProtocol(assetPrefix: string): string { + let protocol = window.location.protocol + + try { + // assetPrefix is a url + protocol = new URL(assetPrefix).protocol + } catch (_) {} + + return protocol === 'http:' ? 'ws' : 'wss' +} diff --git a/packages/next/client/components/react-dev-overlay/internal/helpers/use-error-handler.ts b/packages/next/client/components/react-dev-overlay/internal/helpers/use-error-handler.ts new file mode 100644 index 0000000000000..d5867de015dca --- /dev/null +++ b/packages/next/client/components/react-dev-overlay/internal/helpers/use-error-handler.ts @@ -0,0 +1,35 @@ +import { useEffect, useRef } from 'react' + +export function useErrorHandler( + handleOnUnhandledError: (event: WindowEventMap['error']) => void, + handleOnUnhandledRejection: ( + event: WindowEventMap['unhandledrejection'] + ) => void +) { + const stacktraceLimitRef = useRef() + + useEffect(() => { + try { + const limit = Error.stackTraceLimit + Error.stackTraceLimit = 50 + stacktraceLimitRef.current = limit + } catch {} + + window.addEventListener('error', handleOnUnhandledError) + window.addEventListener('unhandledrejection', handleOnUnhandledRejection) + return () => { + if (stacktraceLimitRef.current !== undefined) { + try { + Error.stackTraceLimit = stacktraceLimitRef.current + } catch {} + stacktraceLimitRef.current = undefined + } + + window.removeEventListener('error', handleOnUnhandledError) + window.removeEventListener( + 'unhandledrejection', + handleOnUnhandledRejection + ) + } + }, [handleOnUnhandledError, handleOnUnhandledRejection]) +} diff --git a/packages/next/client/components/react-dev-overlay/internal/helpers/use-websocket.ts b/packages/next/client/components/react-dev-overlay/internal/helpers/use-websocket.ts new file mode 100644 index 0000000000000..91405df55e1b6 --- /dev/null +++ b/packages/next/client/components/react-dev-overlay/internal/helpers/use-websocket.ts @@ -0,0 +1,66 @@ +import { useCallback, useContext, useEffect, useRef } from 'react' +import { GlobalLayoutRouterContext } from '../../../../../shared/lib/app-router-context' +import { getSocketProtocol } from './get-socket-protocol' + +export function useWebsocket(assetPrefix: string) { + const webSocketRef = useRef() + + useEffect(() => { + if (webSocketRef.current) { + return + } + + const { hostname, port } = window.location + const protocol = getSocketProtocol(assetPrefix) + const normalizedAssetPrefix = assetPrefix.replace(/^\/+/, '') + + let url = `${protocol}://${hostname}:${port}${ + normalizedAssetPrefix ? `/${normalizedAssetPrefix}` : '' + }` + + if (normalizedAssetPrefix.startsWith('http')) { + url = `${protocol}://${normalizedAssetPrefix.split('://')[1]}` + } + + webSocketRef.current = new window.WebSocket(`${url}/_next/webpack-hmr`) + }, [assetPrefix]) + + return webSocketRef +} + +export function useSendMessage(webSocketRef: ReturnType) { + const sendMessage = useCallback( + (data) => { + const socket = webSocketRef.current + if (!socket || socket.readyState !== socket.OPEN) { + return + } + return socket.send(data) + }, + [webSocketRef] + ) + return sendMessage +} + +export function useWebsocketPing( + websocketRef: ReturnType +) { + const sendMessage = useSendMessage(websocketRef) + const { tree } = useContext(GlobalLayoutRouterContext) + + useEffect(() => { + // Taken from on-demand-entries-client.js + // TODO-APP: check 404 case + const interval = setInterval(() => { + sendMessage( + JSON.stringify({ + event: 'ping', + // TODO-APP: fix case for dynamic parameters, this will be resolved wrong currently. + tree, + appDirRoute: true, + }) + ) + }, 2500) + return () => clearInterval(interval) + }, [tree, sendMessage]) +} diff --git a/packages/next/client/image.tsx b/packages/next/client/image.tsx index da4910cadd5a5..bced56ead3475 100644 --- a/packages/next/client/image.tsx +++ b/packages/next/client/image.tsx @@ -299,7 +299,7 @@ function handleLoading( onLoadingCompleteRef.current(img) } if (process.env.NODE_ENV !== 'production') { - if (img.getAttribute('data-nimg') === 'future-fill') { + if (img.getAttribute('data-nimg') === 'fill') { if ( !img.getAttribute('sizes') || img.getAttribute('sizes') === '100vw' @@ -378,7 +378,7 @@ const ImageElement = ({ width={widthInt} height={heightInt} decoding="async" - data-nimg={`future${fill ? '-fill' : ''}`} + data-nimg={fill ? 'fill' : '1'} className={className} // @ts-ignore - TODO: upgrade to `@types/react@17` loading={loading} diff --git a/packages/next/client/script.tsx b/packages/next/client/script.tsx index ee3b4aec0db8b..52080d4027bc6 100644 --- a/packages/next/client/script.tsx +++ b/packages/next/client/script.tsx @@ -259,7 +259,7 @@ function Script(props: ScriptProps): JSX.Element | null { // For the app directory, we need React Float to preload these scripts. if (appDir) { // Before interactive scripts need to be loaded by Next.js' runtime instead - // of native