From 3ab785f0293e3d851b5c43fd99e175552a3e56b9 Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 27 Feb 2024 14:54:29 +0100 Subject: [PATCH 1/3] update regex to account for function referencing --- .../src/ideExtension/messageReferenceMatchers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inlang/source-code/plugins/m-function-matcher/src/ideExtension/messageReferenceMatchers.ts b/inlang/source-code/plugins/m-function-matcher/src/ideExtension/messageReferenceMatchers.ts index d7a6bf3e8e..0717390b63 100644 --- a/inlang/source-code/plugins/m-function-matcher/src/ideExtension/messageReferenceMatchers.ts +++ b/inlang/source-code/plugins/m-function-matcher/src/ideExtension/messageReferenceMatchers.ts @@ -25,10 +25,10 @@ const createParser = () => { findMessage: () => { return Parsimmon.seqMap( Parsimmon.regex(/.*?(? { return { messageId: `${messageId}`, From e9224cfd81cef3d8de897e5e4b51e089869aa368 Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 27 Feb 2024 14:55:10 +0100 Subject: [PATCH 2/3] update test to account for function referencing & improve test coverage --- .../messageReferenceMatchers.test.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/inlang/source-code/plugins/m-function-matcher/src/ideExtension/messageReferenceMatchers.test.ts b/inlang/source-code/plugins/m-function-matcher/src/ideExtension/messageReferenceMatchers.test.ts index 72eb8aa3cc..0d436c1ec0 100644 --- a/inlang/source-code/plugins/m-function-matcher/src/ideExtension/messageReferenceMatchers.test.ts +++ b/inlang/source-code/plugins/m-function-matcher/src/ideExtension/messageReferenceMatchers.test.ts @@ -303,6 +303,49 @@ describe("Paraglide Message Parser", () => { ]) }) + it("should parse function calls without parentheses", () => { + const sourceCode = `import * as m from 'module'; + + const a = { + b: m.helloWorld, + c: m.helloWorld(), + d: m.helloWorld().someFunction(), + e: m.this_is_a_message123, + } + ` + const result = parse(sourceCode) + expect(result).toEqual([ + { + messageId: "helloWorld", + position: { + start: { line: 4, character: 9 }, + end: { line: 4, character: 19 }, + }, + }, + { + messageId: "helloWorld", + position: { + start: { line: 5, character: 9 }, + end: { line: 5, character: 21 }, + }, + }, + { + messageId: "helloWorld", + position: { + start: { line: 6, character: 9 }, + end: { line: 6, character: 21 }, + }, + }, + { + messageId: "this_is_a_message123", + position: { + start: { line: 7, character: 9 }, + end: { line: 7, character: 29 }, + }, + }, + ]) + }) + it("should match if m is defined before the reference to paraglide", () => { const sourceCode = ` m.helloWorld(); @@ -340,4 +383,11 @@ describe("Paraglide Message Parser", () => { const result = parse(sourceCode) expect(result).toEqual([]) }) + + it("should return an empty array when parsing fails", () => { + const sourceCode = undefined + + const result = parse(sourceCode as unknown as string) + expect(result).toEqual([]) + }) }) From 92f7c95320e16735681be694a740de4f5a678b23 Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 27 Feb 2024 14:55:17 +0100 Subject: [PATCH 3/3] update changeset --- .changeset/empty-windows-clap.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/empty-windows-clap.md diff --git a/.changeset/empty-windows-clap.md b/.changeset/empty-windows-clap.md new file mode 100644 index 0000000000..ad62fbb6e4 --- /dev/null +++ b/.changeset/empty-windows-clap.md @@ -0,0 +1,5 @@ +--- +"@inlang/plugin-m-function-matcher": minor +--- + +improve matcher to include function referencing & improve test coverage