From 9aa8ec6ba0b1ea48876a1880170437cb99645a33 Mon Sep 17 00:00:00 2001 From: johanblumenberg Date: Wed, 22 Nov 2017 15:55:43 +0100 Subject: [PATCH] Support for exposing sourcemap to plugins --- index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/index.js b/index.js index 183d637..2786f63 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,7 @@ function rework(str, options) { function Rework(obj) { this.obj = obj; + this.map = undefined; } /** @@ -68,6 +69,22 @@ Rework.prototype.toString = function(options){ return result; }; +/** + * For user of rework to set the current sourcemap for the input, + * and for plugins to read the sourcemap for example to be able to + * map error messages to the correct file and line. + * + * @param {Object} [map] Optional sourcemap to set + * @return {Object} The sourcemap for the input data + * @api public + */ +Rework.prototype.sourcemap = function(map){ + if (map) { + this.map = map; + } + return this.map; +}; + /** * Convert sourcemap to base64-encoded comment *