@@ -23,40 +23,18 @@ type TopicContextState = {
2323 maxTopicIndex : null | 0 ;
2424} ;
2525
26- const enum StateFlags {
27- None = 0 ,
28- Strict = 1 << 0 ,
29- maybeInArrowParameters = 1 << 1 ,
30- inType = 1 << 2 ,
31- noAnonFunctionType = 1 << 3 ,
32- hasFlowComment = 1 << 4 ,
33- isAmbientContext = 1 << 5 ,
34- inAbstractClass = 1 << 6 ,
35- inDisallowConditionalTypesContext = 1 << 7 ,
36- soloAwait = 1 << 8 ,
37- inFSharpPipelineDirectBody = 1 << 9 ,
38- canStartJSXElement = 1 << 10 ,
39- containsEsc = 1 << 11 ,
40- }
41-
4226export const enum LoopLabelKind {
4327 Loop = 1 ,
4428 Switch = 2 ,
4529}
4630
31+ declare const bit : import ( "../../../../scripts/babel-plugin-bit-decorator/types.d.ts" ) . BitDecorator < State > ;
32+
4733export default class State {
48- flags : number = StateFlags . canStartJSXElement ;
34+ @bit . storage flags : number ;
35+
36+ @bit accessor strict = false ;
4937
50- get strict ( ) : boolean {
51- return ( this . flags & StateFlags . Strict ) > 0 ;
52- }
53- set strict ( value : boolean ) {
54- if ( value ) {
55- this . flags |= StateFlags . Strict ;
56- } else {
57- this . flags &= ~ StateFlags . Strict ;
58- }
59- }
6038 curLine : number ;
6139 lineStart : number ;
6240
@@ -98,76 +76,13 @@ export default class State {
9876 noArrowParamsConversionAt : number [ ] = [ ] ;
9977
10078 // Flags to track
101- get maybeInArrowParameters ( ) : boolean {
102- return ( this . flags & StateFlags . maybeInArrowParameters ) > 0 ;
103- }
104- set maybeInArrowParameters ( value : boolean ) {
105- if ( value ) {
106- this . flags |= StateFlags . maybeInArrowParameters ;
107- } else {
108- this . flags &= ~ StateFlags . maybeInArrowParameters ;
109- }
110- }
111- get inType ( ) : boolean {
112- return ( this . flags & StateFlags . inType ) > 0 ;
113- }
114- set inType ( value : boolean ) {
115- if ( value ) {
116- this . flags |= StateFlags . inType ;
117- } else {
118- this . flags &= ~ StateFlags . inType ;
119- }
120- }
121- get noAnonFunctionType ( ) : boolean {
122- return ( this . flags & StateFlags . noAnonFunctionType ) > 0 ;
123- }
124- set noAnonFunctionType ( value : boolean ) {
125- if ( value ) {
126- this . flags |= StateFlags . noAnonFunctionType ;
127- } else {
128- this . flags &= ~ StateFlags . noAnonFunctionType ;
129- }
130- }
131- get hasFlowComment ( ) : boolean {
132- return ( this . flags & StateFlags . hasFlowComment ) > 0 ;
133- }
134- set hasFlowComment ( value : boolean ) {
135- if ( value ) {
136- this . flags |= StateFlags . hasFlowComment ;
137- } else {
138- this . flags &= ~ StateFlags . hasFlowComment ;
139- }
140- }
141- get isAmbientContext ( ) : boolean {
142- return ( this . flags & StateFlags . isAmbientContext ) > 0 ;
143- }
144- set isAmbientContext ( value : boolean ) {
145- if ( value ) {
146- this . flags |= StateFlags . isAmbientContext ;
147- } else {
148- this . flags &= ~ StateFlags . isAmbientContext ;
149- }
150- }
151- get inAbstractClass ( ) : boolean {
152- return ( this . flags & StateFlags . inAbstractClass ) > 0 ;
153- }
154- set inAbstractClass ( value : boolean ) {
155- if ( value ) {
156- this . flags |= StateFlags . inAbstractClass ;
157- } else {
158- this . flags &= ~ StateFlags . inAbstractClass ;
159- }
160- }
161- get inDisallowConditionalTypesContext ( ) : boolean {
162- return ( this . flags & StateFlags . inDisallowConditionalTypesContext ) > 0 ;
163- }
164- set inDisallowConditionalTypesContext ( value : boolean ) {
165- if ( value ) {
166- this . flags |= StateFlags . inDisallowConditionalTypesContext ;
167- } else {
168- this . flags &= ~ StateFlags . inDisallowConditionalTypesContext ;
169- }
170- }
79+ @bit accessor maybeInArrowParameters = false ;
80+ @bit accessor inType = false ;
81+ @bit accessor noAnonFunctionType = false ;
82+ @bit accessor hasFlowComment = false ;
83+ @bit accessor isAmbientContext = false ;
84+ @bit accessor inAbstractClass = false ;
85+ @bit accessor inDisallowConditionalTypesContext = false ;
17186
17287 // For the Hack-style pipelines plugin
17388 topicContext : TopicContextState = {
@@ -176,26 +91,8 @@ export default class State {
17691 } ;
17792
17893 // For the F#-style pipelines plugin
179- get soloAwait ( ) : boolean {
180- return ( this . flags & StateFlags . soloAwait ) > 0 ;
181- }
182- set soloAwait ( value : boolean ) {
183- if ( value ) {
184- this . flags |= StateFlags . soloAwait ;
185- } else {
186- this . flags &= ~ StateFlags . soloAwait ;
187- }
188- }
189- get inFSharpPipelineDirectBody ( ) : boolean {
190- return ( this . flags & StateFlags . inFSharpPipelineDirectBody ) > 0 ;
191- }
192- set inFSharpPipelineDirectBody ( value : boolean ) {
193- if ( value ) {
194- this . flags |= StateFlags . inFSharpPipelineDirectBody ;
195- } else {
196- this . flags &= ~ StateFlags . inFSharpPipelineDirectBody ;
197- }
198- }
94+ @bit accessor soloAwait = false ;
95+ @bit accessor inFSharpPipelineDirectBody = false ;
19996
20097 // Labels in scope.
20198 labels : Array < {
@@ -231,31 +128,14 @@ export default class State {
231128 // The context stack is used to track whether the apostrophe "`" starts
232129 // or ends a string template
233130 context : Array < TokContext > = [ ct . brace ] ;
131+
234132 // Used to track whether a JSX element is allowed to form
235- get canStartJSXElement ( ) : boolean {
236- return ( this . flags & StateFlags . canStartJSXElement ) > 0 ;
237- }
238- set canStartJSXElement ( value : boolean ) {
239- if ( value ) {
240- this . flags |= StateFlags . canStartJSXElement ;
241- } else {
242- this . flags &= ~ StateFlags . canStartJSXElement ;
243- }
244- }
133+ @bit accessor canStartJSXElement = true ;
245134
246135 // Used to signal to callers of `readWord1` whether the word
247136 // contained any escape sequences. This is needed because words with
248137 // escape sequences must not be interpreted as keywords.
249- get containsEsc ( ) : boolean {
250- return ( this . flags & StateFlags . containsEsc ) > 0 ;
251- }
252- set containsEsc ( value : boolean ) {
253- if ( value ) {
254- this . flags |= StateFlags . containsEsc ;
255- } else {
256- this . flags &= ~ StateFlags . containsEsc ;
257- }
258- }
138+ @bit accessor containsEsc = false ;
259139
260140 // Used to track invalid escape sequences in template literals,
261141 // that must be reported if the template is not tagged.
0 commit comments