How to use babel-helpers - 10 common examples

To help you get started, we’ve selected a few babel-helpers 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 salesforce / lwc / packages / babel-helpers-lwc / src / index.js View on Github external
helpers.list.forEach(function (name) {
        if (whitelist && whitelist.indexOf(name) < 0) return;

        const key = t.identifier(name);

        // AST tree for: objectMember.helperName = function () { ... }
        body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier('babelHelpers'), key), helpers.get(name))));
    });
}
github babel / babel / packages / babel-core / src / transformation / file / index.js View on Github external
if (declar) return declar;

    const generator = this.get("helperGenerator");
    const runtime = this.get("helpersNamespace");
    if (generator) {
      const res = generator(name);
      if (res) return res;
    } else if (runtime) {
      return t.memberExpression(runtime, t.identifier(name));
    }

    const uid = (this.declarations[name] = this.scope.generateUidIdentifier(
      name,
    ));

    const { nodes, globals } = getHelper(
      name,
      name => this.addHelper(name),
      uid,
      () => Object.keys(this.scope.getAllBindings()),
    );

    globals.forEach(name => {
      if (this.path.scope.hasBinding(name, true /* noGlobals */)) {
        this.path.scope.rename(name);
      }
    });

    nodes.forEach(node => {
      node._compact = true;
    });
github salesforce / lwc / packages / babel-helpers-lwc / src / index.js View on Github external
function buildHelpers(body, whitelist) {
    helpers.list.forEach(function (name) {
        if (whitelist && whitelist.indexOf(name) < 0) return;

        const key = t.identifier(name);

        // AST tree for: objectMember.helperName = function () { ... }
        body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier('babelHelpers'), key), helpers.get(name))));
    });
}
// Regenerator is a special dependency that we want to include
github LivelyKernel / lively4-core / src / external / plugin-babel / build-babel / systemjs-build-modular-babel-helpers.js View on Github external
var fs = require('fs');
var babel = require('babel');
var helpers = require('babel-helpers');
var t = babel.types;

// ES Module helpers based on https://github.com/babel/babel/blob/master/packages/babel-runtime/scripts/build-dist.js
helpers.list.forEach(function(helperName) {
  var tree = t.program([
    t.exportDefaultDeclaration(helpers.get(helperName))
  ]);
  
  fs.writeFileSync('../babel-helpers/' + helperName + '.js', babel.transformFromAst(tree).code);
});
github TehShrike / abstract-state-router / rollup.config.js View on Github external
}),
		babel({
			babelrc: false,
			presets: [
				[
					'es2015',
					{
						modules: false,
					},
				],
			],
			plugins: [
				'external-helpers',
			],
			// fixing temporary rollup's regression, remove when rollup/rollup#1595 gets solved
			externalHelpersWhitelist: babelHelpersList.filter(helperName => helperName !== 'asyncGenerator'),
		}),
		visualizer(),
	],
	external: [
		'combine-arrays',
		'eventemitter3',
		'hash-brown-router',
		'iso-next-tick',
		'page-path-builder',
		'path-to-regexp-with-reversible-keys',
		'then-denodeify',
	],
}
github brianZeng / babel-plugin-transform-helper / src / HelperRemap.js View on Github external
getUsedMethods({exclude}={}){
    if (!Array.isArray(exclude)) {
      exclude = [];
    }
    let ret = [];
    for (let name of this.usedHelpers) {
      if (exclude.indexOf(name) == -1) {
        let METHOD = this._definedHelpers[name] || babelHelpers.get(name);
        ret.push(helperDefineTemplate({
          METHOD_NAME: Identifier(name),
          METHOD
        }))
      }
    }
    return ret;
  }
github LivelyKernel / lively4-core / src / external / plugin-babel / build-babel / systemjs-build-modular-babel-helpers.js View on Github external
helpers.list.forEach(function(helperName) {
  var tree = t.program([
    t.exportDefaultDeclaration(helpers.get(helperName))
  ]);
  
  fs.writeFileSync('../babel-helpers/' + helperName + '.js', babel.transformFromAst(tree).code);
});
github babel / babel / packages / babel-core / src / tools / build-external-helpers.js View on Github external
each(helpers.list, function (name) {
    if (whitelist && whitelist.indexOf(name) < 0) return;

    let key = t.identifier(name);
    body.push(t.expressionStatement(
      t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name))
    ));
  });
}
github ksherlock / better-babel-cli / babel-external-helpers.js View on Github external
list.forEach( function(fn){
		if (whitelist && whitelist.indexOf(fn) < 0) return;

		callback(fn, bh.get(fn));
	});
}
github babel / babel / packages / babel-core / src / tools / build-external-helpers.js View on Github external
function buildGlobal(namespace, builder) {
  let body      = [];
  let container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
  let tree      = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);

  body.push(t.variableDeclaration("var", [
    t.variableDeclarator(
      namespace,
      t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
    )
  ]));

  builder(body);

  return tree;
}

babel-helpers

Collection of helper functions used by Babel transforms.

MIT
Latest version published 8 years ago

Package Health Score

82 / 100
Full package analysis

Similar packages