Skip to content

Commit 8f56fcb

Browse files
committed
Replace deprecated String.prototype.substr()
String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with slice() which works similarily but isn't deprecated. Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
1 parent 770dea1 commit 8f56fcb

35 files changed

+62
-62
lines changed

examples/template-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exports.replaceResults = (template, baseDir, stdout, prefix) => {
6060
const regexp = new RegExp("_\\{\\{" + (prefix ? prefix + ":" : "") + "([^:\\}]+)\\}\\}_", "g");
6161

6262
return template.replace(regexp, function(match) {
63-
match = match.substr(3 + (prefix ? prefix.length + 1 : 0), match.length - 6 - (prefix ? prefix.length + 1 : 0));
63+
match = match.slice(3 + (prefix ? prefix.length + 1 : 0), -3);
6464
if(match === "stdout")
6565
return stdout;
6666
try {

hot/poll.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
/*globals __resourceQuery */
66
if (module.hot) {
7-
var hotPollInterval = +__resourceQuery.substr(1) || 10 * 60 * 1000;
7+
var hotPollInterval = +__resourceQuery.slice(1) || 10 * 60 * 1000;
88
var log = require("./log");
99

1010
var checkForUpdate = function checkForUpdate(fromUpdate) {

hot/signal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ if (module.hot) {
4545
});
4646
};
4747

48-
process.on(__resourceQuery.substr(1) || "SIGUSR2", function () {
48+
process.on(__resourceQuery.slice(1) || "SIGUSR2", function () {
4949
if (module.hot.status() !== "idle") {
5050
log(
5151
"warning",

lib/Chunk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ class Chunk {
690690
for (const childGroup of group.childrenIterable) {
691691
for (const key of Object.keys(childGroup.options)) {
692692
if (key.endsWith("Order")) {
693-
const name = key.substr(0, key.length - "Order".length);
693+
const name = key.slice(0, key.length - "Order".length);
694694
let list = lists.get(name);
695695
if (list === undefined) {
696696
list = [];

lib/ChunkGroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class ChunkGroup {
486486
for (const childGroup of this._children) {
487487
for (const key of Object.keys(childGroup.options)) {
488488
if (key.endsWith("Order")) {
489-
const name = key.substr(0, key.length - "Order".length);
489+
const name = key.slice(0, key.length - "Order".length);
490490
let list = lists.get(name);
491491
if (list === undefined) {
492492
lists.set(name, (list = []));

lib/Compilation.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3896,7 +3896,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
38963896
module,
38973897
runtime,
38983898
digest,
3899-
digest.substr(0, hashDigestLength)
3899+
digest.slice(0, hashDigestLength)
39003900
);
39013901
statModulesFromCache++;
39023902
continue;
@@ -3960,7 +3960,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
39603960
module,
39613961
runtime,
39623962
moduleHashDigest,
3963-
moduleHashDigest.substr(0, hashDigestLength)
3963+
moduleHashDigest.slice(0, hashDigestLength)
39643964
);
39653965
return moduleHashDigest;
39663966
}
@@ -4164,7 +4164,7 @@ This prevents using hashes of each other and should be avoided.`);
41644164
);
41654165
hash.update(chunkHashDigest);
41664166
chunk.hash = chunkHashDigest;
4167-
chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
4167+
chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
41684168
const fullHashModules =
41694169
chunkGraph.getChunkFullHashModulesIterable(chunk);
41704170
if (fullHashModules) {
@@ -4191,7 +4191,7 @@ This prevents using hashes of each other and should be avoided.`);
41914191
this.logger.time("hashing: hash digest");
41924192
this.hooks.fullHash.call(hash);
41934193
this.fullHash = /** @type {string} */ (hash.digest(hashDigest));
4194-
this.hash = this.fullHash.substr(0, hashDigestLength);
4194+
this.hash = this.fullHash.slice(0, hashDigestLength);
41954195
this.logger.timeEnd("hashing: hash digest");
41964196

41974197
this.logger.time("hashing: process full hash modules");
@@ -4211,7 +4211,7 @@ This prevents using hashes of each other and should be avoided.`);
42114211
module,
42124212
chunk.runtime,
42134213
moduleHashDigest,
4214-
moduleHashDigest.substr(0, hashDigestLength)
4214+
moduleHashDigest.slice(0, hashDigestLength)
42154215
);
42164216
codeGenerationJobsMap.get(oldHash).get(module).hash = moduleHashDigest;
42174217
}
@@ -4222,7 +4222,7 @@ This prevents using hashes of each other and should be avoided.`);
42224222
chunkHash.digest(hashDigest)
42234223
);
42244224
chunk.hash = chunkHashDigest;
4225-
chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
4225+
chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
42264226
this.hooks.contentHash.call(chunk);
42274227
}
42284228
this.logger.timeEnd("hashing: process full hash modules");

lib/Compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ class Compiler {
596596
let immutable = info.immutable;
597597
const queryStringIdx = targetFile.indexOf("?");
598598
if (queryStringIdx >= 0) {
599-
targetFile = targetFile.substr(0, queryStringIdx);
599+
targetFile = targetFile.slice(0, queryStringIdx);
600600
// We may remove the hash, which is in the query string
601601
// So we recheck if the file is immutable
602602
// This doesn't cover all cases, but immutable is only a performance optimization anyway

lib/ContextModuleFactory.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
128128
loadersPrefix = "";
129129
const idx = request.lastIndexOf("!");
130130
if (idx >= 0) {
131-
let loadersRequest = request.substr(0, idx + 1);
131+
let loadersRequest = request.slice(0, idx + 1);
132132
let i;
133133
for (
134134
i = 0;
@@ -138,15 +138,15 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
138138
loadersPrefix += "!";
139139
}
140140
loadersRequest = loadersRequest
141-
.substr(i)
141+
.slice(i)
142142
.replace(/!+$/, "")
143143
.replace(/!!+/g, "!");
144144
if (loadersRequest === "") {
145145
loaders = [];
146146
} else {
147147
loaders = loadersRequest.split("!");
148148
}
149-
resource = request.substr(idx + 1);
149+
resource = request.slice(idx + 1);
150150
} else {
151151
loaders = [];
152152
resource = request;
@@ -348,7 +348,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
348348
const obj = {
349349
context: ctx,
350350
request:
351-
"." + subResource.substr(ctx.length).replace(/\\/g, "/")
351+
"." + subResource.slice(ctx.length).replace(/\\/g, "/")
352352
};
353353

354354
this.hooks.alternativeRequests.callAsync(

lib/DelegatedModuleFactoryPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DelegatedModuleFactoryPlugin {
2929
const [dependency] = data.dependencies;
3030
const { request } = dependency;
3131
if (request && request.startsWith(`${scope}/`)) {
32-
const innerRequest = "." + request.substr(scope.length);
32+
const innerRequest = "." + request.slice(scope.length);
3333
let resolved;
3434
if (innerRequest in this.options.content) {
3535
resolved = this.options.content[innerRequest];

lib/ErrorHelpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ exports.cutOffMessage = (stack, message) => {
4343
if (nextLine === -1) {
4444
return stack === message ? "" : stack;
4545
} else {
46-
const firstLine = stack.substr(0, nextLine);
47-
return firstLine === message ? stack.substr(nextLine + 1) : stack;
46+
const firstLine = stack.slice(0, nextLine);
47+
return firstLine === message ? stack.slice(nextLine + 1) : stack;
4848
}
4949
};
5050

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy