How to use the babel-core.canCompile function in babel-core

To help you get started, we’ve selected a few babel-core 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 Legitcode / forms / src / __tests__ / preprocessor.js View on Github external
process: function(src, filename) {
    // Allow the stage to be configured by an environment
    // variable, but use Babel's default stage (2) if
    // no environment variable is specified.
    var stage = process.env.BABEL_JEST_STAGE || 0;

    // Ignore all files within node_modules
    // babel files can be .js, .es, .jsx or .es6
    if (filename.indexOf("node_modules") === -1 && babel.canCompile(filename)) {
      return babel.transform(src, { filename: filename, stage: stage, retainLines: true }).code;
    }

    return src;
  }
}
github kriasoft / aspnet-starter-kit / preprocessor.js View on Github external
process: function(src, filename) {
    // Ignore files other than .js, .es, .jsx or .es6
    if (!babel.canCompile(filename)) {
      return '';
    }
    // Ignore all files within node_modules
    if (filename.indexOf('node_modules') === -1) {
      return babel.transform(src, {filename: filename}).code;
    }
    return src;
  }
};
github Skookum / generator-genreact / app / templates / _jest-preprocessor.js View on Github external
process: function (src, filename) {
    var stage = 0;

    // Ignore all files within node_modules
    // babel files can be .js, .es, .jsx or .es6
    if (filename.indexOf("node_modules") === -1 && babel.canCompile(filename)) {
      return babel.transform(
        src.toString().replace(/((var|let|const)[\s]*[a-zA-Z0-9\-\_]+[\s]*=[\s]*)?require\('[a-zA-Z0-9\.\/\-\_]+\.s?css\'\);?/gm, ''),
        { filename: filename,
          stage: stage,
          retainLines: true,
          auxiliaryCommentBefore: "istanbul ignore next"
        }
      ).code;
    }

    return src;
  }
};
github react-materialize / react-materialize / preprocessor.js View on Github external
process: function(src, filename) {
    // Ignore files other than .js, .es, .jsx or .es6
    if (!babel.canCompile(filename)) {
      return '';
    }
    // Ignore all files within node_modules
    if (filename.indexOf('node_modules') === -1) {
      return babel.transform(src, {filename: filename}).code;
    }
    return src;
  }
};
github groupon / DotCi / src / main / jsx / preprocessor.js View on Github external
process: function(src, filename) {
        // Ignore files other than .js, .es, .jsx or .es6
        if (!babel.canCompile(filename)) {
            return '';
        }
        // Ignore all files within node_modules
        if (filename.indexOf('node_modules') === -1) {
            return babel.transform(src, { filename: filename }).code;
        }
        return src;
    }
};
github jessy1092 / react-semantify / test / preprocessor.js View on Github external
process: function (src, filename) {

    if (filename.indexOf('node_modules') === -1 && babel.canCompile(filename)) {
      var option = {
        filename: filename,
        stage: 0
      }
      return babel.transform(src, option).code;
    }
    return src;
  }
};
github cs-education / sysbuild / webapp / gulp-tasks / babel-transpiler.js View on Github external
transpile(pathname, callback) {
        pathname = slash(pathname);
        if (this.config.babelIgnoreRegexes.some((re) => re.test(pathname))) return callback();
        if (!babelCore.canCompile(pathname)) return callback();
        const src = path.join(this.config.root, pathname);
        const opts = objectAssign({ sourceFileName: '/source/' + pathname }, this.config.babelConfig);
        babelCore.transformFile(src, opts, callback);
    }
github SteveSanderson / generator-ko / app / templates / _gulpfile.js View on Github external
function babelTranspile(pathname, callback) {
    if (babelIgnoreRegexes.some(function (re) { return re.test(pathname); })) return callback();
    if (!babelCore.canCompile(pathname)) return callback();
    var src  = path.join(transpilationConfig.root, pathname);
    var opts = objectAssign({ sourceFileName: '/source/' + pathname }, transpilationConfig.babelConfig);
    babelCore.transformFile(src, opts, callback);
}
github marmelab / ng-admin-react / jest-preprocessor.js View on Github external
process: function (src, filename) {
    if ((filename.indexOf('node_modules') === -1 || filename.indexOf('admin-config')) && babel.canCompile(filename)) {
      return babel.transform(src, { filename: filename, stage: 1, retainLines: true, compact: false }).code;
    }

    return src;
  }
};
github zupzup / reactgym / preprocessor.js View on Github external
process: function(src, file) {
        if (!file.match(/.*\/(__tests__|scripts|react-router|StubRouterContext).*/)) {
            return src;
        }
        var stage = process.env.BABEL_JEST_STAGE || 2;
        var canCompile = babel.canCompile(file);

        if (!canCompile) {
            return "";
        }

        if (file.indexOf("node_modules") === -1) {
            return babel.transform(src, {filename: file, stage: stage}).code;
        }

        return src;
    }
};