From 4ce665bb741c1ec66329f2977718076e6f38a031 Mon Sep 17 00:00:00 2001 From: NtTestAlert <50535142+NtTestAlert@users.noreply.github.com> Date: Wed, 10 Apr 2024 23:40:35 +0200 Subject: [PATCH] fix short-hand-import parser (#227) --- src/imports.js | 2 +- test/integration/imports.test.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/imports.js b/src/imports.js index 998941b0..568dd1a5 100644 --- a/src/imports.js +++ b/src/imports.js @@ -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") 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()