mirror of
https://github.com/ryan-haskell/elm-spa.git
synced 2024-11-22 11:31:58 +03:00
use a better regex
This commit is contained in:
parent
4f350ffcbc
commit
79546c51bf
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user