Skip to content

Commit

Permalink
[javascript mode] Add support for template string types
Browse files Browse the repository at this point in the history
Issue #5774
  • Loading branch information
marijnh committed May 12, 2021
1 parent e2d0b28 commit 472b458
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mode/javascript/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (type == "{") return cont(pushlex("}"), typeprops, poplex, afterType)
if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType, afterType)
if (type == "<") return cont(commasep(typeexpr, ">"), typeexpr)
if (type == "quasi") { return pass(quasiType, afterType); }
}
function maybeReturnType(type) {
if (type == "=>") return cont(typeexpr)
Expand All @@ -647,6 +648,18 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
return cont()
}
}
function quasiType(type, value) {
if (type != "quasi") return pass();
if (value.slice(value.length - 2) != "${") return cont(quasiType);
return cont(typeexpr, continueQuasiType);
}
function continueQuasiType(type) {
if (type == "}") {
cx.marked = "string-2";
cx.state.tokenize = tokenQuasi;
return cont(quasiType);
}
}
function typearg(type, value) {
if (type == "variable" && cx.stream.match(/^\s*[?:]/, false) || value == "?") return cont(typearg)
if (type == ":") return cont(typeexpr)
Expand Down

0 comments on commit 472b458

Please sign in to comment.