Skip to content

Commit

Permalink
refactor(transformer): 转换前先格式化 wxml
Browse files Browse the repository at this point in the history
fix #4142
fix #3010
  • Loading branch information
yuche committed Aug 16, 2019
1 parent af495de commit e4a6f93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/taroize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"babel-types": "^6.26.0",
"babylon": "^6.18.0",
"himalaya-wxml": "^1.1.0",
"html": "^1.0.0",
"lodash": "^4.17.5",
"typescript": "^3.0.1"
},
Expand Down
9 changes: 9 additions & 0 deletions packages/taroize/src/wxml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { parseTemplate, parseModule } from './template'
import { usedComponents, errors, globals } from './global'
import { reserveKeyWords } from './constant'
import { parse as parseFile } from 'babylon'
const { prettyPrint } = require('html')

const allCamelCase = (str: string) =>
str.charAt(0).toUpperCase() + camelCase(str.substr(1))
Expand Down Expand Up @@ -298,6 +299,14 @@ export function parseWXML (dirPath: string, wxml?: string, parseImport?: boolean
imports: Imports[]
refIds: Set<string>
} {
try {
wxml = prettyPrint(wxml, {
max_char: 0,
unformatted: ['text']
})
} catch (error) {
//
}
if (!parseImport) {
errors.length = 0
usedComponents.clear()
Expand Down

0 comments on commit e4a6f93

Please sign in to comment.