(html, options)
| 7 | const empty = Object.create(null) |
| 8 | |
| 9 | export default function parse(html, options) { |
| 10 | options || (options = {}) |
| 11 | options.components || (options.components = empty) |
| 12 | const result = [] |
| 13 | const arr = [] |
| 14 | let current |
| 15 | let level = -1 |
| 16 | let inComponent = false |
| 17 | |
| 18 | // handle text at top level |
| 19 | if (html.indexOf('<') !== 0) { |
| 20 | var end = html.indexOf('<') |
| 21 | result.push({ |
| 22 | type: 'text', |
| 23 | content: end === -1 ? html : html.substring(0, end), |
| 24 | }) |
| 25 | } |
| 26 | |
| 27 | html.replace(tagRE, function (tag, index) { |
| 28 | if (inComponent) { |
| 29 | if (tag !== '</' + current.name + '>') { |
| 30 | return |
| 31 | } else { |
| 32 | inComponent = false |
| 33 | } |
| 34 | } |
| 35 | const isOpen = tag.charAt(1) !== '/' |
| 36 | const isComment = tag.startsWith('<!--') |
| 37 | const start = index + tag.length |
| 38 | const nextChar = html.charAt(start) |
| 39 | let parent |
| 40 | |
| 41 | if (isComment) { |
| 42 | const comment = parseTag(tag) |
| 43 | |
| 44 | // if we're at root, push new base node |
| 45 | if (level < 0) { |
| 46 | result.push(comment) |
| 47 | return result |
| 48 | } |
| 49 | parent = arr[level] |
| 50 | parent.children.push(comment) |
| 51 | return result |
| 52 | } |
| 53 | |
| 54 | if (isOpen) { |
| 55 | level++ |
| 56 | |
| 57 | current = parseTag(tag) |
| 58 | if (current.type === 'tag' && options.components[current.name]) { |
| 59 | current.type = 'component' |
| 60 | inComponent = true |
| 61 | } |
| 62 | |
| 63 | if ( |
| 64 | !current.voidElement && |
| 65 | !inComponent && |
| 66 | nextChar && |
no outgoing calls
no test coverage detected
searching dependent graphs…