Picolab / pico-engine

An implementation of the pico-engine hosted on node.js
http://picolabs.io/
MIT License
43 stars 8 forks source link

Installing a ruleset gives this error "SyntaxError: Identifier 'url3' has already been declared" #590

Open b1conrad opened 2 years ago

b1conrad commented 2 years ago

But running it through krl-compiler --verify didn't report an error.

Trying it without the --verify flag... No error reported, but the generated Javascript code includes

        var url3 = $state.setting["url"];
        this.rule.state = Object.assign({}, $state, { "setting": {} });
        const url3 = await get1($ctx, [...]);

so the error isn't detected until the JS compiled code is brought into the pico engine in order to evaluate the global block.

It is a KRL programmer error! But it would be nice if the krl-compiler could catch it!

  rule installApp {
    select when byu_hr_manage_apps new_app
      url re#(.+)# setting(url)
    pre {
      url = event:attr("_headers").get("referer")
    }   
    if url then send_directive("_redirect",{"url":url})
    fired {
      raise wrangler event "install_ruleset_request"
        attributes {"url":url,"tx":meta:txnId}
    }   
  }

Meanwhile, it can be easily fixed in KRL by not re-using a variable name from setting within the prelude.