From 16941a7dc94f28cf6272a45091cb8b0ac1b4c55d Mon Sep 17 00:00:00 2001 From: Sebastian Landwehr Date: Sat, 13 Dec 2025 04:01:16 +0100 Subject: [PATCH 1/5] fix: fix for loop local variable detection --- src/regexp.ts | 2 +- test/existing-scanning.test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/regexp.ts b/src/regexp.ts index 8ceb141f..37dc1c21 100644 --- a/src/regexp.ts +++ b/src/regexp.ts @@ -10,7 +10,7 @@ export const excludeRE = [ /\bclass\s*([\w$]+)\s*\{/g, // defined as local variable // eslint-disable-next-line regexp/no-super-linear-backtracking - /\b(?:const|let|var)\s+?(\[.*?\]|\{.*?\}|.+?)\s*?[=;\n]/gs, + /\b(?:const|let|var)\s+?(\[.*?\]|\{.*?\}|.+?)\s*?(?:[=;\n]|of)/gs ] export const importAsRE = /^.*\sas\s+/ diff --git a/test/existing-scanning.test.ts b/test/existing-scanning.test.ts index 7a258454..7b23ad6f 100644 --- a/test/existing-scanning.test.ts +++ b/test/existing-scanning.test.ts @@ -9,6 +9,7 @@ describe('regex for extract local variable', () => { { input: 'const { ref} = Vue', output: ['ref'] }, { input: 'const { maybe_test, $test} = Vue', output: ['maybe_test', '$test'] }, { input: 'const [state] = useState(1)', output: ['state'] }, + { input: 'for (const [index, value] of list.entries()) {}', output: ['index', 'value'] }, // We may not able to handle these cases // { input: 'const b = computed(0) , test=1;', output: ['b', 'test'] }, From a73ded03fcabb0ab443ba2c46cc68a0c8bcd7157 Mon Sep 17 00:00:00 2001 From: Sebastian Landwehr Date: Tue, 16 Dec 2025 02:08:50 +0100 Subject: [PATCH 2/5] fix: fix regex after minimal reproduction --- src/regexp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/regexp.ts b/src/regexp.ts index 37dc1c21..69bd0176 100644 --- a/src/regexp.ts +++ b/src/regexp.ts @@ -10,7 +10,7 @@ export const excludeRE = [ /\bclass\s*([\w$]+)\s*\{/g, // defined as local variable // eslint-disable-next-line regexp/no-super-linear-backtracking - /\b(?:const|let|var)\s+?(\[.*?\]|\{.*?\}|.+?)\s*?(?:[=;\n]|of)/gs + /\b(?:const|let|var)\s+?(\[.*?\]|\{.*?\}|.+?)\s*?(=|;|\n|of)/gs, ] export const importAsRE = /^.*\sas\s+/ From 471a7a264bc4a939d4ff9e5d7983375ea8ca72cd Mon Sep 17 00:00:00 2001 From: Sebastian Landwehr Date: Tue, 16 Dec 2025 02:42:40 +0100 Subject: [PATCH 3/5] chore: reset test --- test/existing-scanning.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/existing-scanning.test.ts b/test/existing-scanning.test.ts index 7b23ad6f..7a258454 100644 --- a/test/existing-scanning.test.ts +++ b/test/existing-scanning.test.ts @@ -9,7 +9,6 @@ describe('regex for extract local variable', () => { { input: 'const { ref} = Vue', output: ['ref'] }, { input: 'const { maybe_test, $test} = Vue', output: ['maybe_test', '$test'] }, { input: 'const [state] = useState(1)', output: ['state'] }, - { input: 'for (const [index, value] of list.entries()) {}', output: ['index', 'value'] }, // We may not able to handle these cases // { input: 'const b = computed(0) , test=1;', output: ['b', 'test'] }, From 8774c3a3c6f285a2f9b955943377aba158a2e59d Mon Sep 17 00:00:00 2001 From: Sebastian Landwehr Date: Tue, 16 Dec 2025 18:20:53 +0100 Subject: [PATCH 4/5] fix: add test --- src/regexp.ts | 2 +- test/existing-scanning.test.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/regexp.ts b/src/regexp.ts index 69bd0176..baf08bfa 100644 --- a/src/regexp.ts +++ b/src/regexp.ts @@ -10,7 +10,7 @@ export const excludeRE = [ /\bclass\s*([\w$]+)\s*\{/g, // defined as local variable // eslint-disable-next-line regexp/no-super-linear-backtracking - /\b(?:const|let|var)\s+?(\[.*?\]|\{.*?\}|.+?)\s*?(=|;|\n|of)/gs, + /\b(?:const|let|var)\s+?(\[.*?\]|\{.*?\}|.+?)\s*?(?:=|;|\n|of)/gs, ] export const importAsRE = /^.*\sas\s+/ diff --git a/test/existing-scanning.test.ts b/test/existing-scanning.test.ts index 7a258454..a7ecc081 100644 --- a/test/existing-scanning.test.ts +++ b/test/existing-scanning.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest' import { excludeRE, importAsRE, separatorRE, stripCommentsAndStrings } from '../src/regexp' -describe('regex for extract local variable', () => { +describe.only('regex for extract local variable', () => { const cases: { input: string, output: string[] }[] = [ { input: 'const b;', output: ['b'] }, { input: 'const { ref, computed,watch} = Vue', output: ['ref', 'computed', 'watch'] }, @@ -9,6 +9,12 @@ describe('regex for extract local variable', () => { { input: 'const { ref} = Vue', output: ['ref'] }, { input: 'const { maybe_test, $test} = Vue', output: ['maybe_test', '$test'] }, { input: 'const [state] = useState(1)', output: ['state'] }, + { input: ` +for (const [index] of [1,2,3].entries()) { + const a = AUTO_IMPORTED; + const b = []; // Make sure that the destructuring bracket in the loop does not expand to here +} +`, output: ['index', 'a', 'b'] }, // We may not able to handle these cases // { input: 'const b = computed(0) , test=1;', output: ['b', 'test'] }, From e43f8283af51152131b5b9d238e7ee71c8e84cce Mon Sep 17 00:00:00 2001 From: Sebastian Landwehr Date: Tue, 16 Dec 2025 18:21:13 +0100 Subject: [PATCH 5/5] chore: remove only --- test/existing-scanning.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/existing-scanning.test.ts b/test/existing-scanning.test.ts index a7ecc081..b136fec3 100644 --- a/test/existing-scanning.test.ts +++ b/test/existing-scanning.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest' import { excludeRE, importAsRE, separatorRE, stripCommentsAndStrings } from '../src/regexp' -describe.only('regex for extract local variable', () => { +describe('regex for extract local variable', () => { const cases: { input: string, output: string[] }[] = [ { input: 'const b;', output: ['b'] }, { input: 'const { ref, computed,watch} = Vue', output: ['ref', 'computed', 'watch'] },