|
80 | 80 | * |
81 | 81 | * Passed in source info to `jsxDEV` when using the automatic runtime with |
82 | 82 | * `development: true`. |
| 83 | + * @property {boolean | null | undefined} [ignoreInvalidStyle=false] |
| 84 | + * Ignore invalid CSS in `style` props (default: `false`); |
| 85 | + * the default behavior is to throw an error. |
83 | 86 | * @property {boolean | null | undefined} [passKeys=true] |
84 | 87 | * Generate keys to optimize frameworks that support them (default: `true`). |
85 | 88 | * |
|
170 | 173 | * Casing to use for attribute names. |
171 | 174 | * @property {string | undefined} filePath |
172 | 175 | * File path. |
| 176 | + * @property {boolean} ignoreInvalidStyle |
| 177 | + * Ignore invalid CSS in `style` props. |
173 | 178 | * @property {boolean} passKeys |
174 | 179 | * Generate keys to optimize frameworks that support them. |
175 | 180 | * @property {boolean} passNode |
@@ -285,6 +290,7 @@ export function toJsxRuntime(tree, options) { |
285 | 290 | create, |
286 | 291 | elementAttributeNameCase: options.elementAttributeNameCase || 'react', |
287 | 292 | filePath, |
| 293 | + ignoreInvalidStyle: options.ignoreInvalidStyle || false, |
288 | 294 | passKeys: options.passKeys !== false, |
289 | 295 | passNode: options.passNode || false, |
290 | 296 | schema: options.space === 'svg' ? svg : html, |
@@ -607,19 +613,20 @@ function parseStyle(state, ancestors, value) { |
607 | 613 | try { |
608 | 614 | styleToObject(value, replacer) |
609 | 615 | } catch (error) { |
610 | | - const cause = /** @type {Error} */ (error) |
611 | | - |
612 | | - const message = new VFileMessage('Cannot parse `style` attribute', { |
613 | | - ancestors, |
614 | | - cause, |
615 | | - source: 'hast-util-to-jsx-runtime', |
616 | | - ruleId: 'style' |
617 | | - }) |
618 | | - message.file = state.filePath || undefined |
619 | | - message.url = |
620 | | - 'https://github.com/syntax-tree/hast-util-to-jsx-runtime#cannot-parse-style-attribute' |
621 | | - |
622 | | - throw message |
| 616 | + if (!state.ignoreInvalidStyle) { |
| 617 | + const cause = /** @type {Error} */ (error) |
| 618 | + const message = new VFileMessage('Cannot parse `style` attribute', { |
| 619 | + ancestors, |
| 620 | + cause, |
| 621 | + source: 'hast-util-to-jsx-runtime', |
| 622 | + ruleId: 'style' |
| 623 | + }) |
| 624 | + message.file = state.filePath || undefined |
| 625 | + message.url = |
| 626 | + 'https://github.com/syntax-tree/hast-util-to-jsx-runtime#cannot-parse-style-attribute' |
| 627 | + |
| 628 | + throw message |
| 629 | + } |
623 | 630 | } |
624 | 631 |
|
625 | 632 | return result |
|
0 commit comments