jsgen improve spacing (#18048)

* Fix inconsistent spacings in generated JS of jsgen
This commit is contained in:
Juan Carlos 2021-05-20 10:48:46 -03:00 • committed by GitHub
commit 6a5973882b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 32 deletions

View file

@ -322,7 +322,7 @@ proc isSimpleExpr(p: PProc; n: PNode): bool =
proc getTemp(p: PProc, defineInLocals: bool = true): Rope = proc getTemp(p: PProc, defineInLocals: bool = true): Rope =
inc(p.unique) inc(p.unique)
result = "Tmp$1" % [rope(p.unique)] result = "Temporary$1" % [rope(p.unique)]
if defineInLocals: if defineInLocals:
p.locals.add(p.indentLine("var $1;$n" % [result])) p.locals.add(p.indentLine("var $1;$n" % [result]))
@ -704,7 +704,7 @@ proc hasFrameInfo(p: PProc): bool =
((p.prc == nil) or not (sfPure in p.prc.flags)) ((p.prc == nil) or not (sfPure in p.prc.flags))
proc lineDir(config: ConfigRef, info: TLineInfo, line: int): Rope = proc lineDir(config: ConfigRef, info: TLineInfo, line: int): Rope =
ropes.`%`("// line $2 \"$1\"$n", ropes.`%`("/* line $2 \"$1\" */$n",
[rope(toFullPath(config, info)), rope(line)]) [rope(toFullPath(config, info)), rope(line)])
proc genLineDir(p: PProc, n: PNode) = proc genLineDir(p: PProc, n: PNode) =
@ -725,9 +725,9 @@ proc genWhileStmt(p: PProc, n: PNode) =
p.blocks[^1].id = -p.unique p.blocks[^1].id = -p.unique
p.blocks[^1].isLoop = true p.blocks[^1].isLoop = true
let labl = p.unique.rope let labl = p.unique.rope
lineF(p, "L$1: while (true) {$n", [labl]) lineF(p, "Label$1: while (true) {$n", [labl])
p.nested: gen(p, n[0], cond) p.nested: gen(p, n[0], cond)
lineF(p, "if (!$1) break L$2;$n", lineF(p, "if (!$1) break Label$2;$n",
[cond.res, labl]) [cond.res, labl])
p.nested: genStmt(p, n[1]) p.nested: genStmt(p, n[1])
lineF(p, "}$n", [labl]) lineF(p, "}$n", [labl])
@ -750,8 +750,8 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) =
# try { # try {
# stmts; # stmts;
# --excHandler; # --excHandler;
# } catch (EXC) { # } catch (EXCEPTION) {
# var prevJSError = lastJSError; lastJSError = EXC; # var prevJSError = lastJSError; lastJSError = EXCEPTION;
# framePtr = tmpFramePtr; # framePtr = tmpFramePtr;
# --excHandler; # --excHandler;
# if (e.typ && e.typ == NTI433 || e.typ == NTI2321) { # if (e.typ && e.typ == NTI433 || e.typ == NTI2321) {
@ -785,8 +785,8 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) =
moveInto(p, a, r) moveInto(p, a, r)
var generalCatchBranchExists = false var generalCatchBranchExists = false
if catchBranchesExist: if catchBranchesExist:
p.body.addf("--excHandler;$n} catch (EXC) {$n var prevJSError = lastJSError;$n" & p.body.addf("--excHandler;$n} catch (EXCEPTION) {$n var prevJSError = lastJSError;$n" &
" lastJSError = EXC;$n --excHandler;$n", []) " lastJSError = EXCEPTION;$n --excHandler;$n", [])
line(p, "framePtr = $1;$n" % [tmpFramePtr]) line(p, "framePtr = $1;$n" % [tmpFramePtr])
while i < n.len and n[i].kind == nkExceptBranch: while i < n.len and n[i].kind == nkExceptBranch:
if n[i].len == 1: if n[i].len == 1:
@ -928,7 +928,7 @@ proc genBlock(p: PProc, n: PNode, r: var TCompRes) =
sym.loc.k = locOther sym.loc.k = locOther
sym.position = idx+1 sym.position = idx+1
let labl = p.unique let labl = p.unique
lineF(p, "L$1: do {$n", [labl.rope]) lineF(p, "Label$1: do {$n", [labl.rope])
setLen(p.blocks, idx + 1) setLen(p.blocks, idx + 1)
p.blocks[idx].id = - p.unique # negative because it isn't used yet p.blocks[idx].id = - p.unique # negative because it isn't used yet
gen(p, n[1], r) gen(p, n[1], r)
@ -951,7 +951,7 @@ proc genBreakStmt(p: PProc, n: PNode) =
if idx < 0 or not p.blocks[idx].isLoop: if idx < 0 or not p.blocks[idx].isLoop:
internalError(p.config, n.info, "no loop to break") internalError(p.config, n.info, "no loop to break")
p.blocks[idx].id = abs(p.blocks[idx].id) # label is used p.blocks[idx].id = abs(p.blocks[idx].id) # label is used
lineF(p, "break L$1;$n", [rope(p.blocks[idx].id)]) lineF(p, "break Label$1;$n", [rope(p.blocks[idx].id)])
proc genAsmOrEmitStmt(p: PProc, n: PNode) = proc genAsmOrEmitStmt(p: PProc, n: PNode) =
genLineDir(p, n) genLineDir(p, n)
@ -2431,10 +2431,10 @@ proc genProc(oldProc: PProc, prc: PSym): Rope =
# references will end up calling the reloaded code. # references will end up calling the reloaded code.
var thunkName = name var thunkName = name
name = name & "IMLP" name = name & "IMLP"
result.add("function $#() { return $#.apply(this, arguments); }$n" % result.add("\Lfunction $#() { return $#.apply(this, arguments); }$n" %
[thunkName, name]) [thunkName, name])
def = "function $#($#) {$n$#$#$#$#$#" % def = "\Lfunction $#($#) {$n$#$#$#$#$#" %
[ name, [ name,
header, header,
optionalLine(p.globals), optionalLine(p.globals),