@@ -23,29 +23,29 @@ import * as NodePath_comments from "./comments";
2323
2424const debug = buildDebug ( "babel" ) ;
2525
26+ export const REMOVED = 1 << 0 ;
27+ export const SHOULD_STOP = 1 << 1 ;
28+ export const SHOULD_SKIP = 1 << 2 ;
29+
2630export default class NodePath {
2731 constructor ( hub : HubInterface , parent : Object ) {
2832 this . parent = parent ;
2933 this . hub = hub ;
3034 this . contexts = [ ] ;
31- this . data = Object . create ( null ) ;
32- this . shouldSkip = false ;
33- this . shouldStop = false ;
34- this . removed = false ;
35+ this . data = null ;
36+ // this.shouldSkip = false; this.shouldStop = false; this.removed = false;
37+ this . _traverseFlags = 0 ;
3538 this . state = null ;
3639 this . opts = null ;
3740 this . skipKeys = null ;
3841 this . parentPath = null ;
3942 this . context = null ;
4043 this . container = null ;
4144 this . listKey = null ;
42- this . inList = false ;
43- this . parentKey = null ;
4445 this . key = null ;
4546 this . node = null ;
4647 this . scope = null ;
4748 this . type = null ;
48- this . typeAnnotation = null ;
4949 }
5050
5151 parent : Object ;
@@ -57,18 +57,16 @@ export default class NodePath {
5757 removed : boolean ;
5858 state : any ;
5959 opts : ?Object ;
60+ _traverseFlags : number ;
6061 skipKeys : ?Object ;
6162 parentPath : ?NodePath ;
6263 context : TraversalContext ;
6364 container : ?Object | Array < Object > ;
6465 listKey : ?string ;
65- inList : boolean ;
66- parentKey : ?string ;
6766 key : ?string ;
6867 node : ?Object ;
6968 scope : Scope ;
7069 type : ?string ;
71- typeAnnotation : ?Object ;
7270
7371 static get ( { hub, parentPath, parent, container, listKey, key } ) : NodePath {
7472 if ( ! hub && parentPath ) {
@@ -111,10 +109,16 @@ export default class NodePath {
111109 }
112110
113111 setData ( key : string , val : any ) : any {
112+ if ( this . data == null ) {
113+ this . data = Object . create ( null ) ;
114+ }
114115 return ( this . data [ key ] = val ) ;
115116 }
116117
117118 getData ( key : string , def ?: any ) : any {
119+ if ( this . data == null ) {
120+ this . data = Object . create ( null ) ;
121+ }
118122 let val = this . data [ key ] ;
119123 if ( val === undefined && def !== undefined ) val = this . data [ key ] = def ;
120124 return val ;
@@ -152,6 +156,49 @@ export default class NodePath {
152156 toString ( ) {
153157 return generator ( this . node ) . code;
154158 }
159+
160+ get inList ( ) {
161+ return ! ! this . listKey ;
162+ }
163+
164+ get parentKey ( ) {
165+ return this . listKey || this . key ;
166+ }
167+
168+ get shouldSkip ( ) {
169+ return ! ! ( this . _traverseFlags & SHOULD_SKIP ) ;
170+ }
171+
172+ set shouldSkip ( v ) {
173+ if ( v ) {
174+ this . _traverseFlags |= SHOULD_SKIP ;
175+ } else {
176+ this . _traverseFlags &= ~ SHOULD_SKIP ;
177+ }
178+ }
179+
180+ get shouldStop ( ) {
181+ return ! ! ( this . _traverseFlags & SHOULD_STOP ) ;
182+ }
183+
184+ set shouldStop ( v ) {
185+ if ( v ) {
186+ this . _traverseFlags |= SHOULD_STOP ;
187+ } else {
188+ this . _traverseFlags &= ~ SHOULD_STOP ;
189+ }
190+ }
191+
192+ get removed ( ) {
193+ return ! ! ( this . _traverseFlags & REMOVED ) ;
194+ }
195+ set removed ( v ) {
196+ if ( v ) {
197+ this . _traverseFlags |= REMOVED ;
198+ } else {
199+ this . _traverseFlags &= ~ REMOVED ;
200+ }
201+ }
155202}
156203
157204Object . assign (
0 commit comments