vinsol_spree_themes 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.ruby-version +1 -0
- data/Appraisals +16 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +386 -0
- data/LICENSE +26 -0
- data/README.md +250 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/codemirror/codemirror.js +9351 -0
- data/app/assets/javascripts/spree/backend/codemirror/css-hint.js +60 -0
- data/app/assets/javascripts/spree/backend/codemirror/fullscreen.js +41 -0
- data/app/assets/javascripts/spree/backend/codemirror/html-hint.js +348 -0
- data/app/assets/javascripts/spree/backend/codemirror/javascript-hint.js +155 -0
- data/app/assets/javascripts/spree/backend/codemirror/javascript.js +813 -0
- data/app/assets/javascripts/spree/backend/codemirror/markdown.js +796 -0
- data/app/assets/javascripts/spree/backend/codemirror/ruby.js +295 -0
- data/app/assets/javascripts/spree/backend/codemirror/show-hint.js +438 -0
- data/app/assets/javascripts/spree/backend/editor.js +11 -0
- data/app/assets/javascripts/spree/backend/jquery.treemenu.js +87 -0
- data/app/assets/javascripts/spree/backend/main.js +26 -0
- data/app/assets/javascripts/spree/backend/spree_themes.js +2 -0
- data/app/assets/javascripts/spree/backend/template.js +51 -0
- data/app/assets/javascripts/spree/backend/theme.js +17 -0
- data/app/assets/javascripts/spree/frontend/spree_themes.js +2 -0
- data/app/assets/stylesheets/spree/backend/codemirror/codemirror.css +340 -0
- data/app/assets/stylesheets/spree/backend/codemirror/fullscreen.css +6 -0
- data/app/assets/stylesheets/spree/backend/codemirror/show-hint.css +36 -0
- data/app/assets/stylesheets/spree/backend/editor.css +7 -0
- data/app/assets/stylesheets/spree/backend/jquery.treemenu.css +8 -0
- data/app/assets/stylesheets/spree/backend/spree_themes.css +7 -0
- data/app/assets/stylesheets/spree/backend/style.css +239 -0
- data/app/assets/stylesheets/spree/backend/template_editor.css +39 -0
- data/app/assets/stylesheets/spree/frontend/spree_themes.css +6 -0
- data/app/assets/stylesheets/spree/frontend/theme_preview.css +9 -0
- data/app/controllers/spree/admin/themes_controller.rb +80 -0
- data/app/controllers/spree/admin/themes_preview_controller.rb +30 -0
- data/app/controllers/spree/admin/themes_templates_controller.rb +60 -0
- data/app/controllers/spree/fragment_cache_controller.rb +13 -0
- data/app/controllers/spree/store_controller_decorator.rb +37 -0
- data/app/helpers/spree/base_helper_decorator.rb +45 -0
- data/app/models/spree/theme.rb +153 -0
- data/app/models/spree/themes_template.rb +67 -0
- data/app/models/spree/themes_template/cache_resolver.rb +37 -0
- data/app/overrides/spree/add_preview_bar_to_store.html.rb +6 -0
- data/app/overrides/spree/add_theme_meta_details_to_store.html.rb +6 -0
- data/app/overrides/spree/admin/add_themes_tab.html.rb +6 -0
- data/app/services/assets_precompiler_service.rb +86 -0
- data/app/services/file_generator_service.rb +29 -0
- data/app/services/template_generator_service.rb +101 -0
- data/app/services/zip_file_builder.rb +87 -0
- data/app/services/zip_file_extractor.rb +52 -0
- data/app/views/spree/admin/shared/_theme_menu_button.html.erb +5 -0
- data/app/views/spree/admin/themes/_themes.html.erb +44 -0
- data/app/views/spree/admin/themes/_upload.html.erb +17 -0
- data/app/views/spree/admin/themes/index.html.erb +50 -0
- data/app/views/spree/admin/themes_templates/_editor.html.erb +29 -0
- data/app/views/spree/admin/themes_templates/_template.html.erb +12 -0
- data/app/views/spree/admin/themes_templates/edit.html.erb +13 -0
- data/app/views/spree/admin/themes_templates/edit.js.erb +1 -0
- data/app/views/spree/admin/themes_templates/index.html.erb +27 -0
- data/app/views/spree/admin/themes_templates/new.html.erb +56 -0
- data/app/views/spree/shared/_preview_bar.html.erb +7 -0
- data/app/views/spree/shared/_theme_metadata.html.erb +9 -0
- data/bin/rails +7 -0
- data/config/initializers/assets.rb +24 -0
- data/config/initializers/sprockets.rb +85 -0
- data/config/locales/en.yml +52 -0
- data/config/routes.rb +22 -0
- data/db/migrate/20170628072452_vinsol_spree_themes_create_themes_and_themes_templates_table.rb +24 -0
- data/gemfiles/spree_3_1.gemfile +8 -0
- data/gemfiles/spree_3_2.gemfile +9 -0
- data/gemfiles/spree_master.gemfile +9 -0
- data/lib/generators/themes/default.zip +0 -0
- data/lib/generators/vinsol_spree_themes/install/install_generator.rb +50 -0
- data/lib/tasks/sync_templates.rake +47 -0
- data/lib/vinsol_spree_themes.rb +3 -0
- data/lib/vinsol_spree_themes/engine.rb +22 -0
- data/lib/vinsol_spree_themes/factories.rb +6 -0
- data/lib/vinsol_spree_themes/version.rb +18 -0
- data/spec/spec_helper.rb +93 -0
- data/vinsol_spree_themes.gemspec +43 -0
- metadata +374 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2
|
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3
|
+
|
4
|
+
(function(mod) {
|
5
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6
|
+
mod(require("../../lib/codemirror"));
|
7
|
+
else if (typeof define == "function" && define.amd) // AMD
|
8
|
+
define(["../../lib/codemirror"], mod);
|
9
|
+
else // Plain browser env
|
10
|
+
mod(CodeMirror);
|
11
|
+
})(function(CodeMirror) {
|
12
|
+
var Pos = CodeMirror.Pos;
|
13
|
+
|
14
|
+
function forEach(arr, f) {
|
15
|
+
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
|
16
|
+
}
|
17
|
+
|
18
|
+
function arrayContains(arr, item) {
|
19
|
+
if (!Array.prototype.indexOf) {
|
20
|
+
var i = arr.length;
|
21
|
+
while (i--) {
|
22
|
+
if (arr[i] === item) {
|
23
|
+
return true;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
return arr.indexOf(item) != -1;
|
29
|
+
}
|
30
|
+
|
31
|
+
function scriptHint(editor, keywords, getToken, options) {
|
32
|
+
// Find the token at the cursor
|
33
|
+
var cur = editor.getCursor(), token = getToken(editor, cur);
|
34
|
+
if (/\b(?:string|comment)\b/.test(token.type)) return;
|
35
|
+
token.state = CodeMirror.innerMode(editor.getMode(), token.state).state;
|
36
|
+
|
37
|
+
// If it's not a 'word-style' token, ignore the token.
|
38
|
+
if (!/^[\w$_]*$/.test(token.string)) {
|
39
|
+
token = {start: cur.ch, end: cur.ch, string: "", state: token.state,
|
40
|
+
type: token.string == "." ? "property" : null};
|
41
|
+
} else if (token.end > cur.ch) {
|
42
|
+
token.end = cur.ch;
|
43
|
+
token.string = token.string.slice(0, cur.ch - token.start);
|
44
|
+
}
|
45
|
+
|
46
|
+
var tprop = token;
|
47
|
+
// If it is a property, find out what it is a property of.
|
48
|
+
while (tprop.type == "property") {
|
49
|
+
tprop = getToken(editor, Pos(cur.line, tprop.start));
|
50
|
+
if (tprop.string != ".") return;
|
51
|
+
tprop = getToken(editor, Pos(cur.line, tprop.start));
|
52
|
+
if (!context) var context = [];
|
53
|
+
context.push(tprop);
|
54
|
+
}
|
55
|
+
return {list: getCompletions(token, context, keywords, options),
|
56
|
+
from: Pos(cur.line, token.start),
|
57
|
+
to: Pos(cur.line, token.end)};
|
58
|
+
}
|
59
|
+
|
60
|
+
function javascriptHint(editor, options) {
|
61
|
+
return scriptHint(editor, javascriptKeywords,
|
62
|
+
function (e, cur) {return e.getTokenAt(cur);},
|
63
|
+
options);
|
64
|
+
};
|
65
|
+
CodeMirror.registerHelper("hint", "javascript", javascriptHint);
|
66
|
+
|
67
|
+
function getCoffeeScriptToken(editor, cur) {
|
68
|
+
// This getToken, it is for coffeescript, imitates the behavior of
|
69
|
+
// getTokenAt method in javascript.js, that is, returning "property"
|
70
|
+
// type and treat "." as indepenent token.
|
71
|
+
var token = editor.getTokenAt(cur);
|
72
|
+
if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
|
73
|
+
token.end = token.start;
|
74
|
+
token.string = '.';
|
75
|
+
token.type = "property";
|
76
|
+
}
|
77
|
+
else if (/^\.[\w$_]*$/.test(token.string)) {
|
78
|
+
token.type = "property";
|
79
|
+
token.start++;
|
80
|
+
token.string = token.string.replace(/\./, '');
|
81
|
+
}
|
82
|
+
return token;
|
83
|
+
}
|
84
|
+
|
85
|
+
function coffeescriptHint(editor, options) {
|
86
|
+
return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
|
87
|
+
}
|
88
|
+
CodeMirror.registerHelper("hint", "coffeescript", coffeescriptHint);
|
89
|
+
|
90
|
+
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
|
91
|
+
"toUpperCase toLowerCase split concat match replace search").split(" ");
|
92
|
+
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
|
93
|
+
"lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
|
94
|
+
var funcProps = "prototype apply call bind".split(" ");
|
95
|
+
var javascriptKeywords = ("break case catch continue debugger default delete do else false finally for function " +
|
96
|
+
"if in instanceof new null return switch throw true try typeof var void while with").split(" ");
|
97
|
+
var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " +
|
98
|
+
"if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
|
99
|
+
|
100
|
+
function forAllProps(obj, callback) {
|
101
|
+
if (!Object.getOwnPropertyNames || !Object.getPrototypeOf) {
|
102
|
+
for (var name in obj) callback(name)
|
103
|
+
} else {
|
104
|
+
for (var o = obj; o; o = Object.getPrototypeOf(o))
|
105
|
+
Object.getOwnPropertyNames(o).forEach(callback)
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
function getCompletions(token, context, keywords, options) {
|
110
|
+
var found = [], start = token.string, global = options && options.globalScope || window;
|
111
|
+
function maybeAdd(str) {
|
112
|
+
if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
|
113
|
+
}
|
114
|
+
function gatherCompletions(obj) {
|
115
|
+
if (typeof obj == "string") forEach(stringProps, maybeAdd);
|
116
|
+
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
|
117
|
+
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
|
118
|
+
forAllProps(obj, maybeAdd)
|
119
|
+
}
|
120
|
+
|
121
|
+
if (context && context.length) {
|
122
|
+
// If this is a property, see if it belongs to some object we can
|
123
|
+
// find in the current environment.
|
124
|
+
var obj = context.pop(), base;
|
125
|
+
if (obj.type && obj.type.indexOf("variable") === 0) {
|
126
|
+
if (options && options.additionalContext)
|
127
|
+
base = options.additionalContext[obj.string];
|
128
|
+
if (!options || options.useGlobalScope !== false)
|
129
|
+
base = base || global[obj.string];
|
130
|
+
} else if (obj.type == "string") {
|
131
|
+
base = "";
|
132
|
+
} else if (obj.type == "atom") {
|
133
|
+
base = 1;
|
134
|
+
} else if (obj.type == "function") {
|
135
|
+
if (global.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
|
136
|
+
(typeof global.jQuery == 'function'))
|
137
|
+
base = global.jQuery();
|
138
|
+
else if (global._ != null && (obj.string == '_') && (typeof global._ == 'function'))
|
139
|
+
base = global._();
|
140
|
+
}
|
141
|
+
while (base != null && context.length)
|
142
|
+
base = base[context.pop().string];
|
143
|
+
if (base != null) gatherCompletions(base);
|
144
|
+
} else {
|
145
|
+
// If not, just look in the global object and any local scope
|
146
|
+
// (reading into JS mode internals to get at the local and global variables)
|
147
|
+
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
|
148
|
+
for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
|
149
|
+
if (!options || options.useGlobalScope !== false)
|
150
|
+
gatherCompletions(global);
|
151
|
+
forEach(keywords, maybeAdd);
|
152
|
+
}
|
153
|
+
return found;
|
154
|
+
}
|
155
|
+
});
|
@@ -0,0 +1,813 @@
|
|
1
|
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2
|
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3
|
+
|
4
|
+
(function(mod) {
|
5
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6
|
+
mod(require("../../lib/codemirror"));
|
7
|
+
else if (typeof define == "function" && define.amd) // AMD
|
8
|
+
define(["../../lib/codemirror"], mod);
|
9
|
+
else // Plain browser env
|
10
|
+
mod(CodeMirror);
|
11
|
+
})(function(CodeMirror) {
|
12
|
+
"use strict";
|
13
|
+
|
14
|
+
function expressionAllowed(stream, state, backUp) {
|
15
|
+
return /^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
|
16
|
+
(state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
|
17
|
+
}
|
18
|
+
|
19
|
+
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
20
|
+
var indentUnit = config.indentUnit;
|
21
|
+
var statementIndent = parserConfig.statementIndent;
|
22
|
+
var jsonldMode = parserConfig.jsonld;
|
23
|
+
var jsonMode = parserConfig.json || jsonldMode;
|
24
|
+
var isTS = parserConfig.typescript;
|
25
|
+
var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
|
26
|
+
|
27
|
+
// Tokenizer
|
28
|
+
|
29
|
+
var keywords = function(){
|
30
|
+
function kw(type) {return {type: type, style: "keyword"};}
|
31
|
+
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
|
32
|
+
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
33
|
+
|
34
|
+
var jsKeywords = {
|
35
|
+
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
36
|
+
"return": C, "break": C, "continue": C, "new": kw("new"), "delete": C, "throw": C, "debugger": C,
|
37
|
+
"var": kw("var"), "const": kw("var"), "let": kw("var"),
|
38
|
+
"function": kw("function"), "catch": kw("catch"),
|
39
|
+
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
40
|
+
"in": operator, "typeof": operator, "instanceof": operator,
|
41
|
+
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
42
|
+
"this": kw("this"), "class": kw("class"), "super": kw("atom"),
|
43
|
+
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
|
44
|
+
"await": C, "async": kw("async")
|
45
|
+
};
|
46
|
+
|
47
|
+
// Extend the 'normal' keywords with the TypeScript language extensions
|
48
|
+
if (isTS) {
|
49
|
+
var type = {type: "variable", style: "variable-3"};
|
50
|
+
var tsKeywords = {
|
51
|
+
// object-like things
|
52
|
+
"interface": kw("class"),
|
53
|
+
"implements": C,
|
54
|
+
"namespace": C,
|
55
|
+
"module": kw("module"),
|
56
|
+
"enum": kw("module"),
|
57
|
+
|
58
|
+
// scope modifiers
|
59
|
+
"public": kw("modifier"),
|
60
|
+
"private": kw("modifier"),
|
61
|
+
"protected": kw("modifier"),
|
62
|
+
"abstract": kw("modifier"),
|
63
|
+
|
64
|
+
// operators
|
65
|
+
"as": operator,
|
66
|
+
|
67
|
+
// types
|
68
|
+
"string": type, "number": type, "boolean": type, "any": type
|
69
|
+
};
|
70
|
+
|
71
|
+
for (var attr in tsKeywords) {
|
72
|
+
jsKeywords[attr] = tsKeywords[attr];
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
return jsKeywords;
|
77
|
+
}();
|
78
|
+
|
79
|
+
var isOperatorChar = /[+\-*&%=<>!?|~^@]/;
|
80
|
+
var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
|
81
|
+
|
82
|
+
function readRegexp(stream) {
|
83
|
+
var escaped = false, next, inSet = false;
|
84
|
+
while ((next = stream.next()) != null) {
|
85
|
+
if (!escaped) {
|
86
|
+
if (next == "/" && !inSet) return;
|
87
|
+
if (next == "[") inSet = true;
|
88
|
+
else if (inSet && next == "]") inSet = false;
|
89
|
+
}
|
90
|
+
escaped = !escaped && next == "\\";
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
// Used as scratch variables to communicate multiple values without
|
95
|
+
// consing up tons of objects.
|
96
|
+
var type, content;
|
97
|
+
function ret(tp, style, cont) {
|
98
|
+
type = tp; content = cont;
|
99
|
+
return style;
|
100
|
+
}
|
101
|
+
function tokenBase(stream, state) {
|
102
|
+
var ch = stream.next();
|
103
|
+
if (ch == '"' || ch == "'") {
|
104
|
+
state.tokenize = tokenString(ch);
|
105
|
+
return state.tokenize(stream, state);
|
106
|
+
} else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
|
107
|
+
return ret("number", "number");
|
108
|
+
} else if (ch == "." && stream.match("..")) {
|
109
|
+
return ret("spread", "meta");
|
110
|
+
} else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
111
|
+
return ret(ch);
|
112
|
+
} else if (ch == "=" && stream.eat(">")) {
|
113
|
+
return ret("=>", "operator");
|
114
|
+
} else if (ch == "0" && stream.eat(/x/i)) {
|
115
|
+
stream.eatWhile(/[\da-f]/i);
|
116
|
+
return ret("number", "number");
|
117
|
+
} else if (ch == "0" && stream.eat(/o/i)) {
|
118
|
+
stream.eatWhile(/[0-7]/i);
|
119
|
+
return ret("number", "number");
|
120
|
+
} else if (ch == "0" && stream.eat(/b/i)) {
|
121
|
+
stream.eatWhile(/[01]/i);
|
122
|
+
return ret("number", "number");
|
123
|
+
} else if (/\d/.test(ch)) {
|
124
|
+
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
|
125
|
+
return ret("number", "number");
|
126
|
+
} else if (ch == "/") {
|
127
|
+
if (stream.eat("*")) {
|
128
|
+
state.tokenize = tokenComment;
|
129
|
+
return tokenComment(stream, state);
|
130
|
+
} else if (stream.eat("/")) {
|
131
|
+
stream.skipToEnd();
|
132
|
+
return ret("comment", "comment");
|
133
|
+
} else if (expressionAllowed(stream, state, 1)) {
|
134
|
+
readRegexp(stream);
|
135
|
+
stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
|
136
|
+
return ret("regexp", "string-2");
|
137
|
+
} else {
|
138
|
+
stream.eatWhile(isOperatorChar);
|
139
|
+
return ret("operator", "operator", stream.current());
|
140
|
+
}
|
141
|
+
} else if (ch == "`") {
|
142
|
+
state.tokenize = tokenQuasi;
|
143
|
+
return tokenQuasi(stream, state);
|
144
|
+
} else if (ch == "#") {
|
145
|
+
stream.skipToEnd();
|
146
|
+
return ret("error", "error");
|
147
|
+
} else if (isOperatorChar.test(ch)) {
|
148
|
+
if (ch != ">" || !state.lexical || state.lexical.type != ">")
|
149
|
+
stream.eatWhile(isOperatorChar);
|
150
|
+
return ret("operator", "operator", stream.current());
|
151
|
+
} else if (wordRE.test(ch)) {
|
152
|
+
stream.eatWhile(wordRE);
|
153
|
+
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
|
154
|
+
return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
|
155
|
+
ret("variable", "variable", word);
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
function tokenString(quote) {
|
160
|
+
return function(stream, state) {
|
161
|
+
var escaped = false, next;
|
162
|
+
if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
|
163
|
+
state.tokenize = tokenBase;
|
164
|
+
return ret("jsonld-keyword", "meta");
|
165
|
+
}
|
166
|
+
while ((next = stream.next()) != null) {
|
167
|
+
if (next == quote && !escaped) break;
|
168
|
+
escaped = !escaped && next == "\\";
|
169
|
+
}
|
170
|
+
if (!escaped) state.tokenize = tokenBase;
|
171
|
+
return ret("string", "string");
|
172
|
+
};
|
173
|
+
}
|
174
|
+
|
175
|
+
function tokenComment(stream, state) {
|
176
|
+
var maybeEnd = false, ch;
|
177
|
+
while (ch = stream.next()) {
|
178
|
+
if (ch == "/" && maybeEnd) {
|
179
|
+
state.tokenize = tokenBase;
|
180
|
+
break;
|
181
|
+
}
|
182
|
+
maybeEnd = (ch == "*");
|
183
|
+
}
|
184
|
+
return ret("comment", "comment");
|
185
|
+
}
|
186
|
+
|
187
|
+
function tokenQuasi(stream, state) {
|
188
|
+
var escaped = false, next;
|
189
|
+
while ((next = stream.next()) != null) {
|
190
|
+
if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
|
191
|
+
state.tokenize = tokenBase;
|
192
|
+
break;
|
193
|
+
}
|
194
|
+
escaped = !escaped && next == "\\";
|
195
|
+
}
|
196
|
+
return ret("quasi", "string-2", stream.current());
|
197
|
+
}
|
198
|
+
|
199
|
+
var brackets = "([{}])";
|
200
|
+
// This is a crude lookahead trick to try and notice that we're
|
201
|
+
// parsing the argument patterns for a fat-arrow function before we
|
202
|
+
// actually hit the arrow token. It only works if the arrow is on
|
203
|
+
// the same line as the arguments and there's no strange noise
|
204
|
+
// (comments) in between. Fallback is to only notice when we hit the
|
205
|
+
// arrow, and not declare the arguments as locals for the arrow
|
206
|
+
// body.
|
207
|
+
function findFatArrow(stream, state) {
|
208
|
+
if (state.fatArrowAt) state.fatArrowAt = null;
|
209
|
+
var arrow = stream.string.indexOf("=>", stream.start);
|
210
|
+
if (arrow < 0) return;
|
211
|
+
|
212
|
+
if (isTS) { // Try to skip TypeScript return type declarations after the arguments
|
213
|
+
var m = /:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(stream.string.slice(stream.start, arrow))
|
214
|
+
if (m) arrow = m.index
|
215
|
+
}
|
216
|
+
|
217
|
+
var depth = 0, sawSomething = false;
|
218
|
+
for (var pos = arrow - 1; pos >= 0; --pos) {
|
219
|
+
var ch = stream.string.charAt(pos);
|
220
|
+
var bracket = brackets.indexOf(ch);
|
221
|
+
if (bracket >= 0 && bracket < 3) {
|
222
|
+
if (!depth) { ++pos; break; }
|
223
|
+
if (--depth == 0) { if (ch == "(") sawSomething = true; break; }
|
224
|
+
} else if (bracket >= 3 && bracket < 6) {
|
225
|
+
++depth;
|
226
|
+
} else if (wordRE.test(ch)) {
|
227
|
+
sawSomething = true;
|
228
|
+
} else if (/["'\/]/.test(ch)) {
|
229
|
+
return;
|
230
|
+
} else if (sawSomething && !depth) {
|
231
|
+
++pos;
|
232
|
+
break;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
if (sawSomething && !depth) state.fatArrowAt = pos;
|
236
|
+
}
|
237
|
+
|
238
|
+
// Parser
|
239
|
+
|
240
|
+
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true};
|
241
|
+
|
242
|
+
function JSLexical(indented, column, type, align, prev, info) {
|
243
|
+
this.indented = indented;
|
244
|
+
this.column = column;
|
245
|
+
this.type = type;
|
246
|
+
this.prev = prev;
|
247
|
+
this.info = info;
|
248
|
+
if (align != null) this.align = align;
|
249
|
+
}
|
250
|
+
|
251
|
+
function inScope(state, varname) {
|
252
|
+
for (var v = state.localVars; v; v = v.next)
|
253
|
+
if (v.name == varname) return true;
|
254
|
+
for (var cx = state.context; cx; cx = cx.prev) {
|
255
|
+
for (var v = cx.vars; v; v = v.next)
|
256
|
+
if (v.name == varname) return true;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
|
260
|
+
function parseJS(state, style, type, content, stream) {
|
261
|
+
var cc = state.cc;
|
262
|
+
// Communicate our context to the combinators.
|
263
|
+
// (Less wasteful than consing up a hundred closures on every call.)
|
264
|
+
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
|
265
|
+
|
266
|
+
if (!state.lexical.hasOwnProperty("align"))
|
267
|
+
state.lexical.align = true;
|
268
|
+
|
269
|
+
while(true) {
|
270
|
+
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
|
271
|
+
if (combinator(type, content)) {
|
272
|
+
while(cc.length && cc[cc.length - 1].lex)
|
273
|
+
cc.pop()();
|
274
|
+
if (cx.marked) return cx.marked;
|
275
|
+
if (type == "variable" && inScope(state, content)) return "variable-2";
|
276
|
+
return style;
|
277
|
+
}
|
278
|
+
}
|
279
|
+
}
|
280
|
+
|
281
|
+
// Combinator utils
|
282
|
+
|
283
|
+
var cx = {state: null, column: null, marked: null, cc: null};
|
284
|
+
function pass() {
|
285
|
+
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
286
|
+
}
|
287
|
+
function cont() {
|
288
|
+
pass.apply(null, arguments);
|
289
|
+
return true;
|
290
|
+
}
|
291
|
+
function register(varname) {
|
292
|
+
function inList(list) {
|
293
|
+
for (var v = list; v; v = v.next)
|
294
|
+
if (v.name == varname) return true;
|
295
|
+
return false;
|
296
|
+
}
|
297
|
+
var state = cx.state;
|
298
|
+
cx.marked = "def";
|
299
|
+
if (state.context) {
|
300
|
+
if (inList(state.localVars)) return;
|
301
|
+
state.localVars = {name: varname, next: state.localVars};
|
302
|
+
} else {
|
303
|
+
if (inList(state.globalVars)) return;
|
304
|
+
if (parserConfig.globalVars)
|
305
|
+
state.globalVars = {name: varname, next: state.globalVars};
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
// Combinators
|
310
|
+
|
311
|
+
var defaultVars = {name: "this", next: {name: "arguments"}};
|
312
|
+
function pushcontext() {
|
313
|
+
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
|
314
|
+
cx.state.localVars = defaultVars;
|
315
|
+
}
|
316
|
+
function popcontext() {
|
317
|
+
cx.state.localVars = cx.state.context.vars;
|
318
|
+
cx.state.context = cx.state.context.prev;
|
319
|
+
}
|
320
|
+
function pushlex(type, info) {
|
321
|
+
var result = function() {
|
322
|
+
var state = cx.state, indent = state.indented;
|
323
|
+
if (state.lexical.type == "stat") indent = state.lexical.indented;
|
324
|
+
else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
|
325
|
+
indent = outer.indented;
|
326
|
+
state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
|
327
|
+
};
|
328
|
+
result.lex = true;
|
329
|
+
return result;
|
330
|
+
}
|
331
|
+
function poplex() {
|
332
|
+
var state = cx.state;
|
333
|
+
if (state.lexical.prev) {
|
334
|
+
if (state.lexical.type == ")")
|
335
|
+
state.indented = state.lexical.indented;
|
336
|
+
state.lexical = state.lexical.prev;
|
337
|
+
}
|
338
|
+
}
|
339
|
+
poplex.lex = true;
|
340
|
+
|
341
|
+
function expect(wanted) {
|
342
|
+
function exp(type) {
|
343
|
+
if (type == wanted) return cont();
|
344
|
+
else if (wanted == ";") return pass();
|
345
|
+
else return cont(exp);
|
346
|
+
};
|
347
|
+
return exp;
|
348
|
+
}
|
349
|
+
|
350
|
+
function statement(type, value) {
|
351
|
+
if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
|
352
|
+
if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex);
|
353
|
+
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
354
|
+
if (type == "{") return cont(pushlex("}"), block, poplex);
|
355
|
+
if (type == ";") return cont();
|
356
|
+
if (type == "if") {
|
357
|
+
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
|
358
|
+
cx.state.cc.pop()();
|
359
|
+
return cont(pushlex("form"), parenExpr, statement, poplex, maybeelse);
|
360
|
+
}
|
361
|
+
if (type == "function") return cont(functiondef);
|
362
|
+
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
|
363
|
+
if (type == "variable") {
|
364
|
+
if (isTS && value == "type") {
|
365
|
+
cx.marked = "keyword"
|
366
|
+
return cont(typeexpr, expect("operator"), typeexpr, expect(";"));
|
367
|
+
} else {
|
368
|
+
return cont(pushlex("stat"), maybelabel);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"),
|
372
|
+
block, poplex, poplex);
|
373
|
+
if (type == "case") return cont(expression, expect(":"));
|
374
|
+
if (type == "default") return cont(expect(":"));
|
375
|
+
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
376
|
+
statement, poplex, popcontext);
|
377
|
+
if (type == "class") return cont(pushlex("form"), className, poplex);
|
378
|
+
if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
|
379
|
+
if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
|
380
|
+
if (type == "module") return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex)
|
381
|
+
if (type == "async") return cont(statement)
|
382
|
+
if (value == "@") return cont(expression, statement)
|
383
|
+
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
384
|
+
}
|
385
|
+
function expression(type) {
|
386
|
+
return expressionInner(type, false);
|
387
|
+
}
|
388
|
+
function expressionNoComma(type) {
|
389
|
+
return expressionInner(type, true);
|
390
|
+
}
|
391
|
+
function parenExpr(type) {
|
392
|
+
if (type != "(") return pass()
|
393
|
+
return cont(pushlex(")"), expression, expect(")"), poplex)
|
394
|
+
}
|
395
|
+
function expressionInner(type, noComma) {
|
396
|
+
if (cx.state.fatArrowAt == cx.stream.start) {
|
397
|
+
var body = noComma ? arrowBodyNoComma : arrowBody;
|
398
|
+
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
|
399
|
+
else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
|
400
|
+
}
|
401
|
+
|
402
|
+
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
|
403
|
+
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
|
404
|
+
if (type == "function") return cont(functiondef, maybeop);
|
405
|
+
if (type == "class") return cont(pushlex("form"), classExpression, poplex);
|
406
|
+
if (type == "keyword c" || type == "async") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
|
407
|
+
if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
|
408
|
+
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
|
409
|
+
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
|
410
|
+
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
|
411
|
+
if (type == "quasi") return pass(quasi, maybeop);
|
412
|
+
if (type == "new") return cont(maybeTarget(noComma));
|
413
|
+
return cont();
|
414
|
+
}
|
415
|
+
function maybeexpression(type) {
|
416
|
+
if (type.match(/[;\}\)\],]/)) return pass();
|
417
|
+
return pass(expression);
|
418
|
+
}
|
419
|
+
function maybeexpressionNoComma(type) {
|
420
|
+
if (type.match(/[;\}\)\],]/)) return pass();
|
421
|
+
return pass(expressionNoComma);
|
422
|
+
}
|
423
|
+
|
424
|
+
function maybeoperatorComma(type, value) {
|
425
|
+
if (type == ",") return cont(expression);
|
426
|
+
return maybeoperatorNoComma(type, value, false);
|
427
|
+
}
|
428
|
+
function maybeoperatorNoComma(type, value, noComma) {
|
429
|
+
var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
|
430
|
+
var expr = noComma == false ? expression : expressionNoComma;
|
431
|
+
if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
|
432
|
+
if (type == "operator") {
|
433
|
+
if (/\+\+|--/.test(value)) return cont(me);
|
434
|
+
if (value == "?") return cont(expression, expect(":"), expr);
|
435
|
+
return cont(expr);
|
436
|
+
}
|
437
|
+
if (type == "quasi") { return pass(quasi, me); }
|
438
|
+
if (type == ";") return;
|
439
|
+
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
|
440
|
+
if (type == ".") return cont(property, me);
|
441
|
+
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
|
442
|
+
}
|
443
|
+
function quasi(type, value) {
|
444
|
+
if (type != "quasi") return pass();
|
445
|
+
if (value.slice(value.length - 2) != "${") return cont(quasi);
|
446
|
+
return cont(expression, continueQuasi);
|
447
|
+
}
|
448
|
+
function continueQuasi(type) {
|
449
|
+
if (type == "}") {
|
450
|
+
cx.marked = "string-2";
|
451
|
+
cx.state.tokenize = tokenQuasi;
|
452
|
+
return cont(quasi);
|
453
|
+
}
|
454
|
+
}
|
455
|
+
function arrowBody(type) {
|
456
|
+
findFatArrow(cx.stream, cx.state);
|
457
|
+
return pass(type == "{" ? statement : expression);
|
458
|
+
}
|
459
|
+
function arrowBodyNoComma(type) {
|
460
|
+
findFatArrow(cx.stream, cx.state);
|
461
|
+
return pass(type == "{" ? statement : expressionNoComma);
|
462
|
+
}
|
463
|
+
function maybeTarget(noComma) {
|
464
|
+
return function(type) {
|
465
|
+
if (type == ".") return cont(noComma ? targetNoComma : target);
|
466
|
+
else return pass(noComma ? expressionNoComma : expression);
|
467
|
+
};
|
468
|
+
}
|
469
|
+
function target(_, value) {
|
470
|
+
if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); }
|
471
|
+
}
|
472
|
+
function targetNoComma(_, value) {
|
473
|
+
if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); }
|
474
|
+
}
|
475
|
+
function maybelabel(type) {
|
476
|
+
if (type == ":") return cont(poplex, statement);
|
477
|
+
return pass(maybeoperatorComma, expect(";"), poplex);
|
478
|
+
}
|
479
|
+
function property(type) {
|
480
|
+
if (type == "variable") {cx.marked = "property"; return cont();}
|
481
|
+
}
|
482
|
+
function objprop(type, value) {
|
483
|
+
if (type == "async") {
|
484
|
+
cx.marked = "property";
|
485
|
+
return cont(objprop);
|
486
|
+
} else if (type == "variable" || cx.style == "keyword") {
|
487
|
+
cx.marked = "property";
|
488
|
+
if (value == "get" || value == "set") return cont(getterSetter);
|
489
|
+
return cont(afterprop);
|
490
|
+
} else if (type == "number" || type == "string") {
|
491
|
+
cx.marked = jsonldMode ? "property" : (cx.style + " property");
|
492
|
+
return cont(afterprop);
|
493
|
+
} else if (type == "jsonld-keyword") {
|
494
|
+
return cont(afterprop);
|
495
|
+
} else if (type == "modifier") {
|
496
|
+
return cont(objprop)
|
497
|
+
} else if (type == "[") {
|
498
|
+
return cont(expression, expect("]"), afterprop);
|
499
|
+
} else if (type == "spread") {
|
500
|
+
return cont(expression);
|
501
|
+
} else if (type == ":") {
|
502
|
+
return pass(afterprop)
|
503
|
+
}
|
504
|
+
}
|
505
|
+
function getterSetter(type) {
|
506
|
+
if (type != "variable") return pass(afterprop);
|
507
|
+
cx.marked = "property";
|
508
|
+
return cont(functiondef);
|
509
|
+
}
|
510
|
+
function afterprop(type) {
|
511
|
+
if (type == ":") return cont(expressionNoComma);
|
512
|
+
if (type == "(") return pass(functiondef);
|
513
|
+
}
|
514
|
+
function commasep(what, end, sep) {
|
515
|
+
function proceed(type, value) {
|
516
|
+
if (sep ? sep.indexOf(type) > -1 : type == ",") {
|
517
|
+
var lex = cx.state.lexical;
|
518
|
+
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
|
519
|
+
return cont(function(type, value) {
|
520
|
+
if (type == end || value == end) return pass()
|
521
|
+
return pass(what)
|
522
|
+
}, proceed);
|
523
|
+
}
|
524
|
+
if (type == end || value == end) return cont();
|
525
|
+
return cont(expect(end));
|
526
|
+
}
|
527
|
+
return function(type, value) {
|
528
|
+
if (type == end || value == end) return cont();
|
529
|
+
return pass(what, proceed);
|
530
|
+
};
|
531
|
+
}
|
532
|
+
function contCommasep(what, end, info) {
|
533
|
+
for (var i = 3; i < arguments.length; i++)
|
534
|
+
cx.cc.push(arguments[i]);
|
535
|
+
return cont(pushlex(end, info), commasep(what, end), poplex);
|
536
|
+
}
|
537
|
+
function block(type) {
|
538
|
+
if (type == "}") return cont();
|
539
|
+
return pass(statement, block);
|
540
|
+
}
|
541
|
+
function maybetype(type, value) {
|
542
|
+
if (isTS) {
|
543
|
+
if (type == ":") return cont(typeexpr);
|
544
|
+
if (value == "?") return cont(maybetype);
|
545
|
+
}
|
546
|
+
}
|
547
|
+
function typeexpr(type) {
|
548
|
+
if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
|
549
|
+
if (type == "string" || type == "number" || type == "atom") return cont(afterType);
|
550
|
+
if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
|
551
|
+
if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
|
552
|
+
}
|
553
|
+
function maybeReturnType(type) {
|
554
|
+
if (type == "=>") return cont(typeexpr)
|
555
|
+
}
|
556
|
+
function typeprop(type, value) {
|
557
|
+
if (type == "variable" || cx.style == "keyword") {
|
558
|
+
cx.marked = "property"
|
559
|
+
return cont(typeprop)
|
560
|
+
} else if (value == "?") {
|
561
|
+
return cont(typeprop)
|
562
|
+
} else if (type == ":") {
|
563
|
+
return cont(typeexpr)
|
564
|
+
} else if (type == "[") {
|
565
|
+
return cont(expression, maybetype, expect("]"), typeprop)
|
566
|
+
}
|
567
|
+
}
|
568
|
+
function typearg(type) {
|
569
|
+
if (type == "variable") return cont(typearg)
|
570
|
+
else if (type == ":") return cont(typeexpr)
|
571
|
+
}
|
572
|
+
function afterType(type, value) {
|
573
|
+
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
|
574
|
+
if (value == "|" || type == ".") return cont(typeexpr)
|
575
|
+
if (type == "[") return cont(expect("]"), afterType)
|
576
|
+
if (value == "extends") return cont(typeexpr)
|
577
|
+
}
|
578
|
+
function vardef() {
|
579
|
+
return pass(pattern, maybetype, maybeAssign, vardefCont);
|
580
|
+
}
|
581
|
+
function pattern(type, value) {
|
582
|
+
if (type == "modifier") return cont(pattern)
|
583
|
+
if (type == "variable") { register(value); return cont(); }
|
584
|
+
if (type == "spread") return cont(pattern);
|
585
|
+
if (type == "[") return contCommasep(pattern, "]");
|
586
|
+
if (type == "{") return contCommasep(proppattern, "}");
|
587
|
+
}
|
588
|
+
function proppattern(type, value) {
|
589
|
+
if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
|
590
|
+
register(value);
|
591
|
+
return cont(maybeAssign);
|
592
|
+
}
|
593
|
+
if (type == "variable") cx.marked = "property";
|
594
|
+
if (type == "spread") return cont(pattern);
|
595
|
+
if (type == "}") return pass();
|
596
|
+
return cont(expect(":"), pattern, maybeAssign);
|
597
|
+
}
|
598
|
+
function maybeAssign(_type, value) {
|
599
|
+
if (value == "=") return cont(expressionNoComma);
|
600
|
+
}
|
601
|
+
function vardefCont(type) {
|
602
|
+
if (type == ",") return cont(vardef);
|
603
|
+
}
|
604
|
+
function maybeelse(type, value) {
|
605
|
+
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
|
606
|
+
}
|
607
|
+
function forspec(type) {
|
608
|
+
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
|
609
|
+
}
|
610
|
+
function forspec1(type) {
|
611
|
+
if (type == "var") return cont(vardef, expect(";"), forspec2);
|
612
|
+
if (type == ";") return cont(forspec2);
|
613
|
+
if (type == "variable") return cont(formaybeinof);
|
614
|
+
return pass(expression, expect(";"), forspec2);
|
615
|
+
}
|
616
|
+
function formaybeinof(_type, value) {
|
617
|
+
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
|
618
|
+
return cont(maybeoperatorComma, forspec2);
|
619
|
+
}
|
620
|
+
function forspec2(type, value) {
|
621
|
+
if (type == ";") return cont(forspec3);
|
622
|
+
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
|
623
|
+
return pass(expression, expect(";"), forspec3);
|
624
|
+
}
|
625
|
+
function forspec3(type) {
|
626
|
+
if (type != ")") cont(expression);
|
627
|
+
}
|
628
|
+
function functiondef(type, value) {
|
629
|
+
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
|
630
|
+
if (type == "variable") {register(value); return cont(functiondef);}
|
631
|
+
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, maybetype, statement, popcontext);
|
632
|
+
if (isTS && value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, functiondef)
|
633
|
+
}
|
634
|
+
function funarg(type) {
|
635
|
+
if (type == "spread") return cont(funarg);
|
636
|
+
return pass(pattern, maybetype, maybeAssign);
|
637
|
+
}
|
638
|
+
function classExpression(type, value) {
|
639
|
+
// Class expressions may have an optional name.
|
640
|
+
if (type == "variable") return className(type, value);
|
641
|
+
return classNameAfter(type, value);
|
642
|
+
}
|
643
|
+
function className(type, value) {
|
644
|
+
if (type == "variable") {register(value); return cont(classNameAfter);}
|
645
|
+
}
|
646
|
+
function classNameAfter(type, value) {
|
647
|
+
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, classNameAfter)
|
648
|
+
if (value == "extends" || value == "implements" || (isTS && type == ","))
|
649
|
+
return cont(isTS ? typeexpr : expression, classNameAfter);
|
650
|
+
if (type == "{") return cont(pushlex("}"), classBody, poplex);
|
651
|
+
}
|
652
|
+
function classBody(type, value) {
|
653
|
+
if (type == "variable" || cx.style == "keyword") {
|
654
|
+
if ((value == "async" || value == "static" || value == "get" || value == "set" ||
|
655
|
+
(isTS && (value == "public" || value == "private" || value == "protected" || value == "readonly" || value == "abstract"))) &&
|
656
|
+
cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) {
|
657
|
+
cx.marked = "keyword";
|
658
|
+
return cont(classBody);
|
659
|
+
}
|
660
|
+
cx.marked = "property";
|
661
|
+
return cont(isTS ? classfield : functiondef, classBody);
|
662
|
+
}
|
663
|
+
if (type == "[")
|
664
|
+
return cont(expression, expect("]"), isTS ? classfield : functiondef, classBody)
|
665
|
+
if (value == "*") {
|
666
|
+
cx.marked = "keyword";
|
667
|
+
return cont(classBody);
|
668
|
+
}
|
669
|
+
if (type == ";") return cont(classBody);
|
670
|
+
if (type == "}") return cont();
|
671
|
+
if (value == "@") return cont(expression, classBody)
|
672
|
+
}
|
673
|
+
function classfield(type, value) {
|
674
|
+
if (value == "?") return cont(classfield)
|
675
|
+
if (type == ":") return cont(typeexpr, maybeAssign)
|
676
|
+
if (value == "=") return cont(expressionNoComma)
|
677
|
+
return pass(functiondef)
|
678
|
+
}
|
679
|
+
function afterExport(type, value) {
|
680
|
+
if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
|
681
|
+
if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
|
682
|
+
if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(";"));
|
683
|
+
return pass(statement);
|
684
|
+
}
|
685
|
+
function exportField(type, value) {
|
686
|
+
if (value == "as") { cx.marked = "keyword"; return cont(expect("variable")); }
|
687
|
+
if (type == "variable") return pass(expressionNoComma, exportField);
|
688
|
+
}
|
689
|
+
function afterImport(type) {
|
690
|
+
if (type == "string") return cont();
|
691
|
+
return pass(importSpec, maybeMoreImports, maybeFrom);
|
692
|
+
}
|
693
|
+
function importSpec(type, value) {
|
694
|
+
if (type == "{") return contCommasep(importSpec, "}");
|
695
|
+
if (type == "variable") register(value);
|
696
|
+
if (value == "*") cx.marked = "keyword";
|
697
|
+
return cont(maybeAs);
|
698
|
+
}
|
699
|
+
function maybeMoreImports(type) {
|
700
|
+
if (type == ",") return cont(importSpec, maybeMoreImports)
|
701
|
+
}
|
702
|
+
function maybeAs(_type, value) {
|
703
|
+
if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
|
704
|
+
}
|
705
|
+
function maybeFrom(_type, value) {
|
706
|
+
if (value == "from") { cx.marked = "keyword"; return cont(expression); }
|
707
|
+
}
|
708
|
+
function arrayLiteral(type) {
|
709
|
+
if (type == "]") return cont();
|
710
|
+
return pass(commasep(expressionNoComma, "]"));
|
711
|
+
}
|
712
|
+
|
713
|
+
function isContinuedStatement(state, textAfter) {
|
714
|
+
return state.lastType == "operator" || state.lastType == "," ||
|
715
|
+
isOperatorChar.test(textAfter.charAt(0)) ||
|
716
|
+
/[,.]/.test(textAfter.charAt(0));
|
717
|
+
}
|
718
|
+
|
719
|
+
// Interface
|
720
|
+
|
721
|
+
return {
|
722
|
+
startState: function(basecolumn) {
|
723
|
+
var state = {
|
724
|
+
tokenize: tokenBase,
|
725
|
+
lastType: "sof",
|
726
|
+
cc: [],
|
727
|
+
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
728
|
+
localVars: parserConfig.localVars,
|
729
|
+
context: parserConfig.localVars && {vars: parserConfig.localVars},
|
730
|
+
indented: basecolumn || 0
|
731
|
+
};
|
732
|
+
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
|
733
|
+
state.globalVars = parserConfig.globalVars;
|
734
|
+
return state;
|
735
|
+
},
|
736
|
+
|
737
|
+
token: function(stream, state) {
|
738
|
+
if (stream.sol()) {
|
739
|
+
if (!state.lexical.hasOwnProperty("align"))
|
740
|
+
state.lexical.align = false;
|
741
|
+
state.indented = stream.indentation();
|
742
|
+
findFatArrow(stream, state);
|
743
|
+
}
|
744
|
+
if (state.tokenize != tokenComment && stream.eatSpace()) return null;
|
745
|
+
var style = state.tokenize(stream, state);
|
746
|
+
if (type == "comment") return style;
|
747
|
+
state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
|
748
|
+
return parseJS(state, style, type, content, stream);
|
749
|
+
},
|
750
|
+
|
751
|
+
indent: function(state, textAfter) {
|
752
|
+
if (state.tokenize == tokenComment) return CodeMirror.Pass;
|
753
|
+
if (state.tokenize != tokenBase) return 0;
|
754
|
+
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical, top
|
755
|
+
// Kludge to prevent 'maybelse' from blocking lexical scope pops
|
756
|
+
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
|
757
|
+
var c = state.cc[i];
|
758
|
+
if (c == poplex) lexical = lexical.prev;
|
759
|
+
else if (c != maybeelse) break;
|
760
|
+
}
|
761
|
+
while ((lexical.type == "stat" || lexical.type == "form") &&
|
762
|
+
(firstChar == "}" || ((top = state.cc[state.cc.length - 1]) &&
|
763
|
+
(top == maybeoperatorComma || top == maybeoperatorNoComma) &&
|
764
|
+
!/^[,\.=+\-*:?[\(]/.test(textAfter))))
|
765
|
+
lexical = lexical.prev;
|
766
|
+
if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
|
767
|
+
lexical = lexical.prev;
|
768
|
+
var type = lexical.type, closing = firstChar == type;
|
769
|
+
|
770
|
+
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0);
|
771
|
+
else if (type == "form" && firstChar == "{") return lexical.indented;
|
772
|
+
else if (type == "form") return lexical.indented + indentUnit;
|
773
|
+
else if (type == "stat")
|
774
|
+
return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
|
775
|
+
else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
|
776
|
+
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
|
777
|
+
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
778
|
+
else return lexical.indented + (closing ? 0 : indentUnit);
|
779
|
+
},
|
780
|
+
|
781
|
+
electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
|
782
|
+
blockCommentStart: jsonMode ? null : "/*",
|
783
|
+
blockCommentEnd: jsonMode ? null : "*/",
|
784
|
+
lineComment: jsonMode ? null : "//",
|
785
|
+
fold: "brace",
|
786
|
+
closeBrackets: "()[]{}''\"\"``",
|
787
|
+
|
788
|
+
helperType: jsonMode ? "json" : "javascript",
|
789
|
+
jsonldMode: jsonldMode,
|
790
|
+
jsonMode: jsonMode,
|
791
|
+
|
792
|
+
expressionAllowed: expressionAllowed,
|
793
|
+
skipExpression: function(state) {
|
794
|
+
var top = state.cc[state.cc.length - 1]
|
795
|
+
if (top == expression || top == expressionNoComma) state.cc.pop()
|
796
|
+
}
|
797
|
+
};
|
798
|
+
});
|
799
|
+
|
800
|
+
CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
|
801
|
+
|
802
|
+
CodeMirror.defineMIME("text/javascript", "javascript");
|
803
|
+
CodeMirror.defineMIME("text/ecmascript", "javascript");
|
804
|
+
CodeMirror.defineMIME("application/javascript", "javascript");
|
805
|
+
CodeMirror.defineMIME("application/x-javascript", "javascript");
|
806
|
+
CodeMirror.defineMIME("application/ecmascript", "javascript");
|
807
|
+
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
|
808
|
+
CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
|
809
|
+
CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true});
|
810
|
+
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
|
811
|
+
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
|
812
|
+
|
813
|
+
});
|