react-docgen-typescript
Advanced tools
Comparing version
@@ -25,4 +25,4 @@ "use strict"; | ||
var opts = {}; | ||
var filterFn = (0, buildFilter_1.buildFilter)(opts); | ||
(0, chai_1.expect)([prop1, prop2, children].filter(function (prop) { | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, children].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name }); | ||
@@ -36,4 +36,4 @@ })).to.eql([prop1, prop2]); | ||
var opts = {}; | ||
var filterFn = (0, buildFilter_1.buildFilter)(opts); | ||
(0, chai_1.expect)([prop1, prop2, children].filter(function (prop) { | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, children].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name }); | ||
@@ -51,4 +51,4 @@ })).to.eql([prop1, prop2, children]); | ||
}; | ||
var filterFn = (0, buildFilter_1.buildFilter)(opts); | ||
(0, chai_1.expect)([prop1, prop2].filter(function (prop) { return filterFn(prop, { name: prop.name }); })).to.eql([prop2]); | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2].filter(function (prop) { return filterFn(prop, { name: prop.name }); })).to.eql([prop2]); | ||
}); | ||
@@ -62,4 +62,4 @@ it('should skip multiple props by name', function () { | ||
}; | ||
var filterFn = (0, buildFilter_1.buildFilter)(opts); | ||
(0, chai_1.expect)([prop1, prop2, prop3].filter(function (prop) { | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name }); | ||
@@ -76,4 +76,4 @@ })).to.eql([prop2]); | ||
}; | ||
var filterFn = (0, buildFilter_1.buildFilter)(opts); | ||
(0, chai_1.expect)([prop1, prop2].filter(function (prop) { return filterFn(prop, { name: prop.name }); })).to.eql([prop1]); | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2].filter(function (prop) { return filterFn(prop, { name: prop.name }); })).to.eql([prop1]); | ||
}); | ||
@@ -90,4 +90,4 @@ }); | ||
}; | ||
var filterFn = (0, buildFilter_1.buildFilter)(opts); | ||
(0, chai_1.expect)([prop1, prop2, prop3].filter(function (prop) { | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name }); | ||
@@ -103,4 +103,4 @@ })).to.eql([prop2]); | ||
}; | ||
var filterFn = (0, buildFilter_1.buildFilter)(opts); | ||
(0, chai_1.expect)([prop1, prop2, prop3].filter(function (prop) { | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name.toUpperCase() }); | ||
@@ -130,4 +130,4 @@ })).to.eql([prop1]); | ||
}; | ||
var filterFn = (0, buildFilter_1.buildFilter)(opts); | ||
(0, chai_1.expect)([prop1, prop2, prop3].filter(function (prop) { | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { | ||
return filterFn(prop, { name: 'SomeComponent' }); | ||
@@ -134,0 +134,0 @@ })).to.eql([prop1]); |
@@ -9,3 +9,3 @@ "use strict"; | ||
function fixturePath(componentName) { | ||
return path.join(__dirname, '..', '..', 'src', '__tests__', 'data', componentName + ".tsx"); // it's running in ./temp | ||
return path.join(__dirname, '..', '..', 'src', '__tests__', 'data', "" + componentName + (componentName.includes('.ts') ? '' : '.tsx')); // it's running in ./temp | ||
} | ||
@@ -15,3 +15,3 @@ exports.fixturePath = fixturePath; | ||
if (exactProperties === void 0) { exactProperties = true; } | ||
var result = (0, parser_1.parse)(fixturePath(componentName), parserOpts); | ||
var result = parser_1.parse(fixturePath(componentName), parserOpts); | ||
checkComponent(result, expected, exactProperties, description); | ||
@@ -103,3 +103,3 @@ } | ||
var expectedValue = expectedProp.value; | ||
if (expectedValue && !(0, lodash_1.isEqual)(expectedValue, prop.type.value)) { | ||
if (expectedValue && !lodash_1.isEqual(expectedValue, prop.type.value)) { | ||
// tslint:disable-next-line:max-line-length | ||
@@ -110,3 +110,3 @@ errors.push("Property '" + compName + "." + expectedPropName + "' value is different - expected: " + JSON.stringify(expectedValue) + ", actual: " + JSON.stringify(prop.type.value)); | ||
var propTags = prop.tags; | ||
if (expectedPropTags && !(0, lodash_1.isEqual)(expectedPropTags, propTags)) { | ||
if (expectedPropTags && !lodash_1.isEqual(expectedPropTags, propTags)) { | ||
errors.push("Property '" + compName + "." + expectedPropName + "' tags are different - expected: " + JSON.stringify(expectedPropTags) + ", actual: " + JSON.stringify(propTags)); | ||
@@ -126,5 +126,5 @@ } | ||
} | ||
(0, chai_1.assert)(ok, errors.join('\r\n')); | ||
chai_1.assert(ok, errors.join('\r\n')); | ||
} | ||
exports.checkComponent = checkComponent; | ||
//# sourceMappingURL=testUtils.js.map |
@@ -11,11 +11,11 @@ "use strict"; | ||
var input = cwd + "/src/__tests__/data/ExportsPropTypeImport.tsx"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, cwd, platform), 'react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, cwd, platform), 'react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
}); | ||
it('works with repeated path segments', function () { | ||
var input = cwd + "/react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, cwd, platform), 'react-docgen-typescript/react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, cwd, platform), 'react-docgen-typescript/react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
}); | ||
it('preserves package name from node_modules', function () { | ||
var input = cwd + "/node_modules/@types/react/index.d.ts"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, cwd, platform), 'react-docgen-typescript/node_modules/@types/react/index.d.ts'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, cwd, platform), 'react-docgen-typescript/node_modules/@types/react/index.d.ts'); | ||
}); | ||
@@ -26,7 +26,7 @@ it('preserves package name from node_modules in monorepo', function () { | ||
var input = cwd + "/node_modules/@types/react/index.d.ts"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, monorepoCwd, platform), 'react-docgen-typescript/node_modules/@types/react/index.d.ts'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, monorepoCwd, platform), 'react-docgen-typescript/node_modules/@types/react/index.d.ts'); | ||
}); | ||
it('returns full path if there is no common root', function () { | ||
var input = '/somewhere/else/foo.d.ts'; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, cwd, platform), input); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, cwd, platform), input); | ||
}); | ||
@@ -36,3 +36,3 @@ it('works when run at the root directory', function () { | ||
var input = "/src/__tests__/data/ExportsPropTypeImport.tsx"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, '/', platform), 'src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, '/', platform), 'src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
}); | ||
@@ -47,11 +47,11 @@ }); | ||
var input = cwdForwardSlash + "/src/__tests__/data/ExportsPropTypeImport.tsx"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, cwd, platform), 'react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, cwd, platform), 'react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
}); | ||
it('works with repeated path segments', function () { | ||
var input = cwdForwardSlash + "/react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, cwd, platform), 'react-docgen-typescript/react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, cwd, platform), 'react-docgen-typescript/react-docgen-typescript/src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
}); | ||
it('preserves package name from node_modules', function () { | ||
var input = cwdForwardSlash + "/node_modules/@types/react/index.d.ts"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, cwd, platform), 'react-docgen-typescript/node_modules/@types/react/index.d.ts'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, cwd, platform), 'react-docgen-typescript/node_modules/@types/react/index.d.ts'); | ||
}); | ||
@@ -61,11 +61,11 @@ it('preserves package name from node_modules in monorepo', function () { | ||
var input = cwdForwardSlash + "/node_modules/@types/react/index.d.ts"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, monorepoCwd, platform), 'react-docgen-typescript/node_modules/@types/react/index.d.ts'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, monorepoCwd, platform), 'react-docgen-typescript/node_modules/@types/react/index.d.ts'); | ||
}); | ||
it('returns full path if there is no common root', function () { | ||
var input = 'D:/somewhere/else/foo.d.ts'; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, cwd, platform), input); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, cwd, platform), input); | ||
}); | ||
it('works when run at the filesystem root', function () { | ||
var input = "C:/src/__tests__/data/ExportsPropTypeImport.tsx"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, 'C:\\', platform), 'src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, 'C:\\', platform), 'src/__tests__/data/ExportsPropTypeImport.tsx'); | ||
}); | ||
@@ -75,3 +75,3 @@ it('works with backslashes', function () { | ||
var input = cwd + "\\src\\__tests__\\data\\ExportsPropTypeImport.tsx"; | ||
chai_1.assert.equal((0, trimFileName_1.trimFileName)(input, cwd, platform), 'react-docgen-typescript\\src\\__tests__\\data\\ExportsPropTypeImport.tsx'); | ||
chai_1.assert.equal(trimFileName_1.trimFileName(input, cwd, platform), 'react-docgen-typescript\\src\\__tests__\\data\\ExportsPropTypeImport.tsx'); | ||
}); | ||
@@ -78,0 +78,0 @@ }); |
@@ -8,2 +8,3 @@ import * as ts from 'typescript'; | ||
expression?: ts.Symbol; | ||
rootExpression?: ts.Symbol; | ||
displayName: string; | ||
@@ -67,2 +68,3 @@ filePath: string; | ||
shouldExtractValuesFromUnion?: boolean; | ||
shouldSortUnions?: boolean; | ||
skipChildrenPropWithoutDoc?: boolean; | ||
@@ -113,2 +115,3 @@ savePropValueAsString?: boolean; | ||
private readonly shouldExtractValuesFromUnion; | ||
private readonly shouldSortUnions; | ||
private readonly savePropValueAsString; | ||
@@ -115,0 +118,0 @@ private readonly shouldIncludePropTagMap; |
@@ -13,10 +13,6 @@ "use strict"; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -105,8 +101,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function Parser(program, opts) { | ||
var savePropValueAsString = opts.savePropValueAsString, shouldExtractLiteralValuesFromEnum = opts.shouldExtractLiteralValuesFromEnum, shouldRemoveUndefinedFromOptional = opts.shouldRemoveUndefinedFromOptional, shouldExtractValuesFromUnion = opts.shouldExtractValuesFromUnion, shouldIncludePropTagMap = opts.shouldIncludePropTagMap, shouldIncludeExpression = opts.shouldIncludeExpression; | ||
var savePropValueAsString = opts.savePropValueAsString, shouldExtractLiteralValuesFromEnum = opts.shouldExtractLiteralValuesFromEnum, shouldRemoveUndefinedFromOptional = opts.shouldRemoveUndefinedFromOptional, shouldExtractValuesFromUnion = opts.shouldExtractValuesFromUnion, shouldSortUnions = opts.shouldSortUnions, shouldIncludePropTagMap = opts.shouldIncludePropTagMap, shouldIncludeExpression = opts.shouldIncludeExpression; | ||
this.checker = program.getTypeChecker(); | ||
this.propFilter = (0, buildFilter_1.buildFilter)(opts); | ||
this.propFilter = buildFilter_1.buildFilter(opts); | ||
this.shouldExtractLiteralValuesFromEnum = Boolean(shouldExtractLiteralValuesFromEnum); | ||
this.shouldRemoveUndefinedFromOptional = Boolean(shouldRemoveUndefinedFromOptional); | ||
this.shouldExtractValuesFromUnion = Boolean(shouldExtractValuesFromUnion); | ||
this.shouldSortUnions = Boolean(shouldSortUnions); | ||
this.savePropValueAsString = Boolean(savePropValueAsString); | ||
@@ -165,6 +162,8 @@ this.shouldIncludePropTagMap = Boolean(shouldIncludePropTagMap); | ||
'StyledComponent', | ||
'IStyledComponent', | ||
'FunctionComponent', | ||
'ForwardRefExoticComponent' | ||
'ForwardRefExoticComponent', | ||
'MemoExoticComponent' | ||
]; | ||
var supportedComponentTypes = __spreadArray(__spreadArray([], defaultComponentTypes, true), customComponentTypes, true); | ||
var supportedComponentTypes = __spreadArray(__spreadArray([], defaultComponentTypes), customComponentTypes); | ||
if (supportedComponentTypes.indexOf(expName) !== -1) { | ||
@@ -234,2 +233,3 @@ commentSource = this.checker.getAliasedSymbol(commentSource); | ||
result.expression = rootExp; | ||
result.rootExpression = exp; | ||
} | ||
@@ -407,2 +407,7 @@ return result; | ||
} | ||
if (this.shouldSortUnions) { | ||
value.sort(function (a, b) { | ||
return a.value.toString().localeCompare(b.value.toString()); | ||
}); | ||
} | ||
return { | ||
@@ -431,8 +436,8 @@ name: 'enum', | ||
propertiesOfProps = __spreadArray(__spreadArray([], (propertiesOfProps = this | ||
.checker.getAllPossiblePropertiesOfTypes(propsType.types)), true), baseProps, true); | ||
.checker.getAllPossiblePropertiesOfTypes(propsType.types))), baseProps); | ||
if (!propertiesOfProps.length) { | ||
var subTypes = this.checker.getAllPossiblePropertiesOfTypes(propsType.types.reduce( | ||
// @ts-ignore | ||
function (all, t) { return __spreadArray(__spreadArray([], all, true), (t.types || []), true); }, [])); | ||
propertiesOfProps = __spreadArray(__spreadArray([], subTypes, true), baseProps, true); | ||
function (all, t) { return __spreadArray(__spreadArray([], all), (t.types || [])); }, [])); | ||
propertiesOfProps = __spreadArray(__spreadArray([], subTypes), baseProps); | ||
} | ||
@@ -475,3 +480,4 @@ } | ||
: jsDocComment.fullComment.replace(/\r\n/g, '\n'); | ||
result[propName] = __assign({ defaultValue: defaultValue, description: description, name: propName, parent: parent, declarations: parents, required: required, type: type }, propTags); | ||
result[propName] = __assign({ defaultValue: defaultValue, description: description, name: propName, parent: parent, declarations: parents, required: required, | ||
type: type }, propTags); | ||
}); | ||
@@ -557,3 +563,3 @@ return result; | ||
return _this.checker.getSymbolAtLocation(stmt.name) === symbol; | ||
}), true), source.statements.filter(function (stmt) { return ts.isExpressionStatement(stmt) || ts.isVariableStatement(stmt); }), true); | ||
})), source.statements.filter(function (stmt) { return ts.isExpressionStatement(stmt) || ts.isVariableStatement(stmt); })); | ||
return possibleStatements.reduce(function (res, statement) { | ||
@@ -836,7 +842,9 @@ if (statementIsClassDeclaration(statement) && statement.members.length) { | ||
'StyledComponent', | ||
'IStyledComponent', | ||
'FunctionComponent', | ||
'StatelessComponent', | ||
'ForwardRefExoticComponent' | ||
'ForwardRefExoticComponent', | ||
'MemoExoticComponent' | ||
]; | ||
var supportedComponentTypes = __spreadArray(__spreadArray([], defaultComponentTypes, true), customComponentTypes, true); | ||
var supportedComponentTypes = __spreadArray(__spreadArray([], defaultComponentTypes), customComponentTypes); | ||
if (supportedComponentTypes.indexOf(exportName) !== -1) { | ||
@@ -851,3 +859,3 @@ return getDefaultExportForFile(source); | ||
function getDefaultExportForFile(source) { | ||
var name = path.basename(source.fileName, path.extname(source.fileName)); | ||
var name = path.basename(source.fileName).split('.')[0]; | ||
var filename = name === 'index' ? path.basename(path.dirname(source.fileName)) : name; | ||
@@ -882,3 +890,3 @@ // JS identifiers must starts with a letter, and contain letters and/or numbers | ||
parents.push({ | ||
fileName: (0, trimFileName_1.trimFileName)(fileName), | ||
fileName: trimFileName_1.trimFileName(fileName), | ||
name: parentName | ||
@@ -902,3 +910,3 @@ }); | ||
return { | ||
fileName: (0, trimFileName_1.trimFileName)(fileName), | ||
fileName: trimFileName_1.trimFileName(fileName), | ||
name: parentName | ||
@@ -955,3 +963,4 @@ }; | ||
if (doc) { | ||
componentDocs.push(__assign(__assign({}, doc), { displayName: exp.escapedName + "." + symbol.escapedName })); | ||
var prefix = exp.escapedName === 'default' ? '' : exp.escapedName + "."; | ||
componentDocs.push(__assign(__assign({}, doc), { displayName: "" + prefix + symbol.escapedName })); | ||
} | ||
@@ -967,3 +976,3 @@ }); | ||
return prevVal; | ||
return __spreadArray(__spreadArray([], prevVal, true), [comp], false); | ||
return __spreadArray(__spreadArray([], prevVal), [comp]); | ||
}, []); | ||
@@ -975,5 +984,5 @@ var filteredComponentDocs = componentDocsNoDuplicates.filter(function (comp, index, comps) { | ||
}); | ||
return __spreadArray(__spreadArray([], docs, true), filteredComponentDocs, true); | ||
return __spreadArray(__spreadArray([], docs), filteredComponentDocs); | ||
}, []); | ||
} | ||
//# sourceMappingURL=parser.js.map |
@@ -10,5 +10,5 @@ "use strict"; | ||
function parse(fileName) { | ||
return (0, parser_1.parse)(fileName); | ||
return parser_1.parse(fileName); | ||
} | ||
exports.parse = parse; | ||
//# sourceMappingURL=propTypesParser.js.map |
{ | ||
"name": "react-docgen-typescript", | ||
"version": "2.2.2", | ||
"version": "2.2.3-beta.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/styleguidist/react-docgen-typescript/", |
@@ -143,2 +143,6 @@ # react-docgen-typescript | ||
### `shouldSortUnions`: boolean | ||
When used in combination with `shouldExtractValuesFromUnion` or `shouldExtractLiteralValuesFromEnum`, sorts union members in string-sort order when set to true. This is useful for ensuring the same order of members every time. | ||
### `skipChildrenPropWithoutDoc`: boolean (default: `true`) | ||
@@ -145,0 +149,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
245131
1.15%3166
2.23%284
1.43%45
-11.76%1
Infinity%