mirror of
https://github.com/github/semantic.git
synced 2024-11-28 10:15:55 +03:00
Merge pull request #2044 from github/js-exports
Eval `export function ...` in JavaScript
This commit is contained in:
commit
989cf32231
@ -10,7 +10,7 @@ import Prologue
|
|||||||
import Proto3.Suite.Class
|
import Proto3.Suite.Class
|
||||||
|
|
||||||
data Function a = Function { functionContext :: ![a], functionName :: !a, functionParameters :: ![a], functionBody :: !a }
|
data Function a = Function { functionContext :: ![a], functionName :: !a, functionParameters :: ![a], functionBody :: !a }
|
||||||
deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Mergeable, FreeVariables1, Declarations1, ToJSONFields1, Named1, Message1)
|
deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Mergeable, FreeVariables1, ToJSONFields1, Named1, Message1)
|
||||||
|
|
||||||
instance Diffable Function where
|
instance Diffable Function where
|
||||||
equivalentBySubterm = Just . functionName
|
equivalentBySubterm = Just . functionName
|
||||||
@ -33,6 +33,11 @@ instance Evaluatable Function where
|
|||||||
instance Declarations a => Declarations (Function a) where
|
instance Declarations a => Declarations (Function a) where
|
||||||
declaredName Function{..} = declaredName functionName
|
declaredName Function{..} = declaredName functionName
|
||||||
|
|
||||||
|
instance Declarations1 Function where
|
||||||
|
liftDeclaredName declaredName Function{..} =
|
||||||
|
case declaredName functionName of
|
||||||
|
[] -> Nothing
|
||||||
|
(x:_) -> Just x
|
||||||
|
|
||||||
data Method a = Method { methodContext :: ![a], methodReceiver :: !a, methodName :: !a, methodParameters :: ![a], methodBody :: !a }
|
data Method a = Method { methodContext :: ![a], methodReceiver :: !a, methodName :: !a, methodParameters :: ![a], methodBody :: !a }
|
||||||
deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Mergeable, FreeVariables1, Declarations1, ToJSONFields1, Named1, Message1)
|
deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Mergeable, FreeVariables1, Declarations1, ToJSONFields1, Named1, Message1)
|
||||||
|
@ -270,10 +270,10 @@ instance Show1 DefaultExport where liftShowsPrec = genericLiftShowsPrec
|
|||||||
|
|
||||||
instance Evaluatable DefaultExport where
|
instance Evaluatable DefaultExport where
|
||||||
eval (DefaultExport term) = do
|
eval (DefaultExport term) = do
|
||||||
v <- subtermValue term
|
|
||||||
case declaredName term of
|
case declaredName term of
|
||||||
Just name -> do
|
Just name -> do
|
||||||
addr <- lookupOrAlloc name
|
addr <- lookupOrAlloc name
|
||||||
|
v <- subtermValue term
|
||||||
assign addr v
|
assign addr v
|
||||||
export name name Nothing
|
export name name Nothing
|
||||||
bind name addr
|
bind name addr
|
||||||
|
6
test/fixtures/javascript/analysis/exports/lib.js
vendored
Normal file
6
test/fixtures/javascript/analysis/exports/lib.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export function square(x) {
|
||||||
|
return x * x;
|
||||||
|
}
|
||||||
|
export function area(x, y) {
|
||||||
|
return x * y;
|
||||||
|
}
|
3
test/fixtures/javascript/analysis/exports/main.js
vendored
Normal file
3
test/fixtures/javascript/analysis/exports/main.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { square, area } from 'lib';
|
||||||
|
console.log(square(11)); // 121
|
||||||
|
console.log(area(4, 3)); // 12
|
Loading…
Reference in New Issue
Block a user