diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index 66f4acc5..d7e13699 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.6.0 (function() { - var Lexer, baseFileName, compile, ext, fs, helpers, lexer, loadFile, parser, path, sourcemap, vm, _i, _len, _ref, + var Lexer, compile, ext, fs, helpers, lexer, loadFile, parser, path, sourcemap, vm, _i, _len, _ref, __hasProp = {}.hasOwnProperty; fs = require('fs'); @@ -37,13 +37,7 @@ exports.VERSION = '1.6.0'; - exports.helpers = require('./helpers'); - - baseFileName = function(fileName) { - var extension; - extension = path.extname(fileName); - return path.basename(fileName, extension); - }; + exports.helpers = helpers; exports.compile = compile = function(code, options) { var answer, coffeeFile, currentColumn, currentLine, fragment, fragments, header, js, jsFile, merge, newLines, sourceMap, _j, _len1; @@ -54,7 +48,7 @@ try { if (options.sourceMap) { coffeeFile = path.basename(options.filename); - jsFile = baseFileName(options.filename) + ".js"; + jsFile = helpers.baseFileName(options.filename) + ".js"; sourceMap = new sourcemap.SourceMap(); } fragments = (parser.parse(lexer.tokenize(code, options))).compileToFragments(options); diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index beb55d8a..308646da 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -170,7 +170,7 @@ } else { compiled = CoffeeScript.compile(t.input, t.options); t.output = compiled; - if (o.sourceMap) { + if (o.map) { t.output = compiled.js; t.sourceMap = compiled.v3SourceMap; } @@ -370,11 +370,11 @@ }; outputPath = function(source, base, extension) { - var baseDir, basename, dir, srcDir, _ref1; + var baseDir, basename, dir, srcDir; if (extension == null) { extension = ".js"; } - basename = path.basename(source, ((_ref1 = source.match(/\.((lit)?coffee|coffee\.md)$/)) != null ? _ref1[0] : void 0) || path.extname(source)); + basename = helpers.baseFileName(source); srcDir = path.dirname(source); baseDir = base === '.' ? srcDir : srcDir.substring(base.length); dir = opts.output ? path.join(opts.output, baseDir) : srcDir; diff --git a/lib/coffee-script/helpers.js b/lib/coffee-script/helpers.js index 10f5e352..54d060e4 100644 --- a/lib/coffee-script/helpers.js +++ b/lib/coffee-script/helpers.js @@ -121,6 +121,18 @@ } }; + exports.baseFileName = function(file) { + var parts; + parts = file.split('/'); + file = parts[parts.length - 1]; + parts = file.split('.'); + parts.pop(); + if (parts[parts.length - 1] === 'coffee') { + parts.pop(); + } + return parts.join('.'); + }; + exports.isCoffee = function(file) { return /\.((lit)?coffee|coffee\.md)$/.test(file); }; diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 6d749437..3fc124e4 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -12,7 +12,7 @@ path = require 'path' {parser} = require './parser' helpers = require './helpers' vm = require 'vm' -sourcemap = require './sourcemap' +sourcemap = require './sourcemap' # Load and run a CoffeeScript file for Node, stripping any `BOM`s. loadFile = (module, filename) -> @@ -28,11 +28,7 @@ if require.extensions exports.VERSION = '1.6.0' # Expose helpers for testing. -exports.helpers = require './helpers' - -baseFileName = (fileName) -> - extension = path.extname(fileName) - return path.basename fileName, extension +exports.helpers = helpers # Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler. # @@ -48,7 +44,7 @@ exports.compile = compile = (code, options = {}) -> if options.sourceMap coffeeFile = path.basename options.filename - jsFile = baseFileName(options.filename) + ".js" + jsFile = helpers.baseFileName(options.filename) + ".js" sourceMap = new sourcemap.SourceMap() fragments = (parser.parse lexer.tokenize(code, options)).compileToFragments options diff --git a/src/command.coffee b/src/command.coffee index 00fd4cc6..126ebe7d 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -127,7 +127,7 @@ compileScript = (file, input, base) -> else compiled = CoffeeScript.compile t.input, t.options t.output = compiled - if o.sourceMap + if o.map t.output = compiled.js t.sourceMap = compiled.v3SourceMap @@ -251,7 +251,7 @@ removeSource = (source, base, removeJs) -> # 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 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 diff --git a/src/helpers.coffee b/src/helpers.coffee index 5c1dfab4..a496b234 100644 --- a/src/helpers.coffee +++ b/src/helpers.coffee @@ -92,6 +92,15 @@ exports.locationDataToString = (obj) -> else "No location data" +# A `.coffee.md` compatible version of `basename`, that returns the file sans-extension. +exports.baseFileName = (file) -> + parts = file.split('/') + file = parts[parts.length - 1] + 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