diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index 36fa5547..54c60fba 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -2711,6 +2711,7 @@ repository: template: patterns: + - include: '#template-raw' - include: '#template-call' - contentName: string.template.ts begin: '({{identifier}})?(`)' @@ -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*)?`) diff --git a/TypeScript.tmLanguage b/TypeScript.tmLanguage index 4d91f6ad..ade926d6 100644 --- a/TypeScript.tmLanguage +++ b/TypeScript.tmLanguage @@ -8236,6 +8236,10 @@ patterns + + include + #template-raw + include #template-call @@ -8282,6 +8286,57 @@ + template-raw + + contentName + string.template.ts + begin + (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(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 + + + match + \\(.|$) + + + template-call patterns diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index a7aec5da..9d998477 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -8184,6 +8184,10 @@ patterns + + include + #template-raw + include #template-call @@ -8230,6 +8234,57 @@ + template-raw + + contentName + string.template.tsx + begin + (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(String)\s*(\.)\s*(raw)\s*(`) + beginCaptures + + 1 + + name + support.class.builtin.tsx + + 2 + + name + punctuation.accessor.tsx + + 3 + + name + entity.name.function.tagged-template.tsx + + 4 + + name + string.template.tsx punctuation.definition.string.template.begin.tsx + + + end + ` + endCaptures + + 0 + + name + string.template.tsx punctuation.definition.string.template.end.tsx + + + patterns + + + include + #template-substitution-element + + + match + \\(.|$) + + + template-call patterns diff --git a/tests/baselines/Issue1039.baseline.txt b/tests/baselines/Issue1039.baseline.txt new file mode 100644 index 00000000..76f8adb8 --- /dev/null +++ b/tests/baselines/Issue1039.baseline.txt @@ -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 \ No newline at end of file diff --git a/tests/cases/Issue1039.ts b/tests/cases/Issue1039.ts new file mode 100644 index 00000000..094be5e3 --- /dev/null +++ b/tests/cases/Issue1039.ts @@ -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`;