UNPKG

6.78 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 * as dom5 from 'dom5/lib/index-next';
16import { Annotation as JsDocAnnotation } from '../javascript/jsdoc';
17import { ImmutableArray } from '../model/immutable';
18import { AstNodeWithLanguage, Class, Document, Element, ElementBase, LiteralValue, Privacy, Property, ScannedAttribute, ScannedElement, ScannedElementBase, ScannedEvent, ScannedMethod, ScannedProperty, SourceRange, Warning } from '../model/model';
19import { ScannedReference } from '../model/reference';
20import { Behavior } from './behavior';
21import { JavascriptDatabindingExpression } from './expression-scanner';
22export interface BasePolymerProperty {
23 published?: boolean;
24 notify?: boolean;
25 observer?: string;
26 observerNode?: babel.Expression | babel.Pattern;
27 observerExpression?: JavascriptDatabindingExpression;
28 reflectToAttribute?: boolean;
29 computedExpression?: JavascriptDatabindingExpression;
30 /**
31 * True if the property is part of Polymer's element configuration syntax.
32 *
33 * e.g. 'properties', 'is', 'extends', etc
34 */
35 isConfiguration?: boolean;
36 /**
37 * Constructor used when deserializing this property from an attribute.
38 */
39 attributeType?: string;
40}
41export interface ScannedPolymerProperty extends ScannedProperty, BasePolymerProperty {
42}
43export interface PolymerProperty extends Property, BasePolymerProperty {
44}
45export declare function mergePropertyDeclarations(propA: Readonly<ScannedPolymerProperty>, propB: Readonly<ScannedPolymerProperty>): ScannedPolymerProperty;
46export declare class LocalId {
47 name: string;
48 range: SourceRange;
49 nodeName: string;
50 constructor(name: string, range: SourceRange, nodeName: string);
51}
52export interface Observer {
53 javascriptNode: babel.Expression | babel.SpreadElement;
54 expression: LiteralValue;
55 parsedExpression: JavascriptDatabindingExpression | undefined;
56}
57export interface Options {
58 tagName: string | undefined;
59 className: string | undefined;
60 superClass: ScannedReference<'class'> | undefined;
61 mixins: ScannedReference<'element-mixin'>[];
62 extends: string | undefined;
63 jsdoc: JsDocAnnotation;
64 description: string | undefined;
65 properties: ScannedProperty[];
66 methods: Map<string, ScannedMethod>;
67 staticMethods: Map<string, ScannedMethod>;
68 attributes: Map<string, ScannedAttribute>;
69 observers: Observer[];
70 listeners: {
71 event: string;
72 handler: string;
73 }[];
74 behaviors: ScannedReference<'behavior'>[];
75 events: Map<string, ScannedEvent>;
76 abstract: boolean;
77 privacy: Privacy;
78 astNode: AstNodeWithLanguage;
79 statementAst: babel.Statement | undefined;
80 sourceRange: SourceRange | undefined;
81 /** true iff element was defined using the legacy Polymer() function. */
82 isLegacyFactoryCall: boolean | undefined;
83}
84export interface ScannedPolymerExtension extends ScannedElementBase {
85 properties: Map<string, ScannedPolymerProperty>;
86 methods: Map<string, ScannedMethod>;
87 observers: Observer[];
88 listeners: {
89 event: string;
90 handler: string;
91 }[];
92 behaviorAssignments: ScannedReference<'behavior'>[];
93 pseudo: boolean;
94 addProperty(prop: ScannedPolymerProperty): void;
95}
96export declare function addProperty(target: ScannedPolymerExtension, prop: ScannedPolymerProperty): void;
97export declare function addMethod(target: ScannedPolymerExtension, method: ScannedMethod): void;
98export declare function addStaticMethod(target: ScannedPolymerExtension, method: ScannedMethod): void;
99/**
100 * The metadata for a single polymer element
101 */
102export declare class ScannedPolymerElement extends ScannedElement implements ScannedPolymerExtension {
103 properties: Map<string, ScannedPolymerProperty>;
104 methods: Map<string, ScannedMethod>;
105 staticMethods: Map<string, ScannedMethod>;
106 observers: Observer[];
107 listeners: {
108 event: string;
109 handler: string;
110 }[];
111 behaviorAssignments: ScannedReference<'behavior'>[];
112 pseudo: boolean;
113 abstract: boolean;
114 isLegacyFactoryCall: boolean;
115 constructor(options: Options);
116 addProperty(prop: ScannedPolymerProperty): void;
117 addMethod(method: ScannedMethod): void;
118 addStaticMethod(method: ScannedMethod): void;
119 resolve(document: Document): PolymerElement;
120}
121export interface PolymerExtension extends ElementBase {
122 properties: Map<string, PolymerProperty>;
123 observers: ImmutableArray<{
124 javascriptNode: babel.Expression | babel.SpreadElement;
125 expression: LiteralValue;
126 parsedExpression: JavascriptDatabindingExpression | undefined;
127 }>;
128 listeners: ImmutableArray<{
129 event: string;
130 handler: string;
131 }>;
132 behaviorAssignments: ImmutableArray<ScannedReference<'behavior'>>;
133 localIds: ImmutableArray<LocalId>;
134 emitPropertyMetadata(property: PolymerProperty): any;
135}
136declare module '../model/queryable' {
137 interface FeatureKindMap {
138 'polymer-element': PolymerElement;
139 'pseudo-element': Element;
140 }
141}
142export declare class PolymerElement extends Element implements PolymerExtension {
143 readonly properties: Map<string, PolymerProperty>;
144 readonly observers: ImmutableArray<Observer>;
145 readonly listeners: ImmutableArray<{
146 event: string;
147 handler: string;
148 }>;
149 readonly behaviorAssignments: ImmutableArray<ScannedReference<'behavior'>>;
150 readonly domModule?: dom5.Node;
151 readonly localIds: ImmutableArray<LocalId>;
152 /** true iff element was defined using the legacy Polymer() function. */
153 readonly isLegacyFactoryCall: boolean;
154 constructor(scannedElement: ScannedPolymerElement, document: Document);
155 emitPropertyMetadata(property: PolymerProperty): {
156 polymer: {
157 notify: boolean | undefined;
158 observer: string | undefined;
159 readOnly: boolean | undefined;
160 attributeType: string | undefined;
161 };
162 };
163 protected _getSuperclassAndMixins(document: Document, init: ScannedPolymerElement): Class[];
164}
165export declare function getBehaviors(behaviorReferences: Iterable<ScannedReference<'behavior'>>, document: Document): {
166 warnings: Warning[];
167 behaviors: Behavior[];
168};