Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
spat-ne-hochu committed Jun 19, 2016
2 parents 80d7c46 + 267102d commit 8956bf3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ jspm_packages
.npm
.node_repl_history
.idea
/.wallaby.js
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var nodeParse = require('./lib/node-parse');
const nodeParse = require('./lib/node-parse');

/**
*
Expand All @@ -10,7 +10,7 @@ var nodeParse = require('./lib/node-parse');
*/
module.exports = function(string) {
if (typeof string !== 'string') {
throw 'parse need string';
throw Error('parse need string');
}

let state = new ParseState(string),
Expand All @@ -27,8 +27,7 @@ module.exports = function(string) {
stack[state.indent] = node;
} while (! state.isEOF);
} catch (e) {
console.error(state, e);
throw 'parse error';
throw Error('parse error');
}

return stack[0];
Expand Down
2 changes: 1 addition & 1 deletion lib/line-analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(state) {
} else if(spaces % 4 === 2) {
isNode = false;
} else {
throw 'invalid indent'
throw Error('invalid indent');
}

return {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@combinejs/parser",
"version": "0.1.0",
"version": "0.1.1",
"description": "default combinejs parser",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global before, after, beforeEach, describe, it */

const assert = require('chai').assert,
expect = require('chai').expect,
fs = require('fs'),
path = require('path'),
parse = require('../index');
Expand All @@ -21,4 +22,17 @@ describe('parser tests', function() {

assert.deepEqual(tree, json);
});

it('is not string parse throw', function() {
expect(function() {
parse(new Buffer(32));
}).to.throw('parse need string');
});

it('invalid indent', function() {
expect(function() {
let block = fs.readFileSync(path.resolve('./test/invalid-indent.comb')).toString();
parse(block);
}).to.throw('parse error');
});
});
3 changes: 3 additions & 0 deletions test/invalid-indent.comb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TableBeauty
html.tag = 'table'
css.display = 'table'

0 comments on commit 8956bf3

Please sign in to comment.