Chromium Code Reviews| Index: pkg/analyzer/lib/src/dart/resolver/scope.dart |
| diff --git a/pkg/analyzer/lib/src/dart/resolver/scope.dart b/pkg/analyzer/lib/src/dart/resolver/scope.dart |
| index 9211f8ace0aca832c01a17b61b5a53c4fe8ac0bf..f627efe6aa953b153f9946255a29284949e0326f 100644 |
| --- a/pkg/analyzer/lib/src/dart/resolver/scope.dart |
| +++ b/pkg/analyzer/lib/src/dart/resolver/scope.dart |
| @@ -125,7 +125,8 @@ class EnclosedScope extends Scope { |
| getSource(identifier), |
| identifier.offset, |
| identifier.length, |
| - CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, [name])); |
| + CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, |
| + [name])); |
| return hiddenElement; |
| } |
| } |
| @@ -438,6 +439,53 @@ class LibraryImportScope extends Scope { |
| return foundElement; |
| } |
| + @override |
| + bool shouldIgnoreUndefined(Identifier node) { |
| + bool exists(ImportElement importElement) => |
| + importElement.context.exists(importElement.importedLibrary.source); |
|
scheglov
2016/08/08 21:10:20
AnalysisContext.exists() is an expensive operation
Brian Wilkerson
2016/08/08 21:19:29
Yeah, I considered that possibility, but forgot to
|
| + Iterable<NamespaceCombinator> getShowCombinators( |
| + ImportElement importElement) => |
| + importElement.combinators.where((NamespaceCombinator combinator) => |
| + combinator is ShowElementCombinator); |
| + if (node is PrefixedIdentifier) { |
| + String prefix = node.prefix.name; |
| + String name = node.identifier.name; |
| + List<ImportElement> imports = _definingLibrary.imports; |
| + int count = imports.length; |
| + for (int i = 0; i < count; i++) { |
| + ImportElement importElement = imports[i]; |
| + if (importElement.prefix?.name == prefix && !exists(importElement)) { |
|
scheglov
2016/08/08 21:10:20
What if there is an import with the same prefix na
Brian Wilkerson
2016/08/08 21:19:29
Then presumably we would have found the correspond
|
| + Iterable<NamespaceCombinator> showCombinators = |
| + getShowCombinators(importElement); |
| + if (showCombinators.isEmpty) { |
| + return true; |
| + } |
| + for (ShowElementCombinator combinator in showCombinators) { |
| + if (combinator.shownNames.contains(name)) { |
| + return true; |
| + } |
| + } |
| + } |
| + } |
| + } else if (node is SimpleIdentifier) { |
| + String name = node.name; |
| + List<ImportElement> imports = _definingLibrary.imports; |
| + int count = imports.length; |
| + for (int i = 0; i < count; i++) { |
| + ImportElement importElement = imports[i]; |
| + if (importElement.prefix == null && !exists(importElement)) { |
| + for (ShowElementCombinator combinator |
| + in getShowCombinators(importElement)) { |
| + if (combinator.shownNames.contains(name)) { |
| + return true; |
| + } |
| + } |
| + } |
| + } |
| + } |
| + return false; |
| + } |
| + |
| /** |
| * Create all of the namespaces associated with the libraries imported into |
| * this library. The names are not added to this scope, but are stored for |
| @@ -521,8 +569,7 @@ class LibraryImportScope extends Scope { |
| return foundElement; |
| } |
| for (int i = 0; i < _importedNamespaces.length; i++) { |
| - Namespace nameSpace = _importedNamespaces[i]; |
| - Element element = nameSpace.getPrefixed(prefix, name); |
| + Element element = _importedNamespaces[i].getPrefixed(prefix, name); |
| if (element != null) { |
| if (foundElement == null) { |
| foundElement = element; |
| @@ -1161,6 +1208,20 @@ abstract class Scope { |
| } |
| /** |
| + * Return `true` if the fact that the given [node] is not defined should be |
| + * ignored (from the perspective of error reporting). This will be the case if |
| + * there is at least one import that defines the node's prefix, and if that |
| + * import either has no show combinators or has a show combinator that |
| + * explicitly lists the node's name. |
| + */ |
| + bool shouldIgnoreUndefined(Identifier node) { |
| + if (enclosingScope != null) { |
| + return enclosingScope.shouldIgnoreUndefined(node); |
| + } |
| + return false; |
| + } |
| + |
| + /** |
| * Return the name that will be used to look up the given [element]. |
| */ |
| String _getName(Element element) { |