UNPKG

3.22 kBtext/coffeescriptView Raw
1ion = require '../'
2index = require '../compiler'
3
4tests =
5 """
6 let x = 10
7 """: """
8 'use strict';
9 var x = 10;
10 """
11 """
12 let x = 10
13 if foo
14 let y = 20
15 if bar
16 const y = 30
17 """: """
18 'use strict';
19 var x = 10;
20 if (foo) {
21 var y = 20;
22 }
23 if (bar) {
24 var y = 30;
25 }
26 """
27 """
28 export class StampFilter
29 stamp: (key, object) ->
30 for name, property of key.type.properties if property.stamp
31 log(name)
32 """: """
33 'use strict';
34 var ion = require('ion');
35 var StampFilter = ion.defineClass({
36 name: 'StampFilter',
37 stamp: function (key, object) {
38 {
39 var _ref = key.type.properties;
40 for (var name in _ref) {
41 var property = _ref[name];
42 if (property.stamp) {
43 log(name);
44 }
45 }
46 }
47 }
48 });
49 module.exports = exports = StampFilter;
50 """
51 """
52 let element =
53 (body: 2)
54 """: """
55 'use strict';
56 var ion = require('ion');
57 var element = {};
58 {
59 var _body = 2;
60 element.body = _body;
61 ion.add(element, _body);
62 }
63 """
64 """
65 (foo: bar)
66 x: 1
67 """: {line:1, column:2}
68 """
69 let foo = bar(
70 1
71 2
72 )
73 .toString(
74 "12"
75 )
76 .split(' ')
77 """: """
78 'use strict';
79 var foo = bar(1, 2).toString('12').split(' ');
80 """
81 # """
82 # template -> alpha ? beta
83 # """: null
84 """
85 ""
86 foo
87 bar #baz
88 """: """
89 'use strict';
90 'foo\\nbar #baz';
91 """
92 """
93 let object =
94 x: 10
95 property visible:
96 get: -> true
97 y: 20
98 """: """
99 'use strict';
100 var object = Object.defineProperties({
101 x: 10,
102 y: 20
103 }, {
104 visible: {
105 get: function () {
106 return true;
107 }
108 }
109 });
110 """
111
112if global.window?
113 return
114
115exports.test = ->
116 for input, expected of tests
117 options = {target:'es5'}
118 if expected is null
119 index.compile input, ion.patch({loc:false,source:'ionCompilerES5.js', debug:true}, options)
120 else if typeof expected is 'object'
121 # expected to throw an error
122 error = null
123 try
124 index.compile input, options
125 catch e
126 error = e
127 # check equivalent fields
128 for key, value of expected
129 if value isnt e[key]
130 throw new Error "\n#{JSON.stringify e}\n!=\n#{JSON.stringify expected}"
131 if not error?
132 throw new Error "Expected an error: #{JSON.stringify expected}"
133 else
134 output = index.compile input, options
135 if output.trim() isnt expected.trim()
136 console.log '-Output---------------------------------------------'
137 console.log output
138 throw new Error "\n#{output}\n!=\n#{expected}"
139 return