(&mut self, script: Script)
| 118 | } |
| 119 | |
| 120 | pub fn compile_add_script(&mut self, script: Script) -> Result<ScriptState, String> { |
| 121 | let prefixed_source = prepend_script_source_header(&script.original_source, Some(&script)); |
| 122 | |
| 123 | match tscompiler::compile_typescript( |
| 124 | &prefixed_source, |
| 125 | script_url(&script, "ts").to_string(), |
| 126 | ) { |
| 127 | Ok(compiled) => { |
| 128 | let item = ScriptState { |
| 129 | compiled: Some(compiled), |
| 130 | url: script_url(&script, "js"), |
| 131 | script, |
| 132 | state: ScriptLoadState::Unloaded, |
| 133 | }; |
| 134 | |
| 135 | self.scripts.push(item.clone()); |
| 136 | |
| 137 | Ok(item) |
| 138 | } |
| 139 | Err(e) => { |
| 140 | let item = ScriptState { |
| 141 | compiled: None, |
| 142 | url: script_url(&script, "js"), |
| 143 | script, |
| 144 | state: ScriptLoadState::FailedCompilation, |
| 145 | }; |
| 146 | |
| 147 | self.scripts.push(item.clone()); |
| 148 | |
| 149 | Err(e) |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | pub fn set_state(&mut self, script_id: u64, new_state: ScriptLoadState) { |
| 155 | if let Some(current) = self.get_script_mut(script_id) { |
no test coverage detected