Comparing changes
Open a pull request
|
|
StanAngeloff |
FIXES #390: super() calls in constructor of classes that are defined …
…as object properties |
aba1984
|
|
|
StanAngeloff |
FIXES #397: Can't use @variable in switch in instance method
|
e17bb4f
|
|
|
jashkenas |
ahh, finally. switched up our Jison configuration to provide better s…
…yntax errors. Now you get the unexpected token, instead of the expected one. |
59de6b5
|
|||
|
|
jashkenas |
adding copying header to extras/coffee-script.js
|
1fbb6e8
|
|||
|
|
jashkenas |
making the lexer more sophisticated about incorrect outdents ... a li…
…ttle safer for everyone. |
61d9bd7
|
|||
|
|
jashkenas |
fixing block comments at the top of function blocks, and in other loc…
…ations ... Issue #379 |
b3d1c23
|
|||
|
|
jashkenas |
making block comments require their own lines for delimiters. Issue 379.
|
8321f6b
|
|||
|
|
jashkenas |
Fix for issue #414 -- apostrophes in heredocs.
|
e370561
|
|
|
jashkenas |
reworking parser for more permissive non-comma-separated array elements.
|
676e893
|
|
|
jashkenas |
allowing a regex literal to be the last token in a file ... Lexer bug.
|
88ea66b
|
|||
|
|
jashkenas |
allowing implicit returns to be pushed down into each branch of compu…
…tation, even when there's an explicit return nested more deeply. Issue #401 |
5612a59
|
|||
|
|
jashkenas |
adding another statement/expression/return test.
|
3bcca99
|
|||
|
|
jashkenas |
switching to 'Compiled' messages after the code has finished compilin…
…g on --watch ... |
4ecb1bb
|
|||
|
|
jashkenas |
slight refactor to IfNode::ensureExpressions
|
6f91331
|
|
|
jashkenas |
Ticket #423. When functions are generated within comprehensions ... t…
…he comprehensions should close over the element instead of sharing it. |
b0a45e5
|
|||
|
|
jashkenas |
fixing comprehensions to also close over the index variable, if used …
…in an inner function... |
d0948e5
|
|
|
jashkenas |
first draft at ticket #437 ... automatic quoting of reserved words an…
…d keywords. |
4b284f6
|
|||
|
|
jashkenas |
a bit more work on keywords-in-object-literals...
|
de768ae
|
|||
|
|
jashkenas |
adding the ability to have classes with functions pre-bound to the in…
…stance, using the fat arrow, and the constructor-function-definition pattern, avoiding prototypes. |
8d853a6
|
|||
|
|
jashkenas |
more streamlined code generation for instance-bound methods ... keep …
…the prototype method around, and just bind it in the constructor. |
06ca2ef
|
|
|
jashkenas |
changing a couple repetitions to DRY objects ... doesn't change the c…
…ompiled output. |
9aaf789
|
|
|
tim-smart |
Update package.json to allow for npm publishing and installation
|
2ed66f6
|
|||
|
|
jashkenas |
Merge branch 'npm' of git://github.com/Tim-Smart/coffee-script
|
7725fe3
|
|
|
jashkenas |
removing extensions from CoffeeScript
|
f7345ff
|
|||
|
|
jashkenas |
fixing issue #454 single-line function with single-line if/else
|
698784e
|
|||
|
|
jashkenas |
adding a test for #454
|
e020f58
|
- +38 −21 Cakefile
- +11 −1 Rakefile
- +5 −3 documentation/coffee/aliases.coffee
- +0 −5 documentation/coffee/binding.coffee
- +1 −1 documentation/coffee/cake_tasks.coffee
- +5 −5 documentation/coffee/conditionals.coffee
- +3 −3 documentation/coffee/expressions.coffee
- +2 −2 documentation/coffee/multiple_return_values.coffee
- +2 −2 documentation/coffee/object_comprehensions.coffee
- +1 −0 documentation/coffee/objects_reserved.coffee
- +3 −3 documentation/coffee/overview.coffee
- +3 −3 documentation/coffee/parallel_assignment.coffee
- +4 −4 documentation/coffee/range_comprehensions.coffee
- +5 −5 documentation/coffee/scope.coffee
- +2 −2 documentation/coffee/slices.coffee
- +1 −1 documentation/coffee/soaks.coffee
- +7 −7 documentation/coffee/splats.coffee
- +1 −1 documentation/coffee/strings.coffee
- +8 −8 documentation/coffee/switch.coffee
- +3 −3 documentation/coffee/try.coffee
- +2 −2 documentation/coffee/while.coffee
- +5 −5 documentation/docs/cake.html
- +6 −11 documentation/docs/coffee-script.html
- +42 −40 documentation/docs/command.html
- +79 −92 documentation/docs/grammar.html
- +5 −33 documentation/docs/helpers.html
- +168 −138 documentation/docs/lexer.html
- +545 −520 documentation/docs/nodes.html
- +23 −23 documentation/docs/optparse.html
- +10 −6 documentation/docs/repl.html
- +49 −63 documentation/docs/rewriter.html
- +16 −16 documentation/docs/scope.html
- +1 −1 documentation/docs/underscore.html
- +49 −26 documentation/index.html.erb
- +7 −4 documentation/js/aliases.js
- +0 −2 documentation/js/array_comprehensions.js
- +0 −13 documentation/js/binding.js
- +8 −6 documentation/js/cake_tasks.js
- +6 −6 documentation/js/conditionals.js
- +3 −3 documentation/js/expressions.js
- +0 −1 documentation/js/expressions_comprehension.js
- +7 −7 documentation/js/fat_arrow.js
- +3 −4 documentation/js/multiple_return_values.js
- +3 −3 documentation/js/object_comprehensions.js
- +5 −0 documentation/js/objects_reserved.js
- +5 −13 documentation/js/overview.js
- +6 −6 documentation/js/parallel_assignment.js
- +12 −11 documentation/js/range_comprehensions.js
- +8 −8 documentation/js/scope.js
- +3 −3 documentation/js/slices.js
- +1 −1 documentation/js/soaks.js
- +7 −8 documentation/js/splats.js
- +2 −2 documentation/js/strings.js
- +8 −8 documentation/js/switch.js
- +3 −3 documentation/js/try.js
- +1 −3 documentation/js/while.js
- +1 −1 examples/beautiful_code/regular_expression_matcher.coffee
- +1 −1 examples/code.coffee
- +1 −2 examples/potion.coffee
- +1 −1 examples/underscore.coffee
- +8 −1 extras/coffee-script.js
- +257 −276 index.html
- +10 −30 lib/cake.js
- +6 −40 lib/coffee-script.js
- +77 −108 lib/command.js
- +46 −218 lib/grammar.js
- +7 −76 lib/helpers.js
- +0 −1 lib/index.js
- +196 −290 lib/lexer.js
- +605 −833 lib/nodes.js
- +29 −52 lib/optparse.js
- +219 −221 lib/parser.js
- +16 −19 lib/repl.js
- +90 −141 lib/rewriter.js
- +19 −50 lib/scope.js
- +11 −1 package.json
- +5 −5 src/cake.coffee
- +4 −12 src/coffee-script.coffee
- +43 −41 src/command.coffee
- +31 −59 src/grammar.coffee
- +4 −35 src/helpers.coffee
- +155 −137 src/lexer.coffee
- +511 −501 src/nodes.coffee
- +23 −23 src/optparse.coffee
- +13 −9 src/repl.coffee
- +41 −58 src/rewriter.coffee
- +17 −17 src/scope.coffee
- +2 −2 test/test_arguments.coffee
- +3 −3 test/test_assignment.coffee
- +0 −22 test/test_bind.coffee
- +11 −1 test/test_blocks.coffee
- +7 −7 test/test_break.coffee
- +2 −2 test/test_chaining.coffee
- +51 −1 test/test_classes.coffee
- +37 −1 test/test_comments.coffee
- +1 −66 test/test_compilation.coffee
- +27 −12 test/test_comprehensions.coffee
- +5 −5 test/test_existence.coffee
- +1 −1 test/test_expressions.coffee
- +25 −2 test/test_functions.coffee
- +4 −0 test/test_heredocs.coffee
- +27 −9 test/test_if.coffee
- +38 −8 test/test_literals.coffee
- +1 −1 test/test_module.coffee
- +16 −0 test/test_operations.coffee
- +21 −1 test/test_returns.coffee
- +4 −4 test/test_splats.coffee
- +15 −3 test/test_switch.coffee
- +11 −0 test/test_while.coffee
- +0 −1,500 vendor/jison/lib/jison.js
- +0 −52 vendor/jison/lib/jison/bnf.js
- +0 −22 vendor/jison/lib/jison/jisonlex.js
- +0 −145 vendor/jison/lib/jison/json2jison.js
- +0 −248 vendor/jison/lib/jison/lexer.js
- +0 −442 vendor/jison/lib/jison/util/bnf-parser.js
- +0 −456 vendor/jison/lib/jison/util/lex-parser.js
- +0 −94 vendor/jison/lib/jison/util/set.js
- +0 −90 vendor/jison/lib/jison/util/typal.js
- +0 −14 vendor/jison/package.json
| @@ -3,27 +3,40 @@ fs: require 'fs' | ||
| CoffeeScript: require './lib/coffee-script' | ||
| {spawn, exec}: require('child_process') | ||
| +# ANSI Terminal Colors. | ||
| +red: '\033[0;31m' | ||
| +green: '\033[0;32m' | ||
| +reset: '\033[0m' | ||
| + | ||
| # Run a CoffeeScript through our node/coffee interpreter. | ||
| run: (args) -> | ||
| proc: spawn 'bin/coffee', args | ||
| proc.stderr.addListener 'data', (buffer) -> puts buffer.toString() | ||
| proc.addListener 'exit', (status) -> process.exit(1) if status != 0 | ||
| +# Log a message with a color. | ||
| +log: (message, color, explanation) -> | ||
| + puts "$color$message$reset ${explanation or ''}" | ||
| + | ||
| option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`' | ||
| task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) -> | ||
| base: options.prefix or '/usr/local' | ||
| lib: "$base/lib/coffee-script" | ||
| bin: "$base/bin" | ||
| + node: "~/.node_libraries/coffee-script" | ||
| + puts "Installing CoffeeScript to $lib" | ||
| + puts "Linking to $node" | ||
| + puts "Linking 'coffee' to $bin/coffee" | ||
| exec([ | ||
| "mkdir -p $lib $bin" | ||
| - "cp -rf bin lib LICENSE README package.json src vendor $lib" | ||
| - "ln -sf $lib/bin/coffee $base/bin/coffee" | ||
| - "ln -sf $lib/bin/cake $base/bin/cake" | ||
| + "cp -rf bin lib LICENSE README package.json src $lib" | ||
| + "ln -sf $lib/bin/coffee $bin/coffee" | ||
| + "ln -sf $lib/bin/cake $bin/cake" | ||
| "mkdir -p ~/.node_libraries" | ||
| - "ln -sf $lib/lib ~/.node_libraries/coffee-script" | ||
| + "ln -sf $lib/lib $node" | ||
| ].join(' && '), (err, stdout, stderr) -> | ||
| - if err then print stderr | ||
| + if err then print stderr else log 'done', green | ||
| ) | ||
| @@ -41,11 +54,11 @@ task 'build:full', 'rebuild the source twice, and run the tests', -> | ||
| task 'build:parser', 'rebuild the Jison parser (run build first)', -> | ||
| - require.paths.unshift 'vendor/jison/lib' | ||
| + require 'jison' | ||
| parser: require('./lib/grammar').parser | ||
| js: parser.generate() | ||
| - parser_path: 'lib/parser.js' | ||
| - fs.writeFile parser_path, js | ||
| + parserPath: 'lib/parser.js' | ||
| + fs.writeFile parserPath, js | ||
| task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', -> | ||
| @@ -73,22 +86,27 @@ task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', -> | ||
| throw err if err | ||
| +task 'loc', 'count the lines of source code in CoffeeScript', -> | ||
| + exec "cat src/*.coffee | grep -v '^\\( *#\\|\\s*$\\)' | wc -l | tr -s ' '", (err, stdout) -> | ||
| + print stdout | ||
| + | ||
| + | ||
| task 'test', 'run the CoffeeScript language test suite', -> | ||
| helpers.extend global, require 'assert' | ||
| - passed_tests: failed_tests: 0 | ||
| - start_time: new Date() | ||
| - original_ok: ok | ||
| + passedTests: failedTests: 0 | ||
| + startTime: new Date() | ||
| + originalOk: ok | ||
| helpers.extend global, { | ||
| - ok: (args...) -> passed_tests += 1; original_ok(args...) | ||
| + ok: (args...) -> passedTests += 1; originalOk(args...) | ||
| CoffeeScript: CoffeeScript | ||
| } | ||
| - red: '\033[0;31m' | ||
| - green: '\033[0;32m' | ||
| - reset: '\033[0m' | ||
| process.addListener 'exit', -> | ||
| - time: ((new Date() - start_time) / 1000).toFixed(2) | ||
| - message: "passed $passed_tests tests in $time seconds$reset" | ||
| - puts(if failed_tests then "${red}failed $failed_tests and $message" else "$green$message") | ||
| + time: ((new Date() - startTime) / 1000).toFixed(2) | ||
| + message: "passed $passedTests tests in $time seconds$reset" | ||
| + if failedTests | ||
| + log "failed $failedTests and $message", red | ||
| + else | ||
| + log message, green | ||
| fs.readdir 'test', (err, files) -> | ||
| files.forEach (file) -> | ||
| return unless file.match(/\.coffee$/i) | ||
| @@ -97,6 +115,5 @@ task 'test', 'run the CoffeeScript language test suite', -> | ||
| try | ||
| CoffeeScript.run code.toString(), {source: source} | ||
| catch err | ||
| - failed_tests += 1 | ||
| - puts "${red}failed:${reset} $source" | ||
| - puts err.stack | ||
| + failedTests += 1 | ||
| + log "failed $source", red, '\n' + err.stack.toString() | ||
| @@ -4,6 +4,16 @@ require 'rake/testtask' | ||
| require 'rubygems' | ||
| require 'yui/compressor' | ||
| +HEADER = <<-EOS | ||
| +/** | ||
| + * CoffeeScript Compiler v0.7.0 | ||
| + * http://coffeescript.org | ||
| + * | ||
| + * Copyright 2010, Jeremy Ashkenas | ||
| + * Released under the MIT License | ||
| + */ | ||
| +EOS | ||
| + | ||
| desc "Build the documentation page" | ||
| task :doc do | ||
| source = 'documentation/index.html.erb' | ||
| @@ -26,6 +36,6 @@ task :browser do | ||
| sources = %w(helpers.js rewriter.js lexer.js parser.js scope.js nodes.js coffee-script.js) | ||
| code = sources.map {|s| File.read('lib/' + s) }.join('') | ||
| code = YUI::JavaScriptCompressor.new.compress(code) | ||
| - File.open('extras/coffee-script.js', 'w+') {|f| f.write(code) } | ||
| + File.open('extras/coffee-script.js', 'w+') {|f| f.write(HEADER + code) } | ||
| end | ||
| @@ -1,9 +1,11 @@ | ||
| launch() if ignition is on | ||
| -volume: 10 if band isnt spinal_tap | ||
| +volume: 10 if band isnt SpinalTap | ||
| -let_the_wild_rumpus_begin() unless answer is no | ||
| +letTheWildRumpusBegin() unless answer is no | ||
| -if car.speed < speed_limit then accelerate() | ||
| +if car.speed < limit then accelerate() | ||
| + | ||
| +winner: yes if pick in [47, 92, 13] | ||
| print "My name is " + @name |
| @@ -1,5 +0,0 @@ | ||
| -url: "documentation/coffee/binding.coffee" | ||
| - | ||
| -get_source: jQuery.get <- jQuery, url | ||
| - | ||
| -get_source (response) -> alert response |
| @@ -1,3 +1,3 @@ | ||
| task 'test', 'run each of the unit tests', -> | ||
| - for test in test_files | ||
| + for test in files | ||
| fs.readFile test, (err, code) -> eval coffee.compile code |
| @@ -1,9 +1,9 @@ | ||
| -mood: greatly_improved if singing | ||
| +mood: greatlyImproved if singing | ||
| -if happy and knows_it | ||
| - claps_hands() | ||
| - cha_cha_cha() | ||
| +if happy and knowsIt | ||
| + clapsHands() | ||
| + chaChaCha() | ||
| date: if friday then sue else jill | ||
| -expensive: or do_the_math() | ||
| +options: or defaultOptions |
| @@ -1,8 +1,8 @@ | ||
| grade: (student) -> | ||
| - if student.excellent_work | ||
| + if student.excellentWork | ||
| "A+" | ||
| - else if student.okay_stuff | ||
| - if student.tried_hard then "B" else "B-" | ||
| + else if student.okayStuff | ||
| + if student.triedHard then "B" else "B-" | ||
| else | ||
| "C" | ||
| @@ -1,5 +1,5 @@ | ||
| -weather_report: (location) -> | ||
| +weatherReport: (location) -> | ||
| # Make an Ajax request to fetch the weather... | ||
| [location, 72, "Mostly Sunny"] | ||
| -[city, temp, forecast]: weather_report "Berkeley, CA" | ||
| +[city, temp, forecast]: weatherReport "Berkeley, CA" |
| @@ -1,4 +1,4 @@ | ||
| -years_old: {max: 10, ida: 9, tim: 11} | ||
| +yearsOld: {max: 10, ida: 9, tim: 11} | ||
| -ages: for child, age of years_old | ||
| +ages: for child, age of yearsOld | ||
| child + " is " + age |
| @@ -0,0 +1 @@ | ||
| +$('.account').css {class: 'active'} |
| @@ -1,9 +1,9 @@ | ||
| # Assignment: | ||
| number: 42 | ||
| -opposite_day: true | ||
| +opposite: true | ||
| # Conditions: | ||
| -number: -42 if opposite_day | ||
| +number: -42 if opposite | ||
| # Functions: | ||
| square: (x) -> x * x | ||
| @@ -26,4 +26,4 @@ race: (winner, runners...) -> | ||
| alert "I knew it!" if elvis? | ||
| # Array comprehensions: | ||
| -cubed_list: math.cube num for num in list | ||
| +cubes: math.cube num for num in list | ||
| @@ -1,4 +1,4 @@ | ||
| -bait: 1000 | ||
| -and_switch: 0 | ||
| +theBait: 1000 | ||
| +theSwitch: 0 | ||
| -[bait, and_switch]: [and_switch, bait] | ||
| +[theBait, theSwitch]: [theSwitch, theBait] |
| @@ -1,6 +1,6 @@ | ||
| -countdown: num for num in [10..1] | ||
| +countdown: num for num in [10..1] by -1 | ||
| -egg_delivery: -> | ||
| +deliverEggs: -> | ||
| for i in [0...eggs.length] by 12 | ||
| - dozen_eggs: eggs[i...i+12] | ||
| - deliver new egg_carton(dozen) | ||
| + dozen: eggs[i...i+12] | ||
| + deliver new eggCarton(dozen) |
| @@ -1,5 +1,5 @@ | ||
| -num: 1 | ||
| -change_numbers: -> | ||
| - new_num: -1 | ||
| - num: 10 | ||
| -new_num: change_numbers() | ||
| +outer: 1 | ||
| +changeNumbers: -> | ||
| + inner: -1 | ||
| + outer: 10 | ||
| +inner: changeNumbers() |
| @@ -1,6 +1,6 @@ | ||
| numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
| -three_to_six: numbers[3..6] | ||
| +threeToSix: numbers[3..6] | ||
| -numbers_copy: numbers[0...numbers.length] | ||
| +copy: numbers[0...numbers.length] | ||
| @@ -1 +1 @@ | ||
| -lottery.draw_winner()?.address?.zipcode | ||
| +lottery.drawWinner()?.address?.zipcode |
| @@ -1,9 +1,9 @@ | ||
| -gold: silver: the_field: "unknown" | ||
| +gold: silver: rest: "unknown" | ||
| -award_medals: (first, second, rest...) -> | ||
| - gold: first | ||
| - silver: second | ||
| - the_field: rest | ||
| +awardMedals: (first, second, rest...) -> | ||
| + gold: first | ||
| + silver: second | ||
| + rest: rest | ||
| contenders: [ | ||
| "Michael Phelps" | ||
| @@ -18,8 +18,8 @@ contenders: [ | ||
| "Usain Bolt" | ||
| ] | ||
| -award_medals contenders... | ||
| +awardMedals contenders... | ||
| alert "Gold: " + gold | ||
| alert "Silver: " + silver | ||
| -alert "The Field: " + the_field | ||
| +alert "The Field: " + rest | ||
| @@ -1,4 +1,4 @@ | ||
| -moby_dick: "Call me Ishmael. Some years ago -- | ||
| +mobyDick: "Call me Ishmael. Some years ago -- | ||
| never mind how long precisely -- having little | ||
| or no money in my purse, and nothing particular | ||
| to interest me on shore, I thought I would sail | ||
| @@ -1,10 +1,10 @@ | ||
| switch day | ||
| - when "Mon" then go_to_work() | ||
| - when "Tue" then go_to_the_park() | ||
| - when "Thu" then go_ice_fishing() | ||
| + when "Mon" then goToWork() | ||
| + when "Tue" then goToThePark() | ||
| + when "Thu" then goIceFishing() | ||
| when "Fri", "Sat" | ||
| - if day is bingo_day | ||
| - go_to_bingo() | ||
| - go_dancing() | ||
| - when "Sun" then go_to_church() | ||
| - else go_to_work() | ||
| + if day is bingoDay | ||
| + goToBingo() | ||
| + goDancing() | ||
| + when "Sun" then goToChurch() | ||
| + else goToWork() |
| @@ -1,7 +1,7 @@ | ||
| try | ||
| - all_hell_breaks_loose() | ||
| - cats_and_dogs_living_together() | ||
| + allHellBreaksLoose() | ||
| + catsAndDogsLivingTogether() | ||
| catch error | ||
| print error | ||
| finally | ||
| - clean_up() | ||
| + cleanUp() |
| @@ -1,10 +1,10 @@ | ||
| # Econ 101 | ||
| -if this.studying_economics | ||
| +if this.studyingEconomics | ||
| buy() while supply > demand | ||
| sell() until supply > demand | ||
| # Nursery Rhyme | ||
| num: 6 | ||
| -lyrics: while num -= 1 | ||
| +lyrics: while num: - 1 | ||
| num + " little monkeys, jumping on the bed. | ||
| One fell out and bumped his head." |
Showing you all comments on commits in this comparison.
|
is it really worth adding this keyword ? |
|
Feel free to pop into As demonstrated in the usage at the top of this commit -- it really clarifies intent. We had a number of "while true" in the compiler, and they never read naturally. Mostly though, I'm pretty happy with our current treatment of "CoffeeScript keywords" -- the keywords that we use that JavaScript doesn't reserve. Since you can now use them as keys in object literals and as object property names, it doesn't really hurt anything to reserve "loop". In summary: "loop" is readable, pleasant, and comes up in real-world use. |
|
yes it does read well, i suppose you could take it even further : |
|
Well, that's just a
Would still compile. |