-
-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathadd-comments.ts
More file actions
61 lines (47 loc) · 2.03 KB
/
Copy pathadd-comments.ts
File metadata and controls
61 lines (47 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as ts from "typescript";
import * as tstl from "../../../src";
const plugin: tstl.Plugin = {
visitors: {
[ts.SyntaxKind.VariableStatement](node, context) {
const result = context.superTransformStatements(node);
const firstLuaStatement = result[0];
const lastLuaStatement = result[result.length - 1];
firstLuaStatement.leadingComments = [
"This comment on variable declaration was added by a plugin!",
"- This one too!",
];
lastLuaStatement.trailingComments = [" This trailing comment was also added by a plugin!"];
return result;
},
[ts.SyntaxKind.ExpressionStatement](node, context) {
const result = context.superTransformStatements(node);
const firstLuaStatement = result[0];
const lastLuaStatement = result[result.length - 1];
firstLuaStatement.leadingComments = ["- Example luadoc comment", "-@param paramName ParamClass"];
lastLuaStatement.trailingComments = [
"[[ This plugin can also (kinda) create multiline comments.",
" Line 2",
"]]",
];
return result;
},
[ts.SyntaxKind.WhileStatement](node, context) {
const result = context.superTransformStatements(node);
const firstLuaStatement = result[0];
const lastLuaStatement = result[result.length - 1];
firstLuaStatement.leadingComments = [
["Multiline comments are supported as arrays", "This is the second line!"],
];
lastLuaStatement.trailingComments = [
"Single line comments and multiline comments can also be mixed",
["Like this", "Pretty cool!"],
"Empty multiline comment below:",
[],
"Single line multiline comment:",
["Single line"],
];
return result;
},
},
};
export default plugin;