In the first and second trimesters, occasionally eating chocolate is safe, as long as you don’t go overboard. There has been some debate about eating foods that contain polyphenols, like dark chocolate which contains a much higher level than milk chocolate, in the third trimester. One study found they can trigger a condition that is rare but serious in which too much blood circulates in the lungs and heart of the fetus (source).
Don’t worry if you’ve eaten chocolate late in pregnancy — the key is to cut down and monitor your intake. If you think you could benefit from some additional information about your diet, consult your doctor.