Using raw property in a tagged template function
What? The property raw is on the array that contains all string parts of a template string
WHEN reading .raw of the strings (the 1st parameter) THEN it returns an array of all raw strings of the template
WHEN reading the raw value of a backslash THEN this returns the text as written in the original string, not the character only
WHEN analyzing the tag-function arguments THEN the function signature is much like the one of String.raw
using raw in a tagged template
WHEN using .raw on a "normal" character THEN this is the character itself
WHEN reading the first character of the raw value of a line break THEN this is a backslash
Links
Description of `raw` property of tagged template strings.
Describing the raw behavior.
The JS engine internal abstract operation `GetTemplateObject` describes how the template object, that is passed to the tag-function is created, see esp. the adding of the `raw` property onto the array here (item: 14. Perform ! DefinePropertyOrThrow(template, "raw"...).
Required Knowledge
- basics (Template strings)
- tagged template strings (Template strings)
- `String.raw` (String API)
Related Katas
Template strings
- basics
- multiline
- tagged template strings
rawproperty
String API
string.includes()string.repeat(count)string.startsWith()string.endsWith()String.rawstring.trimStart()string.matchAll()
Difficulty Level
EXPERT
First Published
18 March 2015
Stats
5 tests to solve