Skip to content

Commit

Permalink
Better handling of circular JS containers in getTypeOfVariableOrParam…
Browse files Browse the repository at this point in the history
…eterOrProperty (#24732)

* avoid circularity in getTypeOfVariableOrParameterOrProperty

Modify getTypeOfVariableOrParameterOrProperty to get the type of the
variable declaration before widening it. This essentially avoids some
circularities by (1) setting the type of the variable declaration to the
unwidened type (2) updating the type of the variable declaration to the
widened one.

You will still get a circular noImplicitAny in (1), for expressions that
actually are circular, but not in (2), for the containers of things that
are not themselves circular.

* Stop checking js init object literals via checkObjectLiteral

* checkBinaryExpression: new code for special assignments

* Chained lookup for js initializer type

* Check for JS-specific types only once

Also make sure to respect the type annotation if there is one.

* Accept API changes
  • Loading branch information
sandersn authored Jun 12, 2018
1 parent 8ba5fb9 commit 5be8f1f
Show file tree
Hide file tree
Showing 45 changed files with 1,231 additions and 999 deletions.
3 changes: 2 additions & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2514,11 +2514,12 @@ namespace ts {
return true;
}
const node = symbol.valueDeclaration;
const init = !node ? undefined :
let init = !node ? undefined :
isVariableDeclaration(node) ? node.initializer :
isBinaryExpression(node) ? node.right :
isPropertyAccessExpression(node) && isBinaryExpression(node.parent) ? node.parent.right :
undefined;
init = init && getRightMostAssignedExpression(init);
if (init) {
const isPrototypeAssignment = isPrototypeAccess(isVariableDeclaration(node) ? node.name : isBinaryExpression(node) ? node.left : node);
return !!getJavascriptInitializer(isBinaryExpression(init) && init.operatorToken.kind === SyntaxKind.BarBarToken ? init.right : init, isPrototypeAssignment);
Expand Down
206 changes: 128 additions & 78 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/parser/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,12 @@ namespace ts {
return node.initializer;
}

/** Get the declaration initializer when it is container-like (See getJavascriptInitializer). */
export function getDeclaredJavascriptInitializer(node: HasExpressionInitializer) {
const init = getEffectiveInitializer(node);
return init && getJavascriptInitializer(init, isPrototypeAccess(node.name));
}

/**
* Get the assignment 'initializer' -- the righthand side-- when the initializer is container-like (See getJavascriptInitializer).
* We treat the right hand side of assignments with container-like initalizers as declarations.
Expand Down
146 changes: 73 additions & 73 deletions tests/baselines/reference/APISample_Watch.errors.txt
Original file line number Diff line number Diff line change
@@ -1,67 +1,65 @@
typescript_standalone.d.ts(21,28): error TS1005: ';' expected.
typescript_standalone.d.ts(21,41): error TS1005: ';' expected.
typescript_standalone.d.ts(8910,28): error TS1005: ';' expected.
typescript_standalone.d.ts(8910,42): error TS1005: ';' expected.
typescript_standalone.d.ts(9170,28): error TS1005: ';' expected.
typescript_standalone.d.ts(9170,46): error TS1005: ';' expected.
typescript_standalone.d.ts(9520,28): error TS1005: ';' expected.
typescript_standalone.d.ts(9520,36): error TS1005: ';' expected.
typescript_standalone.d.ts(9544,28): error TS1005: ';' expected.
typescript_standalone.d.ts(9544,36): error TS1005: ';' expected.
typescript_standalone.d.ts(9631,28): error TS1005: ';' expected.
typescript_standalone.d.ts(9631,38): error TS1005: ';' expected.
typescript_standalone.d.ts(10796,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10796,57): error TS1005: ';' expected.
typescript_standalone.d.ts(10807,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10807,41): error TS1005: ';' expected.
typescript_standalone.d.ts(10817,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10817,48): error TS1005: ';' expected.
typescript_standalone.d.ts(10892,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10892,47): error TS1005: ';' expected.
typescript_standalone.d.ts(10949,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10949,47): error TS1005: ';' expected.
typescript_standalone.d.ts(11003,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11003,52): error TS1005: ';' expected.
typescript_standalone.d.ts(11023,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11023,44): error TS1005: ';' expected.
typescript_standalone.d.ts(11033,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11033,35): error TS1005: ';' expected.
typescript_standalone.d.ts(11067,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11067,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11070,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11070,43): error TS1005: ';' expected.
typescript_standalone.d.ts(11074,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11074,45): error TS1005: ';' expected.
typescript_standalone.d.ts(11092,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11092,56): error TS1005: ';' expected.
typescript_standalone.d.ts(11118,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11118,36): error TS1005: ';' expected.
typescript_standalone.d.ts(11121,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11121,43): error TS1005: ';' expected.
typescript_standalone.d.ts(11133,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11133,43): error TS1005: ';' expected.
typescript_standalone.d.ts(11163,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11163,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11197,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11197,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11208,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11208,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11232,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11232,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11240,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11240,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11244,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11244,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11274,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11274,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11317,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11317,41): error TS1005: ';' expected.
typescript_standalone.d.ts(11504,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11504,37): error TS1005: ';' expected.
typescript_standalone.d.ts(8912,28): error TS1005: ';' expected.
typescript_standalone.d.ts(8912,42): error TS1005: ';' expected.
typescript_standalone.d.ts(9172,28): error TS1005: ';' expected.
typescript_standalone.d.ts(9172,46): error TS1005: ';' expected.
typescript_standalone.d.ts(9522,28): error TS1005: ';' expected.
typescript_standalone.d.ts(9522,36): error TS1005: ';' expected.
typescript_standalone.d.ts(9546,28): error TS1005: ';' expected.
typescript_standalone.d.ts(9546,36): error TS1005: ';' expected.
typescript_standalone.d.ts(9633,28): error TS1005: ';' expected.
typescript_standalone.d.ts(9633,38): error TS1005: ';' expected.
typescript_standalone.d.ts(10798,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10798,57): error TS1005: ';' expected.
typescript_standalone.d.ts(10809,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10809,41): error TS1005: ';' expected.
typescript_standalone.d.ts(10819,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10819,48): error TS1005: ';' expected.
typescript_standalone.d.ts(10894,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10894,47): error TS1005: ';' expected.
typescript_standalone.d.ts(10951,28): error TS1005: ';' expected.
typescript_standalone.d.ts(10951,47): error TS1005: ';' expected.
typescript_standalone.d.ts(11005,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11005,52): error TS1005: ';' expected.
typescript_standalone.d.ts(11025,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11025,44): error TS1005: ';' expected.
typescript_standalone.d.ts(11035,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11035,35): error TS1005: ';' expected.
typescript_standalone.d.ts(11069,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11069,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11072,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11072,43): error TS1005: ';' expected.
typescript_standalone.d.ts(11076,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11076,45): error TS1005: ';' expected.
typescript_standalone.d.ts(11094,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11094,56): error TS1005: ';' expected.
typescript_standalone.d.ts(11120,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11120,36): error TS1005: ';' expected.
typescript_standalone.d.ts(11123,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11123,43): error TS1005: ';' expected.
typescript_standalone.d.ts(11135,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11135,43): error TS1005: ';' expected.
typescript_standalone.d.ts(11165,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11165,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11199,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11199,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11210,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11210,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11234,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11234,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11242,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11242,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11246,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11246,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11276,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11276,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11319,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11319,41): error TS1005: ';' expected.
typescript_standalone.d.ts(11506,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11506,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11510,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11510,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11508,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11508,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11512,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11512,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11514,28): error TS1005: ';' expected.
Expand All @@ -70,8 +68,8 @@ typescript_standalone.d.ts(11516,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11516,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11518,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11518,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11527,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11527,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11520,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11520,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11529,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11529,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11531,28): error TS1005: ';' expected.
Expand Down Expand Up @@ -100,8 +98,8 @@ typescript_standalone.d.ts(11553,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11553,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11555,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11555,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11565,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11565,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11557,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11557,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11567,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11567,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11569,28): error TS1005: ';' expected.
Expand All @@ -115,19 +113,21 @@ typescript_standalone.d.ts(11575,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11577,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11577,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11579,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11579,72): error TS1005: ';' expected.
typescript_standalone.d.ts(11579,37): error TS1005: ';' expected.
typescript_standalone.d.ts(11581,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11581,52): error TS1005: ';' expected.
typescript_standalone.d.ts(11653,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11653,72): error TS1005: ';' expected.
typescript_standalone.d.ts(11581,72): error TS1005: ';' expected.
typescript_standalone.d.ts(11583,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11583,52): error TS1005: ';' expected.
typescript_standalone.d.ts(11655,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11655,38): error TS1005: ';' expected.
typescript_standalone.d.ts(11655,72): error TS1005: ';' expected.
typescript_standalone.d.ts(11657,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11657,71): error TS1005: ';' expected.
typescript_standalone.d.ts(11657,38): error TS1005: ';' expected.
typescript_standalone.d.ts(11659,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11659,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11735,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11735,48): error TS1005: ';' expected.
typescript_standalone.d.ts(11659,71): error TS1005: ';' expected.
typescript_standalone.d.ts(11661,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11661,40): error TS1005: ';' expected.
typescript_standalone.d.ts(11737,28): error TS1005: ';' expected.
typescript_standalone.d.ts(11737,48): error TS1005: ';' expected.


==== tests/cases/compiler/APISample_Watch.ts (0 errors) ====
Expand Down
Loading

0 comments on commit 5be8f1f

Please sign in to comment.