mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 08:50:13 +02:00
refactor fns in ast
This commit is contained in:
@@ -16,7 +16,7 @@ function getId() {
|
|||||||
exports.setDirection = function(dir) {
|
exports.setDirection = function(dir) {
|
||||||
direction = dir;
|
direction = dir;
|
||||||
}
|
}
|
||||||
exports.pushCommit = function(msg) {
|
exports.commit = function(msg) {
|
||||||
var commit = { id: getId(),
|
var commit = { id: getId(),
|
||||||
message: msg,
|
message: msg,
|
||||||
parent: head == null ? null : head.id};
|
parent: head == null ? null : head.id};
|
||||||
@@ -26,12 +26,12 @@ exports.pushCommit = function(msg) {
|
|||||||
log.debug("in pushCommit");
|
log.debug("in pushCommit");
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createBranch = function(name) {
|
exports.branch = function(name) {
|
||||||
branches[name] = head != null ? head.id: null;
|
branches[name] = head != null ? head.id: null;
|
||||||
log.debug("in createBranch");
|
log.debug("in createBranch");
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.mergeBranch = function() {
|
exports.merge = function() {
|
||||||
log.debug("in mergeBranch");
|
log.debug("in mergeBranch");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ exports.checkout = function(branch) {
|
|||||||
var id = branches[curBranch];
|
var id = branches[curBranch];
|
||||||
head = commits[id];
|
head = commits[id];
|
||||||
}
|
}
|
||||||
exports.reset = function () {
|
exports.clear = function () {
|
||||||
commits = {};
|
commits = {};
|
||||||
head = null;
|
head = null;
|
||||||
branches = { "master" : head };
|
branches = { "master" : head };
|
||||||
|
@@ -4,7 +4,7 @@ describe('when parsing a gitGraph',function() {
|
|||||||
"use strict";
|
"use strict";
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
parser.yy = ast;
|
parser.yy = ast;
|
||||||
parser.yy.reset();
|
parser.yy.clear();
|
||||||
});
|
});
|
||||||
it('should handle a gitGraph defintion', function () {
|
it('should handle a gitGraph defintion', function () {
|
||||||
var str = 'gitGraph:\n' +
|
var str = 'gitGraph:\n' +
|
||||||
|
@@ -57,10 +57,10 @@ line
|
|||||||
;
|
;
|
||||||
|
|
||||||
statement
|
statement
|
||||||
: COMMIT commit_arg {yy.pushCommit($2)}
|
: COMMIT commit_arg {yy.commit($2)}
|
||||||
| BRANCH ID {yy.createBranch($2)}
|
| BRANCH ID {yy.branch($2)}
|
||||||
| CHECKOUT ID {yy.checkout($2)}
|
| CHECKOUT ID {yy.checkout($2)}
|
||||||
| MERGE ID {yy.mergeBranch($2)}
|
| MERGE ID {yy.merge($2)}
|
||||||
;
|
;
|
||||||
|
|
||||||
commit_arg
|
commit_arg
|
||||||
|
@@ -101,16 +101,16 @@ case 5:
|
|||||||
this.$ =$$[$0-1]
|
this.$ =$$[$0-1]
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
yy.pushCommit($$[$0])
|
yy.commit($$[$0])
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
yy.createBranch($$[$0])
|
yy.branch($$[$0])
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
yy.checkout($$[$0])
|
yy.checkout($$[$0])
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
yy.mergeBranch($$[$0])
|
yy.merge($$[$0])
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
this.$ = ""
|
this.$ = ""
|
||||||
|
Reference in New Issue
Block a user