fix issue with Msg(..) exported on pages

This commit is contained in:
Ryan Haskell-Glatz 2021-05-02 09:54:52 -05:00
parent a93993ed3b
commit 7e64f27955
4 changed files with 28 additions and 6 deletions

View File

@ -1,12 +1,12 @@
{
"name": "elm-spa",
"version": "6.0.0",
"version": "6.0.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "elm-spa",
"version": "6.0.0",
"version": "6.0.1",
"license": "BSD-3-Clause",
"dependencies": {
"chokidar": "3.4.2",

View File

@ -1,6 +1,6 @@
{
"name": "elm-spa",
"version": "6.0.0",
"version": "6.0.1",
"description": "single page apps made easy",
"bin": "dist/src/index.js",
"scripts": {

View File

@ -317,7 +317,7 @@ const pageModelArguments = (path: string[], options : Options) : string => {
}
const exposes = (value : string) => (str : string) : boolean => {
const regex = new RegExp('^module\\s+[^\\s]+\\s+exposing\\s+\\(([^)]+)\\)')
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)
@ -327,7 +327,7 @@ const exposes = (value : string) => (str : string) : boolean => {
}
export const exposesModel = exposes('Model')
export const exposesMsg = exposes('Msg')
export const exposesMsg = (str : string) => exposes('Msg')(str) || exposes('Msg(..)')(str)
export const exposesPageFunction = exposes('page')
export const exposesViewFunction = exposes('view')

View File

@ -198,4 +198,26 @@ describe.each([['Model'], ['Msg']])
)
`.trim())).toBe(true)
})
})
})
describe('exposes', () => {
it('works with unexposed variants', () =>{
expect(Utils.exposesMsg('module Page exposing (Msg)')).toBe(true)
expect(Utils.exposesMsg('module Page exposing (Model, Msg)')).toBe(true)
expect(Utils.exposesMsg('module Page exposing (Model, Msg, view)')).toBe(true)
})
it('works with exposed variants', () =>{
expect(Utils.exposesMsg('module Page exposing (Msg(..))')).toBe(true)
expect(Utils.exposesMsg('module Page exposing (Model, Msg(..))')).toBe(true)
expect(Utils.exposesMsg('module Page exposing (Model, Msg(..), view)')).toBe(true)
})
it(`exposed variants don't cause issues for other keywords`, () => {
expect(Utils.exposesModel('module Page exposing (Model, Msg(..), view, page)')).toBe(true)
expect(Utils.exposesViewFunction('module Page exposing (Model, Msg(..), view, page)')).toBe(true)
expect(Utils.exposesPageFunction('module Page exposing (Model, Msg(..), view, page)')).toBe(true)
expect(Utils.exposesModel('module Page exposing (Msg(..), view) Model')).toBe(false)
expect(Utils.exposesViewFunction('module Page exposing (Model, Msg(..)) view')).toBe(false)
expect(Utils.exposesPageFunction('module Page exposing (Model, Msg(..)) page')).toBe(false)
})
})