Skip to content

Commit 77f3846

Browse files
committed
Adds new :@ prefix for dynamic properties. Fixes #98
1 parent b90eeb6 commit 77f3846

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/attributeSerializer.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { escapeAttribute } from 'entities/lib/escape.js';
33

44
class AttributeSerializer {
55
static prefixes = {
6-
props: "@",
6+
prop: "@",
77
dynamic: ":",
8+
dynamicProp: ":@",
89
}
910

1011
// Merge multiple style/class attributes into a single one, operates on :dynamic and @prop but with transformed values
@@ -78,9 +79,17 @@ class AttributeSerializer {
7879
}
7980

8081
static peekAttribute(name) {
81-
if(name.startsWith(AttributeSerializer.prefixes.props)) {
82+
if(name.startsWith(AttributeSerializer.prefixes.dynamicProp)) {
8283
return {
83-
name: name.slice(AttributeSerializer.prefixes.props.length),
84+
name: name.slice(AttributeSerializer.prefixes.dynamicProp.length),
85+
privacy: "private", // property
86+
evaluation: "script",
87+
};
88+
}
89+
90+
if(name.startsWith(AttributeSerializer.prefixes.prop)) {
91+
return {
92+
name: name.slice(AttributeSerializer.prefixes.prop.length),
8493
privacy: "private", // property
8594
evaluation: false,
8695
};

test/issue-98-test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import test from "ava";
2+
import { WebC } from "../webc.js";
3+
4+
test("Issue #3 slot inconsistency", async t => {
5+
let component = new WebC();
6+
7+
component.setInputPath("./test/stubs/issue-98/page.webc");
8+
component.defineComponents("./test/stubs/issue-98/component.webc");
9+
10+
let { html, css, js, components } = await component.compile();
11+
12+
t.deepEqual(components, [
13+
"./test/stubs/issue-98/page.webc",
14+
"./test/stubs/issue-98/component.webc",
15+
]);
16+
17+
t.is(html, `<div id="hahaha"></div>`);
18+
});

test/stubs/issue-98/component.webc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div :id="myDynamicProp"></div>

test/stubs/issue-98/page.webc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<component :@my-dynamic-prop="'hahaha'"></component>

0 commit comments

Comments
 (0)