From 70197fe4ca4be3d44b5dc8ceb3beb25afa5b0fc7 Mon Sep 17 00:00:00 2001 From: Paolo Ricciuti Date: Fri, 2 Aug 2024 14:07:01 +0200 Subject: [PATCH] fix: maintain imports in modules (#12704) * fix: maintain imports in modules * chore: add snapshot test --- .../3-transform/client/visitors/ImportDeclaration.js | 3 ++- .../samples/imports-in-modules/_expected/client/export.js | 1 + .../imports-in-modules/_expected/client/index.svelte.js | 7 +++++++ .../imports-in-modules/_expected/client/module.svelte.js | 5 +++++ .../samples/imports-in-modules/_expected/server/export.js | 1 + .../imports-in-modules/_expected/server/index.svelte.js | 6 ++++++ .../imports-in-modules/_expected/server/module.svelte.js | 5 +++++ .../tests/snapshot/samples/imports-in-modules/export.js | 1 + .../tests/snapshot/samples/imports-in-modules/index.svelte | 3 +++ .../snapshot/samples/imports-in-modules/module.svelte.js | 3 +++ 10 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/export.js create mode 100644 packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/index.svelte.js create mode 100644 packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/module.svelte.js create mode 100644 packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/export.js create mode 100644 packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/index.svelte.js create mode 100644 packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/module.svelte.js create mode 100644 packages/svelte/tests/snapshot/samples/imports-in-modules/export.js create mode 100644 packages/svelte/tests/snapshot/samples/imports-in-modules/index.svelte create mode 100644 packages/svelte/tests/snapshot/samples/imports-in-modules/module.svelte.js diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/ImportDeclaration.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/ImportDeclaration.js index a222353687..29700246d4 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/ImportDeclaration.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/ImportDeclaration.js @@ -9,7 +9,8 @@ import * as b from '../../../../utils/builders.js'; export function ImportDeclaration(node, context) { if ('hoisted' in context.state) { context.state.hoisted.push(node); + return b.empty; } - return b.empty; + context.next(); } diff --git a/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/export.js b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/export.js new file mode 100644 index 0000000000..b4bb7075da --- /dev/null +++ b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/export.js @@ -0,0 +1 @@ +export * from '../../export.js'; \ No newline at end of file diff --git a/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/index.svelte.js b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/index.svelte.js new file mode 100644 index 0000000000..464ef519af --- /dev/null +++ b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/index.svelte.js @@ -0,0 +1,7 @@ +import "svelte/internal/disclose-version"; +import * as $ from "svelte/internal/client"; +import { random } from './module.svelte'; + +export default function Imports_in_modules($$anchor) { + +} \ No newline at end of file diff --git a/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/module.svelte.js b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/module.svelte.js new file mode 100644 index 0000000000..6edbc8af77 --- /dev/null +++ b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/client/module.svelte.js @@ -0,0 +1,5 @@ +/* module.svelte.js generated by Svelte VERSION */ +import * as $ from "svelte/internal/client"; +import { random } from './export'; + +export { random }; \ No newline at end of file diff --git a/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/export.js b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/export.js new file mode 100644 index 0000000000..b4bb7075da --- /dev/null +++ b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/export.js @@ -0,0 +1 @@ +export * from '../../export.js'; \ No newline at end of file diff --git a/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/index.svelte.js b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/index.svelte.js new file mode 100644 index 0000000000..35b64b4186 --- /dev/null +++ b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/index.svelte.js @@ -0,0 +1,6 @@ +import * as $ from "svelte/internal/server"; +import { random } from './module.svelte'; + +export default function Imports_in_modules($$payload) { + +} \ No newline at end of file diff --git a/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/module.svelte.js b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/module.svelte.js new file mode 100644 index 0000000000..e51aae5a25 --- /dev/null +++ b/packages/svelte/tests/snapshot/samples/imports-in-modules/_expected/server/module.svelte.js @@ -0,0 +1,5 @@ +/* module.svelte.js generated by Svelte VERSION */ +import * as $ from "svelte/internal/server"; +import { random } from './export'; + +export { random }; \ No newline at end of file diff --git a/packages/svelte/tests/snapshot/samples/imports-in-modules/export.js b/packages/svelte/tests/snapshot/samples/imports-in-modules/export.js new file mode 100644 index 0000000000..07ed4a67bd --- /dev/null +++ b/packages/svelte/tests/snapshot/samples/imports-in-modules/export.js @@ -0,0 +1 @@ +export const random = 42; diff --git a/packages/svelte/tests/snapshot/samples/imports-in-modules/index.svelte b/packages/svelte/tests/snapshot/samples/imports-in-modules/index.svelte new file mode 100644 index 0000000000..518377177f --- /dev/null +++ b/packages/svelte/tests/snapshot/samples/imports-in-modules/index.svelte @@ -0,0 +1,3 @@ + diff --git a/packages/svelte/tests/snapshot/samples/imports-in-modules/module.svelte.js b/packages/svelte/tests/snapshot/samples/imports-in-modules/module.svelte.js new file mode 100644 index 0000000000..b39abe1b0e --- /dev/null +++ b/packages/svelte/tests/snapshot/samples/imports-in-modules/module.svelte.js @@ -0,0 +1,3 @@ +import { random } from './export'; + +export { random };