From f934199fba7f39c20a26a18dbcda86e12cf35a96 Mon Sep 17 00:00:00 2001 From: David Majda Date: Tue, 3 May 2016 15:12:28 +0200 Subject: [PATCH] Simplify code which generates parser wrappers --- lib/compiler/passes/generate-js.js | 36 +++++++++++++----------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index dc636cc..96efd01 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -1171,17 +1171,15 @@ function generateJS(ast, options) { var generators = { bare: function() { - var parts = []; - - parts.push('(function() {'); - parts.push(indent2(generateIntro())); - parts.push(''); - parts.push(indent2(toplevelCode)); - parts.push(''); - parts.push(indent2('return ' + generateParserObject() + ';')); - parts.push('})()'); - - return parts.join('\n'); + return [ + '(function() {', + indent2(generateIntro()), + '', + indent2(toplevelCode), + '', + indent2('return ' + generateParserObject() + ';'), + '})()' + ].join('\n'); }, umd: function() { @@ -1217,16 +1215,12 @@ function generateJS(ast, options) { parts.push([ ' }', - '})(this, function(' + params + ') {' - ].join('\n')); - - parts.push(indent2(generateIntro())); - parts.push(''); - parts.push(indent2(toplevelCode)); - parts.push(''); - parts.push(indent2('return ' + generateParserObject() + ';')); - - parts.push([ + '})(this, function(' + params + ') {', + indent2(generateIntro()), + '', + indent2(toplevelCode), + '', + indent2('return ' + generateParserObject() + ';'), '});', '' ].join('\n'));