refactor: material-parser

This commit is contained in:
wuji.xwt 2020-09-07 11:25:06 +08:00
parent 081a817aa9
commit cc180b8cce
5 changed files with 9 additions and 3 deletions

View File

@ -11,6 +11,7 @@ export default function resolveTranspiledClass(path: any) {
visitFunctionDeclaration(arg) { visitFunctionDeclaration(arg) {
classPath = new NodePath( classPath = new NodePath(
builders.functionDeclaration( builders.functionDeclaration(
// @ts-ignore
arg.node.id || 'Default', arg.node.id || 'Default',
[], [],
builders.blockStatement([ builders.blockStatement([

View File

@ -115,6 +115,7 @@ function handleTSTypeLiteral(path, typeParams) {
value: getTSTypeWithRequirements(param.get('typeAnnotation'), typeParams), value: getTSTypeWithRequirements(param.get('typeAnnotation'), typeParams),
}); });
} else if (t.TSCallSignatureDeclaration.check(param.node)) { } else if (t.TSCallSignatureDeclaration.check(param.node)) {
// @ts-ignore
type.signature.constructor = handleTSFunctionType(param, typeParams); type.signature.constructor = handleTSFunctionType(param, typeParams);
} else if (t.TSIndexSignature.check(param.node)) { } else if (t.TSIndexSignature.check(param.node)) {
type.signature.properties.push({ type.signature.properties.push({
@ -195,12 +196,14 @@ function handleTSFunctionType(path, typeParams) {
}; };
if (param.node.name === 'this') { if (param.node.name === 'this') {
// @ts-ignore
type.signature.this = arg.type; type.signature.this = arg.type;
return; return;
} }
if (param.node.type === 'RestElement') { if (param.node.type === 'RestElement') {
arg.name = param.node.argument.name; arg.name = param.node.argument.name;
// @ts-ignore
arg.rest = true; arg.rest = true;
} }
@ -288,7 +291,7 @@ function handleTSIndexedAccessType(path, typeParams) {
let visitedTypes = {}; let visitedTypes = {};
function getTSTypeWithResolvedTypes(path, typeParams) { function getTSTypeWithResolvedTypes(path, typeParams?) {
if (t.TSTypeAnnotation.check(path.node)) { if (t.TSTypeAnnotation.check(path.node)) {
path = path.get('typeAnnotation'); path = path.get('typeAnnotation');
} }
@ -343,7 +346,7 @@ function getTSTypeWithResolvedTypes(path, typeParams) {
* *
* If there is no match, "unknown" is returned. * If there is no match, "unknown" is returned.
*/ */
export default function getTSType(path, typeParamMap) { export default function getTSType(path, typeParamMap?) {
// Empty visited types before an after run // Empty visited types before an after run
// Before: in case the detection threw and we rerun again // Before: in case the detection threw and we rerun again
// After: cleanup memory after we are done here // After: cleanup memory after we are done here

View File

@ -72,6 +72,7 @@ function getDocgenTypeHelper(
}[] = symbolArr.map((prop) => { }[] = symbolArr.map((prop) => {
const propType = checker.getTypeOfSymbolAtLocation( const propType = checker.getTypeOfSymbolAtLocation(
prop, prop,
// @ts-ignore
prop.valueDeclaration || (prop.declarations && prop.declarations[0]) || {}, prop.valueDeclaration || (prop.declarations && prop.declarations[0]) || {},
); );
return { return {

View File

@ -4,7 +4,8 @@
"target": "es6", "target": "es6",
"module": "commonjs", "module": "commonjs",
"rootDir": "src", "rootDir": "src",
"outDir": "lib" "outDir": "lib",
"strict": false
}, },
"include": ["src/**/*"], "include": ["src/**/*"],
"exclude": ["schemas"] "exclude": ["schemas"]