Correctly set position of import declaration nodes

This commit is contained in:
Anders Hejlsberg
2015-02-06 14:44:24 -08:00
parent 7bd14a7895
commit 7e187ef75f

View File

@@ -4527,6 +4527,8 @@ module ts {
function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration {
parseExpected(SyntaxKind.ImportKeyword);
var afterImportPos = scanner.getStartPos();
var identifier: Identifier;
if (isIdentifier()) {
identifier = parseIdentifier();
@@ -4554,28 +4556,7 @@ module ts {
if (identifier || // import id
token === SyntaxKind.AsteriskToken || // import *
token === SyntaxKind.OpenBraceToken) { // import {
//ImportClause:
// ImportedDefaultBinding
// NameSpaceImport
// NamedImports
// ImportedDefaultBinding, NameSpaceImport
// ImportedDefaultBinding, NamedImports
var importClause = <ImportClause>createNode(SyntaxKind.ImportClause);
if (identifier) {
// ImportedDefaultBinding:
// ImportedBinding
importClause.name = identifier;
}
// If there was no default import or if there is comma token after default import
// parse namespace or named imports
if (!importClause.name ||
parseOptional(SyntaxKind.CommaToken)) {
importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports();
}
importDeclaration.importClause = finishNode(importClause);
importDeclaration.importClause = parseImportClause(identifier, afterImportPos);
parseExpected(SyntaxKind.FromKeyword);
}
@@ -4584,6 +4565,31 @@ module ts {
return finishNode(importDeclaration);
}
function parseImportClause(identifier: Identifier, fullStart: number) {
//ImportClause:
// ImportedDefaultBinding
// NameSpaceImport
// NamedImports
// ImportedDefaultBinding, NameSpaceImport
// ImportedDefaultBinding, NamedImports
var importClause = <ImportClause>createNode(SyntaxKind.ImportClause, fullStart);
if (identifier) {
// ImportedDefaultBinding:
// ImportedBinding
importClause.name = identifier;
}
// If there was no default import or if there is comma token after default import
// parse namespace or named imports
if (!importClause.name ||
parseOptional(SyntaxKind.CommaToken)) {
importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports();
}
return finishNode(importClause);
}
function parseModuleReference() {
return isExternalModuleReference()
? parseExternalModuleReference()