MCPcopy
hub / github.com/facebook/react / parseOptions

Function parseOptions

compiler/apps/playground/components/Editor/EditorImpl.tsx:138–190  ·  view source on GitHub ↗
(
  source: string,
  mode: 'compiler' | 'linter',
  configOverrides: string,
)

Source from the content-addressed store, hash-verified

136];
137
138function parseOptions(
139 source: string,
140 mode: 'compiler' | 'linter',
141 configOverrides: string,
142): PluginOptions {
143 // Extract the first line to quickly check for custom test directives
144 const pragma = source.substring(0, source.indexOf('\n'));
145
146 const parsedPragmaOptions = parseConfigPragmaForTests(pragma, {
147 compilationMode: 'infer',
148 environment:
149 mode === 'linter'
150 ? {
151 // enabled in compiler
152 validateRefAccessDuringRender: false,
153 // enabled in linter
154 validateNoSetStateInRender: true,
155 validateNoSetStateInEffects: true,
156 validateNoJSXInTryStatements: true,
157 validateNoImpureFunctionsInRender: true,
158 validateStaticComponents: true,
159 validateNoFreezingKnownMutableFunctions: true,
160 validateNoVoidUseMemo: true,
161 }
162 : {
163 /* use defaults for compiler mode */
164 },
165 });
166
167 // Parse config overrides from config editor
168 let configOverrideOptions: any = {};
169 const configMatch = configOverrides.match(/^\s*import.*?\n\n\((.*)\)/s);
170 if (configOverrides.trim()) {
171 if (configMatch && configMatch[1]) {
172 const configString = configMatch[1].replace(/satisfies.*$/, '').trim();
173 configOverrideOptions = new Function(`return (${configString})`)();
174 } else {
175 throw new Error('Invalid override format');
176 }
177 }
178
179 const opts: PluginOptions = parsePluginOptions({
180 ...parsedPragmaOptions,
181 ...configOverrideOptions,
182 environment: {
183 ...parsedPragmaOptions.environment,
184 ...configOverrideOptions.environment,
185 customHooks: new Map([...COMMON_HOOKS]),
186 },
187 });
188
189 return opts;
190}
191
192function compile(
193 source: string,

Callers 1

compileFunction · 0.85

Calls 2

parsePluginOptionsFunction · 0.90

Tested by

no test coverage detected