Skip to content

Commit

Permalink
Get rid typeof undef in all lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha committed Aug 21, 2018
1 parent efa69cd commit 1f954b4
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 60 deletions.
2 changes: 1 addition & 1 deletion lib/CompatibilityPlugin.js
Expand Up @@ -30,7 +30,7 @@ class CompatibilityPlugin {
.for("javascript/auto")
.tap("CompatibilityPlugin", (parser, parserOptions) => {
if (
typeof parserOptions.browserify !== "undefined" &&
parserOptions.browserify !== undefined &&
!parserOptions.browserify
)
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/EnvironmentPlugin.js
Expand Up @@ -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;
}, {});
Expand Down
4 changes: 2 additions & 2 deletions lib/ExternalModuleFactoryPlugin.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions lib/HotModuleReplacement.runtime.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/LibraryTemplatePlugin.js
Expand Up @@ -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} || {}`;
Expand Down
4 changes: 2 additions & 2 deletions lib/MultiStats.js
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions lib/OptionsDefaulter.js
Expand Up @@ -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]];
Expand Down
5 changes: 1 addition & 4 deletions lib/RequireJsStuffPlugin.js
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions lib/Stats.js
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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") {
Expand Down
4 changes: 2 additions & 2 deletions lib/UmdMainTemplatePlugin.js
Expand Up @@ -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} || {}`;
})
Expand Down Expand Up @@ -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
);
Expand Down
3 changes: 1 addition & 2 deletions lib/dependencies/AMDPlugin.js
Expand Up @@ -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 => {
Expand Down
5 changes: 1 addition & 4 deletions lib/dependencies/CommonJsPlugin.js
Expand Up @@ -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 = [
Expand Down
5 changes: 1 addition & 4 deletions lib/dependencies/HarmonyModulesPlugin.js
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions lib/dependencies/ImportParserPlugin.js
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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") {
Expand All @@ -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") {
Expand All @@ -136,7 +136,7 @@ class ImportParserPlugin {
);
}
}
if (typeof importOptions.webpackInclude !== "undefined") {
if (importOptions.webpackInclude !== undefined) {
if (
!importOptions.webpackInclude ||
importOptions.webpackInclude.constructor.name !== "RegExp"
Expand All @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions lib/dependencies/ImportPlugin.js
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/dependencies/RequireContextPlugin.js
Expand Up @@ -42,7 +42,7 @@ class RequireContextPlugin {

const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireContext !== "undefined" &&
parserOptions.requireContext !== undefined &&
!parserOptions.requireContext
)
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/dependencies/RequireEnsurePlugin.js
Expand Up @@ -38,7 +38,7 @@ class RequireEnsurePlugin {

const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireEnsure !== "undefined" &&
parserOptions.requireEnsure !== undefined &&
!parserOptions.requireEnsure
)
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/dependencies/RequireIncludePlugin.js
Expand Up @@ -25,7 +25,7 @@ class RequireIncludePlugin {

const handler = (parser, parserOptions) => {
if (
typeof parserOptions.requireInclude !== "undefined" &&
parserOptions.requireInclude !== undefined &&
!parserOptions.requireInclude
)
return;
Expand Down
7 changes: 2 additions & 5 deletions lib/dependencies/SystemPlugin.js
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/optimize/ConcatenatedModule.js
Expand Up @@ -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;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/util/identifier.js
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/wasm/WebAssemblyGenerator.js
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 1f954b4

Please sign in to comment.