Skip to content

Commit

Permalink
test: update babel alignment tests to latest version (#4774)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Apr 5, 2022
1 parent 86fa2c7 commit de68e5e
Show file tree
Hide file tree
Showing 10 changed files with 918 additions and 1,597 deletions.
@@ -1,2 +1,2 @@
const x: X<never>;
var x: X<never>;
Observable.empty<never>();
@@ -1 +1 @@
const x: abstract new () => void;
var x: abstract new () => void;
@@ -1 +1 @@
const x: new () => void;
var x: new () => void;
2 changes: 1 addition & 1 deletion packages/typescript-estree/package.json
Expand Up @@ -51,7 +51,7 @@
},
"devDependencies": {
"@babel/code-frame": "^7.16.0",
"@babel/parser": "^7.16.0",
"@babel/parser": "^7.17.8",
"@types/babel__code-frame": "^7.0.3",
"@types/debug": "*",
"@types/glob": "*",
Expand Down
40 changes: 13 additions & 27 deletions packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
Expand Up @@ -181,12 +181,6 @@ tester.addFixturePatternConfig('javascript/classes', {
* TS3.6 made computed constructors parse as actual constructors.
*/
'class-two-methods-computed-constructor',
/**
* Babel emits a `PrivateName` instead of `PrivateIdentifier`
*/
'class-private-identifier-accessor',
'class-private-identifier-method',
'class-private-identifier-field',
],
});

Expand Down Expand Up @@ -236,12 +230,18 @@ tester.addFixturePatternConfig('javascript/importMeta');
tester.addFixturePatternConfig('javascript/labels');

tester.addFixturePatternConfig('javascript/modules', {
ignore: [
/**
* [BABEL ERRORED, BUT TS-ESTREE DID NOT]
* SyntaxError: Unexpected keyword 'default'.
*/
'invalid-export-named-default',
],
ignoreSourceType: [
'error-function',
'error-strict',
'error-delete',
'invalid-await',
'invalid-export-named-default',
// babel does not recognize these as modules
'export-named-as-default',
'export-named-as-specifier',
Expand All @@ -261,13 +261,6 @@ tester.addFixturePatternConfig('javascript/objectLiteralComputedProperties');

tester.addFixturePatternConfig('javascript/objectLiteralDuplicateProperties', {
ignore: [
/**
* Babel throws SyntaxError: Redefinition of __proto__ property
*
* TypeScript reports it via the overloaded TS 2300 "Duplicate identifier '{0}'.", which we
* do not currently enable as per the notes above.
*/
'error-proto-string-property', // babel parse errors
/**
* ts-estree throws thanks to TS 1117 (ts 3.2 at time of writing)
* "An object literal cannot have multiple properties with the same name in strict mode."
Expand Down Expand Up @@ -306,13 +299,6 @@ tester.addFixturePatternConfig('jsx', {
* https://github.com/Microsoft/TypeScript/issues/7410
*/
'embedded-tags',
/**
* Current random error difference on jsx/invalid-no-tag-name.src.js
* ts-estree - SyntaxError
* Babel - RangeError
* @see https://github.com/babel/babel/issues/6680
*/
'invalid-no-tag-name',
/**
* [BABEL ERRORED, BUT TS-ESTREE DID NOT]
* SyntaxError: Unexpected token
Expand Down Expand Up @@ -398,18 +384,17 @@ tester.addFixturePatternConfig('typescript/basics', {
* TODO: enforce that accessibility is not allowed on a private identifier
*/
'class-private-identifier-field-with-accessibility-error',
/**
* Babel emits a `PrivateName` instead of `PrivateIdentifier`
*/
'class-private-identifier-field-with-annotation',
/**
* [TS-ESTREE ERRORED, BUT BABEL DID NOT]
* TypeScript 4.4 new feature
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#abstract-properties-do-not-allow-initializers
*/
'abstract-class-with-abstract-readonly-property',
'abstract-class-with-abstract-properties',
'abstract-class-with-override-property',
/**
* [BABEL ERRORED, BUT TS-ESTREE DID NOT]
* SyntaxError: Missing initializer in const declaration.
*/
'var-with-definite-assignment',
],
ignoreSourceType: [
/**
Expand All @@ -436,6 +421,7 @@ tester.addFixturePatternConfig('typescript/basics', {
'import-type-named',
'import-type-named-as',
'import-type-star-as-ns',
'keyword-variables',
],
});

Expand Down
14 changes: 14 additions & 0 deletions packages/typescript-estree/tests/ast-alignment/utils.ts
Expand Up @@ -263,6 +263,20 @@ export function preprocessBabylonAST(ast: File): any {
Object.keys(node).forEach(key => delete node[key]);
Object.assign(node, typeAnnotation);
},
/**
* babel 7.17.x introduced index property to location data to 2 node types
* TODO: report this to babel
*/
TSEnumDeclaration(node: any) {
if (node.loc?.start?.index) {
delete node.loc.start.index;
}
},
TSTypePredicate(node: any) {
if (node.loc?.start?.index) {
delete node.loc.start.index;
}
},
},
);
}
Expand Down

0 comments on commit de68e5e

Please sign in to comment.