Skip to content

Commit 8d0dc91

Browse files
CR feedback.
1 parent 53ed427 commit 8d0dc91

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/compiler/emitter.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,6 +3959,21 @@ module ts {
39593959
// NOTE(cyrusn): Some expressions may seem to be side effect free, but may
39603960
// actually have side effects. For example, a binary + expression may cause
39613961
// 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:
39623977
case SyntaxKind.StringLiteral:
39633978
case SyntaxKind.NoSubstitutionTemplateLiteral:
39643979
case SyntaxKind.NumericLiteral:
@@ -3975,6 +3990,8 @@ module ts {
39753990
case SyntaxKind.SetAccessor:
39763991
return false;
39773992

3993+
// These constructs may or may not have side effects depending on their
3994+
// constituent children.
39783995
case SyntaxKind.ArrayBindingPattern:
39793996
case SyntaxKind.ObjectBindingPattern:
39803997
return forEach((<BindingPattern>node).elements, hasPossibleSideEffects);
@@ -3987,16 +4004,9 @@ module ts {
39874004
return hasPossibleSideEffects((<ParameterDeclaration>node).name) ||
39884005
hasPossibleSideEffects((<ParameterDeclaration>node).initializer);
39894006

3990-
case SyntaxKind.PropertyAccessExpression:
3991-
return hasPossibleSideEffects((<PropertyAccessExpression>node).expression);
3992-
39934007
case SyntaxKind.ArrayLiteralExpression:
39944008
return forEach((<ArrayLiteralExpression>node).elements, hasPossibleSideEffects);
39954009

3996-
case SyntaxKind.ElementAccessExpression:
3997-
return hasPossibleSideEffects((<ElementAccessExpression>node).expression) ||
3998-
hasPossibleSideEffects((<ElementAccessExpression>node).argumentExpression);
3999-
40004010
case SyntaxKind.ParenthesizedExpression:
40014011
return hasPossibleSideEffects((<ParenthesizedExpression>node).expression);
40024012

tests/baselines/reference/functionWithDefaultParameterWithNoStatements11.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ function bar(a = v[0]) {
88

99
//// [functionWithDefaultParameterWithNoStatements11.js]
1010
var v;
11-
function foo(a) { }
11+
function foo(a) {
12+
if (a === void 0) { a = v[0]; }
13+
}
1214
function bar(a) {
15+
if (a === void 0) { a = v[0]; }
1316
}

tests/baselines/reference/functionWithDefaultParameterWithNoStatements9.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ function bar(a = console.log) {
55
}
66

77
//// [functionWithDefaultParameterWithNoStatements9.js]
8-
function foo(a) { }
8+
function foo(a) {
9+
if (a === void 0) { a = console.log; }
10+
}
911
function bar(a) {
12+
if (a === void 0) { a = console.log; }
1013
}

0 commit comments

Comments
 (0)