Skip to content

Commit 918234a

Browse files
committed
Fixes.
1 parent a94595b commit 918234a

21 files changed

+258
-61
lines changed

spec/compilers2/defer_2

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Data {
2+
const ITEMS = defer [ defer ITEM_1 ]
3+
const ITEM_1 = "Hello"
4+
}
5+
6+
component Main {
7+
fun componentDidMount : Promise(String) {
8+
let [item] = await Data.ITEMS or return ""
9+
await item
10+
}
11+
12+
fun render : Html {
13+
<div>""</div>
14+
}
15+
}
16+
--------------------------------------------------------------------------------
17+
---=== /index.js ===---
18+
import {
19+
patternVariable as E,
20+
createElement as F,
21+
destructure as C,
22+
useEffect as B,
23+
load as D
24+
} from "runtime";
25+
26+
export const
27+
a = `/__mint__/d5f8d9aa357303a4ba78b554c55d598bd238f679b.js`,
28+
A = () => {
29+
B(() => {
30+
(async () => {
31+
const b = C(await D(a), [E]);
32+
if (b === false) {
33+
return ``
34+
};
35+
const [c] = b;
36+
return await D(c)
37+
})()
38+
}, []);
39+
return F(`div`, {}, [``])
40+
};
41+
42+
---=== /__mint__/d96571c631d11ed793b887a131e80107a65e05223.js ===---
43+
export const
44+
a = `Hello`,
45+
b = a;
46+
47+
export default b;
48+
49+
---=== /__mint__/d5f8d9aa357303a4ba78b554c55d598bd238f679b.js ===---
50+
export const a = [`/__mint__/d96571c631d11ed793b887a131e80107a65e05223.js`];
51+
52+
export default a;
53+
Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
component Main {
22
fun render : Html {
33
<<#MARKDOWN(highlight)
4+
\#{name}
45
```mint
6+
`Something`
7+
"\#{name}"
58
"First line" \
69
"Second line" \
710
"Third line"
@@ -16,35 +19,59 @@ import {
1619
} from "runtime";
1720

1821
export const A = () => {
19-
return B(C, {}, [B('pre', {}, [B('code', {
20-
class: "language-mint"
21-
}, [
22-
B('span', {
23-
className: "line"
22+
return B(C, {}, [
23+
B('p', {}, [`#{name}`]),
24+
B('pre', {}, [B('code', {
25+
class: "language-mint"
2426
}, [
2527
B('span', {
26-
className: "string"
27-
}, [`"First line" \\`]),
28-
`
28+
className: "line"
29+
}, [`\`Something\`
30+
`]),
31+
B('span', {
32+
className: "line"
33+
}, [
34+
``,
35+
B('span', {
36+
className: "string"
37+
}, [`"#{`]),
38+
B('span', {
39+
className: "variable"
40+
}, [`name`]),
41+
B('span', {
42+
className: "string"
43+
}, [`}"`]),
44+
`
2945
`
30-
]),
31-
B('span', {
32-
className: "line"
33-
}, [
34-
``,
46+
]),
3547
B('span', {
36-
className: "string"
37-
}, [`"Second line" \\`]),
38-
`
48+
className: "line"
49+
}, [
50+
``,
51+
B('span', {
52+
className: "string"
53+
}, [`"First line" \`]),
54+
`
3955
`
40-
]),
41-
B('span', {
42-
className: "line"
43-
}, [
44-
``,
56+
]),
57+
B('span', {
58+
className: "line"
59+
}, [
60+
``,
61+
B('span', {
62+
className: "string"
63+
}, [`"Second line" \`]),
64+
`
65+
`
66+
]),
4567
B('span', {
46-
className: "string"
47-
}, [`"Third line"`])
48-
])
49-
])])])
68+
className: "line"
69+
}, [
70+
``,
71+
B('span', {
72+
className: "string"
73+
}, [`"Third line"`])
74+
])
75+
])])
76+
])
5077
};

spec/compilers2/store_with_get

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ component Main {
1111

1212
fun render : String {
1313
xxx
14+
Test.hello
1415
}
1516
}
1617
--------------------------------------------------------------------------------
@@ -22,6 +23,7 @@ export const
2223
return `hello`
2324
},
2425
B = () => {
25-
return a.value
26+
a.value;
27+
return b()
2628
};
2729

spec/compilers2/string_literal_escaped

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ component Main {
55
}
66
--------------------------------------------------------------------------------
77
export const A = () => {
8-
return `Hello There \"Joe\"`
8+
return `Hello There "Joe"`
99
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
component Main {
2+
fun render : String {
3+
"Hello There \#{name}"
4+
}
5+
}
6+
--------------------------------------------------------------------------------
7+
export const A = () => {
8+
return `Hello There #{name}`
9+
};

src/compiler2/js.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Mint
2626
end
2727

2828
def string(value : String) : Compiled
29-
["`", Raw.new(value), "`"] of Item
29+
["`", Raw.new(value.gsub('`', "\\`").gsub("${", "\\${`")), "`"] of Item
3030
end
3131

3232
# Renders an object destructuring.

src/compiler2/program.cr

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,33 @@ module Mint
1313
end
1414
end
1515

16+
def self.dbg_name(node)
17+
case x = node
18+
when Ast::Component
19+
"<#{x.name.value}>"
20+
when Ast::Module, Ast::Store, Ast::Provider
21+
x.name.value
22+
when Ast::Function, Ast::Constant, Ast::Get, Ast::State
23+
"#{dbg_name(x.parent)}.#{x.name.value}"
24+
when Ast::Block
25+
"{block}"
26+
when Ast::Access
27+
"{access .#{x.field.value}}"
28+
when Ast::Statement
29+
name =
30+
case target = x.target
31+
when Ast::Variable
32+
" #{target.value}"
33+
end
34+
35+
"{statement#{name}}"
36+
when Ast::Route
37+
"{route #{x.url}}"
38+
else
39+
x.class.name
40+
end
41+
end
42+
1643
def self.program(
1744
artifacts : TypeChecker::Artifacts,
1845
config : Config
@@ -105,6 +132,25 @@ module Mint
105132
end
106133
end
107134

135+
# bundles.each do |node, items|
136+
# entities =
137+
# items.compact_map do |item|
138+
# if item[0] == node
139+
# next if node.is_a?(Ast::Defer)
140+
# else
141+
# next if item[0].is_a?(Ast::Component) &&
142+
# item[0].as(Ast::Component).async?
143+
# end
144+
145+
# dbg_name(item[0])
146+
# end
147+
148+
# puts bundle_name(node)
149+
# entities.sort.each do |item|
150+
# puts " > #{item}"
151+
# end
152+
# end
153+
108154
# Add not already added items to the main bundle.
109155
bundles[nil].concat(compiler.compiled)
110156

src/compiler2/utils.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ module Mint
5959
parts.map do |item|
6060
case item
6161
in String
62-
["`", Raw.new(item.escape_for_javascript), "`"] of Item
62+
js.string(item)
6363
in Tuple(SemanticTokenizer::TokenType, String)
6464
js.call(Builtin::CreateElement, [
6565
[%("span")] of Item,
6666
js.object({"className".as(Item) => [
6767
%("#{item[0].to_s.underscore}"),
6868
] of Item}),
69-
js.array([["`", Raw.new(item[1].escape_for_javascript), "`"] of Item]),
69+
js.array([js.string(item[1])]),
7070
])
7171
end
7272
end

src/compilers2/directives/format.cr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ module Mint
99
Formatter.new
1010
.format(node.content, Formatter::BlockFormat::Naked)
1111
.gsub('\\', "\\\\")
12-
.gsub('`', "\\`")
13-
.gsub("${", "\\${")
1412

1513
js.array([content, js.string(formatted)])
1614
end

src/compilers2/env.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Mint
33
def compile(node : Ast::Env) : Compiled
44
compile node do
55
value =
6-
MINT_ENV[node.name].to_s.gsub('`', "\\`")
6+
MINT_ENV[node.name].to_s
77

88
js.string(value)
99
end

0 commit comments

Comments
 (0)