scrivito_codemirror_editor 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +21 -165
  3. data/README.md +2 -2
  4. data/app/assets/javascripts/scrivito_codemirror_editor/codemirror_editor.js +29 -0
  5. data/lib/scrivito_codemirror_editor.rb +0 -2
  6. data/vendor/assets/javascripts/codemirror/addons/comment/comment.js +203 -0
  7. data/vendor/assets/javascripts/codemirror/addons/comment/continuecomment.js +85 -0
  8. data/vendor/assets/javascripts/codemirror/addons/dialog/dialog.js +157 -0
  9. data/vendor/assets/javascripts/codemirror/addons/display/autorefresh.js +47 -0
  10. data/vendor/assets/javascripts/codemirror/addons/display/fullscreen.js +41 -0
  11. data/vendor/assets/javascripts/codemirror/addons/display/panel.js +112 -0
  12. data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +62 -0
  13. data/vendor/assets/javascripts/codemirror/addons/display/rulers.js +51 -0
  14. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +195 -0
  15. data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +169 -0
  16. data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +51 -0
  17. data/vendor/assets/javascripts/codemirror/addons/edit/matchbrackets.js +120 -0
  18. data/vendor/assets/javascripts/codemirror/addons/edit/matchtags.js +66 -0
  19. data/vendor/assets/javascripts/codemirror/addons/edit/trailingspace.js +27 -0
  20. data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +105 -0
  21. data/vendor/assets/javascripts/codemirror/addons/fold/comment-fold.js +59 -0
  22. data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +150 -0
  23. data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +146 -0
  24. data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +44 -0
  25. data/vendor/assets/javascripts/codemirror/addons/fold/markdown-fold.js +49 -0
  26. data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +182 -0
  27. data/vendor/assets/javascripts/codemirror/addons/hint/anyword-hint.js +41 -0
  28. data/vendor/assets/javascripts/codemirror/addons/hint/css-hint.js +60 -0
  29. data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +348 -0
  30. data/vendor/assets/javascripts/codemirror/addons/hint/javascript-hint.js +146 -0
  31. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +437 -0
  32. data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +271 -0
  33. data/vendor/assets/javascripts/codemirror/addons/hint/xml-hint.js +110 -0
  34. data/vendor/assets/javascripts/codemirror/addons/lint/coffeescript-lint.js +41 -0
  35. data/vendor/assets/javascripts/codemirror/addons/lint/css-lint.js +35 -0
  36. data/vendor/assets/javascripts/codemirror/addons/lint/html-lint.js +46 -0
  37. data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +136 -0
  38. data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +31 -0
  39. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +239 -0
  40. data/vendor/assets/javascripts/codemirror/addons/lint/yaml-lint.js +28 -0
  41. data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +773 -0
  42. data/vendor/assets/javascripts/codemirror/addons/mode/loadmode.js +64 -0
  43. data/vendor/assets/javascripts/codemirror/addons/mode/multiplex.js +123 -0
  44. data/vendor/assets/javascripts/codemirror/addons/mode/overlay.js +85 -0
  45. data/vendor/assets/javascripts/codemirror/addons/mode/simple.js +213 -0
  46. data/vendor/assets/javascripts/codemirror/addons/runmode/colorize.js +40 -0
  47. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode-standalone.js +157 -0
  48. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.js +72 -0
  49. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +179 -0
  50. data/vendor/assets/javascripts/codemirror/addons/scroll/annotatescrollbar.js +118 -0
  51. data/vendor/assets/javascripts/codemirror/addons/scroll/scrollpastend.js +48 -0
  52. data/vendor/assets/javascripts/codemirror/addons/scroll/simplescrollbars.js +152 -0
  53. data/vendor/assets/javascripts/codemirror/addons/search/jump-to-line.js +49 -0
  54. data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +146 -0
  55. data/vendor/assets/javascripts/codemirror/addons/search/matchesonscrollbar.js +97 -0
  56. data/vendor/assets/javascripts/codemirror/addons/search/search.js +249 -0
  57. data/vendor/assets/javascripts/codemirror/addons/search/searchcursor.js +189 -0
  58. data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +74 -0
  59. data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +118 -0
  60. data/vendor/assets/javascripts/codemirror/addons/selection/selection-pointer.js +98 -0
  61. data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +701 -0
  62. data/vendor/assets/javascripts/codemirror/addons/tern/worker.js +44 -0
  63. data/vendor/assets/javascripts/codemirror/addons/wrap/hardwrap.js +144 -0
  64. data/vendor/assets/javascripts/codemirror/keymaps/emacs.js +412 -0
  65. data/vendor/assets/javascripts/codemirror/keymaps/sublime.js +580 -0
  66. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +5065 -0
  67. data/vendor/assets/javascripts/codemirror/modes/apl.js +174 -0
  68. data/vendor/assets/javascripts/codemirror/modes/asciiarmor.js +73 -0
  69. data/vendor/assets/javascripts/codemirror/modes/asn.1.js +204 -0
  70. data/vendor/assets/javascripts/codemirror/modes/asterisk.js +196 -0
  71. data/vendor/assets/javascripts/codemirror/modes/brainfuck.js +85 -0
  72. data/vendor/assets/javascripts/codemirror/modes/clike.js +786 -0
  73. data/vendor/assets/javascripts/codemirror/modes/clojure.js +306 -0
  74. data/vendor/assets/javascripts/codemirror/modes/cmake.js +97 -0
  75. data/vendor/assets/javascripts/codemirror/modes/cobol.js +255 -0
  76. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +355 -0
  77. data/vendor/assets/javascripts/codemirror/modes/commonlisp.js +123 -0
  78. data/vendor/assets/javascripts/codemirror/modes/crystal.js +391 -0
  79. data/vendor/assets/javascripts/codemirror/modes/css.js +825 -0
  80. data/vendor/assets/javascripts/codemirror/modes/cypher.js +146 -0
  81. data/vendor/assets/javascripts/codemirror/modes/d.js +218 -0
  82. data/vendor/assets/javascripts/codemirror/modes/dart.js +157 -0
  83. data/vendor/assets/javascripts/codemirror/modes/diff.js +47 -0
  84. data/vendor/assets/javascripts/codemirror/modes/django.js +356 -0
  85. data/vendor/assets/javascripts/codemirror/modes/dockerfile.js +79 -0
  86. data/vendor/assets/javascripts/codemirror/modes/dtd.js +142 -0
  87. data/vendor/assets/javascripts/codemirror/modes/dylan.js +344 -0
  88. data/vendor/assets/javascripts/codemirror/modes/ebnf.js +195 -0
  89. data/vendor/assets/javascripts/codemirror/modes/ecl.js +206 -0
  90. data/vendor/assets/javascripts/codemirror/modes/eiffel.js +160 -0
  91. data/vendor/assets/javascripts/codemirror/modes/elm.js +205 -0
  92. data/vendor/assets/javascripts/codemirror/modes/erlang.js +618 -0
  93. data/vendor/assets/javascripts/codemirror/modes/factor.js +83 -0
  94. data/vendor/assets/javascripts/codemirror/modes/fcl.js +173 -0
  95. data/vendor/assets/javascripts/codemirror/modes/forth.js +180 -0
  96. data/vendor/assets/javascripts/codemirror/modes/fortran.js +188 -0
  97. data/vendor/assets/javascripts/codemirror/modes/gas.js +345 -0
  98. data/vendor/assets/javascripts/codemirror/modes/gfm.js +130 -0
  99. data/vendor/assets/javascripts/codemirror/modes/gherkin.js +178 -0
  100. data/vendor/assets/javascripts/codemirror/modes/go.js +185 -0
  101. data/vendor/assets/javascripts/codemirror/modes/groovy.js +230 -0
  102. data/vendor/assets/javascripts/codemirror/modes/haml.js +161 -0
  103. data/vendor/assets/javascripts/codemirror/modes/handlebars.js +62 -0
  104. data/vendor/assets/javascripts/codemirror/modes/haskell-literate.js +43 -0
  105. data/vendor/assets/javascripts/codemirror/modes/haskell.js +267 -0
  106. data/vendor/assets/javascripts/codemirror/modes/haxe.js +515 -0
  107. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +28 -0
  108. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +152 -0
  109. data/vendor/assets/javascripts/codemirror/modes/http.js +113 -0
  110. data/vendor/assets/javascripts/codemirror/modes/idl.js +290 -0
  111. data/vendor/assets/javascripts/codemirror/modes/jade.js +590 -0
  112. data/vendor/assets/javascripts/codemirror/modes/javascript.js +748 -0
  113. data/vendor/assets/javascripts/codemirror/modes/jinja2.js +142 -0
  114. data/vendor/assets/javascripts/codemirror/modes/jsx.js +147 -0
  115. data/vendor/assets/javascripts/codemirror/modes/julia.js +392 -0
  116. data/vendor/assets/javascripts/codemirror/modes/livescript.js +280 -0
  117. data/vendor/assets/javascripts/codemirror/modes/lua.js +159 -0
  118. data/vendor/assets/javascripts/codemirror/modes/markdown.js +797 -0
  119. data/vendor/assets/javascripts/codemirror/modes/mathematica.js +176 -0
  120. data/vendor/assets/javascripts/codemirror/modes/mbox.js +129 -0
  121. data/vendor/assets/javascripts/codemirror/modes/mirc.js +193 -0
  122. data/vendor/assets/javascripts/codemirror/modes/mllike.js +205 -0
  123. data/vendor/assets/javascripts/codemirror/modes/modelica.js +245 -0
  124. data/vendor/assets/javascripts/codemirror/modes/mscgen.js +169 -0
  125. data/vendor/assets/javascripts/codemirror/modes/mumps.js +148 -0
  126. data/vendor/assets/javascripts/codemirror/modes/nginx.js +178 -0
  127. data/vendor/assets/javascripts/codemirror/modes/nsis.js +95 -0
  128. data/vendor/assets/javascripts/codemirror/modes/ntriples.js +186 -0
  129. data/vendor/assets/javascripts/codemirror/modes/octave.js +135 -0
  130. data/vendor/assets/javascripts/codemirror/modes/oz.js +252 -0
  131. data/vendor/assets/javascripts/codemirror/modes/pascal.js +109 -0
  132. data/vendor/assets/javascripts/codemirror/modes/pegjs.js +114 -0
  133. data/vendor/assets/javascripts/codemirror/modes/perl.js +837 -0
  134. data/vendor/assets/javascripts/codemirror/modes/php.js +234 -0
  135. data/vendor/assets/javascripts/codemirror/modes/pig.js +178 -0
  136. data/vendor/assets/javascripts/codemirror/modes/powershell.js +396 -0
  137. data/vendor/assets/javascripts/codemirror/modes/properties.js +78 -0
  138. data/vendor/assets/javascripts/codemirror/modes/protobuf.js +68 -0
  139. data/vendor/assets/javascripts/codemirror/modes/puppet.js +220 -0
  140. data/vendor/assets/javascripts/codemirror/modes/python.js +340 -0
  141. data/vendor/assets/javascripts/codemirror/modes/q.js +139 -0
  142. data/vendor/assets/javascripts/codemirror/modes/r.js +164 -0
  143. data/vendor/assets/javascripts/codemirror/modes/rpm.js +109 -0
  144. data/vendor/assets/javascripts/codemirror/modes/rst.js +557 -0
  145. data/vendor/assets/javascripts/codemirror/modes/ruby.js +285 -0
  146. data/vendor/assets/javascripts/codemirror/modes/rust.js +71 -0
  147. data/vendor/assets/javascripts/codemirror/modes/sas.js +315 -0
  148. data/vendor/assets/javascripts/codemirror/modes/sass.js +414 -0
  149. data/vendor/assets/javascripts/codemirror/modes/scheme.js +249 -0
  150. data/vendor/assets/javascripts/codemirror/modes/shell.js +139 -0
  151. data/vendor/assets/javascripts/codemirror/modes/sieve.js +193 -0
  152. data/vendor/assets/javascripts/codemirror/modes/slim.js +575 -0
  153. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +168 -0
  154. data/vendor/assets/javascripts/codemirror/modes/smarty.js +225 -0
  155. data/vendor/assets/javascripts/codemirror/modes/solr.js +104 -0
  156. data/vendor/assets/javascripts/codemirror/modes/soy.js +199 -0
  157. data/vendor/assets/javascripts/codemirror/modes/sparql.js +180 -0
  158. data/vendor/assets/javascripts/codemirror/modes/spreadsheet.js +112 -0
  159. data/vendor/assets/javascripts/codemirror/modes/sql.js +413 -0
  160. data/vendor/assets/javascripts/codemirror/modes/stex.js +251 -0
  161. data/vendor/assets/javascripts/codemirror/modes/stylus.js +769 -0
  162. data/vendor/assets/javascripts/codemirror/modes/swift.js +202 -0
  163. data/vendor/assets/javascripts/codemirror/modes/tcl.js +139 -0
  164. data/vendor/assets/javascripts/codemirror/modes/textile.js +469 -0
  165. data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +308 -0
  166. data/vendor/assets/javascripts/codemirror/modes/tiki.js +312 -0
  167. data/vendor/assets/javascripts/codemirror/modes/toml.js +88 -0
  168. data/vendor/assets/javascripts/codemirror/modes/tornado.js +68 -0
  169. data/vendor/assets/javascripts/codemirror/modes/troff.js +84 -0
  170. data/vendor/assets/javascripts/codemirror/modes/ttcn-cfg.js +214 -0
  171. data/vendor/assets/javascripts/codemirror/modes/ttcn.js +283 -0
  172. data/vendor/assets/javascripts/codemirror/modes/turtle.js +162 -0
  173. data/vendor/assets/javascripts/codemirror/modes/twig.js +141 -0
  174. data/vendor/assets/javascripts/codemirror/modes/vb.js +276 -0
  175. data/vendor/assets/javascripts/codemirror/modes/vbscript.js +350 -0
  176. data/vendor/assets/javascripts/codemirror/modes/velocity.js +201 -0
  177. data/vendor/assets/javascripts/codemirror/modes/verilog.js +537 -0
  178. data/vendor/assets/javascripts/codemirror/modes/vhdl.js +189 -0
  179. data/vendor/assets/javascripts/codemirror/modes/vue.js +69 -0
  180. data/vendor/assets/javascripts/codemirror/modes/webidl.js +195 -0
  181. data/vendor/assets/javascripts/codemirror/modes/xml.js +394 -0
  182. data/vendor/assets/javascripts/codemirror/modes/xquery.js +437 -0
  183. data/vendor/assets/javascripts/codemirror/modes/yacas.js +204 -0
  184. data/vendor/assets/javascripts/codemirror/modes/yaml-frontmatter.js +68 -0
  185. data/vendor/assets/javascripts/codemirror/modes/yaml.js +117 -0
  186. data/vendor/assets/javascripts/codemirror/modes/z80.js +116 -0
  187. data/vendor/assets/javascripts/codemirror.js +8922 -0
  188. data/vendor/assets/stylesheets/codemirror/addons/dialog/dialog.css +32 -0
  189. data/vendor/assets/stylesheets/codemirror/addons/display/fullscreen.css +6 -0
  190. data/vendor/assets/stylesheets/codemirror/addons/fold/foldgutter.css +20 -0
  191. data/vendor/assets/stylesheets/codemirror/addons/hint/show-hint.css +37 -0
  192. data/vendor/assets/stylesheets/codemirror/addons/lint/lint.css +73 -0
  193. data/vendor/assets/stylesheets/codemirror/addons/merge/merge.css +113 -0
  194. data/vendor/assets/stylesheets/codemirror/addons/scroll/simplescrollbars.css +66 -0
  195. data/vendor/assets/stylesheets/codemirror/addons/search/matchesonscrollbar.css +8 -0
  196. data/vendor/assets/stylesheets/codemirror/addons/tern/tern.css +87 -0
  197. data/vendor/assets/stylesheets/codemirror/modes/tiddlywiki.css +14 -0
  198. data/vendor/assets/stylesheets/codemirror/modes/tiki.css +26 -0
  199. data/vendor/assets/stylesheets/codemirror/themes/3024-day.css +41 -0
  200. data/vendor/assets/stylesheets/codemirror/themes/3024-night.css +39 -0
  201. data/vendor/assets/stylesheets/codemirror/themes/abcdef.css +32 -0
  202. data/vendor/assets/stylesheets/codemirror/themes/ambiance-mobile.css +5 -0
  203. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +74 -0
  204. data/vendor/assets/stylesheets/codemirror/themes/base16-dark.css +38 -0
  205. data/vendor/assets/stylesheets/codemirror/themes/base16-light.css +38 -0
  206. data/vendor/assets/stylesheets/codemirror/themes/bespin.css +34 -0
  207. data/vendor/assets/stylesheets/codemirror/themes/blackboard.css +32 -0
  208. data/vendor/assets/stylesheets/codemirror/themes/cobalt.css +25 -0
  209. data/vendor/assets/stylesheets/codemirror/themes/colorforth.css +33 -0
  210. data/vendor/assets/stylesheets/codemirror/themes/dracula.css +41 -0
  211. data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +23 -0
  212. data/vendor/assets/stylesheets/codemirror/themes/elegant.css +13 -0
  213. data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +34 -0
  214. data/vendor/assets/stylesheets/codemirror/themes/hopscotch.css +34 -0
  215. data/vendor/assets/stylesheets/codemirror/themes/icecoder.css +43 -0
  216. data/vendor/assets/stylesheets/codemirror/themes/isotope.css +34 -0
  217. data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +47 -0
  218. data/vendor/assets/stylesheets/codemirror/themes/liquibyte.css +95 -0
  219. data/vendor/assets/stylesheets/codemirror/themes/material.css +53 -0
  220. data/vendor/assets/stylesheets/codemirror/themes/mbo.css +37 -0
  221. data/vendor/assets/stylesheets/codemirror/themes/mdn-like.css +46 -0
  222. data/vendor/assets/stylesheets/codemirror/themes/midnight.css +45 -0
  223. data/vendor/assets/stylesheets/codemirror/themes/monokai.css +36 -0
  224. data/vendor/assets/stylesheets/codemirror/themes/neat.css +12 -0
  225. data/vendor/assets/stylesheets/codemirror/themes/neo.css +43 -0
  226. data/vendor/assets/stylesheets/codemirror/themes/night.css +27 -0
  227. data/vendor/assets/stylesheets/codemirror/themes/paraiso-dark.css +38 -0
  228. data/vendor/assets/stylesheets/codemirror/themes/paraiso-light.css +38 -0
  229. data/vendor/assets/stylesheets/codemirror/themes/pastel-on-dark.css +53 -0
  230. data/vendor/assets/stylesheets/codemirror/themes/railscasts.css +34 -0
  231. data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +25 -0
  232. data/vendor/assets/stylesheets/codemirror/themes/seti.css +44 -0
  233. data/vendor/assets/stylesheets/codemirror/themes/solarized.css +169 -0
  234. data/vendor/assets/stylesheets/codemirror/themes/the-matrix.css +30 -0
  235. data/vendor/assets/stylesheets/codemirror/themes/tomorrow-night-bright.css +35 -0
  236. data/vendor/assets/stylesheets/codemirror/themes/tomorrow-night-eighties.css +38 -0
  237. data/vendor/assets/stylesheets/codemirror/themes/ttcn.css +64 -0
  238. data/vendor/assets/stylesheets/codemirror/themes/twilight.css +32 -0
  239. data/vendor/assets/stylesheets/codemirror/themes/vibrant-ink.css +34 -0
  240. data/vendor/assets/stylesheets/codemirror/themes/xq-dark.css +53 -0
  241. data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +43 -0
  242. data/vendor/assets/stylesheets/codemirror/themes/yeti.css +44 -0
  243. data/vendor/assets/stylesheets/codemirror/themes/zenburn.css +37 -0
  244. data/vendor/assets/stylesheets/codemirror.css +347 -0
  245. metadata +244 -49
  246. data/app/assets/javascripts/scrivito_codemirror_editor/codemirror_editor.js.coffee +0 -23
