Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/native_binding/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/binding",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Node binding for taro",
"main": "binding.js",
"typings": "binding.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-darwin-arm64",
"description": "Native binding for taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-darwin-x64",
"description": "Native binding for taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-linux-arm64-gnu",
"description": "Native binding for taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-linux-x64-gnu",
"description": "Native binding for taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/binding-linux-x64-musl",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-win32-x64-msvc",
"description": "Native binding for taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "开放式跨端跨框架开发解决方案",
"homepage": "https://github.com/NervJS/taro#readme",
"author": "O2Team",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-react-jsx-to-rn-stylesheet",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Transform stylesheet selector to style in JSX Elements.",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-solid-jsx/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "babel-plugin-transform-solid-jsx",
"description": "A JSX to DOM plugin that wraps expressions for fine grained change detection",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-taroapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-taroapi",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"author": "O2Team",
"license": "MIT",
"main": "dist/index.js",
Expand Down
85 changes: 79 additions & 6 deletions packages/babel-plugin-transform-taroapi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ const plugin = function (babel: typeof BabelCore): BabelCore.PluginObj<IState> {
ariaValuetext: 'aria-valuetext',
}

function stripTSCast (node: any): any {
while (
t.isTSAsExpression(node) ||
t.isTSTypeAssertion(node) ||
t.isTSNonNullExpression(node) ||
(t.isTSSatisfiesExpression && t.isTSSatisfiesExpression(node))
) {
node = node.expression
}
return node
}

// 这些变量需要在每个 program 里重置
const invokedApis: Map<string, string> = new Map()
let taroName: string
Expand Down Expand Up @@ -105,10 +117,41 @@ const plugin = function (babel: typeof BabelCore): BabelCore.PluginObj<IState> {
}
})
},
MemberExpression (ast: BabelCore.NodePath<any>) {
'MemberExpression|OptionalMemberExpression' (ast: BabelCore.NodePath<any>) {
const node = ast.node

// 处理两层命名空间属性访问:Taro.xx.yy / Taro?.xx?.yy(非调用场景)
// 调用场景由 CallExpression|OptionalCallExpression 负责
const isCalleeOfCall = (t.isCallExpression(ast.parent) || t.isOptionalCallExpression(ast.parent)) && (ast.parent as any).callee === node
if (!isCalleeOfCall) {
const innerObj = stripTSCast(node.object)
if (t.isMemberExpression(innerObj) || t.isOptionalMemberExpression(innerObj)) {
const isTaroNamespace = t.isIdentifier(innerObj.object, { name: taroName })
if (isTaroNamespace) {
const namespaceName = t.isIdentifier(innerObj.property) ? innerObj.property.name : (t.isStringLiteral(innerObj.property) ? innerObj.property.value : null)
const methodName = t.isIdentifier(node.property) ? node.property.name : (t.isStringLiteral(node.property) ? node.property.value : null)
if (namespaceName && methodName) {
const flatName = `${namespaceName}_${methodName}`
if (this.apis.has(flatName)) {
let identifier: BabelCore.types.Identifier
if (invokedApis.has(flatName)) {
identifier = t.identifier(invokedApis.get(flatName)!)
} else {
const newName = ast.scope.generateUid(flatName)
invokedApis.set(flatName, newName)
identifier = t.identifier(newName)
}
ast.replaceWith(identifier as any)
return
}
}
}
}
}
Comment on lines +125 to +150

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's find and examine the target file
find . -type f -name "index.ts" -path "*/babel-plugin-transform-taroapi/src/*" | head -5

Repository: NervJS/taro

Length of output: 109


🏁 Script executed:

# Read the file to see the context around lines 125-150 and 171
cat -n packages/babel-plugin-transform-taroapi/src/index.ts | sed -n '100,200p'

Repository: NervJS/taro

Length of output: 5262


🏁 Script executed:

# Get the total line count to ensure we're looking at the right file
wc -l packages/babel-plugin-transform-taroapi/src/index.ts

Repository: NervJS/taro

Length of output: 111


🏁 Script executed:

# Check the exact context around line 171 to understand the assignment protection pattern
cat -n packages/babel-plugin-transform-taroapi/src/index.ts | sed -n '168,185p'

Repository: NervJS/taro

Length of output: 966


🏁 Script executed:

# Search for other assignment-related checks in the file
rg -n "isAssignment|AssignmentExpression" packages/babel-plugin-transform-taroapi/src/index.ts

Repository: NervJS/taro

Length of output: 273


🏁 Script executed:

# Let's check what happens in the CallExpression handler to see if there's additional protection there
cat -n packages/babel-plugin-transform-taroapi/src/index.ts | sed -n '189,230p'

Repository: NervJS/taro

Length of output: 2456


🏁 Script executed:

# Check if there's any parent checking for the first MemberExpression handler (lines 125-150)
cat -n packages/babel-plugin-transform-taroapi/src/index.ts | sed -n '120,155p'

Repository: NervJS/taro

Length of output: 2200


缺少赋值左值保护,会产生非法重写

第 126-145 行的处理逻辑缺少对赋值表达式左值的保护。当源码为 Taro.xx.yy = fn 时,会被错误地改写为 imported_id = fn,造成语法错误或运行时异常。第 171 行已有对单层命名空间 Taro.xxx 的正确保护,应对嵌套命名空间采用一致的防护措施。

建议在第 126 行添加 isAssignmentLHS 检查,参考如下:

🔧 建议修复
       'MemberExpression|OptionalMemberExpression' (ast: BabelCore.NodePath<any>) {
         const node = ast.node

         // 处理两层命名空间属性访问:Taro.xx.yy / Taro?.xx?.yy(非调用场景)
         // 调用场景由 CallExpression|OptionalCallExpression 负责
         const isCalleeOfCall = (t.isCallExpression(ast.parent) || t.isOptionalCallExpression(ast.parent)) && (ast.parent as any).callee === node
-        if (!isCalleeOfCall) {
+        const isAssignmentLHS = t.isAssignmentExpression(ast.parent) && ast.parent.left === node
+        if (!isCalleeOfCall && !isAssignmentLHS) {
           const innerObj = stripTSCast(node.object)
           if (t.isMemberExpression(innerObj) || t.isOptionalMemberExpression(innerObj)) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/babel-plugin-transform-taroapi/src/index.ts` around lines 125 - 150,
The current transformation in the block that computes isCalleeOfCall and then
rewrites nested namespace member expressions (using stripTSCast, invokedApis,
this.apis and ast.replaceWith) lacks protection against being the left-hand side
of an assignment, so expressions like Taro.xx.yy = fn get wrongly rewritten; add
an isAssignmentLHS guard (similar to the existing protection used for
single-level Taro.xxx) by detecting when ast.parent is an AssignmentExpression
(or OptionalAssignment if applicable) and ast.parent.left === node and skip the
rewrite when true.


/* 处理 Taro.xxx */
const isTaro = t.isIdentifier(ast.node.object, { name: taroName })
const property = ast.node.property
const isTaro = t.isIdentifier(node.object, { name: taroName })
const property = node.property
let propertyName: string | null = null
let propName = 'name'

Expand All @@ -125,7 +168,7 @@ const plugin = function (babel: typeof BabelCore): BabelCore.PluginObj<IState> {
// 同一 api 使用多次,读取变量名
if (this.apis.has(propertyName)) {
const parentNode = ast.parent as BabelCore.types.AssignmentExpression
const isAssignment = t.isAssignmentExpression(parentNode) && parentNode.left === ast.node
const isAssignment = t.isAssignmentExpression(parentNode) && parentNode.left === node

if (!isAssignment) {
let identifier: BabelCore.types.Identifier
Expand All @@ -143,9 +186,39 @@ const plugin = function (babel: typeof BabelCore): BabelCore.PluginObj<IState> {
needDefault = true
}
},
CallExpression (ast: BabelCore.NodePath<any>) {
if (!ast.scope.hasReference(this.canIUse)) return
'CallExpression|OptionalCallExpression' (ast: BabelCore.NodePath<any>) {
const callee = ast.node.callee

// 对存在命名空间的 API 支持 tree-shaking:Taro.xx.yy -> xx_yy
// 同时兼容:可选链调用(Taro?.JDMTA.pv() / Taro.JDMTA?.pv())、TS 类型断言(as any / ! / satisfies)
if (t.isMemberExpression(callee) || t.isOptionalMemberExpression(callee)) {
const rawObject = stripTSCast(callee.object)
if (t.isMemberExpression(rawObject) || t.isOptionalMemberExpression(rawObject)) {
const inner = rawObject
const isTaroNamespace = t.isIdentifier(inner.object, { name: taroName })
if (isTaroNamespace) {
const namespaceName = t.isIdentifier(inner.property) ? inner.property.name : (t.isStringLiteral(inner.property) ? inner.property.value : null)
const methodName = t.isIdentifier(callee.property) ? callee.property.name : (t.isStringLiteral(callee.property) ? callee.property.value : null)
if (namespaceName && methodName) {
const flatName = `${namespaceName}_${methodName}`
if (this.apis.has(flatName)) {
let identifier: BabelCore.types.Identifier
if (invokedApis.has(flatName)) {
identifier = t.identifier(invokedApis.get(flatName)!)
} else {
const newName = ast.scope.generateUid(flatName)
invokedApis.set(flatName, newName)
identifier = t.identifier(newName)
}
ast.node.callee = identifier as any
return
}
}
}
}
}

if (!ast.scope.hasReference(this.canIUse)) return
if (t.isMemberExpression(callee) && t.isIdentifier(callee.object, { name: taroName })) {
let propertyName: string | null = null
let propName = 'name'
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-taro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Taro babel preset",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/create-app",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "create taro app with one command",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/css-to-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "taro-css-to-react-native",
"description": "Convert CSS text to a React Native stylesheet object",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"author": "O2Team",
"license": "MIT",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-taro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Taro specific linting rules for ESLint",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-taro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Taro specific linting plugin for ESLint",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-helper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-taro-helper",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "jest helper for taro",
"private": true,
"author": "O2Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-html-transform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-html-transform",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "transform html tag name selector",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-plugin-constparse/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-plugin-constparse",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "parse constants defined in config",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-pxtransform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-pxtransform",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-unit-transform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-taro-unit-transform",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "小程序单位转换",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup-plugin-copy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-copy",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "rollup-plugin-copy for taro",
"private": true,
"author": "O2Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/shared",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Taro utils internal use.",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/stylelint-config-taro-rn/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stylelint-config-taro-rn",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Shareable stylelint config for React Native CSS modules",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/stylelint-taro-rn/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stylelint-taro-rn",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "A collection of React Native specific rules for stylelint",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/stylelint-taro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stylelint-taro",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Taro stylelint 规则集合",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/api",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Taro common API",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-cli-convertor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/cli-convertor",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "cli tool for taro-convert",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/cli",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "cli tool for taro",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-advanced/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-advanced",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "",
"author": "O2Team",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-library-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-library-react",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Taro 组件库 React 版本库",
"private": true,
"author": "O2Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-library-solid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-library-solid",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Taro 组件库 Solid 版本库",
"private": true,
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-library-vue3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-library-vue3",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "Taro 组件库 Vue3 版本库",
"private": true,
"author": "O2Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-react",
"version": "4.1.11",
"version": "4.1.12-alpha.1",
"description": "",
"main:h5": "dist/index.js",
"main": "dist/index.js",
Expand Down
Loading