Skip to content

Commit

Permalink
fix(rn): 接入项目的 babel config 配置导致的 constructor 编译错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Pines-Cheng committed Oct 24, 2019
1 parent 2b67f64 commit ba853b8
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/taro-cli/src/rn/transformJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ const PACKAGES = {
}

const additionalConstructorNode = toAst(`Taro._$app = this`)
const superNode = t.expressionStatement(
t.callExpression(
// @ts-ignore
t.super(),
[
t.identifier('props'),
t.identifier('context')
]
)
)

function getInitPxTransformNode (projectConfig) {
const pxTransformConfig = {designWidth: projectConfig.designWidth || 750}
Expand Down Expand Up @@ -484,9 +494,16 @@ export function parseJSCode ({code, filePath, isEntryFile, projectConfig}) {
]), false, false))
}
if (!hasConstructor) {
node.body.unshift(t.classMethod(
'method', t.identifier('constructor'), [t.identifier('props'), t.identifier('context')],
t.blockStatement([toAst('super(props, context)'), additionalConstructorNode] as t.Statement[]), false, false))
node.body.unshift(
t.classMethod(
'constructor',
t.identifier('constructor'),
[t.identifier('props'), t.identifier('context')],
t.blockStatement([superNode, additionalConstructorNode] as t.Statement[]),
false,
false
)
)
}
}
},
Expand Down

0 comments on commit ba853b8

Please sign in to comment.