From 9785fd03337ffe98bc51a6cc2c82d328931da4de Mon Sep 17 00:00:00 2001
From: Jeremy Ashkenas
If included on a webpage, it will automatically sniff out, compile, and
-execute all scripts present in text/coffeescript
tags.
fs = require 'fs'
-path = require 'path'
-{Lexer} = require './lexer'
-{parser} = require './parser'
TODO: Remove registerExtension when fully deprecated.
if require.extensions
+execute all scripts present in text/coffeescript
tags.
fs = require 'fs'
+path = require 'path'
+{Lexer,RESERVED} = require './lexer'
+{parser} = require './parser'
TODO: Remove registerExtension when fully deprecated.
if require.extensions
require.extensions['.coffee'] = (module, filename) ->
content = compile fs.readFileSync filename, 'utf8'
module._compile content, filename
else if require.registerExtension
- require.registerExtension '.coffee', (content) -> compile content
The current CoffeeScript version number.
exports.VERSION = '0.9.6'
Expose helpers for testing.
exports.helpers = require './helpers'
Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison + require.registerExtension '.coffee', (content) -> compile content
The current CoffeeScript version number.
exports.VERSION = '0.9.6'
Words that cannot be used as identifiers in CoffeeScript code
exports.RESERVED = RESERVED
Expose helpers for testing.
exports.helpers = require './helpers'
Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
exports.compile = compile = (code, options = {}) ->
try
(parser.parse lexer.tokenize code).compile options
catch err
err.message = "In #{options.fileName}, #{err.message}" if options.fileName
- throw err
Tokenize a string of CoffeeScript code, and return the array of tokens.
exports.tokens = (code, options) ->
- lexer.tokenize code, options
Parse a string of CoffeeScript code or an array of lexed tokens, and + throw err
Tokenize a string of CoffeeScript code, and return the array of tokens.
exports.tokens = (code, options) ->
+ lexer.tokenize code, options
Parse a string of CoffeeScript code or an array of lexed tokens, and
return the AST. You can then compile it by calling .compile()
on the root,
or traverse it by using .traverse()
with a callback.
exports.nodes = (source, options) ->
if typeof source is 'string'
parser.parse lexer.tokenize source, options
else
- parser.parse source
Compile and execute a string of CoffeeScript (on the server), correctly
-setting __filename
, __dirname
, and relative require()
.
exports.run = (code, options) ->
We want the root module.
root = module
+ parser.parse source
Compile and execute a string of CoffeeScript (on the server), correctly
+setting __filename
, __dirname
, and relative require()
.
exports.run = (code, options) ->
We want the root module.
root = module
while root.parent
- root = root.parent
Set the filename.
root.filename = fs.realpathSync options.fileName or '.'
Clear the module cache.
root.moduleCache = {} if root.moduleCache
Compile.
if path.extname(root.filename) isnt '.coffee' or require.extensions
+ root = root.parent
Set the filename.
root.filename = fs.realpathSync options.fileName or '.'
Clear the module cache.
root.moduleCache = {} if root.moduleCache
Compile.
if path.extname(root.filename) isnt '.coffee' or require.extensions
root._compile compile(code, options), root.filename
else
- root._compile code, root.filename
Compile and evaluate a string of CoffeeScript (in a Node.js-like environment). + root._compile code, root.filename
Compile and evaluate a string of CoffeeScript (in a Node.js-like environment). The CoffeeScript REPL uses this to run the input.
exports.eval = (code, options) ->
__filename = options.fileName
__dirname = path.dirname __filename
- eval compile code, options
Instantiate a Lexer for our use here.
lexer = new Lexer
The real Lexer produces a generic stream of tokens. This object provides a + eval compile code, options
Instantiate a Lexer for our use here.
lexer = new Lexer
The real Lexer produces a generic stream of tokens. This object provides a thin wrapper around it, compatible with the Jison API. We can then pass it directly as a "Jison lexer".
parser.lexer =
lex: ->
diff --git a/documentation/docs/command.html b/documentation/docs/command.html
index dc6a5610..b0dddb0a 100644
--- a/documentation/docs/command.html
+++ b/documentation/docs/command.html
@@ -52,7 +52,7 @@ Many flags cause us to divert before compiling anything. Flags passed after
sources.pop()
if opts.run
flags = sources.splice(1).concat flags
- process.ARGV = process.argv = flags
+ process.ARGV = process.argv = process.argv.slice(0, 2).concat flags
compileScripts()
Asynchronously read in each CoffeeScript in a list of source files and compile them. If a directory is passed, recursively compile all '.coffee' extension source files in it and all subdirectories.
compileScripts = ->
diff --git a/documentation/docs/lexer.html b/documentation/docs/lexer.html
index c8485ef1..6013e87a 100644
--- a/documentation/docs/lexer.html
+++ b/documentation/docs/lexer.html
@@ -401,7 +401,9 @@ to avoid having a JavaScript error at runtime.
The superset of both JavaScript keywords and reserved words, none of which may -be used as identifiers or properties.
JS_FORBIDDEN = JS_KEYWORDS.concat RESERVED
Token matching regexes.
IDENTIFIER = /// ^
+be used as identifiers or properties.
JS_FORBIDDEN = JS_KEYWORDS.concat RESERVED
+
+exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS)
Token matching regexes.
IDENTIFIER = /// ^
( [$A-Za-z_][$\w]* )
( [^\n\S]* : (?!:) )? # Is this a property name?
///
diff --git a/documentation/docs/nodes.html b/documentation/docs/nodes.html
index ea38d69b..efed2923 100644
--- a/documentation/docs/nodes.html
+++ b/documentation/docs/nodes.html
@@ -161,7 +161,7 @@ declarations of all inner variables pushed up to the top.
Instead of generating the JavaScript string directly, we build up the equivalent syntax tree and compile that, in pieces. You can see the constructor, property assignments, and inheritance getting built out below.
exports.Assign = class Assign extends Base
- constructor: (@variable, @value, @context) ->
The Assign is used to assign a local variable to value, or to set the + constructor: (@variable, @value, @context, options) -> + @param = options and options.param
The Assign is used to assign a local variable to value, or to set the property of an object -- including within object literals.
METHOD_DEF: /^(?:(\S+)\.prototype\.|\S+?)?\b([$A-Za-z_][$\w]*)$/
children: ['variable', 'value']
@@ -622,8 +623,11 @@ property of an object -- including within object literals.
Compile an assignment, delegating to compilePatternMatch
or
compileSplice
if appropriate. Keep track of the name of the base object
@@ -684,7 +688,7 @@ for details.
A shorthand {a, b, @c} = val
pattern-match.
compileConditional: (o) ->
@@ -694,14 +698,16 @@ operands are only evaluated once, even though we have to reference them
more than once.
compileSplice: (o) ->
{range} = @variable.properties.pop()
name = @variable.compile o
- plus = if range.exclusive then '' else ' + 1'
+ excl = range.exclusive
from = if range.from then range.from.compile(o) else '0'
to = "#{name}.length" unless range.to
unless to
if range.from and range.from.isSimpleNumber() and range.to.isSimpleNumber()
- to = (+range.to.compile(o)) - +from + +plus
+ to = +range.to.compile(o) - +from
+ to += 1 unless excl
else
- to = range.to.compile(o) + ' - ' + from + plus
+ to = range.to.compile(o) + ' - ' + from
+ to += ' + 1' unless excl
val = @value.compile(o)
"[].splice.apply(#{name}, [#{from}, #{to}].concat(#{val}))"
Compile the assignment from an array splice literal, using JavaScript's
Array#splice
method.
exports.Code = class Code extends Base
@@ -732,7 +738,7 @@ has no children -- they're within the inner scope.
compileChain: (o) ->
[@first.second, shared] = @first.second.cache o
fst = @first.compile o, LEVEL_OP
- fst = fst.slice 1, -1 if @first.unwrap() instanceof Op and @first.isChainable() and fst.charAt(0) is '('
code = "#{fst} #{if @invert then '&&' else '||'} #{ shared.compile o } #{@operator} #{ @second.compile o, LEVEL_OP }"
"(#{code})"
@@ -1087,7 +1092,7 @@ parentheses, but no longer -- you can put in as many as you please.
if @range
forPart = source.compile merge(o, {index: ivar, @step})
else
- svar = @source.compile o, LEVEL_TOP
+ svar = @source.compile o, LEVEL_LIST
if (name or @own) and not IDENTIFIER.test svar
defPart = "#{@tab}#{ref = scope.freeVariable 'ref'} = #{svar};\n"
svar = ref
@@ -1106,7 +1111,7 @@ parentheses, but no longer -- you can put in as many as you please.
if @guard
body = Expressions.wrap [new If @guard, body]
if hasCode
- body = Closure.wrap(body, yes)
+ body = Closure.wrap(body, yes, not @returns)
varPart = "\n#{idt1}#{namePart};" if namePart
if @object
forPart = "#{ivar} in #{svar}"
@@ -1252,7 +1257,7 @@ which is helpful for recording the result arrays from comprehensions.
args = [new Literal 'this']
args.push new Literal 'arguments' if mentionsArgs
func = new Value func, [new Access meth]
- func.noReturn = noReturn
+ func.noReturn = noReturn
call = new Call func, args
if statement then Expressions.wrap [call] else call
diff --git a/documentation/docs/scope.html b/documentation/docs/scope.html
index b9627837..ffeeb4c4 100644
--- a/documentation/docs/scope.html
+++ b/documentation/docs/scope.html
@@ -19,7 +19,6 @@ it wraps.
find: (name, options) ->
return yes if @check name, options
@add name, 'var'
- @hasDeclarations = yes
no
Reserve a variable name as originating from a function parameter for this
scope. No var
required for internal references.
parameter: (name) ->
return if @shared and @check name, yes
@@ -38,16 +37,16 @@ compiler-generated variable. _var
, _var2
, and so on...
index = 0
index++ while @check((temp = @temporary type, index), true)
@add temp, 'var'
- @hasDeclarations = yes
temp
Ensure that an assignment is made at the top of this scope (or at the top-level scope, if requested).
assign: (name, value) ->
@add name, value: value, assigned: true
- @hasAssignments = yes
Return the list of variables first declared in this scope.
declaredVariables: ->
+ @hasAssignments = yes
Does this scope have any declared variables?
hasDeclarations: ->
+ !!@declaredVariables().length
Return the list of variables first declared in this scope.
declaredVariables: ->
realVars = []
tempVars = []
for v in @variables when v.type is 'var'
(if v.name.charAt(0) is '_' then tempVars else realVars).push v.name
- realVars.sort().concat tempVars.sort()
Return the list of assignments that are supposed to be made at the top + realVars.sort().concat tempVars.sort()
Return the list of assignments that are supposed to be made at the top of this scope.
assignedVariables: ->
"#{v.name} = #{v.type.value}" for v in @variables when v.type.assigned
diff --git a/documentation/images/banding.png b/documentation/images/banding.png
new file mode 100644
index 0000000000000000000000000000000000000000..f7b6862baa77328a72e9cbb3bf584d2bdaa27c9e
GIT binary patch
literal 132
zcmeAS@N?(olHy`uVBq!ia0vp^0zk~i!3HGN^yhQ|DajJoh?3y^w370~qErUQl>DSr
z1<%~X^wgl##FWaylc_c!wVp1HAr-fh{`~)MuguKa(Ans8fawVH>!v{c08O5M{Z)-d
c3<3!Zi#M?FVdQ&MBb@0JPjE3IG5A
literal 0
HcmV?d00001
diff --git a/documentation/images/button_bg_dark.gif b/documentation/images/button_bg_dark.gif
new file mode 100644
index 0000000000000000000000000000000000000000..ded7a55fa0922a957fcb8b12bec93b7cd450fa4e
GIT binary patch
literal 148
zcmZ?wbhEHbWMq(FIKsdX78X`pTbrAkTV7sXSXh{yogEz=U0Pb2nwpxFloS*cR8vzE
zA0J;?S(%xcSzKIPS69bC3Q+vX0#>dAB0+XCunH=u^d)UDIs8$;>7fE=GJ_WfgEase
CQ6H56
literal 0
HcmV?d00001
diff --git a/documentation/images/button_bg_green.gif b/documentation/images/button_bg_green.gif
new file mode 100644
index 0000000000000000000000000000000000000000..5f817dd0a40c3fefb7d4d1191ec90b4ca31d1e8e
GIT binary patch
literal 95
zcmZ?wbhEHbWMq(F*v!CSyf)AFV71oN7^_{S220a*7bF|4$hO{BVY#(fXI6sQrXst;
jH4I2V@h1zIrvoBEW-zeu6rA)-w_w&x@bGkEVXy`OA_o_8
literal 0
HcmV?d00001
diff --git a/documentation/images/screenshadow.png b/documentation/images/screenshadow.png
new file mode 100644
index 0000000000000000000000000000000000000000..9f1da9c1d988847fd0190edfa64dad9f8b067bde
GIT binary patch
literal 4452
zcmcIoS5(u>xBew`kRV-pLX#?>AjJrw2%(4q5y5~40qIqQfRre32rUT#ktV2cK#?M#
zAc7L90Y#(*B$OjfY0`_K{d4~JUQd0KAq+
zGkX94k(fh`lbz{VX_#wePGVt~oWdM}?u13Sg?a+U9znM~p_Tz|UY_=zZXS^#-JWm&
z;AgiqGe%*@mM6GE>F?g->{6aDvyJP7?X(nD%y#4z{$d~GEY6q)a6eIhk2frZtNBsN
zWaQ_1jgAjCTT&vV=tlXy^ZQGGT3yL4MMiP4Z*RpN?5+Qpq)yFkH#SCpzj?EezT>yo
zCLtd23ETfIeYxQNt)Rmu)25@arK`<~u74s*7?|UIaDdF`_#95EfGtd%qo1nC-Df`C
zKNGv#yCN9EpTFfkkU$#x4FieYH8%L`^q8?W84Le<{piow@y$?jqiB9_`tb+;oH=&^
zlYx%*85lIayMntoL&g|Oe#dE!!UktPIcY-
z2N-a{{w!XWcV>Uvy_NiqPq1sO)vf1gyDs8Yfo+smz={d7mfI%~w4g|6vtq7L!tD3L
z1WYzw9iq~_W%)_`Qf(F-%hyjr`Vm);3T;z}miwK04Csg&&=pWa
z!~2xx9rMDq92HK?1=Y6LTw`i@$*4uBUhQI?)T(6A{g$VHG%%wZS9|?t=zaBQWs%3z-MnpMS
zh!V+#LuJ2IHG^yx%b%)OX{JlIl^rXFkS-?Tvb67wK7aT|@wi;YJ5|+y8f)by?jsT#
zyqhSwq#1yF>G9iVRtQqB5nf8O2Q5IzKVyxbx=WCbQRKNA@~=^3L2D6~43G^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+3KByaZM=m+XS$@
LWNTJsf_eBK=AjVn
literal 0
HcmV?d00001
diff --git a/documentation/index.html.erb b/documentation/index.html.erb
index 99917988..3f09196e 100644
--- a/documentation/index.html.erb
+++ b/documentation/index.html.erb
@@ -1,6 +1,9 @@
<%
require 'uv'
+ require 'json'
+ @counter = 0
def code_for(file, executable=false)
+ @counter += 1
return '' unless File.exists?("documentation/js/#{file}.js")
cs = File.read("documentation/coffee/#{file}.coffee")
js = File.read("documentation/js/#{file}.js")
@@ -8,8 +11,11 @@
jshtml = Uv.parse(js, 'xhtml', 'javascript', false, 'idle', false)
append = executable == true ? '' : "alert(#{executable});"
run = executable == true ? 'run' : "run: #{executable}"
- button = executable ? "#{cshtml}#{jshtml}#{button}
"
+ name = "example#{@counter}"
+ script = ""
+ import = " "
+ button = executable ? " " : ''
+ "#{cshtml}#{jshtml}#{script}#{import}#{button}
"
end
%>
@@ -23,7 +29,7 @@
-
+
@@ -33,7 +39,7 @@
-
+
+
-
+
+
+
+
+
+
+
-
-
-
+
@@ -85,7 +96,7 @@
-
+
+
@@ -751,6 +762,8 @@ awardMedals contenders...
alert "Gold: " + gold
alert "Silver: " + silver
alert "The Field: " + rest
+
+
var awardMedals, contenders, gold, rest, silver;
var __slice = Array.prototype.slice;
gold = silver = rest = "unknown";
@@ -766,7 +779,7 @@ awardMedals.apply(alert("Gold: " + gold);
alert("Silver: " + silver);
alert("The Field: " + rest);
-
+
If you know the start and end of your loop, or would like to step through
in fixed-size increments, you can use a range to specify the start and
@@ -877,7 +890,7 @@ countdown = (function(
}
return _results;
}());
-
" : ''
- "
var numbers; numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; [].splice.apply(numbers, [3, 4].concat([-3, -4, -5, -6])); -
@@ -1011,7 +1025,7 @@ eldest = if = 24 > 21 ? "Liz" : "Ike"; -
six = (one = 1) + (two = 2) + (three = 3) + +
var one, six, three, two; six = (one = 1) + (two = 2) + (three = 3); -
Things that would otherwise be statements in JavaScript, when used @@ -1057,7 +1073,7 @@ globals = (function() } return _results; }()).slice(0, 10); -
+Soaking up nulls is similar to Ruby's andand gem, and to the @@ -1244,7 +1261,7 @@ sam = new = new Horse("Tommy the Palomino"); sam.move(); tom.move(); -
String::dasherize = -> this.replace /_/g, "-" +
String.prototype.dasherize = function() { return this.replace(/_/g, "-"); }; -
@@ -1326,11 +1344,12 @@ tom.move();;'>run
theSwitch = 0
[theBait, theSwitch] = [theSwitch, theBait]
+
var theBait, theSwitch, _ref; theBait = 1000; theSwitch = 0; _ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1]; -
If we had used -> in the callback above, @customer would have referred to the undefined "customer" property of the DOM element, @@ -1467,7 +1486,7 @@ _ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call hi = function() { return [document.title, "Hello JavaScript"].join(": "); }; -
@@ -1535,6 +1554,7 @@ hi = function() { print error finally cleanUp() +
try { allHellBreaksLoose(); catsAndDogsLivingTogether(); @@ -1543,7 +1563,7 @@ hi = function() { } finally { cleanUp(); } -
@@ -1561,7 +1581,7 @@ healthy = 200
Heredocs can be used to hold formatted or indentation-sensitive text
@@ -1612,9 +1632,11 @@ mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely --
cup of coffeescript
</strong>
'''
+
+
Double-quoted heredocs, like double-quoted strings, allow interpolation.
@@ -1652,9 +1676,11 @@ html = '<
| \?\. # soak access
| \.{2,3} # range or splat
) ///
+
+
If you need to invoke one task before another — for example, running
build before test, you can use the invoke function:
@@ -2347,55 +2373,57 @@ task('build:parser
# Set up the compilation function, to run when you stop typing.
- compile_source = ->
+ compileSource = ->
source = $('#repl_source').val()
- window.compiled_js = ''
+ window.compiledJS = ''
try
- window.compiled_js = CoffeeScript.compile source, bare: on
- $('#repl_results').text window.compiled_js
+ window.compiledJS = CoffeeScript.compile source, bare: on
+ $('#repl_results').text window.compiledJS
$('#error').hide()
catch error
$('#error').text(error.message).show()
# Listen for keypresses and recompile.
- $('#repl_source').keyup -> compile_source()
+ $('#repl_source').keyup -> compileSource()
# Eval the compiled js.
- $('button.run').click ->
+ $('.minibutton.run').click ->
try
- eval window.compiled_js
+ eval window.compiledJS
catch error then alert error
- current_nav = null
+ # Load the console with a string of CoffeeScript.
+ window.loadConsole = (coffee) ->
+ $('#repl_source').val coffee
+ compileSource()
+ $('.navigation.try').addClass 'active'
+
+ currentNav = null
# Helper to hide the menus.
- close_menus = ->
- if current_nav
- current_nav.removeClass 'active'
- document.body.className = 'minimized'
- current_nav = null
+ closeMenus = ->
+ if currentNav
+ currentNav.removeClass 'active'
+ currentNav = null
# Bind navigation buttons to open the menus.
$('.navigation').click (e) ->
return if e.target.tagName.toLowerCase() is 'a'
- if this isnt (current_nav and current_nav[0])
- close_menus()
- current_nav = $(this)
- current_nav.addClass 'active'
+ return false if $(e.target).closest('.repl_wrapper').length
+ if this is (currentNav and currentNav[0])
+ closeMenus()
+ else
+ closeMenus()
+ currentNav = $(this)
+ currentNav.addClass 'active'
false
- $(document.body).click -> close_menus()
-
- $('.navigation .full_screen').click ->
- document.body.className = 'full_screen'
-
- $('.navigation .minimize').click ->
- document.body.className = 'minimized'
+ $(document.body).click -> closeMenus()
$('#open_webchat').click ->
$(this).replaceWith $('')
- compile_source()
+ compileSource()
diff --git a/test/importing.coffee b/test/importing.coffee
index 23a0282f..a5f4b4f1 100644
--- a/test/importing.coffee
+++ b/test/importing.coffee
@@ -1,17 +1,18 @@
# Importing
# ---------
-test "coffeescript modules can be imported and executed", ->
+unless window? or testingBrowser
+ test "coffeescript modules can be imported and executed", ->
- magicKey = __filename
- magicValue = 0xFFFF
+ magicKey = __filename
+ magicValue = 0xFFFF
- if global[magicKey]?
- if exports?
- local = magicValue
- exports.method = -> local
- else
- global[magicKey] = {}
- if require?.extensions? or require?.registerExtension?
- ok require(__filename).method() is magicValue
- delete global[magicKey]
+ if global[magicKey]?
+ if exports?
+ local = magicValue
+ exports.method = -> local
+ else
+ global[magicKey] = {}
+ if require?.extensions? or require?.registerExtension?
+ ok require(__filename).method() is magicValue
+ delete global[magicKey]
diff --git a/test/test.html b/test/test.html
index d7fc6adf..0a0241ca 100644
--- a/test/test.html
+++ b/test/test.html
@@ -34,6 +34,9 @@
stdout.appendChild div
msg
+ this.test = (desc, fn) ->
+ fn()
+
this.ok = (good, msg) ->
++total
if good then ++success else throw Error say msg
@@ -50,7 +53,7 @@
cb yes
run = (name) ->
- CoffeeScript.load "test_#{name}.coffee", (yay) ->
+ CoffeeScript.load "#{name}.coffee", (yay) ->
say "#{ if yay then '\u2714' else '\u3000' } #{name}", yay
++failed unless yay
fin() if ++done is names.length
@@ -66,26 +69,27 @@
'arguments'
'assignment'
'break'
- 'chaining'
- 'classes'
'comments'
- 'compilation'
- 'comprehensions'
- 'existence'
- 'functions'
- 'helpers'
- 'heredocs'
- 'if'
- 'literals'
- 'operations'
- 'pattern_matching'
- 'regexps'
- 'returns'
- 'splats'
- 'strings'
- 'switch'
- 'try_catch'
- 'while'
+ 'exception_handling'
+ 'operators'
+ 'regular_expressions'
+ 'test_chaining'
+ 'test_classes'
+ 'test_compilation'
+ 'test_comprehensions'
+ 'test_existence'
+ 'test_functions'
+ 'test_helpers'
+ 'test_heredocs'
+ 'test_if'
+ 'test_literals'
+ 'test_pattern_matching'
+ 'test_ranges_slices_and_splices'
+ 'test_returns'
+ 'test_splats'
+ 'test_strings'
+ 'test_switch'
+ 'test_while'
]
var cholesterol, healthy;
cholesterol = 127;
healthy = (200 > cholesterol && cholesterol > 60);
-
@@ -1582,7 +1602,7 @@ sentence = "Wittgenstein";
quote = "A picture is a fact. -- " + author;
sentence = "" + (22 / 7) + " is a decent approximation of π";
-
@@ -1599,7 +1619,7 @@ sentence = "" + (22 / 7) + " is a decent approximation of π";;alert(sentence);'
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...";
-
var html;
html = '<strong>\n cup of coffeescript\n</strong>';
-
+
###
CoffeeScript Compiler v0.9.6
Released under the MIT License
-###
+###
+
+
/*
CoffeeScript Compiler v0.9.6
Released under the MIT License
*/
-
var OPERATOR;
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
-
+
@@ -1699,7 +1725,7 @@ task('build:parser= options.output || 'lib';
return fs.writeFile("" + dir + "/parser.js", code);
});
-
+