Skip to content

Commit e75b417

Browse files
committed
Rename attrs to props
1 parent f8cc979 commit e75b417

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

typescript/packages/common-html/src/parser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sax from "sax";
22
import parseMustaches from "./stache.js";
33
import { isHole } from "./hole.js";
4-
import { create as createVNode, VNode, Attrs } from "./vnode.js";
4+
import { create as createVNode, VNode, Props } from "./vnode.js";
55
import * as logger from "./logger.js";
66

77
/** Parse a template into a simple JSON markup representation */
@@ -23,8 +23,8 @@ export const parse = (markup: string): VNode => {
2323
parser.onopentag = (node) => {
2424
// We've turned off the namespace feature, so node attributes will
2525
// contain only string values, not QualifiedAttribute objects.
26-
const attrs = parseAttrs(node.attributes as { [key: string]: string });
27-
const next = createVNode(node.name, attrs);
26+
const props = parseProps(node.attributes as { [key: string]: string });
27+
const next = createVNode(node.name, props);
2828
const top = getTop(stack);
2929
if (!top) {
3030
throw new ParseError(`No parent tag for ${node.name}`);
@@ -61,8 +61,8 @@ export default parse;
6161

6262
const getTop = (stack: Array<VNode>): VNode | null => stack.at(-1) ?? null;
6363

64-
const parseAttrs = (attrs: { [key: string]: string }): Attrs => {
65-
const result: Attrs = {};
64+
const parseProps = (attrs: { [key: string]: string }): Props => {
65+
const result: Props = {};
6666
for (const [key, value] of Object.entries(attrs)) {
6767
const parsed = parseMustaches(value);
6868
const first = parsed.at(0);

typescript/packages/common-html/src/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const renderNode = (
3333
return null;
3434
}
3535
const element = document.createElement(sanitizedNode.tag);
36-
attrs: for (const [name, value] of Object.entries(sanitizedNode.attrs)) {
36+
attrs: for (const [name, value] of Object.entries(sanitizedNode.props)) {
3737
if (isHole(value)) {
3838
const replacement = context[value.name];
3939
// If prop is an event, we need to add an event listener

typescript/packages/common-html/src/vnode.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import { Hole } from "./hole.js";
33
export type VNode = {
44
type: "vnode";
55
tag: string;
6-
attrs: Attrs;
6+
props: Props;
77
children: Children;
88
};
99

10-
export type Attrs = { [key: string]: string | Hole };
10+
export type Props = { [key: string]: string | Hole };
1111

1212
export type Children = Array<VNode | Hole | string>;
1313

1414
export const create = (
1515
tag: string,
16-
attrs: Attrs = {},
16+
props: Props = {},
1717
children: Children = [],
1818
): VNode => ({
1919
type: "vnode",
2020
tag,
21-
attrs,
21+
props,
2222
children,
2323
});
2424

0 commit comments

Comments
 (0)