Skip to content

Commit daf5276

Browse files
Add version global (#536)
* Add version global * format * Add .clang-format * Address review feedback * Remove trailing commas in imports * Add test * format
1 parent a7148bc commit daf5276

12 files changed

+845
-714
lines changed

.clang-format

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BasedOnStyle: Google
2+
AlignAfterOpenBracket: AlwaysBreak
3+
AllowAllParametersOfDeclarationOnNextLine: false
4+
AllowShortBlocksOnASingleLine: false
5+
AllowShortCaseLabelsOnASingleLine: false
6+
AllowShortFunctionsOnASingleLine: None
7+
AllowShortIfStatementsOnASingleLine: false
8+
AllowShortLoopsOnASingleLine: false
9+
BinPackArguments: false
10+
# This breaks async functions sometimes, see
11+
# https://github.com/Polymer/polymer-analyzer/pull/393
12+
# BinPackParameters: false

src/demo/ts-element.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {html, LitElement, property} from '../lit-element.js';
22

33
class TSElement extends LitElement {
4-
54
@property() message = 'Hi';
65

76
@property(
8-
{attribute : 'more-info', converter: (value: string) => `[${value}]`})
7+
{attribute: 'more-info', converter: (value: string) => `[${value}]`})
98
extra = '';
109

1110
render() {

src/env.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface ShadowRoot {
2020
adoptedStyleSheets: CSSStyleSheet[];
2121
}
2222

23-
declare var ShadowRoot: {prototype: ShadowRoot; new () : ShadowRoot;}
23+
declare var ShadowRoot: {prototype: ShadowRoot; new (): ShadowRoot;}
2424

2525
interface CSSStyleSheet {
2626
replaceSync(cssText: string): void;

src/lib/css-tag.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ found at http://polymer.github.io/PATENTS.txt
1010
*/
1111

1212
export const supportsAdoptingStyleSheets =
13-
('adoptedStyleSheets' in Document.prototype) && ('replace' in CSSStyleSheet.prototype);
13+
('adoptedStyleSheets' in Document.prototype) &&
14+
('replace' in CSSStyleSheet.prototype);
1415

1516
const constructionToken = Symbol();
1617

1718
export class CSSResult {
18-
1919
_styleSheet?: CSSStyleSheet|null;
2020

2121
readonly cssText: string;
2222

2323
constructor(cssText: string, safeToken: symbol) {
2424
if (safeToken !== constructionToken) {
25-
throw new Error('CSSResult is not constructable. Use `unsafeCSS` or `css` instead.');
25+
throw new Error(
26+
'CSSResult is not constructable. Use `unsafeCSS` or `css` instead.');
2627
}
2728
this.cssText = cssText;
2829
}
@@ -66,7 +67,7 @@ const textFromCSSResult = (value: CSSResult) => {
6667
throw new Error(
6768
`Value passed to 'css' function must be a 'css' function result: ${
6869
value}. Use 'unsafeCSS' to pass non-literal values, but
69-
take care to ensure page security.` );
70+
take care to ensure page security.`);
7071
}
7172
};
7273

@@ -76,10 +77,9 @@ const textFromCSSResult = (value: CSSResult) => {
7677
* used. To incorporate non-literal values `unsafeCSS` may be used inside a
7778
* template string part.
7879
*/
79-
export const css =
80-
(strings: TemplateStringsArray, ...values: CSSResult[]) => {
81-
const cssText = values.reduce(
82-
(acc, v, idx) => acc + textFromCSSResult(v) + strings[idx + 1],
83-
strings[0]);
84-
return new CSSResult(cssText, constructionToken);
85-
};
80+
export const css = (strings: TemplateStringsArray, ...values: CSSResult[]) => {
81+
const cssText = values.reduce(
82+
(acc, v, idx) => acc + textFromCSSResult(v) + strings[idx + 1],
83+
strings[0]);
84+
return new CSSResult(cssText, constructionToken);
85+
};

src/lib/decorators.ts

+52-46
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ const standardCustomElement =
6868
*
6969
* @param tagName the name of the custom element to define
7070
*/
71-
export const customElement = (tagName: string) => (
72-
classOrDescriptor: Constructor<HTMLElement>|ClassDescriptor) =>
73-
(typeof classOrDescriptor === 'function')
74-
? legacyCustomElement(tagName,
75-
classOrDescriptor as Constructor<HTMLElement>)
76-
: standardCustomElement(tagName, classOrDescriptor as ClassDescriptor);
71+
export const customElement = (tagName: string) =>
72+
(classOrDescriptor: Constructor<HTMLElement>|ClassDescriptor) =>
73+
(typeof classOrDescriptor === 'function') ?
74+
legacyCustomElement(
75+
tagName, classOrDescriptor as Constructor<HTMLElement>) :
76+
standardCustomElement(tagName, classOrDescriptor as ClassDescriptor);
7777

7878
const standardProperty =
7979
(options: PropertyDeclaration, element: ClassElement) => {
@@ -93,10 +93,10 @@ const standardProperty =
9393
// must return some kind of descriptor, so return a descriptor for an
9494
// unused prototype field. The finisher calls createProperty().
9595
return {
96-
kind : 'field',
97-
key : Symbol(),
98-
placement : 'own',
99-
descriptor : {},
96+
kind: 'field',
97+
key: Symbol(),
98+
placement: 'own',
99+
descriptor: {},
100100
// When @babel/plugin-proposal-decorators implements initializers,
101101
// do this instead of the initializer below. See:
102102
// https://github.com/babel/babel/issues/9260 extras: [
@@ -118,10 +118,11 @@ const standardProperty =
118118
}
119119
};
120120

121-
const legacyProperty = (options: PropertyDeclaration, proto: Object,
122-
name: PropertyKey) => {
123-
(proto.constructor as typeof UpdatingElement).createProperty(name!, options);
124-
};
121+
const legacyProperty =
122+
(options: PropertyDeclaration, proto: Object, name: PropertyKey) => {
123+
(proto.constructor as typeof UpdatingElement)
124+
.createProperty(name!, options);
125+
};
125126

126127
/**
127128
* A property decorator which creates a LitElement property which reflects a
@@ -132,35 +133,36 @@ const legacyProperty = (options: PropertyDeclaration, proto: Object,
132133
*/
133134
export function property(options?: PropertyDeclaration) {
134135
return (protoOrDescriptor: Object|ClassElement, name?: PropertyKey): any =>
135-
(name !== undefined)
136-
? legacyProperty(options!, protoOrDescriptor as Object, name)
137-
: standardProperty(options!,
138-
protoOrDescriptor as ClassElement);
136+
(name !== undefined) ?
137+
legacyProperty(options!, protoOrDescriptor as Object, name) :
138+
standardProperty(options!, protoOrDescriptor as ClassElement);
139139
}
140140

141141
/**
142142
* A property decorator that converts a class property into a getter that
143143
* executes a querySelector on the element's renderRoot.
144144
*/
145-
export const query = _query((target: NodeSelector, selector: string) =>
146-
target.querySelector(selector));
145+
export const query = _query(
146+
(target: NodeSelector, selector: string) => target.querySelector(selector));
147147

148148
/**
149149
* A property decorator that converts a class property into a getter
150150
* that executes a querySelectorAll on the element's renderRoot.
151151
*/
152-
export const queryAll = _query((target: NodeSelector, selector: string) =>
153-
target.querySelectorAll(selector));
152+
export const queryAll = _query(
153+
(target: NodeSelector, selector: string) =>
154+
target.querySelectorAll(selector));
154155

155156
const legacyQuery =
156-
(descriptor: PropertyDescriptor, proto: Object,
157-
name: PropertyKey) => { Object.defineProperty(proto, name, descriptor); };
157+
(descriptor: PropertyDescriptor, proto: Object, name: PropertyKey) => {
158+
Object.defineProperty(proto, name, descriptor);
159+
};
158160

159161
const standardQuery = (descriptor: PropertyDescriptor, element: ClassElement) =>
160162
({
161-
kind : 'method',
162-
placement : 'prototype',
163-
key : element.key,
163+
kind: 'method',
164+
placement: 'prototype',
165+
key: element.key,
164166
descriptor,
165167
});
166168

@@ -173,33 +175,37 @@ const standardQuery = (descriptor: PropertyDescriptor, element: ClassElement) =>
173175
* element.
174176
*/
175177
function _query<T>(queryFn: (target: NodeSelector, selector: string) => T) {
176-
return (selector: string) => (protoOrDescriptor: Object|ClassElement,
177-
name?: PropertyKey): any => {
178-
const descriptor = {
179-
get(this: LitElement) { return queryFn(this.renderRoot!, selector); },
180-
enumerable : true,
181-
configurable : true,
182-
};
183-
return (name !== undefined)
184-
? legacyQuery(descriptor, protoOrDescriptor as Object, name)
185-
: standardQuery(descriptor, protoOrDescriptor as ClassElement);
186-
};
178+
return (selector: string) =>
179+
(protoOrDescriptor: Object|ClassElement,
180+
name?: PropertyKey): any => {
181+
const descriptor = {
182+
get(this: LitElement) {
183+
return queryFn(this.renderRoot!, selector);
184+
},
185+
enumerable: true,
186+
configurable: true,
187+
};
188+
return (name !== undefined) ?
189+
legacyQuery(descriptor, protoOrDescriptor as Object, name) :
190+
standardQuery(descriptor, protoOrDescriptor as ClassElement);
191+
};
187192
}
188193

189194
const standardEventOptions =
190195
(options: AddEventListenerOptions, element: ClassElement) => {
191196
return {
192197
...element,
193198
finisher(clazz: typeof UpdatingElement) {
194-
Object.assign(clazz.prototype[element.key as keyof UpdatingElement],
195-
options);
199+
Object.assign(
200+
clazz.prototype[element.key as keyof UpdatingElement], options);
196201
}
197202
};
198203
};
199204

200205
const legacyEventOptions =
201-
(options: AddEventListenerOptions, proto: any,
202-
name: PropertyKey) => { Object.assign(proto[name], options); };
206+
(options: AddEventListenerOptions, proto: any, name: PropertyKey) => {
207+
Object.assign(proto[name], options);
208+
};
203209

204210
/**
205211
* Adds event listener options to a method used as an event listener in a
@@ -234,7 +240,7 @@ export const eventOptions = (options: AddEventListenerOptions) =>
234240
// TODO(kschaaf): unclear why it was only failing on this decorator and not
235241
// the others
236242
((protoOrDescriptor: Object|ClassElement, name?: string) =>
237-
(name !== undefined)
238-
? legacyEventOptions(options, protoOrDescriptor as Object, name)
239-
: standardEventOptions(options,
240-
protoOrDescriptor as ClassElement)) as any;
243+
(name !== undefined) ?
244+
legacyEventOptions(options, protoOrDescriptor as Object, name) :
245+
standardEventOptions(options, protoOrDescriptor as ClassElement)) as
246+
any;

0 commit comments

Comments
 (0)