use a better regex

This commit is contained in:
Ryan Haskell-Glatz 2021-03-01 17:30:43 -06:00 committed by GitHub
parent 4f350ffcbc
commit 79546c51bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
exposesViewFunction(src)