@ant-yasa/uast-parser-java-js 0.1.15-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.babelrc +12 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.js +38 -0
  4. package/.mocharc-integration.js +1 -0
  5. package/.mocharc.js +4 -0
  6. package/.prettierignore +1 -0
  7. package/.prettierrc +4 -0
  8. package/LEGAL.md +7 -0
  9. package/README.md +35 -0
  10. package/antlr/Java.g4 +1008 -0
  11. package/antlr/JavaLexer.g4 +241 -0
  12. package/antlr/JavaLexer_origin.g4 +241 -0
  13. package/antlr/JavaParser.g4 +765 -0
  14. package/antlr/JavaParser_origin.g4 +766 -0
  15. package/dist/package.json +73 -0
  16. package/dist/src/frontend/java/ASTBuilder.d.ts +171 -0
  17. package/dist/src/frontend/java/ASTBuilder.js +2369 -0
  18. package/dist/src/frontend/java/ASTBuilder.js.map +1 -0
  19. package/dist/src/frontend/java/ErrorListener.d.ts +9 -0
  20. package/dist/src/frontend/java/ErrorListener.js +24 -0
  21. package/dist/src/frontend/java/ErrorListener.js.map +1 -0
  22. package/dist/src/frontend/java/antlr/JavaLexer.d.ts +154 -0
  23. package/dist/src/frontend/java/antlr/JavaLexer.js +812 -0
  24. package/dist/src/frontend/java/antlr/JavaLexer.js.map +1 -0
  25. package/dist/src/frontend/java/antlr/JavaListener.d.ts +1393 -0
  26. package/dist/src/frontend/java/antlr/JavaListener.js +4 -0
  27. package/dist/src/frontend/java/antlr/JavaListener.js.map +1 -0
  28. package/dist/src/frontend/java/antlr/JavaParser.d.ts +2065 -0
  29. package/dist/src/frontend/java/antlr/JavaParser.js +15279 -0
  30. package/dist/src/frontend/java/antlr/JavaParser.js.map +1 -0
  31. package/dist/src/frontend/java/antlr/JavaVisitor.d.ts +892 -0
  32. package/dist/src/frontend/java/antlr/JavaVisitor.js +4 -0
  33. package/dist/src/frontend/java/antlr/JavaVisitor.js.map +1 -0
  34. package/dist/src/frontend/java/parser.d.ts +20 -0
  35. package/dist/src/frontend/java/parser.js +93 -0
  36. package/dist/src/frontend/java/parser.js.map +1 -0
  37. package/dist/src/frontend/java/testBuilder.d.ts +146 -0
  38. package/dist/src/frontend/java/testBuilder.js +464 -0
  39. package/dist/src/frontend/java/testBuilder.js.map +1 -0
  40. package/dist/src/frontend/java/types.d.ts +29 -0
  41. package/dist/src/frontend/java/types.js +3 -0
  42. package/dist/src/frontend/java/types.js.map +1 -0
  43. package/dist/src/frontend/javascript/parser.d.ts +8 -0
  44. package/dist/src/frontend/javascript/parser.js +1121 -0
  45. package/dist/src/frontend/javascript/parser.js.map +1 -0
  46. package/dist/src/index.d.ts +14 -0
  47. package/dist/src/index.js +76 -0
  48. package/dist/src/index.js.map +1 -0
  49. package/output.txt +3820 -0
  50. package/package.json +73 -0
  51. package/tests/benchmark/base/class.js +32 -0
  52. package/tests/benchmark/base/class.js.json +1809 -0
  53. package/tests/benchmark/base/class_test.js +13 -0
  54. package/tests/benchmark/base/class_test.js.json +435 -0
  55. package/tests/benchmark/base/comment.js +21 -0
  56. package/tests/benchmark/base/comment.js.json +1443 -0
  57. package/tests/benchmark/base/demo.ts +1060 -0
  58. package/tests/benchmark/base/empty.js +4 -0
  59. package/tests/benchmark/base/empty.js.json +202 -0
  60. package/tests/benchmark/base/export.js +36 -0
  61. package/tests/benchmark/base/export.js.json +6345 -0
  62. package/tests/benchmark/base/export1.js +2 -0
  63. package/tests/benchmark/base/export1.js.json +251 -0
  64. package/tests/benchmark/base/export2.js +35 -0
  65. package/tests/benchmark/base/export2.js.json +3297 -0
  66. package/tests/benchmark/base/expressions.js +25 -0
  67. package/tests/benchmark/base/expressions.js.json +1654 -0
  68. package/tests/benchmark/base/for.js +7 -0
  69. package/tests/benchmark/base/for.js.json +738 -0
  70. package/tests/benchmark/base/function.js +15 -0
  71. package/tests/benchmark/base/function.js.json +1458 -0
  72. package/tests/benchmark/base/import.js +3 -0
  73. package/tests/benchmark/base/import.js.json +416 -0
  74. package/tests/benchmark/base/literal.js +27 -0
  75. package/tests/benchmark/base/literal.js.json +1234 -0
  76. package/tests/benchmark/base/param.js +4 -0
  77. package/tests/benchmark/base/param.js.json +410 -0
  78. package/tests/benchmark/base/parseerror.js +1 -0
  79. package/tests/benchmark/base/parseerror.js.json +191 -0
  80. package/tests/benchmark/base/patternlike.js +24 -0
  81. package/tests/benchmark/base/patternlike.js.json +3720 -0
  82. package/tests/benchmark/base/react.js +8 -0
  83. package/tests/benchmark/base/react.js.json +211 -0
  84. package/tests/benchmark/base/switch.js +11 -0
  85. package/tests/benchmark/base/switch.js.json +741 -0
  86. package/tests/benchmark/base/taint.ts +61 -0
  87. package/tests/benchmark/base/temp.js +311 -0
  88. package/tests/benchmark/base/temp.js.json +22170 -0
  89. package/tests/benchmark/base/tmp.js +134 -0
  90. package/tests/benchmark/base/tmp.js.json +15409 -0
  91. package/tests/benchmark/base/vardecl.js +9 -0
  92. package/tests/benchmark/base/vardecl.js.json +491 -0
  93. package/tests/index.js +43 -0
  94. package/tests/index.ts +66 -0
  95. package/tests/test.d.ts +0 -0
  96. package/tests/test.js +38 -0
  97. package/tests/test.ts +60 -0
  98. package/tsconfig.json +24 -0
  99. package/tsconfig.test.json +13 -0
  100. package/webpack.config.js +21 -0
