glebtv-ckeditor 4.5.10.3 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (295) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/ckeditor/config.js.erb +1 -1
  3. data/lib/ckeditor.rb +1 -0
  4. data/lib/ckeditor/version.rb +2 -2
  5. data/lib/generators/ckeditor/templates/active_record/carrierwave/migration.rb +1 -1
  6. data/lib/generators/ckeditor/templates/active_record/dragonfly/migration.rb +1 -1
  7. data/lib/generators/ckeditor/templates/active_record/paperclip/migration.rb +1 -1
  8. data/lib/generators/ckeditor/templates/active_record/refile/migration.rb +1 -1
  9. data/vendor/assets/javascripts/ckeditor/LICENSE.md +2 -2
  10. data/vendor/assets/javascripts/ckeditor/adapters/jquery.js +1 -1
  11. data/vendor/assets/javascripts/ckeditor/build-config.js +26 -26
  12. data/vendor/assets/javascripts/ckeditor/ckeditor.js +605 -576
  13. data/vendor/assets/javascripts/ckeditor/lang/en.js +2 -2
  14. data/vendor/assets/javascripts/ckeditor/lang/ru.js +2 -2
  15. data/vendor/assets/javascripts/ckeditor/plugins/CKCss/css/styles.css +9 -0
  16. data/vendor/assets/javascripts/ckeditor/plugins/CKCss/dialogs/ckcss.js +2 -1
  17. data/vendor/assets/javascripts/ckeditor/plugins/CKCss/plugin.js +3 -1
  18. data/vendor/assets/javascripts/ckeditor/plugins/a11yhelp/dialogs/a11yhelp.js +6 -6
  19. data/vendor/assets/javascripts/ckeditor/plugins/a11yhelp/dialogs/lang/en.js +3 -4
  20. data/vendor/assets/javascripts/ckeditor/plugins/a11yhelp/dialogs/lang/ru.js +4 -4
  21. data/vendor/assets/javascripts/ckeditor/plugins/about/dialogs/about.js +4 -3
  22. data/vendor/assets/javascripts/ckeditor/plugins/clipboard/dialogs/paste.js +1 -1
  23. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/LICENSE.md +21 -0
  24. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/css/codemirror.ckeditor.css +183 -0
  25. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/css/codemirror.css +341 -0
  26. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/css/codemirror.min.css +1 -1
  27. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/comment/comment.js +206 -0
  28. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/comment/continuecomment.js +85 -0
  29. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/dialog/dialog.css +32 -0
  30. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/dialog/dialog.js +157 -0
  31. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/closebrackets.js +202 -0
  32. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/closetag.js +169 -0
  33. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/continuelist.js +51 -0
  34. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/matchbrackets.js +122 -0
  35. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/matchtags.js +66 -0
  36. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/trailingspace.js +27 -0
  37. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/fold/brace-fold.js +105 -0
  38. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/fold/comment-fold.js +59 -0
  39. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/fold/foldcode.js +150 -0
  40. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/fold/foldgutter.css +20 -0
  41. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/fold/foldgutter.js +146 -0
  42. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/fold/indent-fold.js +44 -0
  43. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/fold/markdown-fold.js +49 -0
  44. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/fold/xml-fold.js +182 -0
  45. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/format/autoFormatAll.js +43 -0
  46. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/format/formatting.js +226 -0
  47. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/hint/anyword-hint.js +41 -0
  48. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/hint/css-hint.js +60 -0
  49. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/hint/html-hint.js +348 -0
  50. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/hint/javascript-hint.js +155 -0
  51. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/hint/show-hint.css +36 -0
  52. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/hint/show-hint.js +438 -0
  53. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/hint/sql-hint.js +271 -0
  54. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/hint/xml-hint.js +110 -0
  55. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/mode/loadmode.js +64 -0
  56. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/mode/multiplex.js +123 -0
  57. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/mode/multiplex_test.js +33 -0
  58. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/mode/overlay.js +85 -0
  59. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/mode/simple.js +213 -0
  60. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/search/jump-to-line.js +49 -0
  61. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/search/match-highlighter.js +165 -0
  62. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/search/matchesonscrollbar.css +8 -0
  63. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/search/matchesonscrollbar.js +97 -0
  64. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/search/search.js +252 -0
  65. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/search/searchcursor.js +189 -0
  66. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/selection/active-line.js +74 -0
  67. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/selection/mark-selection.js +118 -0
  68. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/selection/selection-pointer.js +98 -0
  69. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/beautify-html.js +952 -0
  70. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/beautify.js +2087 -0
  71. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/codemirror.addons.min.js +1 -1
  72. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/codemirror.addons.search.min.js +1 -1
  73. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/codemirror.js +9109 -0
  74. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/codemirror.min.js +1 -1
  75. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/codemirror.mode.htmlmixed.min.js +1 -1
  76. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/codemirror.mode.javascript.min.js +1 -1
  77. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/codemirror.mode.php.min.js +1 -1
  78. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/bbcode/bbcode.js +137 -0
  79. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/bbcode/index.html +73 -0
  80. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/bbcodemixed/bbcodemixed.js +161 -0
  81. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/bbcodemixed/index.html +128 -0
  82. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/clike/clike.js +785 -0
  83. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/clike/index.html +360 -0
  84. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/clike/scala.html +767 -0
  85. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/clike/test.js +55 -0
  86. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/css/css.js +825 -0
  87. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/css/gss.html +103 -0
  88. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/css/gss_test.js +17 -0
  89. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/css/index.html +75 -0
  90. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/css/less.html +152 -0
  91. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/css/less_test.js +54 -0
  92. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/css/scss.html +157 -0
  93. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/css/scss_test.js +110 -0
  94. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/css/test.js +200 -0
  95. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/htmlembedded/htmlembedded.js +28 -0
  96. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/htmlembedded/index.html +60 -0
  97. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/htmlmixed/htmlmixed.js +152 -0
  98. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/htmlmixed/index.html +89 -0
  99. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/javascript/index.html +114 -0
  100. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/javascript/javascript.js +784 -0
  101. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/javascript/json-ld.html +72 -0
  102. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/javascript/test.js +247 -0
  103. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/javascript/typescript.html +61 -0
  104. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/php/index.html +64 -0
  105. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/php/php.js +234 -0
  106. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/php/test.js +154 -0
  107. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/xml/index.html +61 -0
  108. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/xml/test.js +51 -0
  109. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/js/mode/xml/xml.js +394 -0
  110. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/plugin.js +30 -24
  111. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/theme/dracula.css +1 -1
  112. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/theme/duotone-dark.css +35 -0
  113. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/theme/duotone-light.css +36 -0
  114. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/theme/panda-syntax.css +85 -0
  115. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/theme/pastel-on-dark.css +0 -1
  116. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/theme/solarized.css +21 -15
  117. data/vendor/assets/javascripts/ckeditor/plugins/colordialog/dialogs/colordialog.css +1 -1
  118. data/vendor/assets/javascripts/ckeditor/plugins/colordialog/dialogs/colordialog.js +1 -1
  119. data/vendor/assets/javascripts/ckeditor/plugins/dialog/dialogDefinition.js +1 -1
  120. data/vendor/assets/javascripts/ckeditor/plugins/find/dialogs/find.js +9 -9
  121. data/vendor/assets/javascripts/ckeditor/plugins/flash/dialogs/flash.js +12 -12
  122. data/vendor/assets/javascripts/ckeditor/plugins/forms/dialogs/button.js +1 -1
  123. data/vendor/assets/javascripts/ckeditor/plugins/forms/dialogs/checkbox.js +1 -1
  124. data/vendor/assets/javascripts/ckeditor/plugins/forms/dialogs/form.js +1 -1
  125. data/vendor/assets/javascripts/ckeditor/plugins/forms/dialogs/hiddenfield.js +1 -1
  126. data/vendor/assets/javascripts/ckeditor/plugins/forms/dialogs/radio.js +1 -1
  127. data/vendor/assets/javascripts/ckeditor/plugins/forms/dialogs/select.js +11 -11
  128. data/vendor/assets/javascripts/ckeditor/plugins/forms/dialogs/textarea.js +1 -1
  129. data/vendor/assets/javascripts/ckeditor/plugins/forms/dialogs/textfield.js +1 -1
  130. data/vendor/assets/javascripts/ckeditor/plugins/icons.png +0 -0
  131. data/vendor/assets/javascripts/ckeditor/plugins/icons_hidpi.png +0 -0
  132. data/vendor/assets/javascripts/ckeditor/plugins/iframe/dialogs/iframe.js +1 -1
  133. data/vendor/assets/javascripts/ckeditor/plugins/iframedialog/plugin.js +1 -1
  134. data/vendor/assets/javascripts/ckeditor/plugins/image/dialogs/image.js +28 -28
  135. data/vendor/assets/javascripts/ckeditor/plugins/lineheight/LICENSE +0 -0
  136. data/vendor/assets/javascripts/ckeditor/plugins/lineheight/README.md +0 -0
  137. data/vendor/assets/javascripts/ckeditor/plugins/lineheight/lang/LANG.js +3 -0
  138. data/vendor/assets/javascripts/ckeditor/plugins/lineheight/lang/en.js +0 -0
  139. data/vendor/assets/javascripts/ckeditor/plugins/lineheight/lang/ru.js +3 -3
  140. data/vendor/assets/javascripts/ckeditor/plugins/lineheight/plugin.js +1 -1
  141. data/vendor/assets/javascripts/ckeditor/plugins/lineheight/readme.txt +0 -0
  142. data/vendor/assets/javascripts/ckeditor/plugins/link/dialogs/anchor.js +1 -1
  143. data/vendor/assets/javascripts/ckeditor/plugins/link/dialogs/link.js +25 -23
  144. data/vendor/assets/javascripts/ckeditor/plugins/link/images/anchor.png +0 -0
  145. data/vendor/assets/javascripts/ckeditor/plugins/link/images/hidpi/anchor.png +0 -0
  146. data/vendor/assets/javascripts/ckeditor/plugins/liststyle/dialogs/liststyle.js +1 -1
  147. data/vendor/assets/javascripts/ckeditor/plugins/notification/lang/en.js +1 -1
  148. data/vendor/assets/javascripts/ckeditor/plugins/notification/lang/ru.js +1 -1
  149. data/vendor/assets/javascripts/ckeditor/plugins/notification/plugin.js +2 -2
  150. data/vendor/assets/javascripts/ckeditor/plugins/pastefromword/filter/default.js +40 -29
  151. data/vendor/assets/javascripts/ckeditor/plugins/scayt/dialogs/options.js +19 -19
  152. data/vendor/assets/javascripts/ckeditor/plugins/scayt/skins/moono-lisa/scayt.css +20 -0
  153. data/vendor/assets/javascripts/ckeditor/plugins/smiley/dialogs/smiley.js +1 -1
  154. data/vendor/assets/javascripts/ckeditor/plugins/specialchar/dialogs/lang/en.js +2 -2
  155. data/vendor/assets/javascripts/ckeditor/plugins/specialchar/dialogs/lang/ru.js +1 -1
  156. data/vendor/assets/javascripts/ckeditor/plugins/specialchar/dialogs/specialchar.js +1 -1
  157. data/vendor/assets/javascripts/ckeditor/plugins/stylesheetparser/plugin.js +1 -1
  158. data/vendor/assets/javascripts/ckeditor/plugins/stylesheetparser/samples/assets/sample.css +70 -0
  159. data/vendor/assets/javascripts/ckeditor/plugins/stylesheetparser/samples/stylesheetparser.html +85 -0
  160. data/vendor/assets/javascripts/ckeditor/plugins/table/dialogs/table.js +1 -1
  161. data/vendor/assets/javascripts/ckeditor/plugins/tabletools/dialogs/tableCell.js +1 -1
  162. data/vendor/assets/javascripts/ckeditor/plugins/templates/dialogs/templates.css +1 -1
  163. data/vendor/assets/javascripts/ckeditor/plugins/templates/dialogs/templates.js +1 -1
  164. data/vendor/assets/javascripts/ckeditor/plugins/templates/templates/default.js +2 -2
  165. data/vendor/assets/javascripts/ckeditor/plugins/templates/templates/images/template1.gif +0 -0
  166. data/vendor/assets/javascripts/ckeditor/plugins/templates/templates/images/template2.gif +0 -0
  167. data/vendor/assets/javascripts/ckeditor/plugins/templates/templates/images/template3.gif +0 -0
  168. data/vendor/assets/javascripts/ckeditor/plugins/wordcount/css/wordcount.css +0 -0
  169. data/vendor/assets/javascripts/ckeditor/plugins/wordcount/lang/en.js +1 -1
  170. data/vendor/assets/javascripts/ckeditor/plugins/wordcount/lang/ru.js +1 -1
  171. data/vendor/assets/javascripts/ckeditor/plugins/wordcount/plugin.js +60 -13
  172. data/vendor/assets/javascripts/ckeditor/plugins/wordcount/samples/wordcount.html +61 -0
  173. data/vendor/assets/javascripts/ckeditor/plugins/wordcount/samples/wordcountWithMaxCount.html +110 -0
  174. data/vendor/assets/javascripts/ckeditor/plugins/wsc/dialogs/wsc.js +9 -9
  175. data/vendor/assets/javascripts/ckeditor/plugins/wsc/skins/moono-lisa/wsc.css +43 -0
  176. data/vendor/assets/javascripts/ckeditor/plugins/youtube/LICENSE.md +15 -0
  177. data/vendor/assets/javascripts/ckeditor/plugins/youtube/images/icon.png +0 -0
  178. data/vendor/assets/javascripts/ckeditor/plugins/youtube/lang/en.js +3 -1
  179. data/vendor/assets/javascripts/ckeditor/plugins/youtube/lang/ru.js +1 -0
  180. data/vendor/assets/javascripts/ckeditor/plugins/youtube/plugin.js +448 -388
  181. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/dev/icons16.png +0 -0
  182. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/dev/icons16.svg +175 -0
  183. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/dev/icons32.png +0 -0
  184. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/dev/icons32.svg +167 -0
  185. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/dev/locations.json +145 -0
  186. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/dialog.css +5 -0
  187. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/dialog_ie.css +5 -0
  188. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/dialog_ie8.css +5 -0
  189. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/dialog_iequirks.css +5 -0
  190. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/editor.css +5 -0
  191. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/editor_gecko.css +5 -0
  192. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/editor_ie.css +5 -0
  193. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/editor_ie8.css +5 -0
  194. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/editor_iequirks.css +5 -0
  195. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/arrow.png +0 -0
  196. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/close.png +0 -0
  197. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/hidpi/close.png +0 -0
  198. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/hidpi/lock-open.png +0 -0
  199. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/hidpi/lock.png +0 -0
  200. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/hidpi/refresh.png +0 -0
  201. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/lock-open.png +0 -0
  202. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/lock.png +0 -0
  203. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/refresh.png +0 -0
  204. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/images/spinner.gif +0 -0
  205. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/readme.md +46 -0
  206. data/vendor/assets/javascripts/ckeditor/skins/moono-lisa/skin.js +7 -0
  207. data/vendor/assets/javascripts/ckeditor/skins/moono/dialog.css +1 -1
  208. data/vendor/assets/javascripts/ckeditor/skins/moono/dialog_ie.css +1 -1
  209. data/vendor/assets/javascripts/ckeditor/skins/moono/dialog_ie7.css +1 -1
  210. data/vendor/assets/javascripts/ckeditor/skins/moono/dialog_ie8.css +1 -1
  211. data/vendor/assets/javascripts/ckeditor/skins/moono/dialog_iequirks.css +1 -1
  212. data/vendor/assets/javascripts/ckeditor/skins/moono/editor.css +2 -2
  213. data/vendor/assets/javascripts/ckeditor/skins/moono/editor_gecko.css +2 -2
  214. data/vendor/assets/javascripts/ckeditor/skins/moono/editor_ie.css +2 -2
  215. data/vendor/assets/javascripts/ckeditor/skins/moono/editor_ie7.css +2 -2
  216. data/vendor/assets/javascripts/ckeditor/skins/moono/editor_ie8.css +2 -2
  217. data/vendor/assets/javascripts/ckeditor/skins/moono/editor_iequirks.css +2 -2
  218. data/vendor/assets/javascripts/ckeditor/skins/moono/icons.png +0 -0
  219. data/vendor/assets/javascripts/ckeditor/skins/moono/icons_hidpi.png +0 -0
  220. data/vendor/assets/javascripts/ckeditor/skins/moono/images/anchor.png +0 -0
  221. data/vendor/assets/javascripts/ckeditor/skins/moono/images/close.png +0 -0
  222. data/vendor/assets/javascripts/ckeditor/skins/moono/images/hidpi/anchor.png +0 -0
  223. data/vendor/assets/javascripts/ckeditor/skins/moono/images/hidpi/close.png +0 -0
  224. data/vendor/assets/javascripts/ckeditor/skins/moono/images/hidpi/lock-open.png +0 -0
  225. data/vendor/assets/javascripts/ckeditor/skins/moono/images/hidpi/lock.png +0 -0
  226. data/vendor/assets/javascripts/ckeditor/skins/moono/images/hidpi/refresh.png +0 -0
  227. data/vendor/assets/javascripts/ckeditor/skins/moono/images/lock-open.png +0 -0
  228. data/vendor/assets/javascripts/ckeditor/skins/moono/images/lock.png +0 -0
  229. data/vendor/assets/javascripts/ckeditor/skins/moono/images/refresh.png +0 -0
  230. data/vendor/assets/javascripts/ckeditor/skins/moono/readme.md +3 -3
  231. data/vendor/assets/javascripts/ckeditor/styles.js +42 -16
  232. metadata +161 -105
  233. data/app/assets/javascripts/ckeditor/config_orig.js +0 -58
  234. data/vendor/assets/javascripts/ckeditor/README.md +0 -39
  235. data/vendor/assets/javascripts/ckeditor/config.js +0 -10
  236. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/af.js +0 -12
  237. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/ar.js +0 -12
  238. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/bg.js +0 -12
  239. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/bn.js +0 -12
  240. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/bs.js +0 -12
  241. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/ca.js +0 -12
  242. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/cs.js +0 -12
  243. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/cy.js +0 -12
  244. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/da.js +0 -12
  245. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/de.js +0 -12
  246. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/el.js +0 -12
  247. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/en-au.js +0 -12
  248. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/en-ca.js +0 -12
  249. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/en-gb.js +0 -12
  250. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/eo.js +0 -12
  251. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/es.js +0 -12
  252. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/et.js +0 -12
  253. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/eu.js +0 -12
  254. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/fa.js +0 -12
  255. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/fi.js +0 -12
  256. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/fo.js +0 -12
  257. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/fr-ca.js +0 -12
  258. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/fr.js +0 -12
  259. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/gl.js +0 -12
  260. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/gu.js +0 -12
  261. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/he.js +0 -12
  262. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/hi.js +0 -12
  263. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/hr.js +0 -12
  264. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/hu.js +0 -12
  265. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/is.js +0 -12
  266. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/it.js +0 -12
  267. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/ja.js +0 -12
  268. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/ka.js +0 -12
  269. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/km.js +0 -12
  270. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/ko.js +0 -12
  271. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/ku.js +0 -12
  272. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/lt.js +0 -12
  273. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/lv.js +0 -12
  274. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/mk.js +0 -12
  275. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/mn.js +0 -12
  276. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/ms.js +0 -12
  277. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/nb.js +0 -12
  278. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/nl.js +0 -12
  279. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/no.js +0 -12
  280. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/pl.js +0 -12
  281. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/pt-br.js +0 -12
  282. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/pt.js +0 -12
  283. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/ro.js +0 -12
  284. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/sk.js +0 -12
  285. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/sl.js +0 -12
  286. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/sr-latn.js +0 -12
  287. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/sr.js +0 -12
  288. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/sv.js +0 -12
  289. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/th.js +0 -12
  290. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/tr.js +0 -12
  291. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/ug.js +0 -12
  292. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/uk.js +0 -12
  293. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/vi.js +0 -12
  294. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/zh-cn.js +0 -12
  295. data/vendor/assets/javascripts/ckeditor/plugins/codemirror/lang/zh.js +0 -12
