From 30a729627406c358fd1b824bea3a33818bf2bc9a Mon Sep 17 00:00:00 2001 From: Brenley Dueck Date: Thu, 17 Sep 2026 20:21:30 -0500 Subject: [PATCH] fix: don't treat functions with a rest parameter as components The Pascal-case heuristic wrapped any capitalized top-level function with fewer than two declared parameters in the HMR component proxy. A rest parameter counts as a single parameter, so a plain helper such as `function GlobalTest(...arr)` in a `.jsx` file was proxied, and the proxy (`HMRComp(props)`) forwards only its first argument. Calling `GlobalTest(1, 2, 3)` in dev then received just `1`, while the same function in a `.js` file or a production build worked. A component receives at most one argument (its props), so a function declaring a rest parameter can't be one. Skip it in all three wrapping paths (function declarations, variable declarators, and hoisted export declarations) and add snapshot tests for every declaration shape across all bundler and mode suites. Fixes solidjs/solid-vite-plugin#214 Co-Authored-By: Claude Fable 5.1 --- src/babel/core/checks.ts | 12 ++ src/babel/index.ts | 8 +- .../__snapshots__/esm.test.ts.snap | 105 +++++++++++++++++ .../__snapshots__/rspack-esm.test.ts.snap | 105 +++++++++++++++++ .../__snapshots__/standard.test.ts.snap | 105 +++++++++++++++++ .../__snapshots__/vite.test.ts.snap | 110 ++++++++++++++++++ .../__snapshots__/webpack5.test.ts.snap | 105 +++++++++++++++++ tests/client-hydratable/esm.test.ts | 70 +++++++++++ tests/client-hydratable/rspack-esm.test.ts | 70 +++++++++++ tests/client-hydratable/standard.test.ts | 70 +++++++++++ tests/client-hydratable/vite.test.ts | 70 +++++++++++ tests/client-hydratable/webpack5.test.ts | 70 +++++++++++ tests/client/__snapshots__/esm.test.ts.snap | 100 ++++++++++++++++ .../__snapshots__/rspack-esm.test.ts.snap | 100 ++++++++++++++++ .../__snapshots__/standard.test.ts.snap | 100 ++++++++++++++++ tests/client/__snapshots__/vite.test.ts.snap | 105 +++++++++++++++++ .../__snapshots__/webpack5.test.ts.snap | 100 ++++++++++++++++ tests/client/esm.test.ts | 70 +++++++++++ tests/client/rspack-esm.test.ts | 70 +++++++++++ tests/client/standard.test.ts | 70 +++++++++++ tests/client/vite.test.ts | 70 +++++++++++ tests/client/webpack5.test.ts | 70 +++++++++++ .../__snapshots__/esm.test.ts.snap | 105 +++++++++++++++++ .../__snapshots__/rspack-esm.test.ts.snap | 105 +++++++++++++++++ .../__snapshots__/standard.test.ts.snap | 105 +++++++++++++++++ .../__snapshots__/vite.test.ts.snap | 110 ++++++++++++++++++ .../__snapshots__/webpack5.test.ts.snap | 105 +++++++++++++++++ tests/server-hydratable/esm.test.ts | 70 +++++++++++ tests/server-hydratable/rspack-esm.test.ts | 70 +++++++++++ tests/server-hydratable/standard.test.ts | 70 +++++++++++ tests/server-hydratable/vite.test.ts | 70 +++++++++++ tests/server-hydratable/webpack5.test.ts | 70 +++++++++++ tests/server/__snapshots__/esm.test.ts.snap | 100 ++++++++++++++++ .../__snapshots__/rspack-esm.test.ts.snap | 100 ++++++++++++++++ .../__snapshots__/standard.test.ts.snap | 100 ++++++++++++++++ tests/server/__snapshots__/vite.test.ts.snap | 105 +++++++++++++++++ .../__snapshots__/webpack5.test.ts.snap | 100 ++++++++++++++++ tests/server/esm.test.ts | 70 +++++++++++ tests/server/rspack-esm.test.ts | 70 +++++++++++ tests/server/standard.test.ts | 70 +++++++++++ tests/server/vite.test.ts | 70 +++++++++++ tests/server/webpack5.test.ts | 70 +++++++++++ 42 files changed, 3486 insertions(+), 4 deletions(-) diff --git a/src/babel/core/checks.ts b/src/babel/core/checks.ts index 1203865..d4ac482 100644 --- a/src/babel/core/checks.ts +++ b/src/babel/core/checks.ts @@ -13,3 +13,15 @@ export function getImportSpecifierName(specifier: t.ImportSpecifier): string { } return specifier.imported.value; } + +// A component receives at most one argument (its props), so a +// function with more than one parameter isn't a component. +// A rest parameter accepts any number of arguments, so a function +// declaring one isn't a component either: it's a plain function +// that happens to have a Pascal-cased name, and wrapping it in the +// HMR proxy would drop every argument after the first. +export function isComponentishParams( + params: (t.Identifier | t.Pattern | t.RestElement)[], +): boolean { + return params.length < 2 && !params.some(param => t.isRestElement(param)); +} diff --git a/src/babel/index.ts b/src/babel/index.ts index c627ee9..4905553 100644 --- a/src/babel/index.ts +++ b/src/babel/index.ts @@ -1,7 +1,7 @@ import type * as babel from '@babel/core'; import * as t from '@babel/types'; import path from 'path'; -import { isComponentishName } from './core/checks'; +import { isComponentishName, isComponentishParams } from './core/checks'; import { IMPORT_COMPONENT, IMPORT_CONTEXT, @@ -238,7 +238,7 @@ function transformVariableDeclarator( !(trueFuncExpr.async || trueFuncExpr.generator) && // Might be component-like, but the only valid components // have zero or one parameter - trueFuncExpr.params.length < 2 + isComponentishParams(trueFuncExpr.params) ) { path.node.init = wrapComponent(state, path, identifier, trueFuncExpr); } @@ -269,7 +269,7 @@ function transformFunctionDeclaration( !(decl.generator || decl.async) && // Might be component-like, but the only valid components // have zero or one parameter - decl.params.length < 2 + isComponentishParams(decl.params) ) { path.scope.registerDeclaration( path.replaceWith( @@ -307,7 +307,7 @@ function bubbleFunctionDeclaration( !(decl.generator || decl.async) && // Might be component-like, but the only valid components // have zero or one parameter - decl.params.length < 2 + isComponentishParams(decl.params) ) { if (path.parentPath.isExportNamedDeclaration()) { path.parentPath.replaceWith( diff --git a/tests/client-hydratable/__snapshots__/esm.test.ts.snap b/tests/client-hydratable/__snapshots__/esm.test.ts.snap index 6ca7987..90d13d6 100644 --- a/tests/client-hydratable/__snapshots__/esm.test.ts.snap +++ b/tests/client-hydratable/__snapshots__/esm.test.ts.snap @@ -97,6 +97,27 @@ if (import.meta.hot) { }" `; +exports[`esm (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -329,6 +350,27 @@ if (import.meta.hot) { }" `; +exports[`esm (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -558,6 +600,27 @@ if (import.meta.hot) { }" `; +exports[`esm (client, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -781,6 +844,27 @@ if (import.meta.hot) { }" `; +exports[`esm (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -1004,6 +1088,27 @@ if (import.meta.hot) { }" `; +exports[`esm (client, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client-hydratable/__snapshots__/rspack-esm.test.ts.snap b/tests/client-hydratable/__snapshots__/rspack-esm.test.ts.snap index b57cc4e..e0e04da 100644 --- a/tests/client-hydratable/__snapshots__/rspack-esm.test.ts.snap +++ b/tests/client-hydratable/__snapshots__/rspack-esm.test.ts.snap @@ -97,6 +97,27 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -329,6 +350,27 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -558,6 +600,27 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -781,6 +844,27 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -1004,6 +1088,27 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client-hydratable/__snapshots__/standard.test.ts.snap b/tests/client-hydratable/__snapshots__/standard.test.ts.snap index 1ee8753..017436e 100644 --- a/tests/client-hydratable/__snapshots__/standard.test.ts.snap +++ b/tests/client-hydratable/__snapshots__/standard.test.ts.snap @@ -97,6 +97,27 @@ if (module.hot) { }" `; +exports[`standard (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -329,6 +350,27 @@ if (module.hot) { }" `; +exports[`standard (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -558,6 +600,27 @@ if (module.hot) { }" `; +exports[`standard (client, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -781,6 +844,27 @@ if (module.hot) { }" `; +exports[`standard (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -1004,6 +1088,27 @@ if (module.hot) { }" `; +exports[`standard (client, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client-hydratable/__snapshots__/vite.test.ts.snap b/tests/client-hydratable/__snapshots__/vite.test.ts.snap index 8f57e26..3ab6a73 100644 --- a/tests/client-hydratable/__snapshots__/vite.test.ts.snap +++ b/tests/client-hydratable/__snapshots__/vite.test.ts.snap @@ -100,6 +100,28 @@ if (import.meta.hot) { }" `; +exports[`vite (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -338,6 +360,28 @@ if (import.meta.hot) { }" `; +exports[`vite (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -573,6 +617,28 @@ if (import.meta.hot) { }" `; +exports[`vite (client, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -802,6 +868,28 @@ if (import.meta.hot) { }" `; +exports[`vite (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -1031,6 +1119,28 @@ if (import.meta.hot) { }" `; +exports[`vite (client, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client-hydratable/__snapshots__/webpack5.test.ts.snap b/tests/client-hydratable/__snapshots__/webpack5.test.ts.snap index 17687d3..f883c61 100644 --- a/tests/client-hydratable/__snapshots__/webpack5.test.ts.snap +++ b/tests/client-hydratable/__snapshots__/webpack5.test.ts.snap @@ -97,6 +97,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -329,6 +350,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -558,6 +600,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -781,6 +844,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -1004,6 +1088,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +import { getNextElement as _$getNextElement } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$getNextElement(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client-hydratable/esm.test.ts b/tests/client-hydratable/esm.test.ts index b2b9240..3b1a5bf 100644 --- a/tests/client-hydratable/esm.test.ts +++ b/tests/client-hydratable/esm.test.ts @@ -90,6 +90,20 @@ describe('esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/client-hydratable/rspack-esm.test.ts b/tests/client-hydratable/rspack-esm.test.ts index a265e1c..3f4298e 100644 --- a/tests/client-hydratable/rspack-esm.test.ts +++ b/tests/client-hydratable/rspack-esm.test.ts @@ -90,6 +90,20 @@ describe('rspack-esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('rspack-esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('rspack-esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('rspack-esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('rspack-esm (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/client-hydratable/standard.test.ts b/tests/client-hydratable/standard.test.ts index b03423c..1c017d3 100644 --- a/tests/client-hydratable/standard.test.ts +++ b/tests/client-hydratable/standard.test.ts @@ -90,6 +90,20 @@ describe('standard (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('standard (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'standard', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('standard (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'standard', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('standard (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('standard (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/client-hydratable/vite.test.ts b/tests/client-hydratable/vite.test.ts index 5de1ca1..58d3265 100644 --- a/tests/client-hydratable/vite.test.ts +++ b/tests/client-hydratable/vite.test.ts @@ -90,6 +90,20 @@ describe('vite (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('vite (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'vite', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('vite (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'vite', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('vite (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('vite (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/client-hydratable/webpack5.test.ts b/tests/client-hydratable/webpack5.test.ts index 1286338..e08f4eb 100644 --- a/tests/client-hydratable/webpack5.test.ts +++ b/tests/client-hydratable/webpack5.test.ts @@ -90,6 +90,20 @@ describe('webpack5 (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('webpack5 (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'webpack5', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('webpack5 (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'webpack5', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('webpack5 (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('webpack5 (client, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'client', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/client/__snapshots__/esm.test.ts.snap b/tests/client/__snapshots__/esm.test.ts.snap index 826ba4b..ab425d3 100644 --- a/tests/client/__snapshots__/esm.test.ts.snap +++ b/tests/client/__snapshots__/esm.test.ts.snap @@ -93,6 +93,26 @@ if (import.meta.hot) { }" `; +exports[`esm (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -317,6 +337,26 @@ if (import.meta.hot) { }" `; +exports[`esm (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -538,6 +578,26 @@ if (import.meta.hot) { }" `; +exports[`esm (client, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -753,6 +813,26 @@ if (import.meta.hot) { }" `; +exports[`esm (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -968,6 +1048,26 @@ if (import.meta.hot) { }" `; +exports[`esm (client, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (client, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client/__snapshots__/rspack-esm.test.ts.snap b/tests/client/__snapshots__/rspack-esm.test.ts.snap index e44e7f2..cc59e93 100644 --- a/tests/client/__snapshots__/rspack-esm.test.ts.snap +++ b/tests/client/__snapshots__/rspack-esm.test.ts.snap @@ -93,6 +93,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -317,6 +337,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -538,6 +578,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -753,6 +813,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -968,6 +1048,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (client, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (client, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client/__snapshots__/standard.test.ts.snap b/tests/client/__snapshots__/standard.test.ts.snap index 480d636..d39b3a2 100644 --- a/tests/client/__snapshots__/standard.test.ts.snap +++ b/tests/client/__snapshots__/standard.test.ts.snap @@ -93,6 +93,26 @@ if (module.hot) { }" `; +exports[`standard (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -317,6 +337,26 @@ if (module.hot) { }" `; +exports[`standard (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -538,6 +578,26 @@ if (module.hot) { }" `; +exports[`standard (client, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -753,6 +813,26 @@ if (module.hot) { }" `; +exports[`standard (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -968,6 +1048,26 @@ if (module.hot) { }" `; +exports[`standard (client, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (client, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client/__snapshots__/vite.test.ts.snap b/tests/client/__snapshots__/vite.test.ts.snap index 74dab89..2200e8a 100644 --- a/tests/client/__snapshots__/vite.test.ts.snap +++ b/tests/client/__snapshots__/vite.test.ts.snap @@ -96,6 +96,27 @@ if (import.meta.hot) { }" `; +exports[`vite (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -326,6 +347,27 @@ if (import.meta.hot) { }" `; +exports[`vite (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -553,6 +595,27 @@ if (import.meta.hot) { }" `; +exports[`vite (client, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -774,6 +837,27 @@ if (import.meta.hot) { }" `; +exports[`vite (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -995,6 +1079,27 @@ if (import.meta.hot) { }" `; +exports[`vite (client, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (client, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client/__snapshots__/webpack5.test.ts.snap b/tests/client/__snapshots__/webpack5.test.ts.snap index 45420d3..4bbea44 100644 --- a/tests/client/__snapshots__/webpack5.test.ts.snap +++ b/tests/client/__snapshots__/webpack5.test.ts.snap @@ -93,6 +93,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -317,6 +337,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -538,6 +578,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -753,6 +813,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; @@ -968,6 +1048,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (client, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { template as _$template } from "solid-js/web"; +import { createComponent as _$createComponent } from "solid-js/web"; +var _tmpl$ = /*#__PURE__*/_$template(\`

