forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. `getRawLiteral()`: barf if `currentSourceFile` is missing, since if it is, then the following `getSourceTextOfNodeFromSourceFile` will return a bogus `""`. 2. One `||` -> `??` change. 3. `backtickQuoteEscapedCharsRegExp`: escape the usual control characters except for a simple LF. This code does get used to generate backtick strings when `rawText` is not given, and not escaping things like TAB characters can get mangled by editor settings. Worse, not escaping a CRLF and putting it verbatim in sthe string source will interpret it as LF, so add a special case for escaping these as `\r\n`. Added test. Related to microsoft#44313 and microsoft#40625.
- Loading branch information
1 parent
3266ffb
commit 635f5bd
Showing
7 changed files
with
70 additions
and
4 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
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/templateLiteralsInTypes.errors.txt
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,14 @@ | ||
tests/cases/compiler/templateLiteralsInTypes.ts(3,1): error TS2554: Expected 2 arguments, but got 1. | ||
tests/cases/compiler/templateLiteralsInTypes.ts(3,8): error TS2339: Property 'foo' does not exist on type '`${string}:\t${number}\r\n`'. | ||
|
||
|
||
==== tests/cases/compiler/templateLiteralsInTypes.ts (2 errors) ==== | ||
const f = (hdr: string, val: number) => `${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n`; | ||
|
||
f("x").foo; | ||
~~~~~~ | ||
!!! error TS2554: Expected 2 arguments, but got 1. | ||
!!! related TS6210 tests/cases/compiler/templateLiteralsInTypes.ts:1:25: An argument for 'val' was not provided. | ||
~~~ | ||
!!! error TS2339: Property 'foo' does not exist on type '`${string}:\t${number}\r\n`'. | ||
|
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,14 @@ | ||
//// [templateLiteralsInTypes.ts] | ||
const f = (hdr: string, val: number) => `${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n`; | ||
|
||
f("x").foo; | ||
|
||
|
||
//// [templateLiteralsInTypes.js] | ||
"use strict"; | ||
var f = function (hdr, val) { return hdr + ":\t" + val + "\r\n"; }; | ||
f("x").foo; | ||
|
||
|
||
//// [templateLiteralsInTypes.d.ts] | ||
declare const f: (hdr: string, val: number) => `${string}:\t${number}\r\n`; |
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,11 @@ | ||
=== tests/cases/compiler/templateLiteralsInTypes.ts === | ||
const f = (hdr: string, val: number) => `${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n`; | ||
>f : Symbol(f, Decl(templateLiteralsInTypes.ts, 0, 5)) | ||
>hdr : Symbol(hdr, Decl(templateLiteralsInTypes.ts, 0, 11)) | ||
>val : Symbol(val, Decl(templateLiteralsInTypes.ts, 0, 23)) | ||
>hdr : Symbol(hdr, Decl(templateLiteralsInTypes.ts, 0, 11)) | ||
>val : Symbol(val, Decl(templateLiteralsInTypes.ts, 0, 23)) | ||
|
||
f("x").foo; | ||
>f : Symbol(f, Decl(templateLiteralsInTypes.ts, 0, 5)) | ||
|
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,18 @@ | ||
=== tests/cases/compiler/templateLiteralsInTypes.ts === | ||
const f = (hdr: string, val: number) => `${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n`; | ||
>f : (hdr: string, val: number) => `${string}:\t${number}\r\n` | ||
>(hdr: string, val: number) => `${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n` : (hdr: string, val: number) => `${string}:\t${number}\r\n` | ||
>hdr : string | ||
>val : number | ||
>`${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n` : `${string}:\t${number}\r\n` | ||
>`${hdr}:\t${val}\r\n` : `${string}:\t${number}\r\n` | ||
>hdr : string | ||
>val : number | ||
|
||
f("x").foo; | ||
>f("x").foo : any | ||
>f("x") : `${string}:\t${number}\r\n` | ||
>f : (hdr: string, val: number) => `${string}:\t${number}\r\n` | ||
>"x" : "x" | ||
>foo : any | ||
|
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,6 @@ | ||
// @strict: true | ||
// @declaration: true | ||
|
||
const f = (hdr: string, val: number) => `${hdr}:\t${val}\r\n` as `${string}:\t${number}\r\n`; | ||
|
||
f("x").foo; |