From 5f98f5581e94cc20e784f6ea215dcaa439d2b559 Mon Sep 17 00:00:00 2001 From: Forrest Date: Tue, 6 Feb 2024 17:39:58 -0500 Subject: [PATCH] chore(rewrite-imports): update regex lastIndex --- .../Manipulators/MouseRangeManipulator/index.d.ts | 2 +- Utilities/build/rewrite-imports.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Interaction/Manipulators/MouseRangeManipulator/index.d.ts b/Sources/Interaction/Manipulators/MouseRangeManipulator/index.d.ts index 1b5982a1304..c3b4ed9510b 100644 --- a/Sources/Interaction/Manipulators/MouseRangeManipulator/index.d.ts +++ b/Sources/Interaction/Manipulators/MouseRangeManipulator/index.d.ts @@ -1,7 +1,7 @@ -import { vtkObject } from '../../../interfaces'; import vtkCompositeMouseManipulator, { ICompositeMouseManipulatorInitialValues, } from '../../../Interaction/Manipulators/CompositeMouseManipulator'; +import { vtkObject } from '../../../interfaces'; export interface IMouseRangeManipulatorInitialValues extends ICompositeMouseManipulatorInitialValues {} diff --git a/Utilities/build/rewrite-imports.js b/Utilities/build/rewrite-imports.js index cb5fb9d0691..37465cb265d 100644 --- a/Utilities/build/rewrite-imports.js +++ b/Utilities/build/rewrite-imports.js @@ -1,7 +1,7 @@ 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++; @@ -9,7 +9,10 @@ module.exports = (code, replaceFunc) => { 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;