简体   繁体   English

预处理 Javascript 以删除 object 属性名称引号

[英]Preprocess Javascript to remove object property names quotes

I would like to preprocess javascript property names to convert them from我想预处理 javascript 属性名称以将它们从

{
  'extension': object,
  'config': {id: 1}
}

to

{
  extension: object,
  config: {id: 1}
}

I know that they mean the same thing for JS, but they are not the same thing for Google Closure Compiler on Advance mode where the quoted property is left untouched while the unquoted might be changed to我知道它们对 JS 的意思是一样的,但是对于高级模式下的 Google Closure Compiler 来说它们不是一回事,其中引用的属性保持不变,而未引用的属性可能会更改为

{
  a: object,
  b: {a: 1}
}  

I am not sure if this is the right solution to my original problem which is:我不确定这是否是我原来的问题的正确解决方案,即:

Developers are working on an extension based on an API.开发人员正在开发基于 API 的扩展。 This API is defined by quoted property names.此 API 由引用的属性名称定义。 The code on my side is compiled and mangled.我这边的代码被编译和修改。 I would like to take their code, remove all the quotes and compile both my code and the developer code on advance and at the end there should be no 'extension' string in the final.js我想使用他们的代码,删除所有引号并提前编译我的代码和开发人员代码,最后在 final.js 中应该没有“扩展”字符串

Thanks谢谢

If all you need is to remove quotes, Prettier has options to remove quotes from properties:如果您只需要删除引号,Prettier 可以选择从属性中删除引号:

https://prettier.io/docs/en/options.html#quote-props https://prettier.io/docs/en/options.html#quote-props

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM