Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into ack

  • Loading branch information...
commit 78b86a7110265232f27275bc3922b230bb00963d 2 parents 41a15a3 + 004b294
@gjtorikian gjtorikian authored
Showing with 8,124 additions and 6,434 deletions.
  1. +5 −6 Makefile
  2. +14 −2 Makefile.dryice.js
  3. +1 −6 README.md
  4. +3 −5 build/app.build.tmpl.js
  5. +9 −10 build/core.build.js
  6. +5 −4 configs/default.js
  7. +96 −0 doc/ext.extension_template/extension_template.js
  8. +26 −0 doc/ext.extension_template/extension_template.xml
  9. +14 −0 doc/ext.extension_template/package.json
  10. +20 −20 package.json
  11. +1 −0  plugins-client/cloud9.core/www/core/ide.js
  12. +48 −7 plugins-client/cloud9.core/www/core/util.js
  13. +298 −0 plugins-client/ext.autosave/autosave.js
  14. 0  plugins-client/{ext.revisions → ext.autosave}/settings.xml
  15. +54 −30 plugins-client/ext.beautify/beautify.js
  16. +1 −1  plugins-client/ext.beautify/res/jsbeautify/jsbeautify-min.js
  17. +1,035 −140 plugins-client/ext.beautify/res/jsbeautify/jsbeautify.js
  18. +2 −0  plugins-client/ext.beautify/settings.xml
  19. +8 −20 plugins-client/ext.code/code.js
  20. +3 −4 plugins-client/ext.code/code.xml
  21. +0 −1  plugins-client/ext.codecomplete/complete_util.js
  22. +1 −9 plugins-client/ext.codecomplete/local_completer.js
  23. +1 −2  plugins-client/ext.codecomplete/open_files_local_completer.js
  24. +5 −3 plugins-client/ext.codecomplete/snippet_completer.js
  25. +5 −5 plugins-client/ext.codecomplete/snippets/javascript.json
  26. +10 −5 plugins-client/ext.codetools/codetools.js
  27. +42 −15 plugins-client/ext.console/console.js
  28. +1 −1  plugins-client/ext.console/console.xml
  29. +1 −1  plugins-client/ext.consolehints/consolehints.js
  30. +646 −0 plugins-client/ext.dbg-node/dbg-node.js
  31. +83 −0 plugins-client/ext.debugger/apfhook.js
  32. +312 −0 plugins-client/ext.debugger/breakpoints.js
  33. +110 −238 plugins-client/ext.debugger/debugger.js
  34. +19 −11 plugins-client/ext.debugger/debugger.xml
  35. +3 −5 plugins-client/ext.debugger/inspector.js
  36. +219 −0 plugins-client/ext.debugger/sources.js
  37. +63 −3 plugins-client/ext.dockpanel/dockpanel.js
  38. +20 −3 plugins-client/ext.dockpanel/libdock.js
  39. +76 −50 plugins-client/ext.editors/editors.js
  40. +8 −4 plugins-client/ext.filelist/filelist.js
  41. +15 −9 plugins-client/ext.filesystem/filesystem.js
  42. +0 −1  plugins-client/ext.gitblame/blame_gutter.js
  43. +69 −56 plugins-client/ext.gitblame/gitblame.js
  44. +49 −17 plugins-client/ext.gotofile/gotofile.js
  45. +22 −1 plugins-client/ext.gotofile/gotofile.xml
  46. +1 −1  plugins-client/ext.gotofile/search.js
  47. +1 −1  plugins-client/ext.guidedtour/tour.js
  48. +1 −1  plugins-client/ext.help/help.js
  49. +2 −2 plugins-client/ext.jslanguage/debugger.js
  50. +26 −7 plugins-client/ext.jslanguage/{narcissus_jshint.js → jshint.js}
  51. +31 −5 plugins-client/ext.jslanguage/{narcissus_jshint_test.js → jshint_test.js}
  52. +1 −1  plugins-client/ext.jslanguage/jslanguage.js
  53. +53 −30 plugins-client/ext.jslanguage/outline.js
  54. +13 −1 plugins-client/ext.jslanguage/parse.js
  55. +2 −2 plugins-client/ext.jslanguage/parse_test.js
  56. +151 −120 plugins-client/ext.jslanguage/scope_analyzer.js
  57. +63 −2 plugins-client/ext.jslanguage/scope_analyzer_test.js
  58. +112 −31 plugins-client/ext.language/base_handler.js
  59. +36 −13 plugins-client/ext.language/complete.js
  60. +12 −5 plugins-client/ext.language/keyhandler.js
  61. +22 −16 plugins-client/ext.language/language.js
  62. +75 −41 plugins-client/ext.language/liveinspect.js
  63. +1 −0  plugins-client/ext.language/liveinspect.xml
  64. +13 −28 plugins-client/ext.language/outline.js
  65. +133 −24 plugins-client/ext.language/refactor.js
  66. +1 −1  plugins-client/ext.language/settings.xml
  67. +313 −95 plugins-client/ext.language/worker.js
  68. +1 −1  plugins-client/ext.log/log.js
  69. +6 −1 plugins-client/ext.main/main.xml
  70. BIN  plugins-client/ext.main/style/icons/delete_icon.png
  71. BIN  plugins-client/ext.main/style/icons/file-tree-load-spinner-selected.gif
  72. BIN  plugins-client/ext.main/style/icons/file-tree-load-spinner.gif
  73. +64 −36 plugins-client/ext.main/style/skins.xml
  74. +29 −72 plugins-client/ext.noderunner/noderunner.js
  75. +0 −23 plugins-client/ext.noderunner/noderunner.xml
  76. +0 −370 plugins-client/ext.offline/lib-offlinedav.js
  77. +0 −803 plugins-client/ext.offline/lib-offlinefs.js
  78. +0 −156 plugins-client/ext.offline/lib-offlinels.js
  79. +0 −108 plugins-client/ext.offline/lib-sync.js
  80. +0 −149 plugins-client/ext.offline/lib-webdav-wrap.js
  81. +10 −270 plugins-client/ext.offline/offline.js
  82. +1 −1  plugins-client/ext.openfiles/openfiles.js
  83. +2 −2 plugins-client/ext.quickwatch/quickwatch.xml
  84. +20 −12 plugins-client/ext.recentfiles/recentfiles.js
  85. +232 −438 plugins-client/ext.revisions/revisions.js
  86. +2 −35 plugins-client/ext.revisions/revisions_util.js
  87. +0 −1  plugins-client/ext.revisions/skin.xml
  88. +3 −2 plugins-client/ext.runpanel/runpanel.js
  89. +59 −10 plugins-client/ext.save/save.js
  90. +20 −3 plugins-client/ext.save/save.xml
  91. +20 −19 plugins-client/ext.searchinfiles/searchinfiles.js
  92. +4 −4 plugins-client/ext.searchreplace/searchreplace.js
  93. +1 −1  plugins-client/ext.sync/sync.js
  94. +9 −3 plugins-client/ext.sync/sync.xml
  95. +1 −1  plugins-client/ext.testpanel/testpanel.js
  96. +7 −2 plugins-client/ext.uploadfiles/uploadfiles.js
  97. +22 −6 plugins-client/ext.vim/cli.js
  98. +24 −10 plugins-client/ext.watcher/watcher.js
  99. +35 −58 plugins-client/lib.ace/www/mode/mode-c9search.js
  100. +58 −13 plugins-client/lib.ace/www/mode/mode-c_cpp.js
  101. +7 −6 plugins-client/lib.ace/www/mode/mode-clojure.js
  102. +94 −30 plugins-client/lib.ace/www/mode/mode-coffee.js
  103. +109 −69 plugins-client/lib.ace/www/mode/mode-coldfusion.js
  104. +58 −13 plugins-client/lib.ace/www/mode/mode-csharp.js
  105. +16 −14 plugins-client/lib.ace/www/mode/mode-css.js
  106. +18 −16 plugins-client/lib.ace/www/mode/mode-diff.js
  107. +58 −13 plugins-client/lib.ace/www/mode/mode-golang.js
  108. +60 −15 plugins-client/lib.ace/www/mode/mode-groovy.js
  109. +58 −13 plugins-client/lib.ace/www/mode/mode-haxe.js
  110. +195 −75 plugins-client/lib.ace/www/mode/mode-html.js
  111. +60 −15 plugins-client/lib.ace/www/mode/mode-java.js
  112. +60 −15 plugins-client/lib.ace/www/mode/mode-javascript.js
  113. +59 −14 plugins-client/lib.ace/www/mode/mode-json.js
  114. +58 −13 plugins-client/lib.ace/www/mode/mode-jsx.js
  115. +15 −13 plugins-client/lib.ace/www/mode/mode-less.js
  116. +7 −33 plugins-client/lib.ace/www/mode/mode-liquid.js
  117. +88 −20 plugins-client/lib.ace/www/mode/mode-lua.js
  118. +284 −97 plugins-client/lib.ace/www/mode/mode-luapage.js
  119. +195 −75 plugins-client/lib.ace/www/mode/mode-markdown.js
  120. +15 −13 plugins-client/lib.ace/www/mode/mode-perl.js
  121. +58 −13 plugins-client/lib.ace/www/mode/mode-php.js
  122. +58 −13 plugins-client/lib.ace/www/mode/mode-powershell.js
  123. +16 −14 plugins-client/lib.ace/www/mode/mode-python.js
  124. +58 −13 plugins-client/lib.ace/www/mode/mode-scad.js
  125. +60 −15 plugins-client/lib.ace/www/mode/mode-scala.js
  126. +15 −13 plugins-client/lib.ace/www/mode/mode-scss.js
  127. +108 −68 plugins-client/lib.ace/www/mode/mode-svg.js
  128. +320 −0 plugins-client/lib.ace/www/mode/mode-tcl.js
  129. +106 −66 plugins-client/lib.ace/www/mode/mode-xml.js
  130. +44 −1 plugins-client/lib.ace/www/mode/mode-xquery.js
  131. +2 −2 plugins-client/lib.ace/www/theme/theme-clouds_midnight.js
  132. +2 −2 plugins-client/lib.ace/www/theme/theme-cobalt.js
  133. +4 −0 plugins-client/lib.ace/www/theme/theme-crimson_editor.js
  134. +56 −4 plugins-client/lib.ace/www/theme/theme-github.js
  135. +2 −2 plugins-client/lib.ace/www/theme/theme-idle_fingers.js
  136. +2 −2 plugins-client/lib.ace/www/theme/theme-kr_theme.js
  137. +3 −3 plugins-client/lib.ace/www/theme/theme-merbivore.js
  138. +2 −2 plugins-client/lib.ace/www/theme/theme-merbivore_soft.js
  139. +2 −2 plugins-client/lib.ace/www/theme/theme-mono_industrial.js
  140. +2 −2 plugins-client/lib.ace/www/theme/theme-pastel_on_dark.js
  141. +2 −1  plugins-client/lib.ace/www/theme/theme-textmate.js
  142. +1 −1  plugins-client/lib.ace/www/theme/theme-tomorrow.js
  143. +2 −2 plugins-client/lib.ace/www/theme/theme-tomorrow_night.js
  144. +2 −2 plugins-client/lib.ace/www/theme/theme-tomorrow_night_bright.js
  145. +2 −2 plugins-client/lib.ace/www/theme/theme-tomorrow_night_eighties.js
  146. +2 −2 plugins-client/lib.ace/www/theme/theme-twilight.js
  147. +2 −2 plugins-client/lib.ace/www/theme/theme-vibrant_ink.js
  148. +16 −8 plugins-client/lib.apf/www/apf-packaged/apf_release.js
  149. +5 −160 plugins-client/lib.apf/www/apf/elements/codeeditor.js
  150. +0 −133 plugins-client/lib.apf/www/apf/elements/dbg/chromedebughost.js
  151. +0 −576 plugins-client/lib.apf/www/apf/elements/dbg/v8debugger.js
  152. +0 −89 plugins-client/lib.apf/www/apf/elements/dbg/v8debughost.js
  153. +0 −67 plugins-client/lib.apf/www/apf/elements/dbg/v8websocketdebughost.js
  154. +0 −424 plugins-client/lib.apf/www/apf/elements/debugger.js
  155. +0 −146 plugins-client/lib.apf/www/apf/elements/debughost.js
  156. +1 −1  plugins-server/cloud9.client-plugins/client-plugins.js
  157. +38 −21 plugins-server/cloud9.core/ide-plugin.js
  158. +11 −16 plugins-server/cloud9.core/ide.js
  159. +4 −2 plugins-server/cloud9.core/user.js
  160. +14 −3 plugins-server/cloud9.core/workspace.js
  161. +6 −7 plugins-server/cloud9.fs/dav/permission.js
  162. +35 −18 plugins-server/cloud9.ide.revisions/revisions.js
  163. +2 −1  plugins-server/cloud9.ide.run-apache/run-apache.js
  164. +41 −11 plugins-server/cloud9.ide.run-node/run-node.js
  165. +39 −19 plugins-server/cloud9.ide.run-npm-module/run-npm-module.js
  166. +2 −1  plugins-server/cloud9.ide.run-php/run-php.js
  167. +2 −1  plugins-server/cloud9.ide.run-python/run-python.js
  168. +2 −1  plugins-server/cloud9.ide.run-ruby/run-ruby.js
  169. +3 −2 plugins-server/cloud9.ide.search/search.js
  170. +3 −1 plugins-server/cloud9.ide.settings/settings.js
  171. +11 −8 plugins-server/cloud9.ide.shell/shell.js
  172. +6 −4 plugins-server/cloud9.ide.state/state.js
  173. +196 −136 plugins-server/cloud9.ide.watcher/watcher.js
  174. +12 −7 plugins-server/cloud9.process-manager/process_manager.js
  175. +16 −0 plugins-server/cloud9.routes/package.json
  176. +24 −0 plugins-server/cloud9.routes/routes-plugin.js
  177. +0 −1  plugins-server/cloud9.run.python/python-plugin.js
  178. +1 −0  plugins-server/cloud9.run.python/python-runner.js
  179. +2 −2 plugins-server/cloud9.run.shell/shell.js
  180. +20 −15 server.js
  181. 0  test/{ → _attic}/Makefile
  182. 0  test/{ → _attic}/simple/test-ext-watcher-eventemitter-limit.js
  183. 0  test/{ → _attic}/simple/test-ext-watcher-unwatch-file.js
  184. +11 −0 test/blacklist.txt
  185. +15 −0 test/gen.sh
  186. +22 −0 test/run-tests.sh
  187. +1 −0  test/setup_paths.js
