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

Julien Puydt julien.puydt at laposte.net
Thu Feb 9 08:55:53 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 9fa859efbdeea5f6001c135ce24fb31ae65a874e
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Thu Feb 9 09:13:49 2017 +0100

    New upstream version 0.11.21
---
 lib/parser.js   |  5 +++++
 lib/patcher.js  | 15 ++++++++++++---
 lib/printer.js  |  3 +++
 package.json    |  4 ++--
 test/babylon.js | 26 ++++++++++----------------
 5 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/lib/parser.js b/lib/parser.js
index db09a5e..60a5164 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -142,6 +142,11 @@ TCp.copy = function(node) {
         var key = keys[i];
         if (key === "loc") {
             copy[key] = node[key];
+        } else if (key === "tokens" &&
+                   node.type === "File") {
+            // Preserve file.tokens (uncopied) in case client code cares
+            // about it, even though Recast ignores it when reprinting.
+            copy[key] = node[key];
         } else {
             copy[key] = this.copy(node[key]);
         }
diff --git a/lib/patcher.js b/lib/patcher.js
index ac21eff..7f2a3a1 100644
--- a/lib/patcher.js
+++ b/lib/patcher.js
@@ -496,10 +496,19 @@ function findChildReprints(newPath, oldPath, reprints) {
         return false;
     }
 
-    for (var k in util.getUnionOfKeys(newNode, oldNode)) {
-        if (k === "loc")
-            continue;
+    var keys = util.getUnionOfKeys(oldNode, newNode);
 
+    if (oldNode.type === "File" ||
+        newNode.type === "File") {
+        // Don't bother traversing file.tokens, an often very large array
+        // returned by Babylon, and useless for our purposes.
+        delete keys.tokens;
+    }
+
+    // Don't bother traversing .loc objects looking for reprintable nodes.
+    delete keys.loc;
+
+    for (var k in keys) {
         newPath.stack.push(k, types.getFieldValue(newNode, k));
         oldPath.stack.push(k, types.getFieldValue(oldNode, k));
         var canReprint = findAnyReprints(newPath, oldPath, reprints);
diff --git a/lib/printer.js b/lib/printer.js
index 283b728..ca255b4 100644
--- a/lib/printer.js
+++ b/lib/printer.js
@@ -486,6 +486,9 @@ function genericPrintNoParens(path, options, print) {
     case "ExportDefaultSpecifier":
         return path.call(print, "exported");
 
+    case "Import":
+        return fromString("import", options);
+
     case "ImportDeclaration":
         parts.push("import ");
 
diff --git a/package.json b/package.json
index de9f896..97d86e6 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
     "parsing",
     "pretty-printing"
   ],
-  "version": "0.11.20",
+  "version": "0.11.21",
   "homepage": "http://github.com/benjamn/recast",
   "repository": {
     "type": "git",
@@ -28,7 +28,7 @@
     "fs": false
   },
   "dependencies": {
-    "ast-types": "0.9.4",
+    "ast-types": "0.9.5",
     "esprima": "~3.1.0",
     "private": "~0.1.5",
     "source-map": "~0.5.0"
diff --git a/test/babylon.js b/test/babylon.js
index 83c6356..2140773 100644
--- a/test/babylon.js
+++ b/test/babylon.js
@@ -10,22 +10,7 @@ describe("decorators", function () {
     sourceType: 'module',
     allowImportExportEverywhere: false,
     allowReturnOutsideFunction: false,
-    plugins: [
-      'asyncFunctions',
-      'asyncGenerators',
-      'classConstructorCall',
-      'classProperties',
-      'decorators',
-      'doExpressions',
-      'exponentiationOperator',
-      'exportExtensions',
-      'flow',
-      'functionSent',
-      'functionBind',
-      'jsx',
-      'objectRestSpread',
-      'trailingFunctionCommas'
-    ]
+    plugins: ["*", "jsx", "flow"]
   };
 
   var parseOptions = {
@@ -369,4 +354,13 @@ describe("decorators", function () {
       'fn(test, true);'
     );
   });
+
+  it("should parse and print dynamic import(...)", function () {
+    var code = 'wait(import("oyez"));';
+    var ast = recast.parse(code, parseOptions);
+    assert.strictEqual(
+      recast.prettyPrint(ast).code,
+      code
+    );
+  });
 });

-- 
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