Skip to content

Commit

Permalink
refactor: cleanup template literal state
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Aug 8, 2022
1 parent 65a2935 commit f923c5e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/states/TEMPLATE_STRING.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
},

Expand Down

0 comments on commit f923c5e

Please sign in to comment.