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

Unified Diff: lib/src/codegen/js_names.dart

Issue 1133593004: fixes #131, use before define from variables to classes (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « lib/src/codegen/js_module_item_order.dart ('k') | lib/src/codegen/side_effect_analysis.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_names.dart
diff --git a/lib/src/codegen/js_names.dart b/lib/src/codegen/js_names.dart
index 00ee437a6231bef9120e9a0ab4c880c9ac3e9e93..e050532a4a35e22d240de3ae0db6b30abef564e8 100644
--- a/lib/src/codegen/js_names.dart
+++ b/lib/src/codegen/js_names.dart
@@ -17,13 +17,44 @@ class TemporaryId extends Identifier {
TemporaryId(String name) : super(name);
}
+/// Creates a qualified identifier, without determining for sure if it needs to
+/// be qualified until [setQualified] is called.
+///
+/// This expression is transparent to visiting after [setQualified].
+class MaybeQualifiedId extends Expression {
+ Expression _expr;
+
+ final Identifier qualifier;
+ final Expression name;
+
+ MaybeQualifiedId(this.qualifier, this.name) {
+ _expr = new PropertyAccess(qualifier, name);
+ }
+
+ /// Helper to create an [Identifier] from something that starts as a property.
+ static identifier(LiteralString propertyName) =>
+ new Identifier(propertyName.valueWithoutQuotes);
+
+ void setQualified(bool qualified) {
+ if (!qualified && name is LiteralString) {
+ _expr = identifier(name);
+ }
+ }
+
+ int get precedenceLevel => _expr.precedenceLevel;
+
+ accept(NodeVisitor visitor) => _expr.accept(visitor);
+
+ void visitChildren(NodeVisitor visitor) => _expr.visitChildren(visitor);
+}
+
/// This class has two purposes:
///
/// * rename JS identifiers to avoid keywords.
/// * rename temporary variables to avoid colliding with user-specified names,
/// or other temporaries
///
-/// Each instance of [JSTemporary] is treated as a unique variable, with its
+/// Each instance of [TemporaryId] is treated as a unique variable, with its
/// `name` field simply the suggestion of what name to use. By contrast
/// [Identifiers] are never renamed unless they are an invalid identifier, like
/// `function` or `instanceof`, and their `name` field controls whether they
@@ -115,7 +146,6 @@ class _RenameVisitor extends VariableDeclarationVisitor {
if (needsRename(node)) {
usedIn = pendingRenames.putIfAbsent(id, () => new HashSet());
}
-
for (var s = scope, end = declScope.parent; s != end; s = s.parent) {
if (usedIn != null) {
usedIn.add(s);
@@ -184,7 +214,7 @@ class _RenameVisitor extends VariableDeclarationVisitor {
bool needsRename(Identifier node) =>
node is TemporaryId || node.allowRename && invalidVariableName(node.name);
-Object /*String|JSTemporary*/ identifierKey(Identifier node) =>
+Object /*String|TemporaryId*/ identifierKey(Identifier node) =>
node is TemporaryId ? node : node.name;
/// Returns true for invalid JS variable names, such as keywords.
« no previous file with comments | « lib/src/codegen/js_module_item_order.dart ('k') | lib/src/codegen/side_effect_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698