Shortened Wasp.JsImport fields.

This commit is contained in:
Martin Sosic 2020-08-25 15:55:37 +02:00
parent 495ba96284
commit ce6cf2bc5a
5 changed files with 17 additions and 17 deletions

View File

@ -93,11 +93,11 @@ generatePageComponent wasp page = Common.makeTemplateFD tmplPath dstPath (Just t
toJsImportData :: WJsImport.JsImport -> Aeson.Value
toJsImportData jsImport = object
[ "what" .= fromMaybe (error "Expected default JS import.") (WJsImport.jsImportDefaultImport jsImport)
[ "what" .= fromMaybe (error "Expected default JS import.") (WJsImport._defaultImport jsImport)
-- NOTE: Here we assume that "from" is relative to external code dir path.
-- If this part will be reused, consider externalizing this assumption, so we don't have it on multiple places.
, "from" .= buildImportPathFromPathInSrc
(extCodeDirInWebAppSrcDir </> castRelPathFromSrcToGenExtCodeDir (WJsImport.jsImportFrom jsImport))
(extCodeDirInWebAppSrcDir </> castRelPathFromSrcToGenExtCodeDir (WJsImport._from jsImport))
]
data PageDir

View File

@ -25,7 +25,7 @@ jsImport = do
-- We would need to write this from scratch, with single quote escaping enabled.
from <- Parser.ExternalCode.extCodeFilePathString
return Wasp.JsImport.JsImport
{ Wasp.JsImport.jsImportDefaultImport = defaultImport
, Wasp.JsImport.jsImportNamedImports = namedImports
, Wasp.JsImport.jsImportFrom = from
{ Wasp.JsImport._defaultImport = defaultImport
, Wasp.JsImport._namedImports = namedImports
, Wasp.JsImport._from = from
}

View File

@ -11,14 +11,14 @@ import ExternalCode (SourceExternalCodeDir)
-- | Represents javascript import -> "import <what> from <from>".
data JsImport = JsImport
{ jsImportDefaultImport :: !(Maybe String)
, jsImportNamedImports :: ![String]
, jsImportFrom :: !(Path (Rel SourceExternalCodeDir) File)
{ _defaultImport :: !(Maybe String)
, _namedImports :: ![String]
, _from :: !(Path (Rel SourceExternalCodeDir) File)
} deriving (Show, Eq)
instance ToJSON JsImport where
toJSON jsImport = object
[ "defaultImport" .= jsImportDefaultImport jsImport
, "namedImports" .= jsImportNamedImports jsImport
, "from" .= SP.toFilePath (jsImportFrom jsImport)
[ "defaultImport" .= _defaultImport jsImport
, "namedImports" .= _namedImports jsImport
, "from" .= SP.toFilePath (_from jsImport)
]

View File

@ -123,9 +123,9 @@ spec_parseWasp =
, WaspElementQuery $ Wasp.Query.Query
{ Wasp.Query._name = "myQuery"
, Wasp.Query._jsFunction = Wasp.JsImport.JsImport
{ Wasp.JsImport.jsImportDefaultImport = Nothing
, Wasp.JsImport.jsImportNamedImports = [ "myJsQuery" ]
, Wasp.JsImport.jsImportFrom = SP.fromPathRelFile [P.relfile|some/path|]
{ Wasp.JsImport._defaultImport = Nothing
, Wasp.JsImport._namedImports = [ "myJsQuery" ]
, Wasp.JsImport._from = SP.fromPathRelFile [P.relfile|some/path|]
}
}
]

View File

@ -23,9 +23,9 @@ spec_parseQuery =
let testQuery = Wasp.Query.Query
{ Wasp.Query._name = testQueryName
, Wasp.Query._jsFunction = Wasp.JsImport.JsImport
{ Wasp.JsImport.jsImportDefaultImport = Nothing
, Wasp.JsImport.jsImportNamedImports = [ testQueryJsFunctionName ]
, Wasp.JsImport.jsImportFrom = testQueryJsFunctionFrom
{ Wasp.JsImport._defaultImport = Nothing
, Wasp.JsImport._namedImports = [ testQueryJsFunctionName ]
, Wasp.JsImport._from = testQueryJsFunctionFrom
}
}
parseQuery ( "query " ++ testQueryName ++ " {\n" ++