Visit ExportDeclaration.

Examples:

export default = value
export default;
export DECLARATION
export { name, one as other }
8493
function visitExportDeclaration(traverse, node, path, state) {
  var specifier, name, len, i;
  utils.catchup(node.range[0], state);

  if (node.declaration) {

    // export default = value
    if (Array.isArray(node.declaration)) {

      assert(
        node.declaration.length === 1,
        formatError('cannot export more than a single declaration', node));

      name = node.declaration[0].id.name;
      switch (name) {
        case 'default':
          utils.append('module.exports =', state);
          break;
        default:
          utils.append('module.exports.' + name + ' = ', state);
      }

      if (node.declaration[0].init) {
        // -1 compensates for an additional space after '=' token
        utils.move(node.declaration[0].init.range[0] - 1, state);
        traverse(node.declaration[0].init, path, state);
      } else {
        utils.move(node.range[1], state);
      }


    // export DECLARATION
    } else {
      switch (node.declaration.type) {
        // export var name = value
        case Syntax.VariableDeclaration:
          utils.move(node.declaration.range[0], state);
          node.declaration.declarations.forEach(function(declaration) {
            utils.catchup(declaration.id.range[1], state);
            utils.append(' = module.exports.' + declaration.id.name, state);
            traverse(declaration.init, path, state);
          });
          break;
        case Syntax.FunctionDeclaration:
          name = node.declaration.id.name;
          utils.move(node.declaration.range[0], state);
          traverse(node.declaration, path, state);
          utils.append(' module.exports.' + name + ' = ' + name + ';', state);
          break;
        case Syntax.ClassDeclaration:
          name = node.declaration.id.name;
          utils.move(node.declaration.range[0], state);
          traverse(node.declaration, path, state);
          utils.append('module.exports.' + name + ' = ' + name + ';', state);
          break;
        default:
          assert(false, "unknown declaration: " + node.declaration.type);
      }
    }

  } else if (node.source) {

    var modID;

    // export * from "module"
    if (node.specifiers.length === 1 &&
        node.specifiers[0].type === Syntax.ExportBatchSpecifier) {

      modID = genID('mod');
      utils.append('var ' + modID + ' = require(' + node.source.raw + ');', state);

      var keyID = genID('key');
      utils.append(
        'for (var ' + keyID + ' in ' + modID + ') ' +
        'module.exports[' + keyID + '] = ' + modID + '[' + keyID + '];',
        state
      );

      utils.move(node.range[1], state);

    // export {name, one as other} from "module"
    } else {

      if (node.specifiers.length === 1) {
        modID = 'require(' + node.source.raw + ')';
      } else {
        modID = genID('mod');
        utils.append('var ' + modID + ' = require(' + node.source.raw + ');', state);
      }

      for (i = 0, len = node.specifiers.length; i < len; i++) {
        specifier = node.specifiers[i];
        utils.catchupNewlines(specifier.range[0], state);
        name = specifier.name ? specifier.name.name : specifier.id.name;
        utils.append(
          'module.exports.' + name + ' = ' + modID +
          '.' + specifier.id.name + ';',
          state
        );
        utils.move(specifier.id.range[1], state);
      }
    }

    utils.catchupNewlines(node.range[1], state);
    utils.move(node.range[1], state);

  } else if (node.specifiers) {

    // export { name, one as other }
    for (i = 0, len = node.specifiers.length; i < len; i++) {
      specifier = node.specifiers[i];
      utils.catchupNewlines(specifier.range[0], state);
      name = specifier.name ? specifier.name.name : specifier.id.name;
      utils.append('module.exports.' + name + ' = ' + specifier.id.name + ';', state);
    }

    utils.catchupNewlines(node.range[1], state);
    utils.move(node.range[1], state);

  } else {

    assert(false, "don't know how to compile export declaration");
  }

  return false;
}
613953
function parseExportSpecifier() {
        var exported, local, node = new Node(), def;
        if (matchKeyword('default')) {
            // export {default} from 'something';
            def = new Node();
            lex();
            local = def.finishIdentifier('default');
        } else {
            local = parseVariableIdentifier();
        }
        if (matchContextualKeyword('as')) {
            lex();
            exported = parseNonComputedProperty();
        }
        return node.finishExportSpecifier(local, exported);
    }
1257191
function importTypes(names: Array<string>, module: string) {
  const importDeclaration = t.importDeclaration(
    names.map(name =>
      t.importSpecifier(t.identifier(name), t.identifier(name)),
    ),
    t.stringLiteral(module),
  );
  importDeclaration.importKind = 'type';
  return importDeclaration;
}
898675
function getTypeForVariableLikeDeclaration(declaration, includeOptionality) {
            if (declaration.flags & 134217728 /* JavaScriptFile */) {
                // If this is a variable in a JavaScript file, then use the JSDoc type (if it has
                // one as its type), otherwise fallback to the below standard TS codepaths to
                // try to figure it out.
                var type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration);
                if (type && type !== unknownType) {
                    return type;
                }
            }
            // A variable declared in a for..in statement is always of type string
            if (declaration.parent.parent.kind === 207 /* ForInStatement */) {
                return stringType;
            }
            if (declaration.parent.parent.kind === 208 /* ForOfStatement */) {
                // checkRightHandSideOfForOf will return undefined if the for-of expression type was
                // missing properties/signatures required to get its iteratedType (like
                // [Symbol.iterator] or next). This may be because we accessed properties from anyType,
                // or it may have led to an error inside getElementTypeOfIterable.
                return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType;
            }
            if (ts.isBindingPattern(declaration.parent)) {
                return getTypeForBindingElement(declaration);
            }
            // Use type from type annotation if one is present
            if (declaration.type) {
                return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality);
            }
            if (declaration.kind === 142 /* Parameter */) {
                var func = declaration.parent;
                // For a parameter of a set accessor, use the type of the get accessor if one is present
                if (func.kind === 150 /* SetAccessor */ && !ts.hasDynamicName(func)) {
                    var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 149 /* GetAccessor */);
                    if (getter) {
                        var getterSignature = getSignatureFromDeclaration(getter);
                        var thisParameter = getAccessorThisParameter(func);
                        if (thisParameter && declaration === thisParameter) {
                            // Use the type from the *getter*
                            ts.Debug.assert(!thisParameter.type);
                            return getTypeOfSymbol(getterSignature.thisParameter);
                        }
                        return getReturnTypeOfSignature(getterSignature);
                    }
                }
                // Use contextual parameter type if one is available
                var type = void 0;
                if (declaration.symbol.name === "this") {
                    var thisParameter = getContextualThisParameter(func);
                    type = thisParameter ? getTypeOfSymbol(thisParameter) : undefined;
                }
                else {
                    type = getContextuallyTypedParameterType(declaration);
                }
                if (type) {
                    return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality);
                }
            }
            // Use the type of the initializer expression if one is present
            if (declaration.initializer) {
                return addOptionality(checkExpressionCached(declaration.initializer), /*optional*/ declaration.questionToken && includeOptionality);
            }
            // If it is a short-hand property assignment, use the type of the identifier
            if (declaration.kind === 254 /* ShorthandPropertyAssignment */) {
                return checkIdentifier(declaration.name);
            }
            // If the declaration specifies a binding pattern, use the type implied by the binding pattern
            if (ts.isBindingPattern(declaration.name)) {
                return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ false, /*reportErrors*/ true);
            }
            // No type specified and nothing can be inferred
            return undefined;
        }
