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

100% Statements 43/43
100% Branches 13/13
100% Functions 1/1
100% Lines 43/43

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 33 34 35 36 37 38 39 40 41 42 43 44149x 149x 149x 149x 149x 149x 149x 149x 149x 149x 149x 149x 1192x 1192x 1192x 1192x 1192x 1192x 1192x 1192x 183x 162x 1171x 1171x 1171x 1171x 1184x 800x 1192x 471x 1110x 687x 686x 1157x 1157x 1157x 1157x 1157x 1192x 149x 149x 149x 149x  
'use strict';
 
const { defaultGetFormat } = require('internal/modules/esm/get_format');
const { defaultGetSource } = require('internal/modules/esm/get_source');
const { validateAssertions } = require('internal/modules/esm/assert');
 
/**
 * Node.js default load hook.
 * @param {string} url
 * @param {object} context
 * @returns {object}
 */
async function defaultLoad(url, context) {
  const { importAssertions } = context;
  let {
    format,
    source,
  } = context;
 
  if (format == null) {
    format = await defaultGetFormat(url, context);
  }
 
  validateAssertions(url, format, importAssertions);
 
  if (
    format === 'builtin' ||
    format === 'commonjs'
  ) {
    source = null;
  } else if (source == null) {
    source = await defaultGetSource(url, context);
  }
 
  return {
    format,
    source,
  };
}
 
module.exports = {
  defaultLoad,
};