From b78ed2efe68b013a1f9ab12850b93a8dc49f0eb9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 1 Nov 2018 09:07:21 -0700 Subject: [PATCH] Avoid stack overflow in completions In symbolCanBeReferfencedAtTypeLocation, 3.1.3 has a stack overflow in the recursive case that checks exportedSymbols. I believe that the cause is a commonjs module with both export assignment and export property assignments via an alias [1], but I haven't been able to repro the crash. Nevertheless, I think the correct fix is just to not recur in the case that an exported symbol is identical to its containing module. ```js // @Filename: module.js exports.version = 'hi' function alias() { } module.exports = alias // @Filename: use.js var m = require('./module') m.al/**/ ``` I expected the overflow to happen when requesting completions at `/**/` but it didn't. --- src/services/completions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index f1e33087fdc4b..06b3824ee8020 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1142,7 +1142,7 @@ namespace ts.Completions { const exportedSymbols = typeChecker.getExportsOfModule(symbol); // If the exported symbols contains type, // symbol can be referenced at locations where type is allowed - return exportedSymbols.some(symbolCanBeReferencedAtTypeLocation); + return exportedSymbols.some(ex => ex !== symbol && symbolCanBeReferencedAtTypeLocation(ex)); } return false; }