Skip to content

Angular 5.1.0 with typescript 2.5.x does not emit extra decorators with ngc #20864

Closed
angular/tsickle
#675

Description

@mlakmal

I'm submitting a...


[ x] Bug report  

Current behavior

ngc command does not emit extra decorators with Angular 5.1.0 and typescript 2.5.3

Expected behavior

it should emit decorators as it did with Angular 5.0.x and typescript 2.4.2

Minimal reproduction of the problem with instructions

create a custom typescript decorator and add this to a Angular component and try compiling using ngc. it won't emit the custom decorator with the output.
ex:

@EntryComponent({})
@Component({
  selector: 'test',
  template: ''
})
export class LoginComponent{
}

What is the motivation / use case for changing the behavior?

we have number of libraries internally using and build through angular ngc command for umd support (similar to angular package build commands). we are not able to update to Angular 5.1.0 with above bundle process does not emit decorators anymore.

Environment


Angular version: 5.1.0
Typescript: 2.5.x

Activity

  1. mlc-mlapis commented on Dec 7, 2017

    @mlc-mlapis
    Contributor

    @mlakmal ... do you mean AppComponent.decorators = [...] or AppModule.decorators = [...] in compiled JS files?

  2. mlakmal commented on Dec 7, 2017

    @mlakmal
    Author

    below is v5.0.5 output which includes custom decorator (EntryComponent). this is getting stripped with 5.1.0

        LoginComponent = LoginComponent_1 = __decorate([
    
            core$1.EntryComponent({
                type: LoginComponent_1,
                name: 'LoginComponent'
            }),
    
            __metadata("design:paramtypes", [utility.Logger,
                core$1.ContentHelper,
                main.AppSession,
                platformBrowser.DomSanitizer,
                cnsShared.WebAccountApi,
                cnsShared.DTMUtil,
                shared.PhoneNumberPipe,
                cnsTwoFactor.AuthenticateModel,
                core$1.ElementHelper,
                cnsShared.CustomCookieHelper,
                core$1.PageHasChangeListner, Object, core.ElementRef,
                main.AppConfig,
                AuthenticationErrorHandler, Object, cnsTwoFactor.SecureAuthUtil,
                cnsTwoFactor.TwoFactorModel])
        ], LoginComponent);
        return LoginComponent;
    
  3. mlc-mlapis commented on Dec 7, 2017

    @mlc-mlapis
    Contributor

    @mlakmal ... hmm, I have it with Angular 5.1.0 and TS 2.5.3 & AOT ... here for @Timeout(2000):

    var AppComponent = (function () {
        ...
        AppComponent.ctorParameters = function () { return [
            { type: app_config_1.AppConfig, },
            { type: router_1.Router, },
        ]; };
        __decorate([
            timeout_decorator_1.Timeout(2000),
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AppComponent.prototype, "runDecoratedFunction", null);
        return AppComponent;
    }());
    
  4. mlc-mlapis commented on Dec 7, 2017

    @mlc-mlapis
    Contributor

    @mlakmal ... are you sure that you compile with TS 2.5.3 and not with TS 2.6?

  5. mlakmal commented on Dec 7, 2017

    @mlakmal
    Author

    @mlc-mlapis are you using angular cli ? i am directly using ngc command to create umd bundle

    yes i am using 2.5.x typescript

  6. mlc-mlapis commented on Dec 7, 2017

    @mlc-mlapis
    Contributor

    @mlakmal ... yes, directly ngc to create bundles also ...

  7. mlakmal commented on Dec 7, 2017

    @mlakmal
    Author

    @mlc-mlapis can you share your tsconfig if possible ? i am using below which is simillar to angular project build configs.

    main config

    {
      "compilerOptions": {
        "declaration": true,
        "stripInternal": true,
        "noImplicitAny": false,
        "strictNullChecks": false,
        "noFallthroughCasesInSwitch": false,
        "moduleResolution": "node",
        "module": "es2015",
        "target": "es2015",
        "lib": [
          "es2015",
          "dom"
        ],
        "skipLibCheck": true,
        // don't auto-discover @types/node, it results in a ///<reference in the .d.ts output
    
        "types": [
          "jquery",
          "node",
          "custom",
          "jasmine"
        ],
        "experimentalDecorators": true,
        // This is needed due to https://github.com/Microsoft/TypeScript/issues/17516.
        // As tsickle will lower decorators before TS, this is not a problem for our build.
        "emitDecoratorMetadata": true,
        "sourceMap": true,
        "inlineSources": true
      },
      "exclude": [
        "node_modules",
        "typings",
        "log",
        "dist",
        "distPkg",
        "app/internal_packages",
        "app/uxd",
        "app/assets",
        "tools",
        ".tmp"
      ]
    }
    

    package config

    {
      "extends": "../../../../tsconfig-rollup.json",
      "compilerOptions": {
        "rootDir": ".",
        "baseUrl": ".",
        "paths": {
          "xyz/cns-main": [
            "../../../../distNpm/cns-main/cns-main"
          ],
          "xyz/cns-shared": [
            "../../../../distNpm/cns-shared/cns-shared"
          ],
          "xyz/cns-two-factor": [
            "../../../../distNpm/cns-two-factor/cns-two-factor"
          ],
          "xyz/cns-change-password": [
            "../../../../distNpm/cns-change-password/cns-change-password"
          ]
        },
        "outDir": "../../../../distNpm/cns-login"
      },
      "angularCompilerOptions": {
        "annotateForClosureCompiler": true,
        "strictMetadataEmit": false,
        "skipTemplateCodegen": true,
        "flatModuleOutFile": "cns-login.js",
        "flatModuleId": "xyz/cns-login"
      },
      "files": [
        "./public_api.ts"
      ]
    }
    
  8. mlc-mlapis commented on Dec 7, 2017

    @mlc-mlapis
    Contributor

    @mlakmal ... and my is:

    {
    	"compilerOptions": {
    		"target": "es5",
    		"module": "commonjs",
    		"declaration": true,
    		"moduleResolution": "node",
    		"sourceMap": false,
    		"allowUnreachableCode": false,
    		"outDir": ".",
    		"allowSyntheticDefaultImports": true,
    		"emitDecoratorMetadata": true,
    		"experimentalDecorators": true,
    		"stripInternal": true,
    		"pretty": true,
    		"removeComments": true,
    		"strictNullChecks": false,
    		"noImplicitAny": false,
    		"noUnusedParameters": false,
    		"noUnusedLocals": false,
    		"skipLibCheck": true,
    		"lib": ["es5", "es2015", "dom"],
    		"typeRoots": ["./node_modules/@types"]
    	},
    	"angularCompilerOptions": {
    		"skipTemplateCodegen": false,
    		"annotationsAs": "static fields",
    		"skipMetadataEmit": false,
    		"strictMetadataEmit": true,
    		"strictInjectionParameters": true
    	},
    	"include": [
    		"./aot/app/**/*.ts"
    	],
    	"exclude": [
    		"node_modules",
    		"app",
    		"./aot/**/*.spec.ts",
    		"./app/**/*.spec.ts"
    	]
    }
    
  9. mlakmal commented on Dec 7, 2017

    @mlakmal
    Author

    @mlc-mlapis looks like you are bundling individual files instead of umd bundle for esm5/esm2015 ?

    when i tried your config i would not be able to setup esm5/esm2015 bundle etc ...

  10. mlakmal commented on Dec 7, 2017

    @mlakmal
    Author

    while debugging this issue, i am seeing that having both @Component and @EntryComponent decorators doesn't emit the EntryComponent decorator while compiling. if i remove 1 other gets compiled. looks like new compiler doesn't compile multiple decorators

  11. changed the title [-]Angular 5.1.0 with typescript 2.5.x does not emit decorators with ngc[/-] [+]Angular 5.1.0 with typescript 2.5.x does not emit extra decorators with ngc[/+] on Dec 7, 2017
  12. mlc-mlapis commented on Dec 7, 2017

    @mlc-mlapis
    Contributor

    @mlakmal ... yes, bundling individual files but for compiling it doesn't matter. In my test case I have @Component & custom @Timeout decorators together and as you can see above they are not removed.

  13. kemsky commented on Dec 7, 2017

    @kemsky

    Probably i have the same issue, i have custom decorator and @Injectable(), will check ngc output.

  14. mlc-mlapis commented on Dec 7, 2017

    @mlc-mlapis
    Contributor

    @mlakmal ... I tried to change to:

    {
    	"compilerOptions": {
    		"target": "es2015",
    		"module": "es2015",
    		...
    	},
    	...
    }
    

    and decorators are still here when ngc compiles the sources:

    export class AppComponent {
        constructor(...) {
            ...
        }
        runDecoratedFunction() {
            console.log('... printing from a decorated function delayed by 2000 ms');
        }
    }
    AppComponent.decorators = [
        { type: Component, args: [{
                    selector: 'app',
                    template: `...`,
                    ...
        }]}
    ];
    AppComponent.ctorParameters = () => [...];
    __decorate([
        Timeout(2000),
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], AppComponent.prototype, "runDecoratedFunction", null);
    
  15. kemsky commented on Dec 7, 2017

    @kemsky

    Single custom Api decorator:

        AccessTokenService = tslib_1.__decorate([
            Api(),
            tslib_1.__metadata("design:paramtypes", [])
        ], AccessTokenService);

    Two decorators, Api and Injectable:

        AccessTokenService.decorators = [
            { type: Injectable },
        ];

    TypeScript 2.5.3, Angular 5.1.0, "module": "es2015"

  16. 15 remaining items

  17. assigned and unassigned on Dec 12, 2017
  18. alxhub commented on Dec 12, 2017

    @alxhub
    Member

    Reproduced in an ngc test: alxhub@b4835e3

  19. chuckjaz commented on Dec 15, 2017

    @chuckjaz
    Contributor

    This appears to be a bug in Tsickle's decorator down-leveling which I reported here angular/tsickle#674.

    I will submit a PR to fix this in the Tsickle repository.

    I will leave this bug open to track when Angular is update to use the corrected version of Tsickle

  20. chuckjaz commented on Dec 15, 2017

    @chuckjaz
    Contributor

    Reopening. This was automatically closed when the Tsickle change committed.

  21. assigned and unassigned on Dec 15, 2017
  22. chuckjaz commented on Dec 22, 2017

    @chuckjaz
    Contributor

    This is fixed by [email protected]

  23. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  24. locked and limited conversation to collaborators on Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: corefreq2: mediumregressiontype: bug/fix

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions