diff --git a/package.json b/package.json index 15cd49458..a7edc4a3d 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "prettier": "^1.15.3", "rimraf": "^2.6.3", "ts-node": "^7.0.1", + "tslint": "^6.1.0", + "tslint-config-prettier": "^1.18.0", "typescript": "^3.2.2" }, "engines": { diff --git a/packages/material-parser/src/generator/Generator.ts b/packages/material-parser/src/generator/Generator.ts index 9d69ecf3b..bec97c827 100644 --- a/packages/material-parser/src/generator/Generator.ts +++ b/packages/material-parser/src/generator/Generator.ts @@ -93,7 +93,6 @@ class Generator implements IGenerator { matParsedModel: IMaterialParsedModel, ): Promise<{ manifestFilePath: string; // manifest 文件路径 - manifestJS: string; // manifest 文件内容 manifestObj: IComponentMaterial; // manifest 文件对象 }> { const manifestObj: Partial = { @@ -127,7 +126,6 @@ class Generator implements IGenerator { }, ); return { - manifestJS: manifest.manifestJS, manifestObj: manifest.manifestObj, manifestFilePath: manifest.manifestFilePath, }; diff --git a/packages/material-parser/src/parser/ReactParser.ts b/packages/material-parser/src/parser/ReactParser.ts index ca1418f16..5ececea15 100644 --- a/packages/material-parser/src/parser/ReactParser.ts +++ b/packages/material-parser/src/parser/ReactParser.ts @@ -15,6 +15,7 @@ import { } from '../types'; import BaseParser from './BaseParser'; import resolver from './resolver'; +import handlers from './handlers'; const log = debug.extend('mat'); const parser = buildParser(); @@ -75,7 +76,10 @@ function transformItem(name: string, item: any): any { result.description = description; } if (defaultValue) { - result.defaultValue = defaultValue.value; + try { + const value = eval(defaultValue.value); + result.defaultValue = value; + } catch (e) {} } return result; @@ -179,8 +183,12 @@ class ReactParser extends BaseParser { item => item.filePath === model.mainEntry, ); - const result = reactDocs.parse(mainEntryItem.fileContent, resolver); - const props = Object.keys(result.props).map(name => { + const result = reactDocs.parse( + mainEntryItem.fileContent, + resolver, + handlers, + ); + const props = Object.keys(result.props || {}).map(name => { return transformItem(name, result.props[name]); }); @@ -529,20 +537,17 @@ class ReactParser extends BaseParser { fileContent: string; }): Promise { const ast = parser.parse(params.fileContent); - const result = reactDocs.parse(params.fileContent, resolver); - // @ts-ignore - // ast.__src = params.fileContent; - const props = Object.keys(result.props).map(name => { + const result = reactDocs.parse(params.fileContent, resolver, handlers); + const props = Object.keys(result.props || {}).map(name => { return transformItem(name, result.props[name]); }); - // const defaultExportName = await this.parseDefaultExportNameES6(ast); + const defaultExportName = await this.parseDefaultExportNameES6(ast); // const subModules = await this.parseSubModulesES6(ast); return { filePath: params.filePath, - // defaultExportName, + defaultExportName, // subModules, - // propsTypes, props, } as any; } diff --git a/packages/material-parser/src/parser/handlers/index.ts b/packages/material-parser/src/parser/handlers/index.ts new file mode 100644 index 000000000..a4ff85a6c --- /dev/null +++ b/packages/material-parser/src/parser/handlers/index.ts @@ -0,0 +1,22 @@ +const { handlers } = require('react-docgen'); +import { + propTypeHandler, + contextTypeHandler, + childContextTypeHandler, +} from './propTypeHandler'; + +const defaultHandlers = [ + propTypeHandler, + contextTypeHandler, + childContextTypeHandler, + handlers.propTypeCompositionHandler, + handlers.propDocBlockHandler, + handlers.flowTypeHandler, + handlers.defaultPropsHandler, + handlers.componentDocblockHandler, + handlers.displayNameHandler, + handlers.componentMethodsHandler, + handlers.componentMethodsJsDocHandler, +]; + +export default defaultHandlers; diff --git a/packages/material-parser/src/parser/handlers/propTypeHandler.ts b/packages/material-parser/src/parser/handlers/propTypeHandler.ts new file mode 100644 index 000000000..619a88eb4 --- /dev/null +++ b/packages/material-parser/src/parser/handlers/propTypeHandler.ts @@ -0,0 +1,136 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import { namedTypes as t, visit } from 'ast-types'; +import { throwStatement } from '@babel/types'; +const { + resolveToValue, + getPropType, + getPropertyName, + getMemberValuePath, + isReactModuleName, + printValue, + resolveToModule, +} = require('react-docgen').utils; + +const isRequiredPropType = require('react-docgen/dist/utils/isRequiredPropType') + .default; + +function getRoot(node: any) { + let root = node.parent; + while (root.parent) { + root = root.parent; + } + return root; +} +// import type Documentation from '../Documentation'; + +function isPropTypesExpression(path: any) { + const moduleName = resolveToModule(path); + if (moduleName) { + return isReactModuleName(moduleName) || moduleName === 'ReactPropTypes'; + } + return false; +} + +function amendPropTypes(getDescriptor: any, path: any) { + if (!t.ObjectExpression.check(path.node)) { + return; + } + + path.get('properties').each((propertyPath: any) => { + switch (propertyPath.node.type) { + // @ts-ignore + case t.Property.name: { + const propName = getPropertyName(propertyPath); + if (!propName) return; + + const propDescriptor = getDescriptor(propName); + const valuePath = propertyPath.get('value'); + const type = isPropTypesExpression(valuePath) + ? getPropType(valuePath) + : { name: 'custom', raw: printValue(valuePath) }; + + if (type) { + propDescriptor.type = type; + propDescriptor.required = + type.name !== 'custom' && isRequiredPropType(valuePath); + } + break; + } + // @ts-ignore + case t.SpreadElement.name: { + const resolvedValuePath = resolveToValue(propertyPath.get('argument')); + switch (resolvedValuePath.node.type) { + // @ts-ignore + case t.ObjectExpression.name: // normal object literal + amendPropTypes(getDescriptor, resolvedValuePath); + break; + } + break; + } + } + }); +} + +function getDefinePropertyValuePath(nodePath: any, propName: string) { + const program = getRoot(nodePath); + const componentName = nodePath.node.id.name; + let resultPath = nodePath; + + visit(program, { + visitCallExpression: function(path) { + const args = path.get('arguments'); + const argsNodeList = args.value; + if ( + argsNodeList.length === 3 && + t.Identifier.check(argsNodeList[0]) && + argsNodeList[0].name === componentName && + t.Literal.check(argsNodeList[1]) && + argsNodeList[1].value === propName + ) { + resultPath = args.get(2); + } + return false; + }, + }); + return resultPath; +} + +function getPropTypeHandler(propName: string) { + return function(documentation: any, path: any) { + let propTypesPath = getMemberValuePath(path, propName); + if (!propTypesPath) { + propTypesPath = getDefinePropertyValuePath(path, propName); + if (!propTypesPath) { + return; + } + } + propTypesPath = resolveToValue(propTypesPath); + if (!propTypesPath) { + return; + } + let getDescriptor; + switch (propName) { + case 'childContextTypes': + getDescriptor = documentation.getChildContextDescriptor; + break; + case 'contextTypes': + getDescriptor = documentation.getContextDescriptor; + break; + default: + getDescriptor = documentation.getPropDescriptor; + } + amendPropTypes(getDescriptor.bind(documentation), propTypesPath); + }; +} + +export const propTypeHandler = getPropTypeHandler('propTypes'); +export const contextTypeHandler = getPropTypeHandler('contextTypes'); +export const childContextTypeHandler = getPropTypeHandler('childContextTypes'); diff --git a/packages/material-parser/src/parser/resolver/checkIsIIFE.ts b/packages/material-parser/src/parser/resolver/checkIsIIFE.ts index 7862aeffd..a3182be8c 100644 --- a/packages/material-parser/src/parser/resolver/checkIsIIFE.ts +++ b/packages/material-parser/src/parser/resolver/checkIsIIFE.ts @@ -1,7 +1,7 @@ -module.exports = function checkIsIIFE(path: any) { +export default function checkIsIIFE(path: any) { return ( path.value.callee && path.value.callee.type === 'FunctionExpression' && path.node.type === 'CallExpression' ); -}; +} diff --git a/packages/material-parser/src/parser/resolver/index.ts b/packages/material-parser/src/parser/resolver/index.ts index 24c6aed9c..b16a99fd4 100644 --- a/packages/material-parser/src/parser/resolver/index.ts +++ b/packages/material-parser/src/parser/resolver/index.ts @@ -17,6 +17,7 @@ const { resolveExportDeclaration, resolveToValue, } = require('react-docgen').utils; +import checkIsIIFE from './checkIsIIFE'; import resolveHOC from './resolveHOC'; import resolveIIFE from './resolveIIFE'; import resolveTranspiledClass from './resolveTranspiledClass'; @@ -56,6 +57,29 @@ function resolveDefinition(definition: any) { return null; } +function getDefinition(definition: any) { + if (checkIsIIFE(definition)) { + definition = resolveToValue(resolveIIFE(definition)); + if (!isComponentDefinition(definition)) { + definition = resolveTranspiledClass(definition); + } + } else { + definition = resolveToValue(resolveHOC(definition)); + if (checkIsIIFE(definition)) { + definition = resolveToValue(resolveIIFE(definition)); + if (!isComponentDefinition(definition)) { + definition = resolveTranspiledClass(definition); + } + } + } + // definition = resolveToValue(resolveIIFE(definition)); + // if (!isComponentDefinition(definition)) { + // definition = resolveTranspiledClass(definition); + // } + // definition = resolveToValue(resolveHOC(definition)); + + return definition; +} /** * Given an AST, this function tries to find the exported component definition. * @@ -80,13 +104,9 @@ export default function findExportedComponentDefinition(ast: any) { if (isComponentDefinition(definition)) { acc.push(definition); } else { - // definition = resolveToValue(resolveIIFE(definition)); - // if (!isComponentDefinition(definition)) { - // definition = resolveTranspiledClass(definition); - // } - const resolved = resolveToValue(resolveHOC(definition)); - if (isComponentDefinition(resolved)) { - acc.push(resolved); + definition = getDefinition(definition); + if (isComponentDefinition(definition)) { + acc.push(definition); } } return acc; @@ -133,15 +153,7 @@ export default function findExportedComponentDefinition(ast: any) { // expression, something like React.createClass path = resolveToValue(path.get('right')); if (!isComponentDefinition(path)) { - // path = resolveToValue(resolveHOC(path)); - // if (!isComponentDefinition(path)) { - path = resolveToValue(resolveIIFE(path)); - if (!isComponentDefinition(path)) { - path = resolveTranspiledClass(path); - if (!isComponentDefinition(path)) { - path = resolveToValue(resolveHOC(path)); - } - } + path = getDefinition(path); } if (foundDefinition) { // If a file exports multiple components, ... complain! diff --git a/packages/material-parser/src/parser/resolver/resolveHOC.ts b/packages/material-parser/src/parser/resolver/resolveHOC.ts index 63df72e10..a5538a91f 100644 --- a/packages/material-parser/src/parser/resolver/resolveHOC.ts +++ b/packages/material-parser/src/parser/resolver/resolveHOC.ts @@ -38,11 +38,13 @@ export default function resolveHOC(path: any): any { t.SpreadElement.check(inner.node)) ) { return resolveHOC( - resolveToValue(path.get('arguments', node.arguments.length - 1)), + // resolveToValue(path.get('arguments', node.arguments.length - 1)), + path.get('arguments', node.arguments.length - 1), ); } - return resolveHOC(resolveToValue(inner)); + // return resolveHOC(resolveToValue(inner)); + return resolveHOC(inner); } } diff --git a/packages/material-parser/src/parser/resolver/resolveIIFE.ts b/packages/material-parser/src/parser/resolver/resolveIIFE.ts index ba3ad384b..011328600 100644 --- a/packages/material-parser/src/parser/resolver/resolveIIFE.ts +++ b/packages/material-parser/src/parser/resolver/resolveIIFE.ts @@ -14,7 +14,7 @@ const resolveFunctionDefinitionToReturnValue = require('react-docgen/dist/utils/ // resolveToValue, // resolveHOC -const checkIsIIFE = require('./checkIsIIFE'); +import checkIsIIFE from './checkIsIIFE'; /** * If the path is a call expression, it recursively resolves to the * rightmost argument, stopping if it finds a React.createClass call expression diff --git a/packages/material-parser/src/scanner/Scanner.ts b/packages/material-parser/src/scanner/Scanner.ts index 6c26b0bf2..880678e13 100644 --- a/packages/material-parser/src/scanner/Scanner.ts +++ b/packages/material-parser/src/scanner/Scanner.ts @@ -42,9 +42,9 @@ class Scanner implements IScanner { const isDepsMode = cwd !== entry; const pkgJsonPath = join(cwd, 'package.json'); // 判断是否存在 package.json - if (!(await pathExists(pkgJsonPath))) { - throw new Error(`Cannot find package.json. ${pkgJsonPath}`); - } + // if (!(await pathExists(pkgJsonPath))) { + // throw new Error(`Cannot find package.json. ${pkgJsonPath}`); + // } // 读取 package.json let pkgJson = await this.resolvePkgJson(pkgJsonPath); model.pkgName = pkgJson.name; @@ -69,10 +69,10 @@ class Scanner implements IScanner { log('entryFile', entryFile); model.mainEntry = entryFilePath; // 记录入口文件 - // model.modules.push({ - // filePath: entryFilePath, - // fileContent: entryFile, - // }); + model.modules.push({ + filePath: entryFilePath, + fileContent: entryFile, + }); log('model', model); // debugger; if (options.isExportedAsMultiple) { @@ -82,7 +82,7 @@ class Scanner implements IScanner { entryFilePath, sourceType: model.sourceType, }); - model.modules.push(...modules); + model.modules = [...modules]; } log('model', model); return model; diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/Materialize.ts.md b/packages/material-parser/test/fixtures/__snapshots__/test/Materialize.ts.md index 68246f0eb..7a2d6f6db 100644 --- a/packages/material-parser/test/fixtures/__snapshots__/test/Materialize.ts.md +++ b/packages/material-parser/test/fixtures/__snapshots__/test/Materialize.ts.md @@ -8,4 +8,181 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 - [] + [ + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js', + package: 'single-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'optionalArray', + propType: 'array', + }, + { + name: 'optionalBool', + propType: 'bool', + }, + { + name: 'optionalFunc', + propType: 'func', + }, + { + defaultValue: 123, + name: 'optionalNumber', + propType: 'number', + }, + { + name: 'optionalObject', + propType: 'object', + }, + { + name: 'optionalString', + propType: 'string', + }, + { + name: 'optionalSymbol', + propType: 'symbol', + }, + { + name: 'optionalNode', + propType: 'node', + }, + { + name: 'optionalElement', + propType: 'element', + }, + { + name: 'optionalElementType', + propType: 'elementType', + }, + { + name: 'optionalMessage', + propType: { + type: 'instanceOf', + value: 'Demo', + }, + }, + { + name: 'optionalEnum', + propType: { + type: 'oneOf', + value: [ + 'News', + 'Photos', + ], + }, + }, + { + name: 'optionalUnion', + propType: { + type: 'oneOfType', + value: [ + 'string', + 'number', + { + type: 'instanceOf', + value: 'Demo', + }, + ], + }, + }, + { + name: 'optionalArrayOf', + propType: { + type: 'arrayOf', + value: 'number', + }, + }, + { + name: 'optionalObjectOf', + propType: { + type: 'objectOf', + value: 'number', + }, + }, + { + name: 'optionalObjectWithShape', + propType: { + type: 'shape', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'optionalObjectWithShape2', + propType: { + isRequired: true, + type: 'shape', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'optionalObjectWithStrictShape', + propType: { + type: 'exact', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'requiredFunc', + propType: { + isRequired: true, + type: 'func', + }, + }, + { + name: 'requiredAny', + propType: { + isRequired: true, + type: 'any', + }, + }, + ], + screenshot: '', + title: 'single-exported-component', + }, + }, + ] diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/Materialize.ts.snap b/packages/material-parser/test/fixtures/__snapshots__/test/Materialize.ts.snap index f342695c9..c49d07908 100644 Binary files a/packages/material-parser/test/fixtures/__snapshots__/test/Materialize.ts.snap and b/packages/material-parser/test/fixtures/__snapshots__/test/Materialize.ts.snap differ diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/accesser/LocalAccesser.ts.md b/packages/material-parser/test/fixtures/__snapshots__/test/accesser/LocalAccesser.ts.md index 1ea353a7d..27bbbe3db 100644 --- a/packages/material-parser/test/fixtures/__snapshots__/test/accesser/LocalAccesser.ts.md +++ b/packages/material-parser/test/fixtures/__snapshots__/test/accesser/LocalAccesser.ts.md @@ -8,4 +8,181 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 - [] + [ + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js', + package: '@ali/lowcode-engine-material-parser', + subName: '', + version: '0.1.0', + }, + props: [ + { + name: 'optionalArray', + propType: 'array', + }, + { + name: 'optionalBool', + propType: 'bool', + }, + { + name: 'optionalFunc', + propType: 'func', + }, + { + defaultValue: 123, + name: 'optionalNumber', + propType: 'number', + }, + { + name: 'optionalObject', + propType: 'object', + }, + { + name: 'optionalString', + propType: 'string', + }, + { + name: 'optionalSymbol', + propType: 'symbol', + }, + { + name: 'optionalNode', + propType: 'node', + }, + { + name: 'optionalElement', + propType: 'element', + }, + { + name: 'optionalElementType', + propType: 'elementType', + }, + { + name: 'optionalMessage', + propType: { + type: 'instanceOf', + value: 'Demo', + }, + }, + { + name: 'optionalEnum', + propType: { + type: 'oneOf', + value: [ + 'News', + 'Photos', + ], + }, + }, + { + name: 'optionalUnion', + propType: { + type: 'oneOfType', + value: [ + 'string', + 'number', + { + type: 'instanceOf', + value: 'Demo', + }, + ], + }, + }, + { + name: 'optionalArrayOf', + propType: { + type: 'arrayOf', + value: 'number', + }, + }, + { + name: 'optionalObjectOf', + propType: { + type: 'objectOf', + value: 'number', + }, + }, + { + name: 'optionalObjectWithShape', + propType: { + type: 'shape', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'optionalObjectWithShape2', + propType: { + isRequired: true, + type: 'shape', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'optionalObjectWithStrictShape', + propType: { + type: 'exact', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'requiredFunc', + propType: { + isRequired: true, + type: 'func', + }, + }, + { + name: 'requiredAny', + propType: { + isRequired: true, + type: 'any', + }, + }, + ], + screenshot: '', + title: '@ali/lowcode-engine-material-parser', + }, + }, + ] diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/accesser/LocalAccesser.ts.snap b/packages/material-parser/test/fixtures/__snapshots__/test/accesser/LocalAccesser.ts.snap index d369f481a..368768b7c 100644 Binary files a/packages/material-parser/test/fixtures/__snapshots__/test/accesser/LocalAccesser.ts.snap and b/packages/material-parser/test/fixtures/__snapshots__/test/accesser/LocalAccesser.ts.snap differ diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/generator/Generator.ts.md b/packages/material-parser/test/fixtures/__snapshots__/test/generator/Generator.ts.md index 064c32d38..d01bf610e 100644 --- a/packages/material-parser/test/fixtures/__snapshots__/test/generator/Generator.ts.md +++ b/packages/material-parser/test/fixtures/__snapshots__/test/generator/Generator.ts.md @@ -4,8 +4,1132 @@ The actual snapshot is saved in `Generator.ts.snap`. Generated by [AVA](https://avajs.dev). +## generate multiple exported components + +> Snapshot 1 + + [ + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeBlank/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleFlexLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + { + name: 'id', + propType: 'string', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeIcon/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'className', + propType: 'string', + }, + { + name: 'iconClassName', + propType: 'string', + }, + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleText', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeImage/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeLink/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleText', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakePlaceholder/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeText/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + 'string', + ], + }, + }, + { + name: 'type', + propType: 'string', + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleText', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/Root/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'style', + propType: 'object', + }, + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + 'element', + { + type: 'arrayOf', + value: 'element', + }, + ], + }, + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + ] + +## generate multiple exported components with extensions + +> Snapshot 1 + + [ + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeBlank/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleFlexLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + { + name: 'id', + propType: 'string', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeIcon/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'className', + propType: 'string', + }, + { + name: 'iconClassName', + propType: 'string', + }, + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleText', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeImage/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeLink/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleText', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakePlaceholder/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeText/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + 'string', + ], + }, + }, + { + name: 'type', + propType: 'string', + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleText', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/Root/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', + package: 'multiple-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'style', + propType: 'object', + }, + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + 'element', + { + type: 'arrayOf', + value: 'element', + }, + ], + }, + }, + ], + screenshot: '', + title: 'multiple-exported-component', + }, + }, + ] + ## generate single exported components > Snapshot 1 - [] + [ + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js', + package: 'single-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'optionalArray', + propType: 'array', + }, + { + name: 'optionalBool', + propType: 'bool', + }, + { + name: 'optionalFunc', + propType: 'func', + }, + { + defaultValue: 123, + name: 'optionalNumber', + propType: 'number', + }, + { + name: 'optionalObject', + propType: 'object', + }, + { + name: 'optionalString', + propType: 'string', + }, + { + name: 'optionalSymbol', + propType: 'symbol', + }, + { + name: 'optionalNode', + propType: 'node', + }, + { + name: 'optionalElement', + propType: 'element', + }, + { + name: 'optionalElementType', + propType: 'elementType', + }, + { + name: 'optionalMessage', + propType: { + type: 'instanceOf', + value: 'Demo', + }, + }, + { + name: 'optionalEnum', + propType: { + type: 'oneOf', + value: [ + 'News', + 'Photos', + ], + }, + }, + { + name: 'optionalUnion', + propType: { + type: 'oneOfType', + value: [ + 'string', + 'number', + { + type: 'instanceOf', + value: 'Demo', + }, + ], + }, + }, + { + name: 'optionalArrayOf', + propType: { + type: 'arrayOf', + value: 'number', + }, + }, + { + name: 'optionalObjectOf', + propType: { + type: 'objectOf', + value: 'number', + }, + }, + { + name: 'optionalObjectWithShape', + propType: { + type: 'shape', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'optionalObjectWithShape2', + propType: { + isRequired: true, + type: 'shape', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'optionalObjectWithStrictShape', + propType: { + type: 'exact', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'requiredFunc', + propType: { + isRequired: true, + type: 'func', + }, + }, + { + name: 'requiredAny', + propType: { + isRequired: true, + type: 'any', + }, + }, + ], + screenshot: '', + title: 'single-exported-component', + }, + }, + ] + +## generate single exported components with extensions + +> Snapshot 1 + + [ + { + manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/src/manifest.json', + manifestObj: { + docUrl: '', + npm: { + destructuring: false, + exportName: '', + main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js', + package: 'single-exported-component', + subName: '', + version: '1.0.0', + }, + props: [ + { + name: 'optionalArray', + propType: 'array', + }, + { + name: 'optionalBool', + propType: 'bool', + }, + { + name: 'optionalFunc', + propType: 'func', + }, + { + defaultValue: 123, + name: 'optionalNumber', + propType: 'number', + }, + { + name: 'optionalObject', + propType: 'object', + }, + { + name: 'optionalString', + propType: 'string', + }, + { + name: 'optionalSymbol', + propType: 'symbol', + }, + { + name: 'optionalNode', + propType: 'node', + }, + { + name: 'optionalElement', + propType: 'element', + }, + { + name: 'optionalElementType', + propType: 'elementType', + }, + { + name: 'optionalMessage', + propType: { + type: 'instanceOf', + value: 'Demo', + }, + }, + { + name: 'optionalEnum', + propType: { + type: 'oneOf', + value: [ + 'News', + 'Photos', + ], + }, + }, + { + name: 'optionalUnion', + propType: { + type: 'oneOfType', + value: [ + 'string', + 'number', + { + type: 'instanceOf', + value: 'Demo', + }, + ], + }, + }, + { + name: 'optionalArrayOf', + propType: { + type: 'arrayOf', + value: 'number', + }, + }, + { + name: 'optionalObjectOf', + propType: { + type: 'objectOf', + value: 'number', + }, + }, + { + name: 'optionalObjectWithShape', + propType: { + type: 'shape', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'optionalObjectWithShape2', + propType: { + isRequired: true, + type: 'shape', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'optionalObjectWithStrictShape', + propType: { + type: 'exact', + value: [ + { + name: 'optionalProperty', + propType: 'string', + }, + { + name: 'requiredProperty', + propType: { + isRequired: true, + type: 'number', + }, + }, + ], + }, + }, + { + name: 'requiredFunc', + propType: { + isRequired: true, + type: 'func', + }, + }, + { + name: 'requiredAny', + propType: { + isRequired: true, + type: 'any', + }, + }, + ], + screenshot: '', + title: 'single-exported-component', + }, + }, + ] diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/generator/Generator.ts.snap b/packages/material-parser/test/fixtures/__snapshots__/test/generator/Generator.ts.snap index c05b27d87..6da53d5f1 100644 Binary files a/packages/material-parser/test/fixtures/__snapshots__/test/generator/Generator.ts.snap and b/packages/material-parser/test/fixtures/__snapshots__/test/generator/Generator.ts.snap differ diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/parser/ReactParser.ts.md b/packages/material-parser/test/fixtures/__snapshots__/test/parser/ReactParser.ts.md index 5b7e05ec9..6a6806c56 100644 --- a/packages/material-parser/test/fixtures/__snapshots__/test/parser/ReactParser.ts.md +++ b/packages/material-parser/test/fixtures/__snapshots__/test/parser/ReactParser.ts.md @@ -4,12 +4,311 @@ The actual snapshot is saved in `ReactParser.ts.snap`. Generated by [AVA](https://avajs.dev). +## parse es6 multiple exported component by local + +> Snapshot 1 + + [ + { + defaultExportName: 'AIMakeBlank', + filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeBlank/index.js', + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleFlexLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + { + name: 'id', + propType: 'string', + }, + ], + }, + { + defaultExportName: 'AIMakeIcon', + filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeIcon/index.js', + props: [ + { + name: 'className', + propType: 'string', + }, + { + name: 'iconClassName', + propType: 'string', + }, + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleText', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + }, + { + defaultExportName: 'AIMakeImage', + filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeImage/index.js', + props: [ + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + }, + { + defaultExportName: 'AIMakeLink', + filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeLink/index.js', + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleText', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + }, + { + defaultExportName: 'AIMakePlaceholder', + filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakePlaceholder/index.js', + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + ], + }, + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + }, + { + defaultExportName: 'AIMakeText', + filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeText/index.js', + props: [ + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + { + type: 'arrayOf', + value: 'node', + }, + 'node', + 'string', + ], + }, + }, + { + name: 'type', + propType: 'string', + }, + { + name: 'styleBoxModel', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleText', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleLayout', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'styleBackground', + propType: { + isRequired: true, + type: 'object', + }, + }, + { + name: 'style', + propType: 'object', + }, + ], + }, + { + defaultExportName: 'Root', + filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/Root/index.js', + props: [ + { + name: 'style', + propType: 'object', + }, + { + name: 'children', + propType: { + type: 'oneOfType', + value: [ + 'element', + { + type: 'arrayOf', + value: 'element', + }, + ], + }, + }, + ], + }, + ] + ## parse es6 single exported component by local > Snapshot 1 [ { + defaultExportName: 'Demo', filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js', props: [ { @@ -25,7 +324,7 @@ Generated by [AVA](https://avajs.dev). propType: 'func', }, { - defaultValue: '123', + defaultValue: 123, name: 'optionalNumber', propType: 'number', }, @@ -73,7 +372,7 @@ Generated by [AVA](https://avajs.dev). { name: 'optionalUnion', propType: { - type: 'union', + type: 'oneOfType', value: [ 'string', 'number', diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/parser/ReactParser.ts.snap b/packages/material-parser/test/fixtures/__snapshots__/test/parser/ReactParser.ts.snap index 5b72f473c..452d8b7a8 100644 Binary files a/packages/material-parser/test/fixtures/__snapshots__/test/parser/ReactParser.ts.snap and b/packages/material-parser/test/fixtures/__snapshots__/test/parser/ReactParser.ts.snap differ diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/scanner/Scanner.ts.md b/packages/material-parser/test/fixtures/__snapshots__/test/scanner/Scanner.ts.md index 8b8752e4b..e047efd48 100644 --- a/packages/material-parser/test/fixtures/__snapshots__/test/scanner/Scanner.ts.md +++ b/packages/material-parser/test/fixtures/__snapshots__/test/scanner/Scanner.ts.md @@ -11,18 +11,6 @@ Generated by [AVA](https://avajs.dev). { mainEntry: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', modules: [ - { - fileContent: `import AIMakeBlank from './basic/AIMakeBlank';␊ - import AIMakeIcon from './basic/AIMakeIcon';␊ - import AIMakeImage from './basic/AIMakeImage';␊ - import AIMakeLink from './basic/AIMakeLink';␊ - import AIMakePlaceholder from './basic/AIMakePlaceholder';␊ - import AIMakeText from './basic/AIMakeText';␊ - import Root from './basic/Root';␊ - export { AIMakeBlank, AIMakeIcon, AIMakeImage, AIMakeLink, AIMakePlaceholder, AIMakeText, Root };␊ - `, - filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js', - }, { fileContent: `import _extends from "@babel/runtime/helpers/extends";␊ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";␊ diff --git a/packages/material-parser/test/fixtures/__snapshots__/test/scanner/Scanner.ts.snap b/packages/material-parser/test/fixtures/__snapshots__/test/scanner/Scanner.ts.snap index f88205cce..fb0e88c04 100644 Binary files a/packages/material-parser/test/fixtures/__snapshots__/test/scanner/Scanner.ts.snap and b/packages/material-parser/test/fixtures/__snapshots__/test/scanner/Scanner.ts.snap differ diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeBlank/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeBlank/manifest.json index 94d358017..482a32c96 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeBlank/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeBlank/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeBlank","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeBlank","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"union","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":"object"},{"name":"styleLayout","propType":"object"},{"name":"styleBackground","propType":"object"},{"name":"styleFlexLayout","propType":"object"},{"name":"style","propType":"object"},{"name":"id","propType":"string"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleLayout","propType":{"type":"object","isRequired":true}},{"name":"styleBackground","propType":{"type":"object","isRequired":true}},{"name":"styleFlexLayout","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"},{"name":"id","propType":"string"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeIcon/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeIcon/manifest.json index 1b9fd4b3d..410ac1a62 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeIcon/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeIcon/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeIcon","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeIcon","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"className","propType":"string"},{"name":"iconClassName","propType":"string"},{"name":"children","propType":{"type":"union","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":"object"},{"name":"styleText","propType":"object"},{"name":"styleBackground","propType":"object"},{"name":"style","propType":"object"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"className","propType":"string"},{"name":"iconClassName","propType":"string"},{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleText","propType":{"type":"object","isRequired":true}},{"name":"styleBackground","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeImage/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeImage/manifest.json index 2092db4b6..382cec354 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeImage/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeImage/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeImage","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeImage","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"styleBoxModel","propType":"object"},{"name":"style","propType":"object"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeLink/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeLink/manifest.json index 993baf75f..4a6347ce0 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeLink/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeLink/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeLink","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeLink","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"union","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":"object"},{"name":"styleText","propType":"object"},{"name":"styleLayout","propType":"object"},{"name":"styleBackground","propType":"object"},{"name":"style","propType":"object"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleText","propType":{"type":"object","isRequired":true}},{"name":"styleLayout","propType":{"type":"object","isRequired":true}},{"name":"styleBackground","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakePlaceholder/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakePlaceholder/manifest.json index f4d1ef441..bbbe45981 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakePlaceholder/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakePlaceholder/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakePlaceholder","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakePlaceholder","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"union","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":"object"},{"name":"styleLayout","propType":"object"},{"name":"style","propType":"object"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleLayout","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeText/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeText/manifest.json index b9bc6c295..4ae0e73c1 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeText/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeText/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeText","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeText","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"union","value":[{"type":"arrayOf","value":"node"},"node","string"]}},{"name":"type","propType":"string"},{"name":"styleBoxModel","propType":"object"},{"name":"styleText","propType":"object"},{"name":"styleLayout","propType":"object"},{"name":"styleBackground","propType":"object"},{"name":"style","propType":"object"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node","string"]}},{"name":"type","propType":"string"},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleText","propType":{"type":"object","isRequired":true}},{"name":"styleLayout","propType":{"type":"object","isRequired":true}},{"name":"styleBackground","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/Root/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/Root/manifest.json index a791f69fa..3b2498e18 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/Root/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/Root/manifest.json @@ -1 +1 @@ -{"componentName":"Root","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"Root","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"style","propType":"object"},{"name":"children","propType":{"type":"union","value":["element",{"type":"arrayOf","value":"element"}]}}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"style","propType":"object"},{"name":"children","propType":{"type":"oneOfType","value":["element",{"type":"arrayOf","value":"element"}]}}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeBlank/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeBlank/manifest.json index 44a517687..482a32c96 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeBlank/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeBlank/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeBlank","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeBlank","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType"}},{"name":"styleBoxModel","propType":"object"},{"name":"styleLayout","propType":"object"},{"name":"styleBackground","propType":"object"},{"name":"styleFlexLayout","propType":"object"},{"name":"style","propType":"object","defaultValue":"{}"},{"name":"id","propType":"string"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleLayout","propType":{"type":"object","isRequired":true}},{"name":"styleBackground","propType":{"type":"object","isRequired":true}},{"name":"styleFlexLayout","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"},{"name":"id","propType":"string"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeIcon/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeIcon/manifest.json index e3c51f31e..410ac1a62 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeIcon/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeIcon/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeIcon","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeIcon","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"className","propType":"string"},{"name":"iconClassName","propType":"string"},{"name":"children","propType":{"type":"oneOfType"}},{"name":"styleBoxModel","propType":"object"},{"name":"styleText","propType":"object"},{"name":"styleBackground","propType":"object"},{"name":"style","propType":"object","defaultValue":"{}"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"className","propType":"string"},{"name":"iconClassName","propType":"string"},{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleText","propType":{"type":"object","isRequired":true}},{"name":"styleBackground","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeImage/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeImage/manifest.json index 76a5bb10f..382cec354 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeImage/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeImage/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeImage","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeImage","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"styleBoxModel","propType":"object"},{"name":"style","propType":"object","defaultValue":"{}"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeLink/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeLink/manifest.json index 6557dd4f6..4a6347ce0 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeLink/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeLink/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeLink","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeLink","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType"}},{"name":"styleBoxModel","propType":"object"},{"name":"styleText","propType":"object"},{"name":"styleLayout","propType":"object"},{"name":"styleBackground","propType":"object"},{"name":"style","propType":"object","defaultValue":"{}"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleText","propType":{"type":"object","isRequired":true}},{"name":"styleLayout","propType":{"type":"object","isRequired":true}},{"name":"styleBackground","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakePlaceholder/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakePlaceholder/manifest.json index 91203f99b..bbbe45981 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakePlaceholder/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakePlaceholder/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakePlaceholder","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakePlaceholder","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType"}},{"name":"styleBoxModel","propType":"object"},{"name":"styleLayout","propType":"object"},{"name":"style","propType":"object","defaultValue":"{}"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node"]}},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleLayout","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeText/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeText/manifest.json index 06231166e..4ae0e73c1 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeText/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/AIMakeText/manifest.json @@ -1 +1 @@ -{"componentName":"AIMakeText","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"AIMakeText","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType"}},{"name":"type","propType":"string"},{"name":"styleBoxModel","propType":"object"},{"name":"styleText","propType":"object"},{"name":"styleLayout","propType":"object"},{"name":"styleBackground","propType":"object"},{"name":"style","propType":"object","defaultValue":"{}"}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"children","propType":{"type":"oneOfType","value":[{"type":"arrayOf","value":"node"},"node","string"]}},{"name":"type","propType":"string"},{"name":"styleBoxModel","propType":{"type":"object","isRequired":true}},{"name":"styleText","propType":{"type":"object","isRequired":true}},{"name":"styleLayout","propType":{"type":"object","isRequired":true}},{"name":"styleBackground","propType":{"type":"object","isRequired":true}},{"name":"style","propType":"object"}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/Root/manifest.json b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/Root/manifest.json index 666da89a5..3b2498e18 100644 --- a/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/Root/manifest.json +++ b/packages/material-parser/test/fixtures/multiple-exported-component/src/basic/Root/manifest.json @@ -1 +1 @@ -{"componentName":"Root","title":"","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"Root","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"style","propType":"object","defaultValue":"{\n padding: 0,\n backgroundColor: '#f0f2f5',\n minHeight: '100%'\n}"},{"name":"children","propType":{"type":"oneOfType"}}]} \ No newline at end of file +{"title":"multiple-exported-component","docUrl":"","screenshot":"","npm":{"package":"multiple-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"style","propType":"object"},{"name":"children","propType":{"type":"oneOfType","value":["element",{"type":"arrayOf","value":"element"}]}}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/single-exported-component/es/manifest.json b/packages/material-parser/test/fixtures/single-exported-component/es/manifest.json index 9ca46e161..18cfc93c4 100644 --- a/packages/material-parser/test/fixtures/single-exported-component/es/manifest.json +++ b/packages/material-parser/test/fixtures/single-exported-component/es/manifest.json @@ -1 +1 @@ -{"componentName":"Demo","title":"single-exported-component","docUrl":"","screenshot":"","npm":{"package":"single-exported-component","version":"1.0.0","exportName":"Demo","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"optionalArray","propType":"array"},{"name":"optionalBool","propType":"bool"},{"name":"optionalFunc","propType":"func"},{"name":"optionalNumber","propType":"number"},{"name":"optionalObject","propType":"object"},{"name":"optionalString","propType":"string"},{"name":"optionalSymbol","propType":"symbol"},{"name":"optionalNode","propType":"node"},{"name":"optionalElement","propType":"element"},{"name":"optionalElementType","propType":"elementType"},{"name":"optionalMessage","propType":{"type":"instanceOf","value":"Demo"}},{"name":"optionalEnum","propType":{"type":"oneOf","value":["News","Photos"]}},{"name":"optionalUnion","propType":{"type":"union","value":["string","number",{"type":"instanceOf","value":"Demo"}]}},{"name":"optionalArrayOf","propType":{"type":"arrayOf","value":"number"}},{"name":"optionalObjectOf","propType":{"type":"objectOf","value":"number"}},{"name":"optionalObjectWithShape","propType":{"type":"shape","value":[{"name":"optionalProperty","propType":"string"},{"name":"requiredProperty","propType":{"type":"number","isRequired":true}}]}},{"name":"optionalObjectWithShape2","propType":{"type":"shape","isRequired":true,"value":[{"name":"optionalProperty","propType":"string"},{"name":"requiredProperty","propType":{"type":"number","isRequired":true}}]}},{"name":"optionalObjectWithStrictShape","propType":{"type":"exact","value":[{"name":"optionalProperty","propType":"string"},{"name":"requiredProperty","propType":{"type":"number","isRequired":true}}]}},{"name":"requiredFunc","propType":{"type":"func","isRequired":true}},{"name":"requiredAny","propType":{"type":"any","isRequired":true}}]} \ No newline at end of file +{"title":"single-exported-component","docUrl":"","screenshot":"","npm":{"package":"single-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"optionalArray","propType":"array"},{"name":"optionalBool","propType":"bool"},{"name":"optionalFunc","propType":"func"},{"name":"optionalNumber","propType":"number","defaultValue":123},{"name":"optionalObject","propType":"object"},{"name":"optionalString","propType":"string"},{"name":"optionalSymbol","propType":"symbol"},{"name":"optionalNode","propType":"node"},{"name":"optionalElement","propType":"element"},{"name":"optionalElementType","propType":"elementType"},{"name":"optionalMessage","propType":{"type":"instanceOf","value":"Demo"}},{"name":"optionalEnum","propType":{"type":"oneOf","value":["News","Photos"]}},{"name":"optionalUnion","propType":{"type":"oneOfType","value":["string","number",{"type":"instanceOf","value":"Demo"}]}},{"name":"optionalArrayOf","propType":{"type":"arrayOf","value":"number"}},{"name":"optionalObjectOf","propType":{"type":"objectOf","value":"number"}},{"name":"optionalObjectWithShape","propType":{"type":"shape","value":[{"name":"optionalProperty","propType":"string"},{"name":"requiredProperty","propType":{"type":"number","isRequired":true}}]}},{"name":"optionalObjectWithShape2","propType":{"type":"shape","isRequired":true,"value":[{"name":"optionalProperty","propType":"string"},{"name":"requiredProperty","propType":{"type":"number","isRequired":true}}]}},{"name":"optionalObjectWithStrictShape","propType":{"type":"exact","value":[{"name":"optionalProperty","propType":"string"},{"name":"requiredProperty","propType":{"type":"number","isRequired":true}}]}},{"name":"requiredFunc","propType":{"type":"func","isRequired":true}},{"name":"requiredAny","propType":{"type":"any","isRequired":true}}]} \ No newline at end of file diff --git a/packages/material-parser/test/fixtures/single-exported-component/src/manifest.json b/packages/material-parser/test/fixtures/single-exported-component/src/manifest.json index 4c5c7745a..18cfc93c4 100644 --- a/packages/material-parser/test/fixtures/single-exported-component/src/manifest.json +++ b/packages/material-parser/test/fixtures/single-exported-component/src/manifest.json @@ -1 +1 @@ -{"componentName":"Demo","title":"","docUrl":"","screenshot":"","npm":{"package":"single-exported-component","version":"1.0.0","exportName":"Demo","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"optionalArray","propType":"array"},{"name":"optionalBool","propType":"bool"},{"name":"optionalFunc","propType":"func"},{"name":"optionalNumber","propType":"number"},{"name":"optionalObject","propType":"object"},{"name":"optionalString","propType":"string"},{"name":"optionalSymbol","propType":{"type":"symbol"}},{"name":"optionalNode","propType":"node"},{"name":"optionalElement","propType":"element"},{"name":"optionalElementType","propType":{"type":"elementType"}},{"name":"optionalMessage","propType":{"type":"instanceOf"}},{"name":"optionalEnum","propType":{"type":"oneOf"}},{"name":"optionalUnion","propType":{"type":"oneOfType"}},{"name":"optionalArrayOf","propType":{"type":"arrayOf"}},{"name":"optionalObjectOf","propType":{"type":"objectOf"}},{"name":"optionalObjectWithShape","propType":{"type":"shape"}},{"name":"optionalObjectWithShape2","propType":{"type":"shape"}},{"name":"optionalObjectWithStrictShape","propType":{"type":"exact"}},{"name":"requiredFunc","propType":"func"},{"name":"requiredAny","propType":"any"}]} \ No newline at end of file +{"title":"single-exported-component","docUrl":"","screenshot":"","npm":{"package":"single-exported-component","version":"1.0.0","exportName":"","main":"/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js","destructuring":false,"subName":""},"props":[{"name":"optionalArray","propType":"array"},{"name":"optionalBool","propType":"bool"},{"name":"optionalFunc","propType":"func"},{"name":"optionalNumber","propType":"number","defaultValue":123},{"name":"optionalObject","propType":"object"},{"name":"optionalString","propType":"string"},{"name":"optionalSymbol","propType":"symbol"},{"name":"optionalNode","propType":"node"},{"name":"optionalElement","propType":"element"},{"name":"optionalElementType","propType":"elementType"},{"name":"optionalMessage","propType":{"type":"instanceOf","value":"Demo"}},{"name":"optionalEnum","propType":{"type":"oneOf","value":["News","Photos"]}},{"name":"optionalUnion","propType":{"type":"oneOfType","value":["string","number",{"type":"instanceOf","value":"Demo"}]}},{"name":"optionalArrayOf","propType":{"type":"arrayOf","value":"number"}},{"name":"optionalObjectOf","propType":{"type":"objectOf","value":"number"}},{"name":"optionalObjectWithShape","propType":{"type":"shape","value":[{"name":"optionalProperty","propType":"string"},{"name":"requiredProperty","propType":{"type":"number","isRequired":true}}]}},{"name":"optionalObjectWithShape2","propType":{"type":"shape","isRequired":true,"value":[{"name":"optionalProperty","propType":"string"},{"name":"requiredProperty","propType":{"type":"number","isRequired":true}}]}},{"name":"optionalObjectWithStrictShape","propType":{"type":"exact","value":[{"name":"optionalProperty","propType":"string"},{"name":"requiredProperty","propType":{"type":"number","isRequired":true}}]}},{"name":"requiredFunc","propType":{"type":"func","isRequired":true}},{"name":"requiredAny","propType":{"type":"any","isRequired":true}}]} \ No newline at end of file diff --git a/packages/material-parser/test/generator/Generator.ts b/packages/material-parser/test/generator/Generator.ts index bb2bb561c..dead5622e 100644 --- a/packages/material-parser/test/generator/Generator.ts +++ b/packages/material-parser/test/generator/Generator.ts @@ -30,20 +30,20 @@ async function generate( return actual; } -// test.serial('generate multiple exported components', async t => { -// const options: IMaterializeOptions = { -// cwd: multiExportedComptPath, -// entry: multiExportedComptPath, -// accesser: 'local', -// isExportedAsMultiple: true, -// }; +test.serial('generate multiple exported components', async t => { + const options: IMaterializeOptions = { + cwd: multiExportedComptPath, + entry: multiExportedComptPath, + accesser: 'local', + isExportedAsMultiple: true, + }; -// const actual = await generate(options); + const actual = await generate(options); -// t.snapshot(actual); -// }); + t.snapshot(actual); +}); -test.only('generate single exported components', async t => { +test.serial('generate single exported components', async t => { const options: IMaterializeOptions = { cwd: singleExportedComptPath, entry: singleExportedComptPath, diff --git a/packages/material-parser/test/parser/ReactParser.ts b/packages/material-parser/test/parser/ReactParser.ts index 543557d3a..9b7dbafd0 100644 --- a/packages/material-parser/test/parser/ReactParser.ts +++ b/packages/material-parser/test/parser/ReactParser.ts @@ -18,24 +18,23 @@ test.serial('parse es6 multiple exported component by local', async t => { const scanner = new Scanner(options); const scanModel = await scanner.scan(); const parser = new ReactParser(options); -// debugger; const actual: IMaterialParsedModel[] = await parser.parse(scanModel); t.snapshot(actual); }); -// test.serial('parse es6 single exported component by local', async t => { -// const options: IMaterializeOptions = { -// cwd: singleExportedComptPath, -// entry: singleExportedComptPath, -// accesser: 'local', -// isExportedAsMultiple: false, -// }; +test.serial('parse es6 single exported component by local', async t => { + const options: IMaterializeOptions = { + cwd: singleExportedComptPath, + entry: singleExportedComptPath, + accesser: 'local', + isExportedAsMultiple: false, + }; -// const scanner = new Scanner(options); -// const scanModel = await scanner.scan(); -// const parser = new ReactParser(options); -// const actual: IMaterialParsedModel[] = await parser.parse(scanModel); + const scanner = new Scanner(options); + const scanModel = await scanner.scan(); + const parser = new ReactParser(options); + const actual: IMaterialParsedModel[] = await parser.parse(scanModel); -// t.snapshot(actual); -// }); + t.snapshot(actual); +});