Repository: parcel-bundler/parcel
File: packages/transformers/js/core/src/lib.rs (Rust)

Code before:
              if let Some(jsx_pragma) = &config.jsx_pragma {
                react_options.pragma = jsx_pragma.clone();
              }
              if let Some(jsx_pragma_frag) = &config.jsx_pragma_frag {
                react_options.pragma_frag = jsx_pragma_frag.clone();
              }
              react_options.development = config.is_development;
              react_options.refresh = if config.react_refresh {
                Some(react::RefreshOptions::default())
              } else {
                None
              };

              react_options.runtime = if config.automatic_jsx_runtime {
                if let Some(import_source) = &config.jsx_import_source {
                  react_options.import_source = import_source.clone();
                }
                Some(react::Runtime::Automatic)
              } else {
                Some(react::Runtime::Classic)
              };
            }

            let global_mark = Mark::fresh(Mark::root());
            let ignore_mark = Mark::fresh(Mark::root());
            module = module.fold_with(&mut resolver_with_mark(global_mark));

            module = {
              let mut passes = chain!(
                Optional::new(
                  react::react(
                    source_map.clone(),
                    Some(&comments),
                    react_options,
                    global_mark
                  ),
                  config.is_jsx
                ),
                // Decorators can use type information, so must run before the TypeScript pass.
                Optional::new(
                  decorators::decorators(decorators::Config {
                    legacy: true,
                    // Always disabled for now, SWC's implementation doesn't match TSC.
                    emit_metadata: false
                  }),
                  config.decorators
                ),
                Optional::new(typescript::strip(), config.is_type_script)
              );

              module.fold_with(&mut passes)

Review comment (bug):
We just ran into this issue too. I think you can use `ts_resolver` here instead, which seemed to fix our issues (but maybe I'm wrong). I believe `resolver_with_mark` doesn't have any knowledge of typescript nodes.

Code after:
              if let Some(jsx_pragma) = &config.jsx_pragma {
                react_options.pragma = jsx_pragma.clone();
              }
              if let Some(jsx_pragma_frag) = &config.jsx_pragma_frag {
                react_options.pragma_frag = jsx_pragma_frag.clone();
              }
              react_options.development = config.is_development;
              react_options.refresh = if config.react_refresh {
                Some(react::RefreshOptions::default())
              } else {
                None
              };

              react_options.runtime = if config.automatic_jsx_runtime {
                if let Some(import_source) = &config.jsx_import_source {
                  react_options.import_source = import_source.clone();
                }
                Some(react::Runtime::Automatic)
              } else {
                Some(react::Runtime::Classic)
              };
            }

            let global_mark = Mark::fresh(Mark::root());
            let ignore_mark = Mark::fresh(Mark::root());
            module = {
              let mut passes = chain!(
                resolver_with_mark(global_mark),
                Optional::new(
                  react::react(
                    source_map.clone(),
                    Some(&comments),
                    react_options,
                    global_mark
                  ),
                  config.is_jsx
                ),
                // Decorators can use type information, so must run before the TypeScript pass.
                Optional::new(
                  decorators::decorators(decorators::Config {
                    legacy: true,
                    // Always disabled for now, SWC's implementation doesn't match TSC.
                    emit_metadata: false
                  }),
                  config.decorators
                ),
                Optional::new(typescript::strip(), config.is_type_script),
                // Run resolver again. TS pass messes things up.
                resolver_with_mark(global_mark),
              );