Skip to content
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

Fix/unwrap none in convert funcAppToElem #598

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions packages/dbml-parse/src/lib/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class Some<T> {
return new Some(callback(this.value));
}

is_some_and(callback: (_: T) => boolean): boolean {
return callback(this.value);
}

// eslint-disable-next-line class-methods-use-this
isOk(): boolean {
return true;
Expand Down Expand Up @@ -53,6 +57,11 @@ export class None<T> {
return new None();
}

// eslint-disable-next-line class-methods-use-this
is_some_and(callback: (_: T) => boolean): boolean {
return false;
}

// eslint-disable-next-line class-methods-use-this
isOk(): boolean {
return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/dbml-parse/src/lib/parser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function convertFuncAppToElem(
const attributeList =
_.last(cpArgs) instanceof ListExpressionNode ? (cpArgs.pop() as ListExpressionNode) : undefined;

if (cpArgs.length === 3 && extractVariableNode(cpArgs[1]).unwrap().value === 'as') {
if (cpArgs.length === 3 && extractVariableNode(cpArgs[1]).is_some_and((token) => token.value === 'as')) {
return new Some(
factory.create(ElementDeclarationNode, {
type,
Expand Down
Loading