Fix #2232 - wrongly matching prop after comments ending with a dot (#2249)

* Fix #2232 - wrongly matching prop after comments ending with a dot

* Avoid matching urls `://`
This commit is contained in:
Rasmus Porsager 2018-10-14 22:32:28 +02:00 committed by Isiah Meadows
parent 385458aadd
commit 68e412bb59
3 changed files with 6 additions and 5 deletions

View file

@ -93,9 +93,10 @@ function run(input, output) {
})
//fix props
var props = new RegExp("(\\.\\s*)(" + candidates + ")|([\\{,]\\s*)(" + candidates + ")(\\s*:)", "gm")
var props = new RegExp("((?:[^:]\\/\\/.*)?\\.\\s*)(" + candidates + ")|([\\{,]\\s*)(" + candidates + ")(\\s*:)", "gm")
code = code.replace(props, function(match, dot, a, pre, b, post) {
if (dot) return dot + a.replace(/\d+$/, "")
if (dot && dot.indexOf("//") === 1) return match // Don't do anything because dot was matched in a comment
else if (dot) return dot + a.replace(/\d+$/, "")
else return pre + b.replace(/\d+$/, "") + post
})