Skip to content

Commit c17816f

Browse files
committed
fix(plugin-dva): 删除 getModels 中关于 jsx 的单测,增加 jsx 中使用尖括号类型断言的单测
1 parent 1079b3e commit c17816f

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
3+
const A = () => <div>123</div>
4+
const AbcModel = {
5+
namespace: <string>'a',
6+
};
7+
8+
export default AbcModel;

packages/plugin-dva/src/getModels/getModels.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,25 @@ test('getModels with opts.extraModels and opts.skipModelValidate', () => {
6262
]);
6363
});
6464

65-
test('parser error when has jsx', () => {
65+
// test('parser error when has jsx', () => {
66+
// const base = join(fixtures, 'jsx');
67+
// const filePath = join(base, 'a.jsx');
68+
// expect(() => {
69+
// getModels({
70+
// base,
71+
// cwd: __dirname,
72+
// skipModelValidate: false,
73+
// });
74+
// }).toThrow(
75+
// `Dva model ${utils.winPath(
76+
// relative(__dirname, filePath),
77+
// )} parse failed, SyntaxError: Unterminated regular expression. (3:26)`,
78+
// );
79+
// });
80+
81+
test('parser error when ambiguous with jsx', () => {
6682
const base = join(fixtures, 'jsx');
67-
const filePath = join(base, 'a.jsx');
83+
const filePath = join(base, 'b.jsx');
6884
expect(() => {
6985
getModels({
7086
base,
@@ -74,6 +90,6 @@ test('parser error when has jsx', () => {
7490
}).toThrow(
7591
`Dva model ${utils.winPath(
7692
relative(__dirname, filePath),
77-
)} parse failed, SyntaxError: Unterminated regular expression. (3:26)`,
93+
)} parse failed, SyntaxError: Unterminated JSX contents. (5:21) Maybe you use type assertions that would be ambiguous with JSX`,
7894
);
7995
});

packages/plugin-dva/src/getModels/getModels.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ export function getModels(opts: {
3030
const isJsx = /.(j|t)sx$/.test(f);
3131
// TODO: fs cache for performance
3232
try {
33-
console.log(
34-
f,
35-
isValidModel(
36-
{
37-
content: readFileSync(f, 'utf-8'),
38-
},
39-
isJsx,
40-
),
41-
);
4233
return isValidModel(
4334
{
4435
content: readFileSync(f, 'utf-8'),

0 commit comments

Comments
 (0)