Skip to content

Commit f421c33

Browse files
committed
Add /* and <!-- commend patterns
1 parent bdc63fd commit f421c33

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

parse.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export default function parse(code) {
55
commentContents = firstLine.substring(1).trimStart();
66
} else if (firstLine.startsWith("//")) {
77
commentContents = firstLine.substring(2).trimStart();
8+
} else if (firstLine.startsWith("/*")) {
9+
commentContents = firstLine.substring(2).trimStart();
10+
} else if (firstLine.startsWith("<!--")) {
11+
commentContents = firstLine.substring(4).trimStart();
812
}
913

1014
if (commentContents) {

test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,38 @@
55
import parse from "./parse";
66
import { CodeplusInstance } from "./index";
77

8-
test("parse filename", () => {
8+
test("parse # filename", () => {
99
const parsed = parse("# filename.js\nfunction foo() {}");
1010
expect(parsed).toEqual({
1111
filename: "filename.js",
1212
displayName: "",
1313
});
1414
});
1515

16+
test("parse // filename", () => {
17+
const parsed = parse("// filename.js\nfunction foo() {}");
18+
expect(parsed).toEqual({
19+
filename: "filename.js",
20+
displayName: "",
21+
});
22+
});
23+
24+
test("parse /* filename", () => {
25+
const parsed = parse("/* filename.js */\nfunction foo() {}");
26+
expect(parsed).toEqual({
27+
filename: "filename.js",
28+
displayName: "",
29+
});
30+
});
31+
32+
test("parse <!-- filename", () => {
33+
const parsed = parse("<!-- filename.js -->\nfunction foo() {}");
34+
expect(parsed).toEqual({
35+
filename: "filename.js",
36+
displayName: "",
37+
});
38+
});
39+
1640
test("parse filename multiple dots", () => {
1741
const parsed = parse("# test.filename.template.js\nfunction foo() {}");
1842
expect(parsed).toEqual({

0 commit comments

Comments
 (0)