Skip to content

Commit

Permalink
R!! Use new TypeScript5 API in addons package
Browse files Browse the repository at this point in the history
  • Loading branch information
jwloka committed May 13, 2023
1 parent 2b342ac commit fa18317
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createClientTransformer = ({ libPath, functionsDir }: Transformatio
}

if (ts.isImportDeclaration(node)) {
return undefined;
return node;
}

if (!isTransformable(node)) {
Expand All @@ -41,15 +41,15 @@ export const createClientTransformer = ({ libPath, functionsDir }: Transformatio

const decorations = getDecoration(sf, node, DECORATOR_NAME);
if (!isNodeExported(node) || !decorations) {
return undefined;
return node;
}

const [transformedNode, isServiceFunction] = transformNode(node, sf, decorations);
hasServiceFunctions = hasServiceFunctions || isServiceFunction;
return transformedNode ?? node;
};

sf = ts.visitNode(sf, visitor);
sf = ts.visitNode(sf, visitor, ts.isSourceFile);
if (hasServiceFunctions) {
if (!hasInvokeImport(sf, libPath, NAMED_IMPORTS)) {
sf = ts.factory.updateSourceFile(sf, [getImportInvoke(libPath, NAMED_IMPORTS), ...sf.statements]);
Expand Down Expand Up @@ -94,7 +94,6 @@ export const hasInvokeImport = (sf: ts.SourceFile, libPath: string, namedImports

export const getImportInvoke = (libPath: string, namedImports: string[]): ts.Statement => {
return ts.factory.createImportDeclaration(
undefined,
undefined,
ts.factory.createImportClause(
false,
Expand Down
1 change: 0 additions & 1 deletion packages/addons/addons/magellan-shared/node-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export const getFunctionName = (node: ts.VariableStatement | ts.FunctionDeclarat

export const createInvokeImport = (libPath: string, namedImports: string[]): ts.Statement => {
return factory.createImportDeclaration(
undefined,
undefined,
factory.createImportClause(
false,
Expand Down
10 changes: 6 additions & 4 deletions packages/addons/addons/magellan-shared/transform-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export const transformInvocableFunction = (
const parameters = getObjectLiteralsOfNode(node);
return factory.updateFunctionDeclaration(
node,
node.decorators,
node.modifiers,
node.asteriskToken,
node.name,
Expand All @@ -133,7 +132,6 @@ export const transformLocalServerFunction = (node: ts.Node): ts.Node => {
const newParameters = createObjectifiedParameter(node);
return factory.updateFunctionDeclaration(
node,
node.decorators,
node.modifiers,
node.asteriskToken,
node.name,
Expand Down Expand Up @@ -178,9 +176,13 @@ const createObjectifiedParameter = (node: ts.Node): ts.ParameterDeclaration[] =>
parameters?.map(p => factory.createBindingElement(undefined, undefined, factory.createIdentifier(p.name.getText()), undefined)) ?? []
);
const typeLiteral = factory.createTypeLiteralNode(
parameters?.map(p => factory.createPropertySignature(p.modifiers, p.name.getText(), p.questionToken, p.type))
parameters?.map(p => factory.createPropertySignature(
// TODO: API clash ModifierLike[] (new) vs. Modifier[] (old)
p.modifiers as any,
p.name.getText(),
p.questionToken, p.type))
);
return [factory.createParameterDeclaration(undefined, undefined, undefined, bindingPattern, undefined, typeLiteral, undefined)];
return [factory.createParameterDeclaration(undefined, undefined, bindingPattern, undefined, typeLiteral, undefined)];
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const createServerTransformer = ({ functionsDir }: TransformationArgument
return ts.visitEachChild(node, visitor, ctx);
};

return ts.visitNode(sf, visitor);
return ts.visitNode(sf, visitor, ts.isSourceFile);
};
};
return platformTransformerFactory;
Expand Down

0 comments on commit fa18317

Please sign in to comment.