mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
Use substring instead of substr (#20578)
* Use substring instead of substr * Remove unused scanning of SyntaxKind.DotDotDotToken in jsdoc * Remove other unnecessary jsdoc syntax kinds * Move all pos++ together
This commit is contained in:
parent
464df8f699
commit
a23bbe65e6
@ -6276,17 +6276,17 @@ namespace ts {
|
||||
indent += text.length;
|
||||
}
|
||||
|
||||
nextJSDocToken();
|
||||
while (token() === SyntaxKind.WhitespaceTrivia) {
|
||||
nextJSDocToken();
|
||||
let t = nextJSDocToken();
|
||||
while (t === SyntaxKind.WhitespaceTrivia) {
|
||||
t = nextJSDocToken();
|
||||
}
|
||||
if (token() === SyntaxKind.NewLineTrivia) {
|
||||
if (t === SyntaxKind.NewLineTrivia) {
|
||||
state = JSDocState.BeginningOfLine;
|
||||
indent = 0;
|
||||
nextJSDocToken();
|
||||
t = nextJSDocToken();
|
||||
}
|
||||
while (token() !== SyntaxKind.EndOfFileToken) {
|
||||
switch (token()) {
|
||||
loop: while (true) {
|
||||
switch (t) {
|
||||
case SyntaxKind.AtToken:
|
||||
if (state === JSDocState.BeginningOfLine || state === JSDocState.SawAsterisk) {
|
||||
removeTrailingNewlines(comments);
|
||||
@ -6340,7 +6340,7 @@ namespace ts {
|
||||
indent += whitespace.length;
|
||||
break;
|
||||
case SyntaxKind.EndOfFileToken:
|
||||
break;
|
||||
break loop;
|
||||
default:
|
||||
// anything other than whitespace or asterisk at the beginning of the line starts the comment text
|
||||
state = JSDocState.SavingComments;
|
||||
@ -6348,10 +6348,11 @@ namespace ts {
|
||||
break;
|
||||
}
|
||||
if (advanceToken) {
|
||||
nextJSDocToken();
|
||||
t = nextJSDocToken();
|
||||
}
|
||||
else {
|
||||
advanceToken = true;
|
||||
t = currentToken as JsDocSyntaxKind;
|
||||
}
|
||||
}
|
||||
removeLeadingNewlines(comments);
|
||||
@ -6462,8 +6463,9 @@ namespace ts {
|
||||
comments.push(text);
|
||||
indent += text.length;
|
||||
}
|
||||
while (token() !== SyntaxKind.AtToken && token() !== SyntaxKind.EndOfFileToken) {
|
||||
switch (token()) {
|
||||
let tok = token() as JsDocSyntaxKind;
|
||||
loop: while (true) {
|
||||
switch (tok) {
|
||||
case SyntaxKind.NewLineTrivia:
|
||||
if (state >= JSDocState.SawAsterisk) {
|
||||
state = JSDocState.BeginningOfLine;
|
||||
@ -6472,8 +6474,9 @@ namespace ts {
|
||||
indent = 0;
|
||||
break;
|
||||
case SyntaxKind.AtToken:
|
||||
case SyntaxKind.EndOfFileToken:
|
||||
// Done
|
||||
break;
|
||||
break loop;
|
||||
case SyntaxKind.WhitespaceTrivia:
|
||||
if (state === JSDocState.SavingComments) {
|
||||
pushComment(scanner.getTokenText());
|
||||
@ -6501,11 +6504,7 @@ namespace ts {
|
||||
pushComment(scanner.getTokenText());
|
||||
break;
|
||||
}
|
||||
if (token() === SyntaxKind.AtToken) {
|
||||
// Done
|
||||
break;
|
||||
}
|
||||
nextJSDocToken();
|
||||
tok = nextJSDocToken();
|
||||
}
|
||||
|
||||
removeLeadingNewlines(comments);
|
||||
@ -6783,8 +6782,7 @@ namespace ts {
|
||||
let canParseTag = true;
|
||||
let seenAsterisk = false;
|
||||
while (true) {
|
||||
nextJSDocToken();
|
||||
switch (token()) {
|
||||
switch (nextJSDocToken()) {
|
||||
case SyntaxKind.AtToken:
|
||||
if (canParseTag) {
|
||||
const child = tryParseChildTag(target);
|
||||
@ -6880,7 +6878,7 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function nextJSDocToken(): SyntaxKind {
|
||||
function nextJSDocToken(): JsDocSyntaxKind {
|
||||
return currentToken = scanner.scanJSDocToken();
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ namespace ts {
|
||||
scanJsxAttributeValue(): SyntaxKind;
|
||||
reScanJsxToken(): SyntaxKind;
|
||||
scanJsxToken(): SyntaxKind;
|
||||
scanJSDocToken(): SyntaxKind;
|
||||
scanJSDocToken(): JsDocSyntaxKind;
|
||||
scan(): SyntaxKind;
|
||||
getText(): string;
|
||||
// Sets the text for the scanner to scan. An optional subrange starting point and length
|
||||
@ -1905,7 +1905,7 @@ namespace ts {
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokenValue += text.substr(firstCharPosition, pos - firstCharPosition);
|
||||
tokenValue += text.substring(firstCharPosition, pos);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
@ -1924,7 +1924,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function scanJSDocToken(): SyntaxKind {
|
||||
function scanJSDocToken(): JsDocSyntaxKind {
|
||||
if (pos >= end) {
|
||||
return token = SyntaxKind.EndOfFileToken;
|
||||
}
|
||||
@ -1933,6 +1933,7 @@ namespace ts {
|
||||
tokenPos = pos;
|
||||
|
||||
const ch = text.charCodeAt(pos);
|
||||
pos++;
|
||||
switch (ch) {
|
||||
case CharacterCodes.tab:
|
||||
case CharacterCodes.verticalTab:
|
||||
@ -1943,56 +1944,31 @@ namespace ts {
|
||||
}
|
||||
return token = SyntaxKind.WhitespaceTrivia;
|
||||
case CharacterCodes.at:
|
||||
pos++;
|
||||
return token = SyntaxKind.AtToken;
|
||||
case CharacterCodes.lineFeed:
|
||||
case CharacterCodes.carriageReturn:
|
||||
pos++;
|
||||
return token = SyntaxKind.NewLineTrivia;
|
||||
case CharacterCodes.asterisk:
|
||||
pos++;
|
||||
return token = SyntaxKind.AsteriskToken;
|
||||
case CharacterCodes.openBrace:
|
||||
pos++;
|
||||
return token = SyntaxKind.OpenBraceToken;
|
||||
case CharacterCodes.closeBrace:
|
||||
pos++;
|
||||
return token = SyntaxKind.CloseBraceToken;
|
||||
case CharacterCodes.openBracket:
|
||||
pos++;
|
||||
return token = SyntaxKind.OpenBracketToken;
|
||||
case CharacterCodes.closeBracket:
|
||||
pos++;
|
||||
return token = SyntaxKind.CloseBracketToken;
|
||||
case CharacterCodes.lessThan:
|
||||
pos++;
|
||||
return token = SyntaxKind.LessThanToken;
|
||||
case CharacterCodes.greaterThan:
|
||||
pos++;
|
||||
return token = SyntaxKind.GreaterThanToken;
|
||||
case CharacterCodes.equals:
|
||||
pos++;
|
||||
return token = SyntaxKind.EqualsToken;
|
||||
case CharacterCodes.comma:
|
||||
pos++;
|
||||
return token = SyntaxKind.CommaToken;
|
||||
case CharacterCodes.dot:
|
||||
pos++;
|
||||
if (text.substr(tokenPos, pos + 2) === "...") {
|
||||
pos += 2;
|
||||
return token = SyntaxKind.DotDotDotToken;
|
||||
}
|
||||
return token = SyntaxKind.DotToken;
|
||||
case CharacterCodes.exclamation:
|
||||
pos++;
|
||||
return token = SyntaxKind.ExclamationToken;
|
||||
case CharacterCodes.question:
|
||||
pos++;
|
||||
return token = SyntaxKind.QuestionToken;
|
||||
}
|
||||
|
||||
if (isIdentifierStart(ch, ScriptTarget.Latest)) {
|
||||
pos++;
|
||||
while (isIdentifierPart(text.charCodeAt(pos), ScriptTarget.Latest) && pos < end) {
|
||||
pos++;
|
||||
}
|
||||
@ -2000,7 +1976,7 @@ namespace ts {
|
||||
return token = SyntaxKind.Identifier;
|
||||
}
|
||||
else {
|
||||
return pos += 1, token = SyntaxKind.Unknown;
|
||||
return token = SyntaxKind.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -58,6 +58,23 @@ namespace ts {
|
||||
end: number;
|
||||
}
|
||||
|
||||
export type JsDocSyntaxKind =
|
||||
| SyntaxKind.EndOfFileToken
|
||||
| SyntaxKind.WhitespaceTrivia
|
||||
| SyntaxKind.AtToken
|
||||
| SyntaxKind.NewLineTrivia
|
||||
| SyntaxKind.AsteriskToken
|
||||
| SyntaxKind.OpenBraceToken
|
||||
| SyntaxKind.CloseBraceToken
|
||||
| SyntaxKind.LessThanToken
|
||||
| SyntaxKind.OpenBracketToken
|
||||
| SyntaxKind.CloseBracketToken
|
||||
| SyntaxKind.EqualsToken
|
||||
| SyntaxKind.CommaToken
|
||||
| SyntaxKind.DotToken
|
||||
| SyntaxKind.Identifier
|
||||
| SyntaxKind.Unknown;
|
||||
|
||||
// token > SyntaxKind.Identifer => token is a keyword
|
||||
// Also, If you add a new SyntaxKind be sure to keep the `Markers` section at the bottom in sync
|
||||
export const enum SyntaxKind {
|
||||
|
||||
@ -59,6 +59,7 @@ declare namespace ts {
|
||||
pos: number;
|
||||
end: number;
|
||||
}
|
||||
type JsDocSyntaxKind = SyntaxKind.EndOfFileToken | SyntaxKind.WhitespaceTrivia | SyntaxKind.AtToken | SyntaxKind.NewLineTrivia | SyntaxKind.AsteriskToken | SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.LessThanToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.EqualsToken | SyntaxKind.CommaToken | SyntaxKind.DotToken | SyntaxKind.Identifier | SyntaxKind.Unknown;
|
||||
enum SyntaxKind {
|
||||
Unknown = 0,
|
||||
EndOfFileToken = 1,
|
||||
@ -3127,7 +3128,7 @@ declare namespace ts {
|
||||
scanJsxAttributeValue(): SyntaxKind;
|
||||
reScanJsxToken(): SyntaxKind;
|
||||
scanJsxToken(): SyntaxKind;
|
||||
scanJSDocToken(): SyntaxKind;
|
||||
scanJSDocToken(): JsDocSyntaxKind;
|
||||
scan(): SyntaxKind;
|
||||
getText(): string;
|
||||
setText(text: string, start?: number, length?: number): void;
|
||||
|
||||
@ -59,6 +59,7 @@ declare namespace ts {
|
||||
pos: number;
|
||||
end: number;
|
||||
}
|
||||
type JsDocSyntaxKind = SyntaxKind.EndOfFileToken | SyntaxKind.WhitespaceTrivia | SyntaxKind.AtToken | SyntaxKind.NewLineTrivia | SyntaxKind.AsteriskToken | SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.LessThanToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.EqualsToken | SyntaxKind.CommaToken | SyntaxKind.DotToken | SyntaxKind.Identifier | SyntaxKind.Unknown;
|
||||
enum SyntaxKind {
|
||||
Unknown = 0,
|
||||
EndOfFileToken = 1,
|
||||
@ -2788,7 +2789,7 @@ declare namespace ts {
|
||||
scanJsxAttributeValue(): SyntaxKind;
|
||||
reScanJsxToken(): SyntaxKind;
|
||||
scanJsxToken(): SyntaxKind;
|
||||
scanJSDocToken(): SyntaxKind;
|
||||
scanJSDocToken(): JsDocSyntaxKind;
|
||||
scan(): SyntaxKind;
|
||||
getText(): string;
|
||||
setText(text: string, start?: number, length?: number): void;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user