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

Commit 6c5f920

Browse files
author
Nandiin
committed
fix: Throw style compilation errors
1 parent deab460 commit 6c5f920

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

Diff for: 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+
let styles = await Promise.all(
214+
descriptor.styles.map(async style => {
215+
let 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

Diff for: test/forward-style-compiler-errors.spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
// expect(() => { throw Error()}).toThrow()
16+
})
17+
})

0 commit comments

Comments
 (0)