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

Commit 5dae849

Browse files
dannyfritzJamesHenry
authored andcommitted
New: Accessibility Modifiers (fixes #87) (#88)
1 parent 68992eb commit 5dae849

File tree

40 files changed

+4739
-3396
lines changed

40 files changed

+4739
-3396
lines changed

lib/ast-converter.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,32 @@ module.exports = function(ast, extra) {
498498
};
499499
}
500500

501+
/**
502+
* Gets a TSNode's accessibility level
503+
* @param {TSNode} tsNode The TSNode
504+
* @returns {string | null} accessibility "public", "protected", "private", or null
505+
*/
506+
function getTSNodeAccessibility(tsNode) {
507+
var modifiers = tsNode.modifiers;
508+
if (!modifiers) {
509+
return null;
510+
}
511+
for (var i = 0; i < modifiers.length; i++) {
512+
var modifier = modifiers[i];
513+
switch (modifier.kind) {
514+
case SyntaxKind.PublicKeyword:
515+
return "public";
516+
case SyntaxKind.ProtectedKeyword:
517+
return "protected";
518+
case SyntaxKind.PrivateKeyword:
519+
return "private";
520+
default:
521+
continue;
522+
}
523+
}
524+
return null;
525+
}
526+
501527
/**
502528
* Converts a TSNode's typeParameters array to a flow-like TypeParameterDeclaration node
503529
* @param {TSNode[]} typeParameters TSNode typeParameters
@@ -984,6 +1010,7 @@ module.exports = function(ast, extra) {
9841010
value: convertChild(node.initializer),
9851011
computed: (node.name.kind === SyntaxKind.ComputedPropertyName),
9861012
static: Boolean(node.flags & ts.NodeFlags.Static),
1013+
accessibility: getTSNodeAccessibility(node),
9871014
decorators: (node.decorators) ? node.decorators.map(function(d) {
9881015
return convertChild(d.expression);
9891016
}) : []
@@ -1066,6 +1093,7 @@ module.exports = function(ast, extra) {
10661093
computed: isMethodNameComputed,
10671094
static: Boolean(node.flags & ts.NodeFlags.Static),
10681095
kind: "method",
1096+
accessibility: getTSNodeAccessibility(node),
10691097
decorators: (node.decorators) ? node.decorators.map(function(d) {
10701098
return convertChild(d.expression);
10711099
}) : []
@@ -1157,6 +1185,7 @@ module.exports = function(ast, extra) {
11571185
key: constructorKey,
11581186
value: constructor,
11591187
computed: constructorIsComputed,
1188+
accessibility: getTSNodeAccessibility(node),
11601189
static: constructorIsStatic,
11611190
kind: (constructorIsStatic || constructorIsComputed) ? "method" : "constructor"
11621191
});

tests/fixtures/attach-comments/export-default-anonymous-class.result.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ module.exports = {
7373
},
7474
"kind": "method",
7575
"computed": false,
76+
"accessibility": null,
7677
"decorators": [],
7778
"range": [
7879
103,

0 commit comments

Comments
 (0)