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

Issue with block-scoped declarations #306

Closed
mk0x9 opened this issue Jan 14, 2016 · 9 comments
Closed

Issue with block-scoped declarations #306

mk0x9 opened this issue Jan 14, 2016 · 9 comments

Comments

@mk0x9
Copy link

mk0x9 commented Jan 14, 2016

With the following code:

if (true) {
    const a = 1;
} else {
    const a = 2;
}

js2-mode declares error on the second declaration of a with TypeError: redeclaration of const a.

@dgutov
Copy link
Collaborator

dgutov commented Mar 5, 2016

Thanks for the report. Any other examples where we don't create new block scope, that we should know about?

@mk0x9
Copy link
Author

mk0x9 commented Mar 23, 2016

Re-declaring const or let within same block should throw exception IIRC.

@dgutov
Copy link
Collaborator

dgutov commented Mar 23, 2016

Sorry, what?

I'm asking for other similar examples where we shouldn't throw an error on seeing a declaration, but we do.

@mk0x9
Copy link
Author

mk0x9 commented Mar 23, 2016

My bad. Another one:

const a = 1;
{
    const a = 2;
}

@dgutov
Copy link
Collaborator

dgutov commented Mar 23, 2016

Thanks.

@Yonezawa-T2
Copy link

Other examples with ES2015 section numbers:

function foo() {
    if (aaa) {
        const a = 1;
    }

    // 13.2.13
    {
        const a = 1;
    }

    // 13.7.4.7, 13.2.13
    for (const a = 0; a < 10; a++) {
        const a = 1;
    }

    // 13.7.5.12, 13.2.13
    for (const a in aaa) {
        const a = 1;
    }

    // 13.7.5.12, 13.2.13
    for (const a of aaa) {
        const a = 1;
    }

    // 13.12.11
    switch (aaa) {
    case 0:
        const a = 1;
    }

    // 13.15.7
    try {
    } catch (e) {
        const a = 1;
    }
}

@dgutov
Copy link
Collaborator

dgutov commented Jun 20, 2016

Hey @jacksonrayhamilton,

You had fixed the examples above before, but only with use strict. Do you remember why?

Firefox doesn't seem to mind (most of) them even without use strict.

@jacksonrayhamilton
Copy link
Contributor

At some point in time I believed that const wasn't block-scoped in non-strict mode. Later I could find no evidence of that in the spec. I think it should always be block-scoped, despite strictness.

@dgutov dgutov closed this as completed in 66fe8de Jun 21, 2016
@dgutov
Copy link
Collaborator

dgutov commented Jun 21, 2016

Thanks everyone, this seems to fix all the examples above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants