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

Normative: the TV of `\` NotEscapeSequence #965

Closed
jmdyck opened this Issue Aug 3, 2017 · 6 comments

Comments

Projects
None yet
2 participants
@jmdyck
Collaborator

jmdyck commented Aug 3, 2017

Commit 138c9ef merged the Template Literal revision proposal, that removes the restriction on escape sequences in tagged template literals. In it, the syntax-directed operation TV is altered to return *undefined* if the subject of the operation contains a NotEscapeSequence.

However, the rules for Evaluation of TemplateLiterals (etc) don't allow for this possibility. They continue to assume that the result of TV is a sequence of code units.

We could make the Evaluation algorithms work again by applying ToString() to the result of TV, but what would be the point? Why would you ever use a NotEscapeSequence in a TemplateLiteral if you're just going to get the string undefined at the corresponding point in the resulting value?

It seems to me that from a usability point of view, the TV of a NotEscapeSequence should return the same as the TRV does (or something pretty close to that). Isn't that what's needed by the latex example at https://tc39.github.io/proposal-template-literal-revision/?

(Does test262 have any tests that examine the value of a TemplateLiteral containing a NotEscapeSequence? I don't see any.)

@bakkot

This comment has been minimized.

Show comment
Hide comment
@bakkot

bakkot Aug 3, 2017

Contributor

Maybe I'm missing something - why is this a problem? My understanding is that tagged template literals aren't ever Evaluated; rather, the template parse node is passed through to ArgumentListEvaluation. And untagged templates are statically prevented from containing NotEscapeSequences.

Contributor

bakkot commented Aug 3, 2017

Maybe I'm missing something - why is this a problem? My understanding is that tagged template literals aren't ever Evaluated; rather, the template parse node is passed through to ArgumentListEvaluation. And untagged templates are statically prevented from containing NotEscapeSequences.

@jmdyck

This comment has been minimized.

Show comment
Hide comment
@jmdyck

jmdyck Aug 3, 2017

Collaborator

Ah, I see... a tagged template is evaluated without evaluating the TemplateLiteral per se. Thanks!

So a tag-function that's prepared to accept NotEscapeSequences in the TemplateLiteral would probably just ignore all the cooked strings of the template object, undefined or not?

Looking at the proposal again, I see now that that's what it says. (When I read it before, I thought it was saying something like "if the cooked value is undefined, you can use the raw string instead".)

So now what I'm wondering is: if the tag-function is probably going to ignore the TV values anyway, is there a particular advantage to making TV of NotEscapeSequence be *undefined*, as opposed to say, empty string?

Collaborator

jmdyck commented Aug 3, 2017

Ah, I see... a tagged template is evaluated without evaluating the TemplateLiteral per se. Thanks!

So a tag-function that's prepared to accept NotEscapeSequences in the TemplateLiteral would probably just ignore all the cooked strings of the template object, undefined or not?

Looking at the proposal again, I see now that that's what it says. (When I read it before, I thought it was saying something like "if the cooked value is undefined, you can use the raw string instead".)

So now what I'm wondering is: if the tag-function is probably going to ignore the TV values anyway, is there a particular advantage to making TV of NotEscapeSequence be *undefined*, as opposed to say, empty string?

@bakkot

This comment has been minimized.

Show comment
Hide comment
@bakkot

bakkot Aug 3, 2017

Contributor

In most cases that's what I'd expect, yes. The cooked values of sections not containing a NotEscapeSequence are available if necessary; those of sections containing a NotEscapeSequence are undefined, which isn't all that useful but does at least let you know that the section had something weird in it.

Contributor

bakkot commented Aug 3, 2017

In most cases that's what I'd expect, yes. The cooked values of sections not containing a NotEscapeSequence are available if necessary; those of sections containing a NotEscapeSequence are undefined, which isn't all that useful but does at least let you know that the section had something weird in it.

@bakkot

This comment has been minimized.

Show comment
Hide comment
@bakkot

bakkot Aug 3, 2017

Contributor

But for example

String.raw`\xyz`

works just fine, since String.raw does not even look at the cooked values.

Contributor

bakkot commented Aug 3, 2017

But for example

String.raw`\xyz`

works just fine, since String.raw does not even look at the cooked values.

@jmdyck

This comment has been minimized.

Show comment
Hide comment
@jmdyck

jmdyck Aug 3, 2017

Collaborator

I guess if a tag-function is not prepared to handle NotEscapeSequences, *undefined* lets it know (more easily than would empty string) that the template literal has 'bad' input.

Collaborator

jmdyck commented Aug 3, 2017

I guess if a tag-function is not prepared to handle NotEscapeSequences, *undefined* lets it know (more easily than would empty string) that the template literal has 'bad' input.

@jmdyck

This comment has been minimized.

Show comment
Hide comment
@jmdyck

jmdyck Aug 3, 2017

Collaborator

Okay, closing this then.

Collaborator

jmdyck commented Aug 3, 2017

Okay, closing this then.

@jmdyck jmdyck closed this Aug 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment