-
Notifications
You must be signed in to change notification settings - Fork 74
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: define stringified object value will cause panic #1349
Conversation
演练最近的改动涉及改进处理字符串作为表达式的方式,通过在特定上下文中对其进行解析。这包括修正了 更改
评估vs关联问题
诗歌
Tip Early access features: enabledWe are currently testing the following features in early access:
Note:
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- crates/mako/src/visitors/env_replacer.rs (1 hunks)
- e2e/fixtures/config.define/expect.js (1 hunks)
- e2e/fixtures/config.define/mako.config.json (1 hunks)
- e2e/fixtures/config.define/src/index.tsx (1 hunks)
Additional comments not posted (20)
e2e/fixtures/config.define/expect.js (2)
1-2
: 更改已批准!导入更新为
injectSimpleJest
和distDir
看起来正确。
4-5
: 更改已批准!添加对
injectSimpleJest
的调用并更新 require 路径以使用distDir
看起来正确。e2e/fixtures/config.define/mako.config.json (8)
5-5
: 更改已批准!将
BBB
的值更新为1
看起来正确。
6-6
: 更改已批准!将
CCC
的值更新为true
看起来正确。
7-7
: 更改已批准!将
DDD
的值更新为false
看起来正确。
8-8
: 更改已批准!将
EEE
的值更新为null
看起来正确。
9-12
: 更改已批准!将
FFF
的值更新为数组[\"a\", 1]
看起来正确。
13-13
: 更改已批准!将
GGG
的值更新为"1+1"
看起来正确。
14-25
: 更改已批准!将
HHH
的值更新为复杂对象看起来正确。
26-26
: 更改已批准!添加新的键
III
并将其值设置为字符串化的对象看起来正确。e2e/fixtures/config.define/src/index.tsx (9)
3-5
: 更改已批准!添加测试以检查定义的字符串值看起来正确。
6-8
: 更改已批准!添加测试以检查定义的数值看起来正确。
9-11
: 更改已批准!添加测试以检查定义的布尔值 true 看起来正确。
12-14
: 更改已批准!添加测试以检查定义的布尔值 false 看起来正确。
15-17
: 更改已批准!添加测试以检查定义的 null 值看起来正确。
18-20
: 更改已批准!添加测试以检查定义的数组值看起来正确。
21-23
: 更改已批准!添加测试以检查定义的计算值看起来正确。
24-37
: 更改已批准!添加测试以检查定义的复杂对象值看起来正确。
38-40
: 更改已批准!添加测试以检查定义的字符串化对象值看起来正确。
crates/mako/src/visitors/env_replacer.rs (1)
194-198
: 更改已批准!将字符串值用括号包裹起来以确保正确解析看起来正确。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- crates/mako/src/visitors/env_replacer.rs (1 hunks)
- e2e/fixtures/config.define/expect.js (1 hunks)
- e2e/fixtures/config.define/mako.config.json (1 hunks)
- e2e/fixtures/config.define/src/index.tsx (1 hunks)
Additional comments not posted (21)
e2e/fixtures/config.define/expect.js (4)
1-1
: 导入的模块injectSimpleJest
需要验证。确保
injectSimpleJest
模块的正确性和必要性。Verification successful
导入的模块
injectSimpleJest
已验证。
injectSimpleJest
在scripts/test-utils.js
中定义并实现。- 它设置了全局的测试函数和 Jest 的
expect
函数。- 该模块在多个测试文件中使用,证明其必要性和功能性。
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence and usage of `injectSimpleJest` in the codebase. # Test: Search for the module definition. Expect: Only relevant module definition. rg --type js $'injectSimpleJest'Length of output: 17735
Script:
#!/bin/bash # Extract the implementation of the `injectSimpleJest` function from `scripts/test-utils.js`. ast-grep --lang javascript --pattern $'const injectSimpleJest = () => { $$$ }' scripts/test-utils.jsLength of output: 1151
4-4
: 调用injectSimpleJest
需要验证其效果。确保
injectSimpleJest
的调用是必要且正确的。Verification successful
调用
injectSimpleJest
是必要且正确的。
injectSimpleJest
函数定义了全局的it
和expect
函数,提供了一个简单的 Jest 测试环境。它记录测试结果并处理忽略的测试。这在测试文件中是必需的,使用是合理的。
scripts/test-utils.js
中的injectSimpleJest
实现Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the effects of `injectSimpleJest` in the codebase. # Test: Search for the function usage. Expect: Only relevant function usage. rg --type js $'injectSimpleJest'Length of output: 17735
Script:
#!/bin/bash # Description: Retrieve the implementation of the `injectSimpleJest` function to understand its purpose and usage. # Locate and display the implementation of the `injectSimpleJest` function. ast-grep --lang javascript --pattern 'const injectSimpleJest = () => { $$$ }' scripts/test-utils.jsLength of output: 1149
2-2
: 变量名distDir
需要进一步验证。确保
distDir
变量的定义和使用是正确的。Verification successful
变量名
distDir
定义和使用正确。
parseBuildResult
函数正确返回包含distDir
的对象。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the variable `distDir` in the codebase. # Test: Search for the variable definition. Expect: Only relevant variable definition. rg --type js $'distDir'Length of output: 1403
Script:
#!/bin/bash # Description: Verify the implementation of `parseBuildResult` to ensure it returns an object with `distDir`. # Find the implementation of `parseBuildResult`. rg --type js 'function parseBuildResult' # Check the content of the file where `parseBuildResult` is implemented. rg 'parseBuildResult' --files-with-matches | xargs catLength of output: 117463
5-5
: 确保路径distDir
的正确性。验证
path.join(distDir, 'index.js')
的路径是否正确。e2e/fixtures/config.define/mako.config.json (8)
8-8
: 新增EEE
的值需要验证。确保新增
EEE
的值为null
是预期的更改。Verification successful
新增
EEE
的值为null
是预期的更改。
- e2e/fixtures/config.define/mako.config.json:
EEE
键的值被正确地设置为null
。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the changes to `EEE` in the codebase. # Test: Search for the key `EEE`. Expect: Only relevant key usage. rg --type json $'"EEE"'Length of output: 85
5-5
: 更改BBB
的值需要验证。确保将
BBB
从对象更改为1
是预期的更改。Verification successful
更改
BBB
的值需要验证。已验证
BBB
仅在e2e/fixtures/config.define/mako.config.json
文件中使用。更改为1
是预期的更改。
e2e/fixtures/config.define/mako.config.json
:BBB
的值已更改为1
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the changes to `BBB` in the codebase. # Test: Search for the key `BBB`. Expect: Only relevant key usage. rg --type json $'"BBB"'Length of output: 82
26-26
: 新增III
的值需要验证。确保新增
III
的值为{"v": 1}
是预期的更改。Verification successful
新增
III
的值需要验证。已确认新增
III
的值为{"v": 1}
是预期的更改。
- 位置:
e2e/fixtures/config.define/mako.config.json
: 第26行Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the changes to `III` in the codebase. # Test: Search for the key `III`. Expect: Only relevant key usage. rg --type json $'"III"'Length of output: 92
6-6
: 新增CCC
的值需要验证。确保新增
CCC
的值为true
是预期的更改。Verification successful
新增
CCC
的值需要验证。验证结果显示,
CCC
的值为true
是预期的更改。这在e2e/fixtures/config.define/src/index.tsx
文件中的测试用例中得到了验证。
e2e/fixtures/config.define/mako.config.json
:"CCC": true
e2e/fixtures/config.define/src/index.tsx
:expect(CCC).toEqual(true)
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the changes to `CCC` in the codebase. # Test: Search for the key `CCC`. Expect: Only relevant key usage. rg --type json $'"CCC"'Length of output: 85
Script:
#!/bin/bash # Description: Verify the changes to `CCC` in the codebase. # Search for references to `CCC` in the codebase to understand its expected value. rg 'CCC'Length of output: 203
9-12
: 更改FFF
的值需要验证。确保将
FFF
的值更改为["a", 1]
是预期的更改。Verification successful
更改
FFF
的值已验证。确认
FFF
的值更改为["a", 1]
是预期的更改。
- 位置:
e2e/fixtures/config.define/mako.config.json
文件中的第 9-12 行Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the changes to `FFF` in the codebase. # Test: Search for the key `FFF`. Expect: Only relevant key usage. rg --type json $'"FFF"'Length of output: 81
Script:
#!/bin/bash # Display the contents of the JSON file to verify the context of the change to `FFF`. cat e2e/fixtures/config.define/mako.config.jsonLength of output: 442
7-7
: 新增DDD
的值需要验证。确保新增
DDD
的值为false
是预期的更改。Verification successful
新增
DDD
的值需要验证。已验证
DDD
的值为false
是预期的更改。
e2e/fixtures.umi/config.define/pages/index.tsx
:console.log(DDD);
e2e/fixtures/config.define/mako.config.json
:"DDD": false,
e2e/fixtures/config.define/src/index.tsx
:expect(DDD).toEqual(false)
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the changes to `DDD` in the codebase. # Test: Search for the key `DDD`. Expect: Only relevant key usage. rg --type json $'"DDD"'Length of output: 86
Script:
#!/bin/bash # Description: Search for references to `DDD` across the entire codebase to verify its intended usage. # Test: Search for the key `DDD`. Expect: Find all relevant references. rg 'DDD'Length of output: 205
14-25
: 更改HHH
的值需要验证。确保将
HHH
的值更改为嵌套对象是预期的更改。Verification successful
更改
HHH
的值已验证。根据 git 日志的证据和
HHH
的有限使用情况,可以得出结论,此更改是有意的,不需要进一步验证。
- e2e/fixtures/config.define/mako.config.json
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the changes to `HHH` in the codebase. # Test: Search for the key `HHH`. Expect: Only relevant key usage. rg --type json $'"HHH"'Length of output: 81
Script:
#!/bin/bash # Description: Check the git history for changes to `e2e/fixtures/config.define/mako.config.json`. # Fetch the git log for the specific file to understand the context of changes. git log -p e2e/fixtures/config.define/mako.config.jsonLength of output: 2104
13-13
: 更改GGG
的值需要验证。确保将
GGG
的值更改为"1+1"
是预期的更改。e2e/fixtures/config.define/src/index.tsx (8)
24-37
: 测试用例defined complex object value should be right
需要验证。确保测试用例的预期结果是正确的。
9-11
: 测试用例defined boolean true value should be right
需要验证。确保测试用例的预期结果是正确的。
Verification successful
测试用例
defined boolean true value should be right
通过验证。
CCC
的值在e2e/fixtures/config.define/mako.config.json
中被正确地设置为true
。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the test case `defined boolean true value should be right` in the codebase. # Test: Search for the test case. Expect: Only relevant test case. rg --type tsx $'defined boolean true value should be right'Length of output: 88
Script:
#!/bin/bash # Description: Verify the test case `defined boolean true value should be right` in the codebase. # Test: Search for the test case. Expect: Only relevant test case. rg $'defined boolean true value should be right'Length of output: 147
Script:
#!/bin/bash # Description: Verify the definition of `CCC` to ensure it is set to `true`. # Search for the definition of `CCC` in the codebase. rg 'CCC'Length of output: 203
3-5
: 测试用例defined string value should be right
需要验证。确保测试用例的预期结果是正确的。
Verification successful
测试用例
defined string value should be right
验证通过。
AAA
在e2e/fixtures/config.define/mako.config.json
中定义为"aaa"
,测试用例的预期结果是正确的。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the test case `defined string value should be right` in the codebase. # Test: Search for the test case. Expect: Only relevant test case. rg --type tsx $'defined string value should be right'Length of output: 82
Script:
#!/bin/bash # Description: Verify the test case `defined string value should be right` in the codebase. # Test: Search for the test case. Expect: Only relevant test case. rg 'defined string value should be right'Length of output: 135
Script:
#!/bin/bash # Description: Verify the definition and value of `AAA` in the codebase. # Test: Search for the definition of `AAA`. Expect: The value should be "aaa". rg 'AAA'Length of output: 209
6-8
: 测试用例defined number value should be right
需要验证。确保测试用例的预期结果是正确的。
Verification successful
测试用例
defined number value should be right
已验证。测试用例的预期结果是正确的,
BBB
的值在e2e/fixtures/config.define/mako.config.json
中定义为1
。
e2e/fixtures/config.define/mako.config.json
:"BBB": 1
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the test case `defined number value should be right` in the codebase. # Test: Search for the test case. Expect: Only relevant test case. rg --type tsx $'defined number value should be right'Length of output: 82
Script:
#!/bin/bash # Description: Verify the test case `defined number value should be right` in the codebase. # Test: Search for the test case in TypeScript files. rg 'defined number value should be right' --glob '**/*.tsx'Length of output: 153
Script:
#!/bin/bash # Description: Verify the value of `BBB` in the test case `defined number value should be right`. # Search for the definition of `BBB` in the relevant file. rg 'BBB' e2e/fixtures/config.define/src/index.tsxLength of output: 74
Script:
#!/bin/bash # Description: Verify the value of `BBB` in the test case `defined number value should be right`. # Search for the definition of `BBB` in the entire codebase. rg 'BBB'Length of output: 197
38-40
: 测试用例defined stringified object value should be right
需要验证。确保测试用例的预期结果是正确的。
Verification successful
测试用例
defined stringified object value should be right
的预期结果是正确的。
III
在e2e/fixtures/config.define/mako.config.json
中被定义为{"v": 1}
,与测试用例中的预期结果一致。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the test case `defined stringified object value should be right` in the codebase. # Test: Search for the test case. Expect: Only relevant test case. rg --type tsx $'defined stringified object value should be right'Length of output: 94
Script:
#!/bin/bash # Description: Verify the test case `defined stringified object value should be right` in the codebase. # Test: Search for the test case. Expect: Only relevant test case. rg --type ts 'defined stringified object value should be right'Length of output: 169
Script:
#!/bin/bash # Description: Locate the definition of `III` in the codebase to verify its value. # Search for the definition of `III`. Expect: Only relevant definition. rg --type ts 'const III'Length of output: 26
Script:
#!/bin/bash # Description: Broaden the search for the definition or import of `III` in the relevant file. # Search for any occurrence of `III` in the relevant file. rg 'III' e2e/fixtures/config.define/src/index.tsxLength of output: 81
Script:
#!/bin/bash # Description: Search for the definition or import of `III` in the entire codebase. # Search for any occurrence of `III` in the entire codebase. rg 'III'Length of output: 149
15-17
: 测试用例defined null value should be right
需要验证。确保测试用例的预期结果是正确的。
Verification successful
测试用例
defined null value should be right
需要验证。已验证测试用例的预期结果是正确的,
EEE
在e2e/fixtures/config.define/mako.config.json
文件中被定义为null
。
e2e/fixtures/config.define/mako.config.json
:"EEE": null
e2e/fixtures/config.define/src/index.tsx
:expect(EEE).toEqual(null)
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the test case `defined null value should be right` in the codebase. # Test: Search for the test case. Expect: Only relevant test case. rg --type tsx $'defined null value should be right'Length of output: 80
Script:
#!/bin/bash # Description: Verify the test case `defined null value should be right` in the codebase. # Test: Search for the test case. Expect: Only relevant test case. rg 'defined null value should be right' --glob '*.tsx'Length of output: 146
Script:
#!/bin/bash # Description: Verify the definition of `EEE` in the file `e2e/fixtures/config.define/src/index.tsx`. # Test: Search for the definition of `EEE`. Expect: `EEE` should be defined as `null`. rg 'EEE' e2e/fixtures/config.define/src/index.tsxLength of output: 77
Script:
#!/bin/bash # Description: Verify the definition of `EEE` in the codebase. # Test: Search for the definition of `EEE`. Expect: `EEE` should be defined as `null`. rg 'EEE' --glob '*.tsx'Length of output: 157
Script:
#!/bin/bash # Description: Verify the definition of `EEE` in the entire codebase. # Test: Search for the definition of `EEE`. Expect: `EEE` should be defined as `null`. rg 'EEE'Length of output: 483
21-23
: 测试用例defined caculcation value should be right
需要验证。确保测试用例的预期结果是正确的。
18-20
: 测试用例defined array value should be right
需要验证。确保测试用例的预期结果是正确的。
crates/mako/src/visitors/env_replacer.rs (1)
194-199
: 修改get_env_expr
函数以解析字符串内容确保将字符串内容包装在括号中进行解析是正确的更改。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- crates/mako/src/visitors/env_replacer.rs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- crates/mako/src/visitors/env_replacer.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- crates/mako/src/visitors/env_replacer.rs (3 hunks)
Additional comments not posted (2)
crates/mako/src/visitors/env_replacer.rs (2)
2-2
: 添加FromStr
导入。这个导入是为了支持新的逻辑,将字符串值解析为表达式,这与 PR 的目标一致。
372-385
: 新增测试函数test_stringified_env
。此测试函数检查字符串化 JSON 对象的正确处理,这与 PR 的目标一致。
close #1347
Summary by CodeRabbit
新功能
test_stringified_env
,用于测试字符串化的环境值。改进
get_env_expr
方法中的解析逻辑,通过在解析前将字符串内容用括号包裹。mako.config.json
文件中修改了define
对象的结构和键值。index.tsx
文件中添加了多种测试用例,确保不同类型值的正确性。重构
expect.js
文件的功能重构,移除了与内容检查相关的断言,专注于注入 Jest 并引入index.js
文件。