diff --git a/mode/javascript/javascript.js b/mode/javascript/javascript.js index ef0184789ab3d201ab17d949d8ca5cf12da26096..c86f49e1f60a9d8559bae42639534b1f23eddbe2 100644 --- a/mode/javascript/javascript.js +++ b/mode/javascript/javascript.js @@ -482,8 +482,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { function maybetype(type) { if (isTS && type == ":") return cont(typedef); } + function maybedefault(_, value) { + if (value == "=") return cont(expressionNoComma); + } function typedef(type) { - if (type == "variable"){cx.marked = "variable-3"; return cont();} + if (type == "variable") {cx.marked = "variable-3"; return cont();} } function vardef() { return pass(pattern, maybetype, maybeAssign, vardefCont); @@ -538,7 +541,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { } function funarg(type) { if (type == "spread") return cont(funarg); - return pass(pattern, maybetype); + return pass(pattern, maybetype, maybedefault); } function className(type, value) { if (type == "variable") {register(value); return cont(classNameAfter);} diff --git a/mode/javascript/test.js b/mode/javascript/test.js index 91b0e89a06a7e0a6503b238fbb906ba0f085bb49..092d25dc9ad06074fc0792afa5256ef0d9c2cffc 100644 --- a/mode/javascript/test.js +++ b/mode/javascript/test.js @@ -160,6 +160,11 @@ "]];", "[number 10];"); + MT("param_default", + "[keyword function] [variable foo]([def x] [operator =] [string-2 `foo${][number 10][string-2 }bar`]) {", + " [keyword return] [variable-2 x];", + "}"); + var jsonld_mode = CodeMirror.getMode( {indentUnit: 2}, {name: "javascript", jsonld: true}