Skip to content

Commit 31eb1b2

Browse files
committed
[javascript mode] Handle trailing commas better
1 parent e60f4b7 commit 31eb1b2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

mode/javascript/javascript.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
495495
if (type == ",") {
496496
var lex = cx.state.lexical;
497497
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
498-
return cont(what, proceed);
498+
return cont(function(type, value) {
499+
if (type == end || value == end) return pass()
500+
return pass(what)
501+
}, proceed);
499502
}
500503
if (type == end || value == end) return cont();
501504
return cont(expect(end));

mode/javascript/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
" [keyword import] { [def encrypt], [def decrypt] } [keyword from] [string 'crypto'];",
4545
"}");
4646

47+
MT("import_trailing_comma",
48+
"[keyword import] {[def foo], [def bar],} [keyword from] [string 'baz']")
49+
4750
MT("const",
4851
"[keyword function] [def f]() {",
4952
" [keyword const] [[ [def a], [def b] ]] [operator =] [[ [number 1], [number 2] ]];",

0 commit comments

Comments
 (0)