mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 04:26:32 +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>
95 lines
2.5 KiB
JavaScript
95 lines
2.5 KiB
JavaScript
import { list, unescape, autoParenter } from "./helpers.js";
|
|
import { WrappedToken } from "./token.js";
|
|
import { Base } from "./base.js";
|
|
|
|
class EnumValue extends WrappedToken {
|
|
/**
|
|
* @param {import("../tokeniser").Tokeniser} tokeniser
|
|
*/
|
|
static parse(tokeniser) {
|
|
const value = tokeniser.consumeKind("string");
|
|
if (value) {
|
|
return new EnumValue({ source: tokeniser.source, tokens: { value } });
|
|
}
|
|
}
|
|
|
|
get type() {
|
|
return "enum-value";
|
|
}
|
|
get value() {
|
|
return super.value.slice(1, -1);
|
|
}
|
|
|
|
/** @param {import("../writer.js").Writer} w */
|
|
write(w) {
|
|
const { parent } = this;
|
|
return w.ts.wrap([
|
|
w.ts.trivia(this.tokens.value.trivia),
|
|
w.ts.definition(
|
|
w.ts.wrap(['"', w.ts.name(this.value, { data: this, parent }), '"']),
|
|
{ data: this, parent }
|
|
),
|
|
w.token(this.tokens.separator),
|
|
]);
|
|
}
|
|
}
|
|
|
|
export class Enum extends Base {
|
|
/**
|
|
* @param {import("../tokeniser").Tokeniser} tokeniser
|
|
*/
|
|
static parse(tokeniser) {
|
|
/** @type {Base["tokens"]} */
|
|
const tokens = {};
|
|
tokens.base = tokeniser.consume("enum");
|
|
if (!tokens.base) {
|
|
return;
|
|
}
|
|
tokens.name =
|
|
tokeniser.consumeKind("identifier") ||
|
|
tokeniser.error("No name for enum");
|
|
const ret = autoParenter(new Enum({ source: tokeniser.source, tokens }));
|
|
tokeniser.current = ret.this;
|
|
tokens.open = tokeniser.consume("{") || tokeniser.error("Bodyless enum");
|
|
ret.values = list(tokeniser, {
|
|
parser: EnumValue.parse,
|
|
allowDangler: true,
|
|
listName: "enumeration",
|
|
});
|
|
if (tokeniser.probeKind("string")) {
|
|
tokeniser.error("No comma between enum values");
|
|
}
|
|
tokens.close =
|
|
tokeniser.consume("}") || tokeniser.error("Unexpected value in enum");
|
|
if (!ret.values.length) {
|
|
tokeniser.error("No value in enum");
|
|
}
|
|
tokens.termination =
|
|
tokeniser.consume(";") || tokeniser.error("No semicolon after enum");
|
|
return ret.this;
|
|
}
|
|
|
|
get type() {
|
|
return "enum";
|
|
}
|
|
get name() {
|
|
return unescape(this.tokens.name.value);
|
|
}
|
|
|
|
/** @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.open),
|
|
w.ts.wrap(this.values.map((v) => v.write(w))),
|
|
w.token(this.tokens.close),
|
|
w.token(this.tokens.termination),
|
|
]),
|
|
{ data: this }
|
|
);
|
|
}
|
|
}
|