1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Add require.extensions support.

This commit is contained in:
Tim-Smart 2010-09-21 13:23:45 +12:00
parent 15d84dbb4e
commit ba850790ed
2 changed files with 16 additions and 3 deletions

View file

@ -1,12 +1,19 @@
(function() { (function() {
var Lexer, compile, helpers, lexer, parser, path; var Lexer, compile, fs, helpers, lexer, parser, path;
if (typeof process !== "undefined" && process !== null) { if (typeof process !== "undefined" && process !== null) {
path = require('path'); path = require('path');
fs = require('fs');
Lexer = require('./lexer').Lexer; Lexer = require('./lexer').Lexer;
parser = require('./parser').parser; parser = require('./parser').parser;
helpers = require('./helpers').helpers; helpers = require('./helpers').helpers;
helpers.extend(global, require('./nodes')); helpers.extend(global, require('./nodes'));
if (require.registerExtension) { if (require.extensions) {
require.extensions['.coffee'] = function(module, filename) {
var content;
content = compile(fs.readFileSync(filename, 'utf8'));
return module._compile(content, filename + '.js');
};
} else if (require.registerExtension) {
require.registerExtension('.coffee', function(content) { require.registerExtension('.coffee', function(content) {
return compile(content); return compile(content);
}); });

View file

@ -9,11 +9,17 @@
# Set up dependencies correctly for both the server and the browser. # Set up dependencies correctly for both the server and the browser.
if process? if process?
path = require 'path' path = require 'path'
fs = require 'fs'
Lexer = require('./lexer').Lexer Lexer = require('./lexer').Lexer
parser = require('./parser').parser parser = require('./parser').parser
helpers = require('./helpers').helpers helpers = require('./helpers').helpers
helpers.extend global, require './nodes' helpers.extend global, require './nodes'
if require.registerExtension # TODO: Remove registerExtension when fully depreciated
if require.extensions
require.extensions['.coffee'] = (module, filename) ->
content = compile fs.readFileSync filename, 'utf8'
module._compile content, filename + '.js'
else if require.registerExtension
require.registerExtension '.coffee', (content) -> compile content require.registerExtension '.coffee', (content) -> compile content
else else
this.exports = this.CoffeeScript = {} this.exports = this.CoffeeScript = {}