1
1
mirror of https://github.com/github/semantic.git synced 2024-12-15 01:51:39 +03:00

Update TypeScript and JavaScript scope / frames for qualified imports

Co-Authored-By: Josh Vera <vera@github.com>
This commit is contained in:
Rick Winfrey 2018-11-27 15:12:16 -08:00
parent 07c1b2202b
commit 4317960df3
2 changed files with 22 additions and 16 deletions

View File

@ -11,7 +11,9 @@ import Data.JSON.Fields
import Diffing.Algorithm
import Language.TypeScript.Resolution
import Control.Abstract.ScopeGraph hiding (Import)
import Control.Abstract.Heap
import qualified Data.Abstract.ScopeGraph as ScopeGraph
import qualified Data.Map.Strict as Map
data JavaScriptRequire a = JavaScriptRequire { javascriptRequireIden :: !a, javascriptRequireFrom :: ImportPath }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Message1, NFData1, Named1, Ord, Show, ToJSONFields1, Traversable)
@ -23,17 +25,20 @@ instance Show1 JavaScriptRequire where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable JavaScriptRequire where
eval _ (JavaScriptRequire aliasTerm importPath) = do
modulePath <- resolveWithNodejsStrategy importPath javascriptExtensions
(scopeGraph, _) <- require modulePath
-- alias <- maybeM (throwEvalError NoNameError) (declaredName aliasTerm)
-- rvalBox =<< evalRequire modulePath alias
(moduleScope, (moduleFrame, _)) <- require modulePath
case declaredName aliasTerm of
Just alias -> do
span <- get @Span
void $ declare (Declaration alias) span (ScopeGraph.currentScope scopeGraph) -- TODO: declare shouldn't return a fake (Address address)
span <- ask @Span
importScope <- newScope (Map.singleton ScopeGraph.Import [ moduleScope ])
declare (Declaration alias) span (Just importScope)
let scopeMap = Map.singleton moduleScope moduleFrame
aliasFrame <- newFrame importScope (Map.singleton ScopeGraph.Import scopeMap)
aliasSlot <- lookupDeclaration (Declaration alias)
assign aliasSlot =<< object aliasFrame
Nothing -> do
-- TODO: Throw a resumable exception if no current scope in imported scope graph.
-- Or better yet get rid of the Maybe in ScopeGraph { currentScope :: Maybe scope, ... }
maybe (pure ()) insertImportEdge (ScopeGraph.currentScope scopeGraph)
insertImportEdge moduleScope
insertFrameLink ScopeGraph.Import (Map.singleton moduleScope moduleFrame)
rvalBox unit
data Debugger a = Debugger

View File

@ -57,19 +57,20 @@ instance Show1 QualifiedAliasedImport where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable QualifiedAliasedImport where
eval _ (QualifiedAliasedImport aliasTerm importPath) = do
modulePath <- resolveWithNodejsStrategy importPath typescriptExtensions
alias <- maybeM (throwEvalError NoNameError) (declaredName aliasTerm)
span <- ask @Span
(moduleScope, (moduleFrame, _)) <- require modulePath
declare (Declaration alias) span (Just moduleScope)
aliasSlot <- lookupDeclaration (Declaration alias)
span <- ask @Span
insertImportEdge moduleScope
let scopeMap = Map.singleton moduleScope moduleFrame
insertFrameLink ScopeGraph.Import scopeMap
importScope <- newScope (Map.singleton ScopeGraph.Import [ moduleScope ])
let scopeMap = Map.singleton moduleScope moduleFrame
aliasFrame <- newFrame importScope (Map.singleton ScopeGraph.Import scopeMap)
alias <- maybeM (throwEvalError NoNameError) (declaredName aliasTerm)
declare (Declaration alias) span (Just importScope)
aliasSlot <- lookupDeclaration (Declaration alias)
assign aliasSlot =<< object aliasFrame
pure (LvalMember aliasSlot)
rvalBox unit
newtype SideEffectImport a = SideEffectImport { sideEffectImportFrom :: ImportPath }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Message1, NFData1, Named1, Ord, Show, ToJSONFields1, Traversable)