From 10884cbb4df28080c32abb153c2efc0169982ce7 Mon Sep 17 00:00:00 2001 From: Willow Snow Date: Sat, 1 Sep 2018 20:26:20 -0500 Subject: [PATCH] Fix lexer issue with name, update tokens to const /undefined/.test() returns true, so ```parser('test');``` will infinite loop. Tokens is never redefined, so const is preferred. --- the-super-tiny-compiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/the-super-tiny-compiler.js b/the-super-tiny-compiler.js index 411fa54..634f0cd 100755 --- a/the-super-tiny-compiler.js +++ b/the-super-tiny-compiler.js @@ -384,7 +384,7 @@ function tokenizer(input) { let current = 0; // And a `tokens` array for pushing our tokens to. - let tokens = []; + const tokens = []; // We start by creating a `while` loop where we are setting up our `current` // variable to be incremented as much as we want `inside` the loop. @@ -517,7 +517,7 @@ function tokenizer(input) { // Again we're just going to loop through all the letters pushing them to // a value. - while (LETTERS.test(char)) { + while (char && LETTERS.test(char)) { value += char; char = input[++current]; }