Content-Length: 25099 | pFad | http://github.com/typescript-eslint/typescript-eslint/pull/11299.patch

thub.com From dd117a81f879b33256926cffdd0ebb5a961897f8 Mon Sep 17 00:00:00 2001 From: ntdiary <2471314@gmail.com> Date: Thu, 12 Jun 2025 21:22:34 +0800 Subject: [PATCH 1/2] align constructor literal with eslint --- packages/typescript-estree/src/convert.ts | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 8f293db2af02..f2a504aa4a1d 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1695,14 +1695,24 @@ export class Converter { this.fixParentLocation(constructor, constructor.typeParameters.range); } - const constructorKey = this.createNode(node, { - type: AST_NODE_TYPES.Identifier, - range: [constructorToken.getStart(this.ast), constructorToken.end], - decorators: [], - name: 'constructor', - optional: false, - typeAnnotation: undefined, - }); + const constructorKey = + constructorToken.kind === SyntaxKind.StringLiteral + ? this.createNode(constructorToken, { + type: AST_NODE_TYPES.Literal, + raw: constructorToken.getText(), + value: 'constructor', + }) + : this.createNode(node, { + type: AST_NODE_TYPES.Identifier, + range: [ + constructorToken.getStart(this.ast), + constructorToken.end, + ], + decorators: [], + name: 'constructor', + optional: false, + typeAnnotation: undefined, + }); const isStatic = hasModifier(SyntaxKind.StaticKeyword, node); From 5868bef0b59766babcfcbe1e77f98141a115857a Mon Sep 17 00:00:00 2001 From: ntdiary <2471314@gmail.com> Date: Mon, 16 Jun 2025 16:22:59 +0800 Subject: [PATCH 2/2] add fixtures for constructor --- .../constructor-string-literal/fixture.ts | 4 + .../snapshots/1-TSESTree-AST.shot | 100 +++++++++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 92 ++++++++++++++++ .../snapshots/3-Babel-AST.shot | 100 +++++++++++++++++ .../snapshots/4-Babel-Tokens.shot | 92 ++++++++++++++++ .../fixtures/constructor/fixture.ts | 3 + .../constructor/snapshots/1-TSESTree-AST.shot | 101 ++++++++++++++++++ .../snapshots/2-TSESTree-Tokens.shot | 92 ++++++++++++++++ .../constructor/snapshots/3-Babel-AST.shot | 101 ++++++++++++++++++ .../constructor/snapshots/4-Babel-Tokens.shot | 92 ++++++++++++++++ 10 files changed, 777 insertions(+) create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/fixture.ts create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/1-TSESTree-AST.shot create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/2-TSESTree-Tokens.shot create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/3-Babel-AST.shot create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/4-Babel-Tokens.shot create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/fixture.ts create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/1-TSESTree-AST.shot create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/2-TSESTree-Tokens.shot create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/3-Babel-AST.shot create mode 100644 packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/4-Babel-Tokens.shot diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/fixture.ts b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/fixture.ts new file mode 100644 index 000000000000..4c180fec4267 --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/fixture.ts @@ -0,0 +1,4 @@ +class Foo { + // prettier-ignore + "constructor"() {} +} diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..c67c432e3f4e --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,100 @@ +Program { + type: "Program", + body: [ + ClassDeclaration { + type: "ClassDeclaration", + abstract: false, + body: ClassBody { + type: "ClassBody", + body: [ + MethodDefinition { + type: "MethodDefinition", + computed: false, + decorators: [], + key: Literal { + type: "Literal", + raw: ""constructor"", + value: "constructor", + + range: [35, 48], + loc: { + start: { column: 2, line: 3 }, + end: { column: 15, line: 3 }, + }, + }, + kind: "constructor", + optional: false, + override: false, + static: false, + value: FunctionExpression { + type: "FunctionExpression", + async: false, + body: BlockStatement { + type: "BlockStatement", + body: [], + + range: [51, 53], + loc: { + start: { column: 18, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + declare: false, + expression: false, + generator: false, + id: null, + params: [], + + range: [48, 53], + loc: { + start: { column: 15, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + + range: [35, 53], + loc: { + start: { column: 2, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + ], + + range: [10, 55], + loc: { + start: { column: 10, line: 1 }, + end: { column: 1, line: 4 }, + }, + }, + declare: false, + decorators: [], + id: Identifier { + type: "Identifier", + decorators: [], + name: "Foo", + optional: false, + + range: [6, 9], + loc: { + start: { column: 6, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + implements: [], + superClass: null, + + range: [0, 55], + loc: { + start: { column: 0, line: 1 }, + end: { column: 1, line: 4 }, + }, + }, + ], + sourceType: "script", + + range: [0, 56], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 5 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..d7b945f9e519 --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,92 @@ +[ + Keyword { + type: "Keyword", + value: "class", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "Foo", + + range: [6, 9], + loc: { + start: { column: 6, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + String { + type: "String", + value: ""constructor"", + + range: [35, 48], + loc: { + start: { column: 2, line: 3 }, + end: { column: 15, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [48, 49], + loc: { + start: { column: 15, line: 3 }, + end: { column: 16, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [49, 50], + loc: { + start: { column: 16, line: 3 }, + end: { column: 17, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [51, 52], + loc: { + start: { column: 18, line: 3 }, + end: { column: 19, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [52, 53], + loc: { + start: { column: 19, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [54, 55], + loc: { + start: { column: 0, line: 4 }, + end: { column: 1, line: 4 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..c67c432e3f4e --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/3-Babel-AST.shot @@ -0,0 +1,100 @@ +Program { + type: "Program", + body: [ + ClassDeclaration { + type: "ClassDeclaration", + abstract: false, + body: ClassBody { + type: "ClassBody", + body: [ + MethodDefinition { + type: "MethodDefinition", + computed: false, + decorators: [], + key: Literal { + type: "Literal", + raw: ""constructor"", + value: "constructor", + + range: [35, 48], + loc: { + start: { column: 2, line: 3 }, + end: { column: 15, line: 3 }, + }, + }, + kind: "constructor", + optional: false, + override: false, + static: false, + value: FunctionExpression { + type: "FunctionExpression", + async: false, + body: BlockStatement { + type: "BlockStatement", + body: [], + + range: [51, 53], + loc: { + start: { column: 18, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + declare: false, + expression: false, + generator: false, + id: null, + params: [], + + range: [48, 53], + loc: { + start: { column: 15, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + + range: [35, 53], + loc: { + start: { column: 2, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + ], + + range: [10, 55], + loc: { + start: { column: 10, line: 1 }, + end: { column: 1, line: 4 }, + }, + }, + declare: false, + decorators: [], + id: Identifier { + type: "Identifier", + decorators: [], + name: "Foo", + optional: false, + + range: [6, 9], + loc: { + start: { column: 6, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + implements: [], + superClass: null, + + range: [0, 55], + loc: { + start: { column: 0, line: 1 }, + end: { column: 1, line: 4 }, + }, + }, + ], + sourceType: "script", + + range: [0, 56], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 5 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..d7b945f9e519 --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor-string-literal/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,92 @@ +[ + Keyword { + type: "Keyword", + value: "class", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "Foo", + + range: [6, 9], + loc: { + start: { column: 6, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + String { + type: "String", + value: ""constructor"", + + range: [35, 48], + loc: { + start: { column: 2, line: 3 }, + end: { column: 15, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [48, 49], + loc: { + start: { column: 15, line: 3 }, + end: { column: 16, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [49, 50], + loc: { + start: { column: 16, line: 3 }, + end: { column: 17, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [51, 52], + loc: { + start: { column: 18, line: 3 }, + end: { column: 19, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [52, 53], + loc: { + start: { column: 19, line: 3 }, + end: { column: 20, line: 3 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [54, 55], + loc: { + start: { column: 0, line: 4 }, + end: { column: 1, line: 4 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/fixture.ts b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/fixture.ts new file mode 100644 index 000000000000..5e9e3c9272a2 --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/fixture.ts @@ -0,0 +1,3 @@ +class Foo { + constructor() {} +} diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/1-TSESTree-AST.shot new file mode 100644 index 000000000000..3eef72dde2c6 --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/1-TSESTree-AST.shot @@ -0,0 +1,101 @@ +Program { + type: "Program", + body: [ + ClassDeclaration { + type: "ClassDeclaration", + abstract: false, + body: ClassBody { + type: "ClassBody", + body: [ + MethodDefinition { + type: "MethodDefinition", + computed: false, + decorators: [], + key: Identifier { + type: "Identifier", + decorators: [], + name: "constructor", + optional: false, + + range: [14, 25], + loc: { + start: { column: 2, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + kind: "constructor", + optional: false, + override: false, + static: false, + value: FunctionExpression { + type: "FunctionExpression", + async: false, + body: BlockStatement { + type: "BlockStatement", + body: [], + + range: [28, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + declare: false, + expression: false, + generator: false, + id: null, + params: [], + + range: [25, 30], + loc: { + start: { column: 13, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + + range: [14, 30], + loc: { + start: { column: 2, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + ], + + range: [10, 32], + loc: { + start: { column: 10, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + declare: false, + decorators: [], + id: Identifier { + type: "Identifier", + decorators: [], + name: "Foo", + optional: false, + + range: [6, 9], + loc: { + start: { column: 6, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + implements: [], + superClass: null, + + range: [0, 32], + loc: { + start: { column: 0, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 33], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/2-TSESTree-Tokens.shot new file mode 100644 index 000000000000..dae0e3eb6ca1 --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/2-TSESTree-Tokens.shot @@ -0,0 +1,92 @@ +[ + Keyword { + type: "Keyword", + value: "class", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "Foo", + + range: [6, 9], + loc: { + start: { column: 6, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "constructor", + + range: [14, 25], + loc: { + start: { column: 2, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [25, 26], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [26, 27], + loc: { + start: { column: 14, line: 2 }, + end: { column: 15, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [28, 29], + loc: { + start: { column: 16, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [29, 30], + loc: { + start: { column: 17, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [31, 32], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, +] \ No newline at end of file diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/3-Babel-AST.shot new file mode 100644 index 000000000000..3eef72dde2c6 --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/3-Babel-AST.shot @@ -0,0 +1,101 @@ +Program { + type: "Program", + body: [ + ClassDeclaration { + type: "ClassDeclaration", + abstract: false, + body: ClassBody { + type: "ClassBody", + body: [ + MethodDefinition { + type: "MethodDefinition", + computed: false, + decorators: [], + key: Identifier { + type: "Identifier", + decorators: [], + name: "constructor", + optional: false, + + range: [14, 25], + loc: { + start: { column: 2, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + kind: "constructor", + optional: false, + override: false, + static: false, + value: FunctionExpression { + type: "FunctionExpression", + async: false, + body: BlockStatement { + type: "BlockStatement", + body: [], + + range: [28, 30], + loc: { + start: { column: 16, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + declare: false, + expression: false, + generator: false, + id: null, + params: [], + + range: [25, 30], + loc: { + start: { column: 13, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + + range: [14, 30], + loc: { + start: { column: 2, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + ], + + range: [10, 32], + loc: { + start: { column: 10, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + declare: false, + decorators: [], + id: Identifier { + type: "Identifier", + decorators: [], + name: "Foo", + optional: false, + + range: [6, 9], + loc: { + start: { column: 6, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + implements: [], + superClass: null, + + range: [0, 32], + loc: { + start: { column: 0, line: 1 }, + end: { column: 1, line: 3 }, + }, + }, + ], + sourceType: "script", + + range: [0, 33], + loc: { + start: { column: 0, line: 1 }, + end: { column: 0, line: 4 }, + }, +} \ No newline at end of file diff --git a/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/4-Babel-Tokens.shot new file mode 100644 index 000000000000..dae0e3eb6ca1 --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/fixtures/constructor/snapshots/4-Babel-Tokens.shot @@ -0,0 +1,92 @@ +[ + Keyword { + type: "Keyword", + value: "class", + + range: [0, 5], + loc: { + start: { column: 0, line: 1 }, + end: { column: 5, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "Foo", + + range: [6, 9], + loc: { + start: { column: 6, line: 1 }, + end: { column: 9, line: 1 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [10, 11], + loc: { + start: { column: 10, line: 1 }, + end: { column: 11, line: 1 }, + }, + }, + Identifier { + type: "Identifier", + value: "constructor", + + range: [14, 25], + loc: { + start: { column: 2, line: 2 }, + end: { column: 13, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "(", + + range: [25, 26], + loc: { + start: { column: 13, line: 2 }, + end: { column: 14, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: ")", + + range: [26, 27], + loc: { + start: { column: 14, line: 2 }, + end: { column: 15, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "{", + + range: [28, 29], + loc: { + start: { column: 16, line: 2 }, + end: { column: 17, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [29, 30], + loc: { + start: { column: 17, line: 2 }, + end: { column: 18, line: 2 }, + }, + }, + Punctuator { + type: "Punctuator", + value: "}", + + range: [31, 32], + loc: { + start: { column: 0, line: 3 }, + end: { column: 1, line: 3 }, + }, + }, +] \ No newline at end of file








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/typescript-eslint/typescript-eslint/pull/11299.patch

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy