Skip to content

Commit 21ca3c3

Browse files
committedJul 18, 2022
chore: lint
1 parent 7717a53 commit 21ca3c3

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed
 

‎src/extract.js

+43-33
Original file line numberDiff line numberDiff line change
@@ -8,7 +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']
11+
const javaScriptTagNames = options.javaScriptTagNames || ["script"]
1212
let index = 0
1313
let inScript = false
1414
let cdata = []
@@ -180,47 +180,57 @@ function* dedent(indent, slice) {
180180
}
181181
}
182182

183-
function extract(code, indentDescriptor, xmlMode, javaScriptTagNames, isJavaScriptMIMEType) {
183+
function extract(
184+
code,
185+
indentDescriptor,
186+
xmlMode,
187+
javaScriptTagNames,
188+
isJavaScriptMIMEType
189+
) {
184190
const badIndentationLines = []
185191
const codeParts = []
186192
let lineNumber = 1
187193
let previousHTML = ""
188194

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+
}
202212
}
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+
}
219229
}
230+
codeParts.push(transformedCode)
220231
}
221-
codeParts.push(transformedCode)
222232
}
223-
})
233+
)
224234

225235
return {
226236
code: codeParts,

0 commit comments

Comments
 (0)
Please sign in to comment.