@contrast/rewriter 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,12 +1,8 @@
1
1
  ## `@contrast/rewriter`
2
2
 
3
- Provides a configured service for rewriting code.
3
+ Rewrite javascript code with custom rewrite transforms.
4
4
 
5
- Basic idea: Enabled features can register rewrite transforms to support their end goal.
6
-
7
- Example: Assess
8
-
9
- Assess will register transforms for `+` -> `contrast_add()` so that it can perform propagation
5
+ For example, Assess will register transforms for `+` -> `contrast_add()` so that it can perform propagation
10
6
  via instrumentation of `contrast_add()`.
11
7
 
12
8
 
@@ -15,7 +11,7 @@ via instrumentation of `contrast_add()`.
15
11
  ```typescript
16
12
  const { Rewriter } = require('.');
17
13
 
18
- const rewriter = new Rewriter({ config, logger });
14
+ const rewriter = new Rewriter({ logger });
19
15
 
20
16
  rewriter.addTransforms({
21
17
  BinaryExpression(path) {
@@ -33,7 +29,5 @@ rewriter.addTransforms({
33
29
  }
34
30
  });
35
31
 
36
- const result = rewriter.rewriteFile({
37
- content: 'function add(x, y) { return x + y; }'
38
- });
32
+ const result = rewriter.rewrite('function add(x, y) { return x + y; }');
39
33
  ```
package/lib/index.js CHANGED
@@ -79,6 +79,9 @@ class Rewriter {
79
79
  statement(
80
80
  'const ContrastMethods = global.ContrastMethods || (() => { throw new SyntaxError(\'ContrastMethods undefined during compilation\'); })();'
81
81
  )(),
82
+ statement(
83
+ 'var Function = global.ContrastMethods.Function || Function;'
84
+ )(),
82
85
  ]);
83
86
  }
84
87
  },
@@ -88,11 +91,6 @@ class Rewriter {
88
91
  t.callExpression(expression('global.ContrastMethods.eval')(), path.node.arguments)
89
92
  ];
90
93
  }
91
- if (path.node.callee.name === 'Function') {
92
- path.node.arguments = [
93
- t.callExpression(expression('global.ContrastMethods.Function')(), path.node.arguments)
94
- ];
95
- }
96
94
  },
97
95
  };
98
96
  this.unwriteTransforms = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/rewriter",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "A transpilation tool mainly used for instrumentation",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",