This repository was archived by the owner on Aug 5, 2024. It is now read-only.
File tree 10 files changed +100
-12
lines changed
10 files changed +100
-12
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ Comparison :
83
83
84
84
### Loop
85
85
86
+ #### ** ` For ` loop** :
86
87
```
87
88
fomo i endup 10
88
89
kalo i lebih gede 3
@@ -98,6 +99,27 @@ for (let i = 0; i < 10; i++) {
98
99
}
99
100
```
100
101
102
+ #### ** ` For of ` loop** :
103
+ ```
104
+ fomo semua foo dari bar
105
+ spill foo
106
+ udahan
107
+
108
+ // transform to
109
+ for (const foo of bar) {
110
+ console.log(foo);
111
+ }
112
+ ```
113
+
114
+ #### ** ` break ` ** and ** ` continue ` ** :
115
+ ```
116
+ stop
117
+ // break;
118
+
119
+ skip
120
+ // continue;
121
+ ```
122
+
101
123
### Function
102
124
```
103
125
so about my_story
Original file line number Diff line number Diff line change
1
+ const loopForOf = require ( '../../../lib/logics/parser/loopForOf' ) ;
2
+ const getJsFormat = require ( '../test-parser-helper' ) ;
3
+
4
+ describe ( 'Test var assign' , ( ) => {
5
+ it ( 'Should return null if not match' , ( ) => {
6
+ const test1 = loopForOf ( 'fomo semu foo dari bar' ) ;
7
+ const test2 = loopForOf ( 'fomo smua foo dar bar' ) ;
8
+ expect ( test1 ) . toBe ( null ) ;
9
+ expect ( test2 ) . toBe ( null ) ;
10
+ } ) ;
11
+
12
+ it ( 'Should return correctly flexing' , ( ) => {
13
+ const jsFormat = getJsFormat ( `
14
+ fomo semua foo dari bar
15
+ spill foo
16
+ udahan
17
+ ` ) ;
18
+ expect ( jsFormat ) . not . toBeNull ( ) ;
19
+ let shouldMatch = [ 'for (const foo of bar) {' , 'console.log(foo)' , '}' ] ;
20
+ jsFormat . split ( '\n' ) . every ( ( v , i ) => {
21
+ if ( ! shouldMatch [ i ] ) return true ;
22
+ return expect ( v ) . toContain ( shouldMatch [ i ] ) ;
23
+ } ) ;
24
+ } ) ;
25
+ } ) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ const conditionElIf = require("./parser/conditionElIf");
7
7
const conditionElse = require ( "./parser/conditionElse" ) ;
8
8
const conditionClose = require ( "./parser/conditionClose" ) ;
9
9
const loopFor = require ( "./parser/loopFor" ) ;
10
+ const loopForOf = require ( "./parser/loopForOf" ) ;
10
11
const functionDeclarationBegin = require ( "./parser/functionDeclarationBegin" ) ;
11
12
const functionDeclarationEnd = require ( "./parser/functionDeclarationEnd" ) ;
12
13
const functionCall = require ( "./parser/functionCall" ) ;
@@ -16,6 +17,8 @@ const catchFn = require("./parser/catchFn");
16
17
const finallyFn = require ( "./parser/finallyFn" ) ;
17
18
const functionDeclarationAsyncBegin = require ( "./parser/functionDeclarationAsyncBegin" ) ;
18
19
const awaitProcess = require ( "./parser/awaitProcess" ) ;
20
+ const breakStatement = require ( "./parser/break" ) ;
21
+ const continueStatement = require ( "./parser/continue" ) ;
19
22
20
23
function getCmd ( cmdLines ) {
21
24
let parser = [
@@ -27,6 +30,7 @@ function getCmd(cmdLines) {
27
30
conditionElIf ,
28
31
conditionElse ,
29
32
conditionClose ,
33
+ loopForOf ,
30
34
loopFor ,
31
35
functionDeclarationBegin ,
32
36
functionDeclarationEnd ,
@@ -36,8 +40,9 @@ function getCmd(cmdLines) {
36
40
catchFn ,
37
41
finallyFn ,
38
42
functionDeclarationAsyncBegin ,
39
- awaitProcess
40
-
43
+ awaitProcess ,
44
+ breakStatement ,
45
+ continueStatement
41
46
] ;
42
47
43
48
return cmdLines
Original file line number Diff line number Diff line change
1
+ const breakStatement = ( msg ) => {
2
+ let format = / s t o p / ;
3
+ let match = msg . match ( format ) ;
4
+ if ( ! match ) return null ;
5
+
6
+ return {
7
+ exp : `break;` ,
8
+ } ;
9
+ } ;
10
+
11
+ module . exports = breakStatement ;
12
+
Original file line number Diff line number Diff line change 1
1
const valueTransform = require ( "../../utils/valueTransform" ) ;
2
2
3
3
const constAssign = ( msg ) => {
4
- let format = / s e r i o u s l y ( [ a - z A - Z 0 - 9 ] + ) i t u ( [ ^ \[ \] \( \) \n ] + ) / ;
4
+ let format = / s e r i o u s l y ( [ a - z A - Z _ ] + [ a - z A - Z 0 - 9 _ ] * ) i t u ( [ ^ \[ \] \( \) \n ] + ) / ;
5
5
let match = msg . match ( format ) ;
6
6
if ( ! match ) return null ;
7
7
Original file line number Diff line number Diff line change
1
+ const continueStatement = ( msg ) => {
2
+ let format = / s k i p / ;
3
+ let match = msg . match ( format ) ;
4
+ if ( ! match ) return null ;
5
+
6
+ return {
7
+ exp : `continue;` ,
8
+ } ;
9
+ } ;
10
+
11
+ module . exports = continueStatement ;
12
+
Original file line number Diff line number Diff line change 1
1
const loopFor = ( msg ) => {
2
- let format = / f o m o ( [ a - z A - Z 0 - 9 ] + ) e n d u p ( [ a - z A - Z 0 - 9 ] + ) / ;
3
- let match = msg . match ( format ) ;
4
- if ( ! match ) return null ;
2
+ let format = / f o m o ( [ a - z A - Z 0 - 9 ] + ) e n d u p ( [ a - z A - Z 0 - 9 ] + ) / ;
3
+ let match = msg . match ( format ) ;
4
+ if ( ! match ) return null ;
5
5
6
- return {
7
- exp : `for(let ${ match [ 1 ] } = 0; ${ match [ 1 ] } <= ${ match [ 2 ] } ; ${ match [ 1 ] } ++)` ,
8
- openGroup : true ,
9
- } ;
6
+ return {
7
+ exp : `for(let ${ match [ 1 ] } = 0; ${ match [ 1 ] } <= ${ match [ 2 ] } ; ${ match [ 1 ] } ++)` ,
8
+ openGroup : true ,
9
+ } ;
10
10
} ;
11
11
12
12
module . exports = loopFor ;
Original file line number Diff line number Diff line change
1
+ const loopForOf = ( msg ) => {
2
+ let format = / f o m o s e m u a ( [ a - z A - Z ] + [ a - z A - Z 0 - 9 ] * ) d a r i ( [ a - z A - Z ] + [ a - z A - Z 0 - 9 ] * ) / ;
3
+ let match = msg . match ( format ) ;
4
+ if ( ! match ) return null ;
5
+
6
+ return {
7
+ exp : `for (const ${ match [ 1 ] } of ${ match [ 2 ] } )` ,
8
+ openGroup : true ,
9
+ } ;
10
+ } ;
11
+
12
+ module . exports = loopForOf ;
Original file line number Diff line number Diff line change 1
1
const valueTransform = require ( "../../utils/valueTransform" ) ;
2
2
3
3
const varAssign = ( msg ) => {
4
- let format = / l i t e r a l l y ( [ a - z A - Z 0 - 9 ] + ) i t u ( [ ^ \[ \] \( \) \n ] + ) / ;
4
+ let format = / l i t e r a l l y ( [ a - z A - Z _ ] + [ a - z A - Z 0 - 9 _ ] * ) i t u ( [ ^ \[ \] \( \) \n ] + ) / ;
5
5
let match = msg . match ( format ) ;
6
6
if ( ! match ) return null ;
7
7
Original file line number Diff line number Diff line change 1
1
const valueTransform = require ( "../../utils/valueTransform" ) ;
2
2
3
3
const varReassign = ( msg ) => {
4
- let format = / w h i c h i s ( [ a - z A - Z 0 - 9 ] + ) i t u ( [ ^ \[ \] \( \) \n ] + ) / ;
4
+ let format = / w h i c h i s ( [ a - z A - Z _ ] + [ a - z A - Z 0 - 9 _ ] * ) i t u ( [ ^ \[ \] \( \) \n ] + ) / ;
5
5
let match = msg . match ( format ) ;
6
6
if ( ! match ) return null ;
7
7
You can’t perform that action at this time.
0 commit comments