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
Switch to iterative model and clean up error reporting
  • Loading branch information
mhegazy committed Jul 21, 2015
commit 98cd10784cdff7f7bc3c45a482b1541f874a01a8
99 changes: 63 additions & 36 deletions src/compiler/declarationEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace ts {
visited?: boolean;
collected?: boolean;
hasExportDeclarations?: boolean;
errorReported?: boolean;
}

interface PreprocessResults {
Expand Down Expand Up @@ -1039,6 +1040,7 @@ namespace ts {
function preprocessDeclarations(sourceFiles: SourceFile[], resolver: EmitResolver, diagnostics: Diagnostic[], compilerOptions: CompilerOptions): PreprocessResults {
let currentSourceFile: SourceFile;
let nodeLinks: NodeLinks[] = [];
let declarationsToProcess: { declaration: Node; errorNode?: Node }[] = [];

for (let sourceFile of sourceFiles) {
preprocessSourceFile(sourceFile);
Expand Down Expand Up @@ -1298,10 +1300,17 @@ namespace ts {
}

function collectDeclarations(symbol: Symbol, errorNode: Node): void {
forEach(symbol.declarations, d => collectDeclaration(d, errorNode));
forEach(symbol.declarations, declaration => {
collectDeclatation(declaration, errorNode);
});
}
}

function collectDeclatation(declaration:Node, errorNode?: Node) {
declarationsToProcess.push({ declaration, errorNode });
//preprocessDeclaration(declaration, errorNode);
}

function isDeclarationExported(node: Node): boolean {
if (compilerOptions.stripInternal && isInternal(node)) {
// TODO: this is the correct place for this check, enable this
Expand Down Expand Up @@ -1421,31 +1430,31 @@ namespace ts {
*
*/
function canWriteDeclaration(node: Node): boolean {
if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) {
node = node.parent.parent;
}

// If the declaration is exported from its parent, we can
// safelly write a declaration for it
if (isDeclarationExported(node)) {
if (node.kind === SyntaxKind.SourceFile ||
node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ImportDeclaration) {
return true;
}

if (node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ImportDeclaration) {
return true;
if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) {
node = node.parent.parent;
}

// If the parent module has an export declaration or export
// assingment, then the scoping rules change, and only declarations
// with export modifier are visible, so we can safely write
// a declaration of a non-exported entity without exposing it
let parent = getEnclosingDeclaration(node);
if (parent) {
return (parent.kind === SyntaxKind.ModuleDeclaration || parent.kind === SyntaxKind.SourceFile) &&
hasExportDeclatations(parent);

if (!isDeclarationExported(node)) {
// If the parent module has an export declaration or export
// assingment, then the scoping rules change, and only declarations
// with export modifier are visible, so we can safely write
// a declaration of a non-exported entity without exposing it
if (!((parent.kind === SyntaxKind.ModuleDeclaration || parent.kind === SyntaxKind.SourceFile) &&
hasExportDeclatations(parent))) {
return false;
}
}

return false;
// The declaration is exported from its parent, or can be written without
// an export modifier. Now check if the parent is visible as well.
return canWriteDeclaration(parent);
}

function getNameText(node: ParameterDeclaration|PropertyDeclaration|VariableDeclaration|FunctionDeclaration| AccessorDeclaration| MethodDeclaration): string {
Expand Down Expand Up @@ -1597,44 +1606,64 @@ namespace ts {
Debug.fail("Could not find container node");
}

function collectDeclaration(node: Node, errorNode?: Node): void {
if (node.kind === SyntaxKind.TypeParameter || node.kind === SyntaxKind.Parameter) {
function preprocessDeclaration(declaration: Node, errorNode?: Node): void {
if (declaration.kind === SyntaxKind.TypeParameter || declaration.kind === SyntaxKind.Parameter) {
return;
}

// Make sure this declaration can be emitted, that is it is accessible
// and is connected to its parent, or else report a accessibility error
ensureDeclarationVisible(node, errorNode);
// Always report the error, even if the node was visited before, so that
// diffrent references to the same declaration are flagged
if (errorNode && reportDeclarationAccessiblityError(declaration, errorNode)) {
return;
}

// If this declaration is from a diffrent file, we will get to it later.
if (getSourceFileOfNode(node) !== currentSourceFile) {
// Skip it for now.
if (getSourceFileOfNode(declaration) !== currentSourceFile) {
return;
}

let links = getNodeLinks(node);
let links = getNodeLinks(declaration);
if (!links.collected) {
links.collected = true;

// Make sure this declaration can be emitted, that is it is accessible
// and is connected to its parent, or else report a accessibility error
ensureDeclarationVisible(declaration, errorNode);

// Collect any dependencies
collectReferencedDeclarations(node);
collectReferencedDeclarations(declaration);

// Collect children as well
switch (node.kind) {
switch (declaration.kind) {
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.VariableStatement:
collectTopLevelChildDeclarations(node);
collectTopLevelChildDeclarations(declaration);
break;
}
}
}

function reportDeclarationAccessiblityError(declaration: Node, errorNode: Node): boolean {
let node = errorNode;
while (node.parent.kind === SyntaxKind.QualifiedName || node.parent.kind === SyntaxKind.PropertyAccessExpression) {
node = node.parent;
}
let links = getNodeLinks(node);
if (!links.errorReported && !canWriteDeclaration(declaration)) {
links.errorReported = true;
reportDeclarationAccessiblityMessage(<Declaration>declaration, errorNode);
}
return links.errorReported;
}

function collectTopLevelChildDeclarations(node: Node): void {
forEachTopLevelDeclaration(node, child => {
if (isDeclarationExported(child)) {
collectDeclaration(child);
collectDeclatation(child);
}
});
}
Expand All @@ -1654,13 +1683,6 @@ namespace ts {
attachVisibleChild(parent, node);
}
}

// Always report the error, even if the node was visited before
if (errorNode) {
if (!canWriteDeclaration(node)) {
reportDeclarationAccessiblityMessage(<Declaration>node, errorNode);
}
}
}

function attachVisibleChild(node: Node, child: Node): void {
Expand All @@ -1676,6 +1698,11 @@ namespace ts {

// Collect all visible declarations
collectTopLevelChildDeclarations(sourceFile);

while (declarationsToProcess.length > 0) {
let {declaration, errorNode} = declarationsToProcess.shift();
preprocessDeclaration(declaration, errorNode);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(13,13):
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(14,19): error TS4038: Return type of method 'method' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(15,22): error TS4049: Return type of index signature references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(16,22): error TS4049: Return type of index signature references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(18,16): error TS4025: Type of variable 'x2' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(18,16): error TS4025: Type of variable 'x2' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(25,16): error TS4025: Type of variable 'x3' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(25,16): error TS4025: Type of variable 'x3' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(28,23): error TS4030: Type of parameter 'a' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(28,36): error TS4025: Type of variable 'y' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(29,16): error TS4025: Type of variable 'y2' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(29,16): error TS4025: Type of variable 'y2' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(32,27): error TS4030: Type of parameter 'a' references inaccessible name 'private1'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(32,40): error TS4025: Type of variable 'z' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(33,16): error TS4025: Type of variable 'z2' references inaccessible name 'm2'.
tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(33,16): error TS4025: Type of variable 'z2' references inaccessible name 'private1'.


==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts (18 errors) ====
==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts (14 errors) ====

module m {
class private1 {
Expand Down Expand Up @@ -50,8 +46,6 @@ tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(33,16):
};
export var x2 = {
~~
!!! error TS4025: Type of variable 'x2' references inaccessible name 'm2'.
~~
!!! error TS4025: Type of variable 'x2' references inaccessible name 'private1'.
x: new private1(),
y: new m2.public1(),
Expand All @@ -62,8 +56,6 @@ tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(33,16):
export var x3 = x;
~~
!!! error TS4025: Type of variable 'x3' references inaccessible name 'm2'.
~~
!!! error TS4025: Type of variable 'x3' references inaccessible name 'private1'.

// Function type
export var y: (a: private1) => m2.public1;
Expand All @@ -73,8 +65,6 @@ tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(33,16):
!!! error TS4025: Type of variable 'y' references inaccessible name 'm2'.
export var y2 = y;
~~
!!! error TS4025: Type of variable 'y2' references inaccessible name 'm2'.
~~
!!! error TS4025: Type of variable 'y2' references inaccessible name 'private1'.

// constructor type
Expand All @@ -85,7 +75,5 @@ tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(33,16):
!!! error TS4025: Type of variable 'z' references inaccessible name 'm2'.
export var z2 = z;
~~
!!! error TS4025: Type of variable 'z2' references inaccessible name 'm2'.
~~
!!! error TS4025: Type of variable 'z2' references inaccessible name 'private1'.
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
tests/cases/compiler/expressionInExtendsClauseWithVisibilityErrors.ts(16,30): error TS4020: Extends clause references inaccessible name 'C'.
tests/cases/compiler/expressionInExtendsClauseWithVisibilityErrors.ts(16,30): error TS4020: Extends clause references inaccessible name 'I'.


==== tests/cases/compiler/expressionInExtendsClauseWithVisibilityErrors.ts (2 errors) ====
==== tests/cases/compiler/expressionInExtendsClauseWithVisibilityErrors.ts (1 errors) ====

interface I {
}
Expand All @@ -21,8 +20,6 @@ tests/cases/compiler/expressionInExtendsClauseWithVisibilityErrors.ts(16,30): er
export class MyClass extends getClass(2) <string, I> {
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4020: Extends clause references inaccessible name 'C'.
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4020: Extends clause references inaccessible name 'I'.
}


Loading