fix buildExternalHelpers whitelist not including underscored helpers - fixes #2940

This commit is contained in:
Sebastian McKenzie 2015-11-10 03:40:35 -08:00
parent 28a13bd400
commit a55f210c7f
2 changed files with 24 additions and 1 deletions

View File

@ -73,8 +73,26 @@ function buildVar(namespace, builder) {
}
function buildHelpers(body, namespace, whitelist) {
function shouldIgnore(name) {
if (!whitelist) {
return false;
}
// check for the raw name
if (whitelist.indexOf(name) >= 0) {
return false;
}
// typeof -> _typeof
if (name[0] === "_" && whitelist.indexOf(name.slice(1)) >= 0) {
return false;
}
return true;
}
each(helpers.list, function (name) {
if (whitelist && whitelist.indexOf(name) === -1) return;
if (shouldIgnore(name)) return;
let key = t.identifier(t.toIdentifier(name));
body.push(t.expressionStatement(

View File

@ -387,5 +387,10 @@ suite("api", function () {
assert.ok(script.indexOf("classCallCheck") === -1);
assert.ok(script.indexOf("inherits") === -1);
});
test("underscored", function () {
var script = buildExternalHelpers(["typeof"]);
assert.ok(script.indexOf("typeof") >= 0);
});
});
});