Replace non-inclusive "whitelist" and "blacklist" terms with "allowlist" etc. (#11758)

This commit is contained in:
Wojciech Maj 2020-06-29 21:39:38 +02:00 committed by GitHub
parent cfaa70dcf4
commit 1dd94e813e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 20 deletions

View File

@ -21,7 +21,7 @@ const buildUmdWrapper = replacements =>
}); });
`(replacements); `(replacements);
function buildGlobal(whitelist) { function buildGlobal(allowlist) {
const namespace = t.identifier("babelHelpers"); const namespace = t.identifier("babelHelpers");
const body = []; const body = [];
@ -60,14 +60,14 @@ function buildGlobal(whitelist) {
]), ]),
); );
buildHelpers(body, namespace, whitelist); buildHelpers(body, namespace, allowlist);
return tree; return tree;
} }
function buildModule(whitelist) { function buildModule(allowlist) {
const body = []; const body = [];
const refs = buildHelpers(body, null, whitelist); const refs = buildHelpers(body, null, allowlist);
body.unshift( body.unshift(
t.exportNamedDeclaration( t.exportNamedDeclaration(
@ -81,7 +81,7 @@ function buildModule(whitelist) {
return t.program(body, [], "module"); return t.program(body, [], "module");
} }
function buildUmd(whitelist) { function buildUmd(allowlist) {
const namespace = t.identifier("babelHelpers"); const namespace = t.identifier("babelHelpers");
const body = []; const body = [];
@ -91,7 +91,7 @@ function buildUmd(whitelist) {
]), ]),
); );
buildHelpers(body, namespace, whitelist); buildHelpers(body, namespace, allowlist);
return t.program([ return t.program([
buildUmdWrapper({ buildUmdWrapper({
@ -109,7 +109,7 @@ function buildUmd(whitelist) {
]); ]);
} }
function buildVar(whitelist) { function buildVar(allowlist) {
const namespace = t.identifier("babelHelpers"); const namespace = t.identifier("babelHelpers");
const body = []; const body = [];
@ -119,12 +119,12 @@ function buildVar(whitelist) {
]), ]),
); );
const tree = t.program(body); const tree = t.program(body);
buildHelpers(body, namespace, whitelist); buildHelpers(body, namespace, allowlist);
body.push(t.expressionStatement(namespace)); body.push(t.expressionStatement(namespace));
return tree; return tree;
} }
function buildHelpers(body, namespace, whitelist) { function buildHelpers(body, namespace, allowlist) {
const getHelperReference = name => { const getHelperReference = name => {
return namespace return namespace
? t.memberExpression(namespace, t.identifier(name)) ? t.memberExpression(namespace, t.identifier(name))
@ -133,7 +133,7 @@ function buildHelpers(body, namespace, whitelist) {
const refs = {}; const refs = {};
helpers.list.forEach(function (name) { helpers.list.forEach(function (name) {
if (whitelist && whitelist.indexOf(name) < 0) return; if (allowlist && allowlist.indexOf(name) < 0) return;
const ref = (refs[name] = getHelperReference(name)); const ref = (refs[name] = getHelperReference(name));
@ -145,7 +145,7 @@ function buildHelpers(body, namespace, whitelist) {
return refs; return refs;
} }
export default function ( export default function (
whitelist?: Array<string>, allowlist?: Array<string>,
outputType: "global" | "module" | "umd" | "var" = "global", outputType: "global" | "module" | "umd" | "var" = "global",
) { ) {
let tree; let tree;
@ -158,7 +158,7 @@ export default function (
}[outputType]; }[outputType];
if (build) { if (build) {
tree = build(whitelist); tree = build(allowlist);
} else { } else {
throw new Error(`Unsupported output type ${outputType}`); throw new Error(`Unsupported output type ${outputType}`);
} }

View File

@ -733,13 +733,13 @@ describe("api", function () {
expect(script).toEqual(expect.stringContaining("inherits")); expect(script).toEqual(expect.stringContaining("inherits"));
}); });
it("whitelist", function () { it("allowlist", function () {
const script = babel.buildExternalHelpers(["inherits"]); const script = babel.buildExternalHelpers(["inherits"]);
expect(script).not.toEqual(expect.stringContaining("classCallCheck")); expect(script).not.toEqual(expect.stringContaining("classCallCheck"));
expect(script).toEqual(expect.stringContaining("inherits")); expect(script).toEqual(expect.stringContaining("inherits"));
}); });
it("empty whitelist", function () { it("empty allowlist", function () {
const script = babel.buildExternalHelpers([]); const script = babel.buildExternalHelpers([]);
expect(script).not.toEqual(expect.stringContaining("classCallCheck")); expect(script).not.toEqual(expect.stringContaining("classCallCheck"));
expect(script).not.toEqual(expect.stringContaining("inherits")); expect(script).not.toEqual(expect.stringContaining("inherits"));

View File

@ -47,8 +47,8 @@ function assertDirectory(loc) {
} }
} }
function shouldIgnore(name, blacklist?: Array<string>) { function shouldIgnore(name, ignore?: Array<string>) {
if (blacklist && blacklist.indexOf(name) >= 0) { if (ignore && ignore.indexOf(name) >= 0) {
return true; return true;
} }

View File

@ -162,12 +162,12 @@ export function registerPresets(newPresets: {
} }
// All the plugins we should bundle // All the plugins we should bundle
// Want to get rid of this long whitelist of plugins? // Want to get rid of this long list of allowed plugins?
// Wait! Please read https://github.com/babel/babel/pull/6177 first. // Wait! Please read https://github.com/babel/babel/pull/6177 first.
registerPlugins(all); registerPlugins(all);
// All the presets we should bundle // All the presets we should bundle
// Want to get rid of this whitelist of presets? // Want to get rid of this list of allowed presets?
// Wait! Please read https://github.com/babel/babel/pull/6177 first. // Wait! Please read https://github.com/babel/babel/pull/6177 first.
registerPresets({ registerPresets({
env: presetEnv, env: presetEnv,

View File

@ -419,7 +419,7 @@ export default class Scope {
/** /**
* Determine whether evaluating the specific input `node` is a consequenceless reference. ie. * Determine whether evaluating the specific input `node` is a consequenceless reference. ie.
* evaluating it wont result in potentially arbitrary code from being ran. The following are * evaluating it wont result in potentially arbitrary code from being ran. The following are
* whitelisted and determined not to cause side effects: * allowed and determined not to cause side effects:
* *
* - `this` expressions * - `this` expressions
* - `super` expressions * - `super` expressions

View File

@ -471,7 +471,7 @@ describe("scope", () => {
}); });
if (kind1 !== kind2) { if (kind1 !== kind2) {
//todo: remove the if whitelist // todo: remove the if allowed
if (kind1 === "const" && (kind2 === "function" || kind2 === "var")) { if (kind1 === "const" && (kind2 === "function" || kind2 === "var")) {
continue; continue;
} }