8000 Merge pull request #447 from github/js-ts-modules · github/semantic@966824f · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 966824f

Browse files
authored
Merge pull request #447 from github/js-ts-modules
Properly tag Module in TSX and TypeScript
2 parents 4a1b0ed + b582152 commit 966824f

File tree

2 files changed

+28
-2
lines changed
  • semantic-tsx/src/Language/TSX
  • semantic-typescript/src/Language/TypeScript

2 files changed

+28
-2
lines changed

semantic-tsx/src/Language/TSX/Tags.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ instance ToTags Tsx.Class where
100100
} = yieldTag text Class loc byteRange >> gtags t
101101
tags t = gtags t
102102

103+
instance ToTags Tsx.Module where
104+
tags t@Tsx.Module
105+
{ ann = loc@Loc { byteRange }
106+
, name
107+
} = match name
108+
where
109+
match expr = case expr of
110+
Prj Tsx.Identifier { text } -> yield text
111+
-- TODO: Handle NestedIdentifiers and Strings
112+
-- Prj Tsx.NestedIdentifier { extraChildren } -> match
113+
_ -> gtags t
114+
yield text = yieldTag text Module loc byteRange >> gtags t
115+
103116
instance (ToTags l, ToTags r) => ToTags (l :+: r) where
104117
tags (L1 l) = tags l
105118
tags (R1 r) = tags r
@@ -222,7 +235,7 @@ instance ToTags Tsx.MemberExpression
222235
instance ToTags Tsx.MetaProperty
223236
-- instance ToTags Tsx.MethodDefinition
224237
instance ToTags Tsx.MethodSignature
225-
instance ToTags Tsx.Module
238+
-- instance ToTags Tsx.Module
226239
instance ToTags Tsx.NamedImports
227240
instance ToTags Tsx.NamespaceImport
228241
instance ToTags Tsx.NestedIdentifier

semantic-typescript/src/Language/TypeScript/Tags.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ instance ToTags Ts.CallExpression where
9393
_ -> gtags t
9494
yield name = yieldTag name Call loc byteRange >> gtags t
9595

96+
instance ToTags Ts.Module where
97+
tags t@Ts.Module
98+
{ ann = loc@Loc { byteRange }
99+
, name
100+
} = match name
101+
where
102+
match expr = case expr of
103+
Prj Ts.Identifier { text } -> yield text
104+
-- TODO: Handle NestedIdentifiers and Strings
105+
-- Prj Tsx.NestedIdentifier { extraChildren } -> match
106+
_ -> gtags t
107+
yield text = yieldTag text Module loc byteRange >> gtags t
108+
96109
instance (ToTags l, ToTags r) => ToTags (l :+: r) where
97110
tags (L1 l) = tags l
98111
tags (R1 r) = tags r
@@ -215,7 +228,7 @@ instance ToTags Ts.MemberExpression
215228
instance ToTags Ts.MetaProperty
216229
-- instance ToTags Ts.MethodDefinition
217230
instance ToTags Ts.MethodSignature
218-
instance ToTags Ts.Module
231+
-- instance ToTags Ts.Module
219232
instance ToTags Ts.NamedImports
220233
instance ToTags Ts.NamespaceImport
221234
instance ToTags Ts.NestedIdentifier

0 commit comments

Comments
 (0)
0