kimroen / ember-cli-coffeescript

Adds precompilation of CoffeeScript files and all the basic generation types to the ember generate command.
MIT License
72 stars 49 forks source link

Generated code no longer pass the tests #135

Closed mriska closed 7 years ago

mriska commented 7 years ago

Steps to reproduce:

ember new foo
cd foo
ember install ember-cli-coffeescript
ember g helper bar
ember test

produces the following error:

not ok 9 PhantomJS 2.1 - TestLoader Failures: foo/tests/unit/helpers/bar-test: could not be loaded
    ---
        actual: >
            null
        stack: >
            http://localhost:7357/assets/foo.js:46:22
            exports@http://localhost:7357/assets/vendor.js:140:37
            _reify@http://localhost:7357/assets/vendor.js:173:66
            reify@http://localhost:7357/assets/vendor.js:159:33
            exports@http://localhost:7357/assets/vendor.js:138:15
            requireModule@http://localhost:7357/assets/vendor.js:32:25
            require@http://localhost:7357/assets/test-support.js:4713:14
            loadModules@http://localhost:7357/assets/test-support.js:4705:21
            load@http://localhost:7357/assets/test-support.js:4735:33
            http://localhost:7357/assets/test-support.js:4619:22
        message: >
            Died on test #1 moduleLoadFailure@http://localhost:7357/assets/test-support.js:4607:17
            require@http://localhost:7357/assets/test-support.js:4715:29
            loadModules@http://localhost:7357/assets/test-support.js:4705:21
            load@http://localhost:7357/assets/test-support.js:4735:33
            http://localhost:7357/assets/test-support.js:4619:22: Strict mode forbids implicit creation of global property 'bar'
        Log: |
    ...
not ok 10 PhantomJS 2.1 - Global error: Error:
ReferenceError: Strict mode forbids implicit creation of global property 'bar' at http://localhost:7357/assets/test-support.js, line 4614
    ---
        Log: |
            { type: 'error',
              text: 'Error: \nReferenceError: Strict mode forbids implicit creation of global property \'bar\' at http://localhost:7357/assets/test-support.js, line 4614\n' }
    ...
not ok 11 PhantomJS 2.1 - TestLoader Failures: global failure
    ---
        actual: >
            null
        stack: >
            http://localhost:7357/assets/test-support.js:4614
        message: >
            Error:
            ReferenceError: Strict mode forbids implicit creation of global property 'bar'
        Log: |
    ...

This is due to the way the compiled file looks:

define('foo/helpers/bar', ['exports', 'ember'], function (exports, _ember) {
  var BarHelper;

  exports.bar = bar = function (params) {
    return params;
  };

  BarHelper = _ember['default'].Helper.helper(bar);

  exports.bar = bar;
  exports['default'] = BarHelper;
});

The variable bar does not get defined properly. This issue is related to #134. Directly exporting the functions produces code that passes the tests.

This problem affects at least helper, initializer, util, serializer

@kimroen Do you want me to create a PR for the changes?

kimroen commented 7 years ago

@mriska If you have time to go through and update all the blueprints as mentioned in #134 then I would love a PR for that. If not, then I'll make sure to check that this works after making those changes.

Thanks!

mriska commented 7 years ago

I'll see if I can find some time for it tomorrow.