| 1 | import type { TWConfig } from '../types' |
| 2 | |
| 3 | export const checkUnsafeInlineConfig = <T extends Partial<TWConfig>>(inlineConfig: T | undefined) => { |
| 4 | if (!inlineConfig) return |
| 5 | |
| 6 | if ( |
| 7 | 'plugins' in inlineConfig && Array.isArray(inlineConfig.plugins) |
| 8 | && inlineConfig.plugins.find(p => typeof p === 'function' || typeof p?.handler === 'function') |
| 9 | ) { |
| 10 | return 'plugins' |
| 11 | } |
| 12 | |
| 13 | if (inlineConfig.content) { |
| 14 | // @ts-expect-error indexing content with different possibilities |
| 15 | const invalidProperty = ['extract', 'transform'].find(i => i in inlineConfig.content! && typeof inlineConfig.content![i] === 'function') |
| 16 | |
| 17 | if (invalidProperty) { |
| 18 | return `content.${invalidProperty}` |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | if (inlineConfig.safelist) { |
| 23 | const invalidIdx = inlineConfig.safelist.findIndex(s => typeof s === 'object' && s.pattern instanceof RegExp) |
| 24 | |
| 25 | if (invalidIdx > -1) { |
| 26 | return `safelist[${invalidIdx}]` |
| 27 | } |
| 28 | } |
| 29 | } |