Closed SukkaW closed 2 years ago
I am developing a Rollup plugin based on swc (using swc as a transformer).
swc
Rollup uses \0 as its virtual module identifier, e.g. rollup's commonjs module uses \0commonjsHelpers.js as the name of its virtual module, which would emit lines like this:
\0
virtual module
\0commonjsHelpers.js
import * as commonjsHelpers from "\0commonjsHelpers.js";
However, swc would throw Syntax Error on \0:
Syntax Error
Error: error: Unterminated string constant | 1 | import * as commonjsHelpers from " | ^ Caused by: 0: failed to process js file 1: Syntax Error
// Minimum reproduction // Check on repl.it: https://replit.com/@SukkaW/SweetSmallModulus const { transformSync: swcTransform } = require('@swc/core'); const { transformSync: esbuildTransform } = require('esbuild'); const code = ` import * as commonjsHelpers from "\0commonjsHelpers.js"; `; try { console.log(esbuildTransform(code, {})); } catch (e) { console.trace(e); } try { console.log(swcTransform(code), {}); } catch (e) { console.trace(e); } // This is the minimum repro, kaboom! try { console.log(swcTransform(`const a = "\0a"`), {}); } catch (e) { console.trace(e); }
{}
No response
Shouldn't throw Syntax Error on \0, either escape it (no matter the given target) silently or leave it as it is.
1.2.111
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Describe the bug
I am developing a Rollup plugin based on
swc
(using swc as a transformer).Rollup uses
\0
as itsvirtual module
identifier, e.g. rollup's commonjs module uses\0commonjsHelpers.js
as the name of its virtual module, which would emit lines like this:However, swc would throw
Syntax Error
on\0
:Input code
Config
Playground link
No response
Expected behavior
Shouldn't throw Syntax Error on
\0
, either escape it (no matter the given target) silently or leave it as it is.Version
1.2.111
Additional context
No response