|
| 1 | +import {operator} from 'putout'; |
| 2 | +import {astiAc, astiEc} from '../../../pratyahara.js'; |
| 3 | +import {praptaPratapadika} from '../../../pratipadika.js'; |
| 4 | + |
| 5 | +const {remove} = operator; |
| 6 | + |
| 7 | +export const report = () => `eco yavāyāvaḥ`; |
| 8 | + |
| 9 | +export const fix = ({path, next, name, nextName}) => { |
| 10 | + if (name.endsWith('e')) { |
| 11 | + path.node.name = `${name.slice(0, -1)}ay${nextName}`; |
| 12 | + remove(next); |
| 13 | + |
| 14 | + return; |
| 15 | + } |
| 16 | + |
| 17 | + if (name.endsWith('o')) { |
| 18 | + path.node.name = `${name.slice(0, -1)}av${nextName}`; |
| 19 | + remove(next); |
| 20 | + |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + if (name.endsWith('ai')) { |
| 25 | + path.node.name = `${name.slice(0, -1)}Ay${nextName}`; |
| 26 | + remove(next); |
| 27 | + |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + if (name.endsWith('au')) { |
| 32 | + path.node.name = `${name.slice(0, -1)}Av${nextName}`; |
| 33 | + remove(next); |
| 34 | + |
| 35 | + return; |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +export const traverse = ({push}) => ({ |
| 40 | + Identifier(path) { |
| 41 | + const next = path.getNextSibling(); |
| 42 | + |
| 43 | + if (!next.node) |
| 44 | + return; |
| 45 | + |
| 46 | + const {name} = path.node; |
| 47 | + |
| 48 | + const nextName = next.node.name; |
| 49 | + const first = nextName.at(0); |
| 50 | + const last = name.at(-1); |
| 51 | + const preLast = name.at(-2); |
| 52 | + |
| 53 | + if (!astiEc(last) && !astiEc(preLast + last)) |
| 54 | + return; |
| 55 | + |
| 56 | + if (!astiAc(first)) |
| 57 | + return; |
| 58 | + |
| 59 | + if (first === 'e' && first === last) |
| 60 | + return; |
| 61 | + |
| 62 | + const stem = praptaPratapadika(name); |
| 63 | + |
| 64 | + if (stem && stem !== name) |
| 65 | + return; |
| 66 | + |
| 67 | + push({ |
| 68 | + path, |
| 69 | + next, |
| 70 | + name, |
| 71 | + nextName, |
| 72 | + }); |
| 73 | + }, |
| 74 | +}); |
0 commit comments