Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): add heritage clauses earlier in native transform #4769

Merged
merged 1 commit into from
Sep 11, 2023
Merged
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
21 changes: 14 additions & 7 deletions src/compiler/transformers/component-native/native-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export const updateNativeComponentClass = (
moduleFile: d.Module,
cmp: d.ComponentCompilerMeta,
): ts.ClassDeclaration | ts.VariableStatement => {
const heritageClauses = updateNativeHostComponentHeritageClauses(classNode, moduleFile);
const members = updateNativeHostComponentMembers(transformOpts, classNode, moduleFile, cmp);
return updateComponentClass(transformOpts, classNode, heritageClauses, members);
const withHeritageClauses = updateNativeHostComponentHeritageClauses(classNode, moduleFile);
const members = updateNativeHostComponentMembers(transformOpts, withHeritageClauses, moduleFile, cmp);
return updateComponentClass(transformOpts, withHeritageClauses, withHeritageClauses.heritageClauses, members);
};

/**
Expand All @@ -46,15 +46,15 @@ export const updateNativeComponentClass = (
*
* @param classNode the syntax tree of the Stencil component class to update
* @param moduleFile the Stencil Module associated with the provided class node
* @returns the generated heritage clause
* @returns an updated class declaration with the generated heritage clause
*/
const updateNativeHostComponentHeritageClauses = (
classNode: ts.ClassDeclaration,
moduleFile: d.Module,
): ts.NodeArray<ts.HeritageClause> | [ts.HeritageClause] => {
): ts.ClassDeclaration => {
if (classNode.heritageClauses != null && classNode.heritageClauses.length > 0) {
// the syntax tree has a heritage clause already, don't generate a new one
return classNode.heritageClauses;
return classNode;
}

if (moduleFile.cmps.length >= 1) {
Expand All @@ -66,7 +66,14 @@ const updateNativeHostComponentHeritageClauses = (
ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier(HTML_ELEMENT), []),
]);

return [heritageClause];
return ts.factory.updateClassDeclaration(
classNode,
classNode.modifiers,
classNode.name,
classNode.typeParameters,
[heritageClause],
classNode.members,
);
};

/**
Expand Down