[dartdevc] use var for top-level

This is a potential workaround for:

https://bugs.webkit.org/show_bug.cgi?id=199866

until a proper fix lands in Safari.  See:

https://github.com/dart-lang/sdk/issues/40380

Change-Id: I66f5aefefcc6c8f12fd3b747fcee587fc16d437d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133542
Commit-Queue: Vijay Menon <vsm@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Vijay Menon 2020-01-31 21:30:32 +00:00 committed by commit-bot@chromium.org
parent a5cfdf6586
commit 18f41ce9e5
3 changed files with 19 additions and 7 deletions

View file

@ -262,7 +262,9 @@ abstract class SharedCompiler<Library, Class, InterfaceType, FunctionNode> {
var idName = name.endsWith('=') ? name.replaceAll('=', '_') : name;
idName = idName.replaceAll(js_ast.invalidCharInIdentifier, '_');
id ??= js_ast.TemporaryId(idName);
moduleItems.add(js.statement('const # = #.privateName(#, #)',
// TODO(vsm): Change back to `const`.
// See https://github.com/dart-lang/sdk/issues/40380.
moduleItems.add(js.statement('var # = #.privateName(#, #)',
[id, runtimeModule, emitLibraryName(library), js.string(name)]));
return id;
}
@ -417,8 +419,10 @@ abstract class SharedCompiler<Library, Class, InterfaceType, FunctionNode> {
var alias = jsLibraryAlias(library);
var aliasId = alias == null ? null : js_ast.TemporaryId(alias);
// TODO(vsm): Change back to `const`.
// See https://github.com/dart-lang/sdk/issues/40380.
items.add(js.statement(
'const # = Object.create(#.library)', [libraryId, runtimeModule]));
'var # = Object.create(#.library)', [libraryId, runtimeModule]));
exports.add(js_ast.NameSpecifier(libraryId, asName: aliasId));
}
@ -426,8 +430,10 @@ abstract class SharedCompiler<Library, Class, InterfaceType, FunctionNode> {
// TODO(jmesserly): find a cleaner design for this.
if (isBuildingSdk) {
var id = extensionSymbolsModule;
items.add(js.statement(
'const # = Object.create(#.library)', [id, runtimeModule]));
// TODO(vsm): Change back to `const`.
// See https://github.com/dart-lang/sdk/issues/40380.
items.add(js
.statement('var # = Object.create(#.library)', [id, runtimeModule]));
exports.add(js_ast.NameSpecifier(id));
}
@ -512,7 +518,9 @@ abstract class SharedCompiler<Library, Class, InterfaceType, FunctionNode> {
if (isBuildingSdk) {
value = js.call('# = Symbol(#)', [value, js.string('dartx.$name')]);
}
items.add(js.statement('const # = #;', [id, value]));
// TODO(vsm): Change back to `const`.
// See https://github.com/dart-lang/sdk/issues/40380.
items.add(js.statement('var # = #;', [id, value]));
});
}

View file

@ -5541,7 +5541,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
js.call('# || #.#', [constAliasId, _constTable, constAliasProperty]);
constAliasCache[node] = constAccessor;
var constJs = super.visitConstant(node);
moduleItems.add(js.statement('let #;', [constAliasId]));
// TODO(vsm): Change back to `let`.
// See https://github.com/dart-lang/sdk/issues/40380.
moduleItems.add(js.statement('var #;', [constAliasId]));
var func = js_ast.Fun(
[],

View file

@ -122,7 +122,9 @@ class _GeneratorTable extends _CacheTable {
if (name != null) {
js_ast.Expression init = _defs.remove(t);
assert(init != null);
return js.statement('let # = () => ((# = #.constFn(#))());',
// TODO(vsm): Change back to `let`.
// See https://github.com/dart-lang/sdk/issues/40380.
return js.statement('var # = () => ((# = #.constFn(#))());',
[name, name, _runtimeModule, init]);
}
return null;