diff --git a/api/mode.ts b/api/mode.ts new file mode 100644 index 00000000..371cd055 --- /dev/null +++ b/api/mode.ts @@ -0,0 +1,762 @@ +/*global prettydiff*/ +function mode(diffmeta?:diffmeta):string { + "use strict"; + const pdcomment = function mode_pdcomment():void { + const ops:any = prettydiff.sparser.options; + let sindex:number = options.source.search(/((\/(\*|\/))| + // + // + // - Parsing Considerations: + // * there may be any amount of space at the start or end of the comment + // * "prettydiff.com" must exist at the start of the comment + // * comment must exist prior to non-comment tokens (near top of code) + // * parameters are name value pairs separated by white space + // * the delimiter separating name and value is either ":" or "=" characters + + if ((sindex > -1 && (sindex === 0 || "\"':".indexOf(options.source.charAt(sindex - 1)) < 0)) || (options.mode === "diff" && dindex > -1 && (dindex === 0 || "\"':".indexOf(options.diff.charAt(dindex - 1)) < 0))) { + let pdcom:number = sindex, + a:number = (pdcom > -1) + ? pdcom + : dindex, + b:number = 0, + quote:string = "", + item:string = "", + lang:string = "", + lex:string = "", + valkey:string[] = [], + op:string[] = []; + const ops:string[] = [], + source:string = (pdcom > -1) + ? options.source + : options.diff, + len:number = source.length, + comment:string = (source.charAt(a) === "<") + ? "") { + break; + } + if (comment === "//" && source.charAt(a) === "\n") { + break; + } + if (comment === "/\u002a" && source.slice(a - 1, a + 1) === "\u002a/") { + break; + } + } else if (source.charAt(a) === quote && quote !== "${") { + quote = ""; + } else if (quote === "`" && source.slice(a, a + 2) === "${") { + quote = "${"; + } else if (quote === "${" && source.charAt(a) === "}") { + quote = "`"; + } + } + a = a + 1; + } while (a < len); + if (b > 0) { + quote = source.slice(b, a + 1); + if (comment === "
  • brace_line

  • brace_padding

  • brace_style

  • braces

  • color

  • comment_line

  • comments

  • complete_document

  • compressed_css

  • conditional

  • content

  • correct

  • crlf

  • css_insert_lines

  • diff

  • diff_comments

  • diff_context

  • diff_format

  • diff_label

  • diff_rendered_html

  • diff_space_ignore

  • diff_view

  • else_line

  • end

  • end_comma

  • end_quietly

  • force_attribute

  • force_indent

  • format_array

  • format_object

  • function_name

  • help

  • indent_char

  • indent_level

  • indent_size

  • jsscope

  • language

  • language_default

  • language_name

  • lexer

  • list_options

  • method_chain

  • minify_keep_comments

  • minify_wrap

  • mode

  • never_flatten

  • new_line

  • no_case_indent

  • no_lead_zero

  • node_error

  • object_sort

  • output

  • parse_format

  • parse_space

  • preserve

  • preserve_comment

  • preserve_text

  • quote

  • quote_convert

  • read_method

  • selector_list

  • semicolon

  • source

  • source_label

  • space

  • space_close

  • start

  • styleguide

  • summary_only

  • tag_merge

  • tag_sort

  • ternary_line

  • top_comments

  • unformatted

  • variable_list

  • version

  • vertical

  • wrap

  • +
  • brace_line

  • brace_padding

  • brace_style

  • braces

  • color

  • comment_line

  • comments

  • complete_document

  • compressed_css

  • conditional

  • content

  • correct

  • crlf

  • css_insert_lines

  • diff

  • diff_comments

  • diff_context

  • diff_format

  • diff_label

  • diff_rendered_html

  • diff_space_ignore

  • diff_view

  • else_line

  • end_comma

  • end_quietly

  • force_attribute

  • force_indent

  • format_array

  • format_object

  • function_name

  • help

  • indent_char

  • indent_level

  • indent_size

  • jsscope

  • language

  • language_default

  • language_name

  • lexer

  • list_options

  • method_chain

  • minify_keep_comments

  • minify_wrap

  • mode

  • never_flatten

  • new_line

  • no_case_indent

  • no_lead_zero

  • node_error

  • object_sort

  • output

  • parse_format

  • parse_space

  • preserve

  • preserve_comment

  • preserve_text

  • quote

  • quote_convert

  • read_method

  • selector_list

  • semicolon

  • source

  • source_label

  • space

  • space_close

  • styleguide

  • summary_only

  • tag_merge

  • tag_sort

  • ternary_line

  • top_comments

  • unformatted

  • variable_list

  • version

  • vertical

  • wrap

  • @@ -373,6 +373,6 @@ - + \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index c95313f8..ee0cd569 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 { @@ -155,7 +155,6 @@ interface optionDef { } interface optionFunctions { definitions?: {}; - } interface performance { codeLength: number; @@ -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[]; @@ -193,6 +207,11 @@ interface simulationItem { qualifier: qualifier; test: string; } +interface version { + date: string; + number: string; + parse: string; +} interface Window { sparser: any; } \ No newline at end of file diff --git a/index.xhtml b/index.xhtml index 5ef66746..4e4c9568 100644 --- a/index.xhtml +++ b/index.xhtml @@ -9,7 +9,7 @@ - +
    -

    Latest Commit:2 Apr 2019 Version: 100.3.1 +

    Latest Commit:21 Apr 2019 Version: 101.0.0

    @@ -347,7 +347,7 @@ - + diff --git a/minify/markup.ts b/minify/markup.ts index 8cef4bed..4c20e442 100644 --- a/minify/markup.ts +++ b/minify/markup.ts @@ -4,16 +4,16 @@ const markup = function minify_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 minify_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 minify_markup_levels_next():number { let x:number = a + 1, @@ -79,7 +79,7 @@ } comstart = -1; }; - let a:number = options.start, + let a:number = prettydiff.start, next:number = 0, comstart:number = -1; // data.lines -> space before token @@ -183,7 +183,7 @@ } data.token[y - 1] = data.token[y - 1] + end[0]; }; - let a:number = options.start, + let a:number = prettydiff.start, b:number = 0, next:number = 0, external:string = "", @@ -191,7 +191,7 @@ count:number = 0, linelen:number = 0, lines:string[] = []; - if (options.top_comments === true && data.types[a] === "comment" && options.start === 0) { + if (options.top_comments === true && data.types[a] === "comment" && prettydiff.start === 0) { if (a > 0) { build.push(lf); } @@ -280,9 +280,9 @@ count = count + data.token[a].length; } } else { - options.end = externalIndex[a]; + prettydiff.end = externalIndex[a]; options.indent_level = lastLevel; - options.start = a; + prettydiff.start = a; external = prettydiff.minify[data.lexer[a]](options).replace(/\s+$/, ""); if (options.wrap > 0 && options.minify_wrap === true) { build.push(lf); diff --git a/minify/script.ts b/minify/script.ts index ebafb67f..70d90860 100644 --- a/minify/script.ts +++ b/minify/script.ts @@ -15,9 +15,9 @@ : "\n", lexer:string = "script", invisibles:string[] = ["x;", "x}", "x{", "x(", "x)"], - end:number = (options.end < 1 || options.end > data.token.length) + end:number = (prettydiff.end < 1 || prettydiff.end > data.token.length) ? data.token.length - : options.end + 1, + : prettydiff.end + 1, build:string[] = [], lastsemi = function minify_script_lastsemi() { let aa:number = a, @@ -38,10 +38,10 @@ aa = aa - 1; } while (aa > -1); }; - let a:number = options.start, + let a:number = prettydiff.start, count:number = 0, external:string = ""; - if (options.top_comments === true && options.minify_keep_comments === false && data.types[a] === "comment" && options.start === 0) { + if (options.top_comments === true && options.minify_keep_comments === false && data.types[a] === "comment" && prettydiff.start === 0) { if (a > 0) { build.push(lf); } @@ -121,12 +121,12 @@ } a = a + 1; } while (a < end); - options.start = skip; - options.end = a; + prettydiff.start = skip; + prettydiff.end = a; if (a > end - 1) { a = skip; quit = true; - options.end = end - 2; + prettydiff.end = end - 2; } external = prettydiff.minify[data.lexer[a]](options).replace(/\s+$/, ""); if (options.wrap > 0 && options.minify_wrap === true && data.token[skip - 1] !== "return") { diff --git a/minify/style.ts b/minify/style.ts index 3bc9fad8..6be0aecf 100644 --- a/minify/style.ts +++ b/minify/style.ts @@ -6,11 +6,11 @@ lf:"\r\n"|"\n" = (options.crlf === true) ? "\r\n" : "\n", - len:number = (options.end < 1 || options.end > data.token.length) + len:number = (prettydiff.end < 1 || prettydiff.end > data.token.length) ? data.token.length - : options.end + 1, + : prettydiff.end + 1, build:string[] = []; - let a:number = options.start, + let a:number = prettydiff.start, b:number = 0, c:number = 0, list:string[] = [], @@ -18,7 +18,7 @@ countx:number = 0; //beautification loop - if (options.top_comments === true && options.minify_keep_comments === false && data.types[a] === "comment" && options.start === 0) { + if (options.top_comments === true && options.minify_keep_comments === false && data.types[a] === "comment" && prettydiff.start === 0) { if (a > 0) { build.push(lf); } diff --git a/mode.ts b/mode.ts deleted file mode 100644 index eee388d3..00000000 --- a/mode.ts +++ /dev/null @@ -1,768 +0,0 @@ -/*global global, window*/ -(function mode_init() { - "use strict"; - const mode = function mode_(options:any, diffmeta?:diffmeta):string { - let globalAPI:any = (options.api === "dom") - ? window - : global, - modeValue:"beautify"|"minify" = options.mode, - result:string = ""; - const pdcomment = function mode_pdcomment(options:any):void { - const ops:any = globalAPI.sparser.options; - let sindex:number = options.source.search(/((\/(\*|\/))| - // - // - // - Parsing Considerations: - // * there may be any amount of space at the start or end of the comment - // * "prettydiff.com" must exist at the start of the comment - // * comment must exist prior to non-comment tokens (near top of code) - // * parameters are name value pairs separated by white space - // * the delimiter separating name and value is either ":" or "=" characters - - if ((sindex > -1 && (sindex === 0 || "\"':".indexOf(options.source.charAt(sindex - 1)) < 0)) || (options.mode === "diff" && dindex > -1 && (dindex === 0 || "\"':".indexOf(options.diff.charAt(dindex - 1)) < 0))) { - let pdcom:number = sindex, - a:number = (pdcom > -1) - ? pdcom - : dindex, - b:number = 0, - quote:string = "", - item:string = "", - lang:string = "", - lex:string = "", - valkey:string[] = [], - op:string[] = []; - const ops:string[] = [], - source:string = (pdcom > -1) - ? options.source - : options.diff, - len:number = source.length, - comment:string = (source.charAt(a) === "<") - ? "") { - break; - } - if (comment === "//" && source.charAt(a) === "\n") { - break; - } - if (comment === "/\u002a" && source.slice(a - 1, a + 1) === "\u002a/") { - break; - } - } else if (source.charAt(a) === quote && quote !== "${") { - quote = ""; - } else if (quote === "`" && source.slice(a, a + 2) === "${") { - quote = "${"; - } else if (quote === "${" && source.charAt(a) === "}") { - quote = "`"; - } - } - a = a + 1; - } while (a < len); - if (b > 0) { - quote = source.slice(b, a + 1); - if (comment === "", - injectFlag: `${versionData.date} Version: ${versionData.number}`, + injectFlag: `${prettydiff.version.date} Version: ${prettydiff.version.number}`, start: "" }); data = data.replace(/(\.css\?\d*)/g, `.css?${date}`).replace(/(\.js\?\d*)/g, `.js?${date}`); } else if (fileFlag === "webtool") { - modify({ - end: "// end option defaults", - injectFlag: buildDefaults("dom"), - start:"// start option defaults" - }); modify({ end: "// prettydiff dom insertion end", - injectFlag: saveas + libraries + mode, + injectFlag: `prettydiff=${complete.replace(/(\s*\/\*(\w|\s|\d|\.|:|-)+\*\/)+\s*/, "").replace(/\s*("|')use\s+strict("|');/g, "") + saveas}return prettydiff;}());`, start: "// prettydiff dom insertion start" }); - data = `${parser + data.replace(/("|')use strict("|');/g, "").replace(/window\.sparser/g, "sparser")}}());`; - } else if (fileFlag === "node") { - modify({ - end: "// node option default end", - injectFlag: buildDefaults("node"), - start:"// node option default start" - }); - } else if (fileFlag === "mode") { - modify({ - end: "// prettydiff file insertion end", - injectFlag: `prettydiff={};${libraries}`, - start: "// prettydiff file insertion start" - }); + webtool = data; } - node.fs.writeFile(file, data, function node_apps_build_libraries_modifyFile_read_write(errw:Error) { - if (errw !== null && errw.toString() !== "") { - apps.errout([errw.toString()]); - return; - } + if (file.slice(file.length - 3) !== ".js") { + node.fs.writeFile(file, data, "utf8", function node_apps_build_libraries_modifyFile_write(err:Error) { + if (err !== null) { + apps.errout([err.toString()]); + return; + } + flag[fileFlag] = true; + writeJavaScript(); + }); + } else { flag[fileFlag] = true; - if (flag.documentation === true && flag.html === true && flag.node === true && flag.webtool === true) { - let thirdparty:string = parser + libraries + mode.replace(/,\s*\/\/\s*prettydiff\s*file\s*insertion\s*start\s+prettydiff\s*=\s*\{\};\s*\/\/\s*prettydiff\s*file\s*insertion\s*end/, ";"); - node.fs.writeFile(`${js}browser.js`, `${thirdparty}window.prettydiff=prettydiff;}());`, function node_apps_build_libraries_modifyFile_read_write_readParser_writeBrowser(erbr:Error) { - if (erbr !== null && erbr.toString() !== "") { - apps.errout([erbr.toString()]); - return; - } - flag.browser = true; - if (flag.prettydiff === true) { - next(`${text.green}Option details written to files.${text.none}`); - } - }); - node.fs.writeFile(`${js}prettydiff.js`, `${thirdparty}module.exports=prettydiff;}());`, function node_apps_build_libraries_modifyFile_read_write_readParser_writePrettydiff(erth:Error) { - if (erth !== null && erth.toString() !== "") { - apps.errout([erth.toString()]); - return; - } - flag.prettydiff = true; - if (flag.browser === true) { - next(`${text.green}Option details written to files.${text.none}`); - } - }); - } - }); + writeJavaScript(); + } }); }, libraryFiles = function node_apps_build_libraries_libraryFiles() { libFiles.push(`${projectPath}node_modules${sep}file-saver${sep}FileSaver.min.js`); libFiles.push(`${projectPath}node_modules${sep}sparser${sep}js${sep}browser.js`); - libFiles.push(`${projectPath}node_modules${sep}sparser${sep}js${sep}libs${sep}language.js`); const appendFile = function node_apps_build_libraries_libraryFiles_appendFile(filePath:string):void { node.fs.readFile(filePath, "utf8", function node_apps_build_libraries_libraryFiles_appendFile_read(errr:Error, filedata:string):void { const filenames:string[] = filePath.split(sep), @@ -1331,35 +1265,41 @@ interface readFile { } else if (filePath === `${projectPath}node_modules${sep}sparser${sep}js${sep}browser.js`) { // both sparser and prettydiff contain a browser.js file, so it is important to target the correct one filedata = filedata - .replace(/("|')use strict("|');/g, "") - .replace(/\s*const\s+parser/, `"use strict";const prettydiff={api:{},beautify:{},defaults:${JSON.stringify(options)},minify:{}},parser`) + .replace(/\s*("|')use strict("|');/g, "") + .replace(/\s*const\s+parser/, `"use strict";const parser`) .replace(/window\.sparser/g, "sparser") - .replace(/sparser\s*=\s*sparser;\s*\}\(\)\);(prettydiff\.beautify=\{\};)?(prettydiff\.api=\{\};)?(prettydiff\.minify=\{\};)?/, ""); + .replace(/sparser\s*=\s*sparser;\s*\}\(\)\);(prettydiff\.beautify=\{\};)?(prettydiff\.api=\{\};)?(prettydiff\.minify=\{\};)?/, "") + .replace(/\s*sparser\.libs\.language\s*=\s*language;/, "sparser.libs.language=language;prettydiff.api.language=language;"); parser = filedata; } else { filedata = filedata .replace(/(\/\*global\s+global(,\s*options)?(,\s*prettydiff)?\s*\*\/\s*)/, "") .replace(/global\s*\.\s*prettydiff\s*\./g, "prettydiff.") - .replace(/("|')use strict("|');/, ""); + .replace(/\s*("|')use strict("|');/, ""); if (filename === "mode.js" && filePath.indexOf(filename) === filePath.length - filename.length) { mode = filedata + .replace(/\/\*\s*global\s+prettydiff\s*\*\//, "") + .replace(/\s+/, "") + .replace(/\s+$/, ";") .replace(/global(API)?\./g, "") - .replace(/\/\*global\s+global(\s*,\s*window)?\*\//, "") + .replace(/globalAPI\.sparser/g, "sparser") .replace(/globalAPI\s*=\s*\(options\.api\s*===\s*"dom"\)\s*\?\s*window\s*:\s*global,/, "") .replace(/if\s*\(options\.api\s*===\s*"dom"\)\s*\{\s*globalAPI\s*=\s*window;\s*\}/, "") - .replace(/,\s*\/\/\s*prettydiff file insertion start\s+prettydiff\s*=\s*\{\};/, ";"); - } else if (filename === "language.js" && filePath.indexOf(filename) === filePath.length - filename.length) { - libraries = libraries + filedata.replace("global.sparser.libs.language", "prettydiff.api.language"); - } else { - libraries = libraries + filedata; + .replace(/,\s*\/\/\s*prettydiff file insertion start\s+prettydiff\s*=\s*\{\};/, ";") + .replace(/\s*mode\(\);/, "") + .replace(/\s*prettydiff\s*=\s*prettydiff;/, "") + `prettydiff.api={};prettydiff.beautify={};prettydiff.end=0;prettydiff.iterator=0;prettydiff.meta={error:"",lang:["","",""],time:"",insize:0,outsize:0,difftotal:0,difflines:0};prettydiff.minify={};prettydiff.options=${defaults};prettydiff.scopes=[];prettydiff.start=0;`; + } else if (filename !== "prettydiff-webtool.js") { + libraries = libraries + filedata.replace(/\s*global\s*\.\s*prettydiff/, "prettydiff"); } } a = a + 1; if (a === filelen) { - modifyFile(`${js}services.js`, "node"); + const inject = function node_apps_build_libraries_appendFile_inject(version:string):string { + return `${version.slice(0, version.length - 1)},prettydiff=${mode}`; + }; + complete = `${parser.replace(/version:\{date:"\d+\s+\w+\s+\d{4}",number:"\d+\.\d+\.\d+"\}\s*\};/, inject) + libraries}prettydiff.sparser=sparser;prettydiff.version=${JSON.stringify(prettydiff.version)};`; modifyFile(`${projectPath}index.xhtml`, "html"); - modifyFile(`${js}prettydiff-webtool.js`, "webtool"); - modifyFile(`${js}mode.js`, "mode"); + modifyFile(`${js}api${sep}prettydiff-webtool.js`, "webtool"); modifyFile(`${projectPath}documentation.xhtml`, "documentation"); } }); @@ -1376,9 +1316,6 @@ interface readFile { apps.errout([errd.toString()]); return; } - const dirnames:string[] = pathitem.split(sep).filter(dirs => dirs !== ""), - groupname:string = dirnames[dirnames.length - 1]; - libraries = libraries + `prettydiff.${groupname}={};`; filelen = filelen + (filelist.length - 1); filelist.forEach(function node_apps_build_libraries_libraryFiles_stat_callback_readdir_each(value:string):void { node_apps_build_libraries_libraryFiles_stat(pathitem + sep + value); @@ -1402,23 +1339,30 @@ interface readFile { return; } const date:string[] = stderr.slice(stderr.indexOf("Date:") + 12).split(" "); - versionData.date = `${date[1]} ${date[0]} ${date[3]}`; + prettydiff.version.date = `${date[1]} ${date[0]} ${date[3]}`; node.fs.readFile(`${projectPath}package.json`, "utf8", function node_apps_build_libraries_versionGather_child_readPackage(errp:Error, data:string):void { if (errp !== null) { apps.errout([errp.toString()]); return; } - versionData.number = JSON.parse(data).version; + prettydiff.version.number = JSON.parse(data).version; node.fs.readFile(`${projectPath}node_modules${sep}sparser${sep}package.json`, "utf8", function node_apps_build_libraries_versionGather_child_readPackage_readSparser(errf:Error, frameData:string):void { if (errf !== null) { apps.errout([errf.toString()]); return; } - versionData.parse = JSON.parse(frameData).version; + prettydiff.version.parse = JSON.parse(frameData).version; // update information for display in current build - version.date = versionData.date; - version.number = versionData.number; - version.parse = versionData.parse; + defaults = (function node_apps_build_libraries_modifyFile_read_buildDefault():string { + const obj:any = {}; + let a:number = 0; + do { + obj[optkeys[a]] = prettydiff.api.optionDef[optkeys[a]].default; + a = a + 1; + } while (a < keyslen); + obj.lexerOptions = {}; + return JSON.stringify(obj); + }()); libraryFiles(); }); }); @@ -2927,8 +2871,8 @@ interface readFile { }); if (verbose === true) { console.log(""); - console.log(`Sparser version ${text.angry + version.parse + text.none}`); - console.log(`Pretty Diff version ${text.angry + version.number + text.none} dated ${text.cyan + version.date + text.none}`); + console.log(`Sparser version ${text.angry + prettydiff.version.parse + text.none}`); + console.log(`Pretty Diff version ${text.angry + prettydiff.version.number + text.none} dated ${text.cyan + prettydiff.version.date + text.none}`); apps.humantime(true); } }; @@ -3328,8 +3272,6 @@ interface readFile { return; } const readmethod:string = options.read_method, - //auto:boolean = (readmethod === "auto"), - all = require(`${projectPath}node_modules${sep}sparser${sep}js${sep}lexers${sep}all`), item:string = (diff === true) ? "diff" : "source", @@ -3343,11 +3285,11 @@ interface readFile { differences: 0, lines: 0 }; - const result:string = prettydiff.mode(options, meta); + const result:string = prettydiff(meta); apps.log([""], result, `${meta.differences},${meta.lines}`); } } else { - apps.log([""], prettydiff.mode(options), ""); + apps.log([""], prettydiff(options), ""); } }, resolveItem = function node_apps_readmethod_resolve_stat_resolveItem() { @@ -3669,7 +3611,7 @@ interface readFile { callback: function node_apps_readmethod_resolve_stat_resolveItem_callbackOther_readFiles_callback(args:readFile, dump:string|Buffer):void { if (typeof dump === "string") { options.source = dump; - const result:string = prettydiff.mode(options); + const result:string = prettydiff(options); if (result.indexOf("Error: ") === 0) { apps.errout([result.replace("Error: ", "")]); fail = true; @@ -3740,7 +3682,7 @@ interface readFile { differences: 0, lines: 0 }; - const result:string = prettydiff.mode(options, meta), + const result:string = prettydiff(meta), path = (options.mode === "diff") ? `${meta.differences},${meta.lines}` : args.path; @@ -3807,12 +3749,7 @@ interface readFile { } }); }; - if (global.sparser === undefined) { - require(`${projectPath}node_modules${sep}sparser${sep}js${sep}parse`); - } - all(options, function node_apps_readmethod_allLexers() { - resolve(); - }); + resolve(); }; // similar to posix "rm -rf" command apps.remove = function node_apps_remove(filepath:string, callback:Function):void { @@ -3942,7 +3879,7 @@ interface readFile { : projectPath + uri.slice(1).replace(/\/$/, "").replace(/\//g, sep); node.fs.stat(localpath, function node_apps_server_create_stat(ers:nodeError, stat:Stats):void { const random:number = Math.random(), - page:string = `Pretty Diff - Local Service

    Pretty Diff - Local Server

    Browse Pretty Diff on GitHub or NPM.

    insertme
    `; + page:string = `Pretty Diff - Local Service

    Pretty Diff - Local Server

    Browse Pretty Diff on GitHub or NPM.

    insertme
    `; if (ers !== null) { if (ers.code === "ENOENT") { console.log(`${text.angry}404${text.none} for ${uri}`); @@ -4327,11 +4264,9 @@ interface readFile { }; // unit test validation runner for Pretty Diff mode commands apps.validation = function node_apps_validation(callback:Function):void { - require(`${projectPath}node_modules${sep}sparser${sep}js${sep}parse`); let count_raw = 0, count_formatted = 0; - const all = require(`${projectPath}node_modules${sep}sparser${sep}js${sep}lexers${sep}all`), - flag = { + const flag = { raw: false, formatted: false }, @@ -4451,7 +4386,7 @@ interface readFile { b = b + 1; } while (b < noteslen); } - output = prettydiff.mode(options); + output = prettydiff(options); if (output === formatted[a][1]) { filecount = filecount + 1; console.log(`${apps.humantime(false) + text.green}Pass ${filecount}:${text.none} ${formatted[a][0]}`); @@ -4546,10 +4481,8 @@ interface readFile { if (command === "validation") { verbose = true; } - all(options, function node_apps_validation_allLexers() { - readDir("raw"); - readDir("formatted"); - }); + readDir("raw"); + readDir("formatted"); }; // runs apps.log apps.version = function ():void { diff --git a/tests/browser-demo.js b/tests/browser-demo.js index 161bc385..b0ac8526 100644 --- a/tests/browser-demo.js +++ b/tests/browser-demo.js @@ -3,14 +3,14 @@ import "../js/browser.js"; let button = document.getElementsByTagName("button")[0], execute = function () { let prettydiff = window.prettydiff, - options = prettydiff.defaults, + options = prettydiff.options, output = ""; options.api = "dom"; options.language = "auto"; options.lexer = "script"; options.mode = "beautify"; options.source = document.getElementById("input").value; - output = prettydiff.mode(options); + output = prettydiff(options); document.getElementById("output").value = output; }; button.onclick = execute; diff --git a/tests/browser.html b/tests/browser.html index 2e80f15a..9da17c0a 100644 --- a/tests/browser.html +++ b/tests/browser.html @@ -20,9 +20,10 @@

    Attaching the application

    Configuring and executing the application

    Configuring the application is as simple as creating the options object and passing that object into the application.

    - let prettydiff = window.prettydiff.mode, - options = {source:"var a=1;",wrap:80}, - myResult = prettydiff(options); + let prettydiff = window.prettydiff; + prettydiff.options.source = "var a=1;"; + prettydiff.options.wrap = 80; + myResult = prettydiff();

    Please note that while that does work it is risky. I always recommend building options off the default options object for more predictable options. See the larger following example.

    @@ -38,7 +39,7 @@

    Demo

    // inside the application we gather the application let prettydiff = window.prettydiff, // this provides all options set to their default values for safety - options = prettydiff.defaults, + options = prettydiff.options, output = ""; // here is where we overwrite the default options with custom values options.api = "dom"; @@ -48,7 +49,7 @@

    Demo

    options.source = document.getElementById("input").value; // this where the application executes and the string output is assigned - output = prettydiff.mode(options); + output = prettydiff(); // output the generated string into the dom document.getElementById("output").value = output; @@ -67,4 +68,4 @@

    Demo

    - \ No newline at end of file + \ No newline at end of file diff --git a/tests/formatted/beautify_script_language-jsx_scriptStart.txt b/tests/formatted/beautify_script_language-jsx_scriptStart.txt new file mode 100644 index 00000000..7e9704de --- /dev/null +++ b/tests/formatted/beautify_script_language-jsx_scriptStart.txt @@ -0,0 +1,31 @@ +var a = ( + + { + getFieldDecorator('flow_path_id', { + initialValue: value.FlowPathId + ? value.FlowPathId + : '', + rules : [ + { + required: true + }, + ] + })(); + } + + this.showFlowSteps(value.FlowPathId); + }> + + + + +); diff --git a/tests/formatted/minify_style_less_top_comments.txt b/tests/formatted/minify_style_less_top_comments.txt index 66a6c672..a4110aec 100644 --- a/tests/formatted/minify_style_less_top_comments.txt +++ b/tests/formatted/minify_style_less_top_comments.txt @@ -8,4 +8,4 @@ Please see the license.txt file associated with the Pretty Diff application for license information. ****************************************************************************/ -@carrier-logo-height:33px;@carrier-logo-width:44px;.itemResultsCard(){@arrow-size:10px;@font-size-xxs:10px;@line-height-xxs:12px;.itemResultsCard{border:1px solid @color-neutral-md-light;color:@color-black;.clearfix();.itemSummary{float:left;width:70%;.display-inline-block();}}} +@carrier-logo-height:33px;@carrier-logo-width:44px;.itemResultsCard(){@arrow-size:10px;@font-size-xxs:10px;@line-height-xxs:12px;.itemResultsCard{border:1px solid @color-neutral-md-light;color:@color-black;.itemSummary{float:left;width:70%;.display-inline-block();}}} diff --git a/tests/raw/beautify_script_language-jsx_scriptStart.txt b/tests/raw/beautify_script_language-jsx_scriptStart.txt new file mode 100644 index 00000000..77ac9276 --- /dev/null +++ b/tests/raw/beautify_script_language-jsx_scriptStart.txt @@ -0,0 +1,24 @@ + var a = ( + + + + {getFieldDecorator('flow_path_id', { + rules: [ + { + required: true, + }, + ], + initialValue: value.FlowPathId ? value.FlowPathId : '', + })()} + + + this.showFlowSteps(value.FlowPathId)}> + + + + + ); \ No newline at end of file diff --git a/tests/raw/minify_style_less_top_comments.txt b/tests/raw/minify_style_less_top_comments.txt index f7c7c217..7c7b0c59 100644 --- a/tests/raw/minify_style_less_top_comments.txt +++ b/tests/raw/minify_style_less_top_comments.txt @@ -18,7 +18,6 @@ .itemResultsCard { border: 1px solid @color-neutral-md-light; - .clearfix(); color : @color-black; // Card Layout Sections diff --git a/tests/simulations.ts b/tests/simulations.ts index 99a5e3f4..cb601bfc 100644 --- a/tests/simulations.ts +++ b/tests/simulations.ts @@ -358,7 +358,7 @@ { command: "opts 2", qualifier: "contains", - test: `${text.green}78${text.none} matching options.` + test: `${text.green}76${text.none} matching options.` }, { command: "opts api:node",