mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 11:54:44 -06:00
Check for CR, LF, space, and tab before doing the lookup.
This commit is contained in:
parent
811526d993
commit
9830671eef
@ -1991,28 +1991,41 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
|
||||
|
||||
const ch = codePointUnchecked(pos);
|
||||
|
||||
if (ch === CharacterCodes.tab || ch === CharacterCodes.space) {
|
||||
if (skipTrivia) {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
while (pos < end && isWhiteSpaceSingleLine(charCodeUnchecked(pos))) {
|
||||
pos++;
|
||||
}
|
||||
return token = SyntaxKind.WhitespaceTrivia;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch === CharacterCodes.lineFeed || ch === CharacterCodes.carriageReturn) {
|
||||
tokenFlags |= TokenFlags.PrecedingLineBreak;
|
||||
if (skipTrivia) {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if (ch === CharacterCodes.carriageReturn && pos + 1 < end && charCodeUnchecked(pos + 1) === CharacterCodes.lineFeed) {
|
||||
// consume both CR and LF
|
||||
pos += 2;
|
||||
}
|
||||
else {
|
||||
pos++;
|
||||
}
|
||||
return token = SyntaxKind.NewLineTrivia;
|
||||
}
|
||||
}
|
||||
|
||||
const tokenInfo = ch < charcodeToTokenInfoCommon.length ?
|
||||
charcodeToTokenInfoCommon[ch] :
|
||||
charcodeToTokenInfoUncommon.get(ch) ?? TokenInfo.None;
|
||||
if (tokenInfo !== TokenInfo.None) {
|
||||
if (tokenInfo & TokenInfo.LineBreak) {
|
||||
tokenFlags |= TokenFlags.PrecedingLineBreak;
|
||||
if (skipTrivia) {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if (ch === CharacterCodes.carriageReturn && pos + 1 < end && charCodeUnchecked(pos + 1) === CharacterCodes.lineFeed) {
|
||||
// consume both CR and LF
|
||||
pos += 2;
|
||||
}
|
||||
else {
|
||||
pos++;
|
||||
}
|
||||
return token = SyntaxKind.NewLineTrivia;
|
||||
}
|
||||
}
|
||||
|
||||
if (tokenInfo & TokenInfo.Whitespace) {
|
||||
if (skipTrivia) {
|
||||
pos++;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user