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

Annotation does not occur when I stop using decorators with BabelJS (indirect cause) #248

Closed
nweldev opened this issue Aug 8, 2016 · 2 comments

Comments

@nweldev
Copy link

nweldev commented Aug 8, 2016

When using the `/* @ngInject */ comment on an ES6 class' constructor, the annotation does not occur if I stop using decorators (indirect cause, of course).

The issue

input

var AppComponent =

/* @ngInject */
exports.AppComponent = function AppComponent($log, $mdSidenav) {
    _classCallCheck(this, AppComponent);

    $log.debug('App Component');
    this.toggleLeftMenu = MaterialUtil.buildToggler($mdSidenav, $log, 'main-left');
};

AppComponent.$$name = 'fooSeed';

AppComponent.$$config = {
    selector: 'foo-seed',
    templateUrl: _appComponent2.default.name,
    controller: AppComponent
};

expected output

var AppComponent =

/* @ngInject */
exports.AppComponent = ['$log', '$mdSidenav', function AppComponent($log, $mdSidenav) {
    _classCallCheck(this, AppComponent);

    $log.debug('App Component');
    this.toggleLeftMenu = MaterialUtil.buildToggler($mdSidenav, $log, 'main-left');
}; ]

AppComponent.$$name = 'fooSeed';

AppComponent.$$config = {
    selector: 'foo-seed',
    templateUrl: _appComponent2.default.name,
    controller: AppComponent
};

OR (better) :

var AppComponent =

/* @ngInject */
function AppComponent($log, $mdSidenav) {
    _classCallCheck(this, AppComponent);

    $log.debug('App Component');
    this.toggleLeftMenu = MaterialUtil.buildToggler($mdSidenav, $log, 'main-left');
};

AppComponent.$inject =  ['$log', '$mdSidenav'];

exports.AppComponent = AppComponent;

AppComponent.$$name = 'fooSeed';

AppComponent.$$config = {
    selector: 'foo-seed',
    templateUrl: _appComponent2.default.name,
    controller: AppComponent
};

actual output : no modification

var AppComponent =

/* @ngInject */
exports.AppComponent = function AppComponent($log, $mdSidenav) {
    _classCallCheck(this, AppComponent);

    $log.debug('App Component');
    this.toggleLeftMenu = MaterialUtil.buildToggler($mdSidenav, $log, 'main-left');
};

AppComponent.$$name = 'fooSeed';

AppComponent.$$config = {
    selector: 'foo-seed',
    templateUrl: _appComponent2.default.name,
    controller: AppComponent
};

FYI : ES6 Input

export class AppComponent {

    /* @ngInject */
    constructor($log, $mdSidenav) {
        $log.debug('App Component');
        this.toggleLeftMenu = MaterialUtil.buildToggler($mdSidenav, $log, 'main-left');
    }

}

AppComponent.$$name = 'fooSeed';

AppComponent.$$config = {
    selector: 'foo-seed',
    templateUrl: template.name,
    controller: AppComponent
};

The part which was working before

input

var AppComponent = exports.AppComponent = (_dec = (0, _router.Routes)([{ name: 'admin', path: '/admin', lazy: true, component: 'app/admin/admin.component' }, { name: 'dashboards', path: '/dashboards', component: _dashboards.DashboardComponent }, { name: 'forms', path: '/forms', lazy: true, component: 'app/demo-forms/demo-forms.component' }, { path: '/', component: _home.HomeComponent, useAsDefault: true }]), _dec2 = (0, _ng.Module)({
    name: 'fooSeed',
    dependencies: ['ui.router', 'oc.lazyLoad', 'ct.ui.router.extras', 'ngMaterial', 'restangular', _dashboards.DashboardComponent.$ngmodule.name],
    main: true,
    html5mode: {
        enabled: config.html5,
        requireBase: false
    },
    debug: true,
    configs: [Config.mdTheming]
}), _dec3 = (0, _core.Component)({
    selector: 'foo-seed',
    templateUrl: _appComponent2.default.name,
    directives: [_home.HomeComponent]
}), _dec(_class = _dec2(_class = _dec3(_class =

/* @ngInject */
function AppComponent($log, $mdSidenav) {
    _classCallCheck(this, AppComponent);

    $log.debug('App Component');
    this.toggleLeftMenu = MaterialUtil.buildToggler($mdSidenav, $log, 'main-left');
}) || _class) || _class) || _class);

Output

var AppComponent = exports.AppComponent = (_dec = (0, _router.Routes)([{ name: 'admin', path: '/admin', lazy: true, component: 'app/admin/admin.component' }, { name: 'dashboards', path: '/dashboards', component: _dashboards.DashboardComponent }, { name: 'forms', path: '/forms', lazy: true, component: 'app/demo-forms/demo-forms.component' }, { path: '/', component: _home.HomeComponent, useAsDefault: true }]), _dec2 = (0, _ng.Module)({
    name: 'fooSeed',
    dependencies: ['ui.router', 'oc.lazyLoad', 'ct.ui.router.extras', 'ngMaterial', 'restangular', _dashboards.DashboardComponent.$ngmodule.name],
    main: true,
    html5mode: {
        enabled: config.html5,
        requireBase: false
    },
    debug: true,
    configs: [Config.mdTheming]
}), _dec3 = (0, _core.Component)({
    selector: 'foo-seed',
    templateUrl: _appComponent2.default.name,
    directives: [_home.HomeComponent]
}), _dec(_class = _dec2(_class = _dec3(_class =

/* @ngInject */
["$log", "$mdSidenav", function AppComponent($log, $mdSidenav) {
    _classCallCheck(this, AppComponent);

    $log.debug('App Component');
    this.toggleLeftMenu = MaterialUtil.buildToggler($mdSidenav, $log, 'main-left');
}]) || _class) || _class) || _class);

FYI : ES6 Input

@Routes([
    { name: 'admin', path: '/admin', lazy: true, component: 'app/admin/admin.component' },
    { name: 'dashboards', path: '/dashboards', component: DashboardComponent },
    { name: 'forms', path: '/forms', lazy: true, component: 'app/demo-forms/demo-forms.component' },
    { path: '/', component: HomeComponent, useAsDefault: true }
])
@Module({
    name: 'fooSeed',
    dependencies: [
        'ui.router',
        'oc.lazyLoad',
        'ct.ui.router.extras',
        'ngMaterial',
        'restangular',
        DashboardComponent.$ngmodule.name
    ],
    main: true,
    html5mode: {
        enabled: config.html5,
        requireBase: false
    },
    debug: true,
    configs: [
        Config.mdTheming
    ]
})
@Component({
    selector: 'foo-seed',
    templateUrl: template.name,
    directives: [
        HomeComponent
    ]
})
export class AppComponent {

    /* @ngInject */
    constructor($log, $mdSidenav) {
        $log.debug('App Component');
        this.toggleLeftMenu = MaterialUtil.buildToggler($mdSidenav, $log, 'main-left');
    }

}
nweldev added a commit to Sedona-Solutions/sdn-angularjs-seed that referenced this issue Aug 9, 2016
Alternative version without any dependency to the
angular-transition-sugar library.

This is the first alternative created.

The current solution (using git branches) should NOT be the final
solution for alternatives management. See #30.

There is still an issue about ng-annotate. So, the current version doesn't
support any uglification, and is therefore not ready for production (or need to use .$inject any time) ! See olov/ng-annotate#248.
@olov
Copy link
Owner

olov commented Oct 1, 2016

#245

@olov olov closed this as completed Oct 1, 2016
@nweldev
Copy link
Author

nweldev commented Oct 10, 2016

Thank you, I didn't saw that you choosed to end /* @ngInject */ at the same time. Everything is fine with "ngInject".

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

No branches or pull requests

2 participants