Skip to content

Commit 901666a

Browse files
committed
[javascript mode] Properly parse quasi quotes without prefix
Closes #2472
1 parent effbd7f commit 901666a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

mode/javascript/javascript.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
355355
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
356356
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
357357
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
358+
if (type == "quasi") { return pass(quasi, maybeop); }
358359
return cont();
359360
}
360361
function maybeexpression(type) {
@@ -379,21 +380,22 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
379380
if (value == "?") return cont(expression, expect(":"), expr);
380381
return cont(expr);
381382
}
382-
if (type == "quasi") { cx.cc.push(me); return quasi(value); }
383+
if (type == "quasi") { return pass(quasi, me); }
383384
if (type == ";") return;
384385
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
385386
if (type == ".") return cont(property, me);
386387
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
387388
}
388-
function quasi(value) {
389-
if (value.slice(value.length - 2) != "${") return cont();
389+
function quasi(type, value) {
390+
if (type != "quasi") return pass();
391+
if (value.slice(value.length - 2) != "${") return cont(quasi);
390392
return cont(expression, continueQuasi);
391393
}
392394
function continueQuasi(type) {
393395
if (type == "}") {
394396
cx.marked = "string-2";
395397
cx.state.tokenize = tokenQuasi;
396-
return cont();
398+
return cont(quasi);
397399
}
398400
}
399401
function arrowBody(type) {

mode/javascript/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
MT("quasi",
7171
"[variable re][string-2 `fofdlakj${][variable x] [operator +] ([variable re][string-2 `foo`]) [operator +] [number 1][string-2 }fdsa`] [operator +] [number 2]");
7272

73+
MT("quasi_no_function",
74+
"[variable x] [operator =] [string-2 `fofdlakj${][variable x] [operator +] [string-2 `foo`] [operator +] [number 1][string-2 }fdsa`] [operator +] [number 2]");
75+
7376
MT("indent_statement",
7477
"[keyword var] [variable x] [operator =] [number 10]",
7578
"[variable x] [operator +=] [variable y] [operator +]",

0 commit comments

Comments
 (0)