Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit c152007

Browse files
committed
New: Accessibility Modifiers (fixes #1234)
1 parent ac0c95d commit c152007

File tree

4 files changed

+1155
-0
lines changed

4 files changed

+1155
-0
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
*.js eol=lf
3+
*.ts eol=lf

lib/ast-converter.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ module.exports = function(ast, extra) {
420420
return null;
421421
}
422422

423+
var accessibility;
424+
423425
var result = {
424426
type: "",
425427
range: [node.getStart(), node.end],
@@ -498,6 +500,31 @@ module.exports = function(ast, extra) {
498500
};
499501
}
500502

503+
/**
504+
* Gets a TSNode's accessibility level
505+
* @returns {string} accessibility "public", "protected", or "private"
506+
*/
507+
function getTSNodeAccessibility() {
508+
var modifiers = node.modifiers;
509+
if (!modifiers) {
510+
return "";
511+
}
512+
for (var i = 0; i < modifiers.length; i++) {
513+
var modifier = modifiers[i];
514+
switch (modifier.kind) {
515+
case SyntaxKind.PublicKeyword:
516+
return "public";
517+
case SyntaxKind.ProtectedKeyword:
518+
return "protected";
519+
case SyntaxKind.PrivateKeyword:
520+
return "private";
521+
default:
522+
continue;
523+
}
524+
}
525+
return "";
526+
}
527+
501528
/**
502529
* Converts a TSNode's typeParameters array to a flow-like TypeParameterDeclaration node
503530
* @param {TSNode[]} typeParameters TSNode typeParameters
@@ -988,6 +1015,11 @@ module.exports = function(ast, extra) {
9881015
return convertChild(d.expression);
9891016
}) : []
9901017
});
1018+
1019+
accessibility = getTSNodeAccessibility(node);
1020+
if (accessibility) {
1021+
result.accessibility = accessibility;
1022+
}
9911023
break;
9921024

9931025
case SyntaxKind.GetAccessor:
@@ -1013,6 +1045,7 @@ module.exports = function(ast, extra) {
10131045
}
10141046
};
10151047

1048+
10161049
if (node.type) {
10171050
method.returnType = convertTypeAnnotation(node.type);
10181051
}
@@ -1073,6 +1106,11 @@ module.exports = function(ast, extra) {
10731106

10741107
}
10751108

1109+
accessibility = getTSNodeAccessibility(node);
1110+
if (accessibility) {
1111+
result.accessibility = accessibility;
1112+
}
1113+
10761114
if (node.kind === SyntaxKind.GetAccessor) {
10771115
result.kind = "get";
10781116
} else if (node.kind === SyntaxKind.SetAccessor) {

0 commit comments

Comments
 (0)