853948
function buildExportNameListDeclaration(
  programPath: NodePath,
  metadata: ModuleMetadata,
) {
  const exportedVars = Object.create(null);
  for (const data of metadata.local.values()) {
    for (const name of data.names) {
      exportedVars[name] = true;
    }
  }

  let hasReexport = false;
  for (const data of metadata.source.values()) {
    for (const exportName of data.reexports.keys()) {
      exportedVars[exportName] = true;
    }
    for (const exportName of data.reexportNamespace) {
      exportedVars[exportName] = true;
    }

    hasReexport = hasReexport || data.reexportAll;
  }

  if (!hasReexport || Object.keys(exportedVars).length === 0) return null;

  const name = programPath.scope.generateUidIdentifier("exportNames");

  delete exportedVars.default;

  return {
    name: name.name,
    statement: t.variableDeclaration("var", [
      t.variableDeclarator(name, t.valueToNode(exportedVars)),
    ]),
  };
}
1129415
function getHelperMetadata(file) {
  const globals = new Set();
  const localBindingNames = new Set();
  // Maps imported identifier -> helper name
  const dependencies = new Map();

  let exportName;
  let exportPath;
  const exportBindingAssignments = [];
  const importPaths = [];
  const importBindingsReferences = [];

  traverse(file, {
    ImportDeclaration(child) {
      const name = child.node.source.value;
      if (!helpers[name]) {
        throw child.buildCodeFrameError(`Unknown helper ${name}`);
      }
      if (
        child.get("specifiers").length !== 1 ||
        !child.get("specifiers.0").isImportDefaultSpecifier()
      ) {
        throw child.buildCodeFrameError(
          "Helpers can only import a default value",
        );
      }
      const bindingIdentifier = child.node.specifiers[0].local;
      dependencies.set(bindingIdentifier, name);
      importPaths.push(makePath(child));
    },
    ExportDefaultDeclaration(child) {
      const decl = child.get("declaration");

      if (decl.isFunctionDeclaration()) {
        if (!decl.node.id) {
          throw decl.buildCodeFrameError(
            "Helpers should give names to their exported func declaration",
          );
        }

        exportName = decl.node.id.name;
      }
      exportPath = makePath(child);
    },
    ExportAllDeclaration(child) {
      throw child.buildCodeFrameError("Helpers can only export default");
    },
    ExportNamedDeclaration(child) {
      throw child.buildCodeFrameError("Helpers can only export default");
    },
    Statement(child) {
      if (child.isModuleDeclaration()) return;

      child.skip();
    },
  });

  traverse(file, {
    Program(path) {
      const bindings = path.scope.getAllBindings();

      Object.keys(bindings).forEach(name => {
        if (name === exportName) return;
        if (dependencies.has(bindings[name].identifier)) return;

        localBindingNames.add(name);
      });
    },
    ReferencedIdentifier(child) {
      const name = child.node.name;
      const binding = child.scope.getBinding(name, /* noGlobal */ true);
      if (!binding) {
        globals.add(name);
      } else if (dependencies.has(binding.identifier)) {
        importBindingsReferences.push(makePath(child));
      }
    },
    AssignmentExpression(child) {
      const left = child.get("left");

      if (!(exportName in left.getBindingIdentifiers())) return;

      if (!left.isIdentifier()) {
        throw left.buildCodeFrameError(
          "Only simple assignments to exports are allowed in helpers",
        );
      }

      const binding = child.scope.getBinding(exportName);

      if (binding && binding.scope.path.isProgram()) {
        exportBindingAssignments.push(makePath(child));
      }
    },
  });

  if (!exportPath) throw new Error("Helpers must default-export something.");

  // Process these in reverse so that mutating the references does not invalidate any later paths in
  // the list.
  exportBindingAssignments.reverse();

  return {
    globals: Array.from(globals),
    localBindingNames: Array.from(localBindingNames),
    dependencies,
    exportBindingAssignments,
    exportPath,
    exportName,
    importBindingsReferences,
    importPaths,
  };
}
870261
function exportDeclarations() {

    var docs = getJSONDocs();
    var sugarjs = getDeclaredNamespace('sugarjs');

    var extendedInterfaces = [], nativeNames = [];

    function getNamespaceTypesMerged(num, suffixVal, join, supplementary) {
      var types = nativeNames.concat(supplementary || []);
      var indent = ' '.repeat(num);
      return types.map(function(type) {
        var suffix = typeof suffixVal === 'function' ? suffixVal(type) : suffixVal;
        return type + suffix;
      }).join(' ' + join + '\n' + indent);
    }

    function getChainableNameExternal(type) {
      return '.Chainable' + getChainableBaseGenerics(type, CHAINABLE_RAW_TYPE, 'any');
    }

    function writeDeclarations(filename, declarations) {
      declarations = compact(declarations);
      var hasNoDeclarations = declarations.every(function(dec) {
        return /^\/\//.test(dec);
      });
      if (hasNoDeclarations) {
        return;
      }
      writeFile(path.join(basePath || '', filename), compact(declarations).join('\n\n'));
    }

    sugarjs.interfaces.push(getLocaleInterface(docs.namespaces));

    // Sort namespaces for Sugar to come before SugarNamespace
    // as it has ExtendOptions which are defined first.
    docs.namespaces.sort(collateNamespaces);

    docs.namespaces.forEach(function(namespace) {

      function addExtras(module) {
        addCallbackTypes(module);
        addOptionsInterfaces(module);
      }

      function addCallbackTypes(module) {

        // If the param has multiple types, then move callbacks into the
        // module as named types. Only do this if there are multiple
        // types, otherwise the callback signature can be inlined into
        // the method declaration.
        function getAlternateTypes(method) {
          var types = [];

          function process(arr) {
            if (arr) {
              arr.forEach(function(obj) {
                if (obj.type) {
                  var split = obj.type.split('|');
                  if (split.length > 1) {
                    types = types.concat(split);
                  }
                }
              });
            }
          }

          process(method.params);
          process(method.options);

          return types;
        }

        function addModuleCallbackType(method, callback) {
          var typeExists = module.types.some(function(t) {
            return t.name === callback.name;
          });
          if (!typeExists) {
            var signature = getCallbackSignature(callback, method, namespace);
            if (method.generics) {
              moduleCallbackGenerics[namespace.name + ':' + callback.name] = method.generics;
            }
            module.types.push({
              name: callback.name,
              generics: getGenericSource(callback.generics),
              type: signature
            });
          }
        }

        namespace.methods.forEach(function(method) {
          if (!method.callbacks || methodIsBlacklisted(namespace.name, method)) {
            return;
          }
          getAlternateTypes(method).forEach(function(type) {
            if (type.match(/Fn$/)) {
              var callback = findMethodCallbackByName(method, type);
              addModuleCallbackType(method, callback);
            }
          });
        });

      }

      function addOptionsInterfaces(module) {
        namespace.methods.forEach(function(method) {
          if (!method.options || methodIsBlacklisted(namespace.name, method)) {
            return;
          }

          var params = method.params;
          (method.signatures || []).forEach(function(signature) {
            params = params.concat(signature);
          })

          var optionsParam = params.find(function(param) {
            return param.type.match(/Options$/);
          });

          var optionsGenerics = [];

          var src = method.options.map(function(option) {
            var types = option.type.split('|');
            types = types.map(function(type) {
              if (type.match(/Fn$/)) {
                var callback = findMethodCallbackByName(method, type);
                if (types.length === 1 && type.match(/Fn$/)) {
                  // Inline a callback delcaration
                  type = getCallbackSignature(callback, method, namespace);
                } else {
                  // Refer to callback externally
                  type += getGenericSource(moduleCallbackGenerics[namespace.name + ':' + callback.name]);
                }
                optionsGenerics = optionsGenerics.concat(callback.generics);
              }
              return type;
            });
            return option.name + (option.required ? '' : '?') + ': ' + types.join('|') + ';';
          }).join('\n');

          // Store references to the namespaces that option interfaces exist in
          // so that we can reference them externally later.
          if (!namespace.name.match(/^Sugar/)) {
            optionInterfaceNamespaces[optionsParam.type] = namespace.name;
          }

          moduleOptionsGenerics[namespace.name + ':' + optionsParam.type] = optionsGenerics;
          var name = optionsParam.type + getGenericSource(optionsGenerics);
          module.interfaces.push(getInterfaceSource(name, src));
        });
      }

      function getCallbackSignature(callback, method, namespace) {
        var genericsLength = method.generic && method.generics.length || 0, gen;
        var params = getParams(callback.params, method, namespace);
        var returns = callback.returns ? getType(callback.returns, method) : 'void';
        // Slightly convoluted way of getting generics for the callback by
        // subtracting method generics from what they were previously.
        callback.generics = method.generics.slice(genericsLength);
        return '(' + params + ') => ' + returns;
      }

      function findMethodCallbackByName(method, name) {
        return method.callbacks.find(function(callback) {
          return callback.name === name;
        });
      }


      // Exclude polyfills
      namespace.methods = namespace.methods.filter(function(method) {
        return !method.module.match(/ES[5-7]/);
      });

      // Unpack sets like "[unit]FromNow"
      namespace.methods = unpackMethodSets(namespace.methods);

      if (namespace.name === 'Sugar') {
        addExtras(sugarjs);
        sugarjs.interfaces.push(getSugarInterface(namespace, docs.namespaces));
      } else if (namespace.name === 'SugarNamespace') {
        // The generic "SugarNamespace" interface is required for the
        // "createNamespace" method that needs to return an as-yet undefined
        // type. For existing namespaces, the methods here will instead be
        // mixed into each individual interface. This is required, as each
        // namespace returns a reference to itself, and so (it would appear)
        // cannot use extend.
        addExtras(sugarjs);
        sugarjs.interfaces.push(getSugarNamespaceInterface(namespace));
      } else if (namespace.name === 'Range') {
        sugarjs.interfaces.push(getRangeInterface(namespace));
      } else {
        var module = getDeclaredNamespace(namespace.name);
        addExtras(module);
        module.interfaces.push(getConstructorInterface(namespace, module));
        module.interfaces.push(getChainableBaseInterface(namespace));


        // Export extended interfaces unless opting out.
        if (args['extended-mode'] !== false) {
          extendedInterfaces.push(getExtendedConstructorInterface(namespace));

          // Note: due to Typescript quirkiness about incompatible interfaces,
          // Object.prototype mode cannot be supported here for now.
          if (namespace.name !== 'Object') {
            extendedInterfaces.push(getExtendedInstanceInterface(namespace));
          }
        }

        sugarjs.namespaces.push(getDeclaredNamespaceSource(module));
        nativeNames.push(namespace.name);
      }

    });

    var wrappedGeneric = getGenericSource(CHAINABLE_RAW_TYPE);
    sugarjs.types.push({
      name: 'SugarDefaultChainable' + wrappedGeneric,
      type: getNamespaceTypesMerged(39, getChainableNameExternal, '&'),
    });

    sugarjs.types.push({
      name: 'NativeConstructor',
      type: getNamespaceTypesMerged(25, 'Constructor', '|', ['Boolean', 'Error']),
    });


    var baseDeclarations = [];
    baseDeclarations.push(TS_LICENSE);
    baseDeclarations.push(getDeclaredNamespaceSource(sugarjs, true));
    baseDeclarations.push(getDeclaredModuleSource());
    baseDeclarations.push('declare var Sugar: sugarjs.Sugar;');

    var extendedDeclarations = [];
    extendedDeclarations.push(TS_EXTENDED_LICENSE);
    extendedDeclarations.push('/// <reference path="sugar.d.ts" />');
    extendedDeclarations.push(getInterfaceBlocks(extendedInterfaces));

    writeDeclarations('sugar.d.ts', baseDeclarations);
    writeDeclarations('sugar-extended.d.ts', extendedDeclarations);
  }
