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

WIP: feat: new ast for typescript 3.8 #1465

Closed
wants to merge 11 commits into from
Closed

WIP: feat: new ast for typescript 3.8 #1465

wants to merge 11 commits into from

Conversation

armano2
Copy link
Member

@armano2 armano2 commented Jan 17, 2020

DO NOT MERGE,

This is branch contains so far only test scenarios for upcoming typescript 3.8.


TODO:

Implemented as draft (AST may change base on tickets above:

  • Private class properties
  • Private class method
  • Export type
    • exportKind: 'type' | 'value'
  • Import type
    • importKind: 'type' | 'value'
  • Export as ns from

Issues:

prettier/prettier#6608
prettier/prettier#7263
import-js/eslint-plugin-import#645
fixes #1436

@armano2 armano2 added DO NOT MERGE PRs which should not be merged yet package: parser Issues related to @typescript-eslint/parser package: typescript-estree Issues related to @typescript-eslint/typescript-estree RFC dependencies Issue about dependencies of the package labels Jan 17, 2020
@armano2 armano2 self-assigned this Jan 17, 2020
@typescript-eslint

This comment has been minimized.

@armano2 armano2 changed the title WIP: feat: first draft of support for typescript 3.8 WIP: feat: typescript 3.8 Jan 17, 2020
@armano2 armano2 changed the title WIP: feat: typescript 3.8 WIP: feat: new ast for typescript 3.8 Jan 17, 2020
@armano2
Copy link
Member Author

armano2 commented Jan 18, 2020

Private class properties in tsx are supported by typescript but so far they are not documented (i'm unsure if this is intended)

i updated PR with links to estree spec proposals

@nicolo-ribaudo
Copy link

There is difference in range for export * as ns between babel and ts

Which is the difference? Is it something that should be fixed in Babel?

Conflicts:
	packages/experimental-utils/package.json
@armano2
Copy link
Member Author

armano2 commented Jan 24, 2020

@nicolo-ribaudo for code

export * as ns from 'x'

babel reports ExportNamespaceSpecifier node at char 7, typescript node NamespaceExport is at char 12

babel: * as ns - astexplorer
typescript: ns - ts-ast-viewer


it looks like typescript returns same range for NamespaceExport and Identifier(ns)
this seems to be an issue in typescript ast, estree/estree#202 (comment) and if it stays as is i will patch it on our side
unless estree/estree#205 is accepted, then we should return ns in ExportAllDeclaration

Conflicts:
	package.json
	packages/typescript-estree/package.json
	yarn.lock
@dsherret
Copy link

FYI that range difference was a bug that is now fixed: microsoft/TypeScript#36762

@NickHeiner
Copy link
Contributor

NickHeiner commented Feb 26, 2020

Is this PR actively being worked on? It looks like there haven't been any commits for a while.

Edit: I'm sorry – I didn't mean to convey a sense of entitlement. I was just looking for context for my own planning purposes.

@bradzacher
Copy link
Member

bradzacher commented Feb 26, 2020

There's a lot of work that needs to happen here.

For import/export type, they are TS specific features, so we are relatively free to implement them. However we need to be sure we're syncing up with babel so that our AST representations match. Both packages are part of one ecosystem, so we need to match up. (babel/babel#11171)

With the 3.7 release, we made the decision to jump the gun on the AST for both nullish coalescing and optional chaining, and used babel's representation. However it looks like the ESTree spec will go with a different representation, which ESLint will then build on top of. So in order to support the ecosystem, we'll have to migrate to that representation via a non-trival amount of work, and a major version bump.
This will cause a headache for any plugins using the current AST, so we want to avoid jumping the gun again.

So for private class fields/methods, and export * as ns, we taking it slow for now, to see what the official spec work is heading toward to minimise this disruption.

There is a lot of volunteers working on this across many projects, so it takes time as they find moments in their free time to work on it.

@NickHeiner
Copy link
Contributor

Thanks for that context. I've updated my original comment to be clear that I don't feel entitled to anything. I appreciate the volunteers.

bors bot added a commit to neo-one-suite/neo-one that referenced this pull request Mar 9, 2020
1984: feat(ts): add TS v3.7/3.8 language features r=spencercorwin a=spencercorwin

### Description of the Change

Upgrades Smart-Contract compiler to support new TS language features:

Features from TS v3.7:
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html
- [x] Optional Chaining
- [x] Nullish Coalescing
  - Added in previous TS PR
- [x] Assertion Functions
  - Not supported?
- [x] `never`-Returning Functions
  - No change needed?
- [x] Recursive Type Aliases
- [x] Uncalled Function Checks
  - Should be supported without change from us?

Features from TS v3.8.1-rc:
https://devblogs.microsoft.com/typescript/announcing-typescript-3-8-rc/
- [x] Type-Only Imports and Exports
- [x] ECMAScript Private Fields
- [x] `export * as ns` Syntax
  - Added in previous TS PR
- [x] Top-Level `await`
  - Not supported?

### Test Plan

- All Unit Tests
  - `rush test`
  - `rush e2e`
- Optional Chaining
  - `rush test -t packages/neo-one-smart-contract-compiler/src/__tests__/compile/expression/CallExpressionCompiler.test.ts`
  - `rush test -t packages/neo-one-smart-contract-compiler/src/__tests__/compile/expression/ElementAccessExpressionCompiler.test.ts`
  - `rush test -t packages/neo-one-smart-contract-compiler/src/__tests__/compile/expression/PropertyAccessExpressionCompiler.test.ts`
- Nullish Coalescing
  - `rush test -t packages/neo-one-smart-contract-compiler/src/__tests__/compile/expression/ToNullishBooleanHelper.test.ts`
- Recursive Type Aliases
  - `rush test -t packages/neo-one-smart-contract-compiler/src/__tests__/compile/declaration/TypeAliasDeclarationCompiler.test.ts`
- Type-Only Imports and Exports
  - `rush test -t packages/neo-one-typescript-concatenator/src/__tests__/concatenate.test.ts`
- ECMAScript Private Fields
  - `rush test -t packages/neo-one-smart-contract-compiler/src/__tests__/compile/declaration/ClassDeclarationCompiler.test.ts`
  - `rush test -t packages/neo-one-smart-contract-compiler/src/__tests__/compile/expression/ObjectLiteralExpressionCompiler.test.ts`
- `export * as ns` Syntax
  - `rush test -t packages/neo-one-typescript-concatenator/src/__tests__/concatenate.test.ts`
- Top-Level `await`
  - `rush test -t packages/neo-one-smart-contract-compiler/src/__tests__/compiler/expression/AwaitExpressionCompiler.test.ts`

### Alternate Designs

None.

### Benefits

- We support the latest language features for writing Smart Contracts in TS.

### Possible Drawbacks

- Prettier doesn't support some TS v3.8 syntax yet, so all Prettier checks will fail on the `neo-one-typescript-concatenator` package until they/we update Prettier. They have an issue open for this [here](prettier/prettier#7263). They are waiting for TS 3.8 support in `typescript-eslint` for the new AST [here](typescript-eslint/typescript-eslint#1465). This is easy to ignore for now.
- Possibly unforeseen problems.

### Applicable Issues

#1889 


Co-authored-by: Spencer Corwin <spencercorwin@icloud.com>
@bradzacher bradzacher closed this Sep 28, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2020
@armano2 armano2 deleted the typescript-3.8 branch February 3, 2021 05:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependencies Issue about dependencies of the package DO NOT MERGE PRs which should not be merged yet package: parser Issues related to @typescript-eslint/parser package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript 3.8 Syntax Support
6 participants