Skip to content

Commit bf92cc8

Browse files
committed
minor refactoring
1 parent 7737fb4 commit bf92cc8

File tree

7 files changed

+30
-25
lines changed

7 files changed

+30
-25
lines changed

lib/build/parser/actions.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
"use strict";
22
var cleanup_1 = require('./cleanup');
33
var Match = require('./match');
4-
function doAction(type, isArray, actionValue, result, line, index) {
5-
if (result.chapters[index.chapter].pages[index.page].tasks[index.task][type] === undefined) {
6-
result.chapters[index.chapter].pages[index.page].tasks[index.task][type] = [];
4+
function doAction(type, isArray, actionValue, result, line, _a) {
5+
var chapter = _a.chapter, page = _a.page, task = _a.task;
6+
if (result.chapters[chapter].pages[page].tasks[task][type] === undefined) {
7+
result.chapters[chapter].pages[page].tasks[task][type] = [];
78
}
89
if (!!isArray) {
910
var values = cleanup_1.trimArray(actionValue);
1011
values.forEach(function (value) {
11-
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(value);
12+
result.chapters[chapter].pages[page].tasks[task][type].push(value);
1213
});
1314
}
1415
else {
15-
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(actionValue);
16+
result.chapters[chapter].pages[page].tasks[task][type].push(actionValue);
1617
}
1718
return result;
1819
}
1920
function addToTasks(result, line, index) {
2021
var action = Match.isAction(line);
21-
var task = result.chapters[index.chapter].pages[index.page].tasks[index.task];
22+
var chapter = index.chapter, page = index.page, task = index.task;
23+
var currentTask = result.chapters[chapter].pages[page].tasks[task];
2224
var trimmedContent = line.slice(action.length + 2, line.length - 1);
2325
var actionValue = cleanup_1.trimQuotes(trimmedContent);
2426
var isActionArray = Match.isArray(cleanup_1.trimQuotes(actionValue));
@@ -32,19 +34,19 @@ function addToTasks(result, line, index) {
3234
case 'continue':
3335
break;
3436
case 'action':
35-
if (task.actions === undefined) {
36-
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions = [];
37+
if (currentTask.actions === undefined) {
38+
result.chapters[chapter].pages[page].tasks[task].actions = [];
3739
}
3840
if (!!isActionArray) {
3941
var arrayOfActions = JSON.parse(isActionArray);
4042
arrayOfActions.forEach(function (value) {
4143
value = cleanup_1.trimCommandValue(cleanup_1.trimQuotes(value.trim()));
42-
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value);
44+
result.chapters[chapter].pages[page].tasks[task].actions.push(value);
4345
});
4446
}
4547
else {
4648
var value = cleanup_1.trimCommandValue(actionValue);
47-
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value);
49+
result.chapters[chapter].pages[page].tasks[task].actions.push(value);
4850
}
4951
return result;
5052
default:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"dependencies": {
2626
"chalk": "1.1.1",
2727
"commander": "2.9.0",
28-
"lodash": "4.5.1",
28+
"lodash": "4.6.1",
2929
"prompt": "1.0.0",
3030
"validate-npm-package-name": "2.2.2"
3131
},

setup/tutorial/1/01/01.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ loadJS('page-01.js')
66
describe('01 addOne', function() {
77

88
it('doesn\'t exist', function() {
9-
expect(addOne).to.not.be.undefined;
9+
expect(addOne).to.be.defined;
1010
});
1111

1212
it('should take a parameter', function() {

setup/tutorial/1/01/02.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe('02 subtractOne', function() {
22

33
it('doesn\'t exist', function () {
4-
expect(subtractOne).to.not.be.undefined;
4+
expect(subtractOne).to.be.defined;
55
});
66

77
it('should take a parameter', function() {

setup/tutorial/1/02/01.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ loadJS('page-02.js')
77
describe('01 divideOne', function() {
88

99
it('doesn\'t exist', function () {
10-
expect(divideOne).to.not.be.undefined;
10+
expect(divideOne).to.be.defined;
1111
});
1212

1313
it('should take a parameter', function() {

setup/tutorial/1/02/02.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe('02 multiplyOne', function() {
22

33
it('doesn\'t exist', function () {
4-
expect(multiplyOne).to.not.be.undefined;
4+
expect(multiplyOne).to.be.defined;
55
});
66

77
it('should take a parameter', function() {

src/build/parser/actions.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
import {trimQuotes, trimCommandValue, trimArray} from './cleanup';
22
import * as Match from './match';
33

4-
function doAction(type: CR.OutputAction, isArray, actionValue, result, line, index): CR.Output {
4+
// TODO: change to use new Set ()
5+
6+
function doAction(type: CR.OutputAction, isArray, actionValue, result, line, {chapter, page, task}): CR.Output {
57
// set to array
6-
if (result.chapters[index.chapter].pages[index.page].tasks[index.task][type] === undefined) {
7-
result.chapters[index.chapter].pages[index.page].tasks[index.task][type] = [];
8+
if (result.chapters[chapter].pages[page].tasks[task][type] === undefined) {
9+
result.chapters[chapter].pages[page].tasks[task][type] = [];
810
}
911
if (!!isArray) {
1012
// array
1113
let values = trimArray(actionValue);
1214
values.forEach((value) => {
13-
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(value);
15+
result.chapters[chapter].pages[page].tasks[task][type].push(value);
1416
});
1517
} else {
1618
// string
17-
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(actionValue);
19+
result.chapters[chapter].pages[page].tasks[task][type].push(actionValue);
1820
}
1921
return result;
2022
}
2123

2224
export function addToTasks(result, line, index) {
2325
let action: CR.TaskAction|string = Match.isAction(line); // 'action'|'test'|'hint'|'continue'
24-
let task: CR.Task = result.chapters[index.chapter].pages[index.page].tasks[index.task];
26+
const {chapter, page, task} = index;
27+
let currentTask: CR.Task = result.chapters[chapter].pages[page].tasks[task];
2528
let trimmedContent: string = line.slice(action.length + 2, line.length - 1); // content between brackets
2629
let actionValue: string = trimQuotes(trimmedContent);
2730
let isActionArray = Match.isArray(trimQuotes(actionValue));
@@ -35,18 +38,18 @@ export function addToTasks(result, line, index) {
3538
case 'continue':
3639
break;
3740
case 'action':
38-
if (task.actions === undefined) {
39-
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions = [];
41+
if (currentTask.actions === undefined) {
42+
result.chapters[chapter].pages[page].tasks[task].actions = [];
4043
}
4144
if (!!isActionArray) {
4245
var arrayOfActions: string[] = JSON.parse(isActionArray);
4346
arrayOfActions.forEach(function(value) {
4447
value = trimCommandValue(trimQuotes(value.trim()));
45-
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value);
48+
result.chapters[chapter].pages[page].tasks[task].actions.push(value);
4649
});
4750
} else {
4851
let value: string = trimCommandValue(actionValue);
49-
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value);
52+
result.chapters[chapter].pages[page].tasks[task].actions.push(value);
5053
}
5154
return result;
5255

0 commit comments

Comments
 (0)