Thanks to visit codestin.com
Credit goes to github.com

Skip to content

test: update babel alignment tests to latest version #4774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const x: X<never>;
var x: X<never>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my learning: why the change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

babel reports now errors for unidealized const variables, witch is tested in

    /**
     * [BABEL ERRORED, BUT TS-ESTREE DID NOT]
     * SyntaxError: Missing initializer in const declaration.
     */
    'var-with-definite-assignment',

Observable.empty<never>();
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const x: abstract new () => void;
var x: abstract new () => void;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const x: new () => void;
var x: new () => void;
2 changes: 1 addition & 1 deletion packages/typescript-estree/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading