Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle decorators #5

Merged
merged 1 commit into from
Aug 23, 2018
Merged

Handle decorators #5

merged 1 commit into from
Aug 23, 2018

Conversation

ssutar
Copy link
Contributor

@ssutar ssutar commented Aug 2, 2018

This PR handles different decorators mentioned in #1

@ssutar ssutar force-pushed the decorators branch 3 times, most recently from 538a99d to 5873ae1 Compare August 8, 2018 00:21
Copy link
Collaborator

@pzuraq pzuraq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking good, some minor comments but I think the structure is looking good. Generally bucketing things into parse and transform helpers seems to be a solid pattern, and config of whether to use decorators or not is 👍

@@ -10,7 +10,7 @@
"codemod-cli"
],
"dependencies": {
"codemod-cli": "^0.1.0"
"codemod-cli": "ssutar/codemod-cli"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an upstream PR here? Ideally we should get that merged and published before we merge this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is PR rwjblue/codemod-cli#41 Not sure if it will be merged. I'll sync up with @rwjblue and merge it

});

// Do not transform as extends Mixin
const Foo = EmberObject.extend(MyMixin, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be transformed to the following:

class Foo extends EmberObject.extend(MyMixin) {
  biz = 'div';
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of adding mixin support in different PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you added mixin support, so this test case can be removed/updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixin support is added with config option --mixins=true with codemod command line. Please see the mixins.options.json. So we need to keep the mixin test case

});

// Do not transform
const Foo = EmberObject.extend({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should transform to:

@layout('div')
class Foo extends EmberObject {}

@controller("abc")
myController;

@observes("xyz")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to come back to observers/event listeners. The trickiness is in subclasses, we must apply the opposite if the field is overriden:

const Foo = EmberObject.extend({
  fooObserver: observer('foo', function() {})
});

const Bar = Foo.extend({
  fooObserver: null, // unsets the observer
});
class Foo extends EmberObject {
  @observes('foo') fooObserver() {}
}

class Bar extends Foo {
  @unobserves('foo') fooObserver = null;
}

This will mean we have to add a second pass to the codemod, since we can't know what the subclass/superclass is until we've completed the first pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detail, I'll create a new issue so that we can track this separately

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added #7

Copy link
Collaborator

@pzuraq pzuraq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one minor comment about a test case but I think once that's resolved this is good to merge 👍

});

// Do not transform as extends Mixin
const Foo = EmberObject.extend(MyMixin, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you added mixin support, so this test case can be removed/updated?

/**
* Lname
*/
@alias.readOnly("firstName", "lastName")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may need to change to alias('firstName', 'lastName').readOnly(), but since ember-decorators doesn't have this API yet we merge this for now and update it later on once that API is finalized

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixin support is added with config option --mixins=true with codemod command line. Please see the mixins.options.json. So we need to keep the mixin test case

@pzuraq pzuraq merged commit 88e0f1b into ember-codemods:master Aug 23, 2018
@pzuraq
Copy link
Collaborator

pzuraq commented Aug 23, 2018

Sounds good, thanks again @ssutar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants