mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-05 20:47:53 +00:00
[JS backend] improve discard statement; ridding of the awkward special variable _ (#23498)
According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/Expression_statement, some expression statements need parentheses to make it unambiguous. `_` introduced in the https://github.com/nim-lang/Nim/pull/15789 is unnecessary. We can get rid of it by adding parentheses so that object literals are not ambiguous with block statements.
This commit is contained in:
@@ -2985,7 +2985,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
|
||||
if n[0].kind != nkEmpty:
|
||||
genLineDir(p, n)
|
||||
gen(p, n[0], r)
|
||||
r.res = "var _ = " & r.res
|
||||
r.res = "(" & r.res & ")"
|
||||
of nkAsmStmt:
|
||||
warningDeprecated(p.config, n.info, "'asm' for the JS target is deprecated, use the 'emit' pragma")
|
||||
genAsmOrEmitStmt(p, n, true)
|
||||
|
||||
@@ -269,5 +269,5 @@ block: # test **
|
||||
block: # issue #21208
|
||||
type MyEnum = enum baz
|
||||
var obj: JsObject
|
||||
{.emit: "`obj` = {bar: {baz: 123}}".}
|
||||
{.emit: "`obj` = {bar: {baz: 123}};".}
|
||||
discard obj.bar.baz
|
||||
|
||||
Reference in New Issue
Block a user