Skip to content

Commit

Permalink
Remove type support
Browse files Browse the repository at this point in the history
All tree’s, whether abstract or concrete, are in the future
placed under `tree` instead of `ast` or `cst`.
  • Loading branch information
wooorm committed Sep 14, 2015
1 parent 6dae05d commit 8748cfe
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 125 deletions.
18 changes: 8 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var pipeline = ware()
*
* @param {Object} options - Configuration.
* @param {string} options.name - Private storage.
* @param {string} options.type - Type of syntax tree.
* @param {Function} options.Parser - Class to turn a
* virtual file into a syntax tree.
* @param {Function} options.Compiler - Class to turn a
Expand All @@ -48,7 +47,6 @@ var pipeline = ware()
*/
function unified(options) {
var name = options.name;
var type = options.type;
var Parser = options.Parser;
var Compiler = options.Compiler;

Expand Down Expand Up @@ -129,9 +127,9 @@ function unified(options) {
space = file.namespace(name);

if (!node) {
node = space[type] || node;
} else if (!space[type]) {
space[type] = node;
node = space.tree || node;
} else if (!space.tree) {
space.tree = node;
}

if (!node) {
Expand Down Expand Up @@ -171,7 +169,7 @@ function unified(options) {
var CustomParser = (this && this.Parser) || Parser;
var node = new CustomParser(file, settings).parse();

file.namespace(name)[type] = node;
file.namespace(name).tree = node;

return node;
}
Expand All @@ -180,7 +178,7 @@ function unified(options) {
* Compile a file.
*
* Used the parsed node at the `name`
* namespace at `type` when no node was given.
* namespace at `'tree'` when no node was given.
*
* @this {Processor?} - Either a Processor instance or
* the Processor constructor.
Expand All @@ -207,9 +205,9 @@ function unified(options) {
space = file.namespace(name);

if (!node) {
node = space[type] || node;
} else if (!space[type]) {
space[type] = node;
node = space.tree || node;
} else if (!space.tree) {
space.tree = node;
}

if (!node) {
Expand Down
12 changes: 2 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var Compiler = require('./lib/stringify.js');

module.exports = unified({
'name': 'mdast',
'type': 'ast',
'Parser': Parser,
'Compiler': Compiler
});
Expand Down Expand Up @@ -78,13 +77,6 @@ Create a new `Processor` constructor.

* `name` (`string`) — Unique namespace, e.g. `'mdast'` or `'retext'`.

* `type` (`string`) — Type of the produced syntax tree. For example,
**mdast** uses an `'ast'` (Abstract Syntax Tree), whereas **retext**
uses a `'cst'` (Concrete Syntax Tree).

Used to store the syntax tree after parsing on the file (at
`file.namespace(name)[type]`).

* `Parser` (`Function`) — Constructor which transforms a virtual file
into a syntax tree. When input is parsed, this function will be
constructed with a `file` and `settings`. `Parser` instances should
Expand All @@ -100,15 +92,15 @@ Create a new `Processor` constructor.
have a `compile` method which returns a `string`.

The syntax tree representation of a file can be accessed by executing
`file.namespace(name)[type]`.
`file.namespace(name).tree`.

**Returns**`Function` (`Processor` constructor).

### Processor(\[processor\])

> Note that all methods on the instance are also available as functions on the
> constructor, which, when invoked, create a new instance.
>
>
> Thus, invoking `new Processor().process()` is the same as
> `Processor.process()`.
Expand Down
28 changes: 6 additions & 22 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('unified()', function () {
it('should create a new constructor', function () {
Processor = unified({
'name': 'foo',
'type': 'bar',
'Parser': noop,
'Compiler': noop
});
Expand Down Expand Up @@ -200,7 +199,6 @@ describe('unified()', function () {

var parse = unified({
'name': 'foo',
'type': 'bar',
'Parser': Bound,
'Compiler': noop
}).parse;
Expand Down Expand Up @@ -262,7 +260,7 @@ describe('unified()', function () {
'value': 'bar'
};

vfile.namespace('foo').bar = node;
vfile.namespace('foo').tree = node;

new Processor().run(vfile, function (err, tree, file) {
equal(err, null);
Expand All @@ -280,7 +278,7 @@ describe('unified()', function () {
'value': 'bar'
};

vfile.namespace('foo').bar = node;
vfile.namespace('foo').tree = node;

new Processor().run(node, vfile, function (err, tree, file) {
equal(err, null);
Expand Down Expand Up @@ -317,7 +315,7 @@ describe('unified()', function () {
function Compiler(file, options) {
self = this;

equal(file.namespace('foo').bar, node);
equal(file.namespace('foo').tree, node);
equal(options, 'bar');
}

Expand Down Expand Up @@ -361,7 +359,7 @@ describe('unified()', function () {

Compiler.prototype.compile = done;

vfile.namespace('foo').bar = tree;
vfile.namespace('foo').tree = tree;

Processor.Compiler = Compiler;

Expand Down Expand Up @@ -409,7 +407,7 @@ describe('unified()', function () {

Processor.Compiler = Compiler;

vfile.namespace('foo').bar = tree;
vfile.namespace('foo').tree = tree;

Processor.stringify(vfile);

Expand Down Expand Up @@ -438,7 +436,7 @@ describe('unified()', function () {

Processor.Compiler = Compiler;

vfile.namespace('foo').bar = tree;
vfile.namespace('foo').tree = tree;

Processor.stringify(tree, vfile, settings);

Expand Down Expand Up @@ -467,7 +465,6 @@ describe('unified()', function () {

var stringify = unified({
'name': 'foo',
'type': 'bar',
'Parser': noop,
'Compiler': Bound
}).stringify;
Expand Down Expand Up @@ -520,7 +517,6 @@ describe('unified()', function () {

Processor2 = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': Compiler
});
Expand Down Expand Up @@ -576,7 +572,6 @@ describe('unified()', function () {

Processor2 = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': Compiler
});
Expand Down Expand Up @@ -629,7 +624,6 @@ describe('unified()', function () {

Processor2 = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': Compiler
});
Expand Down Expand Up @@ -686,7 +680,6 @@ describe('unified()', function () {

Processor2 = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': Compiler
});
Expand Down Expand Up @@ -746,7 +739,6 @@ describe('unified()', function () {

Processor2 = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': Compiler
});
Expand Down Expand Up @@ -805,7 +797,6 @@ describe('unified()', function () {

Processor2 = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': Compiler
});
Expand Down Expand Up @@ -868,7 +859,6 @@ describe('unified()', function () {

processor = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': Compiler
});
Expand Down Expand Up @@ -905,7 +895,6 @@ describe('unified()', function () {

processor = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': noop
});
Expand Down Expand Up @@ -952,7 +941,6 @@ describe('unified()', function () {

processor = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': Compiler
});
Expand Down Expand Up @@ -984,7 +972,6 @@ describe('unified()', function () {

processor = unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': noop
}).use(function () {
Expand Down Expand Up @@ -1017,7 +1004,6 @@ describe('unified()', function () {

unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': noop
}).process('foo', function (err) {
Expand Down Expand Up @@ -1061,7 +1047,6 @@ describe('unified()', function () {

unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': Compiler
}).process('foo', function (err) {
Expand Down Expand Up @@ -1090,7 +1075,6 @@ describe('unified()', function () {

unified({
'name': 'foo',
'type': 'bar',
'Parser': Parser,
'Compiler': noop
}).use(function () {
Expand Down

0 comments on commit 8748cfe

Please sign in to comment.