| 1 |
"use strict"; |
| 2 |
|
| 3 |
var repeat = require("es5-ext/string/#/repeat") |
| 4 |
, esniff = require("./"); |
| 5 |
|
| 6 |
module.exports = exports = function (code/*, options*/) { |
| 7 |
var options = Object(arguments[1]); |
| 8 |
|
| 9 |
var comments = esniff(code, function (emitter, accessor) { |
| 10 |
accessor.shouldCollectComments = true; |
| 11 |
}); |
| 12 |
|
| 13 |
if (!comments.length) return code; |
| 14 |
var i = 0, result = []; |
| 15 |
comments.forEach(function (commentMeta) { |
| 16 |
result.push(code.slice(i, commentMeta.point)); |
| 17 |
if (options.preserveLocation) { |
| 18 |
result.push(repeat.call(" ", commentMeta.endPoint - commentMeta.point)); |
| 19 |
} |
| 20 |
i = commentMeta.endPoint; |
| 21 |
}); |
| 22 |
result.push(code.slice(i)); |
| 23 |
return result.join(""); |
| 24 |
}; |