@@ -3959,6 +3959,21 @@ module ts {
3959
3959
// NOTE(cyrusn): Some expressions may seem to be side effect free, but may
3960
3960
// actually have side effects. For example, a binary + expression may cause
3961
3961
// the toString method to be called on value, which may have side effects.
3962
+
3963
+ // These are the set of syntactic productions which we know could definitely
3964
+ // have side effects:
3965
+ case SyntaxKind . CallExpression :
3966
+ case SyntaxKind . NewExpression :
3967
+ return true ;
3968
+
3969
+ case SyntaxKind . PropertyAccessExpression :
3970
+ case SyntaxKind . ElementAccessExpression :
3971
+ // Property/Element access might end up causing an accessor to run. As
3972
+ // such, we have to assume there will be side effects.
3973
+ return true ;
3974
+
3975
+ // These are the set of syntactic productions which we know definitely do not
3976
+ // have side effects:
3962
3977
case SyntaxKind . StringLiteral :
3963
3978
case SyntaxKind . NoSubstitutionTemplateLiteral :
3964
3979
case SyntaxKind . NumericLiteral :
@@ -3975,6 +3990,8 @@ module ts {
3975
3990
case SyntaxKind . SetAccessor :
3976
3991
return false ;
3977
3992
3993
+ // These constructs may or may not have side effects depending on their
3994
+ // constituent children.
3978
3995
case SyntaxKind . ArrayBindingPattern :
3979
3996
case SyntaxKind . ObjectBindingPattern :
3980
3997
return forEach ( ( < BindingPattern > node ) . elements , hasPossibleSideEffects ) ;
@@ -3987,16 +4004,9 @@ module ts {
3987
4004
return hasPossibleSideEffects ( ( < ParameterDeclaration > node ) . name ) ||
3988
4005
hasPossibleSideEffects ( ( < ParameterDeclaration > node ) . initializer ) ;
3989
4006
3990
- case SyntaxKind . PropertyAccessExpression :
3991
- return hasPossibleSideEffects ( ( < PropertyAccessExpression > node ) . expression ) ;
3992
-
3993
4007
case SyntaxKind . ArrayLiteralExpression :
3994
4008
return forEach ( ( < ArrayLiteralExpression > node ) . elements , hasPossibleSideEffects ) ;
3995
4009
3996
- case SyntaxKind . ElementAccessExpression :
3997
- return hasPossibleSideEffects ( ( < ElementAccessExpression > node ) . expression ) ||
3998
- hasPossibleSideEffects ( ( < ElementAccessExpression > node ) . argumentExpression ) ;
3999
-
4000
4010
case SyntaxKind . ParenthesizedExpression :
4001
4011
return hasPossibleSideEffects ( ( < ParenthesizedExpression > node ) . expression ) ;
4002
4012
0 commit comments