mirror of
https://github.com/ryan-haskell/elm-spa.git
synced 2024-10-26 21:59:47 +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 = (value : string) => (str : string) : boolean => {
|
||||||
const exposes = (keyword: string) => (elmSourceCode: string): boolean =>
|
const regex = new RegExp('^module\\s+[^\\s]+\\s+exposing\\s+\\(([^)]+)\\)')
|
||||||
new RegExp(`module\\s(\\S)+\\sexposing(\\s)+\\([^\\)]*${keyword}[^\\)]*\\)`, 'm').test(elmSourceCode)
|
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 exposesModel = exposes('Model')
|
||||||
export const exposesMsg = exposes('Msg')
|
export const exposesMsg = exposes('Msg')
|
||||||
@ -334,4 +340,4 @@ export const isStaticPage = (src : string) =>
|
|||||||
exposesPageFunction(src)
|
exposesPageFunction(src)
|
||||||
|
|
||||||
export const isStaticView = (src : string) =>
|
export const isStaticView = (src : string) =>
|
||||||
exposesViewFunction(src)
|
exposesViewFunction(src)
|
||||||
|
Loading…
Reference in New Issue
Block a user