Tesla has a preliminary deal with the Shanghai municipal government that will give Tesla ownership of a new Tesla factory in Shanghai’s free trade zone.

The preliminary deal still offers Tesla control over its trade secrets and may give the company leverage to negotiate better terms with the Chinese government in the future. Tesla hopes to complete the deal by the end of the year.

Tesla to build cars in Shanghai while still paying tariffs on them would be a coup for the Chinese government. If Tesla were making cars in the Shanghai area, it would have a powerful incentive to buy many, if not most, of the parts in China, strengthening China’s base of suppliers for the fast-growing electric car industry.

China already has the world’s largest market for electric cars.

LMC Automotive, a global consulting firm, estimates that 295,000 battery-electric cars will be sold this year in China, compared with 287,000 in the rest of the world combined. LMC predicts that China’s total will nearly triple in the next two years, while the rest of the world’s will merely double.

Chinese government regulations will require automakers starting in 2019 to sell ever-increasing numbers of electric cars and plug-in hybrids if they want to keep selling gasoline cars.

China is and will be the largest consumer and producer of electric vehicles in the world. Tesla has to compete in China.

China charges a tariff of 25 percent on imported cars, compared with 2.5 percent in the United States and 9.8 percent in the European Union. China also has a 17 percent value-added tax — a kind of sales tax — that is charged not only on the price of the car but also on the tariff, so that the taxes are effectively compounded.