Skip to content

Commit 6bcb7a5

Browse files
authored
chore: remove deprecated usage of String.prototype.substr (#4699)
1 parent c9613eb commit 6bcb7a5

File tree

7 files changed

+17
-18
lines changed

7 files changed

+17
-18
lines changed

packages/compiler-core/__tests__/utils.spec.ts

-8
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ describe('getInnerRange', () => {
5656
expect(loc2.end.offset).toBe(4)
5757
})
5858

59-
test('at end', () => {
60-
const loc2 = getInnerRange(loc1, 4)
61-
expect(loc2.start.column).toBe(1)
62-
expect(loc2.start.line).toBe(2)
63-
expect(loc2.start.offset).toBe(4)
64-
expect(loc2.end).toEqual(loc1.end)
65-
})
66-
6759
test('in between', () => {
6860
const loc2 = getInnerRange(loc1, 4, 3)
6961
expect(loc2.start.column).toBe(1)

packages/compiler-core/src/parse.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,9 @@ function parseAttribute(
825825
context,
826826
ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END
827827
)
828-
content = content.substr(1)
828+
content = content.slice(1)
829829
} else {
830-
content = content.substr(1, content.length - 2)
830+
content = content.slice(1, content.length - 1)
831831
}
832832
} else if (isSlot) {
833833
// #1241 special case for v-slot: vuetify relies extensively on slot
@@ -855,7 +855,7 @@ function parseAttribute(
855855
valueLoc.source = valueLoc.source.slice(1, -1)
856856
}
857857

858-
const modifiers = match[3] ? match[3].substr(1).split('.') : []
858+
const modifiers = match[3] ? match[3].slice(1).split('.') : []
859859
if (isPropShorthand) modifiers.push('prop')
860860

861861
// 2.x compat v-bind:foo.sync -> v-model:foo
@@ -1167,7 +1167,7 @@ function isEnd(
11671167
function startsWithEndTagOpen(source: string, tag: string): boolean {
11681168
return (
11691169
startsWith(source, '</') &&
1170-
source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
1170+
source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
11711171
/[\t\r\n\f />]/.test(source[2 + tag.length] || '>')
11721172
)
11731173
}

packages/compiler-core/src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ export const isMemberExpression = __BROWSER__
182182
export function getInnerRange(
183183
loc: SourceLocation,
184184
offset: number,
185-
length?: number
185+
length: number
186186
): SourceLocation {
187187
__TEST__ && assert(offset <= loc.source.length)
188-
const source = loc.source.substr(offset, length)
188+
const source = loc.source.slice(offset, offset + length)
189189
const newLoc: SourceLocation = {
190190
source,
191191
start: advancePositionWithClone(loc.start, loc.source, offset),

packages/compiler-dom/src/decodeHtml.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const decodeHtml: ParserOptions['decodeEntities'] = (
4242
)
4343
}
4444
for (let length = maxCRNameLength; !value && length > 0; --length) {
45-
name = rawText.substr(1, length)
45+
name = rawText.slice(1, 1 + length)
4646
value = (namedCharacterReferences as Record<string, string>)[name]
4747
}
4848
if (value) {

packages/global.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ declare module '@vue/repl' {
4545
const ReplStore: any
4646
export { Repl, ReplStore }
4747
}
48+
49+
declare interface String {
50+
/**
51+
* @deprecated Please use String.prototype.slice instead of String.prototype.substring in the repository.
52+
*/
53+
substring(start: number, end?: number): string;
54+
}

packages/sfc-playground/src/Header.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function fetchVersions(): Promise<string[]> {
6060
)
6161
const releases: any[] = await res.json()
6262
const versions = releases.map(r =>
63-
/^v/.test(r.tag_name) ? r.tag_name.substr(1) : r.tag_name
63+
/^v/.test(r.tag_name) ? r.tag_name.slice(1) : r.tag_name
6464
)
6565
// if the latest version is a pre-release, list all current pre-releases
6666
// otherwise filter out pre-releases

packages/shared/src/escapeHtml.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ export function escapeHtml(string: unknown) {
3434
}
3535

3636
if (lastIndex !== index) {
37-
html += str.substring(lastIndex, index)
37+
html += str.slice(lastIndex, index)
3838
}
3939

4040
lastIndex = index + 1
4141
html += escaped
4242
}
4343

44-
return lastIndex !== index ? html + str.substring(lastIndex, index) : html
44+
return lastIndex !== index ? html + str.slice(lastIndex, index) : html
4545
}
4646

4747
// https://www.w3.org/TR/html52/syntax.html#comments

0 commit comments

Comments
 (0)