mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Merge branch 'master' into parserErrors2
This commit is contained in:
commit
15e6b64ff6
@ -972,10 +972,8 @@ module ts {
|
||||
}
|
||||
|
||||
export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: string, isOpen: boolean = false): SourceFile {
|
||||
var scanner: Scanner;
|
||||
var token: SyntaxKind;
|
||||
var parsingContext: ParsingContext;
|
||||
var commentRanges: TextRange[];
|
||||
var identifiers: Map<string> = {};
|
||||
var identifierCount = 0;
|
||||
var nodeCount = 0;
|
||||
@ -1184,10 +1182,6 @@ module ts {
|
||||
parseErrorAtPosition(pos, 0, message);
|
||||
}
|
||||
|
||||
function onComment(pos: number, end: number) {
|
||||
if (commentRanges) commentRanges.push({ pos: pos, end: end });
|
||||
}
|
||||
|
||||
function getNodePos(): number {
|
||||
return scanner.getStartPos();
|
||||
}
|
||||
@ -4267,14 +4261,25 @@ module ts {
|
||||
}
|
||||
|
||||
function processReferenceComments(): ReferenceComments {
|
||||
var triviaScanner = createScanner(languageVersion, /*skipTrivia*/false, sourceText);
|
||||
var referencedFiles: FileReference[] = [];
|
||||
var amdDependencies: string[] = [];
|
||||
var amdModuleName: string;
|
||||
commentRanges = [];
|
||||
token = scanner.scan();
|
||||
|
||||
for (var i = 0; i < commentRanges.length; i++) {
|
||||
var range = commentRanges[i];
|
||||
// Keep scanning all the leading trivia in the file until we get to something that
|
||||
// isn't trivia. Any single line comment will be analyzed to see if it is a
|
||||
// reference comment.
|
||||
while (true) {
|
||||
var kind = triviaScanner.scan();
|
||||
if (kind === SyntaxKind.WhitespaceTrivia || kind === SyntaxKind.NewLineTrivia || kind === SyntaxKind.MultiLineCommentTrivia) {
|
||||
continue;
|
||||
}
|
||||
if (kind !== SyntaxKind.SingleLineCommentTrivia) {
|
||||
break;
|
||||
}
|
||||
|
||||
var range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos() };
|
||||
|
||||
var comment = sourceText.substring(range.pos, range.end);
|
||||
var referencePathMatchResult = getFileReferenceFromReferencePath(comment, range);
|
||||
if (referencePathMatchResult) {
|
||||
@ -4305,7 +4310,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
commentRanges = undefined;
|
||||
|
||||
return {
|
||||
referencedFiles,
|
||||
amdDependencies,
|
||||
@ -4341,7 +4346,6 @@ module ts {
|
||||
return syntacticDiagnostics;
|
||||
}
|
||||
|
||||
scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError, onComment);
|
||||
var rootNodeFlags: NodeFlags = 0;
|
||||
if (fileExtensionIs(filename, ".d.ts")) {
|
||||
rootNodeFlags = NodeFlags.DeclarationFile;
|
||||
@ -4367,6 +4371,10 @@ module ts {
|
||||
sourceFile.amdDependencies = referenceComments.amdDependencies;
|
||||
sourceFile.amdModuleName = referenceComments.amdModuleName;
|
||||
|
||||
// Create and prime the scanner before parsing the source elements.
|
||||
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError);
|
||||
nextToken();
|
||||
|
||||
sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement);
|
||||
Debug.assert(token === SyntaxKind.EndOfFileToken);
|
||||
sourceFile.endOfFileToken = parseTokenNode();
|
||||
|
||||
@ -472,7 +472,7 @@ module ts {
|
||||
ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion);
|
||||
}
|
||||
|
||||
export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, text?: string, onError?: ErrorCallback, onComment?: CommentCallback): Scanner {
|
||||
export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, text?: string, onError?: ErrorCallback): Scanner {
|
||||
var pos: number; // Current position (end position of text of current token)
|
||||
var len: number; // Length of text
|
||||
var startPos: number; // Start position of whitespace before current token
|
||||
@ -908,9 +908,6 @@ module ts {
|
||||
pos++;
|
||||
|
||||
}
|
||||
if (onComment) {
|
||||
onComment(tokenPos, pos);
|
||||
}
|
||||
|
||||
if (skipTrivia) {
|
||||
continue;
|
||||
@ -943,10 +940,6 @@ module ts {
|
||||
error(Diagnostics.Asterisk_Slash_expected);
|
||||
}
|
||||
|
||||
if (onComment) {
|
||||
onComment(tokenPos, pos);
|
||||
}
|
||||
|
||||
if (skipTrivia) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user