@@ -73,11 +73,7 @@ describe('Parser', function() {
73
73
"type" : "Identifier" ,
74
74
"name" : "a"
75
75
} ,
76
- "init" : {
77
- "type" : "Literal" ,
78
- "value" : 1 ,
79
- "raw" : "1"
80
- }
76
+ "init" : { "type" : "Literal" , "value" : 1 , "raw" : "1" }
81
77
}
82
78
] ,
83
79
"kind" : "var"
@@ -87,15 +83,8 @@ describe('Parser', function() {
87
83
"expression" : {
88
84
"type" : "AssignmentExpression" ,
89
85
"operator" : "=" ,
90
- "left" : {
91
- "type" : "Identifier" ,
92
- "name" : "a"
93
- } ,
94
- "right" : {
95
- "type" : "Literal" ,
96
- "value" : 2 ,
97
- "raw" : "2"
98
- }
86
+ "left" : { "type" : "Identifier" , "name" : "a" } ,
87
+ "right" : { "type" : "Literal" , "value" : 2 , "raw" : "2" }
99
88
}
100
89
}
101
90
] ,
@@ -2769,11 +2758,239 @@ describe('Parser', function() {
2769
2758
expect ( R . equals ( parser ( input ) , output ) ) . to . equal ( true ) ;
2770
2759
} ) ;
2771
2760
2772
-
2761
+ // Test xx - Swift input: 'let firstNum = 1; let secNum = 2; var dict = [firstNum: [[1,2], [3,4]], secNum: [["one", "two"], ["three", "four"]]];'
2762
+ // AST Explorer input:
2763
+ /*
2764
+ var firstNum = 1;
2765
+ var secNum = 2;
2766
+ var dict = {};
2767
+ dict[firstNum] = [[1,2], [3,4]];
2768
+ dict[secNum] = [["one", "two"], ["three", "four"]];
2769
+ */
2770
+ it ( 'should handle basic dynamic key assignment in dictionary creation' , function ( ) {
2771
+ input = [
2772
+ { type : "DECLARATION_KEYWORD" , value : "var" } ,
2773
+ { type : "IDENTIFIER" , value : "firstNum" } ,
2774
+ { type : "OPERATOR" , value : "=" } ,
2775
+ { type : "NUMBER" , value : "1" } ,
2776
+ { type : "PUNCTUATION" , value : ";" } ,
2777
+ { type : "DECLARATION_KEYWORD" , value : "var" } ,
2778
+ { type : "IDENTIFIER" , value : "secNum" } ,
2779
+ { type : "OPERATOR" , value : "=" } ,
2780
+ { type : "NUMBER" , value : "2" } ,
2781
+ { type : "PUNCTUATION" , value : ";" } ,
2782
+ { type : "DECLARATION_KEYWORD" , value : "var" } ,
2783
+ { type : "IDENTIFIER" , value : "dict" } ,
2784
+ { type : "OPERATOR" , value : "=" } ,
2785
+ { type : "DICTIONARY_START" , value : "[" } ,
2786
+ { type : "IDENTIFIER" , value : "firstNum" } ,
2787
+ { type : "PUNCTUATION" , value : ":" } ,
2788
+ { type : "ARRAY_START" , value : "[" } ,
2789
+ { type : "ARRAY_START" , value : "[" } ,
2790
+ { type : "NUMBER" , value : "1" } ,
2791
+ { type : "PUNCTUATION" , value : "," } ,
2792
+ { type : "NUMBER" , value : "2" } ,
2793
+ { type : "ARRAY_END" , value : "]" } ,
2794
+ { type : "PUNCTUATION" , value : "," } ,
2795
+ { type : "ARRAY_START" , value : "[" } ,
2796
+ { type : "NUMBER" , value : "3" } ,
2797
+ { type : "PUNCTUATION" , value : "," } ,
2798
+ { type : "NUMBER" , value : "4" } ,
2799
+ { type : "ARRAY_END" , value : "]" } ,
2800
+ { type : "ARRAY_END" , value : "]" } ,
2801
+ { type : "PUNCTUATION" , value : "," } ,
2802
+ { type : "IDENTIFIER" , value : "secNum" } ,
2803
+ { type : "PUNCTUATION" , value : ":" } ,
2804
+ { type : "ARRAY_START" , value : "[" } ,
2805
+ { type : "ARRAY_START" , value : "[" } ,
2806
+ { type : "STRING" , value : "one" } ,
2807
+ { type : "PUNCTUATION" , value : "," } ,
2808
+ { type : "STRING" , value : "two" } ,
2809
+ { type : "ARRAY_END" , value : "]" } ,
2810
+ { type : "PUNCTUATION" , value : "," } ,
2811
+ { type : "ARRAY_START" , value : "[" } ,
2812
+ { type : "STRING" , value : "three" } ,
2813
+ { type : "PUNCTUATION" , value : "," } ,
2814
+ { type : "STRING" , value : "four" } ,
2815
+ { type : "ARRAY_END" , value : "]" } ,
2816
+ { type : "ARRAY_END" , value : "]" } ,
2817
+ { type : "DICTIONARY_END" , value : "]" } ,
2818
+ { type : "PUNCTUATION" , value : ";" } ,
2819
+ { type : "TERMINATOR" , value : "EOF" }
2820
+ ] ;
2821
+ output = {
2822
+ "type" : "Program" ,
2823
+ "body" : [
2824
+ {
2825
+ "type" : "VariableDeclaration" ,
2826
+ "declarations" : [
2827
+ {
2828
+ "type" : "VariableDeclarator" ,
2829
+ "id" : {
2830
+ "type" : "Identifier" ,
2831
+ "name" : "firstNum"
2832
+ } ,
2833
+ "init" : {
2834
+ "type" : "Literal" ,
2835
+ "value" : 1 ,
2836
+ "raw" : "1"
2837
+ }
2838
+ }
2839
+ ] ,
2840
+ "kind" : "var"
2841
+ } ,
2842
+ {
2843
+ "type" : "VariableDeclaration" ,
2844
+ "declarations" : [
2845
+ {
2846
+ "type" : "VariableDeclarator" ,
2847
+ "id" : {
2848
+ "type" : "Identifier" ,
2849
+ "name" : "secNum"
2850
+ } ,
2851
+ "init" : {
2852
+ "type" : "Literal" ,
2853
+ "value" : 2 ,
2854
+ "raw" : "2"
2855
+ }
2856
+ }
2857
+ ] ,
2858
+ "kind" : "var"
2859
+ } ,
2860
+ {
2861
+ "type" : "VariableDeclaration" ,
2862
+ "declarations" : [
2863
+ {
2864
+ "type" : "VariableDeclarator" ,
2865
+ "id" : {
2866
+ "type" : "Identifier" ,
2867
+ "name" : "dict"
2868
+ } ,
2869
+ "init" : {
2870
+ "type" : "ObjectExpression" ,
2871
+ "properties" : [ ]
2872
+ }
2873
+ }
2874
+ ] ,
2875
+ "kind" : "var"
2876
+ } ,
2877
+ {
2878
+ "type" : "ExpressionStatement" ,
2879
+ "expression" : {
2880
+ "type" : "AssignmentExpression" ,
2881
+ "operator" : "=" ,
2882
+ "left" : {
2883
+ "type" : "MemberExpression" ,
2884
+ "computed" : true ,
2885
+ "object" : {
2886
+ "type" : "Identifier" ,
2887
+ "name" : "dict"
2888
+ } ,
2889
+ "property" : {
2890
+ "type" : "Identifier" ,
2891
+ "name" : "firstNum"
2892
+ }
2893
+ } ,
2894
+ "right" : {
2895
+ "type" : "ArrayExpression" ,
2896
+ "elements" : [
2897
+ {
2898
+ "type" : "ArrayExpression" ,
2899
+ "elements" : [
2900
+ {
2901
+ "type" : "Literal" ,
2902
+ "value" : 1 ,
2903
+ "raw" : "1"
2904
+ } ,
2905
+ {
2906
+ "type" : "Literal" ,
2907
+ "value" : 2 ,
2908
+ "raw" : "2"
2909
+ }
2910
+ ]
2911
+ } ,
2912
+ {
2913
+ "type" : "ArrayExpression" ,
2914
+ "elements" : [
2915
+ {
2916
+ "type" : "Literal" ,
2917
+ "value" : 3 ,
2918
+ "raw" : "3"
2919
+ } ,
2920
+ {
2921
+ "type" : "Literal" ,
2922
+ "value" : 4 ,
2923
+ "raw" : "4"
2924
+ }
2925
+ ]
2926
+ }
2927
+ ]
2928
+ }
2929
+ }
2930
+ } ,
2931
+ {
2932
+ "type" : "ExpressionStatement" ,
2933
+ "expression" : {
2934
+ "type" : "AssignmentExpression" ,
2935
+ "operator" : "=" ,
2936
+ "left" : {
2937
+ "type" : "MemberExpression" ,
2938
+ "computed" : true ,
2939
+ "object" : {
2940
+ "type" : "Identifier" ,
2941
+ "name" : "dict"
2942
+ } ,
2943
+ "property" : {
2944
+ "type" : "Identifier" ,
2945
+ "name" : "secNum"
2946
+ }
2947
+ } ,
2948
+ "right" : {
2949
+ "type" : "ArrayExpression" ,
2950
+ "elements" : [
2951
+ {
2952
+ "type" : "ArrayExpression" ,
2953
+ "elements" : [
2954
+ {
2955
+ "type" : "Literal" ,
2956
+ "value" : "one" ,
2957
+ "raw" : "\"one\""
2958
+ } ,
2959
+ {
2960
+ "type" : "Literal" ,
2961
+ "value" : "two" ,
2962
+ "raw" : "\"two\""
2963
+ }
2964
+ ]
2965
+ } ,
2966
+ {
2967
+ "type" : "ArrayExpression" ,
2968
+ "elements" : [
2969
+ {
2970
+ "type" : "Literal" ,
2971
+ "value" : "three" ,
2972
+ "raw" : "\"three\""
2973
+ } ,
2974
+ {
2975
+ "type" : "Literal" ,
2976
+ "value" : "four" ,
2977
+ "raw" : "\"four\""
2978
+ }
2979
+ ]
2980
+ }
2981
+ ]
2982
+ }
2983
+ }
2984
+ }
2985
+ ] ,
2986
+ "sourceType" : "module"
2987
+ } ;
2988
+ expect ( R . equals ( parser ( input ) , output ) ) . to . equal ( true ) ;
2989
+ } ) ;
2773
2990
2774
2991
// Test 20 - Swift input: 'let arr = [1,2]; var v = [arr[0]: [[1,2], [3,4]], arr[1]: [["one", "two"], ["three", "four"]]];'
2775
- // AST Explorer input: 'let arr = [1,2]; var v = {}; v[arr[0]] = [[1,2], [3,4]]; v[arr[1]] = [["one", "two"], ["three", "four"]];'
2776
- xit ( 'should handle arrays of dictionaries' , function ( ) {
2992
+ // AST Explorer input: 'var arr = [1,2]; var v = {}; v[arr[0]] = [[1,2], [3,4]]; v[arr[1]] = [["one", "two"], ["three", "four"]];'
2993
+ it ( 'should handle arrays of dictionaries' , function ( ) {
2777
2994
input = [
2778
2995
{ type : "DECLARATION_KEYWORD" , value : "let" } ,
2779
2996
{ type : "IDENTIFIER" , value : "arr" } ,
@@ -2794,6 +3011,7 @@ describe('Parser', function() {
2794
3011
{ type : "PUNCTUATION" , value : "]" } ,
2795
3012
{ type : "PUNCTUATION" , value : ":" } ,
2796
3013
{ type : "ARRAY_START" , value : "[" } ,
3014
+ { type : "ARRAY_START" , value : "[" } ,
2797
3015
{ type : "NUMBER" , value : "1" } ,
2798
3016
{ type : "PUNCTUATION" , value : "," } ,
2799
3017
{ type : "NUMBER" , value : "2" } ,
@@ -2812,6 +3030,7 @@ describe('Parser', function() {
2812
3030
{ type : "PUNCTUATION" , value : "]" } ,
2813
3031
{ type : "PUNCTUATION" , value : ":" } ,
2814
3032
{ type : "ARRAY_START" , value : "[" } ,
3033
+ { type : "ARRAY_START" , value : "[" } ,
2815
3034
{ type : "STRING" , value : "one" } ,
2816
3035
{ type : "PUNCTUATION" , value : "," } ,
2817
3036
{ type : "STRING" , value : "two" } ,
@@ -2856,7 +3075,7 @@ describe('Parser', function() {
2856
3075
}
2857
3076
}
2858
3077
] ,
2859
- "kind" : "let "
3078
+ "kind" : "var "
2860
3079
} ,
2861
3080
{
2862
3081
"type" : "VariableDeclaration" ,
0 commit comments