Skip to content
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

fix(parser): allow to visit typeParameters in OptionalCallExpression #1377

Merged
merged 1 commit into from Dec 24, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 99 additions & 0 deletions packages/parser/tests/lib/__snapshots__/typescript.ts.snap
Expand Up @@ -40807,6 +40807,105 @@ Object {
}
`;

exports[`typescript fixtures/expressions/optional-call-expression-type-arguments.src 1`] = `
Object {
"$id": 3,
"block": Object {
"range": Array [
0,
35,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 2,
"block": Object {
"range": Array [
0,
35,
],
"type": "Program",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [
Object {
"$id": 0,
"from": Object {
"$ref": 2,
},
"identifier": Object {
"name": "foo",
"range": Array [
0,
3,
],
"type": "Identifier",
},
"kind": "r",
"resolved": null,
"writeExpr": undefined,
},
Object {
"$id": 1,
"from": Object {
"$ref": 2,
},
"identifier": Object {
"name": "foo",
"range": Array [
15,
18,
],
"type": "Identifier",
},
"kind": "r",
"resolved": null,
"writeExpr": undefined,
},
],
"throughReferences": Array [
Object {
"$ref": 0,
},
Object {
"$ref": 1,
},
],
"type": "module",
"upperScope": Object {
"$ref": 3,
},
"variableMap": Object {},
"variableScope": Object {
"$ref": 2,
},
"variables": Array [],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [
Object {
"$ref": 0,
},
Object {
"$ref": 1,
},
],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [],
}
`;

exports[`typescript fixtures/expressions/tagged-template-expression-type-arguments.src 1`] = `
Object {
"$id": 2,
Expand Down
@@ -0,0 +1,2 @@
foo?.bar<A>();
foo?.bar<number>();
armano2 marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -12,7 +12,7 @@ const log = debug('typescript-eslint:typescript-estree:createDefaultProgram');

/**
* @param code The code of the file being linted
* @param options The config object
* @param extra The config object
* @param extra.tsconfigRootDir The root directory for relative tsconfig paths
* @param extra.projects Provided tsconfig paths
* @returns If found, returns the source file corresponding to the code and the containing program
Expand Down
6 changes: 3 additions & 3 deletions packages/typescript-estree/src/parser.ts
Expand Up @@ -51,8 +51,8 @@ interface ASTAndProgram {

/**
* @param code The code of the file being linted
* @param options The config object
* @param shouldProvideParserServices True iff the program should be attempted to be calculated from provided tsconfig files
* @param shouldProvideParserServices True if the program should be attempted to be calculated from provided tsconfig files
* @param shouldCreateDefaultProgram True if the program should be created from compiler host
* @returns Returns a source file and program corresponding to the linted code
*/
function getProgramAndAST(
Expand Down Expand Up @@ -366,7 +366,7 @@ function parseAndGenerateServices<T extends TSESTreeOptions = TSESTreeOptions>(
)!;

/**
* Determine whether or not two-way maps of converted AST nodes should be preserved
* Determine whatever or not two-way maps of converted AST nodes should be preserved
Copy link

Choose a reason for hiding this comment

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

wasn't this correct?
Sounds strange now 🤔

Copy link
Member Author

@armano2 armano2 Dec 30, 2019

Choose a reason for hiding this comment

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

@BO41 hmm, you might be right, "whatever or not" seems weird

The addition of the "or not" is neither logically nor grammatically required. I think it's often used conversationally for emphasis. I definitely wouldn't use it in writing myself.
https://english.stackexchange.com/questions/3382/whether-or-not-vs-whether


—used as a function word usually with correlative or or with or whether to indicate (1) until the early 19th century a direct question involving alternatives; (2) an indirect question involving stated or implied alternatives
https://www.merriam-webster.com/dictionary/whether


Q: When you use “whether,” do you need “or not”? I find “whether” being used alone for “if,” and I wonder what is correct.

A: In the phrase “whether or not,” the “or not” is often optional. When the choice is up to you, you can generally use either “whether” or “if.”


i think it will be safer to change it to

Suggested change
* Determine whatever or not two-way maps of converted AST nodes should be preserved
* Determine if two-way maps of converted AST nodes should be preserved

what do you think? i'm not that good at grammar

Copy link

Choose a reason for hiding this comment

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

just the "if" sounds good 👍
Or just "whether" (not "whatever" ;)

* during the conversion process
*/
const shouldPreserveNodeMaps =
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/visitor-keys.ts
Expand Up @@ -43,7 +43,7 @@ export const visitorKeys = eslintVisitorKeys.unionWith({
BigIntLiteral: [],
ClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'],
Decorator: ['expression'],
OptionalCallExpression: eslintVisitorKeys.KEYS.CallExpression,
armano2 marked this conversation as resolved.
Show resolved Hide resolved
OptionalCallExpression: ['callee', 'typeParameters', 'arguments'],
OptionalMemberExpression: eslintVisitorKeys.KEYS.MemberExpression,
TSAbstractClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'],
TSAbstractKeyword: [],
Expand Down
Expand Up @@ -2502,6 +2502,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/expressions/new-expression-type-arguments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/expressions/optional-call-expression-type-arguments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/expressions/tagged-template-expression-type-arguments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/namespaces-and-modules/ambient-module-declaration-with-import.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down