Skip to content

Commit a5cd31a

Browse files
committed
coverage for sfc-parser
1 parent f0a9e3d commit a5cd31a

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

flow/compiler.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ declare type SFCBlock = {
153153
content: string,
154154
start?: number,
155155
end?: number,
156-
offset?: number,
157156
lang?: string,
158157
src?: string,
159158
scoped?: boolean,

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
"chromedriver": "^2.21.2",
5353
"codecov.io": "^0.1.6",
5454
"cross-spawn": "^4.0.0",
55+
"de-indent": "^1.0.2",
56+
"entities": "^1.1.1",
5557
"eslint": "^2.11.0",
5658
"eslint-config-vue": "^1.0.3",
5759
"eslint-loader": "^1.3.0",
@@ -78,6 +80,7 @@
7880
"rollup-plugin-babel": "^2.4.0",
7981
"rollup-plugin-replace": "^1.1.0",
8082
"selenium-server": "2.53.0",
83+
"source-map": "^0.5.6",
8184
"uglify-js": "^2.6.2",
8285
"webpack": "^1.13.1"
8386
}

src/compiler/parser/sfc-parser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export function parseComponent (
101101

102102
function addSourceMap (block: SFCBlock) {
103103
const filename = options.map.filename
104+
/* istanbul ignore if */
104105
if (!filename) {
105106
throw new Error('Should provide original filename in the map option.')
106107
}

test/unit/modules/compiler/sfc-parser.spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,35 @@ describe('Single File Component parser', () => {
4646
expect(res.styles[0].content).toBe(Array(6 + 1).join('\n') + '\nh1 { color: red }\n')
4747
})
4848

49-
it('source map', () => {
49+
it('source map (without pad)', () => {
50+
const res = parseComponent(`
51+
<script>
52+
export default {}
53+
</script>
54+
<style>
55+
h1 { color: red }
56+
</style>
57+
`.trim(), {
58+
map: {
59+
filename: 'test.vue'
60+
}
61+
})
62+
const scriptConsumer = new SourceMapConsumer(res.script.map)
63+
const scriptPos = scriptConsumer.originalPositionFor({
64+
line: 2,
65+
column: 1
66+
})
67+
expect(scriptPos.line).toBe(2)
68+
69+
const styleConsumer = new SourceMapConsumer(res.styles[0].map)
70+
const stylePos = styleConsumer.originalPositionFor({
71+
line: 2,
72+
column: 1
73+
})
74+
expect(stylePos.line).toBe(5)
75+
})
76+
77+
it('source map (with pad)', () => {
5078
const res = parseComponent(`
5179
<script>
5280
export default {}

0 commit comments

Comments
 (0)