Skip to content

Commit 4c30e11

Browse files
committed
[javascript mode] Handle string defaults in arrow function param lists
Closes #5934
1 parent ac2b82c commit 4c30e11

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mode/javascript/javascript.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
196196
} else if (wordRE.test(ch)) {
197197
sawSomething = true;
198198
} else if (/["'\/]/.test(ch)) {
199-
return;
199+
for (;; --pos) {
200+
if (pos == 0) return
201+
let next = stream.string.charAt(pos - 1)
202+
if (next == ch && stream.string.charAt(pos - 2) != "\\") { pos--; break }
203+
}
200204
} else if (sawSomething && !depth) {
201205
++pos;
202206
break;

mode/javascript/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
"[keyword let] [def f] [operator =] ([[ [def a], [def b] ]], [def c]) [operator =>] [variable-2 a] [operator +] [variable-2 c];",
128128
"[variable c];");
129129

130+
MT("fatArrow_stringDefault",
131+
"([def a], [def b] [operator =] [string 'x\\'y']) [operator =>] [variable-2 a] [operator +] [variable-2 b]")
132+
130133
MT("spread",
131134
"[keyword function] [def f]([def a], [meta ...][def b]) {",
132135
" [variable something]([variable-2 a], [meta ...][variable-2 b]);",

0 commit comments

Comments
 (0)