How to use the @babel/helper-module-imports.addNamespace function in @babel/helper-module-imports

To help you get started, we’ve selected a few @babel/helper-module-imports 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 alan-ai / alan-sdk-reactnative / testtools / node_modules / @babel / helper-builder-react-jsx-experimental / src / index.js View on Github external
imports.forEach(importName => {
        const source = getSource(state.source, importName);
        if (!importMap[importName]) {
          if (!sourceMap[source]) {
            // var _react = require("react")
            sourceMap[source] = addNamespace(path, source, {
              importedInterop: "uncompiled",
              ensureLiveReference: true,
            }).name;
          }

          importMap[importName] = sourceMap[source];
        }
      });
      return importMap;
github chialab / rna-cli / lib / Bundlers / plugins / babel-plugin-dynamic-to-static / babel-plugin-dynamic-to-static.js View on Github external
imports.forEach((imp) => {
                    const identifier = identifiers[imp.moduleName] = identifiers[imp.moduleName] || babelModuleImports.addNamespace(path, imp.moduleName);
                    imp.path.parentPath.replaceWithSourceString(`Promise.resolve(${identifier.name})`);
                });
            },
github vhfmag / tsguard.macro / src / macro.js View on Github external
callExpression.typeParameters.params.length !== 1
    ) {
      throw new MacroError(
        "Macro should be called as a function and passed exactly one type parameter",
      );
    }

    const macroArgument = callExpression.arguments[0];

    if (!t.isIdentifier(macroArgument)) {
      throw new MacroError(
        "For now, this macro works with identifiers only, sorry",
      );
    }

    const generatedImport = addNamespace(path, "generic-type-guard");

    if (!t.isIdentifier(generatedImport)) {
      throw new MacroError("Something wrong happened at our side, sorry");
    }

    const expectedType = callExpression.typeParameters.params[0];
    const identifier = macroArgument.name;
    const generatedCode = `(${typeToPartialGuard(
      expectedType,
      generatedImport.name,
    )})(${identifier})`;
    const generatedAst = parser.parse(generatedCode);
    path.parentPath.replaceWith(generatedAst.program.body[0]);
  }
}

@babel/helper-module-imports

Babel helper functions for inserting module loads

MIT
Latest version published 2 months ago

Package Health Score

95 / 100
Full package analysis

Similar packages