Skip to content

Commit 582ff53

Browse files
committed
feat(build): conditionally include slot polyfill
1 parent 32c5737 commit 582ff53

3 files changed

Lines changed: 29 additions & 30 deletions

File tree

src/declarations/build-conditionals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface BuildConditionals {
2929

3030
// dom
3131
shadowDom: boolean;
32+
scoped: boolean;
3233
slotPolyfill: boolean;
3334

3435
// vdom

src/util/build-conditionals.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function getDefaultBuildConditionals(): d.BuildConditionals {
1010
polyfills: false,
1111
cssVarShim: true,
1212
shadowDom: true,
13+
scoped: true,
1314
slotPolyfill: true,
1415
ssrServerSide: true,
1516
prerenderClientSide: true,
@@ -83,6 +84,7 @@ export async function setBuildConditionals(
8384
ssrServerSide: false,
8485
prerenderClientSide: false,
8586
shadowDom: false,
87+
scoped: false,
8688
slotPolyfill: false,
8789
event: false,
8890
listener: false,
@@ -116,15 +118,14 @@ export async function setBuildConditionals(
116118
await Promise.all(promises);
117119

118120
if (coreId === 'core') {
121+
// modern build
119122
coreBuild.browserModuleLoader = true;
120-
coreBuild.slotPolyfill = !!coreBuild.slotPolyfill;
121-
if (coreBuild.slotPolyfill) {
122-
coreBuild.slotPolyfill = !!(buildCtx.hasSlot);
123-
}
123+
coreBuild.slotPolyfill = (coreBuild.scoped && buildCtx.hasSlot);
124124
coreBuild.prerenderClientSide = shouldPrerender(config);
125125
compilerCtx.lastBuildConditionalsBrowserEsm = coreBuild;
126126

127127
} else if (coreId === 'core.pf') {
128+
// polyfilled build
128129
coreBuild.browserModuleLoader = true;
129130
coreBuild.es5 = true;
130131
coreBuild.polyfills = true;
@@ -134,23 +135,20 @@ export async function setBuildConditionals(
134135
compilerCtx.lastBuildConditionalsBrowserEs5 = coreBuild;
135136

136137
} else if (coreId === 'esm.es5') {
138+
// es5 build to be imported by bundlers
137139
coreBuild.es5 = true;
138140
coreBuild.externalModuleLoader = true;
139141
coreBuild.cssVarShim = true;
140142
coreBuild.slotPolyfill = true;
141143
compilerCtx.lastBuildConditionalsEsmEs5 = coreBuild;
142144

143145
} else if (coreId === 'esm.es2017') {
146+
// es2017 build to be imported by bundlers
144147
coreBuild.externalModuleLoader = true;
145-
coreBuild.slotPolyfill = !!coreBuild.slotPolyfill;
146-
if (coreBuild.slotPolyfill) {
147-
coreBuild.slotPolyfill = !!(buildCtx.hasSlot);
148-
}
148+
coreBuild.slotPolyfill = (coreBuild.scoped && buildCtx.hasSlot);
149149
compilerCtx.lastBuildConditionalsEsmEs2017 = coreBuild;
150150
}
151151

152-
coreBuild.slotPolyfill = true;
153-
154152
return coreBuild;
155153
}
156154

@@ -209,7 +207,7 @@ export function setBuildFromComponentMeta(coreBuild: d.BuildConditionals, cmpMet
209207
}
210208

211209
coreBuild.shadowDom = coreBuild.shadowDom || cmpMeta.encapsulationMeta === ENCAPSULATION.ShadowDom;
212-
coreBuild.slotPolyfill = coreBuild.slotPolyfill || cmpMeta.encapsulationMeta !== ENCAPSULATION.ShadowDom;
210+
coreBuild.scoped = coreBuild.scoped || cmpMeta.encapsulationMeta === ENCAPSULATION.ScopedCss;
213211
coreBuild.event = coreBuild.event || !!(cmpMeta.eventsMeta && cmpMeta.eventsMeta.length > 0);
214212
coreBuild.listener = coreBuild.listener || !!(cmpMeta.listenersMeta && cmpMeta.listenersMeta.length > 0);
215213
coreBuild.styles = coreBuild.styles || !!(cmpMeta.stylesMeta && Object.keys(cmpMeta.stylesMeta).length > 0);

src/util/test/build-conditionals.spec.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('build conditionals', () => {
177177
setBuildFromComponentMeta(coreBuild, cmpMeta);
178178
expect(coreBuild).toEqual({
179179
shadowDom: false,
180-
slotPolyfill: true,
180+
scoped: false,
181181
event: false,
182182
listener: false,
183183
styles: false,
@@ -192,7 +192,7 @@ describe('build conditionals', () => {
192192
setBuildFromComponentMeta(coreBuild, cmpMeta);
193193
expect(coreBuild).toEqual({
194194
shadowDom: false,
195-
slotPolyfill: true,
195+
scoped: false,
196196
event: false,
197197
listener: false,
198198
styles: true,
@@ -205,33 +205,33 @@ describe('build conditionals', () => {
205205
setBuildFromComponentMeta(coreBuild, cmpMeta);
206206
expect(coreBuild).toEqual({
207207
shadowDom: true,
208-
slotPolyfill: false,
208+
scoped: false,
209209
event: false,
210210
listener: false,
211211
styles: false,
212212
hostTheme: false
213213
});
214214
});
215215

216-
it('slotPolyfill cuz ScopedCss', () => {
216+
it('scoped cuz ScopedCss', () => {
217217
cmpMeta.encapsulationMeta = ENCAPSULATION.ScopedCss;
218218
setBuildFromComponentMeta(coreBuild, cmpMeta);
219219
expect(coreBuild).toEqual({
220220
shadowDom: false,
221-
slotPolyfill: true,
221+
scoped: true,
222222
event: false,
223223
listener: false,
224224
styles: false,
225225
hostTheme: false
226226
});
227227
});
228228

229-
it('slotPolyfill cuz NoEncapsulation', () => {
229+
it('no scoped or shadow cuz NoEncapsulation', () => {
230230
cmpMeta.encapsulationMeta = ENCAPSULATION.NoEncapsulation;
231231
setBuildFromComponentMeta(coreBuild, cmpMeta);
232232
expect(coreBuild).toEqual({
233233
shadowDom: false,
234-
slotPolyfill: true,
234+
scoped: false,
235235
event: false,
236236
listener: false,
237237
styles: false,
@@ -245,7 +245,7 @@ describe('build conditionals', () => {
245245
expect(coreBuild.listener).toBeTruthy();
246246
expect(coreBuild).toEqual({
247247
shadowDom: false,
248-
slotPolyfill: true,
248+
scoped: false,
249249
event: false,
250250
listener: true,
251251
styles: false,
@@ -258,7 +258,7 @@ describe('build conditionals', () => {
258258
setBuildFromComponentMeta(coreBuild, cmpMeta);
259259
expect(coreBuild).toEqual({
260260
shadowDom: false,
261-
slotPolyfill: true,
261+
scoped: false,
262262
event: true,
263263
listener: false,
264264
styles: false,
@@ -274,7 +274,7 @@ describe('build conditionals', () => {
274274
expect(coreBuild.element).toBeTruthy();
275275
expect(coreBuild).toEqual({
276276
shadowDom: false,
277-
slotPolyfill: true,
277+
scoped: false,
278278
event: false,
279279
listener: false,
280280
styles: false,
@@ -290,7 +290,7 @@ describe('build conditionals', () => {
290290
setBuildFromComponentMeta(coreBuild, cmpMeta);
291291
expect(coreBuild).toEqual({
292292
shadowDom: false,
293-
slotPolyfill: true,
293+
scoped: false,
294294
event: false,
295295
listener: false,
296296
styles: false,
@@ -306,7 +306,7 @@ describe('build conditionals', () => {
306306
setBuildFromComponentMeta(coreBuild, cmpMeta);
307307
expect(coreBuild).toEqual({
308308
shadowDom: false,
309-
slotPolyfill: true,
309+
scoped: false,
310310
event: false,
311311
listener: false,
312312
styles: false,
@@ -322,7 +322,7 @@ describe('build conditionals', () => {
322322
setBuildFromComponentMeta(coreBuild, cmpMeta);
323323
expect(coreBuild).toEqual({
324324
shadowDom: false,
325-
slotPolyfill: true,
325+
scoped: false,
326326
event: false,
327327
listener: false,
328328
styles: false,
@@ -339,7 +339,7 @@ describe('build conditionals', () => {
339339
setBuildFromComponentMeta(coreBuild, cmpMeta);
340340
expect(coreBuild).toEqual({
341341
shadowDom: false,
342-
slotPolyfill: true,
342+
scoped: false,
343343
event: false,
344344
listener: false,
345345
styles: false,
@@ -356,7 +356,7 @@ describe('build conditionals', () => {
356356
setBuildFromComponentMeta(coreBuild, cmpMeta);
357357
expect(coreBuild).toEqual({
358358
shadowDom: false,
359-
slotPolyfill: true,
359+
scoped: false,
360360
event: false,
361361
listener: false,
362362
styles: false,
@@ -373,7 +373,7 @@ describe('build conditionals', () => {
373373
setBuildFromComponentMeta(coreBuild, cmpMeta);
374374
expect(coreBuild).toEqual({
375375
shadowDom: false,
376-
slotPolyfill: true,
376+
scoped: false,
377377
event: false,
378378
listener: false,
379379
styles: false,
@@ -390,7 +390,7 @@ describe('build conditionals', () => {
390390
setBuildFromComponentMeta(coreBuild, cmpMeta);
391391
expect(coreBuild).toEqual({
392392
shadowDom: false,
393-
slotPolyfill: true,
393+
scoped: false,
394394
event: false,
395395
listener: false,
396396
styles: false,
@@ -406,7 +406,7 @@ describe('build conditionals', () => {
406406
setBuildFromComponentMeta(coreBuild, cmpMeta);
407407
expect(coreBuild).toEqual({
408408
shadowDom: false,
409-
slotPolyfill: true,
409+
scoped: false,
410410
event: false,
411411
listener: false,
412412
styles: false,
@@ -418,7 +418,7 @@ describe('build conditionals', () => {
418418
setBuildFromComponentMeta(coreBuild, cmpMeta);
419419
expect(coreBuild).toEqual({
420420
shadowDom: false,
421-
slotPolyfill: true,
421+
scoped: false,
422422
event: false,
423423
listener: false,
424424
styles: false,

0 commit comments

Comments
 (0)