11import { types as t } from "@babel/core" ;
2- import type { File , PluginAPI , PluginObject } from "@babel/core" ;
2+ import type { PluginAPI , PluginObject } from "@babel/core" ;
33import type { NodePath } from "@babel/traverse" ;
44import nameFunction from "@babel/helper-function-name" ;
55import splitExportDeclaration from "@babel/helper-split-export-declaration" ;
@@ -45,7 +45,7 @@ export function createClassFeaturePlugin({
4545 // @ts -ignore TODO(Babel 8): Remove the default value
4646 api = { assumption : ( ) => void 0 } ,
4747 inherits,
48- } : Options ) {
48+ } : Options ) : PluginObject {
4949 const setPublicClassFields = api . assumption ( "setPublicClassFields" ) ;
5050 const privateFieldsAsProperties = api . assumption ( "privateFieldsAsProperties" ) ;
5151 const constantSuper = api . assumption ( "constantSuper" ) ;
@@ -81,23 +81,23 @@ export function createClassFeaturePlugin({
8181 manipulateOptions,
8282 inherits,
8383
84- pre ( ) {
85- enableFeature ( this . file , feature , loose ) ;
84+ pre ( file ) {
85+ enableFeature ( file , feature , loose ) ;
8686
87- if ( ! this . file . get ( versionKey ) || this . file . get ( versionKey ) < version ) {
88- this . file . set ( versionKey , version ) ;
87+ if ( ! file . get ( versionKey ) || file . get ( versionKey ) < version ) {
88+ file . set ( versionKey , version ) ;
8989 }
9090 } ,
9191
9292 visitor : {
93- Class ( path : NodePath < t . Class > , state : File ) {
94- if ( this . file . get ( versionKey ) !== version ) return ;
93+ Class ( path , { file } ) {
94+ if ( file . get ( versionKey ) !== version ) return ;
9595
96- if ( ! shouldTransform ( path , this . file ) ) return ;
96+ if ( ! shouldTransform ( path , file ) ) return ;
9797
9898 if ( path . isClassDeclaration ( ) ) assertFieldTransformed ( path ) ;
9999
100- const loose = isLoose ( this . file , feature ) ;
100+ const loose = isLoose ( file , feature ) ;
101101
102102 let constructor : NodePath < t . ClassMethod > ;
103103 const isDecorated = hasDecorators ( path . node ) ;
@@ -186,7 +186,7 @@ export function createClassFeaturePlugin({
186186 const privateNamesNodes = buildPrivateNamesNodes (
187187 privateNamesMap ,
188188 ( privateFieldsAsProperties ?? loose ) as boolean ,
189- state ,
189+ file ,
190190 ) ;
191191
192192 transformPrivateNamesUsage (
@@ -198,7 +198,7 @@ export function createClassFeaturePlugin({
198198 noDocumentAll,
199199 innerBinding,
200200 } ,
201- state ,
201+ file ,
202202 ) ;
203203
204204 let keysNodes : t . Statement [ ] ,
@@ -213,17 +213,17 @@ export function createClassFeaturePlugin({
213213 ref ,
214214 path ,
215215 elements ,
216- this . file ,
216+ file ,
217217 ) ) ;
218218 } else {
219- keysNodes = extractComputedKeys ( ref , path , computedPaths , this . file ) ;
219+ keysNodes = extractComputedKeys ( path , computedPaths , file ) ;
220220 ( { staticNodes, pureStaticNodes, instanceNodes, wrapClass } =
221221 buildFieldsInitNodes (
222222 ref ,
223223 path . node . superClass ,
224224 props ,
225225 privateNamesMap ,
226- state ,
226+ file ,
227227 ( setPublicClassFields ?? loose ) as boolean ,
228228 ( privateFieldsAsProperties ?? loose ) as boolean ,
229229 ( constantSuper ?? loose ) as boolean ,
@@ -260,8 +260,8 @@ export function createClassFeaturePlugin({
260260 }
261261 } ,
262262
263- ExportDefaultDeclaration ( path : NodePath < t . ExportDefaultDeclaration > ) {
264- if ( this . file . get ( versionKey ) !== version ) return ;
263+ ExportDefaultDeclaration ( path , { file } ) {
264+ if ( file . get ( versionKey ) !== version ) return ;
265265
266266 const decl = path . get ( "declaration" ) ;
267267
0 commit comments