-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
add support for Lift Template Literal Restriction #23801
add support for Lift Template Literal Restriction #23801
Conversation
src/compiler/scanner.ts
Outdated
@@ -428,6 +429,16 @@ namespace ts { | |||
return ch >= CharacterCodes._0 && ch <= CharacterCodes._7; | |||
} | |||
|
|||
/* @internal */ | |||
export function isHexDigit(ch: number): boolean { |
There was a problem hiding this comment.
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.
src/compiler/scanner.ts
Outdated
@@ -27,7 +27,8 @@ namespace ts { | |||
getTokenFlags(): TokenFlags; | |||
reScanGreaterToken(): SyntaxKind; | |||
reScanSlashToken(): SyntaxKind; | |||
reScanTemplateToken(): SyntaxKind; | |||
reScanTemplateToken(isTaggedTemplate?: boolean): SyntaxKind; | |||
reScanTemplateHead(): SyntaxKind; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.");
}
There was a problem hiding this comment.
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.
src/compiler/types.ts
Outdated
@@ -1606,16 +1607,22 @@ namespace ts { | |||
export interface TemplateHead extends LiteralLikeNode { | |||
kind: SyntaxKind.TemplateHead; | |||
parent?: TemplateExpression; | |||
/* @internal */ | |||
notEscapeFlags?: TokenFlags; |
There was a problem hiding this comment.
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
.
src/compiler/types.ts
Outdated
@@ -1593,6 +1593,7 @@ namespace ts { | |||
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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContainsInvalidEscape
In my memory, there are several issues related to escape sequences (es2015) that can be fixed together |
wow, seems ci is upgrade😄 |
src/compiler/parser.ts
Outdated
@@ -2104,17 +2108,24 @@ namespace ts { | |||
return allowIdentifierNames ? parseIdentifierName() : parseIdentifier(); | |||
} | |||
|
|||
function parseTemplateExpression(): TemplateExpression { | |||
function parseNoSubstitutionTemplate(isTaggedTemplate?: boolean) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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...
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. |
Also, I'm not sure if you want to share that logic between each transform, or to just do the ES2015 transform in ES2018. @rbuckton might have a better idea here. |
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. |
Not the ES2018 transform, since this is not part of ES2018. Rather, this should go in the esnext.ts transform. |
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.. |
e92b6bc
to
2f49205
Compare
⬆ |
Sorry, I didn't have full context as I was reviewing this. Please ignore the last batch of comments. |
@DanielRosenwasser there are a other commit that i miss |
2f49205
to
e92b6bc
Compare
ahhh, Sure enough it committed in my another pc |
@rbuckton can you take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
@typescript-bot pack this |
One last CI run and I will merge this. |
Oh no, it failed on the lint rules we just enabled! I pushed a new commit. |
What is the meaning of |
@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. |
@typescript-bot pack this. |
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. Fixes microsoft#38558.
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. Fixes microsoft#38558.
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.
Fixes #12700