diff --git a/pkg/dev_compiler/lib/src/codegen/js_codegen.dart b/pkg/dev_compiler/lib/src/codegen/js_codegen.dart index e9389cc8570c..824fc0182929 100644 --- a/pkg/dev_compiler/lib/src/codegen/js_codegen.dart +++ b/pkg/dev_compiler/lib/src/codegen/js_codegen.dart @@ -885,23 +885,25 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { var body = []; for (var param in parameters.parameters) { - // TODO(justinfagnani): rename identifier if necessary - var name = param.identifier.name; + var jsParam = _visit(param.identifier); if (param.kind == ParameterKind.NAMED) { + // Parameters will be passed using their real names, not the (possibly + // renamed) local variable. + var paramName = js.string(param.identifier.name, "'"); body.add(js.statement('let # = # && # in # ? #.# : #;', [ - name, + jsParam, _namedArgTemp, - js.string(name, "'"), + paramName, _namedArgTemp, _namedArgTemp, - name, + paramName, _defaultParamValue(param), ])); } else if (param.kind == ParameterKind.POSITIONAL) { body.add(js.statement('if (# === void 0) # = #;', [ - name, - name, + jsParam, + jsParam, _defaultParamValue(param) ])); } diff --git a/pkg/dev_compiler/test/codegen/expect/temps.js b/pkg/dev_compiler/test/codegen/expect/temps.js index 821b41bedc87..c873da0999dd 100644 --- a/pkg/dev_compiler/test/codegen/expect/temps.js +++ b/pkg/dev_compiler/test/codegen/expect/temps.js @@ -11,11 +11,27 @@ var temps; this[_function] = func; } } + let _opt = Symbol('_opt'); + class OptionalArg extends core.Object { + OptionalArg(opt) { + if (opt === void 0) + opt = 123; + this[_opt] = opt; + } + named(opts) { + let opt = opts && '_opt' in opts ? opts._opt : 456; + this[_opt] = opt; + } + } + dart.defineNamedConstructor(OptionalArg, 'named'); // Function main: () → dynamic function main() { core.print(new FormalCollision(1, 2, x => x)); + core.print(new OptionalArg()[_opt]); + core.print(new OptionalArg.named()[_opt]); } // Exports: exports.FormalCollision = FormalCollision; + exports.OptionalArg = OptionalArg; exports.main = main; })(temps || (temps = {})); diff --git a/pkg/dev_compiler/test/codegen/temps.dart b/pkg/dev_compiler/test/codegen/temps.dart index 833874c44a4e..cb63c0a6cf3b 100644 --- a/pkg/dev_compiler/test/codegen/temps.dart +++ b/pkg/dev_compiler/test/codegen/temps.dart @@ -10,6 +10,14 @@ class FormalCollision { FormalCollision(this._x, this.__x, this._function); } +class OptionalArg { + int _opt; + OptionalArg([this._opt = 123]); + OptionalArg.named({this._opt: 456}); +} + main() { print(new FormalCollision(1, 2, (x) => x)); + print(new OptionalArg()._opt); + print(new OptionalArg.named()._opt); }