Skip to content

Commit

Permalink
fix(class-declaration): throw with undefined ast properties (#771)
Browse files Browse the repository at this point in the history
Signed-off-by: Ertugrul Karademir <[email protected]>
  • Loading branch information
ekarademir authored Dec 21, 2023
1 parent c5f5e2e commit c0c306f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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

0 comments on commit c0c306f

Please sign in to comment.