Skip to content

Commit 213ac68

Browse files
csaillyeddyerburgh
authored andcommitted
feat(sourceMap): Add source mapping for external scripts (#37)
1 parent fb667f6 commit 213ac68

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

lib/process.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ module.exports = function (src, path) {
5050
const script = result.code
5151
const inputMap = result.sourceMap
5252

53-
const map = generateSourceMap(script, '', path, src, inputMap)
53+
let scriptSrc = src
54+
if (parts.script && parts.script.src) {
55+
scriptSrc = parts.script.content
56+
}
57+
58+
const map = generateSourceMap(script, '', path, scriptSrc, inputMap)
5459
let output = ';(function(){\n' + script + '\n})()\n' +
5560
'if (module.exports.__esModule) module.exports = module.exports.default\n' +
5661
'var __vue__options__ = (typeof module.exports === "function"' +

test/Babel.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,10 @@ test('generates inline sourcemap', () => {
104104
const output = jestVue.process(fileString, filePath)
105105
expect(output.map).toMatchSnapshot()
106106
})
107+
108+
test('generates inline sourcemap for .vue files using src attributes', () => {
109+
const filePath = resolve(__dirname, './resources/BasicSrc.vue')
110+
const fileString = readFileSync(filePath, { encoding: 'utf8' })
111+
const output = jestVue.process(fileString, filePath)
112+
expect(output.map).toMatchSnapshot()
113+
})

test/__snapshots__/Babel.spec.js.snap

+37
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,40 @@ Object {
4444
"version": 3,
4545
}
4646
`;
47+
48+
exports[`generates inline sourcemap for .vue files using src attributes 1`] = `
49+
Object {
50+
"mappings": ";;;;;;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAHA;AAKA;AAPA;AASA;AACA;AACA;AACA;AAFA;AAIA;AACA;AACA;AACA;AACA;AAHA;AAjBA",
51+
"names": Array [],
52+
"sources": Array [
53+
"BasicSrc.vue",
54+
],
55+
"sourcesContent": Array [
56+
"export default {
57+
name: 'basic',
58+
computed: {
59+
headingClasses: function headingClasses () {
60+
return {
61+
red: this.isCrazy,
62+
blue: !this.isCrazy,
63+
shadow: this.isCrazy
64+
}
65+
}
66+
},
67+
data: function data () {
68+
return {
69+
msg: 'Welcome to Your Vue.js App',
70+
isCrazy: false
71+
}
72+
},
73+
methods: {
74+
toggleClass: function toggleClass () {
75+
this.isCrazy = !this.isCrazy
76+
}
77+
}
78+
}
79+
",
80+
],
81+
"version": 3,
82+
}
83+
`;

0 commit comments

Comments
 (0)