mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-11-27 14:55:20 +03:00
Shortened Wasp.JsImport fields.
This commit is contained in:
parent
495ba96284
commit
ce6cf2bc5a
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
]
|
||||
|
@ -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|]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -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" ++
|
||||
|
Loading…
Reference in New Issue
Block a user