Skip to content
Merged
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
12 changes: 10 additions & 2 deletions packages/taro-platform-ascf/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { Template } from './template'
import type { IOptions } from './index'

const PACKAGE_NAME = '@tarojs/plugin-platform-ascf'
const PROJECT_CONFIG_NAME = 'ascf.config.json'

export default class AscfApp extends TaroPlatformBase {
template: Template
platform = 'ascf'
globalObject = 'has'
projectConfigJson: string = this.config.projectConfigName || 'ascf.config.json'
projectConfigJson: string = this.config.projectConfigName || PROJECT_CONFIG_NAME
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Find the TaroPlatformBase class definition
fd -e ts ".*" | xargs rg -l "class TaroPlatformBase" | head -5

Repository: NervJS/taro

Length of output: 109


🏁 Script executed:

# Get more context about TaroPlatformBase initialization
rg "class TaroPlatformBase" -A 30 | head -50

Repository: NervJS/taro

Length of output: 2895


🏁 Script executed:

# Check where this.config is set in the codebase
rg "this\.config\s*=" | grep -E "(TaroPlatformBase|program\.ts)" | head -20

Repository: NervJS/taro

Length of output: 37


🏁 Script executed:

# Find TaroPlatform class definition (parent of TaroPlatformBase)
rg "class TaroPlatform" -A 30 | head -60

Repository: NervJS/taro

Length of output: 5286


🏁 Script executed:

# Look at the actual file being reviewed
cat -n packages/taro-platform-ascf/src/program.ts | head -30

Repository: NervJS/taro

Length of output: 1082


🏁 Script executed:

# Check if this.config is initialized in constructor body vs field initializer
rg "this\.config\s*=" -B 5 -A 2 | grep -A 7 "constructor\|TaroPlatform" | head -40

Repository: NervJS/taro

Length of output: 2653


修复字段初始化器中对 this.config 的访问时序问题。

字段初始化器在父类构造函数执行前运行。第 15 行的初始化器试图访问 this.config.projectConfigName,但 this.config 只在 TaroPlatform 的构造函数体中被赋值(this.config = config),此时尚未执行。建议将此初始化逻辑移至 AscfApp 的构造函数中或使用 getter 方法来延迟求值。

🤖 Prompt for AI Agents
In @packages/taro-platform-ascf/src/program.ts at line 15, The field initializer
projectConfigJson accesses this.config.projectConfigName before the class
constructor runs, causing a timing bug; move the initialization into the AscfApp
(or TaroPlatform) constructor after this.config = config is assigned, or replace
the initializer with a getter that returns this.config?.projectConfigName ||
PROJECT_CONFIG_NAME so evaluation is delayed; update references to
projectConfigJson to use the new constructor-assigned property or the getter to
avoid accessing this.config in a field initializer.

runtimePath = `${PACKAGE_NAME}/dist/runtime`
taroComponentsPath = `${PACKAGE_NAME}/dist/components-react`
fileType = {
Expand All @@ -37,11 +38,18 @@ export default class AscfApp extends TaroPlatformBase {
close () {
this.modifyTemplate(pluginOptions)
this.modifyWebpackConfig()
this.generateProjectConfig('ascf.config.json', 'ascf.config.json')
}
})
}

/**
* ascf不需要生成project.config.json
* 这里override,内部调用时直接生成ascf.config.json
*/
protected generateProjectConfig(src: string) {
super.generateProjectConfig(src, PROJECT_CONFIG_NAME)
}

/**
* 增加组件或修改组件属性
*/
Expand Down