From 5f0e9769a999fa278a03d789fa8142efcd373d76 Mon Sep 17 00:00:00 2001 From: ssuman Date: Sun, 9 Apr 2017 19:49:37 -0400 Subject: [PATCH] Increase the code coverage for traverse evaluation (#5363) * When applied this commit will increase the code coverage for evaluation.js * Fixing linting issues --- packages/babel-traverse/test/evaluation.js | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/babel-traverse/test/evaluation.js b/packages/babel-traverse/test/evaluation.js index 1269f7c01371..dd2f93af8a16 100644 --- a/packages/babel-traverse/test/evaluation.js +++ b/packages/babel-traverse/test/evaluation.js @@ -61,6 +61,27 @@ describe("evaluation", function () { ); }); + it("should evaluate template literals", function () { + assert.strictEqual( + getPath("var x = 8; var y = 1; var z = `value is ${x >>> y}`") + .get("body.2.declarations.0.init").evaluate().value, + "value is 4" + ); + }); + + it("should evaluate member expressions", function () { + assert.strictEqual( + getPath("var x = 'foo'.length") + .get("body.0.declarations.0.init").evaluate().value, + 3 + ); + const member_expr = getPath("var x = Math.min(2,Math.max(3,4));var y = Math.random();"); + const eval_member_expr = member_expr.get("body.0.declarations.0.init").evaluate(); + const eval_invalid_call = member_expr.get("body.1.declarations.0.init").evaluate(); + assert.strictEqual(eval_member_expr.value, 2); + assert.strictEqual(eval_invalid_call.confident, false); + }); + it("it should not deopt vars in different scope", function () { const input = "var a = 5; function x() { var a = 5; var b = a + 1; } var b = a + 2"; assert.strictEqual( @@ -88,6 +109,12 @@ describe("evaluation", function () { getPath(constExample).get("body.1.consequent.body.1").evaluate().value, false ); + const test_alternate = "var y = (3 < 4)? 3 + 4: 3 + 4;"; + assert.strictEqual( + getPath(test_alternate) + .get("body.0.declarations.0.init.alternate").evaluate().value, + 7 + ); }); it("should deopt ids that are referenced before the bindings", function () {