|
181 | 181 | { find: /export default class/g, replace: 'class' }, |
182 | 182 | { find: /import React from 'react';/g, replace: '' }, |
183 | 183 | { find: /import React from"react";/g, replace: '' }, |
| 184 | + { find: /=>,/g, replace:'=>' }, // Work-around for edge-case JSX, Issue 21 on GitHub |
184 | 185 | ], |
185 | 186 |
|
186 | 187 | /** |
|
588 | 589 | return false; |
589 | 590 | }, |
590 | 591 |
|
| 592 | + /** |
| 593 | + * Helper function that gets called when a '<' charater is |
| 594 | + * found to determine if it's likely an element or not. |
| 595 | + * |
| 596 | + * @param {string} input |
| 597 | + * @param {number} current |
| 598 | + * @param {number} length |
| 599 | + * @returns {bool} |
| 600 | + */ |
| 601 | + isExpression: function(input, current, length) { |
| 602 | + var pos = current + 2; |
| 603 | + var foundName = false; |
| 604 | + while (pos < length) { |
| 605 | + var nextChar = input[pos]; |
| 606 | + pos++; |
| 607 | + if (/[a-zA-Z0-9_/]/.test(nextChar)) { |
| 608 | + if (foundName) { |
| 609 | + break; |
| 610 | + } else { |
| 611 | + continue; |
| 612 | + } |
| 613 | + } else if (nextChar === '>') { |
| 614 | + break; |
| 615 | + } else if (nextChar === ' ') { |
| 616 | + foundName = true; |
| 617 | + continue; |
| 618 | + } else if (nextChar === ')' || nextChar === '&' || nextChar === '|' || nextChar === '?' || nextChar === ';') { |
| 619 | + // This happens if an less than expression uses no spaces and the |
| 620 | + // right-hand side value is a variable. Issue #20 on GitHub. |
| 621 | + return true; |
| 622 | + } |
| 623 | + } |
| 624 | + return false; |
| 625 | + }, |
| 626 | + |
591 | 627 | /** |
592 | 628 | * Compiler Step 1 - Remove Comments from the Code |
593 | 629 | * |
|
709 | 745 | break; |
710 | 746 | case '<': |
711 | 747 | charNext = peekNext(); |
712 | | - if (/[a-zA-Z>]/.test(charNext)) { |
| 748 | + if (/[a-zA-Z>]/.test(charNext) && !this.isExpression(input, current, length)) { |
713 | 749 | state.elementCount++; |
714 | 750 | } else if (charNext === '/') { |
715 | 751 | state.elementCount--; |
|
785 | 821 | state.inStringMultiLine = true; |
786 | 822 | break; |
787 | 823 | case '<': |
788 | | - if (/[a-zA-Z>]/.test(input[c + 1])) { |
| 824 | + if (/[a-zA-Z>]/.test(input[c + 1]) && !jsxLoader.compiler.isExpression(input, c, length)) { |
789 | 825 | return c; // Start of Element found |
790 | 826 | } |
791 | 827 | break; |
|
1103 | 1139 | } |
1104 | 1140 | break; |
1105 | 1141 | case '<': |
1106 | | - if (/[a-zA-Z>/]/.test(peekNext())) { |
| 1142 | + if (/[a-zA-Z>/]/.test(peekNext()) && !jsxLoader.compiler.isExpression(input, current, length)) { |
1107 | 1143 | state.addChild = true; |
1108 | 1144 | state.inElement = true; |
1109 | 1145 | } |
|
0 commit comments