UNPKG

4.47 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2015 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 */
15Object.defineProperty(exports, "__esModule", { value: true });
16const jsdoc = require("../javascript/jsdoc");
17const class_1 = require("./class");
18const model_1 = require("./model");
19const warning_1 = require("./warning");
20/**
21 * Base class for ScannedElement and ScannedElementMixin.
22 */
23class ScannedElementBase {
24 constructor() {
25 this.properties = new Map();
26 this.attributes = new Map();
27 this.description = '';
28 this.summary = '';
29 this.demos = [];
30 this.events = new Map();
31 this.staticMethods = new Map();
32 this.methods = new Map();
33 this.astNode = undefined;
34 this.warnings = [];
35 this['slots'] = [];
36 this.mixins = [];
37 this.abstract = false;
38 this.superClass = undefined;
39 }
40 applyHtmlComment(commentText, containingDocument) {
41 if (commentText && containingDocument) {
42 const commentJsdoc = jsdoc.parseJsdoc(commentText);
43 // Add a Warning if there are already jsdoc tags or a description for this
44 // element.
45 if (this.sourceRange &&
46 (this.description || this.jsdoc && this.jsdoc.tags.length > 0)) {
47 this.warnings.push(new model_1.Warning({
48 severity: warning_1.Severity.WARNING,
49 code: 'multiple-doc-comments',
50 message: `${this.constructor.name} has both HTML doc and JSDoc comments.`,
51 sourceRange: this.sourceRange,
52 parsedDocument: containingDocument
53 }));
54 }
55 this.jsdoc =
56 this.jsdoc ? jsdoc.join(commentJsdoc, this.jsdoc) : commentJsdoc;
57 this.description = [
58 commentJsdoc.description || '',
59 this.description || ''
60 ].join('\n\n').trim();
61 }
62 }
63}
64exports.ScannedElementBase = ScannedElementBase;
65class Slot {
66 constructor(name, range, astNode) {
67 this.name = name;
68 this.range = range;
69 this.astNode = astNode;
70 }
71}
72exports.Slot = Slot;
73/**
74 * Base class for Element and ElementMixin.
75 */
76class ElementBase extends class_1.Class {
77 constructor(init, document) {
78 super(init, document);
79 this['slots'] = [];
80 this.template = undefined;
81 const { events, attributes, slots = [], } = init;
82 this.slots = Array.from(slots);
83 // Initialization of these attributes is kinda awkward, as they're part
84 // of the inheritance system. See `inheritFrom` below which *may* be
85 // called by our superclass, but may not be.
86 // tslint:disable-next-line: no-any
87 this.attributes = this.attributes || new Map();
88 // tslint:disable-next-line: no-any
89 this.events = this.events || new Map();
90 if (attributes !== undefined) {
91 this._overwriteInherited(this.attributes, attributes, undefined, true);
92 }
93 if (events !== undefined) {
94 this._overwriteInherited(this.events, events, undefined, true);
95 }
96 }
97 inheritFrom(superClass) {
98 // This may run as part of the call to the super constructor, so we need
99 // to validate initialization.
100 this.attributes = this.attributes || new Map();
101 this.events = this.events || new Map();
102 super.inheritFrom(superClass);
103 if (superClass instanceof ElementBase) {
104 this._overwriteInherited(this.attributes, superClass.attributes, superClass.name);
105 this._overwriteInherited(this.events, superClass.events, superClass.name);
106 }
107 // TODO(justinfagnani): slots, listeners, observers, dom-module?
108 // What actually inherits?
109 }
110 emitAttributeMetadata(_attribute) {
111 return {};
112 }
113 emitEventMetadata(_event) {
114 return {};
115 }
116}
117exports.ElementBase = ElementBase;
118//# sourceMappingURL=element-base.js.map
\No newline at end of file