gollum 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of gollum might be problematic. Click here for more details.
- data/README.md +44 -7
- data/Rakefile +1 -1
- data/bin/gollum +20 -1
- data/gollum.gemspec +400 -5
- data/lib/gollum.rb +2 -1
- data/lib/gollum/blob_entry.rb +13 -1
- data/lib/gollum/committer.rb +10 -1
- data/lib/gollum/file.rb +15 -2
- data/lib/gollum/file_view.rb +145 -0
- data/lib/gollum/frontend/app.rb +217 -69
- data/lib/gollum/frontend/helpers.rb +21 -0
- data/lib/gollum/frontend/public/gollum/css/_styles.css +121 -0
- data/lib/gollum/frontend/public/gollum/css/editor.css +17 -8
- data/lib/gollum/frontend/public/gollum/css/gollum.css +440 -402
- data/lib/gollum/frontend/public/gollum/css/template.css +540 -289
- data/lib/gollum/frontend/public/gollum/images/dirty-shade.png +0 -0
- data/lib/gollum/frontend/public/gollum/images/fileview/document.png +0 -0
- data/lib/gollum/frontend/public/gollum/images/fileview/folder-horizontal.png +0 -0
- data/lib/gollum/frontend/public/gollum/images/fileview/toggle-small-expand.png +0 -0
- data/lib/gollum/frontend/public/gollum/images/fileview/toggle-small.png +0 -0
- data/lib/gollum/frontend/public/gollum/images/para.png +0 -0
- data/lib/gollum/frontend/public/gollum/images/pin-16.png +0 -0
- data/lib/gollum/frontend/public/gollum/images/pin-20.png +0 -0
- data/lib/gollum/frontend/public/gollum/images/pin-24.png +0 -0
- data/lib/gollum/frontend/public/gollum/images/pin-32.png +0 -0
- data/lib/gollum/frontend/public/gollum/javascript/editor/gollum.editor.js +31 -7
- data/lib/gollum/frontend/public/gollum/javascript/editor/langs/asciidoc.js +2 -1
- data/lib/gollum/frontend/public/gollum/javascript/editor/langs/creole.js +2 -1
- data/lib/gollum/frontend/public/gollum/javascript/editor/langs/markdown.js +18 -6
- data/lib/gollum/frontend/public/gollum/javascript/editor/langs/org.js +2 -1
- data/lib/gollum/frontend/public/gollum/javascript/editor/langs/pod.js +2 -1
- data/lib/gollum/frontend/public/gollum/javascript/editor/langs/textile.js +2 -1
- data/lib/gollum/frontend/public/gollum/javascript/gollum.dialog.js +3 -0
- data/lib/gollum/frontend/public/gollum/javascript/gollum.js +78 -16
- data/lib/gollum/frontend/public/gollum/javascript/jquery-1.7.2.min.js +4 -0
- data/lib/gollum/frontend/public/gollum/javascript/mousetrap.min.js +8 -0
- data/lib/gollum/frontend/public/gollum/livepreview/css/custom.css +107 -0
- data/lib/gollum/frontend/public/gollum/livepreview/images/cancel_24.png +0 -0
- data/lib/gollum/frontend/public/gollum/livepreview/images/lr_24.png +0 -0
- data/lib/gollum/frontend/public/gollum/livepreview/images/save_24.png +0 -0
- data/lib/gollum/frontend/public/gollum/livepreview/images/savecomment_24.png +0 -0
- data/lib/gollum/frontend/public/gollum/livepreview/index.html +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/ace.js +103 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/anchor.js +254 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/anchor_test.js +184 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/background_tokenizer.js +261 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/background_tokenizer_test.js +92 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/commands/command_manager.js +121 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/commands/command_manager_test.js +193 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/commands/default_commands.js +460 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/commands/multi_select_commands.js +101 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/config.js +124 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/css/codefolding-fold-button-states.png +0 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/css/editor.css +327 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/css/expand-marker.png +0 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/document.js +617 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/document_test.js +314 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/edit_session.js +2419 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/edit_session/bracket_match.js +252 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/edit_session/fold.js +116 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/edit_session/fold_line.js +276 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/edit_session/folding.js +759 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/edit_session_test.js +981 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/editor.js +2163 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/editor_change_document_test.js +195 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/editor_highlight_selected_word_test.js +231 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/editor_navigation_test.js +171 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/editor_text_edit_test.js +562 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/ext/static.css +22 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/ext/static_highlight.js +98 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/ext/static_highlight_test.js +81 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/ext/textarea.js +536 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/emacs.js +367 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/hash_handler.js +170 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/keybinding.js +143 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/state_handler.js +257 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/textinput.js +315 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/vim.js +122 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/vim/commands.js +556 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/vim/maps/aliases.js +101 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/vim/maps/motions.js +611 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/vim/maps/operators.js +193 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/vim/maps/util.js +134 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/keyboard/vim/registers.js +49 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/layer/cursor.js +202 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/layer/gutter.js +187 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/layer/marker.js +214 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/layer/text.js +595 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/layer/text_test.js +106 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/browser_focus.js +105 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/dom.js +292 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/es5-shim.js +1059 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/event.js +317 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/event_emitter.js +121 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/event_emitter_test.js +72 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/fixoldbrowsers.js +19 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/keys.js +129 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/lang.js +164 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/net.js +62 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/oop.js +61 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/regexp.js +113 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/lib/useragent.js +105 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/behaviour.js +98 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/behaviour/cstyle.js +225 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/behaviour/html.js +98 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/behaviour/xml.js +113 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/behaviour/xquery.js +68 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/c9search.js +74 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/c9search_highlight_rules.js +66 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/c_cpp.js +132 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/c_cpp_highlight_rules.js +180 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/clojure.js +121 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/clojure_highlight_rules.js +235 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee.js +121 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee/coffee-script.js +63 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee/helpers.js +100 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee/lexer.js +739 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee/nodes.js +2756 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee/parser.js +603 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee/parser_test.js +68 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee/rewriter.js +342 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee/scope.js +154 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee_highlight_rules.js +227 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee_highlight_rules_test.js +72 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coffee_worker.js +92 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coldfusion.js +71 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coldfusion_highlight_rules.js +135 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/coldfusion_test.js +74 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/csharp.js +58 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/csharp_highlight_rules.js +104 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/css.js +110 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/css/csslint.js +9014 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/css_highlight_rules.js +242 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/css_highlight_rules_test.js +99 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/css_test.js +85 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/css_worker.js +66 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/css_worker_test.js +75 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/diff.js +58 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/diff_highlight_rules.js +108 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/doc_comment_highlight_rules.js +93 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/c9search.js +83 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/coffee.js +127 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/coffee_test.js +108 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/cstyle.js +95 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/cstyle_test.js +92 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/diff.js +76 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/fold_mode.js +115 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/html.js +86 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/html_test.js +169 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/mixed.js +88 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/pythonic.js +65 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/pythonic_test.js +105 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/xml.js +262 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/folding/xml_test.js +117 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/golang.js +81 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/golang_highlight_rules.js +129 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/groovy.js +24 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/groovy_highlight_rules.js +183 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/haxe.js +58 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/haxe_highlight_rules.js +104 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/html.js +83 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/html_highlight_rules.js +159 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/html_highlight_rules_test.js +93 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/html_test.js +74 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/java.js +25 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/java_highlight_rules.js +144 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/javascript.js +164 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/javascript_highlight_rules.js +471 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/javascript_highlight_rules_test.js +225 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/javascript_test.js +165 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/javascript_worker.js +88 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/javascript_worker_test.js +99 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/json.js +100 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/json/json_parse.js +346 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/json_highlight_rules.js +111 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/json_worker.js +103 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/json_worker_test.js +108 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/jsx.js +53 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/jsx_highlight_rules.js +122 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/latex.js +57 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/latex_highlight_rules.js +38 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/less.js +87 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/less_highlight_rules.js +279 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/liquid.js +116 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/liquid_highlight_rules.js +220 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/liquid_highlight_rules_test.js +91 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/lua.js +87 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/lua_highlight_rules.js +436 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/luapage.js +22 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/luapage_highlight_rules.js +42 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/markdown.js +81 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/markdown_highlight_rules.js +195 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/matching_brace_outdent.js +81 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/matching_parens_outdent.js +81 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/ocaml.js +103 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/ocaml_highlight_rules.js +355 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/perl.js +117 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/perl_highlight_rules.js +168 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/pgsql.js +78 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/pgsql_highlight_rules.js +583 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/php.js +119 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/php_highlight_rules.js +1165 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/powershell.js +58 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/powershell_highlight_rules.js +138 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/python.js +147 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/python_highlight_rules.js +182 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/python_test.js +86 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/ruby.js +116 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/ruby_highlight_rules.js +194 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/ruby_highlight_rules_test.js +116 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/scad.js +132 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/scad_highlight_rules.js +168 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/scala.js +25 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/scala_highlight_rules.js +179 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/scss.js +86 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/scss_highlight_rules.js +304 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/sh.js +144 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/sh_highlight_rules.js +145 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/sql.js +70 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/sql_highlight_rules.js +89 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/svg.js +78 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/svg_highlight_rules.js +71 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/text.js +159 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/text_highlight_rules.js +109 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/text_test.js +71 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/textile.js +73 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/textile_highlight_rules.js +100 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xml.js +65 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xml_highlight_rules.js +109 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xml_highlight_rules_test.js +103 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xml_test.js +82 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xml_util.js +120 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery.js +202 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/Position.js +59 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/Readme.md +6 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/StringLexer.js +1686 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/XMLLexer.js +2993 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/XQDTLexer.js +69 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/XQDTParser.js +63 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/XQueryLexer.js +10363 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/XQueryParser.js +42525 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/XQuerySemanticHighlighter.js +165 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/antlr3-all.js +6177 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery/xquery.js +55 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery_highlight_rules.js +158 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/xquery_worker.js +86 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/yaml.js +64 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/yaml_highlight_rules.js +116 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/model/editor.js +70 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mouse/default_gutter_handler.js +73 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mouse/default_handlers.js +354 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mouse/dragdrop.js +105 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mouse/fold_handler.js +71 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mouse/mouse_event.js +140 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mouse/mouse_handler.js +158 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mouse/multi_select_handler.js +163 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/multi_select.js +762 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/multi_select_test.js +171 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/narcissus/definitions.js +696 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/narcissus/lexer.js +598 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/narcissus/options.js +61 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/narcissus/parser.js +2072 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/placeholder.js +278 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/placeholder_test.js +164 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/range.js +581 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/range_list.js +230 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/range_list_test.js +170 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/range_test.js +198 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/renderloop.js +93 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/requirejs/text.js +58 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/scrollbar.js +142 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/search.js +398 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/search_highlight.js +87 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/search_test.js +451 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/selection.js +886 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/selection_test.js +472 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/split.js +411 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/all.js +42 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/all_browser.js +136 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/assertions.js +63 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/asyncjs/assert.js +313 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/asyncjs/async.js +529 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/asyncjs/index.js +13 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/asyncjs/test.js +195 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/asyncjs/utils.js +65 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/benchmark.js +85 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/mockdom.js +10 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/mockrenderer.js +204 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/test/tests.html +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/chrome.css +159 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/chrome.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/clouds.css +118 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/clouds.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/clouds_midnight.css +119 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/clouds_midnight.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/cobalt.css +145 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/cobalt.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/crimson_editor.css +151 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/crimson_editor.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/dawn.css +149 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/dawn.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/dreamweaver.css +182 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/dreamweaver.js +45 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/eclipse.css +102 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/eclipse.js +48 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/github.css +133 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/github.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/idle_fingers.css +137 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/idle_fingers.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/kr_theme.css +140 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/kr_theme.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/merbivore.css +140 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/merbivore.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/merbivore_soft.css +146 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/merbivore_soft.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/mono_industrial.css +148 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/mono_industrial.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/monokai.css +145 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/monokai.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/pastel_on_dark.css +150 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/pastel_on_dark.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/solarized_dark.css +131 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/solarized_dark.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/solarized_light.css +130 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/solarized_light.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/textmate.css +165 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/textmate.js +47 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow.css +164 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow_night.css +164 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow_night.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow_night_blue.css +164 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow_night_blue.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow_night_bright.css +164 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow_night_bright.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow_night_eighties.css +160 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/tomorrow_night_eighties.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/twilight.css +162 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/twilight.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/vibrant_ink.css +141 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/theme/vibrant_ink.js +46 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/token_iterator.js +162 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/token_iterator_test.js +219 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/tokenizer.js +195 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/undomanager.js +142 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/unicode.js +107 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/virtual_renderer.js +1402 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/virtual_renderer_test.js +93 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/worker/jshint.js +4469 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/worker/jslint.js +6396 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/worker/mirror.js +43 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/worker/worker.js +138 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/worker/worker_client.js +176 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/worker/worker_sourcemint.js +73 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/jquery.ba-throttle-debounce.min.js +2 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js +456 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/md_sundown.js +22 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/requirejs.min.js +35 -0
- data/lib/gollum/frontend/public/gollum/livepreview/js/sundown.js +1 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/ace/LICENSE.txt +476 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/bootstraponline_gollum/LICENSE.txt +9 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/debounce/LICENSE-MIT.txt +22 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/gollum/LICENSE.txt +21 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/jquery/MIT-LICENSE.txt +20 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/licenses.txt +59 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/notepages/LICENSE.txt +19 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/requirejs/LICENSE.txt +58 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/retina_display_icon_set/by_sa_3.0_unported_legalcode.txt +359 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/sizzle/LICENSE.txt +148 -0
- data/lib/gollum/frontend/public/gollum/livepreview/licenses/sundown/sundown.txt +4 -0
- data/lib/gollum/frontend/public/gollum/livepreview/readme.md +44 -0
- data/lib/gollum/frontend/templates/compare.mustache +9 -9
- data/lib/gollum/frontend/templates/create.mustache +4 -1
- data/lib/gollum/frontend/templates/edit.mustache +6 -3
- data/lib/gollum/frontend/templates/editor.mustache +30 -14
- data/lib/gollum/frontend/templates/file_view.mustache +32 -0
- data/lib/gollum/frontend/templates/history.mustache +8 -8
- data/lib/gollum/frontend/templates/layout.mustache +21 -14
- data/lib/gollum/frontend/templates/page.mustache +37 -14
- data/lib/gollum/frontend/templates/pages.mustache +14 -10
- data/lib/gollum/frontend/templates/search.mustache +2 -2
- data/lib/gollum/frontend/templates/searchbar.mustache +1 -1
- data/lib/gollum/frontend/uri_encode_component.rb +172 -0
- data/lib/gollum/frontend/views/compare.rb +2 -4
- data/lib/gollum/frontend/views/create.rb +5 -0
- data/lib/gollum/frontend/views/edit.rb +12 -0
- data/lib/gollum/frontend/views/file_view.rb +19 -0
- data/lib/gollum/frontend/views/has_page.rb +15 -0
- data/lib/gollum/frontend/views/history.rb +8 -4
- data/lib/gollum/frontend/views/layout.rb +9 -1
- data/lib/gollum/frontend/views/page.rb +37 -10
- data/lib/gollum/frontend/views/pages.rb +48 -0
- data/lib/gollum/git_access.rb +2 -2
- data/lib/gollum/markup.rb +115 -19
- data/lib/gollum/page.rb +79 -9
- data/lib/gollum/tex.rb +319 -42
- data/lib/gollum/wiki.rb +92 -12
- data/licenses/css_tree_menu_thecssninja/license.txt +50 -0
- data/licenses/licenses.txt +23 -0
- data/licenses/unity_asset_pool/COPYRIGHT +286 -0
- data/test/examples/lotr.git/config +1 -1
- data/test/examples/lotr.git/logs/HEAD +4 -0
- data/test/examples/lotr.git/logs/refs/heads/master +4 -0
- data/test/examples/lotr.git/objects/0d/c9016ca928c78d5421a99a53b379b53929221e +0 -0
- data/test/examples/lotr.git/objects/1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 +0 -0
- data/test/examples/lotr.git/objects/27/680b0fce1abfbc528e7aa53d92645852d52eb6 +0 -0
- data/test/examples/lotr.git/objects/45/3b250f979c7bd6dfb62640c944c982ae6721ee +0 -0
- data/test/examples/lotr.git/objects/45/f319ee12f2b551b901b22e72602963c366fff1 +0 -0
- data/test/examples/lotr.git/objects/46/a697caf435815bb07bbce947fc2d58be15f087 +0 -0
- data/test/examples/lotr.git/objects/4c/45c2b4e297a726c3d3f66886f35373e48fe1c5 +2 -0
- data/test/examples/lotr.git/objects/4e/023f460ce466e154ca09d8774c79ad5a53fc15 +0 -0
- data/test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 +1 -0
- data/test/examples/lotr.git/objects/6e/48abfc56565574859e081ee58eae655d48cf71 +0 -0
- data/test/examples/lotr.git/objects/7b/60c5a20a501a70f2317fa0ef763e1e2ce22d6b +0 -0
- data/test/examples/lotr.git/objects/7d/981cd984ad589e3cf00d8122170c6f7d685979 +0 -0
- data/test/examples/lotr.git/objects/94/9a9cc3119b9c98817f375e976d2bb5e2a42809 +0 -0
- data/test/examples/lotr.git/objects/9b/e95b960ac388d4e7db55f610f828e9c31344e6 +0 -0
- data/test/examples/lotr.git/objects/b0/de6e794dfdc7ef3400e894225bfe23308aae5c +0 -0
- data/test/examples/lotr.git/objects/b1/6b3d9fad9d78e5a669e7f33d94c96da374eccd +0 -0
- data/test/examples/lotr.git/objects/c9/6a7645db5d4c76389e77cd103ef3ed77d81e4c +0 -0
- data/test/examples/lotr.git/objects/ca/7355dc497e9729fbaf0c0e3f424b86afef5614 +0 -0
- data/test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd +2 -0
- data/test/examples/lotr.git/objects/d5/29304506d37f544675244c335d85cab5d29966 +0 -0
- data/test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df +1 -0
- data/test/examples/lotr.git/objects/fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 +0 -0
- data/test/examples/lotr.git/objects/ff/6f7de62644369380ba73b4e4297c1a2d6f0b66 +0 -0
- data/test/examples/lotr.git/refs/heads/master +1 -1
- data/test/examples/revert.git/COMMIT_EDITMSG +1 -1
- data/test/examples/revert.git/index +0 -0
- data/test/examples/revert.git/logs/HEAD +1 -0
- data/test/examples/revert.git/logs/refs/heads/master +1 -0
- data/test/examples/revert.git/objects/10/2685c42018f802557f05db171f44443e8dacab +0 -0
- data/test/examples/revert.git/objects/8e/83f898e5e16ae400db59dda1017acad540f3aa +0 -0
- data/test/examples/revert.git/objects/ed/6c9f63b98acf73c25b5ffbb38da557d3682023 +3 -0
- data/test/examples/revert.git/refs/heads/master +1 -1
- data/test/file_view/1_file.txt +3 -0
- data/test/file_view/1_file_1_folder.txt +8 -0
- data/test/file_view/1_folder.txt +8 -0
- data/test/file_view/2_files_2_folders.txt +12 -0
- data/test/file_view/2_files_2_folders_1_root.txt +13 -0
- data/test/file_view/nested_folders.txt +28 -0
- data/test/test_app.rb +162 -12
- data/test/test_app_helpers.rb +13 -0
- data/test/test_committer.rb +1 -1
- data/test/test_file_view.rb +102 -0
- data/test/test_git_access.rb +3 -2
- data/test/test_markup.rb +45 -12
- data/test/test_page.rb +65 -1
- data/test/test_page_revert.rb +14 -2
- data/test/test_pages_view.rb +37 -0
- data/test/test_unicode.rb +110 -0
- data/test/test_wiki.rb +51 -4
- metadata +658 -239
- data/lib/gollum/frontend/public/gollum/javascript/jquery.js +0 -7179
@@ -0,0 +1,2756 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2011 Jeremy Ashkenas
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person
|
5
|
+
* obtaining a copy of this software and associated documentation
|
6
|
+
* files (the "Software"), to deal in the Software without
|
7
|
+
* restriction, including without limitation the rights to use,
|
8
|
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
* copies of the Software, and to permit persons to whom the
|
10
|
+
* Software is furnished to do so, subject to the following
|
11
|
+
* conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be
|
14
|
+
* included in all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
* OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
|
26
|
+
define(function(require, exports, module) {
|
27
|
+
// Generated by CoffeeScript 1.2.1-pre
|
28
|
+
|
29
|
+
var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref, _ref1,
|
30
|
+
__hasProp = {}.hasOwnProperty,
|
31
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; },
|
32
|
+
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
33
|
+
|
34
|
+
Scope = require('./scope').Scope;
|
35
|
+
|
36
|
+
_ref = require('./lexer'), RESERVED = _ref.RESERVED, STRICT_PROSCRIBED = _ref.STRICT_PROSCRIBED;
|
37
|
+
|
38
|
+
_ref1 = require('./helpers'), compact = _ref1.compact, flatten = _ref1.flatten, extend = _ref1.extend, merge = _ref1.merge, del = _ref1.del, starts = _ref1.starts, ends = _ref1.ends, last = _ref1.last;
|
39
|
+
|
40
|
+
exports.extend = extend;
|
41
|
+
|
42
|
+
YES = function() {
|
43
|
+
return true;
|
44
|
+
};
|
45
|
+
|
46
|
+
NO = function() {
|
47
|
+
return false;
|
48
|
+
};
|
49
|
+
|
50
|
+
THIS = function() {
|
51
|
+
return this;
|
52
|
+
};
|
53
|
+
|
54
|
+
NEGATE = function() {
|
55
|
+
this.negated = !this.negated;
|
56
|
+
return this;
|
57
|
+
};
|
58
|
+
|
59
|
+
exports.Base = Base = (function() {
|
60
|
+
|
61
|
+
Base.name = 'Base';
|
62
|
+
|
63
|
+
function Base() {}
|
64
|
+
|
65
|
+
Base.prototype.compile = function(o, lvl) {
|
66
|
+
var node;
|
67
|
+
o = extend({}, o);
|
68
|
+
if (lvl) o.level = lvl;
|
69
|
+
node = this.unfoldSoak(o) || this;
|
70
|
+
node.tab = o.indent;
|
71
|
+
if (o.level === LEVEL_TOP || !node.isStatement(o)) {
|
72
|
+
return node.compileNode(o);
|
73
|
+
} else {
|
74
|
+
return node.compileClosure(o);
|
75
|
+
}
|
76
|
+
};
|
77
|
+
|
78
|
+
Base.prototype.compileClosure = function(o) {
|
79
|
+
if (this.jumps()) {
|
80
|
+
throw SyntaxError('cannot use a pure statement in an expression.');
|
81
|
+
}
|
82
|
+
o.sharedScope = true;
|
83
|
+
return Closure.wrap(this).compileNode(o);
|
84
|
+
};
|
85
|
+
|
86
|
+
Base.prototype.cache = function(o, level, reused) {
|
87
|
+
var ref, sub;
|
88
|
+
if (!this.isComplex()) {
|
89
|
+
ref = level ? this.compile(o, level) : this;
|
90
|
+
return [ref, ref];
|
91
|
+
} else {
|
92
|
+
ref = new Literal(reused || o.scope.freeVariable('ref'));
|
93
|
+
sub = new Assign(ref, this);
|
94
|
+
if (level) {
|
95
|
+
return [sub.compile(o, level), ref.value];
|
96
|
+
} else {
|
97
|
+
return [sub, ref];
|
98
|
+
}
|
99
|
+
}
|
100
|
+
};
|
101
|
+
|
102
|
+
Base.prototype.compileLoopReference = function(o, name) {
|
103
|
+
var src, tmp;
|
104
|
+
src = tmp = this.compile(o, LEVEL_LIST);
|
105
|
+
if (!((-Infinity < +src && +src < Infinity) || IDENTIFIER.test(src) && o.scope.check(src, true))) {
|
106
|
+
src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src;
|
107
|
+
}
|
108
|
+
return [src, tmp];
|
109
|
+
};
|
110
|
+
|
111
|
+
Base.prototype.makeReturn = function(res) {
|
112
|
+
var me;
|
113
|
+
me = this.unwrapAll();
|
114
|
+
if (res) {
|
115
|
+
return new Call(new Literal("" + res + ".push"), [me]);
|
116
|
+
} else {
|
117
|
+
return new Return(me);
|
118
|
+
}
|
119
|
+
};
|
120
|
+
|
121
|
+
Base.prototype.contains = function(pred) {
|
122
|
+
var contains;
|
123
|
+
contains = false;
|
124
|
+
this.traverseChildren(false, function(node) {
|
125
|
+
if (pred(node)) {
|
126
|
+
contains = true;
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
});
|
130
|
+
return contains;
|
131
|
+
};
|
132
|
+
|
133
|
+
Base.prototype.containsType = function(type) {
|
134
|
+
return this instanceof type || this.contains(function(node) {
|
135
|
+
return node instanceof type;
|
136
|
+
});
|
137
|
+
};
|
138
|
+
|
139
|
+
Base.prototype.lastNonComment = function(list) {
|
140
|
+
var i;
|
141
|
+
i = list.length;
|
142
|
+
while (i--) {
|
143
|
+
if (!(list[i] instanceof Comment)) return list[i];
|
144
|
+
}
|
145
|
+
return null;
|
146
|
+
};
|
147
|
+
|
148
|
+
Base.prototype.toString = function(idt, name) {
|
149
|
+
var tree;
|
150
|
+
if (idt == null) idt = '';
|
151
|
+
if (name == null) name = this.constructor.name;
|
152
|
+
tree = '\n' + idt + name;
|
153
|
+
if (this.soak) tree += '?';
|
154
|
+
this.eachChild(function(node) {
|
155
|
+
return tree += node.toString(idt + TAB);
|
156
|
+
});
|
157
|
+
return tree;
|
158
|
+
};
|
159
|
+
|
160
|
+
Base.prototype.eachChild = function(func) {
|
161
|
+
var attr, child, _i, _j, _len, _len1, _ref2, _ref3;
|
162
|
+
if (!this.children) return this;
|
163
|
+
_ref2 = this.children;
|
164
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
165
|
+
attr = _ref2[_i];
|
166
|
+
if (this[attr]) {
|
167
|
+
_ref3 = flatten([this[attr]]);
|
168
|
+
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
|
169
|
+
child = _ref3[_j];
|
170
|
+
if (func(child) === false) return this;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
return this;
|
175
|
+
};
|
176
|
+
|
177
|
+
Base.prototype.traverseChildren = function(crossScope, func) {
|
178
|
+
return this.eachChild(function(child) {
|
179
|
+
if (func(child) === false) return false;
|
180
|
+
return child.traverseChildren(crossScope, func);
|
181
|
+
});
|
182
|
+
};
|
183
|
+
|
184
|
+
Base.prototype.invert = function() {
|
185
|
+
return new Op('!', this);
|
186
|
+
};
|
187
|
+
|
188
|
+
Base.prototype.unwrapAll = function() {
|
189
|
+
var node;
|
190
|
+
node = this;
|
191
|
+
while (node !== (node = node.unwrap())) {
|
192
|
+
continue;
|
193
|
+
}
|
194
|
+
return node;
|
195
|
+
};
|
196
|
+
|
197
|
+
Base.prototype.children = [];
|
198
|
+
|
199
|
+
Base.prototype.isStatement = NO;
|
200
|
+
|
201
|
+
Base.prototype.jumps = NO;
|
202
|
+
|
203
|
+
Base.prototype.isComplex = YES;
|
204
|
+
|
205
|
+
Base.prototype.isChainable = NO;
|
206
|
+
|
207
|
+
Base.prototype.isAssignable = NO;
|
208
|
+
|
209
|
+
Base.prototype.unwrap = THIS;
|
210
|
+
|
211
|
+
Base.prototype.unfoldSoak = NO;
|
212
|
+
|
213
|
+
Base.prototype.assigns = NO;
|
214
|
+
|
215
|
+
return Base;
|
216
|
+
|
217
|
+
})();
|
218
|
+
|
219
|
+
exports.Block = Block = (function(_super) {
|
220
|
+
|
221
|
+
__extends(Block, _super);
|
222
|
+
|
223
|
+
Block.name = 'Block';
|
224
|
+
|
225
|
+
function Block(nodes) {
|
226
|
+
this.expressions = compact(flatten(nodes || []));
|
227
|
+
}
|
228
|
+
|
229
|
+
Block.prototype.children = ['expressions'];
|
230
|
+
|
231
|
+
Block.prototype.push = function(node) {
|
232
|
+
this.expressions.push(node);
|
233
|
+
return this;
|
234
|
+
};
|
235
|
+
|
236
|
+
Block.prototype.pop = function() {
|
237
|
+
return this.expressions.pop();
|
238
|
+
};
|
239
|
+
|
240
|
+
Block.prototype.unshift = function(node) {
|
241
|
+
this.expressions.unshift(node);
|
242
|
+
return this;
|
243
|
+
};
|
244
|
+
|
245
|
+
Block.prototype.unwrap = function() {
|
246
|
+
if (this.expressions.length === 1) {
|
247
|
+
return this.expressions[0];
|
248
|
+
} else {
|
249
|
+
return this;
|
250
|
+
}
|
251
|
+
};
|
252
|
+
|
253
|
+
Block.prototype.isEmpty = function() {
|
254
|
+
return !this.expressions.length;
|
255
|
+
};
|
256
|
+
|
257
|
+
Block.prototype.isStatement = function(o) {
|
258
|
+
var exp, _i, _len, _ref2;
|
259
|
+
_ref2 = this.expressions;
|
260
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
261
|
+
exp = _ref2[_i];
|
262
|
+
if (exp.isStatement(o)) return true;
|
263
|
+
}
|
264
|
+
return false;
|
265
|
+
};
|
266
|
+
|
267
|
+
Block.prototype.jumps = function(o) {
|
268
|
+
var exp, _i, _len, _ref2;
|
269
|
+
_ref2 = this.expressions;
|
270
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
271
|
+
exp = _ref2[_i];
|
272
|
+
if (exp.jumps(o)) return exp;
|
273
|
+
}
|
274
|
+
};
|
275
|
+
|
276
|
+
Block.prototype.makeReturn = function(res) {
|
277
|
+
var expr, len;
|
278
|
+
len = this.expressions.length;
|
279
|
+
while (len--) {
|
280
|
+
expr = this.expressions[len];
|
281
|
+
if (!(expr instanceof Comment)) {
|
282
|
+
this.expressions[len] = expr.makeReturn(res);
|
283
|
+
if (expr instanceof Return && !expr.expression) {
|
284
|
+
this.expressions.splice(len, 1);
|
285
|
+
}
|
286
|
+
break;
|
287
|
+
}
|
288
|
+
}
|
289
|
+
return this;
|
290
|
+
};
|
291
|
+
|
292
|
+
Block.prototype.compile = function(o, level) {
|
293
|
+
if (o == null) o = {};
|
294
|
+
if (o.scope) {
|
295
|
+
return Block.__super__.compile.call(this, o, level);
|
296
|
+
} else {
|
297
|
+
return this.compileRoot(o);
|
298
|
+
}
|
299
|
+
};
|
300
|
+
|
301
|
+
Block.prototype.compileNode = function(o) {
|
302
|
+
var code, codes, node, top, _i, _len, _ref2;
|
303
|
+
this.tab = o.indent;
|
304
|
+
top = o.level === LEVEL_TOP;
|
305
|
+
codes = [];
|
306
|
+
_ref2 = this.expressions;
|
307
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
308
|
+
node = _ref2[_i];
|
309
|
+
node = node.unwrapAll();
|
310
|
+
node = node.unfoldSoak(o) || node;
|
311
|
+
if (node instanceof Block) {
|
312
|
+
codes.push(node.compileNode(o));
|
313
|
+
} else if (top) {
|
314
|
+
node.front = true;
|
315
|
+
code = node.compile(o);
|
316
|
+
if (!node.isStatement(o)) {
|
317
|
+
code = "" + this.tab + code + ";";
|
318
|
+
if (node instanceof Literal) code = "" + code + "\n";
|
319
|
+
}
|
320
|
+
codes.push(code);
|
321
|
+
} else {
|
322
|
+
codes.push(node.compile(o, LEVEL_LIST));
|
323
|
+
}
|
324
|
+
}
|
325
|
+
if (top) {
|
326
|
+
if (this.spaced) {
|
327
|
+
return "\n" + (codes.join('\n\n')) + "\n";
|
328
|
+
} else {
|
329
|
+
return codes.join('\n');
|
330
|
+
}
|
331
|
+
}
|
332
|
+
code = codes.join(', ') || 'void 0';
|
333
|
+
if (codes.length > 1 && o.level >= LEVEL_LIST) {
|
334
|
+
return "(" + code + ")";
|
335
|
+
} else {
|
336
|
+
return code;
|
337
|
+
}
|
338
|
+
};
|
339
|
+
|
340
|
+
Block.prototype.compileRoot = function(o) {
|
341
|
+
var code, exp, i, prelude, preludeExps, rest;
|
342
|
+
o.indent = o.bare ? '' : TAB;
|
343
|
+
o.scope = new Scope(null, this, null);
|
344
|
+
o.level = LEVEL_TOP;
|
345
|
+
this.spaced = true;
|
346
|
+
prelude = "";
|
347
|
+
if (!o.bare) {
|
348
|
+
preludeExps = (function() {
|
349
|
+
var _i, _len, _ref2, _results;
|
350
|
+
_ref2 = this.expressions;
|
351
|
+
_results = [];
|
352
|
+
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
353
|
+
exp = _ref2[i];
|
354
|
+
if (!(exp.unwrap() instanceof Comment)) break;
|
355
|
+
_results.push(exp);
|
356
|
+
}
|
357
|
+
return _results;
|
358
|
+
}).call(this);
|
359
|
+
rest = this.expressions.slice(preludeExps.length);
|
360
|
+
this.expressions = preludeExps;
|
361
|
+
if (preludeExps.length) {
|
362
|
+
prelude = "" + (this.compileNode(merge(o, {
|
363
|
+
indent: ''
|
364
|
+
}))) + "\n";
|
365
|
+
}
|
366
|
+
this.expressions = rest;
|
367
|
+
}
|
368
|
+
code = this.compileWithDeclarations(o);
|
369
|
+
if (o.bare) return code;
|
370
|
+
return "" + prelude + "(function() {\n" + code + "\n}).call(this);\n";
|
371
|
+
};
|
372
|
+
|
373
|
+
Block.prototype.compileWithDeclarations = function(o) {
|
374
|
+
var assigns, code, declars, exp, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;
|
375
|
+
code = post = '';
|
376
|
+
_ref2 = this.expressions;
|
377
|
+
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
378
|
+
exp = _ref2[i];
|
379
|
+
exp = exp.unwrap();
|
380
|
+
if (!(exp instanceof Comment || exp instanceof Literal)) break;
|
381
|
+
}
|
382
|
+
o = merge(o, {
|
383
|
+
level: LEVEL_TOP
|
384
|
+
});
|
385
|
+
if (i) {
|
386
|
+
rest = this.expressions.splice(i, 9e9);
|
387
|
+
_ref3 = [this.spaced, false], spaced = _ref3[0], this.spaced = _ref3[1];
|
388
|
+
_ref4 = [this.compileNode(o), spaced], code = _ref4[0], this.spaced = _ref4[1];
|
389
|
+
this.expressions = rest;
|
390
|
+
}
|
391
|
+
post = this.compileNode(o);
|
392
|
+
scope = o.scope;
|
393
|
+
if (scope.expressions === this) {
|
394
|
+
declars = o.scope.hasDeclarations();
|
395
|
+
assigns = scope.hasAssignments;
|
396
|
+
if (declars || assigns) {
|
397
|
+
if (i) code += '\n';
|
398
|
+
code += "" + this.tab + "var ";
|
399
|
+
if (declars) code += scope.declaredVariables().join(', ');
|
400
|
+
if (assigns) {
|
401
|
+
if (declars) code += ",\n" + (this.tab + TAB);
|
402
|
+
code += scope.assignedVariables().join(",\n" + (this.tab + TAB));
|
403
|
+
}
|
404
|
+
code += ';\n';
|
405
|
+
}
|
406
|
+
}
|
407
|
+
return code + post;
|
408
|
+
};
|
409
|
+
|
410
|
+
Block.wrap = function(nodes) {
|
411
|
+
if (nodes.length === 1 && nodes[0] instanceof Block) return nodes[0];
|
412
|
+
return new Block(nodes);
|
413
|
+
};
|
414
|
+
|
415
|
+
return Block;
|
416
|
+
|
417
|
+
})(Base);
|
418
|
+
|
419
|
+
exports.Literal = Literal = (function(_super) {
|
420
|
+
|
421
|
+
__extends(Literal, _super);
|
422
|
+
|
423
|
+
Literal.name = 'Literal';
|
424
|
+
|
425
|
+
function Literal(value) {
|
426
|
+
this.value = value;
|
427
|
+
}
|
428
|
+
|
429
|
+
Literal.prototype.makeReturn = function() {
|
430
|
+
if (this.isStatement()) {
|
431
|
+
return this;
|
432
|
+
} else {
|
433
|
+
return Literal.__super__.makeReturn.apply(this, arguments);
|
434
|
+
}
|
435
|
+
};
|
436
|
+
|
437
|
+
Literal.prototype.isAssignable = function() {
|
438
|
+
return IDENTIFIER.test(this.value);
|
439
|
+
};
|
440
|
+
|
441
|
+
Literal.prototype.isStatement = function() {
|
442
|
+
var _ref2;
|
443
|
+
return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
|
444
|
+
};
|
445
|
+
|
446
|
+
Literal.prototype.isComplex = NO;
|
447
|
+
|
448
|
+
Literal.prototype.assigns = function(name) {
|
449
|
+
return name === this.value;
|
450
|
+
};
|
451
|
+
|
452
|
+
Literal.prototype.jumps = function(o) {
|
453
|
+
if (this.value === 'break' && !((o != null ? o.loop : void 0) || (o != null ? o.block : void 0))) {
|
454
|
+
return this;
|
455
|
+
}
|
456
|
+
if (this.value === 'continue' && !(o != null ? o.loop : void 0)) return this;
|
457
|
+
};
|
458
|
+
|
459
|
+
Literal.prototype.compileNode = function(o) {
|
460
|
+
var code, _ref2;
|
461
|
+
code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved ? "\"" + this.value + "\"" : this.value;
|
462
|
+
if (this.isStatement()) {
|
463
|
+
return "" + this.tab + code + ";";
|
464
|
+
} else {
|
465
|
+
return code;
|
466
|
+
}
|
467
|
+
};
|
468
|
+
|
469
|
+
Literal.prototype.toString = function() {
|
470
|
+
return ' "' + this.value + '"';
|
471
|
+
};
|
472
|
+
|
473
|
+
return Literal;
|
474
|
+
|
475
|
+
})(Base);
|
476
|
+
|
477
|
+
exports.Return = Return = (function(_super) {
|
478
|
+
|
479
|
+
__extends(Return, _super);
|
480
|
+
|
481
|
+
Return.name = 'Return';
|
482
|
+
|
483
|
+
function Return(expr) {
|
484
|
+
if (expr && !expr.unwrap().isUndefined) this.expression = expr;
|
485
|
+
}
|
486
|
+
|
487
|
+
Return.prototype.children = ['expression'];
|
488
|
+
|
489
|
+
Return.prototype.isStatement = YES;
|
490
|
+
|
491
|
+
Return.prototype.makeReturn = THIS;
|
492
|
+
|
493
|
+
Return.prototype.jumps = THIS;
|
494
|
+
|
495
|
+
Return.prototype.compile = function(o, level) {
|
496
|
+
var expr, _ref2;
|
497
|
+
expr = (_ref2 = this.expression) != null ? _ref2.makeReturn() : void 0;
|
498
|
+
if (expr && !(expr instanceof Return)) {
|
499
|
+
return expr.compile(o, level);
|
500
|
+
} else {
|
501
|
+
return Return.__super__.compile.call(this, o, level);
|
502
|
+
}
|
503
|
+
};
|
504
|
+
|
505
|
+
Return.prototype.compileNode = function(o) {
|
506
|
+
return this.tab + ("return" + [this.expression ? " " + (this.expression.compile(o, LEVEL_PAREN)) : void 0] + ";");
|
507
|
+
};
|
508
|
+
|
509
|
+
return Return;
|
510
|
+
|
511
|
+
})(Base);
|
512
|
+
|
513
|
+
exports.Value = Value = (function(_super) {
|
514
|
+
|
515
|
+
__extends(Value, _super);
|
516
|
+
|
517
|
+
Value.name = 'Value';
|
518
|
+
|
519
|
+
function Value(base, props, tag) {
|
520
|
+
if (!props && base instanceof Value) return base;
|
521
|
+
this.base = base;
|
522
|
+
this.properties = props || [];
|
523
|
+
if (tag) this[tag] = true;
|
524
|
+
return this;
|
525
|
+
}
|
526
|
+
|
527
|
+
Value.prototype.children = ['base', 'properties'];
|
528
|
+
|
529
|
+
Value.prototype.add = function(props) {
|
530
|
+
this.properties = this.properties.concat(props);
|
531
|
+
return this;
|
532
|
+
};
|
533
|
+
|
534
|
+
Value.prototype.hasProperties = function() {
|
535
|
+
return !!this.properties.length;
|
536
|
+
};
|
537
|
+
|
538
|
+
Value.prototype.isArray = function() {
|
539
|
+
return !this.properties.length && this.base instanceof Arr;
|
540
|
+
};
|
541
|
+
|
542
|
+
Value.prototype.isComplex = function() {
|
543
|
+
return this.hasProperties() || this.base.isComplex();
|
544
|
+
};
|
545
|
+
|
546
|
+
Value.prototype.isAssignable = function() {
|
547
|
+
return this.hasProperties() || this.base.isAssignable();
|
548
|
+
};
|
549
|
+
|
550
|
+
Value.prototype.isSimpleNumber = function() {
|
551
|
+
return this.base instanceof Literal && SIMPLENUM.test(this.base.value);
|
552
|
+
};
|
553
|
+
|
554
|
+
Value.prototype.isString = function() {
|
555
|
+
return this.base instanceof Literal && IS_STRING.test(this.base.value);
|
556
|
+
};
|
557
|
+
|
558
|
+
Value.prototype.isAtomic = function() {
|
559
|
+
var node, _i, _len, _ref2;
|
560
|
+
_ref2 = this.properties.concat(this.base);
|
561
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
562
|
+
node = _ref2[_i];
|
563
|
+
if (node.soak || node instanceof Call) return false;
|
564
|
+
}
|
565
|
+
return true;
|
566
|
+
};
|
567
|
+
|
568
|
+
Value.prototype.isStatement = function(o) {
|
569
|
+
return !this.properties.length && this.base.isStatement(o);
|
570
|
+
};
|
571
|
+
|
572
|
+
Value.prototype.assigns = function(name) {
|
573
|
+
return !this.properties.length && this.base.assigns(name);
|
574
|
+
};
|
575
|
+
|
576
|
+
Value.prototype.jumps = function(o) {
|
577
|
+
return !this.properties.length && this.base.jumps(o);
|
578
|
+
};
|
579
|
+
|
580
|
+
Value.prototype.isObject = function(onlyGenerated) {
|
581
|
+
if (this.properties.length) return false;
|
582
|
+
return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated);
|
583
|
+
};
|
584
|
+
|
585
|
+
Value.prototype.isSplice = function() {
|
586
|
+
return last(this.properties) instanceof Slice;
|
587
|
+
};
|
588
|
+
|
589
|
+
Value.prototype.unwrap = function() {
|
590
|
+
if (this.properties.length) {
|
591
|
+
return this;
|
592
|
+
} else {
|
593
|
+
return this.base;
|
594
|
+
}
|
595
|
+
};
|
596
|
+
|
597
|
+
Value.prototype.cacheReference = function(o) {
|
598
|
+
var base, bref, name, nref;
|
599
|
+
name = last(this.properties);
|
600
|
+
if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {
|
601
|
+
return [this, this];
|
602
|
+
}
|
603
|
+
base = new Value(this.base, this.properties.slice(0, -1));
|
604
|
+
if (base.isComplex()) {
|
605
|
+
bref = new Literal(o.scope.freeVariable('base'));
|
606
|
+
base = new Value(new Parens(new Assign(bref, base)));
|
607
|
+
}
|
608
|
+
if (!name) return [base, bref];
|
609
|
+
if (name.isComplex()) {
|
610
|
+
nref = new Literal(o.scope.freeVariable('name'));
|
611
|
+
name = new Index(new Assign(nref, name.index));
|
612
|
+
nref = new Index(nref);
|
613
|
+
}
|
614
|
+
return [base.add(name), new Value(bref || base.base, [nref || name])];
|
615
|
+
};
|
616
|
+
|
617
|
+
Value.prototype.compileNode = function(o) {
|
618
|
+
var code, prop, props, _i, _len;
|
619
|
+
this.base.front = this.front;
|
620
|
+
props = this.properties;
|
621
|
+
code = this.base.compile(o, props.length ? LEVEL_ACCESS : null);
|
622
|
+
if ((this.base instanceof Parens || props.length) && SIMPLENUM.test(code)) {
|
623
|
+
code = "" + code + ".";
|
624
|
+
}
|
625
|
+
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
626
|
+
prop = props[_i];
|
627
|
+
code += prop.compile(o);
|
628
|
+
}
|
629
|
+
return code;
|
630
|
+
};
|
631
|
+
|
632
|
+
Value.prototype.unfoldSoak = function(o) {
|
633
|
+
var result,
|
634
|
+
_this = this;
|
635
|
+
if (this.unfoldedSoak != null) return this.unfoldedSoak;
|
636
|
+
result = (function() {
|
637
|
+
var fst, i, ifn, prop, ref, snd, _i, _len, _ref2;
|
638
|
+
if (ifn = _this.base.unfoldSoak(o)) {
|
639
|
+
Array.prototype.push.apply(ifn.body.properties, _this.properties);
|
640
|
+
return ifn;
|
641
|
+
}
|
642
|
+
_ref2 = _this.properties;
|
643
|
+
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
644
|
+
prop = _ref2[i];
|
645
|
+
if (!prop.soak) continue;
|
646
|
+
prop.soak = false;
|
647
|
+
fst = new Value(_this.base, _this.properties.slice(0, i));
|
648
|
+
snd = new Value(_this.base, _this.properties.slice(i));
|
649
|
+
if (fst.isComplex()) {
|
650
|
+
ref = new Literal(o.scope.freeVariable('ref'));
|
651
|
+
fst = new Parens(new Assign(ref, fst));
|
652
|
+
snd.base = ref;
|
653
|
+
}
|
654
|
+
return new If(new Existence(fst), snd, {
|
655
|
+
soak: true
|
656
|
+
});
|
657
|
+
}
|
658
|
+
return null;
|
659
|
+
})();
|
660
|
+
return this.unfoldedSoak = result || false;
|
661
|
+
};
|
662
|
+
|
663
|
+
return Value;
|
664
|
+
|
665
|
+
})(Base);
|
666
|
+
|
667
|
+
exports.Comment = Comment = (function(_super) {
|
668
|
+
|
669
|
+
__extends(Comment, _super);
|
670
|
+
|
671
|
+
Comment.name = 'Comment';
|
672
|
+
|
673
|
+
function Comment(comment) {
|
674
|
+
this.comment = comment;
|
675
|
+
}
|
676
|
+
|
677
|
+
Comment.prototype.isStatement = YES;
|
678
|
+
|
679
|
+
Comment.prototype.makeReturn = THIS;
|
680
|
+
|
681
|
+
Comment.prototype.compileNode = function(o, level) {
|
682
|
+
var code;
|
683
|
+
code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/\n");
|
684
|
+
if ((level || o.level) === LEVEL_TOP) code = o.indent + code;
|
685
|
+
return code;
|
686
|
+
};
|
687
|
+
|
688
|
+
return Comment;
|
689
|
+
|
690
|
+
})(Base);
|
691
|
+
|
692
|
+
exports.Call = Call = (function(_super) {
|
693
|
+
|
694
|
+
__extends(Call, _super);
|
695
|
+
|
696
|
+
Call.name = 'Call';
|
697
|
+
|
698
|
+
function Call(variable, args, soak) {
|
699
|
+
this.args = args != null ? args : [];
|
700
|
+
this.soak = soak;
|
701
|
+
this.isNew = false;
|
702
|
+
this.isSuper = variable === 'super';
|
703
|
+
this.variable = this.isSuper ? null : variable;
|
704
|
+
}
|
705
|
+
|
706
|
+
Call.prototype.children = ['variable', 'args'];
|
707
|
+
|
708
|
+
Call.prototype.newInstance = function() {
|
709
|
+
var base, _ref2;
|
710
|
+
base = ((_ref2 = this.variable) != null ? _ref2.base : void 0) || this.variable;
|
711
|
+
if (base instanceof Call && !base.isNew) {
|
712
|
+
base.newInstance();
|
713
|
+
} else {
|
714
|
+
this.isNew = true;
|
715
|
+
}
|
716
|
+
return this;
|
717
|
+
};
|
718
|
+
|
719
|
+
Call.prototype.superReference = function(o) {
|
720
|
+
var accesses, method, name;
|
721
|
+
method = o.scope.method;
|
722
|
+
if (!method) throw SyntaxError('cannot call super outside of a function.');
|
723
|
+
name = method.name;
|
724
|
+
if (name == null) {
|
725
|
+
throw SyntaxError('cannot call super on an anonymous function.');
|
726
|
+
}
|
727
|
+
if (method.klass) {
|
728
|
+
accesses = [new Access(new Literal('__super__'))];
|
729
|
+
if (method["static"]) {
|
730
|
+
accesses.push(new Access(new Literal('constructor')));
|
731
|
+
}
|
732
|
+
accesses.push(new Access(new Literal(name)));
|
733
|
+
return (new Value(new Literal(method.klass), accesses)).compile(o);
|
734
|
+
} else {
|
735
|
+
return "" + name + ".__super__.constructor";
|
736
|
+
}
|
737
|
+
};
|
738
|
+
|
739
|
+
Call.prototype.unfoldSoak = function(o) {
|
740
|
+
var call, ifn, left, list, rite, _i, _len, _ref2, _ref3;
|
741
|
+
if (this.soak) {
|
742
|
+
if (this.variable) {
|
743
|
+
if (ifn = unfoldSoak(o, this, 'variable')) return ifn;
|
744
|
+
_ref2 = new Value(this.variable).cacheReference(o), left = _ref2[0], rite = _ref2[1];
|
745
|
+
} else {
|
746
|
+
left = new Literal(this.superReference(o));
|
747
|
+
rite = new Value(left);
|
748
|
+
}
|
749
|
+
rite = new Call(rite, this.args);
|
750
|
+
rite.isNew = this.isNew;
|
751
|
+
left = new Literal("typeof " + (left.compile(o)) + " === \"function\"");
|
752
|
+
return new If(left, new Value(rite), {
|
753
|
+
soak: true
|
754
|
+
});
|
755
|
+
}
|
756
|
+
call = this;
|
757
|
+
list = [];
|
758
|
+
while (true) {
|
759
|
+
if (call.variable instanceof Call) {
|
760
|
+
list.push(call);
|
761
|
+
call = call.variable;
|
762
|
+
continue;
|
763
|
+
}
|
764
|
+
if (!(call.variable instanceof Value)) break;
|
765
|
+
list.push(call);
|
766
|
+
if (!((call = call.variable.base) instanceof Call)) break;
|
767
|
+
}
|
768
|
+
_ref3 = list.reverse();
|
769
|
+
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
770
|
+
call = _ref3[_i];
|
771
|
+
if (ifn) {
|
772
|
+
if (call.variable instanceof Call) {
|
773
|
+
call.variable = ifn;
|
774
|
+
} else {
|
775
|
+
call.variable.base = ifn;
|
776
|
+
}
|
777
|
+
}
|
778
|
+
ifn = unfoldSoak(o, call, 'variable');
|
779
|
+
}
|
780
|
+
return ifn;
|
781
|
+
};
|
782
|
+
|
783
|
+
Call.prototype.filterImplicitObjects = function(list) {
|
784
|
+
var node, nodes, obj, prop, properties, _i, _j, _len, _len1, _ref2;
|
785
|
+
nodes = [];
|
786
|
+
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
787
|
+
node = list[_i];
|
788
|
+
if (!((typeof node.isObject === "function" ? node.isObject() : void 0) && node.base.generated)) {
|
789
|
+
nodes.push(node);
|
790
|
+
continue;
|
791
|
+
}
|
792
|
+
obj = null;
|
793
|
+
_ref2 = node.base.properties;
|
794
|
+
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
795
|
+
prop = _ref2[_j];
|
796
|
+
if (prop instanceof Assign || prop instanceof Comment) {
|
797
|
+
if (!obj) nodes.push(obj = new Obj(properties = [], true));
|
798
|
+
properties.push(prop);
|
799
|
+
} else {
|
800
|
+
nodes.push(prop);
|
801
|
+
obj = null;
|
802
|
+
}
|
803
|
+
}
|
804
|
+
}
|
805
|
+
return nodes;
|
806
|
+
};
|
807
|
+
|
808
|
+
Call.prototype.compileNode = function(o) {
|
809
|
+
var arg, args, code, _ref2;
|
810
|
+
if ((_ref2 = this.variable) != null) _ref2.front = this.front;
|
811
|
+
if (code = Splat.compileSplattedArray(o, this.args, true)) {
|
812
|
+
return this.compileSplat(o, code);
|
813
|
+
}
|
814
|
+
args = this.filterImplicitObjects(this.args);
|
815
|
+
args = ((function() {
|
816
|
+
var _i, _len, _results;
|
817
|
+
_results = [];
|
818
|
+
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
819
|
+
arg = args[_i];
|
820
|
+
_results.push(arg.compile(o, LEVEL_LIST));
|
821
|
+
}
|
822
|
+
return _results;
|
823
|
+
})()).join(', ');
|
824
|
+
if (this.isSuper) {
|
825
|
+
return this.superReference(o) + (".call(this" + (args && ', ' + args) + ")");
|
826
|
+
} else {
|
827
|
+
return (this.isNew ? 'new ' : '') + this.variable.compile(o, LEVEL_ACCESS) + ("(" + args + ")");
|
828
|
+
}
|
829
|
+
};
|
830
|
+
|
831
|
+
Call.prototype.compileSuper = function(args, o) {
|
832
|
+
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")";
|
833
|
+
};
|
834
|
+
|
835
|
+
Call.prototype.compileSplat = function(o, splatArgs) {
|
836
|
+
var base, fun, idt, name, ref;
|
837
|
+
if (this.isSuper) {
|
838
|
+
return "" + (this.superReference(o)) + ".apply(this, " + splatArgs + ")";
|
839
|
+
}
|
840
|
+
if (this.isNew) {
|
841
|
+
idt = this.tab + TAB;
|
842
|
+
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args), t = typeof result;\n" + idt + "return t == \"object\" || t == \"function\" ? result || child : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function(){})";
|
843
|
+
}
|
844
|
+
base = new Value(this.variable);
|
845
|
+
if ((name = base.properties.pop()) && base.isComplex()) {
|
846
|
+
ref = o.scope.freeVariable('ref');
|
847
|
+
fun = "(" + ref + " = " + (base.compile(o, LEVEL_LIST)) + ")" + (name.compile(o));
|
848
|
+
} else {
|
849
|
+
fun = base.compile(o, LEVEL_ACCESS);
|
850
|
+
if (SIMPLENUM.test(fun)) fun = "(" + fun + ")";
|
851
|
+
if (name) {
|
852
|
+
ref = fun;
|
853
|
+
fun += name.compile(o);
|
854
|
+
} else {
|
855
|
+
ref = 'null';
|
856
|
+
}
|
857
|
+
}
|
858
|
+
return "" + fun + ".apply(" + ref + ", " + splatArgs + ")";
|
859
|
+
};
|
860
|
+
|
861
|
+
return Call;
|
862
|
+
|
863
|
+
})(Base);
|
864
|
+
|
865
|
+
exports.Extends = Extends = (function(_super) {
|
866
|
+
|
867
|
+
__extends(Extends, _super);
|
868
|
+
|
869
|
+
Extends.name = 'Extends';
|
870
|
+
|
871
|
+
function Extends(child, parent) {
|
872
|
+
this.child = child;
|
873
|
+
this.parent = parent;
|
874
|
+
}
|
875
|
+
|
876
|
+
Extends.prototype.children = ['child', 'parent'];
|
877
|
+
|
878
|
+
Extends.prototype.compile = function(o) {
|
879
|
+
return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compile(o);
|
880
|
+
};
|
881
|
+
|
882
|
+
return Extends;
|
883
|
+
|
884
|
+
})(Base);
|
885
|
+
|
886
|
+
exports.Access = Access = (function(_super) {
|
887
|
+
|
888
|
+
__extends(Access, _super);
|
889
|
+
|
890
|
+
Access.name = 'Access';
|
891
|
+
|
892
|
+
function Access(name, tag) {
|
893
|
+
this.name = name;
|
894
|
+
this.name.asKey = true;
|
895
|
+
this.soak = tag === 'soak';
|
896
|
+
}
|
897
|
+
|
898
|
+
Access.prototype.children = ['name'];
|
899
|
+
|
900
|
+
Access.prototype.compile = function(o) {
|
901
|
+
var name;
|
902
|
+
name = this.name.compile(o);
|
903
|
+
if (IDENTIFIER.test(name)) {
|
904
|
+
return "." + name;
|
905
|
+
} else {
|
906
|
+
return "[" + name + "]";
|
907
|
+
}
|
908
|
+
};
|
909
|
+
|
910
|
+
Access.prototype.isComplex = NO;
|
911
|
+
|
912
|
+
return Access;
|
913
|
+
|
914
|
+
})(Base);
|
915
|
+
|
916
|
+
exports.Index = Index = (function(_super) {
|
917
|
+
|
918
|
+
__extends(Index, _super);
|
919
|
+
|
920
|
+
Index.name = 'Index';
|
921
|
+
|
922
|
+
function Index(index) {
|
923
|
+
this.index = index;
|
924
|
+
}
|
925
|
+
|
926
|
+
Index.prototype.children = ['index'];
|
927
|
+
|
928
|
+
Index.prototype.compile = function(o) {
|
929
|
+
return "[" + (this.index.compile(o, LEVEL_PAREN)) + "]";
|
930
|
+
};
|
931
|
+
|
932
|
+
Index.prototype.isComplex = function() {
|
933
|
+
return this.index.isComplex();
|
934
|
+
};
|
935
|
+
|
936
|
+
return Index;
|
937
|
+
|
938
|
+
})(Base);
|
939
|
+
|
940
|
+
exports.Range = Range = (function(_super) {
|
941
|
+
|
942
|
+
__extends(Range, _super);
|
943
|
+
|
944
|
+
Range.name = 'Range';
|
945
|
+
|
946
|
+
Range.prototype.children = ['from', 'to'];
|
947
|
+
|
948
|
+
function Range(from, to, tag) {
|
949
|
+
this.from = from;
|
950
|
+
this.to = to;
|
951
|
+
this.exclusive = tag === 'exclusive';
|
952
|
+
this.equals = this.exclusive ? '' : '=';
|
953
|
+
}
|
954
|
+
|
955
|
+
Range.prototype.compileVariables = function(o) {
|
956
|
+
var step, _ref2, _ref3, _ref4, _ref5;
|
957
|
+
o = merge(o, {
|
958
|
+
top: true
|
959
|
+
});
|
960
|
+
_ref2 = this.from.cache(o, LEVEL_LIST), this.fromC = _ref2[0], this.fromVar = _ref2[1];
|
961
|
+
_ref3 = this.to.cache(o, LEVEL_LIST), this.toC = _ref3[0], this.toVar = _ref3[1];
|
962
|
+
if (step = del(o, 'step')) {
|
963
|
+
_ref4 = step.cache(o, LEVEL_LIST), this.step = _ref4[0], this.stepVar = _ref4[1];
|
964
|
+
}
|
965
|
+
_ref5 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref5[0], this.toNum = _ref5[1];
|
966
|
+
if (this.stepVar) return this.stepNum = this.stepVar.match(SIMPLENUM);
|
967
|
+
};
|
968
|
+
|
969
|
+
Range.prototype.compileNode = function(o) {
|
970
|
+
var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref2, _ref3;
|
971
|
+
if (!this.fromVar) this.compileVariables(o);
|
972
|
+
if (!o.index) return this.compileArray(o);
|
973
|
+
known = this.fromNum && this.toNum;
|
974
|
+
idx = del(o, 'index');
|
975
|
+
idxName = del(o, 'name');
|
976
|
+
namedIndex = idxName && idxName !== idx;
|
977
|
+
varPart = "" + idx + " = " + this.fromC;
|
978
|
+
if (this.toC !== this.toVar) varPart += ", " + this.toC;
|
979
|
+
if (this.step !== this.stepVar) varPart += ", " + this.step;
|
980
|
+
_ref2 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref2[0], gt = _ref2[1];
|
981
|
+
condPart = this.stepNum ? +this.stepNum > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref3 = [+this.fromNum, +this.toNum], from = _ref3[0], to = _ref3[1], _ref3), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);
|
982
|
+
stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? "" + idx + "++" : "" + idx + "--" : namedIndex ? "" + cond + " ? ++" + idx + " : --" + idx : "" + cond + " ? " + idx + "++ : " + idx + "--";
|
983
|
+
if (namedIndex) varPart = "" + idxName + " = " + varPart;
|
984
|
+
if (namedIndex) stepPart = "" + idxName + " = " + stepPart;
|
985
|
+
return "" + varPart + "; " + condPart + "; " + stepPart;
|
986
|
+
};
|
987
|
+
|
988
|
+
Range.prototype.compileArray = function(o) {
|
989
|
+
var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref2, _ref3, _results;
|
990
|
+
if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
|
991
|
+
range = (function() {
|
992
|
+
_results = [];
|
993
|
+
for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i++ : _i--){ _results.push(_i); }
|
994
|
+
return _results;
|
995
|
+
}).apply(this);
|
996
|
+
if (this.exclusive) range.pop();
|
997
|
+
return "[" + (range.join(', ')) + "]";
|
998
|
+
}
|
999
|
+
idt = this.tab + TAB;
|
1000
|
+
i = o.scope.freeVariable('i');
|
1001
|
+
result = o.scope.freeVariable('results');
|
1002
|
+
pre = "\n" + idt + result + " = [];";
|
1003
|
+
if (this.fromNum && this.toNum) {
|
1004
|
+
o.index = i;
|
1005
|
+
body = this.compileNode(o);
|
1006
|
+
} else {
|
1007
|
+
vars = ("" + i + " = " + this.fromC) + (this.toC !== this.toVar ? ", " + this.toC : '');
|
1008
|
+
cond = "" + this.fromVar + " <= " + this.toVar;
|
1009
|
+
body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--";
|
1010
|
+
}
|
1011
|
+
post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;
|
1012
|
+
hasArgs = function(node) {
|
1013
|
+
return node != null ? node.contains(function(n) {
|
1014
|
+
return n instanceof Literal && n.value === 'arguments' && !n.asKey;
|
1015
|
+
}) : void 0;
|
1016
|
+
};
|
1017
|
+
if (hasArgs(this.from) || hasArgs(this.to)) args = ', arguments';
|
1018
|
+
return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this" + (args != null ? args : '') + ")";
|
1019
|
+
};
|
1020
|
+
|
1021
|
+
return Range;
|
1022
|
+
|
1023
|
+
})(Base);
|
1024
|
+
|
1025
|
+
exports.Slice = Slice = (function(_super) {
|
1026
|
+
|
1027
|
+
__extends(Slice, _super);
|
1028
|
+
|
1029
|
+
Slice.name = 'Slice';
|
1030
|
+
|
1031
|
+
Slice.prototype.children = ['range'];
|
1032
|
+
|
1033
|
+
function Slice(range) {
|
1034
|
+
this.range = range;
|
1035
|
+
Slice.__super__.constructor.call(this);
|
1036
|
+
}
|
1037
|
+
|
1038
|
+
Slice.prototype.compileNode = function(o) {
|
1039
|
+
var compiled, from, fromStr, to, toStr, _ref2;
|
1040
|
+
_ref2 = this.range, to = _ref2.to, from = _ref2.from;
|
1041
|
+
fromStr = from && from.compile(o, LEVEL_PAREN) || '0';
|
1042
|
+
compiled = to && to.compile(o, LEVEL_PAREN);
|
1043
|
+
if (to && !(!this.range.exclusive && +compiled === -1)) {
|
1044
|
+
toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? "" + (+compiled + 1) : (compiled = to.compile(o, LEVEL_ACCESS), "" + compiled + " + 1 || 9e9"));
|
1045
|
+
}
|
1046
|
+
return ".slice(" + fromStr + (toStr || '') + ")";
|
1047
|
+
};
|
1048
|
+
|
1049
|
+
return Slice;
|
1050
|
+
|
1051
|
+
})(Base);
|
1052
|
+
|
1053
|
+
exports.Obj = Obj = (function(_super) {
|
1054
|
+
|
1055
|
+
__extends(Obj, _super);
|
1056
|
+
|
1057
|
+
Obj.name = 'Obj';
|
1058
|
+
|
1059
|
+
function Obj(props, generated) {
|
1060
|
+
this.generated = generated != null ? generated : false;
|
1061
|
+
this.objects = this.properties = props || [];
|
1062
|
+
}
|
1063
|
+
|
1064
|
+
Obj.prototype.children = ['properties'];
|
1065
|
+
|
1066
|
+
Obj.prototype.compileNode = function(o) {
|
1067
|
+
var i, idt, indent, join, lastNoncom, node, obj, prop, propName, propNames, props, _i, _j, _len, _len1, _ref2;
|
1068
|
+
props = this.properties;
|
1069
|
+
propNames = [];
|
1070
|
+
_ref2 = this.properties;
|
1071
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1072
|
+
prop = _ref2[_i];
|
1073
|
+
if (prop.isComplex()) prop = prop.variable;
|
1074
|
+
if (prop != null) {
|
1075
|
+
propName = prop.unwrapAll().value.toString();
|
1076
|
+
if (__indexOf.call(propNames, propName) >= 0) {
|
1077
|
+
throw SyntaxError("multiple object literal properties named \"" + propName + "\"");
|
1078
|
+
}
|
1079
|
+
propNames.push(propName);
|
1080
|
+
}
|
1081
|
+
}
|
1082
|
+
if (!props.length) return (this.front ? '({})' : '{}');
|
1083
|
+
if (this.generated) {
|
1084
|
+
for (_j = 0, _len1 = props.length; _j < _len1; _j++) {
|
1085
|
+
node = props[_j];
|
1086
|
+
if (node instanceof Value) {
|
1087
|
+
throw new Error('cannot have an implicit value in an implicit object');
|
1088
|
+
}
|
1089
|
+
}
|
1090
|
+
}
|
1091
|
+
idt = o.indent += TAB;
|
1092
|
+
lastNoncom = this.lastNonComment(this.properties);
|
1093
|
+
props = (function() {
|
1094
|
+
var _k, _len2, _results;
|
1095
|
+
_results = [];
|
1096
|
+
for (i = _k = 0, _len2 = props.length; _k < _len2; i = ++_k) {
|
1097
|
+
prop = props[i];
|
1098
|
+
join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
|
1099
|
+
indent = prop instanceof Comment ? '' : idt;
|
1100
|
+
if (prop instanceof Value && prop["this"]) {
|
1101
|
+
prop = new Assign(prop.properties[0].name, prop, 'object');
|
1102
|
+
}
|
1103
|
+
if (!(prop instanceof Comment)) {
|
1104
|
+
if (!(prop instanceof Assign)) prop = new Assign(prop, prop, 'object');
|
1105
|
+
(prop.variable.base || prop.variable).asKey = true;
|
1106
|
+
}
|
1107
|
+
_results.push(indent + prop.compile(o, LEVEL_TOP) + join);
|
1108
|
+
}
|
1109
|
+
return _results;
|
1110
|
+
})();
|
1111
|
+
props = props.join('');
|
1112
|
+
obj = "{" + (props && '\n' + props + '\n' + this.tab) + "}";
|
1113
|
+
if (this.front) {
|
1114
|
+
return "(" + obj + ")";
|
1115
|
+
} else {
|
1116
|
+
return obj;
|
1117
|
+
}
|
1118
|
+
};
|
1119
|
+
|
1120
|
+
Obj.prototype.assigns = function(name) {
|
1121
|
+
var prop, _i, _len, _ref2;
|
1122
|
+
_ref2 = this.properties;
|
1123
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1124
|
+
prop = _ref2[_i];
|
1125
|
+
if (prop.assigns(name)) return true;
|
1126
|
+
}
|
1127
|
+
return false;
|
1128
|
+
};
|
1129
|
+
|
1130
|
+
return Obj;
|
1131
|
+
|
1132
|
+
})(Base);
|
1133
|
+
|
1134
|
+
exports.Arr = Arr = (function(_super) {
|
1135
|
+
|
1136
|
+
__extends(Arr, _super);
|
1137
|
+
|
1138
|
+
Arr.name = 'Arr';
|
1139
|
+
|
1140
|
+
function Arr(objs) {
|
1141
|
+
this.objects = objs || [];
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
Arr.prototype.children = ['objects'];
|
1145
|
+
|
1146
|
+
Arr.prototype.filterImplicitObjects = Call.prototype.filterImplicitObjects;
|
1147
|
+
|
1148
|
+
Arr.prototype.compileNode = function(o) {
|
1149
|
+
var code, obj, objs;
|
1150
|
+
if (!this.objects.length) return '[]';
|
1151
|
+
o.indent += TAB;
|
1152
|
+
objs = this.filterImplicitObjects(this.objects);
|
1153
|
+
if (code = Splat.compileSplattedArray(o, objs)) return code;
|
1154
|
+
code = ((function() {
|
1155
|
+
var _i, _len, _results;
|
1156
|
+
_results = [];
|
1157
|
+
for (_i = 0, _len = objs.length; _i < _len; _i++) {
|
1158
|
+
obj = objs[_i];
|
1159
|
+
_results.push(obj.compile(o, LEVEL_LIST));
|
1160
|
+
}
|
1161
|
+
return _results;
|
1162
|
+
})()).join(', ');
|
1163
|
+
if (code.indexOf('\n') >= 0) {
|
1164
|
+
return "[\n" + o.indent + code + "\n" + this.tab + "]";
|
1165
|
+
} else {
|
1166
|
+
return "[" + code + "]";
|
1167
|
+
}
|
1168
|
+
};
|
1169
|
+
|
1170
|
+
Arr.prototype.assigns = function(name) {
|
1171
|
+
var obj, _i, _len, _ref2;
|
1172
|
+
_ref2 = this.objects;
|
1173
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1174
|
+
obj = _ref2[_i];
|
1175
|
+
if (obj.assigns(name)) return true;
|
1176
|
+
}
|
1177
|
+
return false;
|
1178
|
+
};
|
1179
|
+
|
1180
|
+
return Arr;
|
1181
|
+
|
1182
|
+
})(Base);
|
1183
|
+
|
1184
|
+
exports.Class = Class = (function(_super) {
|
1185
|
+
|
1186
|
+
__extends(Class, _super);
|
1187
|
+
|
1188
|
+
Class.name = 'Class';
|
1189
|
+
|
1190
|
+
function Class(variable, parent, body) {
|
1191
|
+
this.variable = variable;
|
1192
|
+
this.parent = parent;
|
1193
|
+
this.body = body != null ? body : new Block;
|
1194
|
+
this.boundFuncs = [];
|
1195
|
+
this.body.classBody = true;
|
1196
|
+
}
|
1197
|
+
|
1198
|
+
Class.prototype.children = ['variable', 'parent', 'body'];
|
1199
|
+
|
1200
|
+
Class.prototype.determineName = function() {
|
1201
|
+
var decl, tail;
|
1202
|
+
if (!this.variable) return null;
|
1203
|
+
decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;
|
1204
|
+
if (__indexOf.call(STRICT_PROSCRIBED, decl) >= 0) {
|
1205
|
+
throw SyntaxError("variable name may not be " + decl);
|
1206
|
+
}
|
1207
|
+
return decl && (decl = IDENTIFIER.test(decl) && decl);
|
1208
|
+
};
|
1209
|
+
|
1210
|
+
Class.prototype.setContext = function(name) {
|
1211
|
+
return this.body.traverseChildren(false, function(node) {
|
1212
|
+
if (node.classBody) return false;
|
1213
|
+
if (node instanceof Literal && node.value === 'this') {
|
1214
|
+
return node.value = name;
|
1215
|
+
} else if (node instanceof Code) {
|
1216
|
+
node.klass = name;
|
1217
|
+
if (node.bound) return node.context = name;
|
1218
|
+
}
|
1219
|
+
});
|
1220
|
+
};
|
1221
|
+
|
1222
|
+
Class.prototype.addBoundFunctions = function(o) {
|
1223
|
+
var bvar, lhs, _i, _len, _ref2, _results;
|
1224
|
+
if (this.boundFuncs.length) {
|
1225
|
+
_ref2 = this.boundFuncs;
|
1226
|
+
_results = [];
|
1227
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1228
|
+
bvar = _ref2[_i];
|
1229
|
+
lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o);
|
1230
|
+
_results.push(this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)")));
|
1231
|
+
}
|
1232
|
+
return _results;
|
1233
|
+
}
|
1234
|
+
};
|
1235
|
+
|
1236
|
+
Class.prototype.addProperties = function(node, name, o) {
|
1237
|
+
var assign, base, exprs, func, props;
|
1238
|
+
props = node.base.properties.slice(0);
|
1239
|
+
exprs = (function() {
|
1240
|
+
var _results;
|
1241
|
+
_results = [];
|
1242
|
+
while (assign = props.shift()) {
|
1243
|
+
if (assign instanceof Assign) {
|
1244
|
+
base = assign.variable.base;
|
1245
|
+
delete assign.context;
|
1246
|
+
func = assign.value;
|
1247
|
+
if (base.value === 'constructor') {
|
1248
|
+
if (this.ctor) {
|
1249
|
+
throw new Error('cannot define more than one constructor in a class');
|
1250
|
+
}
|
1251
|
+
if (func.bound) {
|
1252
|
+
throw new Error('cannot define a constructor as a bound function');
|
1253
|
+
}
|
1254
|
+
if (func instanceof Code) {
|
1255
|
+
assign = this.ctor = func;
|
1256
|
+
} else {
|
1257
|
+
this.externalCtor = o.scope.freeVariable('class');
|
1258
|
+
assign = new Assign(new Literal(this.externalCtor), func);
|
1259
|
+
}
|
1260
|
+
} else {
|
1261
|
+
if (assign.variable["this"]) {
|
1262
|
+
func["static"] = true;
|
1263
|
+
if (func.bound) func.context = name;
|
1264
|
+
} else {
|
1265
|
+
assign.variable = new Value(new Literal(name), [new Access(new Literal('prototype')), new Access(base)]);
|
1266
|
+
if (func instanceof Code && func.bound) {
|
1267
|
+
this.boundFuncs.push(base);
|
1268
|
+
func.bound = false;
|
1269
|
+
}
|
1270
|
+
}
|
1271
|
+
}
|
1272
|
+
}
|
1273
|
+
_results.push(assign);
|
1274
|
+
}
|
1275
|
+
return _results;
|
1276
|
+
}).call(this);
|
1277
|
+
return compact(exprs);
|
1278
|
+
};
|
1279
|
+
|
1280
|
+
Class.prototype.walkBody = function(name, o) {
|
1281
|
+
var _this = this;
|
1282
|
+
return this.traverseChildren(false, function(child) {
|
1283
|
+
var exps, i, node, _i, _len, _ref2;
|
1284
|
+
if (child instanceof Class) return false;
|
1285
|
+
if (child instanceof Block) {
|
1286
|
+
_ref2 = exps = child.expressions;
|
1287
|
+
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
1288
|
+
node = _ref2[i];
|
1289
|
+
if (node instanceof Value && node.isObject(true)) {
|
1290
|
+
exps[i] = _this.addProperties(node, name, o);
|
1291
|
+
}
|
1292
|
+
}
|
1293
|
+
return child.expressions = exps = flatten(exps);
|
1294
|
+
}
|
1295
|
+
});
|
1296
|
+
};
|
1297
|
+
|
1298
|
+
Class.prototype.hoistDirectivePrologue = function() {
|
1299
|
+
var expressions, index, node;
|
1300
|
+
index = 0;
|
1301
|
+
expressions = this.body.expressions;
|
1302
|
+
while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {
|
1303
|
+
++index;
|
1304
|
+
}
|
1305
|
+
return this.directives = expressions.splice(0, index);
|
1306
|
+
};
|
1307
|
+
|
1308
|
+
Class.prototype.ensureConstructor = function(name) {
|
1309
|
+
if (!this.ctor) {
|
1310
|
+
this.ctor = new Code;
|
1311
|
+
if (this.parent) {
|
1312
|
+
this.ctor.body.push(new Literal("" + name + ".__super__.constructor.apply(this, arguments)"));
|
1313
|
+
}
|
1314
|
+
if (this.externalCtor) {
|
1315
|
+
this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)"));
|
1316
|
+
}
|
1317
|
+
this.ctor.body.makeReturn();
|
1318
|
+
this.body.expressions.unshift(this.ctor);
|
1319
|
+
}
|
1320
|
+
this.ctor.ctor = this.ctor.name = name;
|
1321
|
+
this.ctor.klass = null;
|
1322
|
+
return this.ctor.noReturn = true;
|
1323
|
+
};
|
1324
|
+
|
1325
|
+
Class.prototype.compileNode = function(o) {
|
1326
|
+
var call, decl, klass, lname, name, params, _ref2;
|
1327
|
+
decl = this.determineName();
|
1328
|
+
name = decl || '_Class';
|
1329
|
+
if (name.reserved) name = "_" + name;
|
1330
|
+
lname = new Literal(name);
|
1331
|
+
this.hoistDirectivePrologue();
|
1332
|
+
this.setContext(name);
|
1333
|
+
this.walkBody(name, o);
|
1334
|
+
this.ensureConstructor(name);
|
1335
|
+
this.body.spaced = true;
|
1336
|
+
if (!(this.ctor instanceof Code)) this.body.expressions.unshift(this.ctor);
|
1337
|
+
if (decl) {
|
1338
|
+
this.body.expressions.unshift(new Assign(new Value(new Literal(name), [new Access(new Literal('name'))]), new Literal("'" + name + "'")));
|
1339
|
+
}
|
1340
|
+
this.body.expressions.push(lname);
|
1341
|
+
(_ref2 = this.body.expressions).unshift.apply(_ref2, this.directives);
|
1342
|
+
this.addBoundFunctions(o);
|
1343
|
+
call = Closure.wrap(this.body);
|
1344
|
+
if (this.parent) {
|
1345
|
+
this.superClass = new Literal(o.scope.freeVariable('super', false));
|
1346
|
+
this.body.expressions.unshift(new Extends(lname, this.superClass));
|
1347
|
+
call.args.push(this.parent);
|
1348
|
+
params = call.variable.params || call.variable.base.params;
|
1349
|
+
params.push(new Param(this.superClass));
|
1350
|
+
}
|
1351
|
+
klass = new Parens(call, true);
|
1352
|
+
if (this.variable) klass = new Assign(this.variable, klass);
|
1353
|
+
return klass.compile(o);
|
1354
|
+
};
|
1355
|
+
|
1356
|
+
return Class;
|
1357
|
+
|
1358
|
+
})(Base);
|
1359
|
+
|
1360
|
+
exports.Assign = Assign = (function(_super) {
|
1361
|
+
|
1362
|
+
__extends(Assign, _super);
|
1363
|
+
|
1364
|
+
Assign.name = 'Assign';
|
1365
|
+
|
1366
|
+
function Assign(variable, value, context, options) {
|
1367
|
+
var forbidden, name, _ref2;
|
1368
|
+
this.variable = variable;
|
1369
|
+
this.value = value;
|
1370
|
+
this.context = context;
|
1371
|
+
this.param = options && options.param;
|
1372
|
+
this.subpattern = options && options.subpattern;
|
1373
|
+
forbidden = (_ref2 = (name = this.variable.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0);
|
1374
|
+
if (forbidden && this.context !== 'object') {
|
1375
|
+
throw SyntaxError("variable name may not be \"" + name + "\"");
|
1376
|
+
}
|
1377
|
+
}
|
1378
|
+
|
1379
|
+
Assign.prototype.children = ['variable', 'value'];
|
1380
|
+
|
1381
|
+
Assign.prototype.isStatement = function(o) {
|
1382
|
+
return (o != null ? o.level : void 0) === LEVEL_TOP && (this.context != null) && __indexOf.call(this.context, "?") >= 0;
|
1383
|
+
};
|
1384
|
+
|
1385
|
+
Assign.prototype.assigns = function(name) {
|
1386
|
+
return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);
|
1387
|
+
};
|
1388
|
+
|
1389
|
+
Assign.prototype.unfoldSoak = function(o) {
|
1390
|
+
return unfoldSoak(o, this, 'variable');
|
1391
|
+
};
|
1392
|
+
|
1393
|
+
Assign.prototype.compileNode = function(o) {
|
1394
|
+
var isValue, match, name, val, varBase, _ref2, _ref3, _ref4, _ref5;
|
1395
|
+
if (isValue = this.variable instanceof Value) {
|
1396
|
+
if (this.variable.isArray() || this.variable.isObject()) {
|
1397
|
+
return this.compilePatternMatch(o);
|
1398
|
+
}
|
1399
|
+
if (this.variable.isSplice()) return this.compileSplice(o);
|
1400
|
+
if ((_ref2 = this.context) === '||=' || _ref2 === '&&=' || _ref2 === '?=') {
|
1401
|
+
return this.compileConditional(o);
|
1402
|
+
}
|
1403
|
+
}
|
1404
|
+
name = this.variable.compile(o, LEVEL_LIST);
|
1405
|
+
if (!this.context) {
|
1406
|
+
if (!(varBase = this.variable.unwrapAll()).isAssignable()) {
|
1407
|
+
throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned.");
|
1408
|
+
}
|
1409
|
+
if (!(typeof varBase.hasProperties === "function" ? varBase.hasProperties() : void 0)) {
|
1410
|
+
if (this.param) {
|
1411
|
+
o.scope.add(name, 'var');
|
1412
|
+
} else {
|
1413
|
+
o.scope.find(name);
|
1414
|
+
}
|
1415
|
+
}
|
1416
|
+
}
|
1417
|
+
if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) {
|
1418
|
+
if (match[1]) this.value.klass = match[1];
|
1419
|
+
this.value.name = (_ref3 = (_ref4 = (_ref5 = match[2]) != null ? _ref5 : match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5];
|
1420
|
+
}
|
1421
|
+
val = this.value.compile(o, LEVEL_LIST);
|
1422
|
+
if (this.context === 'object') return "" + name + ": " + val;
|
1423
|
+
val = name + (" " + (this.context || '=') + " ") + val;
|
1424
|
+
if (o.level <= LEVEL_LIST) {
|
1425
|
+
return val;
|
1426
|
+
} else {
|
1427
|
+
return "(" + val + ")";
|
1428
|
+
}
|
1429
|
+
};
|
1430
|
+
|
1431
|
+
Assign.prototype.compilePatternMatch = function(o) {
|
1432
|
+
var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
1433
|
+
top = o.level === LEVEL_TOP;
|
1434
|
+
value = this.value;
|
1435
|
+
objects = this.variable.base.objects;
|
1436
|
+
if (!(olen = objects.length)) {
|
1437
|
+
code = value.compile(o);
|
1438
|
+
if (o.level >= LEVEL_OP) {
|
1439
|
+
return "(" + code + ")";
|
1440
|
+
} else {
|
1441
|
+
return code;
|
1442
|
+
}
|
1443
|
+
}
|
1444
|
+
isObject = this.variable.isObject();
|
1445
|
+
if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
|
1446
|
+
if (obj instanceof Assign) {
|
1447
|
+
_ref2 = obj, (_ref3 = _ref2.variable, idx = _ref3.base), obj = _ref2.value;
|
1448
|
+
} else {
|
1449
|
+
if (obj.base instanceof Parens) {
|
1450
|
+
_ref4 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref4[0], idx = _ref4[1];
|
1451
|
+
} else {
|
1452
|
+
idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);
|
1453
|
+
}
|
1454
|
+
}
|
1455
|
+
acc = IDENTIFIER.test(idx.unwrap().value || 0);
|
1456
|
+
value = new Value(value);
|
1457
|
+
value.properties.push(new (acc ? Access : Index)(idx));
|
1458
|
+
if (_ref5 = obj.unwrap().value, __indexOf.call(RESERVED, _ref5) >= 0) {
|
1459
|
+
throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (value.compile(o)));
|
1460
|
+
}
|
1461
|
+
return new Assign(obj, value, null, {
|
1462
|
+
param: this.param
|
1463
|
+
}).compile(o, LEVEL_TOP);
|
1464
|
+
}
|
1465
|
+
vvar = value.compile(o, LEVEL_LIST);
|
1466
|
+
assigns = [];
|
1467
|
+
splat = false;
|
1468
|
+
if (!IDENTIFIER.test(vvar) || this.variable.assigns(vvar)) {
|
1469
|
+
assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + vvar);
|
1470
|
+
vvar = ref;
|
1471
|
+
}
|
1472
|
+
for (i = _i = 0, _len = objects.length; _i < _len; i = ++_i) {
|
1473
|
+
obj = objects[i];
|
1474
|
+
idx = i;
|
1475
|
+
if (isObject) {
|
1476
|
+
if (obj instanceof Assign) {
|
1477
|
+
_ref6 = obj, (_ref7 = _ref6.variable, idx = _ref7.base), obj = _ref6.value;
|
1478
|
+
} else {
|
1479
|
+
if (obj.base instanceof Parens) {
|
1480
|
+
_ref8 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref8[0], idx = _ref8[1];
|
1481
|
+
} else {
|
1482
|
+
idx = obj["this"] ? obj.properties[0].name : obj;
|
1483
|
+
}
|
1484
|
+
}
|
1485
|
+
}
|
1486
|
+
if (!splat && obj instanceof Splat) {
|
1487
|
+
name = obj.name.unwrap().value;
|
1488
|
+
obj = obj.unwrap();
|
1489
|
+
val = "" + olen + " <= " + vvar + ".length ? " + (utility('slice')) + ".call(" + vvar + ", " + i;
|
1490
|
+
if (rest = olen - i - 1) {
|
1491
|
+
ivar = o.scope.freeVariable('i');
|
1492
|
+
val += ", " + ivar + " = " + vvar + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])";
|
1493
|
+
} else {
|
1494
|
+
val += ") : []";
|
1495
|
+
}
|
1496
|
+
val = new Literal(val);
|
1497
|
+
splat = "" + ivar + "++";
|
1498
|
+
} else {
|
1499
|
+
name = obj.unwrap().value;
|
1500
|
+
if (obj instanceof Splat) {
|
1501
|
+
obj = obj.name.compile(o);
|
1502
|
+
throw new SyntaxError("multiple splats are disallowed in an assignment: " + obj + "...");
|
1503
|
+
}
|
1504
|
+
if (typeof idx === 'number') {
|
1505
|
+
idx = new Literal(splat || idx);
|
1506
|
+
acc = false;
|
1507
|
+
} else {
|
1508
|
+
acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);
|
1509
|
+
}
|
1510
|
+
val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]);
|
1511
|
+
}
|
1512
|
+
if ((name != null) && __indexOf.call(RESERVED, name) >= 0) {
|
1513
|
+
throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (val.compile(o)));
|
1514
|
+
}
|
1515
|
+
assigns.push(new Assign(obj, val, null, {
|
1516
|
+
param: this.param,
|
1517
|
+
subpattern: true
|
1518
|
+
}).compile(o, LEVEL_LIST));
|
1519
|
+
}
|
1520
|
+
if (!(top || this.subpattern)) assigns.push(vvar);
|
1521
|
+
code = assigns.join(', ');
|
1522
|
+
if (o.level < LEVEL_LIST) {
|
1523
|
+
return code;
|
1524
|
+
} else {
|
1525
|
+
return "(" + code + ")";
|
1526
|
+
}
|
1527
|
+
};
|
1528
|
+
|
1529
|
+
Assign.prototype.compileConditional = function(o) {
|
1530
|
+
var left, right, _ref2;
|
1531
|
+
_ref2 = this.variable.cacheReference(o), left = _ref2[0], right = _ref2[1];
|
1532
|
+
if (left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) {
|
1533
|
+
throw new Error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been defined.");
|
1534
|
+
}
|
1535
|
+
if (__indexOf.call(this.context, "?") >= 0) o.isExistentialEquals = true;
|
1536
|
+
return new Op(this.context.slice(0, -1), left, new Assign(right, this.value, '=')).compile(o);
|
1537
|
+
};
|
1538
|
+
|
1539
|
+
Assign.prototype.compileSplice = function(o) {
|
1540
|
+
var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4;
|
1541
|
+
_ref2 = this.variable.properties.pop().range, from = _ref2.from, to = _ref2.to, exclusive = _ref2.exclusive;
|
1542
|
+
name = this.variable.compile(o);
|
1543
|
+
_ref3 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref3[0], fromRef = _ref3[1];
|
1544
|
+
if (to) {
|
1545
|
+
if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) {
|
1546
|
+
to = +to.compile(o) - +fromRef;
|
1547
|
+
if (!exclusive) to += 1;
|
1548
|
+
} else {
|
1549
|
+
to = to.compile(o, LEVEL_ACCESS) + ' - ' + fromRef;
|
1550
|
+
if (!exclusive) to += ' + 1';
|
1551
|
+
}
|
1552
|
+
} else {
|
1553
|
+
to = "9e9";
|
1554
|
+
}
|
1555
|
+
_ref4 = this.value.cache(o, LEVEL_LIST), valDef = _ref4[0], valRef = _ref4[1];
|
1556
|
+
code = "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + valDef + ")), " + valRef;
|
1557
|
+
if (o.level > LEVEL_TOP) {
|
1558
|
+
return "(" + code + ")";
|
1559
|
+
} else {
|
1560
|
+
return code;
|
1561
|
+
}
|
1562
|
+
};
|
1563
|
+
|
1564
|
+
return Assign;
|
1565
|
+
|
1566
|
+
})(Base);
|
1567
|
+
|
1568
|
+
exports.Code = Code = (function(_super) {
|
1569
|
+
|
1570
|
+
__extends(Code, _super);
|
1571
|
+
|
1572
|
+
Code.name = 'Code';
|
1573
|
+
|
1574
|
+
function Code(params, body, tag) {
|
1575
|
+
this.params = params || [];
|
1576
|
+
this.body = body || new Block;
|
1577
|
+
this.bound = tag === 'boundfunc';
|
1578
|
+
if (this.bound) this.context = '_this';
|
1579
|
+
}
|
1580
|
+
|
1581
|
+
Code.prototype.children = ['params', 'body'];
|
1582
|
+
|
1583
|
+
Code.prototype.isStatement = function() {
|
1584
|
+
return !!this.ctor;
|
1585
|
+
};
|
1586
|
+
|
1587
|
+
Code.prototype.jumps = NO;
|
1588
|
+
|
1589
|
+
Code.prototype.compileNode = function(o) {
|
1590
|
+
var code, exprs, i, idt, lit, name, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
1591
|
+
o.scope = new Scope(o.scope, this.body, this);
|
1592
|
+
o.scope.shared = del(o, 'sharedScope');
|
1593
|
+
o.indent += TAB;
|
1594
|
+
delete o.bare;
|
1595
|
+
delete o.isExistentialEquals;
|
1596
|
+
params = [];
|
1597
|
+
exprs = [];
|
1598
|
+
_ref2 = this.paramNames();
|
1599
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1600
|
+
name = _ref2[_i];
|
1601
|
+
if (!o.scope.check(name)) o.scope.parameter(name);
|
1602
|
+
}
|
1603
|
+
_ref3 = this.params;
|
1604
|
+
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
|
1605
|
+
param = _ref3[_j];
|
1606
|
+
if (!param.splat) continue;
|
1607
|
+
_ref4 = this.params;
|
1608
|
+
for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
|
1609
|
+
p = _ref4[_k];
|
1610
|
+
if (p.name.value) o.scope.add(p.name.value, 'var', true);
|
1611
|
+
}
|
1612
|
+
splats = new Assign(new Value(new Arr((function() {
|
1613
|
+
var _l, _len3, _ref5, _results;
|
1614
|
+
_ref5 = this.params;
|
1615
|
+
_results = [];
|
1616
|
+
for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
|
1617
|
+
p = _ref5[_l];
|
1618
|
+
_results.push(p.asReference(o));
|
1619
|
+
}
|
1620
|
+
return _results;
|
1621
|
+
}).call(this))), new Value(new Literal('arguments')));
|
1622
|
+
break;
|
1623
|
+
}
|
1624
|
+
_ref5 = this.params;
|
1625
|
+
for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
|
1626
|
+
param = _ref5[_l];
|
1627
|
+
if (param.isComplex()) {
|
1628
|
+
val = ref = param.asReference(o);
|
1629
|
+
if (param.value) val = new Op('?', ref, param.value);
|
1630
|
+
exprs.push(new Assign(new Value(param.name), val, '=', {
|
1631
|
+
param: true
|
1632
|
+
}));
|
1633
|
+
} else {
|
1634
|
+
ref = param;
|
1635
|
+
if (param.value) {
|
1636
|
+
lit = new Literal(ref.name.value + ' == null');
|
1637
|
+
val = new Assign(new Value(param.name), param.value, '=');
|
1638
|
+
exprs.push(new If(lit, val));
|
1639
|
+
}
|
1640
|
+
}
|
1641
|
+
if (!splats) params.push(ref);
|
1642
|
+
}
|
1643
|
+
wasEmpty = this.body.isEmpty();
|
1644
|
+
if (splats) exprs.unshift(splats);
|
1645
|
+
if (exprs.length) {
|
1646
|
+
(_ref6 = this.body.expressions).unshift.apply(_ref6, exprs);
|
1647
|
+
}
|
1648
|
+
for (i = _m = 0, _len4 = params.length; _m < _len4; i = ++_m) {
|
1649
|
+
p = params[i];
|
1650
|
+
o.scope.parameter(params[i] = p.compile(o));
|
1651
|
+
}
|
1652
|
+
uniqs = [];
|
1653
|
+
_ref7 = this.paramNames();
|
1654
|
+
for (_n = 0, _len5 = _ref7.length; _n < _len5; _n++) {
|
1655
|
+
name = _ref7[_n];
|
1656
|
+
if (__indexOf.call(uniqs, name) >= 0) {
|
1657
|
+
throw SyntaxError("multiple parameters named '" + name + "'");
|
1658
|
+
}
|
1659
|
+
uniqs.push(name);
|
1660
|
+
}
|
1661
|
+
if (!(wasEmpty || this.noReturn)) this.body.makeReturn();
|
1662
|
+
if (this.bound) {
|
1663
|
+
if ((_ref8 = o.scope.parent.method) != null ? _ref8.bound : void 0) {
|
1664
|
+
this.bound = this.context = o.scope.parent.method.context;
|
1665
|
+
} else if (!this["static"]) {
|
1666
|
+
o.scope.parent.assign('_this', 'this');
|
1667
|
+
}
|
1668
|
+
}
|
1669
|
+
idt = o.indent;
|
1670
|
+
code = 'function';
|
1671
|
+
if (this.ctor) code += ' ' + this.name;
|
1672
|
+
code += '(' + params.join(', ') + ') {';
|
1673
|
+
if (!this.body.isEmpty()) {
|
1674
|
+
code += "\n" + (this.body.compileWithDeclarations(o)) + "\n" + this.tab;
|
1675
|
+
}
|
1676
|
+
code += '}';
|
1677
|
+
if (this.ctor) return this.tab + code;
|
1678
|
+
if (this.front || (o.level >= LEVEL_ACCESS)) {
|
1679
|
+
return "(" + code + ")";
|
1680
|
+
} else {
|
1681
|
+
return code;
|
1682
|
+
}
|
1683
|
+
};
|
1684
|
+
|
1685
|
+
Code.prototype.paramNames = function() {
|
1686
|
+
var names, param, _i, _len, _ref2;
|
1687
|
+
names = [];
|
1688
|
+
_ref2 = this.params;
|
1689
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1690
|
+
param = _ref2[_i];
|
1691
|
+
names.push.apply(names, param.names());
|
1692
|
+
}
|
1693
|
+
return names;
|
1694
|
+
};
|
1695
|
+
|
1696
|
+
Code.prototype.traverseChildren = function(crossScope, func) {
|
1697
|
+
if (crossScope) {
|
1698
|
+
return Code.__super__.traverseChildren.call(this, crossScope, func);
|
1699
|
+
}
|
1700
|
+
};
|
1701
|
+
|
1702
|
+
return Code;
|
1703
|
+
|
1704
|
+
})(Base);
|
1705
|
+
|
1706
|
+
exports.Param = Param = (function(_super) {
|
1707
|
+
|
1708
|
+
__extends(Param, _super);
|
1709
|
+
|
1710
|
+
Param.name = 'Param';
|
1711
|
+
|
1712
|
+
function Param(name, value, splat) {
|
1713
|
+
var _ref2;
|
1714
|
+
this.name = name;
|
1715
|
+
this.value = value;
|
1716
|
+
this.splat = splat;
|
1717
|
+
if (_ref2 = (name = this.name.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0) {
|
1718
|
+
throw SyntaxError("parameter name \"" + name + "\" is not allowed");
|
1719
|
+
}
|
1720
|
+
}
|
1721
|
+
|
1722
|
+
Param.prototype.children = ['name', 'value'];
|
1723
|
+
|
1724
|
+
Param.prototype.compile = function(o) {
|
1725
|
+
return this.name.compile(o, LEVEL_LIST);
|
1726
|
+
};
|
1727
|
+
|
1728
|
+
Param.prototype.asReference = function(o) {
|
1729
|
+
var node;
|
1730
|
+
if (this.reference) return this.reference;
|
1731
|
+
node = this.name;
|
1732
|
+
if (node["this"]) {
|
1733
|
+
node = node.properties[0].name;
|
1734
|
+
if (node.value.reserved) {
|
1735
|
+
node = new Literal(o.scope.freeVariable(node.value));
|
1736
|
+
}
|
1737
|
+
} else if (node.isComplex()) {
|
1738
|
+
node = new Literal(o.scope.freeVariable('arg'));
|
1739
|
+
}
|
1740
|
+
node = new Value(node);
|
1741
|
+
if (this.splat) node = new Splat(node);
|
1742
|
+
return this.reference = node;
|
1743
|
+
};
|
1744
|
+
|
1745
|
+
Param.prototype.isComplex = function() {
|
1746
|
+
return this.name.isComplex();
|
1747
|
+
};
|
1748
|
+
|
1749
|
+
Param.prototype.names = function(name) {
|
1750
|
+
var atParam, names, obj, _i, _len, _ref2;
|
1751
|
+
if (name == null) name = this.name;
|
1752
|
+
atParam = function(obj) {
|
1753
|
+
var value;
|
1754
|
+
value = obj.properties[0].name.value;
|
1755
|
+
if (value.reserved) {
|
1756
|
+
return [];
|
1757
|
+
} else {
|
1758
|
+
return [value];
|
1759
|
+
}
|
1760
|
+
};
|
1761
|
+
if (name instanceof Literal) return [name.value];
|
1762
|
+
if (name instanceof Value) return atParam(name);
|
1763
|
+
names = [];
|
1764
|
+
_ref2 = name.objects;
|
1765
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1766
|
+
obj = _ref2[_i];
|
1767
|
+
if (obj instanceof Assign) {
|
1768
|
+
names.push(obj.variable.base.value);
|
1769
|
+
} else if (obj.isArray() || obj.isObject()) {
|
1770
|
+
names.push.apply(names, this.names(obj.base));
|
1771
|
+
} else if (obj["this"]) {
|
1772
|
+
names.push.apply(names, atParam(obj));
|
1773
|
+
} else {
|
1774
|
+
names.push(obj.base.value);
|
1775
|
+
}
|
1776
|
+
}
|
1777
|
+
return names;
|
1778
|
+
};
|
1779
|
+
|
1780
|
+
return Param;
|
1781
|
+
|
1782
|
+
})(Base);
|
1783
|
+
|
1784
|
+
exports.Splat = Splat = (function(_super) {
|
1785
|
+
|
1786
|
+
__extends(Splat, _super);
|
1787
|
+
|
1788
|
+
Splat.name = 'Splat';
|
1789
|
+
|
1790
|
+
Splat.prototype.children = ['name'];
|
1791
|
+
|
1792
|
+
Splat.prototype.isAssignable = YES;
|
1793
|
+
|
1794
|
+
function Splat(name) {
|
1795
|
+
this.name = name.compile ? name : new Literal(name);
|
1796
|
+
}
|
1797
|
+
|
1798
|
+
Splat.prototype.assigns = function(name) {
|
1799
|
+
return this.name.assigns(name);
|
1800
|
+
};
|
1801
|
+
|
1802
|
+
Splat.prototype.compile = function(o) {
|
1803
|
+
if (this.index != null) {
|
1804
|
+
return this.compileParam(o);
|
1805
|
+
} else {
|
1806
|
+
return this.name.compile(o);
|
1807
|
+
}
|
1808
|
+
};
|
1809
|
+
|
1810
|
+
Splat.prototype.unwrap = function() {
|
1811
|
+
return this.name;
|
1812
|
+
};
|
1813
|
+
|
1814
|
+
Splat.compileSplattedArray = function(o, list, apply) {
|
1815
|
+
var args, base, code, i, index, node, _i, _len;
|
1816
|
+
index = -1;
|
1817
|
+
while ((node = list[++index]) && !(node instanceof Splat)) {
|
1818
|
+
continue;
|
1819
|
+
}
|
1820
|
+
if (index >= list.length) return '';
|
1821
|
+
if (list.length === 1) {
|
1822
|
+
code = list[0].compile(o, LEVEL_LIST);
|
1823
|
+
if (apply) return code;
|
1824
|
+
return "" + (utility('slice')) + ".call(" + code + ")";
|
1825
|
+
}
|
1826
|
+
args = list.slice(index);
|
1827
|
+
for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {
|
1828
|
+
node = args[i];
|
1829
|
+
code = node.compile(o, LEVEL_LIST);
|
1830
|
+
args[i] = node instanceof Splat ? "" + (utility('slice')) + ".call(" + code + ")" : "[" + code + "]";
|
1831
|
+
}
|
1832
|
+
if (index === 0) {
|
1833
|
+
return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")");
|
1834
|
+
}
|
1835
|
+
base = (function() {
|
1836
|
+
var _j, _len1, _ref2, _results;
|
1837
|
+
_ref2 = list.slice(0, index);
|
1838
|
+
_results = [];
|
1839
|
+
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
1840
|
+
node = _ref2[_j];
|
1841
|
+
_results.push(node.compile(o, LEVEL_LIST));
|
1842
|
+
}
|
1843
|
+
return _results;
|
1844
|
+
})();
|
1845
|
+
return "[" + (base.join(', ')) + "].concat(" + (args.join(', ')) + ")";
|
1846
|
+
};
|
1847
|
+
|
1848
|
+
return Splat;
|
1849
|
+
|
1850
|
+
})(Base);
|
1851
|
+
|
1852
|
+
exports.While = While = (function(_super) {
|
1853
|
+
|
1854
|
+
__extends(While, _super);
|
1855
|
+
|
1856
|
+
While.name = 'While';
|
1857
|
+
|
1858
|
+
function While(condition, options) {
|
1859
|
+
this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
|
1860
|
+
this.guard = options != null ? options.guard : void 0;
|
1861
|
+
}
|
1862
|
+
|
1863
|
+
While.prototype.children = ['condition', 'guard', 'body'];
|
1864
|
+
|
1865
|
+
While.prototype.isStatement = YES;
|
1866
|
+
|
1867
|
+
While.prototype.makeReturn = function(res) {
|
1868
|
+
if (res) {
|
1869
|
+
return While.__super__.makeReturn.apply(this, arguments);
|
1870
|
+
} else {
|
1871
|
+
this.returns = !this.jumps({
|
1872
|
+
loop: true
|
1873
|
+
});
|
1874
|
+
return this;
|
1875
|
+
}
|
1876
|
+
};
|
1877
|
+
|
1878
|
+
While.prototype.addBody = function(body) {
|
1879
|
+
this.body = body;
|
1880
|
+
return this;
|
1881
|
+
};
|
1882
|
+
|
1883
|
+
While.prototype.jumps = function() {
|
1884
|
+
var expressions, node, _i, _len;
|
1885
|
+
expressions = this.body.expressions;
|
1886
|
+
if (!expressions.length) return false;
|
1887
|
+
for (_i = 0, _len = expressions.length; _i < _len; _i++) {
|
1888
|
+
node = expressions[_i];
|
1889
|
+
if (node.jumps({
|
1890
|
+
loop: true
|
1891
|
+
})) return node;
|
1892
|
+
}
|
1893
|
+
return false;
|
1894
|
+
};
|
1895
|
+
|
1896
|
+
While.prototype.compileNode = function(o) {
|
1897
|
+
var body, code, rvar, set;
|
1898
|
+
o.indent += TAB;
|
1899
|
+
set = '';
|
1900
|
+
body = this.body;
|
1901
|
+
if (body.isEmpty()) {
|
1902
|
+
body = '';
|
1903
|
+
} else {
|
1904
|
+
if (this.returns) {
|
1905
|
+
body.makeReturn(rvar = o.scope.freeVariable('results'));
|
1906
|
+
set = "" + this.tab + rvar + " = [];\n";
|
1907
|
+
}
|
1908
|
+
if (this.guard) {
|
1909
|
+
if (body.expressions.length > 1) {
|
1910
|
+
body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
|
1911
|
+
} else {
|
1912
|
+
if (this.guard) body = Block.wrap([new If(this.guard, body)]);
|
1913
|
+
}
|
1914
|
+
}
|
1915
|
+
body = "\n" + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab;
|
1916
|
+
}
|
1917
|
+
code = set + this.tab + ("while (" + (this.condition.compile(o, LEVEL_PAREN)) + ") {" + body + "}");
|
1918
|
+
if (this.returns) code += "\n" + this.tab + "return " + rvar + ";";
|
1919
|
+
return code;
|
1920
|
+
};
|
1921
|
+
|
1922
|
+
return While;
|
1923
|
+
|
1924
|
+
})(Base);
|
1925
|
+
|
1926
|
+
exports.Op = Op = (function(_super) {
|
1927
|
+
var CONVERSIONS, INVERSIONS;
|
1928
|
+
|
1929
|
+
__extends(Op, _super);
|
1930
|
+
|
1931
|
+
Op.name = 'Op';
|
1932
|
+
|
1933
|
+
function Op(op, first, second, flip) {
|
1934
|
+
if (op === 'in') return new In(first, second);
|
1935
|
+
if (op === 'do') return this.generateDo(first);
|
1936
|
+
if (op === 'new') {
|
1937
|
+
if (first instanceof Call && !first["do"] && !first.isNew) {
|
1938
|
+
return first.newInstance();
|
1939
|
+
}
|
1940
|
+
if (first instanceof Code && first.bound || first["do"]) {
|
1941
|
+
first = new Parens(first);
|
1942
|
+
}
|
1943
|
+
}
|
1944
|
+
this.operator = CONVERSIONS[op] || op;
|
1945
|
+
this.first = first;
|
1946
|
+
this.second = second;
|
1947
|
+
this.flip = !!flip;
|
1948
|
+
return this;
|
1949
|
+
}
|
1950
|
+
|
1951
|
+
CONVERSIONS = {
|
1952
|
+
'==': '===',
|
1953
|
+
'!=': '!==',
|
1954
|
+
'of': 'in'
|
1955
|
+
};
|
1956
|
+
|
1957
|
+
INVERSIONS = {
|
1958
|
+
'!==': '===',
|
1959
|
+
'===': '!=='
|
1960
|
+
};
|
1961
|
+
|
1962
|
+
Op.prototype.children = ['first', 'second'];
|
1963
|
+
|
1964
|
+
Op.prototype.isSimpleNumber = NO;
|
1965
|
+
|
1966
|
+
Op.prototype.isUnary = function() {
|
1967
|
+
return !this.second;
|
1968
|
+
};
|
1969
|
+
|
1970
|
+
Op.prototype.isComplex = function() {
|
1971
|
+
var _ref2;
|
1972
|
+
return !(this.isUnary() && ((_ref2 = this.operator) === '+' || _ref2 === '-')) || this.first.isComplex();
|
1973
|
+
};
|
1974
|
+
|
1975
|
+
Op.prototype.isChainable = function() {
|
1976
|
+
var _ref2;
|
1977
|
+
return (_ref2 = this.operator) === '<' || _ref2 === '>' || _ref2 === '>=' || _ref2 === '<=' || _ref2 === '===' || _ref2 === '!==';
|
1978
|
+
};
|
1979
|
+
|
1980
|
+
Op.prototype.invert = function() {
|
1981
|
+
var allInvertable, curr, fst, op, _ref2;
|
1982
|
+
if (this.isChainable() && this.first.isChainable()) {
|
1983
|
+
allInvertable = true;
|
1984
|
+
curr = this;
|
1985
|
+
while (curr && curr.operator) {
|
1986
|
+
allInvertable && (allInvertable = curr.operator in INVERSIONS);
|
1987
|
+
curr = curr.first;
|
1988
|
+
}
|
1989
|
+
if (!allInvertable) return new Parens(this).invert();
|
1990
|
+
curr = this;
|
1991
|
+
while (curr && curr.operator) {
|
1992
|
+
curr.invert = !curr.invert;
|
1993
|
+
curr.operator = INVERSIONS[curr.operator];
|
1994
|
+
curr = curr.first;
|
1995
|
+
}
|
1996
|
+
return this;
|
1997
|
+
} else if (op = INVERSIONS[this.operator]) {
|
1998
|
+
this.operator = op;
|
1999
|
+
if (this.first.unwrap() instanceof Op) this.first.invert();
|
2000
|
+
return this;
|
2001
|
+
} else if (this.second) {
|
2002
|
+
return new Parens(this).invert();
|
2003
|
+
} else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref2 = fst.operator) === '!' || _ref2 === 'in' || _ref2 === 'instanceof')) {
|
2004
|
+
return fst;
|
2005
|
+
} else {
|
2006
|
+
return new Op('!', this);
|
2007
|
+
}
|
2008
|
+
};
|
2009
|
+
|
2010
|
+
Op.prototype.unfoldSoak = function(o) {
|
2011
|
+
var _ref2;
|
2012
|
+
return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first');
|
2013
|
+
};
|
2014
|
+
|
2015
|
+
Op.prototype.generateDo = function(exp) {
|
2016
|
+
var call, func, param, passedParams, ref, _i, _len, _ref2;
|
2017
|
+
passedParams = [];
|
2018
|
+
func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;
|
2019
|
+
_ref2 = func.params || [];
|
2020
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2021
|
+
param = _ref2[_i];
|
2022
|
+
if (param.value) {
|
2023
|
+
passedParams.push(param.value);
|
2024
|
+
delete param.value;
|
2025
|
+
} else {
|
2026
|
+
passedParams.push(param);
|
2027
|
+
}
|
2028
|
+
}
|
2029
|
+
call = new Call(exp, passedParams);
|
2030
|
+
call["do"] = true;
|
2031
|
+
return call;
|
2032
|
+
};
|
2033
|
+
|
2034
|
+
Op.prototype.compileNode = function(o) {
|
2035
|
+
var code, isChain, _ref2, _ref3;
|
2036
|
+
isChain = this.isChainable() && this.first.isChainable();
|
2037
|
+
if (!isChain) this.first.front = this.front;
|
2038
|
+
if (this.operator === 'delete' && o.scope.check(this.first.unwrapAll().value)) {
|
2039
|
+
throw SyntaxError('delete operand may not be argument or var');
|
2040
|
+
}
|
2041
|
+
if (((_ref2 = this.operator) === '--' || _ref2 === '++') && (_ref3 = this.first.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0)) {
|
2042
|
+
throw SyntaxError('prefix increment/decrement may not have eval or arguments operand');
|
2043
|
+
}
|
2044
|
+
if (this.isUnary()) return this.compileUnary(o);
|
2045
|
+
if (isChain) return this.compileChain(o);
|
2046
|
+
if (this.operator === '?') return this.compileExistence(o);
|
2047
|
+
code = this.first.compile(o, LEVEL_OP) + ' ' + this.operator + ' ' + this.second.compile(o, LEVEL_OP);
|
2048
|
+
if (o.level <= LEVEL_OP) {
|
2049
|
+
return code;
|
2050
|
+
} else {
|
2051
|
+
return "(" + code + ")";
|
2052
|
+
}
|
2053
|
+
};
|
2054
|
+
|
2055
|
+
Op.prototype.compileChain = function(o) {
|
2056
|
+
var code, fst, shared, _ref2;
|
2057
|
+
_ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1];
|
2058
|
+
fst = this.first.compile(o, LEVEL_OP);
|
2059
|
+
code = "" + fst + " " + (this.invert ? '&&' : '||') + " " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
|
2060
|
+
return "(" + code + ")";
|
2061
|
+
};
|
2062
|
+
|
2063
|
+
Op.prototype.compileExistence = function(o) {
|
2064
|
+
var fst, ref;
|
2065
|
+
if (this.first.isComplex() && o.level > LEVEL_TOP) {
|
2066
|
+
ref = new Literal(o.scope.freeVariable('ref'));
|
2067
|
+
fst = new Parens(new Assign(ref, this.first));
|
2068
|
+
} else {
|
2069
|
+
fst = this.first;
|
2070
|
+
ref = fst;
|
2071
|
+
}
|
2072
|
+
return new If(new Existence(fst), ref, {
|
2073
|
+
type: 'if'
|
2074
|
+
}).addElse(this.second).compile(o);
|
2075
|
+
};
|
2076
|
+
|
2077
|
+
Op.prototype.compileUnary = function(o) {
|
2078
|
+
var op, parts, plusMinus;
|
2079
|
+
if (o.level >= LEVEL_ACCESS) return (new Parens(this)).compile(o);
|
2080
|
+
parts = [op = this.operator];
|
2081
|
+
plusMinus = op === '+' || op === '-';
|
2082
|
+
if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {
|
2083
|
+
parts.push(' ');
|
2084
|
+
}
|
2085
|
+
if ((plusMinus && this.first instanceof Op) || (op === 'new' && this.first.isStatement(o))) {
|
2086
|
+
this.first = new Parens(this.first);
|
2087
|
+
}
|
2088
|
+
parts.push(this.first.compile(o, LEVEL_OP));
|
2089
|
+
if (this.flip) parts.reverse();
|
2090
|
+
return parts.join('');
|
2091
|
+
};
|
2092
|
+
|
2093
|
+
Op.prototype.toString = function(idt) {
|
2094
|
+
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
|
2095
|
+
};
|
2096
|
+
|
2097
|
+
return Op;
|
2098
|
+
|
2099
|
+
})(Base);
|
2100
|
+
|
2101
|
+
exports.In = In = (function(_super) {
|
2102
|
+
|
2103
|
+
__extends(In, _super);
|
2104
|
+
|
2105
|
+
In.name = 'In';
|
2106
|
+
|
2107
|
+
function In(object, array) {
|
2108
|
+
this.object = object;
|
2109
|
+
this.array = array;
|
2110
|
+
}
|
2111
|
+
|
2112
|
+
In.prototype.children = ['object', 'array'];
|
2113
|
+
|
2114
|
+
In.prototype.invert = NEGATE;
|
2115
|
+
|
2116
|
+
In.prototype.compileNode = function(o) {
|
2117
|
+
var hasSplat, obj, _i, _len, _ref2;
|
2118
|
+
if (this.array instanceof Value && this.array.isArray()) {
|
2119
|
+
_ref2 = this.array.base.objects;
|
2120
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2121
|
+
obj = _ref2[_i];
|
2122
|
+
if (!(obj instanceof Splat)) continue;
|
2123
|
+
hasSplat = true;
|
2124
|
+
break;
|
2125
|
+
}
|
2126
|
+
if (!hasSplat) return this.compileOrTest(o);
|
2127
|
+
}
|
2128
|
+
return this.compileLoopTest(o);
|
2129
|
+
};
|
2130
|
+
|
2131
|
+
In.prototype.compileOrTest = function(o) {
|
2132
|
+
var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3;
|
2133
|
+
if (this.array.base.objects.length === 0) return "" + (!!this.negated);
|
2134
|
+
_ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1];
|
2135
|
+
_ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
|
2136
|
+
tests = (function() {
|
2137
|
+
var _i, _len, _ref4, _results;
|
2138
|
+
_ref4 = this.array.base.objects;
|
2139
|
+
_results = [];
|
2140
|
+
for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {
|
2141
|
+
item = _ref4[i];
|
2142
|
+
_results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_ACCESS));
|
2143
|
+
}
|
2144
|
+
return _results;
|
2145
|
+
}).call(this);
|
2146
|
+
tests = tests.join(cnj);
|
2147
|
+
if (o.level < LEVEL_OP) {
|
2148
|
+
return tests;
|
2149
|
+
} else {
|
2150
|
+
return "(" + tests + ")";
|
2151
|
+
}
|
2152
|
+
};
|
2153
|
+
|
2154
|
+
In.prototype.compileLoopTest = function(o) {
|
2155
|
+
var code, ref, sub, _ref2;
|
2156
|
+
_ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1];
|
2157
|
+
code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0');
|
2158
|
+
if (sub === ref) return code;
|
2159
|
+
code = sub + ', ' + code;
|
2160
|
+
if (o.level < LEVEL_LIST) {
|
2161
|
+
return code;
|
2162
|
+
} else {
|
2163
|
+
return "(" + code + ")";
|
2164
|
+
}
|
2165
|
+
};
|
2166
|
+
|
2167
|
+
In.prototype.toString = function(idt) {
|
2168
|
+
return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));
|
2169
|
+
};
|
2170
|
+
|
2171
|
+
return In;
|
2172
|
+
|
2173
|
+
})(Base);
|
2174
|
+
|
2175
|
+
exports.Try = Try = (function(_super) {
|
2176
|
+
|
2177
|
+
__extends(Try, _super);
|
2178
|
+
|
2179
|
+
Try.name = 'Try';
|
2180
|
+
|
2181
|
+
function Try(attempt, error, recovery, ensure) {
|
2182
|
+
this.attempt = attempt;
|
2183
|
+
this.error = error;
|
2184
|
+
this.recovery = recovery;
|
2185
|
+
this.ensure = ensure;
|
2186
|
+
}
|
2187
|
+
|
2188
|
+
Try.prototype.children = ['attempt', 'recovery', 'ensure'];
|
2189
|
+
|
2190
|
+
Try.prototype.isStatement = YES;
|
2191
|
+
|
2192
|
+
Try.prototype.jumps = function(o) {
|
2193
|
+
var _ref2;
|
2194
|
+
return this.attempt.jumps(o) || ((_ref2 = this.recovery) != null ? _ref2.jumps(o) : void 0);
|
2195
|
+
};
|
2196
|
+
|
2197
|
+
Try.prototype.makeReturn = function(res) {
|
2198
|
+
if (this.attempt) this.attempt = this.attempt.makeReturn(res);
|
2199
|
+
if (this.recovery) this.recovery = this.recovery.makeReturn(res);
|
2200
|
+
return this;
|
2201
|
+
};
|
2202
|
+
|
2203
|
+
Try.prototype.compileNode = function(o) {
|
2204
|
+
var catchPart, ensurePart, errorPart, tryPart;
|
2205
|
+
o.indent += TAB;
|
2206
|
+
errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
|
2207
|
+
tryPart = this.attempt.compile(o, LEVEL_TOP);
|
2208
|
+
catchPart = (function() {
|
2209
|
+
var _ref2;
|
2210
|
+
if (this.recovery) {
|
2211
|
+
if (_ref2 = this.error.value, __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0) {
|
2212
|
+
throw SyntaxError("catch variable may not be \"" + this.error.value + "\"");
|
2213
|
+
}
|
2214
|
+
if (!o.scope.check(this.error.value)) {
|
2215
|
+
o.scope.add(this.error.value, 'param');
|
2216
|
+
}
|
2217
|
+
return " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}";
|
2218
|
+
} else if (!(this.ensure || this.recovery)) {
|
2219
|
+
return ' catch (_error) {}';
|
2220
|
+
}
|
2221
|
+
}).call(this);
|
2222
|
+
ensurePart = this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : '';
|
2223
|
+
return "" + this.tab + "try {\n" + tryPart + "\n" + this.tab + "}" + (catchPart || '') + ensurePart;
|
2224
|
+
};
|
2225
|
+
|
2226
|
+
return Try;
|
2227
|
+
|
2228
|
+
})(Base);
|
2229
|
+
|
2230
|
+
exports.Throw = Throw = (function(_super) {
|
2231
|
+
|
2232
|
+
__extends(Throw, _super);
|
2233
|
+
|
2234
|
+
Throw.name = 'Throw';
|
2235
|
+
|
2236
|
+
function Throw(expression) {
|
2237
|
+
this.expression = expression;
|
2238
|
+
}
|
2239
|
+
|
2240
|
+
Throw.prototype.children = ['expression'];
|
2241
|
+
|
2242
|
+
Throw.prototype.isStatement = YES;
|
2243
|
+
|
2244
|
+
Throw.prototype.jumps = NO;
|
2245
|
+
|
2246
|
+
Throw.prototype.makeReturn = THIS;
|
2247
|
+
|
2248
|
+
Throw.prototype.compileNode = function(o) {
|
2249
|
+
return this.tab + ("throw " + (this.expression.compile(o)) + ";");
|
2250
|
+
};
|
2251
|
+
|
2252
|
+
return Throw;
|
2253
|
+
|
2254
|
+
})(Base);
|
2255
|
+
|
2256
|
+
exports.Existence = Existence = (function(_super) {
|
2257
|
+
|
2258
|
+
__extends(Existence, _super);
|
2259
|
+
|
2260
|
+
Existence.name = 'Existence';
|
2261
|
+
|
2262
|
+
function Existence(expression) {
|
2263
|
+
this.expression = expression;
|
2264
|
+
}
|
2265
|
+
|
2266
|
+
Existence.prototype.children = ['expression'];
|
2267
|
+
|
2268
|
+
Existence.prototype.invert = NEGATE;
|
2269
|
+
|
2270
|
+
Existence.prototype.compileNode = function(o) {
|
2271
|
+
var cmp, cnj, code, _ref2;
|
2272
|
+
this.expression.front = this.front;
|
2273
|
+
code = this.expression.compile(o, LEVEL_OP);
|
2274
|
+
if (IDENTIFIER.test(code) && !o.scope.check(code)) {
|
2275
|
+
_ref2 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref2[0], cnj = _ref2[1];
|
2276
|
+
code = "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null";
|
2277
|
+
} else {
|
2278
|
+
code = "" + code + " " + (this.negated ? '==' : '!=') + " null";
|
2279
|
+
}
|
2280
|
+
if (o.level <= LEVEL_COND) {
|
2281
|
+
return code;
|
2282
|
+
} else {
|
2283
|
+
return "(" + code + ")";
|
2284
|
+
}
|
2285
|
+
};
|
2286
|
+
|
2287
|
+
return Existence;
|
2288
|
+
|
2289
|
+
})(Base);
|
2290
|
+
|
2291
|
+
exports.Parens = Parens = (function(_super) {
|
2292
|
+
|
2293
|
+
__extends(Parens, _super);
|
2294
|
+
|
2295
|
+
Parens.name = 'Parens';
|
2296
|
+
|
2297
|
+
function Parens(body) {
|
2298
|
+
this.body = body;
|
2299
|
+
}
|
2300
|
+
|
2301
|
+
Parens.prototype.children = ['body'];
|
2302
|
+
|
2303
|
+
Parens.prototype.unwrap = function() {
|
2304
|
+
return this.body;
|
2305
|
+
};
|
2306
|
+
|
2307
|
+
Parens.prototype.isComplex = function() {
|
2308
|
+
return this.body.isComplex();
|
2309
|
+
};
|
2310
|
+
|
2311
|
+
Parens.prototype.compileNode = function(o) {
|
2312
|
+
var bare, code, expr;
|
2313
|
+
expr = this.body.unwrap();
|
2314
|
+
if (expr instanceof Value && expr.isAtomic()) {
|
2315
|
+
expr.front = this.front;
|
2316
|
+
return expr.compile(o);
|
2317
|
+
}
|
2318
|
+
code = expr.compile(o, LEVEL_PAREN);
|
2319
|
+
bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns));
|
2320
|
+
if (bare) {
|
2321
|
+
return code;
|
2322
|
+
} else {
|
2323
|
+
return "(" + code + ")";
|
2324
|
+
}
|
2325
|
+
};
|
2326
|
+
|
2327
|
+
return Parens;
|
2328
|
+
|
2329
|
+
})(Base);
|
2330
|
+
|
2331
|
+
exports.For = For = (function(_super) {
|
2332
|
+
|
2333
|
+
__extends(For, _super);
|
2334
|
+
|
2335
|
+
For.name = 'For';
|
2336
|
+
|
2337
|
+
function For(body, source) {
|
2338
|
+
var _ref2;
|
2339
|
+
this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
|
2340
|
+
this.body = Block.wrap([body]);
|
2341
|
+
this.own = !!source.own;
|
2342
|
+
this.object = !!source.object;
|
2343
|
+
if (this.object) {
|
2344
|
+
_ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1];
|
2345
|
+
}
|
2346
|
+
if (this.index instanceof Value) {
|
2347
|
+
throw SyntaxError('index cannot be a pattern matching expression');
|
2348
|
+
}
|
2349
|
+
this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
|
2350
|
+
this.pattern = this.name instanceof Value;
|
2351
|
+
if (this.range && this.index) {
|
2352
|
+
throw SyntaxError('indexes do not apply to range loops');
|
2353
|
+
}
|
2354
|
+
if (this.range && this.pattern) {
|
2355
|
+
throw SyntaxError('cannot pattern match over range loops');
|
2356
|
+
}
|
2357
|
+
this.returns = false;
|
2358
|
+
}
|
2359
|
+
|
2360
|
+
For.prototype.children = ['body', 'source', 'guard', 'step'];
|
2361
|
+
|
2362
|
+
For.prototype.compileNode = function(o) {
|
2363
|
+
var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2;
|
2364
|
+
body = Block.wrap([this.body]);
|
2365
|
+
lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0;
|
2366
|
+
if (lastJumps && lastJumps instanceof Return) this.returns = false;
|
2367
|
+
source = this.range ? this.source.base : this.source;
|
2368
|
+
scope = o.scope;
|
2369
|
+
name = this.name && this.name.compile(o, LEVEL_LIST);
|
2370
|
+
index = this.index && this.index.compile(o, LEVEL_LIST);
|
2371
|
+
if (name && !this.pattern) {
|
2372
|
+
scope.find(name, {
|
2373
|
+
immediate: true
|
2374
|
+
});
|
2375
|
+
}
|
2376
|
+
if (index) {
|
2377
|
+
scope.find(index, {
|
2378
|
+
immediate: true
|
2379
|
+
});
|
2380
|
+
}
|
2381
|
+
if (this.returns) rvar = scope.freeVariable('results');
|
2382
|
+
ivar = (this.object && index) || scope.freeVariable('i');
|
2383
|
+
kvar = (this.range && name) || index || ivar;
|
2384
|
+
kvarAssign = kvar !== ivar ? "" + kvar + " = " : "";
|
2385
|
+
if (this.step && !this.range) stepvar = scope.freeVariable("step");
|
2386
|
+
if (this.pattern) name = ivar;
|
2387
|
+
varPart = '';
|
2388
|
+
guardPart = '';
|
2389
|
+
defPart = '';
|
2390
|
+
idt1 = this.tab + TAB;
|
2391
|
+
if (this.range) {
|
2392
|
+
forPart = source.compile(merge(o, {
|
2393
|
+
index: ivar,
|
2394
|
+
name: name,
|
2395
|
+
step: this.step
|
2396
|
+
}));
|
2397
|
+
} else {
|
2398
|
+
svar = this.source.compile(o, LEVEL_LIST);
|
2399
|
+
if ((name || this.own) && !IDENTIFIER.test(svar)) {
|
2400
|
+
defPart = "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";
|
2401
|
+
svar = ref;
|
2402
|
+
}
|
2403
|
+
if (name && !this.pattern) {
|
2404
|
+
namePart = "" + name + " = " + svar + "[" + kvar + "]";
|
2405
|
+
}
|
2406
|
+
if (!this.object) {
|
2407
|
+
lvar = scope.freeVariable('len');
|
2408
|
+
forVarPart = "" + kvarAssign + ivar + " = 0, " + lvar + " = " + svar + ".length";
|
2409
|
+
if (this.step) {
|
2410
|
+
forVarPart += ", " + stepvar + " = " + (this.step.compile(o, LEVEL_OP));
|
2411
|
+
}
|
2412
|
+
stepPart = "" + kvarAssign + (this.step ? "" + ivar + " += " + stepvar : (kvar !== ivar ? "++" + ivar : "" + ivar + "++"));
|
2413
|
+
forPart = "" + forVarPart + "; " + ivar + " < " + lvar + "; " + stepPart;
|
2414
|
+
}
|
2415
|
+
}
|
2416
|
+
if (this.returns) {
|
2417
|
+
resultPart = "" + this.tab + rvar + " = [];\n";
|
2418
|
+
returnResult = "\n" + this.tab + "return " + rvar + ";";
|
2419
|
+
body.makeReturn(rvar);
|
2420
|
+
}
|
2421
|
+
if (this.guard) {
|
2422
|
+
if (body.expressions.length > 1) {
|
2423
|
+
body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
|
2424
|
+
} else {
|
2425
|
+
if (this.guard) body = Block.wrap([new If(this.guard, body)]);
|
2426
|
+
}
|
2427
|
+
}
|
2428
|
+
if (this.pattern) {
|
2429
|
+
body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + kvar + "]")));
|
2430
|
+
}
|
2431
|
+
defPart += this.pluckDirectCall(o, body);
|
2432
|
+
if (namePart) varPart = "\n" + idt1 + namePart + ";";
|
2433
|
+
if (this.object) {
|
2434
|
+
forPart = "" + kvar + " in " + svar;
|
2435
|
+
if (this.own) {
|
2436
|
+
guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + kvar + ")) continue;";
|
2437
|
+
}
|
2438
|
+
}
|
2439
|
+
body = body.compile(merge(o, {
|
2440
|
+
indent: idt1
|
2441
|
+
}), LEVEL_TOP);
|
2442
|
+
if (body) body = '\n' + body + '\n';
|
2443
|
+
return "" + defPart + (resultPart || '') + this.tab + "for (" + forPart + ") {" + guardPart + varPart + body + this.tab + "}" + (returnResult || '');
|
2444
|
+
};
|
2445
|
+
|
2446
|
+
For.prototype.pluckDirectCall = function(o, body) {
|
2447
|
+
var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
2448
|
+
defs = '';
|
2449
|
+
_ref2 = body.expressions;
|
2450
|
+
for (idx = _i = 0, _len = _ref2.length; _i < _len; idx = ++_i) {
|
2451
|
+
expr = _ref2[idx];
|
2452
|
+
expr = expr.unwrapAll();
|
2453
|
+
if (!(expr instanceof Call)) continue;
|
2454
|
+
val = expr.variable.unwrapAll();
|
2455
|
+
if (!((val instanceof Code) || (val instanceof Value && ((_ref3 = val.base) != null ? _ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref4 = (_ref5 = val.properties[0].name) != null ? _ref5.value : void 0) === 'call' || _ref4 === 'apply')))) {
|
2456
|
+
continue;
|
2457
|
+
}
|
2458
|
+
fn = ((_ref6 = val.base) != null ? _ref6.unwrapAll() : void 0) || val;
|
2459
|
+
ref = new Literal(o.scope.freeVariable('fn'));
|
2460
|
+
base = new Value(ref);
|
2461
|
+
if (val.base) _ref7 = [base, val], val.base = _ref7[0], base = _ref7[1];
|
2462
|
+
body.expressions[idx] = new Call(base, expr.args);
|
2463
|
+
defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n';
|
2464
|
+
}
|
2465
|
+
return defs;
|
2466
|
+
};
|
2467
|
+
|
2468
|
+
return For;
|
2469
|
+
|
2470
|
+
})(While);
|
2471
|
+
|
2472
|
+
exports.Switch = Switch = (function(_super) {
|
2473
|
+
|
2474
|
+
__extends(Switch, _super);
|
2475
|
+
|
2476
|
+
Switch.name = 'Switch';
|
2477
|
+
|
2478
|
+
function Switch(subject, cases, otherwise) {
|
2479
|
+
this.subject = subject;
|
2480
|
+
this.cases = cases;
|
2481
|
+
this.otherwise = otherwise;
|
2482
|
+
}
|
2483
|
+
|
2484
|
+
Switch.prototype.children = ['subject', 'cases', 'otherwise'];
|
2485
|
+
|
2486
|
+
Switch.prototype.isStatement = YES;
|
2487
|
+
|
2488
|
+
Switch.prototype.jumps = function(o) {
|
2489
|
+
var block, conds, _i, _len, _ref2, _ref3, _ref4;
|
2490
|
+
if (o == null) {
|
2491
|
+
o = {
|
2492
|
+
block: true
|
2493
|
+
};
|
2494
|
+
}
|
2495
|
+
_ref2 = this.cases;
|
2496
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2497
|
+
_ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1];
|
2498
|
+
if (block.jumps(o)) return block;
|
2499
|
+
}
|
2500
|
+
return (_ref4 = this.otherwise) != null ? _ref4.jumps(o) : void 0;
|
2501
|
+
};
|
2502
|
+
|
2503
|
+
Switch.prototype.makeReturn = function(res) {
|
2504
|
+
var pair, _i, _len, _ref2, _ref3;
|
2505
|
+
_ref2 = this.cases;
|
2506
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2507
|
+
pair = _ref2[_i];
|
2508
|
+
pair[1].makeReturn(res);
|
2509
|
+
}
|
2510
|
+
if (res) {
|
2511
|
+
this.otherwise || (this.otherwise = new Block([new Literal('void 0')]));
|
2512
|
+
}
|
2513
|
+
if ((_ref3 = this.otherwise) != null) _ref3.makeReturn(res);
|
2514
|
+
return this;
|
2515
|
+
};
|
2516
|
+
|
2517
|
+
Switch.prototype.compileNode = function(o) {
|
2518
|
+
var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _j, _len, _len1, _ref2, _ref3, _ref4, _ref5;
|
2519
|
+
idt1 = o.indent + TAB;
|
2520
|
+
idt2 = o.indent = idt1 + TAB;
|
2521
|
+
code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n");
|
2522
|
+
_ref3 = this.cases;
|
2523
|
+
for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
|
2524
|
+
_ref4 = _ref3[i], conditions = _ref4[0], block = _ref4[1];
|
2525
|
+
_ref5 = flatten([conditions]);
|
2526
|
+
for (_j = 0, _len1 = _ref5.length; _j < _len1; _j++) {
|
2527
|
+
cond = _ref5[_j];
|
2528
|
+
if (!this.subject) cond = cond.invert();
|
2529
|
+
code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
|
2530
|
+
}
|
2531
|
+
if (body = block.compile(o, LEVEL_TOP)) code += body + '\n';
|
2532
|
+
if (i === this.cases.length - 1 && !this.otherwise) break;
|
2533
|
+
expr = this.lastNonComment(block.expressions);
|
2534
|
+
if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) {
|
2535
|
+
continue;
|
2536
|
+
}
|
2537
|
+
code += idt2 + 'break;\n';
|
2538
|
+
}
|
2539
|
+
if (this.otherwise && this.otherwise.expressions.length) {
|
2540
|
+
code += idt1 + ("default:\n" + (this.otherwise.compile(o, LEVEL_TOP)) + "\n");
|
2541
|
+
}
|
2542
|
+
return code + this.tab + '}';
|
2543
|
+
};
|
2544
|
+
|
2545
|
+
return Switch;
|
2546
|
+
|
2547
|
+
})(Base);
|
2548
|
+
|
2549
|
+
exports.If = If = (function(_super) {
|
2550
|
+
|
2551
|
+
__extends(If, _super);
|
2552
|
+
|
2553
|
+
If.name = 'If';
|
2554
|
+
|
2555
|
+
function If(condition, body, options) {
|
2556
|
+
this.body = body;
|
2557
|
+
if (options == null) options = {};
|
2558
|
+
this.condition = options.type === 'unless' ? condition.invert() : condition;
|
2559
|
+
this.elseBody = null;
|
2560
|
+
this.isChain = false;
|
2561
|
+
this.soak = options.soak;
|
2562
|
+
}
|
2563
|
+
|
2564
|
+
If.prototype.children = ['condition', 'body', 'elseBody'];
|
2565
|
+
|
2566
|
+
If.prototype.bodyNode = function() {
|
2567
|
+
var _ref2;
|
2568
|
+
return (_ref2 = this.body) != null ? _ref2.unwrap() : void 0;
|
2569
|
+
};
|
2570
|
+
|
2571
|
+
If.prototype.elseBodyNode = function() {
|
2572
|
+
var _ref2;
|
2573
|
+
return (_ref2 = this.elseBody) != null ? _ref2.unwrap() : void 0;
|
2574
|
+
};
|
2575
|
+
|
2576
|
+
If.prototype.addElse = function(elseBody) {
|
2577
|
+
if (this.isChain) {
|
2578
|
+
this.elseBodyNode().addElse(elseBody);
|
2579
|
+
} else {
|
2580
|
+
this.isChain = elseBody instanceof If;
|
2581
|
+
this.elseBody = this.ensureBlock(elseBody);
|
2582
|
+
}
|
2583
|
+
return this;
|
2584
|
+
};
|
2585
|
+
|
2586
|
+
If.prototype.isStatement = function(o) {
|
2587
|
+
var _ref2;
|
2588
|
+
return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0);
|
2589
|
+
};
|
2590
|
+
|
2591
|
+
If.prototype.jumps = function(o) {
|
2592
|
+
var _ref2;
|
2593
|
+
return this.body.jumps(o) || ((_ref2 = this.elseBody) != null ? _ref2.jumps(o) : void 0);
|
2594
|
+
};
|
2595
|
+
|
2596
|
+
If.prototype.compileNode = function(o) {
|
2597
|
+
if (this.isStatement(o)) {
|
2598
|
+
return this.compileStatement(o);
|
2599
|
+
} else {
|
2600
|
+
return this.compileExpression(o);
|
2601
|
+
}
|
2602
|
+
};
|
2603
|
+
|
2604
|
+
If.prototype.makeReturn = function(res) {
|
2605
|
+
if (res) {
|
2606
|
+
this.elseBody || (this.elseBody = new Block([new Literal('void 0')]));
|
2607
|
+
}
|
2608
|
+
this.body && (this.body = new Block([this.body.makeReturn(res)]));
|
2609
|
+
this.elseBody && (this.elseBody = new Block([this.elseBody.makeReturn(res)]));
|
2610
|
+
return this;
|
2611
|
+
};
|
2612
|
+
|
2613
|
+
If.prototype.ensureBlock = function(node) {
|
2614
|
+
if (node instanceof Block) {
|
2615
|
+
return node;
|
2616
|
+
} else {
|
2617
|
+
return new Block([node]);
|
2618
|
+
}
|
2619
|
+
};
|
2620
|
+
|
2621
|
+
If.prototype.compileStatement = function(o) {
|
2622
|
+
var body, bodyc, child, cond, exeq, ifPart, _ref2;
|
2623
|
+
child = del(o, 'chainChild');
|
2624
|
+
exeq = del(o, 'isExistentialEquals');
|
2625
|
+
if (exeq) {
|
2626
|
+
return new If(this.condition.invert(), this.elseBodyNode(), {
|
2627
|
+
type: 'if'
|
2628
|
+
}).compile(o);
|
2629
|
+
}
|
2630
|
+
cond = this.condition.compile(o, LEVEL_PAREN);
|
2631
|
+
o.indent += TAB;
|
2632
|
+
body = this.ensureBlock(this.body);
|
2633
|
+
bodyc = body.compile(o);
|
2634
|
+
if (1 === ((_ref2 = body.expressions) != null ? _ref2.length : void 0) && !this.elseBody && !child && bodyc && cond && -1 === (bodyc.indexOf('\n')) && 80 > cond.length + bodyc.length) {
|
2635
|
+
return "" + this.tab + "if (" + cond + ") " + (bodyc.replace(/^\s+/, ''));
|
2636
|
+
}
|
2637
|
+
if (bodyc) bodyc = "\n" + bodyc + "\n" + this.tab;
|
2638
|
+
ifPart = "if (" + cond + ") {" + bodyc + "}";
|
2639
|
+
if (!child) ifPart = this.tab + ifPart;
|
2640
|
+
if (!this.elseBody) return ifPart;
|
2641
|
+
return ifPart + ' else ' + (this.isChain ? (o.indent = this.tab, o.chainChild = true, this.elseBody.unwrap().compile(o, LEVEL_TOP)) : "{\n" + (this.elseBody.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}");
|
2642
|
+
};
|
2643
|
+
|
2644
|
+
If.prototype.compileExpression = function(o) {
|
2645
|
+
var alt, body, code, cond;
|
2646
|
+
cond = this.condition.compile(o, LEVEL_COND);
|
2647
|
+
body = this.bodyNode().compile(o, LEVEL_LIST);
|
2648
|
+
alt = this.elseBodyNode() ? this.elseBodyNode().compile(o, LEVEL_LIST) : 'void 0';
|
2649
|
+
code = "" + cond + " ? " + body + " : " + alt;
|
2650
|
+
if (o.level >= LEVEL_COND) {
|
2651
|
+
return "(" + code + ")";
|
2652
|
+
} else {
|
2653
|
+
return code;
|
2654
|
+
}
|
2655
|
+
};
|
2656
|
+
|
2657
|
+
If.prototype.unfoldSoak = function() {
|
2658
|
+
return this.soak && this;
|
2659
|
+
};
|
2660
|
+
|
2661
|
+
return If;
|
2662
|
+
|
2663
|
+
})(Base);
|
2664
|
+
|
2665
|
+
Closure = {
|
2666
|
+
wrap: function(expressions, statement, noReturn) {
|
2667
|
+
var args, call, func, mentionsArgs, meth;
|
2668
|
+
if (expressions.jumps()) return expressions;
|
2669
|
+
func = new Code([], Block.wrap([expressions]));
|
2670
|
+
args = [];
|
2671
|
+
if ((mentionsArgs = expressions.contains(this.literalArgs)) || expressions.contains(this.literalThis)) {
|
2672
|
+
meth = new Literal(mentionsArgs ? 'apply' : 'call');
|
2673
|
+
args = [new Literal('this')];
|
2674
|
+
if (mentionsArgs) args.push(new Literal('arguments'));
|
2675
|
+
func = new Value(func, [new Access(meth)]);
|
2676
|
+
}
|
2677
|
+
func.noReturn = noReturn;
|
2678
|
+
call = new Call(func, args);
|
2679
|
+
if (statement) {
|
2680
|
+
return Block.wrap([call]);
|
2681
|
+
} else {
|
2682
|
+
return call;
|
2683
|
+
}
|
2684
|
+
},
|
2685
|
+
literalArgs: function(node) {
|
2686
|
+
return node instanceof Literal && node.value === 'arguments' && !node.asKey;
|
2687
|
+
},
|
2688
|
+
literalThis: function(node) {
|
2689
|
+
return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound);
|
2690
|
+
}
|
2691
|
+
};
|
2692
|
+
|
2693
|
+
unfoldSoak = function(o, parent, name) {
|
2694
|
+
var ifn;
|
2695
|
+
if (!(ifn = parent[name].unfoldSoak(o))) return;
|
2696
|
+
parent[name] = ifn.body;
|
2697
|
+
ifn.body = new Value(parent);
|
2698
|
+
return ifn;
|
2699
|
+
};
|
2700
|
+
|
2701
|
+
UTILITIES = {
|
2702
|
+
"extends": function() {
|
2703
|
+
return "function(child, parent) { for (var key in parent) { if (" + (utility('hasProp')) + ".call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }";
|
2704
|
+
},
|
2705
|
+
bind: function() {
|
2706
|
+
return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';
|
2707
|
+
},
|
2708
|
+
indexOf: function() {
|
2709
|
+
return "[].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";
|
2710
|
+
},
|
2711
|
+
hasProp: function() {
|
2712
|
+
return '{}.hasOwnProperty';
|
2713
|
+
},
|
2714
|
+
slice: function() {
|
2715
|
+
return '[].slice';
|
2716
|
+
}
|
2717
|
+
};
|
2718
|
+
|
2719
|
+
LEVEL_TOP = 1;
|
2720
|
+
|
2721
|
+
LEVEL_PAREN = 2;
|
2722
|
+
|
2723
|
+
LEVEL_LIST = 3;
|
2724
|
+
|
2725
|
+
LEVEL_COND = 4;
|
2726
|
+
|
2727
|
+
LEVEL_OP = 5;
|
2728
|
+
|
2729
|
+
LEVEL_ACCESS = 6;
|
2730
|
+
|
2731
|
+
TAB = ' ';
|
2732
|
+
|
2733
|
+
IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";
|
2734
|
+
|
2735
|
+
IDENTIFIER = RegExp("^" + IDENTIFIER_STR + "$");
|
2736
|
+
|
2737
|
+
SIMPLENUM = /^[+-]?\d+$/;
|
2738
|
+
|
2739
|
+
METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\]))|(" + IDENTIFIER_STR + ")$");
|
2740
|
+
|
2741
|
+
IS_STRING = /^['"]/;
|
2742
|
+
|
2743
|
+
utility = function(name) {
|
2744
|
+
var ref;
|
2745
|
+
ref = "__" + name;
|
2746
|
+
Scope.root.assign(ref, UTILITIES[name]());
|
2747
|
+
return ref;
|
2748
|
+
};
|
2749
|
+
|
2750
|
+
multident = function(code, tab) {
|
2751
|
+
code = code.replace(/\n/g, '$&' + tab);
|
2752
|
+
return code.replace(/\s+$/, '');
|
2753
|
+
};
|
2754
|
+
|
2755
|
+
|
2756
|
+
});
|