1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

merging in the try coffeescript linking patch from Jeremy Banks, and regen-ing source. The newline patch makes a *huge* difference on the documentation page.

This commit is contained in:
Jeremy Ashkenas 2011-09-20 22:42:19 -05:00
parent 4c0b2372c7
commit 65b3bf0d4c
41 changed files with 498 additions and 174 deletions

View file

@ -1578,7 +1578,7 @@ Expressions
</div>
<script type="text/coffeescript">
source_fragment_prefix = "try_src:"
sourceFragment = "try:"
# Set up the compilation function, to run when you stop typing.
compileSource = ->
@ -1596,7 +1596,7 @@ Expressions
$('#error').text(error.message).show()
# Update permalink
$('#repl_permalink').attr 'href', "##{source_fragment_prefix}#{encodeURIComponent source}"
$('#repl_permalink').attr 'href', "##{sourceFragment}#{encodeURIComponent source}"
# Listen for keypresses and recompile.
$('#repl_source').keyup -> compileSource()
@ -1650,8 +1650,8 @@ Expressions
# If source code is included in location.hash, display it.
hash = decodeURIComponent location.hash.replace(/^#/, '')
if hash.indexOf(source_fragment_prefix) == 0
src = hash.substr source_fragment_prefix.length
if hash.indexOf(sourceFragment) == 0
src = hash.substr sourceFragment.length
loadConsole src
compileSource()

View file

@ -1,17 +1,13 @@
var volume, winner;
if (ignition === true) {
launch();
}
if (band !== SpinalTap) {
volume = 10;
}
if (answer !== false) {
letTheWildRumpusBegin();
}
if (car.speed < limit) {
accelerate();
}
if (pick === 47 || pick === 92 || pick === 13) {
winner = true;
}
if (ignition === true) launch();
if (band !== SpinalTap) volume = 10;
if (answer !== false) letTheWildRumpusBegin();
if (car.speed < limit) accelerate();
if (pick === 47 || pick === 92 || pick === 13) winner = true;
print(inspect("My name is " + this.name));

View file

@ -1,6 +1,21 @@
var food, _i, _len, _ref;
var course, courses, dish, food, foods, _i, _j, _len, _len2, _len3, _ref;
_ref = ['toast', 'cheese', 'wine'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
food = _ref[_i];
eat(food);
}
courses = ['salad', 'entree', 'dessert'];
for (course = 0, _len2 = courses.length; course < _len2; course++) {
dish = courses[course];
menu(course + 1, dish);
}
foods = ['broccoli', 'spinach', 'chocolate'];
for (_j = 0, _len3 = foods.length; _j < _len3; _j++) {
food = foods[_j];
if (food !== 'chocolate') eat(food);
}

View file

@ -1,4 +1,7 @@
/*
CoffeeScript Compiler v1.1.2
Released under the MIT License
*/

View file

@ -1,6 +1,9 @@
var fs;
fs = require('fs');
option('-o', '--output [DIR]', 'directory for compiled code');
task('build:parser', 'rebuild the Jison parser', function(options) {
var code, dir;
require('jison');

View file

@ -1,44 +1,58 @@
var Animal, Horse, Snake, sam, tom;
var __hasProp = Object.prototype.hasOwnProperty, __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;
};
var __hasProp = Object.prototype.hasOwnProperty, __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; };
Animal = (function() {
function Animal(name) {
this.name = name;
}
Animal.prototype.move = function(meters) {
return alert(this.name + (" moved " + meters + "m."));
};
return Animal;
})();
Snake = (function() {
__extends(Snake, Animal);
function Snake() {
Snake.__super__.constructor.apply(this, arguments);
}
Snake.prototype.move = function() {
alert("Slithering...");
return Snake.__super__.move.call(this, 5);
};
return Snake;
})();
Horse = (function() {
__extends(Horse, Animal);
function Horse() {
Horse.__super__.constructor.apply(this, arguments);
}
Horse.prototype.move = function() {
alert("Galloping...");
return Horse.__super__.move.call(this, 45);
};
return Horse;
})();
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");
sam.move();
tom.move();

View file

@ -1,3 +1,5 @@
var cholesterol, healthy;
cholesterol = 127;
healthy = (200 > cholesterol && cholesterol > 60);

View file

@ -1,12 +1,14 @@
var date, mood;
if (singing) {
mood = greatlyImproved;
}
if (singing) mood = greatlyImproved;
if (happy && knowsIt) {
clapsHands();
chaChaCha();
} else {
showIt();
}
date = friday ? sue : jill;
options || (options = defaults);

View file

@ -1,7 +1,6 @@
var fill;
fill = function(container, liquid) {
if (liquid == null) {
liquid = "coffee";
}
if (liquid == null) liquid = "coffee";
return "Filling the " + container + " with " + liquid + "...";
};

View file

@ -1,4 +1,5 @@
var filename, _fn, _i, _len;
_fn = function(filename) {
return fs.readFile(filename, function(err, contents) {
return compile(filename, contents.toString());

View file

@ -1,4 +1,5 @@
var hi;
hi = function() {
return [document.title, "Hello JavaScript"].join(": ");
};

View file

@ -1,8 +1,9 @@
var footprints, solipsism;
if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
solipsism = true;
}
if (typeof speed === "undefined" || speed === null) {
speed = 75;
}
if (typeof speed === "undefined" || speed === null) speed = 75;
footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear";

View file

@ -1,4 +1,5 @@
var eldest, grade;
grade = function(student) {
if (student.excellentWork) {
return "A+";
@ -12,4 +13,5 @@ grade = function(student) {
return "C";
}
};
eldest = 24 > 21 ? "Liz" : "Ike";

View file

@ -1,2 +1,3 @@
var one, six, three, two;
six = (one = 1) + (two = 2) + (three = 3);

View file

@ -1,4 +1,5 @@
var globals, name;
globals = ((function() {
var _results;
_results = [];

View file

@ -1,3 +1,4 @@
alert((function() {
try {
return nonexistent / void 0;

View file

@ -1,5 +1,6 @@
var Account;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Account = function(customer, cart) {
this.customer = customer;
this.cart = cart;

View file

@ -1,7 +1,9 @@
var cube, square;
square = function(x) {
return x * x;
};
cube = function(x) {
return square(x) * x;
};

View file

@ -1,2 +1,3 @@
var html;
html = '<strong>\n cup of coffeescript\n</strong>';

View file

@ -1,2 +1,3 @@
var OPERATOR;
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;

View file

@ -1,4 +1,7 @@
var author, quote, sentence;
author = "Wittgenstein";
quote = "A picture is a fact. -- " + author;
sentence = "" + (22 / 7) + " is a decent approximation of π";

View file

@ -1,5 +1,7 @@
var city, forecast, temp, weatherReport, _ref;
weatherReport = function(location) {
return [location, 72, "Mostly Sunny"];
};
_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];

View file

@ -1,9 +1,11 @@
var age, ages, child, yearsOld;
yearsOld = {
max: 10,
ida: 9,
tim: 11
};
ages = (function() {
var _results;
_results = [];

View file

@ -1,4 +1,5 @@
var city, futurists, name, street, _ref, _ref2;
futurists = {
sculptor: "Umberto Boccioni",
painter: "Vladimir Burliuk",
@ -7,4 +8,5 @@ futurists = {
address: ["Via Roma 42R", "Bellagio, Italy 22021"]
}
};
_ref = futurists.poet, name = _ref.name, _ref2 = _ref.address, street = _ref2[0], city = _ref2[1];
_ref = futurists.poet, name = _ref.name, (_ref2 = _ref.address, street = _ref2[0], city = _ref2[1]);

View file

@ -1,10 +1,14 @@
var bitlist, kids, singers, song;
song = ["do", "re", "mi", "fa", "so"];
singers = {
Jagger: "Rock",
Elvis: "Roll"
};
bitlist = [1, 0, 1, 0, 0, 1, 1, 1, 0];
kids = {
brother: {
name: "Max",

View file

@ -1,4 +1,6 @@
$('.account').attr({
"class": 'active'
});
log(object["class"]);

View file

@ -1,14 +1,18 @@
var cubes, list, math, num, number, opposite, race, square;
var __slice = Array.prototype.slice;
number = 42;
opposite = true;
if (opposite) {
number = -42;
}
if (opposite) number = -42;
square = function(x) {
return x * x;
};
list = [1, 2, 3, 4, 5];
math = {
root: Math.sqrt,
square: square,
@ -16,14 +20,15 @@ math = {
return x * square(x);
}
};
race = function() {
var runners, winner;
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return print(winner, runners);
};
if (typeof elvis !== "undefined" && elvis !== null) {
alert("I knew it!");
}
if (typeof elvis !== "undefined" && elvis !== null) alert("I knew it!");
cubes = (function() {
var _i, _len, _results;
_results = [];

View file

@ -1,4 +1,7 @@
var theBait, theSwitch, _ref;
theBait = 1000;
theSwitch = 0;
_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];

View file

@ -1,4 +1,6 @@
var close, contents, open, tag, _i, _ref;
var __slice = Array.prototype.slice;
tag = "<impossible>";
_ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call(_ref, 1, _i = _ref.length - 1) : (_i = 1, []), close = _ref[_i++];

View file

@ -1,3 +1,4 @@
String.prototype.dasherize = function() {
return this.replace(/_/g, "-");
};

View file

@ -1,4 +1,5 @@
var countdown, num;
countdown = (function() {
var _results;
_results = [];

View file

@ -1,8 +1,11 @@
var changeNumbers, inner, outer;
outer = 1;
changeNumbers = function() {
var inner;
inner = -1;
return outer = 10;
};
inner = changeNumbers();

View file

@ -1,4 +1,7 @@
var copy, middle, numbers;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
copy = numbers.slice(0, numbers.length);
middle = copy.slice(3, 7);

View file

@ -1,2 +1,3 @@
var zip, _ref;
zip = typeof lottery.drawWinner === "function" ? (_ref = lottery.drawWinner().address) != null ? _ref.zipcode : void 0 : void 0;

View file

@ -1,6 +1,8 @@
var awardMedals, contenders, gold, rest, silver;
var __slice = Array.prototype.slice;
gold = silver = rest = "unknown";
awardMedals = function() {
var first, others, second;
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
@ -8,8 +10,13 @@ awardMedals = function() {
silver = second;
return rest = others;
};
contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
awardMedals.apply(null, contenders);
alert("Gold: " + gold);
alert("Silver: " + silver);
alert("The Field: " + rest);

View file

@ -1,3 +1,5 @@
var numbers, _ref;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
[].splice.apply(numbers, [3, 4].concat(_ref = [-3, -4, -5, -6])), _ref;

View file

@ -1,2 +1,3 @@
var mobyDick;
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 about a little and see the watery part of the world...";

View file

@ -1,3 +1,4 @@
switch (day) {
case "Mon":
go(work);

View file

@ -1,3 +1,4 @@
try {
allHellBreaksLoose();
catsAndDogsLivingTogether();

View file

@ -1,4 +1,5 @@
var lyrics, num;
if (this.studyingEconomics) {
while (supply > demand) {
buy();
@ -7,7 +8,9 @@ if (this.studyingEconomics) {
sell();
}
}
num = 6;
lyrics = (function() {
var _results;
_results = [];

File diff suppressed because it is too large Load diff