Skip to content

Commit

Permalink
fix: reuse the old preprocessor after changing the lang attr (#4224)
Browse files Browse the repository at this point in the history
* fix(plugin-vue): reuse the old preprocessor after changing the lang attr

* feat(playground): add stylus + change lang test in vue

* chore: add eol line break

Co-authored-by: Shinigami <chrissi92@hotmail.de>
  • Loading branch information
y1d7ng and Shinigami92 committed Jul 20, 2021
1 parent 514e124 commit 7a3c6e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/playground/vue/PreProcessors.vue
Expand Up @@ -6,6 +6,9 @@ p.pug
p.pug-less
| This is rendered from &lt;template lang="pug"&gt;
| and styled with &lt;style lang="less"&gt;. It should be green.
p.pug-stylus
| This is rendered from &lt;template lang="pug"&gt;
| and styled with &lt;style lang="stylus"&gt;. It should be orange.
SlotComponent
template(v-slot:test-slot)
div.pug-slot slot content
Expand All @@ -32,3 +35,10 @@ $color: magenta;
color: @color;
}
</style>

<style lang="stylus">
color = orange
.pug-stylus
color: color
</style>
15 changes: 15 additions & 0 deletions packages/playground/vue/__tests__/vue.spec.ts
Expand Up @@ -56,6 +56,21 @@ describe('pre-processors', () => {
)
await untilUpdated(() => getColor(el), 'blue')
})

test('stylus + change lang', async () => {
expect(await getColor('p.pug-stylus')).toBe('orange')
editFile('PreProcessors.vue', (code) =>
code
.replace('<style lang="stylus">', '<style lang="scss">')
.replace('color = orange', '$color: yellow;')
.replace('color: color', '{ color: $color; }')
)
await untilUpdated(() => getColor('p.pug-stylus'), 'yellow')
editFile('PreProcessors.vue', (code) =>
code.replace('$color: yellow;', '$color: orange;')
)
await untilUpdated(() => getColor('p.pug-stylus'), 'orange')
})
})

describe('css modules', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-vue/src/handleHotUpdate.ts
Expand Up @@ -88,7 +88,11 @@ export async function handleHotUpdate({
const next = nextStyles[i]
if (!prev || !isEqualBlock(prev, next)) {
didUpdateStyle = true
const mod = modules.find((m) => m.url.includes(`type=style&index=${i}`))
const mod = modules.find(
(m) =>
m.url.includes(`type=style&index=${i}`) &&
m.url.endsWith(`.${next.lang || 'css'}`)
)
if (mod) {
affectedModules.add(mod)
} else {
Expand Down

0 comments on commit 7a3c6e6

Please sign in to comment.