mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 12:33:47 +08:00
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>
62 lines
1.3 KiB
JavaScript
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)));
|
|
}
|