wx2
Version:
微信小程序 转换 百度小程序
33 lines (28 loc) • 745 B
JavaScript
/**
* 视图内容解析为ast
*
* @file 视图内容解析为ast
*/
;
const {isArray} = require('lodash');
const FAKE_ROOT = Symbol.for('fake-root');
const utils = require('..');
module.exports = function parse(options) {
options = options || {
xmlMode: false,
lowerCaseAttributeNames: false,
recognizeSelfClosing: true,
lowerCaseTags: false
};
this.Parser = parser;
function parser(doc) {
const {htmlParser, handler} = utils.getHtmlParser(options);
htmlParser.end(doc);
return {
type: 'tag',
name: FAKE_ROOT,
attribs: {},
children: isArray(handler.dom) ? handler.dom : [handler.dom]
};
}
};