Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change processor.parser, processor.compiler signatures #24

Closed
wooorm opened this issue Feb 11, 2017 · 0 comments
Closed

Change processor.parser, processor.compiler signatures #24

wooorm opened this issue Feb 11, 2017 · 0 comments
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧑 semver/major This is a change 🦋 type/enhancement This is great to have

Comments

@wooorm
Copy link
Member

wooorm commented Feb 11, 2017

parser(vfile, settings, processor) > parser(doc, vfile)
compiler(vfile, settings, processor) > compiler(tree, vfile)

That makes it more similar to transformers, and allows for settings to be removed (GH-23).


var parse = require('./parse')
var proc = unified().use(parse, {b: true}).data('settings', {a: true});

proces.parse('foo', console.log);

parse.js:

module.exports = parser;

Parser.prototype.parse = parse;
Parser.prototype.defaults = {c: true};

// Invoked when attaching.
function parser(options) {
  var proc = this;
  var LocalParser = proc.parser = unherit(Parser);
  LocalParser.prototype.defaults = xtend(LocalParser.prototype.defaults, options);
  LocalParser.prototype.processor = proc;
}

// Constructed just before parsing.
function Parser(contents, file) {
  // allow use without unified.
  var settings = this.processor ? this.processor.data('settings') : {};
  this.doc = contents;
  this.file = file;
  this.settings = xtend(this.defaults, settings);
}

// Constructed when parsing, with `this` as an instance of Parser.
function parse() {
  this.settings; //=> {a: true, b: true, c: true}
  return this.start(); // ...or something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧑 semver/major This is a change 🦋 type/enhancement This is great to have
Development

No branches or pull requests

1 participant