File tree 9 files changed +114
-17
lines changed
swc/tests/fixture/issues-8xxx
swc_ecma_transforms_proposal
tests/explicit-resource-management/issue-10329
9 files changed +114
-17
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ swc_core : patch
3
+ swc_ecma_transforms_proposal : patch
4
+ ---
5
+
6
+ fix(es/proposal): Fix scope of declarations for ` explicit-resource-management `
Original file line number Diff line number Diff line change 9
9
const foo = _ts_add_disposable_resource . _ ( env , null , false ) ;
10
10
const bar = 1 ;
11
11
console . log ( baz ( ) ) ;
12
+ function baz ( ) {
13
+ return bar ;
14
+ }
12
15
} catch ( e ) {
13
16
env . error = e ;
14
17
env . hasError = true ;
15
18
} finally {
16
19
_ts_dispose_resources . _ ( env ) ;
17
20
}
18
- function baz ( ) {
19
- return bar ;
20
- }
Original file line number Diff line number Diff line change @@ -16,14 +16,14 @@ function main() {
16
16
} ;
17
17
try {
18
18
const file = _ts_add_disposable_resource . _ ( env , new File ( ) , false ) ;
19
+ function readFile ( ) {
20
+ file . read ( ) ;
21
+ }
19
22
readFile ( ) ;
20
23
} catch ( e ) {
21
24
env . error = e ;
22
25
env . hasError = true ;
23
26
} finally {
24
27
_ts_dispose_resources . _ ( env ) ;
25
28
}
26
- function readFile ( ) {
27
- file . read ( ) ;
28
- }
29
29
}
Original file line number Diff line number Diff line change @@ -135,20 +135,20 @@ impl ExplicitResourceManagement {
135
135
136
136
for stmt in stmts. take ( ) {
137
137
match stmt. try_into_stmt ( ) {
138
- Ok ( mut stmt) => {
139
- if matches ! ( stmt , Stmt :: Decl ( Decl :: Fn ( _ ) ) | Stmt :: Decl ( Decl :: Class ( _ ) ) ) {
140
- // function declarations should preserve original level
138
+ Ok ( mut stmt) => match stmt {
139
+ // top level function/class declarations should preserve original level
140
+ Stmt :: Decl ( Decl :: Fn ( .. ) | Decl :: Class ( .. ) ) if ! self . is_not_top_level => {
141
141
extras. push ( stmt. into ( ) ) ;
142
- } else {
143
- if !self . is_not_top_level {
144
- if let Stmt :: Decl ( Decl :: Var ( ref mut var) ) = stmt {
145
- // top level variable declarations should hoist
146
- var. kind = VarDeclKind :: Var ;
147
- }
148
- }
142
+ }
143
+ // top level variable declarations should hoist from inner scope
144
+ Stmt :: Decl ( Decl :: Var ( ref mut var) ) if !self . is_not_top_level => {
145
+ var. kind = VarDeclKind :: Var ;
149
146
try_block. stmts . push ( stmt) ;
150
147
}
151
- }
148
+ _ => {
149
+ try_block. stmts . push ( stmt) ;
150
+ }
151
+ } ,
152
152
Err ( t) => extras. push ( t) ,
153
153
}
154
154
}
Original file line number Diff line number Diff line change
1
+ async function httpServerStreamingResponse ( ) {
2
+ function periodicStream ( ) {
3
+ console . log ( counter ) ;
4
+ }
5
+
6
+ let counter = 0 ;
7
+ await using server = test ;
8
+ }
Original file line number Diff line number Diff line change
1
+ async function httpServerStreamingResponse ( ) {
2
+ const env = {
3
+ stack : [ ] ,
4
+ error : void 0 ,
5
+ hasError : false
6
+ } ;
7
+ try {
8
+ function periodicStream ( ) {
9
+ console . log ( counter ) ;
10
+ }
11
+ let counter = 0 ;
12
+ const server = _ts_add_disposable_resource ( env , test , true ) ;
13
+ } catch ( e ) {
14
+ env . error = e ;
15
+ env . hasError = true ;
16
+ } finally {
17
+ const result = _ts_dispose_resources ( env ) ;
18
+ if ( result ) await result ;
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ async function httpServerStreamingResponse ( ) {
2
+ function periodicStream ( ) {
3
+ console . log ( counter ) ;
4
+ }
5
+
6
+ let counter = 0 ;
7
+ await using server = test ;
8
+ }
9
+
10
+ function periodicStream ( ) {
11
+ console . log ( counter ) ;
12
+ }
13
+
14
+ export function periodicStream2 ( ) {
15
+ console . log ( counter ) ;
16
+ }
17
+
18
+ let counter = 0 ;
19
+ await using server = test ;
Original file line number Diff line number Diff line change
1
+ const env = {
2
+ stack : [ ] ,
3
+ error : void 0 ,
4
+ hasError : false
5
+ } ;
6
+ try {
7
+ var counter = 0 ;
8
+ var server = _ts_add_disposable_resource ( env , test , true ) ;
9
+ } catch ( e ) {
10
+ env . error = e ;
11
+ env . hasError = true ;
12
+ } finally {
13
+ const result = _ts_dispose_resources ( env ) ;
14
+ if ( result ) await result ;
15
+ }
16
+ async function httpServerStreamingResponse ( ) {
17
+ const env = {
18
+ stack : [ ] ,
19
+ error : void 0 ,
20
+ hasError : false
21
+ } ;
22
+ try {
23
+ function periodicStream ( ) {
24
+ console . log ( counter ) ;
25
+ }
26
+ let counter = 0 ;
27
+ const server = _ts_add_disposable_resource ( env , test , true ) ;
28
+ } catch ( e ) {
29
+ env . error = e ;
30
+ env . hasError = true ;
31
+ } finally {
32
+ const result = _ts_dispose_resources ( env ) ;
33
+ if ( result ) await result ;
34
+ }
35
+ }
36
+ function periodicStream ( ) {
37
+ console . log ( counter ) ;
38
+ }
39
+ export function periodicStream2 ( ) {
40
+ console . log ( counter ) ;
41
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "plugins" : [" proposal-explicit-resource-management" ]
3
+ }
You can’t perform that action at this time.
0 commit comments