File tree 3 files changed +33
-7
lines changed
3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -885,23 +885,25 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
885
885
886
886
var body = [];
887
887
for (var param in parameters.parameters) {
888
- // TODO(justinfagnani): rename identifier if necessary
889
- var name = param.identifier.name;
888
+ var jsParam = _visit (param.identifier);
890
889
891
890
if (param.kind == ParameterKind .NAMED ) {
891
+ // Parameters will be passed using their real names, not the (possibly
892
+ // renamed) local variable.
893
+ var paramName = js.string (param.identifier.name, "'" );
892
894
body.add (js.statement ('let # = # && # in # ? #.# : #;' , [
893
- name ,
895
+ jsParam ,
894
896
_namedArgTemp,
895
- js. string (name, "'" ) ,
897
+ paramName ,
896
898
_namedArgTemp,
897
899
_namedArgTemp,
898
- name ,
900
+ paramName ,
899
901
_defaultParamValue (param),
900
902
]));
901
903
} else if (param.kind == ParameterKind .POSITIONAL ) {
902
904
body.add (js.statement ('if (# === void 0) # = #;' , [
903
- name ,
904
- name ,
905
+ jsParam ,
906
+ jsParam ,
905
907
_defaultParamValue (param)
906
908
]));
907
909
}
Original file line number Diff line number Diff line change @@ -11,11 +11,27 @@ var temps;
11
11
this [ _function ] = func ;
12
12
}
13
13
}
14
+ let _opt = Symbol ( '_opt' ) ;
15
+ class OptionalArg extends core . Object {
16
+ OptionalArg ( opt ) {
17
+ if ( opt === void 0 )
18
+ opt = 123 ;
19
+ this [ _opt ] = opt ;
20
+ }
21
+ named ( opts ) {
22
+ let opt = opts && '_opt' in opts ? opts . _opt : 456 ;
23
+ this [ _opt ] = opt ;
24
+ }
25
+ }
26
+ dart . defineNamedConstructor ( OptionalArg , 'named' ) ;
14
27
// Function main: () → dynamic
15
28
function main ( ) {
16
29
core . print ( new FormalCollision ( 1 , 2 , x => x ) ) ;
30
+ core . print ( new OptionalArg ( ) [ _opt ] ) ;
31
+ core . print ( new OptionalArg . named ( ) [ _opt ] ) ;
17
32
}
18
33
// Exports:
19
34
exports . FormalCollision = FormalCollision ;
35
+ exports . OptionalArg = OptionalArg ;
20
36
exports . main = main ;
21
37
} ) ( temps || ( temps = { } ) ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,14 @@ class FormalCollision {
10
10
FormalCollision (this ._x, this .__x, this ._function);
11
11
}
12
12
13
+ class OptionalArg {
14
+ int _opt;
15
+ OptionalArg ([this ._opt = 123 ]);
16
+ OptionalArg .named ({this ._opt: 456 });
17
+ }
18
+
13
19
main () {
14
20
print (new FormalCollision (1 , 2 , (x) => x));
21
+ print (new OptionalArg ()._opt);
22
+ print (new OptionalArg .named ()._opt);
15
23
}
You can’t perform that action at this time.
0 commit comments