pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
391 stars 42 forks source link

syntax error, unexpected 'else' (T_ELSE) #184

Closed sandrodz closed 6 years ago

sandrodz commented 6 years ago

Hello,

I encountered an issue with the following code:

    if wp_footer
      !=wp_footer
    else
      script(src="//cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js")
      script(src="/assets/vendor.js")
      if(prod)
        script(src="//cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.min.js")
      else
        script(src="//cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js")
      script(src="//cdn.jsdelivr.net/npm/vue-social-sharing@2.3.3/dist/vue-social-sharing.min.js")
      script(src="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js")
      script(src="//cdn.jsdelivr.net/npm/izimodal@1.5.1/js/iziModal.min.js")
      script(src="https://cdn.ravenjs.com/3.20.1/console,vue/raven.min.js" crossorigin="anonymous")
      if(prod)
        script.
          Raven.config('#{api.sentry}').install();

          $(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
            Raven.captureMessage(thrownError || jqXHR.statusText, {
              extra: {
                type: ajaxSettings.type,
                url: ajaxSettings.url,
                data: ajaxSettings.data,
                status: jqXHR.status,
                error: thrownError || jqXHR.statusText,
                response: jqXHR.responseText ? jqXHR.responseText.substring(0, 100) : ''
              }
            });
          });
      script(src="/assets/app.js")

In nested if else else is causing error:

      if(prod)
        script(src="//cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.min.js")
      else

Thanks!

kylekatarnls commented 6 years ago

Hi, the problem seems to come from the parentheses. Use if prod instead of if(prod).

I will try to fix that.

kylekatarnls commented 6 years ago

Hi, you can use composer update to update the Phug lexer. The syntax if(prod) is now valid.

sandrodz commented 6 years ago

Thanks! works now.