alephjs / aleph.js

The Full-stack Framework in Deno.

Home Page:https://alephjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ahuigo opened this issue · comments

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/aleph_compiler@0.7.4/mod.ts";
import MagicString from "https://esm.sh/magic-string@0.26.2?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

commented

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

commented

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

commented

since i can't change the swc ast range output

It works!

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