-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(uni-mp-compiler): wxs方法支持变量作为参数 #4905
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
Conversation
|
感谢提供 PR,已在 review |
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.
Pull Request Overview
This PR fixes the issue of supporting variables as parameters in wxs methods by updating the filter transformation logic.
- Added a new code block to handle filter expressions by extracting and rewriting parameters.
- Introduced error handling for unsupported argument types in the parameter extraction.
Comments suppressed due to low confidence (1)
packages/uni-mp-compiler/src/transforms/transformIdentifier.ts:77
- Add validation to confirm that both '(' and ')' exist in contentStr before using them to extract parameters.
const paramStr = contentStr.substring(contentStr.indexOf('(') + 1, contentStr.indexOf(')'))
| } | ||
| }) | ||
| .join('') | ||
| const lhs = contentStr.substring(0, contentStr.indexOf('(')) |
Copilot
AI
May 23, 2025
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.
Ensure that contentStr contains '(' before calling substring to avoid potential index errors if the character is missing.
| const lhs = contentStr.substring(0, contentStr.indexOf('(')) | |
| const openParenIndex = contentStr.indexOf('('); | |
| if (openParenIndex === -1) { | |
| throw new Error("Expected '(' in contentStr but not found."); | |
| } | |
| const lhs = contentStr.substring(0, openParenIndex); |
| }) | ||
| .join('') | ||
| const lhs = contentStr.substring(0, contentStr.indexOf('(')) | ||
| let isLiteral = false |
Copilot
AI
May 23, 2025
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.
[nitpick] Consider adding a comment to explain the purpose of this loop and why only the first non-space character after '(' is checked.
| let isLiteral = false | |
| let isLiteral = false | |
| // Check the first non-space character after '(' to determine if it is a literal object or array. | |
| // This is used to decide how to rewrite the parameters for the function call. |
|
这个修复有点问题,不能正确处理多参数以及嵌套参数的场景,比如下面的示例 <template>
<text class="title">reacitve object: {{ wxs.formatInfo(user, wxs.formatInfo(user)) }}</text>
</template>
<script module="wxs" lang="wxs">
var formatInfo = function (info, b) {
if(!info) {
return 'dsds'
}
return '我是 ' + info.name + ", 今年 " + info.age
}
module.exports = {
formatInfo: formatInfo
}
</script>
<script>
export default {
data() {
return {
user: {
name: 'Test4',
age: '18'
}
}
}
}
</script> |
fixed: #4633