@@ -8,7 +8,7 @@ function iterateScripts(code, options, onChunk) {
8
8
9
9
const xmlMode = options . xmlMode
10
10
const isJavaScriptMIMEType = options . isJavaScriptMIMEType || ( ( ) => true )
11
- const javaScriptTagNames = options . javaScriptTagNames || [ ' script' ]
11
+ const javaScriptTagNames = options . javaScriptTagNames || [ " script" ]
12
12
let index = 0
13
13
let inScript = false
14
14
let cdata = [ ]
@@ -180,47 +180,57 @@ function* dedent(indent, slice) {
180
180
}
181
181
}
182
182
183
- function extract ( code , indentDescriptor , xmlMode , javaScriptTagNames , isJavaScriptMIMEType ) {
183
+ function extract (
184
+ code ,
185
+ indentDescriptor ,
186
+ xmlMode ,
187
+ javaScriptTagNames ,
188
+ isJavaScriptMIMEType
189
+ ) {
184
190
const badIndentationLines = [ ]
185
191
const codeParts = [ ]
186
192
let lineNumber = 1
187
193
let previousHTML = ""
188
194
189
- iterateScripts ( code , { xmlMode, javaScriptTagNames, isJavaScriptMIMEType } , ( chunk ) => {
190
- const slice = code . slice ( chunk . start , chunk . end )
191
- if ( chunk . type === "html" ) {
192
- const match = slice . match ( / \r \n | \n | \r / g)
193
- if ( match ) lineNumber += match . length
194
- previousHTML = slice
195
- } else if ( chunk . type === "script" ) {
196
- const transformedCode = new TransformableString ( code )
197
- let indentSlice = slice
198
- for ( const cdata of chunk . cdata ) {
199
- transformedCode . replace ( cdata . start , cdata . end , "" )
200
- if ( cdata . end === chunk . end ) {
201
- indentSlice = code . slice ( chunk . start , cdata . start )
195
+ iterateScripts (
196
+ code ,
197
+ { xmlMode, javaScriptTagNames, isJavaScriptMIMEType } ,
198
+ ( chunk ) => {
199
+ const slice = code . slice ( chunk . start , chunk . end )
200
+ if ( chunk . type === "html" ) {
201
+ const match = slice . match ( / \r \n | \n | \r / g)
202
+ if ( match ) lineNumber += match . length
203
+ previousHTML = slice
204
+ } else if ( chunk . type === "script" ) {
205
+ const transformedCode = new TransformableString ( code )
206
+ let indentSlice = slice
207
+ for ( const cdata of chunk . cdata ) {
208
+ transformedCode . replace ( cdata . start , cdata . end , "" )
209
+ if ( cdata . end === chunk . end ) {
210
+ indentSlice = code . slice ( chunk . start , cdata . start )
211
+ }
202
212
}
203
- }
204
- transformedCode . replace ( 0 , chunk . start , "" )
205
- transformedCode . replace ( chunk . end , code . length , "" )
206
- for ( const action of dedent (
207
- computeIndent ( indentDescriptor , previousHTML , indentSlice ) ,
208
- indentSlice
209
- ) ) {
210
- lineNumber += 1
211
- if ( action . type === "dedent" ) {
212
- transformedCode . replace (
213
- chunk . start + action . from ,
214
- chunk . start + action . to ,
215
- ""
216
- )
217
- } else if ( action . type === "bad-indent" ) {
218
- badIndentationLines . push ( lineNumber )
213
+ transformedCode . replace ( 0 , chunk . start , "" )
214
+ transformedCode . replace ( chunk . end , code . length , "" )
215
+ for ( const action of dedent (
216
+ computeIndent ( indentDescriptor , previousHTML , indentSlice ) ,
217
+ indentSlice
218
+ ) ) {
219
+ lineNumber += 1
220
+ if ( action . type === "dedent" ) {
221
+ transformedCode . replace (
222
+ chunk . start + action . from ,
223
+ chunk . start + action . to ,
224
+ ""
225
+ )
226
+ } else if ( action . type === "bad-indent" ) {
227
+ badIndentationLines . push ( lineNumber )
228
+ }
219
229
}
230
+ codeParts . push ( transformedCode )
220
231
}
221
- codeParts . push ( transformedCode )
222
232
}
223
- } )
233
+ )
224
234
225
235
return {
226
236
code : codeParts ,
0 commit comments