Skip to content

swc can't handle unescaped \0 #2853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SukkaW opened this issue Nov 23, 2021 · 1 comment · Fixed by #4255
Closed

swc can't handle unescaped \0 #2853

SukkaW opened this issue Nov 23, 2021 · 1 comment · Fixed by #4255
Labels
Milestone

Comments

@SukkaW
Copy link
Contributor

SukkaW commented Nov 23, 2021

Describe the bug

I am developing a Rollup plugin based on swc (using swc as a transformer).

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:

import * as commonjsHelpers from "\0commonjsHelpers.js";

However, swc would throw Syntax Error on \0:

     Error: error: Unterminated string constant

  |
1 | import * as commonjsHelpers from "
  |                                  ^



Caused by:
    0: failed to process js file
    1: Syntax Error

Input code

// 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);
}

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

@kdy1 kdy1 modified the milestones: v1.2.148, v1.2.149, v1.2.150 Mar 4, 2022
@kdy1 kdy1 added this to the Planned milestone Mar 12, 2022
@kdy1 kdy1 closed this as completed in #4255 Apr 5, 2022
@kdy1 kdy1 modified the milestones: Planned, v1.2.164 Apr 5, 2022
SukkaW added a commit to SukkaW/rollup-plugin-swc that referenced this issue Apr 16, 2022
swc already fixes it, and the test case was added in swc-project/swc#4255

x-ref:
- swc-project/swc#2853
- swc-project/swc#2853
- #2
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 16, 2022

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants