From d17be5750c8e536547ddefe9a0d24be4fd419898 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Wed, 21 Jan 2026 13:12:02 +0100 Subject: [PATCH 1/2] fix: keep import attribute --- src/get_config.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/get_config.ts b/src/get_config.ts index 08899a1..778fef0 100644 --- a/src/get_config.ts +++ b/src/get_config.ts @@ -36,6 +36,9 @@ const DEFAULT_CONFIG: SWCConfig = { runtime: 'automatic', }, }, + experimental: { + keepImportAttributes: true, + }, keepClassNames: true, }, } @@ -96,6 +99,9 @@ function tsConfigToSwcConfig(tsConfig: TsConfigJsonResolved): SWCConfig { : {}), }, }, + experimental: { + keepImportAttributes: true, + }, keepClassNames: true, }, } From 78fe3fc463f7a1ad7c2b7c5b4909179e7d01f524 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Wed, 21 Jan 2026 14:38:59 +0100 Subject: [PATCH 2/2] test: update tests + add new for import attributes --- tests/get_config.spec.ts | 12 +++++++++ tests/loader.spec.ts | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/tests/get_config.spec.ts b/tests/get_config.spec.ts index 229979e..7a17ab0 100644 --- a/tests/get_config.spec.ts +++ b/tests/get_config.spec.ts @@ -16,6 +16,9 @@ test.group('Get config', () => { { "swcConfig": { "jsc": { + "experimental": { + "keepImportAttributes": true, + }, "externalHelpers": false, "keepClassNames": true, "parser": { @@ -59,6 +62,9 @@ test.group('Get config', () => { "swcConfig": { "jsc": { "baseUrl": undefined, + "experimental": { + "keepImportAttributes": true, + }, "externalHelpers": false, "keepClassNames": true, "parser": { @@ -107,6 +113,9 @@ test.group('Get config', () => { "swcConfig": { "jsc": { "baseUrl": undefined, + "experimental": { + "keepImportAttributes": true, + }, "externalHelpers": false, "keepClassNames": true, "parser": { @@ -158,6 +167,9 @@ test.group('Get config', () => { "swcConfig": { "jsc": { "baseUrl": undefined, + "experimental": { + "keepImportAttributes": true, + }, "externalHelpers": false, "keepClassNames": true, "parser": { diff --git a/tests/loader.spec.ts b/tests/loader.spec.ts index 2816ce5..7f5e5f1 100644 --- a/tests/loader.spec.ts +++ b/tests/loader.spec.ts @@ -651,4 +651,60 @@ test.group('Loader', (group) => { 'Error: Cannot import "./get_path.ts?v=1" using ".ts" extension. Enable "compilerOptions.rewriteRelativeImportExtensions" to import TypeScript files' ) }) + + test('preserve import attributes for JSON imports', async ({ assert, fs }) => { + await fs.createJson('tsconfig.json', { + compilerOptions: {}, + }) + + await fs.createJson('data.json', { + name: 'ts-exec', + version: '1.0.0', + }) + + await fs.create( + 'index.ts', + ` + import data from './data.json' with { type: 'json' } + console.log(data.name) + ` + ) + + const result = await spawnPromisified( + process.execPath, + ['--no-warnings', '--import', './build/index.js', join(fs.basePath, 'index.ts')], + {} + ) + + assert.equal(result.stdout.trim(), 'ts-exec') + assert.equal(result.stderr.trim(), '') + }) + + test('preserve import attributes for dynamic JSON imports', async ({ assert, fs }) => { + await fs.createJson('tsconfig.json', { + compilerOptions: {}, + }) + + await fs.createJson('config.json', { + enabled: true, + timeout: 5000, + }) + + await fs.create( + 'index.ts', + ` + const config = await import('./config.json', { with: { type: 'json' } }) + console.log(config.default.timeout) + ` + ) + + const result = await spawnPromisified( + process.execPath, + ['--no-warnings', '--import', './build/index.js', join(fs.basePath, 'index.ts')], + {} + ) + + assert.equal(result.stdout.trim(), '5000') + assert.equal(result.stderr.trim(), '') + }) })