1 | "use strict";
|
2 | const parse5_1 = require("parse5");
|
3 | const _htmlSymbol = Symbol("HTML dependencies");
|
4 | function loader(content) {
|
5 | this.cacheable && this.cacheable();
|
6 | this._module[_htmlSymbol] = loader.modules(content);
|
7 | return content;
|
8 | }
|
9 | (function (loader) {
|
10 | loader.htmlSymbol = _htmlSymbol;
|
11 | loader.attributes = {
|
12 | "require": ["from"],
|
13 | "compose": ["view", "view-model"],
|
14 | "router-view": ["layout-view", "layout-view-model"],
|
15 | };
|
16 | function traverse(tree, cb) {
|
17 | tree.childNodes && tree.childNodes.forEach((n) => {
|
18 | const ne = n;
|
19 | ne.attrs && ne.attrs.forEach(attr => {
|
20 | cb(ne.tagName, attr);
|
21 | });
|
22 | if (ne.childNodes)
|
23 | traverse(ne, cb);
|
24 |
|
25 | if (n.content && n.content.childNodes)
|
26 | traverse(n.content, cb);
|
27 | });
|
28 | }
|
29 | function parse(html, cb) {
|
30 | const tree = (0, parse5_1.parseFragment)(html);
|
31 | const attrs = [];
|
32 | traverse(tree, (tag, attr) => {
|
33 | if (cb(tag, attr)) {
|
34 | attrs.push(attr);
|
35 | }
|
36 | });
|
37 | return attrs;
|
38 | }
|
39 | function modules(html) {
|
40 | return parse(html, (tag, attr) => {
|
41 | const attrs = loader.attributes[tag];
|
42 | return attrs && attrs.includes(attr.name);
|
43 | })
|
44 |
|
45 | .filter(attr => !/(^|[^\\])\$\{/.test(attr.value))
|
46 | .map(attr => attr.value);
|
47 | }
|
48 | loader.modules = modules;
|
49 | })(loader || (loader = {}));
|
50 | module.exports = loader;
|