Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feat#Provide a quick-fix for non-exported imports#72

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Richard-Lynch wants to merge12 commits intobloomberg:oss-hackathon-37440
base:oss-hackathon-37440
Choose a base branch
Loading
fromRichard-Lynch:quickfix-non-exported-imports

Conversation

@Richard-Lynch
Copy link

@Richard-LynchRichard-Lynch commentedJun 16, 2022
edited
Loading

Fixesmicrosoft#37440

If:

  • The import is from a .d.ts file, do nothing.

  • The declaration is a single variable (e.g.let a = 1): update toexport let a = 1

  • The declaration is a single function (e.g.function a(){...}): update toexport function a(){...}

  • The declaration is in a list and contains multiple variables (e.g.let a = 1, b = 2)

    • Noexport {...} found in the file: create anexport {...} and add to that
    • Multipleexport {...} found in the file: add to the lastexport {...}

Testing performed
Local testing + tests added

Additional context
Based on thisclosed PR

I think I addressed all the comments exceptthis, which seems reasonable to me!

Richard Lynch added4 commitsJune 16, 2022 15:22
Signed-off-by: Richard Lynch <rlynch79@bloomberg.net>
Signed-off-by: Richard Lynch <rlynch79@bloomberg.net>
Signed-off-by: Richard Lynch <rlynch79@bloomberg.net>
Signed-off-by: Richard Lynch <rlynch79@bloomberg.net>
@Richard-LynchRichard-Lynchforce-pushed thequickfix-non-exported-imports branch from82a3253 toc68ae3bCompareJune 16, 2022 14:23
@Richard-LynchRichard-Lynch changed the titleFeat#Quickfix non exported importsFeat#Provide a quick-fix for non-exported importsJun 16, 2022
@Richard-Lynch
Copy link
Author

Maybe worth adding (at)DanielRosenwasser and (at)sandersn when this is added to the TS repo

@Richard-LynchRichard-Lynch marked this pull request as ready for reviewJune 16, 2022 14:49
Copy link

@mkubilaykmkubilayk left a comment

Choose a reason for hiding this comment

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

Looking very good - some minor comments.

constnode=localSymbol.valueDeclaration.parent;

returnchanges.insertExportModifier(sourceFile,node);
}

Choose a reason for hiding this comment

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

Do we need special handling forclass declarations as well?

Choose a reason for hiding this comment

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

class is captured/handled withisDeclarationStatement but I've added some tests and simplified that logic

// If there is an existing export
if(
namedExportDeclaration?.exportClause&&
isNamedExports(namedExportDeclaration.exportClause)

Choose a reason for hiding this comment

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

Should we check if this is a type-only export? My understanding is that this would change:

exporttype{existingThing};

to

export{existingThing,newThing};

which may not be desired.

Choose a reason for hiding this comment

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

nice! yes, this is a good test case, adding now

if(
isExportDeclaration(statement)&&
statement.exportClause&&
isNamedExports(statement.exportClause)

Choose a reason for hiding this comment

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

We should skip re-export statements here:export { a } from "./something";.

Choose a reason for hiding this comment

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

yup nice, added

Comment on lines 188 to 206
factory.updateExportDeclaration(
/*node*/namedExportDeclaration,
/*modifiers*/undefined,
/*isTypeOnly*/false,
/*exportClause*/factory.updateNamedExports(
/*node*/namedExportDeclaration.exportClause,
/*elements*/sortSpecifiers(
namedExportDeclaration.exportClause.elements.concat(
factory.createExportSpecifier(
/*isTypeOnly*/false,
/*propertyName*/undefined,
node
)
)
)
),
/*moduleSpecifier*/undefined,
/*assertClause*/undefined
)

Choose a reason for hiding this comment

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

Suggested change
factory.updateExportDeclaration(
/*node*/namedExportDeclaration,
/*modifiers*/undefined,
/*isTypeOnly*/false,
/*exportClause*/factory.updateNamedExports(
/*node*/namedExportDeclaration.exportClause,
/*elements*/sortSpecifiers(
namedExportDeclaration.exportClause.elements.concat(
factory.createExportSpecifier(
/*isTypeOnly*/false,
/*propertyName*/undefined,
node
)
)
)
),
/*moduleSpecifier*/undefined,
/*assertClause*/undefined
)
factory.updateExportDeclaration(
namedExportDeclaration,
/*modifiers*/undefined,
/*isTypeOnly*/false,
factory.updateNamedExports(
namedExportDeclaration.exportClause,
sortSpecifiers(
namedExportDeclaration.exportClause.elements.concat(
factory.createExportSpecifier(
/*isTypeOnly*/false,
/*propertyName*/undefined,
node
)
)
)
),
/*moduleSpecifier*/undefined,
/*assertClause*/undefined
)

I think some of these arguments are self explanatory.

Choose a reason for hiding this comment

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

I'm happy to remove any of these you'd like, but tbh as someone new to the project => they're not :P

Honestly half the pain is having so many positional arguments at all!

Comment on lines 217 to 223
/*exportClause*/factory.createNamedExports([
factory.createExportSpecifier(
/*isTypeOnly*/false,
/*propertyName*/undefined,
node
),
]),

Choose a reason for hiding this comment

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

Suggested change
/*exportClause*/factory.createNamedExports([
factory.createExportSpecifier(
/*isTypeOnly*/false,
/*propertyName*/undefined,
node
),
]),
factory.createNamedExports([
factory.createExportSpecifier(
/*isTypeOnly*/false,
/*propertyName*/undefined,
node
),
]),

Comment on lines +788 to +789
/*expression*/!(isVariableDeclarationList(node)&&node.declarations.length!==1),
/*message*/"Only allow adding export modifier to variable lists with 1 element"

Choose a reason for hiding this comment

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

Suggested change
/*expression*/!(isVariableDeclarationList(node)&&node.declarations.length!==1),
/*message*/"Only allow adding export modifier to variable lists with 1 element"
!(isVariableDeclarationList(node)&&node.declarations.length!==1),
"Only allow adding export modifier to variable lists with 1 element"

////let d = 4;
////export function whatever() {
////}
////export { d }

Choose a reason for hiding this comment

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

Would be good to add some test cases where source file has some exports that we cannot use:

exporttype{a};export{b}from"./b";export*ascfrom"./c";// ...

Choose a reason for hiding this comment

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

done

"code":90058
},

"Export '{0}' from module '{1}'": {

Choose a reason for hiding this comment

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

Suggested change
"Export'{0}' from module'{1}'": {
"Export\"{0}\" from module\"{1}\"": {

minor, seems to match the other ones above this.

Choose a reason for hiding this comment

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

yup nice, done

Choose a reason for hiding this comment

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

hmm, theRemove import from './b' uses single quotes, what do you think?

Choose a reason for hiding this comment

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

it looks like there are only 4 instances using double quotes, that seems like a mistake
image
image

"category":"Message",
"code":90059
},
"Add all missing exports": {

Choose a reason for hiding this comment

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

I realise this message is simialr to the "Add all imports" one, but I don't think it really expresses the change that will happen. Maybe "Export all missing members in modules"

Choose a reason for hiding this comment

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

Agreed, I changed toExport all missing members from modules


//@Filename: /b.ts
////declare function foo(): any;
////function bar(): any;

Choose a reason for hiding this comment

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

I would like to see some tests on overloaded functions as well.

Choose a reason for hiding this comment

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

Good shout! do you think the export should be on the implemented function or in a named export? 🤔

Choose a reason for hiding this comment

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

Ok, I've given this a look and its actually a little tricky given the current implementation!

I can easily make all functions export using a named export =>export {add};, but if we want to follow the convention of applying the export on the declaration where possible it'll take a bit more work! Do you think that's critical?

Choose a reason for hiding this comment

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

I think a separate export statement (e.g.export { add }) would be acceptable for function overloads.

index:1,
description:`Export 'b' from module './a'`,
newFileContent:{
"/a.ts":`class a{}, export class b{};

Choose a reason for hiding this comment

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

This is producing invalid syntax. I think we need to fallback toexport { b }; in this case.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mkubilaykmkubilaykmkubilayk left review comments

@acutmoreacutmoreacutmore left review comments

@dragomirtitiandragomirtitiandragomirtitian requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@Richard-Lynch@mkubilayk@acutmore@dragomirtitian

[8]ページ先頭

©2009-2025 Movatter.jp