Skip to content

Commit

Permalink
fix short-hand-import parser
Browse files Browse the repository at this point in the history
  • Loading branch information
NtTestAlert committed Apr 10, 2024
1 parent 3275c15 commit fe3d60f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ 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 cutAt = found.indexOf("import") + 6
const whatMatch = found.substring(cutAt).matchAll(/"?([^"\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 fe3d60f

Please sign in to comment.