Skip to content

Commit

Permalink
fix: allow "view" and "import" as identifier (zenstackhq#750)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Oct 11, 2023
1 parent 43322e1 commit 2e15dfb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/language/src/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export function isReferenceTarget(item: unknown): item is ReferenceTarget {
return reflection.isInstance(item, ReferenceTarget);
}

export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'in' | 'model' | 'plugin' | 'sort' | string;
export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'import' | 'in' | 'model' | 'plugin' | 'sort' | 'view' | string;

export function isRegularID(item: unknown): item is RegularID {
return item === 'model' || item === 'enum' || item === 'attribute' || item === 'datasource' || item === 'plugin' || item === 'abstract' || item === 'in' || item === 'sort' || (typeof item === 'string' && (/[_a-zA-Z][\w_]*/.test(item)));
return item === 'model' || item === 'enum' || item === 'attribute' || item === 'datasource' || item === 'plugin' || item === 'abstract' || item === 'in' || item === 'sort' || item === 'view' || item === 'import' || (typeof item === 'string' && (/[_a-zA-Z][\w_]*/.test(item)));
}

export type TypeDeclaration = DataModel | Enum;
Expand Down
8 changes: 8 additions & 0 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2771,6 +2771,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
{
"$type": "Keyword",
"value": "sort"
},
{
"$type": "Keyword",
"value": "view"
},
{
"$type": "Keyword",
"value": "import"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ QualifiedName returns string:
// https://github.com/langium/langium/discussions/1012
RegularID returns string:
// include keywords that we'd like to work as ID in most places
ID | 'model' | 'enum' | 'attribute' | 'datasource' | 'plugin' | 'abstract' | 'in' | 'sort';
ID | 'model' | 'enum' | 'attribute' | 'datasource' | 'plugin' | 'abstract' | 'in' | 'sort' | 'view' | 'import';

// internal attribute
InternalAttributeName returns string:
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/tests/regression/issue-735.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { loadSchema } from '@zenstackhq/testtools';

describe('Regression: issue 735', () => {
it('regression', async () => {
await loadSchema(
`
model MyModel {
id String @id @default(cuid())
view String
import Int
}
model view {
id String @id @default(cuid())
name String
}
`,
{ pushDb: false }
);
});
});

0 comments on commit 2e15dfb

Please sign in to comment.