View
11 Makefile
@@ -45,9 +45,9 @@ ext:
node build/r.js -o build/app.build.js
# calls dryice on worker & packages it
-worker: plugins-client/lib.ace/www/worker/worker.js
+worker: plugins-client/lib.ace/www/worker/worker-language.js
-plugins-client/lib.ace/www/worker/worker.js : $(wildcard plugins-client/ext.language/*) \
+plugins-client/lib.ace/www/worker/worker-language.js : $(wildcard plugins-client/ext.language/*) \
$(wildcard plugins-client/ext.language/*/*) \
$(wildcard plugins-client/ext.codecomplete/*) \
$(wildcard plugins-client/ext.codecomplete/*/*) \
@@ -66,7 +66,7 @@ plugins-client/lib.ace/www/worker/worker.js : $(wildcard plugins-client/ext.lang
ln -s `pwd`/plugins-client/ext.language /tmp/c9_worker_build/ext/language
ln -s `pwd`/plugins-client/ext.codecomplete /tmp/c9_worker_build/ext/codecomplete
ln -s `pwd`/plugins-client/ext.jslanguage /tmp/c9_worker_build/ext/jslanguage
- ./Makefile.dryice.js worker
+ node Makefile.dryice.js worker
cp node_modules/ace/build/src/worker* plugins-client/lib.ace/www/worker
# copies built ace modes
@@ -95,6 +95,5 @@ package_clean: helper_clean c9core ext
package: helper c9core ext
-test:
- $(MAKE) -C test
- cp node_modules/ace/build/src/worker* plugins-client/cloud9.core/www/js/worker
+test check:
+ test/run-tests.sh
View
16 Makefile.dryice.js 100755 → 100644
@@ -41,6 +41,16 @@ function worker(project) {
var worker = copy.createDataObject();
var workerProject = copy.createCommonJsProject(project);
+
+ // We don't get a return value from dryice, so we monkey patch error handling
+ var yeOldeError = console.error;
+ console.error = function() {
+ yeOldeError();
+ yeOldeError("@@@@ FATAL ERROR: DRYICE FAILED", arguments);
+ yeOldeError();
+ process.exit(1);
+ };
+
copy({
source: [
copy.source.commonjs({
@@ -56,7 +66,7 @@ function worker(project) {
'ext/codecomplete/open_files_local_completer',
'ext/jslanguage/parse',
'ext/jslanguage/scope_analyzer',
- 'ext/jslanguage/narcissus_jshint',
+ 'ext/jslanguage/jshint',
'ext/jslanguage/debugger',
'ext/jslanguage/outline'
]
@@ -71,8 +81,10 @@ function worker(project) {
worker
],
filter: [ /* copy.filter.uglifyjs */],
- dest: __dirname + "/plugins-client/lib.ace/www/worker/worker.js"
+ dest: __dirname + "/plugins-client/lib.ace/www/worker/worker-language.js"
});
+
+ console.error = yeOldeError;
}
function filterTextPlugin(text) {
View
7 README.md
@@ -36,7 +36,7 @@ We support the newer versions of Chrome, Firefox and Safari.
Requirements:
- * NodeJS `>= 0.6.15`
+ * NodeJS `>= 0.6.16` (node 0.8.x will *not work* at the moment!)
* NPM `>= 1.1.16`
Install:
@@ -55,12 +55,7 @@ Install:
cd cloud9
sm install
-**// Super important for Linux users!**
-If you are having issues with installing the o3/libxml dependency, be sure to check this issue for possible solutions:
-https://github.com/ajaxorg/node-libxml/issues/3
-
-**// end super important notice**
The above install steps create a `cloud9` directory in your current directory. Just `cd` into it
and run `bin/cloud9.sh` to start:
View
8 build/app.build.tmpl.js
@@ -10,16 +10,14 @@
"ext/commands" : "%d/ext.commands",
"apf" : "empty:",
"treehugger" : "empty:",
- "debug": "empty:",
+ "v8debug": "empty:",
"apf/elements": "%d/lib.apf/www/apf/elements",
"ace/worker": "%a",
"%m"
},
- include: ["%b/src/core.packed",
- "apf/elements/codeeditor",
- "apf/elements/debugger",
- "apf/elements/debughost",
+ include: ["%b/src/core.packed",
+ "apf/elements/codeeditor",
"ext/commands/commands",
"ext/uploadfiles/uploadfiles",
"%s"],
View
19 build/core.build.js
@@ -6,13 +6,12 @@
"text" : "build/text", // plugin for pulling in text! files
"core" : "plugins-client/cloud9.core/www/core",
"treehugger" : "node_modules/treehugger/lib/treehugger",
- "debug": "node_modules/v8debug/lib/v8debug",
+ "v8debug": "node_modules/v8debug/lib/v8debug",
"ext/main": "plugins-client/ext.main",
"apf-packaged": "plugins-client/lib.apf/www/apf-packaged"
},
include: [
"node_modules/ace/build/src/ace",
- "node_modules/ace/build/src/ace",
"node_modules/ace/build/src/theme-chrome",
"node_modules/ace/build/src/theme-clouds",
"node_modules/ace/build/src/theme-clouds_midnight",
@@ -46,14 +45,14 @@
"ext/main/main",
"treehugger/traverse",
"treehugger/js/parse",
- "debug/Breakpoint",
- "debug/ChromeDebugMessageStream",
- "debug/WSChromeDebugMessageStream",
- "debug/WSV8DebuggerService",
- "debug/DevToolsService",
- "debug/StandaloneV8DebuggerService",
- "debug/V8DebuggerService",
- "debug/V8Debugger"
+ "v8debug/Breakpoint",
+ "v8debug/ChromeDebugMessageStream",
+ "v8debug/WSChromeDebugMessageStream",
+ "v8debug/WSV8DebuggerService",
+ "v8debug/DevToolsService",
+ "v8debug/StandaloneV8DebuggerService",
+ "v8debug/V8DebuggerService",
+ "v8debug/V8Debugger"
],
out: "./src/core.packed.js",
inlineText: true,
View
9 configs/default.js
@@ -20,7 +20,7 @@ var fsUrl = "/workspace";
var vfsUrl = "/vfs";
var port = argv.p || process.env.PORT || 3131;
-var host = argv.l || "localhost";
+var host = argv.l || process.env.IP || "localhost";
var config = [
{
@@ -58,7 +58,7 @@ var config = [
debug: false,
fsUrl: fsUrl,
hosted: false,
- socketIoTransports: [/*"websocket", */"htmlfile", "xhr-multipart", "xhr-polling"],
+ socketIoTransports: ["websocket", "htmlfile", "xhr-multipart", "xhr-polling"],
bundledPlugins: [
"helloworld"
],
@@ -97,6 +97,7 @@ var config = [
//"ext/run/run", //Add location rule
"ext/runpanel/runpanel", //Add location rule
"ext/debugger/debugger", //Add location rule
+ "ext/dbg-node/dbg-node",
"ext/noderunner/noderunner", //Add location rule
"ext/console/console",
"ext/consolehints/consolehints",
@@ -128,6 +129,7 @@ var config = [
"ext/colorpicker/colorpicker",
"ext/gitblame/gitblame",
//"ext/githistory/githistory",
+ "ext/autosave/autosave",
"ext/revisions/revisions",
"ext/quicksearch/quicksearch",
"ext/language/liveinspect"
@@ -197,8 +199,7 @@ var config = [
"./cloud9.ide.revisions",
{
packagePath: "./cloud9.ide.settings",
- settingsPath: ".settings",
- absoluteSettingsPath: path.join(projectDir, ".settings"),
+ settingsPath: ".settings"
},
"./cloud9.ide.shell",
"./cloud9.ide.state",
View
96 doc/ext.extension_template/extension_template.js
@@ -0,0 +1,96 @@
+/**
+ * Extension Template for Cloud9 IDE
+ *
+ * Inserts a context menu item under the "Edit" menu, which, when
+ * clicked, displays a simple window with a "Close" button.
+ *
+ * This file is stripped of comments in order to provide a quick template for
+ * future extensions. Please reference our documentation for a list of what's
+ * going on.
+ *
+ * @copyright 2012, Ajax.org B.V.
+ * @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
+ */
+
+define(function(require, exports, module) {
+
+var ext = require("core/ext");
+var ide = require("core/ide");
+
+var menus = require("ext/menus/menus");
+var commands = require("ext/commands/commands");
+var markup = require("text!ext/extension_template/extension_template.xml");
+
+module.exports = ext.register("ext/extension_template/extension_template", {
+ name : "Extension Template",
+ dev : "Ajax.org",
+ alone : true,
+ deps : [],
+ type : ext.GENERAL,
+ markup : markup,
+
+ nodes : [],
+
+ init : function(){
+ var _self = this;
+ this.winExtensionTemplate = winExtensionTemplate;
+
+ commands.addCommand({
+ name: "sayhello",
+ hint: "I'll say something",
+ msg: "Popping window!",
+ bindKey: {mac: "Shift-1", win: "Ctrl-1"},
+ isAvailable : function() {
+ return true;
+ },
+ exec: function() {
+ _self.winExtensionTemplate.show()
+ }
+ });
+
+ this.nodes.push(
+ menus.addItemByPath("Edit/Extension Template", new apf.item({
+ command : "sayhello"
+ }), 5400)
+ );
+
+ /* Just a plain menu...
+ this.nodes.push(
+ menus.addItemByPath("Edit/Extension Template", new apf.item({
+ onclick : function(){
+ _self.winExtensionTemplate.show();
+ }
+ }), 5400)
+ ); */
+ },
+
+ hook : function(){
+ var _self = this;
+ ext.initExtension(this);
+ },
+
+ enable : function(){
+ this.nodes.each(function(item){
+ item.enable();
+ });
+ },
+
+ disable : function(){
+ this.nodes.each(function(item){
+ item.disable();
+ });
+ },
+
+ destroy : function(){
+ this.nodes.each(function(item){
+ item.destroy(true, true);
+ });
+ this.nodes = [];
+ },
+
+ closeExtensionTemplateWindow : function(){
+ this.winExtensionTemplate.hide();
+ }
+});
+
+});
View
26 doc/ext.extension_template/extension_template.xml
@@ -0,0 +1,26 @@
+<a:application xmlns:a="http://ajax.org/2005/aml">
+ <a:window
+ id = "winExtensionTemplate"
+ title = "Extension Template Window"
+ center = "true"
+ modal = "false"
+ buttons = "close"
+ skin = "bk-window"
+ kbclose = "true"
+ class = "relative"
+ width = "300">
+ <a:vbox>
+ <a:hbox padding="5" edge="10">
+ Hello World!
+ </a:hbox>
+ <a:hbox pack="end" padding="5" edge="6 10 10">
+ <a:button
+ caption = "Close"
+ skin = "btn-default-css3"
+ onclick = "
+ require('ext/extension_template/extension_template').closeExtensionTemplateWindow();"
+ />
+ </a:hbox>
+ </a:vbox>
+ </a:window>
+</a:application>
View
14 doc/ext.extension_template/package.json
@@ -0,0 +1,14 @@
+{
+ "name": "ext.template",
+ "version": "0.0.1",
+ "main": "extension_template.js",
+ "private": true,
+ "plugin": {
+ "provides": [
+ "ext.template"
+ ],
+ "consumes": [
+ "client-plugins"
+ ]
+ }
+}
View
40 package.json
@@ -12,44 +12,44 @@
"pm": "sm",
"dependencies": {
- "socket.io": "0.9.x",
"connect": "1.8.x",
"sourcemint-loader-js": "0.x",
"sourcemint-platform-nodejs": "0.x",
- "http-error": "~0.0.1",
- "simple-template": "~0.0.1",
+ "http-error": "0.0.1",
+ "simple-template": "0.0.1",
- "optimist": "~0.3.1",
+ "optimist": "0.3.4",
"dryice": "0.4.2",
"mappings": "0.1.x",
- "amd-loader": "~0.0.4",
+ "amd-loader": "0.0.4",
"async": "0.1.21",
- "netutil": "~0.0.1",
- "architect": ">=0.1.4",
- "connect-architect": "~0.0.1"
+ "netutil": "0.0.1",
+ "architect": "0.1.4",
+ "connect-architect": "0.0.3"
},
"devDependencies": {
- "nodeunit": "~0.7.4",
- "sinon": "~1.3.4",
- "rimraf": "~2.0.1",
- "vfs-local": "~0.0.0",
- "vfs-nodefs-adapter": "~0.0.1"
+ "nodeunit": "0.7.4",
+ "sinon": "1.3.4",
+ "rimraf": "2.0.1",
+ "vfs-local": "0.1.6",
+ "vfs-nodefs-adapter": "0.0.4"
},
"mappings": {
- "ace": ["npm", "https://github.com/ajaxorg/ace/tarball/78975a0fc26eda9137b9caf11b63fe6f1ea7283f"],
- "apf": ["npm", "https://github.com/ajaxorg/apf/tarball/0f03564345da764409b00e551a681337c7e1df96"],
+ "ace": ["npm", "https://github.com/ajaxorg/ace/tarball/97e40eb58050f7ee9dee435f9e2cf7fc0956a108"],
+ "apf": ["npm", "https://github.com/ajaxorg/apf/tarball/ca9053b1a9a499d587063f04cc02acf091d44b28"],
"asyncjs": ["npm", "https://github.com/ajaxorg/async.js/tarball/0b4ed5608a32c280a7690b5f52883d8d1fc0de08"],
- "jsDAV": ["npm", "https://github.com/ajaxorg/jsDAV/tarball/7fc5b36a5074668f40aad8b45f82a6fbbec04c88"],
+ "jsDAV": ["npm", "https://github.com/ajaxorg/jsDAV/tarball/53818b85736cbe12f63a7cd46e4cbc4214d1c64c"],
"v8debug": ["npm", "https://github.com/ajaxorg/lib-v8debug/tarball/d2fac9b09724cb2e75e2807191eace9bc27d3b52"],
- "packager": ["npm", "https://github.com/ajaxorg/packager/tarball/ae07ff93310d1625c48119e98141bbe5b2c26200"],
- "vfs": ["npm", "https://github.com/c9/vfs/tarball/be43f8b32f9b1c69923dd85ec9be7eb6836bbb29"],
+ "packager": ["npm", "https://github.com/ajaxorg/packager/tarball/01597eacd22ad660977d43c44b4001107117b8ea"],
+ "vfs": ["npm", "https://github.com/c9/vfs/tarball/61841e99eda6ea9a8b801fd145b9a0af286ad324"],
"vfs-architect":["npm", "https://github.com/c9/vfs-architect/tarball/43bd19b9e7b2ddb95bdc1116143ce7fb22c6a5d3"],
- "treehugger": ["npm", "https://github.com/ajaxorg/treehugger/tarball/cb8fd0483417ac6ffb8532b994d23dbf13ad9022"],
- "socket.io-client": ["npm", "https://github.com/ajaxorg/socket.io-client/tarball/9d0c0631f390538134a7d1f841db2c72d79f8cb4"]
+ "treehugger": ["npm", "https://github.com/ajaxorg/treehugger/tarball/8026fea03e87a5a773e87ae9d78e29fab912d52e"],
+ "socket.io": ["npm", "https://github.com/ajaxorg/socket.io/tarball/7aa252bab49e6bbc314dc2678b108b6e0876007a"],
+ "socket.io-client": ["npm", "https://github.com/ajaxorg/socket.io-client/tarball/35f0763ffcaa7ccc3c664460667577e77da82b10"]
},
"repository" : {
View
1  plugins-client/cloud9.core/www/core/ide.js
@@ -126,6 +126,7 @@ define(function(require, exports, module) {
retries++;
if (retries < 10 || retries < 60 && retries % 10 == 0 || retries % 50 == 0) {
sock.disconnect();
+ sock.remainingTransports = null;
sock.connect();
if (retries == 5) {
View
55 plugins-client/cloud9.core/www/core/util.js
@@ -1,3 +1,6 @@
+/*global tabEditors:true, winQuestion:true, winAlert:true, winAlertHeader:true
+winAlertMsg:true, winConfirm:true */
+
/**
* Utilities for the Ajax.org Cloud IDE
*
@@ -11,15 +14,19 @@ var markup = require("text!core/util.xml");
exports.escapeXpathString = function(name){
if (name.indexOf('"') > -1) {
- var out = [], parts = name.split('"');
+ var out = [];
+ var parts = name.split('"');
parts.each(function(part) {
out.push(part == '' ? "'\"'" : '"' + part + '"');
- })
+ });
return "concat(" + out.join(", ") + ")";
}
return '"' + name + '"';
-}
+};
+exports.isNewPage = function(page) {
+ return parseInt(page.$model.data.getAttribute("newfile"), 10) === 1;
+};
exports.alert = function(title, header, msg, onhide) {
if (!self.winAlert)
@@ -79,7 +86,7 @@ exports.removeInteractive = function (amlNode) {
var type = file.getAttribute("type");
require("core/util").question(
"Confirm Remove",
- "You are about to remove the " + type + " " + name,
+ "You are about to remove the " + (type || "item") + " " + name,
"Do you want continue? (This change cannot be undone)",
function () { // Yes
amlNode.confirmed = true;
@@ -114,8 +121,9 @@ exports.removeInteractive = function (amlNode) {
}
confirm(files.shift());
return false;
- } else
+ } else {
return true;
+ }
};
var SupportedIcons = {
@@ -149,7 +157,7 @@ var SupportedIcons = {
var contentTypes = {
"c9search": "text/x-c9search",
-
+
"js": "application/javascript",
"json": "application/json",
"css": "text/css",
@@ -213,7 +221,7 @@ var contentTypes = {
"sh": "application/x-sh",
"bash": "application/x-sh",
-
+
"xq": "text/x-xquery"
};
@@ -365,4 +373,37 @@ exports.replaceStaticPrefix = function (string) {
*/
exports.linkify=function(){var k="[a-z\\d.-]+://",h="(?:(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])",c="(?:(?:[^\\s!@#$%^&*()_=+[\\]{}\\\\|;:'\",.<>/?]+)\\.)+",n="(?:ac|ad|aero|ae|af|ag|ai|al|am|an|ao|aq|arpa|ar|asia|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|biz|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|cat|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|coop|com|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|info|int|in|io|iq|ir|is|it|je|jm|jobs|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mobi|mo|mp|mq|mr|ms|mt|museum|mu|mv|mw|mx|my|mz|name|na|nc|net|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|travel|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xn--0zwm56d|xn--11b5bs3a9aj6g|xn--80akhbyknj4f|xn--9t4b11yi5a|xn--deba0ad|xn--g6w251d|xn--hgbk6aj7f53bba|xn--hlcj6aya9esc7a|xn--jxalpdlp|xn--kgbechtv|xn--zckzah|ye|yt|yu|za|zm|zw)",f="(?:"+c+n+"|"+h+")",o="(?:[;/][^#?<>\\s]*)?",e="(?:\\?[^#<>\\s]*)?(?:#[^<>\\s]*)?",d="\\b"+k+"[^<>\\s]+",a="\\b"+f+o+e+"(?!\\w)",m="mailto:",j="(?:"+m+")?[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@"+f+e+"(?!\\w)",l=new RegExp("(?:"+d+"|"+a+"|"+j+")","ig"),g=new RegExp("^"+k,"i"),b={"'":"`",">":"<",")":"(","]":"[","}":"{","B;":"B+","b:":"b9"},i={callback:function(q,p){return p?'<a href="'+p+'" title="'+p+'">'+q+"</a>":q},punct_regexp:/(?:[!?.,:;'"]|(?:&|&amp;)(?:lt|gt|quot|apos|raquo|laquo|rsaquo|lsaquo);)$/};return function(u,z){z=z||{};var w,v,A,p,x="",t=[],s,E,C,y,q,D,B,r;for(v in i){if(z[v]===undefined){z[v]=i[v]}}while(w=l.exec(u)){A=w[0];E=l.lastIndex;C=E-A.length;if(/[\/:]/.test(u.charAt(C-1))){continue}do{y=A;r=A.substr(-1);B=b[r];if(B){q=A.match(new RegExp("\\"+B+"(?!$)","g"));D=A.match(new RegExp("\\"+r,"g"));if((q?q.length:0)<(D?D.length:0)){A=A.substr(0,A.length-1);E--}}if(z.punct_regexp){A=A.replace(z.punct_regexp,function(F){E-=F.length;return""})}}while(A.length&&A!==y);p=A;if(!g.test(p)){p=(p.indexOf("@")!==-1?(!p.indexOf(m)?"":m):!p.indexOf("irc.")?"irc://":!p.indexOf("ftp.")?"ftp://":"http://")+p}if(s!=C){t.push([u.slice(s,C)]);s=E}t.push([A,p])}t.push([u.substr(s)]);for(v=0;v<t.length;v++){x+=z.callback.apply(window,t[v])}return x||u}}();
+exports.pageHasChanged = function(page) {
+ if (!page) {
+ throw new Error("Page object parameter missing");
+ }
+ return page.changed === 1;
+};
+
+exports.pageIsCode = function(page) {
+ if (!page) {
+ throw new Error("Page object parameter missing");
+ }
+
+ return page.type === "ext/code/code";
+};
+
+exports.stripWSFromPath = function(path) {
+ var docPath = (path || "").replace(ide.davPrefix, "");
+ docPath = docPath.charAt(0) === "/" ? docPath.substr(1) : docPath;
+ return docPath;
+};
+
+exports.getDocPath = function(page) {
+ if (!page && tabEditors) {
+ page = tabEditors.getPage();
+ }
+
+ // Can we rely on `name`?
+ // What follows is a hacky way to get a path that we can use on
+ // the server. I am sure that these workspace string manipulation
+ // functions are somewhere...to be fixed.
+ return exports.stripWSFromPath(page.name);
+};
+
});
View
298 plugins-client/ext.autosave/autosave.js
@@ -0,0 +1,298 @@
+/*global btnSave:true, tabEditors:true, saveStatus:true*/
+/*
+ * Autosave Module for the Cloud9 IDE
+ *
+ * @author Sergi Mansilla <sergi@c9.io>
+ * @copyright 2012, Ajax.org B.V.
+ */
+
+define(function(require, exports, module) {
+
+var ide = require("core/ide");
+var ext = require("core/ext");
+var Util = require("core/util");
+
+var Save = require("ext/save/save");
+var settings = require("ext/settings/settings");
+var markupSettings = require("text!ext/autosave/settings.xml");
+var stripws = require("ext/stripws/stripws");
+var tooltip = require("ext/tooltip/tooltip");
+
+var INTERVAL = 60000;
+var CHANGE_TIMEOUT = 500;
+
+module.exports = ext.register("ext/autosave/autosave", {
+ name: "Autosave",
+ dev: "Cloud9",
+ alone: true,
+ type: ext.GENERAL,
+ offline: true,
+ nodes: [],
+
+ docChangeTimeout: null,
+ docChangeListeners: {},
+
+ hook: function() {
+ var self = this;
+ settings.addSettings("General", markupSettings);
+ ide.addEventListener("settings.load", function(e){
+ e.ext.setDefaults("general", [["autosaveenabled", "false"]]);
+ self.isAutoSaveEnabled = apf.isTrue(e.model.queryValue("general/@autosaveenabled")) || self.tempEnableAutoSave;
+ });
+
+ ide.addEventListener("settings.save", function(e) {
+ if (!e.model.data)
+ return;
+
+ self.isAutoSaveEnabled = apf.isTrue(e.model.queryValue("general/@autosaveenabled")) || self.tempEnableAutoSave;
+ });
+
+ btnSave.setAttribute("caption", "");
+ btnSave.setAttribute("margin", "0 20");
+ btnSave.removeAttribute("tooltip");
+ btnSave.removeAttribute("command");
+ apf.setStyleClass(btnSave.$ext, "btnSave");
+
+ tooltip.add(btnSave, {
+ message : "Changes to your file are automatically saved.<br />\
+ View all your changes through <a href='javascript:void(0)' \
+ onclick='require(\"ext/revisions/revisions\").toggle();' \
+ class='revisionsInfoLink'>the Revision History pane</a>. \
+ Rollback to a previous state, or make comparisons.",
+ width : "250px",
+ hideonclick : true
+ });
+
+ this.$onOpenFileFn = this.onOpenFile.bind(this);
+ this.$onCloseFileFn = this.onCloseFile.bind(this);
+ this.$onBeforeSaveWarning = this.onBeforeSaveWarning.bind(this);
+
+ ide.addEventListener("afteropenfile", this.$onOpenFileFn);
+ ide.addEventListener("closefile", this.$onCloseFileFn);
+ ide.addEventListener("beforesavewarn", this.$onBeforeSaveWarning);
+ },
+
+ /////////////////////
+ // Event listeners //
+ /////////////////////
+
+ onBeforeSaveWarning: function(e) {
+ var isNewFile = apf.isTrue(e.doc.getNode().getAttribute("newfile"));
+ if (!isNewFile && this.isAutoSaveEnabled) {
+ this.save(e.doc.$page);
+ return false;
+ }
+ },
+
+ onOpenFile: function(data) {
+ if (!data || !data.doc)
+ return;
+
+ var self = this;
+ var doc = data.doc;
+ var page = doc.$page;
+ if (!page || !Util.pageIsCode(page)) {
+ return;
+ }
+
+ // Add document change listeners to an array of functions so that we
+ // can clean up on disable plugin.
+ var path = Util.getDocPath(page);
+ if (path && !this.docChangeListeners[path]) {
+ this.docChangeListeners[path] = function(e) {
+ self.onDocChange.call(self, e, doc);
+ };
+ }
+
+ if (!Util.isNewPage(page)) {
+ this.setSaveButtonCaption();
+ }
+
+ (doc.acedoc || doc).addEventListener("change", this.docChangeListeners[path]);
+ },
+
+ onCloseFile: function(e) {
+ if (tabEditors.getPages().length == 1)
+ btnSave.hide();
+ else
+ this.setSaveButtonCaption(e.page);
+
+ this.save(e.page);
+ },
+
+ onDocChange: function(e, doc) {
+ var page = doc.$page;
+ if (page && this.isAutoSaveEnabled && !Util.isNewPage(page)) {
+ clearTimeout(this.docChangeTimeout);
+ this.docChangeTimeout = setTimeout(function(self) {
+ self.setSaveButtonCaption();
+ stripws.disable();
+ self.save(page);
+ }, CHANGE_TIMEOUT, this);
+ }
+ },
+
+ setSaveButtonCaption: function(page) {
+ if (!self.btnSave)
+ return;
+
+ var SAVING = 0;
+ var SAVED = 1;
+
+ btnSave.show();
+ var page = page || tabEditors.getPage();
+ if (page) {
+ var hasChanged = Util.pageHasChanged(page);
+ if (this.isAutoSaveEnabled && hasChanged) {
+ if (btnSave.currentState !== SAVING) {
+ apf.setStyleClass(btnSave.$ext, "saving", ["saved"]);
+ apf.setStyleClass(saveStatus, "saving", ["saved"]);
+ btnSave.currentState = SAVING;
+ btnSave.setCaption("Saving");
+ }
+ }
+ else if (!hasChanged) {
+ if (btnSave.currentState !== SAVED) {
+ apf.setStyleClass(btnSave.$ext, "saved", ["saving"]);
+ apf.setStyleClass(saveStatus, "saved", ["saving"]);
+ btnSave.currentState = SAVED;
+ btnSave.setCaption("Changes saved");
+ }
+ }
+ }
+ else {
+ btnSave.setCaption("");
+ }
+ },
+
+ doAutoSave: function() {
+ // Take advantage of the interval and dump our offlineQueue into
+ // localStorage.
+ localStorage.offlineQueue = JSON.stringify(this.offlineQueue);
+
+ if (typeof tabEditors === "undefined" || !this.isAutoSaveEnabled)
+ return;
+
+ this.save(tabEditors.getPage());
+ },
+
+
+ /**
+ * Autosave#save([page])
+ * - page(Object): Page that contains the document to be saved. In case it is
+ * not provided, the current one will be used
+ *
+ * Prompts a save of the desired document.
+ **/
+ save: function(page, forceSave) {
+ if (!page || !page.$at)
+ page = tabEditors.getPage();
+
+ if (!page)
+ return;
+
+ if ((forceSave !== true) && (!Util.pageHasChanged(page) || !Util.pageIsCode(page)))
+ return;
+
+ var node = page.$doc.getNode();
+ if (node.getAttribute("newfile") || node.getAttribute("debug"))
+ return;
+
+ var _self = this;
+ Save.quicksave(page, function() {
+ stripws.enable();
+ _self.setSaveButtonCaption(page);
+ }, true);
+ },
+
+ disableEventListeners: function() {
+ if (this.$onOpenFileFn)
+ ide.removeEventListener("afteropenfile", this.$onOpenFileFn);
+
+ if (this.$onCloseFileFn)
+ ide.removeEventListener("closefile", this.$onCloseFileFn);
+
+ if (this.$onBeforeSaveWarning)
+ ide.removeEventListener("beforesavewarn", this.$onBeforeSaveWarning);
+ },
+
+ enableEventListeners: function() {
+ if (this.$onOpenFileFn)
+ ide.addEventListener("afteropenfile", this.$onOpenFileFn);
+
+ if (this.$onCloseFileFn)
+ ide.addEventListener("closefile", this.$onCloseFileFn);
+
+ if (this.$onBeforeSaveWarning)
+ ide.addEventListener("beforesavewarn", this.$onBeforeSaveWarning);
+ },
+
+ enable: function() {
+ this.nodes.each(function(item) {
+ item.enable();
+ });
+
+ tabEditors.getPages().forEach(function(page) {
+ var listener = this.docChangeListeners[page.name];
+ if (listener) {
+ page.$doc.removeEventListener("change", listener);
+ if (page.$doc.acedoc) {
+ page.$doc.acedoc.removeEventListener("change", listener);
+ }
+
+ (page.$doc.acedoc || page.$doc).addEventListener("change", listener);
+ }
+ }, this);
+
+ this.enableEventListeners();
+ },
+
+ disable: function() {
+ this.hide();
+ this.nodes.each(function(item){
+ item.disable();
+ });
+
+ tabEditors.getPages().forEach(function(page) {
+ var listener = this.docChangeListeners[page.name];
+ if (listener) {
+ page.$doc.removeEventListener("change", listener);
+ if (page.$doc.acedoc) {
+ page.$doc.acedoc.removeEventListener("change", listener);
+ }
+ }
+ if (page.$mdlRevisions) {
+ delete page.$mdlRevisions;
+ }
+ }, this);
+
+ this.disableEventListeners();
+ },
+
+ destroy: function() {
+ if (this.saveInterval) {
+ clearInterval(this.saveInterval);
+ }
+
+ this.disableEventListeners();
+
+ tabEditors.getPages().forEach(function(page) {
+ var listener = this.docChangeListeners[page.name];
+ if (listener) {
+ page.$doc.removeEventListener("change", listener);
+ if (page.$doc.acedoc) {
+ page.$doc.acedoc.removeEventListener("change", listener);
+ }
+ }
+ if (page.$mdlRevisions) {
+ delete page.$mdlRevisions;
+ }
+ }, this);
+
+ this.nodes.each(function(item){
+ item.destroy(true, true);
+ });
+ this.nodes = [];
+ }
+});
+});
View
0  plugins-client/ext.revisions/settings.xml → plugins-client/ext.autosave/settings.xml
File renamed without changes
View
84 plugins-client/ext.beautify/beautify.js
@@ -37,22 +37,31 @@ module.exports = ext.register("ext/beautify/beautify", {
if (!editor)
editor = editors.currentEditor;
- var sel = editor.getSelection();
- var doc = editor.getDocument();
+ if (editor.ceEditor)
+ editor = editor.ceEditor.$editor;
+
+ var sel = editor.selection;
+ var session = editor.session;
var range = sel.getRange();
- var value = doc.getTextRange(range);
// Load up current settings data
- var preserveEmpty = apf.isTrue(settings.model.queryValue("beautify/jsbeautify/@preserveempty"));
- var keepIndentation = apf.isTrue(settings.model.queryValue("beautify/jsbeautify/@keeparrayindentation"));
- var jsLintHappy = apf.isTrue(settings.model.queryValue("beautify/jsbeautify/@jslinthappy"));
- var braces = settings.model.queryValue("beautify/jsbeautify/@braces") || "end-expand";
- var indentSize = settings.model.queryValue("editors/code/@tabsize");
- var indentTab = apf.isTrue(settings.model.queryValue("editors/code/@softtabs")) ? " " : "\t";
-
- if (indentTab == "\t") indentSize = 1;
+ var options = {};
+ options.space_before_conditional = apf.isTrue(settings.model.queryValue("beautify/jsbeautify/@space_before_conditional"));
+ options.keep_array_indentation = apf.isTrue(settings.model.queryValue("beautify/jsbeautify/@keeparrayindentation"));
+ options.preserve_newlines = apf.isTrue(settings.model.queryValue("beautify/jsbeautify/@preserveempty"));
+ options.unescape_strings = apf.isTrue(settings.model.queryValue("beautify/jsbeautify/@unescape_strings"));
+ options.jslint_happy = apf.isTrue(settings.model.queryValue("beautify/jsbeautify/@jslinthappy"));
+ options.brace_style = settings.model.queryValue("beautify/jsbeautify/@braces");
+
+ if (session.getUseSoftTabs()) {
+ options.indent_char = " ";
+ options.indent_size = session.getTabSize();
+ } else {
+ options.indent_char = "\t";
+ options.indent_size = 1;
+ }
- var line = doc.getLine(range.start.row);
+ var line = session.getLine(range.start.row);
var indent = line.match(/^\s*/)[0];
var trim = false;
@@ -61,26 +70,41 @@ module.exports = ext.register("ext/beautify/beautify", {
else
trim = true;
+
+ var value = session.getTextRange(range);
+ var syntax = session.syntax;
+ var type = null;
+
+ if (syntax == "javascript") {
+ type = "js";
+ } else if (syntax == "css") {
+ type = "css";
+ } if (/^\s*<!?\w/.test(value)) {
+ type = "html";
+ } else if (syntax == "html") {
+ if (/[^<]+?{[\s\-\w]+:[^}]+;/.test(value))
+ type = "css";
+ else if (/<\w+[ \/>]/.test(value))
+ type = "html";
+ else
+ type = "js";
+ }
+
try {
- value = jsbeautify.js_beautify(value, {
- indent_size: indentSize,
- indent_char: indentTab,
- preserve_newlines: preserveEmpty,
- keep_array_indentation: keepIndentation,
- brace_style: braces,
- jslint_happy: jsLintHappy
- });
- value = value.replace(/^/gm, indent);
- if (trim) value = value.trim();
+ value = jsbeautify[type + "_beautify"](value, options);
+ if (trim)
+ value = value.replace(/^/gm, indent).trim();
+ if (range.end.column == 0)
+ value += "\n" + indent;
}
catch (e) {
- util.alert("Error",
- "This code could not be beautified",
- "Please correct any JavaScript errors and try again");
+ util.alert("Error",
+ "This code could not be beautified",
+ '"' + syntax + "\" is not supported yet");
return;
}
- var end = doc.replace(range, value);
+ var end = session.replace(range, value);
sel.setSelectionRange(Range.fromPoints(range.start, end));
},
@@ -90,7 +114,7 @@ module.exports = ext.register("ext/beautify/beautify", {
var _self = this;
this.nodes.push(
- menus.addItemByPath("Tools/Beautify Selection",
+ menus.addItemByPath("Tools/Beautify Selection",
this.mnuItem = new apf.item({
disabled : "true",
command : "beautify"
@@ -105,7 +129,7 @@ module.exports = ext.register("ext/beautify/beautify", {
isAvailable : function(editor){
if (editor && editor.ceEditor) {
var range = editor.ceEditor.$editor.getSelectionRange();
- return range.start.row != range.end.row
+ return range.start.row != range.end.row
|| range.start.column != range.end.column;
}
return false;
@@ -123,8 +147,8 @@ module.exports = ext.register("ext/beautify/beautify", {
["keeparrayindentation", "false"],
["jslinthappy", "false"],
["braces", "end-expand"],
- ["softtabs", "true"],
- ["tabsize", "4"]
+ ["space_before_conditional", "true"],
+ ["unescape_strings", "true"]
]);
});
View
2  plugins-client/ext.beautify/res/jsbeautify/jsbeautify-min.js
@@ -1 +1 @@
-define(function(a,b,c){b.js_beautify=function(a,b){function T(){x=0;if(p>=G)return["","TK_EOF"];v=!1;var a=c.charAt(p);p+=1;var b=F&&P(j.mode);if(b){var e=0;while(S(a,m)){a==="\n"?(H(),d.push("\n"),w=!0,e=0):a==="\t"?e+=4:a!=="\r"&&(e+=1);if(p>=G)return["","TK_EOF"];a=c.charAt(p),p+=1}j.indentation_baseline===-1&&(j.indentation_baseline=e);if(w){var h;for(h=0;h<j.indentation_level+1;h+=1)d.push(l);if(j.indentation_baseline!==-1)for(h=0;h<e-j.indentation_baseline;h++)d.push(" ")}}else{while(S(a,m)){a==="\n"&&(x+=C?x<=C?1:0:1);if(p>=G)return["","TK_EOF"];a=c.charAt(p),p+=1}if(B&&x>1)for(h=0;h<x;h+=1)J(h===0),w=!0;v=x>0}if(S(a,n)){if(p<G)while(S(c.charAt(p),n)){a+=c.charAt(p),p+=1;if(p===G)break}if(p!==G&&a.match(/^[0-9]+[Ee]$/)&&(c.charAt(p)==="-"||c.charAt(p)==="+")){var i=c.charAt(p);p+=1;var k=T(p);a+=i+k[0];return[a,"TK_WORD"]}if(a==="in")return[a,"TK_OPERATOR"];v&&f!=="TK_OPERATOR"&&f!=="TK_EQUALS"&&!j.if_line&&(B||g!=="var")&&J();return[a,"TK_WORD"]}if(a==="("||a==="[")return[a,"TK_START_EXPR"];if(a===")"||a==="]")return[a,"TK_END_EXPR"];if(a==="{")return[a,"TK_START_BLOCK"];if(a==="}")return[a,"TK_END_BLOCK"];if(a===";")return[a,"TK_SEMICOLON"];if(a==="/"){var q="",s=!0;if(c.charAt(p)==="*"){p+=1;if(p<G)while((c.charAt(p)!=="*"||!c.charAt(p+1)||c.charAt(p+1)!=="/")&&p<G){a=c.charAt(p),q+=a;if(a==="\r"||a==="\n")s=!1;p+=1;if(p>=G)break}p+=2;return s?["/*"+q+"*/","TK_INLINE_COMMENT"]:["/*"+q+"*/","TK_BLOCK_COMMENT"]}if(c.charAt(p)==="/"){q=a;while(c.charAt(p)!=="\r"&&c.charAt(p)!=="\n"){q+=c.charAt(p),p+=1;if(p>=G)break}p+=1,v&&J();return[q,"TK_COMMENT"]}}if(a==="'"||a==='"'||a==="/"&&(f==="TK_WORD"&&S(g,["return","do"])||f==="TK_COMMENT"||f==="TK_START_EXPR"||f==="TK_START_BLOCK"||f==="TK_END_BLOCK"||f==="TK_OPERATOR"||f==="TK_EQUALS"||f==="TK_EOF"||f==="TK_SEMICOLON")){var t=a,u=!1,y=a;if(p<G)if(t==="/"){var z=!1;while(u||z||c.charAt(p)!==t){y+=c.charAt(p),u?u=!1:(u=c.charAt(p)==="\\",c.charAt(p)==="["?z=!0:c.charAt(p)==="]"&&(z=!1)),p+=1;if(p>=G)return[y,"TK_STRING"]}}else while(u||c.charAt(p)!==t){y+=c.charAt(p),u?u=!1:u=c.charAt(p)==="\\",p+=1;if(p>=G)return[y,"TK_STRING"]}p+=1,y+=t;if(t==="/")while(p<G&&S(c.charAt(p),n))y+=c.charAt(p),p+=1;return[y,"TK_STRING"]}if(a==="#"){if(d.length===0&&c.charAt(p)==="!"){y=a;while(p<G&&a!="\n")a=c.charAt(p),y+=a,p+=1;d.push(I(y)+"\n"),J();return T()}var A="#";if(p<G&&S(c.charAt(p),r)){do a=c.charAt(p),A+=a,p+=1;while(p<G&&a!=="#"&&a!=="=");a!=="#"&&(c.charAt(p)==="["&&c.charAt(p+1)==="]"?(A+="[]",p+=2):c.charAt(p)==="{"&&c.charAt(p+1)==="}"&&(A+="{}",p+=2));return[A,"TK_WORD"]}}if(a==="<"&&c.substring(p-1,p+3)==="<!--"){p+=3,j.in_html_comment=!0;return["<!--","TK_COMMENT"]}if(a==="-"&&j.in_html_comment&&c.substring(p-1,p+2)==="-->"){j.in_html_comment=!1,p+=2,v&&J();return["-->","TK_COMMENT"]}if(S(a,o)){while(p<G&&S(a+c.charAt(p),o)){a+=c.charAt(p),p+=1;if(p>=G)break}return a==="="?[a,"TK_EQUALS"]:[a,"TK_OPERATOR"]}return[a,"TK_UNKNOWN"]}function S(a,b){for(var c=0;c<b.length;c+=1)if(b[c]===a)return!0;return!1}function R(){u=j.mode==="DO_BLOCK",k.length>0&&(j=k.pop())}function Q(a){return a==="[EXPRESSION]"||a==="[INDENTED-EXPRESSION]"||a==="(EXPRESSION)"}function P(a){return a==="[EXPRESSION]"||a==="[INDENTED-EXPRESSION]"}function O(a){j&&k.push(j),j={previous_mode:j?j.mode:"BLOCK",mode:a,var_line:!1,var_line_tainted:!1,var_line_reindented:!1,in_html_comment:!1,if_line:!1,in_case:!1,eat_next_space:!1,indentation_baseline:-1,indentation_level:j?j.indentation_level+(j.var_line&&j.var_line_reindented?1:0):D,ternary_depth:0}}function N(){d.length&&d[d.length-1]===l&&d.pop()}function M(){j.indentation_level+=1}function L(){w=!1,j.eat_next_space=!1,d.push(e)}function K(){if(j.eat_next_space)j.eat_next_space=!1;else{var a=" ";d.length&&(a=d[d.length-1]),a!==" "&&a!=="\n"&&a!==l&&d.push(" ")}}function J(a){j.eat_next_space=!1;if(!F||!P(j.mode)){a=typeof a=="undefined"?!0:a,j.if_line=!1,H();if(!d.length)return;if(d[d.length-1]!=="\n"||!a)w=!0,d.push("\n");for(var b=0;b<j.indentation_level;b+=1)d.push(l);j.var_line&&j.var_line_reindented&&(A===" "?d.push(" "):d.push(l))}}function I(a){return a.replace(/^\s\s*|\s\s*$/,"")}function H(a){a=typeof a=="undefined"?!1:a;while(d.length&&(d[d.length-1]===" "||d[d.length-1]===l||a&&(d[d.length-1]==="\n"||d[d.length-1]==="\r")))d.pop()}var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x;b=b?b:{};var y;b.space_after_anon_function!==undefined&&b.jslint_happy===undefined&&(b.jslint_happy=b.space_after_anon_function),b.braces_on_own_line!==undefined&&(y=b.braces_on_own_line?"expand":"collapse"),y=b.brace_style?b.brace_style:y?y:"collapse";var z=b.indent_size?b.indent_size:4,A=b.indent_char?b.indent_char:" ",B=typeof b.preserve_newlines=="undefined"?!0:b.preserve_newlines,C=typeof b.max_preserve_newlines=="undefined"?!1:b.max_preserve_newlines,D=b.indent_level?b.indent_level:0,E=b.jslint_happy==="undefined"?!1:b.jslint_happy,F=typeof b.keep_array_indentation=="undefined"?!1:b.keep_array_indentation;w=!1;var G=a.length;l="";while(z>0)l+=A,z-=1;c=a,i="",f="TK_START_EXPR",g="",h="",d=[],u=!1,m="\n\r\t ".split(""),n="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$".split(""),r="0123456789".split(""),o="+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::".split(" "),q="continue,try,throw,return,var,if,switch,case,default,for,while,break,function".split(","),k=[],O("BLOCK"),p=0;for(;;){var U=T(p);e=U[0],t=U[1];if(t==="TK_EOF")break;switch(t){case"TK_START_EXPR":if(e==="["){if(f==="TK_WORD"||g===")"){S(g,q)&&K(),O("(EXPRESSION)"),L();break}j.mode==="[EXPRESSION]"||j.mode==="[INDENTED-EXPRESSION]"?h==="]"&&g===","?(j.mode==="[EXPRESSION]"&&(j.mode="[INDENTED-EXPRESSION]",F||M()),O("[EXPRESSION]"),F||J()):g==="["?(j.mode==="[EXPRESSION]"&&(j.mode="[INDENTED-EXPRESSION]",F||M()),O("[EXPRESSION]"),F||J()):O("[EXPRESSION]"):O("[EXPRESSION]")}else O("(EXPRESSION)");g===";"||f==="TK_START_BLOCK"?J():f!=="TK_END_EXPR"&&f!=="TK_START_EXPR"&&f!=="TK_END_BLOCK"&&g!=="."&&(f!=="TK_WORD"&&f!=="TK_OPERATOR"?K():i==="function"||i==="typeof"?E&&K():(S(g,q)||g==="catch")&&K()),L();break;case"TK_END_EXPR":if(e==="]")if(F){if(g==="}"){N(),L(),R();break}}else if(j.mode==="[INDENTED-EXPRESSION]"&&g==="]"){R(),J(),L();break}R(),L();break;case"TK_START_BLOCK":i==="do"?O("DO_BLOCK"):O("BLOCK"),y=="expand"?(f!=="TK_OPERATOR"&&(g==="return"||g==="="?K():J(!0)),L(),M()):(f!=="TK_OPERATOR"&&f!=="TK_START_EXPR"?f==="TK_START_BLOCK"?J():K():P(j.previous_mode)&&g===","&&(h==="}"?K():J()),M(),L());break;case"TK_END_BLOCK":R(),y=="expand"?(g!=="{"&&J(),L()):(f==="TK_START_BLOCK"?w?N():H():P(j.mode)&&F?(F=!1,J(),F=!0):J(),L());break;case"TK_WORD":if(u){K(),L(),K(),u=!1;break}if(e==="function"){j.var_line&&(j.var_line_reindented=!0);if((w||g===";")&&g!=="{"){x=w?x:0,B||(x=1);for(var V=0;V<2-x;V++)J(!1)}}if(e==="case"||e==="default"){g===":"?N():(j.indentation_level--,J(),j.indentation_level++),L(),j.in_case=!0;break}s="NONE",f==="TK_END_BLOCK"?S(e.toLowerCase(),["else","catch","finally"])?y=="expand"||y=="end-expand"?s="NEWLINE":(s="SPACE",K()):s="NEWLINE":f!=="TK_SEMICOLON"||j.mode!=="BLOCK"&&j.mode!=="DO_BLOCK"?f==="TK_SEMICOLON"&&Q(j.mode)?s="SPACE":f==="TK_STRING"?s="NEWLINE":f==="TK_WORD"?(g==="else"&&H(!0),s="SPACE"):f==="TK_START_BLOCK"?s="NEWLINE":f==="TK_END_EXPR"&&(K(),s="NEWLINE"):s="NEWLINE",S(e,q)&&g!==")"&&(g=="else"?s="SPACE":s="NEWLINE"),j.if_line&&f==="TK_END_EXPR"&&(j.if_line=!1);if(S(e.toLowerCase(),["else","catch","finally"]))f!=="TK_END_BLOCK"||y=="expand"||y=="end-expand"?J():(H(!0),K());else if(s==="NEWLINE"){if(f!=="TK_START_EXPR"&&g!=="="&&g!==","||e!=="function")e==="function"&&g=="new"?K():g==="return"||g==="throw"?K():f!=="TK_END_EXPR"?(f!=="TK_START_EXPR"||e!=="var")&&g!==":"&&(e==="if"&&i==="else"&&g!=="{"?K():(j.var_line=!1,j.var_line_reindented=!1,J())):S(e,q)&&g!=")"&&(j.var_line=!1,j.var_line_reindented=!1,J())}else P(j.mode)&&g===","&&h==="}"?J():s==="SPACE"&&K();L(),i=e,e==="var"&&(j.var_line=!0,j.var_line_reindented=!1,j.var_line_tainted=!1),e==="if"&&(j.if_line=!0),e==="else"&&(j.if_line=!1);break;case"TK_SEMICOLON":L(),j.var_line=!1,j.var_line_reindented=!1,j.mode=="OBJECT"&&(j.mode="BLOCK");break;case"TK_STRING":f==="TK_START_BLOCK"||f==="TK_END_BLOCK"||f==="TK_SEMICOLON"?J():f==="TK_WORD"&&K(),L();break;case"TK_EQUALS":j.var_line&&(j.var_line_tainted=!0),K(),L(),K();break;case"TK_OPERATOR":var W=!0,X=!0;j.var_line&&e===","&&Q(j.mode)&&(j.var_line_tainted=!1);if(j.var_line&&e===","){if(j.var_line_tainted){L(),j.var_line_reindented=!0,j.var_line_tainted=!1,J();break}j.var_line_tainted=!1}if(g==="return"||g==="throw"){K(),L();break}if(e===":"&&j.in_case){L(),J(),j.in_case=!1;break}if(e==="::"){L();break}if(e===","){j.var_line?j.var_line_tainted?(L(),J(),j.var_line_tainted=!1):(L(),K()):f==="TK_END_BLOCK"&&j.mode!=="(EXPRESSION)"?(L(),j.mode==="OBJECT"&&g==="}"?J():K()):j.mode==="OBJECT"?(L(),J()):(L(),K());break}S(e,["--","++","!"])||S(e,["-","+"])&&(S(f,["TK_START_BLOCK","TK_START_EXPR","TK_EQUALS","TK_OPERATOR"])||S(g,q))?(W=!1,X=!1,g===";"&&Q(j.mode)&&(W=!0),f==="TK_WORD"&&S(g,q)&&(W=!0),j.mode==="BLOCK"&&(g==="{"||g===";")&&J()):e==="."?W=!1:e===":"?j.ternary_depth==0?(j.mode="OBJECT",W=!1):j.ternary_depth-=1:e==="?"&&(j.ternary_depth+=1),W&&K(),L(),X&&K(),e!=="!";break;case"TK_BLOCK_COMMENT":var Y=e.split(/\x0a|\x0d\x0a/);if(/^\/\*\*/.test(e)){J(),d.push(Y[0]);for(V=1;V<Y.length;V++)J(),d.push(" "),d.push(I(Y[V]))}else{Y.length>1?(J(),H()):K();for(V=0;V<Y.length;V++)d.push(Y[V]),d.push("\n")}J();break;case"TK_INLINE_COMMENT":K(),L(),Q(j.mode)?K():J();break;case"TK_COMMENT":v?J():K(),L(),J();break;case"TK_UNKNOWN":(g==="return"||g==="throw")&&K(),L()}h=g,f=t,g=e}return d.join("").replace(/[\n ]+$/,"")}})
+define(function(e,t,n){function r(e,t){function B(e){e=typeof e=="undefined"?!1:e;while(r.length&&(r[r.length-1]===" "||r[r.length-1]===c||r[r.length-1]===T||e&&(r[r.length-1]==="\n"||r[r.length-1]==="\r")))r.pop()}function j(e){return e.replace(/^\s\s*|\s\s*$/,"")}function F(e){e=e.replace(/\x0d/g,"");var t=[],n=e.indexOf("\n");while(n!==-1)t.push(e.substring(0,n)),e=e.substring(n+1),n=e.indexOf("\n");return e.length&&t.push(e),t}function I(){var e=M;M=!1,q(),M=e}function q(e){f.eat_next_space=!1;if(M&&V(f.mode))return;e=typeof e=="undefined"?!0:e,f.if_line=!1,B();if(!r.length)return;if(r[r.length-1]!=="\n"||!e)S=!0,r.push("\n");T&&r.push(T);for(var t=0;t<f.indentation_level;t+=1)r.push(c);f.var_line&&f.var_line_reindented&&r.push(c),f.case_body&&r.push(c)}function R(){if(s==="TK_COMMENT")return q();if(f.eat_next_space){f.eat_next_space=!1;return}var e=" ";r.length&&(e=r[r.length-1]),e!==" "&&e!=="\n"&&e!==c&&r.push(" ")}function U(){S=!1,f.eat_next_space=!1,r.push(i)}function z(){f.indentation_level+=1}function W(){r.length&&r[r.length-1]===c&&r.pop()}function X(e){f&&l.push(f),f={previous_mode:f?f.mode:"BLOCK",mode:e,var_line:!1,var_line_tainted:!1,var_line_reindented:!1,in_html_comment:!1,if_line:!1,in_case_statement:!1,in_case:!1,case_body:!1,eat_next_space:!1,indentation_baseline:-1,indentation_level:f?f.indentation_level+(f.case_body?1:0)+(f.var_line&&f.var_line_reindented?1:0):0,ternary_depth:0}}function V(e){return e==="[EXPRESSION]"||e==="[INDENTED-EXPRESSION]"}function $(e){return G(e,["[EXPRESSION]","(EXPRESSION)","(FOR-EXPRESSION)","(COND-EXPRESSION)"])}function J(){w=f.mode==="DO_BLOCK";if(l.length>0){var e=f.mode;f=l.pop(),f.previous_mode=e}}function K(e,t){for(var n=0;n<e.length;n++){var r=j(e[n]);if(r.charAt(0)!==t)return!1}return!0}function Q(e){return G(e,["case","return","do","if","throw","else"])}function G(e,t){for(var n=0;n<t.length;n+=1)if(t[n]===e)return!0;return!1}function Y(e){var t=v,r=n.charAt(t);while(G(r,h)&&r!==e){t++;if(t>=H)return 0;r=n.charAt(t)}return r}function Z(){var e,t;x=0;if(v>=H)return["","TK_EOF"];E=!1;var i=n.charAt(v);v+=1;var u=M&&V(f.mode);if(u){var a=0;while(G(i,h)){i==="\n"?(B(),r.push("\n"),S=!0,a=0):i===" "?a+=4:i!=="\r"&&(a+=1);if(v>=H)return["","TK_EOF"];i=n.charAt(v),v+=1}f.indentation_baseline===-1&&(f.indentation_baseline=a);if(S){for(e=0;e<f.indentation_level+1;e+=1)r.push(c);if(f.indentation_baseline!==-1)for(e=0;e<a-f.indentation_baseline;e++)r.push(" ")}}else{while(G(i,h)){i==="\n"&&(x+=A?x<=A?1:0:1);if(v>=H)return["","TK_EOF"];i=n.charAt(v),v+=1}if(L&&x>1)for(e=0;e<x;e+=1)q(e===0),S=!0;E=x>0}if(G(i,p)){if(v<H)while(G(n.charAt(v),p)){i+=n.charAt(v),v+=1;if(v===H)break}if(v===H||!i.match(/^[0-9]+[Ee]$/)||n.charAt(v)!=="-"&&n.charAt(v)!=="+")return i==="in"?[i,"TK_OPERATOR"]:(E&&s!=="TK_OPERATOR"&&s!=="TK_EQUALS"&&!f.if_line&&(L||o!=="var")&&q(),[i,"TK_WORD"]);var l=n.charAt(v);v+=1;var m=Z();return i+=l+m[0],[i,"TK_WORD"]}if(i==="("||i==="[")return[i,"TK_START_EXPR"];if(i===")"||i==="]")return[i,"TK_END_EXPR"];if(i==="{")return[i,"TK_START_BLOCK"];if(i==="}")return[i,"TK_END_BLOCK"];if(i===";")return[i,"TK_SEMICOLON"];if(i==="/"){var y="",b=!0;if(n.charAt(v)==="*"){v+=1;if(v<H)while(v<H&&(n.charAt(v)!=="*"||!n.charAt(v+1)||n.charAt(v+1)!=="/")){i=n.charAt(v),y+=i;if(i==="\n"||i==="\r")b=!1;v+=1;if(v>=H)break}return v+=2,b&&x===0?["/*"+y+"*/","TK_INLINE_COMMENT"]:["/*"+y+"*/","TK_BLOCK_COMMENT"]}if(n.charAt(v)==="/"){y=i;while(n.charAt(v)!=="\r"&&n.charAt(v)!=="\n"){y+=n.charAt(v),v+=1;if(v>=H)break}return E&&q(),[y,"TK_COMMENT"]}}if(i==="'"||i==='"'||i==="/"&&(s==="TK_WORD"&&Q(o)||o===")"&&G(f.previous_mode,["(COND-EXPRESSION)","(FOR-EXPRESSION)"])||s==="TK_COMMA"||s==="TK_COMMENT"||s==="TK_START_EXPR"||s==="TK_START_BLOCK"||s==="TK_END_BLOCK"||s==="TK_OPERATOR"||s==="TK_EQUALS"||s==="TK_EOF"||s==="TK_SEMICOLON")){var w=i,T=!1,N=0,C=0;t=i;if(v<H)if(w==="/"){var k=!1;while(T||k||n.charAt(v)!==w){t+=n.charAt(v),T?T=!1:(T=n.charAt(v)==="\\",n.charAt(v)==="["?k=!0:n.charAt(v)==="]"&&(k=!1)),v+=1;if(v>=H)return[t,"TK_STRING"]}}else while(T||n.charAt(v)!==w){t+=n.charAt(v),N&&N>=C&&(N=parseInt(t.substr(-C),16),N&&N>=32&&N<=126&&(N=String.fromCharCode(N),t=t.substr(0,t.length-C-2)+(N===w||N==="\\"?"\\":"")+N),N=0),N?N++:T?(T=!1,P&&(n.charAt(v)==="x"?(N++,C=2):n.charAt(v)==="u"&&(N++,C=4))):T=n.charAt(v)==="\\",v+=1;if(v>=H)return[t,"TK_STRING"]}v+=1,t+=w;if(w==="/")while(v<H&&G(n.charAt(v),p))t+=n.charAt(v),v+=1;return[t,"TK_STRING"]}if(i==="#"){if(r.length===0&&n.charAt(v)==="!"){t=i;while(v<H&&i!=="\n")i=n.charAt(v),t+=i,v+=1;return r.push(j(t)+"\n"),q(),Z()}var O="#";if(v<H&&G(n.charAt(v),g)){do i=n.charAt(v),O+=i,v+=1;while(v<H&&i!=="#"&&i!=="=");return i!=="#"&&(n.charAt(v)==="["&&n.charAt(v+1)==="]"?(O+="[]",v+=2):n.charAt(v)==="{"&&n.charAt(v+1)==="}"&&(O+="{}",v+=2)),[O,"TK_WORD"]}}if(i==="<"&&n.substring(v-1,v+3)==="<!--"){v+=3,i="<!--";while(n.charAt(v)!=="\n"&&v<H)i+=n.charAt(v),v++;return f.in_html_comment=!0,[i,"TK_COMMENT"]}if(i==="-"&&f.in_html_comment&&n.substring(v-1,v+2)==="-->")return f.in_html_comment=!1,v+=2,E&&q(),["-->","TK_COMMENT"];if(G(i,d)){while(v<H&&G(i+n.charAt(v),d)){i+=n.charAt(v),v+=1;if(v>=H)break}return i===","?[i,"TK_COMMA"]:i==="="?[i,"TK_EQUALS"]:[i,"TK_OPERATOR"]}return[i,"TK_UNKNOWN"]}var n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T="";t=t?t:{};var N;t.space_after_anon_function!==undefined&&t.jslint_happy===undefined&&(t.jslint_happy=t.space_after_anon_function),t.braces_on_own_line!==undefined&&(N=t.braces_on_own_line?"expand":"collapse"),N=t.brace_style?t.brace_style:N?N:"collapse";var C=t.indent_size?t.indent_size:4,k=t.indent_char?t.indent_char:" ",L=typeof t.preserve_newlines=="undefined"?!0:t.preserve_newlines,A=typeof t.max_preserve_newlines=="undefined"?!1:t.max_preserve_newlines,O=t.jslint_happy==="undefined"?!1:t.jslint_happy,M=typeof t.keep_array_indentation=="undefined"?!1:t.keep_array_indentation,_=typeof t.space_before_conditional=="undefined"?!0:t.space_before_conditional,D=typeof t.indent_case=="undefined"?!1:t.indent_case,P=typeof t.unescape_strings=="undefined"?!1:t.unescape_strings;S=!1;var H=e.length;c="";while(C>0)c+=k,C-=1;while(e&&(e.charAt(0)===" "||e.charAt(0)===" "))T+=e.charAt(0),e=e.substring(1);n=e,a="",s="TK_START_EXPR",o="",u="",r=[],w=!1,h="\n\r ".split(""),p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$".split(""),g="0123456789".split(""),d="+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::",d+=" <%= <% %> <?= <? ?>",d=d.split(" "),m="continue,try,throw,return,var,if,switch,case,default,for,while,break,function".split(","),l=[],X("BLOCK"),v=0;for(;;){var et=Z();i=et[0],b=et[1];if(b==="TK_EOF")break;switch(b){case"TK_START_EXPR":if(i==="["){if(s==="TK_WORD"||o===")"){G(o,m)&&R(),X("(EXPRESSION)"),U();break}f.mode==="[EXPRESSION]"||f.mode==="[INDENTED-EXPRESSION]"?u==="]"&&o===","?(f.mode==="[EXPRESSION]"&&(f.mode="[INDENTED-EXPRESSION]",M||z()),X("[EXPRESSION]"),M||q()):o==="["?(f.mode==="[EXPRESSION]"&&(f.mode="[INDENTED-EXPRESSION]",M||z()),X("[EXPRESSION]"),M||q()):X("[EXPRESSION]"):X("[EXPRESSION]")}else a==="for"?X("(FOR-EXPRESSION)"):G(a,["if","while"])?X("(COND-EXPRESSION)"):X("(EXPRESSION)");o===";"||s==="TK_START_BLOCK"?q():s==="TK_END_EXPR"||s==="TK_START_EXPR"||s==="TK_END_BLOCK"||o==="."?E&&q():s!=="TK_WORD"&&s!=="TK_OPERATOR"?R():a==="function"||a==="typeof"?O&&R():(G(o,m)||o==="catch")&&_&&R(),U();break;case"TK_END_EXPR":if(i==="]")if(M){if(o==="}"){W(),U(),J();break}}else if(f.mode==="[INDENTED-EXPRESSION]"&&o==="]"){J(),q(),U();break}J(),U();break;case"TK_START_BLOCK":a==="do"?X("DO_BLOCK"):X("BLOCK");if(N==="expand"||N==="expand-strict"){var tt=!1;N==="expand-strict"?(tt=Y()==="}",tt||q(!0)):s!=="TK_OPERATOR"&&(o==="="||Q(o)&&o!=="else"?R():q(!0)),U(),tt||z()}else s!=="TK_OPERATOR"&&s!=="TK_START_EXPR"?s==="TK_START_BLOCK"?q():R():V(f.previous_mode)&&o===","&&(u==="}"?R():q()),z(),U();break;case"TK_END_BLOCK":J(),N==="expand"||N==="expand-strict"?(o!=="{"&&q(),U()):(s==="TK_START_BLOCK"?S?W():B():V(f.mode)&&M?(M=!1,q(),M=!0):q(),U());break;case"TK_WORD":if(w){R(),U(),R(),w=!1;break}y="NONE";if(i==="function"){f.var_line&&s!=="TK_EQUALS"&&(f.var_line_reindented=!0);if((S||o===";")&&o!=="{"&&s!=="TK_BLOCK_COMMENT"&&s!=="TK_COMMENT"){x=S?x:0,L||(x=1);for(var nt=0;nt<2-x;nt++)q(!1)}s==="TK_WORD"?o==="get"||o==="set"||o==="new"||o==="return"?R():q():s==="TK_OPERATOR"||o==="="?R():$(f.mode)||q(),U(),a=i;break}if(i==="case"||i==="default"&&f.in_case_statement){o===":"||f.case_body?W():(D||f.indentation_level--,q(),D||f.indentation_level++),U(),f.in_case=!0,f.in_case_statement=!0,f.case_body=!1;break}s==="TK_END_BLOCK"?G(i.toLowerCase(),["else","catch","finally"])?N==="expand"||N==="end-expand"||N==="expand-strict"?y="NEWLINE":(y="SPACE",R()):y="NEWLINE":s!=="TK_SEMICOLON"||f.mode!=="BLOCK"&&f.mode!=="DO_BLOCK"?s==="TK_SEMICOLON"&&$(f.mode)?y="SPACE":s==="TK_STRING"?y="NEWLINE":s==="TK_WORD"?(o==="else"&&B(!0),y="SPACE"):s==="TK_START_BLOCK"?y="NEWLINE":s==="TK_END_EXPR"&&(R(),y="NEWLINE"):y="NEWLINE",G(i,m)&&o!==")"&&(o==="else"?y="SPACE":y="NEWLINE"),f.if_line&&s==="TK_END_EXPR"&&(f.if_line=!1),G(i.toLowerCase(),["else","catch","finally"])?s!=="TK_END_BLOCK"||N==="expand"||N==="end-expand"||N==="expand-strict"?q():(B(!0),R()):y==="NEWLINE"?Q(o)?R():s!=="TK_END_EXPR"?(s!=="TK_START_EXPR"||i!=="var")&&o!==":"&&(i==="if"&&a==="else"&&o!=="{"?R():(f.var_line=!1,f.var_line_reindented=!1,q())):G(i,m)&&o!==")"&&(f.var_line=!1,f.var_line_reindented=!1,q()):V(f.mode)&&o===","&&u==="}"?q():y==="SPACE"&&R(),U(),a=i,i==="var"&&(f.var_line=!0,f.var_line_reindented=!1,f.var_line_tainted=!1),i==="if"&&(f.if_line=!0),i==="else"&&(f.if_line=!1);break;case"TK_SEMICOLON":U(),f.var_line=!1,f.var_line_reindented=!1,f.mode==="OBJECT"&&(f.mode="BLOCK");break;case"TK_STRING":s==="TK_END_EXPR"&&G(f.previous_mode,["(COND-EXPRESSION)","(FOR-EXPRESSION)"])?R():s==="TK_COMMENT"||s==="TK_STRING"||s==="TK_START_BLOCK"||s==="TK_END_BLOCK"||s==="TK_SEMICOLON"?q():s==="TK_WORD"&&R(),U();break;case"TK_EQUALS":f.var_line&&(f.var_line_tainted=!0),R(),U(),R();break;case"TK_COMMA":if(f.var_line){if($(f.mode)||s==="TK_END_BLOCK")f.var_line_tainted=!1;if(f.var_line_tainted){U(),f.var_line_reindented=!0,f.var_line_tainted=!1,q();break}f.var_line_tainted=!1,U(),R();break}s==="TK_COMMENT"&&q(),s==="TK_END_BLOCK"&&f.mode!=="(EXPRESSION)"?(U(),f.mode==="OBJECT"&&o==="}"?q():R()):f.mode==="OBJECT"?(U(),q()):(U(),R());break;case"TK_OPERATOR":var rt=!0,it=!0;if(Q(o)){R(),U();break}if(i==="*"&&s==="TK_UNKNOWN"&&!u.match(/^\d+$/)){U();break}if(i===":"&&f.in_case){D&&(f.case_body=!0),U(),q(),f.in_case=!1;break}if(i==="::"){U();break}G(i,["--","++","!"])||G(i,["-","+"])&&(G(s,["TK_START_BLOCK","TK_START_EXPR","TK_EQUALS","TK_OPERATOR"])||G(o,m))?(rt=!1,it=!1,o===";"&&$(f.mode)&&(rt=!0),s==="TK_WORD"&&G(o,m)&&(rt=!0),f.mode==="BLOCK"&&(o==="{"||o===";")&&q()):i==="."?rt=!1:i===":"?f.ternary_depth===0?(f.mode==="BLOCK"&&(f.mode="OBJECT"),rt=!1):f.ternary_depth-=1:i==="?"&&(f.ternary_depth+=1),rt&&R(),U(),it&&R();break;case"TK_BLOCK_COMMENT":var st=F(i),ot;if(K(st.slice(1),"*")){q(),r.push(st[0]);for(ot=1;ot<st.length;ot++)q(),r.push(" "),r.push(j(st[ot]))}else{st.length>1?q():s==="TK_END_BLOCK"?q():R();for(ot=0;ot<st.length;ot++)r.push(st[ot]),r.push("\n")}Y("\n")!=="\n"&&q();break;case"TK_INLINE_COMMENT":R(),U(),$(f.mode)?R():I();break;case"TK_COMMENT":o===","&&!E&&B(!0),s!=="TK_COMMENT"&&(E?q():R()),U(),q();break;case"TK_UNKNOWN":Q(o)&&R(),U()}u=o,s=b,o=i}var ut=T+r.join("").replace(/[\r\n ]+$/,"");return ut}function i(e,t){function a(){return u=e.charAt(++o)}function f(){return e.charAt(o+1)}function l(t){var n=o;while(a())if(u=="\\")a(),a();else{if(u==t)break;if(u=="\n")break}return e.substring(n,o+1)}function c(){var e=o;while(i.test(f()))o++;return o!=e}function h(){var e=o;do;while(i.test(a()));return o!=e+1}function p(){var t=o;a();while(a())if(u=="*"&&f()=="/"){o++;break}return e.substring(t,o+1)}function d(e,t){return w.slice(-e.length+(t||0),t).join("").toLowerCase()==e}function y(){g++,v+=m}function b(){g--,v=v.slice(0,-n)}t=t||{};var n=t.indent_size||4,r=t.indent_char||" ";typeof n=="string"&&(n=parseInt(n));var i=/^\s+$/,s=/[\w$\-_]/,o=-1,u,v=e.match(/^[\r\n]*[\t ]*/)[0],m=Array(n+1).join(r),g=0;print={},print["{"]=function(e){print.singleSpace(),w.push(e),print.newLine()},print["}"]=function(e){print.newLine(),w.push(e),print.newLine()},print.newLine=function(e){if(!e)while(i.test(w[w.length-1]))w.pop();w.length&&w.push("\n"),v&&w.push(v)},print.singleSpace=function(){w.length&&!i.test(w[w.length-1])&&w.push(" ")};var w=[];v&&w.push(v);for(;;){var E=h();if(!u)break;u=="{"?(y(),print["{"](u)):u=="}"?(b(),print["}"](u)):u=='"'||u=="'"?w.push(l(u)):u==";"?w.push(u,"\n",v):u=="/"&&f()=="*"?(print.newLine(),w.push(p(),"\n",v)):u=="("?(w.push(u),c(),d("url",-1)&&a()&&(u!=")"&&u!='"'&&u!="'"?w.push(l(")")):o--)):u==")"?w.push(u):u==","?(c(),w.push(u),print.singleSpace()):u=="]"?w.push(u):u=="["||u=="="?(c(),w.push(u)):(E&&print.singleSpace(),w.push(u))}var S=w.join("").replace(/[\n ]+$/,"");return S}function s(e,t){function f(){return this.pos=0,this.token="",this.current_mode="CONTENT",this.tags={parent:"parent1",parentcount:1,parent1:""},this.tag_type="",this.token_text=this.last_token=this.last_text=this.token_type="",this.Utils={whitespace:"\n\r ".split(""),single_token:"br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed".split(","),extra_liners:"head,body,/html".split(","),in_array:function(e,t){for(var n=0;n<t.length;n++)if(e===t[n])return!0;return!1}},this.get_content=function(){var e="",t=[],n=!1;while(this.input.charAt(this.pos)!=="<"){if(this.pos>=this.input.length)return t.length?t.join(""):["","TK_EOF"];e=this.input.charAt(this.pos),this.pos++,this.line_char_count++;if(this.Utils.in_array(e,this.Utils.whitespace)){t.length&&(n=!0),this.line_char_count--;continue}if(n){if(this.line_char_count>=this.max_char){t.push("\n");for(var r=0;r<this.indent_level;r++)t.push(this.indent_string);this.line_char_count=0}else t.push(" "),this.line_char_count++;n=!1}t.push(e)}return t.length?t.join(""):""},this.get_contents_to=function(e){if(this.pos==this.input.length)return["","TK_EOF"];var t="",n="",r=new RegExp("</"+e+"\\s*>","igm");r.lastIndex=this.pos;var i=r.exec(this.input),s=i?i.index:this.input.length;return this.pos<s&&(n=this.input.substring(this.pos,s),this.pos=s),n},this.record_tag=function(e){this.tags[e+"count"]?(this.tags[e+"count"]++,this.tags[e+this.tags[e+"count"]]=this.indent_level):(this.tags[e+"count"]=1,this.tags[e+this.tags[e+"count"]]=this.indent_level),this.tags[e+this.tags[e+"count"]+"parent"]=this.tags.parent,this.tags.parent=e+this.tags[e+"count"]},this.retrieve_tag=function(e){if(this.tags[e+"count"]){var t=this.tags.parent;while(t){if(e+this.tags[e+"count"]===t)break;t=this.tags[t+"parent"]}t&&(this.indent_level=this.tags[e+this.tags[e+"count"]],this.tags.parent=this.tags[t+"parent"]),delete this.tags[e+this.tags[e+"count"]+"parent"],delete this.tags[e+this.tags[e+"count"]],this.tags[e+"count"]==1?delete this.tags[e+"count"]:this.tags[e+"count"]--}},this.get_tag=function(){var e="",t=[],n=!1;do{if(this.pos>=this.input.length)return t.length?t.join(""):["","TK_EOF"];e=this.input.charAt(this.pos),this.pos++,this.line_char_count++;if(this.Utils.in_array(e,this.Utils.whitespace)){n=!0,this.line_char_count--;continue}if(e==="'"||e==='"')if(!t[1]||t[1]!=="!")e+=this.get_unformatted(e),n=!0;e==="="&&(n=!1),t.length&&t[t.length-1]!=="="&&e!==">"&&n&&(this.line_char_count>=this.max_char?(this.print_newline(!1,t),this.line_char_count=0):(t.push(" "),this.line_char_count++),n=!1),t.push(e)}while(e!==">");var r=t.join(""),i;r.indexOf(" ")!=-1?i=r.indexOf(" "):i=r.indexOf(">");var s=r.substring(1,i).toLowerCase();if(r.charAt(r.length-2)==="/"||this.Utils.in_array(s,this.Utils.single_token))this.tag_type="SINGLE";else if(s==="script")this.record_tag(s),this.tag_type="SCRIPT";else if(s==="style")this.record_tag(s),this.tag_type="STYLE";else if(this.Utils.in_array(s,unformatted)){var o=this.get_unformatted("</"+s+">",r);t.push(o),this.tag_type="SINGLE"}else if(s.charAt(0)==="!")if(s.indexOf("[if")!=-1){if(r.indexOf("!IE")!=-1){var o=this.get_unformatted("-->",r);t.push(o)}this.tag_type="START"}else if(s.indexOf("[endif")!=-1)this.tag_type="END",this.unindent();else if(s.indexOf("[cdata[")!=-1){var o=this.get_unformatted("]]>",r);t.push(o),this.tag_type="SINGLE"}else{var o=this.get_unformatted("-->",r);t.push(o),this.tag_type="SINGLE"}else s.charAt(0)==="/"?(this.retrieve_tag(s.substring(1)),this.tag_type="END"):(this.record_tag(s),this.tag_type="START"),this.Utils.in_array(s,this.Utils.extra_liners)&&this.print_newline(!0,this.output);return t.join("")},this.get_unformatted=function(e,t){if(t&&t.indexOf(e)!=-1)return"";var n="",r="",i=!0;do{if(this.pos>=this.input.length)return r;n=this.input.charAt(this.pos),this.pos++;if(this.Utils.in_array(n,this.Utils.whitespace)){if(!i){this.line_char_count--;continue}if(n==="\n"||n==="\r"){r+="\n",this.line_char_count=0;continue}}r+=n,this.line_char_count++,i=!0}while(r.indexOf(e)==-1);return r},this.get_token=function(){var e;if(this.last_token==="TK_TAG_SCRIPT"||this.last_token==="TK_TAG_STYLE"){var t=this.last_token.substr(7);return e=this.get_contents_to(t),typeof e!="string"?e:[e,"TK_"+t]}if(this.current_mode==="CONTENT")return e=this.get_content(),typeof e!="string"?e:[e,"TK_CONTENT"];if(this.current_mode==="TAG"){e=this.get_tag();if(typeof e!="string")return e;var n="TK_TAG_"+this.tag_type;return[e,n]}},this.get_full_indent=function(e){return e=this.indent_level+e||0,e<1?"":Array(e+1).join(this.indent_string)},this.printer=function(e,t,n,r,i){this.input=e||"",this.output=[],this.indent_character=t,this.indent_string="",this.indent_size=n,this.brace_style=i,this.indent_level=0,this.max_char=r,this.line_char_count=0;for(var s=0;s<this.indent_size;s++)this.indent_string+=this.indent_character;this.print_newline=function(e,t){this.line_char_count=0;if(!t||!t.length)return;if(!e)while(this.Utils.in_array(t[t.length-1],this.Utils.whitespace))t.pop();t.push("\n");for(var n=0;n<this.indent_level;n++)t.push(this.indent_string)},this.print_token=function(e){this.output.push(e)},this.indent=function(){this.indent_level++},this.unindent=function(){this.indent_level>0&&this.indent_level--}},this}var n,s,o,u,a;t=t||{},s=t.indent_size||4,o=t.indent_char||" ",a=t.brace_style||"collapse",u=t.max_char==0?Infinity:t.max_char||70,unformatted=t.unformatted||["a"],n=new f,n.printer(e,o,s,u,a);for(;;){var l=n.get_token();n.token_text=l[0],n.token_type=l[1];if(n.token_type==="TK_EOF")break;switch(n.token_type){case"TK_TAG_START":n.print_newline(!1,n.output),n.print_token(n.token_text),n.indent(),n.current_mode="CONTENT";break;case"TK_TAG_STYLE":case"TK_TAG_SCRIPT":n.print_newline(!1,n.output),n.print_token(n.token_text),n.current_mode="CONTENT";break;case"TK_TAG_END":if(n.last_token==="TK_CONTENT"&&n.last_text===""){var c=n.token_text.match(/\w+/)[0],h=n.output[n.output.length-1].match(/<\s*(\w+)/);(h===null||h[1]!==c)&&n.print_newline(!0,n.output)}n.print_token(n.token_text),n.current_mode="CONTENT";break;case"TK_TAG_SINGLE":n.print_newline(!1,n.output),n.print_token(n.token_text),n.current_mode="CONTENT";break;case"TK_CONTENT":n.token_text!==""&&n.print_token(n.token_text),n.current_mode="TAG";break;case"TK_STYLE":case"TK_SCRIPT":if(n.token_text!==""){n.output.push("\n");var p=n.token_text;if(n.token_type=="TK_SCRIPT")var d=typeof r=="function"&&r;else if(n.token_type=="TK_STYLE")var d=typeof i=="function"&&i;if(t.indent_scripts=="keep")var v=0;else if(t.indent_scripts=="separate")var v=-n.indent_level;else var v=1;var m=n.get_full_indent(v);if(d)p=d(p.replace(/^\s*/,m),t);else{var g=p.match(/^\s*/)[0],y=g.match(/[^\n\r]*$/)[0].split(n.indent_string).length-1,b=n.get_full_indent(v-y);p=p.replace(/^\s*/,m).replace(/\r\n|\r|\n/g,"\n"+b).replace(/\s*$/,"")}p&&(n.print_token(p),n.print_newline(!0,n.output))}n.current_mode="TAG"}n.last_token=n.token_type,n.last_text=n.token_text}return n.output.join("")}typeof t!="undefined"&&(t.js_beautify=r),typeof t!="undefined"&&(t.css_beautify=i),typeof t!="undefined"&&(t.html_beautify=s)});
View
1,175 plugins-client/ext.beautify/res/jsbeautify/jsbeautify.js
@@ -1,6 +1,7 @@
define(function(require, exports, module) {
/*jslint onevar: false, plusplus: false */
+/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
/*
JS Beautifier
@@ -20,36 +21,52 @@ define(function(require, exports, module) {
js_beautify(js_source_text, options);
The options are:
- indent_size (default 4) indentation size,
- indent_char (default space) character to indent with,
- preserve_newlines (default true) whether existing line breaks should be preserved,
+ indent_size (default 4) - indentation size,
+ indent_char (default space) - character to indent with,
+ preserve_newlines (default true) - whether existing line breaks should be preserved,
preserve_max_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
- indent_level (default 0) — initial indentation level, you probably won't need this ever,
- jslint_happy (default false) if true, then jslint-stricter mode is enforced.
+ jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
jslint_happy !jslint_happy
---------------------------------
function () function()
- brace_style (default "collapse") - "collapse" | "expand" | "end-expand"
+ brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "expand-strict"
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.
+ expand-strict: put brace on own line even in such cases:
+
+ var a =
+ {
+ a: 5,
+ b: 6
+ }
+ This mode may break your scripts - e.g "return { a: 1 }" will be broken into two lines, so beware.
+
+ space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
+
+ unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
+
e.g
- js_beautify(js_source_text, {indent_size: 1, indent_char: '\t'});
+ js_beautify(js_source_text, {
+ 'indent_size': 1,
+ 'indent_char': '\t'
+ });
*/
-exports.js_beautify = function(js_source_text, options) {
+function js_beautify(js_source_text, options) {
var input, output, token_text, last_type, last_text, last_last_text, last_word, flags, flag_store, indent_string;
var whitespace, wordchar, punct, parser_pos, line_starters, digits;
var prefix, token_type, do_block_just_closed;
var wanted_newline, just_added_newline, n_newlines;
+ var preindent_string = '';
// Some interpreters have unexpected results with foo = baz || bar;
@@ -61,7 +78,7 @@ exports.js_beautify = function(js_source_text, options) {
if (options.space_after_anon_function !== undefined && options.jslint_happy === undefined) {
options.jslint_happy = options.space_after_anon_function;
}
- if (options.braces_on_own_line !== undefined) { //graceful handling of depricated option
+ if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
opt_brace_style = options.braces_on_own_line ? "expand" : "collapse";
}
opt_brace_style = options.brace_style ? options.brace_style : (opt_brace_style ? opt_brace_style : "collapse");
@@ -71,9 +88,11 @@ exports.js_beautify = function(js_source_text, options) {
var opt_indent_char = options.indent_char ? options.indent_char : ' ';
var opt_preserve_newlines = typeof options.preserve_newlines === 'undefined' ? true : options.preserve_newlines;
var opt_max_preserve_newlines = typeof options.max_preserve_newlines === 'undefined' ? false : options.max_preserve_newlines;
- var opt_indent_level = options.indent_level ? options.indent_level : 0; // starting indentation
var opt_jslint_happy = options.jslint_happy === 'undefined' ? false : options.jslint_happy;
var opt_keep_array_indentation = typeof options.keep_array_indentation === 'undefined' ? false : options.keep_array_indentation;
+ var opt_space_before_conditional = typeof options.space_before_conditional === 'undefined' ? true : options.space_before_conditional;
+ var opt_indent_case = typeof options.indent_case === 'undefined' ? false : options.indent_case;
+ var opt_unescape_strings = typeof options.unescape_strings === 'undefined' ? false : options.unescape_strings;
just_added_newline = false;
@@ -84,6 +103,7 @@ exports.js_beautify = function(js_source_text, options) {
eat_newlines = typeof eat_newlines === 'undefined' ? false : eat_newlines;
while (output.length && (output[output.length - 1] === ' '
|| output[output.length - 1] === indent_string
+ || output[output.length - 1] === preindent_string
|| (eat_newlines && (output[output.length - 1] === '\n' || output[output.length - 1] === '\r')))) {
output.pop();
}
@@ -93,6 +113,32 @@ exports.js_beautify = function(js_source_text, options) {
return s.replace(/^\s\s*|\s\s*$/, '');
}
+ // we could use just string.split, but
+ // IE doesn't like returning empty strings
+ function split_newlines(s) {
+ //return s.split(/\x0d\x0a|\x0a/);
+
+ s = s.replace(/\x0d/g, '');
+ var out = [],
+ idx = s.indexOf("\n");
+ while (idx !== -1) {
+ out.push(s.substring(0, idx));
+ s = s.substring(idx + 1);
+ idx = s.indexOf("\n");
+ }
+ if (s.length) {
+ out.push(s);
+ }
+ return out;
+ }
+
+ function force_newline() {
+ var old_keep_array_indentation = opt_keep_array_indentation;
+ opt_keep_array_indentation = false;
+ print_newline();
+ opt_keep_array_indentation = old_keep_array_indentation;
+ }
+
function print_newline(ignore_repeated) {
flags.eat_next_space = false;
@@ -113,21 +159,27 @@ exports.js_beautify = function(js_source_text, options) {
just_added_newline = true;
output.push("\n");
}
+ if (preindent_string) {
+ output.push(preindent_string);
+ }
for (var i = 0; i < flags.indentation_level; i += 1) {
output.push(indent_string);
}
if (flags.var_line && flags.var_line_reindented) {
- if (opt_indent_char === ' ') {
- output.push(' '); // var_line always pushes 4 spaces, so that the variables would be one under another
- } else {
- output.push(indent_string); // skip space-stuffing, if indenting with a tab
- }
+ output.push(indent_string); // skip space-stuffing, if indenting with a tab
+ }
+ if (flags.case_body) {
+ output.push(indent_string);
}
}
function print_single_space() {
+
+ if (last_type === 'TK_COMMENT') {
+ return print_newline();
+ }
if (flags.eat_next_space) {
flags.eat_next_space = false;
return;
@@ -171,10 +223,12 @@ exports.js_beautify = function(js_source_text, options) {
var_line_reindented: false,
in_html_comment: false,
if_line: false,
- in_case: false,
+ in_case_statement: false, // switch(..){ INSIDE HERE }
+ in_case: false, // we're on the exact line with "case 0:"
+ case_body: false, // the indented case-action block
eat_next_space: false,
indentation_baseline: -1,
- indentation_level: (flags ? flags.indentation_level + ((flags.var_line && flags.var_line_reindented) ? 1 : 0) : opt_indent_level),
+ indentation_level: (flags ? flags.indentation_level + (flags.case_body ? 1 : 0) + ((flags.var_line && flags.var_line_reindented) ? 1 : 0) : 0),
ternary_depth: 0
};
}
@@ -184,16 +238,31 @@ exports.js_beautify = function(js_source_text, options) {
}
function is_expression(mode) {
- return mode === '[EXPRESSION]' || mode === '[INDENTED-EXPRESSION]' || mode === '(EXPRESSION)';
+ return in_array(mode, ['[EXPRESSION]', '(EXPRESSION)', '(FOR-EXPRESSION)', '(COND-EXPRESSION)']);
}
function restore_mode() {
do_block_just_closed = flags.mode === 'DO_BLOCK';
if (flag_store.length > 0) {
+ var mode = flags.mode;
flags = flag_store.pop();
+ flags.previous_mode = mode;
+ }
+ }
+
+ function all_lines_start_with(lines, c) {
+ for (var i = 0; i < lines.length; i++) {
+ var line = trim(lines[i]);
+ if (line.charAt(0) !== c) {
+ return false;
+ }
}
+ return true;
}
+ function is_special_word(word) {
+ return in_array(word, ['case', 'return', 'do', 'if', 'throw', 'else']);
+ }
function in_array(what, arr) {
for (var i = 0; i < arr.length; i += 1) {
@@ -204,7 +273,23 @@ exports.js_beautify = function(js_source_text, options) {
return false;
}
+ function look_up(exclude) {
+ var local_pos = parser_pos;
+ var c = input.charAt(local_pos);
+ while (in_array(c, whitespace) && c !== exclude) {
+ local_pos++;
+ if (local_pos >= input_length) {
+ return 0;
+ }
+ c = input.charAt(local_pos);
+ }
+ return c;
+ }
+
function get_next_token() {
+ var i;
+ var resulting_string;
+
n_newlines = 0;
if (parser_pos >= input_length) {
@@ -266,7 +351,6 @@ exports.js_beautify = function(js_source_text, options) {
}
if (just_added_newline) {
- var i;
for (i = 0; i < flags.indentation_level + 1; i += 1) {
output.push(indent_string);
}
@@ -281,7 +365,7 @@ exports.js_beautify = function(js_source_text, options) {
while (in_array(c, whitespace)) {
if (c === "\n") {
- n_newlines += ( (opt_max_preserve_newlines) ? (n_newlines <= opt_max_preserve_newlines) ? 1: 0: 1 );
+ n_newlines += ((opt_max_preserve_newlines) ? (n_newlines <= opt_max_preserve_newlines) ? 1 : 0 : 1);
}
@@ -323,7 +407,7 @@ exports.js_beautify = function(js_source_text, options) {
var sign = input.charAt(parser_pos);
parser_pos += 1;
- var t = get_next_token(parser_pos);
+ var t = get_next_token();
c += sign + t[0];
return [c, 'TK_WORD'];
}
@@ -366,10 +450,11 @@ exports.js_beautify = function(js_source_text, options) {
if (input.charAt(parser_pos) === '*') {
parser_pos += 1;
if (parser_pos < input_length) {
- while (! (input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/') && parser_pos < input_length) {
+ while (parser_pos < input_length &&
+ ! (input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/')) {
c = input.charAt(parser_pos);
comment += c;
- if (c === '\x0d' || c === '\x0a') {
+ if (c === "\n" || c === "\r") {
inline_comment = false;
}
parser_pos += 1;
@@ -379,7 +464,7 @@ exports.js_beautify = function(js_source_text, options) {
}
}
parser_pos += 2;
- if (inline_comment) {
+ if (inline_comment && n_newlines === 0) {
return ['/*' + comment + '*/', 'TK_INLINE_COMMENT'];
} else {
return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT'];
@@ -395,7 +480,6 @@ exports.js_beautify = function(js_source_text, options) {
break;
}
}
- parser_pos += 1;
if (wanted_newline) {
print_newline();
}
@@ -407,11 +491,14 @@ exports.js_beautify = function(js_source_text, options) {
if (c === "'" || // string
c === '"' || // string
(c === '/' &&
- ((last_type === 'TK_WORD' && in_array(last_text, ['return', 'do'])) ||
- (last_type === 'TK_COMMENT' || last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp
+ ((last_type === 'TK_WORD' && is_special_word(last_text)) ||
+ (last_text === ')' && in_array(flags.previous_mode, ['(COND-EXPRESSION)', '(FOR-EXPRESSION)'])) ||
+ (last_type === 'TK_COMMA' || last_type === 'TK_COMMENT' || last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp
var sep = c;
var esc = false;
- var resulting_string = c;
+ var esc1 = 0;
+ var esc2 = 0;
+ resulting_string = c;
if (parser_pos < input_length) {
if (sep === '/') {
@@ -445,10 +532,29 @@ exports.js_beautify = function(js_source_text, options) {
//
while (esc || input.charAt(parser_pos) !== sep) {
resulting_string += input.charAt(parser_pos);
- if (!esc) {
+ if (esc1 && esc1 >= esc2) {
+ esc1 = parseInt(resulting_string.substr(-esc2), 16);
+ if (esc1 && esc1 >= 0x20 && esc1 <= 0x7e) {
+ esc1 = String.fromCharCode(esc1);
+ resulting_string = resulting_string.substr(0, resulting_string.length - esc2 - 2) + (((esc1 === sep) || (esc1 === '\\')) ? '\\' : '') + esc1;
+ }
+ esc1 = 0;
+ }
+ if (esc1) {
+ esc1++;
+ } else if (!esc) {
esc = input.charAt(parser_pos) === '\\';
} else {
esc = false;
+ if (opt_unescape_strings) {
+ if (input.charAt(parser_pos) === 'x') {
+ esc1++;
+ esc2 = 2;
+ } else if (input.charAt(parser_pos) === 'u') {
+ esc1++;
+ esc2 = 4;
+ }
+ }
}
parser_pos += 1;
if (parser_pos >= input_length) {
@@ -483,7 +589,7 @@ exports.js_beautify = function(js_source_text, options) {
if (output.length === 0 && input.charAt(parser_pos) === '!') {
// shebang
resulting_string = c;
- while (parser_pos < input_length && c != '\n') {
+ while (parser_pos < input_length && c !== '\n') {
c = input.charAt(parser_pos);
resulting_string += c;
parser_pos += 1;
@@ -520,8 +626,13 @@ exports.js_beautify = function(js_source_text, options) {
if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '<!--') {
parser_pos += 3;
+ c = '<!--';
+ while (input.charAt(parser_pos) !== '\n' && parser_pos < input_length) {
+ c += input.charAt(parser_pos);
+ parser_pos++;
+ }
flags.in_html_comment = true;
- return ['<!--', 'TK_COMMENT'];
+ return [c, 'TK_COMMENT'];
}
if (c === '-' && flags.in_html_comment && input.substring(parser_pos - 1, parser_pos + 2) === '-->') {
@@ -542,7 +653,9 @@ exports.js_beautify = function(js_source_text, options) {
}
}
- if (c === '=') {
+ if (c === ',') {
+ return [c, 'TK_COMMA'];
+ } else if (c === '=') {
return [c, 'TK_EQUALS'];
} else {
return [c, 'TK_OPERATOR'];
@@ -559,6 +672,10 @@ exports.js_beautify = function(js_source_text, options) {
opt_indent_size -= 1;
}
+ while (js_source_text && (js_source_text.charAt(0) === ' ' || js_source_text.charAt(0) === '\t')) {
+ preindent_string += js_source_text.charAt(0);
+ js_source_text = js_source_text.substring(1);
+ }
input = js_source_text;
last_word = ''; // last 'TK_WORD' passed
@@ -573,7 +690,9 @@ exports.js_beautify = function(js_source_text, options) {
wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split('');
digits = '0123456789'.split('');
- punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::'.split(' ');
+ punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::';
+ punct += ' <%= <% %> <?= <? ?>'; // try to be a good boy and try not to break the markup language identifiers
+ punct = punct.split(' ');
// words which should always start on new line.
line_starters = 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function'.split(',');
@@ -585,7 +704,7 @@ exports.js_beautify = function(js_source_text, options) {
parser_pos = 0;
while (true) {
- var t = get_next_token(parser_pos);
+ var t = get_next_token();
token_text = t[0];
token_type = t[1];
if (token_type === 'TK_EOF') {
@@ -644,12 +763,21 @@ exports.js_beautify = function(js_source_text, options) {
} else {
- set_mode('(EXPRESSION)');
+ if (last_word === 'for') {
+ set_mode('(FOR-EXPRESSION)');
+ } else if (in_array(last_word, ['if', 'while'])) {
+ set_mode('(COND-EXPRESSION)');
+ } else {
+ set_mode('(EXPRESSION)');
+ }
}
if (last_text === ';' || last_type === 'TK_START_BLOCK') {
print_newline();
} else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || last_text === '.') {
+ if (wanted_newline) {
+ print_newline();
+ }
// do nothing on (( and )( and ][ and ]( and .(
} else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
print_single_space();
@@ -659,7 +787,9 @@ exports.js_beautify = function(js_source_text, options) {
print_single_space();
}
} else if (in_array(last_text, line_starters) || last_text === 'catch') {
- print_single_space();
+ if (opt_space_before_conditional) {
+ print_single_space();
+ }
}
print_token();
@@ -698,16 +828,26 @@ exports.js_beautify = function(js_source_text, options) {
} else {
set_mode('BLOCK');
}
- if (opt_brace_style=="expand") {
- if (last_type !== 'TK_OPERATOR') {
- if (last_text === 'return' || last_text === '=') {
- print_single_space();
- } else {
+ if (opt_brace_style === "expand" || opt_brace_style === "expand-strict") {
+ var empty_braces = false;
+ if (opt_brace_style === "expand-strict") {
+ empty_braces = (look_up() === '}');
+ if (!empty_braces) {
print_newline(true);
}
+ } else {
+ if (last_type !== 'TK_OPERATOR') {
+ if (last_text === '=' || (is_special_word(last_text) && last_text !== 'else')) {
+ print_single_space();
+ } else {
+ print_newline(true);
+ }
+ }
}
print_token();
- indent();
+ if (!empty_braces) {
+ indent();
+ }
} else {
if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
if (last_type === 'TK_START_BLOCK') {
@@ -734,7 +874,7 @@ exports.js_beautify = function(js_source_text, options) {
case 'TK_END_BLOCK':
restore_mode();
- if (opt_brace_style=="expand") {
+ if (opt_brace_style === "expand" || opt_brace_style === "expand-strict") {
if (last_text !== '{') {
print_newline();
}
@@ -776,15 +916,18 @@ exports.js_beautify = function(js_source_text, options) {
break;
}
+ prefix = 'NONE';
+
if (token_text === 'function') {
- if (flags.var_line) {
+ if (flags.var_line && last_type !== 'TK_EQUALS' ) {
flags.var_line_reindented = true;
}
- if ((just_added_newline || last_text === ';') && last_text !== '{') {
+ if ((just_added_newline || last_text === ';') && last_text !== '{'
+ && last_type !== 'TK_BLOCK_COMMENT' && last_type !== 'TK_COMMENT') {
// make sure there is a nice clean space of at least one blank line
// before a new function definition
n_newlines = just_added_newline ? n_newlines : 0;
- if ( ! opt_preserve_newlines) {
+ if (!opt_preserve_newlines) {
n_newlines = 1;
}
@@ -792,31 +935,53 @@ exports.js_beautify = function(js_source_text, options) {
print_newline(false);
}
}
+ if (last_type === 'TK_WORD') {
+ if (last_text === 'get' || last_text === 'set' || last_text === 'new' || last_text === 'return') {
+ print_single_space();
+ } else {
+ print_newline();
+ }
+ } else if (last_type === 'TK_OPERATOR' || last_text === '=') {
+ // foo = function
+ print_single_space();
+ } else if (is_expression(flags.mode)) {
+ //ää print nothing
+ } else {
+ print_newline();
+ }
+
+ print_token();
+ last_word = token_text;
+ break;
}
- if (token_text === 'case' || token_text === 'default') {
- if (last_text === ':') {
+ if (token_text === 'case' || (token_text === 'default' && flags.in_case_statement)) {
+ if (last_text === ':' || flags.case_body) {
// switch cases following one another
remove_indent();
} else {
// case statement starts in the same line where switch
- flags.indentation_level--;
+ if (!opt_indent_case) {
+ flags.indentation_level--;
+ }
print_newline();
- flags.indentation_level++;
+ if (!opt_indent_case) {
+ flags.indentation_level++;
+ }
}
print_token();
flags.in_case = true;
+ flags.in_case_statement = true;
+ flags.case_body = false;
break;
}
- prefix = 'NONE';
-
if (last_type === 'TK_END_BLOCK') {
if (!in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
prefix = 'NEWLINE';
} else {
- if (opt_brace_style=="expand" || opt_brace_style=="end-expand") {
+ if (opt_brace_style === "expand" || opt_brace_style === "end-expand" || opt_brace_style === "expand-strict") {
prefix = 'NEWLINE';
} else {
prefix = 'SPACE';
@@ -844,30 +1009,26 @@ exports.js_beautify = function(js_source_text, options) {
}
if (in_array(token_text, line_starters) && last_text !== ')') {
- if (last_text == 'else') {
+ if (last_text === 'else') {
prefix = 'SPACE';
} else {
prefix = 'NEWLINE';
}
+
}
if (flags.if_line && last_type === 'TK_END_EXPR') {
flags.if_line = false;
}
if (in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
- if (last_type !== 'TK_END_BLOCK' || opt_brace_style=="expand" || opt_brace_style=="end-expand") {
+ if (last_type !== 'TK_END_BLOCK' || opt_brace_style === "expand" || opt_brace_style === "end-expand" || opt_brace_style === "expand-strict") {
print_newline();
} else {
trim_output(true);
print_single_space();
}
} else if (prefix === 'NEWLINE') {
- if ((last_type === 'TK_START_EXPR' || last_text === '=' || last_text === ',') && token_text === 'function') {
- // no need to force newline on 'function': (function
- // DONOTHING
- } else if (token_text === 'function' && last_text == 'new') {
- print_single_space();
- } else if (last_text === 'return' || last_text === 'throw') {
+ if (is_special_word(last_text)) {
// no newline between 'return nnn'
print_single_space();
} else if (last_type !== 'TK_END_EXPR') {
@@ -882,7 +1043,7 @@ exports.js_beautify = function(js_source_text, options) {
print_newline();
}
}
- } else if (in_array(token_text, line_starters) && last_text != ')') {
+ } else if (in_array(token_text, line_starters) && last_text !== ')') {
flags.var_line = false;
flags.var_line_reindented = false;
print_newline();
@@ -915,7 +1076,7 @@ exports.js_beautify = function(js_source_text, options) {
print_token();
flags.var_line = false;
flags.var_line_reindented = false;
- if (flags.mode == 'OBJECT') {
+ if (flags.mode === 'OBJECT') {
// OBJECT mode is weird and doesn't get reset too well.
flags.mode = 'BLOCK';
}
@@ -923,7 +1084,9 @@ exports.js_beautify = function(js_source_text, options) {
case 'TK_STRING':
- if (last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_SEMICOLON') {
+ if (last_type === 'TK_END_EXPR' && in_array(flags.previous_mode, ['(COND-EXPRESSION)', '(FOR-EXPRESSION)'])) {
+ print_single_space();
+ } else if (last_type === 'TK_COMMENT' || last_type === 'TK_STRING' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_SEMICOLON') {
print_newline();
} else if (last_type === 'TK_WORD') {
print_single_space();
@@ -941,41 +1104,73 @@ exports.js_beautify = function(js_source_text, options) {
print_single_space();
break;
- case 'TK_OPERATOR':
+ case 'TK_COMMA':
+ if (flags.var_line) {
+ if (is_expression(flags.mode) || last_type === 'TK_END_BLOCK' ) {
+ // do not break on comma, for(var a = 1, b = 2)
+ flags.var_line_tainted = false;
+ }
+ if (flags.var_line_tainted) {
+ print_token();
+ flags.var_line_reindented = true;
+ flags.var_line_tainted = false;
+ print_newline();
+ break;
+ } else {
+ flags.var_line_tainted = false;
+ }
- var space_before = true;
- var space_after = true;
+ print_token();
+ print_single_space();
+ break;
+ }
- if (flags.var_line && token_text === ',' && (is_expression(flags.mode))) {
- // do not break on comma, for(var a = 1, b = 2)
- flags.var_line_tainted = false;
+ if (last_type === 'TK_COMMENT') {
+ print_newline();
}
- if (flags.var_line) {
- if (token_text === ',') {
- if (flags.var_line_tainted) {
- print_token();
- flags.var_line_reindented = true;
- flags.var_line_tainted = false;
- print_newline();
- break;
- } else {
- flags.var_line_tainted = false;
- }
- // } else if (token_text === ':') {
- // hmm, when does this happen? tests don't catch this
- // flags.var_line = false;
+ if (last_type === 'TK_END_BLOCK' && flags.mode !== "(EXPRESSION)") {
+ print_token();
+ if (flags.mode === 'OBJECT' && last_text === '}') {
+ print_newline();
+ } else {
+ print_single_space();
+ }
+ } else {
+ if (flags.mode === 'OBJECT') {
+ print_token();
+ print_newline();
+ } else {
+ // EXPR or DO_BLOCK
+ print_token();
+ print_single_space();
}
}
+ break;
+
- if (last_text === 'return' || last_text === 'throw') {
+ case 'TK_OPERATOR':
+
+ var space_before = true;
+ var space_after = true;
+
+ if (is_special_word(last_text)) {
// "return" had a special handling in TK_WORD. Now we need to return the favor
print_single_space();
print_token();
break;
}
+ // hack for actionscript's import .*;
+ if (token_text === '*' && last_type === 'TK_UNKNOWN' && !last_last_text.match(/^\d+$/)) {
+ print_token();
+ break;
+ }
+
if (token_text === ':' && flags.in_case) {
+ if (opt_indent_case) {
+ flags.case_body = true;
+ }
print_token(); // colon really asks for separate treatment
print_newline();
flags.in_case = false;
@@ -988,36 +1183,7 @@ exports.js_beautify = function(js_source_text, options) {
break;
}
- if (token_text === ',') {
- if (flags.var_line) {
- if (flags.var_line_tainted) {
- print_token();
- print_newline();
- flags.var_line_tainted = false;
- } else {
- print_token();
- print_single_space();
- }
- } else if (last_type === 'TK_END_BLOCK' && flags.mode !== "(EXPRESSION)") {
- print_token();
- if (flags.mode === 'OBJECT' && last_text === '}') {
- print_newline();
- } else {
- print_single_space();
- }
- } else {
- if (flags.mode === 'OBJECT') {
- print_token();
- print_newline();
- } else {
- // EXPR or DO_BLOCK
- print_token();
- print_single_space();
- }
- }
- break;
- // } else if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS']) || in_array(last_text, line_starters) || in_array(last_text, ['==', '!=', '+=', '-=', '*=', '/=', '+', '-'])))) {
- } else if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) || in_array(last_text, line_starters)))) {
+ if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) || in_array(last_text, line_starters)))) {
// unary operators (and binary +/- pretending to be unary) special cases
space_before = false;
@@ -1042,8 +1208,10 @@ exports.js_beautify = function(js_source_text, options) {
space_before = false;
} else if (token_text === ':') {
- if (flags.ternary_depth == 0) {
- flags.mode = 'OBJECT';
+ if (flags.ternary_depth === 0) {
+ if (flags.mode === 'BLOCK') {
+ flags.mode = 'OBJECT';
+ }
space_before = false;
} else {
flags.ternary_depth -= 1;
@@ -1061,24 +1229,21 @@ exports.js_beautify = function(js_source_text, options) {
print_single_space();
}
- if (token_text === '!') {
- // flags.eat_next_space = true;
- }
-
break;
case 'TK_BLOCK_COMMENT':
- var lines = token_text.split(/\x0a|\x0d\x0a/);
+ var lines = split_newlines(token_text);
+ var j; // iterator for this case
- if (/^\/\*\*/.test(token_text)) {
+ if (all_lines_start_with(lines.slice(1), '*')) {
// javadoc: reformat and reindent
print_newline();
output.push(lines[0]);
- for (i = 1; i < lines.length; i++) {
+ for (j = 1; j < lines.length; j++) {
print_newline();
output.push(' ');
- output.push(trim(lines[i]));
+ output.push(trim(lines[j]));
}
} else {