Skip to content

Commit 7d2e2df

Browse files
committed
feat(build): conditionally include svg build features
1 parent dc67e63 commit 7d2e2df

4 files changed

Lines changed: 31 additions & 7 deletions

File tree

src/compiler/build/test/conditionals.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,30 @@ describe('build conditionals', () => {
9898

9999
// kick off a rebuild
100100
c.trigger('fileAdd', path.join(root, 'src', 'global.css'));
101+
await c.fs.writeFile(path.join(root, 'src', 'cmp-a.tsx'), `
102+
@Component({ tag: 'cmp-a' }) export class CmpA {
103+
104+
render() {
105+
return [<slot/>];
106+
}
107+
}
108+
`, { clearFileCache: true });
109+
await c.fs.commit();
101110

102111
// wait for the rebuild to finish
103112
// get the rebuild results
104113
r = await rebuildListener;
105114
expect(r.diagnostics).toEqual([]);
106115

107116
expect(r.hasSlot).toBe(true);
108-
expect(r.hasSvg).toBe(true);
117+
expect(r.hasSvg).toBe(false);
118+
119+
c.trigger('fileAdd', path.join(root, 'src', 'global2.css'));
120+
r = await rebuildListener;
121+
expect(r.diagnostics).toEqual([]);
122+
123+
expect(r.hasSlot).toBe(true);
124+
expect(r.hasSvg).toBe(false);
109125
});
110126

111127
it('svg not in build', async () => {

src/renderer/vdom/update-attribute.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ export function updateAttribute(
66
memberName: string,
77
newValue: any,
88
isBooleanAttr = typeof newValue === 'boolean',
9+
isXlinkNs?: boolean
910
) {
10-
const isXlinkNs = (memberName !== (memberName = memberName.replace(/^xlink\:?/, '')));
11+
if (__BUILD_CONDITIONALS__.hasSvg) {
12+
isXlinkNs = (memberName !== (memberName = memberName.replace(/^xlink\:?/, '')));
13+
}
14+
1115
if (newValue == null || (isBooleanAttr && (!newValue || newValue === 'false'))) {
12-
if (isXlinkNs) {
16+
if (__BUILD_CONDITIONALS__.hasSvg && isXlinkNs) {
1317
elm.removeAttributeNS(XLINK_NS, toLowerCase(memberName));
1418

1519
} else {
@@ -22,7 +26,7 @@ export function updateAttribute(
2226
} else {
2327
newValue = newValue.toString();
2428
}
25-
if (isXlinkNs) {
29+
if (__BUILD_CONDITIONALS__.hasSvg && isXlinkNs) {
2630
elm.setAttributeNS(XLINK_NS, toLowerCase(memberName), newValue);
2731

2832
} else {

src/util/build-conditionals.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ export async function setBuildConditionals(
145145
}
146146

147147
coreBuild.slotPolyfill = true;
148-
coreBuild.hasSvg = true;
149148

150149
return coreBuild;
151150
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ describe('build conditionals', () => {
9090
expect(bc.hasSvg).toBe(true);
9191
});
9292

93-
it('set Build.hasSvg always true (for now)', async () => {
94-
buildCtx.hasSvg = false;
93+
it('default Build.hasSvg false', async () => {
94+
const bc = await setBuildConditionals(config, {}, 'core', buildCtx, []);
95+
expect(bc.hasSvg).toBe(false);
96+
});
97+
98+
it('set Build.hasSvg true', async () => {
99+
buildCtx.hasSvg = true;
95100
const bc = await setBuildConditionals(config, {}, 'core', buildCtx, []);
96101
expect(bc.hasSvg).toBe(true);
97102
});

0 commit comments

Comments
 (0)