@@ -120,6 +120,70 @@ pp.expectParenFreeBlockStart = function (node) {
120
120
}
121
121
} ;
122
122
123
+ pp . matchesWhiteBlockASIToken = function ( ) {
124
+ return (
125
+ ( this . match ( tt . comma ) && this . hasPlugin ( "seqExprRequiresParen" ) ) ||
126
+ this . match ( tt . parenR ) ||
127
+ this . match ( tt . bracketR ) ||
128
+ this . match ( tt . braceR ) ||
129
+ this . match ( tt . _else ) ||
130
+ this . match ( tt . _elif ) ||
131
+ this . match ( tt . colon ) ||
132
+ this . match ( tt . eof )
133
+ ) ;
134
+ } ;
135
+
136
+ // c/p statement.js parseBlockBody
137
+ pp . parseWhiteBlockBody = function ( node , allowDirectives , topLevel , whiteBlockIndentLevel ) {
138
+ node . body = [ ] ;
139
+ node . directives = [ ] ;
140
+
141
+ let parsedNonDirective = false ;
142
+ let oldStrict ;
143
+ let octalPosition ;
144
+
145
+ const oldInWhiteBlock = this . state . inWhiteBlock ;
146
+ const oldWhiteBlockIndentLevel = this . state . whiteBlockIndentLevel ;
147
+ this . state . inWhiteBlock = true ;
148
+ this . state . whiteBlockIndentLevel = whiteBlockIndentLevel ;
149
+
150
+ const isEnd = ( ) => this . state . indentLevel <= whiteBlockIndentLevel || this . matchesWhiteBlockASIToken ( ) ;
151
+
152
+ while ( ! isEnd ( ) ) {
153
+ if ( ! parsedNonDirective && this . state . containsOctal && ! octalPosition ) {
154
+ octalPosition = this . state . octalPosition ;
155
+ }
156
+
157
+ const stmt = this . parseStatement ( true , topLevel ) ;
158
+
159
+ if ( allowDirectives && ! parsedNonDirective && this . isValidDirective ( stmt ) ) {
160
+ const directive = this . stmtToDirective ( stmt ) ;
161
+ node . directives . push ( directive ) ;
162
+
163
+ if ( oldStrict === undefined && directive . value . value === "use strict" ) {
164
+ oldStrict = this . state . strict ;
165
+ this . setStrict ( true ) ;
166
+
167
+ if ( octalPosition ) {
168
+ this . raise ( octalPosition , "Octal literal in strict mode" ) ;
169
+ }
170
+ }
171
+
172
+ continue ;
173
+ }
174
+
175
+ parsedNonDirective = true ;
176
+ node . body . push ( stmt ) ;
177
+ }
178
+
179
+ this . state . inWhiteBlock = oldInWhiteBlock ;
180
+ this . state . whiteBlockIndentLevel = oldWhiteBlockIndentLevel ;
181
+
182
+ if ( oldStrict === false ) {
183
+ this . setStrict ( false ) ;
184
+ }
185
+ } ;
186
+
123
187
pp . parseInlineWhiteBlock = function ( node ) {
124
188
if ( this . state . type . startsExpr ) return this . parseMaybeAssign ( ) ;
125
189
// oneline statement case
@@ -130,7 +194,7 @@ pp.parseInlineWhiteBlock = function(node) {
130
194
} ;
131
195
132
196
pp . parseMultilineWhiteBlock = function ( node , indentLevel ) {
133
- this . parseBlockBody ( node , false , false , indentLevel ) ;
197
+ this . parseWhiteBlockBody ( node , false , false , indentLevel ) ;
134
198
if ( ! node . body . length ) {
135
199
this . unexpected ( node . start , "Expected an Indent or Statement" ) ;
136
200
}
0 commit comments