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

fix: Throw style compilation errors #235

Merged
merged 3 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,18 @@ export default function VuePlugin(opts: VuePluginOptions = {}): Plugin {
? hash(path.basename(filename) + source)
: hash(filename + source))
descriptors.set(filename, descriptor)

const styles = await Promise.all(
descriptor.styles.map(async style => {
const compiled = await compiler.compileStyleAsync(filename, scopeId, style)
if (compiled.errors.length > 0) throw Error(compiled.errors[0])
return compiled
})
)

const input: any = {
scopeId,
styles: await Promise.all(
descriptor.styles.map(style =>
compiler.compileStyleAsync(filename, scopeId, style)
)
),
styles,
customBlocks: []
}

Expand Down
16 changes: 16 additions & 0 deletions test/forward-style-compiler-errors.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pluginVue from '..'
describe("forward-style-compiler-errors", () => {
it("throws", async () => {
let plugin = pluginVue()
await expect((plugin as any).transform(`
<template>
<div>Hello, world</div>
</template>
<style lang="scss">
@import 'file-not-exits.scss';
</style>
`, 'virtual-file.vue'
)
).rejects.toBeInstanceOf(Error)
})
})