Skip to content

fix(ivy): ngcc - properly handle aliased class expressions#29119

Closed
JoostK wants to merge 9 commits intoangular:masterfrom
JoostK:ngcc-module-with-providers
Closed

fix(ivy): ngcc - properly handle aliased class expressions#29119
JoostK wants to merge 9 commits intoangular:masterfrom
JoostK:ngcc-module-with-providers

Conversation

@JoostK
Copy link
Member

@JoostK JoostK commented Mar 5, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #29078

What is the new behavior?

Proper handling of class expressions within ngcc.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

WIP!

@JoostK JoostK changed the title fix(ivy): ngcc - properly handle aliases class expressions fix(ivy): ngcc - properly handle aliased class expressions Mar 5, 2019
@kara kara added the comp: ivy label Mar 6, 2019
@ngbot ngbot bot added this to the needsTriage milestone Mar 6, 2019
@JoostK JoostK force-pushed the ngcc-module-with-providers branch 4 times, most recently from c1d6dd3 to f5500e3 Compare March 10, 2019 11:48
@gkalpak gkalpak marked this pull request as ready for review March 10, 2019 12:13
@gkalpak gkalpak requested a review from a team March 10, 2019 12:13
@JoostK JoostK force-pushed the ngcc-module-with-providers branch 2 times, most recently from c9a86e7 to 048f8de Compare March 23, 2019 17:51
@JoostK JoostK requested a review from a team March 23, 2019 17:51
@JoostK JoostK force-pushed the ngcc-module-with-providers branch from 048f8de to 058c618 Compare March 23, 2019 18:32
@JoostK JoostK requested a review from a team March 23, 2019 21:10
@JoostK JoostK force-pushed the ngcc-module-with-providers branch 4 times, most recently from 60ed31e to bf90f0d Compare March 24, 2019 20:05
@petebacondarwin petebacondarwin force-pushed the ngcc-module-with-providers branch from 987afdf to 05570ec Compare April 2, 2019 07:26
@jasonaden jasonaden closed this in 5a1d21e Apr 2, 2019
jasonaden pushed a commit that referenced this pull request Apr 2, 2019
In ES2015, classes could have been emitted as a variable declaration
initialized with a class expression. In certain situations, an intermediary
variable suffixed with `_1` is present such that the variable
declaration's initializer becomes a binary expression with its rhs being
the class expression, and its lhs being the identifier of the intermediate
variable. This structure was not recognized, resulting in such classes not
being considered as a class in `Esm2015ReflectionHost`.

As a consequence, the analysis of functions/methods that return a
`ModuleWithProviders` object did not take the methods of such classes into
account.

Another edge-case with such intermediate variable was that static
properties would not be considered as class members. A testcase was added
to prevent regressions.

Fixes #29078

PR Close #29119
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
In a770aa2 ngcc was moved up one folder, however the angular-robot config
was not updated to reflect this change.

PR Close angular#29119
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…9119)

In ES2015, classes could have been emitted as a variable declaration
initialized with a class expression. In certain situations, an intermediary
variable suffixed with `_1` is present such that the variable
declaration's initializer becomes a binary expression with its rhs being
the class expression, and its lhs being the identifier of the intermediate
variable. This structure was not recognized, resulting in such classes not
being considered as a class in `Esm2015ReflectionHost`.

As a consequence, the analysis of functions/methods that return a
`ModuleWithProviders` object did not take the methods of such classes into
account.

Another edge-case with such intermediate variable was that static
properties would not be considered as class members. A testcase was added
to prevent regressions.

Fixes angular#29078

PR Close angular#29119
@cyrilletuzi
Copy link
Contributor

@JoostK Hi, I'm still having this issue with a lib build with latest next versions:

  • Angular 8.0.0-rc.5
  • CLI 8.0.0-rc.4
  • ng-packagr 5.2.0

Is that normal?

@petebacondarwin
Copy link
Contributor

@cyrilletuzi you need to try the master builds; we have not been backporting ngcc changes to 8.0.0.
Try using https://github.com/angular/compiler-cli-builds as the yarn/npm target.

@cyrilletuzi
Copy link
Contributor

@petebacondarwin Thanks for your quick answer.

I'm not sure to understand: does it mean a library build with v8.0 won't be able to be compatible with Ivy?

