Skip to content

add support for Lift Template Literal Restriction - #23801

Merged
Nathan Shively-Sanders (sandersn) merged 34 commits into
microsoft:masterfrom
Kingwl:Lift-Template-Literal-Restriction
Feb 5, 2020
Merged

add support for Lift Template Literal Restriction#23801
Nathan Shively-Sanders (sandersn) merged 34 commits into
microsoft:masterfrom
Kingwl:Lift-Template-Literal-Restriction

Conversation

@Kingwl

Copy link
Copy Markdown
Contributor

Fixes#12700

Comment threadsrc/compiler/scanner.ts Outdated
}

/* @internal */
export function isHexDigit(ch: number): boolean {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither of these are used outside of scanner.ts, so just don't export them.

Comment threadsrc/compiler/scanner.ts Outdated
reScanSlashToken(): SyntaxKind;
reScanTemplateToken(): SyntaxKind;
reScanTemplateToken(isTaggedTemplate?: boolean): SyntaxKind;
reScanTemplateHead(): SyntaxKind;

@DanielRosenwasserDaniel Rosenwasser (DanielRosenwasser)May 2, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mohamed Hegazy (@mhegazy), thoughts on just having reScanTemplateToken operate on template heads as well? The implementation could have a Debug.assert like so:

if(token!==SyntaxKind.TemplateHead){Debug.assert(isTaggedTemplate,"'reScanTemplateToken' should only be called with a template head when in a tagged template.");}else{Debug.assert(token===SyntaxKind.CloseBraceToken,"'reScanTemplateToken' should only be called on a '}' or TemplateHead.");}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked too closely at the logic yet, but the general mechanism between the parser and the scanner looks close to what I would've done, so that's good!

I think what we also need is tests for es5 and es2015. One thing we need to discuss is whether the es2015 target needs the downleveled version.

Comment threadsrc/compiler/types.ts Outdated
kind: SyntaxKind.TemplateHead;
parent?: TemplateExpression;
/* @internal */
notEscapeFlags?: TokenFlags;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider just calling these templateFlags.

Comment threadsrc/compiler/types.ts Outdated
BinarySpecifier = 1 << 7, // e.g. `0b0110010000000000`
OctalSpecifier = 1 << 8, // e.g. `0o777`
ContainsSeparator = 1 << 9, // e.g. `0b1100_0101`
NotEscape = 1 << 10, // e.g. `\uhello`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContainsInvalidEscape

@Kingwl

Copy link
Copy Markdown
ContributorAuthor

One thing we need to discuss is whether the es2015 target needs the downleveled version.

In my memory, there are several issues related to escape sequences (es2015) that can be fixed together

@Kingwl

Copy link
Copy Markdown
ContributorAuthor

wow, seems ci is upgrade😄

Comment threadsrc/compiler/parser.ts Outdated
}

