Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2711,6 +2711,7 @@ repository:

template:
patterns:
- include: '#template-raw'
- include: '#template-call'
- contentName: string.template.ts
begin: '({{identifier}})?(`)'
Expand All @@ -2724,6 +2725,25 @@ repository:
- include: '#template-substitution-element'
- include: '#string-character-escape'

# String.raw`...` : backslashes are not escape sequences here, but a backslash
# still prevents the following character (e.g. ` or $) from terminating the
# template or starting a substitution.
template-raw:
contentName: string.template.ts
begin: '{{startOfIdentifier}}(String)\s*(\.)\s*(raw)\s*(`)'
beginCaptures:
'1': { name: support.class.builtin.ts }
'2': { name: punctuation.accessor.ts }
'3': { name: entity.name.function.tagged-template.ts }
'4': { name: string.template.ts punctuation.definition.string.template.begin.ts }
end: '`'
endCaptures:
'0': { name: string.template.ts punctuation.definition.string.template.end.ts}
patterns:
- include: '#template-substitution-element'
# consume the backslash and the next character without scoping it as an escape
- match: \\(.|$)

template-call:
patterns:
- begin: (?=(({{identifier}}\s*{{propertyAccessPreIdentifier}})*|({{propertyAccessPreIdentifier}})?)({{identifier}})({{typeArguments}}\s*)?`)
Expand Down
55 changes: 55 additions & 0 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -8236,6 +8236,10 @@
<dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#template-raw</string>
</dict>
<dict>
<key>include</key>
<string>#template-call</string>
Expand Down Expand Up @@ -8282,6 +8286,57 @@
</dict>
</array>
</dict>
<key>template-raw</key>
<dict>
<key>contentName</key>
<string>string.template.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(String)\s*(\.)\s*(raw)\s*(`)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>support.class.builtin.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.accessor.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>entity.name.function.tagged-template.ts</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>string.template.ts punctuation.definition.string.template.begin.ts</string>
</dict>
</dict>
<key>end</key>
<string>`</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>string.template.ts punctuation.definition.string.template.end.ts</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#template-substitution-element</string>
</dict>
<dict>
<key>match</key>
<string>\\(.|$)</string>
</dict>
</array>
</dict>
<key>template-call</key>
<dict>
<key>patterns</key>
Expand Down
55 changes: 55 additions & 0 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -8184,6 +8184,10 @@
<dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#template-raw</string>
</dict>
<dict>
<key>include</key>
<string>#template-call</string>
Expand Down Expand Up @@ -8230,6 +8234,57 @@
</dict>
</array>
</dict>
<key>template-raw</key>
<dict>
<key>contentName</key>
<string>string.template.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(String)\s*(\.)\s*(raw)\s*(`)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>support.class.builtin.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.accessor.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>entity.name.function.tagged-template.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>string.template.tsx punctuation.definition.string.template.begin.tsx</string>
</dict>
</dict>
<key>end</key>
<string>`</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>string.template.tsx punctuation.definition.string.template.end.tsx</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#template-substitution-element</string>
</dict>
<dict>
<key>match</key>
<string>\\(.|$)</string>
</dict>
</array>
</dict>
<key>template-call</key>
<dict>
<key>patterns</key>
Expand Down
178 changes: 178 additions & 0 deletions tests/baselines/Issue1039.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
original file
-----------------------------------
String.raw`--some-flag=C:\Some\Windows\Path`;
String.raw`"This is\nJSON text\u2757"`;
String.raw`\`;
`;
String.raw`a\${not}b${sub}\`c`;
String . raw`C:\path\${x}`;
foo`C:\Some\Path`;
`C:\Some\Path`;

-----------------------------------

