@babel/plugin-transform-property-literals

Ensure that reserved words are quoted in object property keys

This plugin is included in @babel/preset-env

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var foo = {
  // changed
  const: function() {},
  var: function() {},

  // not changed
  "default": 1,
  [a]: 2,
  foo: 1,
};

转换后

1
2
3
4
5
6
7
8
var foo = {
  "const": function() {},
  "var": function() {},

  "default": 1,
  [a]: 2,
  foo: 1,
};