-
Notifications
You must be signed in to change notification settings - Fork 25.8k
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
compiler-cli: lowering_expression transformer does not handle forwardRef like function #20216
Comments
@tbosch I think its an edge case of microsoft/TypeScript#17384 you didn't handle Also, using TS 2.5.3 and 2.6.1 did not solve the problem. |
Another update to help identify the source: export class MyClass {
@MyPropDecorator(() => 15)
prop: string;
} It doesn't have to be a custom type, even intrinsic types will fail. |
When calling `setOriginalNode` attach the original node's parent to the node, if the node does not have a parent. This should solve all `TypeError: Cannot read property 'kind' of undefined` errors when working with transformers and decorators. See microsoft#17384 Also see angular/angular#20216 Query: The implementation does not invalidate `node.parent` when `original` is undefined. I'm not sure if this is a valid use case but based on the existing logic, `node.original` is invalidated even if `original` is undefined...
OK, for now, if by any change someone is interested, this is a working, monkey patching, workaround: /**
* This module will patch the `@angular/compiler-cli` so it will correctly lower expression to declarations in decorators.
* See https://github.com/angular/angular/issues/20216
*/
import * as ts from 'typescript';
import '@angular/compiler-cli';
const lowerExpressions = require('@angular/compiler-cli/src/transformers/lower_expressions');
function touchNode(node: ts.Node) {
if (!node.parent) {
const original: ts.Node = <any> ts.getOriginalNode(node);
if (original !== node && original.parent) {
node.parent = original.parent;
ts.forEachChild(node, touchNode)
}
}
}
const getExpressionLoweringTransformFactory = lowerExpressions.getExpressionLoweringTransformFactory;
lowerExpressions.getExpressionLoweringTransformFactory = function(requestsMap, program) {
const fn = getExpressionLoweringTransformFactory(requestsMap, program);
return context => sourceFile => {
const result = fn(context)(sourceFile);
if (result !== sourceFile) {
ts.forEachChild(result, touchNode)
}
return result;
};
}; just import this file in the top of your webpack config module, or if you use |
waiting for the fix.. |
Any tips on how to integrate this fix into an |
create a local Assuming the following file is in the root of the project: Filename: ng #!/usr/bin/env node
/// WORKAROUND HERE
require('node_modules/.bin/ng'); Did not test it, but should work. You can also add it to your package.json scripts |
typestack/class-transformer#108
|
I had the same issue with: Found a solution by changing typescript.js for now.
Which comes from here, if you compile typescript: |
I want to share my workaround that I put together after reading other advices here and there. It's patching an
Here's what changed, compared to the original file: https://github.com/kirillgroshkov/angular-cli/commit/18f14d71bc5d73dba488f8fc1d08fd46d1d885f1
|
@kirillgroshkov Your solution cannot be applied in my context (@angular 5.0.3) $ ls node_modules/@angular
common/ compiler/ compiler-cli/ core/ forms/ http/ platform-browser/
platform-browser-dynamic/
$ ls node_modules/@angular/compiler-cli
index.d.ts index.js index.js.map ngtools2.d.ts ngtools2.js ngtools2.js.map
package.json README.md src/ any hints? |
@daixtrose My solution is when ps: Lines are there, between 4 and 29: |
Also not working in Angular class Test {
@Transform(
(value) => plainToClass(ApplicationData, JSON.parse(value)),
{ toClassOnly: true }
)
@Transform(
(value) => JSON.stringify(classToPlain(value)),
{ toPlainOnly: true }
)
data: ApplicationData;
} |
Apparently, this started working from Angular CLI 1.7 onwards, so somehow the CLI was involved. I can't reproduce this in newer versions of Angular (or even with Angular 5.0.0, TS 2.4.2 and CLI 1.7.0) so I'm closing as resolved. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This will work:
Being explicit won't help
BUT, being static will help:
Thanks!
The text was updated successfully, but these errors were encountered: