@@ -66,51 +66,62 @@ pub async fn get_decorators_transform_options(
66
66
) -> Result < Vc < DecoratorsOptions > > {
67
67
let tsconfig = get_typescript_options ( project_path) . await ?;
68
68
69
- let decorators_transform_options = if let Some ( tsconfig) = tsconfig {
70
- read_from_tsconfigs ( & tsconfig, |json, _| {
71
- let decorators_kind = if json[ "compilerOptions" ] [ "experimentalDecorators" ]
72
- . as_bool ( )
73
- . unwrap_or ( false )
74
- {
75
- Some ( DecoratorsKind :: Legacy )
76
- } else {
77
- // ref: https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-rc/#differences-with-experimental-legacy-decorators
78
- // `without the flag, decorators will now be valid syntax for all new code.
79
- // Outside of --experimentalDecorators, they will be type-checked and emitted
80
- // differently with ts 5.0, new ecma decorators will be enabled
81
- // if legacy decorators are not enabled
82
- Some ( DecoratorsKind :: Ecma )
83
- } ;
84
-
85
- let emit_decorators_metadata = if let Some ( decorators_kind) = & decorators_kind {
86
- match decorators_kind {
87
- DecoratorsKind :: Legacy => {
88
- // ref: This new decorators proposal is not compatible with
89
- // --emitDecoratorMetadata, and it does not allow decorating parameters.
90
- // Future ECMAScript proposals may be able to help bridge that gap
91
- json[ "compilerOptions" ] [ "emitDecoratorMetadata" ]
92
- . as_bool ( )
93
- . unwrap_or ( false )
94
- }
95
- DecoratorsKind :: Ecma => false ,
96
- }
97
- } else {
98
- false
99
- } ;
100
-
101
- Some ( DecoratorsOptions {
102
- decorators_kind,
103
- emit_decorators_metadata,
104
- use_define_for_class_fields : json[ "compilerOptions" ] [ "useDefineForClassFields" ]
105
- . as_bool ( )
106
- . unwrap_or ( false ) ,
107
- ..Default :: default ( )
108
- } )
69
+ let experimental_decorators = if let Some ( ref tsconfig) = tsconfig {
70
+ read_from_tsconfigs ( tsconfig, |json, _| {
71
+ json[ "compilerOptions" ] [ "experimentalDecorators" ] . as_bool ( )
109
72
} )
110
73
. await ?
111
- . unwrap_or_default ( )
74
+ . unwrap_or ( false )
75
+ } else {
76
+ false
77
+ } ;
78
+
79
+ let decorators_kind = if experimental_decorators {
80
+ Some ( DecoratorsKind :: Legacy )
112
81
} else {
113
- Default :: default ( )
82
+ // ref: https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-rc/#differences-with-experimental-legacy-decorators
83
+ // `without the flag, decorators will now be valid syntax for all new code.
84
+ // Outside of --experimentalDecorators, they will be type-checked and emitted
85
+ // differently with ts 5.0, new ecma decorators will be enabled
86
+ // if legacy decorators are not enabled
87
+ Some ( DecoratorsKind :: Ecma )
88
+ } ;
89
+
90
+ let emit_decorators_metadata = if let Some ( ref tsconfig) = tsconfig {
91
+ read_from_tsconfigs ( tsconfig, |json, _| {
92
+ json[ "compilerOptions" ] [ "emitDecoratorMetadata" ] . as_bool ( )
93
+ } )
94
+ . await ?
95
+ . unwrap_or ( false )
96
+ } else {
97
+ false
98
+ } ;
99
+
100
+ let use_define_for_class_fields = if let Some ( ref tsconfig) = tsconfig {
101
+ read_from_tsconfigs ( tsconfig, |json, _| {
102
+ json[ "compilerOptions" ] [ "useDefineForClassFields" ] . as_bool ( )
103
+ } )
104
+ . await ?
105
+ . unwrap_or ( false )
106
+ } else {
107
+ false
108
+ } ;
109
+
110
+ let decorators_transform_options = DecoratorsOptions {
111
+ decorators_kind : decorators_kind. clone ( ) ,
112
+ emit_decorators_metadata : if let Some ( ref decorators_kind) = decorators_kind {
113
+ match decorators_kind {
114
+ DecoratorsKind :: Legacy => emit_decorators_metadata,
115
+ // ref: This new decorators proposal is not compatible with
116
+ // --emitDecoratorMetadata, and it does not allow decorating parameters.
117
+ // Future ECMAScript proposals may be able to help bridge that gap
118
+ DecoratorsKind :: Ecma => false ,
119
+ }
120
+ } else {
121
+ false
122
+ } ,
123
+ use_define_for_class_fields,
124
+ ..Default :: default ( )
114
125
} ;
115
126
116
127
Ok ( decorators_transform_options. cell ( ) )
0 commit comments