Skip to content

Commit

Permalink
feat(ts): add support for TSInstantiationExpression
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eventualbuddha committed Nov 25, 2022
1 parent 63b2a4c commit 4f828e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,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")]);
Expand Down
14 changes: 14 additions & 0 deletions test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,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(
Expand Down

0 comments on commit 4f828e0

Please sign in to comment.