Skip to content

Commit

Permalink
fix(compiler): fix static analysis of dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed May 29, 2019
1 parent ecafff2 commit c22a0a4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
3 changes: 0 additions & 3 deletions src/compiler/entries/entry-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ export function createEntryModule(cmps: d.ComponentCompilerMeta[]): d.EntryModul

// get the modes used in this bundle
modeNames: getEntryModes(cmps),

// figure out if we'll need a scoped css build
requiresScopedStyles: true
};
}

Expand Down
16 changes: 7 additions & 9 deletions src/compiler/entries/resolve-component-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as d from '../../declarations';
import { flatOne, unique } from '@utils';

export function resolveComponentDependencies(compilerCtx: d.CompilerCtx, cmps: d.ComponentCompilerMeta[]) {
computeDependencies(compilerCtx, cmps);
export function resolveComponentDependencies(cmps: d.ComponentCompilerMeta[]) {
computeDependencies(cmps);
computeDependants(cmps);
}

function computeDependencies(compilerCtx: d.CompilerCtx, cmps: d.ComponentCompilerMeta[]) {
function computeDependencies(cmps: d.ComponentCompilerMeta[]) {
const visited = new Set();
cmps.forEach(cmp => {
resolveTransitiveDependencies(compilerCtx, cmp, cmps, visited);
resolveTransitiveDependencies(cmp, cmps, visited);
cmp.dependencies = unique(cmp.dependencies).sort();
});
}
Expand All @@ -20,21 +20,19 @@ function computeDependants(cmps: d.ComponentCompilerMeta[]) {
});
}

function resolveTransitiveDependencies(compilerCtx: d.CompilerCtx, cmp: d.ComponentCompilerMeta, cmps: d.ComponentCompilerMeta[], visited: Set<d.ComponentCompilerMeta>): string[] {
function resolveTransitiveDependencies(cmp: d.ComponentCompilerMeta, cmps: d.ComponentCompilerMeta[], visited: Set<d.ComponentCompilerMeta>): string[] {
if (visited.has(cmp)) {
return cmp.dependencies;
}
visited.add(cmp);

const moduleFile = compilerCtx.moduleMap.get(cmp.sourceFilePath);

const dependencies = moduleFile.potentialCmpRefs.filter(tagName => cmps.some(c => c.tagName === tagName));
const dependencies = cmp.potentialCmpRefs.filter(tagName => cmps.some(c => c.tagName === tagName));
cmp.dependencies = cmp.directDependencies = dependencies;

const transitiveDeps = flatOne(
dependencies
.map(tagName => cmps.find(c => c.tagName === tagName))
.map(c => resolveTransitiveDependencies(compilerCtx, c, cmps, visited))
.map(c => resolveTransitiveDependencies(c, cmps, visited))
);
return cmp.dependencies = [
...dependencies,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transpile/transpile-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async function processMetadata(config: d.Config, compilerCtx: d.CompilerCtx, bui

buildCtx.moduleFiles = Array.from(compilerCtx.moduleMap.values());
buildCtx.components = getComponentsFromModules(buildCtx.moduleFiles);
resolveComponentDependencies(compilerCtx, buildCtx.components);
updateComponentBuildConditionals(compilerCtx.moduleMap, buildCtx.components);
resolveComponentDependencies(buildCtx.components);

if (doTranspile && !buildCtx.hasError) {
// ts changes have happened!!
Expand Down
1 change: 0 additions & 1 deletion src/declarations/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export interface EntryModule {
entryKey?: string;
dependencies?: string[];
cmps: d.ComponentCompilerMeta[];
requiresScopedStyles?: boolean;
modeNames?: string[];
entryBundles?: EntryBundle[];
}
Expand Down

0 comments on commit c22a0a4

Please sign in to comment.