Browse Source

coverage for sfc-parser

dev
Evan You 9 years ago
parent
commit
a5cd31ab6d
  1. 1
      flow/compiler.js
  2. 3
      package.json
  3. 1
      src/compiler/parser/sfc-parser.js
  4. 30
      test/unit/modules/compiler/sfc-parser.spec.js

1
flow/compiler.js

@ -153,7 +153,6 @@ declare type SFCBlock = {
content: string,
start?: number,
end?: number,
offset?: number,
lang?: string,
src?: string,
scoped?: boolean,

3
package.json

@ -52,6 +52,8 @@
"chromedriver": "^2.21.2",
"codecov.io": "^0.1.6",
"cross-spawn": "^4.0.0",
"de-indent": "^1.0.2",
"entities": "^1.1.1",
"eslint": "^2.11.0",
"eslint-config-vue": "^1.0.3",
"eslint-loader": "^1.3.0",
@ -78,6 +80,7 @@
"rollup-plugin-babel": "^2.4.0",
"rollup-plugin-replace": "^1.1.0",
"selenium-server": "2.53.0",
"source-map": "^0.5.6",
"uglify-js": "^2.6.2",
"webpack": "^1.13.1"
}

1
src/compiler/parser/sfc-parser.js

@ -101,6 +101,7 @@ export function parseComponent (
function addSourceMap (block: SFCBlock) {
const filename = options.map.filename
/* istanbul ignore if */
if (!filename) {
throw new Error('Should provide original filename in the map option.')
}

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

@ -46,7 +46,35 @@ describe('Single File Component parser', () => {
expect(res.styles[0].content).toBe(Array(6 + 1).join('\n') + '\nh1 { color: red }\n')
})
it('source map', () => {
it('source map (without pad)', () => {
const res = parseComponent(`
<script>
export default {}
</script>
<style>
h1 { color: red }
</style>
`.trim(), {
map: {
filename: 'test.vue'
}
})
const scriptConsumer = new SourceMapConsumer(res.script.map)
const scriptPos = scriptConsumer.originalPositionFor({
line: 2,
column: 1
})
expect(scriptPos.line).toBe(2)
const styleConsumer = new SourceMapConsumer(res.styles[0].map)
const stylePos = styleConsumer.originalPositionFor({
line: 2,
column: 1
})
expect(stylePos.line).toBe(5)
})
it('source map (with pad)', () => {
const res = parseComponent(`
<script>
export default {}

Loading…
Cancel
Save