From 287a6d5ac4b2960ee5eb2bb17445fbc9bccb0152 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Fri, 14 Jan 2022 09:50:49 +0100 Subject: [PATCH] [FIX] code_generator: stop matching other variables prefix Previously, we would replace block declarations in some contexts with the variable alone, and decalres the variable higher in the generated code. Issues arise because whe sometimes try to replace "let b2" with "b2" but end up matching "let b20" which is incorrect. This commit fixes that by adding a space to the text that we are trying to match ("let b2 " won't match "let b20") --- src/compiler/code_generator.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/code_generator.ts b/src/compiler/code_generator.ts index a724ea88..dcb8a6bf 100644 --- a/src/compiler/code_generator.ts +++ b/src/compiler/code_generator.ts @@ -673,7 +673,7 @@ export class CodeGenerator { const children = block!.children.slice(); let current = children.shift(); for (let i = codeIdx; i < code.length; i++) { - if (code[i].trimStart().startsWith(`let ${current!.varName}`)) { + if (code[i].trimStart().startsWith(`let ${current!.varName} `)) { code[i] = code[i].replace(`let ${current!.varName}`, current!.varName); current = children.shift(); if (!current) break; @@ -768,7 +768,7 @@ export class CodeGenerator { const children = block!.children.slice(); let current = children.shift(); for (let i = codeIdx; i < code.length; i++) { - if (code[i].trimStart().startsWith(`let ${current!.varName}`)) { + if (code[i].trimStart().startsWith(`let ${current!.varName} `)) { code[i] = code[i].replace(`let ${current!.varName}`, current!.varName); current = children.shift(); if (!current) break; @@ -912,7 +912,7 @@ export class CodeGenerator { const children = block!.children.slice(); let current = children.shift(); for (let i = codeIdx; i < code.length; i++) { - if (code[i].trimStart().startsWith(`let ${current!.varName}`)) { + if (code[i].trimStart().startsWith(`let ${current!.varName} `)) { code[i] = code[i].replace(`let ${current!.varName}`, current!.varName); current = children.shift(); if (!current) break;