Skip to content

Commit

Permalink
chore(rewrite-imports): update regex lastIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Feb 8, 2024
1 parent 0a6222a commit 5f98f55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { vtkObject } from '../../../interfaces';
import vtkCompositeMouseManipulator, {
ICompositeMouseManipulatorInitialValues,
} from '../../../Interaction/Manipulators/CompositeMouseManipulator';
import { vtkObject } from '../../../interfaces';

export interface IMouseRangeManipulatorInitialValues
extends ICompositeMouseManipulatorInitialValues {}
Expand Down
7 changes: 5 additions & 2 deletions Utilities/build/rewrite-imports.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
module.exports = (code, replaceFunc) => {
const importRegex = /(?:import|from) ['"]([^'"]*)['"]/g;
const importRegex = /(?:import|from)\s+['"]([^'"]*)['"]/g;
let m;
while ((m = importRegex.exec(code)) !== null) {
while ((m = importRegex.exec(code)) != null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === importRegex.lastIndex) {
importRegex.lastIndex++;
}

if (m[1].startsWith('../') || m[1].startsWith('./')) {
const importPath = replaceFunc(m[1]);
const origLen = code.length;
code = code.replace(m[0], `from '${importPath}'`);
const lenDiff = code.length - origLen;
importRegex.lastIndex += lenDiff;
}
}
return code;
Expand Down

0 comments on commit 5f98f55

Please sign in to comment.