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

[Bug]: The v2-to-v3 transform removes top level comment #205

Closed
1 task
trivikr opened this issue Dec 22, 2022 · 4 comments
Closed
1 task

[Bug]: The v2-to-v3 transform removes top level comment #205

trivikr opened this issue Dec 22, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@trivikr
Copy link
Member

trivikr commented Dec 22, 2022

Self-service

  • I'd be willing to implement a fix

Describe the bug

The v2-to-v3 transform removes top level comment

Template name

v2-to-v3

Input code

// Top level comment
import AWS from "aws-sdk";

// Create client
const client = new AWS.DynamoDB({ region: "us-west-2" });

// Make listTables call
client.listTables({}, (err, data) => {
  if (err) console.log(err, err.stack);
  else console.log(data);
});

Observed failure

No failure, but the top level comment is removed

import { DynamoDB } from "@aws-sdk/client-dynamodb";

// Create client
const client = new DynamoDB({ region: "us-west-2" });

// Make listTables call
client.listTables({}, (err, data) => {
  if (err) console.log(err, err.stack);
  else console.log(data);
});

Expected output

// Top level comment
import { DynamoDB } from "@aws-sdk/client-dynamodb";

// Create client
const client = new DynamoDB({ region: "us-west-2" });

// Make listTables call
client.listTables({}, (err, data) => {
  if (err) console.log(err, err.stack);
  else console.log(data);
});

### Environment

```shell
aws-sdk-js-codemod: 0.6.4

jscodeshift: 0.14.0
 - babel: 7.20.5
 - babylon: 7.20.5
 - flow: 0.196.2
 - recast: 0.21.5

Additional context

No response

@trivikr trivikr added bug Something isn't working triage Triaging bugs and removed triage Triaging bugs labels Dec 22, 2022
@trivikr trivikr changed the title [Bug?]: The v2-to-v3 transform removes top level comment [Bug]: The v2-to-v3 transform removes top level comment Dec 22, 2022
@trivikr
Copy link
Member Author

trivikr commented Dec 22, 2022

This happens in both import and require.
https://github.com/awslabs/aws-sdk-js-codemod/blob/main/src/transforms/v2-to-v3/utils/remove/removeDefaultModuleIfNotUsed.ts

It happens has recast considers comment as part of VariableDeclaration (in case of require), as shown in the screenshot below.

Screenshot

comment-variable-declarator

@trivikr
Copy link
Member Author

trivikr commented Dec 22, 2022

Comment is considered as part of variable declaration, even if it's a block comment and has newline

Screenshot

code-with-block-comment-and-newline

@trivikr
Copy link
Member Author

trivikr commented Dec 22, 2022

Attempts to fix can be viewed in #206

Closing as wontfix, as this issue is minor as compared to other bug reports or feature requests. Also, there's no straightforward way to preserve comments.

@trivikr trivikr added the wontfix This will not be worked on label Dec 22, 2022
@trivikr trivikr closed this as completed Dec 22, 2022
@github-actions
Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2023
@trivikr trivikr removed the wontfix This will not be worked on label Nov 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant