UNPKG

8.45 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt
6 * The complete set of authors may be found at
7 * http://polymer.github.io/AUTHORS.txt
8 * The complete set of contributors may be found at
9 * http://polymer.github.io/CONTRIBUTORS.txt
10 * Code distributed by Google as part of the polymer project is also
11 * subject to an additional IP rights grant found at
12 * http://polymer.github.io/PATENTS.txt
13 */
14import * as babel from '@babel/types';
15import { ElementMixin } from '..';
16import * as jsdocLib from '../javascript/jsdoc';
17import { AstNodeWithLanguage, Document, Feature, Method, Privacy, Property, Resolvable, ScannedFeature, ScannedMethod, ScannedProperty, ScannedReference, SourceRange, Warning } from '../model/model';
18import { DeclaredWithStatement } from './document';
19import { Demo } from './element-base';
20import { ImmutableMap } from './immutable';
21/**
22 * Represents a JS class as encountered in source code.
23 *
24 * We only emit a ScannedClass when there's not a more specific kind of feature.
25 * Like, we don't emit a ScannedClass when we encounter an element or a mixin
26 * (though in the future those features will likely extend from
27 * ScannedClass/Class).
28 *
29 * TODO(rictic): currently there's a ton of duplicated code across the Class,
30 * Element, Mixin, PolymerElement, and PolymerMixin classes. We should
31 * really unify this stuff to a single representation and set of algorithms.
32 */
33export declare class ScannedClass implements ScannedFeature, Resolvable {
34 readonly name: string | undefined;
35 /** The name of the class in the local scope where it is defined. */
36 readonly localName: string | undefined;
37 readonly astNode: AstNodeWithLanguage;
38 readonly statementAst: babel.Statement | undefined;
39 readonly jsdoc: jsdocLib.Annotation;
40 readonly description: string;
41 readonly summary: string;
42 readonly sourceRange: SourceRange;
43 readonly properties: Map<string, ScannedProperty>;
44 readonly staticMethods: ImmutableMap<string, ScannedMethod>;
45 readonly methods: ImmutableMap<string, ScannedMethod>;
46 readonly constructorMethod?: ScannedMethod;
47 readonly superClass: ScannedReference<'class'> | undefined;
48 readonly mixins: ScannedReference<'element-mixin'>[];
49 readonly abstract: boolean;
50 readonly privacy: Privacy;
51 readonly warnings: Warning[];
52 readonly demos: Demo[];
53 constructor(className: string | undefined, localClassName: string | undefined, astNode: AstNodeWithLanguage, statementAst: babel.Statement | undefined, jsdoc: jsdocLib.Annotation, description: string, sourceRange: SourceRange, properties: Map<string, ScannedProperty>, methods: Map<string, ScannedMethod>, constructorMethod: ScannedMethod | undefined, staticMethods: Map<string, ScannedMethod>, superClass: ScannedReference<'class'> | undefined, mixins: Array<ScannedReference<'element-mixin'>>, privacy: Privacy, warnings: Warning[], abstract: boolean, demos: Demo[]);
54 resolve(document: Document): Feature | undefined;
55 /**
56 * Allows additional properties and methods
57 * to be added to the class after initialization.
58 * For example, members found attached to the
59 * prototype at a later place in the document
60 */
61 finishInitialization(methods: Map<string, ScannedMethod>, properties: Map<string, ScannedProperty>): void;
62}
63declare module '../model/queryable' {
64 interface FeatureKindMap {
65 'class': Class;
66 }
67}
68export interface ClassInit {
69 readonly sourceRange: SourceRange | undefined;
70 readonly astNode: AstNodeWithLanguage | undefined;
71 readonly statementAst: babel.Statement | undefined;
72 readonly warnings?: Warning[];
73 readonly summary: string;
74 readonly name?: string;
75 readonly className?: string;
76 readonly jsdoc?: jsdocLib.Annotation;
77 readonly description: string;
78 readonly properties?: ImmutableMap<string, Property>;
79 readonly staticMethods: ImmutableMap<string, Method>;
80 readonly methods?: ImmutableMap<string, Method>;
81 readonly constructorMethod?: Method;
82 readonly superClass?: ScannedReference<'class'> | undefined;
83 readonly mixins?: Array<ScannedReference<'element-mixin'>>;
84 readonly abstract: boolean;
85 readonly privacy: Privacy;
86 readonly demos?: Demo[];
87}
88export declare class Class implements Feature, DeclaredWithStatement {
89 readonly kinds: Set<string>;
90 readonly identifiers: Set<string>;
91 readonly sourceRange: SourceRange | undefined;
92 readonly astNode: AstNodeWithLanguage | undefined;
93 readonly statementAst: babel.Statement | undefined;
94 readonly warnings: Warning[];
95 readonly summary: string;
96 readonly name: string | undefined;
97 /**
98 * @deprecated use the `name` field instead.
99 */
100 readonly className: string | undefined;
101 readonly jsdoc: jsdocLib.Annotation | undefined;
102 description: string;
103 readonly properties: Map<string, Property>;
104 readonly methods: Map<string, Method>;
105 constructorMethod?: Method;
106 readonly staticMethods: Map<string, Method>;
107 readonly superClass: ScannedReference<'class'> | undefined;
108 /**
109 * Mixins that this class declares with `@mixes`.
110 *
111 * Mixins are applied linearly after the superclass, in order from first
112 * to last. Mixins that compose other mixins will be flattened into a
113 * single list. A mixin can be applied more than once, each time its
114 * members override those before it in the prototype chain.
115 */
116 readonly mixins: ReadonlyArray<ScannedReference<'element-mixin'>>;
117 readonly abstract: boolean;
118 readonly privacy: Privacy;
119 demos: Demo[];
120 private readonly _parsedDocument;
121 constructor(init: ClassInit, document: Document);
122 protected inheritFrom(superClass: Class): void;
123 /**
124 * This method is applied to an array of members to overwrite members lower in
125 * the prototype graph (closer to Object) with members higher up (closer to
126 * the final class we're constructing).
127 *
128 * @param . existing The array of members so far. N.B. *This param is
129 * mutated.*
130 * @param . overriding The array of members from this new, higher prototype in
131 * the graph
132 * @param . overridingClassName The name of the prototype whose members are
133 * being applied over the existing ones. Should be `undefined` when
134 * applyingSelf is true
135 * @param . applyingSelf True on the last call to this method, when we're
136 * applying the class's own local members.
137 */
138 protected _overwriteInherited<P extends PropertyLike>(existing: Map<string, P>, overriding: ImmutableMap<string, P>, overridingClassName: string | undefined, applyingSelf?: boolean): void;
139 /**
140 * This method is applied to a single member to overwrite members lower in
141 * the prototype graph (closer to Object) with members higher up (closer to
142 * the final class we're constructing).
143 *
144 * @param . existing The existin property on the class
145 * @param . overriding The array of members from this new, higher prototype in
146 * the graph
147 * @param . overridingClassName The name of the prototype whose members are
148 * being applied over the existing ones. Should be `undefined` when
149 * applyingSelf is true
150 * @param . applyingSelf True on the last call to this method, when we're
151 * applying the class's own local members.
152 */
153 protected _overwriteSingleInherited<P extends PropertyLike>(existing: P | undefined, overridingVal: P | undefined, overridingClassName: string | undefined): P | undefined;
154 /**
155 * Returns the elementLikes that make up this class's prototype chain.
156 *
157 * Should return them in the order that they're constructed in JS
158 * engine (i.e. closest to HTMLElement first, closest to `this` last).
159 */
160 protected _getSuperclassAndMixins(document: Document, _init: ClassInit): Class[];
161 protected _resolveReferenceToSuperClass(scannedReference: ScannedReference<'class' | 'element-mixin'> | undefined, document: Document): Class | ElementMixin | undefined;
162 emitMetadata(): object;
163 emitPropertyMetadata(_property: Property): object;
164 emitMethodMetadata(_method: Method): object;
165}
166export interface PropertyLike {
167 name: string;
168 sourceRange?: SourceRange;
169 inheritedFrom?: string;
170 privacy?: Privacy;
171}