lib/client/utils/transpileImports.js
/**
 * Replace ECMAScript imports with require() calls
 */
Replace ECMAScript imports with require() calls
Replace ECMAScript imports with require () calls
function transpileImports(code) {
  if (!hasImports(code)) {
    return code;
  } 
  var ast = getAst(code);
  if (!ast) {
    return code;
  }
  var offset = 0; 
  walk(ast, {
    enter: function enter(node) {
      if (node.type === 'ImportDeclaration' && node.source) {
        var start = node.start + offset;
        var end = node.end + offset;
        var statement = code.substring(start, end);
        var transpiledStatement = rewriteImports(statement);
        code = code.substring(0, start) + transpiledStatement + code.substring(end);
        offset += transpiledStatement.length - statement.length;
      }
    }
  });
  return code;
}
function transpileImports ( code ) { if ( ! hasImports ( code ) ) { return code ; } var ast = getAst ( code ) ; if ( ! ast ) { return code ; } var offset = 0 ; walk ( ast , { enter : function enter ( node ) { if ( node . type === 'ImportDeclaration' && node . source ) { var start = node . start + offset ; var end = node . end + offset ; var statement = code . substring ( start , end ) ; var transpiledStatement = rewriteImports ( statement ) ; code = code . substring ( 0 , start ) + transpiledStatement + code . substring ( end ) ; offset += transpiledStatement . length - statement . length ; } } } ) ; return code ; }
Replace ECMAScript imports with require() calls
Replace ECMAScript imports with require () calls
// Don't do anything when the code has nothing that looks like an import // Ignore errors, they should be caught by Buble // estree walkers type is incompatible with acorns output // it is working here out of luck and typescript is demonstrating it  // we have to go through the any part to keep the nodes with their `node.start` // and `node.stop` // eslint-disable-next-line @typescript-eslint/no-explicit-any  // import foo from 'foo' // import 'foo' // eslint-disable-next-line @typescript-eslint/no-explicit-any 