Skip to content

Commit 1f954b4

Browse files
committed
Get rid typeof undef in all lib
1 parent efa69cd commit 1f954b4

22 files changed

+39
-60
lines changed

lib/CompatibilityPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CompatibilityPlugin {
3030
.for("javascript/auto")
3131
.tap("CompatibilityPlugin", (parser, parserOptions) => {
3232
if (
33-
typeof parserOptions.browserify !== "undefined" &&
33+
parserOptions.browserify !== undefined &&
3434
!parserOptions.browserify
3535
)
3636
return;

lib/EnvironmentPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class EnvironmentPlugin {
6060
}
6161

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

6565
return defs;
6666
}, {});

lib/ExternalModuleFactoryPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ExternalModuleFactoryPlugin {
2727
}
2828
if (value === false) return factory(data, callback);
2929
if (value === true) value = dependency.request;
30-
if (typeof type === "undefined" && /^[a-z0-9]+ /.test(value)) {
30+
if (type === undefined && /^[a-z0-9]+ /.test(value)) {
3131
const idx = value.indexOf(" ");
3232
type = value.substr(0, idx);
3333
value = value.substr(idx + 1);
@@ -81,7 +81,7 @@ class ExternalModuleFactoryPlugin {
8181
dependency.request,
8282
(err, value, type) => {
8383
if (err) return callback(err);
84-
if (typeof value !== "undefined") {
84+
if (value !== undefined) {
8585
handleExternal(value, type, callback);
8686
} else {
8787
callback();

lib/HotModuleReplacement.runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ module.exports = function() {
105105
// Module API
106106
active: true,
107107
accept: function(dep, callback) {
108-
if (typeof dep === "undefined") hot._selfAccepted = true;
108+
if (dep === undefined) hot._selfAccepted = true;
109109
else if (typeof dep === "function") hot._selfAccepted = dep;
110110
else if (typeof dep === "object")
111111
for (var i = 0; i < dep.length; i++)
112112
hot._acceptedDependencies[dep[i]] = callback || function() {};
113113
else hot._acceptedDependencies[dep] = callback || function() {};
114114
},
115115
decline: function(dep) {
116-
if (typeof dep === "undefined") hot._selfDeclined = true;
116+
if (dep === undefined) hot._selfDeclined = true;
117117
else if (typeof dep === "object")
118118
for (var i = 0; i < dep.length; i++)
119119
hot._declinedDependencies[dep[i]] = true;

lib/LibraryTemplatePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
3030
? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
3131
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
3232
if (idx === accessors.length - 1) return a;
33-
if (idx === 0 && typeof base === "undefined") {
33+
if (idx === 0 && base === undefined) {
3434
return `${a} = typeof ${a} === "object" ? ${a} : {}`;
3535
}
3636
return `${a} = ${a} || {}`;

lib/MultiStats.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class MultiStats {
4040
return obj;
4141
});
4242
const showVersion =
43-
typeof options.version === "undefined"
43+
options.version === undefined
4444
? jsons.every(j => j.version)
4545
: options.version !== false;
4646
const showHash =
47-
typeof options.hash === "undefined"
47+
options.hash === undefined
4848
? jsons.every(j => j.hash)
4949
: options.hash !== false;
5050
if (showVersion) {

lib/OptionsDefaulter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const getProperty = (obj, name) => {
1616
const setProperty = (obj, name, value) => {
1717
name = name.split(".");
1818
for (let i = 0; i < name.length - 1; i++) {
19-
if (typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined")
20-
return;
19+
if (typeof obj[name[i]] !== "object" && obj[name[i]] !== undefined) return;
2120
if (Array.isArray(obj[name[i]])) return;
2221
if (!obj[name[i]]) obj[name[i]] = {};
2322
obj = obj[name[i]];

lib/RequireJsStuffPlugin.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ module.exports = class RequireJsStuffPlugin {
1919
new ConstDependency.Template()
2020
);
2121
const handler = (parser, parserOptions) => {
22-
if (
23-
typeof parserOptions.requireJs !== "undefined" &&
24-
!parserOptions.requireJs
25-
)
22+
if (parserOptions.requireJs !== undefined && !parserOptions.requireJs)
2623
return;
2724

2825
parser.hooks.call

lib/Stats.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const compareLocations = require("./compareLocations");
1313
const optionsOrFallback = (...args) => {
1414
let optionValues = [];
1515
optionValues.push(...args);
16-
return optionValues.find(optionValue => typeof optionValue !== "undefined");
16+
return optionValues.find(optionValue => optionValue !== undefined);
1717
};
1818

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

107107
const optionOrLocalFallback = (v, def) =>
108-
typeof v !== "undefined"
109-
? v
110-
: typeof options.all !== "undefined"
111-
? options.all
112-
: def;
108+
v !== undefined ? v : options.all !== undefined ? options.all : def;
113109

114110
const testAgainstGivenOption = item => {
115111
if (typeof item === "string") {

lib/UmdMainTemplatePlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const accessorAccess = (base, accessor, joinWith = ", ") => {
3131
? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
3232
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
3333
if (idx === accessors.length - 1) return a;
34-
if (idx === 0 && typeof base === "undefined")
34+
if (idx === 0 && base === undefined)
3535
return `${a} = typeof ${a} === "object" ? ${a} : {}`;
3636
return `${a} = ${a} || {}`;
3737
})
@@ -147,7 +147,7 @@ class UmdMainTemplatePlugin {
147147
if (typeof request === "object") {
148148
request = request[type];
149149
}
150-
if (typeof request === "undefined") {
150+
if (request === undefined) {
151151
throw new Error(
152152
"Missing external configuration for type:" + type
153153
);

0 commit comments

Comments
 (0)