<commit_before>import path from 'path';

import validateOptions from 'schema-utils';
import { getOptions } from 'loader-utils';

import schema from './options.json';
import {
  getSassImplementation,
  getSassOptions,
  getWebpackImporter,
  getRenderFunctionFromSassImplementation,
} from './utils';
import SassError from './SassError';

/**
 * The sass-loader makes node-sass and dart-sass available to webpack modules.
 *
 * @this {object}
 * @param {string} content
 */
function loader(content) {
  const options = getOptions(this);

  validateOptions(schema, options, {
    name: 'Sass Loader',
    baseDataPath: 'options',
  });

  const implementation = getSassImplementation(options.implementation);
  const sassOptions = getSassOptions(this, options, content, implementation);

  const shouldUseWebpackImporter =
    typeof options.webpackImporter === 'boolean'
      ? options.webpackImporter
      : true;

  if (shouldUseWebpackImporter) {
    const { includePaths } = sassOptions;

    sassOptions.importer.push(getWebpackImporter(this, includePaths));
  }

  const callback = this.async();
  const render = getRenderFunctionFromSassImplementation(implementation);

  render(sassOptions, (error, result) => {
    if (error) {
      // `node-sass` returns POSIX paths
      this.addDependency(path.normalize(error.file));

      callback(new SassError(error));

      return;<commit_msg>fix: do not crash on errors (#860)<commit_after>import path from 'path';

import validateOptions from 'schema-utils';
import { getOptions } from 'loader-utils';

import schema from './options.json';
import {
  getSassImplementation,
  getSassOptions,
  getWebpackImporter,
  getRenderFunctionFromSassImplementation,
} from './utils';
import SassError from './SassError';

/**
 * The sass-loader makes node-sass and dart-sass available to webpack modules.
 *
 * @this {object}
 * @param {string} content
 */
function loader(content) {
  const options = getOptions(this);

  validateOptions(schema, options, {
    name: 'Sass Loader',
    baseDataPath: 'options',
  });

  const implementation = getSassImplementation(options.implementation);
  const sassOptions = getSassOptions(this, options, content, implementation);

  const shouldUseWebpackImporter =
    typeof options.webpackImporter === 'boolean'
      ? options.webpackImporter
      : true;

  if (shouldUseWebpackImporter) {
    const { includePaths } = sassOptions;

    sassOptions.importer.push(getWebpackImporter(this, includePaths));
  }

  const callback = this.async();
  const render = getRenderFunctionFromSassImplementation(implementation);

  render(sassOptions, (error, result) => {
    if (error) {
      // There are situations when the `file` property do not exist
      if (error.file) {
        // `node-sass` returns POSIX paths
        this.addDependency(path.normalize(error.file));
      }

      callback(new SassError(error));

      return;
{'fraction_non_alphanumeric': 0.111871365035922, 'fraction_numerical': 0.0010263427984946972, 'mean_word_length': 4.156966490299824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3654217', 'n_tokens_mistral': 876, 'n_tokens_neox': 844, 'n_words': 209}