ReviewOS

also looking at this

stacks/dtsx

chore(deps): update all non-major dependencies

#2997
Closed renovate[bot] wants to merge renovate/all-minor-patch into main
29 files +1047 -444
packages/dtsx/src/processor/declarations.tsmodified+30-19
Changes to packages/dtsx/src/processor/declarations.ts
@@ -64,6 +64,12 @@ export function processVariableDeclaration(decl: Declaration, keepComments: bool
6464 // Add comments if present
6565 const comments = formatComments(decl.leadingComments, keepComments)
6666
67 // Fast path: if we have an explicit type annotation and no value needing special inference,
68 // use the scanner's pre-built text directly
69 if (decl.typeAnnotation && !decl.value) {
70 return comments + decl.text
71 }
72
6773 let result = ''
6874
6975 // Add export if needed
@@ -197,11 +203,14 @@ export function processTypeDeclaration(decl: Declaration, keepComments: boolean
197203 result += 'declare '
198204 }
199205
200 // Extract the type definition from the original text
201 // Remove leading/trailing whitespace and comments
202 const typeMatch = decl.text.match(/type\s[^=]+=\s*([\s\S]+)/)
203 if (typeMatch) {
204 const typeDef = typeMatch[0].replace(/;?\s*$/, '')
206 // Extract the type definition from the original text using indexOf instead of regex
207 const typeIdx = decl.text.indexOf('type ')
208 if (typeIdx !== -1) {
209 let typeDef = decl.text.slice(typeIdx)
210 // Strip trailing semicolons and whitespace
211 let end = typeDef.length
212 while (end > 0 && (typeDef.charCodeAt(end - 1) === 59 /* ; */ || typeDef.charCodeAt(end - 1) === 32 || typeDef.charCodeAt(end - 1) === 10 || typeDef.charCodeAt(end - 1) === 13)) end--
213 if (end < typeDef.length) typeDef = typeDef.slice(0, end)
205214 result += typeDef
206215 }
207216 else {
@@ -260,10 +269,10 @@ export function processEnumDeclaration(decl: Declaration, keepComments: boolean
260269 // Add enum name
261270 result += decl.name
262271
263 // Extract the body from the original text
264 const bodyMatch = decl.text.match(/\{[\s\S]*\}/)
265 if (bodyMatch) {
266 result += ` ${bodyMatch[0]}`
272 // Extract the body from the original text using indexOf instead of regex
273 const enumBraceIdx = decl.text.indexOf('{')
274 if (enumBraceIdx !== -1) {
275 result += ' ' + decl.text.slice(enumBraceIdx)
267276 }
268277 else {
269278 result += ' {}'
@@ -280,8 +289,10 @@ export function processImportDeclaration(decl: Declaration): string {
280289 // Just ensure they end with semicolon
281290 let result = decl.text.trim()
282291
283 // Remove any existing semicolon to avoid doubles
284 result = result.replace(/;+$/, '')
292 // Remove trailing semicolons without regex
293 let end = result.length
294 while (end > 0 && result.charCodeAt(end - 1) === 59 /* ; */) end--
295 if (end < result.length) result = result.slice(0, end)
285296
286297 // Add single semicolon
287298 result += ';'
@@ -320,10 +331,10 @@ export function processModuleDeclaration(decl: Declaration, keepComments: boolea
320331 // Add module name
321332 result += decl.name
322333
323 // Extract the body from the original text
324 const bodyMatch = decl.text.match(/\{[\s\S]*\}/)
325 if (bodyMatch) {
326 result += ` ${bodyMatch[0]}`
334 // Extract the body from the original text using indexOf
335 const modBraceIdx = decl.text.indexOf('{')
336 if (modBraceIdx !== -1) {
337 result += ' ' + decl.text.slice(modBraceIdx)
327338 }
328339 else {
329340 result += ' {}'
@@ -351,10 +362,10 @@ export function processModuleDeclaration(decl: Declaration, keepComments: boolea
351362 // Add namespace name
352363 result += decl.name
353364
354 // Extract the body from the original text
355 const bodyMatch = decl.text.match(/\{[\s\S]*\}/)
356 if (bodyMatch) {
357 result += ` ${bodyMatch[0]}`
365 // Extract the body from the original text using indexOf
366 const nsBraceIdx = decl.text.indexOf('{')
367 if (nsBraceIdx !== -1) {
368 result += ' ' + decl.text.slice(nsBraceIdx)
358369 }
359370 else {
360371 result += ' {}'