Skip to content

Commit 8ef19b4

Browse files
committed
[javascript mode] Accept modifiers before parameters in TypeScript mode
Closes #4916
1 parent 12cc4bc commit 8ef19b4

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

mode/javascript/javascript.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
5555
"private": kw("modifier"),
5656
"protected": kw("modifier"),
5757
"abstract": kw("modifier"),
58+
"readonly": kw("modifier"),
5859

5960
// types
6061
"string": type, "number": type, "boolean": type, "any": type
@@ -647,7 +648,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
647648
if (isTS && value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, functiondef)
648649
}
649650
function funarg(type) {
650-
if (type == "spread") return cont(funarg);
651+
if (type == "spread" || type == "modifier") return cont(funarg);
651652
return pass(pattern, maybetype, maybeAssign);
652653
}
653654
function classExpression(type, value) {
@@ -665,13 +666,14 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
665666
if (type == "{") return cont(pushlex("}"), classBody, poplex);
666667
}
667668
function classBody(type, value) {
668-
if (type == "variable" || cx.style == "keyword") {
669-
if ((value == "async" || value == "static" || value == "get" || value == "set" ||
670-
(isTS && (value == "public" || value == "private" || value == "protected" || value == "readonly" || value == "abstract"))) &&
671-
cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) {
672-
cx.marked = "keyword";
673-
return cont(classBody);
674-
}
669+
if (type == "modifier" || type == "async" ||
670+
(type == "variable" &&
671+
(value == "static" || value == "get" || value == "set") &&
672+
cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) {
673+
cx.marked = "keyword";
674+
return cont(classBody);
675+
}
676+
if (type == "variable") {
675677
cx.marked = "property";
676678
return cont(isTS ? classfield : functiondef, classBody);
677679
}

mode/javascript/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@
346346
TS("typescript_new_typeargs",
347347
"[keyword let] [def x] [operator =] [keyword new] [variable Map][operator <][type string], [type Date][operator >]([string-2 `foo${][variable bar][string-2 }`])")
348348

349+
TS("modifiers",
350+
"[keyword class] [def Foo] {",
351+
" [keyword public] [keyword abstract] [property bar]() {}",
352+
" [property constructor]([keyword readonly] [keyword private] [def x]) {}",
353+
"}")
354+
349355
var jsonld_mode = CodeMirror.getMode(
350356
{indentUnit: 2},
351357
{name: "javascript", jsonld: true}

0 commit comments

Comments
 (0)