Skip to content

Commit

Permalink
feat: add wrapped method for getShorthandAssignmentValueSymbol to `…
Browse files Browse the repository at this point in the history
…TypeChecker` (#1456)
  • Loading branch information
kronodeus committed Dec 2, 2023
1 parent 339f685 commit 1d8b382
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,19 @@ export class ShorthandPropertyAssignment extends ShorthandPropertyAssignmentBase

return structure;
}

/**
* Gets the shorthand assignment value symbol of this node if it exists. Convenience API
* for TypeChecker#getShorthandAssignmentValueSymbol(node)
*/
getValueSymbol() {
return this._context.typeChecker.getShorthandAssignmentValueSymbol(this);
}

/**
* Gets the value symbol or throws if it doesn't exist.
*/
getValueSymbolOrThrow(message?: string | (() => string)) {
return errors.throwIfNullOrUndefined(this.getValueSymbol(), message ?? "Expected to find a value symbol.", this);
}
}
8 changes: 8 additions & 0 deletions packages/ts-morph/src/compiler/tools/TypeChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,12 @@ export class TypeChecker {

return formatFlags;
}

/**
* Gets the shorthand assignment value symbol of the provided node.
*/
getShorthandAssignmentValueSymbol(node: Node) {
const symbol = this.compilerObject.getShorthandAssignmentValueSymbol(node.compilerNode)
return symbol ? this._context.compilerFactory.getSymbol(symbol) : undefined
}
}

0 comments on commit 1d8b382

Please sign in to comment.