774107
function buildExportInitializationStatements(
  programPath: NodePath,
  metadata: ModuleMetadata,
  loose: boolean = false,
) {
  const initStatements = [];

  const exportNames = [];
  for (const [localName, data] of metadata.local) {
    if (data.kind === "import") {
      // No-open since these are explicitly set with the "reexports" block.
    } else if (data.kind === "hoisted") {
      initStatements.push(
        buildInitStatement(metadata, data.names, t.identifier(localName)),
      );
    } else {
      exportNames.push(...data.names);
    }
  }

  for (const data of metadata.source.values()) {
    if (!loose) {
      initStatements.push(...buildReexportsFromMeta(metadata, data, loose));
    }
    for (const exportName of data.reexportNamespace) {
      exportNames.push(exportName);
    }
  }

  initStatements.push(
    ...chunk(exportNames, 100).map(members => {
      return buildInitStatement(
        metadata,
        members,
        programPath.scope.buildUndefinedNode(),
      );
    }),
  );

  return initStatements;
}
497229
function checkVariableDeclaration(node) {
            const parent = node.parent;
            const type = node.kind;

            if (!options[type]) {
                return;
            }

            const declarations = node.declarations;
            const declarationCounts = countDeclarations(declarations);
            const mixedRequires = declarations.some(isRequire) && !declarations.every(isRequire);

            if (options[type].initialized === MODE_ALWAYS) {
                if (options.separateRequires && mixedRequires) {
                    context.report({
                        node,
                        message: "Split requires to be separated into a single block."
                    });
                }
            }

            // consecutive
            const nodeIndex = (parent.body && parent.body.length > 0 && parent.body.indexOf(node)) || 0;

            if (nodeIndex > 0) {
                const previousNode = parent.body[nodeIndex - 1];
                const isPreviousNodeDeclaration = previousNode.type === "VariableDeclaration";
                const declarationsWithPrevious = declarations.concat(previousNode.declarations || []);

                if (
                    isPreviousNodeDeclaration &&
                    previousNode.kind === type &&
                    !(declarationsWithPrevious.some(isRequire) && !declarationsWithPrevious.every(isRequire))
                ) {
                    const previousDeclCounts = countDeclarations(previousNode.declarations);

                    if (options[type].initialized === MODE_CONSECUTIVE && options[type].uninitialized === MODE_CONSECUTIVE) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    } else if (options[type].initialized === MODE_CONSECUTIVE && declarationCounts.initialized > 0 && previousDeclCounts.initialized > 0) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with initialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    } else if (options[type].uninitialized === MODE_CONSECUTIVE &&
                            declarationCounts.uninitialized > 0 &&
                            previousDeclCounts.uninitialized > 0) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with uninitialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    }
                }
            }

            // always
            if (!hasOnlyOneStatement(type, declarations)) {
                if (options[type].initialized === MODE_ALWAYS && options[type].uninitialized === MODE_ALWAYS) {
                    context.report({
                        node,
                        message: "Combine this with the previous '{{type}}' statement.",
                        data: {
                            type
                        },
                        fix: joinDeclarations(declarations)
                    });
                } else {
                    if (options[type].initialized === MODE_ALWAYS && declarationCounts.initialized > 0) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with initialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    }
                    if (options[type].uninitialized === MODE_ALWAYS && declarationCounts.uninitialized > 0) {
                        if (node.parent.left === node && (node.parent.type === "ForInStatement" || node.parent.type === "ForOfStatement")) {
                            return;
                        }
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with uninitialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    }
                }
            }

            // never
            if (parent.type !== "ForStatement" || parent.init !== node) {
                const totalDeclarations = declarationCounts.uninitialized + declarationCounts.initialized;

                if (totalDeclarations > 1) {
                    if (options[type].initialized === MODE_NEVER && options[type].uninitialized === MODE_NEVER) {

                        // both initialized and uninitialized
                        context.report({
                            node,
                            message: "Split '{{type}}' declarations into multiple statements.",
                            data: {
                                type
                            },
                            fix: splitDeclarations(node)
                        });
                    } else if (options[type].initialized === MODE_NEVER && declarationCounts.initialized > 0) {

                        // initialized
                        context.report({
                            node,
                            message: "Split initialized '{{type}}' declarations into multiple statements.",
                            data: {
                                type
                            },
                            fix: splitDeclarations(node)
                        });
                    } else if (options[type].uninitialized === MODE_NEVER && declarationCounts.uninitialized > 0) {

                        // uninitialized
                        context.report({
                            node,
                            message: "Split uninitialized '{{type}}' declarations into multiple statements.",
                            data: {
                                type
                            },
                            fix: splitDeclarations(node)
                        });
                    }
                }
            }
        }
