I think I found a bug: Miniracer crashes with valid ES6 syntax

This is quite frustrating and I’d love to understand how historically this has happened.

If I write the following valid ES6 code into discourse/services/foo.js.es6 and add it to the asset pipeline in Discourse it will fail to compile:

const FOO = 'foo';
export default Ember.Service.extend({
  [FOO]() {
    console.log('This should work');
  }
});

But alas I get:

Bundling assets
** Execute assets:precompile
rake aborted!
MiniRacer::RuntimeError: Error: Line 3: Unexpected token [
JavaScript at throwError (<anonymous>:2581:21)
JavaScript at throwUnexpected (<anonymous>:2643:9)
JavaScript at parseObjectProperty (<anonymous>:2914:17)
JavaScript at <anonymous>:5663:38
JavaScript at parseObjectInitialiser (<anonymous>:2943:24)
JavaScript at parsePrimaryExpression (<anonymous>:3082:20)
JavaScript at <anonymous>:5663:38
JavaScript at trackLeftHandSideExpressionAllowCall (<anonymous>:5565:61)
JavaScript at parsePostfixExpression (<anonymous>:3216:20)
JavaScript at <anonymous>:5663:38
/opt/bitnami/apps/discourse/htdocs/vendor/bundle/ruby/2.3.0/gems/mini_racer-0.1.9/lib/mini_racer.rb:168:in `eval_unsafe'
/opt/bitnami/apps/discourse/htdocs/vendor/bundle/ruby/2.3.0/gems/mini_racer-0.1.9/lib/mini_racer.rb:168:in `block (2 levels) in eval'
/opt/bitnami/apps/discourse/htdocs/vendor/bundle/ruby/2.3.0/gems/mini_racer-0.1.9/lib/mini_racer.rb:239:in `timeout'
/opt/bitnami/apps/discourse/htdocs/vendor/bundle/ruby/2.3.0/gems/mini_racer-0.1.9/lib/mini_racer.rb:167:in `block in eval'
/opt/bitnami/apps/discourse/htdocs/vendor/bundle/ruby/2.3.0/gems/mini_racer-0.1.9/lib/mini_racer.rb:64:in `block in with_lock'
/opt/bitnami/apps/discourse/htdocs/vendor/bundle/ruby/2.3.0/gems/mini_racer-0.1.9/lib/mini_racer.rb:64:in `synchronize'
/opt/bitnami/apps/discourse/htdocs/vendor/bundle/ruby/2.3.0/gems/mini_racer-0.1.9/lib/mini_racer.rb:64:in `with_lock'
/opt/bitnami/apps/discourse/htdocs/vendor/bundle/ruby/2.3.0/gems/mini_racer-0.1.9/lib/mini_racer.rb:165:in `eval'

I know this is valid syntax as babel and ember-cli handle this just fine. The ES2015 specs (§12.2.6) even discuss it.

I have also tried this syntax:

{
  [dynamicMethodName]: function() {}
}

And it too has the same error.

1 Like

Well we appear not to be traspiling it, miniracer gets transpiled js from Babel

1 Like