Get rid typeof undef in all lib

This commit is contained in:
Mihail Bodrov 2018-08-21 03:26:50 +03:00
parent efa69cd628
commit 1f954b4f12
22 changed files with 39 additions and 60 deletions

View File

@ -30,7 +30,7 @@ class CompatibilityPlugin {
.for("javascript/auto") .for("javascript/auto")
.tap("CompatibilityPlugin", (parser, parserOptions) => { .tap("CompatibilityPlugin", (parser, parserOptions) => {
if ( if (
typeof parserOptions.browserify !== "undefined" && parserOptions.browserify !== undefined &&
!parserOptions.browserify !parserOptions.browserify
) )
return; return;

View File

@ -60,7 +60,7 @@ class EnvironmentPlugin {
} }
defs[`process.env.${key}`] = defs[`process.env.${key}`] =
typeof value === "undefined" ? "undefined" : JSON.stringify(value); value === undefined ? "undefined" : JSON.stringify(value);
return defs; return defs;
}, {}); }, {});

View File

@ -27,7 +27,7 @@ class ExternalModuleFactoryPlugin {
} }
if (value === false) return factory(data, callback); if (value === false) return factory(data, callback);
if (value === true) value = dependency.request; 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(" "); const idx = value.indexOf(" ");
type = value.substr(0, idx); type = value.substr(0, idx);
value = value.substr(idx + 1); value = value.substr(idx + 1);
@ -81,7 +81,7 @@ class ExternalModuleFactoryPlugin {
dependency.request, dependency.request,
(err, value, type) => { (err, value, type) => {
if (err) return callback(err); if (err) return callback(err);
if (typeof value !== "undefined") { if (value !== undefined) {
handleExternal(value, type, callback); handleExternal(value, type, callback);
} else { } else {
callback(); callback();

View File

@ -105,7 +105,7 @@ module.exports = function() {
// Module API // Module API
active: true, active: true,
accept: function(dep, callback) { 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 === "function") hot._selfAccepted = dep;
else if (typeof dep === "object") else if (typeof dep === "object")
for (var i = 0; i < dep.length; i++) for (var i = 0; i < dep.length; i++)
@ -113,7 +113,7 @@ module.exports = function() {
else hot._acceptedDependencies[dep] = callback || function() {}; else hot._acceptedDependencies[dep] = callback || function() {};
}, },
decline: function(dep) { decline: function(dep) {
if (typeof dep === "undefined") hot._selfDeclined = true; if (dep === undefined) hot._selfDeclined = true;
else if (typeof dep === "object") else if (typeof dep === "object")
for (var i = 0; i < dep.length; i++) for (var i = 0; i < dep.length; i++)
hot._declinedDependencies[dep[i]] = true; hot._declinedDependencies[dep[i]] = true;

View File

@ -30,7 +30,7 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
? base + accessorToObjectAccess(accessors.slice(0, idx + 1)) ? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1)); : accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
if (idx === accessors.length - 1) return a; 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} = typeof ${a} === "object" ? ${a} : {}`;
} }
return `${a} = ${a} || {}`; return `${a} = ${a} || {}`;

View File

@ -40,11 +40,11 @@ class MultiStats {
return obj; return obj;
}); });
const showVersion = const showVersion =
typeof options.version === "undefined" options.version === undefined
? jsons.every(j => j.version) ? jsons.every(j => j.version)
: options.version !== false; : options.version !== false;
const showHash = const showHash =
typeof options.hash === "undefined" options.hash === undefined
? jsons.every(j => j.hash) ? jsons.every(j => j.hash)
: options.hash !== false; : options.hash !== false;
if (showVersion) { if (showVersion) {

View File

@ -16,8 +16,7 @@ const getProperty = (obj, name) => {
const setProperty = (obj, name, value) => { const setProperty = (obj, name, value) => {
name = name.split("."); name = name.split(".");
for (let i = 0; i < name.length - 1; i++) { for (let i = 0; i < name.length - 1; i++) {
if (typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined") if (typeof obj[name[i]] !== "object" && obj[name[i]] !== undefined) return;
return;
if (Array.isArray(obj[name[i]])) return; if (Array.isArray(obj[name[i]])) return;
if (!obj[name[i]]) obj[name[i]] = {}; if (!obj[name[i]]) obj[name[i]] = {};
obj = obj[name[i]]; obj = obj[name[i]];

View File

@ -19,10 +19,7 @@ module.exports = class RequireJsStuffPlugin {
new ConstDependency.Template() new ConstDependency.Template()
); );
const handler = (parser, parserOptions) => { const handler = (parser, parserOptions) => {
if ( if (parserOptions.requireJs !== undefined && !parserOptions.requireJs)
typeof parserOptions.requireJs !== "undefined" &&
!parserOptions.requireJs
)
return; return;
parser.hooks.call parser.hooks.call

View File

@ -13,7 +13,7 @@ const compareLocations = require("./compareLocations");
const optionsOrFallback = (...args) => { const optionsOrFallback = (...args) => {
let optionValues = []; let optionValues = [];
optionValues.push(...args); optionValues.push(...args);
return optionValues.find(optionValue => typeof optionValue !== "undefined"); return optionValues.find(optionValue => optionValue !== undefined);
}; };
const compareId = (a, b) => { const compareId = (a, b) => {
@ -105,11 +105,7 @@ class Stats {
} }
const optionOrLocalFallback = (v, def) => const optionOrLocalFallback = (v, def) =>
typeof v !== "undefined" v !== undefined ? v : options.all !== undefined ? options.all : def;
? v
: typeof options.all !== "undefined"
? options.all
: def;
const testAgainstGivenOption = item => { const testAgainstGivenOption = item => {
if (typeof item === "string") { if (typeof item === "string") {

View File

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

View File

@ -98,8 +98,7 @@ class AMDPlugin {
); );
const handler = (parser, parserOptions) => { const handler = (parser, parserOptions) => {
if (typeof parserOptions.amd !== "undefined" && !parserOptions.amd) if (parserOptions.amd !== undefined && !parserOptions.amd) return;
return;
const setExpressionToModule = (outerExpr, module) => { const setExpressionToModule = (outerExpr, module) => {
parser.hooks.expression.for(outerExpr).tap("AMDPlugin", expr => { parser.hooks.expression.for(outerExpr).tap("AMDPlugin", expr => {

View File

@ -83,10 +83,7 @@ class CommonJsPlugin {
); );
const handler = (parser, parserOptions) => { const handler = (parser, parserOptions) => {
if ( if (parserOptions.commonjs !== undefined && !parserOptions.commonjs)
typeof parserOptions.commonjs !== "undefined" &&
!parserOptions.commonjs
)
return; return;
const requireExpressions = [ const requireExpressions = [

View File

@ -121,10 +121,7 @@ class HarmonyModulesPlugin {
); );
const handler = (parser, parserOptions) => { const handler = (parser, parserOptions) => {
if ( if (parserOptions.harmony !== undefined && !parserOptions.harmony)
typeof parserOptions.harmony !== "undefined" &&
!parserOptions.harmony
)
return; return;
new HarmonyDetectionParserPlugin().apply(parser); new HarmonyDetectionParserPlugin().apply(parser);

View File

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

View File

@ -57,10 +57,7 @@ class ImportPlugin {
); );
const handler = (parser, parserOptions) => { const handler = (parser, parserOptions) => {
if ( if (parserOptions.import !== undefined && !parserOptions.import)
typeof parserOptions.import !== "undefined" &&
!parserOptions.import
)
return; return;
new ImportParserPlugin(options).apply(parser); new ImportParserPlugin(options).apply(parser);

View File

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

View File

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

View File

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

View File

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

View File

@ -267,7 +267,7 @@ const getPathInAst = (ast, node) => {
if (Array.isArray(ast)) { if (Array.isArray(ast)) {
for (i = 0; i < ast.length; i++) { for (i = 0; i < ast.length; i++) {
const enterResult = enterNode(ast[i]); const enterResult = enterNode(ast[i]);
if (typeof enterResult !== "undefined") return enterResult; if (enterResult !== undefined) return enterResult;
} }
} else if (ast && typeof ast === "object") { } else if (ast && typeof ast === "object") {
const keys = Object.keys(ast); const keys = Object.keys(ast);
@ -275,10 +275,10 @@ const getPathInAst = (ast, node) => {
const value = ast[keys[i]]; const value = ast[keys[i]];
if (Array.isArray(value)) { if (Array.isArray(value)) {
const pathResult = getPathInAst(value, node); const pathResult = getPathInAst(value, node);
if (typeof pathResult !== "undefined") return pathResult; if (pathResult !== undefined) return pathResult;
} else if (value && typeof value === "object") { } else if (value && typeof value === "object") {
const enterResult = enterNode(value); const enterResult = enterNode(value);
if (typeof enterResult !== "undefined") return enterResult; if (enterResult !== undefined) return enterResult;
} }
} }
} }

View File

@ -60,13 +60,13 @@ exports.makePathsRelative = (context, identifier, cache) => {
let cachedResult; let cachedResult;
let contextCache = relativePaths.get(context); let contextCache = relativePaths.get(context);
if (typeof contextCache === "undefined") { if (contextCache === undefined) {
relativePaths.set(context, (contextCache = new Map())); relativePaths.set(context, (contextCache = new Map()));
} else { } else {
cachedResult = contextCache.get(identifier); cachedResult = contextCache.get(identifier);
} }
if (typeof cachedResult !== "undefined") { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} else { } else {
const relativePath = _makePathsRelative(context, identifier); const relativePath = _makePathsRelative(context, identifier);

View File

@ -114,7 +114,7 @@ const getCountImportedFunc = ast => {
const getNextTypeIndex = ast => { const getNextTypeIndex = ast => {
const typeSectionMetadata = t.getSectionMetadata(ast, "type"); const typeSectionMetadata = t.getSectionMetadata(ast, "type");
if (typeof typeSectionMetadata === "undefined") { if (typeSectionMetadata === undefined) {
return t.indexLiteral(0); return t.indexLiteral(0);
} }
@ -135,7 +135,7 @@ const getNextTypeIndex = ast => {
const getNextFuncIndex = (ast, countImportedFunc) => { const getNextFuncIndex = (ast, countImportedFunc) => {
const funcSectionMetadata = t.getSectionMetadata(ast, "func"); const funcSectionMetadata = t.getSectionMetadata(ast, "func");
if (typeof funcSectionMetadata === "undefined") { if (funcSectionMetadata === undefined) {
return t.indexLiteral(0 + countImportedFunc); return t.indexLiteral(0 + countImportedFunc);
} }
@ -271,7 +271,7 @@ const rewriteImports = ({ ast, usedDependencyMap }) => bin => {
path.node.module + ":" + path.node.name path.node.module + ":" + path.node.name
); );
if (typeof result !== "undefined") { if (result !== undefined) {
path.node.module = result.module; path.node.module = result.module;
path.node.name = result.name; path.node.name = result.name;
} }