@@ -785,6 +785,17 @@ class Annotator extends ClosureRewriter {
785
785
case ts . SyntaxKind . AsExpression :
786
786
// Both of these cases are AssertionExpressions.
787
787
const typeAssertion = node as ts . AssertionExpression ;
788
+ if ( this . polymerBehaviorStackCount > 0 ) {
789
+ // Don't emit type casts for Polymer behaviors that are declared
790
+ // by calling the Polymer function
791
+ // as the Polymer closure plugin does not work when emitting them.
792
+ // Note: This only matters in the transformer version of tsickle,
793
+ // as the non transformer version never emitted type casts due to
794
+ // https://github.com/Microsoft/TypeScript/issues/9873 (see below).
795
+ // TODO(tbosch): file an issue with Polymer, tracked in
796
+ // https://github.com/angular/tsickle/issues/529.
797
+ return false ;
798
+ }
788
799
// When using a type casts in template expressions,
789
800
// closure requires another pair of parens, otherwise it will
790
801
// complain with "Misplaced type annotation. Type annotations are not allowed here."
@@ -852,6 +863,15 @@ class Annotator extends ClosureRewriter {
852
863
return true ;
853
864
}
854
865
break ;
866
+ case ts . SyntaxKind . PropertyAssignment :
867
+ const pa = node as ts . PropertyAssignment ;
868
+ if ( isPolymerBehaviorPropertyInCallExpression ( pa ) ) {
869
+ this . polymerBehaviorStackCount ++ ;
870
+ this . writeNodeFrom ( node , node . getStart ( ) ) ;
871
+ this . polymerBehaviorStackCount -- ;
872
+ return true ;
873
+ }
874
+ return false ;
855
875
case ts . SyntaxKind . ElementAccessExpression :
856
876
// Warn for quoted accesses to properties that have a symbol declared.
857
877
// Mixing quoted and non-quoted access to a symbol (x['foo'] and x.foo) risks breaking
@@ -1870,6 +1890,18 @@ class ExternsWriter extends ClosureRewriter {
1870
1890
}
1871
1891
}
1872
1892
1893
+ function isPolymerBehaviorPropertyInCallExpression ( pa : ts . PropertyAssignment ) : boolean {
1894
+ const parentParent = pa . parent && pa . parent . parent ;
1895
+ if ( pa . name . kind !== ts . SyntaxKind . Identifier ||
1896
+ ( pa . name as ts . Identifier ) . text !== 'behaviors' || ! pa . parent || ! pa . parent . parent ||
1897
+ pa . parent . parent . kind !== ts . SyntaxKind . CallExpression ) {
1898
+ return false ;
1899
+ }
1900
+
1901
+ const expr = ( parentParent as ts . CallExpression ) . expression ;
1902
+ return expr . kind === ts . SyntaxKind . Identifier && ( expr as ts . Identifier ) . text === 'Polymer' ;
1903
+ }
1904
+
1873
1905
export function annotate (
1874
1906
typeChecker : ts . TypeChecker , file : ts . SourceFile , host : AnnotatorHost ,
1875
1907
options : AnnotatorOptions = { } , tsHost ?: ts . ModuleResolutionHost , tsOpts ?: ts . CompilerOptions ,
0 commit comments