diff --git a/src/regexp.ts b/src/regexp.ts index 8ceb141f..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]/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..b136fec3 100644 --- a/test/existing-scanning.test.ts +++ b/test/existing-scanning.test.ts @@ -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'] },