@@ -46,6 +46,8 @@ export class Rule extends Lint.Rules.AbstractRule {
46
46
type VisitedVariables = { [ varName : string ] : boolean } ;
47
47
48
48
class NoUseBeforeDeclareWalker extends Lint . ScopeAwareRuleWalker < VisitedVariables > {
49
+ private importedPropertiesPositions : number [ ] = [ ] ;
50
+
49
51
constructor ( sourceFile : ts . SourceFile , options : Lint . IOptions , private languageService : ts . LanguageService ) {
50
52
super ( sourceFile , options ) ;
51
53
}
@@ -89,6 +91,9 @@ class NoUseBeforeDeclareWalker extends Lint.ScopeAwareRuleWalker<VisitedVariable
89
91
90
92
public visitNamedImports ( node : ts . NamedImports ) {
91
93
for ( let namedImport of node . elements ) {
94
+ if ( namedImport . propertyName != null ) {
95
+ this . saveImportedPropertiesPositions ( namedImport . propertyName . getStart ( ) ) ;
96
+ }
92
97
this . validateUsageForVariable ( namedImport . name . text , namedImport . name . getStart ( ) ) ;
93
98
}
94
99
super . visitNamedImports ( node ) ;
@@ -120,12 +125,20 @@ class NoUseBeforeDeclareWalker extends Lint.ScopeAwareRuleWalker<VisitedVariable
120
125
for ( let highlight of highlights ) {
121
126
for ( let highlightSpan of highlight . highlightSpans ) {
122
127
const referencePosition = highlightSpan . textSpan . start ;
123
- if ( referencePosition < position ) {
128
+ if ( referencePosition < position && ! this . isImportedPropertyName ( referencePosition ) ) {
124
129
const failureString = Rule . FAILURE_STRING_PREFIX + name + Rule . FAILURE_STRING_POSTFIX ;
125
130
this . addFailure ( this . createFailure ( referencePosition , name . length , failureString ) ) ;
126
131
}
127
132
}
128
133
}
129
134
}
130
135
}
136
+
137
+ private saveImportedPropertiesPositions ( position : number ) : void {
138
+ this . importedPropertiesPositions . push ( position ) ;
139
+ }
140
+
141
+ private isImportedPropertyName ( position : number ) : boolean {
142
+ return this . importedPropertiesPositions . indexOf ( position ) !== - 1 ;
143
+ }
131
144
}
0 commit comments