Socket
Socket
Sign inDemoInstall

react-docgen-typescript

Package Overview
Dependencies
1
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.20.2 to 1.20.3

54

lib/__tests__/parser.js

@@ -333,2 +333,9 @@ "use strict";

});
it('should get name for default export 2', function () {
testUtils_1.check('ForwardRefDefaultExportAtExport', {
ForwardRefDefaultExport: {
myProp: { type: 'string' }
}
}, false);
});
it('should component where last line is a comment', function () {

@@ -618,5 +625,12 @@ testUtils_1.check('ExportObject', {

});
it('should parse functional component component defined as function as default export', function () {
testUtils_1.check('FunctionDeclarationAsDefaultExport', {
it("should parse functional component component defined as function as default export", function () {
testUtils_1.check("FunctionDeclarationAsDefaultExport", {
Jumbotron: {
prop1: { type: "string", required: true },
},
});
});
it('should parse functional component component thats been wrapped in React.memo', function () {
testUtils_1.check('FunctionDeclarationAsDefaultExportWithMemo', {
Jumbotron: {
prop1: { type: 'string', required: true }

@@ -810,2 +824,38 @@ }

});
it('should defaultProps in variable', function () {
testUtils_1.check('SeparateDefaultProps', {
SeparateDefaultProps: {
disabled: {
description: '',
required: false,
defaultValue: false,
type: 'boolean'
},
id: {
description: '',
required: false,
defaultValue: 123,
type: 'number'
}
}
});
});
it('should defaultProps accessed variable', function () {
testUtils_1.check('SeparateDefaultPropsIndividual', {
SeparateDefaultPropsIndividual: {
disabled: {
description: '',
required: false,
defaultValue: false,
type: 'boolean'
},
id: {
description: '',
required: false,
defaultValue: 123,
type: 'number'
}
}
});
});
describe('Extracting literal values from enums', function () {

@@ -812,0 +862,0 @@ it('extracts literal values from enum', function () {

@@ -101,2 +101,3 @@ import * as ts from 'typescript';

constructor(program: ts.Program, opts: ParserOptions);
private getComponentFromExpression;
getComponentInfo(exp: ts.Symbol, source: ts.SourceFile, componentNameResolver?: ComponentNameResolver): ComponentDoc | null;

@@ -103,0 +104,0 @@ extractPropsFromTypeIfStatelessComponent(type: ts.Type): ts.Symbol | null;

@@ -99,2 +99,22 @@ "use strict";

}
Parser.prototype.getComponentFromExpression = function (exp) {
var declaration = exp.valueDeclaration || exp.declarations[0];
var type = this.checker.getTypeOfSymbolAtLocation(exp, declaration);
var typeSymbol = type.symbol || type.aliasSymbol;
if (!typeSymbol) {
return exp;
}
var symbolName = typeSymbol.getName();
if ((symbolName === "MemoExoticComponent" ||
symbolName === "ForwardRefExoticComponent") &&
exp.valueDeclaration &&
ts.isExportAssignment(exp.valueDeclaration) &&
ts.isCallExpression(exp.valueDeclaration.expression)) {
var component = this.checker.getSymbolAtLocation(exp.valueDeclaration.expression.arguments[0]);
if (component) {
exp = component;
}
}
return exp;
};
Parser.prototype.getComponentInfo = function (exp, source, componentNameResolver) {

@@ -105,11 +125,12 @@ if (componentNameResolver === void 0) { componentNameResolver = function () { return undefined; }; }

}
var declaration = exp.valueDeclaration || exp.declarations[0];
var type = this.checker.getTypeOfSymbolAtLocation(exp, declaration);
var commentSource = exp;
var rootExp = this.getComponentFromExpression(exp);
var declaration = rootExp.valueDeclaration || rootExp.declarations[0];
var type = this.checker.getTypeOfSymbolAtLocation(rootExp, declaration);
var commentSource = rootExp;
var typeSymbol = type.symbol || type.aliasSymbol;
var originalName = exp.getName();
if (!exp.valueDeclaration) {
var originalName = rootExp.getName();
if (!rootExp.valueDeclaration) {
if (originalName === 'default' &&
!typeSymbol &&
(exp.flags & ts.SymbolFlags.Alias) !== 0) {
(rootExp.flags & ts.SymbolFlags.Alias) !== 0) {
commentSource = this.checker.getAliasedSymbol(commentSource);

@@ -121,4 +142,4 @@ }

else {
exp = typeSymbol;
var expName = exp.getName();
rootExp = typeSymbol;
var expName = rootExp.getName();
if (expName === '__function' ||

@@ -134,3 +155,3 @@ expName === 'StatelessComponent' ||

else {
commentSource = exp;
commentSource = rootExp;
}

@@ -152,3 +173,3 @@ }

this.extractPropsFromTypeIfStatefulComponent(type);
var nameSource = originalName === 'default' ? exp : commentSource;
var nameSource = originalName === 'default' ? rootExp : commentSource;
var resolvedComponentName = componentNameResolver(nameSource, source);

@@ -524,2 +545,11 @@ var displayName = resolvedComponentName || computeComponentName(nameSource, source);

var right = child.right;
if (right && ts.isIdentifier(right)) {
var value = source.locals.get(right.escapedText);
if (value &&
value.valueDeclaration &&
ts.isVariableDeclaration(value.valueDeclaration) &&
value.valueDeclaration.initializer) {
right = value.valueDeclaration.initializer;
}
}
if (right) {

@@ -585,3 +615,12 @@ var properties = right.properties;

: null;
case ts.SyntaxKind.PropertyAccessExpression:
case ts.SyntaxKind.PropertyAccessExpression: {
var symbol_3 = this.checker.getSymbolAtLocation(initializer);
if (symbol_3 && symbol_3.declarations.length) {
var declaration = symbol_3.declarations[0];
if (ts.isBindingElement(declaration) ||
ts.isPropertyAssignment(declaration)) {
return this.getLiteralValueFromPropertyAssignment(declaration);
}
}
}
case ts.SyntaxKind.ObjectLiteralExpression:

@@ -588,0 +627,0 @@ default:

2

package.json
{
"name": "react-docgen-typescript",
"version": "1.20.2",
"version": "1.20.3",
"description": "",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/styleguidist/react-docgen-typescript/",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc