mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 20:39:31 +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>
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
import { Base } from "./base.js";
|
|
import {
|
|
return_type,
|
|
argument_list,
|
|
unescape,
|
|
autoParenter,
|
|
} from "./helpers.js";
|
|
|
|
export class CallbackFunction extends Base {
|
|
/**
|
|
* @param {import("../tokeniser.js").Tokeniser} tokeniser
|
|
*/
|
|
static parse(tokeniser, base) {
|
|
const tokens = { base };
|
|
const ret = autoParenter(
|
|
new CallbackFunction({ source: tokeniser.source, tokens })
|
|
);
|
|
tokens.name =
|
|
tokeniser.consumeKind("identifier") ||
|
|
tokeniser.error("Callback lacks a name");
|
|
tokeniser.current = ret.this;
|
|
tokens.assign =
|
|
tokeniser.consume("=") || tokeniser.error("Callback lacks an assignment");
|
|
ret.idlType =
|
|
return_type(tokeniser) || tokeniser.error("Callback lacks a return type");
|
|
tokens.open =
|
|
tokeniser.consume("(") ||
|
|
tokeniser.error("Callback lacks parentheses for arguments");
|
|
ret.arguments = argument_list(tokeniser);
|
|
tokens.close =
|
|
tokeniser.consume(")") || tokeniser.error("Unterminated callback");
|
|
tokens.termination =
|
|
tokeniser.consume(";") ||
|
|
tokeniser.error("Unterminated callback, expected `;`");
|
|
return ret.this;
|
|
}
|
|
|
|
get type() {
|
|
return "callback";
|
|
}
|
|
get name() {
|
|
return unescape(this.tokens.name.value);
|
|
}
|
|
|
|
*validate(defs) {
|
|
yield* this.extAttrs.validate(defs);
|
|
yield* this.idlType.validate(defs);
|
|
}
|
|
|
|
/** @param {import("../writer.js").Writer} w */
|
|
write(w) {
|
|
return w.ts.definition(
|
|
w.ts.wrap([
|
|
this.extAttrs.write(w),
|
|
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.token(this.tokens.open),
|
|
...this.arguments.map((arg) => arg.write(w)),
|
|
w.token(this.tokens.close),
|
|
w.token(this.tokens.termination),
|
|
]),
|
|
{ data: this }
|
|
);
|
|
}
|
|
}
|