Skip to content

Commit

Permalink
WIP 2
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 21, 2023
1 parent a3145a6 commit 64f750c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* TODO comment in `visitors/function`
* TODO comment in `serialize/parseFunction`
* Deal with duplicate bindings:
* Hoisted sloppy functions
* `for (let x of x)`
* `x => { var x; }`
* Hoisted sloppy functions - actually no need, because `isFunction` means both are frozen anyway
* `for (let x of (() => x, [])) eval('x');` - done, but write test
* `function (x, _ = eval('x')) { var x; return x; }`
* Tests
* Tests for binding in higher scope which is shadowed still not being renamed
e.g. `() => { let x = 1; { let x; eval('typeof a !== "undefined" && a = 2'); } return x; }` - make sure param `x` not renamed to `a`
18 changes: 9 additions & 9 deletions lib/instrument/visitors/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Statement = require('./statement.js'),
Expression = require('./expression.js'),
VariableDeclaration = require('./variableDeclaration.js'),
{AssigneeAssignOnly} = require('./assignee.js'),
{createBlock, createAndEnterBlock, createBindingWithoutNameCheck} = require('../blocks.js'),
{createBlock, createAndEnterBlock} = require('../blocks.js'),
{insertBlockVarsIntoBlockStatement} = require('../tracking.js'),
{visitKey, visitKeyMaybe, visitKeyContainer} = require('../visit.js');

Expand Down Expand Up @@ -98,15 +98,15 @@ function ForXStatement(node, state) {
// with all same bindings as init block. Accessing these vars from within right-hand side
// is temporal dead zone violation.
// https://github.com/overlookmotel/livepack/issues/323
// These bindings are in a different block, but just copy the binding objects themselves.
// This ensures that if any binding is frozen by `eval()`, the corresponding binding is too.
// e.g. `function() { let f; for (let x of (f = () => typeof x, [])) { eval('x'); } }`
// Without this, serializing outer function would allow `x` in `typeof x` to be mangled so it wouldn't
// be a TDZ violation any more.
state.currentBlock = parentBlock;
const initBindingNames = Object.keys(initBlock.bindings);
if (initBindingNames.length !== 0) {
const rightBlock = createAndEnterBlock('for', false, state),
fn = state.currentFunction;
for (const varName of initBindingNames) {
const binding = createBindingWithoutNameCheck(rightBlock, varName, {isConst: true});
if (fn) fn.bindings.push(binding);
}
if (Object.keys(initBlock.bindings).length !== 0) {
const rightBlock = createAndEnterBlock('for', false, state);
rightBlock.bindings = initBlock.bindings;
}

// Visit right-hand side
Expand Down

0 comments on commit 64f750c

Please sign in to comment.