src/options.js
// Copy options and fill in default values.
Copy options and fill in default values.
Copy options and fill in default values .
function normalize(options) {
  const normalized = Object.assign({}, options || {});
  const filepath = normalized.filepath;
  if (/\.(css|less|scss)$/.test(filepath)) {
    normalized.parser = "postcss";
  } else if (/\.html$/.test(filepath)) {
    normalized.parser = "parse5";
  } else if (/\.(ts|tsx)$/.test(filepath)) {
    normalized.parser = "typescript";
  } else if (/\.json$/.test(filepath)) {
    normalized.parser = "json";
  }
  if (typeof normalized.trailingComma === "boolean") {
    normalized.trailingComma = "es5";
    console.warn(
      "Warning: `trailingComma` without any argument is deprecated. " +
        'Specify "none", "es5", or "all".'
    );
  }
  const parserBackup = normalized.parser;
  if (typeof normalized.parser === "function") {
    delete normalized.parser;
  }
  validate(normalized, { exampleConfig, deprecatedConfig });
  normalized.parser = parserBackup;
  if ("useFlowParser" in normalized) {
    normalized.parser = normalized.useFlowParser ? "flow" : "babylon";
    delete normalized.useFlowParser;
  }
  Object.keys(defaults).forEach(k => {
    if (normalized[k] == null) {
      normalized[k] = defaults[k];
    }
  });
  return normalized;
}
function normalize ( options ) { const normalized = Object . assign ( { } , options || { } ) ; const filepath = normalized . filepath ; if ( / \.(css|less|scss)$ / . test ( filepath ) ) { normalized . parser = "postcss" ; } else if ( / \.html$ / . test ( filepath ) ) { normalized . parser = "parse5" ; } else if ( / \.(ts|tsx)$ / . test ( filepath ) ) { normalized . parser = "typescript" ; } else if ( / \.json$ / . test ( filepath ) ) { normalized . parser = "json" ; } if ( typeof normalized . trailingComma === "boolean" ) { normalized . trailingComma = "es5" ; console . warn ( "Warning: `trailingComma` without any argument is deprecated. " + 'Specify "none", "es5", or "all".' ) ; } const parserBackup = normalized . parser ; if ( typeof normalized . parser === "function" ) { delete normalized . parser ; } validate ( normalized , { exampleConfig , deprecatedConfig } ) ; normalized . parser = parserBackup ; if ( "useFlowParser" in normalized ) { normalized . parser = normalized . useFlowParser ? "flow" : "babylon" ; delete normalized . useFlowParser ; } Object . keys ( defaults ) . forEach ( k => { if ( normalized [ k ] == null ) { normalized [ k ] = defaults [ k ] ; } } ) ; return normalized ; }
Copy options and fill in default values.
Copy options and fill in default values .
// Support a deprecated boolean type for the trailing comma config // for a few versions. This code can be removed later. // Delete the function from the object to pass validation. // Restore the option back to a function; // For backward compatibility. Deprecated in 0.0.10