[Pkg-javascript-commits] [node-recast] 01/03: New upstream version 0.11.20

Julien Puydt julien.puydt at laposte.net
Fri Jan 20 08:17:25 UTC 2017


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository node-recast.

commit db65ba48686198a5d91e0cc7c50371a65e36e149
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Fri Jan 20 09:14:45 2017 +0100

    New upstream version 0.11.20
---
 lib/fast-path.js |  8 +++++---
 lib/parser.js    |  2 +-
 lib/printer.js   |  1 +
 lib/util.js      |  7 +++++++
 package.json     |  6 +++---
 test/babylon.js  | 35 +++++++++++++++++++++++++++++++++++
 test/parens.js   |  4 ++++
 test/printer.js  | 25 +++++++++++++++++++++++++
 8 files changed, 81 insertions(+), 7 deletions(-)

diff --git a/lib/fast-path.js b/lib/fast-path.js
index 255bd2a..017c57a 100644
--- a/lib/fast-path.js
+++ b/lib/fast-path.js
@@ -326,10 +326,12 @@ FPp.needsParens = function(assumeExpressionContext) {
         }
 
     case "ArrowFunctionExpression":
-        if(parent.type === 'CallExpression' && 
-           name === 'callee') {
+        if(n.CallExpression.check(parent) && name === 'callee') {
             return true;
-        };
+        }
+        if(n.MemberExpression.check(parent) && name === 'object') {
+            return true;
+        }
 
         return isBinary(parent);
 
diff --git a/lib/parser.js b/lib/parser.js
index 77308ca..db09a5e 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -64,7 +64,7 @@ exports.parse = function parse(source, options) {
     // comments, wrap the original Program node with a File node.
     var file = program;
     if (file.type === "Program") {
-        var file = b.file(program);
+        var file = b.file(program, options.sourceFileName || null);
         file.loc = {
             lines: lines,
             indent: 0,
diff --git a/lib/printer.js b/lib/printer.js
index 6a23cb2..283b728 100644
--- a/lib/printer.js
+++ b/lib/printer.js
@@ -1361,6 +1361,7 @@ function genericPrintNoParens(path, options, print) {
         ]);
 
     case "DeclareExportDeclaration":
+    case "DeclareExportAllDeclaration":
         return concat([
             "declare ",
             printExportDeclaration(path, options, print)
diff --git a/lib/util.js b/lib/util.js
index 9b22280..251cc84 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -156,6 +156,13 @@ util.fixFaultyLocations = function(node, lines) {
     }
   }
 
+  if (node.type === "File") {
+    // Babylon returns File nodes whose .loc.{start,end} do not include
+    // leading or trailing whitespace.
+    loc.start = lines.firstPos();
+    loc.end = lines.lastPos();
+  }
+
   if (node.type === "TemplateLiteral") {
     fixTemplateLiteral(node, lines);
 
diff --git a/package.json b/package.json
index e055939..de9f896 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
     "parsing",
     "pretty-printing"
   ],
-  "version": "0.11.18",
+  "version": "0.11.20",
   "homepage": "http://github.com/benjamn/recast",
   "repository": {
     "type": "git",
@@ -28,13 +28,13 @@
     "fs": false
   },
   "dependencies": {
-    "ast-types": "0.9.2",
+    "ast-types": "0.9.4",
     "esprima": "~3.1.0",
     "private": "~0.1.5",
     "source-map": "~0.5.0"
   },
   "devDependencies": {
-    "babylon": "~6.14.1",
+    "babylon": "~6.15.0",
     "esprima-fb": "^15001.1001.0-dev-harmony-fb",
     "mocha": "~3.1.2"
   },
diff --git a/test/babylon.js b/test/babylon.js
index 8a03142..83c6356 100644
--- a/test/babylon.js
+++ b/test/babylon.js
@@ -334,4 +334,39 @@ describe("decorators", function () {
       'x * y ** (x / y);'
     );
   });
+
+  it("should be able to replace top-level statements with leading empty lines", function () {
+    var code = [
+      '',
+      'if (test) {',
+      '  console.log(test);',
+      '}',
+    ].join('\n');
+
+    var ast = recast.parse(code, parseOptions);
+
+    var replacement = b.expressionStatement(
+      b.callExpression(
+        b.identifier('fn'),
+        [b.identifier('test'), b.literal(true)]
+      )
+    );
+
+    recast.types.visit(ast, {
+      visitIfStatement: function(path) {
+        path.replace(replacement);
+        return false;
+      }
+    });
+
+    // This also doesn't work:
+    // ast.program.body[0] = replacement;
+
+    // The `ast` contains the correct replacement nodes but the printed code
+    // is still the same as the original.
+    assert.strictEqual(
+      recast.print(ast).code,
+      'fn(test, true);'
+    );
+  });
 });
diff --git a/test/parens.js b/test/parens.js
index 2c36074..5ec82f6 100644
--- a/test/parens.js
+++ b/test/parens.js
@@ -283,4 +283,8 @@ describe("parens", function() {
         check("(()=>{})()");
         check("(function(){})()");
     });
+
+    it("should be added to bound arrow function expressions", function() {
+        check("(()=>{}).bind(x)");
+    });
 });
diff --git a/test/printer.js b/test/printer.js
index 6418c09..2efbbc7 100644
--- a/test/printer.js
+++ b/test/printer.js
@@ -1035,6 +1035,31 @@ describe("printer", function() {
       assert.strictEqual(pretty, code);
     });
 
+    it("adds parenthesis around arrow function when binding", function() {
+      var code = "var a = (x => y).bind(z);";
+
+      var fn = b.arrowFunctionExpression(
+          [b.identifier("x")],
+          b.identifier("y")
+      );
+
+      var declaration = b.variableDeclaration("var", [
+          b.variableDeclarator(
+              b.identifier("a"),
+              b.callExpression(
+                  b.memberExpression(fn, b.identifier("bind"), false),
+                  [b.identifier("z")]
+              )
+          )
+      ]);
+
+      var ast = b.program([declaration]);
+
+      var printer = new Printer();
+      var pretty = printer.printGenerically(ast).code;
+      assert.strictEqual(pretty, code);
+    });
+
     it("adds parenthesis around async arrow functions with args", function() {
         var code = "async () => {};";
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-recast.git



More information about the Pkg-javascript-commits mailing list