fix(code size): revert previous devMode change to restore size targets

This commit reverts a8d9dbf that introduced a code size regression (16kb gzipped, 63kb minified) in Dart.

Effect on the hello world app:

gzipped: 105kb -> 89kb
minified: 370kb -> 317kb

BREAKING CHANGE:
- This is very unlikely to be breaking, but I'm still marking just in case. The only change to the user should be that dev mode is driven by Dart's checked mode, like it was in the past.
This commit is contained in:
Yegor Jbanov 2015-12-15 00:11:04 -08:00 committed by Yegor
parent 197cf09689
commit c47d85b038
1 changed files with 24 additions and 28 deletions

View File

@ -257,38 +257,34 @@ bool isJsObject(o) {
return false;
}
bool _forceDevMode = true;
bool _modeLocked = false;
void lockMode() {
_modeLocked = true;
}
@deprecated
void enableDevMode() {
if (_forceDevMode) {
return;
}
if (_modeLocked) {
throw new Exception("Cannot enable dev mode after platform setup.");
}
_forceDevMode = true;
}
void enableProdMode() {
if (_forceDevMode) {
return;
}
if (_modeLocked) {
throw new Exception("Cannot enable prod mode after platform setup.");
}
_forceDevMode = false;
}
// Functions below are noop in Dart. Imperatively controlling dev mode kills
// tree shaking. We should only rely on `assertionsEnabled`.
@Deprecated('Do not use this function. It is for JS only. There is no alternative.')
void lockMode() {}
@Deprecated('Do not use this function. It is for JS only. There is no alternative.')
void enableDevMode() {}
@Deprecated('Do not use this function. It is for JS only. There is no alternative.')
void enableProdMode() {}
/// Use this function to guard debugging code. When Dart is compiled in
/// production mode, the code guarded using this function will be tree
/// shaken away, reducing code size.
///
/// WARNING: DO NOT CHANGE THIS METHOD! This method is designed to have no
/// more AST nodes than the maximum allowed by dart2js to inline it. In
/// addition, the use of `assert` allows the compiler to statically compute
/// the value returned by this function and tree shake conditions guarded by
/// it.
///
/// Example:
///
/// if (assertionsEnabled()) {
/// ...code here is tree shaken away in prod mode...
/// }
bool assertionsEnabled() {
var k = false;
assert((k = true));
return _forceDevMode || k;
return k;
}
// Can't be all uppercase as our transpiler would think it is a special directive...