Skip to content

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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

zhylmzr
Copy link

@zhylmzr zhylmzr commented May 15, 2024

fixed: #4633

@Otto-J Otto-J self-requested a review March 26, 2025 03:17
@Otto-J
Copy link
Member

Otto-J commented Mar 27, 2025

感谢提供 PR,已在 review

@Otto-J Otto-J requested a review from Copilot May 23, 2025 11:40
Copy link

@Copilot Copilot AI left a 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('('))
Copy link
Preview

Copilot AI May 23, 2025

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.

})
.join('')
const lhs = contentStr.substring(0, contentStr.indexOf('('))
let isLiteral = false
Copy link
Preview

Copilot AI May 23, 2025

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.

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.

vue3 项目中微信小程序调用 wxs 方法无法传入响应式变量作为参数
2 participants