Skip to content

Commit 4e6f95d

Browse files
committed
Try catch syncs
1 parent 5d8b415 commit 4e6f95d

File tree

5 files changed

+19
-52
lines changed

5 files changed

+19
-52
lines changed

.changeset/poor-terms-help.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pandacss/eslint-plugin": patch
3+
---
4+
5+
Try catch syncs

plugin/src/rules/no-invalid-token-paths.ts

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const rule: Rule = createRule({
3535
const sendReport = (node: any, _value?: string) => {
3636
const value = _value ?? node.value?.toString()
3737
const tokens = getInvalidTokens(value, context)
38+
if (!tokens) return
3839

3940
if (tokens.length > 0) {
4041
tokens.forEach((token) => {
@@ -78,6 +79,7 @@ const rule: Rule = createRule({
7879
const quasis = node.quasi.quasis[0]
7980
const styles = quasis.value.raw
8081
const tokens = getInvalidTokens(styles, context)
82+
if (!tokens) return
8183

8284
tokens.forEach((token, i, arr) => {
8385
// Avoid duplicate reports on the same token

plugin/src/utils/helpers.ts

+2-21
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ const _getImports = (context: RuleContext<any, any>) => {
7979

8080
const getImports = (context: RuleContext<any, any>) => {
8181
const imports = _getImports(context)
82-
try {
83-
return imports.filter((imp) => syncAction('matchImports', getSyncOpts(context), imp))
84-
} catch (error) {
85-
return []
86-
}
82+
return imports.filter((imp) => syncAction('matchImports', getSyncOpts(context), imp))
8783
}
8884

8985
const isValidStyledProp = <T extends Node | string>(node: T, context: RuleContext<any, any>) => {
@@ -156,7 +152,7 @@ export const isPandaProp = (node: TSESTree.JSXAttribute, context: RuleContext<an
156152
return true
157153
}
158154

159-
export const isStyledNode = (node: TSESTree.Property, context: RuleContext<any, any>, calleeName?: string) => {
155+
export const isStyledProperty = (node: TSESTree.Property, context: RuleContext<any, any>, calleeName?: string) => {
160156
if (!isIdentifier(node.key) && !isLiteral(node.key) && !isTemplateLiteral(node.key)) return
161157

162158
if (isIdentifier(node.key) && !isValidProperty(node.key.name, context, calleeName)) return
@@ -167,20 +163,9 @@ export const isStyledNode = (node: TSESTree.Property, context: RuleContext<any,
167163
)
168164
return
169165
if (isTemplateLiteral(node.key) && !isValidProperty(node.key.quasis[0].value.raw, context, calleeName)) return
170-
171166
return true
172167
}
173168

174-
export const isStyledProperty = (node: TSESTree.Property, context: RuleContext<any, any>, calleeName?: string) => {
175-
const ancestor = node.parent.parent
176-
177-
const isValidFuncAncestor =
178-
isCallExpression(ancestor) && isIdentifier(ancestor.callee) && isPandaIsh(ancestor.callee.name, context)
179-
if (isValidFuncAncestor) return isStyledNode(node, context, calleeName)
180-
181-
return isStyledNode(ancestor as any, context, calleeName) && isStyledNode(node, context, calleeName)
182-
}
183-
184169
export const isInPandaFunction = (node: TSESTree.Property, context: RuleContext<any, any>) => {
185170
const callAncestor = getAncestor(isCallExpression, node)
186171
if (!callAncestor) return
@@ -271,10 +256,6 @@ export const getInvalidTokens = (value: string, context: RuleContext<any, any>)
271256
return syncAction('filterInvalidTokens', getSyncOpts(context), tokens)
272257
}
273258

274-
export const getExtendWarnings = (context: RuleContext<any, any>) => {
275-
return syncAction('getExtendWarnings', getSyncOpts(context))
276-
}
277-
278259
export const getTokenImport = (context: RuleContext<any, any>) => {
279260
const imports = _getImports(context)
280261
return imports.find((imp) => imp.name === 'token')

plugin/src/utils/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ export type Rule<A extends readonly unknown[] = any, B extends string = any> = R
1313
const isBase = process.env.NODE_ENV !== 'test' || import.meta.url.endsWith('dist/index.js')
1414
export const distDir = fileURLToPath(new URL(isBase ? './' : '../../dist', import.meta.url))
1515

16-
export const syncAction = createSyncFn(join(distDir, 'utils/worker.mjs')) as typeof run
16+
export const _syncAction = createSyncFn(join(distDir, 'utils/worker.mjs'))
17+
// export const _syncAction = createSyncFn(join(distDir, 'utils/worker.mjs')) as typeof run
18+
19+
export const syncAction = ((...args: any) => {
20+
try {
21+
return _syncAction(...args)
22+
} catch (error) {
23+
return
24+
}
25+
}) as typeof run | ((...args: any) => undefined)
1726

1827
export interface ImportResult {
1928
name: string

plugin/src/utils/worker.ts

-30
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,6 @@ export async function getContext(opts: Opts) {
3131
}
3232
}
3333

34-
async function getExtendWarnings(): Promise<string[]> {
35-
if (!configPath) return []
36-
37-
const cwd = path.dirname(configPath)
38-
const { config } = await bundleConfig({ cwd, file: configPath! })
39-
40-
if (!config.presets || config.presets.length === 0) return []
41-
if (config.eject) return []
42-
43-
const warnings = new Set<string>()
44-
45-
if (config.theme && !config.theme.extend) {
46-
warnings.add('theme')
47-
}
48-
49-
if (config.conditions && !config.conditions.extend) {
50-
warnings.add('conditions')
51-
}
52-
53-
if (config.patterns && !config.patterns.extend) {
54-
warnings.add('patterns')
55-
}
56-
57-
return Array.from(warnings)
58-
}
59-
6034
async function filterInvalidTokens(ctx: PandaContext, paths: string[]): Promise<string[]> {
6135
return paths.filter((path) => !ctx.utility.tokens.view.get(path))
6236
}
@@ -137,7 +111,6 @@ type Opts = {
137111
configPath?: string
138112
}
139113

140-
export function runAsync(action: 'getExtendWarnings', opts: Opts): Promise<string[]>
141114
export function runAsync(action: 'filterInvalidTokens', opts: Opts, paths: string[]): Promise<string[]>
142115
export function runAsync(action: 'isColorToken', opts: Opts, value: string): Promise<boolean>
143116
export function runAsync(action: 'isColorAttribute', opts: Opts, attr: string): Promise<boolean>
@@ -180,12 +153,9 @@ export async function runAsync(action: string, opts: Opts, ...args: any): Promis
180153
case 'filterInvalidTokens':
181154
// @ts-expect-error cast
182155
return filterInvalidTokens(ctx, ...args)
183-
case 'getExtendWarnings':
184-
return getExtendWarnings()
185156
}
186157
}
187158

188-
export function run(action: 'getExtendWarnings', opts: Opts): string[]
189159
export function run(action: 'filterInvalidTokens', opts: Opts, paths: string[]): string[]
190160
export function run(action: 'isColorToken', opts: Opts, value: string): boolean
191161
export function run(action: 'isColorAttribute', opts: Opts, attr: string): boolean

0 commit comments

Comments
 (0)