Skip to content

feat(writer): pass idlType object #764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var result = WebIDL2.write(tree, {
* Called only once for each types, e.g. `Document`, `Promise<DOMString>`, or `sequence<long>`.
* @param type The `wrap()`ed result of references and syntatic bracket strings.
*/
type: type => type,
type: (type, { data }) => type,
/**
* Receives the return value of `reference()`. String if it's absent.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/productions/argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Argument extends Base {
return w.ts.wrap([
this.extAttrs.write(w),
w.token(this.tokens.optional),
w.ts.type(this.idlType.write(w)),
w.ts.type(this.idlType.write(w), { data: this.idlType }),
w.token(this.tokens.variadic),
w.name_token(this.tokens.name, { data: this }),
this.default ? this.default.write(w) : "",
Expand Down
2 changes: 1 addition & 1 deletion lib/productions/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class Attribute extends Base {
w.token(this.tokens.special),
w.token(this.tokens.readonly),
w.token(this.tokens.base),
w.ts.type(this.idlType.write(w)),
w.ts.type(this.idlType.write(w), { data: this.idlType }),
w.name_token(this.tokens.name, { data: this, parent }),
w.token(this.tokens.termination),
]),
Expand Down
2 changes: 1 addition & 1 deletion lib/productions/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class CallbackFunction extends Base {
w.token(this.tokens.base),
w.name_token(this.tokens.name, { data: this }),
w.token(this.tokens.assign),
w.ts.type(this.idlType.write(w)),
w.ts.type(this.idlType.write(w), { data: this.idlType }),
w.token(this.tokens.open),
...this.arguments.map((arg) => arg.write(w)),
w.token(this.tokens.close),
Expand Down
2 changes: 1 addition & 1 deletion lib/productions/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Constant extends Base {
w.ts.wrap([
this.extAttrs.write(w),
w.token(this.tokens.base),
w.ts.type(this.idlType.write(w)),
w.ts.type(this.idlType.write(w), { data: this.idlType }),
w.name_token(this.tokens.name, { data: this, parent }),
w.token(this.tokens.assign),
w.token(this.tokens.value),
Expand Down
2 changes: 1 addition & 1 deletion lib/productions/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Field extends Base {
w.ts.wrap([
this.extAttrs.write(w),
w.token(this.tokens.required),
w.ts.type(this.idlType.write(w)),
w.ts.type(this.idlType.write(w), { data: this.idlType }),
w.name_token(this.tokens.name, { data: this, parent }),
this.default ? this.default.write(w) : "",
w.token(this.tokens.termination),
Expand Down
2 changes: 1 addition & 1 deletion lib/productions/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Operation extends Base {
const { parent } = this;
const body = this.idlType
? [
w.ts.type(this.idlType.write(w)),
w.ts.type(this.idlType.write(w), { data: this.idlType }),
w.name_token(this.tokens.name, { data: this, parent }),
w.token(this.tokens.open),
w.ts.wrap(this.arguments.map((arg) => arg.write(w))),
Expand Down
2 changes: 1 addition & 1 deletion lib/productions/typedef.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Typedef extends Base {
w.ts.wrap([
this.extAttrs.write(w),
w.token(this.tokens.base),
w.ts.type(this.idlType.write(w)),
w.ts.type(this.idlType.write(w), { data: this.idlType }),
w.name_token(this.tokens.name, { data: this }),
w.token(this.tokens.termination),
]),
Expand Down
2 changes: 1 addition & 1 deletion test/custom-production.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CustomAttribute extends Base {
w.ts.wrap([
this.extAttrs.write(w),
w.token(this.tokens.base),
w.ts.type(this.idlType.write(w)),
w.ts.type(this.idlType.write(w), { data: this.idlType }),
w.name_token(this.tokens.name, { data: this, parent }),
w.token(this.tokens.termination),
]),
Expand Down
27 changes: 27 additions & 0 deletions test/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,31 @@ describe("Writer template functions", () => {
"interface[interface Misaki {interface:const[ const short MICHELLE = 1;] };]",
);
});

it("gives idlType object", () => {
const types = [];
rewrite(
`
interface Mizuki {
attribute long attr;
short? op(long long arg);
};
dictionary Ena {
sequence<unsigned short> mem;
};
`,
{
type(type, { data }) {
types.push(data);
},
},
);

expect(types[0].idlType).toBe("long");
expect(types[1].idlType).toBe("short");
expect(types[1].nullable).toBe(true);
expect(types[2].idlType).toBe("long long");
expect(types[3].generic).toBe("sequence");
expect(types[3].idlType[0].idlType).toBe("unsigned short");
});
});