This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to reference refs/pull/251/head
in repository https://gitbox.apache.org/repos/asf/couchdb-escodegen.git

commit 4eac3d64876bca632c982aded39c83ca28578ba3
Author: Oskar Segersvärd <[email protected]>
AuthorDate: Wed Aug 19 17:23:44 2015 +0200

    Fixed mistakes
    
    * Don't shadow variables
    * Don't try to access properties of possibly undefined sourceMap
    * Auto-update version
---
 escodegen.js            | 10 ++++++----
 package.json            |  1 +
 tools/update-version.js | 42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/escodegen.js b/escodegen.js
index 53c3467..b593c9f 100644
--- a/escodegen.js
+++ b/escodegen.js
@@ -71,7 +71,6 @@
         FORMAT_MINIFY,
         FORMAT_DEFAULTS;
 
-    SourceNode = sourceMap.SourceNode;
     Syntax = estraverse.Syntax;
 
     // Generation is done by generateExpression.
@@ -2499,14 +2498,17 @@
         safeConcatenation = options.format.safeConcatenation;
         directive = options.directive;
         parse = json ? null : options.parse;
-        sourceMap = options.sourceMap;
         sourceCode = options.sourceCode;
         preserveBlankLines = options.format.preserveBlankLines && sourceCode 
!== null;
         extra = options;
 
+        if (sourceMap) {
+          SourceNode = sourceMap.SourceNode;
+        }
+
         result = generateInternal(node);
 
-        if (!sourceMap) {
+        if (!options.sourceMap) {
             pair = {code: result.toString(), map: null};
             return options.sourceMapWithCode ? pair : pair.code;
         }
@@ -2545,7 +2547,7 @@
 
     FORMAT_DEFAULTS = getDefaultOptions().format;
 
-    exports.version = require('./package.json').version;
+    exports.version = '1.6.1';
     exports.generate = generate;
     exports.attachComments = estraverse.attachComments;
     exports.Precedence = updateDeeply({}, Precedence);
diff --git a/package.json b/package.json
index 4f21f69..94279b6 100644
--- a/package.json
+++ b/package.json
@@ -53,6 +53,7 @@
     },
     "license": "BSD-2-Clause",
     "scripts": {
+        "prepublish": "node tools/update-version.js",
         "test": "gulp travis",
         "unit-test": "gulp test",
         "lint": "gulp lint",
diff --git a/tools/update-version.js b/tools/update-version.js
new file mode 100644
index 0000000..351d5a8
--- /dev/null
+++ b/tools/update-version.js
@@ -0,0 +1,42 @@
+#!/usr/bin/env node
+/*
+  Copyright (C) 2012 Yusuke Suzuki <[email protected]>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*jslint sloppy:true node:true */
+
+var fs = require('fs'),
+  path = require('path'),
+  version = require('../package.json').version;
+
+(function() {
+  var filename = path.resolve(__dirname, '../escodegen.js');
+
+  var source = fs.readFileSync(filename, { encoding: 'utf8' });
+
+  source = source.replace(
+    /exports\.version = '(\d+\.\d+\.\d+)';/,
+    'exports.version = \'' + version + '\';');
+
+  fs.writeFileSync(filename, source);
+}());

Reply via email to