Skip to content

Commit

Permalink
First draft of switching the CoffeeScript Compiler over to camelCase.…
Browse files Browse the repository at this point in the history
… Pour one on the ground for underscores...
  • Loading branch information
jashkenas committed Jun 12, 2010
1 parent 1948b0c commit e14f4c5
Show file tree
Hide file tree
Showing 57 changed files with 1,244 additions and 1,244 deletions.
24 changes: 12 additions & 12 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options)
"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"
"mkdir -p ~/.node_libraries"
"ln -sf $lib/lib ~/.node_libraries/coffee-script"
"mkdir -p ~/.nodeLibraries"
"ln -sf $lib/lib ~/.nodeLibraries/coffee-script"
].join(' && '), (err, stdout, stderr) ->
if err then print stderr
)
Expand All @@ -44,8 +44,8 @@ task 'build:parser', 'rebuild the Jison parser (run build first)', ->
require.paths.unshift 'vendor/jison/lib'
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', ->
Expand Down Expand Up @@ -80,20 +80,20 @@ task 'loc', 'count the lines of source code in CoffeeScript', ->

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"
puts(if failedTests then "${red}failed $failedTests and $message" else "$green$message")
fs.readdir 'test', (err, files) ->
files.forEach (file) ->
return unless file.match(/\.coffee$/i)
Expand All @@ -102,6 +102,6 @@ task 'test', 'run the CoffeeScript language test suite', ->
try
CoffeeScript.run code.toString(), {source: source}
catch err
failed_tests += 1
failedTests += 1
puts "${red}failed:${reset} $source"
puts err.stack
6 changes: 3 additions & 3 deletions documentation/coffee/aliases.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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 < speedLimit then accelerate()

print "My name is " + @name
2 changes: 1 addition & 1 deletion documentation/coffee/cake_tasks.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
task 'test', 'run each of the unit tests', ->
for test in test_files
for test in testFiles
fs.readFile test, (err, code) -> eval coffee.compile code
10 changes: 5 additions & 5 deletions documentation/coffee/conditionals.coffee
Original file line number Diff line number Diff line change
@@ -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()
expensive: or doTheMath()
6 changes: 3 additions & 3 deletions documentation/coffee/expressions.coffee
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion documentation/coffee/fat_arrow.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Account: (customer, cart) ->
@customer: customer
@cart: cart

$('.shopping_cart').bind 'click', (event) =>
$('.shoppingCart').bind 'click', (event) =>
@customer.purchase @cart
4 changes: 2 additions & 2 deletions documentation/coffee/multiple_return_values.coffee
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions documentation/coffee/object_comprehensions.coffee
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions documentation/coffee/overview.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Assignment:
number: 42
opposite_day: true
oppositeDay: true

# Conditions:
number: -42 if opposite_day
number: -42 if oppositeDay

# Functions:
square: (x) -> x * x
Expand All @@ -26,4 +26,4 @@ race: (winner, runners...) ->
alert "I knew it!" if elvis?

# Array comprehensions:
cubed_list: math.cube num for num in list
cubedList: math.cube num for num in list
4 changes: 2 additions & 2 deletions documentation/coffee/parallel_assignment.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bait: 1000
and_switch: 0
andSwitch: 0

[bait, and_switch]: [and_switch, bait]
[bait, andSwitch]: [andSwitch, bait]
6 changes: 3 additions & 3 deletions documentation/coffee/range_comprehensions.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
countdown: num for num in [10..1]

egg_delivery: ->
eggDelivery: ->
for i in [0...eggs.length] by 12
dozen_eggs: eggs[i...i+12]
deliver new egg_carton(dozen)
dozenEggs: eggs[i...i+12]
deliver new eggCarton(dozen)
6 changes: 3 additions & 3 deletions documentation/coffee/scope.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
num: 1
change_numbers: ->
new_num: -1
changeNumbers: ->
newNum: -1
num: 10
new_num: change_numbers()
newNum: changeNumbers()
4 changes: 2 additions & 2 deletions documentation/coffee/slices.coffee
Original file line number Diff line number Diff line change
@@ -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]
numbersCopy: numbers[0...numbers.length]

