Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

feat(ast): heritage array is now optional, not empty array #120

Merged
merged 6 commits into from
Jan 12, 2019

Conversation

JamesHenry
Copy link
Owner

I'll probably add the other heritage related alignment points before merging

@codecov
Copy link

codecov bot commented Jan 12, 2019

Codecov Report

Merging #120 into master will decrease coverage by 0.01%.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #120      +/-   ##
=========================================
- Coverage   93.22%   93.2%   -0.02%     
=========================================
  Files           8       8              
  Lines        1357    1368      +11     
  Branches      319     324       +5     
=========================================
+ Hits         1265    1275      +10     
  Misses         51      51              
- Partials       41      42       +1
Impacted Files Coverage Δ
src/semantic-errors.ts 77.77% <ø> (ø) ⬆️
src/ast-node-types.ts 100% <100%> (ø) ⬆️
src/convert.ts 93.82% <94.11%> (-0.05%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f11e368...1436d61. Read the comment docs.

@JamesHenry
Copy link
Owner Author

@armano2 in e40b9d7 I have moved the ignore for abstract classes to node patching.

My gut reaction is that aligning with babel here might not actually a step in the right direction. I feel like this is similar to other things we've had before where it makes the most sense for the construct to have its own unique node type...

What do you think? I could imagine this would be harder to deal with in a linting situation, potentially causing issues with existing rules...

@armano2
Copy link
Contributor

armano2 commented Jan 12, 2019

i was thinking about this to, if we unify those nodes, there will be no easy way to query them in eslint.

i will just suggest renaming them, ClassImplements to TSClassImplements (this is no es node),
and we don't want that flow rules are going to play with it.

i will follow name of property from babel:

  • extends
  • implements

instead of heritage

you can use something like this:

     TSExpressionWithTypeArguments(node: any, parent: any) {
        if (parent.type === 'TSInterfaceDeclaration') {
          node.type = 'TSInterfaceHeritage';
        } else if (
          parent.type === 'ClassExpression' ||
          parent.type === 'ClassDeclaration'
        ) {
          node.type = 'ClassImplements';
        }
      }

and we should log suggestion/request on babel repo for this

@JamesHenry
Copy link
Owner Author

One thing is that TSExpressionWithTypeArguments has expression not id.

To be honest though, I'm struggling to create valid TypeScript where it is anything other than an Identifier. Any idea what expression would be valid in extends ...?

cc @uniqueiniquity

@JamesHenry
Copy link
Owner Author

@armano2 I have made all the changes we discussed, please could you take a look?

src/convert.ts Outdated
});

if (interfaceHeritageClauses.length > 0) {
result.extends = interfaceHeritageClauses[0].types.map(el =>
Copy link
Contributor

Choose a reason for hiding this comment

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

i have only one concern here

interface foo implements bar extends foo {}

its going to pick up wrong heritage

Copy link
Contributor

@armano2 armano2 Jan 12, 2019

Choose a reason for hiding this comment

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

i know that whas a case before to, but prettier is going to mess up here

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yep good point, I'll fix it

Copy link
Contributor

@armano2 armano2 Jan 12, 2019

Choose a reason for hiding this comment

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

there is also more broken example

interface foo extends bar extends baz {}

TS1172

@@ -34,6 +34,8 @@ export interface ESTreeNode {
value?: string;
expression?: ESTreeNode | null;
decorators?: (ESTreeNode | null)[];
implements?: ESTreeNode[];
extends?: ESTreeNode[];
Copy link
Contributor

Choose a reason for hiding this comment

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

extends can be array of nodes or node

extends in class is node, in interface is array

Copy link
Owner Author

Choose a reason for hiding this comment

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

It's superClass in classes right? Extends isn't used?

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh you are right, there was change with that :>

@armano2
Copy link
Contributor

armano2 commented Jan 12, 2019

typescript also parses code like this correctly:

interface foo extends foo.call {} // valid
interface foo extends foo.call() {} // TS2499
interface foo extends foo() {} // TS2499
interface foo extends ({ foo: bar }) {} // TS2499

@armano2
Copy link
Contributor

armano2 commented Jan 12, 2019

One thing is that TSExpressionWithTypeArguments has expression not id.

To be honest though, I'm struggling to create valid TypeScript where it is anything other than an Identifier. Any idea what expression would be valid in extends ...?

cc @uniqueiniquity

i'm starting think that expression is better suited for this because it can contain Identifier and QualifiedName

@JamesHenry
Copy link
Owner Author

Pushing shortly, thanks for the updates, and good spot on the TSQualifiedName

@JamesHenry
Copy link
Owner Author

@armano2 let me know what you think of the last two commits

Copy link
Contributor

@armano2 armano2 left a comment

Choose a reason for hiding this comment

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

looks fine, thank you

@JamesHenry JamesHenry merged commit 7176619 into master Jan 12, 2019
@JamesHenry JamesHenry deleted the heritage branch January 12, 2019 18:43
@JamesHenry
Copy link
Owner Author

Thanks! Let's stabilize for a bit now while we catch the ESLint ecosystem up and take stock

@armano2
Copy link
Contributor

armano2 commented Jan 12, 2019

all of nodes are now aligned -> most of issues is due to range bugs in babel :)

i'm running my tests now

@JamesHenry
Copy link
Owner Author

🎉 This PR is included in version 18.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@JamesHenry
Copy link
Owner Author

JamesHenry commented Jan 12, 2019

Well apart from all the property and kind tweaks we have to make to nodes in ast-alignment/utils right? :)

@armano2
Copy link
Contributor

armano2 commented Jan 12, 2019

yes, in my tests i'm doing same thing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants