SandboxJS icon indicating copy to clipboard operation
SandboxJS copied to clipboard

Line after one-line if statement disappears

Open Christilut opened this issue 1 year ago • 4 comments
trafficstars

This is my script:

console.log(1)

if (false) throw new Error('test')

console.log(2)

console.log(3)

I run it like this:

// this.jsContents is the the above script

const jsContentsExecutor: string = `async function _execute() {${this.jsContents}}; return _execute();`

const jsExecutor = sandbox.compileAsync(jsContentsExecutor)

  await jsExecutor({ 
//    _vars: pluginVars, // Normally some vars are added
//    _settings: pluginSettings
  }).run()

This is the output:

1
3

So it appears the 2 is disappearing.

If I change the line to have brackets, it does work:

if (false) { 
  throw new Error('test')
}

Results in:

1
2
3

Christilut avatar Jun 30 '24 11:06 Christilut

Do while loop has the same problem:

console.log(1)

do {
  console.log(2)

  break
} while (true)

console.log(3)

console.log(4)

Results in:

1
2
4

Christilut avatar Jul 01 '24 09:07 Christilut

hello there ! 👋 have you found a solution or are you using other library ?

alvarolm avatar Sep 22 '24 16:09 alvarolm

Same problem here.

gustavotoyotarh avatar Apr 25 '25 12:04 gustavotoyotarh

This seems to be a problem with the semicolon insertions. For now you can add semicolons to lines as a workaround.

nyariv avatar May 10 '25 14:05 nyariv