@@ -134,40 +134,41 @@ pp.parseObjectComprehension = function(node) {
134
134
return this . finishNode ( node , "ObjectComprehension" ) ;
135
135
} ;
136
136
137
- // c/p parseBlock
137
+ pp . parseInlineWhiteBlock = function ( node ) {
138
+ if ( this . state . type . startsExpr ) return this . parseMaybeAssign ( ) ;
139
+ // oneline statement case
140
+ node . body = [ this . parseStatement ( true ) ] ;
141
+ node . directives = [ ] ;
142
+ this . addExtra ( node , "curly" , false ) ;
143
+ return this . finishNode ( node , "BlockStatement" ) ;
144
+ } ;
145
+
146
+ pp . parseMultilineWhiteBlock = function ( node , indentLevel ) {
147
+ this . parseBlockBody ( node , false , false , indentLevel ) ;
148
+ if ( ! node . body . length ) {
149
+ this . unexpected ( node . start , "Expected an Indent or Statement" ) ;
150
+ }
151
+
152
+ this . addExtra ( node , "curly" , false ) ;
153
+ return this . finishNode ( node , "BlockStatement" ) ;
154
+ } ;
138
155
139
- pp . parseWhiteBlock = function ( allowDirectives ? , isExpression ?) {
156
+ pp . parseWhiteBlock = function ( isExpression ?) {
140
157
const node = this . startNode ( ) , indentLevel = this . state . indentLevel ;
141
158
142
- // must start with colon or arrow
143
- if ( isExpression ) {
144
- this . expect ( tt . colon ) ;
145
- if ( ! this . isLineBreak ( ) ) return this . parseMaybeAssign ( ) ;
146
- } else if ( this . eat ( tt . colon ) ) {
147
- if ( ! this . isLineBreak ( ) ) return this . parseStatement ( false ) ;
148
- } else if ( this . eat ( tt . arrow ) ) {
149
- if ( ! this . isLineBreak ( ) ) {
150
- if ( this . match ( tt . braceL ) ) {
151
- // restart node at brace start instead of arrow start
152
- const node = this . startNode ( ) ;
153
- this . next ( ) ;
154
- this . parseBlockBody ( node , allowDirectives , false , tt . braceR ) ;
155
- this . addExtra ( node , "curly" , true ) ;
156
- return this . finishNode ( node , "BlockStatement" ) ;
157
- } else {
158
- return this . parseMaybeAssign ( ) ;
159
- }
159
+ if ( ! this . eat ( tt . colon ) ) this . unexpected ( null , "Whitespace Block must start with a colon or arrow" ) ;
160
+
161
+ // Oneline whiteblock
162
+ if ( ! this . isLineBreak ( ) ) {
163
+ if ( isExpression ) {
164
+ return this . parseInlineWhiteBlock ( node ) ;
165
+ } else {
166
+ return this . parseStatement ( false ) ;
160
167
}
161
- } else {
162
- this . unexpected ( null , "Whitespace Block must start with a colon or arrow" ) ;
163
168
}
164
169
165
- // never parse directives if curly braces aren't used (TODO: document)
166
- this . parseBlockBody ( node , false , false , indentLevel ) ;
167
- this . addExtra ( node , "curly" , false ) ;
168
- if ( ! node . body . length ) this . unexpected ( node . start , "Expected an Indent or Statement" ) ;
169
-
170
- return this . finishNode ( node , "BlockStatement" ) ;
170
+ // TODO: document the fact that directives aren't parsed
171
+ return this . parseMultilineWhiteBlock ( node , indentLevel ) ;
171
172
} ;
172
173
173
174
pp . expectCommaOrLineBreak = function ( ) {
@@ -301,7 +302,23 @@ pp.parseArrowFunctionBody = function (node) {
301
302
this . state . labels = [ ] ;
302
303
this . state . inFunction = true ;
303
304
304
- node . body = this . parseWhiteBlock ( true ) ;
305
+ const indentLevel = this . state . indentLevel ;
306
+ const nodeAtArrow = this . startNode ( ) ;
307
+ this . expect ( tt . arrow ) ;
308
+ if ( ! this . isLineBreak ( ) ) {
309
+ if ( this . match ( tt . braceL ) ) {
310
+ // restart node at brace start instead of arrow start
311
+ node . body = this . startNode ( ) ;
312
+ this . next ( ) ;
313
+ this . parseBlockBody ( node . body , true , false , tt . braceR ) ;
314
+ this . addExtra ( node . body , "curly" , true ) ;
315
+ node . body = this . finishNode ( node . body , "BlockStatement" ) ;
316
+ } else {
317
+ node . body = this . parseInlineWhiteBlock ( nodeAtArrow ) ;
318
+ }
319
+ } else {
320
+ node . body = this . parseMultilineWhiteBlock ( nodeAtArrow , indentLevel ) ;
321
+ }
305
322
306
323
if ( node . body . type !== "BlockStatement" ) {
307
324
node . expression = true ;
@@ -376,7 +393,7 @@ pp.parseIf = function (node, isExpression) {
376
393
} else if ( ! isColon ) {
377
394
node . consequent = this . parseMaybeAssign ( ) ;
378
395
} else {
379
- node . consequent = this . parseWhiteBlock ( false , true ) ;
396
+ node . consequent = this . parseWhiteBlock ( true ) ;
380
397
}
381
398
} else {
382
399
node . consequent = this . parseStatement ( false ) ;
@@ -425,7 +442,7 @@ pp.parseIfAlternate = function (node, isExpression, ifIsWhiteBlock, ifIndentLeve
425
442
} else if ( ! this . match ( tt . colon ) ) {
426
443
return this . parseMaybeAssign ( ) ;
427
444
} else {
428
- return this . parseWhiteBlock ( false , true ) ;
445
+ return this . parseWhiteBlock ( true ) ;
429
446
}
430
447
}
431
448
@@ -613,9 +630,9 @@ export default function (instance) {
613
630
// whitespace following a colon
614
631
615
632
instance . extend ( "parseBlock" , function ( inner ) {
616
- return function ( allowDirectives ) {
633
+ return function ( ) {
617
634
if ( this . match ( tt . colon ) ) {
618
- return this . parseWhiteBlock ( allowDirectives ) ;
635
+ return this . parseWhiteBlock ( ) ;
619
636
}
620
637
const block = inner . apply ( this , arguments ) ;
621
638
this . addExtra ( block , "curly" , true ) ;
0 commit comments