(ast: any, env: TransformerEnv)
| 879 | } |
| 880 | |
| 881 | function transformPug(ast: any, env: TransformerEnv) { |
| 882 | let { matcher } = env |
| 883 | |
| 884 | // This isn't optimal |
| 885 | // We should merge the classes together across class attributes and class tokens |
| 886 | // And then we sort them |
| 887 | // But this is good enough for now |
| 888 | |
| 889 | // First sort the classes in attributes |
| 890 | for (const token of ast.tokens) { |
| 891 | if (token.type === 'attribute' && matcher.hasStaticAttr(token.name)) { |
| 892 | token.val = [ |
| 893 | token.val.slice(0, 1), |
| 894 | sortClasses(token.val.slice(1, -1), { env }), |
| 895 | token.val.slice(-1), |
| 896 | ].join('') |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | // Collect lists of consecutive class tokens |
| 901 | let startIdx = -1 |
| 902 | let endIdx = -1 |
| 903 | let ranges: [number, number][] = [] |
| 904 | |
| 905 | for (let i = 0; i < ast.tokens.length; i++) { |
| 906 | const token = ast.tokens[i] |
| 907 | |
| 908 | if (token.type === 'class') { |
| 909 | startIdx = startIdx === -1 ? i : startIdx |
| 910 | endIdx = i |
| 911 | } else if (startIdx !== -1) { |
| 912 | ranges.push([startIdx, endIdx]) |
| 913 | startIdx = -1 |
| 914 | endIdx = -1 |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | if (startIdx !== -1) { |
| 919 | ranges.push([startIdx, endIdx]) |
| 920 | startIdx = -1 |
| 921 | endIdx = -1 |
| 922 | } |
| 923 | |
| 924 | // Sort the lists of class tokens |
| 925 | for (const [startIdx, endIdx] of ranges) { |
| 926 | const classes = ast.tokens.slice(startIdx, endIdx + 1).map((token: any) => token.val) |
| 927 | |
| 928 | const { classList } = sortClassList({ |
| 929 | classList: classes, |
| 930 | api: env.context, |
| 931 | removeDuplicates: false, |
| 932 | }) |
| 933 | |
| 934 | for (let i = startIdx; i <= endIdx; i++) { |
| 935 | ast.tokens[i].val = classList[i - startIdx] |
| 936 | } |
| 937 | } |
| 938 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…