@@ -20,7 +20,7 @@ interface Context {
20
20
allowIn : boolean ;
21
21
allowStrictDirective : boolean ;
22
22
allowYield : boolean ;
23
- await : boolean ;
23
+ isAsync : boolean ;
24
24
firstCoverInitializedNameError : RawToken | null ;
25
25
isAssignmentTarget : boolean ;
26
26
isBindingElement : boolean ;
@@ -144,7 +144,7 @@ export class Parser {
144
144
145
145
this . context = {
146
146
isModule : false ,
147
- await : false ,
147
+ isAsync : false ,
148
148
allowIn : true ,
149
149
allowStrictDirective : true ,
150
150
allowYield : true ,
@@ -621,7 +621,7 @@ export class Parser {
621
621
622
622
switch ( this . lookahead . type ) {
623
623
case Token . Identifier :
624
- if ( ( this . context . isModule || this . context . await ) && this . lookahead . value === 'await' ) {
624
+ if ( ( this . context . isModule || this . context . isAsync ) && this . lookahead . value === 'await' ) {
625
625
this . tolerateUnexpectedToken ( this . lookahead ) ;
626
626
}
627
627
expr = this . matchAsyncFunction ( ) ? this . parseFunctionExpression ( ) : this . finalize ( node , new Node . Identifier ( this . nextToken ( ) . value ) ) ;
@@ -796,18 +796,14 @@ export class Parser {
796
796
const node = this . createNode ( ) ;
797
797
798
798
const previousAllowYield = this . context . allowYield ;
799
- const previousAwait = this . context . await ;
799
+ const previousIsAsync = this . context . isAsync ;
800
800
this . context . allowYield = false ;
801
- this . context . await = true ;
801
+ this . context . isAsync = true ;
802
802
803
803
const params = this . parseFormalParameters ( ) ;
804
- if ( params . message === Messages . StrictParamDupe ) {
805
- this . throwError ( Messages . DuplicateParameter ) ;
806
- }
807
-
808
804
const method = this . parsePropertyMethod ( params ) ;
809
805
this . context . allowYield = previousAllowYield ;
810
- this . context . await = previousAwait ;
806
+ this . context . isAsync = previousIsAsync ;
811
807
812
808
return this . finalize ( node , new Node . AsyncFunctionExpression ( null , params . params , method , isGenerator ) ) ;
813
809
}
@@ -1567,7 +1563,7 @@ export class Parser {
1567
1563
}
1568
1564
this . context . isAssignmentTarget = false ;
1569
1565
this . context . isBindingElement = false ;
1570
- } else if ( this . context . await && this . matchContextualKeyword ( 'await' ) ) {
1566
+ } else if ( this . context . isAsync && this . matchContextualKeyword ( 'await' ) ) {
1571
1567
expr = this . parseAwaitExpression ( ) ;
1572
1568
} else {
1573
1569
expr = this . parseUpdateExpression ( ) ;
@@ -1798,9 +1794,9 @@ export class Parser {
1798
1794
}
1799
1795
}
1800
1796
1801
- if ( options . message === Messages . StrictParamDupe ) {
1797
+ if ( options . hasDuplicateParameterNames ) {
1802
1798
const token = this . context . strict ? options . stricted : options . firstRestricted ;
1803
- this . throwUnexpectedToken ( token , options . message ) ;
1799
+ this . throwUnexpectedToken ( token , Messages . DuplicateParameter ) ;
1804
1800
}
1805
1801
1806
1802
return {
@@ -1853,9 +1849,9 @@ export class Parser {
1853
1849
this . context . allowStrictDirective = list . simple ;
1854
1850
1855
1851
const previousAllowYield = this . context . allowYield ;
1856
- const previousAwait = this . context . await ;
1852
+ const previousIsAsync = this . context . isAsync ;
1857
1853
this . context . allowYield = true ;
1858
- this . context . await = isAsync ;
1854
+ this . context . isAsync = isAsync ;
1859
1855
1860
1856
const node = this . startNode ( startToken ) ;
1861
1857
this . expect ( '=>' ) ;
@@ -1882,7 +1878,7 @@ export class Parser {
1882
1878
this . context . strict = previousStrict ;
1883
1879
this . context . allowStrictDirective = previousAllowStrictDirective ;
1884
1880
this . context . allowYield = previousAllowYield ;
1885
- this . context . await = previousAwait ;
1881
+ this . context . isAsync = previousIsAsync ;
1886
1882
}
1887
1883
} else {
1888
1884
@@ -2233,7 +2229,7 @@ export class Parser {
2233
2229
this . throwUnexpectedToken ( token ) ;
2234
2230
}
2235
2231
}
2236
- } else if ( ( this . context . isModule || this . context . await ) && token . type === Token . Identifier && token . value === 'await' ) {
2232
+ } else if ( ( this . context . isModule || this . context . isAsync ) && token . type === Token . Identifier && token . value === 'await' ) {
2237
2233
this . tolerateUnexpectedToken ( token ) ;
2238
2234
}
2239
2235
@@ -2403,7 +2399,7 @@ export class Parser {
2403
2399
const node = this . createNode ( ) ;
2404
2400
this . expectKeyword ( 'for' ) ;
2405
2401
if ( this . matchContextualKeyword ( 'await' ) ) {
2406
- if ( ! this . context . await ) {
2402
+ if ( ! this . context . isAsync ) {
2407
2403
this . tolerateUnexpectedToken ( this . lookahead ) ;
2408
2404
}
2409
2405
_await = true ;
@@ -2975,7 +2971,7 @@ export class Parser {
2975
2971
}
2976
2972
if ( Object . prototype . hasOwnProperty . call ( options . paramSet , key ) ) {
2977
2973
options . stricted = param ;
2978
- options . message = Messages . StrictParamDupe ;
2974
+ options . hasDuplicateParameterNames = true ;
2979
2975
}
2980
2976
} else if ( ! options . firstRestricted ) {
2981
2977
if ( this . scanner . isRestrictedWord ( name ) ) {
@@ -2986,7 +2982,7 @@ export class Parser {
2986
2982
options . message = Messages . StrictReservedWord ;
2987
2983
} else if ( Object . prototype . hasOwnProperty . call ( options . paramSet , key ) ) {
2988
2984
options . stricted = param ;
2989
- options . message = Messages . StrictParamDupe ;
2985
+ options . hasDuplicateParameterNames = true ;
2990
2986
}
2991
2987
}
2992
2988
@@ -3026,6 +3022,7 @@ export class Parser {
3026
3022
parseFormalParameters ( firstRestricted ?) {
3027
3023
const options : any = {
3028
3024
simple : true ,
3025
+ hasDuplicateParameterNames : false ,
3029
3026
params : [ ] ,
3030
3027
firstRestricted : firstRestricted
3031
3028
} ;
@@ -3046,6 +3043,12 @@ export class Parser {
3046
3043
}
3047
3044
this . expect ( ')' ) ;
3048
3045
3046
+ if ( options . hasDuplicateParameterNames ) {
3047
+ if ( this . context . strict || this . context . isAsync || ! options . simple ) {
3048
+ this . throwError ( Messages . DuplicateParameter ) ;
3049
+ }
3050
+ }
3051
+
3049
3052
return {
3050
3053
simple : options . simple ,
3051
3054
params : options . params ,
@@ -3109,16 +3112,12 @@ export class Parser {
3109
3112
}
3110
3113
}
3111
3114
3112
- const previousAllowAwait = this . context . await ;
3115
+ const previousIsAsync = this . context . isAsync ;
3113
3116
const previousAllowYield = this . context . allowYield ;
3114
- this . context . await = isAsync ;
3117
+ this . context . isAsync = isAsync ;
3115
3118
this . context . allowYield = ! isGenerator ;
3116
3119
3117
3120
const formalParameters = this . parseFormalParameters ( firstRestricted ) ;
3118
- if ( isGenerator && formalParameters . message === Messages . StrictParamDupe ) {
3119
- this . throwError ( Messages . DuplicateParameter ) ;
3120
- }
3121
-
3122
3121
const params = formalParameters . params ;
3123
3122
const stricted = formalParameters . stricted ;
3124
3123
firstRestricted = formalParameters . firstRestricted ;
@@ -3139,7 +3138,7 @@ export class Parser {
3139
3138
3140
3139
this . context . strict = previousStrict ;
3141
3140
this . context . allowStrictDirective = previousAllowStrictDirective ;
3142
- this . context . await = previousAllowAwait ;
3141
+ this . context . isAsync = previousIsAsync ;
3143
3142
this . context . allowYield = previousAllowYield ;
3144
3143
3145
3144
return isAsync
@@ -3166,9 +3165,9 @@ export class Parser {
3166
3165
let id : Node . Identifier | null = null ;
3167
3166
let firstRestricted ;
3168
3167
3169
- const previousAllowAwait = this . context . await ;
3168
+ const previousIsAsync = this . context . isAsync ;
3170
3169
const previousAllowYield = this . context . allowYield ;
3171
- this . context . await = isAsync ;
3170
+ this . context . isAsync = isAsync ;
3172
3171
this . context . allowYield = ! isGenerator ;
3173
3172
3174
3173
if ( ! this . match ( '(' ) ) {
@@ -3190,12 +3189,6 @@ export class Parser {
3190
3189
}
3191
3190
3192
3191
const formalParameters = this . parseFormalParameters ( firstRestricted ) ;
3193
- if ( formalParameters . message === Messages . StrictParamDupe ) {
3194
- if ( isGenerator || isAsync ) {
3195
- this . throwError ( Messages . DuplicateParameter ) ;
3196
- }
3197
- }
3198
-
3199
3192
const params = formalParameters . params ;
3200
3193
const stricted = formalParameters . stricted ;
3201
3194
firstRestricted = formalParameters . firstRestricted ;
@@ -3215,7 +3208,7 @@ export class Parser {
3215
3208
}
3216
3209
this . context . strict = previousStrict ;
3217
3210
this . context . allowStrictDirective = previousAllowStrictDirective ;
3218
- this . context . await = previousAllowAwait ;
3211
+ this . context . isAsync = previousIsAsync ;
3219
3212
this . context . allowYield = previousAllowYield ;
3220
3213
3221
3214
return isAsync
0 commit comments