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(js_formatter): ensure comments before async keyword are placed before it #1500

Merged
merged 4 commits into from
Jan 11, 2024

Conversation

ah-yu
Copy link
Contributor

@ah-yu ah-yu commented Jan 10, 2024

Summary

Closes #1406

Ensure the comments before the async keyword are placed before it. If the following_token of the comment is async keyword then attach the comment to the preceding node

class Foo {
   @decorator()
   /* comment */async method(){}
}

// before fix
class Foo {
    @decorator()
    async /* comment */ method() {}
}

// after fix
class Foo {
    @decorator()
    /* comment */
    async method() {}
}

// prettier
class Foo {
    @decorator()
    /* comment */
    async method() {}
}

Copy link

netlify bot commented Jan 10, 2024

Deploy Preview for biomejs ready!

Name Link
🔨 Latest commit 0ccbf36
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/659fcb3134bf8500089b727c
😎 Deploy Preview https://deploy-preview-1500--biomejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 94 (🔴 down 6 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 93 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages labels Jan 10, 2024
@ah-yu ah-yu changed the title fix: attach comments before async keyworkd to decorator fix(js_formatter): Ensure comments before async keyword are placed before it Jan 10, 2024
@@ -209,7 +209,8 @@ class Foo {
@decorator /*before*/
/*after*/ method() {}
@decorator.method(value) /*before*/
async /*after*/ method() {}
/*after*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original code

	@decorator.method(value) /*before*/
	/*after*/ async method() {}

The behavior is the same as Prettier

@github-actions github-actions bot added the A-Changelog Area: changelog label Jan 10, 2024
Comment on lines +214 to +215
/*after*/
async method() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

It guess it's a regression.
Prettier playground

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the original code. It has a decorator above.

@decorator.method(value) /*before*/
/*after*/ async method() {}

biome playground

prettier playground

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, you're right(:

Copy link

codspeed-hq bot commented Jan 10, 2024

CodSpeed Performance Report

Merging #1500 will degrade performances by 7.43%

Comparing ah-yu:async_method (0ccbf36) with main (7042ef0)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 91 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main ah-yu:async_method Change
router.ts[uncached] 12.6 ms 13.6 ms -7.43%
eucjp.json[uncached] 5.5 ms 5.1 ms +6.79%

@Conaclos Conaclos changed the title fix(js_formatter): Ensure comments before async keyword are placed before it fix(js_formatter): ensure comments before async keyword are placed before it Jan 10, 2024
@@ -1244,6 +1245,32 @@ fn handle_import_export_specifier_comment(
}
}

/// Ensure that comments before the `async`` keyword are placed just before it.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generators have the same issue. I will submit another PR to fix it.

@Conaclos
Copy link
Member

Conaclos commented Jan 10, 2024

Looks good to me! We have just released a patch version. Could you rebase your branch on main?

@ah-yu
Copy link
Contributor Author

ah-yu commented Jan 11, 2024

Could you rebase your branch on main?

Done

@github-actions github-actions bot added the A-Website Area: website label Jan 11, 2024
@Conaclos Conaclos merged commit 73bced1 into biomejs:main Jan 11, 2024
17 of 18 checks passed
@ah-yu ah-yu deleted the async_method branch January 11, 2024 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Formatter Area: formatter A-Website Area: website L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📝 Formatter propose change that brokes parse with comment and async function
3 participants