Skip to content

Conversation

@CPunisher
Copy link
Member

@CPunisher CPunisher commented Jun 5, 2025

Description:

Use regress because it is compatible with EcmaScript Syntax. So the users can easily migrate from terser.

I will also update the docs.

Related issue (if exists):

closes: #9674

@CPunisher CPunisher requested review from a team as code owners June 5, 2025 15:37
@kdy1
Copy link
Member

kdy1 commented Jun 5, 2025

We are supporting regex in some places with rust syntax, so I'm not sure if it's fine to mix regex. Should we adjust CachedRegex to have two variants like { regex: "rust regex" } | { jsRegex: "js regex" }? I'm not sure about the naming, though.

@kdy1
Copy link
Member

kdy1 commented Jun 5, 2025

At the time of introducing regex to SWC config for the first, there was no good ECMAScript regex crate...
I think we need to do SWC v2 soon, if possible, to clean up APIs, though.

@CPunisher
Copy link
Member Author

Should we adjust CachedRegex

CachedRegex is serialized into strings or is deserialized from strings. To keep the compatibility, if we rewrite it to a enum, we may still serialize the RustRegex variant to a string and serialize the JsRegex to something like { regex: string }.

However, after checking the codebase, it seems that most CachedRegexs are not user-defined but we directly use them in rust. One exception is preserve_comments in html minifier.

🤔 So I'm not sure whether it's necessary to adjust CachedRegex.

@kdy1
Copy link
Member

kdy1 commented Jun 6, 2025

Oh. Then let’s just use js regex, but with something like CachedJsRegex (if the js regex crate supports compiling regex)

@changeset-bot
Copy link

changeset-bot bot commented Jun 6, 2025

⚠️ No Changeset found

Latest commit: a06f5ad

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codspeed-hq
Copy link

codspeed-hq bot commented Jun 6, 2025

CodSpeed Performance Report

Merging #10571 will not alter performance

Comparing CPunisher:06-04-feat/preserve-comments-regex (a06f5ad) with main (e6d4da2)

Summary

✅ 144 untouched benchmarks

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.

Thank you!

@kdy1 kdy1 added this to the Planned milestone Jun 6, 2025
@kdy1 kdy1 changed the title feat(es/minifier): Regex support for format.comments feat(es/minifier): Regex support for format.comments Jun 6, 2025
@kdy1 kdy1 merged commit e441df5 into swc-project:main Jun 6, 2025
167 checks passed
@kdy1 kdy1 modified the milestones: Planned, v1.12.0 Jun 10, 2025
@swc-project swc-project locked as resolved and limited conversation to collaborators Jul 11, 2025
@CPunisher CPunisher deleted the 06-04-feat/preserve-comments-regex branch September 4, 2025 08:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Regex support for format.comments of minifier

2 participants