Skip to content

Commit 298362b

Browse files
committed
refactor logic slightly
1 parent d403490 commit 298362b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/transforms/tree.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,16 @@ const CODE_BACKSLASH = 92;
178178
const CODE_SLASH = 47;
179179

180180
function slashDelimiter(input, delimiterCode) {
181+
if (delimiterCode === CODE_BACKSLASH) throw new Error("delimiter cannot be backslash");
181182
let afterBackslash = false;
182183
for (let i = 0, n = input.length; i < n; ++i) {
183-
const code = input.charCodeAt(i);
184-
if (code === CODE_BACKSLASH && !afterBackslash) {
185-
afterBackslash = true;
186-
continue;
187-
}
188-
switch (code) {
184+
switch (input.charCodeAt(i)) {
185+
case CODE_BACKSLASH:
186+
if (!afterBackslash) {
187+
afterBackslash = true;
188+
continue;
189+
}
190+
break;
189191
case delimiterCode:
190192
if (afterBackslash) {
191193
(input = input.slice(0, i - 1) + input.slice(i)), --i, --n; // remove backslash
@@ -209,13 +211,13 @@ function slashDelimiter(input, delimiterCode) {
209211
function slashUnescape(input) {
210212
let afterBackslash = false;
211213
for (let i = 0, n = input.length; i < n; ++i) {
212-
const code = input.charCodeAt(i);
213-
if (code === CODE_BACKSLASH && !afterBackslash) {
214-
afterBackslash = true;
215-
continue;
216-
}
217-
switch (code) {
214+
switch (input.charCodeAt(i)) {
218215
case CODE_BACKSLASH:
216+
if (!afterBackslash) {
217+
afterBackslash = true;
218+
continue;
219+
}
220+
// eslint-disable-next-line no-fallthrough
219221
case CODE_SLASH:
220222
if (afterBackslash) {
221223
(input = input.slice(0, i - 1) + input.slice(i)), --i, --n; // remove backslash

0 commit comments

Comments
 (0)