Skip to content

Conversation

@sevenryze
Copy link
Contributor

@sevenryze sevenryze commented Sep 7, 2025

To modify the "1" matched in the regular expression to match all integers and decimals in Infinite issue #695

The original regex is designed to match patterns like calc(infinity * 1px) or calc(infinity * 1rpx).

When using a custom design width (e.g., 390 design units), Taro automatically calculates the ratio relative to the standard mini-program design width of 750. This results in formats like calc(infinite * 1.91rpx). However, the original regular expression can only handle scenarios with the 750 design width, causing the rounded-full replacement to fail.

It is now proposed to modify the regex to match all numeric cases, thereby expanding the range of applicable scenarios.

  • (\d+\.?\d*|\.\d+) is used to match integers or decimals:
  • \d+\.?\d* : Matches integers with one or more digits, which can be followed by a decimal point and zero or more decimal digits (e.g., 1, 1., 1.2).
  • |\.\d+ : Alternatively, matches pure decimals starting with a decimal point (e.g., .5).

This regular expression can match the following formats:

  • calc(infinity * 5px)
  • calc(infinity * 3.14rpx)
  • calc(infinity * .6px)
  • calc(infinity * 100.px)

Sourcery 摘要

增强:

  • 更新正则表达式以使用 (\d+.?\d*|.\d+) 来匹配 calc(infinity * …px/rpx) 中的所有整数和十进制值。
Original summary in English

Summary by Sourcery

Enhancements:

  • Update regex to use (\d+.?\d*|.\d+) for matching all integer and decimal values in calc(infinity * …px/rpx).

…gers and decimals in Infinite issue

The original regex is designed to match patterns like calc(infinity * 1px) or calc(infinity * 1rpx). 

When using a custom design width (e.g., 390 design units), Taro automatically calculates the ratio relative to the standard mini-program design width of 750. This results in formats like calc(infinite * 1.91rpx). However, the original regular expression can only handle scenarios with the 750 design width, causing the rounded-full replacement to fail. 

It is now proposed to modify the regex to match all numeric cases, thereby expanding the range of applicable scenarios.
* (\d+\.?\d*|\.\d+) is used to match integers or decimals:
* \d+\.?\d* : Matches integers with one or more digits, which can be followed by a decimal point and zero or more decimal digits (e.g., 1, 1., 1.2).
* |\.\d+ : Alternatively, matches pure decimals starting with a decimal point (e.g., .5).

This regular expression can match the following formats:
* calc(infinity * 5px)
* calc(infinity * 3.14rpx)
* calc(infinity * .6px)
* calc(infinity * 100.px)
@changeset-bot
Copy link

changeset-bot bot commented Sep 7, 2025

⚠️ No Changeset found

Latest commit: 07a4b58

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 7, 2025

评审员指南 (在小型 PR 上折叠)

评审员指南

更新了 CSS 后处理插件中的正则表达式,以匹配 calc(infinity * …px/rpx) 中任意整数或小数乘数,而非固定的“1”,从而正确处理自定义设计宽度。

postcssWeappTailwindcssPostPlugin 中更新的正则表达式处理的类图

classDiagram
class postcssWeappTailwindcssPostPlugin {
  +processDeclaration(decl)
}
class Declaration {
  +value: string
}
postcssWeappTailwindcssPostPlugin --> Declaration: processes

%% Highlight the updated regex usage
class postcssWeappTailwindcssPostPlugin {
  +if value matches /calc(\s*infinity\s*\*\s*(\d+\.?\d*|\.\d+)r?px/)
  +set value = "9999px"
}
Loading

更新的 CSS 值替换逻辑流程图

flowchart TD
    A["CSS Declaration with value"] --> B["Check if value matches /calc(\s*infinity\s*\*\s*(\d+\.?\d*|\.\d+)r?px/)" ]
    B -- Yes --> C["Replace value with '9999px'"]
    B -- No --> D["Leave value unchanged"]
Loading

文件级更改

更改 详情 文件
扩展正则表达式以匹配所有数值乘数
  • 将固定的“1”字面量替换为数字捕获组
  • 添加交替以支持整数和小数格式
  • 保持 px 单位可选的“r”前缀
packages/postcss/src/plugins/post.ts

可能相关的问题


提示和命令

与 Sourcery 互动

  • 触发新评审: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的评审评论。
  • 从评审评论生成 GitHub Issue: 回复 Sourcery 的评审评论,要求其创建 Issue。您也可以回复评审评论并输入 @sourcery-ai issue 来创建 Issue。
  • 生成拉取请求标题: 随时在拉取请求标题的任意位置写入 @sourcery-ai 即可生成标题。您也可以在拉取请求中评论 @sourcery-ai title 来随时(重新)生成标题。
  • 生成拉取请求摘要: 随时在拉取请求正文的任意位置写入 @sourcery-ai summary 即可在您想要的位置生成 PR 摘要。您也可以在拉取请求中评论 @sourcery-ai summary 来随时(重新)生成摘要。
  • 生成评审员指南: 在拉取请求中评论 @sourcery-ai guide 来随时(重新)生成评审员指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve 来解决所有 Sourcery 评论。如果您已经处理了所有评论并且不想再看到它们,这会很有用。
  • 关闭所有 Sourcery 评审: 在拉取请求中评论 @sourcery-ai dismiss 来关闭所有现有 Sourcery 评审。如果您想重新开始一个新评审,这特别有用——别忘了评论 @sourcery-ai review 来触发新评审!

自定义您的体验

访问您的 仪表板 以:

  • 启用或禁用评审功能,例如 Sourcery 生成的拉取请求摘要、评审员指南等。
  • 更改评审语言。
  • 添加、删除或编辑自定义评审说明。
  • 调整其他评审设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updated the regex in the CSS post-processing plugin to match any integer or decimal multiplier in calc(infinity * …px/rpx) instead of a fixed “1”, allowing proper handling of custom design widths.

Class diagram for updated regex handling in postcssWeappTailwindcssPostPlugin

classDiagram
class postcssWeappTailwindcssPostPlugin {
  +processDeclaration(decl)
}
class Declaration {
  +value: string
}
postcssWeappTailwindcssPostPlugin --> Declaration: processes

%% Highlight the updated regex usage
class postcssWeappTailwindcssPostPlugin {
  +if value matches /calc(\s*infinity\s*\*\s*(\d+\.?\d*|\.\d+)r?px/)
  +set value = "9999px"
}
Loading

Flow diagram for updated CSS value replacement logic

flowchart TD
    A["CSS Declaration with value"] --> B["Check if value matches /calc(\s*infinity\s*\*\s*(\d+\.?\d*|\.\d+)r?px/)" ]
    B -- Yes --> C["Replace value with '9999px'"]
    B -- No --> D["Leave value unchanged"]
Loading

File-Level Changes

Change Details Files
Expand regex to match all numerical multipliers
  • Replace fixed “1” literal with a numeric capture group
  • Add alternation to support both integer and decimal formats
  • Maintain optional “r” prefix on the px unit
packages/postcss/src/plugins/post.ts

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@netlify
Copy link

netlify bot commented Sep 7, 2025

Deploy Preview for ice-tw canceled.

Name Link
🔨 Latest commit 07a4b58
🔍 Latest deploy log https://app.netlify.com/projects/ice-tw/deploys/68bd030ba48f1e000825c4ed

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 7, 2025

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

你好 - 我已经审查了你的更改,它们看起来很棒!


Sourcery 对开源免费 - 如果你喜欢我们的评论,请考虑分享它们 ✨
请帮助我更有用!请在每条评论上点击 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Sep 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.62%. Comparing base (8e946d8) to head (07a4b58).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #697   +/-   ##
=======================================
  Coverage   90.62%   90.62%           
=======================================
  Files          75       75           
  Lines        5695     5695           
  Branches      664      672    +8     
=======================================
  Hits         5161     5161           
  Misses        534      534           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonofmagic sonofmagic self-assigned this Sep 7, 2025
@sonofmagic sonofmagic merged commit f8565c1 into sonofmagic:main Sep 7, 2025
20 of 26 checks passed
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

Successfully merging this pull request may close these issues.

2 participants