Skip to content

fix name lookup change again#28501

Closed
Kingwl wants to merge 3 commits intomicrosoft:masterfrom
Kingwl:fix_again_and_again_and_again
Closed

fix name lookup change again#28501
Kingwl wants to merge 3 commits intomicrosoft:masterfrom
Kingwl:fix_again_and_again_and_again

Conversation

@Kingwl
Copy link
Copy Markdown
Contributor

@Kingwl Kingwl commented Nov 13, 2018

Fixes #28474

@Kingwl Kingwl changed the title fix name lookup change again [WIP] fix name lookup change again Nov 13, 2018
@Kingwl
Copy link
Copy Markdown
Contributor Author

Kingwl commented Nov 13, 2018

something seems wrong, i'll fix that later

let bazzzz = 2;
function f9(bar = () => bazzzz) {
~~~~~~
!!! error TS2373: Initializer of parameter 'bar' cannot reference identifier 'bazzzz' declared after it.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this error here? It doesn't reference the inner var bazzzz (var doesn't work any different than let and const in this case). And the outer let bazzzz is definitely not declared after the parameter.

@Kingwl
Copy link
Copy Markdown
Contributor Author

Kingwl commented Nov 14, 2018

@ajafff

 function bar(func = () => foo) {
     let foo = "in";
     return func
}

to

function bar(func) {
    if (func === void 0) { func = function () { return foo; }; }
    var foo = "in";
    return func;
}

and the result is "in" on chrome

@Kingwl
Copy link
Copy Markdown
Contributor Author

Kingwl commented Nov 14, 2018

seems that is not a bug? @weswigham

@weswigham
Copy link
Copy Markdown
Member

Yeah, I'm pretty sure that error reflects the behavior of our actual down level emit rather than the spec.

@Kingwl
Copy link
Copy Markdown
Contributor Author

Kingwl commented Nov 14, 2018

🤷🏻‍♂️ awesome emit

@Kingwl Kingwl closed this Nov 14, 2018
@Kingwl Kingwl deleted the fix_again_and_again_and_again branch November 14, 2018 03:29
@Kingwl Kingwl restored the fix_again_and_again_and_again branch November 14, 2018 11:50
@Kingwl Kingwl reopened this Nov 14, 2018
@Kingwl Kingwl force-pushed the fix_again_and_again_and_again branch from 096eedf to 0f21db3 Compare November 14, 2018 12:11
@Kingwl Kingwl changed the title [WIP] fix name lookup change again fix name lookup change again Nov 14, 2018
@weswigham weswigham requested a review from rbuckton December 8, 2018 00:26
@weswigham weswigham added this to the TypeScript 3.3 milestone Dec 8, 2018
@Kingwl Kingwl closed this Feb 2, 2020
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
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.

parameter initializer wrongly references variable declared in function body

7 participants