*Edit list should be tracked per transform

This commit is contained in:
Derrick Hammer 2022-12-14 14:34:29 -05:00
parent 883f811f91
commit d5ab556f45
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 19 additions and 19 deletions

View File

@ -28,25 +28,6 @@ type Edit = [number, number];
type AstNode = { start: number; end: number }; type AstNode = { start: number; end: number };
export default function bundleNativeModulesPlugin() { export default function bundleNativeModulesPlugin() {
const edits: Edit[] = [];
/*
Copied from https://github.com/sastan/rollup-plugin-define/blob/main/src/define.ts
*/
function markEdited(node: AstNode, edits: Edit[]): number | false {
for (const [start, end] of edits) {
if (
(start <= node.start && node.start < end) ||
(start < node.end && node.end <= end)
) {
return false; // Already edited
}
}
// Not edited
return edits.push([node.start, node.end]);
}
return { return {
name: "bundle-native-modules", name: "bundle-native-modules",
transform(src, id, ast: any) { transform(src, id, ast: any) {
@ -81,6 +62,25 @@ export default function bundleNativeModulesPlugin() {
} }
} }
const edits: Edit[] = [];
/*
Copied from https://github.com/sastan/rollup-plugin-define/blob/main/src/define.ts
*/
function markEdited(node: AstNode, edits: Edit[]): number | false {
for (const [start, end] of edits) {
if (
(start <= node.start && node.start < end) ||
(start < node.end && node.end <= end)
) {
return false; // Already edited
}
}
// Not edited
return edits.push([node.start, node.end]);
}
const findLoady = astMatcher("require('loady')(__str_aName, __any)"); const findLoady = astMatcher("require('loady')(__str_aName, __any)");
const loadyMatches = findLoady(ast); const loadyMatches = findLoady(ast);