Skip to content

Commit 588ca58

Browse files
committed
Allow connecting providers and modules in components.
1 parent ababc2b commit 588ca58

File tree

5 files changed

+65
-11
lines changed

5 files changed

+65
-11
lines changed

spec/compilers/connect_module

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module A {
2+
fun value : String {
3+
""
4+
}
5+
}
6+
7+
component Main {
8+
connect A exposing { value }
9+
10+
fun render {
11+
value()
12+
}
13+
}
14+
--------------------------------------------------------------------------------
15+
export const
16+
a = () => {
17+
return ``
18+
},
19+
A = () => {
20+
return a()
21+
};

spec/compilers/connect_provider

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
type S {
2+
a : String
3+
}
4+
5+
provider A : S {
6+
fun value : String {
7+
""
8+
}
9+
}
10+
11+
component Main {
12+
connect A exposing { value }
13+
14+
fun render {
15+
value()
16+
}
17+
}
18+
--------------------------------------------------------------------------------
19+
import { createProvider as A } from "./runtime.js";
20+
21+
export const
22+
a = () => {
23+
return ``
24+
},
25+
b = new Map(),
26+
B = A(b, () => {
27+
return null
28+
}),
29+
C = () => {
30+
return a()
31+
};

src/ls/definitions/connect_variable.cr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ module Mint
88
@stack[1]?.as?(Ast::Connect)
99

1010
return unless store =
11-
@type_checker.artifacts.ast.stores
12-
.find(&.name.value.==(connect.store.value))
11+
@type_checker.artifacts.ast.unified_modules.find(&.name.value.==(connect.store.value)) ||
12+
@type_checker.artifacts.ast.providers.find(&.name.value.==(connect.store.value)) ||
13+
@type_checker.artifacts.ast.stores.find(&.name.value.==(connect.store.value))
1314

1415
return unless target =
15-
store.functions.find(&.name.value.==(node.name.value)) ||
16-
store.constants.find(&.name.value.==(node.name.value)) ||
17-
store.states.find(&.name.value.==(node.name.value)) ||
18-
store.gets.find(&.name.value.==(node.name.value))
16+
@type_checker.artifacts.scope.resolve(node.name.value, store).try(&.node)
1917

2018
case target
2119
when Ast::Function, Ast::State, Ast::Get, Ast::Constant

src/scope.cr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,18 @@ module Mint
4848
end
4949

5050
# Resolves the targets which can be statically resolved, currently only
51-
# the exposed variables of a connected store in a component.
51+
# the exposed variables of a connected entity in a component.
5252
def resolve
5353
scopes.each do |node, stack|
5454
next unless node.is_a?(Ast::Component)
5555

5656
node.connects.each do |connect|
57-
case store = @ast.stores.find(&.name.value.==(connect.store.value))
58-
when Ast::Store
57+
if item =
58+
@ast.unified_modules.find(&.name.value.==(connect.store.value)) ||
59+
@ast.providers.find(&.name.value.==(connect.store.value)) ||
60+
@ast.stores.find(&.name.value.==(connect.store.value))
5961
connect.keys.each do |key|
60-
scopes[store][1].items[key.name.value]?.try do |value|
62+
scopes[item][1].items[key.name.value]?.try do |value|
6163
stack[1].items[key.target.try(&.value) || key.name.value] = value
6264
end
6365
end

src/type_checkers/connect.cr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ module Mint
22
class TypeChecker
33
def check(node : Ast::Connect) : Checkable
44
store =
5-
ast.stores.find(&.name.value.==(node.store.value))
5+
ast.unified_modules.find(&.name.value.==(node.store.value)) ||
6+
ast.providers.find(&.name.value.==(node.store.value)) ||
7+
ast.stores.find(&.name.value.==(node.store.value))
68

79
error! :connect_not_found_store do
810
block do

0 commit comments

Comments
 (0)