Skip to content

Commit 775e061

Browse files
authored
new sumtype for map value, handle import alias (#144)
1 parent a5d2456 commit 775e061

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

ast.v

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import os
55

66
type Decls = FuncDecl | GenDecl
77

8+
type MapVal = Ident | InterfaceType | SelectorExpr
9+
810
type Expr = InvalidExpr
911
| ArrayType
1012
| FuncType
@@ -108,7 +110,7 @@ struct ArrayType {
108110
struct MapType {
109111
node_type string @[json: '_type']
110112
key Expr @[json: 'Key']
111-
val Expr @[json: 'Value']
113+
val MapVal @[json: 'Value']
112114
}
113115

114116
struct ChanType {

expr.v

+8-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,14 @@ fn (mut app App) map_type(node MapType) {
188188
app.gen('map[')
189189
app.expr(node.key)
190190
app.gen(']')
191-
app.expr(node.val)
191+
match node.val {
192+
Ident, InterfaceType {
193+
app.typ(node.val)
194+
}
195+
SelectorExpr {
196+
app.expr(node.val)
197+
}
198+
}
192199
}
193200

194201
fn (mut app App) chan_type(node ChanType) {

struct.v

+14-3
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,32 @@ fn (mut app App) const_decl(spec ValueSpec) {
112112
const master_module_path = 'g.yxqyang.asia.evanw.esbuild.internal' // TODO hardcoded
113113

114114
fn (mut app App) import_spec(spec ImportSpec) {
115-
name := spec.path.value.replace('"', '').replace('/', '.')
115+
mut name := spec.path.value.replace('"', '').replace('/', '.')
116116
// Skip modules that don't exist in V (fmt, strings etc)
117117
if name in nonexistent_modules {
118118
return
119119
}
120+
if name == 'archive.zip' {
121+
name = 'compress.zip'
122+
}
120123
if name.starts_with(master_module_path) {
121124
n := name.replace(master_module_path, '')
122-
app.genln('import ${n[1..]} // local module')
125+
app.gen('import ${n[1..]}')
126+
if spec.name.name != '' {
127+
app.gen(' as ${spec.name.name}')
128+
}
129+
app.genln(' // local module')
123130
return
124131
}
125132
// TODO a temp hack
126133
if name.starts_with('github') {
127134
return
128135
}
129-
app.genln('import ${name}')
136+
app.gen('import ${name}')
137+
if spec.name.name != '' {
138+
app.gen(' as ${spec.name.name}')
139+
}
140+
app.genln('')
130141
}
131142

132143
fn (mut app App) struct_decl(struct_name string, spec StructType) {

0 commit comments

Comments
 (0)