slash_admin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +95 -0
  3. data/app/assets/config/relax_admin_manifest.js +2 -0
  4. data/app/assets/images/slash_admin/en.png +0 -0
  5. data/app/assets/images/slash_admin/favicon.png +0 -0
  6. data/app/assets/images/slash_admin/fr.png +0 -0
  7. data/app/assets/javascripts/slash_admin/application.js +344 -0
  8. data/app/assets/javascripts/slash_admin/custom.js +0 -0
  9. data/app/assets/stylesheets/slash_admin/alert.scss +29 -0
  10. data/app/assets/stylesheets/slash_admin/application.scss +1469 -0
  11. data/app/assets/stylesheets/slash_admin/colors.scss +17 -0
  12. data/app/assets/stylesheets/slash_admin/custom.scss +0 -0
  13. data/app/controllers/slash_admin/application_controller.rb +17 -0
  14. data/app/controllers/slash_admin/base_controller.rb +45 -0
  15. data/app/controllers/slash_admin/batch_actions_controller.rb +17 -0
  16. data/app/controllers/slash_admin/dashboard_controller.rb +11 -0
  17. data/app/controllers/slash_admin/models_controller.rb +325 -0
  18. data/app/controllers/slash_admin/security/sessions_controller.rb +29 -0
  19. data/app/controllers/slash_admin/selectize_controller.rb +49 -0
  20. data/app/helpers/slash_admin/application_helper.rb +212 -0
  21. data/app/helpers/slash_admin/menu_helper.rb +14 -0
  22. data/app/helpers/slash_admin/widgets_helper.rb +7 -0
  23. data/app/jobs/slash_admin/application_job.rb +4 -0
  24. data/app/mailers/slash_admin/application_mailer.rb +6 -0
  25. data/app/models/slash_admin/admin.rb +46 -0
  26. data/app/models/slash_admin/admin_ability.rb +11 -0
  27. data/app/models/slash_admin/application_record.rb +5 -0
  28. data/app/views/layouts/slash_admin/admin_user.html.erb +16 -0
  29. data/app/views/layouts/slash_admin/application.html.erb +40 -0
  30. data/app/views/slash_admin/base/_data_belongs_to.html.erb +37 -0
  31. data/app/views/slash_admin/base/_data_list.html.erb +276 -0
  32. data/app/views/slash_admin/base/_data_nestable.html.erb +33 -0
  33. data/app/views/slash_admin/base/_data_new.html.erb +16 -0
  34. data/app/views/slash_admin/base/_data_show.html.erb +72 -0
  35. data/app/views/slash_admin/base/_filters.html.erb +60 -0
  36. data/app/views/slash_admin/base/_translatable_fields.html.erb +23 -0
  37. data/app/views/slash_admin/base/edit.html.erb +26 -0
  38. data/app/views/slash_admin/base/index.html.erb +47 -0
  39. data/app/views/slash_admin/base/index.xls.erb +27 -0
  40. data/app/views/slash_admin/base/nestable.html.erb +28 -0
  41. data/app/views/slash_admin/base/new.html.erb +26 -0
  42. data/app/views/slash_admin/base/show.html.erb +22 -0
  43. data/app/views/slash_admin/custom_fields/_color.html.erb +2 -0
  44. data/app/views/slash_admin/custom_fields/_email.html.erb +2 -0
  45. data/app/views/slash_admin/custom_fields/_google_map.html.erb +72 -0
  46. data/app/views/slash_admin/custom_fields/_nested_belongs_to.html.erb +55 -0
  47. data/app/views/slash_admin/custom_fields/_password.html.erb +2 -0
  48. data/app/views/slash_admin/custom_fields/_select.html.erb +2 -0
  49. data/app/views/slash_admin/custom_fields/_tags.html.erb +2 -0
  50. data/app/views/slash_admin/custom_fields/_wysiwyg.html.erb +2 -0
  51. data/app/views/slash_admin/dashboard/home.html.erb +5 -0
  52. data/app/views/slash_admin/dashboard/widgets/_statistic_chart.html.erb +0 -0
  53. data/app/views/slash_admin/dashboard/widgets/_statistic_progress_tile.html.erb +29 -0
  54. data/app/views/slash_admin/fields/_belongs_to.html.erb +9 -0
  55. data/app/views/slash_admin/fields/_boolean.html.erb +2 -0
  56. data/app/views/slash_admin/fields/_carrierwave.html.erb +15 -0
  57. data/app/views/slash_admin/fields/_date.html.erb +2 -0
  58. data/app/views/slash_admin/fields/_decimal.html.erb +2 -0
  59. data/app/views/slash_admin/fields/_form_group.html.erb +12 -0
  60. data/app/views/slash_admin/fields/_has_many.html.erb +12 -0
  61. data/app/views/slash_admin/fields/_has_many_row.html.erb +18 -0
  62. data/app/views/slash_admin/fields/_has_one.html.erb +24 -0
  63. data/app/views/slash_admin/fields/_integer.html.erb +2 -0
  64. data/app/views/slash_admin/fields/_json.html.erb +14 -0
  65. data/app/views/slash_admin/fields/_nested_has_many.html.erb +14 -0
  66. data/app/views/slash_admin/fields/_number.html.erb +2 -0
  67. data/app/views/slash_admin/fields/_string.html.erb +2 -0
  68. data/app/views/slash_admin/fields/_text.html.erb +2 -0
  69. data/app/views/slash_admin/security/sessions/new.html.erb +30 -0
  70. data/app/views/slash_admin/shared/_batch_actions.html.erb +21 -0
  71. data/app/views/slash_admin/shared/_better_paginate.html.erb +30 -0
  72. data/app/views/slash_admin/shared/_breadcrumb.html.erb +30 -0
  73. data/app/views/slash_admin/shared/_debug.html.erb +24 -0
  74. data/app/views/slash_admin/shared/_errors_data_new.html.erb +12 -0
  75. data/app/views/slash_admin/shared/_header.html.erb +38 -0
  76. data/app/views/slash_admin/shared/_menu.html.erb +57 -0
  77. data/app/views/slash_admin/shared/_new_form_buttons.html.erb +9 -0
  78. data/app/views/slash_admin/shared/_sub_header.html.erb +11 -0
  79. data/config/initializers/validators.rb +13 -0
  80. data/config/locales/slash_admin.en.yml +67 -0
  81. data/config/locales/slash_admin.fr.yml +72 -0
  82. data/config/routes.rb +16 -0
  83. data/db/migrate/20170512104248_create_slash_admin_admins.rb +19 -0
  84. data/lib/batch_translation.rb +19 -0
  85. data/lib/generators/slash_admin/controllers/controllers_generator.rb +16 -0
  86. data/lib/generators/slash_admin/controllers/templates/controllers.erb +9 -0
  87. data/lib/generators/slash_admin/install/install_generator.rb +13 -0
  88. data/lib/generators/slash_admin/install/templates/install.erb +14 -0
  89. data/lib/generators/slash_admin/override_admin/override_admin_generator.rb +13 -0
  90. data/lib/generators/slash_admin/override_admin/templates/admin.erb +46 -0
  91. data/lib/generators/slash_admin/override_session/override_session_generator.rb +13 -0
  92. data/lib/generators/slash_admin/override_session/templates/session.erb +27 -0
  93. data/lib/generators/slash_admin/permissions/permissions_generator.rb +13 -0
  94. data/lib/generators/slash_admin/permissions/templates/permissions.erb +11 -0
  95. data/lib/slash_admin.rb +29 -0
  96. data/lib/slash_admin/engine.rb +8 -0
  97. data/lib/slash_admin/version.rb +3 -0
  98. data/lib/tasks/slash_admin_tasks.rake +4 -0
  99. data/vendor/assets/javascripts/bootstrap-material-datetimepicker.js +1295 -0
  100. data/vendor/assets/javascripts/codemirror/codemirror.js +9657 -0
  101. data/vendor/assets/javascripts/codemirror/lint/json-lint.js +37 -0
  102. data/vendor/assets/javascripts/codemirror/lint/jsonlint.js +432 -0
  103. data/vendor/assets/javascripts/codemirror/lint/lint.js +252 -0
  104. data/vendor/assets/javascripts/codemirror/mode/javascript.js +865 -0
  105. data/vendor/assets/javascripts/jquery.nestable.js +910 -0
  106. data/vendor/assets/javascripts/jquery.tagsinput-revisited.min.js +5 -0
  107. data/vendor/assets/javascripts/toastr.js +6 -0
  108. data/vendor/assets/stylesheets/animate.css +1579 -0
  109. data/vendor/assets/stylesheets/bootstrap-material-datetimepicker.css +82 -0
  110. data/vendor/assets/stylesheets/codemirror/codemirror.css +346 -0
  111. data/vendor/assets/stylesheets/codemirror/lint/lint.css +73 -0
  112. data/vendor/assets/stylesheets/codemirror/theme/relax-seti.css +41 -0
  113. data/vendor/assets/stylesheets/jquery.nestable.css +121 -0
  114. data/vendor/assets/stylesheets/jquery.tagsinput-revisited.min.css +1 -0
  115. data/vendor/assets/stylesheets/sweetalert.css +935 -0
  116. data/vendor/assets/stylesheets/toastr.css +1 -0
  117. metadata +509 -0
