Files
react-native-devtools-frontend/node_modules/webidl2/lib/productions/constant.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

75 lines
2.0 KiB
JavaScript

import { Base } from "./base.js";
import { Type } from "./type.js";
import {
const_data,
const_value,
primitive_type,
autoParenter,
unescape,
} from "./helpers.js";
export class Constant extends Base {
/**
* @param {import("../tokeniser.js").Tokeniser} tokeniser
*/
static parse(tokeniser) {
/** @type {Base["tokens"]} */
const tokens = {};
tokens.base = tokeniser.consume("const");
if (!tokens.base) {
return;
}
let idlType = primitive_type(tokeniser);
if (!idlType) {
const base =
tokeniser.consumeKind("identifier") ||
tokeniser.error("Const lacks a type");
idlType = new Type({ source: tokeniser.source, tokens: { base } });
}
if (tokeniser.probe("?")) {
tokeniser.error("Unexpected nullable constant type");
}
idlType.type = "const-type";
tokens.name =
tokeniser.consumeKind("identifier") ||
tokeniser.error("Const lacks a name");
tokens.assign =
tokeniser.consume("=") || tokeniser.error("Const lacks value assignment");
tokens.value =
const_value(tokeniser) || tokeniser.error("Const lacks a value");
tokens.termination =
tokeniser.consume(";") ||
tokeniser.error("Unterminated const, expected `;`");
const ret = new Constant({ source: tokeniser.source, tokens });
autoParenter(ret).idlType = idlType;
return ret;
}
get type() {
return "const";
}
get name() {
return unescape(this.tokens.name.value);
}
get value() {
return const_data(this.tokens.value);
}
/** @param {import("../writer.js").Writer} w */
write(w) {
const { parent } = this;
return w.ts.definition(
w.ts.wrap([
this.extAttrs.write(w),
w.token(this.tokens.base),
w.ts.type(this.idlType.write(w)),
w.name_token(this.tokens.name, { data: this, parent }),
w.token(this.tokens.assign),
w.token(this.tokens.value),
w.token(this.tokens.termination),
]),
{ data: this, parent }
);
}
}