Rename existing import declaration to ImportEqualsDeclaration

This commit is contained in:
Sheetal Nandi 2015-01-27 14:42:20 -08:00
parent a43bb47d7b
commit e0581899fa
10 changed files with 120 additions and 120 deletions

View file

@ -18,7 +18,7 @@ module ts {
return ModuleInstanceState.ConstEnumOnly;
}
// 3. non - exported import declarations
else if (node.kind === SyntaxKind.ImportDeclaration && !(node.flags & NodeFlags.Export)) {
else if (node.kind === SyntaxKind.ImportEqualsDeclaration && !(node.flags & NodeFlags.Export)) {
return ModuleInstanceState.NonInstantiated;
}
// 4. other uninstantiated module declarations.
@ -200,7 +200,7 @@ module ts {
exportKind |= SymbolFlags.ExportNamespace;
}
if (getCombinedNodeFlags(node) & NodeFlags.Export || (node.kind !== SyntaxKind.ImportDeclaration && isAmbientContext(container))) {
if (getCombinedNodeFlags(node) & NodeFlags.Export || (node.kind !== SyntaxKind.ImportEqualsDeclaration && isAmbientContext(container))) {
if (exportKind) {
var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
@ -466,7 +466,7 @@ module ts {
case SyntaxKind.ModuleDeclaration:
bindModuleDeclaration(<ModuleDeclaration>node);
break;
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
bindDeclaration(<Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.SourceFile:

View file

@ -444,7 +444,7 @@ module ts {
var links = getSymbolLinks(symbol);
if (!links.target) {
links.target = resolvingSymbol;
var node = <ImportDeclaration>getDeclarationOfKind(symbol, SyntaxKind.ImportDeclaration);
var node = <ImportEqualsDeclaration>getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration);
// Grammar checking
if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) {
if ((<ExternalModuleReference>node.moduleReference).expression.kind !== SyntaxKind.StringLiteral) {
@ -453,8 +453,8 @@ module ts {
}
var target = node.moduleReference.kind === SyntaxKind.ExternalModuleReference
? resolveExternalModuleName(node, getExternalModuleImportDeclarationExpression(node))
: getSymbolOfPartOfRightHandSideOfImport(<EntityName>node.moduleReference, node);
? resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node))
: getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference, node);
if (links.target === resolvingSymbol) {
links.target = target || unknownSymbol;
}
@ -469,9 +469,9 @@ module ts {
}
// This function is only for imports with entity names
function getSymbolOfPartOfRightHandSideOfImport(entityName: EntityName, importDeclaration?: ImportDeclaration): Symbol {
function getSymbolOfPartOfRightHandSideOfImportEquals(entityName: EntityName, importDeclaration?: ImportEqualsDeclaration): Symbol {
if (!importDeclaration) {
importDeclaration = <ImportDeclaration>getAncestor(entityName, SyntaxKind.ImportDeclaration);
importDeclaration = <ImportEqualsDeclaration>getAncestor(entityName, SyntaxKind.ImportEqualsDeclaration);
Debug.assert(importDeclaration !== undefined);
}
// There are three things we might try to look for. In the following examples,
@ -490,7 +490,7 @@ module ts {
else {
// Case 2 in above example
// entityName.kind could be a QualifiedName or a Missing identifier
Debug.assert(entityName.parent.kind === SyntaxKind.ImportDeclaration);
Debug.assert(entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration);
return resolveEntityName(importDeclaration, entityName, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
}
}
@ -808,7 +808,7 @@ module ts {
if (symbolFromSymbolTable.flags & SymbolFlags.Import) {
if (!useOnlyExternalAliasing || // We can use any type of alias to get the name
// Is this external alias, then use it to name
ts.forEach(symbolFromSymbolTable.declarations, isExternalModuleImportDeclaration)) {
ts.forEach(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration)) {
var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable);
if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) {
@ -934,7 +934,7 @@ module ts {
}
function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult {
var aliasesToMakeVisible: ImportDeclaration[];
var aliasesToMakeVisible: ImportEqualsDeclaration[];
if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) {
return undefined;
}
@ -944,17 +944,17 @@ module ts {
if (!isDeclarationVisible(declaration)) {
// Mark the unexported alias as visible if its parent is visible
// because these kind of aliases can be used to name types in declaration file
if (declaration.kind === SyntaxKind.ImportDeclaration &&
if (declaration.kind === SyntaxKind.ImportEqualsDeclaration &&
!(declaration.flags & NodeFlags.Export) &&
isDeclarationVisible(<Declaration>declaration.parent)) {
getNodeLinks(declaration).isVisible = true;
if (aliasesToMakeVisible) {
if (!contains(aliasesToMakeVisible, declaration)) {
aliasesToMakeVisible.push(<ImportDeclaration>declaration);
aliasesToMakeVisible.push(<ImportEqualsDeclaration>declaration);
}
}
else {
aliasesToMakeVisible = [<ImportDeclaration>declaration];
aliasesToMakeVisible = [<ImportEqualsDeclaration>declaration];
}
return true;
}
@ -975,7 +975,7 @@ module ts {
meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
}
else if (entityName.kind === SyntaxKind.QualifiedName ||
entityName.parent.kind === SyntaxKind.ImportDeclaration) {
entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration) {
// Left identifier from type reference or TypeAlias
// Entity name of the import declaration
meaning = SymbolFlags.Namespace;
@ -1583,11 +1583,11 @@ module ts {
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
var parent = getDeclarationContainer(node);
// If the node is not exported or it is not ambient module element (except import declaration)
if (!(getCombinedNodeFlags(node) & NodeFlags.Export) &&
!(node.kind !== SyntaxKind.ImportDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) {
!(node.kind !== SyntaxKind.ImportEqualsDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) {
return isGlobalSourceFile(parent) || isUsedInExportAssignment(node);
}
// Exported members/ambient module elements (exception import declaration) are visible if parent is visible
@ -4820,7 +4820,7 @@ module ts {
}
/*Transitively mark all linked imports as referenced*/
function markLinkedImportsAsReferenced(node: ImportDeclaration): void {
function markLinkedImportsAsReferenced(node: ImportEqualsDeclaration): void {
var nodeLinks = getNodeLinks(node);
while (nodeLinks.importOnRightSide) {
var rightSide = nodeLinks.importOnRightSide;
@ -4829,7 +4829,7 @@ module ts {
getSymbolLinks(rightSide).referenced = true;
Debug.assert((rightSide.flags & SymbolFlags.Import) !== 0);
nodeLinks = getNodeLinks(getDeclarationOfKind(rightSide, SyntaxKind.ImportDeclaration))
nodeLinks = getNodeLinks(getDeclarationOfKind(rightSide, SyntaxKind.ImportEqualsDeclaration))
}
}
@ -4839,7 +4839,7 @@ module ts {
if (symbol.flags & SymbolFlags.Import) {
var symbolLinks = getSymbolLinks(symbol);
if (!symbolLinks.referenced) {
var importOrExportAssignment = getLeftSideOfImportOrExportAssignment(node);
var importOrExportAssignment = getLeftSideOfImportEqualsOrExportAssignment(node);
// decision about whether import is referenced can be made now if
// - import that are used anywhere except right side of import declarations
@ -4860,7 +4860,7 @@ module ts {
}
if (symbolLinks.referenced) {
markLinkedImportsAsReferenced(<ImportDeclaration>getDeclarationOfKind(symbol, SyntaxKind.ImportDeclaration));
markLinkedImportsAsReferenced(<ImportEqualsDeclaration>getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration));
}
}
@ -7931,7 +7931,7 @@ module ts {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.EnumDeclaration:
return SymbolFlags.ExportType | SymbolFlags.ExportValue;
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
var result: SymbolFlags = 0;
var target = resolveImport(getSymbolOfNode(d));
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); });
@ -9150,8 +9150,8 @@ module ts {
// Export assignments are not allowed in an internal module
grammarErrorOnNode(statement, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module);
}
else if (isExternalModuleImportDeclaration(statement)) {
grammarErrorOnNode(getExternalModuleImportDeclarationExpression(statement), Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module);
else if (isExternalModuleImportEqualsDeclaration(statement)) {
grammarErrorOnNode(getExternalModuleImportEqualsDeclarationExpression(statement), Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module);
}
}
}
@ -9198,7 +9198,7 @@ module ts {
return <Identifier>node;
}
function checkImportDeclaration(node: ImportDeclaration) {
function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) {
// Grammar checking
checkGrammarModifiers(node);
@ -9207,7 +9207,7 @@ module ts {
var symbol = getSymbolOfNode(node);
var target: Symbol;
if (isInternalModuleImportDeclaration(node)) {
if (isInternalModuleImportEqualsDeclaration(node)) {
target = resolveImport(symbol);
// Import declaration for an internal module
if (target !== unknownSymbol) {
@ -9237,8 +9237,8 @@ module ts {
// An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference
// other external modules only through top - level external module names.
// Relative external module names are not permitted.
if (getExternalModuleImportDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
if (isExternalModuleNameRelative((<LiteralExpression>getExternalModuleImportDeclarationExpression(node)).text)) {
if (getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
if (isExternalModuleNameRelative((<LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(node)).text)) {
error(node, Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name);
target = unknownSymbol;
}
@ -9367,8 +9367,8 @@ module ts {
return checkEnumDeclaration(<EnumDeclaration>node);
case SyntaxKind.ModuleDeclaration:
return checkModuleDeclaration(<ModuleDeclaration>node);
case SyntaxKind.ImportDeclaration:
return checkImportDeclaration(<ImportDeclaration>node);
case SyntaxKind.ImportEqualsDeclaration:
return checkImportEqualsDeclaration(<ImportEqualsDeclaration>node);
case SyntaxKind.ExportAssignment:
return checkExportAssignment(<ExportAssignment>node);
case SyntaxKind.EmptyStatement:
@ -9487,7 +9487,7 @@ module ts {
// Mark the import as referenced so that we emit it in the final .js file.
getSymbolLinks(symbol).referenced = true;
// mark any import declarations that depend upon this import as referenced
markLinkedImportsAsReferenced(<ImportDeclaration>getDeclarationOfKind(symbol, SyntaxKind.ImportDeclaration))
markLinkedImportsAsReferenced(<ImportEqualsDeclaration>getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration))
}
}
@ -9715,13 +9715,13 @@ module ts {
return false;
}
function getLeftSideOfImportOrExportAssignment(nodeOnRightSide: EntityName): ImportDeclaration | ExportAssignment {
function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide: EntityName): ImportEqualsDeclaration | ExportAssignment {
while (nodeOnRightSide.parent.kind === SyntaxKind.QualifiedName) {
nodeOnRightSide = <QualifiedName>nodeOnRightSide.parent;
}
if (nodeOnRightSide.parent.kind === SyntaxKind.ImportDeclaration) {
return (<ImportDeclaration>nodeOnRightSide.parent).moduleReference === nodeOnRightSide && <ImportDeclaration>nodeOnRightSide.parent;
if (nodeOnRightSide.parent.kind === SyntaxKind.ImportEqualsDeclaration) {
return (<ImportEqualsDeclaration>nodeOnRightSide.parent).moduleReference === nodeOnRightSide && <ImportEqualsDeclaration>nodeOnRightSide.parent;
}
if (nodeOnRightSide.parent.kind === SyntaxKind.ExportAssignment) {
@ -9732,7 +9732,7 @@ module ts {
}
function isInRightSideOfImportOrExportAssignment(node: EntityName) {
return getLeftSideOfImportOrExportAssignment(node) !== undefined;
return getLeftSideOfImportEqualsOrExportAssignment(node) !== undefined;
}
function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {
@ -9753,7 +9753,7 @@ module ts {
if (entityName.kind !== SyntaxKind.PropertyAccessExpression) {
if (isInRightSideOfImportOrExportAssignment(<EntityName>entityName)) {
// Since we already checked for ExportAssignment, this really could only be an Import
return getSymbolOfPartOfRightHandSideOfImport(<EntityName>entityName);
return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>entityName);
}
}
@ -9814,7 +9814,7 @@ module ts {
if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(<Identifier>node)) {
return node.parent.kind === SyntaxKind.ExportAssignment
? getSymbolOfEntityNameOrPropertyAccessExpression(<Identifier>node)
: getSymbolOfPartOfRightHandSideOfImport(<Identifier>node);
: getSymbolOfPartOfRightHandSideOfImportEquals(<Identifier>node);
}
switch (node.kind) {
@ -9838,8 +9838,8 @@ module ts {
case SyntaxKind.StringLiteral:
// External module name in an import declaration
if (isExternalModuleImportDeclaration(node.parent.parent) &&
getExternalModuleImportDeclarationExpression(node.parent.parent) === node) {
if (isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) {
var importSymbol = getSymbolOfNode(node.parent.parent);
var moduleType = getTypeOfSymbol(importSymbol);
return moduleType ? moduleType.symbol : undefined;
@ -9980,8 +9980,8 @@ module ts {
// An import can be emitted too, if it is referenced as a value.
// Make sure the name in question does not collide with an import.
if (symbolWithRelevantName.flags & SymbolFlags.Import) {
var importDeclarationWithRelevantName = <ImportDeclaration>getDeclarationOfKind(symbolWithRelevantName, SyntaxKind.ImportDeclaration);
if (isReferencedImportDeclaration(importDeclarationWithRelevantName)) {
var importEqualsDeclarationWithRelevantName = <ImportEqualsDeclaration>getDeclarationOfKind(symbolWithRelevantName, SyntaxKind.ImportEqualsDeclaration);
if (isReferencedImportEqualsDeclaration(importEqualsDeclarationWithRelevantName)) {
return false;
}
}
@ -10037,8 +10037,8 @@ module ts {
return symbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol): undefined;
}
function isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean {
if (node.parent.kind !== SyntaxKind.SourceFile || !isInternalModuleImportDeclaration(node)) {
function isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean {
if (node.parent.kind !== SyntaxKind.SourceFile || !isInternalModuleImportEqualsDeclaration(node)) {
// parent is not source file or it is not reference to internal module
return false;
}
@ -10060,7 +10060,7 @@ module ts {
return isConstEnumSymbol(s) || s.constEnumOnlyModule;
}
function isReferencedImportDeclaration(node: ImportDeclaration): boolean {
function isReferencedImportEqualsDeclaration(node: ImportEqualsDeclaration): boolean {
var symbol = getSymbolOfNode(node);
if (getSymbolLinks(symbol).referenced) {
return true;
@ -10140,10 +10140,10 @@ module ts {
getLocalNameOfContainer,
getExpressionNamePrefix,
getExportAssignmentName,
isReferencedImportDeclaration,
isReferencedImportEqualsDeclaration,
getNodeCheckFlags,
getEnumMemberValue,
isTopLevelValueImportWithEntityName,
isTopLevelValueImportEqualsWithEntityName,
hasSemanticErrors,
isDeclarationVisible,
isImplementationOfOverload,
@ -10210,7 +10210,7 @@ module ts {
case SyntaxKind.VariableStatement:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.Parameter:
break;
default:
@ -10315,7 +10315,7 @@ module ts {
return grammarErrorOnNode(lastPrivate, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
}
}
else if (node.kind === SyntaxKind.ImportDeclaration && flags & NodeFlags.Ambient) {
else if (node.kind === SyntaxKind.ImportEqualsDeclaration && flags & NodeFlags.Ambient) {
return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare");
}
else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) {
@ -11037,7 +11037,7 @@ module ts {
// export_opt AmbientDeclaration
//
if (node.kind === SyntaxKind.InterfaceDeclaration ||
node.kind === SyntaxKind.ImportDeclaration ||
node.kind === SyntaxKind.ImportEqualsDeclaration ||
node.kind === SyntaxKind.ExportAssignment ||
(node.flags & NodeFlags.Ambient)) {

View file

@ -28,7 +28,7 @@ module ts {
}
interface AliasDeclarationEmitInfo {
declaration: ImportDeclaration;
declaration: ImportEqualsDeclaration;
outputPos: number;
indent: number;
asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output
@ -381,9 +381,9 @@ module ts {
decreaseIndent = newWriter.decreaseIndent;
}
function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) {
function writeAsychronousImportEqualsDeclarations(importEqualsDeclarations: ImportEqualsDeclaration[]) {
var oldWriter = writer;
forEach(importDeclarations, aliasToWrite => {
forEach(importEqualsDeclarations, aliasToWrite => {
var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined);
// If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration
// then we don't need to write it at this point. We will write it when we actually see its declaration
@ -397,7 +397,7 @@ module ts {
for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
increaseIndent();
}
writeImportDeclaration(aliasToWrite);
writeImportEqualsDeclaration(aliasToWrite);
aliasEmitInfo.asynchronousOutput = writer.getText();
}
});
@ -408,7 +408,7 @@ module ts {
if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) {
// write the aliases
if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
writeAsychronousImportEqualsDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
}
}
else {
@ -533,7 +533,7 @@ module ts {
function emitEntityName(entityName: EntityName) {
var visibilityResult = resolver.isEntityNameVisible(entityName,
// Aliases can be written asynchronously so use correct enclosing declaration
entityName.parent.kind === SyntaxKind.ImportDeclaration ? entityName.parent : enclosingDeclaration);
entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration ? entityName.parent : enclosingDeclaration);
handleSymbolAccessibilityError(visibilityResult);
writeEntityName(entityName);
@ -639,7 +639,7 @@ module ts {
}
}
function emitImportDeclaration(node: ImportDeclaration) {
function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) {
var nodeEmitInfo = {
declaration: node,
outputPos: writer.getTextPos(),
@ -648,11 +648,11 @@ module ts {
};
aliasDeclarationEmitInfo.push(nodeEmitInfo);
if (nodeEmitInfo.hasWritten) {
writeImportDeclaration(node);
writeImportEqualsDeclaration(node);
}
}
function writeImportDeclaration(node: ImportDeclaration) {
function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) {
// note usage of writer. methods instead of aliases created, just to make sure we are using
// correct writer especially to handle asynchronous alias writing
emitJsDocComments(node);
@ -662,13 +662,13 @@ module ts {
write("import ");
writeTextOfNode(currentSourceFile, node.name);
write(" = ");
if (isInternalModuleImportDeclaration(node)) {
if (isInternalModuleImportEqualsDeclaration(node)) {
emitTypeWithNewGetSymbolAccessibilityDiagnostic(<EntityName>node.moduleReference, getImportEntityNameVisibilityError);
write(";");
}
else {
write("require(");
writeTextOfNode(currentSourceFile, getExternalModuleImportDeclarationExpression(node));
writeTextOfNode(currentSourceFile, getExternalModuleImportEqualsDeclarationExpression(node));
write(");");
}
writer.writeLine();
@ -1393,8 +1393,8 @@ module ts {
return emitEnumDeclaration(<EnumDeclaration>node);
case SyntaxKind.ModuleDeclaration:
return emitModuleDeclaration(<ModuleDeclaration>node);
case SyntaxKind.ImportDeclaration:
return emitImportDeclaration(<ImportDeclaration>node);
case SyntaxKind.ImportEqualsDeclaration:
return emitImportEqualsDeclaration(<ImportEqualsDeclaration>node);
case SyntaxKind.ExportAssignment:
return emitExportAssignment(<ExportAssignment>node);
case SyntaxKind.SourceFile:
@ -2248,7 +2248,7 @@ module ts {
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
return (<Declaration>parent).name === node;
case SyntaxKind.BreakStatement:
case SyntaxKind.ContinueStatement:
@ -3791,18 +3791,18 @@ module ts {
emitTrailingComments(node);
}
function emitImportDeclaration(node: ImportDeclaration) {
var emitImportDeclaration = resolver.isReferencedImportDeclaration(node);
function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) {
var emitImportDeclaration = resolver.isReferencedImportEqualsDeclaration(node);
if (!emitImportDeclaration) {
// preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when
// - current file is not external module
// - import declaration is top level and target is value imported by entity name
emitImportDeclaration = !isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node);
emitImportDeclaration = !isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node);
}
if (emitImportDeclaration) {
if (isExternalModuleImportDeclaration(node) && node.parent.kind === SyntaxKind.SourceFile && compilerOptions.module === ModuleKind.AMD) {
if (isExternalModuleImportEqualsDeclaration(node) && node.parent.kind === SyntaxKind.SourceFile && compilerOptions.module === ModuleKind.AMD) {
if (node.flags & NodeFlags.Export) {
writeLine();
emitLeadingComments(node);
@ -3822,11 +3822,11 @@ module ts {
if (!(node.flags & NodeFlags.Export)) write("var ");
emitModuleMemberName(node);
write(" = ");
if (isInternalModuleImportDeclaration(node)) {
if (isInternalModuleImportEqualsDeclaration(node)) {
emit(node.moduleReference);
}
else {
var literal = <LiteralExpression>getExternalModuleImportDeclarationExpression(node);
var literal = <LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(node);
write("require(");
emitStart(literal);
emitLiteral(literal);
@ -3840,11 +3840,11 @@ module ts {
}
}
function getExternalImportDeclarations(node: SourceFile): ImportDeclaration[] {
var result: ImportDeclaration[] = [];
function getExternalImportEqualsDeclarations(node: SourceFile): ImportEqualsDeclaration[] {
var result: ImportEqualsDeclaration[] = [];
forEach(node.statements, statement => {
if (isExternalModuleImportDeclaration(statement) && resolver.isReferencedImportDeclaration(<ImportDeclaration>statement)) {
result.push(<ImportDeclaration>statement);
if (isExternalModuleImportEqualsDeclaration(statement) && resolver.isReferencedImportEqualsDeclaration(<ImportEqualsDeclaration>statement)) {
result.push(<ImportEqualsDeclaration>statement);
}
});
return result;
@ -3859,7 +3859,7 @@ module ts {
}
function emitAMDModule(node: SourceFile, startIndex: number) {
var imports = getExternalImportDeclarations(node);
var imports = getExternalImportEqualsDeclarations(node);
writeLine();
write("define(");
if (node.amdModuleName) {
@ -3868,7 +3868,7 @@ module ts {
write("[\"require\", \"exports\"");
forEach(imports, imp => {
write(", ");
emitLiteral(<LiteralExpression>getExternalModuleImportDeclarationExpression(imp));
emitLiteral(<LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(imp));
});
forEach(node.amdDependencies, amdDependency => {
var text = "\"" + amdDependency + "\"";
@ -4125,8 +4125,8 @@ module ts {
return emitEnumDeclaration(<EnumDeclaration>node);
case SyntaxKind.ModuleDeclaration:
return emitModuleDeclaration(<ModuleDeclaration>node);
case SyntaxKind.ImportDeclaration:
return emitImportDeclaration(<ImportDeclaration>node);
case SyntaxKind.ImportEqualsDeclaration:
return emitImportEqualsDeclaration(<ImportEqualsDeclaration>node);
case SyntaxKind.SourceFile:
return emitSourceFile(<SourceFile>node);
}

View file

@ -246,10 +246,10 @@ module ts {
return visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, (<ModuleDeclaration>node).name) ||
visitNode(cbNode, (<ModuleDeclaration>node).body);
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
return visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, (<ImportDeclaration>node).name) ||
visitNode(cbNode, (<ImportDeclaration>node).moduleReference);
visitNode(cbNode, (<ImportEqualsDeclaration>node).name) ||
visitNode(cbNode, (<ImportEqualsDeclaration>node).moduleReference);
case SyntaxKind.ExportAssignment:
return visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, (<ExportAssignment>node).exportName);
@ -1745,7 +1745,7 @@ module ts {
function isReusableModuleElement(node: Node) {
if (node) {
switch (node.kind) {
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.ExportAssignment:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
@ -4519,8 +4519,8 @@ module ts {
return nextToken() === SyntaxKind.OpenParenToken;
}
function parseImportDeclaration(fullStart: number, modifiers: ModifiersArray): ImportDeclaration {
var node = <ImportDeclaration>createNode(SyntaxKind.ImportDeclaration, fullStart);
function parseImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration {
var node = <ImportEqualsDeclaration>createNode(SyntaxKind.ImportEqualsDeclaration, fullStart);
setModifiers(node, modifiers);
parseExpected(SyntaxKind.ImportKeyword);
node.name = parseIdentifier();
@ -4653,7 +4653,7 @@ module ts {
case SyntaxKind.ModuleKeyword:
return parseModuleDeclaration(fullStart, modifiers);
case SyntaxKind.ImportKeyword:
return parseImportDeclaration(fullStart, modifiers);
return parseImportEqualsDeclaration(fullStart, modifiers);
default:
Debug.fail("Mismatch between isDeclarationStart and parseDeclaration");
}
@ -4736,7 +4736,7 @@ module ts {
function setExternalModuleIndicator(sourceFile: SourceFile) {
sourceFile.externalModuleIndicator = forEach(sourceFile.statements, node =>
node.flags & NodeFlags.Export
|| node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference
|| node.kind === SyntaxKind.ImportEqualsDeclaration && (<ImportEqualsDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference
|| node.kind === SyntaxKind.ExportAssignment
? node
: undefined);

View file

@ -276,10 +276,10 @@ module ts {
function processImportedModules(file: SourceFile, basePath: string) {
forEach(file.statements, node => {
if (isExternalModuleImportDeclaration(node) &&
getExternalModuleImportDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
if (isExternalModuleImportEqualsDeclaration(node) &&
getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
var nameLiteral = <LiteralExpression>getExternalModuleImportDeclarationExpression(node);
var nameLiteral = <LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(node);
var moduleName = nameLiteral.text;
if (moduleName) {
var searchPath = basePath;
@ -304,10 +304,10 @@ module ts {
// The StringLiteral must specify a top - level external module name.
// Relative external module names are not permitted
forEachChild((<ModuleDeclaration>node).body, node => {
if (isExternalModuleImportDeclaration(node) &&
getExternalModuleImportDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
if (isExternalModuleImportEqualsDeclaration(node) &&
getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
var nameLiteral = <LiteralExpression>getExternalModuleImportDeclarationExpression(node);
var nameLiteral = <LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(node);
var moduleName = nameLiteral.text;
if (moduleName) {
// TypeScript 1.0 spec (April 2014): 12.1.6

View file

@ -228,7 +228,7 @@ module ts {
EnumDeclaration,
ModuleDeclaration,
ModuleBlock,
ImportDeclaration,
ImportEqualsDeclaration,
ExportAssignment,
// Module references
@ -849,7 +849,7 @@ module ts {
statements: NodeArray<ModuleElement>
}
export interface ImportDeclaration extends Declaration, ModuleElement {
export interface ImportEqualsDeclaration extends Declaration, ModuleElement {
name: Identifier;
// 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external
@ -1099,7 +1099,7 @@ module ts {
export interface SymbolVisibilityResult {
accessibility: SymbolAccessibility;
aliasesToMakeVisible?: ImportDeclaration[]; // aliases that need to have this symbol visible
aliasesToMakeVisible?: ImportEqualsDeclaration[]; // aliases that need to have this symbol visible
errorSymbolName?: string; // Optional symbol name that results in error
errorNode?: Node; // optional node that results in error
}
@ -1112,8 +1112,8 @@ module ts {
getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string;
getExpressionNamePrefix(node: Identifier): string;
getExportAssignmentName(node: SourceFile): string;
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean;
isReferencedImportEqualsDeclaration(node: ImportEqualsDeclaration): boolean;
isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean;
getNodeCheckFlags(node: Node): NodeCheckFlags;
getEnumMemberValue(node: EnumMember): number;
hasSemanticErrors(sourceFile?: SourceFile): boolean;

View file

@ -578,17 +578,17 @@ module ts {
(preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly);
}
export function isExternalModuleImportDeclaration(node: Node) {
return node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference;
export function isExternalModuleImportEqualsDeclaration(node: Node) {
return node.kind === SyntaxKind.ImportEqualsDeclaration && (<ImportEqualsDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference;
}
export function getExternalModuleImportDeclarationExpression(node: Node) {
Debug.assert(isExternalModuleImportDeclaration(node));
return (<ExternalModuleReference>(<ImportDeclaration>node).moduleReference).expression;
export function getExternalModuleImportEqualsDeclarationExpression(node: Node) {
Debug.assert(isExternalModuleImportEqualsDeclaration(node));
return (<ExternalModuleReference>(<ImportEqualsDeclaration>node).moduleReference).expression;
}
export function isInternalModuleImportDeclaration(node: Node) {
return node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).moduleReference.kind !== SyntaxKind.ExternalModuleReference;
export function isInternalModuleImportEqualsDeclaration(node: Node) {
return node.kind === SyntaxKind.ImportEqualsDeclaration && (<ImportEqualsDeclaration>node).moduleReference.kind !== SyntaxKind.ExternalModuleReference;
}
export function hasDotDotDotToken(node: Node) {
@ -667,7 +667,7 @@ module ts {
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
return true;
}
return false;
@ -764,7 +764,7 @@ module ts {
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
// early exit cases - declarations cannot be nested in classes
return undefined;
default:

View file

@ -175,9 +175,9 @@ module ts.BreakpointResolver {
// span on export = id
return textSpan(node, (<ExportAssignment>node).exportName);
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
// import statement without including semicolon
return textSpan(node,(<ImportDeclaration>node).moduleReference);
return textSpan(node,(<ImportEqualsDeclaration>node).moduleReference);
case SyntaxKind.ModuleDeclaration:
// span on complete module if it is instantiated

View file

@ -452,7 +452,7 @@ module ts.formatting {
return true;
// equal in import a = module('a');
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
// equal in var a = 0;
case SyntaxKind.VariableDeclaration:
// equal in p = 0;

View file

@ -800,7 +800,7 @@ module ts {
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.TypeLiteral:
@ -1864,7 +1864,7 @@ module ts {
function isNameOfExternalModuleImportOrDeclaration(node: Node): boolean {
if (node.kind === SyntaxKind.StringLiteral) {
return isNameOfModuleDeclaration(node) ||
(isExternalModuleImportDeclaration(node.parent.parent) && getExternalModuleImportDeclarationExpression(node.parent.parent) === node);
(isExternalModuleImportEqualsDeclaration(node.parent.parent) && getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node);
}
return false;
@ -2942,19 +2942,19 @@ module ts {
displayParts.push(spacePart());
addFullSymbolName(symbol);
ts.forEach(symbol.declarations, declaration => {
if (declaration.kind === SyntaxKind.ImportDeclaration) {
var importDeclaration = <ImportDeclaration>declaration;
if (isExternalModuleImportDeclaration(importDeclaration)) {
if (declaration.kind === SyntaxKind.ImportEqualsDeclaration) {
var importEqualsDeclaration = <ImportEqualsDeclaration>declaration;
if (isExternalModuleImportEqualsDeclaration(importEqualsDeclaration)) {
displayParts.push(spacePart());
displayParts.push(operatorPart(SyntaxKind.EqualsToken));
displayParts.push(spacePart());
displayParts.push(keywordPart(SyntaxKind.RequireKeyword));
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
displayParts.push(displayPart(getTextOfNode(getExternalModuleImportDeclarationExpression(importDeclaration)), SymbolDisplayPartKind.stringLiteral));
displayParts.push(displayPart(getTextOfNode(getExternalModuleImportEqualsDeclarationExpression(importEqualsDeclaration)), SymbolDisplayPartKind.stringLiteral));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
}
else {
var internalAliasSymbol = typeResolver.getSymbolAtLocation(importDeclaration.moduleReference);
var internalAliasSymbol = typeResolver.getSymbolAtLocation(importEqualsDeclaration.moduleReference);
if (internalAliasSymbol) {
displayParts.push(spacePart());
displayParts.push(operatorPart(SyntaxKind.EqualsToken));
@ -4675,7 +4675,7 @@ module ts {
return SemanticMeaning.Namespace;
}
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace;
// An external module can be a Value
@ -4710,10 +4710,10 @@ module ts {
while (node.parent.kind === SyntaxKind.QualifiedName) {
node = node.parent;
}
return isInternalModuleImportDeclaration(node.parent) && (<ImportDeclaration>node.parent).moduleReference === node;
return isInternalModuleImportEqualsDeclaration(node.parent) && (<ImportEqualsDeclaration>node.parent).moduleReference === node;
}
function getMeaningFromRightHandSideOfImport(node: Node) {
function getMeaningFromRightHandSideOfImportEquals(node: Node) {
Debug.assert(node.kind === SyntaxKind.Identifier);
// import a = |b|; // Namespace
@ -4722,7 +4722,7 @@ module ts {
if (node.parent.kind === SyntaxKind.QualifiedName &&
(<QualifiedName>node.parent).right === node &&
node.parent.parent.kind === SyntaxKind.ImportDeclaration) {
node.parent.parent.kind === SyntaxKind.ImportEqualsDeclaration) {
return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace;
}
return SemanticMeaning.Namespace;
@ -4733,7 +4733,7 @@ module ts {
return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace;
}
else if (isInRightSideOfImport(node)) {
return getMeaningFromRightHandSideOfImport(node);
return getMeaningFromRightHandSideOfImportEquals(node);
}
else if (isDeclarationOrFunctionExpressionOrCatchVariableName(node)) {
return getMeaningFromDeclaration(node.parent);