All files / lib/internal/modules/esm load.js

100% Statements 32/32
100% Branches 12/12
100% Functions 1/1
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33135x 135x 135x 135x 135x 135x 757x 757x 757x 757x 757x 757x 757x 749x 749x 752x 542x 757x 296x 702x 453x 449x 745x 745x 745x 745x 745x 757x 135x 135x 135x 135x  
'use strict';
 
const { defaultGetFormat } = require('internal/modules/esm/get_format');
const { defaultGetSource } = require('internal/modules/esm/get_source');
const { translators } = require('internal/modules/esm/translators');
 
async function defaultLoad(url, context) {
  let {
    format,
    source,
  } = context;
 
  if (!translators.has(format)) format = defaultGetFormat(url);
 
  if (
    format === 'builtin' ||
    format === 'commonjs'
  ) {
    source = null;
  } else if (source == null) {
    source = await defaultGetSource(url, { format });
  }
 
  return {
    format,
    source,
  };
}
 
module.exports = {
  defaultLoad,
};