Skip to content

Commit eb3c655

Browse files
authored
feat(BREAKING): remove explicit resource management pass (#300)
1 parent bb6604f commit eb3c655

File tree

2 files changed

+17
-108
lines changed

2 files changed

+17
-108
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ parsed_source.module();
3333
parsed_source.text_info();
3434
```
3535

36+
## Versioning Strategy
37+
38+
This crate does not follow semver so make sure to pin it to a patch version.
39+
Instead a versioning strategy that optimizes for more efficient maintenance is
40+
used:
41+
42+
- Does [deno_graph](https://github.com/denoland/deno_graph),
43+
[deno_doc](https://github.com/denoland/deno_doc),
44+
[deno_lint](https://github.com/denoland/deno_lint),
45+
[eszip](https://github.com/denoland/eszip), and
46+
[dprint-plugin-typescript](https://github.com/dprint/dprint-plugin-typescript)
47+
still compile in the [Deno](https://github.com/denoland/deno) repo?
48+
- If yes, is this a change that would break something at runtime?
49+
- If yes, it's recommended to do a minor release.
50+
- If no, it's a patch release.
51+
- If no, it's a minor release.
52+
3653
## swc upgrades
3754

3855
We upgrade swc about once a month. Upgrading swc is a very involved process that

src/transpiling/mod.rs

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ pub fn fold_program<'a>(
678678
proposal::decorator_2022_03::decorator_2022_03(),
679679
options.use_decorators_proposal,
680680
),
681-
proposal::explicit_resource_management::explicit_resource_management(),
682681
helpers::inject_helpers(marks.top_level),
683682
// transform imports to var decls before doing the typescript pass
684683
// so that swc doesn't do any optimizations on the import declarations
@@ -983,113 +982,6 @@ var N;
983982
assert!(transpiled_source.source_map.is_none());
984983
}
985984

986-
#[test]
987-
fn test_explicit_resource_management() {
988-
let specifier =
989-
ModuleSpecifier::parse("https://deno.land/x/mod.ts").unwrap();
990-
let source = "using data = create();\nconsole.log(data);";
991-
let program = parse_program(ParseParams {
992-
specifier,
993-
text: source.into(),
994-
media_type: MediaType::TypeScript,
995-
capture_tokens: false,
996-
maybe_syntax: None,
997-
scope_analysis: false,
998-
})
999-
.unwrap();
1000-
let transpiled_source = program
1001-
.transpile(
1002-
&TranspileOptions::default(),
1003-
&TranspileModuleOptions::default(),
1004-
&EmitOptions::default(),
1005-
)
1006-
.unwrap()
1007-
.into_source();
1008-
let expected_text = r#"function _ts_add_disposable_resource(env, value, async) {
1009-
if (value !== null && value !== void 0) {
1010-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
1011-
var dispose, inner;
1012-
if (async) {
1013-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
1014-
dispose = value[Symbol.asyncDispose];
1015-
}
1016-
if (dispose === void 0) {
1017-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
1018-
dispose = value[Symbol.dispose];
1019-
if (async) inner = dispose;
1020-
}
1021-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
1022-
if (inner) dispose = function() {
1023-
try {
1024-
inner.call(this);
1025-
} catch (e) {
1026-
return Promise.reject(e);
1027-
}
1028-
};
1029-
env.stack.push({
1030-
value: value,
1031-
dispose: dispose,
1032-
async: async
1033-
});
1034-
} else if (async) {
1035-
env.stack.push({
1036-
async: true
1037-
});
1038-
}
1039-
return value;
1040-
}
1041-
function _ts_dispose_resources(env) {
1042-
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
1043-
var e = new Error(message);
1044-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1045-
};
1046-
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
1047-
function fail(e) {
1048-
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
1049-
env.hasError = true;
1050-
}
1051-
var r, s = 0;
1052-
function next() {
1053-
while(r = env.stack.pop()){
1054-
try {
1055-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
1056-
if (r.dispose) {
1057-
var result = r.dispose.call(r.value);
1058-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
1059-
fail(e);
1060-
return next();
1061-
});
1062-
} else s |= 1;
1063-
} catch (e) {
1064-
fail(e);
1065-
}
1066-
}
1067-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
1068-
if (env.hasError) throw env.error;
1069-
}
1070-
return next();
1071-
})(env);
1072-
}
1073-
const env = {
1074-
stack: [],
1075-
error: void 0,
1076-
hasError: false
1077-
};
1078-
try {
1079-
var data = _ts_add_disposable_resource(env, create(), false);
1080-
console.log(data);
1081-
} catch (e) {
1082-
env.error = e;
1083-
env.hasError = true;
1084-
} finally{
1085-
_ts_dispose_resources(env);
1086-
}"#;
1087-
assert_eq!(
1088-
&transpiled_source.text[..expected_text.len()],
1089-
expected_text
1090-
);
1091-
}
1092-
1093985
#[test]
1094986
fn test_transpile_tsx() {
1095987
let specifier =

0 commit comments

Comments
 (0)