How to use the @rollup/pluginutils.attachScopes function in @rollup/pluginutils

To help you get started, we’ve selected a few @rollup/pluginutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rollup / plugins / packages / commonjs / src / transform.js View on Github external
sourceMap,
  allowDynamicRequire,
  astCache
) {
  const ast = astCache || tryParse(parse, code, id);

  const magicString = new MagicString(code);

  const required = {};
  // Because objects have no guaranteed ordering, yet we need it,
  // we need to keep track of the order in a array
  const sources = [];

  let uid = 0;

  let scope = attachScopes(ast, 'scope');
  const uses = { module: false, exports: false, global: false, require: false };

  let lexicalDepth = 0;
  let programDepth = 0;

  const globals = new Set();

  // TODO technically wrong since globals isn't populated yet, but ¯\_(ツ)_/¯
  const HELPERS_NAME = deconflict(scope, globals, 'commonjsHelpers');

  const namedExports = {};

  // TODO handle transpiled modules
  let shouldWrap = /__esModule/.test(code);

  function isRequireStatement(node) {
github rollup / plugins / packages / inject / src / index.js View on Github external
}
      if (!ast) {
        return null;
      }

      const imports = new Set();
      ast.body.forEach((node) => {
        if (node.type === 'ImportDeclaration') {
          node.specifiers.forEach((specifier) => {
            imports.add(specifier.local.name);
          });
        }
      });

      // analyse scopes
      let scope = attachScopes(ast, 'scope');

      const magicString = new MagicString(code);

      const newImports = new Map();

      function handleReference(node, name, keypath) {
        let mod = modulesMap.get(keypath);
        if (mod && !imports.has(name) && !scope.contains(name)) {
          if (typeof mod === 'string') mod = [mod, 'default'];

          // prevent module from importing itself
          if (mod[0] === id) return false;

          const hash = `${keypath}:${mod[0]}:${mod[1]}`;

          const importLocalName =

@rollup/pluginutils

A set of utility functions commonly used by Rollup plugins

MIT
Latest version published 6 months ago

Package Health Score

97 / 100
Full package analysis