Skip to content

Commit

Permalink
fix ariatemplates#3 strip leading newline; add newline before module.…
Browse files Browse the repository at this point in the history
…exports
  • Loading branch information
jakub-g committed Mar 12, 2015
1 parent 06ce89e commit 8333145
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion process-js-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ module.exports = function (UglifyJS) {
var node = nodeAndParent.node;
var pos = node.start.pos;
var sourceText = this.sourceText;
this.sourceText = sourceText.substr(0, pos) + "module.exports = " + sourceText.substr(pos);
this.sourceText = sourceText.substr(0, pos) + "\nmodule.exports = " + sourceText.substr(pos);
};

Transformation.prototype.replaceNode = function (nodeAndParent, newNode, stringOperation) {
Expand Down Expand Up @@ -778,11 +778,17 @@ module.exports = function (UglifyJS) {
this.ast.body.splice(0, 0, node);
};

Transformation.prototype.handleNewlines = function () {
// strip leading newlines
this.sourceText = this.sourceText.replace(/^\n+/, "");
};

return function (ast, sourceText, options) {
var scope = new Transformation(ast, sourceText, options);
scope.findAriaDefAndGlobals();
scope.findDependencies();
scope.insertRequires();
scope.handleNewlines();
return scope.sourceText;
};
};
2 changes: 1 addition & 1 deletion test/test-data/out1.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

var Aria = require("ariatemplates/Aria");
require("./UnusedDep");
var modulesFooBarImportantDep = require("./ImportantDep");
var modulesFooBarParentScript = require("./ParentScript");

module.exports = Aria.tplScriptDefinition({
$classpath: 'modules.foo.bar.TestScript',
$extends: modulesFooBarParentScript,
Expand Down

0 comments on commit 8333145

Please sign in to comment.