Repository navigation
Transforming class member with decorators throws #17384
Description
Activity
I think this PR should fix the problem...
Testing it now.
- added a commit that references this issue
on Jul 25, 2017 This bug also affects Angular / Tsickle as we are now using transformers. Our workaround (see transformer_util.ts):
- setting the
parentfor synthetic nodes - not using
ts.updateSourceFileNodebut instead doing this:const sf = getMutableClone(sf); sf.statements = statements; return sf;
/cc Martin Probst (@mprobst) Evan Martin (@evmar) Alex Eagle (@alexeagle)
- setting the
- addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Aug 29, 2017 filipesilva commented
on Sep 15, 2017 ContributorMore actionsTobias Bosch (@tbosch) the related issue #17551 is fixed in 2.5.0 via #18051. Perhaps the workaround in Angular can go away when typescript is detected to be that version of greater.
import { satisfies } from 'semver'; const visitEachChild = satisfies(ts.version, '^2.5.0') ? ts.visitEachChild : visitEachChildWorkaround;This issue should be closed since I think #18051 fixes both.
Filipe Silva (@filipesilva) from what I see #18051 did not solve the issue, or at least did not solve it completely.
- added a commit that references this issue
on Nov 6, 2017 typestack/class-transformer#108
export function serializeType<T>(object: T) { return function () { return object; } } export class CatalogItem { id: string; @Type(serializeType(CatalogCategory)) category?: CatalogCategory = null; @Type(serializeType(PackingVariant)) packing: PackingVariant; price: string = null; }- addedBugA bug in TypeScriptA bug in TypeScriptand removedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Nov 28, 2017 - addedDomain: APIRelates to the public API for TypeScriptRelates to the public API for TypeScript
on Nov 28, 2017 - addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Nov 28, 2017 George Mavritsakis (@gmavritsakis)
I had the same issue with:
Angular CLI 1.6.1
Typescript 2.4.2
Angular 5.0.2Found a solution by changing typescript.js for now.
Replace all the function
function nodeCanBeDecorated(node)
with the following codefunction nodeCanBeDecorated(node) { switch (node.kind) { case 229 /* ClassDeclaration */: // classes are valid targets return true; case 149 /* PropertyDeclaration */: // property declarations are valid if their parent is a class declaration. // return node.parent.kind === 229 /* ClassDeclaration */; return (node.parent && node.parent.kind === 229) || (node.original && node.original.parent && node.original.parent.kind === 229); case 153 /* GetAccessor */: case 154 /* SetAccessor */: case 151 /* MethodDeclaration */: // if this method has a body and its parent is a class declaration, this is a valid target. return node.body !== undefined && // && node.parent.kind === 229 /* ClassDeclaration */; (node.parent && node.parent.kind === 229) || (node.original && node.original.parent && node.original.parent.kind === 229); case 146 /* Parameter */: // if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target; // return node.parent.body !== undefined // && (node.parent.kind === 152 /* Constructor */ // || node.parent.kind === 151 /* MethodDeclaration */ // || node.parent.kind === 154 /* SetAccessor */) // && node.parent.parent.kind === 229 /* ClassDeclaration */; var parent = node.parent || (node.original && node.original.parent); return parent && parent.body !== undefined && (parent.kind === 152 || parent.kind === 151 || parent.kind === 154) && parent.parent.kind === 229; } return false; }Which comes from here, if you compile typescript:
shlomiassaf/TypeScript@7017fa2kirillgroshkov commented
on Jan 13, 2018 More actionsWaiting for the fix... It affects our project to upgrade to Angular5..
kirillgroshkov commented
on Jan 13, 2018 More actionsI want to share my workaround that I put together after reading other advices here and there. It's patching an
ngscript from@angular/cli@1.6.4(current version at the moment of writing). Because of that it prevents updating@angular/cli, so be prepared.- Put a patched copy of
ngsomewhere in your repo. You can grab patched version from here:
https://github.com/kirillgroshkov/angular-cli/blob/18f14d71bc5d73dba488f8fc1d08fd46d1d885f1/packages/%40angular/cli/bin/ng
Here's what changed, compared to the original file: https://github.com/kirillgroshkov/angular-cli/commit/18f14d71bc5d73dba488f8fc1d08fd46d1d885f1
- Add a
postinstallscript in yourpackage.jsonthat will run every time after you donpm install(oryarn install) and copy/overwritengfrom your location tonode_modules/@angular/cli/bin/ng.
"postinstall": "echo 'patching @angular/cli' & cp ./other/ng ./node_modules/@angular/cli/bin"- Run your build as normal, you should see console.log message "!!! using patched @angular/cli".
- Profit
- Put a patched copy of
I have the same issue. Is this a problem with Angular, Typescript, or Angular CLI?
This is fixed in our just-released 2.7 build; so you'd have to wait for a new version of the angular CLI that makes use of it, or manually patch your local outdated copy like those above did (not recommended).
filipesilva commented
on Feb 1, 2018 ContributorMore actionsWesley Wigham (@weswigham) awesome, thanks for the update!
- locked and limited conversation to collaborators
on Jul 3, 2018
TypeScript Version: 2.4.0
Code
In a
PropertyDeclarationvisitorExpected behavior:
Should compile.
Actual behavior:
Exception is thrown
TypeError: Cannot read property 'kind' of undefinedThe exception is throw from here
Trying to reach
node.parent.kindwhilenode.parentis undefined, which is common to all "synthesized" nodes, i.e. transforming nodes.This is true to all other members... Parameter, MethodDeclaration, GetAccessor and SetAccessor