China 's parliament has passed legislation giving the country 's military a legal basis for attacking Taiwan if the island moves toward declaring independence .