Skip to content

Commit f0a9dfc

Browse files
committed
fix(build): vdom/svg build conditionals also from imported modules
1 parent 4921790 commit f0a9dfc

16 files changed

Lines changed: 345 additions & 50 deletions

File tree

src/compiler/app-core/build-conditionals.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
import * as d from '../../declarations';
22

33

4-
export function getBuildFeatures(cmps: d.ComponentCompilerMeta[]) {
4+
export function getBuildFeatures(moduleMap: d.ModuleMap, cmps: d.ComponentCompilerMeta[]) {
5+
cmps.forEach(cmp => {
6+
const importedModules = getModuleImports(moduleMap, cmp.sourceFilePath, []);
7+
importedModules.forEach(importedModule => {
8+
// if the component already has a boolean true value it'll keep it
9+
// otherwise we get the boolean value from the imported module
10+
cmp.hasVdomAttribute = cmp.hasVdomAttribute || importedModule.hasVdomAttribute;
11+
cmp.hasVdomClass = cmp.hasVdomClass || importedModule.hasVdomClass;
12+
cmp.hasVdomFunctional = cmp.hasVdomFunctional || importedModule.hasVdomFunctional;
13+
cmp.hasVdomKey = cmp.hasVdomKey || importedModule.hasVdomKey;
14+
cmp.hasVdomListener = cmp.hasVdomListener || importedModule.hasVdomListener;
15+
cmp.hasVdomRef = cmp.hasVdomRef || importedModule.hasVdomRef;
16+
cmp.hasVdomRender = cmp.hasVdomRender || importedModule.hasVdomRender;
17+
cmp.hasVdomStyle = cmp.hasVdomStyle || importedModule.hasVdomStyle;
18+
cmp.hasVdomText = cmp.hasVdomText || importedModule.hasVdomText;
19+
cmp.htmlAttrNames.push(...importedModule.htmlAttrNames);
20+
cmp.htmlTagNames.push(...importedModule.htmlTagNames);
21+
cmp.potentialCmpRefs.push(...importedModule.potentialCmpRefs);
22+
});
23+
});
24+
525
const slot = cmps.some(c => c.htmlTagNames.includes('slot'));
626
const f: d.BuildFeatures = {
727
allRenderFn: cmps.every(c => c.hasRenderFn),
@@ -58,6 +78,29 @@ export function getBuildFeatures(cmps: d.ComponentCompilerMeta[]) {
5878
}
5979

6080

81+
function getModuleImports(moduleMap: d.ModuleMap, filePath: string, importedModules: d.Module[]) {
82+
let moduleFile = moduleMap.get(filePath);
83+
if (moduleFile == null) {
84+
moduleFile = moduleMap.get(filePath + '.tsx');
85+
if (moduleFile == null) {
86+
moduleFile = moduleMap.get(filePath + '.ts');
87+
if (moduleFile == null) {
88+
moduleFile = moduleMap.get(filePath + '.js');
89+
}
90+
}
91+
}
92+
93+
if (moduleFile && !importedModules.some(m => m.sourceFilePath === moduleFile.sourceFilePath)) {
94+
importedModules.push(moduleFile);
95+
96+
moduleFile.localImports.forEach(localImport => {
97+
getModuleImports(moduleMap, localImport, importedModules);
98+
});
99+
}
100+
return importedModules;
101+
}
102+
103+
61104
export function updateBuildConditionals(config: d.Config, b: d.Build) {
62105
b.isDebug = (config.logLevel === 'debug');
63106
b.isDev = !!config.devMode;

src/compiler/build/build-results.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function generateBuildResults(config: d.Config, compilerCtx: d.CompilerCt
88

99
const buildResults: d.BuildResults = {
1010
buildId: buildCtx.buildId,
11+
buildConditionals: getBuildConditionals(buildCtx),
1112
bundleBuildCount: buildCtx.bundleBuildCount,
1213
diagnostics: normalizeDiagnostics(compilerCtx, buildCtx.diagnostics),
1314
dirsAdded: buildCtx.dirsAdded.slice().sort(),
@@ -69,3 +70,21 @@ export function generateBuildResults(config: d.Config, compilerCtx: d.CompilerCt
6970

7071
return buildResults;
7172
}
73+
74+
function getBuildConditionals(buildCtx: d.BuildCtx) {
75+
const b = {
76+
shadow: false,
77+
slot: false,
78+
svg: false,
79+
vdom: false
80+
};
81+
82+
buildCtx.components.forEach(cmp => {
83+
b.shadow = b.shadow || (cmp.encapsulation === 'shadow');
84+
b.slot = b.slot || cmp.htmlTagNames.includes('slot');
85+
b.svg = b.svg || cmp.htmlTagNames.includes('svg');
86+
b.vdom = b.vdom || cmp.hasVdomRender;
87+
});
88+
89+
return b;
90+
}

src/compiler/build/compiler-ctx.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,22 @@ export function getModule(config: d.Config, compilerCtx: d.CompilerCtx, sourceFi
9090
dtsFilePath: null,
9191
excludeFromCollection: false,
9292
externalImports: [],
93+
hasVdomAttribute: false,
94+
hasVdomClass: false,
95+
hasVdomFunctional: false,
96+
hasVdomKey: false,
97+
hasVdomListener: false,
98+
hasVdomRef: false,
99+
hasVdomRender: false,
100+
hasVdomStyle: false,
101+
hasVdomText: false,
102+
htmlAttrNames: [],
103+
htmlTagNames: [],
93104
isCollectionDependency: false,
94-
localImports: [],
95105
isLegacy: false,
96-
originalCollectionComponentPath: null
106+
localImports: [],
107+
originalCollectionComponentPath: null,
108+
potentialCmpRefs: []
97109
};
98110
compilerCtx.moduleMap.set(sourceFilePath, moduleFile);
99111
return moduleFile;
@@ -110,4 +122,17 @@ export function resetModule(moduleFile: d.Module) {
110122
moduleFile.isCollectionDependency = false;
111123
moduleFile.localImports.length = 0;
112124
moduleFile.originalCollectionComponentPath = null;
125+
126+
moduleFile.hasVdomAttribute = true;
127+
moduleFile.hasVdomClass = true;
128+
moduleFile.hasVdomFunctional = true;
129+
moduleFile.hasVdomKey = true;
130+
moduleFile.hasVdomListener = true;
131+
moduleFile.hasVdomRef = true;
132+
moduleFile.hasVdomRender = false;
133+
moduleFile.hasVdomStyle = true;
134+
moduleFile.hasVdomText = true;
135+
moduleFile.htmlAttrNames.length = 0;
136+
moduleFile.htmlTagNames.length = 0;
137+
moduleFile.potentialCmpRefs.length = 0;
113138
}

src/compiler/component-hydrate/generate-hydrate-app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { writeHydrateOutputs } from './write-hydrate-outputs';
99
export async function generateHydrateApp(config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, outputTargets: d.OutputTargetHydrate[]) {
1010
try {
1111
const cmps = buildCtx.components;
12-
const build = getBuildConditionals(config, cmps);
12+
const build = getBuildConditionals(config, compilerCtx, cmps);
1313

1414
const appEntryCode = await generateHydrateAppCore(config, compilerCtx, buildCtx);
1515

@@ -74,8 +74,8 @@ async function generateHydrateAppCore(config: d.Config, compilerCtx: d.CompilerC
7474
}
7575

7676

77-
function getBuildConditionals(config: d.Config, cmps: d.ComponentCompilerMeta[]) {
78-
const build = getBuildFeatures(cmps) as d.Build;
77+
function getBuildConditionals(config: d.Config, compilerCtx: d.CompilerCtx, cmps: d.ComponentCompilerMeta[]) {
78+
const build = getBuildFeatures(compilerCtx.moduleMap, cmps) as d.Build;
7979

8080
build.lazyLoad = true;
8181
build.hydrateClientSide = false;

src/compiler/component-lazy/generate-lazy-app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function generateLazyLoadedApp(config: d.Config, compilerCtx: d.Com
1313
const timespan = buildCtx.createTimeSpan(`bundling components started`);
1414

1515
const cmps = buildCtx.components;
16-
const build = getBuildConditionals(config, cmps);
16+
const build = getBuildConditionals(config, compilerCtx, cmps);
1717
const rollupBuild = await bundleLazyApp(config, compilerCtx, buildCtx, build);
1818
if (buildCtx.hasError) {
1919
return;
@@ -33,8 +33,8 @@ export async function generateLazyLoadedApp(config: d.Config, compilerCtx: d.Com
3333
buildCtx.componentGraph = generateModuleGraph(buildCtx.components, componentBundle);
3434
}
3535

36-
function getBuildConditionals(config: d.Config, cmps: d.ComponentCompilerMeta[]) {
37-
const build = getBuildFeatures(cmps) as d.Build;
36+
function getBuildConditionals(config: d.Config, compilerCtx: d.CompilerCtx, cmps: d.ComponentCompilerMeta[]) {
37+
const build = getBuildFeatures(compilerCtx.moduleMap, cmps) as d.Build;
3838

3939
build.lazyLoad = true;
4040
build.hydrateServerSide = false;

src/compiler/entries/resolve-component-dependencies.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as d from '../../declarations';
22
import { flatOne, unique } from '@utils';
33

4-
export function resolveComponentDependencies(cmps: d.ComponentCompilerMeta[]) {
5-
computeDependencies(cmps);
4+
export function resolveComponentDependencies(compilerCtx: d.CompilerCtx, cmps: d.ComponentCompilerMeta[]) {
5+
computeDependencies(compilerCtx, cmps);
66
computeDependants(cmps);
77
}
88

9-
function computeDependencies(cmps: d.ComponentCompilerMeta[]) {
9+
function computeDependencies(compilerCtx: d.CompilerCtx, cmps: d.ComponentCompilerMeta[]) {
1010
const visited = new Set();
1111
cmps.forEach(cmp => {
12-
resolveTransitiveDependencies(cmp, cmps, visited);
12+
resolveTransitiveDependencies(compilerCtx, cmp, cmps, visited);
1313
cmp.dependencies = unique(cmp.dependencies).sort();
1414
});
1515
}
@@ -20,19 +20,21 @@ function computeDependants(cmps: d.ComponentCompilerMeta[]) {
2020
});
2121
}
2222

23-
function resolveTransitiveDependencies(cmp: d.ComponentCompilerMeta, cmps: d.ComponentCompilerMeta[], visited: Set<d.ComponentCompilerMeta>): string[] {
23+
function resolveTransitiveDependencies(compilerCtx: d.CompilerCtx, cmp: d.ComponentCompilerMeta, cmps: d.ComponentCompilerMeta[], visited: Set<d.ComponentCompilerMeta>): string[] {
2424
if (visited.has(cmp)) {
2525
return cmp.dependencies;
2626
}
2727
visited.add(cmp);
2828

29-
const dependencies = cmp.potentialCmpRefs.filter(tagName => cmps.some(c => c.tagName === tagName));
29+
const moduleFile = compilerCtx.moduleMap.get(cmp.sourceFilePath);
30+
31+
const dependencies = moduleFile.potentialCmpRefs.filter(tagName => cmps.some(c => c.tagName === tagName));
3032
cmp.dependencies = cmp.directDependencies = dependencies;
3133

3234
const transitiveDeps = flatOne(
3335
dependencies
3436
.map(tagName => cmps.find(c => c.tagName === tagName))
35-
.map(c => resolveTransitiveDependencies(c, cmps, visited))
37+
.map(c => resolveTransitiveDependencies(compilerCtx, c, cmps, visited))
3638
);
3739
return cmp.dependencies = [
3840
...dependencies,

src/compiler/output-targets/output-module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function generateModuleWebComponents(config: d.Config, compilerCtx:
3535

3636
async function bundleRawComponents(config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, outputTargets: d.OutputTargetDistModule[], externalRuntime: boolean) {
3737
const cmps = buildCtx.components;
38-
const build = getBuildConditionals(config, cmps);
38+
const build = getBuildConditionals(config, compilerCtx, cmps);
3939

4040
if (build.mode) {
4141
const warn = buildWarn(buildCtx.diagnostics);
@@ -67,8 +67,8 @@ async function bundleRawComponents(config: d.Config, compilerCtx: d.CompilerCtx,
6767
}
6868

6969

70-
function getBuildConditionals(config: d.Config, cmps: d.ComponentCompilerMeta[]) {
71-
const build = getBuildFeatures(cmps) as d.Build;
70+
function getBuildConditionals(config: d.Config, compilerCtx: d.CompilerCtx, cmps: d.ComponentCompilerMeta[]) {
71+
const build = getBuildFeatures(compilerCtx.moduleMap, cmps) as d.Build;
7272

7373
build.lazyLoad = false;
7474
build.hydrateClientSide = false;

0 commit comments

Comments
 (0)