diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-12-07 12:59:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-07 12:59:59 -0500 |
commit | f4385866f89e0abd3f5f1b0281abf00f1c562be9 (patch) | |
tree | 3400cc38b77f1217250d671481a4113e141a80f9 /cli/build.rs | |
parent | 791e623c321dd9cc73263a64aa848af0111a812b (diff) |
feat: upgrade to TypeScript 4.9.3 (#16973)
Updated from: https://github.com/denoland/TypeScript/pull/2
Diffstat (limited to 'cli/build.rs')
-rw-r--r-- | cli/build.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/cli/build.rs b/cli/build.rs index d87021a6d..a92ba21d0 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -259,17 +259,24 @@ mod ts { } pub(crate) fn version() -> String { - std::fs::read_to_string("tsc/00_typescript.js") - .unwrap() - .lines() - .find(|l| l.contains("ts.version = ")) - .expect( - "Failed to find the pattern `ts.version = ` in typescript source code", - ) - .chars() - .skip_while(|c| !char::is_numeric(*c)) - .take_while(|c| *c != '"') - .collect::<String>() + let file_text = std::fs::read_to_string("tsc/00_typescript.js").unwrap(); + let mut version = String::new(); + for line in file_text.lines() { + let major_minor_text = "ts.versionMajorMinor = \""; + let version_text = "ts.version = \"\".concat(ts.versionMajorMinor, \""; + if version.is_empty() { + if let Some(index) = line.find(major_minor_text) { + let remaining_line = &line[index + major_minor_text.len()..]; + version + .push_str(&remaining_line[..remaining_line.find('"').unwrap()]); + } + } else if let Some(index) = line.find(version_text) { + let remaining_line = &line[index + version_text.len()..]; + version.push_str(&remaining_line[..remaining_line.find('"').unwrap()]); + return version; + } + } + panic!("Could not find ts version.") } } |