|
|
@ -1,5 +1,5 @@
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
|
|
|
|
|
|
|
|
|
|
|
(function(mod) {
|
|
|
|
(function(mod) {
|
|
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
|
@ -11,11 +11,6 @@
|
|
|
|
})(function(CodeMirror) {
|
|
|
|
})(function(CodeMirror) {
|
|
|
|
"use strict";
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
function expressionAllowed(stream, state, backUp) {
|
|
|
|
|
|
|
|
return /^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
|
|
|
|
|
|
|
|
(state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
var indentUnit = config.indentUnit;
|
|
|
|
var indentUnit = config.indentUnit;
|
|
|
|
var statementIndent = parserConfig.statementIndent;
|
|
|
|
var statementIndent = parserConfig.statementIndent;
|
|
|
@ -28,53 +23,21 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
|
|
|
|
|
|
|
|
var keywords = function(){
|
|
|
|
var keywords = function(){
|
|
|
|
function kw(type) {return {type: type, style: "keyword"};}
|
|
|
|
function kw(type) {return {type: type, style: "keyword"};}
|
|
|
|
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
|
|
|
|
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"), D = kw("keyword d");
|
|
|
|
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
|
|
|
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
|
|
|
|
|
|
|
|
|
|
|
var jsKeywords = {
|
|
|
|
return {
|
|
|
|
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
|
|
|
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
|
|
|
"return": C, "break": C, "continue": C, "new": kw("new"), "delete": C, "throw": C, "debugger": C,
|
|
|
|
"return": D, "break": D, "continue": D, "new": kw("new"), "delete": C, "void": C, "throw": C,
|
|
|
|
"var": kw("var"), "const": kw("var"), "let": kw("var"),
|
|
|
|
"debugger": kw("debugger"), "var": kw("var"), "const": kw("var"), "let": kw("var"),
|
|
|
|
"function": kw("function"), "catch": kw("catch"),
|
|
|
|
"function": kw("function"), "catch": kw("catch"),
|
|
|
|
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
|
|
|
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
|
|
|
"in": operator, "typeof": operator, "instanceof": operator,
|
|
|
|
"in": operator, "typeof": operator, "instanceof": operator,
|
|
|
|
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
|
|
|
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
|
|
|
"this": kw("this"), "class": kw("class"), "super": kw("atom"),
|
|
|
|
"this": kw("this"), "class": kw("class"), "super": kw("atom"),
|
|
|
|
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
|
|
|
|
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
|
|
|
|
"await": C, "async": kw("async")
|
|
|
|
"await": C
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Extend the 'normal' keywords with the TypeScript language extensions
|
|
|
|
|
|
|
|
if (isTS) {
|
|
|
|
|
|
|
|
var type = {type: "variable", style: "variable-3"};
|
|
|
|
|
|
|
|
var tsKeywords = {
|
|
|
|
|
|
|
|
// object-like things
|
|
|
|
|
|
|
|
"interface": kw("class"),
|
|
|
|
|
|
|
|
"implements": C,
|
|
|
|
|
|
|
|
"namespace": C,
|
|
|
|
|
|
|
|
"module": kw("module"),
|
|
|
|
|
|
|
|
"enum": kw("module"),
|
|
|
|
|
|
|
|
"type": kw("type"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// scope modifiers
|
|
|
|
|
|
|
|
"public": kw("modifier"),
|
|
|
|
|
|
|
|
"private": kw("modifier"),
|
|
|
|
|
|
|
|
"protected": kw("modifier"),
|
|
|
|
|
|
|
|
"abstract": kw("modifier"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// operators
|
|
|
|
|
|
|
|
"as": operator,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// types
|
|
|
|
|
|
|
|
"string": type, "number": type, "boolean": type, "any": type
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var attr in tsKeywords) {
|
|
|
|
|
|
|
|
jsKeywords[attr] = tsKeywords[attr];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return jsKeywords;
|
|
|
|
|
|
|
|
}();
|
|
|
|
}();
|
|
|
|
|
|
|
|
|
|
|
|
var isOperatorChar = /[+\-*&%=<>!?|~^@]/;
|
|
|
|
var isOperatorChar = /[+\-*&%=<>!?|~^@]/;
|
|
|
@ -112,17 +75,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
return ret(ch);
|
|
|
|
return ret(ch);
|
|
|
|
} else if (ch == "=" && stream.eat(">")) {
|
|
|
|
} else if (ch == "=" && stream.eat(">")) {
|
|
|
|
return ret("=>", "operator");
|
|
|
|
return ret("=>", "operator");
|
|
|
|
} else if (ch == "0" && stream.eat(/x/i)) {
|
|
|
|
} else if (ch == "0" && stream.match(/^(?:x[\da-f]+|o[0-7]+|b[01]+)n?/i)) {
|
|
|
|
stream.eatWhile(/[\da-f]/i);
|
|
|
|
|
|
|
|
return ret("number", "number");
|
|
|
|
|
|
|
|
} else if (ch == "0" && stream.eat(/o/i)) {
|
|
|
|
|
|
|
|
stream.eatWhile(/[0-7]/i);
|
|
|
|
|
|
|
|
return ret("number", "number");
|
|
|
|
|
|
|
|
} else if (ch == "0" && stream.eat(/b/i)) {
|
|
|
|
|
|
|
|
stream.eatWhile(/[01]/i);
|
|
|
|
|
|
|
|
return ret("number", "number");
|
|
|
|
return ret("number", "number");
|
|
|
|
} else if (/\d/.test(ch)) {
|
|
|
|
} else if (/\d/.test(ch)) {
|
|
|
|
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
|
|
|
|
stream.match(/^\d*(?:n|(?:\.\d*)?(?:[eE][+\-]?\d+)?)?/);
|
|
|
|
return ret("number", "number");
|
|
|
|
return ret("number", "number");
|
|
|
|
} else if (ch == "/") {
|
|
|
|
} else if (ch == "/") {
|
|
|
|
if (stream.eat("*")) {
|
|
|
|
if (stream.eat("*")) {
|
|
|
@ -133,10 +89,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
return ret("comment", "comment");
|
|
|
|
return ret("comment", "comment");
|
|
|
|
} else if (expressionAllowed(stream, state, 1)) {
|
|
|
|
} else if (expressionAllowed(stream, state, 1)) {
|
|
|
|
readRegexp(stream);
|
|
|
|
readRegexp(stream);
|
|
|
|
stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
|
|
|
|
stream.match(/^\b(([gimyus])(?![gimyus]*\2))+\b/);
|
|
|
|
return ret("regexp", "string-2");
|
|
|
|
return ret("regexp", "string-2");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
stream.eatWhile(isOperatorChar);
|
|
|
|
stream.eat("=");
|
|
|
|
return ret("operator", "operator", stream.current());
|
|
|
|
return ret("operator", "operator", stream.current());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ch == "`") {
|
|
|
|
} else if (ch == "`") {
|
|
|
@ -146,14 +102,27 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
stream.skipToEnd();
|
|
|
|
stream.skipToEnd();
|
|
|
|
return ret("error", "error");
|
|
|
|
return ret("error", "error");
|
|
|
|
} else if (isOperatorChar.test(ch)) {
|
|
|
|
} else if (isOperatorChar.test(ch)) {
|
|
|
|
if (ch != ">" || !state.lexical || state.lexical.type != ">")
|
|
|
|
if (ch != ">" || !state.lexical || state.lexical.type != ">") {
|
|
|
|
stream.eatWhile(isOperatorChar);
|
|
|
|
if (stream.eat("=")) {
|
|
|
|
|
|
|
|
if (ch == "!" || ch == "=") stream.eat("=")
|
|
|
|
|
|
|
|
} else if (/[<>*+\-]/.test(ch)) {
|
|
|
|
|
|
|
|
stream.eat(ch)
|
|
|
|
|
|
|
|
if (ch == ">") stream.eat(ch)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return ret("operator", "operator", stream.current());
|
|
|
|
return ret("operator", "operator", stream.current());
|
|
|
|
} else if (wordRE.test(ch)) {
|
|
|
|
} else if (wordRE.test(ch)) {
|
|
|
|
stream.eatWhile(wordRE);
|
|
|
|
stream.eatWhile(wordRE);
|
|
|
|
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
|
|
|
|
var word = stream.current()
|
|
|
|
return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
|
|
|
|
if (state.lastType != ".") {
|
|
|
|
ret("variable", "variable", word);
|
|
|
|
if (keywords.propertyIsEnumerable(word)) {
|
|
|
|
|
|
|
|
var kw = keywords[word]
|
|
|
|
|
|
|
|
return ret(kw.type, kw.style, word)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (word == "async" && stream.match(/^(\s|\/\*.*?\*\/)*[\[\(\w]/, false))
|
|
|
|
|
|
|
|
return ret("async", "keyword", word)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret("variable", "variable", word)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -289,35 +258,68 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
pass.apply(null, arguments);
|
|
|
|
pass.apply(null, arguments);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function inList(name, list) {
|
|
|
|
|
|
|
|
for (var v = list; v; v = v.next) if (v.name == name) return true
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
function register(varname) {
|
|
|
|
function register(varname) {
|
|
|
|
function inList(list) {
|
|
|
|
|
|
|
|
for (var v = list; v; v = v.next)
|
|
|
|
|
|
|
|
if (v.name == varname) return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var state = cx.state;
|
|
|
|
var state = cx.state;
|
|
|
|
cx.marked = "def";
|
|
|
|
cx.marked = "def";
|
|
|
|
if (state.context) {
|
|
|
|
if (state.context) {
|
|
|
|
if (inList(state.localVars)) return;
|
|
|
|
if (state.lexical.info == "var" && state.context && state.context.block) {
|
|
|
|
state.localVars = {name: varname, next: state.localVars};
|
|
|
|
// FIXME function decls are also not block scoped
|
|
|
|
|
|
|
|
var newContext = registerVarScoped(varname, state.context)
|
|
|
|
|
|
|
|
if (newContext != null) {
|
|
|
|
|
|
|
|
state.context = newContext
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!inList(varname, state.localVars)) {
|
|
|
|
|
|
|
|
state.localVars = new Var(varname, state.localVars)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall through means this is global
|
|
|
|
|
|
|
|
if (parserConfig.globalVars && !inList(varname, state.globalVars))
|
|
|
|
|
|
|
|
state.globalVars = new Var(varname, state.globalVars)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerVarScoped(varname, context) {
|
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
|
|
|
} else if (context.block) {
|
|
|
|
|
|
|
|
var inner = registerVarScoped(varname, context.prev)
|
|
|
|
|
|
|
|
if (!inner) return null
|
|
|
|
|
|
|
|
if (inner == context.prev) return context
|
|
|
|
|
|
|
|
return new Context(inner, context.vars, true)
|
|
|
|
|
|
|
|
} else if (inList(varname, context.vars)) {
|
|
|
|
|
|
|
|
return context
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (inList(state.globalVars)) return;
|
|
|
|
return new Context(context.prev, new Var(varname, context.vars), false)
|
|
|
|
if (parserConfig.globalVars)
|
|
|
|
|
|
|
|
state.globalVars = {name: varname, next: state.globalVars};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isModifier(name) {
|
|
|
|
|
|
|
|
return name == "public" || name == "private" || name == "protected" || name == "abstract" || name == "readonly"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Combinators
|
|
|
|
// Combinators
|
|
|
|
|
|
|
|
|
|
|
|
var defaultVars = {name: "this", next: {name: "arguments"}};
|
|
|
|
function Context(prev, vars, block) { this.prev = prev; this.vars = vars; this.block = block }
|
|
|
|
|
|
|
|
function Var(name, next) { this.name = name; this.next = next }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var defaultVars = new Var("this", new Var("arguments", null))
|
|
|
|
function pushcontext() {
|
|
|
|
function pushcontext() {
|
|
|
|
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
|
|
|
|
cx.state.context = new Context(cx.state.context, cx.state.localVars, false)
|
|
|
|
cx.state.localVars = defaultVars;
|
|
|
|
cx.state.localVars = defaultVars
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function pushblockcontext() {
|
|
|
|
|
|
|
|
cx.state.context = new Context(cx.state.context, cx.state.localVars, true)
|
|
|
|
|
|
|
|
cx.state.localVars = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function popcontext() {
|
|
|
|
function popcontext() {
|
|
|
|
cx.state.localVars = cx.state.context.vars;
|
|
|
|
cx.state.localVars = cx.state.context.vars
|
|
|
|
cx.state.context = cx.state.context.prev;
|
|
|
|
cx.state.context = cx.state.context.prev
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
popcontext.lex = true
|
|
|
|
function pushlex(type, info) {
|
|
|
|
function pushlex(type, info) {
|
|
|
|
var result = function() {
|
|
|
|
var result = function() {
|
|
|
|
var state = cx.state, indent = state.indented;
|
|
|
|
var state = cx.state, indent = state.indented;
|
|
|
@ -342,17 +344,19 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
function expect(wanted) {
|
|
|
|
function expect(wanted) {
|
|
|
|
function exp(type) {
|
|
|
|
function exp(type) {
|
|
|
|
if (type == wanted) return cont();
|
|
|
|
if (type == wanted) return cont();
|
|
|
|
else if (wanted == ";") return pass();
|
|
|
|
else if (wanted == ";" || type == "}" || type == ")" || type == "]") return pass();
|
|
|
|
else return cont(exp);
|
|
|
|
else return cont(exp);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return exp;
|
|
|
|
return exp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function statement(type, value) {
|
|
|
|
function statement(type, value) {
|
|
|
|
if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
|
|
|
|
if (type == "var") return cont(pushlex("vardef", value), vardef, expect(";"), poplex);
|
|
|
|
if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex);
|
|
|
|
if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex);
|
|
|
|
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
|
|
|
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
|
|
|
if (type == "{") return cont(pushlex("}"), block, poplex);
|
|
|
|
if (type == "keyword d") return cx.stream.match(/^\s*$/, false) ? cont() : cont(pushlex("stat"), maybeexpression, expect(";"), poplex);
|
|
|
|
|
|
|
|
if (type == "debugger") return cont(expect(";"));
|
|
|
|
|
|
|
|
if (type == "{") return cont(pushlex("}"), pushblockcontext, block, poplex, popcontext);
|
|
|
|
if (type == ";") return cont();
|
|
|
|
if (type == ";") return cont();
|
|
|
|
if (type == "if") {
|
|
|
|
if (type == "if") {
|
|
|
|
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
|
|
|
|
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
|
|
|
@ -361,60 +365,75 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == "function") return cont(functiondef);
|
|
|
|
if (type == "function") return cont(functiondef);
|
|
|
|
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
|
|
|
|
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
|
|
|
|
if (type == "variable") return cont(pushlex("stat"), maybelabel);
|
|
|
|
if (type == "class" || (isTS && value == "interface")) { cx.marked = "keyword"; return cont(pushlex("form"), className, poplex); }
|
|
|
|
if (type == "switch") return cont(pushlex("form"), parenExpr, pushlex("}", "switch"), expect("{"),
|
|
|
|
if (type == "variable") {
|
|
|
|
block, poplex, poplex);
|
|
|
|
if (isTS && value == "declare") {
|
|
|
|
|
|
|
|
cx.marked = "keyword"
|
|
|
|
|
|
|
|
return cont(statement)
|
|
|
|
|
|
|
|
} else if (isTS && (value == "module" || value == "enum" || value == "type") && cx.stream.match(/^\s*\w/, false)) {
|
|
|
|
|
|
|
|
cx.marked = "keyword"
|
|
|
|
|
|
|
|
if (value == "enum") return cont(enumdef);
|
|
|
|
|
|
|
|
else if (value == "type") return cont(typeexpr, expect("operator"), typeexpr, expect(";"));
|
|
|
|
|
|
|
|
else return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex)
|
|
|
|
|
|
|
|
} else if (isTS && value == "namespace") {
|
|
|
|
|
|
|
|
cx.marked = "keyword"
|
|
|
|
|
|
|
|
return cont(pushlex("form"), expression, block, poplex)
|
|
|
|
|
|
|
|
} else if (isTS && value == "abstract") {
|
|
|
|
|
|
|
|
cx.marked = "keyword"
|
|
|
|
|
|
|
|
return cont(statement)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return cont(pushlex("stat"), maybelabel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"), pushblockcontext,
|
|
|
|
|
|
|
|
block, poplex, poplex, popcontext);
|
|
|
|
if (type == "case") return cont(expression, expect(":"));
|
|
|
|
if (type == "case") return cont(expression, expect(":"));
|
|
|
|
if (type == "default") return cont(expect(":"));
|
|
|
|
if (type == "default") return cont(expect(":"));
|
|
|
|
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
|
|
|
if (type == "catch") return cont(pushlex("form"), pushcontext, maybeCatchBinding, statement, poplex, popcontext);
|
|
|
|
statement, poplex, popcontext);
|
|
|
|
|
|
|
|
if (type == "class") return cont(pushlex("form"), className, poplex);
|
|
|
|
|
|
|
|
if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
|
|
|
|
if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
|
|
|
|
if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
|
|
|
|
if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
|
|
|
|
if (type == "module") return cont(pushlex("form"), pattern, pushlex("}"), expect("{"), block, poplex, poplex)
|
|
|
|
|
|
|
|
if (type == "type") return cont(typeexpr, expect("operator"), typeexpr, expect(";"));
|
|
|
|
|
|
|
|
if (type == "async") return cont(statement)
|
|
|
|
if (type == "async") return cont(statement)
|
|
|
|
if (value == "@") return cont(expression, statement)
|
|
|
|
if (value == "@") return cont(expression, statement)
|
|
|
|
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
|
|
|
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function expression(type) {
|
|
|
|
function maybeCatchBinding(type) {
|
|
|
|
return expressionInner(type, false);
|
|
|
|
if (type == "(") return cont(funarg, expect(")"))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function expression(type, value) {
|
|
|
|
|
|
|
|
return expressionInner(type, value, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function expressionNoComma(type) {
|
|
|
|
function expressionNoComma(type, value) {
|
|
|
|
return expressionInner(type, true);
|
|
|
|
return expressionInner(type, value, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function parenExpr(type) {
|
|
|
|
function parenExpr(type) {
|
|
|
|
if (type != "(") return pass()
|
|
|
|
if (type != "(") return pass()
|
|
|
|
return cont(pushlex(")"), expression, expect(")"), poplex)
|
|
|
|
return cont(pushlex(")"), expression, expect(")"), poplex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function expressionInner(type, noComma) {
|
|
|
|
function expressionInner(type, value, noComma) {
|
|
|
|
if (cx.state.fatArrowAt == cx.stream.start) {
|
|
|
|
if (cx.state.fatArrowAt == cx.stream.start) {
|
|
|
|
var body = noComma ? arrowBodyNoComma : arrowBody;
|
|
|
|
var body = noComma ? arrowBodyNoComma : arrowBody;
|
|
|
|
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
|
|
|
|
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, expect("=>"), body, popcontext);
|
|
|
|
else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
|
|
|
|
else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
|
|
|
|
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
|
|
|
|
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
|
|
|
|
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
|
|
|
|
if (type == "function") return cont(functiondef, maybeop);
|
|
|
|
if (type == "function") return cont(functiondef, maybeop);
|
|
|
|
if (type == "class") return cont(pushlex("form"), classExpression, poplex);
|
|
|
|
if (type == "class" || (isTS && value == "interface")) { cx.marked = "keyword"; return cont(pushlex("form"), classExpression, poplex); }
|
|
|
|
if (type == "keyword c" || type == "async") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
|
|
|
|
if (type == "keyword c" || type == "async") return cont(noComma ? expressionNoComma : expression);
|
|
|
|
if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
|
|
|
|
if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
|
|
|
|
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
|
|
|
|
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
|
|
|
|
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
|
|
|
|
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
|
|
|
|
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
|
|
|
|
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
|
|
|
|
if (type == "quasi") return pass(quasi, maybeop);
|
|
|
|
if (type == "quasi") return pass(quasi, maybeop);
|
|
|
|
if (type == "new") return cont(maybeTarget(noComma));
|
|
|
|
if (type == "new") return cont(maybeTarget(noComma));
|
|
|
|
|
|
|
|
if (type == "import") return cont(expression);
|
|
|
|
return cont();
|
|
|
|
return cont();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function maybeexpression(type) {
|
|
|
|
function maybeexpression(type) {
|
|
|
|
if (type.match(/[;\}\)\],]/)) return pass();
|
|
|
|
if (type.match(/[;\}\)\],]/)) return pass();
|
|
|
|
return pass(expression);
|
|
|
|
return pass(expression);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function maybeexpressionNoComma(type) {
|
|
|
|
|
|
|
|
if (type.match(/[;\}\)\],]/)) return pass();
|
|
|
|
|
|
|
|
return pass(expressionNoComma);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function maybeoperatorComma(type, value) {
|
|
|
|
function maybeoperatorComma(type, value) {
|
|
|
|
if (type == ",") return cont(expression);
|
|
|
|
if (type == ",") return cont(expression);
|
|
|
@ -425,7 +444,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
var expr = noComma == false ? expression : expressionNoComma;
|
|
|
|
var expr = noComma == false ? expression : expressionNoComma;
|
|
|
|
if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
|
|
|
|
if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
|
|
|
|
if (type == "operator") {
|
|
|
|
if (type == "operator") {
|
|
|
|
if (/\+\+|--/.test(value)) return cont(me);
|
|
|
|
if (/\+\+|--/.test(value) || isTS && value == "!") return cont(me);
|
|
|
|
|
|
|
|
if (isTS && value == "<" && cx.stream.match(/^([^>]|<.*?>)*>\s*\(/, false))
|
|
|
|
|
|
|
|
return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, me);
|
|
|
|
if (value == "?") return cont(expression, expect(":"), expr);
|
|
|
|
if (value == "?") return cont(expression, expect(":"), expr);
|
|
|
|
return cont(expr);
|
|
|
|
return cont(expr);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -434,6 +455,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
|
|
|
|
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
|
|
|
|
if (type == ".") return cont(property, me);
|
|
|
|
if (type == ".") return cont(property, me);
|
|
|
|
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
|
|
|
|
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
|
|
|
|
|
|
|
|
if (isTS && value == "as") { cx.marked = "keyword"; return cont(typeexpr, me) }
|
|
|
|
|
|
|
|
if (type == "regexp") {
|
|
|
|
|
|
|
|
cx.state.lastType = cx.marked = "operator"
|
|
|
|
|
|
|
|
cx.stream.backUp(cx.stream.pos - cx.stream.start - 1)
|
|
|
|
|
|
|
|
return cont(expr)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function quasi(type, value) {
|
|
|
|
function quasi(type, value) {
|
|
|
|
if (type != "quasi") return pass();
|
|
|
|
if (type != "quasi") return pass();
|
|
|
@ -458,6 +485,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
function maybeTarget(noComma) {
|
|
|
|
function maybeTarget(noComma) {
|
|
|
|
return function(type) {
|
|
|
|
return function(type) {
|
|
|
|
if (type == ".") return cont(noComma ? targetNoComma : target);
|
|
|
|
if (type == ".") return cont(noComma ? targetNoComma : target);
|
|
|
|
|
|
|
|
else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma)
|
|
|
|
else return pass(noComma ? expressionNoComma : expression);
|
|
|
|
else return pass(noComma ? expressionNoComma : expression);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -481,18 +509,25 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
} else if (type == "variable" || cx.style == "keyword") {
|
|
|
|
} else if (type == "variable" || cx.style == "keyword") {
|
|
|
|
cx.marked = "property";
|
|
|
|
cx.marked = "property";
|
|
|
|
if (value == "get" || value == "set") return cont(getterSetter);
|
|
|
|
if (value == "get" || value == "set") return cont(getterSetter);
|
|
|
|
|
|
|
|
var m // Work around fat-arrow-detection complication for detecting typescript typed arrow params
|
|
|
|
|
|
|
|
if (isTS && cx.state.fatArrowAt == cx.stream.start && (m = cx.stream.match(/^\s*:\s*/, false)))
|
|
|
|
|
|
|
|
cx.state.fatArrowAt = cx.stream.pos + m[0].length
|
|
|
|
return cont(afterprop);
|
|
|
|
return cont(afterprop);
|
|
|
|
} else if (type == "number" || type == "string") {
|
|
|
|
} else if (type == "number" || type == "string") {
|
|
|
|
cx.marked = jsonldMode ? "property" : (cx.style + " property");
|
|
|
|
cx.marked = jsonldMode ? "property" : (cx.style + " property");
|
|
|
|
return cont(afterprop);
|
|
|
|
return cont(afterprop);
|
|
|
|
} else if (type == "jsonld-keyword") {
|
|
|
|
} else if (type == "jsonld-keyword") {
|
|
|
|
return cont(afterprop);
|
|
|
|
return cont(afterprop);
|
|
|
|
} else if (type == "modifier") {
|
|
|
|
} else if (isTS && isModifier(value)) {
|
|
|
|
|
|
|
|
cx.marked = "keyword"
|
|
|
|
return cont(objprop)
|
|
|
|
return cont(objprop)
|
|
|
|
} else if (type == "[") {
|
|
|
|
} else if (type == "[") {
|
|
|
|
return cont(expression, expect("]"), afterprop);
|
|
|
|
return cont(expression, maybetype, expect("]"), afterprop);
|
|
|
|
} else if (type == "spread") {
|
|
|
|
} else if (type == "spread") {
|
|
|
|
return cont(expression);
|
|
|
|
return cont(expressionNoComma, afterprop);
|
|
|
|
|
|
|
|
} else if (value == "*") {
|
|
|
|
|
|
|
|
cx.marked = "keyword";
|
|
|
|
|
|
|
|
return cont(objprop);
|
|
|
|
} else if (type == ":") {
|
|
|
|
} else if (type == ":") {
|
|
|
|
return pass(afterprop)
|
|
|
|
return pass(afterprop)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -539,11 +574,32 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
if (value == "?") return cont(maybetype);
|
|
|
|
if (value == "?") return cont(maybetype);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function typeexpr(type) {
|
|
|
|
function mayberettype(type) {
|
|
|
|
if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
|
|
|
|
if (isTS && type == ":") {
|
|
|
|
|
|
|
|
if (cx.stream.match(/^\s*\w+\s+is\b/, false)) return cont(expression, isKW, typeexpr)
|
|
|
|
|
|
|
|
else return cont(typeexpr)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function isKW(_, value) {
|
|
|
|
|
|
|
|
if (value == "is") {
|
|
|
|
|
|
|
|
cx.marked = "keyword"
|
|
|
|
|
|
|
|
return cont()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function typeexpr(type, value) {
|
|
|
|
|
|
|
|
if (value == "keyof" || value == "typeof") {
|
|
|
|
|
|
|
|
cx.marked = "keyword"
|
|
|
|
|
|
|
|
return cont(value == "keyof" ? typeexpr : expressionNoComma)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "variable" || value == "void") {
|
|
|
|
|
|
|
|
cx.marked = "type"
|
|
|
|
|
|
|
|
return cont(afterType)
|
|
|
|
|
|
|
|
}
|
|
|
|
if (type == "string" || type == "number" || type == "atom") return cont(afterType);
|
|
|
|
if (type == "string" || type == "number" || type == "atom") return cont(afterType);
|
|
|
|
if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex)
|
|
|
|
if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType)
|
|
|
|
|
|
|
|
if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
|
|
|
|
if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
|
|
|
|
if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
|
|
|
|
|
|
|
|
if (type == "<") return cont(commasep(typeexpr, ">"), typeexpr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function maybeReturnType(type) {
|
|
|
|
function maybeReturnType(type) {
|
|
|
|
if (type == "=>") return cont(typeexpr)
|
|
|
|
if (type == "=>") return cont(typeexpr)
|
|
|
@ -556,25 +612,39 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
return cont(typeprop)
|
|
|
|
return cont(typeprop)
|
|
|
|
} else if (type == ":") {
|
|
|
|
} else if (type == ":") {
|
|
|
|
return cont(typeexpr)
|
|
|
|
return cont(typeexpr)
|
|
|
|
|
|
|
|
} else if (type == "[") {
|
|
|
|
|
|
|
|
return cont(expression, maybetype, expect("]"), typeprop)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function typearg(type) {
|
|
|
|
function typearg(type, value) {
|
|
|
|
if (type == "variable") return cont(typearg)
|
|
|
|
if (type == "variable" && cx.stream.match(/^\s*[?:]/, false) || value == "?") return cont(typearg)
|
|
|
|
else if (type == ":") return cont(typeexpr)
|
|
|
|
if (type == ":") return cont(typeexpr)
|
|
|
|
|
|
|
|
return pass(typeexpr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function afterType(type, value) {
|
|
|
|
function afterType(type, value) {
|
|
|
|
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
|
|
|
|
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
|
|
|
|
if (value == "|" || type == ".") return cont(typeexpr)
|
|
|
|
if (value == "|" || type == "." || value == "&") return cont(typeexpr)
|
|
|
|
if (type == "[") return cont(expect("]"), afterType)
|
|
|
|
if (type == "[") return cont(expect("]"), afterType)
|
|
|
|
|
|
|
|
if (value == "extends" || value == "implements") { cx.marked = "keyword"; return cont(typeexpr) }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function maybeTypeArgs(_, value) {
|
|
|
|
|
|
|
|
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function vardef() {
|
|
|
|
function typeparam() {
|
|
|
|
|
|
|
|
return pass(typeexpr, maybeTypeDefault)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function maybeTypeDefault(_, value) {
|
|
|
|
|
|
|
|
if (value == "=") return cont(typeexpr)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function vardef(_, value) {
|
|
|
|
|
|
|
|
if (value == "enum") {cx.marked = "keyword"; return cont(enumdef)}
|
|
|
|
return pass(pattern, maybetype, maybeAssign, vardefCont);
|
|
|
|
return pass(pattern, maybetype, maybeAssign, vardefCont);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function pattern(type, value) {
|
|
|
|
function pattern(type, value) {
|
|
|
|
if (type == "modifier") return cont(pattern)
|
|
|
|
if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(pattern) }
|
|
|
|
if (type == "variable") { register(value); return cont(); }
|
|
|
|
if (type == "variable") { register(value); return cont(); }
|
|
|
|
if (type == "spread") return cont(pattern);
|
|
|
|
if (type == "spread") return cont(pattern);
|
|
|
|
if (type == "[") return contCommasep(pattern, "]");
|
|
|
|
if (type == "[") return contCommasep(eltpattern, "]");
|
|
|
|
if (type == "{") return contCommasep(proppattern, "}");
|
|
|
|
if (type == "{") return contCommasep(proppattern, "}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function proppattern(type, value) {
|
|
|
|
function proppattern(type, value) {
|
|
|
@ -587,6 +657,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
if (type == "}") return pass();
|
|
|
|
if (type == "}") return pass();
|
|
|
|
return cont(expect(":"), pattern, maybeAssign);
|
|
|
|
return cont(expect(":"), pattern, maybeAssign);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function eltpattern() {
|
|
|
|
|
|
|
|
return pass(pattern, maybeAssign)
|
|
|
|
|
|
|
|
}
|
|
|
|
function maybeAssign(_type, value) {
|
|
|
|
function maybeAssign(_type, value) {
|
|
|
|
if (value == "=") return cont(expressionNoComma);
|
|
|
|
if (value == "=") return cont(expressionNoComma);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -596,7 +669,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
function maybeelse(type, value) {
|
|
|
|
function maybeelse(type, value) {
|
|
|
|
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
|
|
|
|
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function forspec(type) {
|
|
|
|
function forspec(type, value) {
|
|
|
|
|
|
|
|
if (value == "await") return cont(forspec);
|
|
|
|
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
|
|
|
|
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function forspec1(type) {
|
|
|
|
function forspec1(type) {
|
|
|
@ -620,11 +694,13 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
function functiondef(type, value) {
|
|
|
|
function functiondef(type, value) {
|
|
|
|
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
|
|
|
|
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
|
|
|
|
if (type == "variable") {register(value); return cont(functiondef);}
|
|
|
|
if (type == "variable") {register(value); return cont(functiondef);}
|
|
|
|
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, maybetype, statement, popcontext);
|
|
|
|
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, mayberettype, statement, popcontext);
|
|
|
|
if (isTS && value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, functiondef)
|
|
|
|
if (isTS && value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, functiondef)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function funarg(type) {
|
|
|
|
function funarg(type, value) {
|
|
|
|
|
|
|
|
if (value == "@") cont(expression, funarg)
|
|
|
|
if (type == "spread") return cont(funarg);
|
|
|
|
if (type == "spread") return cont(funarg);
|
|
|
|
|
|
|
|
if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(funarg); }
|
|
|
|
return pass(pattern, maybetype, maybeAssign);
|
|
|
|
return pass(pattern, maybetype, maybeAssign);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function classExpression(type, value) {
|
|
|
|
function classExpression(type, value) {
|
|
|
@ -636,24 +712,27 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
if (type == "variable") {register(value); return cont(classNameAfter);}
|
|
|
|
if (type == "variable") {register(value); return cont(classNameAfter);}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function classNameAfter(type, value) {
|
|
|
|
function classNameAfter(type, value) {
|
|
|
|
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, classNameAfter)
|
|
|
|
if (value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, classNameAfter)
|
|
|
|
if (value == "extends" || value == "implements" || (isTS && type == ","))
|
|
|
|
if (value == "extends" || value == "implements" || (isTS && type == ",")) {
|
|
|
|
|
|
|
|
if (value == "implements") cx.marked = "keyword";
|
|
|
|
return cont(isTS ? typeexpr : expression, classNameAfter);
|
|
|
|
return cont(isTS ? typeexpr : expression, classNameAfter);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (type == "{") return cont(pushlex("}"), classBody, poplex);
|
|
|
|
if (type == "{") return cont(pushlex("}"), classBody, poplex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function classBody(type, value) {
|
|
|
|
function classBody(type, value) {
|
|
|
|
|
|
|
|
if (type == "async" ||
|
|
|
|
|
|
|
|
(type == "variable" &&
|
|
|
|
|
|
|
|
(value == "static" || value == "get" || value == "set" || (isTS && isModifier(value))) &&
|
|
|
|
|
|
|
|
cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) {
|
|
|
|
|
|
|
|
cx.marked = "keyword";
|
|
|
|
|
|
|
|
return cont(classBody);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (type == "variable" || cx.style == "keyword") {
|
|
|
|
if (type == "variable" || cx.style == "keyword") {
|
|
|
|
if ((value == "async" || value == "static" || value == "get" || value == "set" ||
|
|
|
|
|
|
|
|
(isTS && (value == "public" || value == "private" || value == "protected" || value == "readonly" || value == "abstract"))) &&
|
|
|
|
|
|
|
|
cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) {
|
|
|
|
|
|
|
|
cx.marked = "keyword";
|
|
|
|
|
|
|
|
return cont(classBody);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cx.marked = "property";
|
|
|
|
cx.marked = "property";
|
|
|
|
return cont(isTS ? classfield : functiondef, classBody);
|
|
|
|
return cont(isTS ? classfield : functiondef, classBody);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == "[")
|
|
|
|
if (type == "[")
|
|
|
|
return cont(expression, expect("]"), isTS ? classfield : functiondef, classBody)
|
|
|
|
return cont(expression, maybetype, expect("]"), isTS ? classfield : functiondef, classBody)
|
|
|
|
if (value == "*") {
|
|
|
|
if (value == "*") {
|
|
|
|
cx.marked = "keyword";
|
|
|
|
cx.marked = "keyword";
|
|
|
|
return cont(classBody);
|
|
|
|
return cont(classBody);
|
|
|
@ -680,6 +759,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function afterImport(type) {
|
|
|
|
function afterImport(type) {
|
|
|
|
if (type == "string") return cont();
|
|
|
|
if (type == "string") return cont();
|
|
|
|
|
|
|
|
if (type == "(") return pass(expression);
|
|
|
|
return pass(importSpec, maybeMoreImports, maybeFrom);
|
|
|
|
return pass(importSpec, maybeMoreImports, maybeFrom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function importSpec(type, value) {
|
|
|
|
function importSpec(type, value) {
|
|
|
@ -701,6 +781,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
if (type == "]") return cont();
|
|
|
|
if (type == "]") return cont();
|
|
|
|
return pass(commasep(expressionNoComma, "]"));
|
|
|
|
return pass(commasep(expressionNoComma, "]"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function enumdef() {
|
|
|
|
|
|
|
|
return pass(pushlex("form"), pattern, expect("{"), pushlex("}"), commasep(enummember, "}"), poplex, poplex)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function enummember() {
|
|
|
|
|
|
|
|
return pass(pattern, maybeAssign);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isContinuedStatement(state, textAfter) {
|
|
|
|
function isContinuedStatement(state, textAfter) {
|
|
|
|
return state.lastType == "operator" || state.lastType == "," ||
|
|
|
|
return state.lastType == "operator" || state.lastType == "," ||
|
|
|
@ -708,6 +794,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
/[,.]/.test(textAfter.charAt(0));
|
|
|
|
/[,.]/.test(textAfter.charAt(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function expressionAllowed(stream, state, backUp) {
|
|
|
|
|
|
|
|
return state.tokenize == tokenBase &&
|
|
|
|
|
|
|
|
/^(?:operator|sof|keyword [bcd]|case|new|export|default|spread|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
|
|
|
|
|
|
|
|
(state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Interface
|
|
|
|
// Interface
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
@ -718,7 +810,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
cc: [],
|
|
|
|
cc: [],
|
|
|
|
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
|
|
|
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
|
|
|
localVars: parserConfig.localVars,
|
|
|
|
localVars: parserConfig.localVars,
|
|
|
|
context: parserConfig.localVars && {vars: parserConfig.localVars},
|
|
|
|
context: parserConfig.localVars && new Context(null, null, false),
|
|
|
|
indented: basecolumn || 0
|
|
|
|
indented: basecolumn || 0
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
|
|
|
|
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
|
|
|
@ -759,7 +851,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
lexical = lexical.prev;
|
|
|
|
lexical = lexical.prev;
|
|
|
|
var type = lexical.type, closing = firstChar == type;
|
|
|
|
var type = lexical.type, closing = firstChar == type;
|
|
|
|
|
|
|
|
|
|
|
|
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0);
|
|
|
|
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info.length + 1 : 0);
|
|
|
|
else if (type == "form" && firstChar == "{") return lexical.indented;
|
|
|
|
else if (type == "form" && firstChar == "{") return lexical.indented;
|
|
|
|
else if (type == "form") return lexical.indented + indentUnit;
|
|
|
|
else if (type == "form") return lexical.indented + indentUnit;
|
|
|
|
else if (type == "stat")
|
|
|
|
else if (type == "stat")
|
|
|
@ -773,6 +865,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
|
|
|
|
electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
|
|
|
|
blockCommentStart: jsonMode ? null : "/*",
|
|
|
|
blockCommentStart: jsonMode ? null : "/*",
|
|
|
|
blockCommentEnd: jsonMode ? null : "*/",
|
|
|
|
blockCommentEnd: jsonMode ? null : "*/",
|
|
|
|
|
|
|
|
blockCommentContinue: jsonMode ? null : " * ",
|
|
|
|
lineComment: jsonMode ? null : "//",
|
|
|
|
lineComment: jsonMode ? null : "//",
|
|
|
|
fold: "brace",
|
|
|
|
fold: "brace",
|
|
|
|
closeBrackets: "()[]{}''\"\"``",
|
|
|
|
closeBrackets: "()[]{}''\"\"``",
|
|
|
@ -782,6 +875,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
|
jsonMode: jsonMode,
|
|
|
|
jsonMode: jsonMode,
|
|
|
|
|
|
|
|
|
|
|
|
expressionAllowed: expressionAllowed,
|
|
|
|
expressionAllowed: expressionAllowed,
|
|
|
|
|
|
|
|
|
|
|
|
skipExpression: function(state) {
|
|
|
|
skipExpression: function(state) {
|
|
|
|
var top = state.cc[state.cc.length - 1]
|
|
|
|
var top = state.cc[state.cc.length - 1]
|
|
|
|
if (top == expression || top == expressionNoComma) state.cc.pop()
|
|
|
|
if (top == expression || top == expressionNoComma) state.cc.pop()
|
|
|
|