From 79546c51bf735335045ae12a8055ed84937b0485 Mon Sep 17 00:00:00 2001 From: Ryan Haskell-Glatz Date: Mon, 1 Mar 2021 17:30:43 -0600 Subject: [PATCH] use a better regex --- src/cli/src/templates/utils.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cli/src/templates/utils.ts b/src/cli/src/templates/utils.ts index 8362959..5c254e5 100644 --- a/src/cli/src/templates/utils.ts +++ b/src/cli/src/templates/utils.ts @@ -316,9 +316,15 @@ const pageModelArguments = (path: string[], options : Options) : string => { } } -// Used in place of sophisticated AST parsing -const exposes = (keyword: string) => (elmSourceCode: string): boolean => - new RegExp(`module\\s(\\S)+\\sexposing(\\s)+\\([^\\)]*${keyword}[^\\)]*\\)`, 'm').test(elmSourceCode) +const exposes = (value : string) => (str : string) : boolean => { + const regex = new RegExp('^module\\s+[^\\s]+\\s+exposing\\s+\\(([^)]+)\\)') + const match = (str.match(regex) || [])[1] + if (match) { + return match.split(',').filter(a => a).map(a => a.trim()).includes(value) + } else { + return false + } +} export const exposesModel = exposes('Model') export const exposesMsg = exposes('Msg') @@ -334,4 +340,4 @@ export const isStaticPage = (src : string) => exposesPageFunction(src) export const isStaticView = (src : string) => - exposesViewFunction(src) \ No newline at end of file + exposesViewFunction(src)