mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
refactoring to a baseFileName that can work in the browser, for later
This commit is contained in:
parent
b2b801a78b
commit
b2ef77d92e
6 changed files with 32 additions and 21 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue