Skip to content

fix: avoid parse errors in older umi builds#6

Open
zombieJ wants to merge 1 commit intomasterfrom
fix/build-parse-compat
Open

fix: avoid parse errors in older umi builds#6
zombieJ wants to merge 1 commit intomasterfrom
fix/build-parse-compat

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Mar 17, 2026

Summary

  • remove class field syntax from NumberDecimal and BigIntDecimal source so the published build output no longer contains origin = '' style class fields
  • replace optional chaining in equality checks with plain guards to avoid shipping additional modern syntax in the package output
  • keep runtime behavior unchanged while restoring compatibility for older Umi 3.x build pipelines

Testing

  • ut run lint:tsc
  • ut run compile
  • ut run test

Fixes #5

Summary by CodeRabbit

发布说明

  • 重构

    • 优化了内部API结构,将类实现转换为公共接口,提高了类型安全性。
  • Bug修复

    • 改进了相等性比较逻辑,更准确地处理边界情况。

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Walkthrough

将 BigIntDecimal 和 NumberDecimal 从导出的类重构为不导出的实现类,同时新增并导出具有相同名称的公共接口。两个文件的构造函数都初始化了 origin 属性,equals 方法也进行了相应调整。

Changes

Cohort / File(s) Summary
API 层次结构重构
src/BigIntDecimal.ts, src/NumberDecimal.ts
将类从默认导出更改为内部实现,新增同名接口作为公共 API 导出。构造函数初始化 origin 属性,equals 方法改进了 null/undefined 处理逻辑。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

兔子舞起来,接口来替代,
类藏在幕后,公共 API 闪耀,
初始化 origin,equals 更聪慧,
类型声明深,代码层次对,
🐰✨ 重构之路,清晰又明快!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确地概括了主要变更:移除现代JavaScript语法以修复与旧版Umi构建的兼容性问题。
Linked Issues check ✅ Passed 代码变更移除了类字段语法和可选链,符合问题#5中修复Umi 3.5.43兼容性的要求。
Out of Scope Changes check ✅ Passed 所有变更均针对目标:将BigIntDecimal和NumberDecimal中的现代语法替换为兼容旧版构建的等价形式。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/build-parse-compat
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting to disable sequence diagrams in the walkthrough.

@github-actions
Copy link

github-actions bot commented Mar 17, 2026

😭 Deploy PR Preview 485fd53 failed. Build logs

🤖 By surge-preview

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses compatibility issues with older Umi 3.x build pipelines by refactoring modern JavaScript syntax features, specifically class field declarations and optional chaining, into more widely supported constructs. The changes aim to produce package output that avoids parse errors in environments that do not support these newer language features, without altering the intended runtime functionality.

Highlights

  • Syntax Downgrade: Removed class field syntax from BigIntDecimal and NumberDecimal source files to ensure compatibility with older build environments.
  • Optional Chaining Replacement: Replaced optional chaining (?.) with explicit conditional checks in equality methods to avoid modern syntax in the package output.
  • Compatibility Restoration: Ensured runtime behavior remains unchanged while restoring compatibility for older Umi 3.x build pipelines.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/BigIntDecimal.ts
    • Refactored class field declarations into explicit property assignments.
    • Replaced optional chaining with a ternary operator in the equals method.
    • Modified default export to separate class definition from export statement.
  • src/NumberDecimal.ts
    • Refactored class field declarations into explicit property assignments.
    • Replaced optional chaining with a ternary operator in the equals method.
    • Modified default export to separate class definition from export statement.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the BigIntDecimal and NumberDecimal classes to remove modern JavaScript syntax like class fields and optional chaining, aiming to improve compatibility with older build systems. The changes are logical and correctly preserve the existing behavior. I've added a couple of suggestions to initialize all class properties in the constructors. This will improve type safety and robustness by ensuring that all properties have a defined value, even when the classes are instantiated with empty or invalid inputs, thus fully satisfying the contracts of their respective interfaces.


class BigIntDecimal implements DecimalClass {
constructor(value: string | number) {
this.origin = '';

Choose a reason for hiding this comment

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

medium

To ensure type safety and prevent potential runtime errors, it's best to initialize all class properties at the beginning of the constructor. The BigIntDecimal interface defines properties like negative, integer, etc., as non-optional. However, if an empty value is passed to the constructor, these properties are never initialized, leaving them as undefined, which violates the interface contract. Initializing them with default values makes the class more robust.

Suggested change
this.origin = '';
this.origin = '';
this.negative = false;
this.integer = BigInt(0);
this.decimal = BigInt(0);
this.decimalLen = 0;
this.empty = false;
this.nan = false;


class NumberDecimal implements DecimalClass {
constructor(value: ValueType) {
this.origin = '';

Choose a reason for hiding this comment

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

medium

To ensure type safety and prevent potential runtime errors, it's best to initialize all class properties at the beginning of the constructor. The NumberDecimal interface defines number and empty as non-optional properties. However, if an empty value is passed to the constructor, number is not initialized, leaving it as undefined, which violates the interface contract. Initializing all properties with default values makes the class more robust.

    this.origin = '';
    this.number = 0;
    this.empty = false;

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/NumberDecimal.ts (1)

119-123: 接口声明的属性类型与运行时实际值不完全匹配。

接口声明 number: numberempty: boolean 为必需属性,但根据构造函数逻辑:

  • value 为空时,仅设置 this.empty = truethis.number 保持 undefined
  • value 非空时,仅设置 this.numberthis.empty 保持 undefined

建议将这些属性标记为可选,以准确反映运行时行为:

♻️ 建议修改
 interface NumberDecimal {
   origin: string;
-  number: number;
-  empty: boolean;
+  number?: number;
+  empty?: boolean;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NumberDecimal.ts` around lines 119 - 123, The NumberDecimal interface's
declared types don't match runtime behavior: the constructor sometimes only sets
this.empty or this.number leaving the other undefined; update the interface
(NumberDecimal) so that number and empty are optional or allow undefined (e.g.,
make number?: number or number: number | undefined and empty?: boolean or empty:
boolean | undefined) while keeping origin as required so the type accurately
reflects the runtime state used by the constructor.
src/BigIntDecimal.ts (1)

189-198: 接口声明中多个属性应标记为可选。

根据构造函数的不同执行路径:

  • empty/nan 状态下:仅部分属性被赋值
  • 正常值状态下:emptynan 未显式赋值(保持 undefined

以下属性在运行时可能为 undefined

♻️ 建议修改以匹配运行时行为
 interface BigIntDecimal {
   origin: string;
-  negative: boolean;
-  integer: bigint;
-  decimal: bigint;
+  negative?: boolean;
+  integer?: bigint;
+  decimal?: bigint;
   /** BigInt will convert `0009` to `9`. We need record the len of decimal */
-  decimalLen: number;
-  empty: boolean;
-  nan: boolean;
+  decimalLen?: number;
+  empty?: boolean;
+  nan?: boolean;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/BigIntDecimal.ts` around lines 189 - 198, The BigIntDecimal interface
declares several properties that can be undefined at runtime; update the
interface BigIntDecimal to mark the properties that are not always assigned as
optional (add ? to negative, integer, decimal, decimalLen, empty, nan and any
other properties that can be undefined in certain constructor paths) so the type
matches runtime behavior and avoids incorrect non-null assumptions; locate the
interface BigIntDecimal to make these fields optional and then run type checks
to fix any sites that assumed them non-null.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/BigIntDecimal.ts`:
- Around line 189-198: The BigIntDecimal interface declares several properties
that can be undefined at runtime; update the interface BigIntDecimal to mark the
properties that are not always assigned as optional (add ? to negative, integer,
decimal, decimalLen, empty, nan and any other properties that can be undefined
in certain constructor paths) so the type matches runtime behavior and avoids
incorrect non-null assumptions; locate the interface BigIntDecimal to make these
fields optional and then run type checks to fix any sites that assumed them
non-null.

In `@src/NumberDecimal.ts`:
- Around line 119-123: The NumberDecimal interface's declared types don't match
runtime behavior: the constructor sometimes only sets this.empty or this.number
leaving the other undefined; update the interface (NumberDecimal) so that number
and empty are optional or allow undefined (e.g., make number?: number or number:
number | undefined and empty?: boolean or empty: boolean | undefined) while
keeping origin as required so the type accurately reflects the runtime state
used by the constructor.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aec88bd6-c373-41ea-bf49-227a6ea69752

📥 Commits

Reviewing files that changed from the base of the PR and between ebb8580 and 485fd53.

📒 Files selected for processing (2)
  • src/BigIntDecimal.ts
  • src/NumberDecimal.ts

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.17%. Comparing base (ebb8580) to head (485fd53).

Additional details and impacted files
@@           Coverage Diff           @@
##           master       #6   +/-   ##
=======================================
  Coverage   91.17%   91.17%           
=======================================
  Files           5        5           
  Lines         238      238           
  Branches       70       74    +4     
=======================================
  Hits          217      217           
  Misses         21       21           

☔ 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.

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.

umi 3.5.43 版本运行报错

1 participant