11import { trimQuotes , trimCommandValue , trimArray } from './cleanup' ;
22import { isAction , isArray } from './match' ;
33
4- // TODO: change to use new Set ()
5-
6- function doAction (
7- type : CR . OutputAction , isArray , actionValue , result , line ,
8- { page, task}
9- ) : CR . Output {
4+ function doAction ( {
5+ type, isArray, actionValue, result,
6+ index : { page, task}
7+ } ) : CR . Output {
108 // set to array
119 if ( result . pages [ page ] . tasks [ task ] [ type ] === undefined ) {
1210 result . pages [ page ] . tasks [ task ] [ type ] = [ ] ;
1311 }
14- let current = result . pages [ page ] . tasks [ task ] [ type ] ;
12+ let current = new Set ( result . pages [ page ] . tasks [ task ] [ type ] ) ;
1513 if ( ! ! isArray ) {
1614 // array
1715 let values = trimArray ( actionValue ) ;
18- values . forEach ( ( value ) => {
19- if ( current . indexOf ( value ) === - 1 && values . indexOf ( value ) === - 1 ) {
20- result . pages [ page ] . tasks [ task ] [ type ] . push ( value ) ;
21- }
16+ values . forEach ( ( v ) => {
17+ current . add ( v ) ;
2218 } ) ;
2319 } else {
2420 // string
25- if ( current . indexOf ( actionValue ) === - 1 ) {
26- result . pages [ page ] . tasks [ task ] [ type ] . push ( actionValue ) ;
27- }
21+ current . add ( actionValue ) ;
2822 }
23+ result . pages [ page ] . tasks [ task ] [ type ] = Array . from ( current ) ;
2924 return result ;
3025}
3126
32- export function addToTasks ( result , line , index ) {
27+ export function addToTasks ( { result, line, index } ) {
3328 let action : CR . TaskAction | string = isAction ( line ) ; // 'action'|'test'|'hint'|'openConsole'
3429 const { page, task} = index ;
3530 let currentTask : CR . Task = result . pages [ page ] . tasks [ task ] ;
@@ -38,10 +33,22 @@ export function addToTasks(result, line, index) {
3833 let isActionArray = isArray ( trimQuotes ( actionValue ) ) ;
3934 switch ( action ) {
4035 case 'test' :
41- result = doAction ( 'tests' , isActionArray , actionValue , result , line , index ) ;
36+ result = doAction ( {
37+ type : 'tests' ,
38+ isArray : isActionArray ,
39+ actionValue,
40+ result,
41+ index
42+ } ) ;
4243 break ;
4344 case 'hint' :
44- result = doAction ( 'hints' , isActionArray , actionValue , result , line , index ) ;
45+ result = doAction ( {
46+ type : 'hints' ,
47+ isArray : isActionArray ,
48+ actionValue,
49+ result,
50+ index
51+ } ) ;
4552 break ;
4653 case 'continue' :
4754 break ;
@@ -51,8 +58,8 @@ export function addToTasks(result, line, index) {
5158 }
5259 if ( ! ! isActionArray ) {
5360 var arrayOfActions : string [ ] = JSON . parse ( isActionArray ) ;
54- arrayOfActions . forEach ( function ( value ) {
55- value = trimCommandValue ( trimQuotes ( value . trim ( ) ) ) ;
61+ arrayOfActions . forEach ( ( v ) => {
62+ let value = trimCommandValue ( trimQuotes ( v . trim ( ) ) ) ;
5663 result . pages [ page ] . tasks [ task ] . actions . push ( value ) ;
5764 } ) ;
5865 } else {
0 commit comments