From a44c325ac6d4d0ef4e71b246279d9f35fceb49d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 21 Dec 2021 14:37:26 +0100 Subject: [PATCH 1/5] feat(babel): provide caller information to Babel --- src/transformers/babel.ts | 8 ++++++++ test/transformers/babel.test.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/transformers/babel.ts b/src/transformers/babel.ts index dc9645ea..6ca94049 100644 --- a/src/transformers/babel.ts +++ b/src/transformers/babel.ts @@ -20,6 +20,14 @@ const transformer: Transformer = async ({ minified: false, ast: false, code: true, + caller: { + name: 'svelte-preprocess', + supportsStaticESM: true, + supportsDynamicImport: true, + supportsTopLevelAwait: true, + supportsExportNamespaceFrom: true, + ...options?.caller, + }, } as TransformOptions; const result = await transformAsync(content, babelOptions); diff --git a/test/transformers/babel.test.ts b/test/transformers/babel.test.ts index 2e16ffa7..6e2fba25 100644 --- a/test/transformers/babel.test.ts +++ b/test/transformers/babel.test.ts @@ -40,4 +40,37 @@ $: bar = foo?.b ?? 120 $: bar = (_foo$b = foo == null ? void 0 : foo.b) != null ? _foo$b : 120;" `); }); + + it('should not transpile modules with preset-env', async () => { + const template = ``; + + const opts = sveltePreprocess({ + babel: { + presets: [ + [ + '@babel/preset-env', + { + loose: true, + targets: { + esmodules: true, + }, + }, + ], + ], + }, + }); + + const preprocessed = await preprocess(template, opts); + + expect(preprocessed.code).toMatchInlineSnapshot(` + "" + `); + }); }); From d1a06d04982a78b5fb111b5a5c50a516f34f64d9 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Wed, 22 Dec 2021 08:46:22 +0100 Subject: [PATCH 2/5] Update test/transformers/babel.test.ts --- test/transformers/babel.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/transformers/babel.test.ts b/test/transformers/babel.test.ts index 6e2fba25..081ae4f2 100644 --- a/test/transformers/babel.test.ts +++ b/test/transformers/babel.test.ts @@ -41,7 +41,7 @@ $: bar = foo?.b ?? 120 `); }); - it('should not transpile modules with preset-env', async () => { + it('should not transpile import/export syntax with preset-env', async () => { const template = `