Skip to content

Commit e2be399

Browse files
committed
chore: add tsx demo and update readme
1 parent bffa5be commit e2be399

File tree

6 files changed

+81
-12
lines changed

6 files changed

+81
-12
lines changed

modules/material-parser/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
# @ali/lowcode-material-parser
1+
# @alilc/lowcode-material-parser
22

33
> 入料模块
44
55
本模块负责物料接入,能自动扫描、解析源码组件,并最终产出一份符合《中后台搭建组件描述协议》的 **JSON Schema**
66

7-
详见[文档](https://yuque.antfin-inc.com/ali-lowcode/docs/tyktrt)
7+
详见[文档](https://lowcode-engine.cn/docV2/yhgcqb)
88

99
## demo
1010

1111
```shell
1212
cd demo
13-
node index.js
13+
14+
// parse jsx
15+
node parse-jsx.js
16+
17+
// parse tsx
18+
node parse-tsx.js
19+
1420
```
1521

1622
## API
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* eslint-disable react/forbid-prop-types,react/no-unused-prop-types */
2+
import React from 'react';
3+
4+
import './main.scss';
5+
6+
interface DemoProps {
7+
optionalArray?: [],
8+
optionalBool: boolean,
9+
optionalFunc: Function,
10+
optionalNumber: number,
11+
optionalObject: object,
12+
optionalString: string,
13+
optionalSymbol: symbol,
14+
15+
// Anything that can be rendered: numbers, strings, elements or an array
16+
// (or fragment) containing these types.
17+
optionalNode: React.ReactNode,
18+
19+
// A React element (ie. <MyComponent />).
20+
optionalElement: React.ReactElement,
21+
22+
// A React element type (ie. MyComponent).
23+
optionalElementType: React.ElementType,
24+
25+
// You can also declare that a prop is an instance of a class. This uses
26+
// JS's instanceof operator.
27+
optionalMessage: React.ReactInstance,
28+
29+
// You can ensure that your prop is limited to specific values by treating
30+
// it as an enum.
31+
optionalEnum: 'News'|'Photos',
32+
33+
// An object that could be one of many types
34+
optionalUnion: string|number|React.ReactInstance,
35+
36+
// An array of a certain type
37+
optionalArrayOf: number[],
38+
39+
// An object with property values of a certain type
40+
optionalObjectOf: Record<number, any>,
41+
42+
// You can chain any of the above with `isRequired` to make sure a warning
43+
// is shown if the prop isn't provided.
44+
}
45+
46+
const Demo = (props: DemoProps) => {
47+
return <div> Test </div>;
48+
}
49+
50+
Demo.defaultProps = {
51+
optionalString: 'optionalString'
52+
};
53+
54+
export default Demo;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const parse = require('../lib').default;
2+
3+
(async () => {
4+
const options = {
5+
entry: './component.tsx',
6+
accesser: 'local',
7+
};
8+
9+
const actual = await parse(options);
10+
console.log(JSON.stringify(actual, null, 2));
11+
})();

modules/material-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alilc/lowcode-material-parser",
3-
"version": "1.0.1-beta.3",
3+
"version": "1.0.3",
44
"description": "material parser for Ali lowCode engine",
55
"main": "lib/index.js",
66
"files": [

modules/material-parser/src/parse/transform.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,23 +282,21 @@ export function transformItem(name: string, item: any) {
282282
if (!isNil(defaultValue) && typeof defaultValue === 'object' && isEvaluable(defaultValue)) {
283283
if (defaultValue === null) {
284284
result.defaultValue = defaultValue;
285-
} else {
286-
// if ('computed' in defaultValue) {
287-
// val = val.value;
285+
} else if ('computed' in defaultValue) {
286+
// parsed data from react-docgen
288287
try {
289288
if (isEvaluable(defaultValue.value)) {
290-
const value = safeEval(`'${defaultValue.value}'`);
291-
result.defaultValue = value;
289+
result.defaultValue = safeEval(defaultValue.value);
292290
} else {
293291
result.defaultValue = defaultValue.value;
294292
}
295293
} catch (e) {
296294
log(e);
297295
}
296+
} else {
297+
// parsed data from react-docgen-typescript
298+
result.defaultValue = defaultValue.value;
298299
}
299-
// else {
300-
// result.defaultValue = defaultValue.value;
301-
// }
302300
}
303301
if (result.propType === undefined) {
304302
delete result.propType;

0 commit comments

Comments
 (0)