Skip to content
Permalink
Browse files
Get rid typeof undef in all lib
  • Loading branch information
Connormiha committed Aug 21, 2018
1 parent efa69cd commit 1f954b4f1281f2bb97492fcd911d270efb097fd5
Showing 22 changed files with 39 additions and 60 deletions.
@@ -30,7 +30,7 @@ class CompatibilityPlugin {
.for("javascript/auto")
.tap("CompatibilityPlugin", (parser, parserOptions) => {
if (
typeof parserOptions.browserify !== "undefined" &&
parserOptions.browserify !== undefined &&
!parserOptions.browserify
)
return;
@@ -60,7 +60,7 @@ class EnvironmentPlugin {
}

defs[`process.env.${key}`] =
typeof value === "undefined" ? "undefined" : JSON.stringify(value);
value === undefined ? "undefined" : JSON.stringify(value);

return defs;
}, {});
@@ -27,7 +27,7 @@ class ExternalModuleFactoryPlugin {
}
if (value === false) return factory(data, callback);
if (value === true) value = dependency.request;
if (typeof type === "undefined" && /^[a-z0-9]+ /.test(value)) {
if (type === undefined && /^[a-z0-9]+ /.test(value)) {
const idx = value.indexOf(" ");
type = value.substr(0, idx);
value = value.substr(idx + 1);
@@ -81,7 +81,7 @@ class ExternalModuleFactoryPlugin {
dependency.request,
(err, value, type) => {
if (err) return callback(err);
if (typeof value !== "undefined") {
if (value !== undefined) {
handleExternal(value, type, callback);
} else {
callback();
@@ -105,15 +105,15 @@ module.exports = function() {
// Module API
active: true,
accept: function(dep, callback) {
if (typeof dep === "undefined") hot._selfAccepted = true;
if (dep === undefined) hot._selfAccepted = true;
else if (typeof dep === "function") hot._selfAccepted = dep;
else if (typeof dep === "object")
for (var i = 0; i < dep.length; i++)
hot._acceptedDependencies[dep[i]] = callback || function() {};
else hot._acceptedDependencies[dep] = callback || function() {};
},
decline: function(dep) {
if (typeof dep === "undefined") hot._selfDeclined = true;
if (dep === undefined) hot._selfDeclined = true;
else if (typeof dep === "object")
for (var i = 0; i < dep.length; i++)
hot._declinedDependencies[dep[i]] = true;
@@ -30,7 +30,7 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
if (idx === accessors.length - 1) return a;
if (idx === 0 && typeof base === "undefined") {
if (idx === 0 && base === undefined) {
return `${a} = typeof ${a} === "object" ? ${a} : {}`;
}
return `${a} = ${a} || {}`;
@@ -40,11 +40,11 @@ class MultiStats {
return obj;
});
const showVersion =
typeof options.version === "undefined"
options.version === undefined
? jsons.every(j => j.version)
: options.version !== false;
const showHash =
typeof options.hash === "undefined"
options.hash === undefined
? jsons.every(j => j.hash)
: options.hash !== false;
if (showVersion) {
@@ -16,8 +16,7 @@ const getProperty = (obj, name) => {
const setProperty = (obj, name, value) => {
name = name.split(".");
for (let i = 0; i < name.length - 1; i++) {
if (typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined")
return;
if (typeof obj[name[i]] !== "object" && obj[name[i]] !== undefined) return;
if (Array.isArray(obj[name[i]])) return;
if (!obj[name[i]]) obj[name[i]] = {};
obj = obj[name[i]];
@@ -19,10 +19,7 @@ module.exports = class RequireJsStuffPlugin {
new ConstDependency.Template()
);
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireJs !== "undefined" &&
!parserOptions.requireJs
)
if (parserOptions.requireJs !== undefined && !parserOptions.requireJs)
return;

parser.hooks.call
@@ -13,7 +13,7 @@ const compareLocations = require("./compareLocations");
const optionsOrFallback = (...args) => {
let optionValues = [];
optionValues.push(...args);
return optionValues.find(optionValue => typeof optionValue !== "undefined");
return optionValues.find(optionValue => optionValue !== undefined);
};

const compareId = (a, b) => {
@@ -105,11 +105,7 @@ class Stats {
}

const optionOrLocalFallback = (v, def) =>
typeof v !== "undefined"
? v
: typeof options.all !== "undefined"
? options.all
: def;
v !== undefined ? v : options.all !== undefined ? options.all : def;

const testAgainstGivenOption = item => {
if (typeof item === "string") {
@@ -31,7 +31,7 @@ const accessorAccess = (base, accessor, joinWith = ", ") => {
? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
if (idx === accessors.length - 1) return a;
if (idx === 0 && typeof base === "undefined")
if (idx === 0 && base === undefined)
return `${a} = typeof ${a} === "object" ? ${a} : {}`;
return `${a} = ${a} || {}`;
})
@@ -147,7 +147,7 @@ class UmdMainTemplatePlugin {
if (typeof request === "object") {
request = request[type];
}
if (typeof request === "undefined") {
if (request === undefined) {
throw new Error(
"Missing external configuration for type:" + type
);
@@ -98,8 +98,7 @@ class AMDPlugin {
);

const handler = (parser, parserOptions) => {
if (typeof parserOptions.amd !== "undefined" && !parserOptions.amd)
return;
if (parserOptions.amd !== undefined && !parserOptions.amd) return;

const setExpressionToModule = (outerExpr, module) => {
parser.hooks.expression.for(outerExpr).tap("AMDPlugin", expr => {
@@ -83,10 +83,7 @@ class CommonJsPlugin {
);

const handler = (parser, parserOptions) => {
if (
typeof parserOptions.commonjs !== "undefined" &&
!parserOptions.commonjs
)
if (parserOptions.commonjs !== undefined && !parserOptions.commonjs)
return;

const requireExpressions = [
@@ -121,10 +121,7 @@ class HarmonyModulesPlugin {
);

const handler = (parser, parserOptions) => {
if (
typeof parserOptions.harmony !== "undefined" &&
!parserOptions.harmony
)
if (parserOptions.harmony !== undefined && !parserOptions.harmony)
return;

new HarmonyDetectionParserPlugin().apply(parser);
@@ -54,7 +54,7 @@ class ImportParserPlugin {
}

if (importOptions) {
if (typeof importOptions.webpackIgnore !== "undefined") {
if (importOptions.webpackIgnore !== undefined) {
if (typeof importOptions.webpackIgnore !== "boolean") {
parser.state.module.warnings.push(
new UnsupportedFeatureWarning(
@@ -72,7 +72,7 @@ class ImportParserPlugin {
}
}
}
if (typeof importOptions.webpackChunkName !== "undefined") {
if (importOptions.webpackChunkName !== undefined) {
if (typeof importOptions.webpackChunkName !== "string") {
parser.state.module.warnings.push(
new UnsupportedFeatureWarning(
@@ -87,7 +87,7 @@ class ImportParserPlugin {
chunkName = importOptions.webpackChunkName;
}
}
if (typeof importOptions.webpackMode !== "undefined") {
if (importOptions.webpackMode !== undefined) {
if (typeof importOptions.webpackMode !== "string") {
parser.state.module.warnings.push(
new UnsupportedFeatureWarning(
@@ -102,7 +102,7 @@ class ImportParserPlugin {
mode = importOptions.webpackMode;
}
}
if (typeof importOptions.webpackPrefetch !== "undefined") {
if (importOptions.webpackPrefetch !== undefined) {
if (importOptions.webpackPrefetch === true) {
groupOptions.prefetchOrder = 0;
} else if (typeof importOptions.webpackPrefetch === "number") {
@@ -119,7 +119,7 @@ class ImportParserPlugin {
);
}
}
if (typeof importOptions.webpackPreload !== "undefined") {
if (importOptions.webpackPreload !== undefined) {
if (importOptions.webpackPreload === true) {
groupOptions.preloadOrder = 0;
} else if (typeof importOptions.webpackPreload === "number") {
@@ -136,7 +136,7 @@ class ImportParserPlugin {
);
}
}
if (typeof importOptions.webpackInclude !== "undefined") {
if (importOptions.webpackInclude !== undefined) {
if (
!importOptions.webpackInclude ||
importOptions.webpackInclude.constructor.name !== "RegExp"
@@ -154,7 +154,7 @@ class ImportParserPlugin {
include = new RegExp(importOptions.webpackInclude);
}
}
if (typeof importOptions.webpackExclude !== "undefined") {
if (importOptions.webpackExclude !== undefined) {
if (
!importOptions.webpackExclude ||
importOptions.webpackExclude.constructor.name !== "RegExp"
@@ -57,10 +57,7 @@ class ImportPlugin {
);

const handler = (parser, parserOptions) => {
if (
typeof parserOptions.import !== "undefined" &&
!parserOptions.import
)
if (parserOptions.import !== undefined && !parserOptions.import)
return;

new ImportParserPlugin(options).apply(parser);
@@ -42,7 +42,7 @@ class RequireContextPlugin {

const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireContext !== "undefined" &&
parserOptions.requireContext !== undefined &&
!parserOptions.requireContext
)
return;
@@ -38,7 +38,7 @@ class RequireEnsurePlugin {

const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireEnsure !== "undefined" &&
parserOptions.requireEnsure !== undefined &&
!parserOptions.requireEnsure
)
return;
@@ -25,7 +25,7 @@ class RequireIncludePlugin {

const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireInclude !== "undefined" &&
parserOptions.requireInclude !== undefined &&
!parserOptions.requireInclude
)
return;
@@ -17,13 +17,10 @@ class SystemPlugin {
"SystemPlugin",
(compilation, { normalModuleFactory }) => {
const handler = (parser, parserOptions) => {
if (
typeof parserOptions.system !== "undefined" &&
!parserOptions.system
)
if (parserOptions.system !== undefined && !parserOptions.system)
return;

const shouldWarn = typeof parserOptions.system === "undefined";
const shouldWarn = parserOptions.system === undefined;

const setNotSupported = name => {
parser.hooks.evaluateTypeof
@@ -267,18 +267,18 @@ const getPathInAst = (ast, node) => {
if (Array.isArray(ast)) {
for (i = 0; i < ast.length; i++) {
const enterResult = enterNode(ast[i]);
if (typeof enterResult !== "undefined") return enterResult;
if (enterResult !== undefined) return enterResult;
}
} else if (ast && typeof ast === "object") {
const keys = Object.keys(ast);
for (i = 0; i < keys.length; i++) {
const value = ast[keys[i]];
if (Array.isArray(value)) {
const pathResult = getPathInAst(value, node);
if (typeof pathResult !== "undefined") return pathResult;
if (pathResult !== undefined) return pathResult;
} else if (value && typeof value === "object") {
const enterResult = enterNode(value);
if (typeof enterResult !== "undefined") return enterResult;
if (enterResult !== undefined) return enterResult;
}
}
}
@@ -60,13 +60,13 @@ exports.makePathsRelative = (context, identifier, cache) => {

let cachedResult;
let contextCache = relativePaths.get(context);
if (typeof contextCache === "undefined") {
if (contextCache === undefined) {
relativePaths.set(context, (contextCache = new Map()));
} else {
cachedResult = contextCache.get(identifier);
}

if (typeof cachedResult !== "undefined") {
if (cachedResult !== undefined) {
return cachedResult;
} else {
const relativePath = _makePathsRelative(context, identifier);
@@ -114,7 +114,7 @@ const getCountImportedFunc = ast => {
const getNextTypeIndex = ast => {
const typeSectionMetadata = t.getSectionMetadata(ast, "type");

if (typeof typeSectionMetadata === "undefined") {
if (typeSectionMetadata === undefined) {
return t.indexLiteral(0);
}

@@ -135,7 +135,7 @@ const getNextTypeIndex = ast => {
const getNextFuncIndex = (ast, countImportedFunc) => {
const funcSectionMetadata = t.getSectionMetadata(ast, "func");

if (typeof funcSectionMetadata === "undefined") {
if (funcSectionMetadata === undefined) {
return t.indexLiteral(0 + countImportedFunc);
}

@@ -271,7 +271,7 @@ const rewriteImports = ({ ast, usedDependencyMap }) => bin => {
path.node.module + ":" + path.node.name
);

if (typeof result !== "undefined") {
if (result !== undefined) {
path.node.module = result.module;
path.node.name = result.name;
}

0 comments on commit 1f954b4

Please sign in to comment.