diff --git a/documentation/coffee/block_comment.coffee b/documentation/coffee/block_comment.coffee index 8e3d5dad..dd3ce116 100644 --- a/documentation/coffee/block_comment.coffee +++ b/documentation/coffee/block_comment.coffee @@ -1,5 +1,5 @@ ### -CoffeeScript Compiler v1.3.3 +CoffeeScript Compiler v1.4.0 Released under the MIT License ### diff --git a/documentation/docs/browser.html b/documentation/docs/browser.html index 67d03f82..eab39f05 100644 --- a/documentation/docs/browser.html +++ b/documentation/docs/browser.html @@ -1,37 +1,40 @@ -
browser.coffee | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Override exported methods for non-Node.js engines. | CoffeeScript = require './coffee-script'
+ | | |||||||||||||||||||||
External dependencies. | fs = require 'fs'
-path = require 'path'
-helpers = require './helpers'
-optparse = require './optparse'
-CoffeeScript = require './coffee-script' | ||||||||||||||||||||||
Keep track of the list of defined tasks, the accepted options, and so on. | tasks = {}
+current directory's Cakefile. | | |||||||||||||||||||||
External dependencies. | fs = require 'fs'
+path = require 'path'
+helpers = require './helpers'
+optparse = require './optparse'
+CoffeeScript = require './coffee-script'
+
+existsSync = fs.existsSync or path.existsSync | ||||||||||||||||||||||
Keep track of the list of defined tasks, the accepted options, and so on. | tasks = {}
options = {}
switches = []
oparse = null | ||||||||||||||||||||||
Mixin the top-level Cake functions for Cakefiles to use directly. | helpers.extend global, | ||||||||||||||||||||||
Define a Cake task with a short name, an optional sentence description, and the function to run as the action itself. | task: (name, description, action) ->
- [action, description] = [description, action] unless action
+ [action, description] = [description, action] unless action
tasks[name] = {name, description, action} | ||||||||||||||||||||||
Define an option that the Cakefile accepts. The parsed options hash, containing all of the command-line options passed, will be made available as the first argument to the action. | option: (letter, flag, description) ->
switches.push [letter, flag, description] | ||||||||||||||||||||||
Invoke another task in the current Cakefile. | invoke: (name) ->
- missingTask name unless tasks[name]
+ missingTask name unless tasks[name]
tasks[name].action options | ||||||||||||||||||||||
Run | exports.run = ->
- global.__originalDirname = fs.realpathSync '.'
+original directory name, when running Cake tasks from subdirectories. | exports.run = ->
+ global.__originalDirname = fs.realpathSync '.'
process.chdir cakefileDirectory __originalDirname
args = process.argv[2..]
- CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile'
+ CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile'
oparse = new optparse.OptionParser switches
- return printTasks() unless args.length
+ return printTasks() unless args.length
try
options = oparse.parse(args)
catch e
- return fatalError "#{e}"
- invoke arg for arg in options.arguments | |||||||||||||||||||||
Display the list of Cake tasks in a format similar to | printTasks = ->
+ return fatalError "#{e}"
+ invoke arg for arg in options.arguments | ||||||||||||||||||||||
Display the list of Cake tasks in a format similar to | printTasks = ->
relative = path.relative or path.resolve
- cakefilePath = path.join relative(__originalDirname, process.cwd()), 'Cakefile'
- console.log "#{cakefilePath} defines the following tasks:\n"
+ cakefilePath = path.join relative(__originalDirname, process.cwd()), 'Cakefile'
+ console.log "#{cakefilePath} defines the following tasks:\n"
for name, task of tasks
spaces = 20 - name.length
- spaces = if spaces > 0 then Array(spaces + 1).join(' ') else ''
- desc = if task.description then "# #{task.description}" else ''
- console.log "cake #{name}#{spaces} #{desc}"
+ spaces = if spaces > 0 then Array(spaces + 1).join(' ') else ''
+ desc = if task.description then "# #{task.description}" else ''
+ console.log "cake #{name}#{spaces} #{desc}"
console.log oparse.help() if switches.length | ||||||||||||||||||||||
Print an error and exit when attempting to use an invalid task/option. | fatalError = (message) ->
- console.error message + '\n'
- console.log 'To see a list of all tasks/options, run "cake"'
+ console.error message + '\n'
+ console.log 'To see a list of all tasks/options, run "cake"'
process.exit 1
-missingTask = (task) -> fatalError "No such task: #{task}" | ||||||||||||||||||||||
When | |||||||||||||||||||||||
When | cakefileDirectory = (dir) ->
- return dir if path.existsSync path.join dir, 'Cakefile'
- parent = path.normalize path.join dir, '..'
- return cakefileDirectory parent unless parent is dir
- throw new Error "Cakefile not found in #{process.cwd()}"
+ return dir if existsSync path.join dir, 'Cakefile'
+ parent = path.normalize path.join dir, '..'
+ return cakefileDirectory parent unless parent is dir
+ throw new Error "Cakefile not found in #{process.cwd()}"
|
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,RESERVED} = require './lexer'
-{parser} = require './parser'
-vm = require 'vm'
TODO: Remove registerExtension when fully deprecated.
if require.extensions
- require.extensions['.coffee'] = (module, filename) ->
- content = compile fs.readFileSync(filename, 'utf8'), {filename}
- module._compile content, filename
-else if require.registerExtension
- require.registerExtension '.coffee', (content) -> compile content
The current CoffeeScript version number.
exports.VERSION = '1.3.3'
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
+execute all scripts present in text/coffeescript
tags.
fs = require 'fs'
+path = require 'path'
+{Lexer,RESERVED} = require './lexer'
+{parser} = require './parser'
+vm = require 'vm'
+
+stripBOM = (content) ->
+ if content.charCodeAt(0) is 0xFEFF then content.substring 1 else content
+
+if require.extensions
+ require.extensions['.coffee'] = (module, filename) ->
+ content = compile stripBOM(fs.readFileSync filename, 'utf8'), {filename}
+ module._compile content, filename
The current CoffeeScript version number.
exports.VERSION = '1.4.0'
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 = {}) ->
{merge} = exports.helpers
try
js = (parser.parse lexer.tokenize code).compile options
- return js unless options.header
+ return js unless options.header
catch err
- err.message = "In #{options.filename}, #{err.message}" if options.filename
+ err.message = "In #{options.filename}, #{err.message}" if options.filename
throw err
- header = "Generated by CoffeeScript #{@VERSION}"
- "// #{header}\n#{js}"
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 + header = "Generated by CoffeeScript #{@VERSION}" + "// #{header}\n#{js}"
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 .traverseChildren()
with a callback.
exports.nodes = (source, options) ->
- if typeof source is 'string'
+ 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 + parser.parse source
Compile and execute a string of CoffeeScript (on the server), correctly
setting __filename
, __dirname
, and relative require()
.
exports.run = (code, options = {}) ->
- mainModule = require.main
Set the filename.
mainModule.filename = process.argv[1] =
- if options.filename then fs.realpathSync(options.filename) else '.'
Clear the module cache.
mainModule.moduleCache and= {}
Assign paths for node_modules loading
mainModule.paths = require('module')._nodeModulePaths path.dirname fs.realpathSync options.filename
Compile.
if path.extname(mainModule.filename) isnt '.coffee' or require.extensions
+ mainModule = require.main
Set the filename.
mainModule.filename = process.argv[1] =
+ if options.filename then fs.realpathSync(options.filename) else '.'
Clear the module cache.
mainModule.moduleCache and= {}
Assign paths for node_modules loading
mainModule.paths = require('module')._nodeModulePaths path.dirname fs.realpathSync options.filename
Compile.
if path.extname(mainModule.filename) isnt '.coffee' or require.extensions
mainModule._compile compile(code, options), mainModule.filename
else
- mainModule._compile code, mainModule.filename
Compile and evaluate a string of CoffeeScript (in a Node.js-like environment). + mainModule._compile code, mainModule.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 = {}) ->
- return unless code = code.trim()
+ return unless code = code.trim()
Script = vm.Script
if Script
if options.sandbox?
@@ -46,36 +49,36 @@ The CoffeeScript REPL uses this to run the input.
define module/require only if they chose not to specify their own
unless sandbox isnt global or sandbox.module or sandbox.require
- Module = require 'module'
- sandbox.module = _module = new Module(options.modulename || 'eval')
+ sandbox.__filename = options.filename || 'eval'
+ sandbox.__dirname = path.dirname sandbox.__filename
define module/require only if they chose not to specify their own
unless sandbox isnt global or sandbox.module or sandbox.require
+ Module = require 'module'
+ sandbox.module = _module = new Module(options.modulename || 'eval')
sandbox.require = _require = (path) -> Module._load path, _module, true
_module.filename = sandbox.__filename
- _require[r] = require[r] for r in Object.getOwnPropertyNames require when r isnt 'paths'
use the same hack node currently uses for their own REPL
_require.paths = _module.paths = Module._nodeModulePaths process.cwd()
+ _require[r] = require[r] for r in Object.getOwnPropertyNames require when r isnt 'paths'
use the same hack node currently uses for their own REPL
_require.paths = _module.paths = Module._nodeModulePaths process.cwd()
_require.resolve = (request) -> Module._resolveFilename request, _module
o = {}
- o[k] = v for own k, v of options
+ o[k] = v for own k, v of options
o.bare = on # ensure return value
js = compile code, o
if sandbox is global
vm.runInThisContext js
else
- vm.runInContext js, sandbox
Instantiate a Lexer for our use here.
lexer = new Lexer
The real Lexer produces a generic stream of tokens. This object provides a + vm.runInContext js, sandbox
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: ->
- [tag, @yytext, @yylineno] = @tokens[@pos++] or ['']
+ lex: ->
+ [tag, @yytext, @yylineno] = @tokens[@pos++] or ['']
tag
setInput: (@tokens) ->
@pos = 0
- upcomingInput: ->
- ""
+ upcomingInput: ->
+ ""
-parser.yy = require './nodes'
+parser.yy = require './nodes'