TypeScript: Support type arguments on tagged templates (#7754)
| Q | A | ------------------------ | --- | Fixed Issues? | #7747 (partly) | Patch: Bug Fix? | | Major: Breaking Change? | | Minor: New Feature? | Yes | Tests Added + Pass? | Yes | Documentation PR | | Any Dependency Changes? | | License | MIT @JamesHenry This changes the AST format. CC @DanielRosenwasser for review. Supports parsing type arguments on tagged template calls. Should wait on Microsoft/TypeScript#23430 to be merged so we're sure we have the final syntax.
This commit is contained in:
@@ -563,22 +563,41 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
return node;
|
||||
} else if (this.match(tt.backQuote)) {
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.tag = base;
|
||||
node.quasi = this.parseTemplate(true);
|
||||
if (state.optionalChainMember) {
|
||||
this.raise(
|
||||
startPos,
|
||||
"Tagged Template Literals are not allowed in optionalChain",
|
||||
);
|
||||
}
|
||||
return this.finishNode(node, "TaggedTemplateExpression");
|
||||
return this.parseTaggedTemplateExpression(
|
||||
startPos,
|
||||
startLoc,
|
||||
base,
|
||||
state,
|
||||
);
|
||||
} else {
|
||||
state.stop = true;
|
||||
return base;
|
||||
}
|
||||
}
|
||||
|
||||
parseTaggedTemplateExpression(
|
||||
startPos: number,
|
||||
startLoc: Position,
|
||||
base: N.Expression,
|
||||
state: N.ParseSubscriptState,
|
||||
typeArguments?: ?N.TsTypeParameterInstantiation,
|
||||
): N.TaggedTemplateExpression {
|
||||
const node: N.TaggedTemplateExpression = this.startNodeAt(
|
||||
startPos,
|
||||
startLoc,
|
||||
);
|
||||
node.tag = base;
|
||||
node.quasi = this.parseTemplate(true);
|
||||
if (typeArguments) node.typeParameters = typeArguments;
|
||||
if (state.optionalChainMember) {
|
||||
this.raise(
|
||||
startPos,
|
||||
"Tagged Template Literals are not allowed in optionalChain",
|
||||
);
|
||||
}
|
||||
return this.finishNode(node, "TaggedTemplateExpression");
|
||||
}
|
||||
|
||||
atPossibleAsync(base: N.Expression): boolean {
|
||||
return (
|
||||
!this.state.containsEsc &&
|
||||
|
||||
Reference in New Issue
Block a user