Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,23 @@ export function compileProgram(
}
}

/**
* Otherwise if 'use no forget/memo' is present, we still run the code through the compiler
* for validation but we don't mutate the babel AST. This allows us to flag if there is an
* unused 'use no forget/memo' directive.
*/
if (pass.opts.ignoreUseNoForget === false && optOutDirectives.length > 0) {
for (const directive of optOutDirectives) {
pass.opts.logger?.logEvent(pass.filename, {
kind: 'CompileSkip',
fnLoc: fn.node.body.loc ?? null,
reason: `Skipped due to '${directive.value.value}' directive.`,
loc: directive.loc ?? null,
});
}
return null;
}

pass.opts.logger?.logEvent(pass.filename, {
kind: 'CompileSuccess',
fnLoc: fn.node.loc ?? null,
Expand All @@ -492,23 +509,6 @@ export function compileProgram(
return null;
}

/**
* Otherwise if 'use no forget/memo' is present, we still run the code through the compiler
* for validation but we don't mutate the babel AST. This allows us to flag if there is an
* unused 'use no forget/memo' directive.
*/
if (pass.opts.ignoreUseNoForget === false && optOutDirectives.length > 0) {
for (const directive of optOutDirectives) {
pass.opts.logger?.logEvent(pass.filename, {
kind: 'CompileSkip',
fnLoc: fn.node.body.loc ?? null,
reason: `Skipped due to '${directive.value.value}' directive.`,
loc: directive.loc ?? null,
});
}
return null;
}

if (!pass.opts.noEmit) {
return compileResult.compiledFn;
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/packages/react-forgive/server/src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export async function compile({
plugins: ['typescript', 'jsx'],
},
sourceType: 'module',
configFile: false,
babelrc: false,
});
if (ast == null) {
return null;
Expand All @@ -48,6 +50,8 @@ export async function compile({
plugins,
sourceType: 'module',
sourceFileName: file,
configFile: false,
babelrc: false,
});
if (result?.code == null) {
throw new Error(
Expand Down
9 changes: 6 additions & 3 deletions compiler/packages/react-forgive/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ connection.onInitialized(() => {
});

documents.onDidChangeContent(async event => {
connection.console.info(`Changed: ${event.document.uri}`);
connection.console.info(`Compiling: ${event.document.uri}`);
resetState();
if (SUPPORTED_LANGUAGE_IDS.has(event.document.languageId)) {
const text = event.document.getText();
Expand All @@ -143,8 +143,11 @@ documents.onDidChangeContent(async event => {
options: compilerOptions,
});
} catch (err) {
connection.console.error('Failed to compile');
if (err instanceof Error) {
connection.console.error(err.stack ?? '');
connection.console.error(err.stack ?? err.message);
} else {
connection.console.error(JSON.stringify(err, null, 2));
}
}
}
Expand Down Expand Up @@ -192,7 +195,6 @@ connection.onCodeLensResolve(lens => {
});

connection.onCodeAction(params => {
connection.console.log('onCodeAction');
const codeActions: Array<CodeAction> = [];
for (const codeActionEvent of codeActionEvents) {
if (
Expand Down Expand Up @@ -242,6 +244,7 @@ connection.onRequest(AutoDepsDecorationsRequest.type, async params => {
});

function resetState() {
connection.console.debug('Clearing state');
compiledFns.clear();
autoDepsDecorations = [];
codeActionEvents = [];
Expand Down
Loading