(attr: any, env: TransformerEnv)
| 25 | } |
| 26 | |
| 27 | function transformDynamicAngularAttribute(attr: any, env: TransformerEnv) { |
| 28 | let directiveAst = tryParseAngularAttribute(attr.value, env) |
| 29 | |
| 30 | // If we've reached this point we couldn't parse the expression we we should bail |
| 31 | // `tryParseAngularAttribute` will display some warnings/errors |
| 32 | // But we shouldn't fail outright — just miss parsing some attributes |
| 33 | if (!directiveAst) { |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | let changes: StringChange[] = [] |
| 38 | |
| 39 | visit(directiveAst, { |
| 40 | StringLiteral(node, path) { |
| 41 | if (!node.value) return |
| 42 | |
| 43 | let collapseWhitespace = canCollapseWhitespaceIn(path, env) |
| 44 | |
| 45 | changes.push({ |
| 46 | start: node.start + 1, |
| 47 | end: node.end - 1, |
| 48 | before: node.value, |
| 49 | after: sortClasses(node.value, { |
| 50 | env, |
| 51 | collapseWhitespace, |
| 52 | }), |
| 53 | }) |
| 54 | }, |
| 55 | |
| 56 | TemplateLiteral(node, path) { |
| 57 | if (!node.quasis.length) return |
| 58 | |
| 59 | let collapseWhitespace = canCollapseWhitespaceIn(path, env) |
| 60 | |
| 61 | for (let i = 0; i < node.quasis.length; i++) { |
| 62 | let quasi = node.quasis[i] |
| 63 | |
| 64 | changes.push({ |
| 65 | start: quasi.start, |
| 66 | end: quasi.end, |
| 67 | before: quasi.value.raw, |
| 68 | after: sortClasses(quasi.value.raw, { |
| 69 | env, |
| 70 | |
| 71 | // Is not the first "item" and does not start with a space |
| 72 | ignoreFirst: i > 0 && !/^\s/.test(quasi.value.raw), |
| 73 | |
| 74 | // Is between two expressions |
| 75 | // And does not end with a space |
| 76 | ignoreLast: i < node.expressions.length && !/\s$/.test(quasi.value.raw), |
| 77 | |
| 78 | collapseWhitespace: collapseWhitespace |
| 79 | ? { |
| 80 | start: collapseWhitespace.start && i === 0, |
| 81 | end: collapseWhitespace.end && i >= node.expressions.length, |
| 82 | } |
| 83 | : false, |
| 84 | }), |
no test coverage detected
searching dependent graphs…