The Wayback Machine - https://web.archive.org/web/20210619043656/https://github.com/microsoft/TypeScript/issues/42887
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

Open
sugoroku-y opened this issue Feb 19, 2021 · 7 comments
Open

\u in String.raw #42887

sugoroku-y opened this issue Feb 19, 2021 · 7 comments

Comments

@sugoroku-y
Copy link

@sugoroku-y sugoroku-y commented Feb 19, 2021

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

@DanielRosenwasser DanielRosenwasser commented Feb 20, 2021

@Kingwl you might be interested in this one.

@ExE-Boss
Copy link
Contributor

@ExE-Boss 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.

@Kingwl
Copy link
Member

@Kingwl 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

@ExE-Boss ExE-Boss commented Feb 20, 2021

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
Member

@Kingwl Kingwl commented Feb 20, 2021

Ahhhh Okay. Got the point. Thanks.

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Feb 20, 2021

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


Comment by @ExE-Boss

Failed: -

  • Hexadecimal digit expected.

Historical Information

Comment by @ExE-Boss

Version Reproduction Outputs
3.9.2, 4.0.2, 4.1.2, Nightly

Failed: -

  • Hexadecimal digit expected.

3.7.5, 3.8.2

Failed: -

  • Hexadecimal digit expected.
  • Hexadecimal digit expected.

@elibarzilay
Copy link
Member

@elibarzilay elibarzilay commented Jun 3, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants