Skip to content

Commit 6d79615

Browse files
committed
fix: fixes #4
1 parent 9986967 commit 6d79615

File tree

4 files changed

+85
-7
lines changed

4 files changed

+85
-7
lines changed

src/runTransformation.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ export default function runTransformation(
7777
descriptor.template.ast.children[
7878
descriptor.template.ast.children.length - 1
7979
].loc.end.offset + 1
80+
let astStart = descriptor.template.ast.loc.start.offset
81+
let astEnd = descriptor.template.ast.loc.end.offset + 1
8082

81-
fileInfo.source =
82-
source.slice(0, contentStart) +
83-
descriptor.template.content +
84-
source.slice(contentEnd, contentEnd + 11)
83+
fileInfo.source = descriptor.template.ast.loc.source
8584

8685
const out = transformation(fileInfo, params)
8786

@@ -91,13 +90,13 @@ export default function runTransformation(
9190

9291
// need to reconstruct the .vue file from descriptor blocks
9392
if (extension === '.vue') {
94-
if (out === fileInfo.source) {
93+
if (out === descriptor!.template!.content) {
9594
return source // skipped, don't bother re-stringifying
9695
}
9796
// remove redundant <template> tag
9897
descriptor!.template!.content = out.slice(
99-
contentStart,
100-
descriptor.template.content.length - contentEnd
98+
contentStart - astStart,
99+
contentEnd - astEnd
101100
)
102101
return stringifySFC(descriptor!)
103102
}

vue-transformations/__test__/slot-attribute.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ runTest(
77
'vue',
88
'vue'
99
)
10+
1011
runTest(
1112
'template element replace slot="xxx" to v-slot:xxx',
1213
'slot-attribute',
1314
'template-slot-attribute',
1415
'vue',
1516
'vue'
1617
)
18+
19+
runTest(
20+
'Template is between style and script',
21+
'slot-attribute',
22+
'template-tag-slice',
23+
'vue',
24+
'vue'
25+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<style>
2+
.mini-cover {
3+
width: 50px;
4+
height: 50px;
5+
}
6+
</style>
7+
8+
9+
<template>
10+
<div class="img-list" ref="box">
11+
<li v-for="img in list" @click="delMe(img)">
12+
<lazy-component @show="tip">
13+
<img class="mini-cover" :src="img.src" width="100%" height="400">
14+
</lazy-component>
15+
</li>
16+
</div>
17+
</template>
18+
19+
20+
<script>
21+
export default {
22+
name: 'ListC',
23+
props: {
24+
list: Array
25+
},
26+
methods: {
27+
tip (context) {
28+
console.log(context)
29+
},
30+
delMe (img) {
31+
this.$emit('delete', img)
32+
}
33+
}
34+
}
35+
</script>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<style>
2+
.mini-cover {
3+
width: 50px;
4+
height: 50px;
5+
}
6+
</style>
7+
8+
9+
<template>
10+
<div class="img-list" ref="box">
11+
<li v-for="img in list" @click="delMe(img)">
12+
<lazy-component @show="tip">
13+
<img class="mini-cover" :src="img.src" width="100%" height="400">
14+
</lazy-component>
15+
</li>
16+
</div>
17+
</template>
18+
19+
20+
<script>
21+
export default {
22+
name: 'ListC',
23+
props: {
24+
list: Array
25+
},
26+
methods: {
27+
tip (context) {
28+
console.log(context)
29+
},
30+
delMe (img) {
31+
this.$emit('delete', img)
32+
}
33+
}
34+
}
35+
</script>

0 commit comments

Comments
 (0)