'use strict';

const requireFromString = require('require-from-string');

// Parses a JavaScript file
const parse = function ({ content, path }) {
  if (typeof path === 'string') {
    // eslint-disable-next-line import/no-dynamic-require
    return require(path);
  }

  return requireFromString(content);
};

// Serializes a JavaScript file
const serialize = function ({ content }) {
  const json = JSON.stringify(content, null, 2);
  return `module.exports = ${json}`;
};

module.exports = {
  name: 'javascript',
  title: 'JavaScript',
  types: ['conf'],
  extNames: ['js', 'mjs'],
  mimes: [
    'application/javascript',
    'application/x-javascript',
    'application/ecmascript',
    'text/javascript',
    'text/ecmascript',
  ],
  mimeExtensions: ['+js', '+mjs'],
  charsets: ['utf-8'],
  jsonCompat: ['superset'],
  parse,
  serialize,
};

@@ -150,38 +150,77 @@
 if (
-typeof path === 'string') %7B%0A  
+content !== undefined) %7B%0A    return requireFromString(content);%0A  %7D%0A%0A
   //
@@ -271,18 +271,16 @@
 require%0A
-  
   return
@@ -299,50 +299,8 @@
 h);%0A
-  %7D%0A%0A  return requireFromString(content);%0A
 %7D;%0A%0A

Fix JavaScript format loading