cannabis
Version:
TypeScript AST Query library
62 lines • 2.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ts_simple_ast_extra_1 = require("ts-simple-ast-extra");
var astNode_1 = require("../node/astNode");
var astNodeType_1 = require("../node/astNodeType");
var path_1 = require("../node/path");
function getAttribute(node, attr) {
try {
if (attr === 'text') {
return astNode_1.getASTNodeText(node);
}
else if (attr === 'name') {
return (astNode_1.getASTNodeName(node) + '') || '';
}
else if (attr === 'type') {
return astNodeType_1.getASTNodeTypeAsString(node);
}
else if (attr === 'indexPath') {
return ts_simple_ast_extra_1.isNode(node) && path_1.getASTNodeIndexPath(node) || '';
}
else if (attr === 'kindPath') {
return ts_simple_ast_extra_1.isNode(node) && path_1.getASTNodeKindPath(node) || '';
}
else if (attr === 'namePath') {
return ts_simple_ast_extra_1.isNode(node) && path_1.getASTNodeNamePath(node) || '';
}
else if (attr === 'modifiers') {
return ts_simple_ast_extra_1.isNode(node) && ts_simple_ast_extra_1.tsMorph.TypeGuards.isModifierableNode(node) && node.getModifiers().map(function (n) { return n.getText(); }).join(' ') || '';
}
else if (attr === 'expression') {
return ts_simple_ast_extra_1.isNode(node) && node.compilerNode && node.compilerNode.expression || null;
}
else if (attr === 'literalText') {
return ts_simple_ast_extra_1.isNode(node) && ts_simple_ast_extra_1.tsMorph.TypeGuards.isLiteralLikeNode(node) && node.getLiteralText() || null;
}
else if (attr === 'start') {
return ts_simple_ast_extra_1.isNode(node) && node.getStart() || null;
}
else if (attr === 'end') {
return ts_simple_ast_extra_1.isNode(node) && node.getEnd() || null;
}
else if (attr === 'width') {
return ts_simple_ast_extra_1.isNode(node) && node.getWidth() || null;
}
else if (attr === 'body') {
return ts_simple_ast_extra_1.isNode(node) && ts_simple_ast_extra_1.tsMorph.TypeGuards.isBodyableNode(node) && node.getBody() || null;
}
else if (attr === 'leadingComments') {
return ts_simple_ast_extra_1.isNode(node) && node.getLeadingCommentRanges().map(function (c) { return c.getText(); }) || [];
}
else if (attr === 'trailingComments') {
return ts_simple_ast_extra_1.isNode(node) && node.getTrailingCommentRanges().map(function (c) { return c.getText(); }) || [];
}
}
catch (error) {
console.error('ERROR on getAttribute for attr==', attr, error);
}
return null;
// symbol,
}
exports.getAttribute = getAttribute;
//# sourceMappingURL=attributes.js.map