Skip to content

Commit fe3d60f

Browse files
committed
fix short-hand-import parser
1 parent 3275c15 commit fe3d60f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/imports.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const importRegex = new RegExp(
2929
export const fixShorthandImports = code => {
3030
return code.replaceAll(importRegex, found => {
3131
if (found.indexOf(" from") !== -1) return found
32-
const whatMatch = found.matchAll(/"?([^"\s]+)"?,?\s*?/giu)
32+
const cutAt = found.indexOf("import") + 6
33+
const whatMatch = found.substring(cutAt).matchAll(/"?([^"\s]+)"?,?\s*?/giu)
3334
return [...whatMatch]
3435
.map(what => `import ${what[1]} from "./${what[1]}.cdc"`)
3536
.join("\n")

test/integration/imports.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "../../src"
99
import {defaultsByName} from "../../src/file"
1010
import {DEFAULT_TEST_TIMEOUT} from "../util/timeout.const"
11+
import {fixShorthandImports} from "../../src/imports"
1112

1213
jest.setTimeout(DEFAULT_TEST_TIMEOUT)
1314

@@ -49,6 +50,9 @@ describe("import resolver", () => {
4950
access(all) fun main(){}
5051
`
5152

53+
const testFixed = fixShorthandImports(code)
54+
expect(testFixed.includes("import.cdc")).toBe(false)
55+
5256
const addressMap = await resolveImports(code)
5357
const Registry = await getServiceAddress()
5458

0 commit comments

Comments
 (0)