function parseTemplateExpression(): TemplateExpression {
function parseNoSubstitutionTemplate(isTaggedTemplate?: boolean) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no public API, just make this parameter required.

@@ -0,0 +1,47 @@
tests/cases/conformance/es2018/invalidTaggedTemplateEscapeSequences.ts(5,18): error TS1125: Hexadecimal digit expected.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to figure out exactly how to prevent the errors from the initial scan...

@Kingwl

Copy link
Copy Markdown
ContributorAuthor

should this move to es2018 transform?

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented May 7, 2018

Copy link
Copy Markdown
Member

should this move to es2018 transform?

I would say yes, but only run conditionally. So you only use the ES5-style transformed syntax when an "invalid escape" template string is used, but leave it alone otherwise in the ES2018 transform.

@DanielRosenwasser

Copy link
Copy Markdown
Member

Also, I'm not sure if you want to share that logic between each transform, or to just do the ES2015 transform in ES2018. Ron Buckton (@rbuckton) might have a better idea here.

@rbuckton

Copy link
Copy Markdown
Contributor

Also, I'm not sure if you want to share that logic between each transform, or to just do the ES2015 transform in ES2018.

I think the best approach would be to do something similar to what we do for destructuring and pull the logic for template literal down-leveling out of both places. You can then have the esnext.ts transform call this separate API for the tagged templates that need it, and the es2015.ts transform can call it for all tagged templates.

@rbuckton

Copy link
Copy Markdown
Contributor

should this move to es2018 transform?

Not the ES2018 transform, since this is not part of ES2018. Rather, this should go in the esnext.ts transform.

@Kingwl

Copy link
Copy Markdown
ContributorAuthor

is that mean i should add a new transformer, eg: taggedTemplate.ts and export the parse function, call the function in es2015 or esnext transformer?

@mhegazy

Copy link
Copy Markdown
Contributor

is that mean i should add a new transformer, eg: taggedTemplate.ts and export the parse function, call the function in es2015 or esnext transformer?

we already have esnext transform. i would put it there..

@Kingwl
Wenlu Wang (Kingwl)force-pushed the Lift-Template-Literal-Restriction branch from e92b6bc to 2f49205CompareMay 30, 2018 09:50
@Kingwl

Copy link
Copy Markdown
ContributorAuthor

@KingwlWenlu Wang (Kingwl) mentioned this pull request Jun 6, 2018
3 tasks
@DanielRosenwasser

Copy link
Copy Markdown
Member

Sorry, I didn't have full context as I was reviewing this. Please ignore the last batch of comments.

@Kingwl

Copy link
Copy Markdown
ContributorAuthor

Daniel Rosenwasser (@DanielRosenwasser) there are a other commit that i miss
the commit split the transform logic and call them in different transformter
that commit is in my another pc, i'll push it after i finish my work 😢

@Kingwl
Wenlu Wang (Kingwl)force-pushed the Lift-Template-Literal-Restriction branch from 2f49205 to e92b6bcCompareJune 8, 2018 15:00
@Kingwl

Copy link
Copy Markdown
ContributorAuthor

ahhh, Sure enough it committed in my another pc

@mhegazy

Copy link
Copy Markdown
Contributor

Ron Buckton (@rbuckton) can you take a look.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wenlu Wang (@Kingwl) sorry for the delay on this. One last change while you're working on the merge conflicts -- please use the multi-target feature of the test baselines (e.g. @target: es5, es2016) to reduce code duplication. Thanks for the great work here!

Marking as tentative Approve

@Kingwl

Copy link
Copy Markdown
ContributorAuthor

TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 13, 2020

Copy link
Copy Markdown
Contributor

Heya Wenlu Wang (@Kingwl), I've started to run the tarball bundle task on this PR at 569b35e. You can monitor the build here. It should now contribute to this PR's status checks.

@sandersnNathan Shively-Sanders (sandersn) added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Jan 31, 2020
@sandersn

Copy link
Copy Markdown
Member

One last CI run and I will merge this.

@sandersn

Copy link
Copy Markdown
Member

Oh no, it failed on the lint rules we just enabled! I pushed a new commit.

@Kingwl

Copy link
Copy Markdown
ContributorAuthor

What is the meaning of For Milestone Bug ... :XD

@sandersn
Nathan Shively-Sanders (sandersn) merged commit 70399e1 into microsoft:masterFeb 5, 2020
@sandersn

Copy link
Copy Markdown
Member

Wenlu Wang (@Kingwl) the PR is intended to fix a bug that has been accepted into a milestone. That contrasts with "For Backlog Bug", which are PRs intended to fix a backlog bug. This PR technically fixes a backlog bug, but it's an Ecmascript conformance bug, so I think it should have been put in a milestone long ago.

@Kingwl
Wenlu Wang (Kingwl) deleted the Lift-Template-Literal-Restriction branch February 6, 2020 14:47
@Kingwl

Copy link
Copy Markdown
ContributorAuthor

TypeScript Bot (@typescript-bot) pack this.

@typescript-bot

TypeScript Bot (typescript-bot) commented Feb 6, 2020

Copy link
Copy Markdown
Contributor

Heya Wenlu Wang (@Kingwl), I've started to run the tarball bundle task on this PR at f8b9bbb. You can monitor the build here. It should now contribute to this PR's status checks.

Eli Barzilay (elibarzilay) added a commit to elibarzilay/TypeScript that referenced this pull request May 15, 2020
This problem was introduced in 70399e1 (from PR microsoft#23801), which added
a `visitTaggedTemplateExpression` case for `TaggedTemplateExpression`,
before that, it would fallback to the default of `visitNode`. So re-add
that happen in `processTaggedTemplateExpression`.
Since it doesn't hurt, I left a `Debug.checkDefined(property.name)`
instead of `!`-ing it.
Fixesmicrosoft#38558.
Eli Barzilay (elibarzilay) added a commit to elibarzilay/TypeScript that referenced this pull request May 15, 2020
This problem was introduced in 70399e1 (from PR microsoft#23801), which added
a `visitTaggedTemplateExpression` case for `TaggedTemplateExpression`,
before that, it would fallback to the default of `visitNode`. So re-add
that happen in `processTaggedTemplateExpression`.
Since it doesn't hurt, I left a `Debug.checkDefined(property.name)`
instead of `!`-ing it.
Fixesmicrosoft#38558.
Eli Barzilay (elibarzilay) added a commit that referenced this pull request May 15, 2020
This problem was introduced in 70399e1 (from PR #23801), which added
a `visitTaggedTemplateExpression` case for `TaggedTemplateExpression`,
before that, it would fallback to the default of `visitNode`. So re-add
that happen in `processTaggedTemplateExpression`.
Since it doesn't hurt, I left a `Debug.checkDefined(property.name)`
instead of `!`-ing it.
Fixes#38558.
@KingwlWenlu Wang (Kingwl) mentioned this pull request Feb 20, 2021
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone BugPRs that fix a bug with a specific milestone

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Lift Template Literal Restriction on Backslashes

7 participants

@Kingwl@DanielRosenwasser@rbuckton@mhegazy@typescript-bot@sandersn@RyanCavanaugh