Skip to content

Commit

Permalink
update other packages appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Jul 19, 2020
1 parent 56e3fd3 commit f31b792
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 72 deletions.
Expand Up @@ -37,7 +37,6 @@ const getFunctionNameWithKind = eslintUtils.getFunctionNameWithKind as (
const getPropertyName = eslintUtils.getPropertyName as (
node:
| TSESTree.MemberExpression
| TSESTree.OptionalMemberExpression
| TSESTree.Property
| TSESTree.MethodDefinition,
initialScope?: TSESLint.Scope.Scope,
Expand Down
18 changes: 4 additions & 14 deletions packages/experimental-utils/src/ast-utils/predicates.ts
Expand Up @@ -25,11 +25,11 @@ function isNotNonNullAssertionPunctuator(
/**
* Returns true if and only if the node represents: foo?.() or foo.bar?.()
*/
function isOptionalOptionalCallExpression(
function isOptionalCallExpression(
node: TSESTree.Node,
): node is TSESTree.OptionalCallExpression & { optional: true } {
): node is TSESTree.CallExpression & { optional: true } {
return (
node.type === AST_NODE_TYPES.OptionalCallExpression &&
node.type === AST_NODE_TYPES.CallExpression &&
// this flag means the call expression itself is option
// i.e. it is foo.bar?.() and not foo?.bar()
node.optional
Expand Down Expand Up @@ -214,15 +214,6 @@ function isAwaitKeyword(
return node?.type === AST_TOKEN_TYPES.Identifier && node.value === 'await';
}

function isMemberOrOptionalMemberExpression(
node: TSESTree.Node,
): node is TSESTree.MemberExpression | TSESTree.OptionalMemberExpression {
return (
node.type === AST_NODE_TYPES.MemberExpression ||
node.type === AST_NODE_TYPES.OptionalMemberExpression
);
}

export {
isAwaitExpression,
isAwaitKeyword,
Expand All @@ -233,12 +224,11 @@ export {
isFunctionType,
isIdentifier,
isLogicalOrOperator,
isMemberOrOptionalMemberExpression,
isNonNullAssertionPunctuator,
isNotNonNullAssertionPunctuator,
isNotOptionalChainPunctuator,
isOptionalChainPunctuator,
isOptionalOptionalCallExpression,
isOptionalCallExpression,
isSetter,
isTSConstructorType,
isTSFunctionType,
Expand Down
3 changes: 1 addition & 2 deletions packages/experimental-utils/src/ts-eslint/Rule.ts
Expand Up @@ -258,6 +258,7 @@ interface RuleListener {
BreakStatement?: RuleFunction<TSESTree.BreakStatement>;
CallExpression?: RuleFunction<TSESTree.CallExpression>;
CatchClause?: RuleFunction<TSESTree.CatchClause>;
ChainExpression?: RuleFunction<TSESTree.ChainExpression>;
ClassBody?: RuleFunction<TSESTree.ClassBody>;
ClassDeclaration?: RuleFunction<TSESTree.ClassDeclaration>;
ClassExpression?: RuleFunction<TSESTree.ClassExpression>;
Expand Down Expand Up @@ -309,8 +310,6 @@ interface RuleListener {
NewExpression?: RuleFunction<TSESTree.NewExpression>;
ObjectExpression?: RuleFunction<TSESTree.ObjectExpression>;
ObjectPattern?: RuleFunction<TSESTree.ObjectPattern>;
OptionalCallExpression?: RuleFunction<TSESTree.OptionalCallExpression>;
OptionalMemberExpression?: RuleFunction<TSESTree.OptionalMemberExpression>;
Program?: RuleFunction<TSESTree.Program>;
Property?: RuleFunction<TSESTree.Property>;
RestElement?: RuleFunction<TSESTree.RestElement>;
Expand Down
23 changes: 0 additions & 23 deletions packages/parser/src/analyze-scope.ts
Expand Up @@ -341,29 +341,6 @@ class Referencer extends TSESLintScope.Referencer<ScopeManager> {
node.arguments.forEach(this.visit, this);
}

/**
* Visit optional member expression.
* @param node The OptionalMemberExpression node to visit.
*/
OptionalMemberExpression(node: TSESTree.OptionalMemberExpression): void {
this.visit(node.object);
if (node.computed) {
this.visit(node.property);
}
}

/**
* Visit optional call expression.
* @param node The OptionalMemberExpression node to visit.
*/
OptionalCallExpression(node: TSESTree.OptionalCallExpression): void {
this.visitTypeParameters(node);

this.visit(node.callee);

node.arguments.forEach(this.visit, this);
}

/**
* Define the variable of this function declaration only once.
* Because to avoid confusion of `no-redeclare` rule by overloading.
Expand Down
42 changes: 34 additions & 8 deletions packages/parser/tests/lib/__snapshots__/typescript.ts.snap
Expand Up @@ -17623,7 +17623,7 @@ Object {

exports[`typescript fixtures/basics/export-star-as-ns-from.src 1`] = `
Object {
"$id": 1,
"$id": 2,
"block": Object {
"range": Array [
0,
Expand All @@ -17633,7 +17633,7 @@ Object {
},
"childScopes": Array [
Object {
"$id": 0,
"$id": 1,
"block": Object {
"range": Array [
0,
Expand All @@ -17644,28 +17644,54 @@ Object {
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [],
"references": Array [
Object {
"$id": 0,
"from": Object {
"$ref": 1,
},
"identifier": Object {
"name": "foo",
"range": Array [
12,
15,
],
"type": "Identifier",
},
"kind": "r",
"resolved": null,
"writeExpr": undefined,
},
],
"throughReferences": Array [
Object {
"$ref": 0,
},
],
"type": "module",
"upperScope": Object {
"$ref": 1,
"$ref": 2,
},
"variableMap": Object {},
"variableScope": Object {
"$ref": 0,
"$ref": 1,
},
"variables": Array [],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [],
"throughReferences": Array [
Object {
"$ref": 0,
},
],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 1,
"$ref": 2,
},
"variables": Array [],
}
Expand Down
20 changes: 2 additions & 18 deletions packages/scope-manager/src/referencer/Referencer.ts
Expand Up @@ -377,9 +377,7 @@ class Referencer extends Visitor {
// don't reference the break statement's label
}

protected CallExpression(
node: TSESTree.CallExpression | TSESTree.OptionalCallExpression,
): void {
protected CallExpression(node: TSESTree.CallExpression): void {
this.visitChildren(node, ['typeParameters']);
this.visitType(node.typeParameters);
}
Expand Down Expand Up @@ -498,9 +496,7 @@ class Referencer extends Visitor {
this.visit(node.body);
}

protected MemberExpression(
node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression,
): void {
protected MemberExpression(node: TSESTree.MemberExpression): void {
this.visit(node.object);
if (node.computed) {
this.visit(node.property);
Expand All @@ -520,18 +516,6 @@ class Referencer extends Visitor {
this.visitType(node.typeParameters);
}

protected OptionalCallExpression(
node: TSESTree.OptionalCallExpression,
): void {
this.CallExpression(node);
}

protected OptionalMemberExpression(
node: TSESTree.OptionalMemberExpression,
): void {
this.MemberExpression(node);
}

protected Program(node: TSESTree.Program): void {
const globalScope = this.scopeManager.nestGlobalScope(node);
this.populateGlobalsFromLib(globalScope);
Expand Down
6 changes: 2 additions & 4 deletions packages/visitor-keys/package.json
Expand Up @@ -36,10 +36,8 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"eslint-visitor-keys": "^1.1.0"
},
"devDependencies": {
"@typescript-eslint/types": "3.6.1"
"@typescript-eslint/types": "3.6.1",
"eslint-visitor-keys": "^1.3.0"
},
"funding": {
"type": "opencollective",
Expand Down
6 changes: 6 additions & 0 deletions packages/visitor-keys/src/get-keys.ts
@@ -0,0 +1,6 @@
import { TSESTree } from '@typescript-eslint/types';
import { getKeys as getKeysOriginal } from 'eslint-visitor-keys';

const getKeys: (node: TSESTree.Node) => ReadonlyArray<string> = getKeysOriginal;

export { getKeys };
1 change: 1 addition & 0 deletions packages/visitor-keys/src/index.ts
@@ -1 +1,2 @@
export { getKeys } from './get-keys';
export { visitorKeys, VisitorKeys } from './visitor-keys';
2 changes: 0 additions & 2 deletions packages/visitor-keys/src/visitor-keys.ts
Expand Up @@ -48,8 +48,6 @@ const visitorKeys: VisitorKeys = eslintVisitorKeys.unionWith({
// Additional Nodes.
ClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'],
Decorator: ['expression'],
OptionalCallExpression: ['callee', 'typeParameters', 'arguments'],
OptionalMemberExpression: eslintVisitorKeys.KEYS.MemberExpression,
TSAbstractClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'],
TSAbstractKeyword: [],
TSAbstractMethodDefinition: ['key', 'value'],
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -3667,6 +3667,11 @@ eslint-visitor-keys@^1.2.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.2.0.tgz#74415ac884874495f78ec2a97349525344c981fa"
integrity sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ==

eslint-visitor-keys@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==

eslint@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.2.0.tgz#d41b2e47804b30dbabb093a967fb283d560082e6"
Expand Down

0 comments on commit f31b792

Please sign in to comment.