Skip to content

Commit

Permalink
pre-build NodePath and share it
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Dec 15, 2014
1 parent 8ccc0de commit f890cb0
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function compile(source, options) {
*/
function transform(ast, options) {
if (!options) { options = {}; }
var ast = new recast.types.NodePath(ast);;

if (options.computedPropertyKeys !== false) {
ast = es6computedProperties.transform(ast);
Expand Down

2 comments on commit f890cb0

@drslump
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pattern should be as follows:

var rootPath = new recast.types.NodePath(ast);

if (options.xxx) {
  es6xxx.transform(rootPath);
}
if (options.yyy) {
  es6yyy.transform(rootPath);
}
...

transform returns a Node not a NodePath, so if it gets reassigned on the next run a new one is created instead of reusing a single one.

When the transformations are over you can obtain the AST back with rootPath.value.

@stefanpenner
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, quick attempt revealed some of the transforms steps don't work with this technique yet (but most seem to)

Please sign in to comment.