From 44e48287964dbb75bb7176f8184179436f1ddd9e Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Fri, 9 Nov 2018 18:48:53 -0800 Subject: [PATCH] Do lazy behavior copying only when `legacyOptimizations` is set --- lib/legacy/class.html | 18 +++++++++++++++--- test/runner.html | 3 ++- test/unit/behaviors.html | 3 +++ test/unit/styling-scoped.html | 1 - 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/legacy/class.html b/lib/legacy/class.html index ad6817a7fb..6a9043e66a 100644 --- a/lib/legacy/class.html +++ b/lib/legacy/class.html @@ -297,10 +297,10 @@ `is` in `beforeRegister` as you could in 1.x. */ const proto = this; - if (behaviorList) { - applyBehaviors(proto, behaviorList, lifecycle); + // copy properties lazily if we're optimizing + if (Polymer.legacyOptimizations) { + copyPropertiesToProto(proto); } - applyInfo(proto, info, lifecycle, excludeOnInfo); let list = lifecycle.beforeRegister; if (list) { for (let i=0; i < list.length; i++) { @@ -426,6 +426,18 @@ superBehaviors.concat(behaviors) : behaviorList; } + const copyPropertiesToProto = (proto) => { + if (behaviorList) { + applyBehaviors(proto, behaviorList, lifecycle); + } + applyInfo(proto, info, lifecycle, excludeOnInfo); + }; + + // copy properties if we're not optimizing + if (!Polymer.legacyOptimizations) { + copyPropertiesToProto(PolymerGenerated.prototype); + } + PolymerGenerated.generatedFrom = info; return PolymerGenerated; diff --git a/test/runner.html b/test/runner.html index 78b551fa5a..2402bb3174 100644 --- a/test/runner.html +++ b/test/runner.html @@ -55,6 +55,7 @@ 'unit/attributes.html', 'unit/async.html', 'unit/behaviors.html', + 'unit/behaviors.html?legacyOptimizations=true', 'unit/polymer.element.html', 'unit/polymer.properties-mixin.html', 'unit/polymer.properties-mixin-with-property-accessors.html', @@ -87,7 +88,7 @@ function combinations(suites, flags) { return flags.map((f) => { - return f ? suites.map(s => `${s}?${f}`) : suites; + return f ? suites.map(s => `${s}${s.match(/\?/) ? '&' : '?'}${f}`) : suites; }).reduce((arr, s) => arr.concat(s), []); } diff --git a/test/unit/behaviors.html b/test/unit/behaviors.html index b08dfd5dee..3051454e8d 100644 --- a/test/unit/behaviors.html +++ b/test/unit/behaviors.html @@ -30,6 +30,9 @@