The Republican Party had a chance to disavow Donald Trump’s xenophobia and nativism. Instead, the GOP doubled down. In the new 2016 Republican platform, delegates not only promised a wall along the southern border; they also decided to replace the term “illegal immigrants” with the more pejorative, dehumanizing epithet “illegal aliens.”

If history is any guide, these choices could prove very, very costly.

It’s true that Americans, or at least a vocal subset of Americans, have a long history of hostility toward immigrants. But for the most part, presidential candidates and their parties have been punished whenever they’ve indulged that hostility during election years.

The past century and a half provides case after case of candidates getting electorally pummeled after explicitly or implicitly endorsing anti-immigrant rhetoric. In almost every instance, this loss persuaded the defeated party to pivot toward more immigrant-friendly policies by the next election.

In 1844, the Whig presidential ticket actively solicited endorsements from nativist groups. Whig vice-presidential candidate Theodore Frelinghuysen even led several organizations that were “openly hostile to Catholicism and new immigration,” as recounted in the book “Dividing Lines: The Politics of Immigration Control in America,” by Daniel J. Tichenor, a political scientist at the University of Oregon.

Here are some of the people who are speaking at the 2016 Republican National Convention in Cleveland and some who've opted to skip the event. (Sarah Parnass,Danielle Kunitz/The Washington Post)

When the Whigs lost, party leadership concluded that Democrats’ support among immigrants and Catholics had swung the election. Accordingly, the Whigs severed ties with their nativist allies.

Or consider 1884. A week before that election, at a Republican rally, a prominent Protestant minister impugned Democrats as the party of “rum, Romanism and rebellion.”

Republican leadership failed to denounce the comments, which were widely interpreted as slurring Irish Catholic immigrants (among others). Democrats reprinted the minister’s words near and far, and the speech is believed to have cost Republicans the election.

Through the early 1890s, Democrats played up the Republican Party’s connection to the American Protective Association, a virulently anti-Catholic, anti-Irish-immigrant secret society. This cost Republicans more ground among Irish and German Catholics and newer immigrant groups, Tichenor writes.

One of those Republican casualties was William McKinley, who lost his U.S. congressional seat in 1890. When he ran for governor of Ohio the following year, he realized he needed more immigrant and kindred ethnic votes to have any chance. So he chucked the nativist baggage.

On the campaign trail, McKinley declared that his economic vision “believes in America for Americans, native and naturalized”; and that U.S. shores must remain open to “those who are well disposed to our institutions, seeking new and happier homes, ready to share the burdens as well as the blessings of our society.”

He repeated this strategy in his 1896 presidential run and worked to purge the influence of the nativist secret society from his party. In a show of “cultural harmony,” Tichenor writes, a rabbi gave the opening prayer at the Republican National Convention. The party also distributed campaign pamphlets in foreign languages. The about-face helped bring more immigrants in to the GOP fold, and McKinley took the White House.

There are more recent analogues, too.

In 1996, Republican presidential candidate Bob Dole was weighed down by anti-immigrant measures championed by his party, including opposition to public education of undocumented children and support for a constitutional amendment to deny birthright citizenship to children born to undocumented parents on U.S. soil.

This resulted in a huge boost in Latino and Asian votes for Democratic rival Bill Clinton. Clinton won in a landslide, and Dole became the first Republican candidate in two decades to lose immigrant-heavy Florida.

Not just coincidentally, in the next presidential election, Republican nominee George W. Bush worked hard to remind Latino voters that he didn’t “bash immigrants.”

Even more recently, Mitt Romney’s comments encouraging “self-deportation” lost him a majority of Latino and Asian votes in the 2012 election. The GOP’s post-election “autopsy” lamented this language and urged the party to embrace immigration reform ASAP.

Trump’s assessment was even more damning. Just weeks after Romney’s defeat, Trump declared the self-deportation comments “mean-spirited” and “maniacal.” A Republican Party pivot on immigration was in order, Trump announced, if it wanted to win back the presidency.

But of course, this time, that pivot never came.

These many historical precedents are not dispositive. But they are instructive. Like it or not, we are a nation of immigrants. Naturalized immigrants, and their children and kindred ethnics, are almost always a large share of our electorate. Today, as in other periods, they are also a growing share of the electorate.

Politicians alienate the “aliens” at their peril.