11cb0ef41Sopenharmony_ciconst DATA_URL_PATTERN = /^data:application\/json(?:[^,]*?)(;base64)?,([\s\S]*)$/;
21cb0ef41Sopenharmony_ciconst JSON_URL_PATTERN = /^[^?]+\.json(\?[^#]*)?(#.*)?$/;
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciexport async function resolve(specifier, context, next) {
51cb0ef41Sopenharmony_ci  const noAttributesSpecified = context.importAttributes.type == null;
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci  // Mutation from resolve hook should be discarded.
81cb0ef41Sopenharmony_ci  context.importAttributes.type = 'whatever';
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci  // This fixture assumes that no other resolve hooks in the chain will error on invalid import attributes
111cb0ef41Sopenharmony_ci  // (as defaultResolve doesn't).
121cb0ef41Sopenharmony_ci  const result = await next(specifier, context);
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  if (noAttributesSpecified &&
151cb0ef41Sopenharmony_ci      (DATA_URL_PATTERN.test(result.url) || JSON_URL_PATTERN.test(result.url))) {
161cb0ef41Sopenharmony_ci    // Clean new import attributes object to ensure that this test isn't passing due to mutation.
171cb0ef41Sopenharmony_ci    result.importAttributes = {
181cb0ef41Sopenharmony_ci      ...(result.importAttributes ?? context.importAttributes),
191cb0ef41Sopenharmony_ci      type: 'json',
201cb0ef41Sopenharmony_ci    };
211cb0ef41Sopenharmony_ci  }
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  return result;
241cb0ef41Sopenharmony_ci}
25