|
|
@@ -12,7 +12,7 @@
|
|
|
"use strict";
|
|
|
|
|
|
function expressionAllowed(stream, state, backUp) {
|
|
|
- return /^(?:operator|sof|keyword c|case|new|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
|
|
|
+ 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))))
|
|
|
}
|
|
|
|
|
|
@@ -146,7 +146,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
stream.skipToEnd();
|
|
|
return ret("error", "error");
|
|
|
} else if (isOperatorChar.test(ch)) {
|
|
|
- stream.eatWhile(isOperatorChar);
|
|
|
+ if (ch != ">" || !state.lexical || state.lexical.type != ">")
|
|
|
+ stream.eatWhile(isOperatorChar);
|
|
|
return ret("operator", "operator", stream.current());
|
|
|
} else if (wordRE.test(ch)) {
|
|
|
stream.eatWhile(wordRE);
|
|
|
@@ -504,9 +505,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
if (type == ":") return cont(expressionNoComma);
|
|
|
if (type == "(") return pass(functiondef);
|
|
|
}
|
|
|
- function commasep(what, end) {
|
|
|
+ function commasep(what, end, sep) {
|
|
|
function proceed(type, value) {
|
|
|
- if (type == ",") {
|
|
|
+ if (sep ? sep.indexOf(type) > -1 : type == ",") {
|
|
|
var lex = cx.state.lexical;
|
|
|
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
|
|
|
return cont(function(type, value) {
|
|
|
@@ -539,16 +540,19 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
}
|
|
|
function typeexpr(type) {
|
|
|
if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
|
|
|
- if (type == "{") return cont(commasep(typeprop, "}"))
|
|
|
+ if (type == "string" || type == "number" || type == "atom") return cont(afterType);
|
|
|
+ if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex)
|
|
|
if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
|
|
|
}
|
|
|
function maybeReturnType(type) {
|
|
|
if (type == "=>") return cont(typeexpr)
|
|
|
}
|
|
|
- function typeprop(type) {
|
|
|
+ function typeprop(type, value) {
|
|
|
if (type == "variable" || cx.style == "keyword") {
|
|
|
cx.marked = "property"
|
|
|
return cont(typeprop)
|
|
|
+ } else if (value == "?") {
|
|
|
+ return cont(typeprop)
|
|
|
} else if (type == ":") {
|
|
|
return cont(typeexpr)
|
|
|
}
|
|
|
@@ -558,7 +562,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
else if (type == ":") return cont(typeexpr)
|
|
|
}
|
|
|
function afterType(type, value) {
|
|
|
- if (value == "<") return cont(commasep(typeexpr, ">"), afterType)
|
|
|
+ if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
|
|
|
+ if (value == "|" || type == ".") return cont(typeexpr)
|
|
|
if (type == "[") return cont(expect("]"), afterType)
|
|
|
}
|
|
|
function vardef() {
|
|
|
@@ -655,14 +660,19 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
if (type == ":") return cont(typeexpr, maybeAssign)
|
|
|
return pass(functiondef)
|
|
|
}
|
|
|
- function afterExport(_type, value) {
|
|
|
+ function afterExport(type, value) {
|
|
|
if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
|
|
|
if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
|
|
|
+ if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(";"));
|
|
|
return pass(statement);
|
|
|
}
|
|
|
+ function exportField(type, value) {
|
|
|
+ if (value == "as") { cx.marked = "keyword"; return cont(expect("variable")); }
|
|
|
+ if (type == "variable") return pass(expressionNoComma, exportField);
|
|
|
+ }
|
|
|
function afterImport(type) {
|
|
|
if (type == "string") return cont();
|
|
|
- return pass(importSpec, maybeFrom);
|
|
|
+ return pass(importSpec, maybeMoreImports, maybeFrom);
|
|
|
}
|
|
|
function importSpec(type, value) {
|
|
|
if (type == "{") return contCommasep(importSpec, "}");
|
|
|
@@ -670,6 +680,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
|
if (value == "*") cx.marked = "keyword";
|
|
|
return cont(maybeAs);
|
|
|
}
|
|
|
+ function maybeMoreImports(type) {
|
|
|
+ if (type == ",") return cont(importSpec, maybeMoreImports)
|
|
|
+ }
|
|
|
function maybeAs(_type, value) {
|
|
|
if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
|
|
|
}
|