{"id":"3ba4fbabde474b83","repo":"babel/babel","slug":"experimental-preserveformat-is-not-compatible-wi-3ba4fb","errorCode":null,"errorMessage":"`experimental_preserveFormat` is not compatible with the `jsescOption` option","messagePattern":"`experimental_preserveFormat` is not compatible with the `jsescOption` option","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/babel-generator/src/index.ts","lineNumber":46,"sourceCode":"      );\n    }\n    if (!opts.retainLines) {\n      throw new Error(\n        \"`experimental_preserveFormat` requires `retainLines` to be set to `true`\",\n      );\n    }\n    if (opts.compact && opts.compact !== \"auto\") {\n      throw new Error(\n        \"`experimental_preserveFormat` is not compatible with the `compact` option\",\n      );\n    }\n    if (opts.minified) {\n      throw new Error(\n        \"`experimental_preserveFormat` is not compatible with the `minified` option\",\n      );\n    }\n    if (opts.jsescOption) {\n      throw new Error(\n        \"`experimental_preserveFormat` is not compatible with the `jsescOption` option\",\n      );\n    }\n    if (!Array.isArray((ast as any).tokens)) {\n      throw new Error(\n        \"`experimental_preserveFormat` requires the AST to have attached the token of the input code. Make sure to enable the `tokens: true` parser option.\",\n      );\n    }\n  }\n\n  const format: Format = {\n    auxiliaryCommentBefore: opts.auxiliaryCommentBefore,\n    auxiliaryCommentAfter: opts.auxiliaryCommentAfter,\n    // @ts-expect-error define it later\n    shouldPrintComment: opts.shouldPrintComment,\n    preserveFormat: opts.experimental_preserveFormat,\n    retainLines: opts.retainLines,\n    retainFunctionParens: opts.retainFunctionParens,","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/babel/babel/blob/06b6eae39da4ce0689fad64e2c48a6375a464208/packages/babel-generator/src/index.ts#L28-L64","documentation":"`jsescOption` customizes string escaping, which would alter the exact bytes preserveFormat is meant to retain. At index.ts:45-49, if `experimental_preserveFormat` is on and `jsescOption` is set, the generator throws.","triggerScenarios":"Passing both `experimental_preserveFormat: true` and a `jsescOption` object.","commonSituations":"Carrying over quote/escape preferences from an existing generator config into a preserveFormat pipeline.","solutions":["Remove the `jsescOption` from generator options when using experimental_preserveFormat."],"exampleFix":"// before\ngenerate(ast, { experimental_preserveFormat: true, jsescOption: { quotes: 'single' }, retainLines: true }, code);\n\n// after\ngenerate(ast, { experimental_preserveFormat: true, retainLines: true }, code);","handlingStrategy":"validation","validationCode":"function assertPreserveFormatCompatible(opts) {\n  if (opts.experimental_preserveFormat && opts.jsescOption) {\n    throw new Error('experimental_preserveFormat is incompatible with jsescOption');\n  }\n}","typeGuard":"const preserveFormatJsescOk = (opts) =>\n  !opts.experimental_preserveFormat || !opts.jsescOption;","tryCatchPattern":"try {\n  generate(ast, opts, code);\n} catch (err) {\n  if (/not compatible with the .jsescOption. option/.test(err.message)) {\n    const { jsescOption, ...rest } = opts;\n    generate(ast, rest, code);\n  } else throw err;\n}","preventionTips":["Drop jsescOption when preserving format.","Use a single option-normalization helper to catch all preserveFormat conflicts."],"tags":["babel-generator","preserve-format","config"],"analyzedSha":"06b6eae39da4ce0689fad64e2c48a6375a464208","analyzedAt":"2026-08-03T20:13:43.465Z","schemaVersion":2}