Skip to content

fix(@ngtools/webpack): replace resources should effect only class dec… #12503

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

Merged
merged 1 commit into from
Nov 8, 2018
Merged

fix(@ngtools/webpack): replace resources should effect only class dec… #12503

merged 1 commit into from
Nov 8, 2018

Conversation

alan-agius4
Copy link
Collaborator

@alan-agius4 alan-agius4 commented Oct 8, 2018

Replace resources should effect only class decorators

At the moment we are processing all property assignments in object literals irrespective if they are in a decorator or not. With this change we will process only property assignments found under a class decorator.

Fixes #12488, Fixes #6007, Fixes: #6498 and Fixes: #8295

@alan-agius4 alan-agius4 added the target: major This PR is targeted for the next major release label Oct 8, 2018
@alan-agius4 alan-agius4 requested a review from clydin October 8, 2018 07:31
Copy link
Contributor

@filipesilva filipesilva left a comment

Choose a reason for hiding this comment

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

Hm this is a tricky one. Pretty sure some usecases are going to be broken by this. Like consts outside of the decorator that compose properties.

But I kinda think we should reduce the magic we do, and be more clear about it. It's not intuitive at all that that things can break by having a templateUrl property anywhere. I'm pretty sure this ended up causing some AngularJS templates to also be processed, for instance.

Adding the discussion label to make sure everyone is onboard with the direction.

Personally I think this PR should go in, and enhanced with some information about the magic we do in a readme, either CLI or ngtools/webpack (or both). Stuff like "templateUrl and stylesUrl will be processed if found within decorators, loadChildren will also be processed and should have a relative path or from the tsconfig baseUrl".

@filipesilva filipesilva added the needs: discussion On the agenda for team meeting to determine next steps label Oct 8, 2018
@alan-agius4
Copy link
Collaborator Author

alan-agius4 commented Oct 8, 2018

We can also do an addition checks that we only process Component decorators from `@angular/core. But that would incur that we need to get the import clauses and check their symbols because of various usecases.

Ex

import { Component as NgComponent} from '@angular/core'
import { Component } from '@angular/core'
import * as ng from '@angular/core'

@clydin
Copy link
Member

clydin commented Oct 8, 2018

Feel free to resurrect all or part of this old PR: #8401

@alan-agius4
Copy link
Collaborator Author

@clydin thanks, ill continue this tomorrow. that getDecoratorOrigin is will be pretty useful :)

…orators

At the moment we are processing all property assignments in object literals irrespective if they are in a decorator or not. With this change we will process only property assignments found under in a component decorator.

Fixes #12488, Fixes #6007, Fixes: #6498 and Fixes: #8295
@alexeagle
Copy link
Contributor

/cc @alxhub - this seems related to how the AOT compiler works - but in this case we need to do some transform for JIT

Also related to how we'd like to get away from JIT mode altogether when Ivy is just a tsc plugin

@alxhub
Copy link
Member

alxhub commented Oct 25, 2018

FWIW, Ivy requires that component metadata be inlined into the decorator.

Personally, I think this PR should land. You already don't support the full capabilities of ngc today. For example, this is totally valid:


import {templateUrlFor} from './templates';

@Component({
  templateUrl: templateUrlFor('some-component'),
  ...
})
export class SomeComponent {}

...

// templates.ts:
export function templateUrlFor(name: string) {
  return `../templates/${name}.ng.html`;
}

Trying to support all of this and resolve metadata in the same ways that ngc does would be infeasible.

@alexeagle alexeagle removed the needs: discussion On the agenda for team meeting to determine next steps label Nov 1, 2018
Copy link
Contributor

@filipesilva filipesilva left a comment

Choose a reason for hiding this comment

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

Especially like all the new tests 👍

@alan-agius4 alan-agius4 removed the request for review from clydin November 2, 2018 14:36
@alan-agius4 alan-agius4 added target: major This PR is targeted for the next major release and removed target: major This PR is targeted for the next major release labels Nov 2, 2018
@vikerman vikerman merged commit 96606b3 into angular:master Nov 8, 2018
@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 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
target: major This PR is targeted for the next major release
Projects
None yet
7 participants