Skip to content

Commit

Permalink
fix: improved regex of isolated declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed Sep 20, 2024
1 parent 1dccbac commit d01352a
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const isolatedDeclarationsPlugin = (
this.emitFile({
fileName: entryFileNames.replace("[name]", relative(outBase, filename)).replace(".cts", ".ts"),
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands,regexp/no-misleading-capturing-group,regexp/no-super-linear-backtracking
source: source.replaceAll(/(from\s)['|"](.*)\..+['|"];?/g, (_, group1, group2) => group1 + quote + group2 + ".d.ts" + quote + ";"),
source: source.replaceAll(/(from\s)['|"]((.*)\..+|['|"].*)['|"];?/g, (_, group1, group2, group3) => group1 + quote + (group3 || group2) + ".d.ts" + quote + ";"),
type: "asset",
});
}
Expand All @@ -198,9 +198,9 @@ export const isolatedDeclarationsPlugin = (
fileName: entryFileNames.replace("[name]", relative(outBase, filename)),
source: source.replaceAll(
// eslint-disable-next-line regexp/no-misleading-capturing-group,regexp/no-super-linear-backtracking
/(from\s)['|"](.*)\..+['|"];?/g,
/(from\s)['|"]((.*)\..+|['|"].*)['|"];?/g,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
(_, group1, group2) => group1 + quote + group2 + (outputOptions.format === "cjs" ? ".d.cts" : ".d.mts") + quote + ";",
(_, group1, group2, group3) => group1 + quote + (group3 || group2) + (outputOptions.format === "cjs" ? ".d.cts" : ".d.mts") + quote + ";",
),
type: "asset",
});
Expand Down

0 comments on commit d01352a

Please sign in to comment.