From fe3d60fb818836e2d7cfdfd26c283917c96dbd1c Mon Sep 17 00:00:00 2001 From: NtTestAlert <50535142+NtTestAlert@users.noreply.github.com> Date: Wed, 10 Apr 2024 11:36:00 +0200 Subject: [PATCH] fix short-hand-import parser --- src/imports.js | 3 ++- test/integration/imports.test.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/imports.js b/src/imports.js index 998941b0..3b489324 100644 --- a/src/imports.js +++ b/src/imports.js @@ -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") diff --git a/test/integration/imports.test.js b/test/integration/imports.test.js index ef3471b5..435581b6 100644 --- a/test/integration/imports.test.js +++ b/test/integration/imports.test.js @@ -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) @@ -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()