Merge branch 'pr/1407' into devel

This commit is contained in:
David Glasser
2013-09-12 14:29:58 -07:00
8 changed files with 36 additions and 16 deletions

View File

@@ -3,9 +3,10 @@ Tinytest.add("coffeescript - presence", function(test) {
});
Tinytest.add("literate coffeescript - presence", function(test) {
test.isTrue(Meteor.__LITCOFFEESCRIPT_PRESENT);
test.isTrue(Meteor.__COFFEEMDSCRIPT_PRESENT);
});
Tinytest.add("coffeescript - exported variable", function(test) {
test.equal(COFFEESCRIPT_EXPORTED, 123);
test.equal(Package['coffeescript-test-helper'].COFFEESCRIPT_EXPORTED, 123);
});
});

View File

@@ -16,9 +16,10 @@ Package.on_test(function (api) {
api.use(['coffeescript-test-helper'], ['client', 'server']);
api.add_files([
'coffeescript_test_setup.js',
'coffeescript_tests.coffee',
'coffeescript_strict_tests.coffee',
'litcoffeescript_tests.litcoffee',
'tests/coffeescript_tests.coffee',
'tests/coffeescript_strict_tests.coffee',
'tests/litcoffeescript_tests.litcoffee',
'tests/litcoffeescript_tests.coffee.md',
'coffeescript_tests.js'
], ['client', 'server']);
});

View File

@@ -113,13 +113,14 @@ var addSharedHeader = function (source, sourceMap) {
};
};
var handler = function (compileStep) {
var handler = function (compileStep, isLiterate) {
var source = compileStep.read().toString('utf8');
var outputFile = compileStep.inputPath + ".js";
var options = {
bare: true,
filename: compileStep.inputPath,
literate: path.extname(compileStep.inputPath) === '.litcoffee',
literate: !!isLiterate,
// Return a source map.
sourceMap: true,
// Include the original source in the source map (sourcesContent field).
@@ -152,6 +153,11 @@ var handler = function (compileStep) {
});
};
Plugin.registerSourceHandler("coffee", handler);
Plugin.registerSourceHandler("litcoffee", handler);
var literateHandler = function (compileStep) {
return handler(compileStep, true);
}
Plugin.registerSourceHandler("coffee", handler);
Plugin.registerSourceHandler("litcoffee", literateHandler);
Plugin.registerSourceHandler("coffee.md", literateHandler);

View File

@@ -0,0 +1,6 @@
This file is just the same as `coffeescript_tests.coffee`, first we set a
property, which we check for in `coffeescript_tests.js`, and then a trivial
testcase.
Meteor.__COFFEEMDSCRIPT_PRESENT = true
Tinytest.add "markdown coffeescript - compile", (test) -> test.isTrue true

View File

@@ -236,8 +236,8 @@ _.extend(Slice.prototype, {
var relPath = source.relPath;
var fileOptions = _.clone(source.fileOptions) || {};
var absPath = path.resolve(self.pkg.sourceRoot, relPath);
var ext = path.extname(relPath).substr(1);
var handler = !fileOptions.isAsset && self._getSourceHandler(ext);
var filename = path.basename(relPath);
var handler = !fileOptions.isAsset && self._getSourceHandler(filename);
var contents = watch.readAndWatchFile(self.watchSet, absPath);
if (contents === null) {
@@ -723,12 +723,17 @@ _.extend(Slice.prototype, {
// Find the function that should be used to handle a source file for
// this slice, or return null if there isn't one. We'll use handlers
// that are defined in this package and in its immediate
// dependencies. ('extension' should be the extension of the file
// without a leading dot.)
_getSourceHandler: function (extension) {
// that are defined in this package and in its immediate dependencies.
_getSourceHandler: function (filename) {
var self = this;
return (self._allHandlers())[extension] || null;
var handlers = self._allHandlers();
var parts = filename.split('.');
for (var i = 0; i < parts.length; i++) {
var extension = parts.slice(i).join('.');
if (_.has(handlers, extension))
return handlers[extension];
}
return null;
}
});
@@ -946,7 +951,8 @@ _.extend(Package.prototype, {
return;
var Plugin = {
// 'extension' is a file extension without a dot (eg 'js', 'coffee')
// 'extension' is a file extension without the separation dot
// (eg 'js', 'coffee', 'coffee.md')
//
// 'handler' is a function that takes a single argument, a
// CompileStep (#CompileStep)