]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: remove deprecated usage of String.prototype.substr (#4699)
authorChe Guevara <836934184@qq.com>
Fri, 8 Oct 2021 16:31:34 +0000 (00:31 +0800)
committerGitHub <noreply@github.com>
Fri, 8 Oct 2021 16:31:34 +0000 (12:31 -0400)
packages/compiler-core/__tests__/utils.spec.ts
packages/compiler-core/src/parse.ts
packages/compiler-core/src/utils.ts
packages/compiler-dom/src/decodeHtml.ts
packages/global.d.ts
packages/sfc-playground/src/Header.vue
packages/shared/src/escapeHtml.ts

index 3c5412796e3663eb75c65f8904b80d77923ff244..45fa46fea7a60d28a367fe5c4f1a886280eb530e 100644 (file)
@@ -56,14 +56,6 @@ describe('getInnerRange', () => {
     expect(loc2.end.offset).toBe(4)
   })
 
-  test('at end', () => {
-    const loc2 = getInnerRange(loc1, 4)
-    expect(loc2.start.column).toBe(1)
-    expect(loc2.start.line).toBe(2)
-    expect(loc2.start.offset).toBe(4)
-    expect(loc2.end).toEqual(loc1.end)
-  })
-
   test('in between', () => {
     const loc2 = getInnerRange(loc1, 4, 3)
     expect(loc2.start.column).toBe(1)
index b824314d010a8aec75ed560e83942eb42f91532a..078066e3d56d4739b642fbddb942524d74a04bf0 100644 (file)
@@ -825,9 +825,9 @@ function parseAttribute(
             context,
             ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END
           )
-          content = content.substr(1)
+          content = content.slice(1)
         } else {
-          content = content.substr(1, content.length - 2)
+          content = content.slice(1, content.length - 1)
         }
       } else if (isSlot) {
         // #1241 special case for v-slot: vuetify relies extensively on slot
@@ -855,7 +855,7 @@ function parseAttribute(
       valueLoc.source = valueLoc.source.slice(1, -1)
     }
 
-    const modifiers = match[3] ? match[3].substr(1).split('.') : []
+    const modifiers = match[3] ? match[3].slice(1).split('.') : []
     if (isPropShorthand) modifiers.push('prop')
 
     // 2.x compat v-bind:foo.sync -> v-model:foo
@@ -1167,7 +1167,7 @@ function isEnd(
 function startsWithEndTagOpen(source: string, tag: string): boolean {
   return (
     startsWith(source, '</') &&
-    source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
+    source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
     /[\t\r\n\f />]/.test(source[2 + tag.length] || '>')
   )
 }
index ab5dd80ba8e0e453bd51cebd2ef22493b44b6aab..416cf79e9f9a3ae4b4436b5f6e4b10874b26794d 100644 (file)
@@ -182,10 +182,10 @@ export const isMemberExpression = __BROWSER__
 export function getInnerRange(
   loc: SourceLocation,
   offset: number,
-  length?: number
+  length: number
 ): SourceLocation {
   __TEST__ && assert(offset <= loc.source.length)
-  const source = loc.source.substr(offset, length)
+  const source = loc.source.slice(offset, offset + length)
   const newLoc: SourceLocation = {
     source,
     start: advancePositionWithClone(loc.start, loc.source, offset),
index b28592d95cee05430da32c702630ddd4703fe162..68b0277a434b1071873ef5dd387c4c684f02b4a6 100644 (file)
@@ -42,7 +42,7 @@ export const decodeHtml: ParserOptions['decodeEntities'] = (
           )
         }
         for (let length = maxCRNameLength; !value && length > 0; --length) {
-          name = rawText.substr(1, length)
+          name = rawText.slice(1, 1 + length)
           value = (namedCharacterReferences as Record<string, string>)[name]
         }
         if (value) {
index a15d04b2ceac4009d071f76fcd084c6cb0247640..65693b1f60db6cd99ab953572e867a9a21dabc80 100644 (file)
@@ -45,3 +45,10 @@ declare module '@vue/repl' {
   const ReplStore: any
   export { Repl, ReplStore }
 }
+
+declare interface String {
+  /**
+   * @deprecated Please use String.prototype.slice instead of String.prototype.substring in the repository.
+   */
+  substring(start: number, end?: number): string;
+}
index c0cc7a8b962911e5cf7071fc5d322faebbbadfdf..44b1d46f2304e4c1ccf59a5ce367aa578b32450a 100644 (file)
@@ -60,7 +60,7 @@ async function fetchVersions(): Promise<string[]> {
   )
   const releases: any[] = await res.json()
   const versions = releases.map(r =>
-    /^v/.test(r.tag_name) ? r.tag_name.substr(1) : r.tag_name
+    /^v/.test(r.tag_name) ? r.tag_name.slice(1) : r.tag_name
   )
   // if the latest version is a pre-release, list all current pre-releases
   // otherwise filter out pre-releases
index 4a6435e6a517cd1b0b0d9be9a1adcfdee80a2b40..bacd182ad976ae987d5c83e355fd99e2518be967 100644 (file)
@@ -34,14 +34,14 @@ export function escapeHtml(string: unknown) {
     }
 
     if (lastIndex !== index) {
-      html += str.substring(lastIndex, index)
+      html += str.slice(lastIndex, index)
     }
 
     lastIndex = index + 1
     html += escaped
   }
 
-  return lastIndex !== index ? html + str.substring(lastIndex, index) : html
+  return lastIndex !== index ? html + str.slice(lastIndex, index) : html
 }
 
 // https://www.w3.org/TR/html52/syntax.html#comments