diff --git a/README.md b/README.md index 25a1a58f3ed..2443ba50a16 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ The latest version under the `canary` tag **(latest commit to master)** is: ## Supported TypeScript Version -**The version range of TypeScript currently supported by this parser is `>=3.3.1 <4.4.0`.** +**The version range of TypeScript currently supported by this parser is `>=3.3.1 <4.5.0`.** These versions are what we test against. diff --git a/package.json b/package.json index 3939cc2d63a..2e42c438b86 100644 --- a/package.json +++ b/package.json @@ -121,12 +121,12 @@ "ts-jest": "^27.0.1", "ts-node": "^10.0.0", "tslint": "^6.1.3", - "typescript": ">=3.3.1 <4.4.0" + "typescript": ">=3.3.1 <4.5.0" }, "resolutions": { "@types/node": "^15.6.1", "jest-diff": "^27.0.0", "pretty-format": "^27.0.0", - "typescript": "4.3.5" + "typescript": "4.4.2" } } diff --git a/packages/ast-spec/src/ast-node-types.ts b/packages/ast-spec/src/ast-node-types.ts index 6aa0087d5eb..90a18ba8d9e 100644 --- a/packages/ast-spec/src/ast-node-types.ts +++ b/packages/ast-spec/src/ast-node-types.ts @@ -68,6 +68,7 @@ export enum AST_NODE_TYPES { ReturnStatement = 'ReturnStatement', SequenceExpression = 'SequenceExpression', SpreadElement = 'SpreadElement', + StaticBlock = 'StaticBlock', Super = 'Super', SwitchCase = 'SwitchCase', SwitchStatement = 'SwitchStatement', diff --git a/packages/ast-spec/src/element/StaticBlock/spec.ts b/packages/ast-spec/src/element/StaticBlock/spec.ts new file mode 100644 index 00000000000..526a5f65f6d --- /dev/null +++ b/packages/ast-spec/src/element/StaticBlock/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Statement } from '../../unions/Statement'; + +export interface StaticBlock extends BaseNode { + type: AST_NODE_TYPES.StaticBlock; + body: Statement[]; +} diff --git a/packages/ast-spec/src/element/spec.ts b/packages/ast-spec/src/element/spec.ts index 5ee18d91402..a31caecced3 100644 --- a/packages/ast-spec/src/element/spec.ts +++ b/packages/ast-spec/src/element/spec.ts @@ -2,6 +2,7 @@ export * from './ClassProperty/spec'; export * from './MethodDefinition/spec'; export * from './Property/spec'; export * from './SpreadElement/spec'; +export * from './StaticBlock/spec'; export * from './TSAbstractClassProperty/spec'; export * from './TSAbstractMethodDefinition/spec'; export * from './TSCallSignatureDeclaration/spec'; diff --git a/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts b/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts index 174e98e6c6b..d15682a4efe 100644 --- a/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts +++ b/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts @@ -45,7 +45,7 @@ export interface PunctuatorTokenToText { [SyntaxKind.AtToken]: '@'; [SyntaxKind.QuestionQuestionToken]: '??'; [SyntaxKind.BacktickToken]: '`'; - // [SyntaxKind.HashToken]: '#'; // new in PunctuationSyntaxKind in TS 4.4 + [SyntaxKind.HashToken]: '#'; [SyntaxKind.EqualsToken]: '='; [SyntaxKind.PlusEqualsToken]: '+='; [SyntaxKind.MinusEqualsToken]: '-='; @@ -58,8 +58,8 @@ export interface PunctuatorTokenToText { [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: '>>>='; [SyntaxKind.AmpersandEqualsToken]: '&='; [SyntaxKind.BarEqualsToken]: '|='; - [SyntaxKind.BarBarEqualsToken]: '||='; // included in PunctuationSyntaxKind in TS 4.4 - [SyntaxKind.AmpersandAmpersandEqualsToken]: '&&='; // included in PunctuationSyntaxKind in TS 4.4 - [SyntaxKind.QuestionQuestionEqualsToken]: '??='; // included in PunctuationSyntaxKind in TS 4.4 + [SyntaxKind.BarBarEqualsToken]: '||='; + [SyntaxKind.AmpersandAmpersandEqualsToken]: '&&='; + [SyntaxKind.QuestionQuestionEqualsToken]: '??='; [SyntaxKind.CaretEqualsToken]: '^='; } diff --git a/packages/ast-spec/src/unions/ClassElement.ts b/packages/ast-spec/src/unions/ClassElement.ts index a4d986d09c7..c174c4ce6c7 100644 --- a/packages/ast-spec/src/unions/ClassElement.ts +++ b/packages/ast-spec/src/unions/ClassElement.ts @@ -1,5 +1,6 @@ import type { ClassProperty } from '../element/ClassProperty/spec'; import type { MethodDefinition } from '../element/MethodDefinition/spec'; +import type { StaticBlock } from '../element/StaticBlock/spec'; import type { TSAbstractClassProperty } from '../element/TSAbstractClassProperty/spec'; import type { TSAbstractMethodDefinition } from '../element/TSAbstractMethodDefinition/spec'; import type { TSIndexSignature } from '../element/TSIndexSignature/spec'; @@ -7,6 +8,7 @@ import type { TSIndexSignature } from '../element/TSIndexSignature/spec'; export type ClassElement = | ClassProperty | MethodDefinition + | StaticBlock | TSAbstractClassProperty | TSAbstractMethodDefinition | TSIndexSignature; diff --git a/packages/ast-spec/src/unions/Node.ts b/packages/ast-spec/src/unions/Node.ts index 61c943af566..f0802b3b685 100644 --- a/packages/ast-spec/src/unions/Node.ts +++ b/packages/ast-spec/src/unions/Node.ts @@ -16,6 +16,7 @@ import type { ClassProperty } from '../element/ClassProperty/spec'; import type { MethodDefinition } from '../element/MethodDefinition/spec'; import type { Property } from '../element/Property/spec'; import type { SpreadElement } from '../element/SpreadElement/spec'; +import type { StaticBlock } from '../element/StaticBlock/spec'; import type { TSAbstractClassProperty } from '../element/TSAbstractClassProperty/spec'; import type { TSAbstractMethodDefinition } from '../element/TSAbstractMethodDefinition/spec'; import type { TSCallSignatureDeclaration } from '../element/TSCallSignatureDeclaration/spec'; @@ -235,6 +236,7 @@ export type Node = | ReturnStatement | SequenceExpression | SpreadElement + | StaticBlock | Super | SwitchCase | SwitchStatement diff --git a/packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts b/packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts index c673a7d5af4..6feea3d95ad 100644 --- a/packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts +++ b/packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts @@ -179,7 +179,7 @@ export class OffsetStorage { fromToken.range[1] <= range[1]; // this has to be before the delete + insert below or else you'll get into a cycle const fromTokenDescriptor = fromTokenIsInRange - ? this.getOffsetDescriptor(fromToken!) + ? this.getOffsetDescriptor(fromToken) : null; // First, remove any existing nodes in the range from the tree. @@ -193,8 +193,8 @@ export class OffsetStorage { * even if it's in the current range. */ if (fromTokenIsInRange) { - this.tree.insert(fromToken!.range[0], fromTokenDescriptor!); - this.tree.insert(fromToken!.range[1], descriptorToInsert); + this.tree.insert(fromToken.range[0], fromTokenDescriptor!); + this.tree.insert(fromToken.range[1], descriptorToInsert); } /* diff --git a/packages/parser/tests/tools/test-utils.ts b/packages/parser/tests/tools/test-utils.ts index 575ac1dc5b7..6dd679d1fea 100644 --- a/packages/parser/tests/tools/test-utils.ts +++ b/packages/parser/tests/tools/test-utils.ts @@ -59,7 +59,7 @@ export function createSnapshotTestBlock( * AST_NODE_TYPE, we rethrow to cause the test to fail */ if (/Unknown AST_NODE_TYPE/.exec((error as Error).message)) { - throw new Error(error); + throw error; } expect(parse).toThrowErrorMatchingSnapshot(); } diff --git a/packages/scope-manager/tests/fixtures.test.ts b/packages/scope-manager/tests/fixtures.test.ts index 69833caa7fa..af327985df3 100644 --- a/packages/scope-manager/tests/fixtures.test.ts +++ b/packages/scope-manager/tests/fixtures.test.ts @@ -139,7 +139,10 @@ function nestDescribe( try { makeDir.sync(fixture.snapshotPath); - } catch (e) { + } catch ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + e: any + ) { if ('code' in e && e.code === 'EEXIST') { // already exists - ignored } else { diff --git a/packages/shared-fixtures/fixtures/typescript/basics/class-static-blocks.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/class-static-blocks.src.ts new file mode 100644 index 00000000000..21ae81c3aea --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/class-static-blocks.src.ts @@ -0,0 +1,8 @@ +class Foo { + static count = 0; + static { + if (someCondition()) { + count++; + } + } +} diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 7f8514d8bc0..8170cedad3c 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -311,7 +311,11 @@ export class Converter { */ private convertBodyExpressions( nodes: ts.NodeArray, - parent: ts.SourceFile | ts.Block | ts.ModuleBlock, + parent: + | ts.SourceFile + | ts.Block + | ts.ModuleBlock + | ts.ClassStaticBlockDeclaration, ): TSESTree.Statement[] { let allowDirectives = canContainDirective(parent); @@ -2824,6 +2828,13 @@ export class Converter { return result; } + case SyntaxKind.ClassStaticBlockDeclaration: { + return this.createNode(node, { + type: AST_NODE_TYPES.StaticBlock, + body: this.convertBodyExpressions(node.body.statements, node), + }); + } + default: return this.deeplyCopy(node); } diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 8c223ed650a..82f487b864c 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -194,7 +194,11 @@ export function getLocFor( * @returns returns true if node can contain directive */ export function canContainDirective( - node: ts.SourceFile | ts.Block | ts.ModuleBlock, + node: + | ts.SourceFile + | ts.Block + | ts.ModuleBlock + | ts.ClassStaticBlockDeclaration, ): boolean { if (node.kind === ts.SyntaxKind.Block) { switch (node.parent.kind) { diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index e61b1b69ec2..6cb3a2d6c27 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -30,12 +30,12 @@ const log = debug('typescript-eslint:typescript-estree:parser'); * This needs to be kept in sync with the top-level README.md in the * typescript-eslint monorepo */ -const SUPPORTED_TYPESCRIPT_VERSIONS = '>=3.3.1 <4.4.0'; +const SUPPORTED_TYPESCRIPT_VERSIONS = '>=3.3.1 <4.5.0'; /* * The semver package will ignore prerelease ranges, and we don't want to explicitly document every one * List them all separately here, so we can automatically create the full string */ -const SUPPORTED_PRERELEASE_RANGES: string[] = ['4.3.0-beta', '4.3.1-rc']; +const SUPPORTED_PRERELEASE_RANGES: string[] = ['4.4.0-beta', '4.4.1-rc']; const ACTIVE_TYPESCRIPT_VERSION = ts.version; const isRunningSupportedTypeScriptVersion = semver.satisfies( ACTIVE_TYPESCRIPT_VERSION, diff --git a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts index 0f74c42ac64..d5daed09332 100644 --- a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts +++ b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts @@ -135,6 +135,7 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.ReturnStatement]: ts.ReturnStatement; [AST_NODE_TYPES.SequenceExpression]: ts.BinaryExpression; [AST_NODE_TYPES.SpreadElement]: ts.SpreadElement | ts.SpreadAssignment; + [AST_NODE_TYPES.StaticBlock]: ts.ClassStaticBlockDeclaration; [AST_NODE_TYPES.Super]: ts.SuperExpression; [AST_NODE_TYPES.SwitchCase]: ts.CaseClause | ts.DefaultClause; [AST_NODE_TYPES.SwitchStatement]: ts.SwitchStatement; diff --git a/packages/typescript-estree/src/ts-estree/ts-nodes.ts b/packages/typescript-estree/src/ts-estree/ts-nodes.ts index 80a7b34e0c8..673dd6f9831 100644 --- a/packages/typescript-estree/src/ts-estree/ts-nodes.ts +++ b/packages/typescript-estree/src/ts-estree/ts-nodes.ts @@ -43,6 +43,7 @@ export type TSNode = | ts.KeywordTypeNode // TODO: This node is bad, maybe we should report this | ts.ImportTypeNode | ts.ThisTypeNode + | ts.ClassStaticBlockDeclaration // | ts.FunctionOrConstructorTypeNodeBase -> FunctionTypeNode, ConstructorTypeNode | ts.ConstructorTypeNode | ts.FunctionTypeNode diff --git a/packages/typescript-estree/tests/ast-alignment/parse.ts b/packages/typescript-estree/tests/ast-alignment/parse.ts index 7a463d97256..484c8ef18d1 100644 --- a/packages/typescript-estree/tests/ast-alignment/parse.ts +++ b/packages/typescript-estree/tests/ast-alignment/parse.ts @@ -26,6 +26,7 @@ function parseWithBabelParser(text: string, jsx = true): File { const plugins: ParserPlugin[] = [ 'classProperties', 'decorators-legacy', + 'classStaticBlock', 'estree', 'typescript', ]; @@ -61,7 +62,7 @@ function parseWithTypeScriptESTree(text: string, jsx = true): parser.AST { jsx, }); return result.ast; - } catch (e) { + } catch (e: any) { throw createError(e.message, e.lineNumber, e.column); } } @@ -97,7 +98,7 @@ export function parse( 'Please provide a valid parser: either "typescript-estree" or "@babel/parser"', ); } - } catch (error) { + } catch (error: any) { const loc = error.loc as TSESTree.LineAndColumnData | undefined; if (loc) { error.codeFrame = codeFrameColumns( diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index 3cecac3f09f..7427c1b1831 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -250,6 +250,16 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any { } } }, + /** + * Babel adds a `static` property to the StaticBlock when the + * `typescript` plugin and the `classStaticBlock` plugin are enabled. + * @see https://github.com/babel/babel/issues/13674 + */ + StaticBlock(node: any) { + if (node.static != null) { + delete node.static; + } + }, }, ); } diff --git a/packages/typescript-estree/tests/ast-fixtures.test.ts b/packages/typescript-estree/tests/ast-fixtures.test.ts index 613595e4f8a..f3ffbabd809 100644 --- a/packages/typescript-estree/tests/ast-fixtures.test.ts +++ b/packages/typescript-estree/tests/ast-fixtures.test.ts @@ -58,7 +58,10 @@ function nestDescribe( try { makeDir.sync(fixture.snapshotPath); - } catch (e) { + } catch ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + e: any + ) { if ('code' in e && e.code === 'EEXIST') { // already exists - ignored } else { diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap index 7a972315f31..ce8d6b5cc6e 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap @@ -1408,8 +1408,8 @@ TSError { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-closing-tag.src 1`] = ` TSError { - "column": 3, - "index": 3, + "column": 5, + "index": 5, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a'.", } @@ -1426,8 +1426,8 @@ TSError { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-dot-tag-name.src 1`] = ` TSError { - "column": 7, - "index": 7, + "column": 9, + "index": 9, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a.b.c'.", } @@ -1435,8 +1435,8 @@ TSError { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-namespace-tag.src 1`] = ` TSError { - "column": 5, - "index": 5, + "column": 7, + "index": 7, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a:b'.", } @@ -1742,6 +1742,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-multi-line-keyword-declare.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-static-blocks.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-accessibility-modifiers.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-constructor-and-modifier.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/lib/parse.test.ts b/packages/typescript-estree/tests/lib/parse.test.ts index aa15fc136c1..236dc6929ad 100644 --- a/packages/typescript-estree/tests/lib/parse.test.ts +++ b/packages/typescript-estree/tests/lib/parse.test.ts @@ -50,7 +50,10 @@ describe('parseWithNodeMaps()', () => { it('should have correct column number when strict mode error occurs', () => { try { parser.parseWithNodeMaps('function fn(a, a) {\n}'); - } catch (err) { + } catch ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + err: any + ) { expect(err.column).toEqual(16); } }); @@ -505,7 +508,10 @@ describe('parseAndGenerateServices', () => { /** * Aligns paths between environments, node for windows uses `\`, for linux and mac uses `/` */ - error.message = (error as Error).message.replace(/\\(?!["])/gm, '/'); + (error as Error).message = (error as Error).message.replace( + /\\(?!["])/gm, + '/', + ); throw error; } }; diff --git a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-closing-tag.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-closing-tag.src.js.shot index a35f3afd715..a8788896feb 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-closing-tag.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-closing-tag.src.js.shot @@ -2,8 +2,8 @@ exports[`jsx invalid-mismatched-closing-tag.src 1`] = ` TSError { - "column": 3, - "index": 3, + "column": 5, + "index": 5, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a'.", } diff --git a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-dot-tag-name.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-dot-tag-name.src.js.shot index 77d7e4187c3..560ee71e7f7 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-dot-tag-name.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-dot-tag-name.src.js.shot @@ -2,8 +2,8 @@ exports[`jsx invalid-mismatched-dot-tag-name.src 1`] = ` TSError { - "column": 7, - "index": 7, + "column": 9, + "index": 9, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a.b.c'.", } diff --git a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-namespace-tag.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-namespace-tag.src.js.shot index 1dd65c52105..4e5bac634b9 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-namespace-tag.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-namespace-tag.src.js.shot @@ -2,8 +2,8 @@ exports[`jsx invalid-mismatched-namespace-tag.src 1`] = ` TSError { - "column": 5, - "index": 5, + "column": 7, + "index": 7, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a:b'.", } diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/class-static-blocks.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/class-static-blocks.src.ts.shot new file mode 100644 index 00000000000..e370e9e24ea --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/class-static-blocks.src.ts.shot @@ -0,0 +1,702 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript basics class-static-blocks.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "count", + "range": Array [ + 21, + 26, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "override": false, + "range": Array [ + 14, + 31, + ], + "readonly": undefined, + "static": true, + "type": "ClassProperty", + "value": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 30, + ], + "raw": "0", + "type": "Literal", + "value": 0, + }, + }, + Object { + "body": Array [ + Object { + "alternate": null, + "consequent": Object { + "body": Array [ + Object { + "expression": Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": "count", + "range": Array [ + 76, + 81, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "operator": "++", + "prefix": false, + "range": Array [ + 76, + 83, + ], + "type": "UpdateExpression", + }, + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "range": Array [ + 76, + 84, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 25, + "line": 4, + }, + }, + "range": Array [ + 68, + 90, + ], + "type": "BlockStatement", + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "range": Array [ + 47, + 90, + ], + "test": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "name": "someCondition", + "range": Array [ + 51, + 64, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "optional": false, + "range": Array [ + 51, + 66, + ], + "type": "CallExpression", + }, + "type": "IfStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 34, + 94, + ], + "type": "StaticBlock", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 96, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 96, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 97, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 20, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 26, + ], + "type": "Identifier", + "value": "count", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 30, + ], + "type": "Numeric", + "value": "0", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 31, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 34, + 40, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "range": Array [ + 47, + 49, + ], + "type": "Keyword", + "value": "if", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 7, + "line": 4, + }, + }, + "range": Array [ + 50, + 51, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "range": Array [ + 51, + 64, + ], + "type": "Identifier", + "value": "someCondition", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 4, + }, + "start": Object { + "column": 21, + "line": 4, + }, + }, + "range": Array [ + 64, + 65, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 22, + "line": 4, + }, + }, + "range": Array [ + 65, + 66, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 4, + }, + "start": Object { + "column": 23, + "line": 4, + }, + }, + "range": Array [ + 66, + 67, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 4, + }, + "start": Object { + "column": 25, + "line": 4, + }, + }, + "range": Array [ + 68, + 69, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "range": Array [ + 76, + 81, + ], + "type": "Identifier", + "value": "count", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 11, + "line": 5, + }, + }, + "range": Array [ + 81, + 83, + ], + "type": "Punctuator", + "value": "++", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "range": Array [ + 83, + 84, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 89, + 90, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, + }, + }, + "range": Array [ + 93, + 94, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 8, + }, + }, + "range": Array [ + 95, + 96, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tools/test-utils.ts b/packages/typescript-estree/tools/test-utils.ts index 362560bc08c..c07ab65b831 100644 --- a/packages/typescript-estree/tools/test-utils.ts +++ b/packages/typescript-estree/tools/test-utils.ts @@ -41,7 +41,7 @@ export function createSnapshotTestBlock( * AST_NODE_TYPE, we rethrow to cause the test to fail */ if (/Unknown AST_NODE_TYPE/.exec((error as Error).message)) { - throw new Error(error); + throw error; } expect(parse).toThrowErrorMatchingSnapshot(); } diff --git a/packages/visitor-keys/src/visitor-keys.ts b/packages/visitor-keys/src/visitor-keys.ts index 1f2363e948e..63dcdaf5a95 100644 --- a/packages/visitor-keys/src/visitor-keys.ts +++ b/packages/visitor-keys/src/visitor-keys.ts @@ -50,6 +50,7 @@ const additionalKeys: AdditionalKeys = { ObjectPattern: ['decorators', 'properties', 'typeAnnotation'], RestElement: ['decorators', 'argument', 'typeAnnotation'], TaggedTemplateExpression: ['tag', 'typeParameters', 'quasi'], + StaticBlock: [], // JSX JSXOpeningElement: ['name', 'typeParameters', 'attributes'], diff --git a/yarn.lock b/yarn.lock index 95a2b43532c..0b88e0d193b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9483,10 +9483,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@*, typescript@4.3.5, "typescript@>=3.3.1 <4.4.0", typescript@^4.1.0-dev.20201026, typescript@~4.3.5: - version "4.3.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== +typescript@*, typescript@4.4.2, "typescript@>=3.3.1 <4.5.0", typescript@^4.1.0-dev.20201026, typescript@~4.3.5: + version "4.4.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86" + integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ== uc.micro@^1.0.1, uc.micro@^1.0.5: version "1.0.6"