forked from eslint/typescript-eslint-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixtures-to-test.js
522 lines (480 loc) · 20.5 KB
/
fixtures-to-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
"use strict";
const path = require("path");
const glob = require("glob");
/**
* JSX fixtures which have known issues for typescript-eslint-parser
*/
const jsxFilesWithKnownIssues = require("../jsx-known-issues").map(f => f.replace("jsx/", ""));
/**
* Current random error difference on jsx/invalid-no-tag-name.src.js
* TSEP - SyntaxError
* Babylon - RangeError
*
* Reported here: https://github.com/babel/babylon/issues/674
*/
jsxFilesWithKnownIssues.push("invalid-no-tag-name");
/**
* Custom constructs/concepts used in this file:
*
* type Pattern = string; // used for node-glob matching
*
* interface FixturePatternConfig {
* pattern: Pattern,
* config?: {
* babylonParserOptions: any,
* typeScriptESLintParserOptions: any
* }
* }
*/
/**
* Globally track which fixtures need to be parsed with sourceType: "module"
* so that they can be added with the correct FixturePatternConfig
*/
let fixturesRequiringSourceTypeModule = [];
/**
* Utility to generate a FixturePatternConfig object containing the glob pattern for specific subsections of the fixtures/ directory,
* including the capability to ignore specific nested patterns.
*
* @param {string} fixturesSubPath the sub-path within the fixtures/ directory
* @param {Object?} config an optional configuration object with optional sub-paths to ignore and/or parse with sourceType: module
* @returns {FixturePatternConfig} an object containing the glob pattern and optional additional config
*/
function createFixturePatternConfigFor(fixturesSubPath, config) {
if (!fixturesSubPath) {
return "";
}
config = config || {};
config.ignore = config.ignore || [];
config.fileType = config.fileType || "js";
config.parseWithSourceTypeModule = config.parseWithSourceTypeModule || [];
/**
* The TypeScript compiler gives us the "externalModuleIndicator" to allow typescript-eslint-parser do dynamically detect the "sourceType".
* Babylon does not have an equivalent feature (although perhaps it might come in the future https://github.com/babel/babylon/issues/440),
* so we have to specify the "sourceType" we want to use.
*
* By default we have configured babylon to use "script", but for any fixtures specified in the parseWithSourceTypeModule array we need "module".
*
* First merge the fixtures which need to be parsed with sourceType: "module" into the
* ignore list, and then add their full config into the global array.
*/
if (config.parseWithSourceTypeModule.length) {
config.ignore = [].concat(config.ignore, config.parseWithSourceTypeModule);
fixturesRequiringSourceTypeModule = [].concat(fixturesRequiringSourceTypeModule, config.parseWithSourceTypeModule.map(
fixture => ({
// It needs to be the full path from within fixtures/ for the pattern
pattern: `${fixturesSubPath}/${fixture}.src.${config.fileType}`,
config: { babylonParserOptions: { sourceType: "module" } }
})
));
}
return {
pattern: `${fixturesSubPath}/!(${config.ignore.join("|")}).src.${config.fileType}`
};
}
/**
* An array of FixturePatternConfigs
*/
let fixturePatternConfigsToTest = [
createFixturePatternConfigFor("basics"),
createFixturePatternConfigFor("comments", {
ignore: [
"export-default-anonymous-class", // needs to be parsed with `sourceType: "module"`
/**
* Template strings seem to also be affected by the difference in opinion between different parsers in:
* https://github.com/babel/babylon/issues/673
*/
"no-comment-template", // Purely AST diffs
"template-string-block" // Purely AST diffs
]
}),
createFixturePatternConfigFor("ecma-features/templateStrings", {
ignore: [
"**/*"
]
}),
createFixturePatternConfigFor("ecma-features/experimentalObjectRestSpread", {
ignore: [
/**
* Trailing comma is not permitted after a "RestElement" in Babylon
*/
"invalid-rest-trailing-comma"
]
}),
createFixturePatternConfigFor("ecma-features/arrowFunctions", {
ignore: [
/**
* Expected babylon parse errors - all of these files below produce parse errors in espree
* as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser
* does not actually error on them and will produce an AST.
*/
"error-dup-params", // babylon parse errors
"error-dup-params", // babylon parse errors
"error-strict-dup-params", // babylon parse errors
"error-strict-octal", // babylon parse errors
"error-two-lines" // babylon parse errors
]
}),
createFixturePatternConfigFor("ecma-features/binaryLiterals"),
createFixturePatternConfigFor("ecma-features/blockBindings"),
createFixturePatternConfigFor("ecma-features/classes", {
ignore: [
/**
* super() is being used outside of constructor. Other parsers (e.g. espree, acorn) do not error on this.
*/
"class-one-method-super", // babylon parse errors
/**
* Expected babylon parse errors - all of these files below produce parse errors in espree
* as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser
* does not actually error on them and will produce an AST.
*/
"invalid-class-declaration", // babylon parse errors
"invalid-class-setter-declaration" // babylon parse errors
]
}),
createFixturePatternConfigFor("ecma-features/defaultParams"),
createFixturePatternConfigFor("ecma-features/destructuring", {
ignore: [
/**
* Expected babylon parse errors - all of these files below produce parse errors in espree
* as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser
* does not actually error on them and will produce an AST.
*/
"invalid-defaults-object-assign" // babylon parse errors
]
}),
createFixturePatternConfigFor("ecma-features/destructuring-and-arrowFunctions"),
createFixturePatternConfigFor("ecma-features/destructuring-and-blockBindings"),
createFixturePatternConfigFor("ecma-features/destructuring-and-defaultParams"),
createFixturePatternConfigFor("ecma-features/destructuring-and-forOf"),
createFixturePatternConfigFor("ecma-features/destructuring-and-spread", {
ignore: [
/**
* Expected babylon parse errors - all of these files below produce parse errors in espree
* as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser
* does not actually error on them and will produce an AST.
*/
"error-complex-destructured-spread-first" // babylon parse errors
]
}),
createFixturePatternConfigFor("ecma-features/experimentalAsyncIteration"),
createFixturePatternConfigFor("ecma-features/experimentalDynamicImport"),
createFixturePatternConfigFor("ecma-features/exponentiationOperators"),
createFixturePatternConfigFor("ecma-features/forOf", {
ignore: [
/**
* TypeScript, espree and acorn parse this fine - esprima, flow and babylon do not...
*/
"for-of-with-function-initializer" // babylon parse errors
]
}),
createFixturePatternConfigFor("ecma-features/generators"),
createFixturePatternConfigFor("ecma-features/globalReturn"),
createFixturePatternConfigFor("ecma-features/modules", {
ignore: [
/**
* TypeScript, flow and babylon parse this fine - esprima, espree and acorn do not...
*/
"invalid-export-default", // typescript-eslint-parser parse errors
/**
* Expected babylon parse errors - all of these files below produce parse errors in espree
* as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser
* does not actually error on them and will produce an AST.
*/
"invalid-export-named-default", // babylon parse errors
"invalid-import-default-module-specifier", // babylon parse errors
"invalid-import-module-specifier", // babylon parse errors
/**
* Deleting local variable in strict mode
*/
"error-delete", // babylon parse errors
/**
* 'with' in strict mode
*/
"error-strict" // babylon parse errors
],
parseWithSourceTypeModule: [
"export-default-array",
"export-default-class",
"export-default-expression",
"export-default-function",
"export-default-named-class",
"export-default-named-function",
"export-default-number",
"export-default-object",
"export-default-value",
"export-from-batch",
"export-from-default",
"export-from-named-as-default",
"export-from-named-as-specifier",
"export-from-named-as-specifiers",
"export-from-specifier",
"export-from-specifiers",
"export-function",
"export-named-as-default",
"export-named-as-specifier",
"export-named-as-specifiers",
"export-named-class",
"export-named-empty",
"export-named-specifier",
"export-named-specifiers-comma",
"export-named-specifiers",
"export-var-anonymous-function",
"export-var-number",
"export-var",
"import-default-and-named-specifiers",
"import-default-and-namespace-specifiers",
"import-default-as",
"import-default",
"import-jquery",
"import-module",
"import-named-as-specifier",
"import-named-as-specifiers",
"import-named-empty",
"import-named-specifier",
"import-named-specifiers-comma",
"import-named-specifiers",
"import-namespace-specifier",
"import-null-as-nil",
"invalid-await",
"invalid-class"
]
}),
createFixturePatternConfigFor("ecma-features/newTarget", {
ignore: [
/**
* Expected babylon parse errors - all of these files below produce parse errors in espree
* as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser
* does not actually error on them and will produce an AST.
*/
"invalid-new-target", // babylon parse errors
"invalid-unknown-property" // babylon parse errors
]
}),
createFixturePatternConfigFor("ecma-features/objectLiteralComputedProperties"),
createFixturePatternConfigFor("ecma-features/objectLiteralDuplicateProperties", {
ignore: [
/**
* Expected babylon parse errors - all of these files below produce parse errors in espree
* as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser
* does not actually error on them and will produce an AST.
*/
"error-proto-property", // babylon parse errors
"error-proto-string-property" // babylon parse errors
]
}),
createFixturePatternConfigFor("ecma-features/objectLiteralShorthandMethods"),
createFixturePatternConfigFor("ecma-features/objectLiteralShorthandProperties"),
createFixturePatternConfigFor("ecma-features/octalLiterals"),
createFixturePatternConfigFor("ecma-features/regex"),
createFixturePatternConfigFor("ecma-features/regexUFlag"),
createFixturePatternConfigFor("ecma-features/regexYFlag"),
createFixturePatternConfigFor("ecma-features/restParams", {
ignore: [
/**
* Expected babylon parse errors - all of these files below produce parse errors in espree
* as well, but the TypeScript compiler is so forgiving during parsing that typescript-eslint-parser
* does not actually error on them and will produce an AST.
*/
"error-no-default", // babylon parse errors
"error-not-last" // babylon parse errors
]
}),
createFixturePatternConfigFor("ecma-features/spread"),
createFixturePatternConfigFor("ecma-features/unicodeCodePointEscapes"),
createFixturePatternConfigFor("jsx", { ignore: jsxFilesWithKnownIssues }),
createFixturePatternConfigFor("jsx-useJSXTextNode"),
/* ================================================== */
/**
* TSX-SPECIFIC FILES
*/
createFixturePatternConfigFor("tsx", {
fileType: "tsx",
ignore: [
/**
* AST difference
*/
"react-typed-props",
/**
* currently babylon not supported
*/
"generic-jsx-element"
]
}),
/* ================================================== */
/**
* TYPESCRIPT-SPECIFIC FILES
*/
createFixturePatternConfigFor("typescript/babylon-convergence", { fileType: "ts" }),
createFixturePatternConfigFor("typescript/basics", {
fileType: "ts",
ignore: [
/**
* Other babylon parse errors relating to invalid syntax.
*/
"abstract-class-with-abstract-constructor", // babylon parse errors
"class-with-export-parameter-properties", // babylon parse errors
"class-with-optional-methods", // babylon parse errors
"class-with-static-parameter-properties", // babylon parse errors
"interface-with-all-property-types", // babylon parse errors
"interface-with-construct-signature-with-parameter-accessibility", // babylon parse errors
"class-with-implements-and-extends", // babylon parse errors
"var-with-definite-assignment", // babylon parse errors
"class-with-definite-assignment", // babylon parse errors
/**
* typescript-eslint-parser erroring, but babylon not.
*/
"arrow-function-with-type-parameters", // typescript-eslint-parser parse errors
/**
* Babylon: ClassDeclaration + abstract: true
* tsep: TSAbstractClassDeclaration
*/
"abstract-class-with-abstract-properties",
/**
* Babylon: ClassProperty + abstract: true
* tsep: TSAbstractClassProperty
*/
"abstract-class-with-abstract-readonly-property",
/**
* Babylon: TSExpressionWithTypeArguments
* tsep: ClassImplements
*/
"class-with-implements-generic-multiple",
"class-with-implements-generic",
"class-with-implements",
"class-with-extends-and-implements",
/**
* Babylon: TSDeclareFunction + declare: true
* tsep: DeclareFunction
*/
"declare-function",
/**
* Other major AST differences (e.g. fundamentally different node types)
*/
"class-with-mixin",
"function-with-types-assignation",
"interface-extends-multiple",
"interface-extends",
"interface-type-parameters",
"interface-with-extends-type-parameters",
"interface-with-generic",
"interface-with-jsdoc",
"interface-with-optional-properties",
"interface-without-type-annotation",
"type-alias-declaration-with-constrained-type-parameter",
"type-alias-declaration",
"type-alias-object-without-annotation",
"typed-this",
"export-type-function-declaration",
"export-type-class-declaration",
"abstract-interface",
"export-type-alias-declaration",
"unique-symbol",
"keyof-operator",
/**
* tsep bug - Program.body[0].expression.left.properties[0].value.right is currently showing up
* as `ArrayPattern`, babylon, acorn and espree say it should be `ArrayExpression`
* TODO: Fix this
*/
"destructuring-assignment",
/**
* Babylon bug for optional or abstract methods?
*/
"abstract-class-with-abstract-method", // babylon parse errors
"abstract-class-with-optional-method", // babylon parse errors
"declare-class-with-optional-method", // babylon parse errors
/**
* Awaiting feedback on Babylon issue https://github.com/babel/babylon/issues/700
*/
"class-with-private-parameter-properties",
"class-with-protected-parameter-properties",
"class-with-public-parameter-properties",
"class-with-readonly-parameter-properties",
/**
* Not yet supported in Babylon https://github.com/babel/babel/issues/7749
*/
"import-type-with-type-parameters-in-type-reference"
],
parseWithSourceTypeModule: [
"export-named-enum",
"export-assignment",
"export-default-class-with-generic",
"export-default-class-with-multiple-generics",
"export-named-class-with-generic",
"export-named-class-with-multiple-generics"
]
}),
createFixturePatternConfigFor("typescript/decorators/accessor-decorators", { fileType: "ts" }),
createFixturePatternConfigFor("typescript/decorators/class-decorators", { fileType: "ts" }),
createFixturePatternConfigFor("typescript/decorators/method-decorators", { fileType: "ts" }),
createFixturePatternConfigFor("typescript/decorators/parameter-decorators", { fileType: "ts" }),
createFixturePatternConfigFor("typescript/decorators/property-decorators", { fileType: "ts" }),
createFixturePatternConfigFor("typescript/expressions", {
fileType: "ts",
ignore: [
/**
* currently babylon not supported
*/
"tagged-template-expression-type-arguments"
]
}),
createFixturePatternConfigFor("typescript/errorRecovery", {
fileType: "ts",
ignore: [
/**
* AST difference
*/
"interface-empty-extends",
/**
* TypeScript-specific tests taken from "errorRecovery". Babylon is not being as forgiving as the TypeScript compiler here.
*/
"class-empty-extends-implements", // babylon parse errors
"class-empty-extends", // babylon parse errors
"decorator-on-enum-declaration", // babylon parse errors
"decorator-on-interface-declaration", // babylon parse errors
"interface-property-modifiers", // babylon parse errors
"enum-with-keywords" // babylon parse errors
]
}),
createFixturePatternConfigFor("typescript/namespaces-and-modules", {
fileType: "ts",
ignore: [
/**
* Minor AST difference
*/
"nested-internal-module",
/**
* Babylon: TSDeclareFunction
* tsep: TSNamespaceFunctionDeclaration
*/
"declare-namespace-with-exported-function"
]
})
];
/**
* Add in all the fixtures which need to be parsed with sourceType: "module"
*/
fixturePatternConfigsToTest = [].concat(fixturePatternConfigsToTest, fixturesRequiringSourceTypeModule);
/**
* interface Fixture {
* filename: string,
* config?: any
* }
*/
const fixturesToTest = [];
const fixturesDirPath = path.join(__dirname, "../fixtures");
/**
* Resolve the glob patterns into actual Fixture files that we can run assertions for...
*/
fixturePatternConfigsToTest.forEach(fixturePatternConfig => {
/**
* Find the fixture files which match the given pattern
*/
const matchingFixtures = glob.sync(`${fixturesDirPath}/${fixturePatternConfig.pattern}`, {});
matchingFixtures.forEach(filename => {
fixturesToTest.push({
filename,
config: fixturePatternConfig.config
});
});
});
module.exports = fixturesToTest;