Skip to content

Commit cb74c37

Browse files
refactor: replace deprecated String.prototype.substr() (#14377)
1 parent 3ee9db7 commit cb74c37

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/babel-core/src/config/printer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function descriptorToConfig(
7979
// If the unloaded descriptor is a function, i.e. `plugins: [ require("my-plugin") ]`,
8080
// we print the first 50 characters of the function source code and hopefully we can see
8181
// `name: 'my-plugin'` in the source
82-
name = `[Function: ${d.value.toString().substr(0, 50)} ... ]`;
82+
name = `[Function: ${d.value.toString().slice(0, 50)} ... ]`;
8383
}
8484
}
8585
if (name == null) {

packages/babel-highlight/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ if (process.env.BABEL_8_BREAKING) {
176176

177177
if (
178178
JSX_TAG.test(token.value) &&
179-
(text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")
179+
(text[offset - 1] === "<" || text.slice(offset - 2, offset) == "</")
180180
) {
181181
return "jsxIdentifier";
182182
}

packages/babel-parser/src/tokenizer/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ export default class Tokenizer extends CommentsParser {
16061606
-1,
16071607
);
16081608
const match = this.input
1609-
.substr(this.state.pos - 1, 3)
1609+
.slice(this.state.pos - 1, this.state.pos + 2)
16101610
.match(/^[0-7]+/);
16111611

16121612
// This is never null, because of the if condition above.

scripts/parser-tests/test262/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const runner = new TestRunner({
170170

171171
for await (const test of stream) {
172172
// strip test/
173-
const fileName = test.file.substr(5);
173+
const fileName = test.file.slice(5);
174174

175175
if (ignoredTests.some(start => fileName.startsWith(start))) continue;
176176

0 commit comments

Comments
 (0)