generator-angular2-library icon indicating copy to clipboard operation
generator-angular2-library copied to clipboard

inline templates and styles needs regex improvement

Open BioPhoton opened this issue 8 years ago • 9 comments
trafficstars

I notices some wrong behavior when trying to use the new inline features of v9.0.0.

After research i found following things:

  • the regex for tempalteUrl and styleUrls works only with ' not with "
  • the regex for templateUrl and styleUrls parses also the comments and strings. It should only parse the related property

here is a test that shows the testcases: https://regex101.com/r/M6pB9M/2

BioPhoton avatar Apr 29 '17 10:04 BioPhoton

Hey @BioPhoton nice catch thanks! I think the edge cases you're proposing are all valid. I took a stab at fixing this, take a look here: https://regex101.com/r/M6pB9M/4. Can you please double check we're not missing any edge case here?

caroso1222 avatar May 01 '17 18:05 caroso1222

Hi @caroso1222! I added a view more checks with comments if they are imho not right... https://regex101.com/r/M6pB9M/6

BioPhoton avatar May 01 '17 19:05 BioPhoton

@BioPhoton — Nice catch, thank you!

Would you be interested in creating a PR to fix this?

I don't think we should worry about the double quotes., because the tslint.json is configured to only accept single quotes.

What are your thoughts? Thanks!

jvandemo avatar May 02 '17 20:05 jvandemo

Just passing by and thought I'd try some tweaks and add another test case: https://regex101.com/r/vIRDKR/5 https://regex101.com/r/vIRDKR/6

Not sure how to deal with comments without lookbehind.

franzeal avatar May 06 '17 22:05 franzeal

@franzeal — Thank you for the additional tests, much appreciated!

jvandemo avatar May 07 '17 14:05 jvandemo

Quick update: this regex is used in the Angular SystemJS loader: /templateUrl\s*:(\s*['"](.*?)['"]\s*)/gm

https://github.com/angular/angular/blob/061475402c26759a2d7c0840b99507320c3dffc4/aio/tools/examples/shared/boilerplate/src/systemjs-angular-loader.js#L1

It looks like this could work if we could first filter out comments.

What are your thoughts? Thanks!

jvandemo avatar May 07 '17 14:05 jvandemo

I think this is a bug but not enhancement. Discussion values but takes too long. A beta version may be better. @BioPhoton do you have time to make it or I will give it a try.

e-cloud avatar Jun 15 '17 15:06 e-cloud

Yes I think the same...

I already added more rules)Tests here: https://regex101.com/r/vIRDKR/8

There is a Version select at the top where you can change to latest... Currently im not into a PR. So next to my regex thing don't consider more help.

Best Michael

BioPhoton avatar Jun 15 '17 16:06 BioPhoton

good catch - I spent more than an hour trying to figure out why my html template wasn't inlining and throwing aot errors!

sgentile avatar Aug 17 '17 13:08 sgentile