Enable nested namespace (#951) (#2105)

* Enable nested namespace (#951)

* Specify the namespace as array (#951)

* added an example to the document

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
This commit is contained in:
Hajime Fukuda
2020-05-27 08:36:20 -07:00
committed by GitHub
parent e0ad7bfeac
commit 87663c6d2a
11 changed files with 144 additions and 24 deletions

View File

@ -1998,7 +1998,7 @@ impl<'a> Context<'a> {
JsImportName::VendorPrefixed { name, prefixes } => {
self.imports_post.push_str("const l");
self.imports_post.push_str(&name);
self.imports_post.push_str(name);
self.imports_post.push_str(" = ");
switch(&mut self.imports_post, name, "", prefixes);
self.imports_post.push_str(";\n");

View File

@ -898,7 +898,7 @@ impl<'a> Context<'a> {
"import of `{}` through js namespace `{}` isn't supported \
right now when it lists a polyfill",
item,
ns
ns.join(".")
);
}
return Ok(JsImport {
@ -911,8 +911,12 @@ impl<'a> Context<'a> {
}
let (name, fields) = match import.js_namespace {
Some(ns) => (ns, vec![item.to_string()]),
None => (item, Vec::new()),
Some(ref ns) => {
let mut tail = (&ns[1..]).to_owned();
tail.push(item.to_string());
(ns[0].to_owned(), tail)
}
None => (item.to_owned(), Vec::new()),
};
let name = match import.module {