关于使用StrollingWolf工具去除代码注释的一些注意事项

前言

近期项目中遇到需求,需要处理掉从Github上获取到的JavaScript代码中的注释,因为正则方法很难完全去除各种形式的注释。故找到了一个叫StrollingWolf的工具,号称能够去除多种语言中的各种形式的注释。试用之后发现确实效果还不错,我以为它的原理是基于语法树去除的,然而在正式在项目中使用它时却发生了意外。

重现

首先发现其处理过后的数据中有莫名其妙的缺失,于是慢慢排查,发现确实是由于这个工具引起的。例子:

function(input) {
	
  input = input.replace(/'/g, "''")
  // backslashes (\) must be replaced with double backslashes (\\)
  input = input.replace(/\\/g, '\\\\')
  // double quotes (") must be replaced with escaped quotes (\\")
  input = input.replace(/"/g, '\\"')
  return input
}

function() {

    this.title = "OpenClipart.org";
    this.name = "OpenClipart.org";
    this.uri = "https://openclipart.org/";
    this.icon = "https://openclipart.org/favicon.ico";
    this.baseUri = "https://openclipart.org/search/json/&
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值