Skip to content

Commit

Permalink
remove swc experimental options
Browse files Browse the repository at this point in the history
This removes support for keeping import assertions, which were broken in
swc at some point, and unconditionally transpiled into import
attributes. (Ie, `import/with` instead of `import/assert`.)

No version of node supports import attributes with this syntax yet, so
anyone using swc to import json in ESM is out of luck no matter what.

And swc 1.3.83 broke the option that ts-node was using. The position of
the swc project is that experimental features are not supported, and may
change in patch versions without warning, making them unsafe to rely on
(as evidenced here, and the reason why this behavior changed
unexpectedly in the first place).

Better to just not use experimental swc features, and let it remove
import assertions rather than transpile them into something that node
can't run.

Fix: TypeStrong#2056
  • Loading branch information
isaacs committed Sep 7, 2023
1 parent 47d4f45 commit 670d0ea
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 22 deletions.
19 changes: 0 additions & 19 deletions src/test/transpilers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,4 @@ test.suite('swc', (test) => {
);
});
});

test.suite('preserves import assertions for json imports', (test) => {
test.if(tsSupportsImportAssertions);
test(
'basic json import',
compileMacro,
{ module: 'esnext' },
outdent`
import document from './document.json' assert {type: 'json'};
document;
`,
outdent`
import document from './document.json' assert {
type: 'json'
};
document;
`
);
});
});
3 changes: 0 additions & 3 deletions src/transpilers/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ export function createSwcOptions(
},
},
keepClassNames,
experimental: {
keepImportAssertions: true,
},
},
};

Expand Down

0 comments on commit 670d0ea

Please sign in to comment.