From 8b861cf781eb59ec08035d97b6cd0604b539f055 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sun, 12 Nov 2023 03:54:11 -0800 Subject: [PATCH] Check for raw string in extra.raw when searching for quotes (#721) --- .changeset/happy-seahorses-buy.md | 5 +++++ .../v2-to-v3/__fixtures__/misc/single-quote.require.input.js | 3 +++ .../__fixtures__/misc/single-quote.require.output.js | 3 +++ .../v2-to-v3/utils/getMostUsedStringLiteralQuote.ts | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/happy-seahorses-buy.md create mode 100644 src/transforms/v2-to-v3/__fixtures__/misc/single-quote.require.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/misc/single-quote.require.output.js diff --git a/.changeset/happy-seahorses-buy.md b/.changeset/happy-seahorses-buy.md new file mode 100644 index 000000000..a51cab73f --- /dev/null +++ b/.changeset/happy-seahorses-buy.md @@ -0,0 +1,5 @@ +--- +"aws-sdk-js-codemod": patch +--- + +Check for raw string in extra.raw when searching for quotes diff --git a/src/transforms/v2-to-v3/__fixtures__/misc/single-quote.require.input.js b/src/transforms/v2-to-v3/__fixtures__/misc/single-quote.require.input.js new file mode 100644 index 000000000..12ab19858 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/misc/single-quote.require.input.js @@ -0,0 +1,3 @@ +const AWS = require('aws-sdk'); + +const client = new AWS.DynamoDB(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/misc/single-quote.require.output.js b/src/transforms/v2-to-v3/__fixtures__/misc/single-quote.require.output.js new file mode 100644 index 000000000..790a47f48 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/misc/single-quote.require.output.js @@ -0,0 +1,3 @@ +const { DynamoDB } = require('@aws-sdk/client-dynamodb'); + +const client = new DynamoDB(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/utils/getMostUsedStringLiteralQuote.ts b/src/transforms/v2-to-v3/utils/getMostUsedStringLiteralQuote.ts index 696792cd5..c8d136fed 100644 --- a/src/transforms/v2-to-v3/utils/getMostUsedStringLiteralQuote.ts +++ b/src/transforms/v2-to-v3/utils/getMostUsedStringLiteralQuote.ts @@ -21,7 +21,7 @@ export const getMostUsedStringLiteralQuote = ( if (typeof value === "string") { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore Property 'raw' does not exist on type 'Literal'. - const rawValue = path.node.raw || ""; + const rawValue = path.node.raw || path.node.extra?.raw || ""; if (rawValue.startsWith("'")) { quoteCount[StringLiteralQuoteType.SINGLE]++; } else if (rawValue.startsWith('"')) {