mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into constLet
This commit is contained in:
+30
-11
@@ -885,13 +885,13 @@ module ts {
|
||||
if (accessibleSymbolChain) {
|
||||
var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
|
||||
if (!hasAccessibleDeclarations) {
|
||||
return {
|
||||
return <SymbolAccessiblityResult>{
|
||||
accessibility: SymbolAccessibility.NotAccessible,
|
||||
errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
|
||||
errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, SymbolFlags.Namespace) : undefined,
|
||||
};
|
||||
}
|
||||
return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasAccessibleDeclarations.aliasesToMakeVisible };
|
||||
return hasAccessibleDeclarations;
|
||||
}
|
||||
|
||||
// If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible.
|
||||
@@ -948,12 +948,12 @@ module ts {
|
||||
(declaration.kind === SyntaxKind.SourceFile && isExternalModule(<SourceFile>declaration));
|
||||
}
|
||||
|
||||
function hasVisibleDeclarations(symbol: Symbol): { aliasesToMakeVisible?: ImportDeclaration[]; } {
|
||||
function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult {
|
||||
var aliasesToMakeVisible: ImportDeclaration[];
|
||||
if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) {
|
||||
return undefined;
|
||||
}
|
||||
return { aliasesToMakeVisible };
|
||||
return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible };
|
||||
|
||||
function getIsDeclarationVisible(declaration: Declaration) {
|
||||
if (!isDeclarationVisible(declaration)) {
|
||||
@@ -982,14 +982,32 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult {
|
||||
function isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult {
|
||||
// get symbol of the first identifier of the entityName
|
||||
var meaning: SymbolFlags;
|
||||
if (entityName.parent.kind === SyntaxKind.TypeQuery) {
|
||||
// Typeof value
|
||||
meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
|
||||
}
|
||||
else if (entityName.kind === SyntaxKind.QualifiedName ||
|
||||
entityName.parent.kind === SyntaxKind.ImportDeclaration) {
|
||||
// Left identifier from type reference or TypeAlias
|
||||
// Entity name of the import declaration
|
||||
meaning = SymbolFlags.Namespace;
|
||||
}
|
||||
else {
|
||||
// Type Reference or TypeAlias entity = Identifier
|
||||
meaning = SymbolFlags.Type;
|
||||
}
|
||||
var firstIdentifier = getFirstIdentifier(entityName);
|
||||
var symbolOfNameSpace = resolveName(entityName.parent, (<Identifier>firstIdentifier).text, SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, firstIdentifier);
|
||||
var symbol = resolveName(enclosingDeclaration, (<Identifier>firstIdentifier).text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
|
||||
|
||||
// Verify if the symbol is accessible
|
||||
var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace);
|
||||
return hasNamespaceDeclarationsVisibile ?
|
||||
{ accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } :
|
||||
{ accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: declarationNameToString(<Identifier>firstIdentifier) };
|
||||
return hasVisibleDeclarations(symbol) || <SymbolVisibilityResult>{
|
||||
accessibility: SymbolAccessibility.NotAccessible,
|
||||
errorSymbolName: getTextOfNode(firstIdentifier),
|
||||
errorNode: firstIdentifier
|
||||
};
|
||||
}
|
||||
|
||||
function releaseStringWriter(writer: StringSymbolWriter) {
|
||||
@@ -1601,6 +1619,7 @@ module ts {
|
||||
case SyntaxKind.IndexSignature:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.TypeParameter:
|
||||
return isDeclarationVisible(node.parent);
|
||||
|
||||
// Source file is always visible
|
||||
@@ -9135,7 +9154,7 @@ module ts {
|
||||
writeTypeAtLocation,
|
||||
writeReturnTypeOfSignatureDeclaration,
|
||||
isSymbolAccessible,
|
||||
isImportDeclarationEntityNameReferenceDeclarationVisibile,
|
||||
isEntityNameVisible,
|
||||
getConstantValue,
|
||||
};
|
||||
checkProgram();
|
||||
|
||||
@@ -275,27 +275,16 @@ module ts {
|
||||
Type_alias_name_cannot_be_0: { code: 2457, category: DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
|
||||
An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: DiagnosticCategory.Error, key: "An AMD module cannot have multiple name assignments." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4003, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4005, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." },
|
||||
Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4006, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4007, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." },
|
||||
Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4008, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4009, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." },
|
||||
Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 4010, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4011, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." },
|
||||
Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 4012, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4013, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." },
|
||||
Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 4014, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4015, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
|
||||
Type_parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4016, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using private name '{1}'." },
|
||||
Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4017, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
|
||||
Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4018, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
|
||||
Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4019, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using private name '{1}'." },
|
||||
Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4020, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." },
|
||||
Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 4021, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." },
|
||||
Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: { code: 4022, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using private name '{1}'." },
|
||||
Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4023, category: DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
|
||||
Exported_variable_0_has_or_is_using_name_1_from_private_module_2: { code: 4024, category: DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from private module '{2}'." },
|
||||
@@ -353,8 +342,6 @@ module ts {
|
||||
Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4076, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named." },
|
||||
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
|
||||
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
|
||||
Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4079, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
|
||||
Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2: { code: 4080, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using name '{1}' from private module '{2}'." },
|
||||
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." },
|
||||
Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." },
|
||||
In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true },
|
||||
|
||||
@@ -1097,78 +1097,38 @@
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
},
|
||||
"Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4001
|
||||
},
|
||||
"Type parameter '{0}' of exported class has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4002
|
||||
},
|
||||
"Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4003
|
||||
},
|
||||
"Type parameter '{0}' of exported interface has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4004
|
||||
},
|
||||
"Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4005
|
||||
},
|
||||
"Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4006
|
||||
},
|
||||
"Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4007
|
||||
},
|
||||
"Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4008
|
||||
},
|
||||
"Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4009
|
||||
},
|
||||
"Type parameter '{0}' of public static method from exported class has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4010
|
||||
},
|
||||
"Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4011
|
||||
},
|
||||
"Type parameter '{0}' of public method from exported class has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4012
|
||||
},
|
||||
"Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4013
|
||||
},
|
||||
"Type parameter '{0}' of method from exported interface has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4014
|
||||
},
|
||||
"Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4015
|
||||
},
|
||||
"Type parameter '{0}' of exported function has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4016
|
||||
},
|
||||
"Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4017
|
||||
},
|
||||
"Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4018
|
||||
},
|
||||
"Implements clause of exported class '{0}' has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4019
|
||||
@@ -1177,10 +1137,6 @@
|
||||
"category": "Error",
|
||||
"code": 4020
|
||||
},
|
||||
"Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4021
|
||||
},
|
||||
"Extends clause of exported interface '{0}' has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4022
|
||||
@@ -1409,14 +1365,6 @@
|
||||
"category": "Error",
|
||||
"code": 4078
|
||||
},
|
||||
"Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named.": {
|
||||
"category": "Error",
|
||||
"code": 4079
|
||||
},
|
||||
"Exported type alias '{0}' has or is using name '{1}' from private module '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 4080
|
||||
},
|
||||
"Exported type alias '{0}' has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4081
|
||||
|
||||
+370
-210
@@ -6,6 +6,7 @@
|
||||
module ts {
|
||||
interface EmitTextWriter {
|
||||
write(s: string): void;
|
||||
writeTextOfNode(node: Node): void;
|
||||
writeLine(): void;
|
||||
increaseIndent(): void;
|
||||
decreaseIndent(): void;
|
||||
@@ -18,7 +19,15 @@ module ts {
|
||||
getIndent(): number;
|
||||
}
|
||||
|
||||
interface SymbolAccessibilityDiagnostic {
|
||||
errorNode: Node;
|
||||
diagnosticMessage: DiagnosticMessage;
|
||||
typeName?: DeclarationName;
|
||||
}
|
||||
type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic;
|
||||
|
||||
interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter{
|
||||
getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic;
|
||||
}
|
||||
|
||||
var indentStrings: string[] = ["", " "];
|
||||
@@ -156,11 +165,16 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function writeTextOfNode(node: Node) {
|
||||
write(getSourceTextOfLocalNode(node));
|
||||
}
|
||||
|
||||
return {
|
||||
write: write,
|
||||
rawWrite: rawWrite,
|
||||
writeLiteral: writeLiteral,
|
||||
writeLine: writeLine,
|
||||
write,
|
||||
rawWrite,
|
||||
writeTextOfNode,
|
||||
writeLiteral,
|
||||
writeLine,
|
||||
increaseIndent: () => indent++,
|
||||
decreaseIndent: () => indent--,
|
||||
getIndent: () => indent,
|
||||
@@ -317,6 +331,7 @@ module ts {
|
||||
function emitJavaScript(jsFilePath: string, root?: SourceFile) {
|
||||
var writer = createTextWriter();
|
||||
var write = writer.write;
|
||||
var writeTextOfNode = writer.writeTextOfNode;
|
||||
var writeLine = writer.writeLine;
|
||||
var increaseIndent = writer.increaseIndent;
|
||||
var decreaseIndent = writer.decreaseIndent;
|
||||
@@ -933,7 +948,7 @@ module ts {
|
||||
write((<LiteralExpression>node).text);
|
||||
}
|
||||
else {
|
||||
write(getSourceTextOfLocalNode(node));
|
||||
writeTextOfNode(node);
|
||||
}
|
||||
|
||||
write("\"");
|
||||
@@ -977,7 +992,7 @@ module ts {
|
||||
write(prefix);
|
||||
write(".");
|
||||
}
|
||||
write(getSourceTextOfLocalNode(node));
|
||||
writeTextOfNode(node);
|
||||
}
|
||||
|
||||
function emitIdentifier(node: Identifier) {
|
||||
@@ -985,7 +1000,7 @@ module ts {
|
||||
emitExpressionIdentifier(node);
|
||||
}
|
||||
else {
|
||||
write(getSourceTextOfLocalNode(node));
|
||||
writeTextOfNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2549,11 +2564,13 @@ module ts {
|
||||
}
|
||||
|
||||
function emitDeclarations(jsFilePath: string, root?: SourceFile) {
|
||||
var writer = createTextWriterWithSymbolWriter();
|
||||
var write = writer.write;
|
||||
var writeLine = writer.writeLine;
|
||||
var increaseIndent = writer.increaseIndent;
|
||||
var decreaseIndent = writer.decreaseIndent;
|
||||
var write: (s: string) => void;
|
||||
var writeLine: () => void;
|
||||
var increaseIndent: () => void;
|
||||
var decreaseIndent: () => void;
|
||||
var writeTextOfNode: (node: Node) => void;
|
||||
|
||||
var writer = createAndSetNewTextWriterWithSymbolWriter();
|
||||
|
||||
var enclosingDeclaration: Node;
|
||||
var reportedDeclarationError = false;
|
||||
@@ -2567,13 +2584,7 @@ module ts {
|
||||
asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output
|
||||
}[] = [];
|
||||
|
||||
var getSymbolVisibilityDiagnosticMessage: (symbolAccesibilityResult: SymbolAccessiblityResult) => {
|
||||
errorNode: Node;
|
||||
diagnosticMessage: DiagnosticMessage;
|
||||
typeName?: DeclarationName
|
||||
}
|
||||
|
||||
function createTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter {
|
||||
function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter {
|
||||
var writer = <EmitTextWriterWithSymbolWriter>createTextWriter();
|
||||
writer.trackSymbol = trackSymbol;
|
||||
writer.writeKeyword = writer.write;
|
||||
@@ -2583,28 +2594,36 @@ module ts {
|
||||
writer.writeStringLiteral = writer.writeLiteral;
|
||||
writer.writeParameter = writer.write;
|
||||
writer.writeSymbol = writer.write;
|
||||
setWriter(writer);
|
||||
return writer;
|
||||
}
|
||||
|
||||
function setWriter(newWriter: EmitTextWriterWithSymbolWriter) {
|
||||
writer = newWriter;
|
||||
write = newWriter.write;
|
||||
writeTextOfNode = newWriter.writeTextOfNode;
|
||||
writeLine = newWriter.writeLine;
|
||||
increaseIndent = newWriter.increaseIndent;
|
||||
decreaseIndent = newWriter.decreaseIndent;
|
||||
}
|
||||
|
||||
function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) {
|
||||
var oldWriter = writer;
|
||||
forEach(importDeclarations, aliasToWrite => {
|
||||
var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined);
|
||||
writer = createTextWriterWithSymbolWriter();
|
||||
createAndSetNewTextWriterWithSymbolWriter();
|
||||
for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
|
||||
writer.increaseIndent();
|
||||
increaseIndent();
|
||||
}
|
||||
|
||||
writeImportDeclaration(aliasToWrite);
|
||||
aliasEmitInfo.asynchronousOutput = writer.getText();
|
||||
});
|
||||
writer = oldWriter;
|
||||
setWriter(oldWriter);
|
||||
}
|
||||
|
||||
function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) {
|
||||
var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning);
|
||||
function handleSymbolAccessibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) {
|
||||
|
||||
// write the aliases
|
||||
if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
|
||||
writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
|
||||
@@ -2613,17 +2632,17 @@ module ts {
|
||||
else {
|
||||
// Report error
|
||||
reportedDeclarationError = true;
|
||||
var errorInfo = getSymbolVisibilityDiagnosticMessage(symbolAccesibilityResult);
|
||||
var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult);
|
||||
if (errorInfo) {
|
||||
if (errorInfo.typeName) {
|
||||
diagnostics.push(createDiagnosticForNode(errorInfo.errorNode,
|
||||
diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode,
|
||||
errorInfo.diagnosticMessage,
|
||||
getSourceTextOfLocalNode(errorInfo.typeName),
|
||||
symbolAccesibilityResult.errorSymbolName,
|
||||
symbolAccesibilityResult.errorModuleName));
|
||||
}
|
||||
else {
|
||||
diagnostics.push(createDiagnosticForNode(errorInfo.errorNode,
|
||||
diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode,
|
||||
errorInfo.diagnosticMessage,
|
||||
symbolAccesibilityResult.errorSymbolName,
|
||||
symbolAccesibilityResult.errorModuleName));
|
||||
@@ -2632,23 +2651,55 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) {
|
||||
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
|
||||
}
|
||||
|
||||
function writeTypeAtLocation(location: Node, type: TypeNode, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
|
||||
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
|
||||
write(": ");
|
||||
if (type) {
|
||||
// Write the type
|
||||
emitType(type);
|
||||
}
|
||||
else {
|
||||
resolver.writeTypeAtLocation(location, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
}
|
||||
}
|
||||
|
||||
function writeReturnTypeAtSignature(signature: SignatureDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
|
||||
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
|
||||
write(": ");
|
||||
if (signature.type) {
|
||||
// Write the type
|
||||
emitType(signature.type);
|
||||
}
|
||||
else {
|
||||
resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
}
|
||||
}
|
||||
|
||||
function emitLines(nodes: Node[]) {
|
||||
for (var i = 0, n = nodes.length; i < n; i++) {
|
||||
emitNode(nodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void) {
|
||||
function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void) {
|
||||
var currentWriterPos = writer.getTextPos();
|
||||
for (var i = 0, n = nodes.length; i < n; i++) {
|
||||
if (currentWriterPos !== writer.getTextPos()) {
|
||||
write(", ");
|
||||
write(separator);
|
||||
}
|
||||
currentWriterPos = writer.getTextPos();
|
||||
eachNodeEmitFn(nodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void) {
|
||||
emitSeparatedList(nodes, ", ", eachNodeEmitFn);
|
||||
}
|
||||
|
||||
function writeJsDocComments(declaration: Declaration) {
|
||||
if (declaration) {
|
||||
var jsDocComments = getJsDocComments(declaration, currentSourceFile);
|
||||
@@ -2658,8 +2709,112 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitSourceTextOfNode(node: Node) {
|
||||
write(getSourceTextOfLocalNode(node));
|
||||
function emitTypeWithNewGetSymbolAccessibilityDiangostic(type: TypeNode, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
|
||||
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
|
||||
emitType(type);
|
||||
}
|
||||
|
||||
function emitType(type: TypeNode) {
|
||||
switch (type.kind) {
|
||||
case SyntaxKind.AnyKeyword:
|
||||
case SyntaxKind.StringKeyword:
|
||||
case SyntaxKind.NumberKeyword:
|
||||
case SyntaxKind.BooleanKeyword:
|
||||
case SyntaxKind.VoidKeyword:
|
||||
case SyntaxKind.StringLiteral:
|
||||
return writeTextOfNode(type);
|
||||
case SyntaxKind.TypeReference:
|
||||
return emitTypeReference(<TypeReferenceNode>type);
|
||||
case SyntaxKind.TypeQuery:
|
||||
return emitTypeQuery(<TypeQueryNode>type);
|
||||
case SyntaxKind.ArrayType:
|
||||
return emitArrayType(<ArrayTypeNode>type);
|
||||
case SyntaxKind.TupleType:
|
||||
return emitTupleType(<TupleTypeNode>type);
|
||||
case SyntaxKind.UnionType:
|
||||
return emitUnionType(<UnionTypeNode>type);
|
||||
case SyntaxKind.ParenType:
|
||||
return emitParenType(<ParenTypeNode>type);
|
||||
case SyntaxKind.FunctionType:
|
||||
case SyntaxKind.ConstructorType:
|
||||
return emitSignatureDeclarationWithJsDocComments(<SignatureDeclaration>type);
|
||||
case SyntaxKind.TypeLiteral:
|
||||
return emitTypeLiteral(<TypeLiteralNode>type);
|
||||
case SyntaxKind.Identifier:
|
||||
return emitEntityName(<Identifier>type);
|
||||
case SyntaxKind.QualifiedName:
|
||||
return emitEntityName(<QualifiedName>type);
|
||||
default:
|
||||
Debug.fail("Unknown type annotation: " + type.kind);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
handleSymbolAccessibilityError(visibilityResult);
|
||||
writeEntityName(entityName);
|
||||
|
||||
function writeEntityName(entityName: EntityName) {
|
||||
if (entityName.kind === SyntaxKind.Identifier) {
|
||||
writeTextOfNode(entityName);
|
||||
}
|
||||
else {
|
||||
var qualifiedName = <QualifiedName>entityName;
|
||||
writeEntityName(qualifiedName.left);
|
||||
write(".");
|
||||
writeTextOfNode(qualifiedName.right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitTypeReference(type: TypeReferenceNode) {
|
||||
emitEntityName(type.typeName);
|
||||
if (type.typeArguments) {
|
||||
write("<");
|
||||
emitCommaList(type.typeArguments, emitType);
|
||||
write(">");
|
||||
}
|
||||
}
|
||||
|
||||
function emitTypeQuery(type: TypeQueryNode) {
|
||||
write("typeof ");
|
||||
emitEntityName(type.exprName);
|
||||
}
|
||||
|
||||
function emitArrayType(type: ArrayTypeNode) {
|
||||
emitType(type.elementType);
|
||||
write("[]");
|
||||
}
|
||||
|
||||
function emitTupleType(type: TupleTypeNode) {
|
||||
write("[");
|
||||
emitCommaList(type.elementTypes, emitType);
|
||||
write("]");
|
||||
}
|
||||
|
||||
function emitUnionType(type: UnionTypeNode) {
|
||||
emitSeparatedList(type.types, " | ", emitType);
|
||||
}
|
||||
|
||||
function emitParenType(type: ParenTypeNode) {
|
||||
write("(");
|
||||
emitType(type.type);
|
||||
write(")");
|
||||
}
|
||||
|
||||
function emitTypeLiteral(type: TypeLiteralNode) {
|
||||
write("{");
|
||||
if (type.members.length) {
|
||||
writeLine();
|
||||
increaseIndent();
|
||||
// write members
|
||||
emitLines(type.members);
|
||||
decreaseIndent();
|
||||
}
|
||||
write("}");
|
||||
}
|
||||
}
|
||||
|
||||
function emitSourceFile(node: SourceFile) {
|
||||
@@ -2670,42 +2825,38 @@ module ts {
|
||||
|
||||
function emitExportAssignment(node: ExportAssignment) {
|
||||
write("export = ");
|
||||
emitSourceTextOfNode(node.exportName);
|
||||
writeTextOfNode(node.exportName);
|
||||
write(";");
|
||||
writeLine();
|
||||
}
|
||||
|
||||
function emitDeclarationFlags(node: Declaration) {
|
||||
if (node.flags & NodeFlags.Static) {
|
||||
if (node.flags & NodeFlags.Private) {
|
||||
write("private ");
|
||||
function emitModuleElementDeclarationFlags(node: Declaration) {
|
||||
// If the node is parented in the current source file we need to emit export declare or just export
|
||||
if (node.parent === currentSourceFile) {
|
||||
// If the node is exported
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
write("export ");
|
||||
}
|
||||
else if (node.flags & NodeFlags.Protected) {
|
||||
write("protected ");
|
||||
}
|
||||
write("static ");
|
||||
}
|
||||
else {
|
||||
if (node.flags & NodeFlags.Private) {
|
||||
write("private ");
|
||||
}
|
||||
else if (node.flags & NodeFlags.Protected) {
|
||||
write("protected ");
|
||||
}
|
||||
// If the node is parented in the current source file we need to emit export declare or just export
|
||||
else if (node.parent === currentSourceFile) {
|
||||
// If the node is exported
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
write("export ");
|
||||
}
|
||||
|
||||
if (node.kind !== SyntaxKind.InterfaceDeclaration) {
|
||||
write("declare ");
|
||||
}
|
||||
if (node.kind !== SyntaxKind.InterfaceDeclaration) {
|
||||
write("declare ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitClassMemberDeclarationFlags(node: Declaration) {
|
||||
if (node.flags & NodeFlags.Private) {
|
||||
write("private ");
|
||||
}
|
||||
else if (node.flags & NodeFlags.Protected) {
|
||||
write("protected ");
|
||||
}
|
||||
|
||||
if (node.flags & NodeFlags.Static) {
|
||||
write("static ");
|
||||
}
|
||||
}
|
||||
|
||||
function emitImportDeclaration(node: ImportDeclaration) {
|
||||
var nodeEmitInfo = {
|
||||
declaration: node,
|
||||
@@ -2724,52 +2875,41 @@ module ts {
|
||||
// correct writer especially to handle asynchronous alias writing
|
||||
emitJsDocComments(node);
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
writer.write("export ");
|
||||
write("export ");
|
||||
}
|
||||
writer.write("import ");
|
||||
writer.write(getSourceTextOfLocalNode(node.name));
|
||||
writer.write(" = ");
|
||||
write("import ");
|
||||
writeTextOfNode(node.name);
|
||||
write(" = ");
|
||||
if (node.entityName) {
|
||||
checkEntityNameAccessible();
|
||||
writer.write(getSourceTextOfLocalNode(node.entityName));
|
||||
writer.write(";");
|
||||
emitTypeWithNewGetSymbolAccessibilityDiangostic(node.entityName, getImportEntityNameVisibilityError);
|
||||
write(";");
|
||||
}
|
||||
else {
|
||||
writer.write("require(");
|
||||
writer.write(getSourceTextOfLocalNode(node.externalModuleName));
|
||||
writer.write(");");
|
||||
write("require(");
|
||||
writeTextOfNode(node.externalModuleName);
|
||||
write(");");
|
||||
}
|
||||
writer.writeLine();
|
||||
|
||||
function checkEntityNameAccessible() {
|
||||
var symbolAccesibilityResult = resolver.isImportDeclarationEntityNameReferenceDeclarationVisibile(node.entityName);
|
||||
if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) {
|
||||
// write the aliases
|
||||
if (symbolAccesibilityResult.aliasesToMakeVisible) {
|
||||
writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Report error
|
||||
reportedDeclarationError = true;
|
||||
diagnostics.push(createDiagnosticForNode(node,
|
||||
Diagnostics.Import_declaration_0_is_using_private_name_1,
|
||||
getSourceTextOfLocalNode(node.name),
|
||||
symbolAccesibilityResult.errorSymbolName));
|
||||
}
|
||||
function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
return {
|
||||
diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1,
|
||||
errorNode: node,
|
||||
typeName: node.name
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function emitModuleDeclaration(node: ModuleDeclaration) {
|
||||
if (resolver.isDeclarationVisible(node)) {
|
||||
emitJsDocComments(node);
|
||||
emitDeclarationFlags(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
write("module ");
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
while (node.body.kind !== SyntaxKind.ModuleBlock) {
|
||||
node = <ModuleDeclaration>node.body;
|
||||
write(".");
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
}
|
||||
var prevEnclosingDeclaration = enclosingDeclaration;
|
||||
enclosingDeclaration = node;
|
||||
@@ -2787,24 +2927,18 @@ module ts {
|
||||
function emitTypeAliasDeclaration(node: TypeAliasDeclaration) {
|
||||
if (resolver.isDeclarationVisible(node)) {
|
||||
emitJsDocComments(node);
|
||||
emitDeclarationFlags(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
write("type ");
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
write(" = ");
|
||||
getSymbolVisibilityDiagnosticMessage = getTypeAliasDeclarationVisibilityError;
|
||||
resolver.writeTypeAtLocation(node.type, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
emitTypeWithNewGetSymbolAccessibilityDiangostic(node.type, getTypeAliasDeclarationVisibilityError);
|
||||
write(";");
|
||||
writeLine();
|
||||
}
|
||||
function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
var diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1;
|
||||
function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
return {
|
||||
diagnosticMessage,
|
||||
errorNode: node,
|
||||
diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
|
||||
errorNode: node.type,
|
||||
typeName: node.name
|
||||
};
|
||||
}
|
||||
@@ -2813,12 +2947,12 @@ module ts {
|
||||
function emitEnumDeclaration(node: EnumDeclaration) {
|
||||
if (resolver.isDeclarationVisible(node)) {
|
||||
emitJsDocComments(node);
|
||||
emitDeclarationFlags(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
if (isConst(node)) {
|
||||
write("const ")
|
||||
}
|
||||
write("enum ");
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
write(" {");
|
||||
writeLine();
|
||||
increaseIndent();
|
||||
@@ -2831,7 +2965,7 @@ module ts {
|
||||
|
||||
function emitEnumMemberDeclaration(node: EnumMember) {
|
||||
emitJsDocComments(node);
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
var enumMemberValue = resolver.getEnumMemberValue(node);
|
||||
if (enumMemberValue !== undefined) {
|
||||
write(" = ");
|
||||
@@ -2843,56 +2977,62 @@ module ts {
|
||||
|
||||
function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) {
|
||||
function emitTypeParameter(node: TypeParameterDeclaration) {
|
||||
function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
increaseIndent();
|
||||
emitJsDocComments(node);
|
||||
decreaseIndent();
|
||||
writeTextOfNode(node.name);
|
||||
// If there is constraint present and this is not a type parameter of the private method emit the constraint
|
||||
if (node.constraint && (node.parent.kind !== SyntaxKind.Method || !(node.parent.flags & NodeFlags.Private))) {
|
||||
write(" extends ");
|
||||
if (node.parent.kind === SyntaxKind.FunctionType ||
|
||||
node.parent.kind === SyntaxKind.ConstructorType ||
|
||||
(node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) {
|
||||
Debug.assert(node.parent.kind === SyntaxKind.Method ||
|
||||
node.parent.kind === SyntaxKind.FunctionType ||
|
||||
node.parent.kind === SyntaxKind.ConstructorType ||
|
||||
node.parent.kind === SyntaxKind.CallSignature ||
|
||||
node.parent.kind === SyntaxKind.ConstructSignature);
|
||||
emitType(node.constraint);
|
||||
}
|
||||
else {
|
||||
emitTypeWithNewGetSymbolAccessibilityDiangostic(node.constraint, getTypeParameterConstraintVisibilityError);
|
||||
}
|
||||
}
|
||||
|
||||
function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
// Type parameter constraints are named by user so we should always be able to name it
|
||||
var diagnosticMessage: DiagnosticMessage;
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
case SyntaxKind.ConstructSignature:
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
case SyntaxKind.CallSignature:
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
case SyntaxKind.Method:
|
||||
if (node.parent.flags & NodeFlags.Static) {
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2905,17 +3045,6 @@ module ts {
|
||||
typeName: node.name
|
||||
};
|
||||
}
|
||||
|
||||
increaseIndent();
|
||||
emitJsDocComments(node);
|
||||
decreaseIndent();
|
||||
emitSourceTextOfNode(node.name);
|
||||
// If there is constraint present and this is not a type parameter of the private method emit the constraint
|
||||
if (node.constraint && (node.parent.kind !== SyntaxKind.Method || !(node.parent.flags & NodeFlags.Private))) {
|
||||
write(" extends ");
|
||||
getSymbolVisibilityDiagnosticMessage = getTypeParameterConstraintVisibilityError;
|
||||
resolver.writeTypeAtLocation(node.constraint, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeParameters) {
|
||||
@@ -2932,36 +3061,20 @@ module ts {
|
||||
}
|
||||
|
||||
function emitTypeOfTypeReference(node: Node) {
|
||||
getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError;
|
||||
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType | TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
emitTypeWithNewGetSymbolAccessibilityDiangostic(node, getHeritageClauseVisibilityError);
|
||||
|
||||
function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
var diagnosticMessage: DiagnosticMessage;
|
||||
// Heritage clause is written by user so it can always be named
|
||||
if (node.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
// Class
|
||||
if (symbolAccesibilityResult.errorModuleName) {
|
||||
// Module is inaccessible
|
||||
diagnosticMessage = isImplementsList ?
|
||||
Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2;
|
||||
}
|
||||
else {
|
||||
// Class or Interface implemented/extended is inaccessible
|
||||
diagnosticMessage = isImplementsList ?
|
||||
Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
|
||||
Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
|
||||
}
|
||||
// Class or Interface implemented/extended is inaccessible
|
||||
diagnosticMessage = isImplementsList ?
|
||||
Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
|
||||
Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
if (symbolAccesibilityResult.errorModuleName) {
|
||||
// Module is inaccessible
|
||||
diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2;
|
||||
}
|
||||
else {
|
||||
// interface is inaccessible
|
||||
diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
|
||||
}
|
||||
// interface is inaccessible
|
||||
diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -2986,9 +3099,9 @@ module ts {
|
||||
|
||||
if (resolver.isDeclarationVisible(node)) {
|
||||
emitJsDocComments(node);
|
||||
emitDeclarationFlags(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
write("class ");
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
var prevEnclosingDeclaration = enclosingDeclaration;
|
||||
enclosingDeclaration = node;
|
||||
emitTypeParameters(node.typeParameters);
|
||||
@@ -3011,9 +3124,9 @@ module ts {
|
||||
function emitInterfaceDeclaration(node: InterfaceDeclaration) {
|
||||
if (resolver.isDeclarationVisible(node)) {
|
||||
emitJsDocComments(node);
|
||||
emitDeclarationFlags(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
write("interface ");
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
var prevEnclosingDeclaration = enclosingDeclaration;
|
||||
enclosingDeclaration = node;
|
||||
emitTypeParameters(node.typeParameters);
|
||||
@@ -3031,7 +3144,7 @@ module ts {
|
||||
|
||||
function emitPropertyDeclaration(node: PropertyDeclaration) {
|
||||
emitJsDocComments(node);
|
||||
emitDeclarationFlags(node);
|
||||
emitClassMemberDeclarationFlags(node);
|
||||
emitVariableDeclaration(<VariableDeclaration>node);
|
||||
write(";");
|
||||
writeLine();
|
||||
@@ -3042,19 +3155,20 @@ module ts {
|
||||
// If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted
|
||||
// so there is no check needed to see if declaration is visible
|
||||
if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) {
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
// If optional property emit ?
|
||||
if (node.kind === SyntaxKind.Property && (node.flags & NodeFlags.QuestionMark)) {
|
||||
write("?");
|
||||
}
|
||||
if (!(node.flags & NodeFlags.Private)) {
|
||||
write(": ");
|
||||
getSymbolVisibilityDiagnosticMessage = getVariableDeclarationTypeVisibilityError;
|
||||
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
if (node.kind === SyntaxKind.Property && node.parent.kind === SyntaxKind.TypeLiteral) {
|
||||
emitTypeOfVariableDeclarationFromTypeLiteral(node);
|
||||
}
|
||||
else if (!(node.flags & NodeFlags.Private)) {
|
||||
writeTypeAtLocation(node, node.type, getVariableDeclarationTypeVisibilityError);
|
||||
}
|
||||
}
|
||||
|
||||
function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
var diagnosticMessage: DiagnosticMessage;
|
||||
if (node.kind === SyntaxKind.VariableDeclaration) {
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
@@ -3089,18 +3203,28 @@ module ts {
|
||||
}
|
||||
|
||||
return diagnosticMessage !== undefined ? {
|
||||
diagnosticMessage: diagnosticMessage,
|
||||
diagnosticMessage,
|
||||
errorNode: node,
|
||||
typeName: node.name
|
||||
} : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableDeclaration) {
|
||||
// if this is property of type literal,
|
||||
// or is parameter of method/call/construct/index signature of type literal
|
||||
// emit only if type is specified
|
||||
if (node.type) {
|
||||
write(": ");
|
||||
emitType(node.type);
|
||||
}
|
||||
}
|
||||
|
||||
function emitVariableStatement(node: VariableStatement) {
|
||||
var hasDeclarationWithEmit = forEach(node.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration));
|
||||
if (hasDeclarationWithEmit) {
|
||||
emitJsDocComments(node);
|
||||
emitDeclarationFlags(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
if (isLet(node)) {
|
||||
write("let ");
|
||||
}
|
||||
@@ -3121,22 +3245,38 @@ module ts {
|
||||
if (node === accessors.firstAccessor) {
|
||||
emitJsDocComments(accessors.getAccessor);
|
||||
emitJsDocComments(accessors.setAccessor);
|
||||
emitDeclarationFlags(node);
|
||||
emitSourceTextOfNode(node.name);
|
||||
emitClassMemberDeclarationFlags(node);
|
||||
writeTextOfNode(node.name);
|
||||
if (!(node.flags & NodeFlags.Private)) {
|
||||
write(": ");
|
||||
getSymbolVisibilityDiagnosticMessage = getAccessorDeclarationTypeVisibilityError;
|
||||
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
var accessorWithTypeAnnotation: AccessorDeclaration = node;
|
||||
var type = getTypeAnnotationFromAccessor(node);
|
||||
if (!type) {
|
||||
// couldn't get type for the first accessor, try the another one
|
||||
var anotherAccessor = node.kind === SyntaxKind.GetAccessor ? accessors.setAccessor : accessors.getAccessor;
|
||||
type = getTypeAnnotationFromAccessor(anotherAccessor);
|
||||
if (type) {
|
||||
accessorWithTypeAnnotation = anotherAccessor;
|
||||
}
|
||||
}
|
||||
writeTypeAtLocation(node, type, getAccessorDeclarationTypeVisibilityError);
|
||||
}
|
||||
write(";");
|
||||
writeLine();
|
||||
}
|
||||
|
||||
function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode {
|
||||
if (accessor) {
|
||||
return accessor.kind === SyntaxKind.GetAccessor ?
|
||||
accessor.type : // Getter - return type
|
||||
accessor.parameters[0].type; // Setter parameter type
|
||||
}
|
||||
}
|
||||
|
||||
function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
var diagnosticMessage: DiagnosticMessage;
|
||||
if (node.kind === SyntaxKind.SetAccessor) {
|
||||
if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) {
|
||||
// Setters have to have type named and cannot infer it so, the type should always be named
|
||||
if (node.parent.flags & NodeFlags.Static) {
|
||||
if (accessorWithTypeAnnotation.parent.flags & NodeFlags.Static) {
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
|
||||
@@ -3148,13 +3288,13 @@ module ts {
|
||||
}
|
||||
return {
|
||||
diagnosticMessage,
|
||||
errorNode: <Node>node.parameters[0],
|
||||
errorNode: <Node>accessorWithTypeAnnotation.parameters[0],
|
||||
// TODO(jfreeman): Investigate why we are passing node.name instead of node.parameters[0].name
|
||||
typeName: node.name
|
||||
typeName: accessorWithTypeAnnotation.name
|
||||
};
|
||||
}
|
||||
else {
|
||||
if (node.flags & NodeFlags.Static) {
|
||||
if (accessorWithTypeAnnotation.flags & NodeFlags.Static) {
|
||||
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
|
||||
symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
|
||||
@@ -3170,7 +3310,7 @@ module ts {
|
||||
}
|
||||
return {
|
||||
diagnosticMessage,
|
||||
errorNode: <Node>node.name,
|
||||
errorNode: <Node>accessorWithTypeAnnotation.name,
|
||||
typeName: undefined
|
||||
};
|
||||
}
|
||||
@@ -3183,16 +3323,21 @@ module ts {
|
||||
if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) &&
|
||||
!resolver.isImplementationOfOverload(node)) {
|
||||
emitJsDocComments(node);
|
||||
emitDeclarationFlags(node);
|
||||
if (node.kind === SyntaxKind.FunctionDeclaration) {
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
}
|
||||
else if (node.kind === SyntaxKind.Method) {
|
||||
emitClassMemberDeclarationFlags(node);
|
||||
}
|
||||
if (node.kind === SyntaxKind.FunctionDeclaration) {
|
||||
write("function ");
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
}
|
||||
else if (node.kind === SyntaxKind.Constructor) {
|
||||
write("constructor");
|
||||
}
|
||||
else {
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
if (node.flags & NodeFlags.QuestionMark) {
|
||||
write("?");
|
||||
}
|
||||
@@ -3201,16 +3346,15 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitConstructSignatureDeclaration(node: SignatureDeclaration) {
|
||||
function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) {
|
||||
emitJsDocComments(node);
|
||||
write("new ");
|
||||
emitSignatureDeclaration(node);
|
||||
}
|
||||
|
||||
function emitSignatureDeclaration(node: SignatureDeclaration) {
|
||||
if (node.kind === SyntaxKind.CallSignature || node.kind === SyntaxKind.IndexSignature) {
|
||||
// Only index and call signatures are emitted directly, so emit their js doc comments, rest will do that in their own functions
|
||||
emitJsDocComments(node);
|
||||
// Construct signature or constructor type write new Signature
|
||||
if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) {
|
||||
write("new ");
|
||||
}
|
||||
emitTypeParameters(node.typeParameters);
|
||||
if (node.kind === SyntaxKind.IndexSignature) {
|
||||
@@ -3220,6 +3364,9 @@ module ts {
|
||||
write("(");
|
||||
}
|
||||
|
||||
var prevEnclosingDeclaration = enclosingDeclaration;
|
||||
enclosingDeclaration = node;
|
||||
|
||||
// Parameters
|
||||
emitCommaList(node.parameters, emitParameterDeclaration);
|
||||
|
||||
@@ -3231,15 +3378,26 @@ module ts {
|
||||
}
|
||||
|
||||
// If this is not a constructor and is not private, emit the return type
|
||||
if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) {
|
||||
write(": ");
|
||||
getSymbolVisibilityDiagnosticMessage = getReturnTypeVisibilityError;
|
||||
resolver.writeReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
var isFunctionTypeOrConstructorType = node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.ConstructorType;
|
||||
if (isFunctionTypeOrConstructorType || node.parent.kind === SyntaxKind.TypeLiteral) {
|
||||
// Emit type literal signature return type only if specified
|
||||
if (node.type) {
|
||||
write(isFunctionTypeOrConstructorType ? " => " : ": ");
|
||||
emitType(node.type);
|
||||
}
|
||||
}
|
||||
else if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) {
|
||||
writeReturnTypeAtSignature(node, getReturnTypeVisibilityError);
|
||||
}
|
||||
write(";");
|
||||
writeLine();
|
||||
|
||||
function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
enclosingDeclaration = prevEnclosingDeclaration;
|
||||
|
||||
if (!isFunctionTypeOrConstructorType) {
|
||||
write(";");
|
||||
writeLine();
|
||||
}
|
||||
|
||||
function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
var diagnosticMessage: DiagnosticMessage;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ConstructSignature:
|
||||
@@ -3311,19 +3469,22 @@ module ts {
|
||||
if (node.flags & NodeFlags.Rest) {
|
||||
write("...");
|
||||
}
|
||||
emitSourceTextOfNode(node.name);
|
||||
writeTextOfNode(node.name);
|
||||
if (node.initializer || (node.flags & NodeFlags.QuestionMark)) {
|
||||
write("?");
|
||||
}
|
||||
decreaseIndent();
|
||||
|
||||
if (!(node.parent.flags & NodeFlags.Private)) {
|
||||
write(": ");
|
||||
getSymbolVisibilityDiagnosticMessage = getParameterDeclarationTypeVisibilityError;
|
||||
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
if (node.parent.kind === SyntaxKind.FunctionType ||
|
||||
node.parent.kind === SyntaxKind.ConstructorType ||
|
||||
node.parent.parent.kind === SyntaxKind.TypeLiteral) {
|
||||
emitTypeOfVariableDeclarationFromTypeLiteral(node);
|
||||
}
|
||||
else if (!(node.parent.flags & NodeFlags.Private)) {
|
||||
writeTypeAtLocation(node, node.type, getParameterDeclarationTypeVisibilityError);
|
||||
}
|
||||
|
||||
function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
|
||||
function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
var diagnosticMessage: DiagnosticMessage;
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.Constructor:
|
||||
@@ -3398,10 +3559,9 @@ module ts {
|
||||
case SyntaxKind.Method:
|
||||
return emitFunctionDeclaration(<FunctionLikeDeclaration>node);
|
||||
case SyntaxKind.ConstructSignature:
|
||||
return emitConstructSignatureDeclaration(<SignatureDeclaration>node);
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
return emitSignatureDeclaration(<SignatureDeclaration>node);
|
||||
return emitSignatureDeclarationWithJsDocComments(<SignatureDeclaration>node);
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return emitAccessorDeclaration(<AccessorDeclaration>node);
|
||||
|
||||
@@ -828,11 +828,15 @@ module ts {
|
||||
CannotBeNamed
|
||||
}
|
||||
|
||||
export interface SymbolAccessiblityResult {
|
||||
export interface SymbolVisibilityResult {
|
||||
accessibility: SymbolAccessibility;
|
||||
errorSymbolName?: string // Optional symbol name that results in error
|
||||
errorModuleName?: string // If the symbol is not visible from module, module's name
|
||||
aliasesToMakeVisible?: ImportDeclaration[]; // 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
|
||||
}
|
||||
|
||||
export interface SymbolAccessiblityResult extends SymbolVisibilityResult {
|
||||
errorModuleName?: string // If the symbol is not visible from module, module's name
|
||||
}
|
||||
|
||||
export interface EmitResolver {
|
||||
@@ -850,7 +854,7 @@ module ts {
|
||||
writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||
isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult;
|
||||
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
|
||||
getConstantValue(node: PropertyAccess | IndexedAccess): number;
|
||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||
|
||||
+5
-106
@@ -715,12 +715,12 @@ module ts {
|
||||
public filename: string;
|
||||
public text: string;
|
||||
|
||||
// These methods will have their implementation overridden with the implementation the
|
||||
// These methods will have their implementation provided by the implementation the
|
||||
// compiler actually exports off of SourceFile.
|
||||
public getLineAndCharacterFromPosition(position: number): { line: number; character: number } { return null; }
|
||||
public getPositionFromLineAndCharacter(line: number, character: number): number { return -1; }
|
||||
public getLineStarts(): number[] { return undefined; }
|
||||
public getSyntacticDiagnostics(): Diagnostic[] { return undefined; }
|
||||
public getLineAndCharacterFromPosition: (position: number) => LineAndCharacter;
|
||||
public getPositionFromLineAndCharacter: (line: number, character: number) => number;
|
||||
public getLineStarts: () => number[];
|
||||
public getSyntacticDiagnostics: () => Diagnostic[];
|
||||
|
||||
public amdDependencies: string[];
|
||||
public amdModuleName: string;
|
||||
@@ -890,9 +890,6 @@ module ts {
|
||||
|
||||
getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems;
|
||||
|
||||
// Obsolete. Use getSignatureHelpItems instead.
|
||||
getSignatureAtPosition(fileName: string, position: number): SignatureInfo;
|
||||
|
||||
getRenameInfo(fileName: string, position: number): RenameInfo;
|
||||
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[];
|
||||
|
||||
@@ -917,41 +914,6 @@ module ts {
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export interface SignatureInfo {
|
||||
actual: ActualSignatureInfo;
|
||||
formal: FormalSignatureItemInfo[]; // Formal signatures
|
||||
activeFormal: number; // Index of the "best match" formal signature
|
||||
}
|
||||
|
||||
export interface FormalSignatureItemInfo {
|
||||
signatureInfo: string;
|
||||
typeParameters: FormalTypeParameterInfo[];
|
||||
parameters: FormalParameterInfo[]; // Array of parameters
|
||||
docComment: string; // Help for the signature
|
||||
}
|
||||
|
||||
export interface FormalTypeParameterInfo {
|
||||
name: string; // Type parameter name
|
||||
docComment: string; // Comments that contain help for the parameter
|
||||
minChar: number; // minChar for parameter info in the formal signature info string
|
||||
limChar: number; // lim char for parameter info in the formal signature info string
|
||||
}
|
||||
|
||||
export interface FormalParameterInfo {
|
||||
name: string; // Parameter name
|
||||
isVariable: boolean; // true if parameter is var args
|
||||
docComment: string; // Comments that contain help for the parameter
|
||||
minChar: number; // minChar for parameter info in the formal signature info string
|
||||
limChar: number; // lim char for parameter info in the formal signature info string
|
||||
}
|
||||
|
||||
export interface ActualSignatureInfo {
|
||||
parameterMinChar: number;
|
||||
parameterLimChar: number;
|
||||
currentParameterIsTypeParameter: boolean; // current parameter is a type argument or a normal argument
|
||||
currentParameter: number; // Index of active parameter in "parameters" or "typeParamters" array
|
||||
}
|
||||
|
||||
export interface ClassifiedSpan {
|
||||
textSpan: TextSpan;
|
||||
classificationType: string; // ClassificationTypeNames
|
||||
@@ -4795,68 +4757,6 @@ module ts {
|
||||
return SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken);
|
||||
}
|
||||
|
||||
function getSignatureAtPosition(filename: string, position: number): SignatureInfo {
|
||||
var signatureHelpItems = getSignatureHelpItems(filename, position);
|
||||
|
||||
if (!signatureHelpItems) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var currentArgumentState = { argumentIndex: signatureHelpItems.argumentIndex, argumentCount: signatureHelpItems.argumentCount };
|
||||
|
||||
var formalSignatures: FormalSignatureItemInfo[] = [];
|
||||
forEach(signatureHelpItems.items, signature => {
|
||||
var signatureInfoString = displayPartsToString(signature.prefixDisplayParts);
|
||||
|
||||
var parameters: FormalParameterInfo[] = [];
|
||||
if (signature.parameters) {
|
||||
for (var i = 0, n = signature.parameters.length; i < n; i++) {
|
||||
var parameter = signature.parameters[i];
|
||||
|
||||
// add the parameter to the string
|
||||
if (i) {
|
||||
signatureInfoString += displayPartsToString(signature.separatorDisplayParts);
|
||||
}
|
||||
|
||||
var start = signatureInfoString.length;
|
||||
signatureInfoString += displayPartsToString(parameter.displayParts);
|
||||
var end = signatureInfoString.length;
|
||||
|
||||
// add the parameter to the list
|
||||
parameters.push({
|
||||
name: parameter.name,
|
||||
isVariable: i === n - 1 && signature.isVariadic,
|
||||
docComment: displayPartsToString(parameter.documentation),
|
||||
minChar: start,
|
||||
limChar: end
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
signatureInfoString += displayPartsToString(signature.suffixDisplayParts);
|
||||
|
||||
formalSignatures.push({
|
||||
signatureInfo: signatureInfoString,
|
||||
docComment: displayPartsToString(signature.documentation),
|
||||
parameters: parameters,
|
||||
typeParameters: [],
|
||||
});
|
||||
});
|
||||
|
||||
var actualSignature: ActualSignatureInfo = {
|
||||
parameterMinChar: signatureHelpItems.applicableSpan.start(),
|
||||
parameterLimChar: signatureHelpItems.applicableSpan.end(),
|
||||
currentParameterIsTypeParameter: false,
|
||||
currentParameter: currentArgumentState.argumentIndex
|
||||
};
|
||||
|
||||
return {
|
||||
actual: actualSignature,
|
||||
formal: formalSignatures,
|
||||
activeFormal: 0
|
||||
};
|
||||
}
|
||||
|
||||
/// Syntactic features
|
||||
function getCurrentSourceFile(filename: string): SourceFile {
|
||||
filename = normalizeSlashes(filename);
|
||||
@@ -5483,7 +5383,6 @@ module ts {
|
||||
getFormattingEditsForDocument,
|
||||
getFormattingEditsAfterKeystroke,
|
||||
getEmitOutput,
|
||||
getSignatureAtPosition,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -98,9 +98,6 @@ module ts {
|
||||
|
||||
getSignatureHelpItems(fileName: string, position: number): string;
|
||||
|
||||
// Obsolete. Use getSignatureHelpItems instead.
|
||||
getSignatureAtPosition(fileName: string, position: number): string;
|
||||
|
||||
/**
|
||||
* Returns a JSON-encoded value of the type:
|
||||
* { canRename: boolean, localizedErrorMessage: string, displayName: string, fullDisplayName: string, kind: string, kindModifiers: string, triggerSpan: { start; length } }
|
||||
@@ -609,14 +606,6 @@ module ts {
|
||||
});
|
||||
}
|
||||
|
||||
public getSignatureAtPosition(fileName: string, position: number): string {
|
||||
return this.forwardJSONCall(
|
||||
"getSignatureAtPosition('" + fileName + "', " + position + ")",
|
||||
() => {
|
||||
return this.languageService.getSignatureAtPosition(fileName, position);
|
||||
});
|
||||
}
|
||||
|
||||
/// GOTO DEFINITION
|
||||
|
||||
/**
|
||||
|
||||
@@ -592,6 +592,7 @@ module TypeScript.IncrementalParser {
|
||||
text: text,
|
||||
fileName: fileName,
|
||||
languageVersion: languageVersion,
|
||||
absolutePosition: absolutePosition,
|
||||
currentNode: currentNode,
|
||||
currentToken: currentToken,
|
||||
currentContextualToken: currentContextualToken,
|
||||
|
||||
@@ -45,6 +45,9 @@ module TypeScript.Parser {
|
||||
// but can affect the diagnostics produced while parsing.
|
||||
languageVersion: ts.ScriptTarget;
|
||||
|
||||
// The place in the source text that we're currently pointing at.
|
||||
absolutePosition(): number;
|
||||
|
||||
// The current syntax node the source is pointing at. Only available in incremental settings.
|
||||
// The source can point at a node if that node doesn't intersect any of the text changes in
|
||||
// the file, and doesn't contain certain unacceptable constructs. For example, if the node
|
||||
@@ -541,13 +544,32 @@ module TypeScript.Parser {
|
||||
return eatToken(SyntaxKind.SemicolonToken);
|
||||
}
|
||||
|
||||
function createEmptyToken(kind: SyntaxKind): ISyntaxToken {
|
||||
// The position of the empty token we're creating is not necessarily the position that
|
||||
// the parser is at now. This is because we may have seen some existing missing tokens
|
||||
// before finally deciding we needed a missing token. For example, if you have:
|
||||
//
|
||||
// Foo(a, # <eof>
|
||||
//
|
||||
// We will need to create a empty token for the missing ")". However, we will have
|
||||
// skipped the "#" token, and thus will be right after the "#". Because the "#" token
|
||||
// will actually become *skipped* trivia on the *next* token we see, the close paren
|
||||
// should not be considered to be after #, and should instead be after the ",".
|
||||
//
|
||||
// So, if we have any skipped tokens, then the position of the empty token should be
|
||||
// the position of the first skipped token we have. Otherwise it's just at the position
|
||||
// of the parser.
|
||||
var fullStart = _skippedTokens ? _skippedTokens[0].fullStart() : source.absolutePosition();
|
||||
return Syntax.emptyToken(kind, fullStart);
|
||||
}
|
||||
|
||||
function createMissingToken(expectedKind: SyntaxKind, actual: ISyntaxToken, diagnosticCode?: string): ISyntaxToken {
|
||||
var diagnostic = getExpectedTokenDiagnostic(expectedKind, actual, diagnosticCode);
|
||||
addDiagnostic(diagnostic);
|
||||
|
||||
// The missing token will be at the full start of the current token. That way empty tokens
|
||||
// will always be between real tokens and not inside an actual token.
|
||||
return Syntax.emptyToken(expectedKind);
|
||||
return createEmptyToken(expectedKind);
|
||||
}
|
||||
|
||||
function getExpectedTokenDiagnostic(expectedKind: SyntaxKind, actual?: ISyntaxToken, diagnosticCode?: string): Diagnostic {
|
||||
@@ -2871,7 +2893,7 @@ module TypeScript.Parser {
|
||||
addDiagnostic(diagnostic);
|
||||
|
||||
return new ArgumentListSyntax(parseNodeData, typeArgumentList,
|
||||
Syntax.emptyToken(SyntaxKind.OpenParenToken), <any>[], Syntax.emptyToken(SyntaxKind.CloseParenToken));
|
||||
createEmptyToken(SyntaxKind.OpenParenToken), <any>[], createEmptyToken(SyntaxKind.CloseParenToken));
|
||||
}
|
||||
else {
|
||||
Debug.assert(token0.kind === SyntaxKind.OpenParenToken);
|
||||
@@ -2931,7 +2953,7 @@ module TypeScript.Parser {
|
||||
DiagnosticCode.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead, undefined);
|
||||
addDiagnostic(diagnostic);
|
||||
|
||||
return Syntax.emptyToken(SyntaxKind.IdentifierName);
|
||||
return createEmptyToken(SyntaxKind.IdentifierName);
|
||||
}
|
||||
else {
|
||||
return allowInAnd(parseExpression);
|
||||
@@ -3086,7 +3108,7 @@ module TypeScript.Parser {
|
||||
else {
|
||||
var diagnostic = getExpectedTokenDiagnostic(SyntaxKind.CloseBraceToken);
|
||||
addDiagnostic(diagnostic);
|
||||
token = Syntax.emptyToken(SyntaxKind.TemplateEndToken);
|
||||
token = createEmptyToken(SyntaxKind.TemplateEndToken);
|
||||
}
|
||||
|
||||
return new TemplateClauseSyntax(parseNodeData, expression, token);
|
||||
@@ -4219,7 +4241,7 @@ module TypeScript.Parser {
|
||||
// consume the '}' just fine. So ASI doesn't apply.
|
||||
|
||||
if (allowAutomaticSemicolonInsertion && canEatAutomaticSemicolon(/*allowWithoutNewline:*/ false)) {
|
||||
var semicolonToken = eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false) || Syntax.emptyToken(SyntaxKind.SemicolonToken);
|
||||
var semicolonToken = eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false) || createEmptyToken(SyntaxKind.SemicolonToken);
|
||||
nodesAndSeparators.push(semicolonToken);
|
||||
// Debug.assert(items.length % 2 === 0);
|
||||
continue;
|
||||
|
||||
@@ -290,8 +290,8 @@ module TypeScript.Syntax {
|
||||
return new RealizedToken(token.fullStart(), token.kind, token.isKeywordConvertedToIdentifier(), leadingTrivia, token.text());
|
||||
}
|
||||
|
||||
export function emptyToken(kind: SyntaxKind): ISyntaxToken {
|
||||
return new EmptyToken(kind);
|
||||
export function emptyToken(kind: SyntaxKind, fullStart: number): ISyntaxToken {
|
||||
return new EmptyToken(kind, fullStart);
|
||||
}
|
||||
|
||||
class EmptyToken implements ISyntaxToken {
|
||||
@@ -300,17 +300,17 @@ module TypeScript.Syntax {
|
||||
public parent: ISyntaxElement;
|
||||
public childCount: number;
|
||||
|
||||
constructor(public kind: SyntaxKind) {
|
||||
constructor(public kind: SyntaxKind, private _fullStart: number) {
|
||||
}
|
||||
|
||||
public setFullStart(fullStart: number): void {
|
||||
// An empty token is always at the -1 position.
|
||||
this._fullStart = fullStart;
|
||||
}
|
||||
|
||||
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
|
||||
|
||||
public clone(): ISyntaxToken {
|
||||
return new EmptyToken(this.kind);
|
||||
return new EmptyToken(this.kind, this._fullStart);
|
||||
}
|
||||
|
||||
// Empty tokens are never incrementally reusable.
|
||||
@@ -321,75 +321,7 @@ module TypeScript.Syntax {
|
||||
}
|
||||
|
||||
public fullWidth() { return 0; }
|
||||
|
||||
private position(): number {
|
||||
// It's hard for us to tell the position of an empty token at the eact time we create
|
||||
// it. For example, we may have:
|
||||
//
|
||||
// a / finally
|
||||
//
|
||||
// There will be a missing token detected after the forward slash, so it would be
|
||||
// tempting to set its position as the full-end of hte slash token. However,
|
||||
// immediately after that, the 'finally' token will be skipped and will be attached
|
||||
// as skipped text to the forward slash. This means the 'full-end' of the forward
|
||||
// slash will change, and thus the empty token will now appear to be embedded inside
|
||||
// another token. This violates are rule that all tokens must only touch at the end,
|
||||
// and makes enforcing invariants much harder.
|
||||
//
|
||||
// To address this we create the empty token with no known position, and then we
|
||||
// determine what it's position should be based on where it lies in the tree.
|
||||
// Specifically, we find the previous non-zero-width syntax element, and we consider
|
||||
// the full-start of this token to be at the full-end of that element.
|
||||
|
||||
var previousElement = this.previousNonZeroWidthElement();
|
||||
return !previousElement ? 0 : fullStart(previousElement) + fullWidth(previousElement);
|
||||
}
|
||||
|
||||
private previousNonZeroWidthElement(): ISyntaxElement {
|
||||
var current: ISyntaxElement = this;
|
||||
while (true) {
|
||||
var parent = current.parent;
|
||||
if (parent === undefined) {
|
||||
Debug.assert(current.kind === SyntaxKind.SourceUnit, "We had a node without a parent that was not the root node!");
|
||||
|
||||
// We walked all the way to the top, and never found a previous element. This
|
||||
// can happen with code like:
|
||||
//
|
||||
// / b;
|
||||
//
|
||||
// We will have an empty identifier token as the first token in the tree. In
|
||||
// this case, return undefined so that the position of the empty token will be
|
||||
// considered to be 0.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Ok. We have a parent. First, find out which slot we're at in the parent.
|
||||
for (var i = 0, n = childCount(parent); i < n; i++) {
|
||||
if (childAt(parent, i) === current) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.assert(i !== n, "Could not find current element in parent's child list!");
|
||||
|
||||
// Walk backward from this element, looking for a non-zero-width sibling.
|
||||
for (var j = i - 1; j >= 0; j--) {
|
||||
var sibling = childAt(parent, j);
|
||||
if (sibling && fullWidth(sibling) > 0) {
|
||||
return sibling;
|
||||
}
|
||||
}
|
||||
|
||||
// We couldn't find a non-zero-width sibling. We were either the first element, or
|
||||
// all preceding elements are empty. So, move up to our parent so we we can find
|
||||
// its preceding sibling.
|
||||
current = current.parent;
|
||||
}
|
||||
}
|
||||
|
||||
public fullStart(): number {
|
||||
return this.position();
|
||||
}
|
||||
public fullStart(): number { return this._fullStart; }
|
||||
|
||||
public text() { return ""; }
|
||||
public fullText(): string { return ""; }
|
||||
|
||||
Reference in New Issue
Block a user