summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/inspector/front-end/ScriptFormatterWorker.js
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/inspector/front-end/ScriptFormatterWorker.js')
-rw-r--r--Source/WebCore/inspector/front-end/ScriptFormatterWorker.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/Source/WebCore/inspector/front-end/ScriptFormatterWorker.js b/Source/WebCore/inspector/front-end/ScriptFormatterWorker.js
index e900317..1a4c28e 100644
--- a/Source/WebCore/inspector/front-end/ScriptFormatterWorker.js
+++ b/Source/WebCore/inspector/front-end/ScriptFormatterWorker.js
@@ -32,7 +32,10 @@ var parse = loadModule("parse-js.js");
var process = loadModule("process.js");
onmessage = function(event) {
- postMessage(beautify(event.data));
+ var source = event.data;
+ var formattedSource = beautify(source);
+ var mapping = buildMapping(source, formattedSource);
+ postMessage({ formattedSource: formattedSource, mapping: mapping });
};
function beautify(source)
@@ -47,6 +50,25 @@ function beautify(source)
return process.gen_code(ast, beautifyOptions);
}
+function buildMapping(source, formattedSource)
+{
+ var mapping = { original: [], formatted: [] };
+ var lastCodePosition = 0;
+ var regexp = /[\$\.\w]+|{|}/g;
+ while (true) {
+ var match = regexp.exec(formattedSource);
+ if (!match)
+ break;
+ var position = source.indexOf(match[0], lastCodePosition);
+ if (position === -1)
+ continue;
+ mapping.original.push(position);
+ mapping.formatted.push(match.index);
+ lastCodePosition = position + match[0].length;
+ }
+ return mapping;
+}
+
function loadModule(src)
{
var request = new XMLHttpRequest();