Permalink
Browse files

fix problems with the new extensions system

  • Loading branch information...
1 parent 0d2535b commit 173a06903351f8b5cf1fb17621f856a85eb8b20d @maxtaco committed Jan 19, 2012
Showing with 36 additions and 19 deletions.
  1. +33 −16 lib/coffee-script/coffee-script.js
  2. +3 −3 src/coffee-script.coffee
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.2.1-pre
(function() {
- var Lexer, RESERVED, compile, fs, lexer, parser, path, tame, vm, _ref,
+ var EXTENSIONS, Lexer, RESERVED, compile, e, fs, isCoffeeFile, lexer, parser, path, tame, vm, _i, _j, _len, _len2, _ref,
__hasProp = {}.hasOwnProperty;
fs = require('fs');
@@ -15,18 +15,35 @@
vm = require('vm');
+ exports.EXTENSIONS = EXTENSIONS = [".coffee"];
+
+ isCoffeeFile = function(file) {
+ var e, _i, _len;
+ for (_i = 0, _len = EXTENSIONS.length; _i < _len; _i++) {
+ e = EXTENSIONS[_i];
+ if (path.extname(file) === e) return true;
+ }
+ return false;
+ };
+
if (require.extensions) {
- require.extensions['.coffee'] = function(module, filename) {
- var content;
- content = compile(fs.readFileSync(filename, 'utf8'), {
- filename: filename
- });
- return module._compile(content, filename);
- };
+ for (_i = 0, _len = EXTENSIONS.length; _i < _len; _i++) {
+ e = EXTENSIONS[_i];
+ require.extensions[e] = function(module, filename) {
+ var content;
+ content = compile(fs.readFileSync(filename, 'utf8'), {
+ filename: filename
+ });
+ return module._compile(content, filename);
+ };
+ }
} else if (require.registerExtension) {
- require.registerExtension('.coffee', function(content) {
- return compile(content);
- });
+ for (_j = 0, _len2 = EXTENSIONS.length; _j < _len2; _j++) {
+ e = EXTENSIONS[_j];
+ require.registerExtension(e, function(content) {
+ return compile(content);
+ });
+ }
}
exports.VERSION = '1.2.1-pre';
@@ -71,15 +88,15 @@
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';
mainModule.moduleCache && (mainModule.moduleCache = {});
mainModule.paths = require('module')._nodeModulePaths(path.dirname(options.filename));
- if (path.extname(mainModule.filename) !== '.coffee' || require.extensions) {
+ if ((!isCoffeeFile(mainModule.filename)) || require.extensions) {
return mainModule._compile(compile(code, options), mainModule.filename);
} else {
return mainModule._compile(code, mainModule.filename);
}
};
- exports["eval"] = function(code, options) {
- var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref2, _ref3, _require;
+ exports.eval = function(code, options) {
+ var Module, Script, js, k, o, r, sandbox, v, _k, _len3, _module, _ref2, _ref3, _require;
if (options == null) options = {};
if (!(code = code.trim())) return;
Script = vm.Script;
@@ -110,8 +127,8 @@
};
_module.filename = sandbox.__filename;
_ref3 = Object.getOwnPropertyNames(require);
- for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
- r = _ref3[_i];
+ for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
+ r = _ref3[_k];
if (r !== 'paths') _require[r] = require[r];
}
_require.paths = _module.paths = Module._nodeModulePaths(process.cwd());
@@ -14,12 +14,12 @@ tame = require './tame'
vm = require 'vm'
# Native extensions we're willing to consider
-exports.EXTENSIONS = EXTENSIONS = [ ".coffee", ".toffee"]
+exports.EXTENSIONS = EXTENSIONS = [ ".coffee" ]
isCoffeeFile = (file) ->
for e in EXTENSIONS
return true if path.extname(file) is e
- false
+ false
# TODO: Remove registerExtension when fully deprecated.
if require.extensions
@@ -82,7 +82,7 @@ exports.run = (code, options = {}) ->
mainModule.paths = require('module')._nodeModulePaths path.dirname options.filename
# Compile.
- if not isCoffeeFile mainModule.filename or require.extensions
+ if (not isCoffeeFile mainModule.filename) or require.extensions
mainModule._compile compile(code, options), mainModule.filename
else
mainModule._compile code, mainModule.filename

0 comments on commit 173a069

Please sign in to comment.