Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Also add @nocollapse to all of our static methods and properties, because we never want static property collapsing on these methods.
  • Loading branch information
rictic committed Apr 22, 2019
1 parent 07f1e19 commit cc7702b
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 11 deletions.
9 changes: 7 additions & 2 deletions lib/legacy/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function flattenBehaviors(behaviors, list, exclude) {
* Copies property descriptors from source to target, overwriting all fields
* of any previous descriptor for a property *except* for `value`, which is
* merged in from the target if it does not exist on the source.
*
*
* @param {*} target Target properties object
* @param {*} source Source properties object
*/
Expand Down Expand Up @@ -215,10 +215,13 @@ function GenerateClassFromInfo(info, Base, behaviors) {
class PolymerGenerated extends Base {

// explicitly not calling super._finalizeClass
/** @nocollapse */
static _finalizeClass() {
// if calling via a subclass that hasn't been generated, pass through to super
if (!this.hasOwnProperty(JSCompiler_renameProperty('generatedFrom', this))) {
super._finalizeClass();
// TODO(https://github.com/google/closure-compiler/issues/3240):
// Change back to just super.methodCall()
Base._finalizeClass.call(this);
} else {
// interleave properties and observers per behavior and `info`
if (behaviorList) {
Expand All @@ -243,6 +246,7 @@ function GenerateClassFromInfo(info, Base, behaviors) {
}
}

/** @nocollapse */
static get properties() {
const properties = {};
if (behaviorList) {
Expand All @@ -254,6 +258,7 @@ function GenerateClassFromInfo(info, Base, behaviors) {
return properties;
}

/** @nocollapse */
static get observers() {
let observers = [];
if (behaviorList) {
Expand Down
8 changes: 6 additions & 2 deletions lib/legacy/legacy-data-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const LegacyDataMixin = dedupingMixin(superClass => {
// undefined or not. Multi-property observers must have all arguments defined
if (this._legacyUndefinedCheck && vals.length > 1) {
for (let i=0; i<vals.length; i++) {
if (vals[i] === undefined ||
if (vals[i] === undefined ||
(args[i].wildcard && vals[i].base === undefined)) {
// Break out of effect's control flow; will be caught in
// wrapped property effect function below
Expand Down Expand Up @@ -130,9 +130,13 @@ export const LegacyDataMixin = dedupingMixin(superClass => {
* @param {Object=} effect Effect metadata object
* @return {void}
* @protected
* @nocollapse
*/
static _addTemplatePropertyEffect(templateInfo, prop, effect) {
return super._addTemplatePropertyEffect(templateInfo, prop, wrapEffect(effect));
// TODO(https://github.com/google/closure-compiler/issues/3240):
// Change back to just super.methodCall()
return superClass._addTemplatePropertyEffect.call(
this, templateInfo, prop, wrapEffect(effect));
}

}
Expand Down
1 change: 1 addition & 0 deletions lib/legacy/legacy-element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
* @return {!Object} The `import.meta` object set on the prototype
* @suppress {missingProperties} `this` is always in the instance in
* closure for some reason even in a static method, rather than the class
* @nocollapse
*/
static get importMeta() {
return this.prototype.importMeta;
Expand Down
6 changes: 5 additions & 1 deletion lib/mixins/dir-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ export const DirMixin = dedupingMixin((base) => {
* @param {string} baseURI .
* @return {string} .
* @suppress {missingProperties} Interfaces in closure do not inherit statics, but classes do
* @nocollapse
*/
static _processStyleText(cssText, baseURI) {
cssText = super._processStyleText(cssText, baseURI);
// TODO(https://github.com/google/closure-compiler/issues/3240):
// Change back to just super.methodCall()
cssText = elementBase._processStyleText.call(this, cssText, baseURI);
if (!SHIM_SHADOW && DIR_CHECK.test(cssText)) {
cssText = this._replaceDirInCssText(cssText);
this.__activateDir = true;
Expand All @@ -128,6 +131,7 @@ export const DirMixin = dedupingMixin((base) => {
*
* @param {string} text CSS text to replace DIR
* @return {string} Modified CSS
* @nocollapse
*/
static _replaceDirInCssText(text) {
let replacedText = text;
Expand Down
25 changes: 22 additions & 3 deletions lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ export const ElementMixin = dedupingMixin(base => {
/**
* Current Polymer version in Semver notation.
* @type {string} Semver notation of the current version of Polymer.
* @nocollapse
*/
static get polymerElementVersion() {
return version;
Expand All @@ -340,16 +341,20 @@ export const ElementMixin = dedupingMixin(base => {
* @return {void}
* @protected
* @suppress {missingProperties} Interfaces in closure do not inherit statics, but classes do
* @nocollapse
*/
static _finalizeClass() {
super._finalizeClass();
// TODO(https://github.com/google/closure-compiler/issues/3240):
// Change back to just super.methodCall()
polymerElementBase._finalizeClass.call(this);
const observers = ownObservers(this);
if (observers) {
this.createObservers(observers, this._properties);
}
this._prepareTemplate();
}

/** @nocollapse */
static _prepareTemplate() {
// note: create "working" template that is finalized at instance time
let template = /** @type {PolymerElementConstructor} */ (this).template;
Expand All @@ -371,6 +376,7 @@ export const ElementMixin = dedupingMixin(base => {
* @param {!Object} props .
* @return {void}
* @protected
* @nocollapse
*/
static createProperties(props) {
for (let p in props) {
Expand All @@ -388,6 +394,7 @@ export const ElementMixin = dedupingMixin(base => {
* reference is changed
* @return {void}
* @protected
* @nocollapse
*/
static createObservers(observers, dynamicFns) {
const proto = this.prototype;
Expand Down Expand Up @@ -431,6 +438,7 @@ export const ElementMixin = dedupingMixin(base => {
* }
*
* @return {!HTMLTemplateElement|string} Template to be stamped
* @nocollapse
*/
static get template() {
// Explanation of template-related properties:
Expand Down Expand Up @@ -488,6 +496,7 @@ export const ElementMixin = dedupingMixin(base => {
*
* @return {string} The import path for this element class
* @suppress {missingProperties}
* @nocollapse
*/
static get importPath() {
if (!this.hasOwnProperty(JSCompiler_renameProperty('_importPath', this))) {
Expand Down Expand Up @@ -572,6 +581,7 @@ export const ElementMixin = dedupingMixin(base => {
* @param {string} baseURI Base URI to rebase CSS paths against
* @return {string} The processed CSS text
* @protected
* @nocollapse
*/
static _processStyleText(cssText, baseURI) {
return resolveCss(cssText, baseURI);
Expand All @@ -585,6 +595,7 @@ export const ElementMixin = dedupingMixin(base => {
* @param {string} is Tag name (or type extension name) for this element
* @return {void}
* @protected
* @nocollapse
*/
static _finalizeTemplate(is) {
/** @const {HTMLTemplateElement} */
Expand Down Expand Up @@ -751,10 +762,14 @@ export const ElementMixin = dedupingMixin(base => {
* @param {!NodeInfo} nodeInfo Node metadata for current template.
* @return {boolean} .
* @suppress {missingProperties} Interfaces in closure do not inherit statics, but classes do
* @nocollapse
*/
static _parseTemplateContent(template, templateInfo, nodeInfo) {
templateInfo.dynamicFns = templateInfo.dynamicFns || this._properties;
return super._parseTemplateContent(template, templateInfo, nodeInfo);
// TODO(https://github.com/google/closure-compiler/issues/3240):
// Change back to just super.methodCall()
return polymerElementBase._parseTemplateContent.call(
this, template, templateInfo, nodeInfo);
}

/**
Expand All @@ -767,6 +782,7 @@ export const ElementMixin = dedupingMixin(base => {
* @return {void}
* @protected
* @suppress {missingProperties} Interfaces in closure do not inherit statics, but classes do
* @nocollapse
*/
static _addTemplatePropertyEffect(templateInfo, prop, effect) {
// Warn if properties are used in template without being declared.
Expand All @@ -781,7 +797,10 @@ export const ElementMixin = dedupingMixin(base => {
console.warn(`Property '${prop}' used in template but not declared in 'properties'; ` +
`attribute will not be observed.`);
}
return super._addTemplatePropertyEffect(templateInfo, prop, effect);
// TODO(https://github.com/google/closure-compiler/issues/3240):
// Change back to just super.methodCall()
return polymerElementBase._addTemplatePropertyEffect.call(
this, templateInfo, prop, effect);
}

}
Expand Down
1 change: 1 addition & 0 deletions lib/mixins/mutable-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export const OptionalMutableData = dedupingMixin(superClass => {
*/
class OptionalMutableData extends superClass {

/** @nocollapse */
static get properties() {
return {
/**
Expand Down
3 changes: 3 additions & 0 deletions lib/mixins/properties-changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const PropertiesChanged = dedupingMixin(
* @param {!Object} props Object whose keys are names of accessors.
* @return {void}
* @protected
* @nocollapse
*/
static createProperties(props) {
const proto = this.prototype;
Expand All @@ -74,6 +75,7 @@ export const PropertiesChanged = dedupingMixin(
* @return {string} Attribute name corresponding to the given property.
*
* @protected
* @nocollapse
*/
static attributeNameForProperty(property) {
return property.toLowerCase();
Expand All @@ -85,6 +87,7 @@ export const PropertiesChanged = dedupingMixin(
* @param {string} name Name of property
*
* @protected
* @nocollapse
*/
static typeForProperty(name) { } //eslint-disable-line no-unused-vars

Expand Down
5 changes: 5 additions & 0 deletions lib/mixins/properties-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const PropertiesMixin = dedupingMixin(superClass => {
* Implements standard custom elements getter to observes the attributes
* listed in `properties`.
* @suppress {missingProperties} Interfaces in closure do not inherit statics, but classes do
* @nocollapse
*/
static get observedAttributes() {
if (!this.hasOwnProperty('__observedAttributes')) {
Expand All @@ -129,6 +130,7 @@ export const PropertiesMixin = dedupingMixin(superClass => {
* accessors exist on the element prototype. This method calls
* `_finalizeClass` to finalize each constructor in the prototype chain.
* @return {void}
* @nocollapse
*/
static finalize() {
if (!this.hasOwnProperty(JSCompiler_renameProperty('__finalized', this))) {
Expand All @@ -147,6 +149,7 @@ export const PropertiesMixin = dedupingMixin(superClass => {
* `finalize` and finalizes the class constructor.
*
* @protected
* @nocollapse
*/
static _finalizeClass() {
const props = ownProperties(/** @type {!PropertiesMixinConstructor} */(this));
Expand All @@ -162,6 +165,7 @@ export const PropertiesMixin = dedupingMixin(superClass => {
*
* @return {Object} Object containing properties for this class
* @protected
* @nocollapse
*/
static get _properties() {
if (!this.hasOwnProperty(
Expand All @@ -181,6 +185,7 @@ export const PropertiesMixin = dedupingMixin(superClass => {
* @return {*} Type to which to deserialize attribute
*
* @protected
* @nocollapse
*/
static typeForProperty(name) {
const info = this._properties[name];
Expand Down
2 changes: 2 additions & 0 deletions lib/mixins/property-accessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const PropertyAccessors = dedupingMixin(superClass => {
* `camelCase` convention
*
* @return {void}
* @nocollapse
*/
static createPropertiesForAttributes() {
let a$ = this.observedAttributes;
Expand All @@ -134,6 +135,7 @@ export const PropertyAccessors = dedupingMixin(superClass => {
* @return {string} Attribute name corresponding to the given property.
*
* @protected
* @nocollapse
*/
static attributeNameForProperty(property) {
return camelToDashCase(property);
Expand Down
Loading

0 comments on commit cc7702b

Please sign in to comment.