From eef83a9fcbc01cefb2c7b1bb0d2fffa927aa7512 Mon Sep 17 00:00:00 2001
From: Jeremy Ashkenas text/coffeescript
tags.
Load and run a CoffeeScript file for Node, stripping any BOM
s.
loadFile = (module, filename) ->
+sourcemap = require './sourcemap'
Load and run a CoffeeScript file for Node, stripping any BOM
s.
loadFile = (module, filename) ->
raw = fs.readFileSync filename, 'utf8'
stripped = if raw.charCodeAt(0) is 0xFEFF then raw.substring 1 else raw
module._compile compile(stripped, {filename, literate: helpers.isLiterate filename}), filename
if require.extensions
for ext in ['.coffee', '.litcoffee', '.md', '.coffee.md']
- require.extensions[ext] = loadFile
The current CoffeeScript version number.
exports.VERSION = '1.6.0'
Expose helpers for testing.
exports.helpers = require './helpers'
-
-baseFileName = (fileName) ->
- extension = path.extname(fileName)
- return path.basename fileName, extension
Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
+ require.extensions[ext] = loadFileThe current CoffeeScript version number.
exports.VERSION = '1.6.1'
Expose helpers for testing.
exports.helpers = helpers
Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
If options.sourceMap
is specified, then options.filename
must also be specified.
This returns a javascript string, unless options.sourceMap
or options.returnObject
are true,
+
This returns a javascript string, unless options.sourceMap
is passed,
in which case this returns a `{js, v3SourceMap, sourceMap}
object, where sourceMap is a sourcemap.coffee#SourceMap object, handy for doing programatic
lookups.
exports.compile = compile = (code, options = {}) ->
@@ -33,13 +29,15 @@ lookups.
Update the sourcemap with data from each fragment
if sourceMap
@@ -60,7 +58,7 @@ lookups.
__filename
compileJoin()
else
compiled = CoffeeScript.compile t.input, t.options
- t.output = compiled.js
- t.sourceMap = compiled.v3SourceMap
+ t.output = compiled
+ if o.map
+ t.output = compiled.js
+ t.sourceMap = compiled.v3SourceMap
CoffeeScript.emit 'success', task
- if o.print then printLine t.output.trim()
+ if o.print
+ printLine t.output.trim()
else if o.compile || o.map
writeJs base, t.file, t.output, t.sourceMap
- else if o.lint then lint t.file, t.output
+ else if o.lint
+ lint t.file, t.output
catch err
CoffeeScript.emit 'failure', err, task
return if CoffeeScript.listeners('failure').length
@@ -203,7 +207,7 @@ the compiled JS version as well. Get the corresponding output JavaScript path for a source file.
outputPath = (source, base, extension=".js") ->
- basename = path.basename source, source.match(/\.((lit)?coffee|coffee\.md)$/)?[0] or path.extname(source)
+ basename = helpers.baseFileName source, yes
srcDir = path.dirname source
baseDir = if base is '.' then srcDir else srcDir.substring base.length
dir = if opts.output then path.join opts.output, baseDir else srcDir
@@ -219,7 +223,7 @@ same directory as the .js
file.
Start up a new Node.js instance with the arguments in --nodejs
passed to
the node
binary, preserving the other options.
forkNode = ->
nodeArgs = opts.nodejs.split /\s+/
diff --git a/documentation/docs/helpers.html b/documentation/docs/helpers.html
index 9337135c..0ec8514e 100644
--- a/documentation/docs/helpers.html
+++ b/documentation/docs/helpers.html
@@ -51,6 +51,13 @@ updates that object's locationData. The object is returned either way.
"#{locationData.first_line + 1}:#{locationData.first_column + 1}-" +
"#{locationData.last_line + 1}:#{locationData.last_column + 1}"
else
- "No location data"
Determine if a filename represents a CoffeeScript file.
exports.isCoffee = (file) -> /\.((lit)?coffee|coffee\.md)$/.test file
Determine if a filename represents a Literate CoffeeScript file.
exports.isLiterate = (file) -> /\.(litcoffee|coffee\.md)$/.test file
+ "No location data"
A .coffee.md
compatible version of basename
, that returns the file sans-extension.
exports.baseFileName = (file, stripExt = no) ->
+ parts = file.split('/')
+ file = parts[parts.length - 1]
+ return file unless stripExt
+ parts = file.split('.')
+ parts.pop()
+ parts.pop() if parts[parts.length - 1] is 'coffee'
+ parts.join('.')
Determine if a filename represents a CoffeeScript file.
exports.isCoffee = (file) -> /\.((lit)?coffee|coffee\.md)$/.test file
Determine if a filename represents a Literate CoffeeScript file.
exports.isLiterate = (file) -> /\.(litcoffee|coffee\.md)$/.test file