Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/webidl2.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@
return this.tokens.name.value;
}
}

class Interface extends Container {
static parse(base, { callback = null, partial = null } = {}) {
const tokens = { callback, partial, base };
Expand Down
34 changes: 16 additions & 18 deletions lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,18 @@
]);
}

function container(type) {
return it => {
const trivia = extract_trivia(it);
const ext = extended_attributes(it.extAttrs);
const partial = token(it.partial, "partial");
const name = ts.name(it.escapedName, { data: it });
const head = wrap`${trivia.base}${type}${trivia.name}${name}`;
const inherit = inheritance(it.inheritance);
const body = brace_body(trivia, iterate(it.members, it));
return ts.definition(
wrap`${ext}${partial}${head}${inherit}${body}`,
{ data: it }
);
};
function container(it) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can rename “it” to something more specific?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had no good idea. Do you have a suggestion? data would be helpful for { data } but is not any specific.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No :( maybe will go through it after the refactor and think of something.

return ts.definition(ts.wrap([
extended_attributes(it.extAttrs),
token(it.tokens.partial),
token(it.tokens.base),
name_token(it.tokens.name, { data: it }),
inheritance(it.inheritance),
token(it.tokens.open),
iterate(it.members, it),
token(it.tokens.close),
token(it.tokens.termination)
]), { data: it });
}

function brace_body(trivia, members) {
Expand Down Expand Up @@ -293,7 +291,7 @@
}
function callbackInterface(it) {
return ts.definition(
wrap`${ts.trivia(it.trivia.callback)}callback${container("interface", noop)(it)}`,
wrap`${ts.trivia(it.trivia.callback)}callback${container(it)}`,
{ data: it }
);
}
Expand All @@ -302,12 +300,12 @@
}

const table = {
interface: container("interface"),
interface: container,
"interface mixin": interface_mixin,
namespace: container("namespace"),
namespace: container,
operation,
attribute,
dictionary: container("dictionary"),
dictionary: container,
field,
const: const_,
typedef,
Expand Down