635272
function isExportsStatement(expression) {

    var type, object, property;

    type = expression.type;
    object = expression.object;
    property = expression.property;

    return type === 'MemberExpression' && object && object.name === 'exports' && property && property.type === 'Identifier';

}
989372
Node createSingleConstNameDeclaration(String variableName, Node value) {
    return IR.constNode(createName(variableName, value.getJSType()), value);
  }
471743
function nameAnonymousExports(programPath) {
    // Name anonymous exported locals.
    programPath.get('body').forEach(child => {
        if (!child.isExportDefaultDeclaration()) {
            return;
        }

        // export default foo;
        const declaration = child.get('declaration');
        if (declaration.isFunctionDeclaration()) {
            if (!declaration.node.id) {
                declaration.node.id = declaration.scope.generateUidIdentifier('default');
            }
        }
        else if (declaration.isClassDeclaration()) {
            if (!declaration.node.id) {
                declaration.node.id = declaration.scope.generateUidIdentifier('default');
            }
        }
        else {
            const id = declaration.scope.generateUidIdentifier('default');
            const namedDecl = babelTypes.exportNamedDeclaration(null, [
                babelTypes.exportSpecifier(babelTypes.identifier(id.name), babelTypes.identifier('default')),
            ]);
            namedDecl._blockHoist = child.node._blockHoist;

            const varDecl = babelTypes.variableDeclaration('var', [
                babelTypes.variableDeclarator(id, declaration.node),
            ]);
            varDecl._blockHoist = child.node._blockHoist;

            child.replaceWithMultiple([namedDecl, varDecl]);
        }
    });
}
937230
def compute_exports(exports):
    """"""

    loc, glob = get_calling_namespaces()

    retval = {}
    try:
        for export in exports:
            if SCons.Util.is_Dict(export):
                retval.update(export)
            else:
                try:
                    retval[export] = loc[export]
                except KeyError:
                    retval[export] = glob[export]
    except KeyError as x:
        raise SCons.Errors.UserError("Export of non-existent variable '%s'"%x)

    return retval