@petebacondarwin
Copy link
Contributor

Can you confirm what you are trying to do and what errors you are getting?
If you want to compile with ivy you need to use the master versions when compiling.
If you are generating a library for consumption by a project compiling with ivy then it ought to be fine to compile and publish it compiled as normal (not ivy) via v8.0.0.

@cyrilletuzi
Copy link
Contributor

@petebacondarwin

Steps to reproduce:

  • git clone https://github.com/cyrilletuzi/angular-async-local-storage
  • cd angular-async-local-storage
  • git checkout v8beta
  • npm ci
  • npm run build (build the lib in normal mode)
  • in projects/ivy/src/app/app.module.ts, add:
import { StorageModule } from '@ngx-pwa/local-storage';

@NgModule({
  imports: [
    BrowserModule,
    StorageModule.forRoot({
      IDBNoWrap: true,
    })
  ]
})
export class AppModule { }
  • ./node_modules/.bin/ng serve ivy

Same error as in #29078:

ERROR in projects/ivy/src/app/app.module.ts(9,12): error TS-991010: Value at position 1 in the NgModule.importss of AppModule is not a reference: [object Object]

Works if I remove StorageModule.

@JoostK
Copy link
Member Author

JoostK commented May 27, 2019

@cyrilletuzi I am confused. I can't find StorageModule within @ngx-pwa/local-storage here: https://unpkg.com/@ngx-pwa/local-storage@8.0.0-beta.12/fesm5/ngx-pwa-local-storage.js

@cyrilletuzi
Copy link
Contributor

cyrilletuzi commented May 27, 2019

@JoostK beta.12 didn't contain the last code, the local npm run build do.

I've just published beta.13 if you need it.

@petebacondarwin
Copy link
Contributor

It looks like you are trying to build an example app using ivy inside your library project? Is that right?
If so then you need to use a next version of Angular to do the build in that projects/ivy/src folder. I.E. you need to specify the correct version of @angular/compiler-cli and friends in https://github.com/cyrilletuzi/angular-async-local-storage/blob/master/projects/ngx-pwa/local-storage/package.json

@cyrilletuzi
Copy link
Contributor

@petebacondarwin master branch is indeed in v7, but as mentionned in the repro steps, you need to switch to v8beta branch, where the last Angular v8 next version is used.

@JoostK
Copy link
Member Author

JoostK commented May 27, 2019

It appears that the CLI's integration of ngcc is unable to resolve dist/@ngx-pwa/local-storage/package.json. It currently relies on require.resolve and some quick debugging session leaves me to believe that it only searches in node_modules folders, so the dist directory spoils the fun.

Here's how the package.json is resolved in @ngtools/webpack's integration of ngcc:

https://github.com/angular/angular-cli/blob/5df02a3de5257162c7b8a5e2c65d388debcd51f0/packages/ngtools/webpack/src/ngcc_processor.ts#L88-L105

@alan-agius4 do you see possibilities to alleviate this problem?

@petebacondarwin
Copy link
Contributor

@cyrilletuzi - sorry I didn't spot that the git checkout v8beta was actually checking out a verison that builds with Angular master.

@alan-agius4 could jump in regarding the CLI integration. We do support, I believe dist folders but they need to be setup via the paths property in tsconfig.json, right?

@JoostK
Copy link
Member Author

JoostK commented May 27, 2019

@cyrilletuzi Running ngcc manually on dist using node_modules/.bin/ivy-ngcc -s ./dist lets me compile and serve the app successfully

@cyrilletuzi
Copy link
Contributor

@JoostK I confirm your debug: it works well in an external app, it's just a problem inside a local app.

When doing ng serve in an external app (another project with the lib installed via npm), the first time, I see the compiler doing this:

Compiling @angular/core : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
Compiling @ngx-pwa/local-storage : es2015 as esm2015

But when doing ng serve in a local app (inside dist), I just see this (the lib is not compiled):

Compiling @angular/core : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015

@cyrilletuzi
Copy link
Contributor

@JoostK With your workaround, tests are now passing, thanks. So it's OK on my side. 👍

@alan-agius4
Copy link
Contributor

Hi all, the dist folder resolution is not yet implemented in the CLI, as this was done in angular master after the version 8 branch has been created. Hence it should be available in version 8.1

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants