Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

state: fix state transitions

* apply: do not digIn into unreachable places
  • Loading branch information...
commit d90cd455da07c877416fff6888f2c7f70cfe83d4 1 parent 4ddd37a
@indutny indutny authored
View
4 GNUmakefile
@@ -5,9 +5,7 @@ clean:
# nothing to do
test:
- # Note that --ignore-leaks is a temporary flag and should be removed in future
- mocha --ignore-leaks --slow 600 --ui tdd --growl \
- --reporter spec test/unit/*-test.js
+ npm test
benchmark: *
bin/benchmark --details
View
22 lib/xjst/state.js
@@ -62,6 +62,17 @@ State.prototype.set = function set(key, value) {
});
}
+ if (Array.isArray(this.states.high[key])) {
+ var arrval = Array.isArray(value) ? value : [known ? value : null];
+ var possible = arrval.every(function(value) {
+ return this.states.high[key].some(function(our) {
+ return our === value;
+ });
+ }, this);
+
+ if (!possible) this.mutual = true;
+ }
+
if (Array.isArray(value)) {
this.states.high[key] = value;
delete this.states.low[key];
@@ -216,8 +227,15 @@ State.prototype.merge = function merge(source) {
//
State.prototype.isReachable = function isReachable(state, merge) {
// Skip mutual states
- if (!state) return this.mutual;
- if (state.mutual) return;
+ if (!state) return this.mutual ? -1 : 0;
+ if (state.mutual || this.mutual) return -1;
+
+ // If current node knows more info - next is unreachable
+ // (low state check)
+ if (Object.keys(state.states.low).length >
+ Object.keys(this.states.low).length) {
+ return -1;
+ }
var current = merge ? this._mergedState() : this.states.high,
next = state.states.high,
View
14 lib/xjst/transforms/apply.js
@@ -3,12 +3,13 @@ var xjst = require('../../xjst'),
XJSTLocalAndApplyCompiler = xjst.ometa.XJSTLocalAndApplyCompiler;
//
-// ### function digIn (state, node)
+// ### function digIn (state, node, options)
// #### @state {State} source state
// #### @node {AST} target node
+// #### @options {Object} options
// Digs into switches sequence if state allows it
//
-function digIn(state, node) {
+function digIn(state, node, options) {
if (node.tagStr && state.has(node.tagStr) && !state.has(node.tagStr, null)) {
var cases = node.cases.map(function(branch) {
return [utils.stringify(branch[0]), branch[1]];
@@ -25,8 +26,11 @@ function digIn(state, node) {
if (!result) result = node['default'];
- return result.state.isReachable() ?
- digIn(state, result || node['default'])
+ return state.isReachable(
+ result.state,
+ options.engine === 'sort-group'
+ ) > 0 ?
+ digIn(state, result || node['default'], options)
:
node;
} else {
@@ -207,7 +211,7 @@ exports.process = function optimizeRecursion(tree, source, options,
// If the node is matching our condition - we should wrap it into a
// function
- result.node = digIn(apply.state, result.node);
+ result.node = digIn(apply.state, result.node, options);
result.node.fn = true;
// Mark apply as optimized
View
6 package.json
@@ -21,8 +21,8 @@
"dependencies": {
"coa": "0.3.1",
"ometajs": "~ 3.1.4",
- "q": "0.7.x",
- "uglify-js": "1.2.x"
+ "q": "0.8.x",
+ "uglify-js": "1.3.x"
},
"devDependencies": {
"benchmark": "0.3.x",
@@ -45,6 +45,6 @@
"scripts": {
"prepublish": "make -B",
"publish": "make clean",
- "test": "make test"
+ "test": "mocha --ignore-leaks --slow 600 --ui tdd --growl --reporter spec test/unit/*-test.js"
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.