-
-
Notifications
You must be signed in to change notification settings - Fork 16
When parsing more than one file "start" and "end" accumulate values #39
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
Comments
Any update on this? I patched this on my end by running the parser in a worker. It works, but starting up the worker takes about 900 ms on my system. import { parse } from "swc";
self.postMessage("ready");
self.onmessage = (evt) => {
try {
const program = parse(evt.data, {
target: "es2019",
syntax: "typescript",
comments: true,
tsx: true,
});
const ast = JSON.stringify(program);
self.postMessage(ast);
} catch (e) {
self.postMessage({
error: {
message: e.message,
},
});
}
}; export function parse(source: string): Promise<string> {
return new Promise((resolve, reject) => {
const url = new URL("./parse.worker.js", import.meta.url);
const worker = new Worker(url.href, { type: "module" });
worker.addEventListener("message", (event) => {
if (event.data !== "ready") {
reject("Worker failed to initialize");
return;
}
worker.addEventListener("message", (event) => {
resolve(event.data);
}, { once: true });
worker.postMessage(source);
}, { once: true });
worker.addEventListener("error", (event) => {
reject(event.error);
});
worker.addEventListener("messageerror", (event) => {
reject(event.data);
});
});
} |
The problem comes from the main package. Here is the issue. Unfortunately, most of the solutions there do not currently work. You have to either instantiate the module for each file, or subtract |
What happen when span.start exceeding |
@rizrmd You have to parse 9,007,199,254,740,991 bytes (~9 Petabytes) of source code to get to that point. What are you planning to do? |
Haha, sorry, just curious… I never thought MAX_SAFE_INTEGER is 9 petabytes |
In that case for 'file1' "span.start" for Module will be "0"
But for 'file2' "span.start" will be "span.end" of another file.
Is it possible to have "0" as "span.start" for each file ?
The text was updated successfully, but these errors were encountered: