Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdotdesign committed Feb 12, 2024
1 parent a94595b commit 918234a
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 61 deletions.
53 changes: 53 additions & 0 deletions spec/compilers2/defer_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module Data {
const ITEMS = defer [ defer ITEM_1 ]
const ITEM_1 = "Hello"
}

component Main {
fun componentDidMount : Promise(String) {
let [item] = await Data.ITEMS or return ""
await item
}

fun render : Html {
<div>""</div>
}
}
--------------------------------------------------------------------------------
---=== /index.js ===---
import {
patternVariable as E,
createElement as F,
destructure as C,
useEffect as B,
load as D
} from "runtime";

export const
a = `/__mint__/d5f8d9aa357303a4ba78b554c55d598bd238f679b.js`,
A = () => {
B(() => {
(async () => {
const b = C(await D(a), [E]);
if (b === false) {
return ``
};
const [c] = b;
return await D(c)
})()
}, []);
return F(`div`, {}, [``])
};

---=== /__mint__/d96571c631d11ed793b887a131e80107a65e05223.js ===---
export const
a = `Hello`,
b = a;

export default b;

---=== /__mint__/d5f8d9aa357303a4ba78b554c55d598bd238f679b.js ===---
export const a = [`/__mint__/d96571c631d11ed793b887a131e80107a65e05223.js`];

export default a;

77 changes: 52 additions & 25 deletions spec/compilers2/here_doc_markdown_escape
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
component Main {
fun render : Html {
<<#MARKDOWN(highlight)
\#{name}
```mint
`Something`
"\#{name}"
"First line" \
"Second line" \
"Third line"
Expand All @@ -16,35 +19,59 @@ import {
} from "runtime";

export const A = () => {
return B(C, {}, [B('pre', {}, [B('code', {
class: "language-mint"
}, [
B('span', {
className: "line"
return B(C, {}, [
B('p', {}, [`#{name}`]),
B('pre', {}, [B('code', {
class: "language-mint"
}, [
B('span', {
className: "string"
}, [`"First line" \\`]),
`
className: "line"
}, [`\`Something\`
`]),
B('span', {
className: "line"
}, [
``,
B('span', {
className: "string"
}, [`"#{`]),
B('span', {
className: "variable"
}, [`name`]),
B('span', {
className: "string"
}, [`}"`]),
`
`
]),
B('span', {
className: "line"
}, [
``,
]),
B('span', {
className: "string"
}, [`"Second line" \\`]),
`
className: "line"
}, [
``,
B('span', {
className: "string"
}, [`"First line" \`]),
`
`
]),
B('span', {
className: "line"
}, [
``,
]),
B('span', {
className: "line"
}, [
``,
B('span', {
className: "string"
}, [`"Second line" \`]),
`
`
]),
B('span', {
className: "string"
}, [`"Third line"`])
])
])])])
className: "line"
}, [
``,
B('span', {
className: "string"
}, [`"Third line"`])
])
])])
])
};
4 changes: 3 additions & 1 deletion spec/compilers2/store_with_get
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ component Main {

fun render : String {
xxx
Test.hello
}
}
--------------------------------------------------------------------------------
Expand All @@ -22,6 +23,7 @@ export const
return `hello`
},
B = () => {
return a.value
a.value;
return b()
};

2 changes: 1 addition & 1 deletion spec/compilers2/string_literal_escaped
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ component Main {
}
--------------------------------------------------------------------------------
export const A = () => {
return `Hello There \"Joe\"`
return `Hello There "Joe"`
};
9 changes: 9 additions & 0 deletions spec/compilers2/string_literal_with_escaped_interpolation
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
component Main {
fun render : String {
"Hello There \#{name}"
}
}
--------------------------------------------------------------------------------
export const A = () => {
return `Hello There #{name}`
};
2 changes: 1 addition & 1 deletion src/compiler2/js.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Mint
end

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

# Renders an object destructuring.
Expand Down
46 changes: 46 additions & 0 deletions src/compiler2/program.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,33 @@ module Mint
end
end

def self.dbg_name(node)
case x = node
when Ast::Component
"<#{x.name.value}>"
when Ast::Module, Ast::Store, Ast::Provider
x.name.value
when Ast::Function, Ast::Constant, Ast::Get, Ast::State
"#{dbg_name(x.parent)}.#{x.name.value}"
when Ast::Block
"{block}"
when Ast::Access
"{access .#{x.field.value}}"
when Ast::Statement
name =
case target = x.target
when Ast::Variable
" #{target.value}"
end

"{statement#{name}}"
when Ast::Route
"{route #{x.url}}"
else
x.class.name
end
end

def self.program(
artifacts : TypeChecker::Artifacts,
config : Config
Expand Down Expand Up @@ -105,6 +132,25 @@ module Mint
end
end

# bundles.each do |node, items|
# entities =
# items.compact_map do |item|
# if item[0] == node
# next if node.is_a?(Ast::Defer)
# else
# next if item[0].is_a?(Ast::Component) &&
# item[0].as(Ast::Component).async?
# end

# dbg_name(item[0])
# end

# puts bundle_name(node)
# entities.sort.each do |item|
# puts " > #{item}"
# end
# end

# Add not already added items to the main bundle.
bundles[nil].concat(compiler.compiled)

Expand Down
4 changes: 2 additions & 2 deletions src/compiler2/utils.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ module Mint
parts.map do |item|
case item
in String
["`", Raw.new(item.escape_for_javascript), "`"] of Item
js.string(item)
in Tuple(SemanticTokenizer::TokenType, String)
js.call(Builtin::CreateElement, [
[%("span")] of Item,
js.object({"className".as(Item) => [
%("#{item[0].to_s.underscore}"),
] of Item}),
js.array([["`", Raw.new(item[1].escape_for_javascript), "`"] of Item]),
js.array([js.string(item[1])]),
])
end
end
Expand Down
2 changes: 0 additions & 2 deletions src/compilers2/directives/format.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module Mint
Formatter.new
.format(node.content, Formatter::BlockFormat::Naked)
.gsub('\\', "\\\\")
.gsub('`', "\\`")
.gsub("${", "\\${")

js.array([content, js.string(formatted)])
end
Expand Down
2 changes: 1 addition & 1 deletion src/compilers2/env.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Mint
def compile(node : Ast::Env) : Compiled
compile node do
value =
MINT_ENV[node.name].to_s.gsub('`', "\\`")
MINT_ENV[node.name].to_s

js.string(value)
end
Expand Down
1 change: 1 addition & 0 deletions src/compilers2/here_doc.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Mint
.lchop('\r')
.lchop("\n\r")
.rstrip
.gsub("\\\#{", "\#{")

if node.modifier == '#'
document =
Expand Down
6 changes: 3 additions & 3 deletions src/compilers2/js.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ module Mint
value =
node.value.flat_map do |entity|
case entity
when Ast::Node
in Ast::Node
compile entity
else
entity
in String
entity.gsub("\\`", '`')
end
end

Expand Down
4 changes: 3 additions & 1 deletion src/compilers2/string_literal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module Mint
[
item
.gsub('`', "\\`")
.gsub("${", "\\${"),
.gsub("${", "\\${")
.gsub("\\\"", "\"")
.gsub("\\\#{", "\#{"),
]
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/js.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Mint
when Ast::Interpolation
item.source
else
format(item).gsub('`', "\\`")
format(item)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/parsers/js.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Mint

value =
many(parse_whitespace: false) do
raw('`').try(&.gsub("\\`", '`')) || interpolation
raw('`') || interpolation
end

next error :js_expected_closing_tick do
Expand Down
9 changes: 7 additions & 2 deletions src/parsers/operator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ module Mint
next unless operator
next if operator != "|>" && !whitespace?

ast.operators << {saved_position, saved_position + operator.size}
whitespace
case operator
when "or"
ast.keywords << {saved_position, saved_position + operator.size}
else
ast.operators << {saved_position, saved_position + operator.size}
end

whitespace
operator
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/reactor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module Mint
workspace = Workspace.current
workspace.format = auto_format
workspace.check_env = true
workspace.check_everything = true
workspace.check_everything = false

workspace.on "change" do |result|
case result
Expand Down
Loading

0 comments on commit 918234a

Please sign in to comment.