blob: be3d728f96f53bd99e7f48e3865b3c404261f5d1 [file] [log] [blame]
Verifies JavaScript pretty-printing functionality.
Running: forInFormatting
====== 8< ------
for (var key in myMap)
print(key);
------ >8 ======
Correct mapping for <myMap>
Correct mapping for <print>
Running: forOfFormatting
====== 8< ------
for (var value of myMap)
print(value);
------ >8 ======
Correct mapping for <myMap>
Correct mapping for <print>
Running: commaBetweenStatementsFormatting
====== 8< ------
rebuild(),
show(),
hasNew ? refresh() : noop();
------ >8 ======
Correct mapping for <noop>
Correct mapping for <hasNew>
Running: complexScriptFormatting
====== 8< ------
function formatted1() {
var variable1 = 0;
}
function withComments() {
// comment
return "functionWithComments";
}
try {
onmessage = function(event) {
var source = event.data;
var formattedSource = beautify(source);
var mapping = buildMapping(source, formattedSource);
postMessage({
formattedSource: formattedSource,
mapping: mapping
})
}
;
function beautify(source) {
var ast = parse.parse(source);
var beautifyOptions = {
indent_level: 4,
indent_start: 0,
quote_keys: false,
space_colon: false
};
return process.gen_code(ast, beautifyOptions)
}
function buildMapping(source, formattedSource) {
var mapping = {
original: [],
formatted: []
};
var lastPosition = 0;
var regexp = /(^|[^\\])\b((?=\D)[\$\.\w]+)\b/g;
while (true) {
var match = regexp.exec(formattedSource);
if (!match)
break;
var position = source.indexOf(match[2], lastPosition);
if (position === -1)
throw "No match found in original source for " + match[2];
mapping.original.push(position);
mapping.formatted.push(match.index + match[1].length);
lastPosition = position + match[2].length
}
return mapping
}
function require() {
return parse
}
var exports = {};
importScripts("UglifyJS/parse-js.js");
var parse = exports;
var exports = {};
importScripts("UglifyJS/process.js");
var process = exports;
} catch (e) {}
function formatted2() {
var variable2 = 0;
}
------ >8 ======
Correct mapping for <function>
Correct mapping for <formatted1>
Correct mapping for <variable1>
Correct mapping for < return "functionWithComments">
Correct mapping for <onmessage>
Correct mapping for <indent_start>
Correct mapping for <function require>
Correct mapping for <var regexp>
Correct mapping for <importScripts>
Correct mapping for <formatted2>
Running: ifStatementIndentRegression
====== 8< ------
{
if (a > b) {
a();
pretty();
} else if (a + b)
e();
reset();
}
------ >8 ======
Correct mapping for <pretty>
Correct mapping for <reset>