Skip to content

Commit

Permalink
Increase the code coverage for traverse evaluation (babel#5363)
Browse files Browse the repository at this point in the history
* When applied this commit will increase the code coverage for evaluation.js

* Fixing linting issues
  • Loading branch information
ssuman authored and jridgewell committed May 3, 2017
1 parent 16f1d60 commit b16689f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/babel-traverse/test/evaluation.js
Expand Up @@ -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(
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit b16689f

Please sign in to comment.