Skip to content

Instantly share code, notes, and snippets.

@Havvy
Created January 12, 2014 16:15
Show Gist options
  • Select an option

  • Save Havvy/8386654 to your computer and use it in GitHub Desktop.

Select an option

Save Havvy/8386654 to your computer and use it in GitHub Desktop.
fez.js (*)
test-src/
test-bdd.sjs (*)
test/
node_modules/
fez/
fez-sweet.js/
plugin.js (*)
node_modules/
sweet.js/
bluebird/
(*) Included in this gist.
#!/usr/bin/env node
var fez = require('fez');
var sweetjs = require('fez-sweet.js');
exports.build = function(rule) {
rule.each("test-src/*.sjs", fez.mapFile("test/%f.js"), sweetjs({'modules': ['sweet-bdd']}));
};
exports.default = exports.build;
fez(module);
var SweetJS = require('sweet.js');
var Promise = require('bluebird');
var inspect = require('util').inspect;
module.exports = function (options) {
console.log(inspect(options, {depth: null, showColors: true}));
var cwd = process.cwd();
var modules = (options.modules || []).map(function (modulename) {
return SweetJS.loadNodeModule(cwd, modulename);
});
function sjs(promise) {
return promise
.then(function (input) {
var src = input.toString();
console.log("SRC:", "\n", src, "\n");
console.log("Modules:", "\n", inspect(modules[0], {depth: 2, showColors: true}), "\n");
console.log("Compilation Result:");
var outfile = SweetJS.compile(src, modules).code;
console.log(outfile);
return outfile;
});
}
return function (inputs) {
return Promise.all(inputs.map(function (input) { return input.asBuffer(); }).map(sjs));
}
}
$ ./fez.js
{ modules: [ 'sweet-bdd' ] }
Creating test/test-bdd.js
SRC:
it "x" { }
Modules:
{ env:
{ __data:
{ 'quoteSyntax$3': [Object],
'syntax$13': [Object],
'#$15': [Object],
'syntaxCase$77': [Object],
'macro$106': [Object],
'withSyntax_unzip$170': [Object],
'withSyntax$196': [Object],
'letstx$246': [Object],
'quoteSyntax$247': [Object],
'syntax$248': [Object],
'#$249': [Object],
'syntaxCase$250': [Object],
'macro$251': [Object],
'withSyntax$252': [Object],
'letstx$253': [Object],
'describe$278': [Object],
'it$306': [Object],
'beforeEach$334': [Object],
'afterEach$362': [Object] } },
defscope: undefined,
templateMap:
{ __data:
{ '275': [Object],
'300': [Object],
'303': [Object],
'328': [Object],
'331': [Object],
'356': [Object],
'359': [Object] } },
mark: undefined,
exports:
[ { oldExport: [Object], newParam: [Object] },
{ oldExport: [Object], newParam: [Object] },
{ oldExport: [Object], newParam: [Object] },
{ oldExport: [Object], newParam: [Object] } ] }
Compilation Result:
{ _bitField: 134217728,
_settledValue:
{ [Error: Line 1: Unexpected string
[... it x { } ...]]
index: 3,
lineNumber: 1,
column: 4,
description: 'Unexpected string' } }
An operation has failed. Aborting.
Nothing to be done.
@natefaubion
Copy link

modules isn't the second arg to sweet.compile. It should be an options object with a modules key:

sweet.compile(src, {
    modules: mods
});

@Havvy
Copy link
Author

Havvy commented Jan 12, 2014

I feel so stupid. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment