Skip to content

Commit cdac321

Browse files
committed
Implemented more robust handling for commeting. This allows for the source map to maintain the original line numbers.
1 parent 417b438 commit cdac321

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

lib/parser.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ module.exports = function (content) {
7171
var start = node.childNodes[0].__location.start
7272
var end = node.childNodes[node.childNodes.length - 1].__location.end
7373

74-
var result = content.slice(start, end).trim()
74+
var result
75+
if (type === 'script') {
76+
result =
77+
commentScript(content.slice(0, start), lang) +
78+
content.slice(start, end) +
79+
commentScript(content.slice(end), lang)
80+
} else {
81+
result = content.slice(start, end).trim()
82+
}
7583

7684
output[type].push({
7785
lang: lang,
@@ -83,14 +91,32 @@ module.exports = function (content) {
8391
cb(null, 'module.exports = ' + JSON.stringify(output))
8492
}
8593

86-
function commentScript (content) {
94+
function commentScript (content, lang) {
8795
return content
8896
.split(/\n\r|\n|\r/g)
8997
.map(function (line) {
90-
if (line.trim() === '') {
91-
return line
92-
} else {
93-
return '// ' + line
98+
switch (lang) {
99+
case 'coffee':
100+
case 'coffee-jsx':
101+
case 'coffee-redux':
102+
if (line.trim() === '') {
103+
return line
104+
} else {
105+
return '# ' + line
106+
}
107+
case 'purs':
108+
case 'ulmus':
109+
if (line.trim() === '') {
110+
return line
111+
} else {
112+
return '-- ' + line
113+
}
114+
default:
115+
if (line.trim() === '') {
116+
return line
117+
} else {
118+
return '// ' + line
119+
}
94120
}
95121
})
96122
.join('\n')

0 commit comments

Comments
 (0)