MCPcopy Index your code
hub / github.com/prettydiff/prettydiff / script

Function script

beautify/script.ts:6–2583  ·  view source on GitHub ↗
(options:any)

Source from the content-addressed store, hash-verified

4(function beautify_script_init():void {
5 "use strict";
6 const script = function beautify_script(options:any):string {
7 let scolon:number = 0,
8 news:number = 0;
9 const data:data = options.parsed,
10 lexer:string = "script",
11 scopes:scriptScopes = prettydiff.scopes,
12 b:number = (prettydiff.end < 1 || prettydiff.end > data.token.length)
13 ? data.token.length
14 : prettydiff.end + 1,
15 externalIndex:externalIndex = {},
16 // levels sets the white space value between the current token and the next token
17 // * -20 value means no white space
18 // * -10 means to separate with a space
19 // * 0 and above is the number of indentation to insert
20 levels:number[] = (function beautify_script_level():number[] {
21 let a = prettydiff.start, //will store the current level of indentation
22 indent:number = (isNaN(options.indent_level) === true)
23 ? 0
24 : Number(options.indent_level),
25 notcomment:boolean = false, // if in comments before any code
26 lastlist:boolean = false, //remembers the list status of the most recently closed block
27 ctype:string = "", //ctype stands for "current type"
28 ctoke:string = "", //ctoke standa for "current token"
29 ltype:string = data.types[0], //ltype stands for "last type"
30 ltoke:string = data.token[0]; //ltype stands for "last token"
31 const varindex:number[] = [-1], //index in current scope of last var, let, or const keyword
32 list:boolean[] = [], //stores comma status of current block
33 level:number[] = (prettydiff.start > 0)
34 ? Array(prettydiff.start).fill(0, 0, prettydiff.start)
35 : [],
36 ternary:number[] = [], //used to identify ternary statments
37 extraindent = [
38 []
39 ], //stores token indexes where extra indentation occurs from ternaries and broken method chains
40 arrbreak:boolean[] = [], //array where a method break has occurred
41 destruct:boolean[] = [], //attempt to identify object destructuring
42 itemcount:number[] = [], //counts items in destructured lists
43 assignlist:boolean[] = [false], //are you in a list right now?
44 wordlist:boolean[] = [],
45 count:number[] = [],
46 comment = function beautify_script_level_comment():void {
47 destructfix(false, false);
48 let ind:number = (options.comments === true)
49 ? 0
50 : indent;
51 if (notcomment === false && (/\/\u002a\s*global\s/).test(data.token[a]) === true) {
52 let globallist:string[] = data.token[a].replace(/\/\u002a\s*global\s+/, "").replace(/\s*\u002a\/$/, "").split(","),
53 aa:number = globallist.length;
54 do {
55 aa = aa - 1;
56 globallist[aa] = globallist[aa].replace(/\s+/g, "");
57 if (globallist[aa] !== "") {
58 scopes.push([globallist[aa], -1]);
59 }
60 } while (aa > 0);
61 }
62 if (data.types[a - 1] === "comment" || data.types[a + 1] === "comment") {
63 level[a - 1] = ind;

Callers

nothing calls this directly

Calls 15

stringFunction · 0.85
templateStringFunction · 0.85
separatorFunction · 0.85
startFunction · 0.85
endFunction · 0.85
typesFunction · 0.85
operatorFunction · 0.85
wordFunction · 0.85
referenceFunction · 0.85
templateFunction · 0.85
blocklineFunction · 0.85
foldstartFunction · 0.85

Tested by

no test coverage detected