Skip to content

Emit downlevel parameter initializers unless we are certain they don't have any side effects. #2109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 23, 2015

Conversation

CyrusNajmabadi
Copy link
Contributor

i.e. if you have:

function foo(a = "") { }

Then we can emit that as:

function foo(a) { }

but if you have:

function foo(a = bar()) { }

then we need to emit that as:

function foo(a) {
    if (a === void 0) { a = bar(); }
}

This also unifies some of emitting code between single line function blocks and other types of functions.

hasPossibleSideEffects((<ParameterDeclaration>node).initializer);

case SyntaxKind.PropertyAccessExpression:
return hasPossibleSideEffects((<PropertyAccessExpression>node).expression);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return true due to get accessors. Leave a comment about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch exclamation point

@DanielRosenwasser
Copy link
Member

👍

Conflicts:
	tests/baselines/reference/recursiveClassReferenceTest.js.map
CyrusNajmabadi added a commit that referenced this pull request Feb 23, 2015
Emit downlevel parameter initializers unless we are certain they don't have any side effects.
@CyrusNajmabadi CyrusNajmabadi merged commit e26de71 into master Feb 23, 2015
@CyrusNajmabadi CyrusNajmabadi deleted the sideEffects branch February 23, 2015 23:43
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants