-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 42132d8
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
test/bundle.js | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var async = require('async'); | ||
var loaderUtils = require('loader-utils'); | ||
var sweet = require('sweet.js'); | ||
|
||
module.exports = function(source) { | ||
this.async(); | ||
|
||
var config = loaderUtils.parseQuery(this.query); | ||
|
||
async.map( | ||
config.modules || [], | ||
function(module, callback) { | ||
this.resolve(this.context, module, function(err, result) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
try { | ||
callback(null, sweet.loadNodeModule(process.cwd(), result)); | ||
} catch (e) { | ||
callback(e); | ||
} | ||
}); | ||
}.bind(this), | ||
function(err, results) { | ||
if (err) { | ||
this.callback(err); | ||
return; | ||
} | ||
config.modules = results; | ||
var result = sweet.compile(source, config); | ||
|
||
this.cacheable && this.cacheable(); | ||
this.callback(null, result.code, result.sourceMap); | ||
}.bind(this) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "sweetjs-loader", | ||
"version": "0.0.0", | ||
"description": "Loader for sweetjs macros", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"sweetjs", | ||
"webpack" | ||
], | ||
"author": "Pete Hunt", | ||
"license": "Apache 2", | ||
"dependencies": { | ||
"sweet.js": "^0.5.0", | ||
"loader-utils": "^0.2.1", | ||
"async": "^0.2.10" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node": "^1.14.2", | ||
"webpack": "^1.1.0-beta9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id(42) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
macro id { | ||
rule { | ||
// after the macro name, match: | ||
// (1) a open paren | ||
// (2) a single token and bind it to `$x` | ||
// (3) a close paren | ||
($x) | ||
} => { | ||
// just return the token that is bound to `$x` | ||
$x | ||
} | ||
} | ||
|
||
export id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var webpack = require('webpack'); | ||
|
||
describe('sweet-loader', function() { | ||
it('should pretty much work', function() { | ||
var BUNDLE_PATH = path.join(__dirname, 'bundle.js'); | ||
|
||
if (fs.existsSync(BUNDLE_PATH)) { | ||
fs.unlinkSync(BUNDLE_PATH); | ||
} | ||
|
||
webpack({ | ||
cache: true, | ||
entry: path.join(__dirname, 'basic.js'), | ||
output: { | ||
filename: BUNDLE_PATH | ||
}, | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js$/, | ||
loader: path.join(__dirname, '../index') + '?modules[]=' + path.join(__dirname, './macros.sjs') | ||
} | ||
] | ||
} | ||
}, function(err, stats) { | ||
console.log(err); | ||
}) | ||
}); | ||
}); |