Skip to content

Commit

Permalink
full coverage restored. unnecessary throws evicted. constancy establi…
Browse files Browse the repository at this point in the history
…shed
  • Loading branch information
StoneCypher committed Aug 12, 2017
1 parent 85dcf04 commit 79e5f5c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 49 deletions.
34 changes: 12 additions & 22 deletions dist/jssm.es5.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/lib/index.html
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8' />
<title>jssm 4.1.10 | Documentation</title>
<title>jssm 4.1.14 | Documentation</title>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' type='text/css' rel='stylesheet' />
<link href='assets/style.css' type='text/css' rel='stylesheet' />
Expand All @@ -14,7 +14,7 @@
<div class='fixed xs-hide fix-3 overflow-auto max-height-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>jssm</h3>
<div class='mb1'><code>4.1.10</code></div>
<div class='mb1'><code>4.1.14</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "jssm",
"version": "4.1.11",
"version": "4.1.14",
"engines": {
"node": ">=6.0.0"
},
Expand All @@ -18,7 +18,7 @@
"make": "npm run clean && npm run peg && npm run babel && npm run rename && npm run setver && npm run pack",
"flow": "flow",
"peg": "rm -f src/js/jssm-dot.js && pegjs src/js/jssm-dot.peg && cp src/js/jssm-dot.js build/",
"eslint": "eslint src/js/jssm.js src/js/tests/*.js",
"eslint": "eslint src/js/jssm.js src/js/jssm-types.js src/js/tests/*.js",
"nyc-html": "nyc ava report --reporter=html",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"vet": "npm run flow && npm run eslint",
Expand Down
10 changes: 5 additions & 5 deletions src/demo/index.html
Expand Up @@ -13,19 +13,19 @@
</style>

<script defer type="text/javascript" src="../../build/jssm.es5.cjs.js"></script>
<script defer type="text/javascript">

var jssm, sm;

<script defer type="text/javascript">
/* eslint-disable */
window.onload = () => {

jssm = require('jssm');
sm = jssm.sm;
let jssm = require('jssm'),
sm = jssm.sm;

document.body.innerHTML = `<h1>Ready</h1><p>JSSM has now been loaded at version ${jssm.version}, and is bound to the global <code>jssm</code> (aka <code>window.jssm</code>.) Also, the state machine template string tag is exposed as <code>sm</code> (aka <code>window.sm</code>).</p><p>Please open a console and type something like</p><p><code>var traffic_light = sm<b>\` off -> red => green => yellow => red; [red yellow green] ~> off; \`</b>;</code></p><p>Now you have a working state machine to play with:</p><pre>&gt; traffic_light.state();\n"off"\n\n&gt; traffic_light.transition("green");\nfalse\n\n&gt; traffic_light.state();\n"off"\n\n&gt; traffic_light.transition("red");\ntrue\n\n&gt; traffic_light.state();\n"red"</pre><p>Consoles are <kbd>f12</kbd> on Windows and Linux PCs, or <kbd>command-option-j</kbd> on Macs.</p>`;

}

/* eslint-enable */
</script>

</head>
Expand Down
13 changes: 11 additions & 2 deletions src/js/jssm-types.js
Expand Up @@ -13,7 +13,10 @@ type JssmResult = JssmSuccess | JssmFailure | JssmIncomplete;
type JssmPermitted = 'required' | 'disallowed';
type JssmPermittedOpt = 'required' | 'disallowed' | 'optional';

type JssmArrow = '->' | '<->' | '<=->' | '<~->' | '=>' | '<=>' | '<-=>' | '<~=>' | '~>' | '<~>' | '<-~>' | '<=~>';
type JssmArrow = '->' | '<->' | '<=->' | '<~->'
| '=>' | '<=>' | '<-=>' | '<~=>'
| '~>' | '<~>' | '<-~>' | '<=~>';

type JssmArrowDirection = 'left' | 'right' | 'both';
type JssmArrowKind = 'none' | 'legal' | 'main' | 'forced';

Expand Down Expand Up @@ -47,7 +50,9 @@ type JssmGenericState<NT> = {


type JssmTransitionPermitter<NT, DT> = (OldState: NT, NewState: NT, OldData: DT, NewData: DT) => boolean;
type JssmTransitionPermitterMaybeArray<NT, DT> = JssmTransitionPermitter<NT, DT> | Array< JssmTransitionPermitter<NT, DT> >;

type JssmTransitionPermitterMaybeArray<NT, DT> = JssmTransitionPermitter<NT, DT>
| Array< JssmTransitionPermitter<NT, DT> >;



Expand Down Expand Up @@ -181,12 +186,16 @@ export type {

JssmGenericConfig,
JssmGenericState,
JssmGenericMachine,

JssmParseTree,
JssmCompileSe,
JssmCompileSeStart,
JssmCompileRule,

JssmPermitted,
JssmResult,

JssmMachineInternalState

};
30 changes: 15 additions & 15 deletions src/js/jssm.js
Expand Up @@ -193,19 +193,21 @@ class Machine<mNT, mDT> {
if (tr.to === undefined) { throw new Error(`transition must define 'to': ${ JSON.stringify(tr)}`); }

// get the cursors. what a mess
let cursor_from : ?JssmGenericState<mNT> = this._states.get(tr.from);
if (cursor_from === undefined) {
this._new_state({name: tr.from, from: [], to: [], complete: complete.includes(tr.from) });
cursor_from = this._states.get(tr.from);
const cursor_from : JssmGenericState<mNT>
= this._states.get(tr.from)
|| { name: tr.from, from: [], to: [], complete: complete.includes(tr.from) };

if (!(this._states.has(tr.from))) {
this._new_state(cursor_from);
}
if (!cursor_from) { throw new Error('cursor_from should have been created. rly silencing flow.'); }

let cursor_to : ?JssmGenericState<mNT> = this._states.get(tr.to);
if (cursor_to === undefined) {
this._new_state({name: tr.to, from: [], to: [], complete: complete.includes(tr.to) });
cursor_to = this._states.get(tr.to);
const cursor_to : JssmGenericState<mNT>
= this._states.get(tr.to)
|| {name: tr.to, from: [], to: [], complete: complete.includes(tr.to) };

if (!(this._states.has(tr.to))) {
this._new_state(cursor_to);
}
if (!cursor_to) { throw new Error('cursor_to should have been created. rly silencing flow.'); }

// guard against existing connections being re-added
if (cursor_from.to.includes(tr.to)) {
Expand All @@ -229,12 +231,10 @@ class Machine<mNT, mDT> {
}

// set up the mapping, so that edges can be looked up by endpoint pairs
let from_mapping : ?Map<mNT, number> = this._edge_map.get(tr.from);
if (from_mapping === undefined) {
this._edge_map.set(tr.from, new Map());
from_mapping = this._edge_map.get(tr.from); // whargarbl burn out uses of any
const from_mapping : Map<mNT, number> = this._edge_map.get(tr.from) || new Map();
if (!(this._edge_map.has(tr.from))) {
this._edge_map.set(tr.from, from_mapping);
}
if (!from_mapping) { throw new Error('from_mapping should have been created. rly silencing flow.'); }

// const to_mapping = from_mapping.get(tr.to);
from_mapping.set(tr.to, thisEdgeId); // already checked that this mapping doesn't exist, above
Expand Down

0 comments on commit 79e5f5c

Please sign in to comment.