Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
687d25a
initial changes
mhegazy Jun 30, 2015
c5c4835
visit nodes
mhegazy Jul 1, 2015
5865c02
Add error reporting
mhegazy Jul 4, 2015
96a2b7f
Do error reporting slightlly difrrentelly
mhegazy Jul 4, 2015
46ddcbf
Walk types
mhegazy Jul 7, 2015
e3444c1
use track symbol insted of walking types
mhegazy Jul 7, 2015
b010a19
remove old diagnostics reporting
mhegazy Jul 7, 2015
4e6948f
Remove isDeclarationVisible uses
mhegazy Jul 7, 2015
4f1c088
rename functions with write prefix to emit
mhegazy Jul 7, 2015
ccba296
clean up
mhegazy Jul 7, 2015
e05b983
Handel visibility correctelly
mhegazy Jul 7, 2015
f33e422
handel internals when collecting declarations
mhegazy Jul 7, 2015
820d77d
Wire trackSymbol to show errors correctelly
mhegazy Jul 7, 2015
655104e
Disable internal check for now untill all code is fixed
mhegazy Jul 7, 2015
7718b22
use custom indexOf instead of array.prototype.indexOf to allow runnin…
mhegazy Jul 7, 2015
86c9578
Accept symbol baselines
mhegazy Jul 7, 2015
ceee493
A few additional fixes
mhegazy Jul 8, 2015
34f0d54
rename functions
mhegazy Jul 8, 2015
672fb44
use namespaces instead of module
mhegazy Jul 9, 2015
6eb1df7
Ensure trackSymbol is only called for type symbols
mhegazy Jul 9, 2015
fc7325b
handel import clauses and export default expression
mhegazy Jul 9, 2015
c8a8ff5
Handel variableDeclarations and variableStatements
mhegazy Jul 9, 2015
0f46057
handel binding patterns
mhegazy Jul 9, 2015
cb964c1
Accept baseline for export default case
mhegazy Jul 10, 2015
50cf293
accept baselines
mhegazy Jul 10, 2015
0e28bee
Fix error reporting issues
mhegazy Jul 10, 2015
a27e6f2
handel expressions in heritage clauses
mhegazy Jul 10, 2015
6384dcf
Handel type paramter declarations correctelly
mhegazy Jul 10, 2015
ffde83c
reorder declarations
mhegazy Jul 10, 2015
99d4e46
clean up collection logic
mhegazy Jul 10, 2015
767e27f
Handel missing PropertyAccessExpression
mhegazy Jul 14, 2015
edaed88
Filter declarations from other files
mhegazy Jul 14, 2015
2f3c689
use forEachChild in visitNode
mhegazy Jul 14, 2015
d1ce92e
Do not collect import declarations
mhegazy Jul 14, 2015
6193c5a
Revert "Accept symbol baselines"
mhegazy Jul 14, 2015
1d92d8e
Update error messages and fix error reporting for computed property n…
mhegazy Jul 14, 2015
8209348
Accept baseline change
mhegazy Jul 14, 2015
d18b829
Accept baseline
mhegazy Jul 15, 2015
d47caa2
Handel inaccisible symbol errors
mhegazy Jul 16, 2015
57aae40
accept baselines
mhegazy Jul 16, 2015
b44fba3
remove unused code from checker
mhegazy Jul 16, 2015
1bf2d0a
Make trackSymbol optional and use an empty writer in visitNode
mhegazy Jul 16, 2015
0758e15
Remove unused interfaces, and simplify the writer logic
mhegazy Jul 16, 2015
4b2aa47
Reorganize how triple slash references are being emitted
mhegazy Jul 16, 2015
0f58d94
remove unsused variable
mhegazy Jul 17, 2015
ca07040
Consolidate emit logic in one place, and split the process into two p…
mhegazy Jul 20, 2015
98cd107
Switch to iterative model and clean up error reporting
mhegazy Jul 21, 2015
bd1347d
handel missing nodes in visitNode
mhegazy Jul 22, 2015
1f0520e
Only check if hasExportDeclarations on external modules
mhegazy Jul 22, 2015
859bd12
Do not create a new typewriter everytime
mhegazy Jul 22, 2015
33ace7a
Merge branch 'master' into declarations
Jul 27, 2015
ce8090a
remove unused property
Jul 27, 2015
fd01a64
Support @internal
Jul 28, 2015
a876104
make forEachTopLevelDeclaration generic
mhegazy Jul 28, 2015
ab42595
Fix #3912: emit declaration for binding elements correctelly
mhegazy Jul 28, 2015
ed2e5d9
move getLocalTargetOfAliasDeclaration back to the emitter
mhegazy Jul 29, 2015
f4da2fe
Merge branch 'master' into declarations
mhegazy Jul 29, 2015
4ec081c
rever sourceRoot change to tsconfig.json
mhegazy Jul 29, 2015
cbb4e2c
Merge branch 'master' into declarations
mhegazy Aug 9, 2015
3eb940b
Merge branch 'master' into declarations
mhegazy Sep 17, 2015
9ebf182
handel outFile flag
mhegazy Sep 21, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handel inaccisible symbol errors
  • Loading branch information
mhegazy committed Jul 16, 2015
commit d47caa268611999fd6498e6af6c711cc2abe75bb
5 changes: 5 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,11 @@ namespace ts {
}
}
else {

if (!parentSymbol) {
writer.trackInaccesibleSymbol(symbol);
}

// If we didn't find accessible symbol chain for this symbol, break if this is external module
if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) {
return;
Expand Down
54 changes: 54 additions & 0 deletions src/compiler/declarationEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ namespace ts {
function createNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter {
let writer = <EmitTextWriterWithSymbolWriter>createTextWriter(newLine);
writer.trackSymbol = trackSymbol;
writer.trackInaccesibleSymbol = trackInaccesibleSymbol;
writer.writeKeyword = writer.write;
writer.writeOperator = writer.write;
writer.writePunctuation = writer.write;
Expand All @@ -154,6 +155,12 @@ namespace ts {
}
}

function trackInaccesibleSymbol(symbol: Symbol): void {
if (currentErrorNode) {
reportUnamedDeclarationMessage(currentErrorNode);
}
}

function emitTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode) {
write(": ");
if (type) {
Expand Down Expand Up @@ -1525,6 +1532,53 @@ namespace ts {
Debug.fail("Could not find container node");
}

function reportUnamedDeclarationMessage(errorNode: Node): void {
reportedDeclarationError = true;
let container = errorNode;

while (container) {
switch (container.kind) {
case SyntaxKind.BindingElement:
case SyntaxKind.VariableDeclaration:
diagnostics.push(createDiagnosticForNode(errorNode,
Diagnostics.Name_of_inferred_type_of_variable_0_could_not_be_written_Consider_adding_an_explicit_type_annotation,
getNameText(<VariableDeclaration>container)));
return;
case SyntaxKind.PropertySignature:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.SetAccessor:
case SyntaxKind.GetAccessor:
diagnostics.push(createDiagnosticForNode(errorNode,
Diagnostics.Name_of_inferred_type_of_property_0_could_not_be_written_Consider_adding_an_explicit_type_annotation,
getNameText(<PropertyDeclaration>container)));
return;
case SyntaxKind.Parameter:
diagnostics.push(createDiagnosticForNode(errorNode,
Diagnostics.Name_of_inferred_type_of_parameter_0_could_not_be_written_Consider_adding_an_explicit_type_annotation,
getNameText(<ParameterDeclaration>container)));
return;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
diagnostics.push(createDiagnosticForNode(errorNode,
Diagnostics.Name_of_inferred_return_type_of_method_0_could_not_be_written_Consider_adding_an_explicit_type_annotation,
getNameText(<MethodDeclaration>container)));
return;
case SyntaxKind.FunctionDeclaration:
diagnostics.push(createDiagnosticForNode(errorNode,
Diagnostics.Name_of_inferred_return_type_of_function_0_could_not_be_written_Consider_adding_an_explicit_type_annotation,
getNameText(<FunctionDeclaration>container)));
return;
case SyntaxKind.ExportAssignment:
diagnostics.push(createDiagnosticForNode(errorNode,
Diagnostics.Name_of_inferred_type_of_default_export_could_not_be_written_Consider_exporting_a_declaration_instead));
return;
}
container = container.parent;
}

Debug.fail("Could not find container node");
}

function collectDeclaration(node: Node, errorNode?: Node): void {
if (node.kind === SyntaxKind.TypeParameter || node.kind === SyntaxKind.Parameter) {
return;
Expand Down
8 changes: 7 additions & 1 deletion src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,22 @@ namespace ts {
Implements_clause_references_inaccessible_name_0: { code: 4019, category: DiagnosticCategory.Error, key: "Implements clause references inaccessible name '{0}'." },
Extends_clause_references_inaccessible_name_0: { code: 4020, category: DiagnosticCategory.Error, key: "Extends clause references inaccessible name '{0}'." },
Type_of_variable_0_references_inaccessible_name_1: { code: 4025, category: DiagnosticCategory.Error, key: "Type of variable '{0}' references inaccessible name '{1}'." },
Name_of_inferred_type_of_variable_0_could_not_be_written_Consider_adding_an_explicit_type_annotation: { code: 4026, category: DiagnosticCategory.Error, key: "Name of inferred type of variable '{0}' could not be written. Consider adding an explicit type annotation." },
Type_of_property_0_references_inaccessible_name_1: { code: 4028, category: DiagnosticCategory.Error, key: "Type of property '{0}' references inaccessible name '{1}'." },
Type_of_parameter_0_references_inaccessible_name_1: { code: 4028, category: DiagnosticCategory.Error, key: "Type of parameter '{0}' references inaccessible name '{1}'." },
Name_of_inferred_type_of_property_0_could_not_be_written_Consider_adding_an_explicit_type_annotation: { code: 4029, category: DiagnosticCategory.Error, key: "Name of inferred type of property '{0}' could not be written. Consider adding an explicit type annotation." },
Type_of_parameter_0_references_inaccessible_name_1: { code: 4030, category: DiagnosticCategory.Error, key: "Type of parameter '{0}' references inaccessible name '{1}'." },
Name_of_inferred_type_of_parameter_0_could_not_be_written_Consider_adding_an_explicit_type_annotation: { code: 4031, category: DiagnosticCategory.Error, key: "Name of inferred type of parameter '{0}' could not be written. Consider adding an explicit type annotation." },
Return_type_of_method_0_references_inaccessible_name_1: { code: 4038, category: DiagnosticCategory.Error, key: "Return type of method '{0}' references inaccessible name '{1}'." },
Name_of_inferred_return_type_of_method_0_could_not_be_written_Consider_adding_an_explicit_type_annotation: { code: 4039, category: DiagnosticCategory.Error, key: "Name of inferred return type of method '{0}' could not be written. Consider adding an explicit type annotation." },
Return_type_of_property_getter_0_references_inaccessible_name_1: { code: 4043, category: DiagnosticCategory.Error, key: "Return type of property getter '{0}' references inaccessible name '{1}'." },
Return_type_of_construct_signature_references_inaccessible_name_0: { code: 4044, category: DiagnosticCategory.Error, key: "Return type of construct signature references inaccessible name '{0}'." },
Return_type_of_call_signature_references_inaccessible_name_0: { code: 4047, category: DiagnosticCategory.Error, key: "Return type of call signature references inaccessible name '{0}'." },
Return_type_of_index_signature_references_inaccessible_name_0: { code: 4049, category: DiagnosticCategory.Error, key: "Return type of index signature references inaccessible name '{0}'." },
Return_type_of_function_0_references_inaccessible_name_1: { code: 4060, category: DiagnosticCategory.Error, key: "Return type of function '{0}' references inaccessible name '{1}'." },
Name_of_inferred_return_type_of_function_0_could_not_be_written_Consider_adding_an_explicit_type_annotation: { code: 4061, category: DiagnosticCategory.Error, key: "Name of inferred return type of function '{0}' could not be written. Consider adding an explicit type annotation." },
Type_alias_0_references_inaccessible_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Type alias '{0}' references inaccessible name '{1}'." },
Default_export_of_the_module_references_inaccessible_name_0: { code: 4082, category: DiagnosticCategory.Error, key: "Default export of the module references inaccessible name '{0}'." },
Name_of_inferred_type_of_default_export_could_not_be_written_Consider_exporting_a_declaration_instead: { code: 4083, category: DiagnosticCategory.Error, key: "Name of inferred type of default export could not be written. Consider exporting a declaration instead." },
Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." },
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
Expand Down
27 changes: 26 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1706,18 +1706,34 @@
"category": "Error",
"code": 4025
},
"Name of inferred type of variable '{0}' could not be written. Consider adding an explicit type annotation.": {
"category": "Error",
"code": 4026
},
"Type of property '{0}' references inaccessible name '{1}'.": {
"category": "Error",
"code": 4028
},
"Name of inferred type of property '{0}' could not be written. Consider adding an explicit type annotation.": {
"category": "Error",
"code": 4029
},
"Type of parameter '{0}' references inaccessible name '{1}'.": {
"category": "Error",
"code": 4028
"code": 4030
},
"Name of inferred type of parameter '{0}' could not be written. Consider adding an explicit type annotation.": {
"category": "Error",
"code": 4031
},
"Return type of method '{0}' references inaccessible name '{1}'.": {
"category": "Error",
"code": 4038
},
"Name of inferred return type of method '{0}' could not be written. Consider adding an explicit type annotation.": {
"category": "Error",
"code": 4039
},
"Return type of property getter '{0}' references inaccessible name '{1}'.": {
"category": "Error",
"code": 4043
Expand All @@ -1738,6 +1754,10 @@
"category": "Error",
"code": 4060
},
"Name of inferred return type of function '{0}' could not be written. Consider adding an explicit type annotation.": {
"category": "Error",
"code": 4061
},
"Type alias '{0}' references inaccessible name '{1}'.": {
"category": "Error",
"code": 4081
Expand All @@ -1746,6 +1766,11 @@
"category": "Error",
"code": 4082
},
"Name of inferred type of default export could not be written. Consider exporting a declaration instead.": {
"category": "Error",
"code": 4083
},


"Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": {
"category": "Error",
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ namespace ts {
// declaration emitter to help determine if it should patch up the final declaration file
// with import statements it previously saw (but chose not to emit).
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
trackInaccesibleSymbol(symbol: Symbol): void;
}

export const enum TypeFormatFlags {
Expand Down Expand Up @@ -1786,10 +1787,10 @@ namespace ts {
StringLike = String | StringLiteral,
NumberLike = Number | Enum,
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
UnionOrIntersection = Union | Intersection,
UnionOrIntersection = Union | Intersection,
StructuredType = ObjectType | Union | Intersection,
/* @internal */
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral
}

// Properties common to all types
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace ts {
increaseIndent: () => { },
decreaseIndent: () => { },
clear: () => str = "",
trackSymbol: () => { }
trackSymbol: () => { },
trackInaccesibleSymbol: () => { }
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ namespace ts {
increaseIndent: () => { indent++; },
decreaseIndent: () => { indent--; },
clear: resetWriter,
trackSymbol: () => { }
trackSymbol: () => { },
trackInaccesibleSymbol: () => { }
};

function writeIndent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(16,21): error TS4043: Return type of property getter 'foo1' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(21,13): error TS4043: Return type of property getter 'foo2' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(26,25): error TS4028: Type of parameter 'param' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(33,25): error TS4028: Type of parameter 'param' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(26,25): error TS4030: Type of parameter 'param' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(33,25): error TS4030: Type of parameter 'param' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(37,21): error TS4043: Return type of property getter 'foo5' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(72,23): error TS4043: Return type of property getter 'foo111' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(77,13): error TS4043: Return type of property getter 'foo112' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(82,27): error TS4028: Type of parameter 'param' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(89,27): error TS4028: Type of parameter 'param' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(82,27): error TS4030: Type of parameter 'param' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(89,27): error TS4030: Type of parameter 'param' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(93,23): error TS4043: Return type of property getter 'foo115' references inaccessible name 'm2'.


Expand Down Expand Up @@ -42,7 +42,7 @@ tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(93,23): e
// setter with annotation
set foo3(param: private1) {
~~~~~~~~
!!! error TS4028: Type of parameter 'param' references inaccessible name 'private1'.
!!! error TS4030: Type of parameter 'param' references inaccessible name 'private1'.
}

// Both - getter without annotation, setter with annotation
Expand All @@ -51,7 +51,7 @@ tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(93,23): e
}
set foo4(param: private1) {
~~~~~~~~
!!! error TS4028: Type of parameter 'param' references inaccessible name 'private1'.
!!! error TS4030: Type of parameter 'param' references inaccessible name 'private1'.
}

// Both - with annotation
Expand Down Expand Up @@ -108,7 +108,7 @@ tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(93,23): e
// setter with annotation
set foo113(param: m2.public2) {
~~
!!! error TS4028: Type of parameter 'param' references inaccessible name 'm2'.
!!! error TS4030: Type of parameter 'param' references inaccessible name 'm2'.
}

// Both - getter without annotation, setter with annotation
Expand All @@ -117,7 +117,7 @@ tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(93,23): e
}
set foo114(param: m2.public2) {
~~
!!! error TS4028: Type of parameter 'param' references inaccessible name 'm2'.
!!! error TS4030: Type of parameter 'param' references inaccessible name 'm2'.
}

// Both - with annotation
Expand Down
Loading