From 6c5f920807ee0ccf096079d8e73fd3db1330cdab Mon Sep 17 00:00:00 2001 From: Nandiin Date: Fri, 21 Sep 2018 16:17:43 +0800 Subject: [PATCH 1/3] fix: Throw style compilation errors --- src/index.ts | 15 ++++++++++----- test/forward-style-compiler-errors.spec.ts | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 test/forward-style-compiler-errors.spec.ts diff --git a/src/index.ts b/src/index.ts index 5ac6e93..541cd82 100644 --- a/src/index.ts +++ b/src/index.ts @@ -209,13 +209,18 @@ export default function VuePlugin(opts: VuePluginOptions = {}): Plugin { ? hash(path.basename(filename) + source) : hash(filename + source)) descriptors.set(filename, descriptor) + + let styles = await Promise.all( + descriptor.styles.map(async style => { + let 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: [] } diff --git a/test/forward-style-compiler-errors.spec.ts b/test/forward-style-compiler-errors.spec.ts new file mode 100644 index 0000000..4509816 --- /dev/null +++ b/test/forward-style-compiler-errors.spec.ts @@ -0,0 +1,17 @@ +import pluginVue from '..' +describe("forward-style-compiler-errors", () => { + it("throws", async () => { + let plugin = pluginVue() + await expect((plugin as any).transform(` + + + `, 'virtual-file.vue' + ) + ).rejects.toBeInstanceOf(Error) + // expect(() => { throw Error()}).toThrow() + }) +}) \ No newline at end of file From fc1557f7c6d731acd6d249dde3147bc9a248079d Mon Sep 17 00:00:00 2001 From: Nandiin Date: Fri, 21 Sep 2018 16:22:25 +0800 Subject: [PATCH 2/3] chore: Remove commented code and add new line at EOF --- test/forward-style-compiler-errors.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/forward-style-compiler-errors.spec.ts b/test/forward-style-compiler-errors.spec.ts index 4509816..16259af 100644 --- a/test/forward-style-compiler-errors.spec.ts +++ b/test/forward-style-compiler-errors.spec.ts @@ -12,6 +12,5 @@ describe("forward-style-compiler-errors", () => { `, 'virtual-file.vue' ) ).rejects.toBeInstanceOf(Error) - // expect(() => { throw Error()}).toThrow() }) -}) \ No newline at end of file +}) From 1f1cbdf0d84aa638847bb9cd53a8fe3ee0e2b35e Mon Sep 17 00:00:00 2001 From: Nandiin Date: Tue, 25 Sep 2018 06:32:19 +0800 Subject: [PATCH 3/3] chore: change 'let' to 'const' --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 541cd82..b67112b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -210,9 +210,9 @@ export default function VuePlugin(opts: VuePluginOptions = {}): Plugin { : hash(filename + source)) descriptors.set(filename, descriptor) - let styles = await Promise.all( + const styles = await Promise.all( descriptor.styles.map(async style => { - let compiled = await compiler.compileStyleAsync(filename, scopeId, style) + const compiled = await compiler.compileStyleAsync(filename, scopeId, style) if (compiled.errors.length > 0) throw Error(compiled.errors[0]) return compiled })