Skip to content

Commit

Permalink
feat(taroize): 支持 wxParse 的 alias 写法
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Dec 3, 2018
1 parent 146e6c6 commit 3f95b44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/taroize/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ export function parseScript (
if (componentType !== 'App') {
classDecl.decorators = [buildDecorator(componentType)]
}
path.insertAfter(t.exportDefaultDeclaration(t.identifier(defaultClassName)))
ast.program.body.push(
classDecl,
t.exportDefaultDeclaration(t.identifier(componentType !== 'App' ? defaultClassName : 'App'))
)
// path.insertAfter(t.exportDefaultDeclaration(t.identifier(defaultClassName)))
path.remove()
}
}
Expand Down
11 changes: 9 additions & 2 deletions packages/taroize/src/wxml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,22 @@ function parseContent (content: string) {

function parseAttribute (attr: Attribute) {
const { key, value } = attr

let jsxValue: null | t.JSXExpressionContainer | t.StringLiteral = null

if (value) {
const { type, content } = parseContent(value)
let expr: t.Expression
if (content.includes(':') && content.startsWith('(') && content.endsWith(')')) {
const [ key, value ] = content.slice(1, content.length - 1).split(':')
expr = t.objectExpression([t.objectProperty(t.stringLiteral(key), buildTemplate(value))])
}
if (!expr!) {
expr = buildTemplate(content)
}
jsxValue =
type === 'raw'
? t.stringLiteral(content)
: t.jSXExpressionContainer(buildTemplate(content))
: t.jSXExpressionContainer(expr!)
}

const jsxKey = handleAttrKey(key)
Expand Down

0 comments on commit 3f95b44

Please sign in to comment.