From 4d7151aa5d32c9bc1d1b903cbcce2830ab60d442 Mon Sep 17 00:00:00 2001 From: Fahad Ibnay Heylaal Date: Thu, 7 Mar 2013 03:41:34 +0600 Subject: [PATCH] fix: compiling `coffee.coffee` produces `.js` file. --- lib/coffee-script/helpers.js | 2 +- src/helpers.coffee | 2 +- test/helpers.coffee | 24 +++++++++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/coffee-script/helpers.js b/lib/coffee-script/helpers.js index aedb4bdf..601aa7fc 100644 --- a/lib/coffee-script/helpers.js +++ b/lib/coffee-script/helpers.js @@ -152,7 +152,7 @@ } parts = file.split('.'); parts.pop(); - if (parts[parts.length - 1] === 'coffee') { + if (parts[parts.length - 1] === 'coffee' && parts.length > 1) { parts.pop(); } return parts.join('.'); diff --git a/src/helpers.coffee b/src/helpers.coffee index d0f9dd1e..6e700d7b 100644 --- a/src/helpers.coffee +++ b/src/helpers.coffee @@ -110,7 +110,7 @@ exports.baseFileName = (file, stripExt = no) -> return file unless stripExt parts = file.split('.') parts.pop() - parts.pop() if parts[parts.length - 1] is 'coffee' + parts.pop() if parts[parts.length - 1] is 'coffee' and parts.length > 1 parts.join('.') # Determine if a filename represents a CoffeeScript file. diff --git a/test/helpers.coffee b/test/helpers.coffee index 66819084..323b7174 100644 --- a/test/helpers.coffee +++ b/test/helpers.coffee @@ -2,7 +2,7 @@ # ------- # pull the helpers from `CoffeeScript.helpers` into local variables -{starts, ends, compact, count, merge, extend, flatten, del, last} = CoffeeScript.helpers +{starts, ends, compact, count, merge, extend, flatten, del, last, baseFileName} = CoffeeScript.helpers # `starts` @@ -94,3 +94,25 @@ test "the `last` helper returns the last item of an array-like object", -> test "the `last` helper allows one to specify an optional offset", -> ary = [0, 1, 2, 3, 4] eq 2, last(ary, 2) + + +# `baseFileName` + +test "the `baseFileName` helper returns the file name to write to", -> + ext = '.js' + sourceToCompiled = + 'a.coffee': 'a' + ext + 'b.coffee': 'b' + ext + 'a.litcoffee': 'a' + ext + 'b.litcoffee': 'b' + ext + 'a.lit': 'a' + ext + 'b.lit': 'b' + ext + 'a.coffee.md': 'a' + ext + 'b.coffee.md': 'b' + ext + 'coffee.coffee': 'coffee' + ext + + for sourceFileName, expectedFileName of sourceToCompiled + name = baseFileName sourceFileName, yes + filename = name + ext + eq filename, expectedFileName +