Skip to content
Snippets Groups Projects
Commit 708084a2 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[javascript mode] Improve import/export parsing

Closes #4451
parent 33d920b0
No related branches found
No related tags found
No related merge requests found
......@@ -658,14 +658,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, "}");
......@@ -673,6 +678,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); }
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment