Permalink
Browse files

Allow loading of .sjs files in node.js

Example program now works:

    var sjs = require('sweet.js'),
        example = require('./example');

Where ./example.sjs contains:

    module A {
	case ($a + $b) => {
	    $a
	}
    }

    exports.one = A(1 + 2);
  • Loading branch information...
1 parent f645704 commit c8d9d6fa8ed41230df56bd4c99f2cf75df5924d6 @puffnfresh puffnfresh committed Oct 4, 2012
Showing with 12 additions and 0 deletions.
  1. +6 −0 lib/sweet.js
  2. +6 −0 src/sweet.js
View
@@ -5123,6 +5123,12 @@ var fs = require("fs");
exports.syntaxToTokens = syntaxToTokens;
exports.tokensToSyntax = tokensToSyntax;
+ // Alow require('./example') for an example.sjs file.
+ require.extensions['.sjs'] = function(module, filename) {
+ var content = require('fs').readFileSync(filename, 'utf8');
+ module._compile(gen.generate(parse(content)), filename);
+ };
+
// Deep copy.
exports.Syntax = (function () {
var name, types = {};
View
@@ -5123,6 +5123,12 @@ var fs = require("fs");
exports.syntaxToTokens = syntaxToTokens;
exports.tokensToSyntax = tokensToSyntax;
+ // Alow require('./example') for an example.sjs file.
+ require.extensions['.sjs'] = function(module, filename) {
+ var content = require('fs').readFileSync(filename, 'utf8');
+ module._compile(gen.generate(parse(content)), filename);
+ };
+
// Deep copy.
exports.Syntax = (function () {
var name, types = {};

0 comments on commit c8d9d6f

Please sign in to comment.