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(class-declaration): throw with undefined ast properties #771

Merged
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
7 changes: 7 additions & 0 deletions packages/concerto-core/lib/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class ClassDeclaration extends Declaration {
}
}

if (!Array.isArray(this.ast.properties)) {
let formatter = Globalize.messageFormatter('classdeclaration-validate-undefined-properties');
throw new IllegalModelException(formatter({
'class':this.name
}), this.modelFile, this.ast.location);
}

for (let n = 0; n < this.ast.properties.length; n++) {
let thing = this.ast.properties[n];

Expand Down
1 change: 1 addition & 0 deletions packages/concerto-core/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"classdeclaration-validate-duplicatefieldname": "Class \"{class}\" has more than one field named \"{fieldName}\".",
"classdeclaration-validate-missingidentifier" : "Class \"{class}\" is not declared as \"abstract\". It must define an identifying field.",
"classdeclaration-validate-selfextending": "Class \"{class}\" cannot extend itself.",
"classdeclaration-validate-undefined-properties": "Properties of Class \"{class}\" has to be defined.",

"modelfile-constructor-unrecmodelelem": "Unrecognised model element \"{type}\".",
"modelfile-resolvetype-undecltype": "Undeclared type \"{type}\" in \"{context}\".",
Expand Down
17 changes: 17 additions & 0 deletions packages/concerto-core/test/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ describe('ClassDeclaration', () => {
}).should.throw(/Invalid class name '2nd'/);
});

it('should throw when ast properties is null', () => {
(() => {
new ClassDeclaration(modelFile, {
name: 'aconcept',
properties: null,
});
}).should.throw(/Properties of Class/);
});

it('should throw when ast properties is undefined', () => {
(() => {
new ClassDeclaration(modelFile, {
name: 'aconcept',
properties: undefined,
});
}).should.throw(/Properties of Class/);
});
});

describe('#validate', () => {
Expand Down