Skip to content

Commit a906dd5

Browse files
committed
feat: avoid object without methods
1 parent e0acfac commit a906dd5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/plugin-react/src/reactCompilerPreset.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ describe('defaultCodeFilter', () => {
4646
'let MyComponent; ({ MyComponent = function() { return <></> } }) = {}',
4747
true,
4848
],
49-
'component property': [
49+
'component property function expression': [
50+
'const components = { MyComponent: function() { return <></> } }',
51+
true,
52+
],
53+
'component property arrow function expression': [
5054
'const components = { MyComponent: () => <></> }',
5155
true,
5256
],
@@ -118,6 +122,8 @@ export default memo(() => {
118122
'non assignments (2)': ['[useState][0]()', false],
119123
'non assignments (3)': ['useState;s()', false],
120124
'non assignments (4)': ['useState,s()', false],
125+
'object without methods (1)': ['const obj = { useState: 1 }', false],
126+
'object without methods (2)': ['const obj = { Foo: 1 }', false],
121127
}
122128

123129
for (const [name, [code, expected]] of Object.entries(cases)) {

packages/plugin-react/src/reactCompilerPreset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
} from '#optionalTypes'
55

66
export const defaultCodeFilter =
7-
/forwardRef|memo|function\s+(?:[A-Z]|use[A-Z0-9])|(?:[A-Z]|use[A-Z0-9])[^\s:=(){}[\],;]*\s*[:=(]/
7+
/forwardRef|memo|function\s+(?:[A-Z]|use[A-Z0-9])|(?:[A-Z]|use[A-Z0-9])[^\s:=(){}[\],;]*\s*(?:\(|[:=]\s*(?:function|\())/
88

99
export const reactCompilerPreset = (
1010
options: Pick<

0 commit comments

Comments
 (0)