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>
105 lines
2.9 KiB
JavaScript
105 lines
2.9 KiB
JavaScript
import { Base } from "./base.js";
|
|
import {
|
|
return_type,
|
|
argument_list,
|
|
unescape,
|
|
autoParenter,
|
|
} from "./helpers.js";
|
|
import { validationError } from "../error.js";
|
|
|
|
export class Operation extends Base {
|
|
/**
|
|
* @typedef {import("../tokeniser.js").Token} Token
|
|
*
|
|
* @param {import("../tokeniser.js").Tokeniser} tokeniser
|
|
* @param {object} [options]
|
|
* @param {Token} [options.special]
|
|
* @param {Token} [options.regular]
|
|
*/
|
|
static parse(tokeniser, { special, regular } = {}) {
|
|
const tokens = { special };
|
|
const ret = autoParenter(
|
|
new Operation({ source: tokeniser.source, tokens })
|
|
);
|
|
if (special && special.value === "stringifier") {
|
|
tokens.termination = tokeniser.consume(";");
|
|
if (tokens.termination) {
|
|
ret.arguments = [];
|
|
return ret;
|
|
}
|
|
}
|
|
if (!special && !regular) {
|
|
tokens.special = tokeniser.consume("getter", "setter", "deleter");
|
|
}
|
|
ret.idlType =
|
|
return_type(tokeniser) || tokeniser.error("Missing return type");
|
|
tokens.name =
|
|
tokeniser.consumeKind("identifier") || tokeniser.consume("includes");
|
|
tokens.open =
|
|
tokeniser.consume("(") || tokeniser.error("Invalid operation");
|
|
ret.arguments = argument_list(tokeniser);
|
|
tokens.close =
|
|
tokeniser.consume(")") || tokeniser.error("Unterminated operation");
|
|
tokens.termination =
|
|
tokeniser.consume(";") ||
|
|
tokeniser.error("Unterminated operation, expected `;`");
|
|
return ret.this;
|
|
}
|
|
|
|
get type() {
|
|
return "operation";
|
|
}
|
|
get name() {
|
|
const { name } = this.tokens;
|
|
if (!name) {
|
|
return "";
|
|
}
|
|
return unescape(name.value);
|
|
}
|
|
get special() {
|
|
if (!this.tokens.special) {
|
|
return "";
|
|
}
|
|
return this.tokens.special.value;
|
|
}
|
|
|
|
*validate(defs) {
|
|
yield* this.extAttrs.validate(defs);
|
|
if (!this.name && ["", "static"].includes(this.special)) {
|
|
const message = `Regular or static operations must have both a return type and an identifier.`;
|
|
yield validationError(this.tokens.open, this, "incomplete-op", message);
|
|
}
|
|
if (this.idlType) {
|
|
yield* this.idlType.validate(defs);
|
|
}
|
|
for (const argument of this.arguments) {
|
|
yield* argument.validate(defs);
|
|
}
|
|
}
|
|
|
|
/** @param {import("../writer.js").Writer} w */
|
|
write(w) {
|
|
const { parent } = this;
|
|
const body = this.idlType
|
|
? [
|
|
w.ts.type(this.idlType.write(w)),
|
|
w.name_token(this.tokens.name, { data: this, parent }),
|
|
w.token(this.tokens.open),
|
|
w.ts.wrap(this.arguments.map((arg) => arg.write(w))),
|
|
w.token(this.tokens.close),
|
|
]
|
|
: [];
|
|
return w.ts.definition(
|
|
w.ts.wrap([
|
|
this.extAttrs.write(w),
|
|
this.tokens.name
|
|
? w.token(this.tokens.special)
|
|
: w.token(this.tokens.special, w.ts.nameless, { data: this, parent }),
|
|
...body,
|
|
w.token(this.tokens.termination),
|
|
]),
|
|
{ data: this, parent }
|
|
);
|
|
}
|
|
}
|