From 241632aaa118610077646ad59b3f9eda25d298ea Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Tue, 15 Sep 2015 12:11:26 -0700 Subject: [PATCH] feat(code size): make assertionsEnabled() statically computable by dart2js Our existing implementation prevented dart2js from statically deducing the return value. This fix does not yet result in better tree-shaking due to the following dart2js bugs: https://github.com/dart-lang/sdk/issues/24354 https://github.com/dart-lang/sdk/issues/24355 Closes #4198 --- modules/angular2/src/core/facade/lang.dart | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/modules/angular2/src/core/facade/lang.dart b/modules/angular2/src/core/facade/lang.dart index 3939834ec5..9ff4b23fd9 100644 --- a/modules/angular2/src/core/facade/lang.dart +++ b/modules/angular2/src/core/facade/lang.dart @@ -243,17 +243,11 @@ bool isJsObject(o) { return false; } -var _assertionsEnabled = null; bool assertionsEnabled() { - if (_assertionsEnabled == null) { - try { - assert(false); - _assertionsEnabled = false; - } catch (e) { - _assertionsEnabled = true; - } - } - return _assertionsEnabled; + // TODO(yjbanov): verify that this is inlined after https://github.com/dart-lang/sdk/issues/24355 + bool k = false; + assert((k = true)); + return k; } // Can't be all uppercase as our transpiler would think it is a special directive...