Skip to content

Commit

Permalink
feat(taroize): json/script/wxml 均可传空值
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche authored and luckyadam committed Nov 19, 2018
1 parent 0dadefa commit 902c697
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/taroize/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { parseJSON } from './json'

interface Option {
json?: string,
script: string,
wxml: string
script?: string,
wxml?: string
}

export function parse (option: Option): t.File {
Expand Down
3 changes: 2 additions & 1 deletion packages/taroize/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { buildImportStatement, codeFrameError } from './utils'
import { usedComponents } from './wxml'
import { PageLifecycle } from './lifecycle'

export function parseScript (script: string, returned: t.Expression, json?: t.ObjectExpression) {
export function parseScript (script?: string, returned?: t.Expression, json?: t.ObjectExpression) {
script = script || 'Page({})'
const { ast } = transform(script, {
parserOpts: {
sourceType: 'module',
Expand Down
5 changes: 4 additions & 1 deletion packages/taroize/src/wxml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ function buildElement (

export const usedComponents = new Set<string>()

export function parseWXML (wxml: string) {
export function parseWXML (wxml?: string) {
if (!wxml) {
return t.nullLiteral()
}
const nodes = removEmptyTextAndComment(parse(wxml.trim()))
const ast = t.file(t.program([t.expressionStatement(parseNode(buildElement('block', nodes)) as t.Expression)], []))

Expand Down

0 comments on commit 902c697

Please sign in to comment.