Socket
Socket
Sign inDemoInstall

mkast

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mkast - npm Package Compare versions

Comparing version 1.1.7 to 1.1.8

test/spec/json-error.js

66

lib/deserialize.js

@@ -14,2 +14,3 @@ var through = require('through3')

this.doc = null;
this.open = 0;
}

@@ -22,22 +23,37 @@

* @member AstDeserialize
* @param {Array} ast input AST document.
*
* @param {Array} node input AST node.
* @param {String} encoding character encoding.
* @param {Function} callback function.
*/
function transform(ast, encoding, cb) {
function transform(chunk, encoding, cb) {
// create root document
if(ast && ast._type === 'document') {
// bad input
if(!chunk) {
return cb();
}
// maintain link references
if(ast.refs && this.doc) {
this.doc.refs = this.doc.refs || [];
this.doc.refs = this.doc.refs.concat(ast.refs);
}
var node = Node.createNode(chunk._type, chunk)
, isDocument = node.is(Node.DOCUMENT)
, isEof = node.is(Node.EOF)
, isMeta = isEof;
if(isDocument) {
this.open++;
}
if(isEof) {
this.open--;
}
// handle documet nodes
if(isDocument) {
// create root document
if(!this.doc) {
this.doc = Node.createDocument();
// append nested document
// append children of nested document
}else{
var next = ast._firstChild;
var next = chunk._firstChild;
while(next) {

@@ -48,10 +64,28 @@ this.doc.appendChild(attach(next));

}
}else if(this.doc && ast._type !== 'eof') {
this.doc.appendChild(attach(ast));
// got EOF with a valid doc, flush it
}else if(this.doc && ast._type === 'eof') {
// maintain link references for nested documents
if(chunk.refs && this.doc) {
this.doc.refs = this.doc.refs || [];
this.doc.refs = this.doc.refs.concat(chunk.refs);
}
// attach to current doc
}else if(this.doc && !isEof) {
this.doc.appendChild(attach(chunk));
// got EOF with a valid root doc, flush it
}else if(this.doc && isEof && this.open === 0) {
this.push(this.doc);
this.emit('eof', this.doc);
this.emit(Node.EOF, this.doc);
this.doc = null;
// concrete node (non-meta node) that does not
// have a parent
}else if(!isMeta) {
console.error('dropped node %s', chunk._type);
console.error(chunk);
throw new Error('node without parent document');
}
cb();

@@ -58,0 +92,0 @@ }

@@ -36,2 +36,5 @@ var Node = require('commonmark/lib/node')

}
if(!k) {
return;
}
return o;

@@ -38,0 +41,0 @@ }

{
"name": "mkast",
"version": "1.1.7",
"version": "1.1.8",
"description": "Commonmark AST transformer",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,4 +6,3 @@ var expect = require('chai').expect

, ast = require('../../index')
, Walk = require('../../lib/walk')
, ParserStream = require('../../lib/parser');
, Walk = require('../../lib/walk');

@@ -85,14 +84,2 @@ describe('mkast:', function() {

it('should error on bad json', function(done) {
var parser = new ParserStream();
parser.once('error', function(err) {
function fn() {
throw err;
}
expect(fn).throws(Error);
done();
});
parser.end(new Buffer('{'));
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc