From 1f954b4f1281f2bb97492fcd911d270efb097fd5 Mon Sep 17 00:00:00 2001 From: Mihail Bodrov Date: Tue, 21 Aug 2018 03:26:50 +0300 Subject: [PATCH] Get rid typeof undef in all lib --- lib/CompatibilityPlugin.js | 2 +- lib/EnvironmentPlugin.js | 2 +- lib/ExternalModuleFactoryPlugin.js | 4 ++-- lib/HotModuleReplacement.runtime.js | 4 ++-- lib/LibraryTemplatePlugin.js | 2 +- lib/MultiStats.js | 4 ++-- lib/OptionsDefaulter.js | 3 +-- lib/RequireJsStuffPlugin.js | 5 +---- lib/Stats.js | 8 ++------ lib/UmdMainTemplatePlugin.js | 4 ++-- lib/dependencies/AMDPlugin.js | 3 +-- lib/dependencies/CommonJsPlugin.js | 5 +---- lib/dependencies/HarmonyModulesPlugin.js | 5 +---- lib/dependencies/ImportParserPlugin.js | 14 +++++++------- lib/dependencies/ImportPlugin.js | 5 +---- lib/dependencies/RequireContextPlugin.js | 2 +- lib/dependencies/RequireEnsurePlugin.js | 2 +- lib/dependencies/RequireIncludePlugin.js | 2 +- lib/dependencies/SystemPlugin.js | 7 ++----- lib/optimize/ConcatenatedModule.js | 6 +++--- lib/util/identifier.js | 4 ++-- lib/wasm/WebAssemblyGenerator.js | 6 +++--- 22 files changed, 39 insertions(+), 60 deletions(-) diff --git a/lib/CompatibilityPlugin.js b/lib/CompatibilityPlugin.js index 7edea8336b8..1544d6c82a4 100644 --- a/lib/CompatibilityPlugin.js +++ b/lib/CompatibilityPlugin.js @@ -30,7 +30,7 @@ class CompatibilityPlugin { .for("javascript/auto") .tap("CompatibilityPlugin", (parser, parserOptions) => { if ( - typeof parserOptions.browserify !== "undefined" && + parserOptions.browserify !== undefined && !parserOptions.browserify ) return; diff --git a/lib/EnvironmentPlugin.js b/lib/EnvironmentPlugin.js index 40353611130..c9fafaa8a7e 100644 --- a/lib/EnvironmentPlugin.js +++ b/lib/EnvironmentPlugin.js @@ -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; }, {}); diff --git a/lib/ExternalModuleFactoryPlugin.js b/lib/ExternalModuleFactoryPlugin.js index 390e305239e..b75cc7476fa 100644 --- a/lib/ExternalModuleFactoryPlugin.js +++ b/lib/ExternalModuleFactoryPlugin.js @@ -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(); diff --git a/lib/HotModuleReplacement.runtime.js b/lib/HotModuleReplacement.runtime.js index 917ef45ba4c..5497091c817 100644 --- a/lib/HotModuleReplacement.runtime.js +++ b/lib/HotModuleReplacement.runtime.js @@ -105,7 +105,7 @@ 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++) @@ -113,7 +113,7 @@ module.exports = 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; diff --git a/lib/LibraryTemplatePlugin.js b/lib/LibraryTemplatePlugin.js index 484442efcbc..c871994fa06 100644 --- a/lib/LibraryTemplatePlugin.js +++ b/lib/LibraryTemplatePlugin.js @@ -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} || {}`; diff --git a/lib/MultiStats.js b/lib/MultiStats.js index 4713524b8db..1a5fcf2b007 100644 --- a/lib/MultiStats.js +++ b/lib/MultiStats.js @@ -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) { diff --git a/lib/OptionsDefaulter.js b/lib/OptionsDefaulter.js index c5ff612d8d7..cad07ea06c2 100644 --- a/lib/OptionsDefaulter.js +++ b/lib/OptionsDefaulter.js @@ -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]]; diff --git a/lib/RequireJsStuffPlugin.js b/lib/RequireJsStuffPlugin.js index 84793c8a997..632deefc2d6 100644 --- a/lib/RequireJsStuffPlugin.js +++ b/lib/RequireJsStuffPlugin.js @@ -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 diff --git a/lib/Stats.js b/lib/Stats.js index 4594a94615a..fd7902bee79 100644 --- a/lib/Stats.js +++ b/lib/Stats.js @@ -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") { diff --git a/lib/UmdMainTemplatePlugin.js b/lib/UmdMainTemplatePlugin.js index bb2e466290c..551ac76f836 100644 --- a/lib/UmdMainTemplatePlugin.js +++ b/lib/UmdMainTemplatePlugin.js @@ -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 ); diff --git a/lib/dependencies/AMDPlugin.js b/lib/dependencies/AMDPlugin.js index 06b8cd73075..d113491c969 100644 --- a/lib/dependencies/AMDPlugin.js +++ b/lib/dependencies/AMDPlugin.js @@ -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 => { diff --git a/lib/dependencies/CommonJsPlugin.js b/lib/dependencies/CommonJsPlugin.js index fc6cae7ec82..6d441a872d9 100644 --- a/lib/dependencies/CommonJsPlugin.js +++ b/lib/dependencies/CommonJsPlugin.js @@ -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 = [ diff --git a/lib/dependencies/HarmonyModulesPlugin.js b/lib/dependencies/HarmonyModulesPlugin.js index 12a50a25aea..43a8d4c0c1d 100644 --- a/lib/dependencies/HarmonyModulesPlugin.js +++ b/lib/dependencies/HarmonyModulesPlugin.js @@ -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); diff --git a/lib/dependencies/ImportParserPlugin.js b/lib/dependencies/ImportParserPlugin.js index 14043851965..86c6b7438e3 100644 --- a/lib/dependencies/ImportParserPlugin.js +++ b/lib/dependencies/ImportParserPlugin.js @@ -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" diff --git a/lib/dependencies/ImportPlugin.js b/lib/dependencies/ImportPlugin.js index 8d488e0d904..1647192595b 100644 --- a/lib/dependencies/ImportPlugin.js +++ b/lib/dependencies/ImportPlugin.js @@ -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); diff --git a/lib/dependencies/RequireContextPlugin.js b/lib/dependencies/RequireContextPlugin.js index 24312449c22..4e44e87117a 100644 --- a/lib/dependencies/RequireContextPlugin.js +++ b/lib/dependencies/RequireContextPlugin.js @@ -42,7 +42,7 @@ class RequireContextPlugin { const handler = (parser, parserOptions) => { if ( - typeof parserOptions.requireContext !== "undefined" && + parserOptions.requireContext !== undefined && !parserOptions.requireContext ) return; diff --git a/lib/dependencies/RequireEnsurePlugin.js b/lib/dependencies/RequireEnsurePlugin.js index e508ec4fcdd..c818e91bc1d 100644 --- a/lib/dependencies/RequireEnsurePlugin.js +++ b/lib/dependencies/RequireEnsurePlugin.js @@ -38,7 +38,7 @@ class RequireEnsurePlugin { const handler = (parser, parserOptions) => { if ( - typeof parserOptions.requireEnsure !== "undefined" && + parserOptions.requireEnsure !== undefined && !parserOptions.requireEnsure ) return; diff --git a/lib/dependencies/RequireIncludePlugin.js b/lib/dependencies/RequireIncludePlugin.js index e5811a07e70..e7d535bc3a0 100644 --- a/lib/dependencies/RequireIncludePlugin.js +++ b/lib/dependencies/RequireIncludePlugin.js @@ -25,7 +25,7 @@ class RequireIncludePlugin { const handler = (parser, parserOptions) => { if ( - typeof parserOptions.requireInclude !== "undefined" && + parserOptions.requireInclude !== undefined && !parserOptions.requireInclude ) return; diff --git a/lib/dependencies/SystemPlugin.js b/lib/dependencies/SystemPlugin.js index c85778861b8..0e3419b5748 100644 --- a/lib/dependencies/SystemPlugin.js +++ b/lib/dependencies/SystemPlugin.js @@ -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 diff --git a/lib/optimize/ConcatenatedModule.js b/lib/optimize/ConcatenatedModule.js index a4e1ae4d8a7..5ec522fee8a 100644 --- a/lib/optimize/ConcatenatedModule.js +++ b/lib/optimize/ConcatenatedModule.js @@ -267,7 +267,7 @@ 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); @@ -275,10 +275,10 @@ const getPathInAst = (ast, node) => { 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; } } } diff --git a/lib/util/identifier.js b/lib/util/identifier.js index ade63590821..186bc064e53 100644 --- a/lib/util/identifier.js +++ b/lib/util/identifier.js @@ -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); diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 1de627866cf..ca664da92d9 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -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; }