1

I was taking a look to the Angular code and I've just found something that I can't find documented anywhere.

const typingsFile = p `testing/testing.d.ts`;

It seems like a p function is invoked without using the parentheses??

This is the p function code:

/**
* Utility functions that allows me to create fs paths
*   p`${foo}/some/${{bar}}/path` rather than path.join(foo, 'some',
*/
function p(templateStringArray: TemplateStringsArray) {
 const segments = [];
 for (const entry of templateStringArray) {
   segments.push(...entry.split('/').filter(s => s !== ''));
 }
 return '';
}

The full code can be found @ the angular repo - angular-master\packages\bazel\test\ng_package\core_package.spec.ts

Garcel
  • 11
  • 4
  • Yes really, effectively I was wrong with the thing I was searching for. I was expecting for a function call without parentheses or something... – Garcel Mar 09 '18 at 10:06
  • Didn't mind about the template string, but any way you don't need to be so rude on your reply. By the other hand, truly thanks for the help. – Garcel Mar 09 '18 at 10:09
  • It **is** (in this case) a call without parentheses; `p` is called a "tag function." Sorry if you found the bluntness rude. – T.J. Crowder Mar 09 '18 at 10:13
  • Yes I got it now, but I was expecting a general behaviour of function calls or something. Didn't link it with the fact that the argument was a template string literal. Things are no so evident when you don't know about 'em. – Garcel Mar 09 '18 at 10:20

0 Answers0