Implement a polyfill attribute for imports

Allow using imported APIs under alternative names, such as prefixed
names, for web APIs when the exact API differs across browsers.
This commit is contained in:
Alex Crichton
2018-09-28 13:17:37 -07:00
parent 11bcaf42d5
commit 3c14f7a6eb
11 changed files with 172 additions and 2 deletions

View File

@ -503,7 +503,16 @@ impl<'src> FirstPassRecord<'src> {
doc_comment: None,
instanceof_shim: format!("__widl_instanceof_{}", name),
extends: Vec::new(),
polyfills: Vec::new(),
};
// whitelist a few names that have known polyfills
match name {
"AudioContext" => {
import_type.polyfills.push(Ident::new("webkitAudioContext", Span::call_site()));
}
_ => {}
}
let extra = camel_case_ident(name);
let extra = &[&extra[..]];
self.append_required_features_doc(&import_type, &mut doc_comment, extra);