Skip to content
Merged

101 #584

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
762 changes: 762 additions & 0 deletions api/mode.ts

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions api/optionDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,6 @@
mode : "beautify",
type : "boolean"
},
end : {
api : "any",
default : 0,
definition: "The last index to process. This option is usefu" +
"l internally when recursively sliding between various libraries. The default val" +
"ue of 0 means to ignore this option.",
label : "End Index",
lexer : "any",
mode : "any",
type : "number"
},
end_comma : {
api : "any",
default : "never",
Expand Down Expand Up @@ -724,16 +713,6 @@
mode : "beautify",
type : "boolean"
},
start : {
api : "any",
default : 0,
definition: "The parse table index to start working from. This is internally used for code sa" +
"mples that require switching between different libraries.",
label : "Start Index",
lexer : "any",
mode : "any",
type : "number"
},
styleguide : {
api : "any",
default : "none",
Expand Down
40 changes: 15 additions & 25 deletions prettydiff-webtool.ts → api/prettydiff-webtool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ if ((/^http:\/\/((\w|-)+\.)*prettydiff\.com/).test(location.href) === true || lo
}
(function dom_init():void {
"use strict";
const meta:meta = {
error: "",
lang: ["", "", ""],
time: "",
insize: 0,
outsize: 0,
difftotal: 0,
difflines: 0
},
id = function dom_id(x:string):any {
const id = function dom_id(x:string):any {
if (document.getElementById === undefined) {
return;
}
Expand All @@ -39,13 +30,6 @@ if ((/^http:\/\/((\w|-)+\.)*prettydiff\.com/).test(location.href) === true || lo
codeIn: id("input"),
codeOut: id("output"),
},
// start option defaults
options:any = {
lang: "",
lexer: "",
source: ""
},
// end option defaults
aceStore:any = {
codeIn: {},
codeOut: {},
Expand Down Expand Up @@ -131,7 +115,7 @@ if ((/^http:\/\/((\w|-)+\.)*prettydiff\.com/).test(location.href) === true || lo
security = function dom_load_security():void {
const scripts:HTMLCollectionOf<HTMLScriptElement> = document.getElementsByTagName("script"),
exclusions:string[] = [
"js/prettydiff-webtool.js",
"js/webtool.js",
"browser-demo.js",
"node_modules/ace-builds"
],
Expand Down Expand Up @@ -736,8 +720,8 @@ if ((/^http:\/\/((\w|-)+\.)*prettydiff\.com/).test(location.href) === true || lo
}
},
selectDescription = function dom_load_selectDescription(el:HTMLSelectElement):void {
const options:HTMLCollectionOf<HTMLOptionElement> = el.getElementsByTagName("option"),
desc:string = options[el.selectedIndex].getAttribute("data-description"),
const opts:HTMLCollectionOf<HTMLOptionElement> = el.getElementsByTagName("option"),
desc:string = opts[el.selectedIndex].getAttribute("data-description"),
opt:HTMLOptionElement = <HTMLOptionElement>el[el.selectedIndex],
value:string = opt.value,
parent:HTMLElement = <HTMLElement>el.parentNode,
Expand Down Expand Up @@ -2495,7 +2479,10 @@ if ((/^http:\/\/((\w|-)+\.)*prettydiff\.com/).test(location.href) === true || lo
}
test.load = false;
};
prettydiff.meta = meta;
let meta:any,
options:any,
prettydiff:any;

// builds the Pretty Diff options comment as options are updated
method.app.commentString = function dom_app_commentString():void {
const comment:HTMLElement = id("commentString");
Expand Down Expand Up @@ -3450,8 +3437,8 @@ if ((/^http:\/\/((\w|-)+\.)*prettydiff\.com/).test(location.href) === true || lo
} else {
pdlang = "characters";
}
if (window.sparser.parseerror !== "" && ann !== null) {
ann.innerHTML = `${ann.innerHTML}<span><strong>Parse Error:</strong> ${sanitize(window.sparser.parseerror)}</span>`;
if (prettydiff.sparser.parseerror !== "" && ann !== null) {
ann.innerHTML = `${ann.innerHTML}<span><strong>Parse Error:</strong> ${sanitize(prettydiff.sparser.parseerror)}</span>`;
} else if (meta.error === "" || meta.error === undefined) {
ann.innerHTML = `${ann.innerHTML}<span><em>Execution time:</em> <strong>${sanitize(meta.time)}</strong>. <em>Output size:</em> <strong>${commanumb(meta.outsize)} ${pdlang}</strong></span>`;
} else {
Expand Down Expand Up @@ -3486,12 +3473,12 @@ if ((/^http:\/\/((\w|-)+\.)*prettydiff\.com/).test(location.href) === true || lo
lines: 0
};
meta.insize = options.source.length + options.diff.length;
output = prettydiff.mode(options, diffmeta);
output = prettydiff(diffmeta);
meta.difftotal = diffmeta.differences;
meta.difflines = diffmeta.lines;
} else {
meta.insize = options.source.length;
output = prettydiff.mode(options);
output = prettydiff();
if (output.indexOf("Error: ") === 0) {
ann.innerHTML = output.replace("Error: ", "");
output = options.source;
Expand Down Expand Up @@ -4627,5 +4614,8 @@ if ((/^http:\/\/((\w|-)+\.)*prettydiff\.com/).test(location.href) === true || lo
};
// prettydiff dom insertion start
// prettydiff dom insertion end
meta = prettydiff.meta;
options = prettydiff.options;
options.api = "dom";
load();
}());
18 changes: 10 additions & 8 deletions beautify/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
const markup = function beautify_markup(options:any):string {
const data:data = options.parsed,
lexer:string = "markup",
c:number = (options.end < 1 || options.end > data.token.length)
c:number = (prettydiff.end < 1 || prettydiff.end > data.token.length)
? data.token.length
: options.end + 1,
: prettydiff.end + 1,
lf:"\r\n"|"\n" = (options.crlf === true)
? "\r\n"
: "\n",
externalIndex:externalIndex = {},
levels:number[] = (function beautify_markup_levels():number[] {
const level:number[] = (options.start > 0)
? Array(options.start).fill(0, 0, options.start)
const level:number[] = (prettydiff.start > 0)
? Array(prettydiff.start).fill(0, 0, prettydiff.start)
: [],
nextIndex = function beautify_markup_levels_next():number {
let x:number = a + 1,
Expand Down Expand Up @@ -393,7 +393,7 @@
wrap(a);
}
};
let a:number = options.start,
let a:number = prettydiff.start,
comstart:number = -1,
next:number = 0,
count:number = 0,
Expand Down Expand Up @@ -450,6 +450,8 @@
}
} else if (data.types[a] === "start" && data.types[next] === "end") {
level.push(-20);
} else if (data.types[a] === "start" && data.types[next] === "script_start") {
level.push(-10);
} else if (options.force_indent === true) {
level.push(indent);
} else if (data.types[a] === "template_start" && data.types[next] === "template_end") {
Expand Down Expand Up @@ -593,7 +595,7 @@
}
data.token[y - 1] = data.token[y - 1] + space + end[0];
};
let a:number = options.start,
let a:number = prettydiff.start,
external:string = "",
lastLevel:number = options.indent_level;
do {
Expand All @@ -616,9 +618,9 @@
if (externalIndex[a] === a && data.types[a] !== "reference") {
build.push(data.token[a]);
} else {
options.end = externalIndex[a];
prettydiff.end = externalIndex[a];
options.indent_level = lastLevel;
options.start = a;
prettydiff.start = a;
external = prettydiff.beautify[data.lexer[a]](options).replace(/\s+$/, "");
build.push(external);
if (levels[prettydiff.iterator] > -1 && externalIndex[a] > a) {
Expand Down
26 changes: 13 additions & 13 deletions beautify/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import { parse } from "path";
const data:data = options.parsed,
lexer:string = "script",
scopes:scriptScopes = prettydiff.scopes,
b:number = (options.end < 1 || options.end > data.token.length)
b:number = (prettydiff.end < 1 || prettydiff.end > data.token.length)
? data.token.length
: options.end + 1,
: prettydiff.end + 1,
externalIndex:externalIndex = {},
// levels sets the white space value between the current token and the next token
// * -20 value means no white space
// * -10 means to separate with a space
// * 0 and above is the number of indentation to insert
levels:number[] = (function beautify_script_level():number[] {
let a = options.start, //will store the current level of indentation
let a = prettydiff.start, //will store the current level of indentation
indent:number = (isNaN(options.indent_level) === true)
? 0
: Number(options.indent_level),
Expand All @@ -30,8 +30,8 @@ import { parse } from "path";
ltoke:string = data.token[0]; //ltype stands for "last token"
const varindex:number[] = [-1], //index in current scope of last var, let, or const keyword
list:boolean[] = [], //stores comma status of current block
level:number[] = (options.start > 0)
? Array(options.start).fill(0, 0, options.start)
level:number[] = (prettydiff.start > 0)
? Array(prettydiff.start).fill(0, 0, prettydiff.start)
: [],
ternary:number[] = [], //used to identify ternary statments
extraindent = [
Expand Down Expand Up @@ -2115,7 +2115,7 @@ import { parse } from "path";
build.push(data.token[a]);
},
invisibles:string[] = ["x;", "x}", "x{", "x(", "x)"];
let a:number = options.start,
let a:number = prettydiff.start,
external:string = "",
lastLevel:number = options.indent_level;
if (options.vertical === true) {
Expand Down Expand Up @@ -2211,7 +2211,7 @@ import { parse } from "path";
scoped:boolean[] = [],
indent:number = options.indent_level,
foldindex:[number, number][] = [],
start:number = options.start,
start:number = prettydiff.start,
exlines:string[] = [],
exlevel:number = 0,
exline:RegExp;
Expand Down Expand Up @@ -2358,7 +2358,7 @@ import { parse } from "path";
scope = 0;
// this loops combines the white space as determined from the algorithm with the
// tokens to create the output
a = options.start;
a = prettydiff.start;
do {
if (data.lexer[a] === lexer || prettydiff.beautify[data.lexer[a]] === undefined) {
if (levels[a] > -1 && a < b - 1) {
Expand Down Expand Up @@ -2446,9 +2446,9 @@ import { parse } from "path";
.replace(/&lt;strong class="new"&gt;this&lt;\/strong&gt;/g, "<strong class=\"new\">this</strong>")
.replace(/&lt;strong class="new"&gt;new&lt;\/strong&gt;/g, "<strong class=\"new\">new</strong>"));
} else {
options.end = externalIndex[a];
prettydiff.end = externalIndex[a];
options.indent_level = lastLevel;
options.start = a;
prettydiff.start = a;
external = prettydiff.beautify[data.lexer[a]](options)
.replace(/\s+$/, "")
.replace(/&/g, "&amp;")
Expand Down Expand Up @@ -2533,7 +2533,7 @@ import { parse } from "path";
code.join("")
].join("").replace(/(\s+)$/, "").replace(options.binary_check, "");
}
a = options.start;
a = prettydiff.start;
do {
if (data.lexer[a] === lexer || prettydiff.beautify[data.lexer[a]] === undefined) {
if (invisibles.indexOf(data.token[a]) < 0) {
Expand Down Expand Up @@ -2561,9 +2561,9 @@ import { parse } from "path";
if (externalIndex[a] === a) {
build.push(data.token[a]);
} else {
options.end = externalIndex[a];
prettydiff.end = externalIndex[a];
options.indent_level = lastLevel;
options.start = a;
prettydiff.start = a;
external = prettydiff.beautify[data.lexer[a]](options).replace(/\s+$/, "");
build.push(external);
a = prettydiff.iterator;
Expand Down
8 changes: 4 additions & 4 deletions beautify/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
lf:"\r\n"|"\n" = (options.crlf === true)
? "\r\n"
: "\n",
len:number = (options.end > 0)
? options.end + 1
len:number = (prettydiff.end > 0)
? prettydiff.end + 1
: data.token.length,
build:string[] = [],
//a single unit of indentation
Expand Down Expand Up @@ -107,7 +107,7 @@
} while (b > 0);
};
let indent:number = options.indent_level,
a:number = options.start,
a:number = prettydiff.start,
when:string[] = ["", ""];
if (options.vertical === true && options.compressed_css === false) {
a = len;
Expand All @@ -117,7 +117,7 @@
vertical();
}
} while (a > 0);
a = options.start;
a = prettydiff.start;
}

//beautification loop
Expand Down
6 changes: 3 additions & 3 deletions documentation.xhtml

Large diffs are not rendered by default.

25 changes: 22 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare var options: any;
declare var ace: any;
declare var prettydiff: any;
declare var options: any;
declare var prettydiff: pd;
declare var window: Window;
declare module NodeJS {
interface Global {
Expand Down Expand Up @@ -155,7 +155,6 @@ interface optionDef {
}
interface optionFunctions {
definitions?: {};

}
interface performance {
codeLength: number;
Expand All @@ -167,6 +166,21 @@ interface performance {
store: number[];
test: boolean;
}
interface pd {
(meta?): string;
api: any;
beautify: any;
end: number;
iterator: number;
meta: meta;
minify: any;
options: any,
saveAs?: Function;
scopes: scriptScopes;
sparser: any;
start: number;
version: version;
}
interface readDirectory {
callback: Function;
exclusions: string[];
Expand All @@ -193,6 +207,11 @@ interface simulationItem {
qualifier: qualifier;
test: string;
}
interface version {
date: string;
number: string;
parse: string;
}
interface Window {
sparser: any;
}
8 changes: 4 additions & 4 deletions index.xhtml

Large diffs are not rendered by default.

Loading