@@ -215,6 +215,7 @@ function tsPlugin(options?: {
215
215
* default kind is undefined
216
216
* */
217
217
importOrExportOuterKind : string | undefined = undefined ;
218
+ ecmaVersion : number ;
218
219
219
220
tsParseConstModifier = this . tsParseModifiers . bind ( this , {
220
221
allowedModifiers : [ 'const' ] ,
@@ -225,6 +226,8 @@ function tsPlugin(options?: {
225
226
226
227
constructor ( options : Options , input : string , startPos ?: number ) {
227
228
super ( options , input , startPos ) ;
229
+ // Acorn normalizes this to numbers 3-16 etc, but it's not reflected in the types
230
+ this . ecmaVersion = this . options . ecmaVersion as number ;
228
231
}
229
232
230
233
// support in Class static
@@ -2699,13 +2702,13 @@ function tsPlugin(options?: {
2699
2702
forInit ?: boolean
2700
2703
) {
2701
2704
this . initFunction ( node ) ;
2702
- if ( this . options . ecmaVersion >= 9 || ( this . options . ecmaVersion >= 6 && ! isAsync ) ) {
2705
+ if ( this . ecmaVersion >= 9 || ( this . ecmaVersion >= 6 && ! isAsync ) ) {
2703
2706
if ( this . type === tt . star && statement & FUNC_HANGING_STATEMENT ) {
2704
2707
this . unexpected ( ) ;
2705
2708
}
2706
2709
node . generator = this . eat ( tt . star ) ;
2707
2710
}
2708
- if ( this . options . ecmaVersion >= 8 ) {
2711
+ if ( this . ecmaVersion >= 8 ) {
2709
2712
node . async = ! ! isAsync ;
2710
2713
}
2711
2714
if ( statement & FUNC_STATEMENT ) {
@@ -2799,7 +2802,7 @@ function tsPlugin(options?: {
2799
2802
if ( this . containsEsc ) this . raiseRecoverable ( this . start , 'Escape sequence in keyword new' ) ;
2800
2803
let node = this . startNode ( ) ;
2801
2804
let meta = this . parseIdent ( true ) ;
2802
- if ( this . options . ecmaVersion >= 6 && this . eat ( tt . dot ) ) {
2805
+ if ( this . ecmaVersion >= 6 && this . eat ( tt . dot ) ) {
2803
2806
node . meta = meta ;
2804
2807
let containsEsc = this . containsEsc ;
2805
2808
@@ -2833,7 +2836,7 @@ function tsPlugin(options?: {
2833
2836
}
2834
2837
// ---end
2835
2838
if ( this . eat ( tt . parenL ) )
2836
- node . arguments = this . parseExprList ( tt . parenR , this . options . ecmaVersion >= 8 , false ) ;
2839
+ node . arguments = this . parseExprList ( tt . parenR , this . ecmaVersion >= 8 , false ) ;
2837
2840
else node . arguments = [ ] ;
2838
2841
return this . finishNode ( node , 'NewExpression' ) ;
2839
2842
}
@@ -2985,7 +2988,7 @@ function tsPlugin(options?: {
2985
2988
}
2986
2989
2987
2990
parseExportAllDeclaration ( node , exports ) {
2988
- if ( this . options . ecmaVersion >= 11 ) {
2991
+ if ( this . ecmaVersion >= 11 ) {
2989
2992
if ( this . eatContextual ( 'as' ) ) {
2990
2993
node . exported = this . parseModuleExportName ( ) ;
2991
2994
this . checkExport ( exports , node . exported , this . lastTokStart ) ;
@@ -3196,7 +3199,7 @@ function tsPlugin(options?: {
3196
3199
containsEsc = this . containsEsc ;
3197
3200
let id = this . parseIdent ( false ) ;
3198
3201
if (
3199
- this . options . ecmaVersion >= 8 &&
3202
+ this . ecmaVersion >= 8 &&
3200
3203
! containsEsc &&
3201
3204
id . name === 'async' &&
3202
3205
! this . canInsertSemicolon ( ) &&
@@ -3220,7 +3223,7 @@ function tsPlugin(options?: {
3220
3223
forInit
3221
3224
) ;
3222
3225
if (
3223
- this . options . ecmaVersion >= 8 &&
3226
+ this . ecmaVersion >= 8 &&
3224
3227
id . name === 'async' &&
3225
3228
this . type === tt . name &&
3226
3229
! containsEsc &&
@@ -3637,7 +3640,6 @@ function tsPlugin(options?: {
3637
3640
parseClassElement ( constructorAllowsSuper ) {
3638
3641
if ( this . eat ( tt . semi ) ) return null ;
3639
3642
3640
- const ecmaVersion = this . options . ecmaVersion ;
3641
3643
let node = this . startNode ( ) ;
3642
3644
let keyName = '' ;
3643
3645
let isGenerator = false ;
@@ -3672,7 +3674,7 @@ function tsPlugin(options?: {
3672
3674
if ( this . tsHasSomeModifiers ( node , modifiers ) ) {
3673
3675
this . raise ( this . start , TypeScriptError . StaticBlockCannotHaveModifier ) ;
3674
3676
}
3675
- if ( ecmaVersion >= 13 ) {
3677
+ if ( this . ecmaVersion >= 13 ) {
3676
3678
super . parseClassStaticBlock ( node ) ;
3677
3679
return node ;
3678
3680
}
@@ -3719,7 +3721,7 @@ function tsPlugin(options?: {
3719
3721
keyName = 'static' ;
3720
3722
}
3721
3723
}
3722
- if ( ! keyName && ecmaVersion >= 8 && this . eatContextual ( 'async' ) ) {
3724
+ if ( ! keyName && this . ecmaVersion >= 8 && this . eatContextual ( 'async' ) ) {
3723
3725
if (
3724
3726
( this . isClassElementNameStart ( ) || this . type === tt . star ) &&
3725
3727
! this . canInsertSemicolon ( )
@@ -3730,7 +3732,7 @@ function tsPlugin(options?: {
3730
3732
}
3731
3733
}
3732
3734
3733
- if ( ! keyName && ( ecmaVersion >= 9 || ! isAsync ) && this . eat ( tt . star ) ) {
3735
+ if ( ! keyName && ( this . ecmaVersion >= 9 || ! isAsync ) && this . eat ( tt . star ) ) {
3734
3736
isGenerator = true ;
3735
3737
}
3736
3738
if ( ! keyName && ! isAsync && ! isGenerator ) {
@@ -3761,7 +3763,7 @@ function tsPlugin(options?: {
3761
3763
// Parse element value
3762
3764
if (
3763
3765
this . isClassMethod ( ) ||
3764
- ecmaVersion < 13 ||
3766
+ this . ecmaVersion < 13 ||
3765
3767
this . type === tt . parenL ||
3766
3768
kind !== 'method' ||
3767
3769
isGenerator ||
@@ -3848,7 +3850,7 @@ function tsPlugin(options?: {
3848
3850
this . enterScope ( functionFlags ( isAsync , false ) | acornScope . SCOPE_ARROW ) ;
3849
3851
this . initFunction ( node ) ;
3850
3852
const oldMaybeInArrowParameters = this . maybeInArrowParameters ;
3851
- if ( this . options . ecmaVersion >= 8 ) node . async = ! ! isAsync ;
3853
+ if ( this . ecmaVersion >= 8 ) node . async = ! ! isAsync ;
3852
3854
3853
3855
this . yieldPos = 0 ;
3854
3856
this . awaitPos = 0 ;
@@ -4313,8 +4315,8 @@ function tsPlugin(options?: {
4313
4315
let startPos = this . start ,
4314
4316
startLoc = this . startLoc ,
4315
4317
val ,
4316
- allowTrailingComma = this . options . ecmaVersion >= 8 ;
4317
- if ( this . options . ecmaVersion >= 6 ) {
4318
+ allowTrailingComma = this . ecmaVersion >= 8 ;
4319
+ if ( this . ecmaVersion >= 6 ) {
4318
4320
const oldMaybeInArrowParameters = this . maybeInArrowParameters ;
4319
4321
this . maybeInArrowParameters = true ;
4320
4322
this . next ( ) ;
@@ -4542,7 +4544,7 @@ function tsPlugin(options?: {
4542
4544
// possibleAsync always false here, because we would have handled it above.
4543
4545
node . arguments = this . parseExprList (
4544
4546
tt . parenR ,
4545
- this . options . ecmaVersion >= 8 ,
4547
+ this . ecmaVersion >= 8 ,
4546
4548
false ,
4547
4549
refDestructuringErrors
4548
4550
) ;
@@ -4594,7 +4596,7 @@ function tsPlugin(options?: {
4594
4596
}
4595
4597
}
4596
4598
// --- end
4597
- let optionalSupported = this . options . ecmaVersion >= 11 ;
4599
+ let optionalSupported = this . ecmaVersion >= 11 ;
4598
4600
let optional = optionalSupported && this . eat ( tt . questionDot ) ;
4599
4601
if ( noCalls && optional )
4600
4602
this . raise (
@@ -4634,7 +4636,7 @@ function tsPlugin(options?: {
4634
4636
this . awaitIdentPos = 0 ;
4635
4637
let exprList = this . parseExprList (
4636
4638
tt . parenR ,
4637
- this . options . ecmaVersion >= 8 ,
4639
+ this . ecmaVersion >= 8 ,
4638
4640
false ,
4639
4641
refDestructuringErrors
4640
4642
) ;
@@ -4834,7 +4836,7 @@ function tsPlugin(options?: {
4834
4836
4835
4837
parseClassFunctionParams ( ) {
4836
4838
const typeParameters = this . tsTryParseTypeParameters ( this . tsParseConstModifier ) ;
4837
- let params = this . parseBindingList ( tt . parenR , false , this . options . ecmaVersion >= 8 , true ) ;
4839
+ let params = this . parseBindingList ( tt . parenR , false , this . ecmaVersion >= 8 , true ) ;
4838
4840
if ( typeParameters ) params . typeParameters = typeParameters ;
4839
4841
4840
4842
return params ;
@@ -4852,8 +4854,8 @@ function tsPlugin(options?: {
4852
4854
oldAwaitPos = this . awaitPos ,
4853
4855
oldAwaitIdentPos = this . awaitIdentPos ;
4854
4856
this . initFunction ( node ) ;
4855
- if ( this . options . ecmaVersion >= 6 ) node . generator = isGenerator ;
4856
- if ( this . options . ecmaVersion >= 8 ) node . async = ! ! isAsync ;
4857
+ if ( this . ecmaVersion >= 6 ) node . generator = isGenerator ;
4858
+ if ( this . ecmaVersion >= 8 ) node . async = ! ! isAsync ;
4857
4859
4858
4860
this . yieldPos = 0 ;
4859
4861
this . awaitPos = 0 ;
0 commit comments