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

Unified Diff: pkg/dev_compiler/lib/src/js_ast/nodes.dart

Issue 2753623002: Support iife heuristic in DDC (Closed)
Patch Set: Created 3 years, 9 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 | « pkg/dev_compiler/lib/src/compiler/module_builder.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/src/js_ast/nodes.dart
diff --git a/pkg/dev_compiler/lib/src/js_ast/nodes.dart b/pkg/dev_compiler/lib/src/js_ast/nodes.dart
index 9cc3a19e724bf4ecff6ba854036a3014f6fb137d..7f4e127dce2d7073f8749b53a2ff5efd7deadda1 100644
--- a/pkg/dev_compiler/lib/src/js_ast/nodes.dart
+++ b/pkg/dev_compiler/lib/src/js_ast/nodes.dart
@@ -1146,8 +1146,12 @@ class Super extends Expression {
class NamedFunction extends Expression {
final Identifier name;
final Fun function;
+ // A heuristic to force extra parens around this function. V8 and other
+ // engines use this IIFE (immediately invoked function expression) heuristic
+ // to eagerly parse a function.
+ final bool immediatelyInvoked;
- NamedFunction(this.name, this.function);
+ NamedFunction(this.name, this.function, [this.immediatelyInvoked = false]);
accept(NodeVisitor visitor) => visitor.visitNamedFunction(this);
@@ -1155,9 +1159,9 @@ class NamedFunction extends Expression {
name.accept(visitor);
function.accept(visitor);
}
- NamedFunction _clone() => new NamedFunction(name, function);
+ NamedFunction _clone() => new NamedFunction(name, function, immediatelyInvoked);
- int get precedenceLevel => PRIMARY_LOW_PRECEDENCE;
+ int get precedenceLevel => immediatelyInvoked ? EXPRESSION : PRIMARY_LOW_PRECEDENCE;
}
abstract class FunctionExpression extends Expression {
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/module_builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698