-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This gains us a massive speedup, envify w/ recast takes almost 7 secs on my mba when browserifying React codebase. While envify w/ jstransform takes this down to 1.5 sec (pre-recast speed) and deliver the same advantages as recast transform (preserves code formatting).
- Loading branch information
1 parent
c66ef44
commit 6216358
Showing
3 changed files
with
38 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var Syntax = require('esprima-fb').Syntax; | ||
var utils = require('jstransform/src/utils'); | ||
|
||
function create(env) { | ||
|
||
function visitProcessEnv(traverse, node, path, state) { | ||
var key = node.property.name; | ||
if (env[key] !== undefined) { | ||
utils.catchup(node.range[0], state); | ||
utils.append(JSON.stringify(env[key]), state); | ||
utils.move(node.range[1], state); | ||
} | ||
return false; | ||
} | ||
|
||
visitProcessEnv.test = function(node, path, state) { | ||
return ( | ||
node.type === Syntax.MemberExpression | ||
&& !node.computed | ||
&& node.property.type === Syntax.Identifier | ||
&& node.object.type === Syntax.MemberExpression | ||
&& node.object.object.type === Syntax.Identifier | ||
&& node.object.object.name === 'process' | ||
&& node.object.property.type === Syntax.Identifier | ||
&& node.object.property.name === 'env' | ||
) | ||
}; | ||
|
||
return [visitProcessEnv]; | ||
} | ||
|
||
module.exports = create; |