本文整理汇总了TypeScript中@glimmer/util.dict函数的典型用法代码示例。如果您正苦于以下问题:TypeScript dict函数的具体用法?TypeScript dict怎么用?TypeScript dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dict函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: debug
export function debug(c: DebugConstants, op: Op, ...operands: number[]): [string, object] {
let metadata = METADATA[op];
if (!metadata) {
throw unreachable(`Missing Opcode Metadata for ${op}`);
}
let out = dict<Opaque>();
metadata.ops.forEach((operand, index) => {
let op = operands[index];
switch (operand.type) {
case 'i32':
case 'symbol':
case 'block':
out[operand.name] = op;
break;
case 'handle':
out[operand.name] = c.resolveHandle(op);
break;
case 'str':
out[operand.name] = c.getString(op);
break;
case 'option-str':
out[operand.name] = op ? c.getString(op) : null;
break;
case 'str-array':
out[operand.name] = c.getStringArray(op);
break;
case 'array':
out[operand.name] = c.getArray(op);
break;
case 'bool':
out[operand.name] = !!op;
break;
case 'primitive':
out[operand.name] = decodePrimitive(op, c);
break;
case 'register':
out[operand.name] = Register[op];
break;
case 'table':
out[operand.name] = c.getSymbolTable(op);
break;
case 'serializable':
out[operand.name] = c.getSerializable(op);
break;
case 'lazy-constant':
out[operand.name] = (c as Recast<DebugConstants, LazyDebugConstants>).getOther(op);
break;
}
});
return [metadata.name, out];
}
示例2: specifierFor
export function specifierFor(module: ModuleName, name: NamedExport): Specifier {
let specifiers = SPECIFIERS[module];
if (!specifiers) specifiers = SPECIFIERS[module] = dict<Specifier>();
let specifier = specifiers[name];
if (!specifier) specifier = specifiers[name] = { module, name };
return specifier;
}
示例3: check
APPEND_OPCODES.add(Op.InvokePartial, (vm, { op1: _meta, op2: _symbols, op3: _evalInfo }) => {
let { constants, constants: { resolver }, stack } = vm;
let name = check(stack.pop(), CheckReference).value();
assert(typeof name === 'string', `Could not find a partial named "${String(name)}"`);
let meta = constants.getSerializable<TemplateMeta>(_meta);
let outerSymbols = constants.getStringArray(_symbols);
let evalInfo = constants.getArray(_evalInfo);
let specifier = resolver.lookupPartial(name as string, meta);
assert(specifier, `Could not find a partial named "${name}"`);
let definition = resolver.resolve<PartialDefinition>(specifier!);
let { symbolTable, handle } = definition.getPartial();
{
let partialSymbols = symbolTable.symbols;
let outerScope = vm.scope();
let partialScope = vm.pushRootScope(partialSymbols.length, false);
partialScope.bindCallerScope(outerScope.getCallerScope());
partialScope.bindEvalScope(outerScope.getEvalScope());
partialScope.bindSelf(outerScope.getSelf());
let locals = dict<VersionedPathReference<Opaque>>();
for (let i = 0; i < evalInfo.length; i++) {
let slot = evalInfo[i];
let name = outerSymbols[slot - 1];
let ref = outerScope.getSymbol(slot);
locals[name] = ref;
}
let evalScope = outerScope.getEvalScope()!;
for (let i = 0; i < partialSymbols.length; i++) {
let name = partialSymbols[i];
let symbol = i + 1;
let value = evalScope[name];
if (value !== undefined) partialScope.bind(symbol, value);
}
partialScope.bindPartialMap(locals);
vm.pushFrame(); // sp += 2
vm.call(handle!);
}
expectStackChange(vm.stack, 1, 'InvokePartial');
});
示例4: forEach
import { Option, Dict, dict, HAS_NATIVE_WEAKMAP } from '@glimmer/util';
export const EMPTY_ARRAY: any[] = (HAS_NATIVE_WEAKMAP ? Object.freeze([]) : []) as any;
export const EMPTY_DICT: Dict<any> = HAS_NATIVE_WEAKMAP ? Object.freeze(dict<any>()) : dict<any>();
export interface EnumerableCallback<T> {
(item: T): void;
}
export interface Enumerable<T> {
forEach(callback: EnumerableCallback<T>): void;
}
export interface Destroyable {
destroy(): void;
}
export interface Range<T> {
min(): number;
max(): number;
at(index: number): Option<T>;
}
export class ListRange<T> implements Range<T> {
private list: T[];
// [start, end]
private start: number;
private end: number;
constructor(list: T[], start: number, end: number) {
示例5: equalsElement
export function equalsElement(element: Element | null, tagName: string, attributes: Object, content: string) {
if (element === null) {
QUnit.assert.pushResult({
result: false,
actual: element,
expected: true,
message: `failed - expected element to not be null`
});
return;
}
QUnit.assert.pushResult({
result: element.tagName === tagName.toUpperCase(),
actual: element.tagName.toLowerCase(),
expected: tagName,
message: `expect tagName to be ${tagName}`
});
let expectedAttrs: Dict<Matcher> = dict<Matcher>();
let expectedCount = 0;
for (let prop in attributes) {
expectedCount++;
let expected = attributes[prop];
let matcher: Matcher = typeof expected === 'object' && MATCHER in expected ? expected : equalsAttr(expected);
expectedAttrs[prop] = matcher;
QUnit.assert.pushResult({
result: expectedAttrs[prop].match(element && element.getAttribute(prop)),
actual: matcher.fail(element && element.getAttribute(prop)),
expected: matcher.fail(element && element.getAttribute(prop)),
message: `Expected element's ${prop} attribute ${matcher.expected()}`
});
}
let actualAttributes = {};
if (element) {
for (let i = 0, l = element.attributes.length; i < l; i++) {
actualAttributes[element.attributes[i].name] = element.attributes[i].value;
}
}
if (!(element instanceof HTMLElement)) {
QUnit.assert.pushResult({
result: element instanceof HTMLElement,
actual: null,
expected: null,
message: "Element must be an HTML Element, not an SVG Element"
});
} else {
QUnit.assert.pushResult({
result: element.attributes.length === expectedCount,
actual: element.attributes.length,
expected: expectedCount,
message: `Expected ${expectedCount} attributes; got ${element.outerHTML}`
});
if (content !== null) {
QUnit.assert.pushResult({
result: element.innerHTML === content,
actual: element.innerHTML,
expected: content,
message: `The element had '${content}' as its content`
});
}
}
}