@@ -0,0 +1,2087 @@
1
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
2
+ /*
3
+
4
+ The MIT License (MIT)
5
+
6
+ Copyright (c) 2007-2013 Einar Lielmanis and contributors.
7
+
8
+ Permission is hereby granted, free of charge, to any person
9
+ obtaining a copy of this software and associated documentation files
10
+ (the "Software"), to deal in the Software without restriction,
11
+ including without limitation the rights to use, copy, modify, merge,
12
+ publish, distribute, sublicense, and/or sell copies of the Software,
13
+ and to permit persons to whom the Software is furnished to do so,
14
+ subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ JS Beautifier
29
+ ---------------
30
+
31
+
32
+ Written by Einar Lielmanis, <einar@jsbeautifier.org>
33
+ http://jsbeautifier.org/
34
+
35
+ Originally converted to javascript by Vital, <vital76@gmail.com>
36
+ "End braces on own line" added by Chris J. Shull, <chrisjshull@gmail.com>
37
+ Parsing improvements for brace-less statements by Liam Newman <bitwiseman@gmail.com>
38
+
39
+
40
+ Usage:
41
+ js_beautify(js_source_text);
42
+ js_beautify(js_source_text, options);
43
+
44
+ The options are:
45
+ indent_size (default 4) - indentation size,
46
+ indent_char (default space) - character to indent with,
47
+ preserve_newlines (default true) - whether existing line breaks should be preserved,
48
+ max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
49
+
50
+ jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
51
+
52
+ jslint_happy !jslint_happy
53
+ ---------------------------------
54
+ function () function()
55
+
56
+ switch () { switch() {
57
+ case 1: case 1:
58
+ break; break;
59
+ } }
60
+
61
+ space_after_anon_function (default false) - should the space before an anonymous function's parens be added, "function()" vs "function ()",
62
+ NOTE: This option is overriden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)
63
+
64
+ brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none"
65
+ put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are.
66
+
67
+ space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
68
+
69
+ unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
70
+
71
+ wrap_line_length (default unlimited) - lines should wrap at next opportunity after this number of characters.
72
+ NOTE: This is not a hard limit. Lines will continue until a point where a newline would
73
+ be preserved if it were present.
74
+
75
+ end_with_newline (default false) - end output with a newline
76
+
77
+
78
+ e.g
79
+
80
+ js_beautify(js_source_text, {
81
+ 'indent_size': 1,
82
+ 'indent_char': '\t'
83
+ });
84
+
85
+ */
86
+
87
+ (function() {
88
+
89
+ var acorn = {};
90
+ (function (exports) {
91
+ // This section of code is taken from acorn.
92
+ //
93
+ // Acorn was written by Marijn Haverbeke and released under an MIT
94
+ // license. The Unicode regexps (for identifiers and whitespace) were
95
+ // taken from [Esprima](http://esprima.org) by Ariya Hidayat.
96
+ //
97
+ // Git repositories for Acorn are available at
98
+ //
99
+ // http://marijnhaverbeke.nl/git/acorn
100
+ // https://github.com/marijnh/acorn.git
101
+
102
+ // ## Character categories
103
+
104
+ // Big ugly regular expressions that match characters in the
105
+ // whitespace, identifier, and identifier-start categories. These
106
+ // are only applied when a character is found to actually have a
107
+ // code point above 128.
108
+
109
+ var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
110
+ var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
111
+ var nonASCIIidentifierChars = "\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df-\u09e0\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5f-\u0b60\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62-\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2-\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d46-\u0d48\u0d57\u0d62-\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e34-\u0e3a\u0e40-\u0e45\u0e50-\u0e59\u0eb4-\u0eb9\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f41-\u0f47\u0f71-\u0f84\u0f86-\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u1029\u1040-\u1049\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u170e-\u1710\u1720-\u1730\u1740-\u1750\u1772\u1773\u1780-\u17b2\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u1920-\u192b\u1930-\u193b\u1951-\u196d\u19b0-\u19c0\u19c8-\u19c9\u19d0-\u19d9\u1a00-\u1a15\u1a20-\u1a53\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b46-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1bb0-\u1bb9\u1be6-\u1bf3\u1c00-\u1c22\u1c40-\u1c49\u1c5b-\u1c7d\u1cd0-\u1cd2\u1d00-\u1dbe\u1e01-\u1f15\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2d81-\u2d96\u2de0-\u2dff\u3021-\u3028\u3099\u309a\ua640-\ua66d\ua674-\ua67d\ua69f\ua6f0-\ua6f1\ua7f8-\ua800\ua806\ua80b\ua823-\ua827\ua880-\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8f3-\ua8f7\ua900-\ua909\ua926-\ua92d\ua930-\ua945\ua980-\ua983\ua9b3-\ua9c0\uaa00-\uaa27\uaa40-\uaa41\uaa4c-\uaa4d\uaa50-\uaa59\uaa7b\uaae0-\uaae9\uaaf2-\uaaf3\uabc0-\uabe1\uabec\uabed\uabf0-\uabf9\ufb20-\ufb28\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
112
+ var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
113
+ var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
114
+
115
+ // Whether a single character denotes a newline.
116
+
117
+ var newline = exports.newline = /[\n\r\u2028\u2029]/;
118
+
119
+ // Matches a whole line break (where CRLF is considered a single
120
+ // line break). Used to count lines.
121
+
122
+ var lineBreak = exports.lineBreak = /\r\n|[\n\r\u2028\u2029]/g;
123
+
124
+ // Test whether a given character code starts an identifier.
125
+
126
+ var isIdentifierStart = exports.isIdentifierStart = function(code) {
127
+ if (code < 65) return code === 36;
128
+ if (code < 91) return true;
129
+ if (code < 97) return code === 95;
130
+ if (code < 123)return true;
131
+ return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
132
+ };
133
+
134
+ // Test whether a given character is part of an identifier.
135
+
136
+ var isIdentifierChar = exports.isIdentifierChar = function(code) {
137
+ if (code < 48) return code === 36;
138
+ if (code < 58) return true;
139
+ if (code < 65) return false;
140
+ if (code < 91) return true;
141
+ if (code < 97) return code === 95;
142
+ if (code < 123)return true;
143
+ return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
144
+ };
145
+ })(acorn);
146
+
147
+ function in_array(what, arr) {
148
+ for (var i = 0; i < arr.length; i += 1) {
149
+ if (arr[i] === what) {
150
+ return true;
151
+ }
152
+ }
153
+ return false;
154
+ }
155
+
156
+ function trim(s) {
157
+ return s.replace(/^\s+|\s+$/g, '');
158
+ }
159
+
160
+ function ltrim(s) {
161
+ return s.replace(/^\s+/g, '');
162
+ }
163
+
164
+ function rtrim(s) {
165
+ return s.replace(/\s+$/g, '');
166
+ }
167
+
168
+ function js_beautify(js_source_text, options) {
169
+ "use strict";
170
+ var beautifier = new Beautifier(js_source_text, options);
171
+ return beautifier.beautify();
172
+ }
173
+
174
+ var MODE = {
175
+ BlockStatement: 'BlockStatement', // 'BLOCK'
176
+ Statement: 'Statement', // 'STATEMENT'
177
+ ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
178
+ ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
179
+ ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
180
+ Conditional: 'Conditional', //'(COND-EXPRESSION)',
181
+ Expression: 'Expression' //'(EXPRESSION)'
182
+ };
183
+
184
+ function Beautifier(js_source_text, options) {
185
+ "use strict";
186
+ var output
187
+ var tokens = [], token_pos;
188
+ var Tokenizer;
189
+ var current_token;
190
+ var last_type, last_last_text, indent_string;
191
+ var flags, previous_flags, flag_store;
192
+ var prefix;
193
+
194
+ var handlers, opt;
195
+ var baseIndentString = '';
196
+
197
+ handlers = {
198
+ 'TK_START_EXPR': handle_start_expr,
199
+ 'TK_END_EXPR': handle_end_expr,
200
+ 'TK_START_BLOCK': handle_start_block,
201
+ 'TK_END_BLOCK': handle_end_block,
202
+ 'TK_WORD': handle_word,
203
+ 'TK_RESERVED': handle_word,
204
+ 'TK_SEMICOLON': handle_semicolon,
205
+ 'TK_STRING': handle_string,
206
+ 'TK_EQUALS': handle_equals,
207
+ 'TK_OPERATOR': handle_operator,
208
+ 'TK_COMMA': handle_comma,
209
+ 'TK_BLOCK_COMMENT': handle_block_comment,
210
+ 'TK_COMMENT': handle_comment,
211
+ 'TK_DOT': handle_dot,
212
+ 'TK_UNKNOWN': handle_unknown,
213
+ 'TK_EOF': handle_eof
214
+ };
215
+
216
+ function create_flags(flags_base, mode) {
217
+ var next_indent_level = 0;
218
+ if (flags_base) {
219
+ next_indent_level = flags_base.indentation_level;
220
+ if (!output.just_added_newline() &&
221
+ flags_base.line_indent_level > next_indent_level) {
222
+ next_indent_level = flags_base.line_indent_level;
223
+ }
224
+ }
225
+
226
+ var next_flags = {
227
+ mode: mode,
228
+ parent: flags_base,
229
+ last_text: flags_base ? flags_base.last_text : '', // last token text
230
+ last_word: flags_base ? flags_base.last_word : '', // last 'TK_WORD' passed
231
+ declaration_statement: false,
232
+ declaration_assignment: false,
233
+ multiline_frame: false,
234
+ if_block: false,
235
+ else_block: false,
236
+ do_block: false,
237
+ do_while: false,
238
+ in_case_statement: false, // switch(..){ INSIDE HERE }
239
+ in_case: false, // we're on the exact line with "case 0:"
240
+ case_body: false, // the indented case-action block
241
+ indentation_level: next_indent_level,
242
+ line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
243
+ start_line_index: output.get_line_number(),
244
+ ternary_depth: 0
245
+ };
246
+ return next_flags;
247
+ }
248
+
249
+ // Some interpreters have unexpected results with foo = baz || bar;
250
+ options = options ? options : {};
251
+ opt = {};
252
+
253
+ // compatibility
254
+ if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
255
+ opt.brace_style = options.braces_on_own_line ? "expand" : "collapse";
256
+ }
257
+ opt.brace_style = options.brace_style ? options.brace_style : (opt.brace_style ? opt.brace_style : "collapse");
258
+
259
+ // graceful handling of deprecated option
260
+ if (opt.brace_style === "expand-strict") {
261
+ opt.brace_style = "expand";
262
+ }
263
+
264
+
265
+ opt.indent_size = options.indent_size ? parseInt(options.indent_size, 10) : 4;
266
+ opt.indent_char = options.indent_char ? options.indent_char : ' ';
267
+ opt.eol = options.eol ? options.eol : '\n';
268
+ opt.preserve_newlines = (options.preserve_newlines === undefined) ? true : options.preserve_newlines;
269
+ opt.break_chained_methods = (options.break_chained_methods === undefined) ? false : options.break_chained_methods;
270
+ opt.max_preserve_newlines = (options.max_preserve_newlines === undefined) ? 0 : parseInt(options.max_preserve_newlines, 10);
271
+ opt.space_in_paren = (options.space_in_paren === undefined) ? false : options.space_in_paren;
272
+ opt.space_in_empty_paren = (options.space_in_empty_paren === undefined) ? false : options.space_in_empty_paren;
273
+ opt.jslint_happy = (options.jslint_happy === undefined) ? false : options.jslint_happy;
274
+ opt.space_after_anon_function = (options.space_after_anon_function === undefined) ? false : options.space_after_anon_function;
275
+ opt.keep_array_indentation = (options.keep_array_indentation === undefined) ? false : options.keep_array_indentation;
276
+ opt.space_before_conditional = (options.space_before_conditional === undefined) ? true : options.space_before_conditional;
277
+ opt.unescape_strings = (options.unescape_strings === undefined) ? false : options.unescape_strings;
278
+ opt.wrap_line_length = (options.wrap_line_length === undefined) ? 0 : parseInt(options.wrap_line_length, 10);
279
+ opt.e4x = (options.e4x === undefined) ? false : options.e4x;
280
+ opt.end_with_newline = (options.end_with_newline === undefined) ? false : options.end_with_newline;
281
+ opt.comma_first = (options.comma_first === undefined) ? false : options.comma_first;
282
+
283
+ // For testing of beautify ignore:start directive
284
+ opt.test_output_raw = (options.test_output_raw === undefined) ? false : options.test_output_raw;
285
+
286
+ // force opt.space_after_anon_function to true if opt.jslint_happy
287
+ if(opt.jslint_happy) {
288
+ opt.space_after_anon_function = true;
289
+ }
290
+
291
+ if(options.indent_with_tabs){
292
+ opt.indent_char = '\t';
293
+ opt.indent_size = 1;
294
+ }
295
+
296
+ opt.eol = opt.eol.replace(/\\r/, '\r').replace(/\\n/, '\n')
297
+
298
+ //----------------------------------
299
+ indent_string = '';
300
+ while (opt.indent_size > 0) {
301
+ indent_string += opt.indent_char;
302
+ opt.indent_size -= 1;
303
+ }
304
+
305
+ var preindent_index = 0;
306
+ if(js_source_text && js_source_text.length) {
307
+ while ( (js_source_text.charAt(preindent_index) === ' ' ||
308
+ js_source_text.charAt(preindent_index) === '\t')) {
309
+ baseIndentString += js_source_text.charAt(preindent_index);
310
+ preindent_index += 1;
311
+ }
312
+ js_source_text = js_source_text.substring(preindent_index);
313
+ }
314
+
315
+ last_type = 'TK_START_BLOCK'; // last token type
316
+ last_last_text = ''; // pre-last token text
317
+ output = new Output(indent_string, baseIndentString);
318
+
319
+ // If testing the ignore directive, start with output disable set to true
320
+ output.raw = opt.test_output_raw;
321
+
322
+
323
+ // Stack of parsing/formatting states, including MODE.
324
+ // We tokenize, parse, and output in an almost purely a forward-only stream of token input
325
+ // and formatted output. This makes the beautifier less accurate than full parsers
326
+ // but also far more tolerant of syntax errors.
327
+ //
328
+ // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
329
+ // MODE.BlockStatement on the the stack, even though it could be object literal. If we later
330
+ // encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";",
331
+ // most full parsers would die, but the beautifier gracefully falls back to
332
+ // MODE.BlockStatement and continues on.
333
+ flag_store = [];
334
+ set_mode(MODE.BlockStatement);
335
+
336
+ this.beautify = function() {
337
+
338
+ /*jshint onevar:true */
339
+ var local_token, sweet_code;
340
+ Tokenizer = new tokenizer(js_source_text, opt, indent_string);
341
+ tokens = Tokenizer.tokenize();
342
+ token_pos = 0;
343
+
344
+ while (local_token = get_token()) {
345
+ for(var i = 0; i < local_token.comments_before.length; i++) {
346
+ // The cleanest handling of inline comments is to treat them as though they aren't there.
347
+ // Just continue formatting and the behavior should be logical.
348
+ // Also ignore unknown tokens. Again, this should result in better behavior.
349
+ handle_token(local_token.comments_before[i]);
350
+ }
351
+ handle_token(local_token);
352
+
353
+ last_last_text = flags.last_text;
354
+ last_type = local_token.type;
355
+ flags.last_text = local_token.text;
356
+
357
+ token_pos += 1;
358
+ }
359
+
360
+ sweet_code = output.get_code();
361
+ if (opt.end_with_newline) {
362
+ sweet_code += '\n';
363
+ }
364
+
365
+ if (opt.eol != '\n') {
366
+ sweet_code = sweet_code.replace(/[\n]/g, opt.eol);
367
+ }
368
+
369
+ return sweet_code;
370
+ };
371
+
372
+ function handle_token(local_token) {
373
+ var newlines = local_token.newlines;
374
+ var keep_whitespace = opt.keep_array_indentation && is_array(flags.mode);
375
+
376
+ if (keep_whitespace) {
377
+ for (i = 0; i < newlines; i += 1) {
378
+ print_newline(i > 0);
379
+ }
380
+ } else {
381
+ if (opt.max_preserve_newlines && newlines > opt.max_preserve_newlines) {
382
+ newlines = opt.max_preserve_newlines;
383
+ }
384
+
385
+ if (opt.preserve_newlines) {
386
+ if (local_token.newlines > 1) {
387
+ print_newline();
388
+ for (var i = 1; i < newlines; i += 1) {
389
+ print_newline(true);
390
+ }
391
+ }
392
+ }
393
+ }
394
+
395
+ current_token = local_token;
396
+ handlers[current_token.type]();
397
+ }
398
+
399
+ // we could use just string.split, but
400
+ // IE doesn't like returning empty strings
401
+ function split_newlines(s) {
402
+ //return s.split(/\x0d\x0a|\x0a/);
403
+
404
+ s = s.replace(/\x0d/g, '');
405
+ var out = [],
406
+ idx = s.indexOf("\n");
407
+ while (idx !== -1) {
408
+ out.push(s.substring(0, idx));
409
+ s = s.substring(idx + 1);
410
+ idx = s.indexOf("\n");
411
+ }
412
+ if (s.length) {
413
+ out.push(s);
414
+ }
415
+ return out;
416
+ }
417
+
418
+ function allow_wrap_or_preserved_newline(force_linewrap) {
419
+ force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
420
+
421
+ // Never wrap the first token on a line
422
+ if (output.just_added_newline()) {
423
+ return
424
+ }
425
+
426
+ if ((opt.preserve_newlines && current_token.wanted_newline) || force_linewrap) {
427
+ print_newline(false, true);
428
+ } else if (opt.wrap_line_length) {
429
+ var proposed_line_length = output.current_line.get_character_count() + current_token.text.length +
430
+ (output.space_before_token ? 1 : 0);
431
+ if (proposed_line_length >= opt.wrap_line_length) {
432
+ print_newline(false, true);
433
+ }
434
+ }
435
+ }
436
+
437
+ function print_newline(force_newline, preserve_statement_flags) {
438
+ if (!preserve_statement_flags) {
439
+ if (flags.last_text !== ';' && flags.last_text !== ',' && flags.last_text !== '=' && last_type !== 'TK_OPERATOR') {
440
+ while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {
441
+ restore_mode();
442
+ }
443
+ }
444
+ }
445
+
446
+ if (output.add_new_line(force_newline)) {
447
+ flags.multiline_frame = true;
448
+ }
449
+ }
450
+
451
+ function print_token_line_indentation() {
452
+ if (output.just_added_newline()) {
453
+ if (opt.keep_array_indentation && is_array(flags.mode) && current_token.wanted_newline) {
454
+ output.current_line.push(current_token.whitespace_before);
455
+ output.space_before_token = false;
456
+ } else if (output.set_indent(flags.indentation_level)) {
457
+ flags.line_indent_level = flags.indentation_level;
458
+ }
459
+ }
460
+ }
461
+
462
+ function print_token(printable_token) {
463
+ if (output.raw) {
464
+ output.add_raw_token(current_token)
465
+ return;
466
+ }
467
+
468
+ if (opt.comma_first && last_type === 'TK_COMMA'
469
+ && output.just_added_newline()) {
470
+ if(output.previous_line.last() === ',') {
471
+ output.previous_line.pop();
472
+ print_token_line_indentation();
473
+ output.add_token(',');
474
+ output.space_before_token = true;
475
+ }
476
+ }
477
+
478
+ printable_token = printable_token || current_token.text;
479
+ print_token_line_indentation();
480
+ output.add_token(printable_token);
481
+ }
482
+
483
+ function indent() {
484
+ flags.indentation_level += 1;
485
+ }
486
+
487
+ function deindent() {
488
+ if (flags.indentation_level > 0 &&
489
+ ((!flags.parent) || flags.indentation_level > flags.parent.indentation_level))
490
+ flags.indentation_level -= 1;
491
+ }
492
+
493
+ function set_mode(mode) {
494
+ if (flags) {
495
+ flag_store.push(flags);
496
+ previous_flags = flags;
497
+ } else {
498
+ previous_flags = create_flags(null, mode);
499
+ }
500
+
501
+ flags = create_flags(previous_flags, mode);
502
+ }
503
+
504
+ function is_array(mode) {
505
+ return mode === MODE.ArrayLiteral;
506
+ }
507
+
508
+ function is_expression(mode) {
509
+ return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
510
+ }
511
+
512
+ function restore_mode() {
513
+ if (flag_store.length > 0) {
514
+ previous_flags = flags;
515
+ flags = flag_store.pop();
516
+ if (previous_flags.mode === MODE.Statement) {
517
+ output.remove_redundant_indentation(previous_flags);
518
+ }
519
+ }
520
+ }
521
+
522
+ function start_of_object_property() {
523
+ return flags.parent.mode === MODE.ObjectLiteral && flags.mode === MODE.Statement && (
524
+ (flags.last_text === ':' && flags.ternary_depth === 0) || (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['get', 'set'])));
525
+ }
526
+
527
+ function start_of_statement() {
528
+ if (
529
+ (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const']) && current_token.type === 'TK_WORD') ||
530
+ (last_type === 'TK_RESERVED' && flags.last_text === 'do') ||
531
+ (last_type === 'TK_RESERVED' && flags.last_text === 'return' && !current_token.wanted_newline) ||
532
+ (last_type === 'TK_RESERVED' && flags.last_text === 'else' && !(current_token.type === 'TK_RESERVED' && current_token.text === 'if')) ||
533
+ (last_type === 'TK_END_EXPR' && (previous_flags.mode === MODE.ForInitializer || previous_flags.mode === MODE.Conditional)) ||
534
+ (last_type === 'TK_WORD' && flags.mode === MODE.BlockStatement
535
+ && !flags.in_case
536
+ && !(current_token.text === '--' || current_token.text === '++')
537
+ && last_last_text !== 'function'
538
+ && current_token.type !== 'TK_WORD' && current_token.type !== 'TK_RESERVED') ||
539
+ (flags.mode === MODE.ObjectLiteral && (
540
+ (flags.last_text === ':' && flags.ternary_depth === 0) || (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['get', 'set']))))
541
+ ) {
542
+
543
+ set_mode(MODE.Statement);
544
+ indent();
545
+
546
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const']) && current_token.type === 'TK_WORD') {
547
+ flags.declaration_statement = true;
548
+ }
549
+
550
+ // Issue #276:
551
+ // If starting a new statement with [if, for, while, do], push to a new line.
552
+ // if (a) if (b) if(c) d(); else e(); else f();
553
+ if (!start_of_object_property()) {
554
+ allow_wrap_or_preserved_newline(
555
+ current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['do', 'for', 'if', 'while']));
556
+ }
557
+
558
+ return true;
559
+ }
560
+ return false;
561
+ }
562
+
563
+ function all_lines_start_with(lines, c) {
564
+ for (var i = 0; i < lines.length; i++) {
565
+ var line = trim(lines[i]);
566
+ if (line.charAt(0) !== c) {
567
+ return false;
568
+ }
569
+ }
570
+ return true;
571
+ }
572
+
573
+ function each_line_matches_indent(lines, indent) {
574
+ var i = 0,
575
+ len = lines.length,
576
+ line;
577
+ for (; i < len; i++) {
578
+ line = lines[i];
579
+ // allow empty lines to pass through
580
+ if (line && line.indexOf(indent) !== 0) {
581
+ return false;
582
+ }
583
+ }
584
+ return true;
585
+ }
586
+
587
+ function is_special_word(word) {
588
+ return in_array(word, ['case', 'return', 'do', 'if', 'throw', 'else']);
589
+ }
590
+
591
+ function get_token(offset) {
592
+ var index = token_pos + (offset || 0);
593
+ return (index < 0 || index >= tokens.length) ? null : tokens[index];
594
+ }
595
+
596
+ function handle_start_expr() {
597
+ if (start_of_statement()) {
598
+ // The conditional starts the statement if appropriate.
599
+ }
600
+
601
+ var next_mode = MODE.Expression;
602
+ if (current_token.text === '[') {
603
+
604
+ if (last_type === 'TK_WORD' || flags.last_text === ')') {
605
+ // this is array index specifier, break immediately
606
+ // a[x], fn()[x]
607
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, Tokenizer.line_starters)) {
608
+ output.space_before_token = true;
609
+ }
610
+ set_mode(next_mode);
611
+ print_token();
612
+ indent();
613
+ if (opt.space_in_paren) {
614
+ output.space_before_token = true;
615
+ }
616
+ return;
617
+ }
618
+
619
+ next_mode = MODE.ArrayLiteral;
620
+ if (is_array(flags.mode)) {
621
+ if (flags.last_text === '[' ||
622
+ (flags.last_text === ',' && (last_last_text === ']' || last_last_text === '}'))) {
623
+ // ], [ goes to new line
624
+ // }, [ goes to new line
625
+ if (!opt.keep_array_indentation) {
626
+ print_newline();
627
+ }
628
+ }
629
+ }
630
+
631
+ } else {
632
+ if (last_type === 'TK_RESERVED' && flags.last_text === 'for') {
633
+ next_mode = MODE.ForInitializer;
634
+ } else if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['if', 'while'])) {
635
+ next_mode = MODE.Conditional;
636
+ } else {
637
+ // next_mode = MODE.Expression;
638
+ }
639
+ }
640
+
641
+ if (flags.last_text === ';' || last_type === 'TK_START_BLOCK') {
642
+ print_newline();
643
+ } else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || flags.last_text === '.') {
644
+ // TODO: Consider whether forcing this is required. Review failing tests when removed.
645
+ allow_wrap_or_preserved_newline(current_token.wanted_newline);
646
+ // do nothing on (( and )( and ][ and ]( and .(
647
+ } else if (!(last_type === 'TK_RESERVED' && current_token.text === '(') && last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
648
+ output.space_before_token = true;
649
+ } else if ((last_type === 'TK_RESERVED' && (flags.last_word === 'function' || flags.last_word === 'typeof')) ||
650
+ (flags.last_text === '*' && last_last_text === 'function')) {
651
+ // function() vs function ()
652
+ if (opt.space_after_anon_function) {
653
+ output.space_before_token = true;
654
+ }
655
+ } else if (last_type === 'TK_RESERVED' && (in_array(flags.last_text, Tokenizer.line_starters) || flags.last_text === 'catch')) {
656
+ if (opt.space_before_conditional) {
657
+ output.space_before_token = true;
658
+ }
659
+ }
660
+
661
+ // Should be a space between await and an IIFE
662
+ if(current_token.text === '(' && last_type === 'TK_RESERVED' && flags.last_word === 'await'){
663
+ output.space_before_token = true;
664
+ }
665
+
666
+ // Support of this kind of newline preservation.
667
+ // a = (b &&
668
+ // (c || d));
669
+ if (current_token.text === '(') {
670
+ if (last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
671
+ if (!start_of_object_property()) {
672
+ allow_wrap_or_preserved_newline();
673
+ }
674
+ }
675
+ }
676
+
677
+ set_mode(next_mode);
678
+ print_token();
679
+ if (opt.space_in_paren) {
680
+ output.space_before_token = true;
681
+ }
682
+
683
+ // In all cases, if we newline while inside an expression it should be indented.
684
+ indent();
685
+ }
686
+
687
+ function handle_end_expr() {
688
+ // statements inside expressions are not valid syntax, but...
689
+ // statements must all be closed when their container closes
690
+ while (flags.mode === MODE.Statement) {
691
+ restore_mode();
692
+ }
693
+
694
+ if (flags.multiline_frame) {
695
+ allow_wrap_or_preserved_newline(current_token.text === ']' && is_array(flags.mode) && !opt.keep_array_indentation);
696
+ }
697
+
698
+ if (opt.space_in_paren) {
699
+ if (last_type === 'TK_START_EXPR' && ! opt.space_in_empty_paren) {
700
+ // () [] no inner space in empty parens like these, ever, ref #320
701
+ output.trim();
702
+ output.space_before_token = false;
703
+ } else {
704
+ output.space_before_token = true;
705
+ }
706
+ }
707
+ if (current_token.text === ']' && opt.keep_array_indentation) {
708
+ print_token();
709
+ restore_mode();
710
+ } else {
711
+ restore_mode();
712
+ print_token();
713
+ }
714
+ output.remove_redundant_indentation(previous_flags);
715
+
716
+ // do {} while () // no statement required after
717
+ if (flags.do_while && previous_flags.mode === MODE.Conditional) {
718
+ previous_flags.mode = MODE.Expression;
719
+ flags.do_block = false;
720
+ flags.do_while = false;
721
+
722
+ }
723
+ }
724
+
725
+ function handle_start_block() {
726
+ // Check if this is should be treated as a ObjectLiteral
727
+ var next_token = get_token(1)
728
+ var second_token = get_token(2)
729
+ if (second_token && (
730
+ (second_token.text === ':' && in_array(next_token.type, ['TK_STRING', 'TK_WORD', 'TK_RESERVED']))
731
+ || (in_array(next_token.text, ['get', 'set']) && in_array(second_token.type, ['TK_WORD', 'TK_RESERVED']))
732
+ )) {
733
+ // We don't support TypeScript,but we didn't break it for a very long time.
734
+ // We'll try to keep not breaking it.
735
+ if (!in_array(last_last_text, ['class','interface'])) {
736
+ set_mode(MODE.ObjectLiteral);
737
+ } else {
738
+ set_mode(MODE.BlockStatement);
739
+ }
740
+ } else {
741
+ set_mode(MODE.BlockStatement);
742
+ }
743
+
744
+ var empty_braces = !next_token.comments_before.length && next_token.text === '}';
745
+ var empty_anonymous_function = empty_braces && flags.last_word === 'function' &&
746
+ last_type === 'TK_END_EXPR';
747
+
748
+ if (opt.brace_style === "expand" ||
749
+ (opt.brace_style === "none" && current_token.wanted_newline)) {
750
+ if (last_type !== 'TK_OPERATOR' &&
751
+ (empty_anonymous_function ||
752
+ last_type === 'TK_EQUALS' ||
753
+ (last_type === 'TK_RESERVED' && is_special_word(flags.last_text) && flags.last_text !== 'else'))) {
754
+ output.space_before_token = true;
755
+ } else {
756
+ print_newline(false, true);
757
+ }
758
+ } else { // collapse
759
+ if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
760
+ if (last_type === 'TK_START_BLOCK') {
761
+ print_newline();
762
+ } else {
763
+ output.space_before_token = true;
764
+ }
765
+ } else {
766
+ // if TK_OPERATOR or TK_START_EXPR
767
+ if (is_array(previous_flags.mode) && flags.last_text === ',') {
768
+ if (last_last_text === '}') {
769
+ // }, { in array context
770
+ output.space_before_token = true;
771
+ } else {
772
+ print_newline(); // [a, b, c, {
773
+ }
774
+ }
775
+ }
776
+ }
777
+ print_token();
778
+ indent();
779
+ }
780
+
781
+ function handle_end_block() {
782
+ // statements must all be closed when their container closes
783
+ while (flags.mode === MODE.Statement) {
784
+ restore_mode();
785
+ }
786
+ var empty_braces = last_type === 'TK_START_BLOCK';
787
+
788
+ if (opt.brace_style === "expand") {
789
+ if (!empty_braces) {
790
+ print_newline();
791
+ }
792
+ } else {
793
+ // skip {}
794
+ if (!empty_braces) {
795
+ if (is_array(flags.mode) && opt.keep_array_indentation) {
796
+ // we REALLY need a newline here, but newliner would skip that
797
+ opt.keep_array_indentation = false;
798
+ print_newline();
799
+ opt.keep_array_indentation = true;
800
+
801
+ } else {
802
+ print_newline();
803
+ }
804
+ }
805
+ }
806
+ restore_mode();
807
+ print_token();
808
+ }
809
+
810
+ function handle_word() {
811
+ if (current_token.type === 'TK_RESERVED' && flags.mode !== MODE.ObjectLiteral &&
812
+ in_array(current_token.text, ['set', 'get'])) {
813
+ current_token.type = 'TK_WORD';
814
+ }
815
+
816
+ if (current_token.type === 'TK_RESERVED' && flags.mode === MODE.ObjectLiteral) {
817
+ var next_token = get_token(1);
818
+ if (next_token.text == ':') {
819
+ current_token.type = 'TK_WORD';
820
+ }
821
+ }
822
+
823
+ if (start_of_statement()) {
824
+ // The conditional starts the statement if appropriate.
825
+ } else if (current_token.wanted_newline && !is_expression(flags.mode) &&
826
+ (last_type !== 'TK_OPERATOR' || (flags.last_text === '--' || flags.last_text === '++')) &&
827
+ last_type !== 'TK_EQUALS' &&
828
+ (opt.preserve_newlines || !(last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const', 'set', 'get'])))) {
829
+
830
+ print_newline();
831
+ }
832
+
833
+ if (flags.do_block && !flags.do_while) {
834
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'while') {
835
+ // do {} ## while ()
836
+ output.space_before_token = true;
837
+ print_token();
838
+ output.space_before_token = true;
839
+ flags.do_while = true;
840
+ return;
841
+ } else {
842
+ // do {} should always have while as the next word.
843
+ // if we don't see the expected while, recover
844
+ print_newline();
845
+ flags.do_block = false;
846
+ }
847
+ }
848
+
849
+ // if may be followed by else, or not
850
+ // Bare/inline ifs are tricky
851
+ // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
852
+ if (flags.if_block) {
853
+ if (!flags.else_block && (current_token.type === 'TK_RESERVED' && current_token.text === 'else')) {
854
+ flags.else_block = true;
855
+ } else {
856
+ while (flags.mode === MODE.Statement) {
857
+ restore_mode();
858
+ }
859
+ flags.if_block = false;
860
+ flags.else_block = false;
861
+ }
862
+ }
863
+
864
+ if (current_token.type === 'TK_RESERVED' && (current_token.text === 'case' || (current_token.text === 'default' && flags.in_case_statement))) {
865
+ print_newline();
866
+ if (flags.case_body || opt.jslint_happy) {
867
+ // switch cases following one another
868
+ deindent();
869
+ flags.case_body = false;
870
+ }
871
+ print_token();
872
+ flags.in_case = true;
873
+ flags.in_case_statement = true;
874
+ return;
875
+ }
876
+
877
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'function') {
878
+ if (in_array(flags.last_text, ['}', ';']) || (output.just_added_newline() && ! in_array(flags.last_text, ['[', '{', ':', '=', ',']))) {
879
+ // make sure there is a nice clean space of at least one blank line
880
+ // before a new function definition
881
+ if ( !output.just_added_blankline() && !current_token.comments_before.length) {
882
+ print_newline();
883
+ print_newline(true);
884
+ }
885
+ }
886
+ if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD') {
887
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['get', 'set', 'new', 'return', 'export', 'async'])) {
888
+ output.space_before_token = true;
889
+ } else if (last_type === 'TK_RESERVED' && flags.last_text === 'default' && last_last_text === 'export') {
890
+ output.space_before_token = true;
891
+ } else {
892
+ print_newline();
893
+ }
894
+ } else if (last_type === 'TK_OPERATOR' || flags.last_text === '=') {
895
+ // foo = function
896
+ output.space_before_token = true;
897
+ } else if (!flags.multiline_frame && (is_expression(flags.mode) || is_array(flags.mode))) {
898
+ // (function
899
+ } else {
900
+ print_newline();
901
+ }
902
+ }
903
+
904
+ if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
905
+ if (!start_of_object_property()) {
906
+ allow_wrap_or_preserved_newline();
907
+ }
908
+ }
909
+
910
+ if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['function', 'get', 'set'])) {
911
+ print_token();
912
+ flags.last_word = current_token.text;
913
+ return;
914
+ }
915
+
916
+ prefix = 'NONE';
917
+
918
+ if (last_type === 'TK_END_BLOCK') {
919
+ if (!(current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['else', 'catch', 'finally']))) {
920
+ prefix = 'NEWLINE';
921
+ } else {
922
+ if (opt.brace_style === "expand" ||
923
+ opt.brace_style === "end-expand" ||
924
+ (opt.brace_style === "none" && current_token.wanted_newline)) {
925
+ prefix = 'NEWLINE';
926
+ } else {
927
+ prefix = 'SPACE';
928
+ output.space_before_token = true;
929
+ }
930
+ }
931
+ } else if (last_type === 'TK_SEMICOLON' && flags.mode === MODE.BlockStatement) {
932
+ // TODO: Should this be for STATEMENT as well?
933
+ prefix = 'NEWLINE';
934
+ } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) {
935
+ prefix = 'SPACE';
936
+ } else if (last_type === 'TK_STRING') {
937
+ prefix = 'NEWLINE';
938
+ } else if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD' ||
939
+ (flags.last_text === '*' && last_last_text === 'function')) {
940
+ prefix = 'SPACE';
941
+ } else if (last_type === 'TK_START_BLOCK') {
942
+ prefix = 'NEWLINE';
943
+ } else if (last_type === 'TK_END_EXPR') {
944
+ output.space_before_token = true;
945
+ prefix = 'NEWLINE';
946
+ }
947
+
948
+ if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, Tokenizer.line_starters) && flags.last_text !== ')') {
949
+ if (flags.last_text === 'else' || flags.last_text === 'export') {
950
+ prefix = 'SPACE';
951
+ } else {
952
+ prefix = 'NEWLINE';
953
+ }
954
+
955
+ }
956
+
957
+ if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['else', 'catch', 'finally'])) {
958
+ if (last_type !== 'TK_END_BLOCK' ||
959
+ opt.brace_style === "expand" ||
960
+ opt.brace_style === "end-expand" ||
961
+ (opt.brace_style === "none" && current_token.wanted_newline)) {
962
+ print_newline();
963
+ } else {
964
+ output.trim(true);
965
+ var line = output.current_line;
966
+ // If we trimmed and there's something other than a close block before us
967
+ // put a newline back in. Handles '} // comment' scenario.
968
+ if (line.last() !== '}') {
969
+ print_newline();
970
+ }
971
+ output.space_before_token = true;
972
+ }
973
+ } else if (prefix === 'NEWLINE') {
974
+ if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
975
+ // no newline between 'return nnn'
976
+ output.space_before_token = true;
977
+ } else if (last_type !== 'TK_END_EXPR') {
978
+ if ((last_type !== 'TK_START_EXPR' || !(current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['var', 'let', 'const']))) && flags.last_text !== ':') {
979
+ // no need to force newline on 'var': for (var x = 0...)
980
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'if' && flags.last_text === 'else') {
981
+ // no newline for } else if {
982
+ output.space_before_token = true;
983
+ } else {
984
+ print_newline();
985
+ }
986
+ }
987
+ } else if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, Tokenizer.line_starters) && flags.last_text !== ')') {
988
+ print_newline();
989
+ }
990
+ } else if (flags.multiline_frame && is_array(flags.mode) && flags.last_text === ',' && last_last_text === '}') {
991
+ print_newline(); // }, in lists get a newline treatment
992
+ } else if (prefix === 'SPACE') {
993
+ output.space_before_token = true;
994
+ }
995
+ print_token();
996
+ flags.last_word = current_token.text;
997
+
998
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'do') {
999
+ flags.do_block = true;
1000
+ }
1001
+
1002
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'if') {
1003
+ flags.if_block = true;
1004
+ }
1005
+ }
1006
+
1007
+ function handle_semicolon() {
1008
+ if (start_of_statement()) {
1009
+ // The conditional starts the statement if appropriate.
1010
+ // Semicolon can be the start (and end) of a statement
1011
+ output.space_before_token = false;
1012
+ }
1013
+ while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {
1014
+ restore_mode();
1015
+ }
1016
+ print_token();
1017
+ }
1018
+
1019
+ function handle_string() {
1020
+ if (start_of_statement()) {
1021
+ // The conditional starts the statement if appropriate.
1022
+ // One difference - strings want at least a space before
1023
+ output.space_before_token = true;
1024
+ } else if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD') {
1025
+ output.space_before_token = true;
1026
+ } else if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
1027
+ if (!start_of_object_property()) {
1028
+ allow_wrap_or_preserved_newline();
1029
+ }
1030
+ } else {
1031
+ print_newline();
1032
+ }
1033
+ print_token();
1034
+ }
1035
+
1036
+ function handle_equals() {
1037
+ if (start_of_statement()) {
1038
+ // The conditional starts the statement if appropriate.
1039
+ }
1040
+
1041
+ if (flags.declaration_statement) {
1042
+ // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
1043
+ flags.declaration_assignment = true;
1044
+ }
1045
+ output.space_before_token = true;
1046
+ print_token();
1047
+ output.space_before_token = true;
1048
+ }
1049
+
1050
+ function handle_comma() {
1051
+ if (flags.declaration_statement) {
1052
+ if (is_expression(flags.parent.mode)) {
1053
+ // do not break on comma, for(var a = 1, b = 2)
1054
+ flags.declaration_assignment = false;
1055
+ }
1056
+
1057
+ print_token();
1058
+
1059
+ if (flags.declaration_assignment) {
1060
+ flags.declaration_assignment = false;
1061
+ print_newline(false, true);
1062
+ } else {
1063
+ output.space_before_token = true;
1064
+ // for comma-first, we want to allow a newline before the comma
1065
+ // to turn into a newline after the comma, which we will fixup later
1066
+ if (opt.comma_first) {
1067
+ allow_wrap_or_preserved_newline();
1068
+ }
1069
+ }
1070
+ return;
1071
+ }
1072
+
1073
+ print_token();
1074
+ if (flags.mode === MODE.ObjectLiteral ||
1075
+ (flags.mode === MODE.Statement && flags.parent.mode === MODE.ObjectLiteral)) {
1076
+ if (flags.mode === MODE.Statement) {
1077
+ restore_mode();
1078
+ }
1079
+ print_newline();
1080
+ } else {
1081
+ // EXPR or DO_BLOCK
1082
+ output.space_before_token = true;
1083
+ // for comma-first, we want to allow a newline before the comma
1084
+ // to turn into a newline after the comma, which we will fixup later
1085
+ if (opt.comma_first) {
1086
+ allow_wrap_or_preserved_newline();
1087
+ }
1088
+ }
1089
+
1090
+ }
1091
+
1092
+ function handle_operator() {
1093
+ if (start_of_statement()) {
1094
+ // The conditional starts the statement if appropriate.
1095
+ }
1096
+
1097
+ if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
1098
+ // "return" had a special handling in TK_WORD. Now we need to return the favor
1099
+ output.space_before_token = true;
1100
+ print_token();
1101
+ return;
1102
+ }
1103
+
1104
+ // hack for actionscript's import .*;
1105
+ if (current_token.text === '*' && last_type === 'TK_DOT') {
1106
+ print_token();
1107
+ return;
1108
+ }
1109
+
1110
+ if (current_token.text === ':' && flags.in_case) {
1111
+ flags.case_body = true;
1112
+ indent();
1113
+ print_token();
1114
+ print_newline();
1115
+ flags.in_case = false;
1116
+ return;
1117
+ }
1118
+
1119
+ if (current_token.text === '::') {
1120
+ // no spaces around exotic namespacing syntax operator
1121
+ print_token();
1122
+ return;
1123
+ }
1124
+
1125
+ // Allow line wrapping between operators
1126
+ if (last_type === 'TK_OPERATOR') {
1127
+ allow_wrap_or_preserved_newline();
1128
+ }
1129
+
1130
+ var space_before = true;
1131
+ var space_after = true;
1132
+
1133
+ if (in_array(current_token.text, ['--', '++', '!', '~']) || (in_array(current_token.text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) || in_array(flags.last_text, Tokenizer.line_starters) || flags.last_text === ','))) {
1134
+ // unary operators (and binary +/- pretending to be unary) special cases
1135
+
1136
+ space_before = false;
1137
+ space_after = false;
1138
+
1139
+ // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
1140
+ // if there is a newline between -- or ++ and anything else we should preserve it.
1141
+ if (current_token.wanted_newline && (current_token.text === '--' || current_token.text === '++')) {
1142
+ print_newline(false, true);
1143
+ }
1144
+
1145
+ if (flags.last_text === ';' && is_expression(flags.mode)) {
1146
+ // for (;; ++i)
1147
+ // ^^^
1148
+ space_before = true;
1149
+ }
1150
+
1151
+ if (last_type === 'TK_RESERVED') {
1152
+ space_before = true;
1153
+ } else if (last_type === 'TK_END_EXPR') {
1154
+ space_before = !(flags.last_text === ']' && (current_token.text === '--' || current_token.text === '++'));
1155
+ } else if (last_type === 'TK_OPERATOR') {
1156
+ // a++ + ++b;
1157
+ // a - -b
1158
+ space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(flags.last_text, ['--', '-', '++', '+']);
1159
+ // + and - are not unary when preceeded by -- or ++ operator
1160
+ // a-- + b
1161
+ // a * +b
1162
+ // a - -b
1163
+ if (in_array(current_token.text, ['+', '-']) && in_array(flags.last_text, ['--', '++'])) {
1164
+ space_after = true;
1165
+ }
1166
+ }
1167
+
1168
+ if ((flags.mode === MODE.BlockStatement || flags.mode === MODE.Statement) && (flags.last_text === '{' || flags.last_text === ';')) {
1169
+ // { foo; --i }
1170
+ // foo(); --bar;
1171
+ print_newline();
1172
+ }
1173
+ } else if (current_token.text === ':') {
1174
+ if (flags.ternary_depth === 0) {
1175
+ // Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.
1176
+ space_before = false;
1177
+ } else {
1178
+ flags.ternary_depth -= 1;
1179
+ }
1180
+ } else if (current_token.text === '?') {
1181
+ flags.ternary_depth += 1;
1182
+ } else if (current_token.text === '*' && last_type === 'TK_RESERVED' && flags.last_text === 'function') {
1183
+ space_before = false;
1184
+ space_after = false;
1185
+ }
1186
+ output.space_before_token = output.space_before_token || space_before;
1187
+ print_token();
1188
+ output.space_before_token = space_after;
1189
+ }
1190
+
1191
+ function handle_block_comment() {
1192
+ if (output.raw) {
1193
+ output.add_raw_token(current_token)
1194
+ if (current_token.directives && current_token.directives['preserve'] === 'end') {
1195
+ // If we're testing the raw output behavior, do not allow a directive to turn it off.
1196
+ if (!opt.test_output_raw) {
1197
+ output.raw = false;
1198
+ }
1199
+ }
1200
+ return;
1201
+ }
1202
+
1203
+ if (current_token.directives) {
1204
+ print_newline(false, true);
1205
+ print_token();
1206
+ if (current_token.directives['preserve'] === 'start') {
1207
+ output.raw = true;
1208
+ }
1209
+ print_newline(false, true);
1210
+ return;
1211
+ }
1212
+
1213
+ // inline block
1214
+ if (!acorn.newline.test(current_token.text) && !current_token.wanted_newline) {
1215
+ output.space_before_token = true;
1216
+ print_token();
1217
+ output.space_before_token = true;
1218
+ return;
1219
+ }
1220
+
1221
+ var lines = split_newlines(current_token.text);
1222
+ var j; // iterator for this case
1223
+ var javadoc = false;
1224
+ var starless = false;
1225
+ var lastIndent = current_token.whitespace_before;
1226
+ var lastIndentLength = lastIndent.length;
1227
+
1228
+ // block comment starts with a new line
1229
+ print_newline(false, true);
1230
+ if (lines.length > 1) {
1231
+ if (all_lines_start_with(lines.slice(1), '*')) {
1232
+ javadoc = true;
1233
+ }
1234
+ else if (each_line_matches_indent(lines.slice(1), lastIndent)) {
1235
+ starless = true;
1236
+ }
1237
+ }
1238
+
1239
+ // first line always indented
1240
+ print_token(lines[0]);
1241
+ for (j = 1; j < lines.length; j++) {
1242
+ print_newline(false, true);
1243
+ if (javadoc) {
1244
+ // javadoc: reformat and re-indent
1245
+ print_token(' ' + ltrim(lines[j]));
1246
+ } else if (starless && lines[j].length > lastIndentLength) {
1247
+ // starless: re-indent non-empty content, avoiding trim
1248
+ print_token(lines[j].substring(lastIndentLength));
1249
+ } else {
1250
+ // normal comments output raw
1251
+ output.add_token(lines[j]);
1252
+ }
1253
+ }
1254
+
1255
+ // for comments of more than one line, make sure there's a new line after
1256
+ print_newline(false, true);
1257
+ }
1258
+
1259
+ function handle_comment() {
1260
+ if (current_token.wanted_newline) {
1261
+ print_newline(false, true);
1262
+ } else {
1263
+ output.trim(true);
1264
+ }
1265
+
1266
+ output.space_before_token = true;
1267
+ print_token();
1268
+ print_newline(false, true);
1269
+ }
1270
+
1271
+ function handle_dot() {
1272
+ if (start_of_statement()) {
1273
+ // The conditional starts the statement if appropriate.
1274
+ }
1275
+
1276
+ if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
1277
+ output.space_before_token = true;
1278
+ } else {
1279
+ // allow preserved newlines before dots in general
1280
+ // force newlines on dots after close paren when break_chained - for bar().baz()
1281
+ allow_wrap_or_preserved_newline(flags.last_text === ')' && opt.break_chained_methods);
1282
+ }
1283
+
1284
+ print_token();
1285
+ }
1286
+
1287
+ function handle_unknown() {
1288
+ print_token();
1289
+
1290
+ if (current_token.text[current_token.text.length - 1] === '\n') {
1291
+ print_newline();
1292
+ }
1293
+ }
1294
+
1295
+ function handle_eof() {
1296
+ // Unwind any open statements
1297
+ while (flags.mode === MODE.Statement) {
1298
+ restore_mode();
1299
+ }
1300
+ }
1301
+ }
1302
+
1303
+
1304
+ function OutputLine(parent) {
1305
+ var _character_count = 0;
1306
+ // use indent_count as a marker for lines that have preserved indentation
1307
+ var _indent_count = -1;
1308
+
1309
+ var _items = [];
1310
+ var _empty = true;
1311
+
1312
+ this.set_indent = function(level) {
1313
+ _character_count = parent.baseIndentLength + level * parent.indent_length
1314
+ _indent_count = level;
1315
+ }
1316
+
1317
+ this.get_character_count = function() {
1318
+ return _character_count;
1319
+ }
1320
+
1321
+ this.is_empty = function() {
1322
+ return _empty;
1323
+ }
1324
+
1325
+ this.last = function() {
1326
+ if (!this._empty) {
1327
+ return _items[_items.length - 1];
1328
+ } else {
1329
+ return null;
1330
+ }
1331
+ }
1332
+
1333
+ this.push = function(input) {
1334
+ _items.push(input);
1335
+ _character_count += input.length;
1336
+ _empty = false;
1337
+ }
1338
+
1339
+ this.pop = function() {
1340
+ var item = null;
1341
+ if (!_empty) {
1342
+ item = _items.pop();
1343
+ _character_count -= item.length;
1344
+ _empty = _items.length === 0;
1345
+ }
1346
+ return item;
1347
+ }
1348
+
1349
+ this.remove_indent = function() {
1350
+ if (_indent_count > 0) {
1351
+ _indent_count -= 1;
1352
+ _character_count -= parent.indent_length
1353
+ }
1354
+ }
1355
+
1356
+ this.trim = function() {
1357
+ while (this.last() === ' ') {
1358
+ var item = _items.pop();
1359
+ _character_count -= 1;
1360
+ }
1361
+ _empty = _items.length === 0;
1362
+ }
1363
+
1364
+ this.toString = function() {
1365
+ var result = '';
1366
+ if (!this._empty) {
1367
+ if (_indent_count >= 0) {
1368
+ result = parent.indent_cache[_indent_count];
1369
+ }
1370
+ result += _items.join('')
1371
+ }
1372
+ return result;
1373
+ }
1374
+ }
1375
+
1376
+ function Output(indent_string, baseIndentString) {
1377
+ baseIndentString = baseIndentString || '';
1378
+ this.indent_cache = [ baseIndentString ];
1379
+ this.baseIndentLength = baseIndentString.length;
1380
+ this.indent_length = indent_string.length;
1381
+ this.raw = false;
1382
+
1383
+ var lines =[];
1384
+ this.baseIndentString = baseIndentString;
1385
+ this.indent_string = indent_string;
1386
+ this.previous_line = null;
1387
+ this.current_line = null;
1388
+ this.space_before_token = false;
1389
+
1390
+ this.add_outputline = function() {
1391
+ this.previous_line = this.current_line;
1392
+ this.current_line = new OutputLine(this);
1393
+ lines.push(this.current_line);
1394
+ }
1395
+
1396
+ // initialize
1397
+ this.add_outputline();
1398
+
1399
+
1400
+ this.get_line_number = function() {
1401
+ return lines.length;
1402
+ }
1403
+
1404
+ // Using object instead of string to allow for later expansion of info about each line
1405
+ this.add_new_line = function(force_newline) {
1406
+ if (this.get_line_number() === 1 && this.just_added_newline()) {
1407
+ return false; // no newline on start of file
1408
+ }
1409
+
1410
+ if (force_newline || !this.just_added_newline()) {
1411
+ if (!this.raw) {
1412
+ this.add_outputline();
1413
+ }
1414
+ return true;
1415
+ }
1416
+
1417
+ return false;
1418
+ }
1419
+
1420
+ this.get_code = function() {
1421
+ var sweet_code = lines.join('\n').replace(/[\r\n\t ]+$/, '');
1422
+ return sweet_code;
1423
+ }
1424
+
1425
+ this.set_indent = function(level) {
1426
+ // Never indent your first output indent at the start of the file
1427
+ if (lines.length > 1) {
1428
+ while(level >= this.indent_cache.length) {
1429
+ this.indent_cache.push(this.indent_cache[this.indent_cache.length - 1] + this.indent_string);
1430
+ }
1431
+
1432
+ this.current_line.set_indent(level);
1433
+ return true;
1434
+ }
1435
+ this.current_line.set_indent(0);
1436
+ return false;
1437
+ }
1438
+
1439
+ this.add_raw_token = function(token) {
1440
+ for (var x = 0; x < token.newlines; x++) {
1441
+ this.add_outputline();
1442
+ }
1443
+ this.current_line.push(token.whitespace_before);
1444
+ this.current_line.push(token.text);
1445
+ this.space_before_token = false;
1446
+ }
1447
+
1448
+ this.add_token = function(printable_token) {
1449
+ this.add_space_before_token();
1450
+ this.current_line.push(printable_token);
1451
+ }
1452
+
1453
+ this.add_space_before_token = function() {
1454
+ if (this.space_before_token && !this.just_added_newline()) {
1455
+ this.current_line.push(' ');
1456
+ }
1457
+ this.space_before_token = false;
1458
+ }
1459
+
1460
+ this.remove_redundant_indentation = function (frame) {
1461
+ // This implementation is effective but has some issues:
1462
+ // - can cause line wrap to happen too soon due to indent removal
1463
+ // after wrap points are calculated
1464
+ // These issues are minor compared to ugly indentation.
1465
+
1466
+ if (frame.multiline_frame ||
1467
+ frame.mode === MODE.ForInitializer ||
1468
+ frame.mode === MODE.Conditional) {
1469
+ return;
1470
+ }
1471
+
1472
+ // remove one indent from each line inside this section
1473
+ var index = frame.start_line_index;
1474
+ var line;
1475
+
1476
+ var output_length = lines.length;
1477
+ while (index < output_length) {
1478
+ lines[index].remove_indent();
1479
+ index++;
1480
+ }
1481
+ }
1482
+
1483
+ this.trim = function(eat_newlines) {
1484
+ eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
1485
+
1486
+ this.current_line.trim(indent_string, baseIndentString);
1487
+
1488
+ while (eat_newlines && lines.length > 1 &&
1489
+ this.current_line.is_empty()) {
1490
+ lines.pop();
1491
+ this.current_line = lines[lines.length - 1]
1492
+ this.current_line.trim();
1493
+ }
1494
+
1495
+ this.previous_line = lines.length > 1 ? lines[lines.length - 2] : null;
1496
+ }
1497
+
1498
+ this.just_added_newline = function() {
1499
+ return this.current_line.is_empty();
1500
+ }
1501
+
1502
+ this.just_added_blankline = function() {
1503
+ if (this.just_added_newline()) {
1504
+ if (lines.length === 1) {
1505
+ return true; // start of the file and newline = blank
1506
+ }
1507
+
1508
+ var line = lines[lines.length - 2];
1509
+ return line.is_empty();
1510
+ }
1511
+ return false;
1512
+ }
1513
+ }
1514
+
1515
+
1516
+ var Token = function(type, text, newlines, whitespace_before, mode, parent) {
1517
+ this.type = type;
1518
+ this.text = text;
1519
+ this.comments_before = [];
1520
+ this.newlines = newlines || 0;
1521
+ this.wanted_newline = newlines > 0;
1522
+ this.whitespace_before = whitespace_before || '';
1523
+ this.parent = null;
1524
+ this.directives = null;
1525
+ }
1526
+
1527
+ function tokenizer(input, opts, indent_string) {
1528
+
1529
+ var whitespace = "\n\r\t ".split('');
1530
+ var digit = /[0-9]/;
1531
+ var digit_hex = /[0123456789abcdefABCDEF]/;
1532
+
1533
+ var punct = ('+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! ~ , : ? ^ ^= |= :: =>'
1534
+ +' <%= <% %> <?= <? ?>').split(' '); // try to be a good boy and try not to break the markup language identifiers
1535
+
1536
+ // words which should always start on new line.
1537
+ this.line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
1538
+ var reserved_words = this.line_starters.concat(['do', 'in', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await']);
1539
+
1540
+ // /* ... */ comment ends with nearest */ or end of file
1541
+ var block_comment_pattern = /([\s\S]*?)((?:\*\/)|$)/g;
1542
+
1543
+ // comment ends just before nearest linefeed or end of file
1544
+ var comment_pattern = /([^\n\r\u2028\u2029]*)/g;
1545
+
1546
+ var directives_block_pattern = /\/\* beautify( \w+[:]\w+)+ \*\//g;
1547
+ var directive_pattern = / (\w+)[:](\w+)/g;
1548
+ var directives_end_ignore_pattern = /([\s\S]*?)((?:\/\*\sbeautify\signore:end\s\*\/)|$)/g;
1549
+
1550
+ var template_pattern = /((<\?php|<\?=)[\s\S]*?\?>)|(<%[\s\S]*?%>)/g
1551
+
1552
+ var n_newlines, whitespace_before_token, in_html_comment, tokens, parser_pos;
1553
+ var input_length;
1554
+
1555
+ this.tokenize = function() {
1556
+ // cache the source's length.
1557
+ input_length = input.length
1558
+ parser_pos = 0;
1559
+ in_html_comment = false
1560
+ tokens = [];
1561
+
1562
+ var next, last;
1563
+ var token_values;
1564
+ var open = null;
1565
+ var open_stack = [];
1566
+ var comments = [];
1567
+
1568
+ while (!(last && last.type === 'TK_EOF')) {
1569
+ token_values = tokenize_next();
1570
+ next = new Token(token_values[1], token_values[0], n_newlines, whitespace_before_token);
1571
+ while(next.type === 'TK_COMMENT' || next.type === 'TK_BLOCK_COMMENT' || next.type === 'TK_UNKNOWN') {
1572
+ if (next.type === 'TK_BLOCK_COMMENT') {
1573
+ next.directives = token_values[2];
1574
+ }
1575
+ comments.push(next);
1576
+ token_values = tokenize_next();
1577
+ next = new Token(token_values[1], token_values[0], n_newlines, whitespace_before_token);
1578
+ }
1579
+
1580
+ if (comments.length) {
1581
+ next.comments_before = comments;
1582
+ comments = [];
1583
+ }
1584
+
1585
+ if (next.type === 'TK_START_BLOCK' || next.type === 'TK_START_EXPR') {
1586
+ next.parent = last;
1587
+ open_stack.push(open);
1588
+ open = next;
1589
+ } else if ((next.type === 'TK_END_BLOCK' || next.type === 'TK_END_EXPR') &&
1590
+ (open && (
1591
+ (next.text === ']' && open.text === '[') ||
1592
+ (next.text === ')' && open.text === '(') ||
1593
+ (next.text === '}' && open.text === '{')))) {
1594
+ next.parent = open.parent;
1595
+ open = open_stack.pop();
1596
+ }
1597
+
1598
+ tokens.push(next);
1599
+ last = next;
1600
+ }
1601
+
1602
+ return tokens;
1603
+ }
1604
+
1605
+ function get_directives (text) {
1606
+ if (!text.match(directives_block_pattern)) {
1607
+ return null;
1608
+ }
1609
+
1610
+ var directives = {};
1611
+ directive_pattern.lastIndex = 0;
1612
+ var directive_match = directive_pattern.exec(text);
1613
+
1614
+ while (directive_match) {
1615
+ directives[directive_match[1]] = directive_match[2];
1616
+ directive_match = directive_pattern.exec(text);
1617
+ }
1618
+
1619
+ return directives;
1620
+ }
1621
+
1622
+ function tokenize_next() {
1623
+ var i, resulting_string;
1624
+ var whitespace_on_this_line = [];
1625
+
1626
+ n_newlines = 0;
1627
+ whitespace_before_token = '';
1628
+
1629
+ if (parser_pos >= input_length) {
1630
+ return ['', 'TK_EOF'];
1631
+ }
1632
+
1633
+ var last_token;
1634
+ if (tokens.length) {
1635
+ last_token = tokens[tokens.length-1];
1636
+ } else {
1637
+ // For the sake of tokenizing we can pretend that there was on open brace to start
1638
+ last_token = new Token('TK_START_BLOCK', '{');
1639
+ }
1640
+
1641
+
1642
+ var c = input.charAt(parser_pos);
1643
+ parser_pos += 1;
1644
+
1645
+ while (in_array(c, whitespace)) {
1646
+
1647
+ if (acorn.newline.test(c)) {
1648
+ if (!(c === '\n' && input.charAt(parser_pos-2) === '\r')) {
1649
+ n_newlines += 1;
1650
+ whitespace_on_this_line = [];
1651
+ }
1652
+ } else {
1653
+ whitespace_on_this_line.push(c);
1654
+ }
1655
+
1656
+ if (parser_pos >= input_length) {
1657
+ return ['', 'TK_EOF'];
1658
+ }
1659
+
1660
+ c = input.charAt(parser_pos);
1661
+ parser_pos += 1;
1662
+ }
1663
+
1664
+ if(whitespace_on_this_line.length) {
1665
+ whitespace_before_token = whitespace_on_this_line.join('');
1666
+ }
1667
+
1668
+ if (digit.test(c)) {
1669
+ var allow_decimal = true;
1670
+ var allow_e = true;
1671
+ var local_digit = digit;
1672
+
1673
+ if (c === '0' && parser_pos < input_length && /[Xx]/.test(input.charAt(parser_pos))) {
1674
+ // switch to hex number, no decimal or e, just hex digits
1675
+ allow_decimal = false;
1676
+ allow_e = false;
1677
+ c += input.charAt(parser_pos);
1678
+ parser_pos += 1;
1679
+ local_digit = digit_hex
1680
+ } else {
1681
+ // we know this first loop will run. It keeps the logic simpler.
1682
+ c = '';
1683
+ parser_pos -= 1
1684
+ }
1685
+
1686
+ // Add the digits
1687
+ while (parser_pos < input_length && local_digit.test(input.charAt(parser_pos))) {
1688
+ c += input.charAt(parser_pos);
1689
+ parser_pos += 1;
1690
+
1691
+ if (allow_decimal && parser_pos < input_length && input.charAt(parser_pos) === '.') {
1692
+ c += input.charAt(parser_pos);
1693
+ parser_pos += 1;
1694
+ allow_decimal = false;
1695
+ }
1696
+
1697
+ if (allow_e && parser_pos < input_length && /[Ee]/.test(input.charAt(parser_pos))) {
1698
+ c += input.charAt(parser_pos);
1699
+ parser_pos += 1;
1700
+
1701
+ if (parser_pos < input_length && /[+-]/.test(input.charAt(parser_pos))) {
1702
+ c += input.charAt(parser_pos);
1703
+ parser_pos += 1;
1704
+ }
1705
+
1706
+ allow_e = false;
1707
+ allow_decimal = false;
1708
+ }
1709
+ }
1710
+
1711
+ return [c, 'TK_WORD'];
1712
+ }
1713
+
1714
+ if (acorn.isIdentifierStart(input.charCodeAt(parser_pos-1))) {
1715
+ if (parser_pos < input_length) {
1716
+ while (acorn.isIdentifierChar(input.charCodeAt(parser_pos))) {
1717
+ c += input.charAt(parser_pos);
1718
+ parser_pos += 1;
1719
+ if (parser_pos === input_length) {
1720
+ break;
1721
+ }
1722
+ }
1723
+ }
1724
+
1725
+ if (!(last_token.type === 'TK_DOT' ||
1726
+ (last_token.type === 'TK_RESERVED' && in_array(last_token.text, ['set', 'get'])))
1727
+ && in_array(c, reserved_words)) {
1728
+ if (c === 'in') { // hack for 'in' operator
1729
+ return [c, 'TK_OPERATOR'];
1730
+ }
1731
+ return [c, 'TK_RESERVED'];
1732
+ }
1733
+
1734
+ return [c, 'TK_WORD'];
1735
+ }
1736
+
1737
+ if (c === '(' || c === '[') {
1738
+ return [c, 'TK_START_EXPR'];
1739
+ }
1740
+
1741
+ if (c === ')' || c === ']') {
1742
+ return [c, 'TK_END_EXPR'];
1743
+ }
1744
+
1745
+ if (c === '{') {
1746
+ return [c, 'TK_START_BLOCK'];
1747
+ }
1748
+
1749
+ if (c === '}') {
1750
+ return [c, 'TK_END_BLOCK'];
1751
+ }
1752
+
1753
+ if (c === ';') {
1754
+ return [c, 'TK_SEMICOLON'];
1755
+ }
1756
+
1757
+ if (c === '/') {
1758
+ var comment = '';
1759
+ // peek for comment /* ... */
1760
+ if (input.charAt(parser_pos) === '*') {
1761
+ parser_pos += 1;
1762
+ block_comment_pattern.lastIndex = parser_pos;
1763
+ var comment_match = block_comment_pattern.exec(input);
1764
+ comment = '/*' + comment_match[0];
1765
+ parser_pos += comment_match[0].length;
1766
+ var directives = get_directives(comment);
1767
+ if (directives && directives['ignore'] === 'start') {
1768
+ directives_end_ignore_pattern.lastIndex = parser_pos;
1769
+ comment_match = directives_end_ignore_pattern.exec(input)
1770
+ comment += comment_match[0];
1771
+ parser_pos += comment_match[0].length;
1772
+ }
1773
+ comment = comment.replace(acorn.lineBreak, '\n');
1774
+ return [comment, 'TK_BLOCK_COMMENT', directives];
1775
+ }
1776
+ // peek for comment // ...
1777
+ if (input.charAt(parser_pos) === '/') {
1778
+ parser_pos += 1;
1779
+ comment_pattern.lastIndex = parser_pos;
1780
+ var comment_match = comment_pattern.exec(input);
1781
+ comment = '//' + comment_match[0];
1782
+ parser_pos += comment_match[0].length;
1783
+ return [comment, 'TK_COMMENT'];
1784
+ }
1785
+
1786
+ }
1787
+
1788
+ if (c === '`' || c === "'" || c === '"' || // string
1789
+ (
1790
+ (c === '/') || // regexp
1791
+ (opts.e4x && c === "<" && input.slice(parser_pos - 1).match(/^<([-a-zA-Z:0-9_.]+|{[^{}]*}|!\[CDATA\[[\s\S]*?\]\])(\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{.*?}))*\s*(\/?)\s*>/)) // xml
1792
+ ) && ( // regex and xml can only appear in specific locations during parsing
1793
+ (last_token.type === 'TK_RESERVED' && in_array(last_token.text , ['return', 'case', 'throw', 'else', 'do', 'typeof', 'yield'])) ||
1794
+ (last_token.type === 'TK_END_EXPR' && last_token.text === ')' &&
1795
+ last_token.parent && last_token.parent.type === 'TK_RESERVED' && in_array(last_token.parent.text, ['if', 'while', 'for'])) ||
1796
+ (in_array(last_token.type, ['TK_COMMENT', 'TK_START_EXPR', 'TK_START_BLOCK',
1797
+ 'TK_END_BLOCK', 'TK_OPERATOR', 'TK_EQUALS', 'TK_EOF', 'TK_SEMICOLON', 'TK_COMMA'
1798
+ ]))
1799
+ )) {
1800
+
1801
+ var sep = c,
1802
+ esc = false,
1803
+ has_char_escapes = false;
1804
+
1805
+ resulting_string = c;
1806
+
1807
+ if (sep === '/') {
1808
+ //
1809
+ // handle regexp
1810
+ //
1811
+ var in_char_class = false;
1812
+ while (parser_pos < input_length &&
1813
+ ((esc || in_char_class || input.charAt(parser_pos) !== sep) &&
1814
+ !acorn.newline.test(input.charAt(parser_pos)))) {
1815
+ resulting_string += input.charAt(parser_pos);
1816
+ if (!esc) {
1817
+ esc = input.charAt(parser_pos) === '\\';
1818
+ if (input.charAt(parser_pos) === '[') {
1819
+ in_char_class = true;
1820
+ } else if (input.charAt(parser_pos) === ']') {
1821
+ in_char_class = false;
1822
+ }
1823
+ } else {
1824
+ esc = false;
1825
+ }
1826
+ parser_pos += 1;
1827
+ }
1828
+ } else if (opts.e4x && sep === '<') {
1829
+ //
1830
+ // handle e4x xml literals
1831
+ //
1832
+ var xmlRegExp = /<(\/?)([-a-zA-Z:0-9_.]+|{[^{}]*}|!\[CDATA\[[\s\S]*?\]\])(\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{.*?}))*\s*(\/?)\s*>/g;
1833
+ var xmlStr = input.slice(parser_pos - 1);
1834
+ var match = xmlRegExp.exec(xmlStr);
1835
+ if (match && match.index === 0) {
1836
+ var rootTag = match[2];
1837
+ var depth = 0;
1838
+ while (match) {
1839
+ var isEndTag = !! match[1];
1840
+ var tagName = match[2];
1841
+ var isSingletonTag = ( !! match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
1842
+ if (tagName === rootTag && !isSingletonTag) {
1843
+ if (isEndTag) {
1844
+ --depth;
1845
+ } else {
1846
+ ++depth;
1847
+ }
1848
+ }
1849
+ if (depth <= 0) {
1850
+ break;
1851
+ }
1852
+ match = xmlRegExp.exec(xmlStr);
1853
+ }
1854
+ var xmlLength = match ? match.index + match[0].length : xmlStr.length;
1855
+ xmlStr = xmlStr.slice(0, xmlLength);
1856
+ parser_pos += xmlLength - 1;
1857
+ xmlStr = xmlStr.replace(acorn.lineBreak, '\n');
1858
+ return [xmlStr, "TK_STRING"];
1859
+ }
1860
+ } else {
1861
+ //
1862
+ // handle string
1863
+ //
1864
+ // Template strings can travers lines without escape characters.
1865
+ // Other strings cannot
1866
+ while (parser_pos < input_length &&
1867
+ (esc || (input.charAt(parser_pos) !== sep &&
1868
+ (sep === '`' || !acorn.newline.test(input.charAt(parser_pos)))))) {
1869
+ // Handle \r\n linebreaks after escapes or in template strings
1870
+ if ((esc || sep === '`') && acorn.newline.test(input.charAt(parser_pos))) {
1871
+ if (input.charAt(parser_pos) === '\r' && input.charAt(parser_pos + 1) === '\n') {
1872
+ parser_pos += 1;
1873
+ }
1874
+ resulting_string += '\n';
1875
+ } else {
1876
+ resulting_string += input.charAt(parser_pos);
1877
+ }
1878
+ if (esc) {
1879
+ if (input.charAt(parser_pos) === 'x' || input.charAt(parser_pos) === 'u') {
1880
+ has_char_escapes = true;
1881
+ }
1882
+ esc = false;
1883
+ } else {
1884
+ esc = input.charAt(parser_pos) === '\\';
1885
+ }
1886
+ parser_pos += 1;
1887
+ }
1888
+
1889
+ }
1890
+
1891
+ if (has_char_escapes && opts.unescape_strings) {
1892
+ resulting_string = unescape_string(resulting_string);
1893
+ }
1894
+
1895
+ if (parser_pos < input_length && input.charAt(parser_pos) === sep) {
1896
+ resulting_string += sep;
1897
+ parser_pos += 1;
1898
+
1899
+ if (sep === '/') {
1900
+ // regexps may have modifiers /regexp/MOD , so fetch those, too
1901
+ // Only [gim] are valid, but if the user puts in garbage, do what we can to take it.
1902
+ while (parser_pos < input_length && acorn.isIdentifierStart(input.charCodeAt(parser_pos))) {
1903
+ resulting_string += input.charAt(parser_pos);
1904
+ parser_pos += 1;
1905
+ }
1906
+ }
1907
+ }
1908
+ return [resulting_string, 'TK_STRING'];
1909
+ }
1910
+
1911
+ if (c === '#') {
1912
+
1913
+ if (tokens.length === 0 && input.charAt(parser_pos) === '!') {
1914
+ // shebang
1915
+ resulting_string = c;
1916
+ while (parser_pos < input_length && c !== '\n') {
1917
+ c = input.charAt(parser_pos);
1918
+ resulting_string += c;
1919
+ parser_pos += 1;
1920
+ }
1921
+ return [trim(resulting_string) + '\n', 'TK_UNKNOWN'];
1922
+ }
1923
+
1924
+
1925
+
1926
+ // Spidermonkey-specific sharp variables for circular references
1927
+ // https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
1928
+ // http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
1929
+ var sharp = '#';
1930
+ if (parser_pos < input_length && digit.test(input.charAt(parser_pos))) {
1931
+ do {
1932
+ c = input.charAt(parser_pos);
1933
+ sharp += c;
1934
+ parser_pos += 1;
1935
+ } while (parser_pos < input_length && c !== '#' && c !== '=');
1936
+ if (c === '#') {
1937
+ //
1938
+ } else if (input.charAt(parser_pos) === '[' && input.charAt(parser_pos + 1) === ']') {
1939
+ sharp += '[]';
1940
+ parser_pos += 2;
1941
+ } else if (input.charAt(parser_pos) === '{' && input.charAt(parser_pos + 1) === '}') {
1942
+ sharp += '{}';
1943
+ parser_pos += 2;
1944
+ }
1945
+ return [sharp, 'TK_WORD'];
1946
+ }
1947
+ }
1948
+
1949
+ if (c === '<' && (input.charAt(parser_pos) === '?' || input.charAt(parser_pos) === '%')) {
1950
+ template_pattern.lastIndex = parser_pos - 1;
1951
+ var template_match = template_pattern.exec(input);
1952
+ if(template_match) {
1953
+ c = template_match[0];
1954
+ parser_pos += c.length - 1;
1955
+ c = c.replace(acorn.lineBreak, '\n');
1956
+ return [c, 'TK_STRING'];
1957
+ }
1958
+ }
1959
+
1960
+ if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '<!--') {
1961
+ parser_pos += 3;
1962
+ c = '<!--';
1963
+ while (!acorn.newline.test(input.charAt(parser_pos)) && parser_pos < input_length) {
1964
+ c += input.charAt(parser_pos);
1965
+ parser_pos++;
1966
+ }
1967
+ in_html_comment = true;
1968
+ return [c, 'TK_COMMENT'];
1969
+ }
1970
+
1971
+ if (c === '-' && in_html_comment && input.substring(parser_pos - 1, parser_pos + 2) === '-->') {
1972
+ in_html_comment = false;
1973
+ parser_pos += 2;
1974
+ return ['-->', 'TK_COMMENT'];
1975
+ }
1976
+
1977
+ if (c === '.') {
1978
+ return [c, 'TK_DOT'];
1979
+ }
1980
+
1981
+ if (in_array(c, punct)) {
1982
+ while (parser_pos < input_length && in_array(c + input.charAt(parser_pos), punct)) {
1983
+ c += input.charAt(parser_pos);
1984
+ parser_pos += 1;
1985
+ if (parser_pos >= input_length) {
1986
+ break;
1987
+ }
1988
+ }
1989
+
1990
+ if (c === ',') {
1991
+ return [c, 'TK_COMMA'];
1992
+ } else if (c === '=') {
1993
+ return [c, 'TK_EQUALS'];
1994
+ } else {
1995
+ return [c, 'TK_OPERATOR'];
1996
+ }
1997
+ }
1998
+
1999
+ return [c, 'TK_UNKNOWN'];
2000
+ }
2001
+
2002
+
2003
+ function unescape_string(s) {
2004
+ var esc = false,
2005
+ out = '',
2006
+ pos = 0,
2007
+ s_hex = '',
2008
+ escaped = 0,
2009
+ c;
2010
+
2011
+ while (esc || pos < s.length) {
2012
+
2013
+ c = s.charAt(pos);
2014
+ pos++;
2015
+
2016
+ if (esc) {
2017
+ esc = false;
2018
+ if (c === 'x') {
2019
+ // simple hex-escape \x24
2020
+ s_hex = s.substr(pos, 2);
2021
+ pos += 2;
2022
+ } else if (c === 'u') {
2023
+ // unicode-escape, \u2134
2024
+ s_hex = s.substr(pos, 4);
2025
+ pos += 4;
2026
+ } else {
2027
+ // some common escape, e.g \n
2028
+ out += '\\' + c;
2029
+ continue;
2030
+ }
2031
+ if (!s_hex.match(/^[0123456789abcdefABCDEF]+$/)) {
2032
+ // some weird escaping, bail out,
2033
+ // leaving whole string intact
2034
+ return s;
2035
+ }
2036
+
2037
+ escaped = parseInt(s_hex, 16);
2038
+
2039
+ if (escaped >= 0x00 && escaped < 0x20) {
2040
+ // leave 0x00...0x1f escaped
2041
+ if (c === 'x') {
2042
+ out += '\\x' + s_hex;
2043
+ } else {
2044
+ out += '\\u' + s_hex;
2045
+ }
2046
+ continue;
2047
+ } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
2048
+ // single-quote, apostrophe, backslash - escape these
2049
+ out += '\\' + String.fromCharCode(escaped);
2050
+ } else if (c === 'x' && escaped > 0x7e && escaped <= 0xff) {
2051
+ // we bail out on \x7f..\xff,
2052
+ // leaving whole string escaped,
2053
+ // as it's probably completely binary
2054
+ return s;
2055
+ } else {
2056
+ out += String.fromCharCode(escaped);
2057
+ }
2058
+ } else if (c === '\\') {
2059
+ esc = true;
2060
+ } else {
2061
+ out += c;
2062
+ }
2063
+ }
2064
+ return out;
2065
+ }
2066
+
2067
+ }
2068
+
2069
+
2070
+ if (typeof define === "function" && define.amd) {
2071
+ // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
2072
+ define([], function() {
2073
+ return { js_beautify: js_beautify };
2074
+ });
2075
+ } else if (typeof exports !== "undefined") {
2076
+ // Add support for CommonJS. Just put this file somewhere on your require.paths
2077
+ // and you will be able to `var js_beautify = require("beautify").js_beautify`.
2078
+ exports.js_beautify = js_beautify;
2079
+ } else if (typeof window !== "undefined") {
2080
+ // If we're running a web page and don't have either of the above, add our one global
2081
+ window.js_beautify = js_beautify;
2082
+ } else if (typeof global !== "undefined") {
2083
+ // If we don't even have window, try global.
2084
+ global.js_beautify = js_beautify;
2085
+ }
2086
+
2087
+ }());