Skip to content

ngcc not running on all files (ESM5) #27841

Closed

Description

@alan-agius4

🐞 bug report

Affected Package

All packages are effected by the output of ngcc

Description

After running ngcc via node_modules/.bin/ivy-ngcc certain Angular decorators are being retained, this is break production builds with Build Optimzer angular/angular-cli#13261.

🔬 Minimal Reproduction

  • Run ngcc against a node_modules/@angular directory
  • Open node_modules/@angular/platform-browser/esm5/src/browser.js
var BrowserModule_1;
BrowserModule = BrowserModule_1 = tslib_1.__decorate([
	NgModule({ providers: BROWSER_MODULE_PROVIDERS, exports: [CommonModule, ApplicationModule] }),
	tslib_1.__param(0, Optional()), tslib_1.__param(0, SkipSelf()), tslib_1.__param(0, Inject(BrowserModule_1)),
	tslib_1.__metadata("design:paramtypes", [Object])
], BrowserModule);
return BrowserModule;

🌍 Your Environment

Angular Version:

Node: 10.10.0
OS: win32 x64
Angular: 7.2.0-rc.0

Anything else relevant?
According to @IgorMinar, there should not be any Angular specific decorators after running ngcc.

Activity

  1. petebacondarwin commented on Dec 27, 2018

    @petebacondarwin
    Contributor

    Quick update: an initial investigation seems to indicate that the ESM5 browser.js is not being processed at all. Or at least the NgModule aspect of this file is not being processed, which is why the decorator is not being removed.

    Other files containing NgModule decorators are being processed.

  2. alan-agius4 commented on Dec 27, 2018

    @alan-agius4
    ContributorAuthor

    There seems to be other files which are not being processed, for example

    node_modules/@angular/common/esm5/src/pipes/date_pipe.js

    var DatePipe_1;
    DatePipe = DatePipe_1 = tslib_1.__decorate([
    	Pipe({ name: 'date', pure: true }),
    	tslib_1.__param(0, Inject(LOCALE_ID)),
    	tslib_1.__metadata("design:paramtypes", [String])
    ], DatePipe);
    return DatePipe;
  3. JoostK commented on Dec 27, 2018

    @JoostK
    Member

    @alan-agius4 Can you cherry-pick f13fb367e03983fd2e11f7cf344162b1c78c5962 from #26947 and see if that resolves the issue? We are aware of inconsistent behavior in the ESM5 reflection host which should have been accounted for in that commit, possibly resolving this issue (?)

  4. alan-agius4 commented on Dec 27, 2018

    @alan-agius4
    ContributorAuthor

    @JoostK, thanks for your tip, though that commit doesn't have any effect on this issue.

    As @petebacondarwin mentioned it looks that certain files are not being processed at all.

    image

    Note: that there are no .bak files for certain files.

  5. changed the title [-]ngcc retains angular specific decorators[/-] [+]ngcc not running on all files (ESM5)[/+] on Dec 27, 2018
  6. JoostK commented on Dec 27, 2018

    @JoostK
    Member

    @alan-agius4 ah, pity. It is related to that though, as the source that fails to be recognized is as follows:

    var DatePipe_1;
        DatePipe = DatePipe_1 = tslib_1.__decorate([

    The intermediate assignment apparently fails to be recognized in ngcc's relfection host for ESM5, causing the decorators not to be linked with the class declaration.

  7. petebacondarwin commented on Dec 27, 2018

    @petebacondarwin
    Contributor

    I believe the error is in this method:

      protected getHelperCall(statement: ts.Statement, helperName: string): ts.CallExpression|null {
        if (ts.isExpressionStatement(statement)) {
          const expression =
              isAssignmentStatement(statement) ? statement.expression.right : statement.expression;
          if (ts.isCallExpression(expression) && getCalleeName(expression) === helperName) {
            return expression;
          }
        }
        return null;
      }
    

    Not that if the statement is an assignment then we take the right hand of the assignment. This works in the case of

    DatePipe = tslib_1.__decorate([...]);
    

    giving us the call to __decorate() but it does not work when there is a chain of assignnments:

    DatePipe = DatePipe_1 = tslib_1.__decorate([
    
  8. added this to the needsTriage milestone on Dec 28, 2018
  9. added a commit that references this issue on Jan 11, 2019
    d09190a
  10. angular-automatic-lock-bot commented on Sep 14, 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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions