@@ -8,6 +8,7 @@ function iterateScripts(code, options, onChunk) {
88
99 const xmlMode = options . xmlMode
1010 const isJavaScriptMIMEType = options . isJavaScriptMIMEType || ( ( ) => true )
11+ const javaScriptTagNames = options . javaScriptTagNames || [ "script" ]
1112 let index = 0
1213 let inScript = false
1314 let cdata = [ ]
@@ -23,7 +24,7 @@ function iterateScripts(code, options, onChunk) {
2324 {
2425 onopentag ( name , attrs ) {
2526 // Test if current tag is a valid <script> tag.
26- if ( name !== "script" ) {
27+ if ( ! javaScriptTagNames . includes ( name ) ) {
2728 return
2829 }
2930
@@ -53,7 +54,7 @@ function iterateScripts(code, options, onChunk) {
5354 } ,
5455
5556 onclosetag ( name ) {
56- if ( name !== "script" || ! inScript ) {
57+ if ( ! javaScriptTagNames . includes ( name ) || ! inScript ) {
5758 return
5859 }
5960
@@ -179,47 +180,57 @@ function* dedent(indent, slice) {
179180 }
180181}
181182
182- function extract ( code , indentDescriptor , xmlMode , isJavaScriptMIMEType ) {
183+ function extract (
184+ code ,
185+ indentDescriptor ,
186+ xmlMode ,
187+ javaScriptTagNames ,
188+ isJavaScriptMIMEType
189+ ) {
183190 const badIndentationLines = [ ]
184191 const codeParts = [ ]
185192 let lineNumber = 1
186193 let previousHTML = ""
187194
188- iterateScripts ( code , { xmlMode, isJavaScriptMIMEType } , ( chunk ) => {
189- const slice = code . slice ( chunk . start , chunk . end )
190- if ( chunk . type === "html" ) {
191- const match = slice . match ( / \r \n | \n | \r / g)
192- if ( match ) lineNumber += match . length
193- previousHTML = slice
194- } else if ( chunk . type === "script" ) {
195- const transformedCode = new TransformableString ( code )
196- let indentSlice = slice
197- for ( const cdata of chunk . cdata ) {
198- transformedCode . replace ( cdata . start , cdata . end , "" )
199- if ( cdata . end === chunk . end ) {
200- 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+ }
201212 }
202- }
203- transformedCode . replace ( 0 , chunk . start , "" )
204- transformedCode . replace ( chunk . end , code . length , "" )
205- for ( const action of dedent (
206- computeIndent ( indentDescriptor , previousHTML , indentSlice ) ,
207- indentSlice
208- ) ) {
209- lineNumber += 1
210- if ( action . type === "dedent" ) {
211- transformedCode . replace (
212- chunk . start + action . from ,
213- chunk . start + action . to ,
214- ""
215- )
216- } else if ( action . type === "bad-indent" ) {
217- 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+ }
218229 }
230+ codeParts . push ( transformedCode )
219231 }
220- codeParts . push ( transformedCode )
221232 }
222- } )
233+ )
223234
224235 return {
225236 code : codeParts ,
0 commit comments