diff options
Diffstat (limited to 'node_modules/tslint/lib/rules/noReferenceImportRule.js')
-rw-r--r-- | node_modules/tslint/lib/rules/noReferenceImportRule.js | 63 |
1 files changed, 11 insertions, 52 deletions
diff --git a/node_modules/tslint/lib/rules/noReferenceImportRule.js b/node_modules/tslint/lib/rules/noReferenceImportRule.js index 8579b5eee..108addd75 100644 --- a/node_modules/tslint/lib/rules/noReferenceImportRule.js +++ b/node_modules/tslint/lib/rules/noReferenceImportRule.js @@ -18,7 +18,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var tsutils_1 = require("tsutils"); -var ts = require("typescript"); var Lint = require("../index"); var Rule = /** @class */ (function (_super) { tslib_1.__extends(Rule, _super); @@ -30,7 +29,7 @@ var Rule = /** @class */ (function (_super) { return "No need to reference \"" + moduleReference + "\", since it is imported."; }; Rule.prototype.apply = function (sourceFile) { - return this.applyWithWalker(new NoReferenceImportWalker(sourceFile, this.ruleName, undefined)); + return this.applyWithFunction(sourceFile, walk); }; /* tslint:disable:object-literal-sort-keys */ Rule.metadata = { @@ -44,55 +43,15 @@ var Rule = /** @class */ (function (_super) { return Rule; }(Lint.Rules.AbstractRule)); exports.Rule = Rule; -var NoReferenceImportWalker = /** @class */ (function (_super) { - tslib_1.__extends(NoReferenceImportWalker, _super); - function NoReferenceImportWalker() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.imports = new Set(); - return _this; +function walk(ctx) { + if (ctx.sourceFile.typeReferenceDirectives.length === 0) { + return; } - NoReferenceImportWalker.prototype.walk = function (sourceFile) { - if (sourceFile.typeReferenceDirectives.length === 0) { - return; + var imports = new Set(tsutils_1.findImports(ctx.sourceFile, 3 /* AllStaticImports */).map(function (name) { return name.text; })); + for (var _i = 0, _a = ctx.sourceFile.typeReferenceDirectives; _i < _a.length; _i++) { + var ref = _a[_i]; + if (imports.has(ref.fileName)) { + ctx.addFailure(ref.pos, ref.end, Rule.FAILURE_STRING(ref.fileName)); } - this.findImports(sourceFile.statements); - for (var _i = 0, _a = sourceFile.typeReferenceDirectives; _i < _a.length; _i++) { - var ref = _a[_i]; - if (this.imports.has(ref.fileName)) { - this.addFailure(ref.pos, ref.end, Rule.FAILURE_STRING(ref.fileName)); - } - } - }; - NoReferenceImportWalker.prototype.findImports = function (statements) { - for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) { - var statement = statements_1[_i]; - if (tsutils_1.isImportDeclaration(statement)) { - this.addImport(statement.moduleSpecifier); - } - else if (tsutils_1.isImportEqualsDeclaration(statement)) { - if (statement.moduleReference.kind === ts.SyntaxKind.ExternalModuleReference && - statement.moduleReference.expression !== undefined) { - this.addImport(statement.moduleReference.expression); - } - } - else if (tsutils_1.isModuleDeclaration(statement) && statement.body !== undefined && this.sourceFile.isDeclarationFile) { - // There can't be any imports in a module augmentation or namespace - this.findImportsInModule(statement.body); - } - } - }; - NoReferenceImportWalker.prototype.findImportsInModule = function (body) { - if (body.kind === ts.SyntaxKind.ModuleBlock) { - return this.findImports(body.statements); - } - else if (body.kind === ts.SyntaxKind.ModuleDeclaration && body.body !== undefined) { - return this.findImportsInModule(body.body); - } - }; - NoReferenceImportWalker.prototype.addImport = function (specifier) { - if (tsutils_1.isStringLiteral(specifier)) { - this.imports.add(specifier.text); - } - }; - return NoReferenceImportWalker; -}(Lint.AbstractWalker)); + } +} |