diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2018-09-01 14:28:53 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-09-02 11:28:45 -0400 |
commit | 739ef6a8ec4e2e792e1e026a5fbc85a15d63704f (patch) | |
tree | 2290876b73e09c49225da0f0c6fbbc74c8fe12fb /js/compiler.ts | |
parent | bbc4e55bdae2d37fee92e778f4a13eaf1d4fb4e1 (diff) |
Fix circular dependencies
Diffstat (limited to 'js/compiler.ts')
-rw-r--r-- | js/compiler.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/js/compiler.ts b/js/compiler.ts index 883feb2f9..376bcc064 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -77,6 +77,7 @@ export class ModuleMetaData implements ts.IScriptSnapshot { public deps?: ModuleFileName[]; public readonly exports = {}; public factory?: AmdFactory; + public gatheringDeps = false; public hasRun = false; public scriptVersion = ""; @@ -250,10 +251,6 @@ export class DenoCompiler implements ts.LanguageServiceHost { } const dependencyMetaData = this._getModuleMetaData(dep); assert(dependencyMetaData != null, `Missing dependency "${dep}".`); - assert( - dependencyMetaData!.hasRun === true, - `Module "${dep}" was not run.` - ); // TypeScript does not track assert, therefore using not null operator return dependencyMetaData!.exports; }); @@ -436,6 +433,9 @@ export class DenoCompiler implements ts.LanguageServiceHost { ): void => { this._log("compiler.localDefine", moduleMetaData.fileName); moduleMetaData.factory = factory; + // when there are circular dependencies, we need to skip recursing the + // dependencies + moduleMetaData.gatheringDeps = true; // we will recursively resolve the dependencies for any modules moduleMetaData.deps = deps.map(dep => { if ( @@ -449,9 +449,12 @@ export class DenoCompiler implements ts.LanguageServiceHost { dep, moduleMetaData.fileName ); - this._gatherDependencies(dependencyMetaData); + if (!dependencyMetaData.gatheringDeps) { + this._gatherDependencies(dependencyMetaData); + } return dependencyMetaData.fileName; }); + moduleMetaData.gatheringDeps = false; if (!this._runQueue.includes(moduleMetaData)) { this._runQueue.push(moduleMetaData); } |