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

Julien Puydt julien.puydt at laposte.net
Tue Jul 11 09:20:51 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 709518b2ea032cc8658da83bc7a1092d0ae1da05
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Tue Jul 11 11:20:13 2017 +0200

    New upstream version 0.12.6
---
 lib/fast-path.js |  10 +-
 package.json     |   4 +-
 test/es6tests.js | 558 +++++++++++++++++++++++++++----------------------------
 test/parens.js   |   5 +
 4 files changed, 295 insertions(+), 282 deletions(-)

diff --git a/lib/fast-path.js b/lib/fast-path.js
index cb353a5..94e280a 100644
--- a/lib/fast-path.js
+++ b/lib/fast-path.js
@@ -183,13 +183,21 @@ FPp.map = function map(callback/*, name1, name2, ... */) {
 // Inspired by require("ast-types").NodePath.prototype.needsParens, but
 // more efficient because we're iterating backwards through a stack.
 FPp.needsParens = function(assumeExpressionContext) {
+  var node = this.getNode();
+
+  // This needs to come before `if (!parent) { return false }` because
+  // an object destructuring assignment requires parens for
+  // correctness even when it's the topmost expression.
+  if (node.type === "AssignmentExpression" && node.left.type === 'ObjectPattern') {
+    return true;
+  }
+
   var parent = this.getParentNode();
   if (!parent) {
     return false;
   }
 
   var name = this.getName();
-  var node = this.getNode();
 
   // If the value of this path is some child of a Node and not a Node
   // itself, then it doesn't need parentheses. Only Node objects (in fact,
diff --git a/package.json b/package.json
index 6cf60a3..39269e9 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
     "parsing",
     "pretty-printing"
   ],
-  "version": "0.12.5",
+  "version": "0.12.6",
   "homepage": "http://github.com/benjamn/recast",
   "repository": {
     "type": "git",
@@ -30,7 +30,7 @@
   "dependencies": {
     "ast-types": "0.9.11",
     "core-js": "^2.4.1",
-    "esprima": "~3.1.0",
+    "esprima": "~4.0.0",
     "private": "~0.1.5",
     "source-map": "~0.5.0"
   },
diff --git a/test/es6tests.js b/test/es6tests.js
index 70e4535..d28a097 100644
--- a/test/es6tests.js
+++ b/test/es6tests.js
@@ -7,289 +7,289 @@ var b = types.builders;
 var eol = require("os").EOL;
 
 describe("ES6 Compatability", function() {
-    function convertShorthandMethod() {
-        var printer = new Printer({ tabWidth: 2 });
-
-        var code = [
-            "var name='test-name';",
-            "var shorthandObj = {",
-            "  name,",
-            "  func() { return 'value'; }",
-            "};"
-        ].join(eol);
-
-        var ast = parse(code);
-        n.VariableDeclaration.assert(ast.program.body[1]);
-
-        var shorthandObjDec = ast.program.body[1].declarations[0].init;
-        var methodDecProperty = shorthandObjDec.properties[1];
-        var newES5MethodProperty = b.property(
-            methodDecProperty.kind,
-            methodDecProperty.key,
-            methodDecProperty.value,
-            false,
-            false
-        );
-
-        var correctMethodProperty = b.property(
-            methodDecProperty.kind,
-            methodDecProperty.key,
-            b.functionExpression(
-                methodDecProperty.value.id,
-                methodDecProperty.value.params,
-                methodDecProperty.value.body,
-                methodDecProperty.value.generator,
-                methodDecProperty.value.expression
-            ),
-            false,
-            false
-        );
-
-        assert.strictEqual(
-            printer.print(newES5MethodProperty).code,
-            printer.print(correctMethodProperty).code
-        );
-    }
-
-    it("correctly converts from a shorthand method to ES5 function",
-       convertShorthandMethod);
-
-    function respectDestructuringAssignment() {
-        var printer = new Printer({ tabWidth: 2 });
-        var code = 'var {a} = {};';
-        var ast = parse(code);
-        n.VariableDeclaration.assert(ast.program.body[0]);
-        assert.strictEqual(printer.print(ast).code, code);
-    }
+  function convertShorthandMethod() {
+    var printer = new Printer({ tabWidth: 2 });
 
-    it("respects destructuring assignments",
-       respectDestructuringAssignment);
+    var code = [
+      "var name='test-name';",
+      "var shorthandObj = {",
+      "  name,",
+      "  func() { return 'value'; }",
+      "};"
+    ].join(eol);
+
+    var ast = parse(code);
+    n.VariableDeclaration.assert(ast.program.body[1]);
+
+    var shorthandObjDec = ast.program.body[1].declarations[0].init;
+    var methodDecProperty = shorthandObjDec.properties[1];
+    var newES5MethodProperty = b.property(
+      methodDecProperty.kind,
+      methodDecProperty.key,
+      methodDecProperty.value,
+      false,
+      false
+    );
+
+    var correctMethodProperty = b.property(
+      methodDecProperty.kind,
+      methodDecProperty.key,
+      b.functionExpression(
+        methodDecProperty.value.id,
+        methodDecProperty.value.params,
+        methodDecProperty.value.body,
+        methodDecProperty.value.generator,
+        methodDecProperty.value.expression
+      ),
+      false,
+      false
+    );
+
+    assert.strictEqual(
+      printer.print(newES5MethodProperty).code,
+      printer.print(correctMethodProperty).code
+    );
+  }
+
+  it("correctly converts from a shorthand method to ES5 function",
+     convertShorthandMethod);
+
+  function respectDestructuringAssignment() {
+    var printer = new Printer({ tabWidth: 2 });
+    var code = 'var {a} = {};';
+    var ast = parse(code);
+    n.VariableDeclaration.assert(ast.program.body[0]);
+    assert.strictEqual(printer.print(ast).code, code);
+  }
+
+  it("respects destructuring assignments",
+     respectDestructuringAssignment);
 });
 
 describe("import/export syntax", function() {
-    var printer = new Printer({ tabWidth: 2 });
-
-    function check(source) {
-        var ast1 = parse(source);
-        var ast2 = parse(printer.printGenerically(ast1).code);
-        types.astNodesAreEquivalent.assert(ast1, ast2);
+  var printer = new Printer({ tabWidth: 2 });
+
+  function check(source) {
+    var ast1 = parse(source);
+    var ast2 = parse(printer.printGenerically(ast1).code);
+    types.astNodesAreEquivalent.assert(ast1, ast2);
+  }
+
+  it("should parse and print import statements correctly", function() {
+    check("import foo from 'foo'");
+
+    // default imports
+    check("import foo from 'foo';");
+    check("import {default as foo} from 'foo';");
+
+    // named imports
+    check("import {bar} from 'foo';");
+    check("import {bar, baz} from 'foo';");
+    check("import {bar as baz} from 'foo';");
+    check("import {bar as baz, xyz} from 'foo';");
+
+    // glob imports
+    check("import * as foo from 'foo';");
+
+    // mixing imports
+    check("import foo, {baz as xyz} from 'foo';");
+    check("import foo, * as bar from 'foo';");
+
+    // just import
+    check("import 'foo';");
+  });
+
+  it("should parse and print export statements correctly", function() {
+    // default exports
+    check("export default 42;");
+    check("export default {};");
+    check("export default [];");
+    check("export default foo;");
+    check("export default function () {}");
+    check("export default class {}");
+    check("export default function foo () {}");
+    check("export default class foo {}");
+
+    // variables exports
+    check("export var foo = 1;");
+    check("export var foo = function () {};");
+    check("export var bar;"); // lazy initialization
+    check("export let foo = 2;");
+    check("export let bar;"); // lazy initialization
+    check("export const foo = 3;");
+    check("export function foo () {}");
+    check("export class foo {}");
+
+    // named exports
+    check("export {foo};");
+    check("export {foo, bar};");
+    check("export {foo as bar};");
+    check("export {foo as default};");
+    check("export {foo as default, bar};");
+
+    // exports from
+    check("export * from 'foo';");
+    check("export {foo} from 'foo';");
+    check("export {foo, bar} from 'foo';");
+    check("export {foo as bar} from 'foo';");
+    check("export {foo as default} from 'foo';");
+    check("export {foo as default, bar} from 'foo';");
+    check("export {default} from 'foo';");
+    check("export {default as foo} from 'foo';");
+  });
+
+  it("should forbid invalid import/export syntax", function() {
+    function checkInvalid(source, expectedMessage) {
+      try {
+        parse(source);
+        throw new Error("Parsing should have failed: " +
+                        JSON.stringify(source));
+      } catch (err) {
+        assert.strictEqual(err.message, "Line 1: " + expectedMessage);
+      }
     }
 
-    it("should parse and print import statements correctly", function() {
-        check("import foo from 'foo'");
-
-        // default imports
-        check("import foo from 'foo';");
-        check("import {default as foo} from 'foo';");
-
-        // named imports
-        check("import {bar} from 'foo';");
-        check("import {bar, baz} from 'foo';");
-        check("import {bar as baz} from 'foo';");
-        check("import {bar as baz, xyz} from 'foo';");
-
-        // glob imports
-        check("import * as foo from 'foo';");
-
-        // mixing imports
-        check("import foo, {baz as xyz} from 'foo';");
-        check("import foo, * as bar from 'foo';");
-
-        // just import
-        check("import 'foo';");
-    });
-
-    it("should parse and print export statements correctly", function() {
-        // default exports
-        check("export default 42;");
-        check("export default {};");
-        check("export default [];");
-        check("export default foo;");
-        check("export default function () {}");
-        check("export default class {}");
-        check("export default function foo () {}");
-        check("export default class foo {}");
-
-        // variables exports
-        check("export var foo = 1;");
-        check("export var foo = function () {};");
-        check("export var bar;"); // lazy initialization
-        check("export let foo = 2;");
-        check("export let bar;"); // lazy initialization
-        check("export const foo = 3;");
-        check("export function foo () {}");
-        check("export class foo {}");
-
-        // named exports
-        check("export {foo};");
-        check("export {foo, bar};");
-        check("export {foo as bar};");
-        check("export {foo as default};");
-        check("export {foo as default, bar};");
-
-        // exports from
-        check("export * from 'foo';");
-        check("export {foo} from 'foo';");
-        check("export {foo, bar} from 'foo';");
-        check("export {foo as bar} from 'foo';");
-        check("export {foo as default} from 'foo';");
-        check("export {foo as default, bar} from 'foo';");
-        check("export {default} from 'foo';");
-        check("export {default as foo} from 'foo';");
-    });
-
-    it("should forbid invalid import/export syntax", function() {
-        function checkInvalid(source, expectedMessage) {
-            try {
-                parse(source);
-                throw new Error("Parsing should have failed: " +
-                                JSON.stringify(source));
-            } catch (err) {
-                assert.strictEqual(err.message, "Line 1: " + expectedMessage);
-            }
-        }
-
-        // const variables must have an initializer
-        checkInvalid(
-            "export const bar;",
-            "Unexpected token ;"
-        );
-
-        // Unexpected token identifier, invalid named export syntax
-        checkInvalid(
-            "export foo;",
-            "Unexpected identifier"
-        );
-
-        // Unexpected token (, use a function declaration instead
-        checkInvalid(
-            "export function () {}",
-            "Unexpected token ("
-        );
-
-        // Unexpected token default
-        checkInvalid(
-            "export function default () {}",
-            "Unexpected token default"
-        );
-
-        // Missing from after import
-        checkInvalid(
-            "import foo;",
-            "Unexpected token ;"
-        );
-
-        // Missing from after import
-        checkInvalid(
-            "import { foo, bar };",
-            "Unexpected token ;"
-        );
-
-        // Invalid module specifier
-        checkInvalid(
-            "import foo from bar;",
-            "Unexpected token"
-        );
-
-        // Unexpected token default
-        checkInvalid(
-            "import default from 'foo';",
-            "Unexpected token default"
-        );
-
-        // Unexpected token from
-        checkInvalid(
-            "export default from 'foo';",
-            "Unexpected token from"
-        );
-
-        // Missing from after export
-        checkInvalid(
-            "export {default};",
-            "Unexpected token ;"
-        );
-
-        // Missing from after export
-        checkInvalid(
-            "export *;",
-            "Unexpected token ;"
-        );
-
-        // Missing from after import
-        checkInvalid(
-            "import {default as foo};",
-            "Unexpected token ;"
-        );
-
-        // Missing as after import *
-        checkInvalid(
-            "import * from 'foo';",
-            "Unexpected token"
-        );
-
-        // Unexpected token =
-        checkInvalid(
-            "export default = 42;",
-            "Unexpected token ="
-        );
-
-        // Unexpected token default
-        checkInvalid(
-            "import {bar as default} from 'foo';",
-            "Unexpected token default"
-        );
-
-        // Unexpected token ,
-        checkInvalid(
-            "import foo, * as bar, {baz as xyz} from 'foo';",
-            "Unexpected token ,"
-        );
-
-        // Unexpected token ,
-        checkInvalid(
-            "import {bar}, foo from 'foo';",
-            "Unexpected token ,"
-        );
-
-        // Unexpected token ,
-        checkInvalid(
-            "import {bar}, * as foo from 'foo';",
-            "Unexpected token ,"
-        );
-
-        // Unexpected token ,
-        checkInvalid(
-            "import foo, {bar}, foo from 'foo';",
-            "Unexpected token ,"
-        );
-
-        // Unexpected token ,
-        checkInvalid(
-            "import {bar}, {foo} from 'foo';",
-            "Unexpected token ,"
-        );
-
-        // Unexpected token ,
-        checkInvalid(
-            "import * as bar, {baz as xyz} from 'foo';",
-            "Unexpected token ,"
-        );
-    });
-
-    it("should pretty-print template strings with backticks", function() {
-        var code = [
-            'var noun = "fool";',
-            'var s = `I am a ${noun}`;',
-            'var t = tag`You said: ${s}!`;'
-        ].join(eol);
-
-        var ast = parse(code);
-
-        assert.strictEqual(
-            new Printer({
-                tabWidth: 2
-            }).printGenerically(ast).code,
-            code
-        );
-    });
+    // const variables must have an initializer
+    checkInvalid(
+      "export const bar;",
+      "Missing initializer in const declaration"
+    );
+
+    // Unexpected token identifier, invalid named export syntax
+    checkInvalid(
+      "export foo;",
+      "Unexpected identifier"
+    );
+
+    // Unexpected token (, use a function declaration instead
+    checkInvalid(
+      "export function () {}",
+      "Unexpected token ("
+    );
+
+    // Unexpected token default
+    checkInvalid(
+      "export function default () {}",
+      "Unexpected token default"
+    );
+
+    // Missing from after import
+    checkInvalid(
+      "import foo;",
+      "Unexpected token ;"
+    );
+
+    // Missing from after import
+    checkInvalid(
+      "import { foo, bar };",
+      "Unexpected token ;"
+    );
+
+    // Invalid module specifier
+    checkInvalid(
+      "import foo from bar;",
+      "Unexpected token"
+    );
+
+    // Unexpected token default
+    checkInvalid(
+      "import default from 'foo';",
+      "Unexpected token default"
+    );
+
+    // Unexpected token from
+    checkInvalid(
+      "export default from 'foo';",
+      "Unexpected token from"
+    );
+
+    // Missing from after export
+    checkInvalid(
+      "export {default};",
+      "Unexpected token ;"
+    );
+
+    // Missing from after export
+    checkInvalid(
+      "export *;",
+      "Unexpected token ;"
+    );
+
+    // Missing from after import
+    checkInvalid(
+      "import {default as foo};",
+      "Unexpected token ;"
+    );
+
+    // Missing as after import *
+    checkInvalid(
+      "import * from 'foo';",
+      "Unexpected token"
+    );
+
+    // Unexpected token =
+    checkInvalid(
+      "export default = 42;",
+      "Unexpected token ="
+    );
+
+    // Unexpected token default
+    checkInvalid(
+      "import {bar as default} from 'foo';",
+      "Unexpected token default"
+    );
+
+    // Unexpected token ,
+    checkInvalid(
+      "import foo, * as bar, {baz as xyz} from 'foo';",
+      "Unexpected token ,"
+    );
+
+    // Unexpected token ,
+    checkInvalid(
+      "import {bar}, foo from 'foo';",
+      "Unexpected token ,"
+    );
+
+    // Unexpected token ,
+    checkInvalid(
+      "import {bar}, * as foo from 'foo';",
+      "Unexpected token ,"
+    );
+
+    // Unexpected token ,
+    checkInvalid(
+      "import foo, {bar}, foo from 'foo';",
+      "Unexpected token ,"
+    );
+
+    // Unexpected token ,
+    checkInvalid(
+      "import {bar}, {foo} from 'foo';",
+      "Unexpected token ,"
+    );
+
+    // Unexpected token ,
+    checkInvalid(
+      "import * as bar, {baz as xyz} from 'foo';",
+      "Unexpected token ,"
+    );
+  });
+
+  it("should pretty-print template strings with backticks", function() {
+    var code = [
+      'var noun = "fool";',
+      'var s = `I am a ${noun}`;',
+      'var t = tag`You said: ${s}!`;'
+    ].join(eol);
+
+    var ast = parse(code);
+
+    assert.strictEqual(
+      new Printer({
+        tabWidth: 2
+      }).printGenerically(ast).code,
+      code
+    );
+  });
 });
diff --git a/test/parens.js b/test/parens.js
index 5ec82f6..c290501 100644
--- a/test/parens.js
+++ b/test/parens.js
@@ -287,4 +287,9 @@ describe("parens", function() {
     it("should be added to bound arrow function expressions", function() {
         check("(()=>{}).bind(x)");
     });
+
+    it("should be added to object destructuring assignment expressions", function() {
+        check("({x}={x:1})");
+    });
+
 });

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