-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Support Parsing Nullish Coalescing, Optional Chaining and Assertion Functions (TS 3.7) #1033
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
Comments
@c-bandy Thanks for the report. Also,
cc @bradzacher |
@a-tarasyuk I'm aware it's not officially supported. It seemed like it was at least partially supported because I could get optional chaining ( |
@c-bandy
Based on the release notes, optional chaining? was implemented in |
3.7.0-beta includes both I am haply using both of these features with typescript 3.7.0-beta, except that eslint and other tools that use typescript-estree are giving errors when they run into I understand it not being implemented yet - its a new feature after all. I'll be subscribing to this issue to track happenings, Thanks for a great tool. |
@a-tarasyuk That's how I knew about it to begin with, I was just surprised optional chaining worked out of the box |
My dudes! You're too quick! The beta was only released yesterday. We'll ofc be adding support for it. Because it's new syntax, we'll have to build in support to the parser for it, and also build support into the rules for it. Optional chaining probably emits an extra prop onto an existing node - hence it's "supported" (note that it's not actually supported, it just doesn't throw an error). I'll have a look at adding support to the parser for this tonight. Thinking about it, it'll probably be a larger piece of work to add support for this across all of the rules, but at least I can stop the parser barfing for you. Pinning this issue to try and make sure that nobody else posts 3.7-beta issues... |
uhhh - I don't actually know. It parses fine using our parser. |
I used a local version of astexplorer to test this with typescript@beta. Optional chaining: x?.concat([]); TS provides the following AST{
"pos": 0,
"end": 15,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"kind": 288,
"text": "x?.concat([]);\n",
"bindDiagnostics": [],
"languageVersion": 99,
"fileName": "astExplorer.tsx",
"languageVariant": 1,
"isDeclarationFile": false,
"scriptKind": 4,
"pragmas": {},
"referencedFiles": [],
"typeReferenceDirectives": [],
"libReferenceDirectives": [],
"amdDependencies": [],
"hasNoDefaultLib": false,
"statements": [
{
"pos": 0,
"end": 14,
"flags": 0,
"modifierFlagsCache": 536870912,
"transformFlags": 0,
"parent": "[Circular ~]",
"kind": 225,
"expression": {
"pos": 0,
"end": 13,
"flags": 32,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0]",
"kind": 195,
"expression": {
"pos": 0,
"end": 9,
"flags": 32,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.expression]",
"kind": 193, // PropertyAccessExpression
"expression": {
"pos": 0,
"end": 1,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.expression.expression]",
"kind": 75,
"escapedText": "x"
},
//////////// THE NEW "QuestionDotToken" ////////////
"questionDotToken": {
"pos": 1,
"end": 3,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.expression.expression]",
"kind": 28 // QuestionDotToken
},
////////////////////////////////////////////////////
"name": {
"pos": 3,
"end": 9,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.expression.expression]",
"kind": 75,
"escapedText": "concat"
}
},
"arguments": [
{
"pos": 10,
"end": 12,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.expression]",
"kind": 191,
"elements": []
}
]
}
}
],
"endOfFileToken": {
"pos": 14,
"end": 15,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~]",
"kind": 1
},
"nodeCount": 9,
"identifierCount": 2,
"identifiers": {},
"parseDiagnostics": [],
"path": "astExplorer.tsx",
"resolvedPath": "astExplorer.tsx",
"originalFileName": "astExplorer.tsx",
"imports": [],
"moduleAugmentations": [],
"ambientModuleNames": []
} Nullish coalescing x ?? y TS provides the following AST{
"pos": 0,
"end": 8,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"kind": 288,
"text": "x ?? y;\n",
"bindDiagnostics": [],
"languageVersion": 99,
"fileName": "astExplorer.tsx",
"languageVariant": 1,
"isDeclarationFile": false,
"scriptKind": 4,
"pragmas": {},
"referencedFiles": [],
"typeReferenceDirectives": [],
"libReferenceDirectives": [],
"amdDependencies": [],
"hasNoDefaultLib": false,
"statements": [
{
"pos": 0,
"end": 7,
"flags": 0,
"modifierFlagsCache": 536870912,
"transformFlags": 0,
"parent": "[Circular ~]",
"kind": 225,
"expression": {
"pos": 0,
"end": 6,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0]",
"kind": 208, // BinaryExpression
"left": {
"pos": 0,
"end": 1,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.expression]",
"kind": 75,
"escapedText": "x"
},
//////////// THE NEW "QuestionQuestionToken" ////////////
"operatorToken": {
"pos": 1,
"end": 4,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.expression]",
"kind": 60 // QuestionQuestionToken
},
/////////////////////////////////////////////////////////
"right": {
"pos": 4,
"end": 6,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.expression]",
"kind": 75,
"escapedText": "y"
}
}
}
],
"endOfFileToken": {
"pos": 7,
"end": 8,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~]",
"kind": 1
},
"nodeCount": 7,
"identifierCount": 2,
"identifiers": {},
"parseDiagnostics": [],
"path": "astExplorer.tsx",
"resolvedPath": "astExplorer.tsx",
"originalFileName": "astExplorer.tsx",
"imports": [],
"moduleAugmentations": [],
"ambientModuleNames": []
} Assertion function function assert(condition): asserts condition {} TS provides the following AST{
"pos": 0,
"end": 49,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"kind": 288,
"text": "function assert(condition): asserts condition {}\n",
"bindDiagnostics": [],
"languageVersion": 99,
"fileName": "astExplorer.tsx",
"languageVariant": 1,
"isDeclarationFile": false,
"scriptKind": 4,
"pragmas": {},
"referencedFiles": [],
"typeReferenceDirectives": [],
"libReferenceDirectives": [],
"amdDependencies": [],
"hasNoDefaultLib": false,
"statements": [
{
"pos": 0,
"end": 48,
"flags": 0,
"modifierFlagsCache": 536870912,
"transformFlags": 0,
"parent": "[Circular ~]",
"kind": 243,
"name": {
"pos": 8,
"end": 15,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0]",
"kind": 75,
"escapedText": "assert"
},
"parameters": [
{
"pos": 16,
"end": 25,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0]",
"kind": 155,
"name": {
"pos": 16,
"end": 25,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.parameters.0]",
"kind": 75,
"escapedText": "condition"
}
}
],
"type": {
"pos": 27,
"end": 45,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0]",
"kind": 167, // TypePredicate
//////////// THE NEW "AssertsKeyword" ////////////
"assertsModifier": {
"pos": 27,
"end": 35,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.type]",
"kind": 123
},
//////////////////////////////////////////////////
"parameterName": {
"pos": 35,
"end": 45,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0.type]",
"kind": 75,
"escapedText": "condition"
}
},
"body": {
"pos": 45,
"end": 48,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~.statements.0]",
"kind": 222,
"statements": []
}
}
],
"endOfFileToken": {
"pos": 48,
"end": 49,
"flags": 0,
"modifierFlagsCache": 0,
"transformFlags": 0,
"parent": "[Circular ~]",
"kind": 1
},
"nodeCount": 11,
"identifierCount": 4,
"identifiers": {},
"parseDiagnostics": [],
"path": "astExplorer.tsx",
"resolvedPath": "astExplorer.tsx",
"originalFileName": "astExplorer.tsx",
"imports": [],
"moduleAugmentations": [],
"ambientModuleNames": []
} |
Yes, "anti-barfing support" would be fantastic. 😎 Real support is less critical than being able to continue to use existing eslint functionality while this sort of thing gets worked out. Thanks a bunch! |
This is true - I was mostly just looking for a tracking item - apologies for the noise.
This would be fantastic - being able to keep using tools even without direct support would great. |
Official support has been released! Note that there shouldn't have been any parser errors on these, the errors people were getting were because prettier hard errors on things it doesn't support. If you want to track progress in prettier, see |
Which release is this in? |
I've been struggling to get eslint to understand typescript's 3.7 features, especially optional chaining. I have however I get |
If you're looking for support in the rules, see the issues linked in As mentioned in the title, and in the comment above - this issue is specifically about parsing support (i.e. making sure that an AST is produced so that eslint won't crash out on the new syntax). There are a number of issues with some of the base rules due to how eslint works. For everyone: |
A note on the |
The TypeScript 3.7 beta is out.
There should be support to lint code using
typescript-eslint
with the new features in this version: nullish coalescing, optional chaining and assertion functions!This post was changed from it's original state as it's pinned now ❤️
The text was updated successfully, but these errors were encountered: