Skip to content

Commit 6933e62

Browse files
committed
Add a test for #2587, fix testcase helper
1 parent 59c1ad5 commit 6933e62

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

scripts/testcase.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
2-
const marked = require("marked");
2+
const md = require("markdown-it");
33
const cp = require("child_process");
44
const { writeFile } = require("fs/promises");
55

@@ -45,16 +45,16 @@ async function main() {
4545
const issue = process.argv[2];
4646
const data = JSON.parse(await exec(curl.replace("ISSUE", issue)));
4747

48-
const lexer = new marked.Lexer({ gfm: true });
49-
const tokens = lexer.lex(data.body);
48+
const parser = md();
49+
const tokens = parser.parse(data.body, {});
5050

51-
const code = /** @type {marked.marked.Tokens.Code} */ (
51+
const code =
5252
tokens.find(
5353
(tok) =>
54-
tok.type === "code" &&
55-
["ts", "tsx", "js", "jsx"].includes(tok.lang || ""),
56-
) || tokens.find((tok) => tok.type === "code")
57-
);
54+
tok.tag === "code" &&
55+
["ts", "tsx", "js", "jsx"].includes(tok.info || ""),
56+
) || tokens.find((tok) => tok.tag === "code");
57+
5858
if (!code) {
5959
console.log("No codeblock found");
6060
const file = `src/test/converter2/issues/gh${issue}.ts`;
@@ -64,7 +64,7 @@ async function main() {
6464

6565
const ext = process.argv[3] ? `.${process.argv[3]}` : guessExtension(code);
6666
const file = `src/test/converter2/issues/gh${issue}${ext}`;
67-
await writeFile(file, code.text);
67+
await writeFile(file, code.content);
6868
await exec(`code ${file} src/test/issues.c2.test.ts`);
6969
}
7070

src/test/converter2/issues/gh2587.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function foo() {
2+
const x = 1;
3+
return {
4+
/**
5+
* Shorthand comment
6+
*/
7+
x,
8+
};
9+
}

src/test/issues.c2.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,4 +1551,18 @@ describe("Issue Tests", () => {
15511551
equal(getComment(project, "f32.a.fn"), "Fn comment");
15521552
equal(getComment(project, "f32.b"), "B comment");
15531553
});
1554+
1555+
it("#2587 comment on shorthand property declaration", () => {
1556+
const project = convert();
1557+
1558+
const sig = querySig(project, "foo");
1559+
equal(sig.type?.type, "reflection");
1560+
const x = sig.type.declaration.getChildByName("x");
1561+
ok(x);
1562+
1563+
equal(
1564+
Comment.combineDisplayParts(x.comment?.summary),
1565+
"Shorthand comment",
1566+
);
1567+
});
15541568
});

0 commit comments

Comments
 (0)