Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(typescript-estree): useTSEmptyBodyFunctionExpression for body-less nodes#1289

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 4 commits intotypescript-eslint:v3fromG-Rath:parse-FunctionExpression-nodes-with-no-body-as-TSEmptyBodyFunctionExpression
May 10, 2020
Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1115,7 +1115,7 @@ export default createRule<Options, MessageIds>({
'FunctionDeclaration, FunctionExpression'(
node:TSESTree.FunctionDeclaration|TSESTree.FunctionExpression,
){
constclosingParen=sourceCode.getTokenBefore(node.body!)!;
constclosingParen=sourceCode.getTokenBefore(node.body)!;
constopeningParen=sourceCode.getTokenBefore(
node.params.length ?node.params[0] :closingParen,
)!;
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -326,7 +326,10 @@ export default util.createRule({
},
// object pattern props are checked via assignments
':not(ObjectPattern) > Property'(node:TSESTree.Property):void{
if(node.value.type===AST_NODE_TYPES.AssignmentPattern){
if(
node.value.type===AST_NODE_TYPES.AssignmentPattern||
node.value.type===AST_NODE_TYPES.TSEmptyBodyFunctionExpression
){
// handled by other selector
return;
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,7 +62,7 @@ function getReporLoc(
)!.loc.end;
}

returnsourceCode.getTokenBefore(node.body!)!.loc.end;
returnsourceCode.getTokenBefore(node.body)!.loc.end;
}

return{
Expand Down
16 changes: 0 additions & 16 deletionspackages/parser/src/parser.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,6 @@ import {
ParserServices,
TSESTreeOptions,
TSESTree,
simpleTraverse,
visitorKeys,
}from'@typescript-eslint/typescript-estree';
import{analyzeScope}from'./analyze-scope';
Expand DownExpand Up@@ -95,21 +94,6 @@ export function parseForESLint(
const{ ast, services}=parseAndGenerateServices(code,parserOptions);
ast.sourceType=options.sourceType;

simpleTraverse(ast,{
enter(node){
switch(node.type){
// Function#body cannot be null in ESTree spec.
caseAST_NODE_TYPES.FunctionExpression:
if(!node.body){
// eslint-disable-next-line @typescript-eslint/no-explicit-any
node.type=`TSEmptyBody${node.type}`asany;
}
break;
// no default
}
},
});

constscopeManager=analyzeScope(ast,options);
return{ ast, services, scopeManager, visitorKeys};
}
Expand Down
20 changes: 14 additions & 6 deletionspackages/typescript-estree/src/convert.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,16 +18,16 @@ import {
isComputedProperty,
isESTreeClassMember,
isOptional,
unescapeStringLiteralText,
TSError,
unescapeStringLiteralText,
} from './node-utils';
import { ParserWeakMap, ParserWeakMapESTreeToTSNode } from './parser-options';
import {
AST_NODE_TYPES,
TSESTree,
TSNode,
TSESTreeToTSNode,
} from './ts-estree';
import { ParserWeakMap, ParserWeakMapESTreeToTSNode } from './parser-options';

const SyntaxKind = ts.SyntaxKind;

Expand DownExpand Up@@ -995,8 +995,12 @@ export class Converter {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.MethodDeclaration: {
const method = this.createNode<TSESTree.FunctionExpression>(node, {
type: AST_NODE_TYPES.FunctionExpression,
const method = this.createNode<
TSESTree.TSEmptyBodyFunctionExpression | TSESTree.FunctionExpression
>(node, {
type: !node.body
? AST_NODE_TYPES.TSEmptyBodyFunctionExpression
: AST_NODE_TYPES.FunctionExpression,
id: null,
generator: !!node.asteriskToken,
expression: false, // ESTreeNode as ESTreeNode here
Expand DownExpand Up@@ -1105,8 +1109,12 @@ export class Converter {
(lastModifier && findNextToken(lastModifier, node, this.ast)) ||
node.getFirstToken()!;

const constructor = this.createNode<TSESTree.FunctionExpression>(node, {
type: AST_NODE_TYPES.FunctionExpression,
const constructor = this.createNode<
TSESTree.TSEmptyBodyFunctionExpression | TSESTree.FunctionExpression
>(node, {
type: !node.body
? AST_NODE_TYPES.TSEmptyBodyFunctionExpression
: AST_NODE_TYPES.FunctionExpression,
id: null,
params: this.convertParameters(node.parameters),
generator: false,
Expand Down
7 changes: 6 additions & 1 deletionpackages/typescript-estree/src/ts-estree/ts-estree.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,7 +674,11 @@ interface MethodDefinitionNonComputedNameBase extends MethodDefinitionBase {
interface PropertyBase extends BaseNode {
type: AST_NODE_TYPES.Property;
key: PropertyName;
value: Expression | AssignmentPattern | BindingName;
value:
| Expression
| AssignmentPattern
| BindingName
| TSEmptyBodyFunctionExpression;
computed: boolean;
method: boolean;
shorthand: boolean;
Expand DownExpand Up@@ -927,6 +931,7 @@ export interface FunctionDeclaration extends FunctionDeclarationBase {

export interface FunctionExpression extends FunctionDeclarationBase {
type: AST_NODE_TYPES.FunctionExpression;
body: BlockStatement;
}

export interface Identifier extends BaseNode {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -768,7 +768,7 @@ Object {
63,
66,
],
"type": "FunctionExpression",
"type": "TSEmptyBodyFunctionExpression",
},
},
],
Expand DownExpand Up@@ -1216,7 +1216,7 @@ Object {
},
},
},
"type": "FunctionExpression",
"type": "TSEmptyBodyFunctionExpression",
},
},
],
Expand DownExpand Up@@ -2433,7 +2433,7 @@ Object {
68,
71,
],
"type": "FunctionExpression",
"type": "TSEmptyBodyFunctionExpression",
},
},
],
Expand DownExpand Up@@ -4034,7 +4034,7 @@ Object {
},
},
},
"type": "FunctionExpression",
"type": "TSEmptyBodyFunctionExpression",
},
},
],
Expand DownExpand Up@@ -24208,7 +24208,7 @@ Object {
18,
21,
],
"type": "FunctionExpression",
"type": "TSEmptyBodyFunctionExpression",
},
},
Object {
Expand DownExpand Up@@ -24304,7 +24304,7 @@ Object {
"type": "TSStringKeyword",
},
},
"type": "FunctionExpression",
"type": "TSEmptyBodyFunctionExpression",
},
},
Object {
Expand DownExpand Up@@ -24401,7 +24401,7 @@ Object {
"type": "TSStringKeyword",
},
},
"type": "FunctionExpression",
"type": "TSEmptyBodyFunctionExpression",
},
},
],
Expand DownExpand Up@@ -38261,7 +38261,7 @@ Object {
"type": "TSAnyKeyword",
},
},
"type": "FunctionExpression",
"type": "TSEmptyBodyFunctionExpression",
},
},
],
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp