UNPKG

3.86 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt
7 * The complete set of authors may be found at
8 * http://polymer.github.io/AUTHORS.txt
9 * The complete set of contributors may be found at
10 * http://polymer.github.io/CONTRIBUTORS.txt
11 * Code distributed by Google as part of the polymer project is also
12 * subject to an additional IP rights grant found at
13 * http://polymer.github.io/PATENTS.txt
14 */
15var __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};
23Object.defineProperty(exports, "__esModule", { value: true });
24const dom5 = require("dom5/lib/index-next");
25const esutil_1 = require("../javascript/esutil");
26const jsdoc = require("../javascript/jsdoc");
27const docs_1 = require("./docs");
28const polymer_element_1 = require("./polymer-element");
29/**
30 * A Polymer pseudo-element is an element that is declared in an unusual way,
31 * such
32 * that the analyzer couldn't normally analyze it, so instead it is declared in
33 * comments.
34 */
35class PseudoElementScanner {
36 scan(document, visit) {
37 return __awaiter(this, void 0, void 0, function* () {
38 const elements = [];
39 yield visit((node) => {
40 if (dom5.isCommentNode(node) && node.data &&
41 node.data.includes('@pseudoElement')) {
42 const parsedJsdoc = jsdoc.parseJsdoc(node.data);
43 const pseudoTag = jsdoc.getTag(parsedJsdoc, 'pseudoElement');
44 const tagName = pseudoTag && pseudoTag.name;
45 if (tagName) {
46 const element = new polymer_element_1.ScannedPolymerElement({
47 astNode: { language: 'html', node, containingDocument: document },
48 statementAst: undefined,
49 tagName: tagName,
50 jsdoc: parsedJsdoc,
51 description: parsedJsdoc.description,
52 sourceRange: document.sourceRangeForNode(node),
53 privacy: esutil_1.getOrInferPrivacy(tagName, parsedJsdoc),
54 abstract: jsdoc.hasTag(parsedJsdoc, 'abstract'),
55 properties: [],
56 attributes: new Map(),
57 events: new Map(),
58 listeners: [],
59 behaviors: [],
60 className: undefined,
61 extends: undefined,
62 staticMethods: new Map(),
63 methods: new Map(),
64 mixins: [],
65 observers: [],
66 superClass: undefined,
67 isLegacyFactoryCall: false,
68 });
69 element.pseudo = true;
70 docs_1.annotateElementHeader(element);
71 elements.push(element);
72 }
73 }
74 });
75 return { features: elements };
76 });
77 }
78}
79exports.PseudoElementScanner = PseudoElementScanner;
80//# sourceMappingURL=pseudo-element-scanner.js.map
\No newline at end of file