capturing.js
function replaceRefs(parsed, options) {
  var topLevel = topLevelDeclsAndRefs(parsed),
      refsToReplace = topLevel.refs.filter(ref => shouldRefBeCaptured(ref, topLevel, options)),
      locallyIgnored = [];

  const replaced = ReplaceVisitor.run(parsed, (node, path) => {

    // cs 2016/06/27, 1a4661
    // ensure keys of shorthand properties are not renamed while capturing
    if (node.type === "Property"
     && refsToReplace.includes(node.key)
     && node.shorthand)
       return prop(id(node.key.name), node.value);

    // don't replace var refs in expressions such as "export { x }" or "export var x;"
    // We make sure that those var references are defined in insertDeclarationsForExports()
    if (node.type === "ExportNamedDeclaration") {
      var { declaration, specifiers } = node;
      if (declaration) {
        if (declaration.id) locallyIgnored.push(declaration.id)
        else if (declaration.declarations)
          locallyIgnored.push(...declaration.declarations.map(({id}) => id))
      }
      specifiers && specifiers.forEach(({local}) => locallyIgnored.push(local));
      return node;
    }

    // declaration wrapper function for assignments
    // "a = 3" => "a = _define('a', 'assignment', 3, _rec)"
    if (node.type === "AssignmentExpression"
     && refsToReplace.includes(node.left)
     && options.declarationWrapper)
       return {
         ...node,
         right: declarationWrapperCall(
                  options.declarationWrapper,
                  null,
                  literal(node.left.name),
                  literal("assignment"),
                  node.right,
                  options.captureObj,
                  options)};

     return node
  });

  return ReplaceVisitor.run(replaced, (node, path, parent) =>
    refsToReplace.includes(node) && !locallyIgnored.includes(node) ?
      member(options.captureObj, node) : node);
}
function replaceRefs(parsed, options) {
  var topLevel = topLevelDeclsAndRefs(parsed),
      refsToReplace = topLevel.refs.filter(ref => shouldRefBeCaptured(ref, topLevel, options)),
      locallyIgnored = [];

  const replaced = ReplaceVisitor.run(parsed, (node, path) => {

    // cs 2016/06/27, 1a4661
    // ensure keys of shorthand properties are not renamed while capturing
    if (node.type === "Property"
     && refsToReplace.includes(node.key)
     && node.shorthand)
       return prop(id(node.key.name), node.value);

    // don't replace var refs in expressions such as "export { x }" or "export var x;"
    // We make sure that those var references are defined in insertDeclarationsForExports()
    if (node.type === "ExportNamedDeclaration") {
      var { declaration, specifiers } = node;
      if (declaration) {
        if (declaration.id) locallyIgnored.push(declaration.id)
        else if (declaration.declarations)
          locallyIgnored.push(...declaration.declarations.map(({id}) => id))
      }
      specifiers && specifiers.forEach(({local}) => locallyIgnored.push(local));
      return node;
    }

    // declaration wrapper function for assignments
    // "a = 3" => "a = _define('a', 'assignment', 3, _rec)"
    if (node.type === "AssignmentExpression"
     && refsToReplace.includes(node.left)
     && options.declarationWrapper)
       return {
         ...node,
         right: declarationWrapperCall(
                  options.declarationWrapper,
                  null,
                  literal(node.left.name),
                  literal("assignment"),
                  node.right,
                  options.captureObj,
                  options)};

     return node
  });

  return ReplaceVisitor.run(replaced, (node, path, parent) =>
    refsToReplace.includes(node) && !locallyIgnored.includes(node) ?
      member(options.captureObj, node) : node);
}
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- replacement helpers