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 parse5_1 = require("parse5");
|
26 | const model_1 = require("../model/model");
|
27 | const expression_scanner_1 = require("./expression-scanner");
|
28 | const polymer_element_1 = require("./polymer-element");
|
29 | const p = dom5.predicates;
|
30 | const isDomModule = p.hasTagName('dom-module');
|
31 | class ScannedDomModule {
|
32 | constructor(id, node, sourceRange, ast, warnings, template, slots, localIds, databindings) {
|
33 | this.warnings = [];
|
34 | this.id = id;
|
35 | this.node = node;
|
36 | this.comment = model_1.getAttachedCommentText(node);
|
37 | this.sourceRange = sourceRange;
|
38 | this.astNode = ast;
|
39 | this.slots = slots;
|
40 | this.localIds = localIds;
|
41 | this.warnings = warnings;
|
42 | this.template = template;
|
43 | this.databindings = databindings;
|
44 | }
|
45 | resolve() {
|
46 | return new DomModule(this.node, this.id, this.comment, this.sourceRange, this.astNode, this.warnings, this.slots, this.localIds, this.template, this.databindings);
|
47 | }
|
48 | }
|
49 | exports.ScannedDomModule = ScannedDomModule;
|
50 | class DomModule {
|
51 | constructor(node, id, comment, sourceRange, ast, warnings, slots, localIds, template, databindings) {
|
52 | this.kinds = new Set(['dom-module']);
|
53 | this.identifiers = new Set();
|
54 | this.node = node;
|
55 | this.id = id;
|
56 | this.comment = comment;
|
57 | if (id) {
|
58 | this.identifiers.add(id);
|
59 | }
|
60 | this.sourceRange = sourceRange;
|
61 | this.astNode = ast;
|
62 | this.warnings = warnings;
|
63 | this.slots = slots;
|
64 | this.localIds = localIds;
|
65 | this.template = template;
|
66 | this.databindings = databindings;
|
67 | }
|
68 | }
|
69 | exports.DomModule = DomModule;
|
70 | class DomModuleScanner {
|
71 | scan(document, visit) {
|
72 | return __awaiter(this, void 0, void 0, function* () {
|
73 | const domModules = [];
|
74 | yield visit((node) => {
|
75 | if (isDomModule(node)) {
|
76 | const children = dom5.defaultChildNodes(node) || [];
|
77 | const template = children.find(dom5.predicates.hasTagName('template'));
|
78 | let slots = [];
|
79 | let localIds = [];
|
80 | let databindings = [];
|
81 | let warnings = [];
|
82 | if (template) {
|
83 | const templateContent = parse5_1.treeAdapters.default.getTemplateContent(template);
|
84 | slots = [...dom5.queryAll(templateContent, dom5.predicates.hasTagName('slot'))]
|
85 | .map((s) => new model_1.Slot(dom5.getAttribute(s, 'name') || '', document.sourceRangeForNode(s), {
|
86 | language: 'html',
|
87 | node: s,
|
88 | containingDocument: document
|
89 | }));
|
90 | localIds =
|
91 | [...dom5.queryAll(templateContent, dom5.predicates.hasAttr('id'))]
|
92 | .map((e) => new polymer_element_1.LocalId(dom5.getAttribute(e, 'id'), document.sourceRangeForNode(e), e.nodeName));
|
93 | const results = expression_scanner_1.scanDatabindingTemplateForExpressions(document, template);
|
94 | warnings = results.warnings;
|
95 | databindings = results.expressions;
|
96 | }
|
97 | domModules.push(new ScannedDomModule(dom5.getAttribute(node, 'id'), node, document.sourceRangeForNode(node), { language: 'html', node, containingDocument: document }, warnings, template, slots, localIds, databindings));
|
98 | }
|
99 | });
|
100 | return { features: domModules };
|
101 | });
|
102 | }
|
103 | }
|
104 | exports.DomModuleScanner = DomModuleScanner;
|
105 |
|
\ | No newline at end of file |