Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Fix value of reflectToAttribute for polymer properties #719

Merged
merged 2 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased

* Scan for CSS custom variable uses and assignments.
* Fix value of reflectToAttribute for polymer properties

## [2.2.2] - 2017-07-20

Expand Down
3 changes: 2 additions & 1 deletion src/polymer/analyze-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export function analyzeProperties(
prop.readOnly = !!astValue.expressionToValue(propertyArg.value);
break;
case 'reflectToAttribute':
prop.reflectToAttribute = !!astValue.expressionToValue(propertyArg);
prop.reflectToAttribute =
!!astValue.expressionToValue(propertyArg.value);
break;
case 'computed':
isComputed = true;
Expand Down
77 changes: 57 additions & 20 deletions src/test/polymer/polymer-element_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,34 @@ suite('PolymerElement', () => {
superClass: element.superClass && element.superClass.identifier,
tagName: element.tagName,
description: element.description,
properties:
Array.from(element.properties.values()).map((p) => ({
name: p.name,
inheritedFrom:
p.inheritedFrom,
})),
properties: Array.from(element.properties.values()).map((p) => {
const prop: {
name: string,
inheritedFrom?: string,
reflectToAttribute?: boolean,
readOnly?: boolean,
default?: string
} = {name: p.name, inheritedFrom: p.inheritedFrom};
p.reflectToAttribute &&
(prop.reflectToAttribute = p.reflectToAttribute);
p.readOnly && (prop.readOnly = p.readOnly);
p.default && (prop.default = p.default);
return prop;
}),
attributes: Array.from(element.attributes.values()).map((a) => ({
name: a.name,
})),
methods: Array.from(element.methods.values())
.map((m) => ({
name: m.name,
params: m.params, return: m.return,
inheritedFrom: m.inheritedFrom
})),
methods: Array.from(element.methods.values()).map((m) => ({
name: m.name,
params: m.params,
return: m.return,
inheritedFrom:
m.inheritedFrom
})),
};
}

test('Scans and resolves base and sub-class', async() => {
test('Scans and resolves base and sub-class', async () => {
const elements = await getElements('test-element-3.js');
const elementData = Array.from(elements).map(getTestProps);
assert.deepEqual(elementData, [
Expand Down Expand Up @@ -105,7 +114,31 @@ suite('PolymerElement', () => {
]);
});

test('Elements inherit from mixins and base classes', async() => {
test('Computes correct property information', async () => {
const elements = await getElements('test-element-17.js');
const elementData = Array.from(elements).map(getTestProps);
assert.deepEqual(elementData, [
{
tagName: undefined,
className: 'BaseElement',
superClass: 'Polymer.Element',
description: '',
properties: [{
name: 'foo',
inheritedFrom: undefined,
reflectToAttribute: true,
readOnly: true,
default: '"foo"'
}],
attributes: [{
name: 'foo',
}],
methods: [],
},
]);
});

test('Elements inherit from mixins and base classes', async () => {
const elements = await getElements('test-element-7.js');
const elementData = Array.from(elements).map(getTestProps);
assert.deepEqual(elementData, [
Expand Down Expand Up @@ -134,7 +167,8 @@ suite('PolymerElement', () => {
],
methods: [{
name: 'customMethodOnBaseElement',
params: [], return: undefined,
params: [],
return: undefined,
inheritedFrom: undefined
}],
},
Expand Down Expand Up @@ -185,17 +219,20 @@ suite('PolymerElement', () => {
methods: [
{
name: 'customMethodOnBaseElement',
params: [], return: undefined,
params: [],
return: undefined,
inheritedFrom: 'BaseElement'
},
{
name: 'customMethodOnMixin',
params: [], return: undefined,
params: [],
return: undefined,
inheritedFrom: 'Mixin'
},
{
name: 'customMethodOnSubElement',
params: [], return: undefined,
params: [],
return: undefined,
inheritedFrom: undefined
},
],
Expand All @@ -212,14 +249,14 @@ suite('PolymerElement', () => {
return [...elements][0]!;
}

test('Elements with only one doc comment have no warning', async() => {
test('Elements with only one doc comment have no warning', async () => {
const element = await getElement('test-element-14.html');
const warning = element.warnings.find(
(w: Warning) => w.code === 'multiple-doc-comments');
assert.isUndefined(warning);
});

test('Elements with more than one doc comment have warning', async() => {
test('Elements with more than one doc comment have warning', async () => {
const element = await getElement('test-element-15.html');
const warning = element.warnings.find(
(w: Warning) => w.code === 'multiple-doc-comments')!;
Expand Down
18 changes: 18 additions & 0 deletions src/test/static/polymer2/test-element-17.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @customElement
* @polymer
* @extends Polymer.Element
*/
class BaseElement extends Polymer.Element {
static get properties() {
return {
foo: {
notify: true,
type: String,
reflectToAttribute: true,
readOnly: true,
value: 'foo'
},
};
}
}