Grammar: TypeScript.tmLanguage
-----------------------------------
>String.raw`--some-flag=C:\Some\Windows\Path`;
^^^^^^
source.ts support.class.builtin.ts
^
source.ts punctuation.accessor.ts
^^^
source.ts entity.name.function.tagged-template.ts
^
source.ts string.template.ts punctuation.definition.string.template.begin.ts
^^^^^^^^^^^^^^
source.ts string.template.ts
^^
source.ts string.template.ts
^^^
source.ts string.template.ts
^^
source.ts string.template.ts
^^^^^^
source.ts string.template.ts
^^
source.ts string.template.ts
^^^
source.ts string.template.ts
^
source.ts string.template.ts punctuation.definition.string.template.end.ts
^
source.ts punctuation.terminator.statement.ts
>String.raw`"This is\nJSON text\u2757"`;
^^^^^^
source.ts support.class.builtin.ts
^
source.ts punctuation.accessor.ts
^^^
source.ts entity.name.function.tagged-template.ts
^
source.ts string.template.ts punctuation.definition.string.template.begin.ts
^^^^^^^^
source.ts string.template.ts
^^
source.ts string.template.ts
^^^^^^^^^
source.ts string.template.ts
^^
source.ts string.template.ts
^^^^^
source.ts string.template.ts
^
source.ts string.template.ts punctuation.definition.string.template.end.ts
^
source.ts punctuation.terminator.statement.ts
>String.raw`\`;
^^^^^^
source.ts support.class.builtin.ts
^
source.ts punctuation.accessor.ts
^^^
source.ts entity.name.function.tagged-template.ts
^
source.ts string.template.ts punctuation.definition.string.template.begin.ts
^^
source.ts string.template.ts
^^
source.ts string.template.ts
>`;
^
source.ts string.template.ts punctuation.definition.string.template.end.ts
^
source.ts punctuation.terminator.statement.ts
>String.raw`a\${not}b${sub}\`c`;
^^^^^^
source.ts support.class.builtin.ts
^
source.ts punctuation.accessor.ts
^^^
source.ts entity.name.function.tagged-template.ts
^
source.ts string.template.ts punctuation.definition.string.template.begin.ts
^
source.ts string.template.ts
^^
source.ts string.template.ts
^^^^^^
source.ts string.template.ts
^^
source.ts string.template.ts meta.template.expression.ts punctuation.definition.template-expression.begin.ts
^^^
source.ts string.template.ts meta.template.expression.ts meta.embedded.line.ts variable.other.readwrite.ts
^
source.ts string.template.ts meta.template.expression.ts punctuation.definition.template-expression.end.ts
^^
source.ts string.template.ts
^
source.ts string.template.ts
^
source.ts string.template.ts punctuation.definition.string.template.end.ts
^
source.ts punctuation.terminator.statement.ts
>String . raw`C:\path\${x}`;
^^^^^^
source.ts support.class.builtin.ts
^
source.ts
^
source.ts punctuation.accessor.ts
^
source.ts
^^^
source.ts entity.name.function.tagged-template.ts
^
source.ts string.template.ts punctuation.definition.string.template.begin.ts
^^
source.ts string.template.ts
^^
source.ts string.template.ts
^^^
source.ts string.template.ts
^^
source.ts string.template.ts
^^^
source.ts string.template.ts
^
source.ts string.template.ts punctuation.definition.string.template.end.ts
^
source.ts punctuation.terminator.statement.ts
>foo`C:\Some\Path`;
^^^
source.ts entity.name.function.tagged-template.ts
^
source.ts string.template.ts punctuation.definition.string.template.begin.ts
^^
source.ts string.template.ts
^^
source.ts string.template.ts constant.character.escape.ts
^^^
source.ts string.template.ts
^^
source.ts string.template.ts constant.character.escape.ts
^^^
source.ts string.template.ts
^
source.ts string.template.ts punctuation.definition.string.template.end.ts
^
source.ts punctuation.terminator.statement.ts
>`C:\Some\Path`;
^
source.ts string.template.ts punctuation.definition.string.template.begin.ts
^^
source.ts string.template.ts
^^
source.ts string.template.ts constant.character.escape.ts
^^^
source.ts string.template.ts
^^
source.ts string.template.ts constant.character.escape.ts
^^^
source.ts string.template.ts
^
source.ts string.template.ts punctuation.definition.string.template.end.ts
^
source.ts punctuation.terminator.statement.ts
>
^
source.ts
8 changes: 8 additions & 0 deletions tests/cases/Issue1039.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
String.raw`--some-flag=C:\Some\Windows\Path`;
String.raw`"This is\nJSON text\u2757"`;
String.raw`\`;
`;
String.raw`a\${not}b${sub}\`c`;
String . raw`C:\path\${x}`;
foo`C:\Some\Path`;
`C:\Some\Path`;