-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5faf3d4
commit bc4c0e5
Showing
14 changed files
with
296 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# TODO | ||
|
||
* Tests | ||
* Deal with `with` in `eval()` | ||
* TODO comments |
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
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
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,58 @@ | ||
/* -------------------- | ||
* livepack module | ||
* Code instrumentation visitor for `with` statements | ||
* ------------------*/ | ||
|
||
'use strict'; | ||
|
||
// Export | ||
module.exports = WithStatement; | ||
|
||
// Modules | ||
const t = require('@babel/types'); | ||
|
||
// Imports | ||
const Expression = require('./expression.js'), | ||
Statement = require('./statement.js'), | ||
{createAndEnterBlock, createBindingWithoutNameCheck} = require('../blocks.js'), | ||
{createTrackerVarNode} = require('../internalVars.js'), | ||
{visitKey} = require('../visit.js'); | ||
|
||
// Exports | ||
|
||
/** | ||
* Visitor for `with () {}` statement. | ||
* @param {Object} node - Statement AST node | ||
* @param {Object} state - State object | ||
* @returns {undefined} | ||
*/ | ||
function WithStatement(node, state) { | ||
// Visit object i.e. expression inside `with (...)` | ||
visitKey(node, 'object', Expression, state); | ||
|
||
// Create block for `with` object | ||
const parentBlock = state.currentBlock; | ||
const block = createAndEnterBlock('with', false, state); | ||
const binding = createBindingWithoutNameCheck(block, 'with', {isConst: true}, state); | ||
|
||
// Visit body | ||
visitKey(node, 'body', Statement, state); | ||
|
||
// Exit block | ||
state.currentBlock = parentBlock; | ||
|
||
// Queue action to wrap `with` object | ||
state.secondPass(instrumentWithObj, node, binding, state); | ||
} | ||
|
||
function instrumentWithObj(node, binding, state) { | ||
// `with (o) {}` -> `with ( livepack_tracker.wrapWith(livepack_temp2 = o) ) {}` | ||
node.object = t.callExpression( | ||
t.memberExpression(createTrackerVarNode(state), t.identifier('wrapWith')), | ||
[ | ||
binding.varNode | ||
? t.assignmentExpression('=', binding.varNode, node.object) | ||
: node.object | ||
] | ||
); | ||
} |
Oops, something went wrong.