[javascriptlint-commit] SF.net SVN: javascriptlint:[230] trunk/pyjsl/lint.py
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2008-08-28 00:25:44
|
Revision: 230
http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=230&view=rev
Author: matthiasmiller
Date: 2008-08-28 00:25:42 +0000 (Thu, 28 Aug 2008)
Log Message:
-----------
improve pyjsl.lint.Scope's contract:
* Outer-level scopes will never be associated with a node.
* All inner-level scopes will always be associated with a node.
Modified Paths:
--------------
trunk/pyjsl/lint.py
Modified: trunk/pyjsl/lint.py
===================================================================
--- trunk/pyjsl/lint.py 2008-08-28 00:18:44 UTC (rev 229)
+++ trunk/pyjsl/lint.py 2008-08-28 00:25:42 UTC (rev 230)
@@ -72,16 +72,20 @@
return (comment, keyword, parms)
class Scope:
- def __init__(self, node):
- """ node may be None """
+ """ Outer-level scopes will never be associated with a node.
+ Inner-level scopes will always be associated with a node.
+ """
+ def __init__(self):
self._parent = None
self._kids = []
self._identifiers = {}
self._references = []
- self._node = node
+ self._node = None
def add_scope(self, node):
- self._kids.append(Scope(node))
+ assert not node is None
+ self._kids.append(Scope())
self._kids[-1]._parent = self
+ self._kids[-1]._node = node
return self._kids[-1]
def add_declaration(self, name, node):
self._identifiers[name] = node
@@ -157,22 +161,22 @@
child._find_unreferenced_and_undeclared(unreferenced, undeclared,
is_in_with_scope)
def find_scope(self, node):
- if not self._node:
- return None
-
for kid in self._kids:
scope = kid.find_scope(node)
if scope:
return scope
# Always add it to the outer scope.
- if not self._parent or \
- (node.start_pos() >= self._node.start_pos() and \
+ if not self._parent:
+ assert not self._node
+ return self
+
+ # Conditionally add it to an inner scope.
+ assert self._node
+ if (node.start_pos() >= self._node.start_pos() and \
node.end_pos() <= self._node.end_pos()):
return self
- return None
-
def lint_files(paths, lint_error, conf=conf.Conf()):
def lint_file(path):
def import_script(import_path):
@@ -258,7 +262,7 @@
# Cache empty results for this script.
assert not script_cache
script_cache['imports'] = set()
- script_cache['scope'] = Scope(None)
+ script_cache['scope'] = Scope()
# Report errors and quit.
for pos, msg in parse_errors:
@@ -321,7 +325,7 @@
assert not script_cache
imports = script_cache['imports'] = set()
- scope = script_cache['scope'] = Scope(root)
+ scope = script_cache['scope'] = Scope()
# Push the scope/variable checks.
visitation.make_visitors(visitors, [_get_scope_checks(scope, report)])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|