@@ -0,0 +1,252 @@
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
+ var GUTTER_ID = "CodeMirror-lint-markers";
14
+
15
+ function showTooltip(e, content) {
16
+ var tt = document.createElement("div");
17
+ tt.className = "CodeMirror-lint-tooltip";
18
+ tt.appendChild(content.cloneNode(true));
19
+ document.body.appendChild(tt);
20
+
21
+ function position(e) {
22
+ if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
23
+ tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
24
+ tt.style.left = (e.clientX + 5) + "px";
25
+ }
26
+ CodeMirror.on(document, "mousemove", position);
27
+ position(e);
28
+ if (tt.style.opacity != null) tt.style.opacity = 1;
29
+ return tt;
30
+ }
31
+ function rm(elt) {
32
+ if (elt.parentNode) elt.parentNode.removeChild(elt);
33
+ }
34
+ function hideTooltip(tt) {
35
+ if (!tt.parentNode) return;
36
+ if (tt.style.opacity == null) rm(tt);
37
+ tt.style.opacity = 0;
38
+ setTimeout(function() { rm(tt); }, 600);
39
+ }
40
+
41
+ function showTooltipFor(e, content, node) {
42
+ var tooltip = showTooltip(e, content);
43
+ function hide() {
44
+ CodeMirror.off(node, "mouseout", hide);
45
+ if (tooltip) { hideTooltip(tooltip); tooltip = null; }
46
+ }
47
+ var poll = setInterval(function() {
48
+ if (tooltip) for (var n = node;; n = n.parentNode) {
49
+ if (n && n.nodeType == 11) n = n.host;
50
+ if (n == document.body) return;
51
+ if (!n) { hide(); break; }
52
+ }
53
+ if (!tooltip) return clearInterval(poll);
54
+ }, 400);
55
+ CodeMirror.on(node, "mouseout", hide);
56
+ }
57
+
58
+ function LintState(cm, options, hasGutter) {
59
+ this.marked = [];
60
+ this.options = options;
61
+ this.timeout = null;
62
+ this.hasGutter = hasGutter;
63
+ this.onMouseOver = function(e) { onMouseOver(cm, e); };
64
+ this.waitingFor = 0
65
+ }
66
+
67
+ function parseOptions(_cm, options) {
68
+ if (options instanceof Function) return {getAnnotations: options};
69
+ if (!options || options === true) options = {};
70
+ return options;
71
+ }
72
+
73
+ function clearMarks(cm) {
74
+ var state = cm.state.lint;
75
+ if (state.hasGutter) cm.clearGutter(GUTTER_ID);
76
+ for (var i = 0; i < state.marked.length; ++i)
77
+ state.marked[i].clear();
78
+ state.marked.length = 0;
79
+ }
80
+
81
+ function makeMarker(labels, severity, multiple, tooltips) {
82
+ var marker = document.createElement("div"), inner = marker;
83
+ marker.className = "CodeMirror-lint-marker-" + severity;
84
+ if (multiple) {
85
+ inner = marker.appendChild(document.createElement("div"));
86
+ inner.className = "CodeMirror-lint-marker-multiple";
87
+ }
88
+
89
+ if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) {
90
+ showTooltipFor(e, labels, inner);
91
+ });
92
+
93
+ return marker;
94
+ }
95
+
96
+ function getMaxSeverity(a, b) {
97
+ if (a == "error") return a;
98
+ else return b;
99
+ }
100
+
101
+ function groupByLine(annotations) {
102
+ var lines = [];
103
+ for (var i = 0; i < annotations.length; ++i) {
104
+ var ann = annotations[i], line = ann.from.line;
105
+ (lines[line] || (lines[line] = [])).push(ann);
106
+ }
107
+ return lines;
108
+ }
109
+
110
+ function annotationTooltip(ann) {
111
+ var severity = ann.severity;
112
+ if (!severity) severity = "error";
113
+ var tip = document.createElement("div");
114
+ tip.className = "CodeMirror-lint-message-" + severity;
115
+ if (typeof ann.messageHTML != 'undefined') {
116
+ tip.innerHTML = ann.messageHTML;
117
+ } else {
118
+ tip.appendChild(document.createTextNode(ann.message));
119
+ }
120
+ return tip;
121
+ }
122
+
123
+ function lintAsync(cm, getAnnotations, passOptions) {
124
+ var state = cm.state.lint
125
+ var id = ++state.waitingFor
126
+ function abort() {
127
+ id = -1
128
+ cm.off("change", abort)
129
+ }
130
+ cm.on("change", abort)
131
+ getAnnotations(cm.getValue(), function(annotations, arg2) {
132
+ cm.off("change", abort)
133
+ if (state.waitingFor != id) return
134
+ if (arg2 && annotations instanceof CodeMirror) annotations = arg2
135
+ cm.operation(function() {updateLinting(cm, annotations)})
136
+ }, passOptions, cm);
137
+ }
138
+
139
+ function startLinting(cm) {
140
+ var state = cm.state.lint, options = state.options;
141
+ /*
142
+ * Passing rules in `options` property prevents JSHint (and other linters) from complaining
143
+ * about unrecognized rules like `onUpdateLinting`, `delay`, `lintOnChange`, etc.
144
+ */
145
+ var passOptions = options.options || options;
146
+ var getAnnotations = options.getAnnotations || cm.getHelper(CodeMirror.Pos(0, 0), "lint");
147
+ if (!getAnnotations) return;
148
+ if (options.async || getAnnotations.async) {
149
+ lintAsync(cm, getAnnotations, passOptions)
150
+ } else {
151
+ var annotations = getAnnotations(cm.getValue(), passOptions, cm);
152
+ if (!annotations) return;
153
+ if (annotations.then) annotations.then(function(issues) {
154
+ cm.operation(function() {updateLinting(cm, issues)})
155
+ });
156
+ else cm.operation(function() {updateLinting(cm, annotations)})
157
+ }
158
+ }
159
+
160
+ function updateLinting(cm, annotationsNotSorted) {
161
+ clearMarks(cm);
162
+ var state = cm.state.lint, options = state.options;
163
+
164
+ var annotations = groupByLine(annotationsNotSorted);
165
+
166
+ for (var line = 0; line < annotations.length; ++line) {
167
+ var anns = annotations[line];
168
+ if (!anns) continue;
169
+
170
+ var maxSeverity = null;
171
+ var tipLabel = state.hasGutter && document.createDocumentFragment();
172
+
173
+ for (var i = 0; i < anns.length; ++i) {
174
+ var ann = anns[i];
175
+ var severity = ann.severity;
176
+ if (!severity) severity = "error";
177
+ maxSeverity = getMaxSeverity(maxSeverity, severity);
178
+
179
+ if (options.formatAnnotation) ann = options.formatAnnotation(ann);
180
+ if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
181
+
182
+ if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
183
+ className: "CodeMirror-lint-mark-" + severity,
184
+ __annotation: ann
185
+ }));
186
+ }
187
+
188
+ if (state.hasGutter)
189
+ cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1,
190
+ state.options.tooltips));
191
+ }
192
+ if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
193
+ }
194
+
195
+ function onChange(cm) {
196
+ var state = cm.state.lint;
197
+ if (!state) return;
198
+ clearTimeout(state.timeout);
199
+ state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500);
200
+ }
201
+
202
+ function popupTooltips(annotations, e) {
203
+ var target = e.target || e.srcElement;
204
+ var tooltip = document.createDocumentFragment();
205
+ for (var i = 0; i < annotations.length; i++) {
206
+ var ann = annotations[i];
207
+ tooltip.appendChild(annotationTooltip(ann));
208
+ }
209
+ showTooltipFor(e, tooltip, target);
210
+ }
211
+
212
+ function onMouseOver(cm, e) {
213
+ var target = e.target || e.srcElement;
214
+ if (!/\bCodeMirror-lint-mark-/.test(target.className)) return;
215
+ var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2;
216
+ var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client"));
217
+
218
+ var annotations = [];
219
+ for (var i = 0; i < spans.length; ++i) {
220
+ var ann = spans[i].__annotation;
221
+ if (ann) annotations.push(ann);
222
+ }
223
+ if (annotations.length) popupTooltips(annotations, e);
224
+ }
225
+
226
+ CodeMirror.defineOption("lint", false, function(cm, val, old) {
227
+ if (old && old != CodeMirror.Init) {
228
+ clearMarks(cm);
229
+ if (cm.state.lint.options.lintOnChange !== false)
230
+ cm.off("change", onChange);
231
+ CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver);
232
+ clearTimeout(cm.state.lint.timeout);
233
+ delete cm.state.lint;
234
+ }
235
+
236
+ if (val) {
237
+ var gutters = cm.getOption("gutters"), hasLintGutter = false;
238
+ for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true;
239
+ var state = cm.state.lint = new LintState(cm, parseOptions(cm, val), hasLintGutter);
240
+ if (state.options.lintOnChange !== false)
241
+ cm.on("change", onChange);
242
+ if (state.options.tooltips != false && state.options.tooltips != "gutter")
243
+ CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
244
+
245
+ startLinting(cm);
246
+ }
247
+ });
248
+
249
+ CodeMirror.defineExtension("performLint", function() {
250
+ if (this.state.lint) startLinting(this);
251
+ });
252
+ });
@@ -0,0 +1,865 @@
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
+ CodeMirror.defineMode("javascript", function(config, parserConfig) {
15
+ var indentUnit = config.indentUnit;
16
+ var statementIndent = parserConfig.statementIndent;
17
+ var jsonldMode = parserConfig.jsonld;
18
+ var jsonMode = parserConfig.json || jsonldMode;
19
+ var isTS = parserConfig.typescript;
20
+ var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
21
+
22
+ // Tokenizer
23
+
24
+ var keywords = function(){
25
+ function kw(type) {return {type: type, style: "keyword"};}
26
+ var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"), D = kw("keyword d");
27
+ var operator = kw("operator"), atom = {type: "atom", style: "atom"};
28
+
29
+ return {
30
+ "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
31
+ "return": D, "break": D, "continue": D, "new": kw("new"), "delete": C, "void": C, "throw": C,
32
+ "debugger": kw("debugger"), "var": kw("var"), "const": kw("var"), "let": kw("var"),
33
+ "function": kw("function"), "catch": kw("catch"),
34
+ "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
35
+ "in": operator, "typeof": operator, "instanceof": operator,
36
+ "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
37
+ "this": kw("this"), "class": kw("class"), "super": kw("atom"),
38
+ "yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
39
+ "await": C
40
+ };
41
+ }();
42
+
43
+ var isOperatorChar = /[+\-*&%=<>!?|~^@]/;
44
+ var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
45
+
46
+ function readRegexp(stream) {
47
+ var escaped = false, next, inSet = false;
48
+ while ((next = stream.next()) != null) {
49
+ if (!escaped) {
50
+ if (next == "/" && !inSet) return;
51
+ if (next == "[") inSet = true;
52
+ else if (inSet && next == "]") inSet = false;
53
+ }
54
+ escaped = !escaped && next == "\\";
55
+ }
56
+ }
57
+
58
+ // Used as scratch variables to communicate multiple values without
59
+ // consing up tons of objects.
60
+ var type, content;
61
+ function ret(tp, style, cont) {
62
+ type = tp; content = cont;
63
+ return style;
64
+ }
65
+ function tokenBase(stream, state) {
66
+ var ch = stream.next();
67
+ if (ch == '"' || ch == "'") {
68
+ state.tokenize = tokenString(ch);
69
+ return state.tokenize(stream, state);
70
+ } else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
71
+ return ret("number", "number");
72
+ } else if (ch == "." && stream.match("..")) {
73
+ return ret("spread", "meta");
74
+ } else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
75
+ return ret(ch);
76
+ } else if (ch == "=" && stream.eat(">")) {
77
+ return ret("=>", "operator");
78
+ } else if (ch == "0" && stream.eat(/x/i)) {
79
+ stream.eatWhile(/[\da-f]/i);
80
+ return ret("number", "number");
81
+ } else if (ch == "0" && stream.eat(/o/i)) {
82
+ stream.eatWhile(/[0-7]/i);
83
+ return ret("number", "number");
84
+ } else if (ch == "0" && stream.eat(/b/i)) {
85
+ stream.eatWhile(/[01]/i);
86
+ return ret("number", "number");
87
+ } else if (/\d/.test(ch)) {
88
+ stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
89
+ return ret("number", "number");
90
+ } else if (ch == "/") {
91
+ if (stream.eat("*")) {
92
+ state.tokenize = tokenComment;
93
+ return tokenComment(stream, state);
94
+ } else if (stream.eat("/")) {
95
+ stream.skipToEnd();
96
+ return ret("comment", "comment");
97
+ } else if (expressionAllowed(stream, state, 1)) {
98
+ readRegexp(stream);
99
+ stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
100
+ return ret("regexp", "string-2");
101
+ } else {
102
+ stream.eat("=");
103
+ return ret("operator", "operator", stream.current());
104
+ }
105
+ } else if (ch == "`") {
106
+ state.tokenize = tokenQuasi;
107
+ return tokenQuasi(stream, state);
108
+ } else if (ch == "#") {
109
+ stream.skipToEnd();
110
+ return ret("error", "error");
111
+ } else if (isOperatorChar.test(ch)) {
112
+ if (ch != ">" || !state.lexical || state.lexical.type != ">") {
113
+ if (stream.eat("=")) {
114
+ if (ch == "!" || ch == "=") stream.eat("=")
115
+ } else if (/[<>*+\-]/.test(ch)) {
116
+ stream.eat(ch)
117
+ if (ch == ">") stream.eat(ch)
118
+ }
119
+ }
120
+ return ret("operator", "operator", stream.current());
121
+ } else if (wordRE.test(ch)) {
122
+ stream.eatWhile(wordRE);
123
+ var word = stream.current()
124
+ if (state.lastType != ".") {
125
+ if (keywords.propertyIsEnumerable(word)) {
126
+ var kw = keywords[word]
127
+ return ret(kw.type, kw.style, word)
128
+ }
129
+ if (word == "async" && stream.match(/^(\s|\/\*.*?\*\/)*[\(\w]/, false))
130
+ return ret("async", "keyword", word)
131
+ }
132
+ return ret("variable", "variable", word)
133
+ }
134
+ }
135
+
136
+ function tokenString(quote) {
137
+ return function(stream, state) {
138
+ var escaped = false, next;
139
+ if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
140
+ state.tokenize = tokenBase;
141
+ return ret("jsonld-keyword", "meta");
142
+ }
143
+ while ((next = stream.next()) != null) {
144
+ if (next == quote && !escaped) break;
145
+ escaped = !escaped && next == "\\";
146
+ }
147
+ if (!escaped) state.tokenize = tokenBase;
148
+ return ret("string", "string");
149
+ };
150
+ }
151
+
152
+ function tokenComment(stream, state) {
153
+ var maybeEnd = false, ch;
154
+ while (ch = stream.next()) {
155
+ if (ch == "/" && maybeEnd) {
156
+ state.tokenize = tokenBase;
157
+ break;
158
+ }
159
+ maybeEnd = (ch == "*");
160
+ }
161
+ return ret("comment", "comment");
162
+ }
163
+
164
+ function tokenQuasi(stream, state) {
165
+ var escaped = false, next;
166
+ while ((next = stream.next()) != null) {
167
+ if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
168
+ state.tokenize = tokenBase;
169
+ break;
170
+ }
171
+ escaped = !escaped && next == "\\";
172
+ }
173
+ return ret("quasi", "string-2", stream.current());
174
+ }
175
+
176
+ var brackets = "([{}])";
177
+ // This is a crude lookahead trick to try and notice that we're
178
+ // parsing the argument patterns for a fat-arrow function before we
179
+ // actually hit the arrow token. It only works if the arrow is on
180
+ // the same line as the arguments and there's no strange noise
181
+ // (comments) in between. Fallback is to only notice when we hit the
182
+ // arrow, and not declare the arguments as locals for the arrow
183
+ // body.
184
+ function findFatArrow(stream, state) {
185
+ if (state.fatArrowAt) state.fatArrowAt = null;
186
+ var arrow = stream.string.indexOf("=>", stream.start);
187
+ if (arrow < 0) return;
188
+
189
+ if (isTS) { // Try to skip TypeScript return type declarations after the arguments
190
+ var m = /:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(stream.string.slice(stream.start, arrow))
191
+ if (m) arrow = m.index
192
+ }
193
+
194
+ var depth = 0, sawSomething = false;
195
+ for (var pos = arrow - 1; pos >= 0; --pos) {
196
+ var ch = stream.string.charAt(pos);
197
+ var bracket = brackets.indexOf(ch);
198
+ if (bracket >= 0 && bracket < 3) {
199
+ if (!depth) { ++pos; break; }
200
+ if (--depth == 0) { if (ch == "(") sawSomething = true; break; }
201
+ } else if (bracket >= 3 && bracket < 6) {
202
+ ++depth;
203
+ } else if (wordRE.test(ch)) {
204
+ sawSomething = true;
205
+ } else if (/["'\/]/.test(ch)) {
206
+ return;
207
+ } else if (sawSomething && !depth) {
208
+ ++pos;
209
+ break;
210
+ }
211
+ }
212
+ if (sawSomething && !depth) state.fatArrowAt = pos;
213
+ }
214
+
215
+ // Parser
216
+
217
+ var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true};
218
+
219
+ function JSLexical(indented, column, type, align, prev, info) {
220
+ this.indented = indented;
221
+ this.column = column;
222
+ this.type = type;
223
+ this.prev = prev;
224
+ this.info = info;
225
+ if (align != null) this.align = align;
226
+ }
227
+
228
+ function inScope(state, varname) {
229
+ for (var v = state.localVars; v; v = v.next)
230
+ if (v.name == varname) return true;
231
+ for (var cx = state.context; cx; cx = cx.prev) {
232
+ for (var v = cx.vars; v; v = v.next)
233
+ if (v.name == varname) return true;
234
+ }
235
+ }
236
+
237
+ function parseJS(state, style, type, content, stream) {
238
+ var cc = state.cc;
239
+ // Communicate our context to the combinators.
240
+ // (Less wasteful than consing up a hundred closures on every call.)
241
+ cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
242
+
243
+ if (!state.lexical.hasOwnProperty("align"))
244
+ state.lexical.align = true;
245
+
246
+ while(true) {
247
+ var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
248
+ if (combinator(type, content)) {
249
+ while(cc.length && cc[cc.length - 1].lex)
250
+ cc.pop()();
251
+ if (cx.marked) return cx.marked;
252
+ if (type == "variable" && inScope(state, content)) return "variable-2";
253
+ return style;
254
+ }
255
+ }
256
+ }
257
+
258
+ // Combinator utils
259
+
260
+ var cx = {state: null, column: null, marked: null, cc: null};
261
+ function pass() {
262
+ for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
263
+ }
264
+ function cont() {
265
+ pass.apply(null, arguments);
266
+ return true;
267
+ }
268
+ function register(varname) {
269
+ function inList(list) {
270
+ for (var v = list; v; v = v.next)
271
+ if (v.name == varname) return true;
272
+ return false;
273
+ }
274
+ var state = cx.state;
275
+ cx.marked = "def";
276
+ if (state.context) {
277
+ if (inList(state.localVars)) return;
278
+ state.localVars = {name: varname, next: state.localVars};
279
+ } else {
280
+ if (inList(state.globalVars)) return;
281
+ if (parserConfig.globalVars)
282
+ state.globalVars = {name: varname, next: state.globalVars};
283
+ }
284
+ }
285
+
286
+ function isModifier(name) {
287
+ return name == "public" || name == "private" || name == "protected" || name == "abstract" || name == "readonly"
288
+ }
289
+
290
+ // Combinators
291
+
292
+ var defaultVars = {name: "this", next: {name: "arguments"}};
293
+ function pushcontext() {
294
+ cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
295
+ cx.state.localVars = defaultVars;
296
+ }
297
+ function popcontext() {
298
+ cx.state.localVars = cx.state.context.vars;
299
+ cx.state.context = cx.state.context.prev;
300
+ }
301
+ function pushlex(type, info) {
302
+ var result = function() {
303
+ var state = cx.state, indent = state.indented;
304
+ if (state.lexical.type == "stat") indent = state.lexical.indented;
305
+ else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
306
+ indent = outer.indented;
307
+ state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
308
+ };
309
+ result.lex = true;
310
+ return result;
311
+ }
312
+ function poplex() {
313
+ var state = cx.state;
314
+ if (state.lexical.prev) {
315
+ if (state.lexical.type == ")")
316
+ state.indented = state.lexical.indented;
317
+ state.lexical = state.lexical.prev;
318
+ }
319
+ }
320
+ poplex.lex = true;
321
+
322
+ function expect(wanted) {
323
+ function exp(type) {
324
+ if (type == wanted) return cont();
325
+ else if (wanted == ";") return pass();
326
+ else return cont(exp);
327
+ };
328
+ return exp;
329
+ }
330
+
331
+ function statement(type, value) {
332
+ if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
333
+ if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex);
334
+ if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
335
+ if (type == "keyword d") return cx.stream.match(/^\s*$/, false) ? cont() : cont(pushlex("stat"), maybeexpression, expect(";"), poplex);
336
+ if (type == "debugger") return cont(expect(";"));
337
+ if (type == "{") return cont(pushlex("}"), block, poplex);
338
+ if (type == ";") return cont();
339
+ if (type == "if") {
340
+ if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
341
+ cx.state.cc.pop()();
342
+ return cont(pushlex("form"), parenExpr, statement, poplex, maybeelse);
343
+ }
344
+ if (type == "function") return cont(functiondef);
345
+ if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
346
+ if (type == "class" || (isTS && value == "interface")) { cx.marked = "keyword"; return cont(pushlex("form"), className, poplex); }
347
+ if (type == "variable") {
348
+ if (isTS && value == "declare") {
349
+ cx.marked = "keyword"
350
+ return cont(statement)
351
+ } else if (isTS && (value == "module" || value == "enum" || value == "type") && cx.stream.match(/^\s*\w/, false)) {
352
+ cx.marked = "keyword"
353
+ if (value == "enum") return cont(enumdef);
354
+ else if (value == "type") return cont(typeexpr, expect("operator"), typeexpr, expect(";"));
355
+ else return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex)
356
+ } else if (isTS && value == "namespace") {
357
+ cx.marked = "keyword"
358
+ return cont(pushlex("form"), expression, block, poplex)
359
+ } else {
360
+ return cont(pushlex("stat"), maybelabel);
361
+ }
362
+ }
363
+ if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"),
364
+ block, poplex, poplex);
365
+ if (type == "case") return cont(expression, expect(":"));
366
+ if (type == "default") return cont(expect(":"));
367
+ if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
368
+ statement, poplex, popcontext);
369
+ if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
370
+ if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
371
+ if (type == "async") return cont(statement)
372
+ if (value == "@") return cont(expression, statement)
373
+ return pass(pushlex("stat"), expression, expect(";"), poplex);
374
+ }
375
+ function expression(type, value) {
376
+ return expressionInner(type, value, false);
377
+ }
378
+ function expressionNoComma(type, value) {
379
+ return expressionInner(type, value, true);
380
+ }
381
+ function parenExpr(type) {
382
+ if (type != "(") return pass()
383
+ return cont(pushlex(")"), expression, expect(")"), poplex)
384
+ }
385
+ function expressionInner(type, value, noComma) {
386
+ if (cx.state.fatArrowAt == cx.stream.start) {
387
+ var body = noComma ? arrowBodyNoComma : arrowBody;
388
+ if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, expect("=>"), body, popcontext);
389
+ else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
390
+ }
391
+
392
+ var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
393
+ if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
394
+ if (type == "function") return cont(functiondef, maybeop);
395
+ if (type == "class" || (isTS && value == "interface")) { cx.marked = "keyword"; return cont(pushlex("form"), classExpression, poplex); }
396
+ if (type == "keyword c" || type == "async") return cont(noComma ? expressionNoComma : expression);
397
+ if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
398
+ if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
399
+ if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
400
+ if (type == "{") return contCommasep(objprop, "}", null, maybeop);
401
+ if (type == "quasi") return pass(quasi, maybeop);
402
+ if (type == "new") return cont(maybeTarget(noComma));
403
+ return cont();
404
+ }
405
+ function maybeexpression(type) {
406
+ if (type.match(/[;\}\)\],]/)) return pass();
407
+ return pass(expression);
408
+ }
409
+
410
+ function maybeoperatorComma(type, value) {
411
+ if (type == ",") return cont(expression);
412
+ return maybeoperatorNoComma(type, value, false);
413
+ }
414
+ function maybeoperatorNoComma(type, value, noComma) {
415
+ var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
416
+ var expr = noComma == false ? expression : expressionNoComma;
417
+ if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
418
+ if (type == "operator") {
419
+ if (/\+\+|--/.test(value) || isTS && value == "!") return cont(me);
420
+ if (isTS && value == "<" && cx.stream.match(/^([^>]|<.*?>)*>\s*\(/, false))
421
+ return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, me);
422
+ if (value == "?") return cont(expression, expect(":"), expr);
423
+ return cont(expr);
424
+ }
425
+ if (type == "quasi") { return pass(quasi, me); }
426
+ if (type == ";") return;
427
+ if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
428
+ if (type == ".") return cont(property, me);
429
+ if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
430
+ if (isTS && value == "as") { cx.marked = "keyword"; return cont(typeexpr, me) }
431
+ if (type == "regexp") {
432
+ cx.state.lastType = cx.marked = "operator"
433
+ cx.stream.backUp(cx.stream.pos - cx.stream.start - 1)
434
+ return cont(expr)
435
+ }
436
+ }
437
+ function quasi(type, value) {
438
+ if (type != "quasi") return pass();
439
+ if (value.slice(value.length - 2) != "${") return cont(quasi);
440
+ return cont(expression, continueQuasi);
441
+ }
442
+ function continueQuasi(type) {
443
+ if (type == "}") {
444
+ cx.marked = "string-2";
445
+ cx.state.tokenize = tokenQuasi;
446
+ return cont(quasi);
447
+ }
448
+ }
449
+ function arrowBody(type) {
450
+ findFatArrow(cx.stream, cx.state);
451
+ return pass(type == "{" ? statement : expression);
452
+ }
453
+ function arrowBodyNoComma(type) {
454
+ findFatArrow(cx.stream, cx.state);
455
+ return pass(type == "{" ? statement : expressionNoComma);
456
+ }
457
+ function maybeTarget(noComma) {
458
+ return function(type) {
459
+ if (type == ".") return cont(noComma ? targetNoComma : target);
460
+ else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma)
461
+ else return pass(noComma ? expressionNoComma : expression);
462
+ };
463
+ }
464
+ function target(_, value) {
465
+ if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); }
466
+ }
467
+ function targetNoComma(_, value) {
468
+ if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); }
469
+ }
470
+ function maybelabel(type) {
471
+ if (type == ":") return cont(poplex, statement);
472
+ return pass(maybeoperatorComma, expect(";"), poplex);
473
+ }
474
+ function property(type) {
475
+ if (type == "variable") {cx.marked = "property"; return cont();}
476
+ }
477
+ function objprop(type, value) {
478
+ if (type == "async") {
479
+ cx.marked = "property";
480
+ return cont(objprop);
481
+ } else if (type == "variable" || cx.style == "keyword") {
482
+ cx.marked = "property";
483
+ if (value == "get" || value == "set") return cont(getterSetter);
484
+ var m // Work around fat-arrow-detection complication for detecting typescript typed arrow params
485
+ if (isTS && cx.state.fatArrowAt == cx.stream.start && (m = cx.stream.match(/^\s*:\s*/, false)))
486
+ cx.state.fatArrowAt = cx.stream.pos + m[0].length
487
+ return cont(afterprop);
488
+ } else if (type == "number" || type == "string") {
489
+ cx.marked = jsonldMode ? "property" : (cx.style + " property");
490
+ return cont(afterprop);
491
+ } else if (type == "jsonld-keyword") {
492
+ return cont(afterprop);
493
+ } else if (isTS && isModifier(value)) {
494
+ cx.marked = "keyword"
495
+ return cont(objprop)
496
+ } else if (type == "[") {
497
+ return cont(expression, maybetype, expect("]"), afterprop);
498
+ } else if (type == "spread") {
499
+ return cont(expressionNoComma, afterprop);
500
+ } else if (value == "*") {
501
+ cx.marked = "keyword";
502
+ return cont(objprop);
503
+ } else if (type == ":") {
504
+ return pass(afterprop)
505
+ }
506
+ }
507
+ function getterSetter(type) {
508
+ if (type != "variable") return pass(afterprop);
509
+ cx.marked = "property";
510
+ return cont(functiondef);
511
+ }
512
+ function afterprop(type) {
513
+ if (type == ":") return cont(expressionNoComma);
514
+ if (type == "(") return pass(functiondef);
515
+ }
516
+ function commasep(what, end, sep) {
517
+ function proceed(type, value) {
518
+ if (sep ? sep.indexOf(type) > -1 : type == ",") {
519
+ var lex = cx.state.lexical;
520
+ if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
521
+ return cont(function(type, value) {
522
+ if (type == end || value == end) return pass()
523
+ return pass(what)
524
+ }, proceed);
525
+ }
526
+ if (type == end || value == end) return cont();
527
+ return cont(expect(end));
528
+ }
529
+ return function(type, value) {
530
+ if (type == end || value == end) return cont();
531
+ return pass(what, proceed);
532
+ };
533
+ }
534
+ function contCommasep(what, end, info) {
535
+ for (var i = 3; i < arguments.length; i++)
536
+ cx.cc.push(arguments[i]);
537
+ return cont(pushlex(end, info), commasep(what, end), poplex);
538
+ }
539
+ function block(type) {
540
+ if (type == "}") return cont();
541
+ return pass(statement, block);
542
+ }
543
+ function maybetype(type, value) {
544
+ if (isTS) {
545
+ if (type == ":") return cont(typeexpr);
546
+ if (value == "?") return cont(maybetype);
547
+ }
548
+ }
549
+ function mayberettype(type) {
550
+ if (isTS && type == ":") {
551
+ if (cx.stream.match(/^\s*\w+\s+is\b/, false)) return cont(expression, isKW, typeexpr)
552
+ else return cont(typeexpr)
553
+ }
554
+ }
555
+ function isKW(_, value) {
556
+ if (value == "is") {
557
+ cx.marked = "keyword"
558
+ return cont()
559
+ }
560
+ }
561
+ function typeexpr(type, value) {
562
+ if (type == "variable" || value == "void") {
563
+ if (value == "keyof") {
564
+ cx.marked = "keyword"
565
+ return cont(typeexpr)
566
+ } else {
567
+ cx.marked = "type"
568
+ return cont(afterType)
569
+ }
570
+ }
571
+ if (type == "string" || type == "number" || type == "atom") return cont(afterType);
572
+ if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType)
573
+ if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
574
+ if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
575
+ }
576
+ function maybeReturnType(type) {
577
+ if (type == "=>") return cont(typeexpr)
578
+ }
579
+ function typeprop(type, value) {
580
+ if (type == "variable" || cx.style == "keyword") {
581
+ cx.marked = "property"
582
+ return cont(typeprop)
583
+ } else if (value == "?") {
584
+ return cont(typeprop)
585
+ } else if (type == ":") {
586
+ return cont(typeexpr)
587
+ } else if (type == "[") {
588
+ return cont(expression, maybetype, expect("]"), typeprop)
589
+ }
590
+ }
591
+ function typearg(type) {
592
+ if (type == "variable") return cont(typearg)
593
+ else if (type == ":") return cont(typeexpr)
594
+ }
595
+ function afterType(type, value) {
596
+ if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
597
+ if (value == "|" || type == ".") return cont(typeexpr)
598
+ if (type == "[") return cont(expect("]"), afterType)
599
+ if (value == "extends" || value == "implements") { cx.marked = "keyword"; return cont(typeexpr) }
600
+ }
601
+ function maybeTypeArgs(_, value) {
602
+ if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
603
+ }
604
+ function typeparam() {
605
+ return pass(typeexpr, maybeTypeDefault)
606
+ }
607
+ function maybeTypeDefault(_, value) {
608
+ if (value == "=") return cont(typeexpr)
609
+ }
610
+ function vardef(_, value) {
611
+ if (value == "enum") {cx.marked = "keyword"; return cont(enumdef)}
612
+ return pass(pattern, maybetype, maybeAssign, vardefCont);
613
+ }
614
+ function pattern(type, value) {
615
+ if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(pattern) }
616
+ if (type == "variable") { register(value); return cont(); }
617
+ if (type == "spread") return cont(pattern);
618
+ if (type == "[") return contCommasep(pattern, "]");
619
+ if (type == "{") return contCommasep(proppattern, "}");
620
+ }
621
+ function proppattern(type, value) {
622
+ if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
623
+ register(value);
624
+ return cont(maybeAssign);
625
+ }
626
+ if (type == "variable") cx.marked = "property";
627
+ if (type == "spread") return cont(pattern);
628
+ if (type == "}") return pass();
629
+ return cont(expect(":"), pattern, maybeAssign);
630
+ }
631
+ function maybeAssign(_type, value) {
632
+ if (value == "=") return cont(expressionNoComma);
633
+ }
634
+ function vardefCont(type) {
635
+ if (type == ",") return cont(vardef);
636
+ }
637
+ function maybeelse(type, value) {
638
+ if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
639
+ }
640
+ function forspec(type) {
641
+ if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
642
+ }
643
+ function forspec1(type) {
644
+ if (type == "var") return cont(vardef, expect(";"), forspec2);
645
+ if (type == ";") return cont(forspec2);
646
+ if (type == "variable") return cont(formaybeinof);
647
+ return pass(expression, expect(";"), forspec2);
648
+ }
649
+ function formaybeinof(_type, value) {
650
+ if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
651
+ return cont(maybeoperatorComma, forspec2);
652
+ }
653
+ function forspec2(type, value) {
654
+ if (type == ";") return cont(forspec3);
655
+ if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
656
+ return pass(expression, expect(";"), forspec3);
657
+ }
658
+ function forspec3(type) {
659
+ if (type != ")") cont(expression);
660
+ }
661
+ function functiondef(type, value) {
662
+ if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
663
+ if (type == "variable") {register(value); return cont(functiondef);}
664
+ if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, mayberettype, statement, popcontext);
665
+ if (isTS && value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, functiondef)
666
+ }
667
+ function funarg(type, value) {
668
+ if (value == "@") cont(expression, funarg)
669
+ if (type == "spread") return cont(funarg);
670
+ if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(funarg); }
671
+ return pass(pattern, maybetype, maybeAssign);
672
+ }
673
+ function classExpression(type, value) {
674
+ // Class expressions may have an optional name.
675
+ if (type == "variable") return className(type, value);
676
+ return classNameAfter(type, value);
677
+ }
678
+ function className(type, value) {
679
+ if (type == "variable") {register(value); return cont(classNameAfter);}
680
+ }
681
+ function classNameAfter(type, value) {
682
+ if (value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, classNameAfter)
683
+ if (value == "extends" || value == "implements" || (isTS && type == ",")) {
684
+ if (value == "implements") cx.marked = "keyword";
685
+ return cont(isTS ? typeexpr : expression, classNameAfter);
686
+ }
687
+ if (type == "{") return cont(pushlex("}"), classBody, poplex);
688
+ }
689
+ function classBody(type, value) {
690
+ if (type == "async" ||
691
+ (type == "variable" &&
692
+ (value == "static" || value == "get" || value == "set" || (isTS && isModifier(value))) &&
693
+ cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) {
694
+ cx.marked = "keyword";
695
+ return cont(classBody);
696
+ }
697
+ if (type == "variable" || cx.style == "keyword") {
698
+ cx.marked = "property";
699
+ return cont(isTS ? classfield : functiondef, classBody);
700
+ }
701
+ if (type == "[")
702
+ return cont(expression, maybetype, expect("]"), isTS ? classfield : functiondef, classBody)
703
+ if (value == "*") {
704
+ cx.marked = "keyword";
705
+ return cont(classBody);
706
+ }
707
+ if (type == ";") return cont(classBody);
708
+ if (type == "}") return cont();
709
+ if (value == "@") return cont(expression, classBody)
710
+ }
711
+ function classfield(type, value) {
712
+ if (value == "?") return cont(classfield)
713
+ if (type == ":") return cont(typeexpr, maybeAssign)
714
+ if (value == "=") return cont(expressionNoComma)
715
+ return pass(functiondef)
716
+ }
717
+ function afterExport(type, value) {
718
+ if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
719
+ if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
720
+ if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(";"));
721
+ return pass(statement);
722
+ }
723
+ function exportField(type, value) {
724
+ if (value == "as") { cx.marked = "keyword"; return cont(expect("variable")); }
725
+ if (type == "variable") return pass(expressionNoComma, exportField);
726
+ }
727
+ function afterImport(type) {
728
+ if (type == "string") return cont();
729
+ return pass(importSpec, maybeMoreImports, maybeFrom);
730
+ }
731
+ function importSpec(type, value) {
732
+ if (type == "{") return contCommasep(importSpec, "}");
733
+ if (type == "variable") register(value);
734
+ if (value == "*") cx.marked = "keyword";
735
+ return cont(maybeAs);
736
+ }
737
+ function maybeMoreImports(type) {
738
+ if (type == ",") return cont(importSpec, maybeMoreImports)
739
+ }
740
+ function maybeAs(_type, value) {
741
+ if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
742
+ }
743
+ function maybeFrom(_type, value) {
744
+ if (value == "from") { cx.marked = "keyword"; return cont(expression); }
745
+ }
746
+ function arrayLiteral(type) {
747
+ if (type == "]") return cont();
748
+ return pass(commasep(expressionNoComma, "]"));
749
+ }
750
+ function enumdef() {
751
+ return pass(pushlex("form"), pattern, expect("{"), pushlex("}"), commasep(enummember, "}"), poplex, poplex)
752
+ }
753
+ function enummember() {
754
+ return pass(pattern, maybeAssign);
755
+ }
756
+
757
+ function isContinuedStatement(state, textAfter) {
758
+ return state.lastType == "operator" || state.lastType == "," ||
759
+ isOperatorChar.test(textAfter.charAt(0)) ||
760
+ /[,.]/.test(textAfter.charAt(0));
761
+ }
762
+
763
+ function expressionAllowed(stream, state, backUp) {
764
+ return state.tokenize == tokenBase &&
765
+ /^(?:operator|sof|keyword [bcd]|case|new|export|default|spread|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
766
+ (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
767
+ }
768
+
769
+ // Interface
770
+
771
+ return {
772
+ startState: function(basecolumn) {
773
+ var state = {
774
+ tokenize: tokenBase,
775
+ lastType: "sof",
776
+ cc: [],
777
+ lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
778
+ localVars: parserConfig.localVars,
779
+ context: parserConfig.localVars && {vars: parserConfig.localVars},
780
+ indented: basecolumn || 0
781
+ };
782
+ if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
783
+ state.globalVars = parserConfig.globalVars;
784
+ return state;
785
+ },
786
+
787
+ token: function(stream, state) {
788
+ if (stream.sol()) {
789
+ if (!state.lexical.hasOwnProperty("align"))
790
+ state.lexical.align = false;
791
+ state.indented = stream.indentation();
792
+ findFatArrow(stream, state);
793
+ }
794
+ if (state.tokenize != tokenComment && stream.eatSpace()) return null;
795
+ var style = state.tokenize(stream, state);
796
+ if (type == "comment") return style;
797
+ state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
798
+ return parseJS(state, style, type, content, stream);
799
+ },
800
+
801
+ indent: function(state, textAfter) {
802
+ if (state.tokenize == tokenComment) return CodeMirror.Pass;
803
+ if (state.tokenize != tokenBase) return 0;
804
+ var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical, top
805
+ // Kludge to prevent 'maybelse' from blocking lexical scope pops
806
+ if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
807
+ var c = state.cc[i];
808
+ if (c == poplex) lexical = lexical.prev;
809
+ else if (c != maybeelse) break;
810
+ }
811
+ while ((lexical.type == "stat" || lexical.type == "form") &&
812
+ (firstChar == "}" || ((top = state.cc[state.cc.length - 1]) &&
813
+ (top == maybeoperatorComma || top == maybeoperatorNoComma) &&
814
+ !/^[,\.=+\-*:?[\(]/.test(textAfter))))
815
+ lexical = lexical.prev;
816
+ if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
817
+ lexical = lexical.prev;
818
+ var type = lexical.type, closing = firstChar == type;
819
+
820
+ if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0);
821
+ else if (type == "form" && firstChar == "{") return lexical.indented;
822
+ else if (type == "form") return lexical.indented + indentUnit;
823
+ else if (type == "stat")
824
+ return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
825
+ else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
826
+ return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
827
+ else if (lexical.align) return lexical.column + (closing ? 0 : 1);
828
+ else return lexical.indented + (closing ? 0 : indentUnit);
829
+ },
830
+
831
+ electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
832
+ blockCommentStart: jsonMode ? null : "/*",
833
+ blockCommentEnd: jsonMode ? null : "*/",
834
+ blockCommentContinue: jsonMode ? null : " * ",
835
+ lineComment: jsonMode ? null : "//",
836
+ fold: "brace",
837
+ closeBrackets: "()[]{}''\"\"``",
838
+
839
+ helperType: jsonMode ? "json" : "javascript",
840
+ jsonldMode: jsonldMode,
841
+ jsonMode: jsonMode,
842
+
843
+ expressionAllowed: expressionAllowed,
844
+
845
+ skipExpression: function(state) {
846
+ var top = state.cc[state.cc.length - 1]
847
+ if (top == expression || top == expressionNoComma) state.cc.pop()
848
+ }
849
+ };
850
+ });
851
+
852
+ CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
853
+
854
+ CodeMirror.defineMIME("text/javascript", "javascript");
855
+ CodeMirror.defineMIME("text/ecmascript", "javascript");
856
+ CodeMirror.defineMIME("application/javascript", "javascript");
857
+ CodeMirror.defineMIME("application/x-javascript", "javascript");
858
+ CodeMirror.defineMIME("application/ecmascript", "javascript");
859
+ CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
860
+ CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
861
+ CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true});
862
+ CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
863
+ CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
864
+
865
+ });