Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: third_party/closure_linter/closure_linter/tokenutil.py

Issue 2328693002: Updated linter with upstream release (2.3.19) (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/closure_linter/closure_linter/tokenutil.py
diff --git a/third_party/closure_linter/closure_linter/tokenutil.py b/third_party/closure_linter/closure_linter/tokenutil.py
index 8b5dbe1a9a3202b0730715d751f7084b92ec72fc..dedf5aaac4b32f6775cf338949ab2b0d30c52f85 100755
--- a/third_party/closure_linter/closure_linter/tokenutil.py
+++ b/third_party/closure_linter/closure_linter/tokenutil.py
@@ -560,11 +560,11 @@ def GetIdentifierStart(token):
while (previous_code_token and (
previous_code_token.IsType(JavaScriptTokenType.IDENTIFIER) or
- _IsDot(previous_code_token))):
+ IsDot(previous_code_token))):
start_token = previous_code_token
previous_code_token = GetPreviousCodeToken(previous_code_token)
- if _IsDot(start_token):
+ if IsDot(start_token):
return None
return start_token
@@ -593,7 +593,7 @@ def GetIdentifierForToken(token):
prev_token = token.previous
while prev_token:
if (prev_token.IsType(JavaScriptTokenType.IDENTIFIER) or
- _IsDot(prev_token)):
+ IsDot(prev_token)):
return None
if (prev_token.IsType(tokens.TokenType.WHITESPACE) or
@@ -629,19 +629,15 @@ def GetIdentifierForToken(token):
for t in token.next:
last_symbol_token = symbol_tokens[-1]
- # An identifier is part of the previous symbol if it has a trailing
- # dot.
- if t.type in identifier_types:
- if last_symbol_token.string.endswith('.'):
- symbol_tokens.append(t)
- continue
- else:
- break
+ # A dot is part of the previous symbol.
+ if IsDot(t):
+ symbol_tokens.append(t)
+ continue
- # A dot is part of the previous symbol if it does not have a trailing
+ # An identifier is part of the previous symbol if the previous one was a
# dot.
- if _IsDot(t):
- if not last_symbol_token.string.endswith('.'):
+ if t.type in identifier_types:
+ if IsDot(last_symbol_token):
symbol_tokens.append(t)
continue
else:
@@ -682,13 +678,21 @@ def GetStringAfterToken(token):
"""
string_token = SearchUntil(token, JavaScriptTokenType.STRING_TEXT,
[JavaScriptTokenType.SINGLE_QUOTE_STRING_END,
- JavaScriptTokenType.DOUBLE_QUOTE_STRING_END])
+ JavaScriptTokenType.DOUBLE_QUOTE_STRING_END,
+ JavaScriptTokenType.TEMPLATE_STRING_END])
if string_token:
return string_token.string
else:
return None
-def _IsDot(token):
+def IsDot(token):
"""Whether the token represents a "dot" operator (foo.bar)."""
- return token.type is tokens.TokenType.NORMAL and token.string == '.'
+ return token.type is JavaScriptTokenType.OPERATOR and token.string == '.'
+
+
+def IsIdentifierOrDot(token):
+ """Whether the token is either an identifier or a '.'."""
+ return (token.type in [JavaScriptTokenType.IDENTIFIER,
+ JavaScriptTokenType.SIMPLE_LVALUE] or
+ IsDot(token))

Powered by Google App Engine
This is Rietveld 408576698