@@ -11,17 +11,17 @@ import { AnalysisError } from "./error.js";
1111/**
1212 * Aggregated result of class field analysis.
1313 */
14- export type ThisFields = {
14+ export type ClassFieldsAnalysis = {
1515 /** Access to instance fields (`this.foo`), indexed by their names. */
16- thisFields : Map < string , ThisFieldSite [ ] > ;
16+ instanceFields : Map < string , InstanceFieldSite [ ] > ;
1717 /** Access to static fields (`C.foo`, where `C` is the class), indexed by their names. */
1818 staticFields : Map < string , StaticFieldSite [ ] > ;
1919} ;
2020
2121/**
2222 * A place where the instance field is declared or used.
2323 */
24- export type ThisFieldSite = {
24+ export type InstanceFieldSite = {
2525 type : "class_field" ;
2626 /**
2727 * Declaration. One of:
@@ -121,9 +121,9 @@ export type StaticFieldSite = {
121121 * - Instance fields ... `this.foo`
122122 * - Static fields ... `C.foo`, where `C` is the class
123123 */
124- export function analyzeThisFields ( path : NodePath < ClassDeclaration > ) : ThisFields {
125- const thisFields = new Map < string , ThisFieldSite [ ] > ( ) ;
126- const getThisField = ( name : string ) => getOr ( thisFields , name , ( ) => [ ] ) ;
124+ export function analyzeClassFields ( path : NodePath < ClassDeclaration > ) : ClassFieldsAnalysis {
125+ const instanceFields = new Map < string , InstanceFieldSite [ ] > ( ) ;
126+ const getInstanceField = ( name : string ) => getOr ( instanceFields , name , ( ) => [ ] ) ;
127127 const staticFields = new Map < string , StaticFieldSite [ ] > ( ) ;
128128 const getStaticField = ( name : string ) => getOr ( staticFields , name , ( ) => [ ] ) ;
129129 let constructor : NodePath < ClassMethod > | undefined = undefined ;
@@ -137,7 +137,7 @@ export function analyzeThisFields(path: NodePath<ClassDeclaration>): ThisFields
137137 if ( name == null ) {
138138 throw new AnalysisError ( `Unnamed class element` ) ;
139139 }
140- const field = isStatic ? getStaticField ( name ) : getThisField ( name ) ;
140+ const field = isStatic ? getStaticField ( name ) : getInstanceField ( name ) ;
141141 if ( isClassPropertyLike ( itemPath ) ) {
142142 // Class field.
143143 // - May have an initializer: `foo = 42;` or not: `foo;`
@@ -273,7 +273,7 @@ export function analyzeThisFields(path: NodePath<ClassDeclaration>): ThisFields
273273 }
274274 // TODO: check for parameter/local variable reference
275275
276- const field = getThisField ( name ) ! ;
276+ const field = getInstanceField ( name ) ! ;
277277 field . push ( {
278278 type : "class_field" ,
279279 path : exprPath ,
@@ -305,7 +305,7 @@ export function analyzeThisFields(path: NodePath<ClassDeclaration>): ThisFields
305305 throw new AnalysisError ( `Unrecognized this-property reference` ) ;
306306 }
307307
308- const field = getThisField ( name ) ! ;
308+ const field = getInstanceField ( name ) ! ;
309309
310310 const thisMemberParentPath = thisMemberPath . parentPath ;
311311 const hasWrite =
@@ -334,9 +334,9 @@ export function analyzeThisFields(path: NodePath<ClassDeclaration>): ThisFields
334334 }
335335
336336 // Post validation
337- for ( const [ name , fieldSites ] of thisFields ) {
337+ for ( const [ name , fieldSites ] of instanceFields ) {
338338 if ( fieldSites . length === 0 ) {
339- thisFields . delete ( name ) ;
339+ instanceFields . delete ( name ) ;
340340 }
341341 const numInits = fieldSites . reduce ( ( n , site ) => n + Number ( ! ! site . init ) , 0 ) ;
342342 if ( numInits > 1 ) {
@@ -349,7 +349,7 @@ export function analyzeThisFields(path: NodePath<ClassDeclaration>): ThisFields
349349 }
350350 for ( const [ name , fieldSites ] of staticFields ) {
351351 if ( fieldSites . length === 0 ) {
352- thisFields . delete ( name ) ;
352+ instanceFields . delete ( name ) ;
353353 }
354354 const numInits = fieldSites . reduce ( ( n , site ) => n + Number ( ! ! site . init ) , 0 ) ;
355355 if ( numInits > 1 ) {
@@ -361,7 +361,7 @@ export function analyzeThisFields(path: NodePath<ClassDeclaration>): ThisFields
361361 }
362362 }
363363
364- return { thisFields , staticFields } ;
364+ return { instanceFields , staticFields } ;
365365}
366366
367367function traverseThis ( path : NodePath , visit : ( path : NodePath < ThisExpression > ) => void ) {
0 commit comments