Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the code coverage for traverse evaluation #5363

Merged
merged 3 commits into from Apr 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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