shapeleak
Find subsequent changes in the shape (hidden-class) of your Objects which result in unoptimized code. If you don't know what we talking about I can recommend this article.
Requires Node 6.4+
Features
- Print exact location of the vulnerability.
- Can be applied to Factory, Object-Literal and objects instantiated by
new
. - Does not break existing code.
Example
const S = // new { thisname = name } A = const a = 'peter'aname = 'sandra'aname = 1afoo = 'bar'delete aname // Factory { return name } build = const b = bname = 'sandra'bname = 1bfoo = 'bar'delete bname // Object literal let c = cname = 'sandra'cname = 1cfoo = 'bar'delete bname
Output
E:\Repositorys\shaped\example.js
20:8 warn - Property 'name' has change his type from 'string' to 'number'
21:7 error - Property 'foo' was added to shape (name)
22:1 error - Property 'name' was deleted from shape (name,foo)
37:8 warn - Property 'name' has change his type from 'string' to 'number'
38:7 error - Property 'foo' was added to shape (name)
39:1 error - Property 'name' was deleted from shape (name,foo)
50:8 warn - Property 'name' has change his type from 'string' to 'number'
51:7 error - Property 'foo' was added to shape (name)
52:1 error - Property 'name' was deleted from shape (foo)