You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-docgen-typescript

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-docgen-typescript - npm Package Compare versions

Comparing version

to
1.4.0

10

lib/__tests__/parser.js

@@ -327,2 +327,12 @@ "use strict";

});
describe('displayName', function () {
it('should be taken from stateless component `displayName` property', function () {
var parsed = parser_1.parse(testUtils_1.fixturePath('StatelessDisplayName'))[0];
chai_1.assert.equal(parsed.displayName, 'i am stateless displayName');
});
it('should be taken from stateful component `displayName` property', function () {
var parsed = parser_1.parse(testUtils_1.fixturePath('StatefulDisplayName'))[0];
chai_1.assert.equal(parsed.displayName, 'i am stateful displayName');
});
});
describe('Parser options', function () {

@@ -329,0 +339,0 @@ describe('Property filtering', function () {

3

lib/__tests__/testUtils.d.ts

@@ -14,3 +14,4 @@ import { ComponentDoc, ParserOptions } from '../parser';

}
export declare function check(component: string, expected: ExpectedComponents, exactProperties?: boolean, description?: string, parserOpts?: ParserOptions): void;
export declare function fixturePath(componentName: string): string;
export declare function check(componentName: string, expected: ExpectedComponents, exactProperties?: boolean, description?: string, parserOpts?: ParserOptions): void;
export declare function checkComponent(actual: ComponentDoc[], expected: ExpectedComponents, exactProperties?: boolean, description?: string): void;

@@ -6,6 +6,9 @@ "use strict";

var parser_1 = require("../parser");
function check(component, expected, exactProperties, description, parserOpts) {
function fixturePath(componentName) {
return path.join(__dirname, '..', '..', 'src', '__tests__', 'data', componentName + ".tsx"); // it's running in ./temp
}
exports.fixturePath = fixturePath;
function check(componentName, expected, exactProperties, description, parserOpts) {
if (exactProperties === void 0) { exactProperties = true; }
var fileName = path.join(__dirname, '../../src/__tests__/data', component + ".tsx"); // it's running in ./temp
var result = parser_1.parse(fileName, parserOpts);
var result = parser_1.parse(fixturePath(componentName), parserOpts);
checkComponent(result, expected, exactProperties, description);

@@ -12,0 +15,0 @@ }

@@ -35,3 +35,5 @@ "use strict";

var basePath = path.dirname(tsconfigPath);
var _a = ts.readConfigFile(tsconfigPath, function (filename) { return fs.readFileSync(filename, 'utf8'); }), config = _a.config, error = _a.error;
var _a = ts.readConfigFile(tsconfigPath, function (filename) {
return fs.readFileSync(filename, 'utf8');
}), config = _a.config, error = _a.error;
if (error !== undefined) {

@@ -391,4 +393,50 @@ throw error;

}
function getTextValueOfClassMember(classDeclaration, memberName) {
var textValue = classDeclaration.members
.filter(function (member) { return ts.isPropertyDeclaration(member); })
.filter(function (member) {
var name = ts.getNameOfDeclaration(member);
return name && name.text === memberName;
})
.map(function (member) {
var property = member;
return (property.initializer && property.initializer.text);
})[0];
return textValue || '';
}
function getTextValueOfFunctionProperty(exp, source, propertyName) {
var textValue = source.statements
.filter(function (statement) { return ts.isExpressionStatement(statement); })
.filter(function (statement) {
var expr = statement
.expression;
return (expr.left.name.escapedText ===
propertyName);
})
.filter(function (statement) {
var expr = statement
.expression;
return (expr.left.expression
.escapedText === exp.getName());
})
.filter(function (statement) {
return ts.isStringLiteral(statement
.expression.right);
})
.map(function (statement) {
return statement
.expression.right.text;
})[0];
return textValue || '';
}
function computeComponentName(exp, source) {
var exportName = exp.getName();
var statelessDisplayName = getTextValueOfFunctionProperty(exp, source, 'displayName');
var statefulDisplayName;
if (exp.valueDeclaration && ts.isClassDeclaration(exp.valueDeclaration)) {
statefulDisplayName = getTextValueOfClassMember(exp.valueDeclaration, 'displayName');
}
if (statelessDisplayName || statefulDisplayName) {
return statelessDisplayName || statefulDisplayName || '';
}
if (exportName === 'default' ||

@@ -395,0 +443,0 @@ exportName === '__function' ||

{
"name": "react-docgen-typescript",
"version": "1.3.2",
"version": "1.4.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -141,2 +141,4 @@ # react-docgen-typescript

**@chrisalbert** *Chris Albert*
**@diegolanda** *Diego* - support for different kinds of components

@@ -158,2 +160,4 @@

**@yoiang** *Ian G*
**@sapegin** *Artem Sapegin* - fix for compatibility with react-styleguidist v5

@@ -160,0 +164,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet