How to use the @babel/helper-module-imports.addNamed 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 indico / js-flask-urls / packages / flask-urls.macro / src / flask-urls.macro.js View on Github external
const quasi = parentPath.node.quasi;
    if (quasi.expressions.length) {
      throw new MacroError('flask-url.macro cannot contain expressions');
    }

    const endpoint = quasi.quasis[0].value.cooked;

    if (builderFuncId) {
      builderFuncId = t.cloneDeep(builderFuncId);
    }

    let replacement;
    if (config.mock) {
      if (!builderFuncId) {
        builderFuncId = addNamedImport(state.file.path, 'mockFlaskURL', config.builder, {
          nameHint: 'mockFlaskURL',
        });
      }

      replacement = buildFuncMock({
        FUNC: builderFuncId,
        ENDPOINT: t.stringLiteral(endpoint),
      });
    } else {
      const data = config.urlMap[endpoint];
      if (!data) {
        throw new MacroError('flask-url.macro must reference a valid flask endpoint');
      }

      // generate import
      if (!builderFuncId) {
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 => {
        if (!importMap[importName]) {
          importMap[importName] = addNamed(
            path,
            importName,
            getSource(state.source, importName),
            {
              importedInterop: "uncompiled",
              ensureLiveReference: true,
            },
          ).name;
        }
      });
github chpio / babel-plugin-transform-promise-to-bluebird / main.js View on Github external
MemberExpression(path) {
				const {node} = path;
				const obj = node.object;

				if (obj.name !== 'Promise') return;
				if (!path.isReferenced()) return;
				if (path.scope.getBindingIdentifier('Promise')) return;

				if (node.computed) {
					path.replaceWith(
						t.memberExpression(
							addNamed(path, 'default', 'bluebird', {nameHint: 'Promise'}),
							node.property,
							true
						)
					);
				} else {
					path.replaceWith(
						addNamed(
							path,
							node.property.name,
							'bluebird',
							{nameHint: 'Promise'}
						)
					);
				}
			},
		},
github yesmeck / reactive.macro / src / state.ts View on Github external
export default function state(stateUpdaters: Map, path: NodePath) {
  const variableDeclaration = path.findParent(p => t.isVariableDeclaration(p)) as NodePath;
  const stateVariable = path.find(p => t.isVariableDeclarator(p)).get('id') as NodePath;
  const initState = getInitState(path);
  const hookId = addNamed(path, 'useState', 'react');
  const updater = path.scope.generateUidIdentifier(`set${stateVariable.node.name}`);
  stateUpdaters.set(stateVariable.node.name, updater);
  variableDeclaration.insertAfter(
    t.variableDeclaration('const', [
      t.variableDeclarator(
        t.arrayPattern([t.identifier(stateVariable.node.name), updater]),
        t.callExpression(hookId, [initState])
      )
    ])
  );
  path.replaceWith(initState);
  const functionDeclaration = path.getFunctionParent();
  functionDeclaration.traverse({
    AssignmentExpression(path: NodePath) {
      const variable = path.get('left').node;
      if (
github ryansolid / babel-plugin-jsx-dom-expressions / src / index.js View on Github external
function registerImportMethod(path, name) {
    const imports =
      path.scope.getProgramParent().data.imports ||
      (path.scope.getProgramParent().data.imports = new Set());
    if (!imports.has(name)) {
      addNamed(path, name, moduleName, { nameHint: `_$${name}` });
      imports.add(name);
    }
  }
github indico / js-flask-urls / packages / babel-plugin-flask-urls / src / plugin.js View on Github external
} else if (!t.isImportDefaultSpecifier(path.node.specifiers[0])) {
            throw path
              .get('specifiers.0')
              .buildCodeFrameError(`${importPrefix} imports must use a default import`);
          }
          const importName = path.node.specifiers[0].local.name;

          let builderFuncId = this.builderFuncId;
          if (builderFuncId) {
            builderFuncId = t.cloneDeep(builderFuncId);
          }

          let variable;
          if (mock) {
            if (!builderFuncId) {
              builderFuncId = this.builderFuncId = addNamedImport(
                path,
                'mockFlaskURL',
                builderImportLocation,
                {
                  nameHint: 'mockFlaskURL',
                }
              );
            }

            variable = t.variableDeclarator(
              t.identifier(importName),
              buildFuncMock({
                FUNC: builderFuncId,
                ENDPOINT: t.stringLiteral(endpoint),
              })
            );
github yesmeck / reactive.macro / src / bind.ts View on Github external
export default function bind(stateUpdaters: Map, path: NodePath) {
  const jsxElement = path.findParent(p => t.isJSXOpeningElement(p)) as NodePath;
  const createElementCall = path.find(p => t.isCallExpression(p)).findParent(p => t.isCallExpression(p)) as NodePath<
    t.CallExpression
  >;
  const stateVariable = (path.parentPath.get('arguments') as Array)[0] as NodePath;
  const eventVariable = path.scope.generateUidIdentifier('e');
  const updater = stateUpdaters.get(stateVariable.node.name);
  const helperId = addDefault(path, 'reactive.macro/lib/helpers/getValue', {
    nameHint: 'getValue'
  });
  const hookId = addNamed(path, 'useCallback', 'react');
  const handler = t.callExpression(hookId, [
    t.arrowFunctionExpression(
      [eventVariable],
      t.callExpression(updater!, [t.callExpression(helperId, [eventVariable])])
    ),
    t.arrayExpression()
  ]);
  if (jsxElement) {
    jsxElement.node.attributes.push(t.jsxAttribute(t.jsxIdentifier('onChange'), t.jsxExpressionContainer(handler)));
  } else if (createElementCall) {
    (createElementCall.node.arguments[1] as t.ObjectExpression).properties.push(
      t.objectProperty(t.identifier('onChange'), handler)
    );
  }
  path.findParent(p => t.isCallExpression(p)).replaceWith(stateVariable.node);
}
github babel / babel / packages / babel-plugin-transform-async-to-generator / src / index.js View on Github external
Function(path, state) {
          if (!path.node.async || path.node.generator) return;

          let wrapAsync = state.methodWrapper;
          if (wrapAsync) {
            wrapAsync = t.cloneNode(wrapAsync);
          } else {
            wrapAsync = state.methodWrapper = addNamed(path, method, module);
          }

          remapAsyncToGenerator(path, { wrapAsync });
        },
      },
github krhougs / mina-webpack-plugin / packages / core / src / remax / BabelRemaxPagePlugin.js View on Github external
function pageConfigExpression(path, id) {
  const createId = addNamed(path, 'createPageConfig', 'remax')
  path.insertAfter(
    t.exportDefaultDeclaration(
      t.callExpression(
        t.identifier('Page'), [t.callExpression(createId, [id])])))
}
github format-message / format-message / packages / babel-plugin-transform-format-message / index.js View on Github external
message.helper = function (type) {
          return imports.addNamed(path, type, 'format-message')
        }

@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