-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Taro-ascf #17748
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
base: main
Are you sure you want to change the base?
Taro-ascf #17748
Conversation
Walkthrough本次变更在 Taro 框架中引入了对 ASCF 平台的支持。涉及核心常量、环境类型、CLI 构建流程、插件编译校验、模板文件类型、依赖包列表等多处扩展,并新增了 Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as Taro CLI
participant Kernel as Taro Kernel
participant Plugin as @tarojs/plugin-platform-ascf
participant AscfApp as AscfApp
participant Template as Template
CLI->>Kernel: build/inspect 命令,识别 ascf 平台
Kernel->>Plugin: 注册 ascf 平台插件
Plugin->>AscfApp: 实例化 AscfApp(ctx, config, options)
AscfApp->>Template: 初始化模板引擎
AscfApp->>AscfApp: 调用 start() 启动编译流程
sequenceDiagram
participant Runtime as Taro Runtime
participant HostConfig as hostConfig
participant Components as components
Runtime->>HostConfig: mergeReconciler(hostConfig)
Runtime->>Components: mergeInternalComponents(components)
Suggested reviewers
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration 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: 8
🧹 Nitpick comments (14)
packages/taro-platform-ascf/README.md (1)
1-3
: 完善 README 文档
当前 README 过于简略,建议补充安装步骤、使用示例、插件配置说明以及常见问题等,以提升插件的可用性和易上手性。packages/taro-platform-ascf/src/runtime.ts (1)
1-6
: ASCF 平台运行时设置恰当运行时代码结构清晰,正确地合并了 ASCF 平台特定的 hostConfig 和组件定义。这种实现方式符合 Taro 框架中其他平台的实现模式。
不过建议添加文件头部注释,说明该文件的用途及其在 ASCF 平台适配中的作用,以提高代码可读性和可维护性。
+/** + * ASCF 平台运行时入口 + * 负责将平台特定的组件和配置合并到 Taro 框架中 + */ import { mergeInternalComponents, mergeReconciler } from '@tarojs/shared' import { components, hostConfig } from './runtime-utils' mergeReconciler(hostConfig) mergeInternalComponents(components)packages/taro-cli/src/presets/platforms/plugin.ts (1)
27-28
: 正确更新插件编译支持条件和提示信息插件编译条件检查中正确添加了对 ASCF 平台的支持,并更新了相应的错误提示信息。这确保了 ASCF 平台的插件可以被正确编译。
建议考虑使用数组和 includes 方法简化平台判断逻辑,使代码更简洁和可维护:
-if (plugin !== ASCF && plugin !== WEAPP && plugin !== ALIPAY && plugin !== JD) { - console.log(chalk.red('目前插件编译仅支持 ASCF/微信/支付宝/京东 小程序!')) +const SUPPORTED_PLATFORMS = [ASCF, WEAPP, ALIPAY, JD]; +if (!SUPPORTED_PLATFORMS.includes(plugin)) { + console.log(chalk.red('目前插件编译仅支持 ASCF/微信/支付宝/京东 小程序!'))packages/taro-cli/src/cli.ts (1)
159-159
: 正确更新小程序插件编译条件在小程序插件编译的条件判断中添加了 ASCF 平台支持,确保了在编译 ASCF 插件时能正确加载相应的平台插件。
与之前相同,建议考虑使用数组和 includes 方法简化平台判断逻辑:
-if (plugin === 'ascf' || plugin === 'weapp' || plugin === 'alipay' || plugin === 'jd') { +const PLUGIN_PLATFORMS = ['ascf', 'weapp', 'alipay', 'jd']; +if (PLUGIN_PLATFORMS.includes(plugin)) {packages/taro-platform-ascf/src/components.ts (4)
25-55
: 地图组件定义全面Map 组件的属性定义十分全面,包含了各种控制选项和事件绑定。建议考虑添加注释说明部分复杂属性的用途。
489-498
: OpenContainer 组件类型定义OpenContainer 组件的属性定义看起来完整,但缺少对各属性作用的注释说明。由于这是一个较为专业的组件,建议添加简要说明帮助开发者理解。
499-505
: DraggableSheet 组件参数说明DraggableSheet 组件定义了尺寸和行为相关的参数,但对于
snapSizes
等属性缺少说明。建议添加简短注释说明其用途和格式。
1-517
: 考虑使用 TypeScript 接口定义组件属性结构整个文件使用简单的对象字面量来定义组件属性。建议考虑为每种组件类型定义 TypeScript 接口,这样可以提供更好的类型检查和文档。
+interface ComponentBaseProps { + [key: string]: string; +} + +interface ButtonProps extends ComponentBaseProps { + lang: string; + 'session-from': string; + // 其他按钮属性... +} + export const components = { // ======== 调整属性 ======== Progress: { // ... }, // ... - Button: { + Button: { lang: 'en', 'session-from': _empty, // ... }, // ... }packages/taro-platform-ascf/src/apis.ts (3)
1-6
: 导入和声明结构清晰导入和类型声明的结构清晰,但
has
类型声明为any
不够严格。建议为has
定义更具体的接口。-declare const has: any +interface HasFeatures { + cloud?: any; + [key: string]: any; +} + +declare const has: HasFeatures
7-24
: API 初始化函数设计合理
initNativeApi
函数设计合理,包含修复已知问题和转换元数据的功能。特别是对showShareMenu
API 的处理很巧妙。但taro
参数缺少类型注解。-export function initNativeApi (taro) { +export function initNativeApi (taro: any) { // ... 现有代码 ...
25-33
: 实用工具方法实现
getTabBar
和getRenderer
方法实现得当,特别是使用了可选链操作符来避免空引用错误。但建议添加适当的返回类型注解以提高代码的可读性和类型安全性。- taro.getTabBar = function (pageCtx) { + taro.getTabBar = function (pageCtx): any { if (typeof pageCtx?.getTabBar === 'function') { return pageCtx.getTabBar()?.$taroInstances } } - taro.getRenderer = function () { + taro.getRenderer = function (): string { return taro.getCurrentInstance()?.page?.renderer ?? 'webview' }packages/taro-platform-ascf/src/components-react.ts (1)
3-38
: 组件类型常量导出文件导出了多个组件类型常量,但缺少对这些组件的分类或注释说明。建议按功能或类型对组件进行分组,并添加简要注释以提高可读性。
// For React.createElement's type export * from '@tarojs/components/mini' + +// 基础内容组件 export const Editor = 'editor' export const MatchMedia = 'match-media' + +// 功能性组件 export const FunctionalPageNavigator = 'functional-page-navigator' export const LivePusher = 'live-pusher' // ... 其他组件 ...packages/taro-platform-ascf/src/program.ts (1)
64-67
:devtoolModuleFilenameTemplate
中对info.namespace
的依赖需校验
当namespace
为空或未定义时,模板字符串会出现webpack:///undefined/...
,影响调试体验。可为namespace
提供默认值或回退逻辑。packages/taro-platform-ascf/src/template.ts (1)
75-102
:modifyTemplateResult
字符串操作脆弱,边界条件未处理
- 假设模板一定含有至少 3 个
</template>
,若不满足将读取越界。split + splice
每次都会重新拼接大字符串,性能与可维护性堪忧。建议:
- 先判断
list.length >= 3
,不足则直接返回res
;- 考虑使用 AST 或正则匹配局部节点,减少字符串切片错误。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (20)
packages/shared/src/constants.ts
(2 hunks)packages/taro-api/src/env.ts
(2 hunks)packages/taro-cli/src/cli.ts
(2 hunks)packages/taro-cli/src/presets/platforms/plugin.ts
(1 hunks)packages/taro-helper/src/constants.ts
(2 hunks)packages/taro-platform-ascf/README.md
(1 hunks)packages/taro-platform-ascf/index.js
(1 hunks)packages/taro-platform-ascf/package.json
(1 hunks)packages/taro-platform-ascf/rollup.config.mjs
(1 hunks)packages/taro-platform-ascf/src/apis-list.ts
(1 hunks)packages/taro-platform-ascf/src/apis.ts
(1 hunks)packages/taro-platform-ascf/src/components-react.ts
(1 hunks)packages/taro-platform-ascf/src/components.ts
(1 hunks)packages/taro-platform-ascf/src/index.ts
(1 hunks)packages/taro-platform-ascf/src/program.ts
(1 hunks)packages/taro-platform-ascf/src/runtime-utils.ts
(1 hunks)packages/taro-platform-ascf/src/runtime.ts
(1 hunks)packages/taro-platform-ascf/src/template.ts
(1 hunks)packages/taro-platform-ascf/tsconfig.json
(1 hunks)packages/taro/types/global.d.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/taro-cli/src/presets/platforms/plugin.ts (1)
packages/taro-helper/src/constants.ts (1)
PLATFORMS
(6-6)
🪛 Biome (1.9.4)
packages/taro-platform-ascf/src/template.ts
[error] 38-38: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 39-39: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
🔇 Additional comments (23)
packages/taro/types/global.d.ts (1)
413-413
: 新增 ENV_TYPE 枚举成员 ASCF
已将ASCF = 'ASCF'
添加到环境类型枚举中,可确保全局类型安全地引用新平台环境。packages/shared/src/constants.ts (2)
3-3
: 新增 PLATFORM_TYPE 枚举成员 ASCF
在PLATFORM_TYPE
中增加ASCF = 'ascf'
,与全局类型与 CLI 平台列表保持一致。
21-23
: 配置映射添加 ascf 条目
已在PLATFORM_CONFIG_MAP
中为ascf
平台添加映射,确保编译入口正确识别并加载 ASCF 平台。packages/taro-platform-ascf/tsconfig.json (1)
1-13
: TS 配置文件检查通过
tsconfig.json
中已正确继承根配置并启用声明文件生成,include 配置覆盖src
目录,符合包内编译需求。packages/taro-platform-ascf/index.js (1)
1-1
: 模块导出设置完善
已正确导出默认接口和命名导出AscfApp
,符合 Node.js CommonJS 规范,可被上层 CLI 与运行时正确加载。Also applies to: 3-4
packages/taro-api/src/env.ts (2)
2-2
: 很好地添加了 ASCF 平台支持在环境类型常量中添加 ASCF 平台定义,保持了与其他平台定义的一致性。
39-40
: ASCF 环境检测实现正确正确地实现了对 ASCF 平台的环境检测逻辑,与其他平台的检测方式保持一致。这确保了在 ASCF 平台上运行时能够正确识别环境类型。
packages/taro-cli/src/presets/platforms/plugin.ts (2)
19-19
: 正确导入 ASCF 平台标识符正确地从 PLATFORMS 对象中解构出 ASCF 平台标识符,为插件编译预设做好准备。
21-21
: 适当添加 ASCF 显示名称在 typeMap 中为 ASCF 平台添加了合适的显示名称,保持了与其他平台的一致性。
packages/taro-cli/src/cli.ts (1)
121-121
: 正确添加 ASCF 平台识别在处理内置平台的 switch 语句中添加了 ASCF 平台的 case,确保能够正确加载 ASCF 平台插件。
packages/taro-helper/src/constants.ts (2)
106-106
: 模板正则表达式更新正确在
REG_TEMPLATE
正则表达式中添加了.hxml
扩展名,这符合 ASCF 平台的模板文件格式。这个更改确保 Taro 能够正确识别和处理 ASCF 平台的模板文件。
180-180
: 包更新列表添加符合预期将
@tarojs/plugin-platform-ascf
添加到UPDATE_PACKAGE_LIST
数组中的位置很合适,它被放置在@tarojs/plugin-platform-weapp
之后,保持了平台插件的字母顺序排列。这确保了在 Taro 更新时能正确处理 ASCF 平台插件。packages/taro-platform-ascf/src/apis-list.ts (1)
1-33
: 需要 Promise 支持的 API 列表设置完整这个文件导出了 ASCF 平台上需要 Promise 支持的 API 集合,覆盖了文件操作、视频收藏、用户认证、位置服务、聊天功能等多种场景。这些 API 将在运行时被正确地封装为返回 Promise 的形式,使开发者能够使用异步/await 语法调用这些接口。
设置合理,与其他平台实现保持一致的风格。
packages/taro-platform-ascf/package.json (1)
1-40
: 插件包配置正确合理package.json 文件配置了 ASCF 平台插件的基本信息、构建脚本和依赖关系:
- 版本号 4.0.10 与当前 Taro 版本匹配
- 使用了工作区依赖引用方式 (
workspace:*
),确保与其他 Taro 包版本同步- 设置了正确的入口文件和类型定义文件
- 包含了必要的构建脚本
- 设置了 Node.js >= 18 的引擎要求
配置符合 Taro 插件开发规范,没有发现问题。
packages/taro-platform-ascf/src/index.ts (1)
1-21
: 平台插件注册实现完善这个文件是 ASCF 平台插件的主入口,实现了以下功能:
- 导出
AscfApp
类,允许其他平台插件继承此平台- 定义
IOptions
接口,包含可选的enablekeyboardAccessory
配置项- 通过
ctx.registerPlatform
注册 ASCF 平台,配置平台名称和对应的工厂函数实现遵循了 Taro 插件架构规范,工厂函数创建并启动
AscfApp
实例的方式与其他平台插件保持一致。代码结构清晰,没有发现问题。packages/taro-platform-ascf/src/components.ts (3)
1-6
: 良好的常量定义使用常量定义常用值(如
_true
、_false
、_empty
等)有助于提高代码一致性和可维护性。
7-24
: 组件属性定义结构清晰Progress、RichText 和 Text 组件的属性定义清晰明了,默认值设置合理。
56-488
: 标准 UI 组件定义完整从 Button 到 Span 的一系列标准 UI 组件定义完整,属性覆盖全面,事件绑定齐全。特别值得称赞的是对 Video 组件中
picture-in-picture-show-progress
属性的详细注释说明。packages/taro-platform-ascf/rollup.config.mjs (4)
1-20
: 基础配置设置合理Rollup 配置文件的基础设置合理,使用了现代 ES 模块语法和 Node.js 原生路径工具。插件配置适当,包括节点解析、外部依赖和 TypeScript 支持。
21-31
: CLI 编译配置编译配置采用 CommonJS 格式输出,适合作为 Taro CLI 使用的插件入口。注释清晰说明了用途。
33-53
: 运行时配置运行时和运行时工具配置使用 ES 模块格式,有利于现代 JavaScript 生态系统和 tree-shaking。注释清晰说明了用途。
55-66
: React 组件配置和配置导出React 组件配置也采用 ES 模块格式,注释说明了 webpack 别名机制。配置数组导出清晰明了。
packages/taro-platform-ascf/src/components-react.ts (1)
1-3
: React 组件导出基础文件开始简洁地说明了用途并从 mini 组件包中重新导出所有内容。
NestedScrollHeader: {}, | ||
NestedScrollBody: {}, | ||
// skyline手势组件 | ||
DoubleTapGestureHandler: {}, | ||
ForcePressGestureHandler: {}, | ||
HorizontalDragGestureHandler: {}, | ||
LongPressGestureHandler: {}, | ||
PanGestureHandler: {}, | ||
ScaleGestureHandler: {}, | ||
TapGestureHandler: {}, | ||
VerticalDragGestureHandler: {}, | ||
} |
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.
💡 Verification agent
🧩 Analysis chain
手势组件定义简洁
Skyline 手势组件的定义简洁明了,但目前所有组件都没有定义任何属性。如果这些组件确实需要特定属性,请确保添加。
🏁 Script executed:
#!/bin/bash
# 检查代码库中是否有关于这些手势组件属性的文档或使用示例
echo "搜索手势组件的使用示例..."
rg -A 2 -B 2 "TapGestureHandler|PanGestureHandler|ScaleGestureHandler" --type ts
Length of output: 16268
🏁 Script executed:
#!/bin/bash
# 查看 TapGestureHandlerProps 定义
sed -n '1,200p' packages/taro-components/types/gesture/TapGestureHandler.d.ts
Length of output: 1242
请为 Skyline 手势组件补充属性映射
在 packages/taro-platform-ascf/src/components.ts(同理也适用于 weapp 平台的对应文件)中,所有 Skyline 手势组件目前均定义为空对象 {}
,导致组件无法透传以下在 packages/taro-components/types/gesture/*
中定义的属性:
tag?
onGestureWorklet?
shouldResponseOnMoveWorklet?
shouldAcceptGestureWorklet?
simultaneousHandlers?
nativeView?
请在每个手势组件的 mapping 对象中添加上述属性,例如:
DoubleTapGestureHandler: {
+ tag: true,
+ onGestureWorklet: true,
+ shouldResponseOnMoveWorklet: true,
+ shouldAcceptGestureWorklet: true,
+ simultaneousHandlers: true,
+ nativeView: true
},
其它手势组件(Pan/Scale/Tap/…)请按同样方式补全。
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
NestedScrollHeader: {}, | |
NestedScrollBody: {}, | |
// skyline手势组件 | |
DoubleTapGestureHandler: {}, | |
ForcePressGestureHandler: {}, | |
HorizontalDragGestureHandler: {}, | |
LongPressGestureHandler: {}, | |
PanGestureHandler: {}, | |
ScaleGestureHandler: {}, | |
TapGestureHandler: {}, | |
VerticalDragGestureHandler: {}, | |
} | |
NestedScrollHeader: {}, | |
NestedScrollBody: {}, | |
// skyline手势组件 | |
- DoubleTapGestureHandler: {}, | |
+ DoubleTapGestureHandler: { | |
+ tag: true, | |
+ onGestureWorklet: true, | |
+ shouldResponseOnMoveWorklet: true, | |
+ shouldAcceptGestureWorklet: true, | |
+ simultaneousHandlers: true, | |
+ nativeView: true | |
+ }, | |
ForcePressGestureHandler: {}, | |
HorizontalDragGestureHandler: {}, | |
LongPressGestureHandler: {}, | |
PanGestureHandler: {}, | |
ScaleGestureHandler: {}, | |
TapGestureHandler: {}, | |
VerticalDragGestureHandler: {}, | |
} |
🤖 Prompt for AI Agents
In packages/taro-platform-ascf/src/components.ts around lines 506 to 517, the
Skyline gesture components are currently defined with empty objects, missing the
necessary property mappings. To fix this, add the properties tag?,
onGestureWorklet?, shouldResponseOnMoveWorklet?, shouldAcceptGestureWorklet?,
simultaneousHandlers?, and nativeView? to each gesture component's mapping
object. Ensure these properties are included for all listed gesture components
such as DoubleTapGestureHandler, ForcePressGestureHandler,
HorizontalDragGestureHandler, LongPressGestureHandler, PanGestureHandler,
ScaleGestureHandler, TapGestureHandler, and VerticalDragGestureHandler.
// For React.createElement's type | ||
export * from '@tarojs/components/mini' | ||
export const Editor = 'editor' | ||
export const MatchMedia = 'match-media' | ||
export const FunctionalPageNavigator = 'functional-page-navigator' | ||
export const LivePusher = 'live-pusher' | ||
export const OfficialAccount = 'official-account' | ||
export const OpenData = 'open-data' | ||
export const NavigationBar = 'navigation-bar' | ||
export const PageMeta = 'page-meta' | ||
export const VoipRoom = 'voip-room' | ||
export const AdCustom = 'ad-custom' | ||
export const PageContainer = 'page-container' | ||
export const ShareElement = 'share-element' | ||
export const KeyboardAccessory = 'keyboard-accessory' | ||
export const RootPortal = 'root-portal' | ||
export const ChannelLive = 'channel-live' | ||
export const ChannelVideo = 'channel-video' | ||
export const ListView = 'list-view' | ||
export const ListBuilder = 'list-builder' | ||
export const GridView = 'grid-view' | ||
export const GridBuilder = 'grid-builder' | ||
export const StickyHeader = 'sticky-header' | ||
export const StickySection = 'sticky-section' | ||
export const Snapshot = 'snapshot' | ||
export const Span = 'span' | ||
export const OpenContainer = 'open-container' | ||
export const DraggableSheet = 'draggable-sheet' | ||
export const NestedScrollHeader = 'nested-scroll-header' | ||
export const NestedScrollBody = 'nested-scroll-body' | ||
export const DoubleTapGestureHandler = 'double-tap-gesture-handler' | ||
export const ForcePressGestureHandler = 'force-press-gesture-handler' | ||
export const HorizontalDragGestureHandler = 'horizontal-drag-gesture-handler' | ||
export const LongPressGestureHandler = 'long-press-gesture-handler' | ||
export const PanGestureHandler = 'pan-gesture-handler' | ||
export const ScaleGestureHandler = 'scale-gesture-handler' | ||
export const TapGestureHandler = 'tap-gesture-handler' | ||
export const VerticalDragGestureHandler = 'vertical-drag-gesture-handler' |
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.
💡 Verification agent
🧩 Analysis chain
验证组件定义完整性
请确保所有在 components.ts
中定义的组件都在此文件中导出了对应的类型常量,以保持一致性。
🏁 Script executed:
#!/bin/bash
# 检查 components.ts 中定义的组件是否都在 components-react.ts 中导出
echo "提取 components.ts 中的组件名称..."
COMPONENTS=$(grep -E "^ [A-Za-z]+" packages/taro-platform-ascf/src/components.ts | awk -F: '{print $1}' | tr -d ' ' | sort)
echo "提取 components-react.ts 中导出的组件..."
REACT_COMPONENTS=$(grep -E "^export const" packages/taro-platform-ascf/src/components-react.ts | awk '{print $3}' | sort)
echo "比较两个文件中的组件定义..."
echo "$COMPONENTS" > /tmp/components.txt
echo "$REACT_COMPONENTS" > /tmp/react_components.txt
MISSING=$(comm -23 /tmp/components.txt /tmp/react_components.txt)
if [ -n "$MISSING" ]; then
echo "以下组件在 components.ts 中定义但未在 components-react.ts 中导出:"
echo "$MISSING"
else
echo "所有组件已正确导出。"
fi
Length of output: 3380
补充缺失的组件导出
发现 packages/taro-platform-ascf/src/components.ts
中定义的以下组件尚未在 components-react.ts
中以 export const
形式导出,请补充对应的类型常量以保持一致性:
- Ad
- Button
- Camera
- Canvas
- CoverView
- Form
- Image
- Input
- LivePlayer
- Map
- Navigator
- Picker
- PickerView
- Progress
- RichText
- ScrollView
- Slider
- Swiper
- SwiperItem
- Text
- Textarea
- Video
🤖 Prompt for AI Agents
In packages/taro-platform-ascf/src/components-react.ts lines 1 to 38, several
components defined in components.ts are missing export const declarations. Add
export const statements for each missing component name listed (Ad, Button,
Camera, Canvas, CoverView, Form, Image, Input, LivePlayer, Map, Navigator,
Picker, PickerView, Progress, RichText, ScrollView, Slider, Swiper, SwiperItem,
Text, Textarea, Video) with their string literal values matching their
kebab-case names to ensure all components are consistently exported.
transferHydrateData (data, element, componentsAlias) { | ||
if (element.isTransferElement) { | ||
const pages = getCurrentPages() | ||
const page = pages[pages.length - 1] | ||
data[Shortcuts.NodeName] = element.dataName | ||
page.setData({ | ||
[toCamelCase(data.nn)]: data | ||
}) | ||
return { | ||
sid: element.sid, | ||
[Shortcuts.Text]: '', | ||
[Shortcuts.NodeName]: componentsAlias['#text']?._num || '8' | ||
} | ||
} | ||
}, |
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.
transferHydrateData
对运行环境的假设过于乐观
getCurrentPages()
在部分运行时(如 SSR 或单测)可能不存在,直接调用会抛错。- 当页面栈为空时,
pages[pages.length - 1]
得到undefined
,page.setData
会再度抛错。 - 函数在
isTransferElement === false
时返回undefined
,但调用方是否能正确处理未定义返回值未见说明。
建议补充存在性检查,并在异常场景记录 warning 或兜底返回。
🤖 Prompt for AI Agents
In packages/taro-platform-ascf/src/runtime-utils.ts around lines 19 to 33, the
function transferHydrateData assumes getCurrentPages() always exists and returns
a non-empty array, which can cause errors in SSR or test environments. Add
checks to ensure getCurrentPages is defined and returns a non-empty array before
accessing the last page. Also verify that page is defined before calling
page.setData. For cases where element.isTransferElement is false or these checks
fail, log a warning and return a safe default value instead of undefined to
avoid unexpected errors in callers.
getMiniLifecycle (config) { | ||
const methods = config.page[5] | ||
if (methods.indexOf('onSaveExitState') === -1) { | ||
methods.push('onSaveExitState') | ||
} | ||
return config |
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.
🛠️ Refactor suggestion
getMiniLifecycle
缺少安全性校验,可能在运行时抛错
config.page[5]
默认假设为数组,若插件或外部调用方改动了 config.page
的结构,methods
将变成 undefined
,随后的 push
会直接抛出异常。建议在访问前增加类型与越界判断,并提供默认空数组。
- const methods = config.page[5]
- if (methods.indexOf('onSaveExitState') === -1) {
- methods.push('onSaveExitState')
+ const methods: string[] = Array.isArray(config.page?.[5])
+ ? config.page[5]
+ : (config.page[5] = [])
+ if (!methods.includes('onSaveExitState')) {
+ methods.push('onSaveExitState')
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
getMiniLifecycle (config) { | |
const methods = config.page[5] | |
if (methods.indexOf('onSaveExitState') === -1) { | |
methods.push('onSaveExitState') | |
} | |
return config | |
getMiniLifecycle (config) { | |
- const methods = config.page[5] | |
- if (methods.indexOf('onSaveExitState') === -1) { | |
- methods.push('onSaveExitState') | |
+ const methods: string[] = Array.isArray(config.page?.[5]) | |
+ ? config.page[5] | |
+ : (config.page[5] = []) | |
+ if (!methods.includes('onSaveExitState')) { | |
+ methods.push('onSaveExitState') | |
} | |
return config | |
} |
🤖 Prompt for AI Agents
In packages/taro-platform-ascf/src/runtime-utils.ts around lines 12 to 17, the
code assumes config.page[5] is always an array, which can cause runtime errors
if it's undefined or not an array. To fix this, add a check to verify
config.page exists and config.page[5] is an array before using it; if not,
initialize methods as an empty array. This prevents exceptions when calling push
on undefined.
constructor (ctx, config, pluginOptions?: IOptions) { | ||
super(ctx, config) | ||
this.template = new Template(pluginOptions) | ||
this.setupTransaction.addWrapper({ | ||
close () { | ||
this.modifyTemplate(pluginOptions) | ||
this.modifyWebpackConfig() | ||
} | ||
}) | ||
} |
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.
🛠️ Refactor suggestion
addWrapper.close()
的 this
指向可能失效
close () { ... }
使用普通函数,若 Taro
内部未显式绑定上下文,this
将指向 undefined
或 wrapper 对象本身,导致 modifyTemplate
与 modifyWebpackConfig
调用失败。为了避免依赖外部绑定行为,建议改为箭头函数或显式 .bind(this)
。
- this.setupTransaction.addWrapper({
- close () {
- this.modifyTemplate(pluginOptions)
- this.modifyWebpackConfig()
- }
- })
+ this.setupTransaction.addWrapper({
+ close: () => {
+ this.modifyTemplate(pluginOptions)
+ this.modifyWebpackConfig()
+ }
+ })
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
constructor (ctx, config, pluginOptions?: IOptions) { | |
super(ctx, config) | |
this.template = new Template(pluginOptions) | |
this.setupTransaction.addWrapper({ | |
close () { | |
this.modifyTemplate(pluginOptions) | |
this.modifyWebpackConfig() | |
} | |
}) | |
} | |
constructor (ctx, config, pluginOptions?: IOptions) { | |
super(ctx, config) | |
this.template = new Template(pluginOptions) | |
this.setupTransaction.addWrapper({ | |
close: () => { | |
this.modifyTemplate(pluginOptions) | |
this.modifyWebpackConfig() | |
} | |
}) | |
} |
🤖 Prompt for AI Agents
In packages/taro-platform-ascf/src/program.ts around lines 33 to 42, the close
method inside addWrapper uses a regular function, causing its this context to be
incorrect and leading to failures when calling modifyTemplate and
modifyWebpackConfig. Fix this by changing the close method to an arrow function
or explicitly binding it to the class instance with .bind(this) to ensure the
correct this context.
buildXSTepFocus (nn: string) { | ||
if (this.pluginOptions.enablekeyboardAccessory) { | ||
const textarea = this.componentsAlias.textarea._num | ||
const input = this.componentsAlias.input._num | ||
const ka = this.componentsAlias['keyboard-accessory']._num | ||
return `function(i, prefix) { | ||
var s = i.focus !== undefined ? 'focus' : 'blur' | ||
var r = prefix + i.${nn} + '_' + s | ||
if ((i.nn === '${textarea}' || i.nn === '${input}') && i.cn[0] && i.cn[0].nn === '${ka}') { | ||
r = r + '_ka' | ||
} | ||
return r | ||
}` | ||
} else { |
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.
🛠️ Refactor suggestion
buildXSTepFocus
需防御性处理组件别名缺失
若运行时未注册 keyboard-accessory
、input
或 textarea
,对 _num
的访问将触发 TypeError
。可以在计算前做存在性判断,不满足条件时直接回退到基类实现。
🤖 Prompt for AI Agents
In packages/taro-platform-ascf/src/template.ts around lines 57 to 70, the
buildXSTepFocus method accesses _num properties of
componentsAlias.keyboard-accessory, input, and textarea without checking if
these components exist, which can cause a TypeError if any are missing. Add
defensive checks to verify the existence of these components and their _num
properties before accessing them; if any are missing, return the base class
implementation instead of proceeding.
if (value === 'eh') { | ||
const nameLowerCase = name.toLowerCase() | ||
if (nameLowerCase === 'bindlongtap' && componentName !== 'canvas') return 'bindlongpress' | ||
return nameLowerCase | ||
} | ||
if (componentName === 'share-element') { | ||
const mapKeyAlias = componentAlias.mapkey | ||
if (value === `i.${mapKeyAlias}`) return 'key' | ||
} | ||
return name | ||
} |
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.
replacePropName
对 componentAlias
的访问缺乏空值保护
当 share-element
组件未出现在 componentsAlias
中时,componentAlias
可能为 undefined
,访问 mapkey
会抛出异常。
- if (componentName === 'share-element') {
- const mapKeyAlias = componentAlias.mapkey
- if (value === `i.${mapKeyAlias}`) return 'key'
+ if (componentName === 'share-element' && componentAlias?.mapkey) {
+ const mapKeyAlias = componentAlias.mapkey
+ if (value === `i.${mapKeyAlias}`) return 'key'
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (value === 'eh') { | |
const nameLowerCase = name.toLowerCase() | |
if (nameLowerCase === 'bindlongtap' && componentName !== 'canvas') return 'bindlongpress' | |
return nameLowerCase | |
} | |
if (componentName === 'share-element') { | |
const mapKeyAlias = componentAlias.mapkey | |
if (value === `i.${mapKeyAlias}`) return 'key' | |
} | |
return name | |
} | |
if (value === 'eh') { | |
const nameLowerCase = name.toLowerCase() | |
if (nameLowerCase === 'bindlongtap' && componentName !== 'canvas') return 'bindlongpress' | |
return nameLowerCase | |
} | |
if (componentName === 'share-element' && componentAlias?.mapkey) { | |
const mapKeyAlias = componentAlias.mapkey | |
if (value === `i.${mapKeyAlias}`) return 'key' | |
} | |
return name | |
} |
🤖 Prompt for AI Agents
In packages/taro-platform-ascf/src/template.ts around lines 45 to 55, the
function replacePropName accesses componentAlias.mapkey without checking if
componentAlias is defined, which can cause an exception if share-element is not
in componentsAlias. Add a null or undefined check for componentAlias before
accessing mapkey to prevent runtime errors. Only access mapkey if componentAlias
exists; otherwise, skip or handle the case safely.
createMiniComponents (components): any { | ||
const result = super.createMiniComponents(components) | ||
|
||
// PageMeta & NavigationBar | ||
this.transferComponents['page-meta'] = result['page-meta'] | ||
this.transferComponents['navigation-bar'] = result['navigation-bar'] | ||
delete result['page-meta'] | ||
delete result['navigation-bar'] | ||
|
||
return result |
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.
🛠️ Refactor suggestion
使用 delete
影响性能,且被静态分析工具标红
在热路径中频繁调用 delete
会导致 V8 难以优化对象结构。可通过解构排除属性或设置为 undefined
代替。
- const result = super.createMiniComponents(components)
-
- // PageMeta & NavigationBar
- this.transferComponents['page-meta'] = result['page-meta']
- this.transferComponents['navigation-bar'] = result['navigation-bar']
- delete result['page-meta']
- delete result['navigation-bar']
-
- return result
+ const raw = super.createMiniComponents(components)
+
+ // PageMeta & NavigationBar
+ this.transferComponents['page-meta'] = raw['page-meta']
+ this.transferComponents['navigation-bar'] = raw['navigation-bar']
+
+ // 构造不含上述两组件的新对象,避免 delete
+ const { ['page-meta']: _pm, ['navigation-bar']: _nb, ...rest } = raw
+ return rest
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
createMiniComponents (components): any { | |
const result = super.createMiniComponents(components) | |
// PageMeta & NavigationBar | |
this.transferComponents['page-meta'] = result['page-meta'] | |
this.transferComponents['navigation-bar'] = result['navigation-bar'] | |
delete result['page-meta'] | |
delete result['navigation-bar'] | |
return result | |
createMiniComponents (components): any { | |
const raw = super.createMiniComponents(components) | |
// PageMeta & NavigationBar | |
this.transferComponents['page-meta'] = raw['page-meta'] | |
this.transferComponents['navigation-bar'] = raw['navigation-bar'] | |
// 构造不含上述两组件的新对象,避免 delete | |
const { ['page-meta']: _pm, ['navigation-bar']: _nb, ...rest } = raw | |
return rest | |
} |
🧰 Tools
🪛 Biome (1.9.4)
[error] 38-38: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 39-39: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
🤖 Prompt for AI Agents
In packages/taro-platform-ascf/src/template.ts around lines 32 to 41, avoid
using the delete operator on result['page-meta'] and result['navigation-bar'] as
it harms performance and triggers static analysis warnings. Instead, refactor
the code to exclude these properties using object destructuring or assign them
to undefined to prevent modifying the object shape, improving V8 optimization.
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
🧹 Nitpick comments (3)
package.json (2)
184-184
: 检查browserslist
覆盖的必要性
新增了对browserslist
的覆盖版本^4.23.0
,请确认此改动是为满足 ASCF 平台兼容性要求,并且不会与其他依赖产生冲突。建议在配置旁添加注释说明此覆盖的动机。
185-185
: 验证本地taro
链接覆盖用途
将taro
指向本地link:
,如果仅用于本地开发调试,请确认是否需要在正式发布前移除该覆盖或在文档中明确使用场景和生命周期。packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json (1)
2331-2334
: 保持属性命名一致性
请确认此处新增的list
组件属性upper-threshold-count
与lower-threshold-count
命名是否与其他平台(如scroll-view
中的upper-threshold
、lower-threshold
)保持一致,或者是否存在命名规范上的差异。若命名有偏差,建议修改为统一的属性名以提升可维护性和使用者体验。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
package.json
(3 hunks)packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json
(2 hunks)
🔇 Additional comments (2)
package.json (1)
3-3
: 请确认版本号变更
当前将版本从4.0.12
降级到4.0.10
。请核实这是出于何种原因(如与新插件版本匹配),以确保不会无意中回退已发布功能或引入兼容性问题。packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json (1)
2345-2345
: 确认list-item
组件声明状态
当前将"list-item": false
标记为不支持。请核实 Harmony 平台下是否确实不支持该组件,或是否需要像其他平台一样声明其可用属性(例如 class、style 等)。若需要支持,可考虑将其改为对象形式并添加相应属性;若不支持,可保留当前配置。
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
🧹 Nitpick comments (1)
pnpm-workspace.yaml (1)
9-9
: 文件末尾缺少换行
根据 YAMLlint 报错,文件末尾缺少换行字符,建议在最后一行后添加一个空行以符合规范。🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 9-9: no new line character at the end of file
(new-line-at-end-of-file)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
package.json
(4 hunks)packages/taro-platform-ascf/package.json
(1 hunks)packages/taro/package.json
(1 hunks)packages/taro/tsconfig.json
(1 hunks)packages/taro/types/api/taro.extend.d.ts
(1 hunks)pnpm-workspace.yaml
(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- packages/taro/package.json
- packages/taro/tsconfig.json
- packages/taro/types/api/taro.extend.d.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- package.json
- packages/taro-platform-ascf/package.json
🧰 Additional context used
🪛 YAMLlint (1.37.1)
pnpm-workspace.yaml
[error] 9-9: no new line character at the end of file
(new-line-at-end-of-file)
🔇 Additional comments (1)
pnpm-workspace.yaml (1)
9-9
: 验证新平台插件路径
请确认'../../a/taro/packages/taro-platform-ascf'
相对路径是否正确,并且该目录已存在于工作区,否则在执行pnpm install
或 workspace 操作时可能找不到该包。🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 9-9: no new line character at the end of file
(new-line-at-end-of-file)
这个 PR 做了什么? (简要描述所做更改)
ASCF-Taro适配
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit
新功能
文档
其他