Skip to content

Commit 974b698

Browse files
committed
[javascript mode] Support typescript-style type params to new
Closes codemirror#4887
1 parent 4b0ae02 commit 974b698

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

mode/javascript/javascript.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
468468
function maybeTarget(noComma) {
469469
return function(type) {
470470
if (type == ".") return cont(noComma ? targetNoComma : target);
471+
else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma)
471472
else return pass(noComma ? expressionNoComma : expression);
472473
};
473474
}
@@ -588,6 +589,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
588589
if (type == "[") return cont(expect("]"), afterType)
589590
if (value == "extends") return cont(typeexpr)
590591
}
592+
function maybeTypeArgs(_, value) {
593+
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
594+
}
591595
function vardef() {
592596
return pass(pattern, maybetype, maybeAssign, vardefCont);
593597
}

mode/javascript/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@
343343
"[keyword function] [def x][operator <][type T] [keyword extends] [keyword keyof] [type X][operator >]([def a]: [type T]) {",
344344
" [keyword return]")
345345

346+
TS("typescript_new_typeargs",
347+
"[keyword let] [def x] [operator =] [keyword new] [variable Map][operator <][type string], [type Date][operator >]([string-2 `foo${][variable bar][string-2 }`])")
348+
346349
var jsonld_mode = CodeMirror.getMode(
347350
{indentUnit: 2},
348351
{name: "javascript", jsonld: true}

0 commit comments

Comments
 (0)