diff --git a/modules/material-parser/README.md b/modules/material-parser/README.md
index a217dc16f..4507b7e6e 100644
--- a/modules/material-parser/README.md
+++ b/modules/material-parser/README.md
@@ -1,16 +1,22 @@
-# @ali/lowcode-material-parser
+# @alilc/lowcode-material-parser
> 入料模块
本模块负责物料接入,能自动扫描、解析源码组件,并最终产出一份符合《中后台搭建组件描述协议》的 **JSON Schema**。
-详见[文档](https://yuque.antfin-inc.com/ali-lowcode/docs/tyktrt)。
+详见[文档](https://lowcode-engine.cn/docV2/yhgcqb)。
## demo
```shell
cd demo
-node index.js
+
+// parse jsx
+node parse-jsx.js
+
+// parse tsx
+node parse-tsx.js
+
```
## API
diff --git a/modules/material-parser/demo/component.tsx b/modules/material-parser/demo/component.tsx
new file mode 100644
index 000000000..29eb7122d
--- /dev/null
+++ b/modules/material-parser/demo/component.tsx
@@ -0,0 +1,54 @@
+/* eslint-disable react/forbid-prop-types,react/no-unused-prop-types */
+import React from 'react';
+
+import './main.scss';
+
+interface DemoProps {
+ optionalArray?: [],
+ optionalBool: boolean,
+ optionalFunc: Function,
+ optionalNumber: number,
+ optionalObject: object,
+ optionalString: string,
+ optionalSymbol: symbol,
+
+ // Anything that can be rendered: numbers, strings, elements or an array
+ // (or fragment) containing these types.
+ optionalNode: React.ReactNode,
+
+ // A React element (ie. ).
+ optionalElement: React.ReactElement,
+
+ // A React element type (ie. MyComponent).
+ optionalElementType: React.ElementType,
+
+ // You can also declare that a prop is an instance of a class. This uses
+ // JS's instanceof operator.
+ optionalMessage: React.ReactInstance,
+
+ // You can ensure that your prop is limited to specific values by treating
+ // it as an enum.
+ optionalEnum: 'News'|'Photos',
+
+ // An object that could be one of many types
+ optionalUnion: string|number|React.ReactInstance,
+
+ // An array of a certain type
+ optionalArrayOf: number[],
+
+ // An object with property values of a certain type
+ optionalObjectOf: Record,
+
+ // You can chain any of the above with `isRequired` to make sure a warning
+ // is shown if the prop isn't provided.
+}
+
+const Demo = (props: DemoProps) => {
+ return Test
;
+}
+
+Demo.defaultProps = {
+ optionalString: 'optionalString'
+};
+
+export default Demo;
diff --git a/modules/material-parser/demo/index.js b/modules/material-parser/demo/parse-jsx.js
similarity index 100%
rename from modules/material-parser/demo/index.js
rename to modules/material-parser/demo/parse-jsx.js
diff --git a/modules/material-parser/demo/parse-tsx.js b/modules/material-parser/demo/parse-tsx.js
new file mode 100644
index 000000000..05d4b1e45
--- /dev/null
+++ b/modules/material-parser/demo/parse-tsx.js
@@ -0,0 +1,11 @@
+const parse = require('../lib').default;
+
+(async () => {
+ const options = {
+ entry: './component.tsx',
+ accesser: 'local',
+ };
+
+ const actual = await parse(options);
+ console.log(JSON.stringify(actual, null, 2));
+})();
diff --git a/modules/material-parser/package.json b/modules/material-parser/package.json
index 10d38cc12..7d7ea57c2 100644
--- a/modules/material-parser/package.json
+++ b/modules/material-parser/package.json
@@ -1,6 +1,6 @@
{
"name": "@alilc/lowcode-material-parser",
- "version": "1.0.1-beta.3",
+ "version": "1.0.3",
"description": "material parser for Ali lowCode engine",
"main": "lib/index.js",
"files": [
diff --git a/modules/material-parser/src/parse/transform.ts b/modules/material-parser/src/parse/transform.ts
index ba12f2c68..9a92f3aba 100644
--- a/modules/material-parser/src/parse/transform.ts
+++ b/modules/material-parser/src/parse/transform.ts
@@ -282,23 +282,21 @@ export function transformItem(name: string, item: any) {
if (!isNil(defaultValue) && typeof defaultValue === 'object' && isEvaluable(defaultValue)) {
if (defaultValue === null) {
result.defaultValue = defaultValue;
- } else {
- // if ('computed' in defaultValue) {
- // val = val.value;
+ } else if ('computed' in defaultValue) {
+ // parsed data from react-docgen
try {
if (isEvaluable(defaultValue.value)) {
- const value = safeEval(`'${defaultValue.value}'`);
- result.defaultValue = value;
+ result.defaultValue = safeEval(defaultValue.value);
} else {
result.defaultValue = defaultValue.value;
}
} catch (e) {
log(e);
}
+ } else {
+ // parsed data from react-docgen-typescript
+ result.defaultValue = defaultValue.value;
}
- // else {
- // result.defaultValue = defaultValue.value;
- // }
}
if (result.propType === undefined) {
delete result.propType;