From f923c5e9e1af8cda5c2e55df25ba0e370465faf1 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Mon, 8 Aug 2022 14:37:54 -0700 Subject: [PATCH] refactor: cleanup template literal state --- src/states/TEMPLATE_STRING.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/states/TEMPLATE_STRING.ts b/src/states/TEMPLATE_STRING.ts index d501932..7e4bf7f 100644 --- a/src/states/TEMPLATE_STRING.ts +++ b/src/states/TEMPLATE_STRING.ts @@ -21,20 +21,21 @@ export const TEMPLATE_STRING: StateDefinition = { exit() {}, char(code) { - if ( - code === CODE.DOLLAR && - this.lookAtCharCodeAhead(1) === CODE.OPEN_CURLY_BRACE - ) { - this.pos++; // skip { - this.enterState(STATE.EXPRESSION).shouldTerminate = - matchesCloseCurlyBrace; - } else { - if (code === CODE.BACK_SLASH) { + switch (code) { + case CODE.DOLLAR: + if (this.lookAtCharCodeAhead(1) === CODE.OPEN_CURLY_BRACE) { + this.pos++; // skip { + this.enterState(STATE.EXPRESSION).shouldTerminate = + matchesCloseCurlyBrace; + } + break; + case CODE.BACK_SLASH: this.pos++; // skip \ - } else if (code === CODE.BACKTICK) { + break; + case CODE.BACKTICK: this.pos++; // skip ` this.exitState(); - } + break; } },