Skip to content
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

usage: fix special handling of parameter initializer #40

Closed
ajafff opened this issue Mar 21, 2018 · 5 comments
Closed

usage: fix special handling of parameter initializer #40

ajafff opened this issue Mar 21, 2018 · 5 comments
Labels

Comments

@ajafff
Copy link
Owner

ajafff commented Mar 21, 2018

let foo; // this `foo` is unused
(bar = () => foo, foo) => bar;

Currently the foo parameter is marked as unused. Actually the outer variable foo is unused.

@ajafff ajafff added the bug label Mar 21, 2018
@ajafff
Copy link
Owner Author

ajafff commented Mar 21, 2018

Turns out to be a bug in newer versions of TypeScript: microsoft/TypeScript#22769

@ajafff ajafff closed this as completed Mar 21, 2018
@ajafff
Copy link
Owner Author

ajafff commented Mar 21, 2018

Actually the above example is handled correctly by the compiler, but has a bug in this library:

let foo;
(bar = () => foo, foo) => bar; // initializer uses parameter `foo`

(bar = foo) => { // initializer uses outer variable `foo`
    var foo = 1;
}

@ajafff ajafff reopened this Mar 21, 2018
@ajafff ajafff changed the title usage: remove special handling of parameter initializer usage: fix special handling of parameter initializer Mar 22, 2018
@ajafff
Copy link
Owner Author

ajafff commented Mar 22, 2018

make sure the following still works correctly:

declare let foo: number;
function fn(bar: typeof foo) { // refers to the inner `foo`
    var foo = '';
}

@ajafff
Copy link
Owner Author

ajafff commented Mar 23, 2018

also make sure this weird clusterfuck either works as expected or is fixed upstream: microsoft/TypeScript#22825

@ajafff
Copy link
Owner Author

ajafff commented Apr 1, 2018

Another case:

let foo = 1;
(function({bar = foo}) {
  var foo = 2; // unused
  return bar; // returns 1
})({});

@ajafff ajafff closed this as completed in a3550cd Apr 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant