<commit_before>var path = require('path');
var mkdirp = require('mkdirp');
var includePathSearcher = require('include-path-searcher');
var CachingWriter = require('broccoli-caching-writer');
var nodeSass = require('node-sass');
var assign = require('object-assign');
var rsvp = require('rsvp');
var Promise = rsvp.Promise;
var fs = require('fs');
var writeFile = rsvp.denodeify(fs.writeFile);

module.exports = SassCompiler;
SassCompiler.prototype = Object.create(CachingWriter.prototype);
SassCompiler.prototype.constructor = SassCompiler;

function SassCompiler (inputNodes, inputFile, outputFile, options) {
  if (!(this instanceof SassCompiler)) { return new SassCompiler(inputNodes, inputFile, outputFile, options); }
  if (!Array.isArray(inputNodes)) { throw new Error('Expected array for first argument - did you mean [tree] instead of tree?'); }

  CachingWriter.call(this, inputNodes, {
    annotation: options.annotation,
    cacheInclude: options.cacheInclude,
    cacheExclude: options.cacheExclude
  });

  this.inputFile = inputFile;
  this.outputFile = outputFile;
  options = options || {};
  this.options = {
    nodeSass: options.nodeSass
  };

  var sass = this.options.nodeSass || nodeSass;

  this.renderSass = rsvp.denodeify(sass.render);

  this.sassOptions = {
    importer: options.importer,
    functions: options.functions,
    indentedSyntax: options.indentedSyntax,
    omitSourceMapUrl: options.omitSourceMapUrl,
    outputStyle: options.outputStyle,
    precision: options.precision,
    sourceComments: options.sourceComments,
    sourceMap: options.sourceMap,
    sourceMapEmbed: options.sourceMapEmbed,
    sourceMapContents: options.sourceMapContents,
    sourceMapRoot: options.sourceMapRoot
  };
}

SassCompiler.prototype.build = function() {
  var destFile = path.join(this.outputPath, this.outputFile);
  var sourceMapFile = this.sassOptions.sourceMap;

  if (typeof sourceMapFile !== 'string') {
    sourceMapFile = destFile + '.map';
  }

  mkdirp.sync(path.dirname(destFile));

  var sassOptions = {
    file: includePathSearcher.findFileSync(this.inputFile, this.inputPaths),
    includePaths: this.inputPaths,
    outFile: destFile
  };

  assign(sassOptions, this.sassOptions);

  return this.renderSass(sassOptions).then(function(result) {
    var files = [
      writeFile(destFile, result.css)
    ];

    if (this.sassOptions.sourceMap && !this.sassOptions.sourceMapEmbed) {
      files.push(writeFile(sourceMapFile, result.map));
    }

    return Promise.all(files);
  }.bind(this));
};<commit_msg>fix Sass errors for better Ember CLI error messages<commit_after>var path = require('path');
var mkdirp = require('mkdirp');
var includePathSearcher = require('include-path-searcher');
var CachingWriter = require('broccoli-caching-writer');
var nodeSass = require('node-sass');
var assign = require('object-assign');
var rsvp = require('rsvp');
var Promise = rsvp.Promise;
var fs = require('fs');
var writeFile = rsvp.denodeify(fs.writeFile);

module.exports = SassCompiler;
SassCompiler.prototype = Object.create(CachingWriter.prototype);
SassCompiler.prototype.constructor = SassCompiler;

function SassCompiler (inputNodes, inputFile, outputFile, options) {
  if (!(this instanceof SassCompiler)) { return new SassCompiler(inputNodes, inputFile, outputFile, options); }
  if (!Array.isArray(inputNodes)) { throw new Error('Expected array for first argument - did you mean [tree] instead of tree?'); }

  CachingWriter.call(this, inputNodes, {
    annotation: options.annotation,
    cacheInclude: options.cacheInclude,
    cacheExclude: options.cacheExclude
  });

  this.inputFile = inputFile;
  this.outputFile = outputFile;
  options = options || {};
  this.options = {
    nodeSass: options.nodeSass
  };

  var sass = this.options.nodeSass || nodeSass;

  this.renderSass = rsvp.denodeify(sass.render);

  this.sassOptions = {
    importer: options.importer,
    functions: options.functions,
    indentedSyntax: options.indentedSyntax,
    omitSourceMapUrl: options.omitSourceMapUrl,
    outputStyle: options.outputStyle,
    precision: options.precision,
    sourceComments: options.sourceComments,
    sourceMap: options.sourceMap,
    sourceMapEmbed: options.sourceMapEmbed,
    sourceMapContents: options.sourceMapContents,
    sourceMapRoot: options.sourceMapRoot
  };
}

/**
 * Mutates the error to include properties expected by Ember CLI.
 * See https://github.com/ember-cli/ember-cli/blob/master/docs/ERRORS.md#error-object
 * @param {Error} error
 */
function rethrowBuildError(error) {
  if (typeof error === 'string') {
    throw new Error('[string exception] ' + error);
  } else {
    error.type = 'Sass Syntax Error';
    error.message = error.formatted;
    error.location = {
      line: error.line,
      column: error.column
    };

    throw error;
  }
}

SassCompiler.prototype.build = function() {
  var destFile = path.join(this.outputPath, this.outputFile);
  var sourceMapFile = this.sassOptions.sourceMap;

  if (typeof sourceMapFile !== 'string') {
    sourceMapFile = destFile + '.map';
  }

  mkdirp.sync(path.dirname(destFile));

  var sassOptions = {
    file: includePathSearcher.findFileSync(this.inputFile, this.inputPaths),
    includePaths: this.inputPaths,
    outFile: destFile
  };

  assign(sassOptions, this.sassOptions);

  return this.renderSass(sassOptions).then(function(result) {
    var files = [
      writeFile(destFile, result.css)
    ];

    if (this.sassOptions.sourceMap && !this.sassOptions.sourceMapEmbed) {
      files.push(writeFile(sourceMapFile, result.map));
    }

    return Promise.all(files);
  }.bind(this)).catch(rethrowBuildError);
};
{'fraction_non_alphanumeric': 0.12243816254416962, 'fraction_numerical': 0.0, 'mean_word_length': 4.469565217391304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '3149484', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1731, 'n_words': 360}