mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Small micro optimizations to incremental parsing.
This commit is contained in:
@@ -711,12 +711,16 @@ module TypeScript.Parser {
|
||||
return sourceUnit;
|
||||
}
|
||||
|
||||
function isDirectivePrologueElement(node: ISyntaxNodeOrToken): boolean {
|
||||
return node.kind === SyntaxKind.ExpressionStatement &&
|
||||
(<ExpressionStatementSyntax>node).expression.kind === SyntaxKind.StringLiteral;
|
||||
}
|
||||
|
||||
function updateStrictModeState(items: any[]): void {
|
||||
if (!isInStrictMode) {
|
||||
// Check if all the items are directive prologue elements.
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
if (!SyntaxFacts.isDirectivePrologueElement(item)) {
|
||||
for (var i = 0, n = items.length; i < n; i++) {
|
||||
if (!isDirectivePrologueElement(items[i])) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -3864,7 +3868,7 @@ module TypeScript.Parser {
|
||||
}
|
||||
|
||||
function tryParseExpectedListItem(
|
||||
currentListType: ListParsingState, inErrorRecovery: boolean, items: ISyntaxElement[], processItems: (items: any[]) => void): boolean {
|
||||
currentListType: ListParsingState, inErrorRecovery: boolean, items: ISyntaxNodeOrToken[], processItems: (items: ISyntaxNodeOrToken[]) => void): boolean {
|
||||
var item = tryParseExpectedListItemWorker(currentListType, inErrorRecovery);
|
||||
|
||||
if (item === undefined) {
|
||||
@@ -3886,7 +3890,7 @@ module TypeScript.Parser {
|
||||
currentToken().kind === SyntaxKind.EndOfFileToken;
|
||||
}
|
||||
|
||||
function parseSyntaxListWorker<T extends ISyntaxNodeOrToken>(currentListType: ListParsingState, skippedTokens: ISyntaxToken[], processItems: (items: any[]) => void ): T[] {
|
||||
function parseSyntaxListWorker<T extends ISyntaxNodeOrToken>(currentListType: ListParsingState, skippedTokens: ISyntaxToken[], processItems: (items: ISyntaxNodeOrToken[]) => void ): T[] {
|
||||
var items: T[] = [];
|
||||
|
||||
while (true) {
|
||||
|
||||
@@ -349,12 +349,13 @@ module TypeScript.Scanner {
|
||||
}
|
||||
|
||||
function reset(_text: ISimpleText, _start: number, _end: number) {
|
||||
Debug.assert(_start <= _text.length(), "Token's start was not within the bounds of text: " + _start + " - [0, " + _text.length() + ")");
|
||||
Debug.assert(_end <= _text.length(), "Token's end was not within the bounds of text: " + _end + " - [0, " + _text.length() + ")");
|
||||
var textLength = _text.length();
|
||||
Debug.assert(_start <= textLength, "Token's start was not within the bounds of text.");
|
||||
Debug.assert(_end <= textLength, "Token's end was not within the bounds of text:");
|
||||
|
||||
if (!str || text !== _text) {
|
||||
text = _text;
|
||||
str = _text.substr(0, _text.length());
|
||||
str = _text.substr(0, textLength);
|
||||
}
|
||||
|
||||
start = _start;
|
||||
|
||||
@@ -2,16 +2,8 @@
|
||||
|
||||
module TypeScript.SyntaxFacts {
|
||||
export function isDirectivePrologueElement(node: ISyntaxNodeOrToken): boolean {
|
||||
if (node.kind === SyntaxKind.ExpressionStatement) {
|
||||
var expressionStatement = <ExpressionStatementSyntax>node;
|
||||
var expression = expressionStatement.expression;
|
||||
|
||||
if (expression.kind === SyntaxKind.StringLiteral) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return node.kind === SyntaxKind.ExpressionStatement &&
|
||||
(<ExpressionStatementSyntax>node).expression.kind === SyntaxKind.StringLiteral;
|
||||
}
|
||||
|
||||
export function isUseStrictDirective(node: ISyntaxNodeOrToken): boolean {
|
||||
|
||||
Reference in New Issue
Block a user