UNPKG

4.21 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 doctrine = require("doctrine");
17const jsdoc = require("../javascript/jsdoc");
18// TODO(rictic): destroy this file with great abadon. It's the oldest and
19// hardest to understand in the repo at this point I think.
20// This is to prevent warnings that annotateProperty is unused.
21// It is unused, but we want to extract the good bits from this file
22// before we delete the whole thing.
23if (Math.random() > 1000) {
24 annotateProperty.name;
25}
26/**
27 * Annotates Hydrolysis scanned features, processing any descriptions as
28 * JSDoc.
29 *
30 * You probably want to use a more specialized version of this, such as
31 * `annotateElement`.
32 *
33 * Processed JSDoc values will be made available via the `jsdoc` property on a
34 * scanned feature.
35 */
36function annotate(feature) {
37 if (!feature || feature.jsdoc) {
38 return;
39 }
40 if (typeof feature.description === 'string') {
41 feature.jsdoc = jsdoc.parseJsdoc(feature.description);
42 // We want to present the normalized form of a feature.
43 feature.description = feature.jsdoc.description;
44 }
45 return;
46}
47exports.annotate = annotate;
48/**
49 * Annotates @event, @hero, & @demo tags
50 */
51function annotateElementHeader(scannedElement) {
52 scannedElement.demos = [];
53 if (scannedElement.jsdoc && scannedElement.jsdoc.tags) {
54 scannedElement.jsdoc.tags.forEach((tag) => {
55 switch (tag.title) {
56 case 'demo':
57 scannedElement.demos.push({
58 desc: 'demo',
59 path: (tag.description || 'demo/index.html')
60 });
61 break;
62 }
63 });
64 }
65}
66exports.annotateElementHeader = annotateElementHeader;
67/**
68 * Annotates event documentation
69 */
70function annotateEvent(annotation) {
71 const eventTag = jsdoc.getTag(annotation, 'event');
72 let name;
73 if (eventTag && eventTag.description) {
74 name = (eventTag.description || '').match(/^\S*/)[0];
75 }
76 else {
77 name = 'N/A';
78 }
79 const scannedEvent = {
80 name: name,
81 description: annotation.description || (eventTag && eventTag.description) ||
82 undefined,
83 jsdoc: annotation,
84 sourceRange: undefined,
85 astNode: undefined,
86 warnings: [],
87 params: []
88 };
89 const tags = (annotation && annotation.tags || []);
90 // process @params
91 scannedEvent.params.push(...tags.filter((tag) => tag.title === 'param').map((param) => {
92 return {
93 type: param.type ? doctrine.type.stringify(param.type) : 'N/A',
94 desc: param.description || '',
95 name: param.name || 'N/A'
96 };
97 }));
98 // process @params
99 return scannedEvent;
100}
101exports.annotateEvent = annotateEvent;
102/**
103 * Annotates documentation found about a scanned polymer property.
104 *
105 * @param feature
106 * @param ignoreConfiguration If true, `configuration` is not set.
107 * @return The descriptior that was given.
108 */
109function annotateProperty(feature) {
110 annotate(feature);
111 // @type JSDoc wins
112 const typeTag = jsdoc.getTag(feature.jsdoc, 'type');
113 if (typeTag !== undefined && typeTag.type != null) {
114 feature.type = doctrine.type.stringify(typeTag.type);
115 }
116 // @default JSDoc wins
117 const defaultTag = jsdoc.getTag(feature.jsdoc, 'default');
118 if (defaultTag !== undefined) {
119 const newDefault = (defaultTag.name || '') + (defaultTag.description || '');
120 if (newDefault !== '') {
121 feature.default = newDefault;
122 }
123 }
124 return feature;
125}
126//# sourceMappingURL=docs.js.map
\No newline at end of file