1359640
function buildNamespaceInitStatements(meta, metadata, checkExport) {
    const statements = [];
    const {localImportName, localImportDefaultName} = getLocalImportName(metadata);

    for (const exportName of metadata.reexportNamespace) {
        // Assign export to namespace object.
        checkExport(exportName);
        statements.push(buildExport({exportName, localName: localImportName}));
    }

    // Source code:
    //      import {color2 as color2Alias, color3, color4, color5} from 'xxx';
    //      export {default as b} from 'xxx';
    //      export {color2Alias};
    //      export {color3};
    //      let color5Renamed = color5
    //      export {color5Renamed};
    // Only two entries in metadata.reexports:
    //      'color2Alias' => 'color2'
    //      'color3' => 'color3',
    //      'b' => 'default'
    //
    // And consider:
    //      export {default as defaultAsBB} from './xx/yy';
    //      export {exportSingle} from './xx/yy';
    // No entries in metadata.imports, and 'default' exists in metadata.reexports.
    for (const entry of metadata.reexports.entries()) {
        const exportName = entry[0];
        checkExport(exportName);
        statements.push(
            (localImportDefaultName || entry[1] === 'default')
                ? buildExport({exportName, localName: localImportName})
                : buildExport({exportName, namespace: localImportName, propName: entry[1]})
        );
    }

    if (metadata.reexportAll) {
        const statement = buildNamespaceReexport(
            meta,
            metadata.name,
            checkExport
        );
        statement.loc = metadata.reexportAll.loc;

        // Iterate props creating getter for each prop.
        statements.push(statement);
    }

    return statements;
}
675170
private List<String> convertExports( Map<String,String> exports ) {

		List<String> result = new ArrayList<> ();
		for( Map.Entry<String,String> entry : exports.entrySet()) {
			String componentOrFacet = VariableHelpers.parseVariableName( entry.getKey()).getKey();
			String s = Utils.isEmptyOrWhitespaces( componentOrFacet )
					? entry.getKey()
					: applyLink( entry.getKey(), componentOrFacet );

			if( ! Utils.isEmptyOrWhitespaces( entry.getValue()))
				s += MessageFormat.format( this.messages.get( "default" ), entry.getValue()); //$NON-NLS-1$

			if( entry.getKey().toLowerCase().endsWith( ".ip" )) //$NON-NLS-1$
				s += this.messages.get( "injected" ); //$NON-NLS-1$

			result.add( s );
		}

		return result;
	}
721275
function hasInferredName(node) {
            const parent = node.parent;

            return isObjectOrClassMethod(node) ||
                (parent.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.init === node) ||
                (parent.type === "Property" && parent.value === node) ||
                (parent.type === "AssignmentExpression" && parent.left.type === "Identifier" && parent.right === node) ||
                (parent.type === "ExportDefaultDeclaration" && parent.declaration === node) ||
                (parent.type === "AssignmentPattern" && parent.right === node);
        }
316607
function getVariableDeclaration(babelTypes, kind, name, value) { // {{{
  return babelTypes.variableDeclaration(kind, [
    babelTypes.variableDeclarator(
      babelTypes.identifier(name),
      value
    )
  ]);
}