Foo\`); +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_tmpl$(), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (client, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { template as _$template } from "solid-js/web"; import { createComponent as _$createComponent } from "solid-js/web"; diff --git a/tests/client/esm.test.ts b/tests/client/esm.test.ts index c6a38ef..e6325d4 100644 --- a/tests/client/esm.test.ts +++ b/tests/client/esm.test.ts @@ -90,6 +90,20 @@ describe('esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/client/rspack-esm.test.ts b/tests/client/rspack-esm.test.ts index ead438c..63cc224 100644 --- a/tests/client/rspack-esm.test.ts +++ b/tests/client/rspack-esm.test.ts @@ -90,6 +90,20 @@ describe('rspack-esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('rspack-esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('rspack-esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('rspack-esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('rspack-esm (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/client/standard.test.ts b/tests/client/standard.test.ts index f076189..07c72a8 100644 --- a/tests/client/standard.test.ts +++ b/tests/client/standard.test.ts @@ -90,6 +90,20 @@ describe('standard (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('standard (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'standard', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('standard (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'standard', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('standard (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('standard (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/client/vite.test.ts b/tests/client/vite.test.ts index e581070..e78af3b 100644 --- a/tests/client/vite.test.ts +++ b/tests/client/vite.test.ts @@ -90,6 +90,20 @@ describe('vite (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('vite (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'vite', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('vite (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'vite', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('vite (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('vite (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/client/webpack5.test.ts b/tests/client/webpack5.test.ts index 29cde94..fe6dedf 100644 --- a/tests/client/webpack5.test.ts +++ b/tests/client/webpack5.test.ts @@ -90,6 +90,20 @@ describe('webpack5 (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('webpack5 (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'webpack5', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('webpack5 (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'webpack5', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('webpack5 (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('webpack5 (client, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'client', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server-hydratable/__snapshots__/esm.test.ts.snap b/tests/server-hydratable/__snapshots__/esm.test.ts.snap index 82ec9ae..14e884d 100644 --- a/tests/server-hydratable/__snapshots__/esm.test.ts.snap +++ b/tests/server-hydratable/__snapshots__/esm.test.ts.snap @@ -97,6 +97,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -325,6 +346,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -550,6 +592,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -769,6 +832,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -988,6 +1072,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server-hydratable/__snapshots__/rspack-esm.test.ts.snap b/tests/server-hydratable/__snapshots__/rspack-esm.test.ts.snap index c340374..ef3aeba 100644 --- a/tests/server-hydratable/__snapshots__/rspack-esm.test.ts.snap +++ b/tests/server-hydratable/__snapshots__/rspack-esm.test.ts.snap @@ -97,6 +97,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -325,6 +346,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -550,6 +592,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -769,6 +832,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -988,6 +1072,27 @@ if (import.meta.hot) { }" `; +exports[`esm (server, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server-hydratable/__snapshots__/standard.test.ts.snap b/tests/server-hydratable/__snapshots__/standard.test.ts.snap index d537390..d82b52a 100644 --- a/tests/server-hydratable/__snapshots__/standard.test.ts.snap +++ b/tests/server-hydratable/__snapshots__/standard.test.ts.snap @@ -97,6 +97,27 @@ if (module.hot) { }" `; +exports[`standard (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -325,6 +346,27 @@ if (module.hot) { }" `; +exports[`standard (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -550,6 +592,27 @@ if (module.hot) { }" `; +exports[`standard (server, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -769,6 +832,27 @@ if (module.hot) { }" `; +exports[`standard (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -988,6 +1072,27 @@ if (module.hot) { }" `; +exports[`standard (server, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server-hydratable/__snapshots__/vite.test.ts.snap b/tests/server-hydratable/__snapshots__/vite.test.ts.snap index 1620475..570d575 100644 --- a/tests/server-hydratable/__snapshots__/vite.test.ts.snap +++ b/tests/server-hydratable/__snapshots__/vite.test.ts.snap @@ -100,6 +100,28 @@ if (import.meta.hot) { }" `; +exports[`vite (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -334,6 +356,28 @@ if (import.meta.hot) { }" `; +exports[`vite (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -565,6 +609,28 @@ if (import.meta.hot) { }" `; +exports[`vite (server, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -790,6 +856,28 @@ if (import.meta.hot) { }" `; +exports[`vite (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -1015,6 +1103,28 @@ if (import.meta.hot) { }" `; +exports[`vite (server, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server-hydratable/__snapshots__/webpack5.test.ts.snap b/tests/server-hydratable/__snapshots__/webpack5.test.ts.snap index a826640..6038008 100644 --- a/tests/server-hydratable/__snapshots__/webpack5.test.ts.snap +++ b/tests/server-hydratable/__snapshots__/webpack5.test.ts.snap @@ -97,6 +97,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -325,6 +346,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -550,6 +592,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -769,6 +832,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -988,6 +1072,27 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web"; +var _tmpl$ = ["Foo"]; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$, _$ssrHydrationKey()), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server-hydratable/esm.test.ts b/tests/server-hydratable/esm.test.ts index 1f55074..eadd565 100644 --- a/tests/server-hydratable/esm.test.ts +++ b/tests/server-hydratable/esm.test.ts @@ -90,6 +90,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server-hydratable/rspack-esm.test.ts b/tests/server-hydratable/rspack-esm.test.ts index 15615c3..79d1929 100644 --- a/tests/server-hydratable/rspack-esm.test.ts +++ b/tests/server-hydratable/rspack-esm.test.ts @@ -90,6 +90,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('esm (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server-hydratable/standard.test.ts b/tests/server-hydratable/standard.test.ts index 77cd43a..75f6513 100644 --- a/tests/server-hydratable/standard.test.ts +++ b/tests/server-hydratable/standard.test.ts @@ -90,6 +90,20 @@ describe('standard (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('standard (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'standard', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('standard (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'standard', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('standard (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('standard (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server-hydratable/vite.test.ts b/tests/server-hydratable/vite.test.ts index 69a9f6b..a29a052 100644 --- a/tests/server-hydratable/vite.test.ts +++ b/tests/server-hydratable/vite.test.ts @@ -90,6 +90,20 @@ describe('vite (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('vite (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'vite', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('vite (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'vite', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('vite (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('vite (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server-hydratable/webpack5.test.ts b/tests/server-hydratable/webpack5.test.ts index 1774f21..0742a2c 100644 --- a/tests/server-hydratable/webpack5.test.ts +++ b/tests/server-hydratable/webpack5.test.ts @@ -90,6 +90,20 @@ describe('webpack5 (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('webpack5 (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'webpack5', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('webpack5 (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'webpack5', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('webpack5 (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('webpack5 (server, hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'server', + true, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server/__snapshots__/esm.test.ts.snap b/tests/server/__snapshots__/esm.test.ts.snap index 0b0eb5f..6fde848 100644 --- a/tests/server/__snapshots__/esm.test.ts.snap +++ b/tests/server/__snapshots__/esm.test.ts.snap @@ -93,6 +93,26 @@ if (import.meta.hot) { }" `; +exports[`esm (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -313,6 +333,26 @@ if (import.meta.hot) { }" `; +exports[`esm (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -530,6 +570,26 @@ if (import.meta.hot) { }" `; +exports[`esm (server, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -741,6 +801,26 @@ if (import.meta.hot) { }" `; +exports[`esm (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -952,6 +1032,26 @@ if (import.meta.hot) { }" `; +exports[`esm (server, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + _$$refresh("esm", import.meta.hot, _REGISTRY); +}" +`; + exports[`esm (server, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server/__snapshots__/rspack-esm.test.ts.snap b/tests/server/__snapshots__/rspack-esm.test.ts.snap index 065c478..bd098df 100644 --- a/tests/server/__snapshots__/rspack-esm.test.ts.snap +++ b/tests/server/__snapshots__/rspack-esm.test.ts.snap @@ -93,6 +93,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -313,6 +333,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -530,6 +570,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (server, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (server, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -741,6 +801,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -952,6 +1032,26 @@ if (import.meta.webpackHot) { }" `; +exports[`rspack-esm (server, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("rspack-esm", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`rspack-esm (server, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server/__snapshots__/standard.test.ts.snap b/tests/server/__snapshots__/standard.test.ts.snap index bc312d8..05601c3 100644 --- a/tests/server/__snapshots__/standard.test.ts.snap +++ b/tests/server/__snapshots__/standard.test.ts.snap @@ -93,6 +93,26 @@ if (module.hot) { }" `; +exports[`standard (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -313,6 +333,26 @@ if (module.hot) { }" `; +exports[`standard (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -530,6 +570,26 @@ if (module.hot) { }" `; +exports[`standard (server, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -741,6 +801,26 @@ if (module.hot) { }" `; +exports[`standard (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -952,6 +1032,26 @@ if (module.hot) { }" `; +exports[`standard (server, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (module.hot) { + _$$refresh("standard", module.hot, _REGISTRY); +}" +`; + exports[`standard (server, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server/__snapshots__/vite.test.ts.snap b/tests/server/__snapshots__/vite.test.ts.snap index 0f992b1..2ffc9e4 100644 --- a/tests/server/__snapshots__/vite.test.ts.snap +++ b/tests/server/__snapshots__/vite.test.ts.snap @@ -96,6 +96,27 @@ if (import.meta.hot) { }" `; +exports[`vite (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -322,6 +343,27 @@ if (import.meta.hot) { }" `; +exports[`vite (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -545,6 +587,27 @@ if (import.meta.hot) { }" `; +exports[`vite (server, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -762,6 +825,27 @@ if (import.meta.hot) { }" `; +exports[`vite (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -979,6 +1063,27 @@ if (import.meta.hot) { }" `; +exports[`vite (server, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.hot) { + import.meta.hot.accept(); + _$$refresh("vite", import.meta.hot, _REGISTRY); +}" +`; + exports[`vite (server, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server/__snapshots__/webpack5.test.ts.snap b/tests/server/__snapshots__/webpack5.test.ts.snap index 1e4d9ab..a75c698 100644 --- a/tests/server/__snapshots__/webpack5.test.ts.snap +++ b/tests/server/__snapshots__/webpack5.test.ts.snap @@ -93,6 +93,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export default function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, non-hydratable) > ExportDefaultDeclaration w/ FunctionExpression > should transform ExportDefaultDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -313,6 +333,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +export function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, non-hydratable) > ExportNamedDeclaration w/ FunctionExpression > should transform ExportNamedDeclaration w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -530,6 +570,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, non-hydratable) > FunctionDeclaration > should skip FunctionDeclaration with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:15", + signature: "4b145a58" +}); +function Foo(...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +} +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, non-hydratable) > FunctionDeclaration > should transform FunctionDeclaration with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -741,6 +801,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = (...args) => { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, non-hydratable) > VariableDeclarator > ArrowFunctionExpression > should transform VariableDeclarator w/ ArrowFunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; @@ -952,6 +1032,26 @@ if (import.meta.webpackHot) { }" `; +exports[`webpack5 (server, non-hydratable) > VariableDeclarator > FunctionExpression > should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter 1`] = ` +"import { createComponent as _$createComponent } from "solid-js/web"; +import { ssr as _$ssr } from "solid-js/web"; +var _tmpl$ = "

Foo

"; +import { $$component as _$$component } from "solid-refresh"; +import { $$refresh as _$$refresh } from "solid-refresh"; +import { $$registry as _$$registry } from "solid-refresh"; +const _REGISTRY = _$$registry(); +const Foo_1 = _$$component(_REGISTRY, "Foo_1", _props => /*@refresh jsx-skip*/_$ssr(_tmpl$), { + location: "example.jsx:3:17", + signature: "4b145a58" +}); +const Foo = function (...args) { + return /*@refresh jsx-skip*/_$createComponent(Foo_1, {}); +}; +if (import.meta.webpackHot) { + _$$refresh("webpack5", import.meta.webpackHot, _REGISTRY); +}" +`; + exports[`webpack5 (server, non-hydratable) > VariableDeclarator > FunctionExpression > should transform VariableDeclarator w/ FunctionExpression with valid Component name and params 1`] = ` "import { createComponent as _$createComponent } from "solid-js/web"; import { ssr as _$ssr } from "solid-js/web"; diff --git a/tests/server/esm.test.ts b/tests/server/esm.test.ts index c472adc..4bd8307 100644 --- a/tests/server/esm.test.ts +++ b/tests/server/esm.test.ts @@ -90,6 +90,20 @@ describe('esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server/rspack-esm.test.ts b/tests/server/rspack-esm.test.ts index e0b412a..a5ab36a 100644 --- a/tests/server/rspack-esm.test.ts +++ b/tests/server/rspack-esm.test.ts @@ -90,6 +90,20 @@ describe('rspack-esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('rspack-esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('rspack-esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'rspack-esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('rspack-esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('rspack-esm (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'rspack-esm', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server/standard.test.ts b/tests/server/standard.test.ts index b34a844..095a037 100644 --- a/tests/server/standard.test.ts +++ b/tests/server/standard.test.ts @@ -90,6 +90,20 @@ describe('standard (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('standard (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'standard', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('standard (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'standard', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('standard (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('standard (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'standard', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server/vite.test.ts b/tests/server/vite.test.ts index ab0ef1b..8cb4315 100644 --- a/tests/server/vite.test.ts +++ b/tests/server/vite.test.ts @@ -90,6 +90,20 @@ describe('vite (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('vite (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'vite', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('vite (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'vite', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('vite (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('vite (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'vite', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( diff --git a/tests/server/webpack5.test.ts b/tests/server/webpack5.test.ts index 97e0fe1..fa13d6d 100644 --- a/tests/server/webpack5.test.ts +++ b/tests/server/webpack5.test.ts @@ -90,6 +90,20 @@ describe('webpack5 (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip FunctionDeclaration with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip FunctionDeclaration with invalid Component name', async () => { expect( await transform( @@ -224,6 +238,20 @@ describe('webpack5 (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = function (...args) { + return

Foo

; + } + `, + 'webpack5', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -356,6 +384,20 @@ describe('webpack5 (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip VariableDeclarator w/ ArrowFunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + const Foo = (...args) => { + return

Foo

; + } + `, + 'webpack5', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip VariableDeclarator w/ ArrowFunctionExpression with invalid Component name', async () => { expect( await transform( @@ -490,6 +532,20 @@ describe('webpack5 (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportNamedDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportNamedDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform( @@ -622,6 +678,20 @@ describe('webpack5 (server, non-hydratable)', () => { ), ).toMatchSnapshot(); }); + it('should skip ExportDefaultDeclaration w/ FunctionExpression with valid Component name and a rest parameter', async () => { + expect( + await transform( + ` + export default function Foo(...args) { + return

Foo

; + } + `, + 'webpack5', + 'server', + false, + ), + ).toMatchSnapshot(); + }); it('should skip ExportDefaultDeclaration w/ FunctionExpression with invalid Component name', async () => { expect( await transform(