File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -70,16 +70,38 @@ module.exports = function (content) {
70
70
71
71
var start = node . childNodes [ 0 ] . __location . start
72
72
var end = node . childNodes [ node . childNodes . length - 1 ] . __location . end
73
+
74
+ var result
75
+ if ( type === 'script' ) {
76
+ result = commentScript ( content . slice ( 0 , start ) ) +
77
+ content . slice ( start , end ) +
78
+ commentScript ( content . slice ( end ) )
79
+ } else {
80
+ result = content . slice ( start , end ) . trim ( )
81
+ }
82
+
73
83
output [ type ] . push ( {
74
84
lang : lang ,
75
85
scoped : scoped ,
76
- content : content . substring ( start , end ) . trim ( )
86
+ content : result
77
87
} )
78
88
} )
79
89
80
90
cb ( null , 'module.exports = ' + JSON . stringify ( output ) )
81
91
}
82
92
93
+ function commentScript ( content ) {
94
+ return content . split ( / \n \r | \n | \r / g)
95
+ . map ( function ( line ) {
96
+ if ( line . trim ( ) === '' ) {
97
+ return line
98
+ } else {
99
+ return '// ' + line
100
+ }
101
+ } )
102
+ . join ( '\n' )
103
+ }
104
+
83
105
function getAttribute ( node , name ) {
84
106
if ( node . attrs ) {
85
107
var i = node . attrs . length
Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ describe('vue-loader', function () {
141
141
getFile ( 'test.build.js.map' , function ( map ) {
142
142
var smc = new SourceMapConsumer ( JSON . parse ( map ) )
143
143
getFile ( 'test.build.js' , function ( code ) {
144
+ console . log ( code )
144
145
var line
145
146
code . split ( '\n' ) . some ( function ( l , i ) {
146
147
if ( l . indexOf ( 'Hello from Component A' ) > - 1 ) {
@@ -153,7 +154,7 @@ describe('vue-loader', function () {
153
154
column : 0
154
155
} )
155
156
expect ( pos . source . indexOf ( 'webpack:///test/fixtures/basic.vue' ) > - 1 )
156
- expect ( pos . line ) . to . equal ( 4 )
157
+ expect ( pos . line ) . to . equal ( 15 )
157
158
done ( )
158
159
} )
159
160
} )
You can’t perform that action at this time.
0 commit comments