@@ -74,6 +74,15 @@ fn has_import_meta_env_member_definition(parser: &JavascriptParser, name: &str)
7474 || has_import_meta_env_object_definition ( parser. compilation_id )
7575}
7676
77+ fn import_meta_env_definitions_expression ( parser : & JavascriptParser , start : u32 ) -> String {
78+ let definitions = import_meta_env_definitions_string ( parser. compilation_id ) ;
79+ if parser. is_asi_position ( start) {
80+ format ! ( ";({definitions})" )
81+ } else {
82+ format ! ( "({definitions})" )
83+ }
84+ }
85+
7786fn create_import_meta_resolve_context_dependency (
7887 parser : & mut JavascriptParser ,
7988 param : & BasicEvaluatedExpression ,
@@ -575,7 +584,7 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for ImportMetaPlugin {
575584 add_import_meta_env_value_dependency ( parser) ;
576585 parser. add_presentational_dependency ( Box :: new ( ConstDependency :: new (
577586 member_expr. span ( ) . into ( ) ,
578- import_meta_env_definitions_string ( parser. compilation_id ) . into ( ) ,
587+ import_meta_env_definitions_expression ( parser, member_expr . span ( ) . real_lo ( ) ) . into ( ) ,
579588 ) ) ) ;
580589 Some ( true )
581590 } else if for_name == expr_name:: IMPORT_META_VERSION {
@@ -623,7 +632,7 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for ImportMetaPlugin {
623632 add_import_meta_env_value_dependency ( parser) ;
624633 parser. add_presentational_dependency ( Box :: new ( ConstDependency :: new (
625634 expr. span ( ) . into ( ) ,
626- import_meta_env_definitions_string ( parser. compilation_id ) . into ( ) ,
635+ import_meta_env_definitions_expression ( parser, expr . span ( ) . real_lo ( ) ) . into ( ) ,
627636 ) ) ) ;
628637 return Some ( true ) ;
629638 }
0 commit comments