@@ -0,0 +1,748 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ // TODO actually recognize syntax of TypeScript constructs
5
+
6
+ (function(mod) {
7
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
8
+ mod(require("../../lib/codemirror"));
9
+ else if (typeof define == "function" && define.amd) // AMD
10
+ define(["../../lib/codemirror"], mod);
11
+ else // Plain browser env
12
+ mod(CodeMirror);
13
+ })(function(CodeMirror) {
14
+ "use strict";
15
+
16
+ function expressionAllowed(stream, state, backUp) {
17
+ return /^(?:operator|sof|keyword c|case|new|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
18
+ (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
19
+ }
20
+
21
+ CodeMirror.defineMode("javascript", function(config, parserConfig) {
22
+ var indentUnit = config.indentUnit;
23
+ var statementIndent = parserConfig.statementIndent;
24
+ var jsonldMode = parserConfig.jsonld;
25
+ var jsonMode = parserConfig.json || jsonldMode;
26
+ var isTS = parserConfig.typescript;
27
+ var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
28
+
29
+ // Tokenizer
30
+
31
+ var keywords = function(){
32
+ function kw(type) {return {type: type, style: "keyword"};}
33
+ var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
34
+ var operator = kw("operator"), atom = {type: "atom", style: "atom"};
35
+
36
+ var jsKeywords = {
37
+ "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
38
+ "return": C, "break": C, "continue": C, "new": kw("new"), "delete": C, "throw": C, "debugger": C,
39
+ "var": kw("var"), "const": kw("var"), "let": kw("var"),
40
+ "function": kw("function"), "catch": kw("catch"),
41
+ "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
42
+ "in": operator, "typeof": operator, "instanceof": operator,
43
+ "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
44
+ "this": kw("this"), "class": kw("class"), "super": kw("atom"),
45
+ "yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
46
+ "await": C, "async": kw("async")
47
+ };
48
+
49
+ // Extend the 'normal' keywords with the TypeScript language extensions
50
+ if (isTS) {
51
+ var type = {type: "variable", style: "variable-3"};
52
+ var tsKeywords = {
53
+ // object-like things
54
+ "interface": kw("class"),
55
+ "implements": C,
56
+ "namespace": C,
57
+ "module": kw("module"),
58
+ "enum": kw("module"),
59
+
60
+ // scope modifiers
61
+ "public": kw("modifier"),
62
+ "private": kw("modifier"),
63
+ "protected": kw("modifier"),
64
+ "abstract": kw("modifier"),
65
+
66
+ // operators
67
+ "as": operator,
68
+
69
+ // types
70
+ "string": type, "number": type, "boolean": type, "any": type
71
+ };
72
+
73
+ for (var attr in tsKeywords) {
74
+ jsKeywords[attr] = tsKeywords[attr];
75
+ }
76
+ }
77
+
78
+ return jsKeywords;
79
+ }();
80
+
81
+ var isOperatorChar = /[+\-*&%=<>!?|~^]/;
82
+ var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
83
+
84
+ function readRegexp(stream) {
85
+ var escaped = false, next, inSet = false;
86
+ while ((next = stream.next()) != null) {
87
+ if (!escaped) {
88
+ if (next == "/" && !inSet) return;
89
+ if (next == "[") inSet = true;
90
+ else if (inSet && next == "]") inSet = false;
91
+ }
92
+ escaped = !escaped && next == "\\";
93
+ }
94
+ }
95
+
96
+ // Used as scratch variables to communicate multiple values without
97
+ // consing up tons of objects.
98
+ var type, content;
99
+ function ret(tp, style, cont) {
100
+ type = tp; content = cont;
101
+ return style;
102
+ }
103
+ function tokenBase(stream, state) {
104
+ var ch = stream.next();
105
+ if (ch == '"' || ch == "'") {
106
+ state.tokenize = tokenString(ch);
107
+ return state.tokenize(stream, state);
108
+ } else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
109
+ return ret("number", "number");
110
+ } else if (ch == "." && stream.match("..")) {
111
+ return ret("spread", "meta");
112
+ } else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
113
+ return ret(ch);
114
+ } else if (ch == "=" && stream.eat(">")) {
115
+ return ret("=>", "operator");
116
+ } else if (ch == "0" && stream.eat(/x/i)) {
117
+ stream.eatWhile(/[\da-f]/i);
118
+ return ret("number", "number");
119
+ } else if (ch == "0" && stream.eat(/o/i)) {
120
+ stream.eatWhile(/[0-7]/i);
121
+ return ret("number", "number");
122
+ } else if (ch == "0" && stream.eat(/b/i)) {
123
+ stream.eatWhile(/[01]/i);
124
+ return ret("number", "number");
125
+ } else if (/\d/.test(ch)) {
126
+ stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
127
+ return ret("number", "number");
128
+ } else if (ch == "/") {
129
+ if (stream.eat("*")) {
130
+ state.tokenize = tokenComment;
131
+ return tokenComment(stream, state);
132
+ } else if (stream.eat("/")) {
133
+ stream.skipToEnd();
134
+ return ret("comment", "comment");
135
+ } else if (expressionAllowed(stream, state, 1)) {
136
+ readRegexp(stream);
137
+ stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
138
+ return ret("regexp", "string-2");
139
+ } else {
140
+ stream.eatWhile(isOperatorChar);
141
+ return ret("operator", "operator", stream.current());
142
+ }
143
+ } else if (ch == "`") {
144
+ state.tokenize = tokenQuasi;
145
+ return tokenQuasi(stream, state);
146
+ } else if (ch == "#") {
147
+ stream.skipToEnd();
148
+ return ret("error", "error");
149
+ } else if (isOperatorChar.test(ch)) {
150
+ stream.eatWhile(isOperatorChar);
151
+ return ret("operator", "operator", stream.current());
152
+ } else if (wordRE.test(ch)) {
153
+ stream.eatWhile(wordRE);
154
+ var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
155
+ return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
156
+ ret("variable", "variable", word);
157
+ }
158
+ }
159
+
160
+ function tokenString(quote) {
161
+ return function(stream, state) {
162
+ var escaped = false, next;
163
+ if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
164
+ state.tokenize = tokenBase;
165
+ return ret("jsonld-keyword", "meta");
166
+ }
167
+ while ((next = stream.next()) != null) {
168
+ if (next == quote && !escaped) break;
169
+ escaped = !escaped && next == "\\";
170
+ }
171
+ if (!escaped) state.tokenize = tokenBase;
172
+ return ret("string", "string");
173
+ };
174
+ }
175
+
176
+ function tokenComment(stream, state) {
177
+ var maybeEnd = false, ch;
178
+ while (ch = stream.next()) {
179
+ if (ch == "/" && maybeEnd) {
180
+ state.tokenize = tokenBase;
181
+ break;
182
+ }
183
+ maybeEnd = (ch == "*");
184
+ }
185
+ return ret("comment", "comment");
186
+ }
187
+
188
+ function tokenQuasi(stream, state) {
189
+ var escaped = false, next;
190
+ while ((next = stream.next()) != null) {
191
+ if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
192
+ state.tokenize = tokenBase;
193
+ break;
194
+ }
195
+ escaped = !escaped && next == "\\";
196
+ }
197
+ return ret("quasi", "string-2", stream.current());
198
+ }
199
+
200
+ var brackets = "([{}])";
201
+ // This is a crude lookahead trick to try and notice that we're
202
+ // parsing the argument patterns for a fat-arrow function before we
203
+ // actually hit the arrow token. It only works if the arrow is on
204
+ // the same line as the arguments and there's no strange noise
205
+ // (comments) in between. Fallback is to only notice when we hit the
206
+ // arrow, and not declare the arguments as locals for the arrow
207
+ // body.
208
+ function findFatArrow(stream, state) {
209
+ if (state.fatArrowAt) state.fatArrowAt = null;
210
+ var arrow = stream.string.indexOf("=>", stream.start);
211
+ if (arrow < 0) return;
212
+
213
+ var depth = 0, sawSomething = false;
214
+ for (var pos = arrow - 1; pos >= 0; --pos) {
215
+ var ch = stream.string.charAt(pos);
216
+ var bracket = brackets.indexOf(ch);
217
+ if (bracket >= 0 && bracket < 3) {
218
+ if (!depth) { ++pos; break; }
219
+ if (--depth == 0) break;
220
+ } else if (bracket >= 3 && bracket < 6) {
221
+ ++depth;
222
+ } else if (wordRE.test(ch)) {
223
+ sawSomething = true;
224
+ } else if (/["'\/]/.test(ch)) {
225
+ return;
226
+ } else if (sawSomething && !depth) {
227
+ ++pos;
228
+ break;
229
+ }
230
+ }
231
+ if (sawSomething && !depth) state.fatArrowAt = pos;
232
+ }
233
+
234
+ // Parser
235
+
236
+ var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true};
237
+
238
+ function JSLexical(indented, column, type, align, prev, info) {
239
+ this.indented = indented;
240
+ this.column = column;
241
+ this.type = type;
242
+ this.prev = prev;
243
+ this.info = info;
244
+ if (align != null) this.align = align;
245
+ }
246
+
247
+ function inScope(state, varname) {
248
+ for (var v = state.localVars; v; v = v.next)
249
+ if (v.name == varname) return true;
250
+ for (var cx = state.context; cx; cx = cx.prev) {
251
+ for (var v = cx.vars; v; v = v.next)
252
+ if (v.name == varname) return true;
253
+ }
254
+ }
255
+
256
+ function parseJS(state, style, type, content, stream) {
257
+ var cc = state.cc;
258
+ // Communicate our context to the combinators.
259
+ // (Less wasteful than consing up a hundred closures on every call.)
260
+ cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
261
+
262
+ if (!state.lexical.hasOwnProperty("align"))
263
+ state.lexical.align = true;
264
+
265
+ while(true) {
266
+ var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
267
+ if (combinator(type, content)) {
268
+ while(cc.length && cc[cc.length - 1].lex)
269
+ cc.pop()();
270
+ if (cx.marked) return cx.marked;
271
+ if (type == "variable" && inScope(state, content)) return "variable-2";
272
+ return style;
273
+ }
274
+ }
275
+ }
276
+
277
+ // Combinator utils
278
+
279
+ var cx = {state: null, column: null, marked: null, cc: null};
280
+ function pass() {
281
+ for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
282
+ }
283
+ function cont() {
284
+ pass.apply(null, arguments);
285
+ return true;
286
+ }
287
+ function register(varname) {
288
+ function inList(list) {
289
+ for (var v = list; v; v = v.next)
290
+ if (v.name == varname) return true;
291
+ return false;
292
+ }
293
+ var state = cx.state;
294
+ cx.marked = "def";
295
+ if (state.context) {
296
+ if (inList(state.localVars)) return;
297
+ state.localVars = {name: varname, next: state.localVars};
298
+ } else {
299
+ if (inList(state.globalVars)) return;
300
+ if (parserConfig.globalVars)
301
+ state.globalVars = {name: varname, next: state.globalVars};
302
+ }
303
+ }
304
+
305
+ // Combinators
306
+
307
+ var defaultVars = {name: "this", next: {name: "arguments"}};
308
+ function pushcontext() {
309
+ cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
310
+ cx.state.localVars = defaultVars;
311
+ }
312
+ function popcontext() {
313
+ cx.state.localVars = cx.state.context.vars;
314
+ cx.state.context = cx.state.context.prev;
315
+ }
316
+ function pushlex(type, info) {
317
+ var result = function() {
318
+ var state = cx.state, indent = state.indented;
319
+ if (state.lexical.type == "stat") indent = state.lexical.indented;
320
+ else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
321
+ indent = outer.indented;
322
+ state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
323
+ };
324
+ result.lex = true;
325
+ return result;
326
+ }
327
+ function poplex() {
328
+ var state = cx.state;
329
+ if (state.lexical.prev) {
330
+ if (state.lexical.type == ")")
331
+ state.indented = state.lexical.indented;
332
+ state.lexical = state.lexical.prev;
333
+ }
334
+ }
335
+ poplex.lex = true;
336
+
337
+ function expect(wanted) {
338
+ function exp(type) {
339
+ if (type == wanted) return cont();
340
+ else if (wanted == ";") return pass();
341
+ else return cont(exp);
342
+ };
343
+ return exp;
344
+ }
345
+
346
+ function statement(type, value) {
347
+ if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
348
+ if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
349
+ if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
350
+ if (type == "{") return cont(pushlex("}"), block, poplex);
351
+ if (type == ";") return cont();
352
+ if (type == "if") {
353
+ if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
354
+ cx.state.cc.pop()();
355
+ return cont(pushlex("form"), expression, statement, poplex, maybeelse);
356
+ }
357
+ if (type == "function") return cont(functiondef);
358
+ if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
359
+ if (type == "variable") return cont(pushlex("stat"), maybelabel);
360
+ if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
361
+ block, poplex, poplex);
362
+ if (type == "case") return cont(expression, expect(":"));
363
+ if (type == "default") return cont(expect(":"));
364
+ if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
365
+ statement, poplex, popcontext);
366
+ if (type == "class") return cont(pushlex("form"), className, poplex);
367
+ if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
368
+ if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
369
+ if (type == "module") return cont(pushlex("form"), pattern, pushlex("}"), expect("{"), block, poplex, poplex)
370
+ if (type == "async") return cont(statement)
371
+ return pass(pushlex("stat"), expression, expect(";"), poplex);
372
+ }
373
+ function expression(type) {
374
+ return expressionInner(type, false);
375
+ }
376
+ function expressionNoComma(type) {
377
+ return expressionInner(type, true);
378
+ }
379
+ function expressionInner(type, noComma) {
380
+ if (cx.state.fatArrowAt == cx.stream.start) {
381
+ var body = noComma ? arrowBodyNoComma : arrowBody;
382
+ if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
383
+ else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
384
+ }
385
+
386
+ var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
387
+ if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
388
+ if (type == "function") return cont(functiondef, maybeop);
389
+ if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
390
+ if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop);
391
+ if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
392
+ if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
393
+ if (type == "{") return contCommasep(objprop, "}", null, maybeop);
394
+ if (type == "quasi") return pass(quasi, maybeop);
395
+ if (type == "new") return cont(maybeTarget(noComma));
396
+ return cont();
397
+ }
398
+ function maybeexpression(type) {
399
+ if (type.match(/[;\}\)\],]/)) return pass();
400
+ return pass(expression);
401
+ }
402
+ function maybeexpressionNoComma(type) {
403
+ if (type.match(/[;\}\)\],]/)) return pass();
404
+ return pass(expressionNoComma);
405
+ }
406
+
407
+ function maybeoperatorComma(type, value) {
408
+ if (type == ",") return cont(expression);
409
+ return maybeoperatorNoComma(type, value, false);
410
+ }
411
+ function maybeoperatorNoComma(type, value, noComma) {
412
+ var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
413
+ var expr = noComma == false ? expression : expressionNoComma;
414
+ if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
415
+ if (type == "operator") {
416
+ if (/\+\+|--/.test(value)) return cont(me);
417
+ if (value == "?") return cont(expression, expect(":"), expr);
418
+ return cont(expr);
419
+ }
420
+ if (type == "quasi") { return pass(quasi, me); }
421
+ if (type == ";") return;
422
+ if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
423
+ if (type == ".") return cont(property, me);
424
+ if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
425
+ }
426
+ function quasi(type, value) {
427
+ if (type != "quasi") return pass();
428
+ if (value.slice(value.length - 2) != "${") return cont(quasi);
429
+ return cont(expression, continueQuasi);
430
+ }
431
+ function continueQuasi(type) {
432
+ if (type == "}") {
433
+ cx.marked = "string-2";
434
+ cx.state.tokenize = tokenQuasi;
435
+ return cont(quasi);
436
+ }
437
+ }
438
+ function arrowBody(type) {
439
+ findFatArrow(cx.stream, cx.state);
440
+ return pass(type == "{" ? statement : expression);
441
+ }
442
+ function arrowBodyNoComma(type) {
443
+ findFatArrow(cx.stream, cx.state);
444
+ return pass(type == "{" ? statement : expressionNoComma);
445
+ }
446
+ function maybeTarget(noComma) {
447
+ return function(type) {
448
+ if (type == ".") return cont(noComma ? targetNoComma : target);
449
+ else return pass(noComma ? expressionNoComma : expression);
450
+ };
451
+ }
452
+ function target(_, value) {
453
+ if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); }
454
+ }
455
+ function targetNoComma(_, value) {
456
+ if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); }
457
+ }
458
+ function maybelabel(type) {
459
+ if (type == ":") return cont(poplex, statement);
460
+ return pass(maybeoperatorComma, expect(";"), poplex);
461
+ }
462
+ function property(type) {
463
+ if (type == "variable") {cx.marked = "property"; return cont();}
464
+ }
465
+ function objprop(type, value) {
466
+ if (type == "variable" || cx.style == "keyword") {
467
+ cx.marked = "property";
468
+ if (value == "get" || value == "set") return cont(getterSetter);
469
+ return cont(afterprop);
470
+ } else if (type == "number" || type == "string") {
471
+ cx.marked = jsonldMode ? "property" : (cx.style + " property");
472
+ return cont(afterprop);
473
+ } else if (type == "jsonld-keyword") {
474
+ return cont(afterprop);
475
+ } else if (type == "modifier") {
476
+ return cont(objprop)
477
+ } else if (type == "[") {
478
+ return cont(expression, expect("]"), afterprop);
479
+ } else if (type == "spread") {
480
+ return cont(expression);
481
+ }
482
+ }
483
+ function getterSetter(type) {
484
+ if (type != "variable") return pass(afterprop);
485
+ cx.marked = "property";
486
+ return cont(functiondef);
487
+ }
488
+ function afterprop(type) {
489
+ if (type == ":") return cont(expressionNoComma);
490
+ if (type == "(") return pass(functiondef);
491
+ }
492
+ function commasep(what, end) {
493
+ function proceed(type, value) {
494
+ if (type == ",") {
495
+ var lex = cx.state.lexical;
496
+ if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
497
+ return cont(what, proceed);
498
+ }
499
+ if (type == end || value == end) return cont();
500
+ return cont(expect(end));
501
+ }
502
+ return function(type, value) {
503
+ if (type == end || value == end) return cont();
504
+ return pass(what, proceed);
505
+ };
506
+ }
507
+ function contCommasep(what, end, info) {
508
+ for (var i = 3; i < arguments.length; i++)
509
+ cx.cc.push(arguments[i]);
510
+ return cont(pushlex(end, info), commasep(what, end), poplex);
511
+ }
512
+ function block(type) {
513
+ if (type == "}") return cont();
514
+ return pass(statement, block);
515
+ }
516
+ function maybetype(type) {
517
+ if (isTS && type == ":") return cont(typeexpr);
518
+ }
519
+ function maybedefault(_, value) {
520
+ if (value == "=") return cont(expressionNoComma);
521
+ }
522
+ function typeexpr(type) {
523
+ if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
524
+ }
525
+ function afterType(type, value) {
526
+ if (value == "<") return cont(commasep(typeexpr, ">"), afterType)
527
+ if (type == "[") return cont(expect("]"), afterType)
528
+ }
529
+ function vardef() {
530
+ return pass(pattern, maybetype, maybeAssign, vardefCont);
531
+ }
532
+ function pattern(type, value) {
533
+ if (type == "modifier") return cont(pattern)
534
+ if (type == "variable") { register(value); return cont(); }
535
+ if (type == "spread") return cont(pattern);
536
+ if (type == "[") return contCommasep(pattern, "]");
537
+ if (type == "{") return contCommasep(proppattern, "}");
538
+ }
539
+ function proppattern(type, value) {
540
+ if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
541
+ register(value);
542
+ return cont(maybeAssign);
543
+ }
544
+ if (type == "variable") cx.marked = "property";
545
+ if (type == "spread") return cont(pattern);
546
+ if (type == "}") return pass();
547
+ return cont(expect(":"), pattern, maybeAssign);
548
+ }
549
+ function maybeAssign(_type, value) {
550
+ if (value == "=") return cont(expressionNoComma);
551
+ }
552
+ function vardefCont(type) {
553
+ if (type == ",") return cont(vardef);
554
+ }
555
+ function maybeelse(type, value) {
556
+ if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
557
+ }
558
+ function forspec(type) {
559
+ if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
560
+ }
561
+ function forspec1(type) {
562
+ if (type == "var") return cont(vardef, expect(";"), forspec2);
563
+ if (type == ";") return cont(forspec2);
564
+ if (type == "variable") return cont(formaybeinof);
565
+ return pass(expression, expect(";"), forspec2);
566
+ }
567
+ function formaybeinof(_type, value) {
568
+ if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
569
+ return cont(maybeoperatorComma, forspec2);
570
+ }
571
+ function forspec2(type, value) {
572
+ if (type == ";") return cont(forspec3);
573
+ if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
574
+ return pass(expression, expect(";"), forspec3);
575
+ }
576
+ function forspec3(type) {
577
+ if (type != ")") cont(expression);
578
+ }
579
+ function functiondef(type, value) {
580
+ if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
581
+ if (type == "variable") {register(value); return cont(functiondef);}
582
+ if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, maybetype, statement, popcontext);
583
+ }
584
+ function funarg(type) {
585
+ if (type == "spread") return cont(funarg);
586
+ return pass(pattern, maybetype, maybedefault);
587
+ }
588
+ function className(type, value) {
589
+ if (type == "variable") {register(value); return cont(classNameAfter);}
590
+ }
591
+ function classNameAfter(type, value) {
592
+ if (value == "extends") return cont(expression, classNameAfter);
593
+ if (type == "{") return cont(pushlex("}"), classBody, poplex);
594
+ }
595
+ function classBody(type, value) {
596
+ if (type == "variable" || cx.style == "keyword") {
597
+ if (value == "static") {
598
+ cx.marked = "keyword";
599
+ return cont(classBody);
600
+ }
601
+ cx.marked = "property";
602
+ if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody);
603
+ return cont(functiondef, classBody);
604
+ }
605
+ if (value == "*") {
606
+ cx.marked = "keyword";
607
+ return cont(classBody);
608
+ }
609
+ if (type == ";") return cont(classBody);
610
+ if (type == "}") return cont();
611
+ }
612
+ function classGetterSetter(type) {
613
+ if (type != "variable") return pass();
614
+ cx.marked = "property";
615
+ return cont();
616
+ }
617
+ function afterExport(_type, value) {
618
+ if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
619
+ if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
620
+ return pass(statement);
621
+ }
622
+ function afterImport(type) {
623
+ if (type == "string") return cont();
624
+ return pass(importSpec, maybeFrom);
625
+ }
626
+ function importSpec(type, value) {
627
+ if (type == "{") return contCommasep(importSpec, "}");
628
+ if (type == "variable") register(value);
629
+ if (value == "*") cx.marked = "keyword";
630
+ return cont(maybeAs);
631
+ }
632
+ function maybeAs(_type, value) {
633
+ if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
634
+ }
635
+ function maybeFrom(_type, value) {
636
+ if (value == "from") { cx.marked = "keyword"; return cont(expression); }
637
+ }
638
+ function arrayLiteral(type) {
639
+ if (type == "]") return cont();
640
+ return pass(expressionNoComma, maybeArrayComprehension);
641
+ }
642
+ function maybeArrayComprehension(type) {
643
+ if (type == "for") return pass(comprehension, expect("]"));
644
+ if (type == ",") return cont(commasep(maybeexpressionNoComma, "]"));
645
+ return pass(commasep(expressionNoComma, "]"));
646
+ }
647
+ function comprehension(type) {
648
+ if (type == "for") return cont(forspec, comprehension);
649
+ if (type == "if") return cont(expression, comprehension);
650
+ }
651
+
652
+ function isContinuedStatement(state, textAfter) {
653
+ return state.lastType == "operator" || state.lastType == "," ||
654
+ isOperatorChar.test(textAfter.charAt(0)) ||
655
+ /[,.]/.test(textAfter.charAt(0));
656
+ }
657
+
658
+ // Interface
659
+
660
+ return {
661
+ startState: function(basecolumn) {
662
+ var state = {
663
+ tokenize: tokenBase,
664
+ lastType: "sof",
665
+ cc: [],
666
+ lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
667
+ localVars: parserConfig.localVars,
668
+ context: parserConfig.localVars && {vars: parserConfig.localVars},
669
+ indented: basecolumn || 0
670
+ };
671
+ if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
672
+ state.globalVars = parserConfig.globalVars;
673
+ return state;
674
+ },
675
+
676
+ token: function(stream, state) {
677
+ if (stream.sol()) {
678
+ if (!state.lexical.hasOwnProperty("align"))
679
+ state.lexical.align = false;
680
+ state.indented = stream.indentation();
681
+ findFatArrow(stream, state);
682
+ }
683
+ if (state.tokenize != tokenComment && stream.eatSpace()) return null;
684
+ var style = state.tokenize(stream, state);
685
+ if (type == "comment") return style;
686
+ state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
687
+ return parseJS(state, style, type, content, stream);
688
+ },
689
+
690
+ indent: function(state, textAfter) {
691
+ if (state.tokenize == tokenComment) return CodeMirror.Pass;
692
+ if (state.tokenize != tokenBase) return 0;
693
+ var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
694
+ // Kludge to prevent 'maybelse' from blocking lexical scope pops
695
+ if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
696
+ var c = state.cc[i];
697
+ if (c == poplex) lexical = lexical.prev;
698
+ else if (c != maybeelse) break;
699
+ }
700
+ if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev;
701
+ if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
702
+ lexical = lexical.prev;
703
+ var type = lexical.type, closing = firstChar == type;
704
+
705
+ if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0);
706
+ else if (type == "form" && firstChar == "{") return lexical.indented;
707
+ else if (type == "form") return lexical.indented + indentUnit;
708
+ else if (type == "stat")
709
+ return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
710
+ else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
711
+ return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
712
+ else if (lexical.align) return lexical.column + (closing ? 0 : 1);
713
+ else return lexical.indented + (closing ? 0 : indentUnit);
714
+ },
715
+
716
+ electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
717
+ blockCommentStart: jsonMode ? null : "/*",
718
+ blockCommentEnd: jsonMode ? null : "*/",
719
+ lineComment: jsonMode ? null : "//",
720
+ fold: "brace",
721
+ closeBrackets: "()[]{}''\"\"``",
722
+
723
+ helperType: jsonMode ? "json" : "javascript",
724
+ jsonldMode: jsonldMode,
725
+ jsonMode: jsonMode,
726
+
727
+ expressionAllowed: expressionAllowed,
728
+ skipExpression: function(state) {
729
+ var top = state.cc[state.cc.length - 1]
730
+ if (top == expression || top == expressionNoComma) state.cc.pop()
731
+ }
732
+ };
733
+ });
734
+
735
+ CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
736
+
737
+ CodeMirror.defineMIME("text/javascript", "javascript");
738
+ CodeMirror.defineMIME("text/ecmascript", "javascript");
739
+ CodeMirror.defineMIME("application/javascript", "javascript");
740
+ CodeMirror.defineMIME("application/x-javascript", "javascript");
741
+ CodeMirror.defineMIME("application/ecmascript", "javascript");
742
+ CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
743
+ CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
744
+ CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true});
745
+ CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
746
+ CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
747
+
748
+ });