Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 5d8aa49

Browse files
Nandiinznck
Nandiin
authored andcommitted
fix: Throw style compilation errors (#235)
* fix: Throw style compilation errors * chore: Remove commented code and add new line at EOF * chore: change 'let' to 'const'
1 parent deab460 commit 5d8aa49

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/index.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,18 @@ export default function VuePlugin(opts: VuePluginOptions = {}): Plugin {
209209
? hash(path.basename(filename) + source)
210210
: hash(filename + source))
211211
descriptors.set(filename, descriptor)
212+
213+
const styles = await Promise.all(
214+
descriptor.styles.map(async style => {
215+
const compiled = await compiler.compileStyleAsync(filename, scopeId, style)
216+
if (compiled.errors.length > 0) throw Error(compiled.errors[0])
217+
return compiled
218+
})
219+
)
220+
212221
const input: any = {
213222
scopeId,
214-
styles: await Promise.all(
215-
descriptor.styles.map(style =>
216-
compiler.compileStyleAsync(filename, scopeId, style)
217-
)
218-
),
223+
styles,
219224
customBlocks: []
220225
}
221226

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pluginVue from '..'
2+
describe("forward-style-compiler-errors", () => {
3+
it("throws", async () => {
4+
let plugin = pluginVue()
5+
await expect((plugin as any).transform(`
6+
<template>
7+
<div>Hello, world</div>
8+
</template>
9+
<style lang="scss">
10+
@import 'file-not-exits.scss';
11+
</style>
12+
`, 'virtual-file.vue'
13+
)
14+
).rejects.toBeInstanceOf(Error)
15+
})
16+
})

0 commit comments

Comments
 (0)