-
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
InlineHtmlStripStylesTransformer is not strict enough #254
Comments
Unless someone else wants to tackle this, I can try and make a PR. |
PR is welcome 👍😀 |
Yeah, this caveat is known and discussed
Problem is, that theoretically someone might rename the annotation, or pull an object into the annotation, that is not declared inside the annotation itself. The AST transformer does not know if an object is actually the Angular Component Decorator or if an object with Consider these examples: import { Component } from '@angular/core';
// classic and easy
@Component({ templateUrl: './file.html' }) export class MyFirstComp { }
// difficult
const MyAnnotation = Component;
@MyAnnotation({ templateUrl: './file.html' }) export class MySecondComp { }
// difficult
const componentConfig = { styles: [], templateUrl: './file.html' };
@Component(componentConfig) export class MyThirdComp { }
// difficult
const partialComponentConfig = { templateUrl: './file.html' };
@Component({...partialComponentConfig, styles: []}) export class MyThirdComp { } We should discuss approaches and their caveats before implementing it. Edit: fixed linked issues |
Would it be an expectation to even support the second case?
For the others we are guaranteed to be in I guess we are also looking at this scenario from the linked issue:
|
I agree, the second example is not very important. The third and fourth are the problematic ones. @electrichead The AST transformer is written in TypeScript, but it works with AST objects. AST is a representation of the code text, not of the evaluated objects. So this situation const componentConfig = { styles: [], templateUrl: './file.html' };
@Component(componentConfig) export class MyThirdComp { } is definitely a problem, as in this example each line is an independent object. References are made when JavaScript is interpreted, not when the AST transformer is executed. The |
@wtho I see the issues. That is fair. Let's make it not as strict as looking for where the object literal is. I think if we check if the file imports Component from Then we can exclude files which do not include: import { Component } from '@angular/core';
import * as core from '@angular/core';
import { Component as Comp } from '@angular/core'; And same for import { TestBed } from '@angular/core/testing';
import * as testing from '@angular/core/testing';
import { TestBed as Bed } from '@angular/core/testing'; I suppose they can import the options from somewhere else.. but I feel like that's a better Caveat to have. What do you think? |
Ok, so one more thought I just had,
ProposalWe could also think about handling them differently, although this might complicate the code unnecessarily.
This would seem more practical to me as |
I think the proposal looks practical and good. I vote for it. |
If someone lands here before that PR is merged - I was able to hack around the problem temporarily by changing:
to
|
This error was driving me mad until I found this issue. |
Wow, discovered this today as well. Suddenly a unit test broke after upgrading to Jest 24. |
Yeah, I am almost done with the PR, will submit it this weekend. It's not really an error, it is an intrusive caveat that kept the transformer simple, but can create side-effects. |
I renamed my property as an easy workaround. 😉 |
This is a nightmare to debug. We were lucky to find it by searching thought node_modules. Is there any that you can do this without using AST Transformations? Or if you are going to use AST Transformations, only modify it when you are sure that it is appropriate? |
@SLKnutson The PR is on the way already #261 If you want to avoid them, you can remove AST Transformers by overriding the array in your jest config and clearing it. To still use jest without the transformers, you will have to inline your templates and styles though. Also you can test the branch of the PR with the appropriate implementation on Testing and reviewing the implementation can speed up the merge. Finally you are free to implement and use custom transformers. |
Current Behavior
Any object literals have their property assignments transformed thus causing source code such as:
to print out
Expected Behavior
Only object literals passed to
@angular/core
's@Component
decorator should have it's property assignments transformed.The text was updated successfully, but these errors were encountered: