From 8333145a9ac9605cc301aee3a2151cff4bf32253 Mon Sep 17 00:00:00 2001 From: jgieryluk Date: Thu, 12 Mar 2015 14:49:30 +0100 Subject: [PATCH] fix #3 strip leading newline; add newline before module.exports --- process-js-ast.js | 8 +++++++- test/test-data/out1.txt | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/process-js-ast.js b/process-js-ast.js index 5c1b060..b9c3211 100644 --- a/process-js-ast.js +++ b/process-js-ast.js @@ -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) { @@ -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; }; }; \ No newline at end of file diff --git a/test/test-data/out1.txt b/test/test-data/out1.txt index 9bfbea4..898c132 100644 --- a/test/test-data/out1.txt +++ b/test/test-data/out1.txt @@ -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,