@@ -104,9 +104,6 @@ pub struct TranspileOptions {
104104 /// TC39 Decorators Proposal - https://github.com/tc39/proposal-decorators
105105 pub use_decorators_proposal : bool ,
106106
107- // Explicit resource management proposal - https://github.com/tc39/proposal-explicit-resource-management
108- pub use_explicit_resource_management : bool ,
109-
110107 /// When emitting a legacy decorator, also emit experimental decorator meta
111108 /// data. Defaults to `false`.
112109 pub emit_metadata : bool ,
@@ -157,7 +154,6 @@ impl Default for TranspileOptions {
157154 TranspileOptions {
158155 use_ts_decorators : false ,
159156 use_decorators_proposal : false ,
160- use_explicit_resource_management : false ,
161157 emit_metadata : false ,
162158 verbatim_module_syntax : false ,
163159 imports_not_used_as_values : ImportsNotUsedAsValues :: Remove ,
@@ -678,10 +674,6 @@ pub fn fold_program(
678674 proposal:: decorator_2022_03:: decorator_2022_03( ) ,
679675 options. use_decorators_proposal,
680676 ) ,
681- Optional :: new(
682- proposal:: explicit_resource_management:: explicit_resource_management( ) ,
683- options. use_explicit_resource_management
684- ) ,
685677 helpers:: inject_helpers( marks. top_level) ,
686678 // transform imports to var decls before doing the typescript pass
687679 // so that swc doesn't do any optimizations on the import declarations
@@ -990,108 +982,6 @@ export class A {
990982 assert ! ( transpiled_source. source_map. is_none( ) ) ;
991983 }
992984
993- #[ test]
994- fn test_explicit_resource_management ( ) {
995- let specifier =
996- ModuleSpecifier :: parse ( "https://deno.land/x/mod.ts" ) . unwrap ( ) ;
997- let source = "using data = create();\n console.log(data);" ;
998- let program = parse_program ( ParseParams {
999- specifier,
1000- text : source. into ( ) ,
1001- media_type : MediaType :: TypeScript ,
1002- capture_tokens : false ,
1003- maybe_syntax : None ,
1004- scope_analysis : false ,
1005- } )
1006- . unwrap ( ) ;
1007- let transpiled_source = program
1008- . transpile (
1009- & TranspileOptions {
1010- use_explicit_resource_management : true ,
1011- ..Default :: default ( )
1012- } ,
1013- & TranspileModuleOptions :: default ( ) ,
1014- & EmitOptions :: default ( ) ,
1015- )
1016- . unwrap ( )
1017- . into_source ( ) ;
1018- let expected_text = r#"function _using_ctx() {
1019- var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
1020- var err = new Error();
1021- err.name = "SuppressedError";
1022- err.suppressed = suppressed;
1023- err.error = error;
1024- return err;
1025- }, empty = {}, stack = [];
1026- function using(isAwait, value) {
1027- if (value != null) {
1028- if (Object(value) !== value) {
1029- throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
1030- }
1031- if (isAwait) {
1032- var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
1033- }
1034- if (dispose == null) {
1035- dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
1036- }
1037- if (typeof dispose !== "function") {
1038- throw new TypeError(`Property [Symbol.dispose] is not a function.`);
1039- }
1040- stack.push({
1041- v: value,
1042- d: dispose,
1043- a: isAwait
1044- });
1045- } else if (isAwait) {
1046- stack.push({
1047- d: value,
1048- a: isAwait
1049- });
1050- }
1051- return value;
1052- }
1053- return {
1054- e: empty,
1055- u: using.bind(null, false),
1056- a: using.bind(null, true),
1057- d: function() {
1058- var error = this.e;
1059- function next() {
1060- while(resource = stack.pop()){
1061- try {
1062- var resource, disposalResult = resource.d && resource.d.call(resource.v);
1063- if (resource.a) {
1064- return Promise.resolve(disposalResult).then(next, err);
1065- }
1066- } catch (e) {
1067- return err(e);
1068- }
1069- }
1070- if (error !== empty) throw error;
1071- }
1072- function err(e) {
1073- error = error !== empty ? new _disposeSuppressedError(error, e) : e;
1074- return next();
1075- }
1076- return next();
1077- }
1078- };
1079- }
1080- try {
1081- var _usingCtx = _using_ctx();
1082- var data = _usingCtx.u(create());
1083- console.log(data);
1084- } catch (_) {
1085- _usingCtx.e = _;
1086- } finally{
1087- _usingCtx.d();
1088- }"# ;
1089- assert_eq ! (
1090- & transpiled_source. text[ ..expected_text. len( ) ] ,
1091- expected_text
1092- ) ;
1093- }
1094-
1095985 #[ test]
1096986 fn test_transpile_tsx ( ) {
1097987 let specifier =
0 commit comments