@@ -6,6 +6,13 @@ var hash = require('hash-sum')
6
6
var deindent = require ( './deindent' )
7
7
var splitRE = / \r ? \n / g
8
8
var emptyRE = / ^ \s * $ /
9
+ var commentSymbols = {
10
+ 'coffee' : '#' ,
11
+ 'coffee-jsx' : '#' ,
12
+ 'coffee-redux' : '#' ,
13
+ 'purs' : '--' ,
14
+ 'ulmus' : '--'
15
+ }
9
16
10
17
module . exports = function ( content , filename ) {
11
18
@@ -97,36 +104,47 @@ module.exports = function (content, filename) {
97
104
result = content . slice ( start , end )
98
105
}
99
106
100
- // generate source map
101
- var map = new SourceMapGenerator ( )
102
- map . setSourceContent ( filenameWithHash , content )
103
- result . split ( splitRE ) . forEach ( function ( line , index ) {
104
- map . addMapping ( {
105
- source : filenameWithHash ,
106
- original : {
107
- line : index + 1 + lineOffset ,
108
- column : 0
109
- } ,
110
- generated : {
111
- line : index + 1 ,
112
- column : 0
107
+ if ( needMap ) {
108
+ // generate source map
109
+ var map = new SourceMapGenerator ( )
110
+ map . setSourceContent ( filenameWithHash , content )
111
+
112
+ // do not add mappings for comment lines - babel's source map
113
+ // somehow gets messed up because of it
114
+ var isCommentLine = function ( line ) {
115
+ return type === 'script' &&
116
+ line . indexOf ( getCommentSymbol ( lang ) ) === 0
117
+ }
118
+
119
+ result . split ( splitRE ) . forEach ( function ( line , index ) {
120
+ if ( ! emptyRE . test ( line ) && ! isCommentLine ( line ) ) {
121
+ map . addMapping ( {
122
+ source : filenameWithHash ,
123
+ original : {
124
+ line : index + 1 + lineOffset ,
125
+ column : 0
126
+ } ,
127
+ generated : {
128
+ line : index + 1 ,
129
+ column : 0
130
+ }
131
+ } )
113
132
}
114
133
} )
115
- } )
116
-
117
- // workaround for Webpack eval-source-map bug
118
- // https://github.com/webpack/webpack/pull/1816
119
- // in case the script was piped through another loader
120
- // that doesn't pass down the source map properly.
121
- if ( type === 'script' && ! lang ) {
122
- result += '\n/* generated by vue-loader */\n'
134
+ // workaround for Webpack eval-source-map bug
135
+ // https://github.com/webpack/webpack/pull/1816
136
+ // in case the script was piped through another loader
137
+ // that doesn't pass down the source map properly.
138
+ if ( type === 'script' && ! lang ) {
139
+ result += '\n/* generated by vue-loader */\n'
140
+ }
123
141
}
124
142
125
143
output [ type ] . push ( {
126
144
lang : lang ,
127
145
scoped : scoped ,
128
146
content : result ,
129
- map : map . toJSON ( )
147
+ map : map && map . toJSON ( )
130
148
} )
131
149
} )
132
150
@@ -135,27 +153,19 @@ module.exports = function (content, filename) {
135
153
}
136
154
137
155
function commentScript ( content , lang ) {
156
+ var symbol = getCommentSymbol ( lang )
138
157
return content
139
158
. split ( splitRE )
140
159
. map ( function ( line ) {
141
- if ( emptyRE . test ( line ) ) {
142
- return line
143
- }
144
- switch ( lang ) {
145
- case 'coffee' :
146
- case 'coffee-jsx' :
147
- case 'coffee-redux' :
148
- return '# ' + line
149
- case 'purs' :
150
- case 'ulmus' :
151
- return '-- ' + line
152
- default :
153
- return '// ' + line
154
- }
160
+ return symbol + ( emptyRE . test ( line ) ? '' : ' ' + line )
155
161
} )
156
162
. join ( '\n' )
157
163
}
158
164
165
+ function getCommentSymbol ( lang ) {
166
+ return commentSymbols [ lang ] || '//'
167
+ }
168
+
159
169
function getAttribute ( node , name ) {
160
170
if ( node . attrs ) {
161
171
var i = node . attrs . length
0 commit comments