machty / ember-concurrency-decorators

Task decorators for ember-concurrency 1.x (merged into ember-concurrency 2.0)
MIT License
70 stars 25 forks source link

"Unexpected token" build error with legacy / stage 1 decorators (no `@e-d/babel-transforms`) #48

Closed niranjan94 closed 5 years ago

niranjan94 commented 5 years ago

Code snippet in question:

export default class AppSearchComponent extends Component {

  @restartableTask
  *searchContent(keyword) {
    if (isEmpty(keyword)) {
      return [];
    }
    yield timeout(250);
    return yield this.store.query('content', { keyword });
  }

}

Error on build:

Build Error (broccoli-persistent-filter:Babel > [Babel: sandbox]) in sandbox/components/navigation/app-search.js

/Users/xyz/sandbox/app/components/navigation/app-search.js: Unexpected token (17:26)

  15 | 
  16 |   @restartableTask
> 17 |   *searchContent(keyword) {
     |                           ^
  18 |     if (isEmpty(keyword)) {
  19 |       return [];
  20 |     }

Dependencies include:

{
    "ember-concurrency": "^0.10.0",
    "ember-concurrency-decorators": "^1.0.0-beta.2",

    "ember-decorators": "^6.0.0",
    "ember-decorators-polyfill": "^1.0.4",

    "ember-cli-babel": "^7.7.3",
    "ember-cli": "~3.9.0",
    "ember-source": "~3.9.0"
}

And not using @ember-decorators/babel-transforms

buschtoens commented 5 years ago

This is caused by https://github.com/babel/babel/issues/9852.

You can either:

niranjan94 commented 5 years ago

@buschtoens thanks for the update 😄 Will wait for https://github.com/babel/babel/pull/9912 to be merged. Using the assignment syntax in the meantime.

buschtoens commented 5 years ago

I just merged #54 and released it as v1.0.0-beta.3. If you manually apply the patch to @babel/parser as described in What happened to the fancy generator method syntax? or wait for it to be released officially, you can use the generator method syntax again.

gabrielgrant commented 5 years ago

@buschtoens looks like the latest Babel release (7 days ago) is v7.5.5, which presumably includes https://github.com/babel/babel/pull/9912 (merged 24 days ago). Does that mean this patch work-around is no longer needed in order to use the "fancy generator method syntax" and the note can be removed/examples updated?

FWIW, looks like ember-cli v3.11 still only requires ^7.4.3, while current HEAD requires ^7.5.5, which I think means this can be relied on once 3.12(-beta?) ships?

buschtoens commented 5 years ago

@gabrielgrant Yes. The fix was already released in v7.5.0. So, if you're on at least that version, everything should be groovy.

Also, the version of @babel/core in ember-cli itself doesn't actually matter. It's the version in ember-cli-babel, which is a dependency in your project's package.json.

If you are using yarn, you can force an upgrade of this @babel/core dependency by setting a resolution. If you're using npm or don't want to use a resolution, a clean re-installation of the dependencies (delete node_modules and any package manager lock files) should also do the trick.