Skip to content

Commit 6925c32

Browse files
committed
chore: splice the source of fileInfo
1 parent da195bd commit 6925c32

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/runTransformation.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,18 @@ export default function runTransformation(
6464
if (!descriptor.template) {
6565
return source
6666
}
67+
let contentStart: number =
68+
descriptor.template.ast.children[0].loc.start.offset
69+
let contentEnd: number =
70+
descriptor.template.ast.children[
71+
descriptor.template.ast.children.length - 1
72+
].loc.end.offset + 1
73+
74+
fileInfo.source =
75+
source.slice(0, contentStart) +
76+
descriptor.template.content +
77+
source.slice(contentEnd, contentEnd + 11)
6778

68-
fileInfo.source = `<template>${descriptor.template.content}</template>`
6979
const out = transformation(fileInfo, params)
7080

7181
if (!out) {
@@ -78,7 +88,10 @@ export default function runTransformation(
7888
return source // skipped, don't bother re-stringifying
7989
}
8090
// remove redundant <template> tag
81-
descriptor!.template!.content = out.slice(11, -11)
91+
descriptor!.template!.content = out.slice(
92+
contentStart,
93+
descriptor.template.content.length - contentEnd
94+
)
8295
return stringifySFC(descriptor!)
8396
}
8497

0 commit comments

Comments
 (0)