Skip to content

Commit

Permalink
Added transformAST method.
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Oct 15, 2014
1 parent 2edb483 commit 64d9577
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
32 changes: 22 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var fs = require('fs'),
ReplacerMap = require('./replacerMap'),
whenWriteFile = Promise.wrap(fs.writeFile);

exports.transform = function (inOptions) {
exports.transformAST = function (inOptions) {
var options = parseOptions(inOptions),
map = new ReplacerMap(options),
replacer = map.get(options.input);
Expand All @@ -18,21 +18,33 @@ exports.transform = function (inOptions) {
deps: options.deps,
modules: modules,
replacer: replacer
}),
expr = (
});

return {
ast: b.program([b.expressionStatement(
options.exports
? b.callExpression(astConsts.tmpl.umdWrapper(options), [b.literal(options.exports), factoryExpr])
: b.callExpression(factoryExpr, [])
),
result = generate(b.program([b.expressionStatement(expr)]), {
sourceMap: !!options.map,
comment: options.comments,
sourceMapWithCode: true
}),
whenOut;
)]),
options: options
};
});
};

exports.transform = function (inOptions) {
return exports.transformAST(inOptions).then(function (result) {
var options = result.options;

result = generate(result.ast, {
sourceMap: !!options.map,
comment: options.comments,
sourceMapWithCode: true
});

result.options = options;

var whenOut;

if (!options.dryRun) {
if (options.map) {
result.code += '\n//# sourceMappingURL=' + pathUtils.relative(pathUtils.std.dirname(options.output), options.map);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pure-cjs",
"version": "1.14.0",
"version": "1.15.0",
"description": "Pure minimalistic CommonJS builder",
"bin": "./bin/pure-cjs.js",
"main": "./lib/index.js",
Expand Down

0 comments on commit 64d9577

Please sign in to comment.