Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\u in String.raw #42887

Closed
sugoroku-y opened this issue Feb 19, 2021 · 10 comments Β· Fixed by #51837
Closed

\u in String.raw #42887

sugoroku-y opened this issue Feb 19, 2021 · 10 comments Β· Fixed by #51837
Labels
Bug A bug in TypeScript Good First Issue Well scoped, documented and has the green light Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros Help Wanted You can do this
Milestone

Comments

@sugoroku-y
Copy link

Bug Report

πŸ”Ž Search Terms

String.raw

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about String.raw

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

String.raw`adc\def\ghi\jkl\mno\pqr\st\uvw\xyz`

πŸ™ Actual behavior

Error reported: error TS1125: Hexadecimal digit expected.

πŸ™‚ Expected behavior

Complete transpile

@DanielRosenwasser
Copy link
Member

@Kingwl you might be interested in this one.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this labels Feb 20, 2021
@DanielRosenwasser DanielRosenwasser added this to the Backlog milestone Feb 20, 2021
@ExE-Boss
Copy link
Contributor

ExE-Boss commented Feb 20, 2021

It’s not just String.raw, this applies to all tagged template literals, whereΒ theΒ top‑level TemplateStringArray containsΒ undefined forΒ anΒ unknownΒ escape, soΒ thisΒ should alsoΒ update TemplateStringsArray:

const taggedTemplate = (template: TemplateStringsArray, ...substitutions: unknown[]) => {
	console.log(template, substitutions);
}

// Logs:
// [
// 	undefined, "bar", undefined,
// 	raw: [ "foo\\uvar", "bar", "baz\\u" ]
// ]
// [ 123, 456 ]
taggedTemplate`foo\uvar${123}bar${456}baz\u`;

Workbench Repro


Also, this doesn’t occur when theΒ \uΒ follows aΒ substitution.

@typescript-bot typescript-bot added the Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros label Feb 20, 2021
@Kingwl
Copy link
Contributor

Kingwl commented Feb 20, 2021

It’s not just String.raw, this applies to all tagged template literals

Sorry I'm not 100% sure what your means.
But seems the runtime behavior is as expected.

image

The current problem is falsely alarm.

Here's some context:

And I have found an PR who try to fix a part of the alarm: #41030

@ExE-Boss
Copy link
Contributor

TheΒ definition ofΒ TemplateStringArray shouldΒ include undefined inΒ theΒ top‑level indexΒ signature, whichΒ should beΒ fixed alongsideΒ this toΒ correctlyΒ describe theΒ runtimeΒ behaviour asΒ ofΒ tc39/ecma262@138c9ef.

@Kingwl
Copy link
Contributor

Kingwl commented Feb 20, 2021

Ahhhh Okay. Got the point. Thanks.

@elibarzilay
Copy link
Contributor

I think that dealing with octal escapes in all strings #396 should be done before dealing with tagged templates as an exception...

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 14, 2022

πŸ‘‹ Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of this repro running against the nightly TypeScript.


Comment by @ExE-Boss

❌ Failed: -

  • Hexadecimal digit expected.

Historical Information
Version Reproduction Outputs
4.2.2, 4.3.2, 4.4.2, 4.5.2, 4.6.2

❌ Failed: -

  • Hexadecimal digit expected.

@bentongxyz
Copy link
Contributor

Hi, is this issue being worked on? I would like to look into this as a first issue.

@reverofevil
Copy link

Almost created a duplicate to this issue.

The proposal was here, normative section in ECMA-262 here.

@reverofevil
Copy link

@ExE-Boss

The definition of TemplateStringArray should include undefined in the top‑level index signature,

I'm afraid such a change will break existing code. undefined is there only if a part of string template contains invalid escape characters, and this information is available in compile-time. I'd suggest replacing TemplateStringsArray with a readonly tuple of strings and undefineds, intersected with {raw: ...}. of equal-sized tuple of strings. This type should be backwards compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Good First Issue Well scoped, documented and has the green light Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros Help Wanted You can do this
Projects
None yet
8 participants