1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
16 | return new (P || (P = Promise))(function (resolve, reject) {
|
17 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
18 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
19 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
20 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
21 | });
|
22 | };
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | const dom5 = require("dom5/lib/index-next");
|
25 | const model_1 = require("../model/model");
|
26 | const p = dom5.predicates;
|
27 | const linkTag = p.hasTagName('link');
|
28 | const notCssLink = p.NOT(p.hasAttrValue('type', 'css'));
|
29 | const isHtmlImportNode = p.AND(linkTag, p.hasAttr('href'), p.hasSpaceSeparatedAttrValue('rel', 'import'), p.NOT(p.hasSpaceSeparatedAttrValue('rel', 'lazy-import')), notCssLink, p.NOT(p.parentMatches(p.hasTagName('template'))));
|
30 | const isLazyImportNode = p.AND(p.hasTagName('link'), p.hasSpaceSeparatedAttrValue('rel', 'lazy-import'), p.hasAttr('href'), p.NOT(p.hasSpaceSeparatedAttrValue('rel', 'import')), notCssLink, p.NOT(p.parentMatches(p.hasTagName('template'))));
|
31 |
|
32 |
|
33 |
|
34 | class HtmlImportScanner {
|
35 | constructor(_lazyEdges) {
|
36 | this._lazyEdges = _lazyEdges;
|
37 | }
|
38 | scan(document, visit) {
|
39 | return __awaiter(this, void 0, void 0, function* () {
|
40 | const imports = [];
|
41 | const type = 'html-import';
|
42 | yield visit((node) => {
|
43 | let lazy;
|
44 | if (isHtmlImportNode(node)) {
|
45 | lazy = false;
|
46 | }
|
47 | else if (isLazyImportNode(node)) {
|
48 | lazy = true;
|
49 | }
|
50 | else {
|
51 | return;
|
52 | }
|
53 | const href = dom5.getAttribute(node, 'href');
|
54 | imports.push(new model_1.ScannedImport(type, href, document.sourceRangeForNode(node), document.sourceRangeForAttributeValue(node, 'href'), { language: 'html', node, containingDocument: document }, lazy));
|
55 | });
|
56 | if (this._lazyEdges) {
|
57 | const edges = this._lazyEdges.get(document.url);
|
58 | if (edges) {
|
59 | for (const edge of edges) {
|
60 | imports.push(new model_1.ScannedImport(type,
|
61 |
|
62 | edge, undefined, undefined, undefined, true));
|
63 | }
|
64 | }
|
65 | }
|
66 | return { features: imports };
|
67 | });
|
68 | }
|
69 | }
|
70 | exports.HtmlImportScanner = HtmlImportScanner;
|
71 |
|
\ | No newline at end of file |