2 changes: 1 addition & 1 deletion documentation/coffee/soaks.coffee
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lottery.draw_winner()?.address?.zipcode
lottery.drawWinner()?.address?.zipcode
10 changes: 5 additions & 5 deletions documentation/coffee/splats.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
gold: silver: the_field: "unknown"
gold: silver: theField: "unknown"

award_medals: (first, second, rest...) ->
awardMedals: (first, second, rest...) ->
gold: first
silver: second
the_field: rest
theField: rest

contenders: [
"Michael Phelps"
Expand All @@ -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: " + theField
2 changes: 1 addition & 1 deletion documentation/coffee/strings.coffee
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions documentation/coffee/switch.coffee
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 3 additions & 3 deletions documentation/coffee/try.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
try
all_hell_breaks_loose()
cats_and_dogs_living_together()
allHellBreaksLoose()
catsAndDogsLivingTogether()
catch error
print error
finally
clean_up()
cleanUp()
2 changes: 1 addition & 1 deletion documentation/coffee/while.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Econ 101
if this.studying_economics
if this.studyingEconomics
buy() while supply > demand
sell() until supply > demand

Expand Down
10 changes: 5 additions & 5 deletions lib/cake.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function(){
var CoffeeScript, fs, helpers, no_such_task, oparse, options, optparse, path, print_tasks, switches, tasks;
var CoffeeScript, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
var __hasProp = Object.prototype.hasOwnProperty;
// `cake` is a simplified version of [Make](http://www.gnu.org/software/make/)
// ([Rake](http://rake.rubyforge.org/), [Jake](http://github.com/280north/jake))
Expand Down Expand Up @@ -45,7 +45,7 @@
// Invoke another task in the current Cakefile.
invoke: function(name) {
if (!(tasks[name])) {
no_such_task(name);
missingTask(name);
}
return tasks[name].action(options);
}
Expand All @@ -65,7 +65,7 @@
});
oparse = new optparse.OptionParser(switches);
if (!(args.length)) {
return print_tasks();
return printTasks();
}
options = oparse.parse(args);
_a = []; _c = options.arguments;
Expand All @@ -77,7 +77,7 @@
});
};
// Display the list of Cake tasks in a format similar to `rake -T`
print_tasks = function() {
printTasks = function() {
var _a, _b, desc, i, name, spaces, task;
puts('');
_a = tasks;
Expand All @@ -99,7 +99,7 @@
}
};
// Print an error and exit when attempting to all an undefined task.
no_such_task = function(task) {
missingTask = function(task) {
puts(("No such task: \"" + task + "\""));
return process.exit(1);
};
Expand Down
8 changes: 4 additions & 4 deletions lib/coffee-script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function(){
var Lexer, compile, helpers, lexer, parser, path, process_scripts;
var Lexer, compile, helpers, lexer, parser, path, processScripts;
// CoffeeScript can be used both on the server, as a command-line compiler based
// on Node.js/V8, or to run CoffeeScripts directly in the browser. This module
// contains the main entry functions for tokenzing, parsing, and compiling source
Expand Down Expand Up @@ -90,7 +90,7 @@
// on page load. Unfortunately, the text contents of remote scripts cannot be
// accessed from the browser, so only inline script tags will work.
if ((typeof document !== "undefined" && document !== null) && document.getElementsByTagName) {
process_scripts = function() {
processScripts = function() {
var _a, _b, _c, _d, tag;
_a = []; _c = document.getElementsByTagName('script');
for (_b = 0, _d = _c.length; _b < _d; _b++) {
Expand All @@ -100,9 +100,9 @@
return _a;
};
if (window.addEventListener) {
window.addEventListener('load', process_scripts, false);
window.addEventListener('load', processScripts, false);
} else if (window.attachEvent) {
window.attachEvent('onload', process_scripts);
window.attachEvent('onload', processScripts);
}
}
})();
Loading

3 comments on commit e14f4c5

@StanAngeloff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh noes! It's all gone camely.

@feistystudios
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHY?

@jashkenas
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.