@@ -135,7 +135,7 @@ module.exports = {
135
135
// consumeLeadingSpaces is false happen DOC prematch END HEREDOC stage.
136
136
137
137
// Ensure current state is really after a new line break, not after a such as ${variables}
138
- const prev_ch = this . _input . substring ( offset - 2 , offset - 1 ) ;
138
+ const prev_ch = this . _input [ offset - 2 ] ;
139
139
if ( prev_ch !== "\n" && prev_ch !== "\r" ) {
140
140
return false ;
141
141
}
@@ -145,26 +145,34 @@ module.exports = {
145
145
let indentation_uses_tabs = false ;
146
146
// reset heredoc_label structure
147
147
let indentation = 0 ;
148
- let leading_ch = this . _input . substring ( offset - 1 , offset ) ;
148
+ let leading_ch = this . _input [ offset - 1 ] ;
149
149
let valid_endings = [ "\n" , "\r" , ";" ] ;
150
150
151
151
if ( this . version >= 703 ) {
152
152
valid_endings = valid_endings . concat ( [ "\t" , " " , "," , ")" , "]" ] ) ;
153
- }
154
153
155
- while ( leading_ch === "\t" || leading_ch === " " ) {
156
- if ( leading_ch === " " ) {
157
- indentation_uses_spaces = true ;
158
- } else if ( leading_ch === "\t" ) {
159
- indentation_uses_tabs = true ;
154
+ while ( leading_ch === "\t" || leading_ch === " " ) {
155
+ if ( leading_ch === " " ) {
156
+ indentation_uses_spaces = true ;
157
+ } else if ( leading_ch === "\t" ) {
158
+ indentation_uses_tabs = true ;
159
+ }
160
+
161
+ leading_ch = this . _input [ offset + indentation ] ;
162
+ indentation ++ ;
160
163
}
161
164
162
- leading_ch = this . _input [ offset + indentation ] ;
163
- indentation ++ ;
164
- }
165
+ // Move offset to skip leading whitespace
166
+ offset = offset + indentation ;
165
167
166
- // Move offset to skip leading whitespace
167
- offset = offset + indentation ;
168
+ // return out if there was only whitespace on this line
169
+ if (
170
+ this . _input [ offset - 1 ] === "\n" ||
171
+ this . _input [ offset - 1 ] === "\r"
172
+ ) {
173
+ return false ;
174
+ }
175
+ }
168
176
169
177
if (
170
178
this . _input . substring (
@@ -216,9 +224,11 @@ module.exports = {
216
224
return ;
217
225
}
218
226
219
- // skip one line
220
- while ( this . _input [ offset ++ ] !== "\n" && offset < this . _input . length ) {
221
- // skip
227
+ if ( this . _input [ offset - 1 ] !== "\n" ) {
228
+ // skip one line
229
+ while ( this . _input [ offset ++ ] !== "\n" && offset < this . _input . length ) {
230
+ // skip
231
+ }
222
232
}
223
233
224
234
offset ++ ;
0 commit comments