Skip to content

Commit

Permalink
feat(generator): add ts params and args
Browse files Browse the repository at this point in the history
  • Loading branch information
LuLaValva committed Nov 9, 2023
1 parent 0819b1d commit 6fd4703
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/compiler/src/babel-types/generator/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ Object.assign(Printer.prototype, {
this.token(tagName);
}

if (node.typeArguments) {
this.token("<");
this.printList(node.typeArguments.params, node);
this.token(">");
}

if (node.var) {
this.token("/");
this.print(node.var, node);
Expand All @@ -187,6 +193,14 @@ Object.assign(Printer.prototype, {
}

if (node.body.params.length) {
if (node.typeParameters) {
if (!node.typeArguments) {
this.token(" ");
}
this.token("<");
this.printList(node.typeParameters.params, node);
this.token(">");
}
this.token("|");
this.printList(node.body.params, node);
this.token("|");
Expand Down
14 changes: 14 additions & 0 deletions packages/compiler/src/babel-types/types/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ const MarkoDefinitions = {
),
optional: true,
},
typeArguments: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("TypeAnnotation"))
),
optional: true,
},
typeParameters: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("TypeAnnotation"))
),
optional: true,
},
rawValue: {
validate: assertValueType("string"),
optional: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<type-arg/>
<type-param|x|>
<type-arg<string, number>/>
<type-param <T, U>|x|>
${x}
</type-param>
<type-arg-and-param|x| arg="hello">
<type-arg-and-param<string><T>|x| arg="hello">
${x}
</type-arg-and-param>

0 comments on commit 6fd4703

Please sign in to comment.