Files
react-native-devtools-frontend/node_modules/webidl2/lib/writer.js
T
Johan Bay 986acd0681 Add dependencies for js signature generation to top-level node_modules
This change makes it easier to run the script from directly
`roll_py.deps` without having to fetch the dependencies first. This also
makes it easier to track which dependencies our tooling have.

Change-Id: I1ce55074ee6a1fffa6f2a2f05a56d0d74b4aca90
Bug: 1255619
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3431346
Reviewed-by: Mathias Bynens <mathias@chromium.org>
Commit-Queue: Johan Bay <jobay@chromium.org>
2022-02-02 17:33:42 +00:00

62 lines
1.3 KiB
JavaScript

function noop(arg) {
return arg;
}
const templates = {
wrap: (items) => items.join(""),
trivia: noop,
name: noop,
reference: noop,
type: noop,
generic: noop,
nameless: noop,
inheritance: noop,
definition: noop,
extendedAttribute: noop,
extendedAttributeReference: noop,
};
export class Writer {
constructor(ts) {
this.ts = Object.assign({}, templates, ts);
}
reference(raw, { unescaped, context }) {
if (!unescaped) {
unescaped = raw.startsWith("_") ? raw.slice(1) : raw;
}
return this.ts.reference(raw, unescaped, context);
}
token(t, wrapper = noop, ...args) {
if (!t) {
return "";
}
const value = wrapper(t.value, ...args);
return this.ts.wrap([this.ts.trivia(t.trivia), value]);
}
reference_token(t, context) {
return this.token(t, this.reference.bind(this), { context });
}
name_token(t, arg) {
return this.token(t, this.ts.name, arg);
}
identifier(id, context) {
return this.ts.wrap([
this.reference_token(id.tokens.value, context),
this.token(id.tokens.separator),
]);
}
}
export function write(ast, { templates: ts = templates } = {}) {
ts = Object.assign({}, templates, ts);
const w = new Writer(ts);
return ts.wrap(ast.map((it) => it.write(w)));
}