-
Notifications
You must be signed in to change notification settings - Fork 785
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
Test fails with ReferenceError: _{method}_decorators is not defined when using custom decorators #4631
Comments
Thanks! I'm going to label this to get it ingested into our internal issue tracking system! |
It looks like this bug can be traced back to v2.19.0 - updated the title of the bug accordingly |
FYI, it worked previously in stencil v3.0.1 with jest and jest-cli v26.0.1. Sharing the dependencies of working tests, for your reference
|
Thanks @Aadhisivam! Upon closer inspection, it looks like this was introduced in v3.2.0. |
After some troubleshooting, I do think the issues might either be in TypeScript or how the class decorator is expunged. Edit: Outdated investigationAfter checking the code source of the `ts.factory.updateClassDeclaration`, I noticed that using `ts.factory.createClassDeclaration` and returning its results do work, as long as the Class is not being used.I noticed the NodeFactory had two updates "mode", I tried to mimick diff --git a/node_modules/@stencil/core/compiler/stencil.js b/node_modules/@stencil/core/compiler/stencil.js
index d4d0311..0b611e6 100644
--- a/node_modules/@stencil/core/compiler/stencil.js
+++ b/node_modules/@stencil/core/compiler/stencil.js
@@ -229782,10 +229782,13 @@ const visitClassDeclaration = (config, diagnostics, typeChecker, program, classN
const updatedClassFields = handleClassFields(classNode, filteredMethodsAndFields);
validateMethods(diagnostics, classMembers);
const currentDecorators = retrieveTsDecorators(classNode);
- return ts.factory.updateClassDeclaration(classNode, [
+ const newNode = ts.factory.createClassDeclaration([
...((_b = filterDecorators(currentDecorators, CLASS_DECORATORS_TO_REMOVE)) !== null && _b !== void 0 ? _b : []),
...((_c = retrieveTsModifiers(classNode)) !== null && _c !== void 0 ? _c : []),
], classNode.name, classNode.typeParameters, classNode.heritageClauses, updatedClassFields);
+ ts.setOriginalNode(classNode, newNode);
+ ts.setTextRange(classNode, newNode);
+ return newNode;
};
/**
* Take a list of `ClassElement` AST nodes and remove any decorators from I'm unsure at this stage of the whole ramification that changes might cause however. I continued my investigation by comparing the transpiled JS used in Stencil with the output of I noticed that both files were not using the same decorate utilities:
I noticed that stencil/src/compiler/transpile/create-build-program.ts Lines 20 to 21 in a1ab21b
stencil/src/compiler/transpile/ts-config.ts Lines 23 to 37 in a1ab21b
The stencil/src/compiler/config/transpile-options.ts Lines 57 to 58 in a1ab21b
Therefore, I think for consistency, it'd be best for the |
Prerequisites
Stencil Version
4.0.2
Current Behavior
*.spec.tsx test fails when using custom decorators in the component.
Expected Behavior
Expect test should not fail due to decorators.
System Info
Steps to Reproduce
Add a custom decorator and use within component, test script will fail with reference error.
Code Reproduction URL
https://github.com/Aadhisivam/stencil-demo/
Additional Information
No response
The text was updated successfully, but these errors were encountered: