Skip to content

Commit

Permalink
fix short-hand-import parser (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
NtTestAlert authored and jribbink committed Apr 10, 2024
1 parent 3275c15 commit 6a11947
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tidy-coats-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/flow-js-testing": patch
---

Fix shorthand imports
2 changes: 1 addition & 1 deletion src/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const importRegex = new RegExp(
export const fixShorthandImports = code => {
return code.replaceAll(importRegex, found => {
if (found.indexOf(" from") !== -1) return found
const whatMatch = found.matchAll(/"?([^"\s]+)"?,?\s*?/giu)
const whatMatch = found.matchAll(/"([^"\s]+)"\s*,?\s*?/giu)
return [...whatMatch]
.map(what => `import ${what[1]} from "./${what[1]}.cdc"`)
.join("\n")
Expand Down
4 changes: 4 additions & 0 deletions test/integration/imports.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "../../src"
import {defaultsByName} from "../../src/file"
import {DEFAULT_TEST_TIMEOUT} from "../util/timeout.const"
import {fixShorthandImports} from "../../src/imports"

jest.setTimeout(DEFAULT_TEST_TIMEOUT)

Expand Down Expand Up @@ -49,6 +50,9 @@ describe("import resolver", () => {
access(all) fun main(){}
`

const testFixed = fixShorthandImports(code)
expect(testFixed.includes("import.cdc")).toBe(false)

const addressMap = await resolveImports(code)
const Registry = await getServiceAddress()

Expand Down

0 comments on commit 6a11947

Please sign in to comment.