mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
jsgen: export module through commonjs (#5895)
This commit is contained in:
parent
88c8e194d0
commit
1a5236e53d
@ -87,8 +87,9 @@ pub fn gen(files []ast.File, table &table.Table, pref &pref.Preferences) string
|
|||||||
}
|
}
|
||||||
// resolve imports
|
// resolve imports
|
||||||
deps_resolved := graph.resolve()
|
deps_resolved := graph.resolve()
|
||||||
|
nodes := deps_resolved.nodes
|
||||||
mut out := g.hashes() + g.definitions.str()
|
mut out := g.hashes() + g.definitions.str()
|
||||||
for node in deps_resolved.nodes {
|
for node in nodes {
|
||||||
name := g.js_name(node.name).replace('.', '_')
|
name := g.js_name(node.name).replace('.', '_')
|
||||||
if g.enable_doc {
|
if g.enable_doc {
|
||||||
out += '/** @namespace $name */\n'
|
out += '/** @namespace $name */\n'
|
||||||
@ -129,6 +130,11 @@ pub fn gen(files []ast.File, table &table.Table, pref &pref.Preferences) string
|
|||||||
}
|
}
|
||||||
out += ');\n\n'
|
out += ');\n\n'
|
||||||
}
|
}
|
||||||
|
if pref.is_shared {
|
||||||
|
// Export, through CommonJS, the module of the entry file if `-shared` was passed
|
||||||
|
export := nodes[nodes.len - 1].name
|
||||||
|
out += 'if (typeof module === "object" && module.exports) module.exports = $export;'
|
||||||
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user