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(typescript-estree): change source of ExportNamedDeclaration to Literal from Expression #3763

Conversation

sosukesuzuki
Copy link
Contributor

source of ExportNamedDeclaration is Literal in estree.

If this is your intention, close this.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @sosukesuzuki!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@sosukesuzuki sosukesuzuki changed the title fix(typescript-estree): change of ExportNamedDeclaration to Literal from Expression fix(typescript-estree): change source of ExportNamedDeclaration to Literal from Expression Aug 20, 2021
@bradzacher
Copy link
Member

This is actually currently done on purpose.
The TS parser is incredibly forgiving - and so it gives us a bad AST.
We don't currently enforce the AST matches the ESTree structure - so in this case import foo from bar is valid code in our parser (as is export { foo } from 1 + 1.

We have two options:

  1. wait until we've done Parsing: strictly enforce the produced AST matches the spec and enforce most "error recovery" parsing errors #1852 and thus have parser errors for bad code
  2. add validation in this diff to enforce that it is a string literal.

I'm happy with either - depends on if you've got time to do the extra work for (2).

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Aug 20, 2021
@sosukesuzuki
Copy link
Contributor Author

@bradzacher Thanks you for telling me.

I'm happy with either - depends on if you've got time to do the extra work for (2).

I can work for implement option (2).

However, one question. Why source of ImportDeclaration is Literal? We can specify any expression to source of ImportDeclaration same as ExportNamedDeclaration.

@sosukesuzuki
Copy link
Contributor Author

I've pushed commits to add assertion for module specifiers, but I'm not sure it is correct way.

@codecov
Copy link

codecov bot commented Aug 21, 2021

Codecov Report

Merging #3763 (5b66c4c) into v5 (a752638) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##               v5    #3763      +/-   ##
==========================================
- Coverage   92.68%   92.68%   -0.01%     
==========================================
  Files         327      325       -2     
  Lines       11351    11349       -2     
  Branches     3201     3203       +2     
==========================================
- Hits        10521    10519       -2     
  Misses        369      369              
  Partials      461      461              
Flag Coverage Δ
unittest 92.68% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/typescript-estree/src/convert.ts 98.28% <100.00%> (+0.01%) ⬆️
packages/visitor-keys/src/visitor-keys.ts
packages/visitor-keys/src/get-keys.ts

@bradzacher bradzacher added breaking change This change will require a new major version to be released and removed awaiting response Issues waiting for a reply from the OP or another party labels Aug 22, 2021
@bradzacher bradzacher added this to the 5.0.0 milestone Aug 22, 2021
@bradzacher bradzacher added the AST PRs and Issues about the AST structure label Aug 22, 2021
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for this!

@bradzacher bradzacher changed the base branch from master to v5 August 22, 2021 00:35
@bradzacher bradzacher merged commit 99bb19d into typescript-eslint:v5 Aug 22, 2021
@sosukesuzuki sosukesuzuki deleted the fix-export-named-declaration-ast-spec branch August 22, 2021 00:37
bradzacher pushed a commit that referenced this pull request Sep 3, 2021
…Literal from Expression (#3763)

* fix(typescript-estree): change  of ExportNamedDeclaration to Literal from Expression

* fix(typescript-estree): add assertion for module specifier
bradzacher pushed a commit that referenced this pull request Sep 21, 2021
…Literal from Expression (#3763)

* fix(typescript-estree): change  of ExportNamedDeclaration to Literal from Expression

* fix(typescript-estree): add assertion for module specifier
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AST PRs and Issues about the AST structure breaking change This change will require a new major version to be released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants