mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 23:30:00 -04:00
handle a bunch of extra logic
This commit is contained in:
parent
e0a16f1c60
commit
39d880cbca
1 changed files with 34 additions and 4 deletions
|
@ -426,6 +426,7 @@ pub fn rewrite(
|
||||||
// dbg!(&program);
|
// dbg!(&program);
|
||||||
ast_pass.visit_program(&program);
|
ast_pass.visit_program(&program);
|
||||||
|
|
||||||
|
let mut hoists = String::new();
|
||||||
if !module {
|
if !module {
|
||||||
for s in &program.body {
|
for s in &program.body {
|
||||||
if let Statement::VariableDeclaration(it) = s {
|
if let Statement::VariableDeclaration(it) = s {
|
||||||
|
@ -437,11 +438,39 @@ pub fn rewrite(
|
||||||
text: String::new(),
|
text: String::new(),
|
||||||
});
|
});
|
||||||
for d in &it.declarations {
|
for d in &it.declarations {
|
||||||
|
let Some(id) = d.id.get_identifier() else {
|
||||||
|
continue; // destructures are todo
|
||||||
|
};
|
||||||
|
if d.init.is_some() {
|
||||||
ast_pass.jschanges.push(JsChange::GenericChange {
|
ast_pass.jschanges.push(JsChange::GenericChange {
|
||||||
span: Span::new(d.id.span().start, d.id.span().start),
|
span: Span::new(d.id.span().start, d.id.span().start),
|
||||||
text: "fakeVars.".to_string(),
|
text: "fakeVars.".to_string(),
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
ast_pass.jschanges.push(JsChange::GenericChange {
|
||||||
|
span: Span::new(d.id.span().start, d.id.span().end),
|
||||||
|
text: format!("fakeVars.{}??=undefined", id),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
hoists += &format!(";fakeVars.{}??=undefined;", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO the function stuff breaks easily if you overwrite it
|
||||||
|
if let Statement::FunctionDeclaration(it) = s {
|
||||||
|
let Some(id) = &it.id else { continue };
|
||||||
|
ast_pass.jschanges.push(JsChange::GenericChange {
|
||||||
|
span: Span::new(it.span.end, it.span.end),
|
||||||
|
text: format!(";fakeVars.{}={};", id, id),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Statement::ClassDeclaration(it) = s {
|
||||||
|
let Some(id) = &it.id else { continue };
|
||||||
|
ast_pass.jschanges.push(JsChange::GenericChange {
|
||||||
|
span: Span::new(it.span.end, it.span.end),
|
||||||
|
text: format!(";fakeVars.{}={};", id, id),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -491,6 +520,7 @@ pub fn rewrite(
|
||||||
|
|
||||||
let size_estimate = (original_len as i32 + difference) as usize;
|
let size_estimate = (original_len as i32 + difference) as usize;
|
||||||
let mut buffer: Vec<u8> = Vec::with_capacity(size_estimate);
|
let mut buffer: Vec<u8> = Vec::with_capacity(size_estimate);
|
||||||
|
buffer.extend_from_slice(hoists.as_bytes());
|
||||||
|
|
||||||
let mut sourcemap: Vec<u8> = Vec::new();
|
let mut sourcemap: Vec<u8> = Vec::new();
|
||||||
if ast_pass.config.do_sourcemaps {
|
if ast_pass.config.do_sourcemaps {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue