browserify / rustify

Rust WebAssembly transform for Browserify
Apache License 2.0
495 stars 25 forks source link

Adding a semi-colon causes issues on the transform #8

Closed gregtatum closed 6 years ago

gregtatum commented 6 years ago

I'd like to do something like this, but the semi-colon added at the beginning of the statement causes a syntax error:

;(async () => {
  const { addOne } = await instantiateWasm(rust`
    #[no_mangle]
    pub fn addOne(x: i32) -> i32 {
      x + 1
    }
  `)
})()
yoshuawuyts commented 6 years ago

@gregtatum Uh oh that's no good. It's probably this code that's probably causing it: https://github.com/browserify/rustify/blob/master/lib/transform.js#L82-L85

What's the resulting (incorrect) code look like? We should probably add the statement type to the whitelist so it doesn't generate it. The node type can be found by passing the ^ code into https://astexplorer.net/.

goto-bus-stop commented 6 years ago

I think we may not need the semicolon code here at all. sheetify needs it because the replacement code starts with an open-paren which may trip up ASI, but rustify's starts with new which doesn't have that issue.