Skip to content

Commit

Permalink
Fixed a bug
Browse files Browse the repository at this point in the history
Fixed a bug where members of model objects, which are themselves objects were not accessible in templates. Added a test case for that.
  • Loading branch information
mike-lischke committed Nov 16, 2024
1 parent 6bade4f commit aac9a12
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/misc/ObjectModelAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ export class ObjectModelAdaptor implements ModelAdaptor<Constructor> {

if (memberName in model) {
// try for a visible field
const field = (model as never)[memberName];
if (typeof field !== "function" && typeof field !== "object") {
member = new Field(clazz, memberName);
}

member = new Field(clazz, memberName);
}

if (!member) {
Expand Down
29 changes: 29 additions & 0 deletions tests/TestDictionaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,35 @@ export class TestDictionaries extends BaseTest {
assertEquals(expected, result);
}

@Test
public testAccessDictionaryFromParameter(): void {
const dir = this.tmpdir;
const g = `
a(parser) ::= <<
<if(parser.tokens)>
public static final int
<parser.tokens:{k | <k>=<parser.tokens.(k)>}; separator=", ", wrap, anchor>;
<endif>
>>`;
TestDictionaries.writeFile(dir, "g.stg", g);

const group = new STGroupFile(this.tmpdir + "/g.stg");
const st = group.getInstanceOf("a");

const parser = {
tokens: new Map<string, number>([
["ID", 1],
["INT", 2],
["FLOAT", 3],
]),
};
st?.add("parser", parser);

const expected = "\tpublic static final int\n\t\tID=1, INT=2, FLOAT=3;\n";
const result = st?.render();
assertEquals(expected, result);
}

@Test
public testAccessDictionaryFromAnonymousTemplateInRegion(): void {
const dir = this.tmpdir;
Expand Down

0 comments on commit aac9a12

Please sign in to comment.