diff --git a/src/Data/Syntax/Declaration.hs b/src/Data/Syntax/Declaration.hs index d6a5d4eeb..3529b1f83 100644 --- a/src/Data/Syntax/Declaration.hs +++ b/src/Data/Syntax/Declaration.hs @@ -251,13 +251,20 @@ instance Show1 Comprehension where liftShowsPrec = genericLiftShowsPrec instance (MonadFail m) => Eval t v m Comprehension -- | Import declarations. -data Import a = Import { importFrom :: !a, importAlias :: !a, importSymbols :: !a } +data Import a = Import { importFrom :: !a, importAlias :: !a, importSymbols :: ![a] } deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1) instance Eq1 Import where liftEq = genericLiftEq instance Ord1 Import where liftCompare = genericLiftCompare instance Show1 Import where liftShowsPrec = genericLiftShowsPrec +data ImportSymbol a = ImportSymbol { importSymbolName :: !a, importSymbolAlias :: !a } + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1) + +instance Eq1 ImportSymbol where liftEq = genericLiftEq +instance Ord1 ImportSymbol where liftCompare = genericLiftCompare +instance Show1 ImportSymbol where liftShowsPrec = genericLiftShowsPrec + -- TODO: Implement Eval instance for Import instance (MonadFail m) => Eval t v m Import diff --git a/src/Language/Go/Assignment.hs b/src/Language/Go/Assignment.hs index d35ca2a16..418575147 100644 --- a/src/Language/Go/Assignment.hs +++ b/src/Language/Go/Assignment.hs @@ -390,8 +390,8 @@ importDeclaration :: Assignment importDeclaration = mk <$> symbol ImportDeclaration <*> children (manyTerm (importSpec <|> importSpecList)) where importSpec = makeTerm <$> symbol ImportSpec <*> children (namedImport <|> plainImport) - namedImport = flip Declaration.Import <$> expression <*> expression <*> emptyTerm - plainImport = Declaration.Import <$> expression <*> emptyTerm <*> emptyTerm + namedImport = flip Declaration.Import <$> expression <*> expression <*> pure [] + plainImport = Declaration.Import <$> expression <*> emptyTerm <*> pure [] importSpecList = makeTerm <$> symbol ImportSpecList <*> children (manyTerm (importSpec <|> comment)) mk _ [child] = child mk location children = makeTerm location children diff --git a/src/Language/Python/Assignment.hs b/src/Language/Python/Assignment.hs index f1412ee07..878f7d818 100644 --- a/src/Language/Python/Assignment.hs +++ b/src/Language/Python/Assignment.hs @@ -377,10 +377,10 @@ comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source) import' :: Assignment import' = mk <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport)) - <|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> expression <*> emptyTerm <*> (wildCard <|> expressions)) + <|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> expression <*> emptyTerm <*> (pure <$> (wildCard <|> expressions))) where - aliasedImport = makeTerm <$> symbol AliasedImport <*> children (Declaration.Import <$> expression <*> expression <*> emptyTerm) - plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> expression <*> emptyTerm <*> emptyTerm) + aliasedImport = makeTerm <$> symbol AliasedImport <*> children (Declaration.Import <$> expression <*> expression <*> pure []) + plainImport = makeTerm <$> symbol DottedName <*> children (Declaration.Import <$> expression <*> emptyTerm <*> pure []) wildCard = makeTerm <$> symbol WildcardImport <*> (Syntax.Identifier <$> source) mk _ [child] = child mk location children = makeTerm location children diff --git a/src/Language/TypeScript/Assignment.hs b/src/Language/TypeScript/Assignment.hs index 0f5aefbe0..b1b67f201 100644 --- a/src/Language/TypeScript/Assignment.hs +++ b/src/Language/TypeScript/Assignment.hs @@ -166,6 +166,7 @@ type Syntax = '[ , TypeScript.Syntax.Update , TypeScript.Syntax.ComputedPropertyName , TypeScript.Syntax.Decorator + , Declaration.ImportSymbol , [] ]