https://www.scientificamerican.com/article/caterpillar-butterfly-metamorphosis-explainer/
Extract
The caterpillar digests itself, releasing enzymes to dissolve all of its tissues. If you were to cut open a cocoon or chrysalis at just the right time, caterpillar soup would ooze out. But the contents of the pupa are not entirely an amorphous mess. Certain highly organized groups of cells known as imaginal discs survive the digestive process. Before hatching, when a caterpillar is still developing inside its egg, it grows an imaginal disc for each of the adult body parts it will need as a mature butterfly or moth—discs for its eyes, for its wings, its legs and so on.
