Skip to content

Commit 44210e6

Browse files
committed
chore: fix jsxfactory
1 parent 39b191a commit 44210e6

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

plugin/src/utils/helpers.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ const isValidStyledProp = <T extends Node>(node: T, context: RuleContext<any, an
9797
export const isPandaIsh = (name: string, context: RuleContext<any, any>) => {
9898
const imports = getImports(context)
9999
if (imports.length === 0) return false
100+
// Check if the name is the jsx factory
101+
const jsxFactory = syncAction('getJsxFactory', getSyncOpts(context))
102+
if (jsxFactory && name === jsxFactory) {
103+
// Check if the jsx factory is imported
104+
return imports.some((imp) => imp.name === name || imp.alias === name)
105+
}
100106
return syncAction('matchFile', getSyncOpts(context), name, imports)
101107
}
102108

@@ -159,10 +165,14 @@ export const isPandaProp = (node: TSESTree.JSXAttribute, context: RuleContext<an
159165
const prop = node.name.name
160166

161167
// Ensure component is a panda component
162-
if (!isPandaIsh(name, context) && !isLocalStyledFactory(jsxAncestor, context)) return
168+
const isPandaComponent = isPandaIsh(name, context) || isLocalStyledFactory(jsxAncestor, context)
169+
if (!isPandaComponent) return
163170

164171
// Ensure prop is a styled prop
165-
if (typeof prop !== 'string' || !isValidProperty(prop, context, name)) return
172+
// For jsx factory components (e.g., styled.div), pass undefined as the pattern name
173+
// so that only global property validation is performed
174+
const patternName = isJSXMemberExpression(jsxAncestor.name) ? undefined : name
175+
if (typeof prop !== 'string' || !isValidProperty(prop, context, patternName)) return
166176

167177
return true
168178
}

plugin/src/utils/worker.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,19 @@ async function resolveLongHand(ctx: Generator, name: string): Promise<string | u
114114
async function isValidProperty(ctx: Generator, name: string, patternName?: string) {
115115
const isValid = ctx.isValidProperty(name)
116116
if (isValid) return true
117-
if (!patternName) return
117+
if (!patternName) return false
118+
119+
// If the pattern name is the jsxFactory (e.g., 'styled'), we should accept
120+
// any property that is valid according to the global property check
121+
// Since styled components are generic wrappers, we don't need pattern-specific checks
122+
if (patternName === ctx.config.jsxFactory) {
123+
// Already checked globally above, so return false if we got here
124+
return false
125+
}
118126

119127
const pattern = ctx.patterns.details.find((p) => p.baseName === patternName || p.jsx.includes(patternName))?.config
120128
.properties
121-
if (!pattern) return
129+
if (!pattern) return false
122130
return Object.keys(pattern).includes(name)
123131
}
124132

@@ -142,6 +150,10 @@ async function matchImports(ctx: Generator, result: MatchImportResult) {
142150
return isMatch
143151
}
144152

153+
async function getJsxFactory(ctx: Generator) {
154+
return ctx.config.jsxFactory
155+
}
156+
145157
export function runAsync(action: 'filterInvalidTokens', opts: Opts, paths: string[]): Promise<string[]>
146158
export function runAsync(action: 'isColorToken', opts: Opts, value: string): Promise<boolean>
147159
export function runAsync(action: 'isColorAttribute', opts: Opts, attr: string): Promise<boolean>
@@ -152,6 +164,7 @@ export function runAsync(action: 'isValidProperty', opts: Opts, name: string, pa
152164
export function runAsync(action: 'matchFile', opts: Opts, name: string, imports: ImportResult[]): Promise<boolean>
153165
export function runAsync(action: 'matchImports', opts: Opts, result: MatchImportResult): Promise<boolean>
154166
export function runAsync(action: 'getPropCategory', opts: Opts, prop: string): Promise<string>
167+
export function runAsync(action: 'getJsxFactory', opts: Opts): Promise<string | undefined>
155168
export function runAsync(
156169
action: 'filterDeprecatedTokens',
157170
opts: Opts,
@@ -190,6 +203,8 @@ export async function runAsync(action: string, opts: Opts, ...args: any): Promis
190203
case 'getPropCategory':
191204
// @ts-expect-error cast
192205
return getPropCategory(ctx, ...args)
206+
case 'getJsxFactory':
207+
return getJsxFactory(ctx)
193208
case 'filterDeprecatedTokens':
194209
// @ts-expect-error cast
195210
return filterDeprecatedTokens(ctx, ...args)
@@ -206,6 +221,7 @@ export function run(action: 'isValidProperty', opts: Opts, name: string, pattern
206221
export function run(action: 'matchFile', opts: Opts, name: string, imports: ImportResult[]): boolean
207222
export function run(action: 'matchImports', opts: Opts, result: MatchImportResult): boolean
208223
export function run(action: 'getPropCategory', opts: Opts, prop: string): string
224+
export function run(action: 'getJsxFactory', opts: Opts): string | undefined
209225
export function run(action: 'filterDeprecatedTokens', opts: Opts, tokens: DeprecatedToken[]): DeprecatedToken[]
210226
export function run(action: string, opts: Opts, ...args: any[]): any {
211227
// @ts-expect-error cast

0 commit comments

Comments
 (0)