From c78d47b78851b7bc8a0261f5b8a79c88bf22273e Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 20 Sep 2019 12:19:52 -0400 Subject: [PATCH] feat(compiler): set sourcesContent for source map --- packages/compiler-core/__tests__/codegen.spec.ts | 10 ++++++++-- packages/compiler-core/src/codegen.ts | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/compiler-core/__tests__/codegen.spec.ts b/packages/compiler-core/__tests__/codegen.spec.ts index 40908535..73e4a5a5 100644 --- a/packages/compiler-core/__tests__/codegen.spec.ts +++ b/packages/compiler-core/__tests__/codegen.spec.ts @@ -3,10 +3,16 @@ import { SourceMapConsumer, RawSourceMap } from 'source-map' describe('compiler: codegen', () => { test('basic source map support', async () => { - const ast = parse(`hello {{ world }}`) - const { code, map } = generate(ast) + const source = `hello {{ world }}` + const ast = parse(source) + const { code, map } = generate(ast, { + filename: `foo.vue` + }) expect(code).toBe(`["hello ", world]`) + expect(map!.sources).toEqual([`foo.vue`]) + expect(map!.sourcesContent).toEqual([source]) + const consumer = await new SourceMapConsumer(map as RawSourceMap) const pos = consumer.originalPositionFor({ line: 1, diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index 857aa92a..e85bb193 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -107,6 +107,9 @@ function createCodegenContext( } } } + if (!__BROWSER__) { + context.map!.setSourceContent(filename, context.source) + } return context }