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

fix(es/parser): emit error if await used as ident in class static ini… #8450

Merged
merged 6 commits into from
Dec 29, 2023

Conversation

iantanwx
Copy link
Contributor

@iantanwx iantanwx commented Dec 22, 2023

…tializer

Description:

This PR fixes #8374

BREAKING CHANGE:

Related issue (if exists):

#8374

@iantanwx iantanwx requested a review from a team as a code owner December 22, 2023 08:15
@CLAassistant
Copy link

CLAassistant commented Dec 22, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@magic-akari
Copy link
Member

This case should be added.

class Foo {
    static {
        function foo() {
            var await = 'bar';
        }
    }
}

@iantanwx
Copy link
Contributor Author

This case should be added.

class Foo {
    static {
        function foo() {
            var await = 'bar';
        }
    }
}

Thanks for this, I've added it.

kdy1
kdy1 previously approved these changes Dec 23, 2023
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thanks!



swc-bump:

  • swc_ecma_parser

@kdy1 kdy1 enabled auto-merge (squash) December 23, 2023 03:37
@kdy1 kdy1 added this to the Planned milestone Dec 23, 2023
@@ -2407,6 +2407,19 @@ export default function waitUntil(callback, options = {}) {
test_parser(src, Syntax::Es(Default::default()), |p| p.parse_expr());
}

#[test]
#[should_panic(expected = "Expected ident")]
Copy link
Member

Choose a reason for hiding this comment

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

No. It should not panic. It's valid JavaScript.

Copy link
Contributor Author

@iantanwx iantanwx Dec 23, 2023

Choose a reason for hiding this comment

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

@magic-akari i didn't realise 😓

fixed it, but i'm not sure if the solution accounts for all corner cases...could you take a look?

Copy link
Member

Choose a reason for hiding this comment

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

class Foo {
    static {
        var await = "bar"; // SyntaxError: Unexpected reserved word

        function foo() {
            var await = "bar"; // ok

            class Bar {
                static {
                    var await = "bar"; // SyntaxError: Unexpected reserved word
                }
            }
        }
    }
}

I recommend setting the variable in_static_block to false upon entering the function body.
Please note that I cannot guarantee that all scenarios have been considered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, your suggested solution seems much better to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@magic-akari magic-akari enabled auto-merge (squash) December 26, 2023 14:03
@magic-akari magic-akari merged commit 0b188cc into swc-project:main Dec 29, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.102 Dec 31, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Jan 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

Missing syntax error for await in class static block
5 participants