babel-traverse: prefer clearer, reduced-bias option naming (#11791)
* babel-traverse: prefer clearer, reduced-bias option naming * Apply suggestions from code review Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
parent
cf425a0bde
commit
9daa50e005
@ -76,7 +76,7 @@ traverse.removeProperties = function (tree, opts) {
|
|||||||
return tree;
|
return tree;
|
||||||
};
|
};
|
||||||
|
|
||||||
function hasBlacklistedType(path, state) {
|
function hasDenylistedType(path, state) {
|
||||||
if (path.node.type === state.type) {
|
if (path.node.type === state.type) {
|
||||||
state.has = true;
|
state.has = true;
|
||||||
path.stop();
|
path.stop();
|
||||||
@ -86,10 +86,10 @@ function hasBlacklistedType(path, state) {
|
|||||||
traverse.hasType = function (
|
traverse.hasType = function (
|
||||||
tree: Object,
|
tree: Object,
|
||||||
type: Object,
|
type: Object,
|
||||||
blacklistTypes?: Array<string>,
|
denylistTypes?: Array<string>,
|
||||||
): boolean {
|
): boolean {
|
||||||
// the node we're searching in is blacklisted
|
// the node we're searching in is denylisted
|
||||||
if (blacklistTypes?.includes(tree.type)) return false;
|
if (denylistTypes?.includes(tree.type)) return false;
|
||||||
|
|
||||||
// the type we're looking for is the same as the passed node
|
// the type we're looking for is the same as the passed node
|
||||||
if (tree.type === type) return true;
|
if (tree.type === type) return true;
|
||||||
@ -103,8 +103,8 @@ traverse.hasType = function (
|
|||||||
tree,
|
tree,
|
||||||
{
|
{
|
||||||
noScope: true,
|
noScope: true,
|
||||||
blacklist: blacklistTypes,
|
denylist: denylistTypes,
|
||||||
enter: hasBlacklistedType,
|
enter: hasDenylistedType,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
state,
|
state,
|
||||||
|
|||||||
@ -51,17 +51,20 @@ export function _call(fns?: Array<Function>): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isBlacklisted(): boolean {
|
export function isDenylisted(): boolean {
|
||||||
const blacklist = this.opts.blacklist;
|
const denylist = this.opts.denylist ?? this.opts.blacklist;
|
||||||
return blacklist && blacklist.indexOf(this.node.type) > -1;
|
return denylist && denylist.indexOf(this.node.type) > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove in Babel 8
|
||||||
|
export { isDenylisted as isBlacklisted };
|
||||||
|
|
||||||
export function visit(): boolean {
|
export function visit(): boolean {
|
||||||
if (!this.node) {
|
if (!this.node) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isBlacklisted()) {
|
if (this.isDenylisted()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -274,7 +274,13 @@ function shouldIgnoreKey(key) {
|
|||||||
if (key === "enter" || key === "exit" || key === "shouldSkip") return true;
|
if (key === "enter" || key === "exit" || key === "shouldSkip") return true;
|
||||||
|
|
||||||
// ignore other options
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,7 @@ describe("traverse", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("traverse blacklistTypes", function () {
|
it("traverse denylistTypes", function () {
|
||||||
const expected = [
|
const expected = [
|
||||||
body[0],
|
body[0],
|
||||||
body[0].declarations[0],
|
body[0].declarations[0],
|
||||||
@ -75,7 +75,7 @@ describe("traverse", function () {
|
|||||||
const actual = [];
|
const actual = [];
|
||||||
|
|
||||||
traverse(program, {
|
traverse(program, {
|
||||||
blacklist: ["MemberExpression"],
|
denylist: ["MemberExpression"],
|
||||||
enter: function (path) {
|
enter: function (path) {
|
||||||
actual.push(path.node);
|
actual.push(path.node);
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user