diff options
Diffstat (limited to 'node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js')
-rw-r--r-- | node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js b/node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js index 374854d97..ff2858c41 100644 --- a/node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js +++ b/node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js @@ -20,7 +20,7 @@ var tslib_1 = require("tslib"); var utils = require("tsutils"); var ts = require("typescript"); var Lint = require("../index"); -var Rule = (function (_super) { +var Rule = /** @class */ (function (_super) { tslib_1.__extends(Rule, _super); function Rule() { return _super !== null && _super.apply(this, arguments) || this; @@ -30,7 +30,7 @@ var Rule = (function (_super) { return "Qualifier is unnecessary since '" + name + "' is in scope."; }; Rule.prototype.applyWithProgram = function (sourceFile, program) { - return this.applyWithFunction(sourceFile, function (ctx) { return walk(ctx, program.getTypeChecker()); }); + return this.applyWithFunction(sourceFile, walk, undefined, program.getTypeChecker()); }; /* tslint:disable:object-literal-sort-keys */ Rule.metadata = { @@ -94,7 +94,7 @@ function walk(ctx, checker) { } // If the symbol in scope is different, the qualifier is necessary. var fromScope = getSymbolInScope(qualifier, accessedSymbol.flags, name.text); - return fromScope === undefined || Lint.Utils.arraysAreEqual(fromScope.declarations, accessedSymbol.declarations, function (a, b) { return a === b; }); + return fromScope === undefined || symbolsAreEqual(accessedSymbol, fromScope); } function getSymbolInScope(node, flags, name) { // TODO:PERF `getSymbolsInScope` gets a long list. Is there a better way? @@ -112,6 +112,16 @@ function walk(ctx, checker) { var alias = tryGetAliasedSymbol(symbol, checker); return alias !== undefined && symbolIsNamespaceInScope(alias); } + function symbolsAreEqual(accessed, inScope) { + // TODO remove type assertion on update to typescript@2.6.0 + if (checker.getExportSymbolOfSymbol !== undefined) { + inScope = checker.getExportSymbolOfSymbol(inScope); + return accessed === inScope; + } + return accessed === inScope || + // For compatibility with typescript@2.5: compare declarations because the symbols don't have the same reference + Lint.Utils.arraysAreEqual(accessed.declarations, inScope.declarations, function (a, b) { return a === b; }); + } } function tryGetAliasedSymbol(symbol, checker) { return Lint.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias) ? checker.getAliasedSymbol(symbol) : undefined; |