Skip to content
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

Bug: aleph parseDeps is not compatible with MagicString when processing unicode #506

Closed
ahuigo opened this issue Aug 25, 2022 · 4 comments
Closed
Labels
✘ bug Something isn't working

Comments

@ahuigo
Copy link

ahuigo commented Aug 25, 2022

Aleph's parseDeps uses bytes as units, while MagicString uses unicode characters as units.

This may cause some problem, e.g.

import {parseDeps} from "https://deno.land/x/[email protected]/mod.ts";
import MagicString from "https://esm.sh/[email protected]?target=esnext";

const source = `a="的";import p from "/pkg/p.js"; `;

const deps = await parseDeps("", source, { lang: "js", });

const s = new MagicString(source);
deps.forEach((dep) => {
  const { importUrl, loc } = dep;
  if (loc) {
    s.overwrite(
      loc.start - 1,
      loc.end - 1,
      `"/-/esm.sh/pkg/p.js"`,
    );
  }
});
const code = s.toString();
if(code.includes('from "/"/-/esm.sh')){
    console.error("bad code:",code)
}else{
    console.log(code)
}

Another bad case: #505

@ije
Copy link
Member

ije commented Aug 29, 2022

oh, thanks for the details!! i will look into it

@ije ije added the ✘ bug Something isn't working label Aug 29, 2022
@ije ije closed this as completed in d6066a2 Sep 8, 2022
@ije
Copy link
Member

ije commented Sep 8, 2022

i added a MagicString alternative class instead, please check d6066a2#diff-0edf38bf7f872ff648fee3cb962cd97497d4fb5cdb8bb200651ccd7312a835e9R468

@ije
Copy link
Member

ije commented Sep 8, 2022

since i can't change the swc ast range output

@ahuigo
Copy link
Author

ahuigo commented Sep 9, 2022

It works!

By the way, your folder .git is too big, how about cleaning it up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✘ bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants