Skip to content
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

fix: 解决convertor编译过程中出现的类型报错 #150

Merged
merged 1 commit into from
Sep 1, 2023
Merged
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 packages/taro-cli-convertor/src/util/astConvert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as t from '@babel/types'

// 最低限度的转义: https://github.com/mathiasbynens/jsesc#minimal
export function generateMinimalEscapeCode (ast: t.File) {
return generate(ast, {
return generate(ast as any, {
jsescOption: {
minimal: true,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-transformer-wx/src/functional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const functionalComponent: () => {
id,
`普通函数式组件命名规则请遵守帕斯卡命名法(Pascal Case), 如果是在函数内声明闭包组件,则需要使用函数表达式的写法。
形如:
const ${id?.name} = ${generate(t.arrowFunctionExpression(params as any, body as any)).code}
const ${id?.name} = ${generate(t.arrowFunctionExpression(params as any, body as any) as any).code}
`
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/taro-transformer-wx/src/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function generateJSXAttr(ast: t.Node) {
quotes: 'single',
retainFunctionParens: true, // 如果您需要 JSON 兼容的字符串,请改用此选项
}
const code = decodeUnicode(generate(ast, options).code).replace(/</g, lessThanSignPlacehold)
const code = decodeUnicode(generate(ast as any, options).code).replace(/</g, lessThanSignPlacehold)
if (Status.isSFC) {
return code
}
Expand Down Expand Up @@ -248,7 +248,7 @@ export function parseJSXElement(element: t.JSXElement, isFirstEmit = false): str
quotes: 'single',
concise: true,
}
let code = decodeUnicode(generate(attrValue.expression, options).code)
let code = decodeUnicode(generate(attrValue.expression as any, options).code)
.replace(/"/g, "'")
.replace(/(this\.props\.)|(this\.state\.)/g, '')
.replace(/this\./g, '')
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-transformer-wx/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function findMethodName(expression: t.Expression): string {
} else if (t.isStringLiteral(expression)) {
methodName = expression.value
} else if (t.isMemberExpression(expression) && t.isIdentifier(expression.property)) {
const { code } = generate(expression)
const { code } = generate(expression as any)
const ids = code.split('.')
if (ids[0] === 'this' && ids[1] === 'props' && ids[2]) {
methodName = code.replace('this.props.', '')
Expand Down