@@ -0,0 +1,9 @@
1
+ var a = 3;
2
+
3
+ let b = a;
4
+
5
+ const c = b;
6
+
7
+ let a1 = true, a2 = false, a3 = a1;
8
+
9
+ let a4;
@@ -0,0 +1,491 @@
1
+ {
2
+ "type": "CompileUnit",
3
+ "body": [
4
+ {
5
+ "type": "VariableDeclaration",
6
+ "id": {
7
+ "type": "Identifier",
8
+ "name": "a",
9
+ "_meta": {
10
+ "_extra": {
11
+ "start": 4,
12
+ "end": 5
13
+ }
14
+ },
15
+ "loc": {
16
+ "start": {
17
+ "line": 1,
18
+ "column": 5
19
+ },
20
+ "end": {
21
+ "line": 1,
22
+ "column": 6
23
+ },
24
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
25
+ }
26
+ },
27
+ "init": {
28
+ "type": "Literal",
29
+ "value": 3,
30
+ "literalType": "number",
31
+ "_meta": {
32
+ "_extra": {
33
+ "start": 8,
34
+ "end": 9
35
+ }
36
+ },
37
+ "loc": {
38
+ "start": {
39
+ "line": 1,
40
+ "column": 9
41
+ },
42
+ "end": {
43
+ "line": 1,
44
+ "column": 10
45
+ },
46
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
47
+ }
48
+ },
49
+ "cloned": false,
50
+ "varType": {
51
+ "type": "DynamicType",
52
+ "id": null,
53
+ "_meta": {}
54
+ },
55
+ "_meta": {
56
+ "_extra": {
57
+ "end": 10
58
+ }
59
+ },
60
+ "loc": {
61
+ "start": {
62
+ "line": 1,
63
+ "column": 5
64
+ },
65
+ "end": {
66
+ "line": 1,
67
+ "column": 10
68
+ },
69
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
70
+ }
71
+ },
72
+ {
73
+ "type": "VariableDeclaration",
74
+ "id": {
75
+ "type": "Identifier",
76
+ "name": "b",
77
+ "_meta": {
78
+ "_extra": {
79
+ "start": 16,
80
+ "end": 17
81
+ }
82
+ },
83
+ "loc": {
84
+ "start": {
85
+ "line": 3,
86
+ "column": 5
87
+ },
88
+ "end": {
89
+ "line": 3,
90
+ "column": 6
91
+ },
92
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
93
+ }
94
+ },
95
+ "init": {
96
+ "type": "Identifier",
97
+ "name": "a",
98
+ "_meta": {
99
+ "_extra": {
100
+ "start": 20,
101
+ "end": 21
102
+ }
103
+ },
104
+ "loc": {
105
+ "start": {
106
+ "line": 3,
107
+ "column": 9
108
+ },
109
+ "end": {
110
+ "line": 3,
111
+ "column": 10
112
+ },
113
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
114
+ }
115
+ },
116
+ "cloned": false,
117
+ "varType": {
118
+ "type": "DynamicType",
119
+ "id": null,
120
+ "_meta": {}
121
+ },
122
+ "_meta": {
123
+ "_extra": {
124
+ "start": 12,
125
+ "end": 22
126
+ }
127
+ },
128
+ "loc": {
129
+ "start": {
130
+ "line": 3,
131
+ "column": 5
132
+ },
133
+ "end": {
134
+ "line": 3,
135
+ "column": 10
136
+ },
137
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
138
+ }
139
+ },
140
+ {
141
+ "type": "VariableDeclaration",
142
+ "id": {
143
+ "type": "Identifier",
144
+ "name": "c",
145
+ "_meta": {
146
+ "_extra": {
147
+ "start": 30,
148
+ "end": 31
149
+ }
150
+ },
151
+ "loc": {
152
+ "start": {
153
+ "line": 5,
154
+ "column": 7
155
+ },
156
+ "end": {
157
+ "line": 5,
158
+ "column": 8
159
+ },
160
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
161
+ }
162
+ },
163
+ "init": {
164
+ "type": "Identifier",
165
+ "name": "b",
166
+ "_meta": {
167
+ "_extra": {
168
+ "start": 34,
169
+ "end": 35
170
+ }
171
+ },
172
+ "loc": {
173
+ "start": {
174
+ "line": 5,
175
+ "column": 11
176
+ },
177
+ "end": {
178
+ "line": 5,
179
+ "column": 12
180
+ },
181
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
182
+ }
183
+ },
184
+ "cloned": false,
185
+ "varType": {
186
+ "type": "DynamicType",
187
+ "id": null,
188
+ "_meta": {}
189
+ },
190
+ "_meta": {
191
+ "_extra": {
192
+ "start": 24,
193
+ "end": 36
194
+ }
195
+ },
196
+ "loc": {
197
+ "start": {
198
+ "line": 5,
199
+ "column": 7
200
+ },
201
+ "end": {
202
+ "line": 5,
203
+ "column": 12
204
+ },
205
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
206
+ }
207
+ },
208
+ {
209
+ "type": "Sequence",
210
+ "expressions": [
211
+ {
212
+ "type": "VariableDeclaration",
213
+ "id": {
214
+ "type": "Identifier",
215
+ "name": "a1",
216
+ "_meta": {
217
+ "_extra": {
218
+ "start": 42,
219
+ "end": 44
220
+ }
221
+ },
222
+ "loc": {
223
+ "start": {
224
+ "line": 7,
225
+ "column": 5
226
+ },
227
+ "end": {
228
+ "line": 7,
229
+ "column": 7
230
+ },
231
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
232
+ }
233
+ },
234
+ "init": {
235
+ "type": "Literal",
236
+ "value": true,
237
+ "literalType": "boolean",
238
+ "_meta": {
239
+ "_extra": {
240
+ "start": 47,
241
+ "end": 51
242
+ }
243
+ },
244
+ "loc": {
245
+ "start": {
246
+ "line": 7,
247
+ "column": 10
248
+ },
249
+ "end": {
250
+ "line": 7,
251
+ "column": 14
252
+ },
253
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
254
+ }
255
+ },
256
+ "cloned": false,
257
+ "varType": {
258
+ "type": "DynamicType",
259
+ "id": null,
260
+ "_meta": {}
261
+ },
262
+ "_meta": {},
263
+ "loc": {
264
+ "start": {
265
+ "line": 7,
266
+ "column": 5
267
+ },
268
+ "end": {
269
+ "line": 7,
270
+ "column": 14
271
+ },
272
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
273
+ }
274
+ },
275
+ {
276
+ "type": "VariableDeclaration",
277
+ "id": {
278
+ "type": "Identifier",
279
+ "name": "a2",
280
+ "_meta": {
281
+ "_extra": {
282
+ "start": 53,
283
+ "end": 55
284
+ }
285
+ },
286
+ "loc": {
287
+ "start": {
288
+ "line": 7,
289
+ "column": 16
290
+ },
291
+ "end": {
292
+ "line": 7,
293
+ "column": 18
294
+ },
295
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
296
+ }
297
+ },
298
+ "init": {
299
+ "type": "Literal",
300
+ "value": false,
301
+ "literalType": "boolean",
302
+ "_meta": {
303
+ "_extra": {
304
+ "start": 58,
305
+ "end": 63
306
+ }
307
+ },
308
+ "loc": {
309
+ "start": {
310
+ "line": 7,
311
+ "column": 21
312
+ },
313
+ "end": {
314
+ "line": 7,
315
+ "column": 26
316
+ },
317
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
318
+ }
319
+ },
320
+ "cloned": false,
321
+ "varType": {
322
+ "type": "DynamicType",
323
+ "id": null,
324
+ "_meta": {}
325
+ },
326
+ "_meta": {},
327
+ "loc": {
328
+ "start": {
329
+ "line": 7,
330
+ "column": 16
331
+ },
332
+ "end": {
333
+ "line": 7,
334
+ "column": 26
335
+ },
336
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
337
+ }
338
+ },
339
+ {
340
+ "type": "VariableDeclaration",
341
+ "id": {
342
+ "type": "Identifier",
343
+ "name": "a3",
344
+ "_meta": {
345
+ "_extra": {
346
+ "start": 65,
347
+ "end": 67
348
+ }
349
+ },
350
+ "loc": {
351
+ "start": {
352
+ "line": 7,
353
+ "column": 28
354
+ },
355
+ "end": {
356
+ "line": 7,
357
+ "column": 30
358
+ },
359
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
360
+ }
361
+ },
362
+ "init": {
363
+ "type": "Identifier",
364
+ "name": "a1",
365
+ "_meta": {
366
+ "_extra": {
367
+ "start": 70,
368
+ "end": 72
369
+ }
370
+ },
371
+ "loc": {
372
+ "start": {
373
+ "line": 7,
374
+ "column": 33
375
+ },
376
+ "end": {
377
+ "line": 7,
378
+ "column": 35
379
+ },
380
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
381
+ }
382
+ },
383
+ "cloned": false,
384
+ "varType": {
385
+ "type": "DynamicType",
386
+ "id": null,
387
+ "_meta": {}
388
+ },
389
+ "_meta": {},
390
+ "loc": {
391
+ "start": {
392
+ "line": 7,
393
+ "column": 28
394
+ },
395
+ "end": {
396
+ "line": 7,
397
+ "column": 35
398
+ },
399
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
400
+ }
401
+ }
402
+ ],
403
+ "_meta": {
404
+ "_extra": {
405
+ "start": 38,
406
+ "end": 73
407
+ }
408
+ },
409
+ "loc": {
410
+ "start": {
411
+ "line": 7,
412
+ "column": 1
413
+ },
414
+ "end": {
415
+ "line": 7,
416
+ "column": 36
417
+ },
418
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
419
+ }
420
+ },
421
+ {
422
+ "type": "VariableDeclaration",
423
+ "id": {
424
+ "type": "Identifier",
425
+ "name": "a4",
426
+ "_meta": {
427
+ "_extra": {
428
+ "start": 79,
429
+ "end": 81
430
+ }
431
+ },
432
+ "loc": {
433
+ "start": {
434
+ "line": 9,
435
+ "column": 5
436
+ },
437
+ "end": {
438
+ "line": 9,
439
+ "column": 7
440
+ },
441
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
442
+ }
443
+ },
444
+ "init": null,
445
+ "cloned": false,
446
+ "varType": {
447
+ "type": "DynamicType",
448
+ "id": null,
449
+ "_meta": {}
450
+ },
451
+ "_meta": {
452
+ "_extra": {
453
+ "start": 75,
454
+ "end": 82
455
+ }
456
+ },
457
+ "loc": {
458
+ "start": {
459
+ "line": 9,
460
+ "column": 5
461
+ },
462
+ "end": {
463
+ "line": 9,
464
+ "column": 7
465
+ },
466
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
467
+ }
468
+ }
469
+ ],
470
+ "language": "javascript",
471
+ "languageVersion": null,
472
+ "uri": "",
473
+ "version": "0.1.63",
474
+ "_meta": {
475
+ "_extra": {
476
+ "end": 83,
477
+ "directives": []
478
+ }
479
+ },
480
+ "loc": {
481
+ "start": {
482
+ "line": 1,
483
+ "column": 1
484
+ },
485
+ "end": {
486
+ "line": 10,
487
+ "column": 1
488
+ },
489
+ "sourcefile": "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/vardecl.js"
490
+ }
491
+ }
package/tests/index.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("mocha");
4
+ var assert = require("assert");
5
+ var parser_1 = require("../src/frontend/javascript/parser");
6
+ var fs = require("fs");
7
+ var path = require("path");
8
+ var globby = require("fast-glob");
9
+ describe('benchmark for javascript', function () {
10
+ var suffixMatch = ['*.js'];
11
+ var jsFiles = globby.sync(suffixMatch, { cwd: path.join(__dirname, '/benchmark/base') });
12
+ var _loop_1 = function (jsFile) {
13
+ it(jsFile, function () {
14
+ var content = fs.readFileSync(path.join(__dirname, '/benchmark/base', jsFile), 'utf8');
15
+ var parsed = (0, parser_1.parse)(content, jsFile);
16
+ var jsonContent = fs.readFileSync(path.join(__dirname, '/benchmark/base', jsFile + '.json'), 'utf8');
17
+ var baseline = JSON.parse(jsonContent);
18
+ assert.ok(deepEqual(parsed, baseline), jsFile);
19
+ });
20
+ };
21
+ for (var _i = 0, jsFiles_1 = jsFiles; _i < jsFiles_1.length; _i++) {
22
+ var jsFile = jsFiles_1[_i];
23
+ _loop_1(jsFile);
24
+ }
25
+ });
26
+ function deepEqual(obj1, obj2) {
27
+ if (obj1 === obj2)
28
+ return true;
29
+ if ((typeof obj1 === 'object' && obj1 !== null) && (typeof obj2 === 'object' && obj2 !== null)) {
30
+ if (Object.keys(obj1).length !== Object.keys(obj2).length)
31
+ return false;
32
+ for (var prop in obj1) {
33
+ if (Object.prototype.hasOwnProperty.call(obj2, prop)) {
34
+ if (!deepEqual(obj1[prop], obj2[prop]))
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ }
40
+ else {
41
+ return false;
42
+ }
43
+ }
package/tests/index.ts ADDED
@@ -0,0 +1,66 @@
1
+ import 'mocha';
2
+ import * as assert from 'assert';
3
+ import { parse } from '../src/frontend/javascript/parser'
4
+ import * as fs from 'fs'
5
+ import * as path from 'path'
6
+ import * as globby from 'fast-glob';
7
+
8
+ function refreshUastJson() {
9
+ const suffixMatch = ['*.js'];
10
+ const jsFiles = globby.sync(suffixMatch, { cwd: path.join(__dirname, '/benchmark/base') });
11
+ for (let file of jsFiles) {
12
+ const content = fs.readFileSync(path.join(__dirname, '/benchmark/base', file), 'utf8');
13
+ const ast = parse(content)
14
+ fs.writeFileSync(path.join(__dirname,'/benchmark/base', `${file}.json`), JSON.stringify(ast, null, 2), 'utf8');
15
+ }
16
+ }
17
+
18
+ // uastparser变更了以后,确认修改都对的情况下,使用tsc编译在yasa替换uastparser验证无误以后
19
+ // 需要重新生成baseline
20
+ // refreshUastJson()
21
+
22
+
23
+ describe('benchmark for javascript', () => {
24
+ const suffixMatch = ['*.js'];
25
+ const jsFiles = globby.sync(suffixMatch, { cwd: path.join(__dirname, '/benchmark/base') });
26
+ for (const jsFile of jsFiles) {
27
+ it(jsFile, () => {
28
+ // fs.writeFileSync(path.join(__dirname, `test.json`), JSON.stringify(parse(content), null, 2), 'utf8');
29
+ const content = fs.readFileSync(path.join(__dirname, '/benchmark/base', jsFile), 'utf8');
30
+ const actual = parse(content,{sourcefile :path.join(__dirname, '/benchmark/base', jsFile),language:"javascript"});
31
+ // console.log(JSON.stringify(parsed));
32
+ // const filePath = path.join(__dirname, '/benchmark/base', jsFile + '.json');
33
+ // fs.writeFile(filePath, JSON.stringify(actual,null,2), (err) => {
34
+ // if (err) {
35
+ // console.error('写入文件时发生错误:', err);
36
+ // return;
37
+ // }
38
+ // console.log('文件已成功写入:', filePath);
39
+ // });
40
+ const baselineJson = fs.readFileSync(path.join(__dirname, '/benchmark/base', jsFile + '.json'), 'utf8')
41
+ // const baseline = JSON.parse(jsonContent);
42
+ // assert.ok(deepEqual(parsed, baseline), jsFile);
43
+
44
+ assert.strictEqual(JSON.stringify(actual,null,2),baselineJson,jsFile)
45
+ });
46
+ }
47
+ });
48
+
49
+ function deepEqual(obj1: any, obj2: any): boolean {
50
+ if (obj1 === obj2) return true
51
+
52
+ if ((typeof obj1 === 'object' && obj1 !== null) && (typeof obj2 === 'object' && obj2 !== null)) {
53
+ if (Object.keys(obj1).length !== Object.keys(obj2).length)
54
+ return false;
55
+
56
+ for (const prop in obj1) {
57
+ if (Object.prototype.hasOwnProperty.call(obj2, prop)) {
58
+ if (!deepEqual(obj1[prop], obj2[prop]))
59
+ return false;
60
+ }
61
+ }
62
+ return true;
63
+ } else {
64
+ return false;
65
+ }
66
+ }
File without changes
package/tests/test.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("mocha");
4
+ var parser_1 = require("../src/frontend/javascript/parser");
5
+ var fs = require("fs");
6
+ var path = require("path");
7
+ function walk(dir, callback) {
8
+ fs.readdir(dir, function (err, files) {
9
+ if (err)
10
+ throw err;
11
+ files.forEach(function (file) {
12
+ var filepath = path.join(dir, file);
13
+ fs.stat(filepath, function (err, stats) {
14
+ if (stats.isDirectory()) {
15
+ walk(filepath, callback);
16
+ }
17
+ else if (stats.isFile()) {
18
+ callback(filepath, stats);
19
+ }
20
+ });
21
+ });
22
+ });
23
+ }
24
+ describe('for preparing benchmark json', function () {
25
+ var filename = 'comment.js';
26
+ it("output ".concat(filename), function () {
27
+ try {
28
+ var content = fs.readFileSync(path.join(__dirname, "/benchmark/base/".concat(filename)), 'utf8');
29
+ fs.writeFileSync(path.join(__dirname, "test.json"), JSON.stringify((0, parser_1.parse)(content,{ sourcefile: "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/demo.ts",
30
+ language: 'javascript'}), null, 2), 'utf8');
31
+ console.log(JSON.stringify((0, parser_1.parse)(content,{ sourcefile: "/Users/jiufo/yasaaaaa/uastparser_js/tests/benchmark/base/demo.ts",
32
+ language: 'javascript'}), null, 2));
33
+ }
34
+ catch (e) {
35
+ console.log(e);
36
+ }
37
+ });
38
+ });