-
Notifications
You must be signed in to change notification settings - Fork 309
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
feat: transform 'styles' only in decorator #261
feat: transform 'styles' only in decorator #261
Conversation
Actually it might be smart to split them up into two transformers, didn't think about it earlier |
I think we should do benchmarking with this change as well. |
Yeah! I still definitely want to split it up before merging. |
252144e
to
6272b7f
Compare
Will fix the @ahnpnl do you have any suggestions how to approach the benchmarking? |
f5af978
to
689478c
Compare
|
InlineHtmlStripStylesTransformer.js | ||
InlineFilesTransformer.js | ||
StripStylesTransformer.js | ||
TransformUtils.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's time for a build/
directory – ideally in a separate PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will start with that once this is done!
689478c
to
04bcba5
Compare
Until now 'templateUrl', 'styleUrls' and 'styles' were transformed everywhere, where they were assigned. The new implementation of the AstTransformers splits it in two: * InlineFilesTransformer, which inlines `templateUrl` and removes `styleUrls` file references * StripStylesTransformer, which removes the `styles` property, but only if it is assigned inside the `@component` decorator Tests were added to ensure the transformers behave as desired in edge cases regarding `styleUrls` and `styles`.
04bcba5
to
351e919
Compare
In last force-push (to
|
@ahnpnl anything to add or can e merge it? :) |
LGTM 🎉 |
This PR is another implementation change in the transformation behavior. It is a proposal and open for discussion.
Motivation
See #254
Until now we transformed 'templateUrl', 'styleUrls' and 'styles'
everywhere they were assigned.
This even transformed code like this:
console.log({ styles: {...}})
=>console.log({ styles: [] })
The new implementation of the AstTransformer only transforms property
assignments to 'styles' if it is placed inside a decorator.
templateUrl
andstyleUrls
are still transformed everywhere if assigned to a string, as Angular might expect them to be an actual Angular-Template or CSS code. This will crash the tests, if they are passed to the@Component
decorator.Example
A new unit test explains the new implementation:
Untransformed:
Transformed:
Caveats
There were always caveats and there still will be.
templateUrl
andstyleUrls
are transformed anywhere in the code. This enables you to declare them somewhere in your unit tests and then plug them into a component, e. g. usingtemplateUrl
andstyleUrls
if you use them in a different context.EDIT:
Closes #254