-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sadly, quite ugly, as template strings match their ENTIRE contents, not only the string literal part, as possible in C#
- Loading branch information
Showing
6 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Single-quoted __T__string | ||
let singleQuoted: string = 'He__T__llo'; | ||
|
||
// Double-quoted __T__string | ||
let doubleQuoted__T__: string = "Wor__T__ld"; | ||
|
||
// Template literal __T__(backticks) | ||
// CAREFUL: variable name is included and will be modified | ||
let templateLiteral: string = `Hello__T__ ${doubleQuoted__T__}`; | ||
|
||
// Tagged __T__template literal | ||
function tag(strings: TemplateStringsArray, ...values: any[]) { | ||
return strings.reduce((result, str, i) => result + str + (values[i] || ''), ''); | ||
} | ||
|
||
// CAREFUL: variable name is included and will be modified | ||
let taggedTemplate: string = tag`This__T__ is ${singleQuoted} and ${doubleQuoted__T__}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Single-quoted __T__string | ||
let singleQuoted: string = 'Hello'; | ||
|
||
// Double-quoted __T__string | ||
let doubleQuoted__T__: string = "World"; | ||
|
||
// Template literal __T__(backticks) | ||
// CAREFUL: variable name is included and will be modified | ||
let templateLiteral: string = `Hello ${doubleQuoted}`; | ||
|
||
// Tagged __T__template literal | ||
function tag(strings: TemplateStringsArray, ...values: any[]) { | ||
return strings.reduce((result, str, i) => result + str + (values[i] || ''), ''); | ||
} | ||
|
||
// CAREFUL: variable name is included and will be modified | ||
let taggedTemplate: string = tag`This is ${singleQuoted} and ${doubleQuoted}`; |