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

babel-traverse: prefer clearer, reduced-bias option naming #11791

Merged
merged 3 commits into from Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 6 additions & 6 deletions packages/babel-traverse/src/index.js
Expand Up @@ -77,7 +77,7 @@ traverse.removeProperties = function (tree, opts) {
return tree;
};

function hasBlacklistedType(path, state) {
function hasDenylistedType(path, state) {
if (path.node.type === state.type) {
state.has = true;
path.stop();
Expand All @@ -87,10 +87,10 @@ function hasBlacklistedType(path, state) {
traverse.hasType = function (
tree: Object,
type: Object,
blacklistTypes: Array<string>,
denylistTypes: Array<string>,
): boolean {
// the node we're searching in is blacklisted
if (includes(blacklistTypes, tree.type)) return false;
// the node we're searching in is denylisted
if (includes(denylistTypes, tree.type)) return false;

// the type we're looking for is the same as the passed node
if (tree.type === type) return true;
Expand All @@ -104,8 +104,8 @@ traverse.hasType = function (
tree,
{
noScope: true,
blacklist: blacklistTypes,
enter: hasBlacklistedType,
denylist: denylistTypes,
enter: hasDenylistedType,
},
null,
state,
Expand Down
11 changes: 7 additions & 4 deletions packages/babel-traverse/src/path/context.js
Expand Up @@ -51,17 +51,20 @@ export function _call(fns?: Array<Function>): boolean {
return false;
}

export function isBlacklisted(): boolean {
const blacklist = this.opts.blacklist;
return blacklist && blacklist.indexOf(this.node.type) > -1;
export function isDenylisted(): boolean {
const denylist = this.opts.denylist ?? this.opts.blacklist;
return denylist && denylist.indexOf(this.node.type) > -1;
}
jayaddison marked this conversation as resolved.
Show resolved Hide resolved

// TODO: Remove in Babel 8
export { isDenylisted as isBlacklisted };

export function visit(): boolean {
if (!this.node) {
return false;
}

if (this.isBlacklisted()) {
if (this.isDenylisted()) {
return false;
}

Expand Down
8 changes: 7 additions & 1 deletion packages/babel-traverse/src/visitors.js
Expand Up @@ -275,7 +275,13 @@ function shouldIgnoreKey(key) {
if (key === "enter" || key === "exit" || key === "shouldSkip") return true;

// ignore other options
if (key === "blacklist" || key === "noScope" || key === "skipKeys") {
if (
key === "denylist" ||
key === "noScope" ||
key === "skipKeys" ||
// TODO: Remove in Babel 8
key === "blacklist"
) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-traverse/test/traverse.js
Expand Up @@ -61,7 +61,7 @@ describe("traverse", function () {
});
});

it("traverse blacklistTypes", function () {
it("traverse denylistTypes", function () {
const expected = [
body[0],
body[0].declarations[0],
Expand All @@ -75,7 +75,7 @@ describe("traverse", function () {
const actual = [];

traverse(program, {
blacklist: ["MemberExpression"],
denylist: ["MemberExpression"],
enter: function (path) {
actual.push(path.node);
},
Expand Down