Permalink
Browse files

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'
  • Loading branch information...
Nandiin authored and znck committed Sep 26, 2018
1 parent deab460 commit 5d8aa494940b962942268936f2959e2fc04d21e9
Showing with 26 additions and 5 deletions.
  1. +10 −5 src/index.ts
  2. +16 −0 test/forward-style-compiler-errors.spec.ts
@@ -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: []
}

@@ -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)
})
})

0 comments on commit 5d8aa49

Please sign in to comment.