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 @@ -71,7 +71,7 @@ export const visitClassDeclaration = (

return ts.updateClassDeclaration(
classNode,
removeDecorators(classNode, CLASS_DECORATORS_TO_REMOVE),
filterDecorators(classNode, CLASS_DECORATORS_TO_REMOVE),
classNode.modifiers,
classNode.name,
classNode.typeParameters,
Expand All @@ -83,7 +83,7 @@ export const visitClassDeclaration = (
const removeStencilDecorators = (classMembers: ts.ClassElement[]) => {
return classMembers.map((m) => {
const currentDecorators = m.decorators;
const newDecorators = removeDecorators(m, MEMBER_DECORATORS_TO_REMOVE);
const newDecorators = filterDecorators(m, MEMBER_DECORATORS_TO_REMOVE);
if (currentDecorators !== newDecorators) {
if (ts.isMethodDeclaration(m)) {
return ts.updateMethod(
Expand All @@ -108,19 +108,28 @@ const removeStencilDecorators = (classMembers: ts.ClassElement[]) => {
});
};

const removeDecorators = (node: ts.Node, decoratorNames: Set<string>) => {
/**
* Generate a list of decorators from an AST node that are not in a provided list
*
* @param node the AST node whose decorators should be inspected
* @param decoratorNames the decorators that should _not_ be included in the returned list
* @returns a list of decorators on the AST node that are not in the provided list, or `undefined` if:
* - there are no decorators on the node
* - the node contains only decorators in the provided list
*/
const filterDecorators = (node: ts.Node, decoratorNames: Set<string>): ts.NodeArray<ts.Decorator> | undefined => {
if (node.decorators) {
const updatedDecoratorList = node.decorators.filter((dec) => {
const name =
ts.isCallExpression(dec.expression) &&
ts.isIdentifier(dec.expression.expression) &&
dec.expression.expression.text;
return !decoratorNames.has(name);
return typeof name === 'boolean' || !decoratorNames.has(name);
});
if (updatedDecoratorList.length === 0) {
return undefined;
} else if (updatedDecoratorList.length !== node.decorators.length) {
return ts.createNodeArray(updatedDecoratorList);
return ts.factory.createNodeArray(updatedDecoratorList);
}
}
return node.decorators;
Expand Down
18 changes: 0 additions & 18 deletions src/compiler/transformers/transform-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,6 @@ export const createStaticGetter = (propName: string, returnExpression: ts.Expres
);
};

export const removeDecorators = (node: ts.Node, decoratorNames: Set<string>) => {
if (node.decorators) {
const updatedDecoratorList = node.decorators.filter((dec) => {
const name =
ts.isCallExpression(dec.expression) &&
ts.isIdentifier(dec.expression.expression) &&
dec.expression.expression.text;
return !decoratorNames.has(name);
});
if (updatedDecoratorList.length === 0) {
return undefined;
} else if (updatedDecoratorList.length !== node.decorators.length) {
return ts.createNodeArray(updatedDecoratorList);
}
}
return node.decorators;
};

export const getStaticValue = (staticMembers: ts.ClassElement[], staticName: string): any => {
const staticMember: ts.GetAccessorDeclaration = staticMembers.find(
(member) => (member.name as any).escapedText === staticName
Expand Down