fix: add support for nested tag long hand properties (#1592)

(cherry picked from commit 8f595fd493d4462f8cc2b103d8ea77e04616edea)
This commit is contained in:
Dylan Piercey 2020-08-07 14:36:01 -07:00
parent 49a73a18c7
commit 36c501ce44
No known key found for this signature in database
GPG Key ID: F6A9A2F45D062CBC
3 changed files with 56 additions and 3 deletions

View File

@ -288,7 +288,7 @@ class TagLoader {
var nestedTagName = part.substring(1, part.length - 1);
nestedTag.name = nestedTagName;
nestedTag.isRepeated = isNestedTagRepeated;
nestedTag.isRepeated = nestedTag.isRepeated || isNestedTagRepeated;
// Use the name of the attribute as the target property unless
// this target property was explicitly provided
nestedTag.targetProperty =
@ -445,6 +445,17 @@ class TagLoader {
var tag = this.tag;
tag.type = value;
}
isRepeated(value) {
var tag = this.tag;
tag.isRepeated = value;
}
targetProperty(value) {
var tag = this.tag;
tag.targetProperty = value;
}
/**
* Declare a nested tag.
*
@ -454,7 +465,7 @@ class TagLoader {
* "nested-tags": {
* "tab": {
* "target-property": "tabs",
* "isRepeated": true
* "is-repeated": true
* }
* }
* }
@ -465,7 +476,7 @@ class TagLoader {
forEachEntry(value, (nestedTagName, nestedTagDef) => {
var dependencyChain = this.dependencyChain.append(
`nestedTags["${nestedTagName}]`
`nestedTags["${nestedTagName}"]`
);
var nestedTag = new types.Tag(filePath);

View File

@ -0,0 +1,22 @@
{
"tags": {
"longhand-tabs": {
"nested-tags": {
"tab": {
"target-property": "tabs",
"is-repeated": true,
"attributes": {
"label": {
"type": "string"
}
}
}
},
"attributes": {
"orientation": {
"type": "string"
}
}
}
}
}

View File

@ -0,0 +1,20 @@
var nodePath = require("path");
exports.check = function(taglibLoader, expect) {
var taglib = taglibLoader.loadTaglibFromFile(
nodePath.join(__dirname, "marko.json")
);
expect(taglib != null).to.equal(true);
expect(taglib.tags)
.has.property("longhand-tabs")
.with.property("nestedTags")
.with.property("tab");
const tab = taglib.tags["longhand-tabs"].nestedTags.tab;
expect(tab).has.property("isRepeated", true);
expect(tab).has.property("targetProperty", "tabs");
expect(tab)
.has.property("attributes")
.with.property("label");
};