feat(ts): add support for TSInstantiationExpression

Refs #1230

See https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#instantiation-expressions.

This won't work yet because `ast-types` does not yet know about
`TSInstantiationExpression`. Once it does `recast` will need to be
updated to include the newer release of `ast-types`, at which point it
will be supported.
This commit is contained in:
Brian Donovan 2022-11-25 09:07:00 -08:00 committed by Ben Newman
parent 2cf243225c
commit 413d600a0a
No known key found for this signature in database
GPG key ID: 15D2E57778C1A4BF
2 changed files with 24 additions and 0 deletions

View file

@ -2532,6 +2532,16 @@ function genericPrintNoParens(path: any, options: any, print: any) {
return concat(parts);
}
case "TSInstantiationExpression": {
parts.push(
path.call(print, "expression"),
path.call(print, "typeParameters"),
);
return concat(parts);
}
// https://github.com/babel/babel/pull/10148
case "V8IntrinsicIdentifier":
return concat(["%", path.call(print, "name")]);

View file

@ -428,6 +428,20 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
["type A = {", " x: boolean;", " y: number;", "}"].join(eol),
);
});
it("TSInstantiationExpression: round trip", function () {
const code = [
"const makeHammerBox = makeBox<Hammer>;",
"const ErrorMap = Map<string, Error>;",
].join(eol);
const ast = recast.parse(code, { parser });
assert.strictEqual(
recast.prettyPrint(ast).code,
code
);
})
});
testReprinting(