Skip to content

Commit

Permalink
Merge branch 'refactor/rm-deprecated-substr'
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Jul 11, 2022
2 parents f8bcd6e + 52fb3c6 commit db54b76
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions server/src/embeddedSupport/vueDocumentRegionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function scanTemplateRegion(scanner: Scanner, text: string): EmbeddedRegion | nu
} else if (token === HtmlTokenType.Unknown) {
if (scanner.getTokenText().charAt(0) === '<') {
const offset = scanner.getTokenOffset();
const unknownText = text.substr(offset, 11);
const unknownText = text.slice(offset, offset + 11);
if (unknownText === '</template>') {
unClosedTemplate--;
// test leading </template>
Expand Down Expand Up @@ -231,7 +231,7 @@ function scanCustomRegion(tagName: string, scanner: Scanner, text: string): Embe
} else if (token === HtmlTokenType.Unknown) {
if (scanner.getTokenText().charAt(0) === '<') {
const offset = scanner.getTokenOffset();
const unknownText = text.substr(offset, `</${tagName}>`.length);
const unknownText = text.slice(offset, offset + `</${tagName}>`.length);
if (unknownText === `</${tagName}>`) {
unClosedTag--;
// test leading </${tagName}>
Expand Down
2 changes: 1 addition & 1 deletion server/src/modes/script/previewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getTagBodyText(tag: ts.JSDocTagInfo): string | undefined {
// check for caption tags, fix for #79704
const captionTagMatches = plain(tag.text).match(/<caption>(.*?)<\/caption>\s*(\r\n|\n)/);
if (captionTagMatches && captionTagMatches.index === 0) {
return captionTagMatches[1] + '\n\n' + makeCodeblock(plain(tag.text).substr(captionTagMatches[0].length));
return captionTagMatches[1] + '\n\n' + makeCodeblock(plain(tag.text).slice(captionTagMatches[0].length));
} else {
return makeCodeblock(plain(tag.text));
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/modes/template/parser/htmlScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class MultiLineStream {
}

public advanceIfRegExp(regex: RegExp): string {
const str = this.source.substr(this.position);
const str = this.source.slice(this.position);
const match = str.match(regex);
if (match) {
this.position = this.position + match.index! + match[0].length;
Expand All @@ -112,7 +112,7 @@ class MultiLineStream {
}

public advanceUntilRegExp(regex: RegExp): string {
const str = this.source.substr(this.position);
const str = this.source.slice(this.position);
const match = str.match(regex);
if (match) {
this.position = this.position + match.index!;
Expand Down
2 changes: 1 addition & 1 deletion server/src/modes/template/test/highlighting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { findDocumentHighlights } from '../services/htmlHighlighting';
suite('HTML Highlighting', () => {
function assertHighlights(value: string, expectedMatches: number[], elementName: string | null): void {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);
value = value.slice(0, offset) + value.slice(offset + 1);

const document = TextDocument.create('test://test/test.html', 'html', 0, value);

Expand Down
5 changes: 4 additions & 1 deletion server/src/modes/template/test/scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ suite('HTML Scanner', () => {
while (tokenType !== HtmlTokenType.EOS) {
const actualToken: Token = { offset: scanner.getTokenOffset(), type: tokenType };
if (tokenType === HtmlTokenType.StartTag || tokenType === HtmlTokenType.EndTag) {
actualToken.content = t.input.substr(scanner.getTokenOffset(), scanner.getTokenLength());
actualToken.content = t.input.slice(
scanner.getTokenOffset(),
scanner.getTokenOffset() + scanner.getTokenLength()
);
}
actual.push(actualToken);
tokenType = scanner.scan();
Expand Down
2 changes: 1 addition & 1 deletion server/src/modes/test-util/completion-test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface CompletionTestSetup {
export function testDSL(setup: CompletionTestSetup): (text: TemplateStringsArray) => CompletionAsserter {
return function test([value]: TemplateStringsArray) {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);
value = value.substring(0, offset) + value.slice(offset + 1);

const document = TextDocument.create(setup.docUri, setup.langId, 0, value);
const position = document.positionAt(offset);
Expand Down
2 changes: 1 addition & 1 deletion server/src/modes/test-util/hover-test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class HoverAsserter {
export function hoverDSL(setup: HoverTestSetup) {
return function test([value]: TemplateStringsArray) {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);
value = value.slice(0, offset) + value.slice(offset + 1);
const document = TextDocument.create(setup.docUri, setup.langId, 0, value);

const position = document.positionAt(offset);
Expand Down
2 changes: 1 addition & 1 deletion server/src/modes/test/region.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function testcase(description: string) {
let content = generateContent();
const offset = content.indexOf('|');
if (offset >= 0) {
content = content.substr(0, offset) + content.substr(offset + 1);
content = content.slice(0, offset) + content.slice(offset + 1);
}
const doc = TextDocument.create('test://test/test.vue', 'vue', 0, content);

Expand Down
2 changes: 1 addition & 1 deletion server/src/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getWordAtText(text: string, offset: number, wordDefinition: RegE
lineStart--;
}
const offsetInLine = offset - lineStart;
const lineText = text.substr(lineStart);
const lineText = text.slice(lineStart);

// make a copy of the regex as to not keep the state
const flags = wordDefinition.ignoreCase ? 'gi' : 'g';
Expand Down

0 comments on commit db54b76

Please sign in to comment.