本文整理汇总了TypeScript中op/Op.caseOp函数的典型用法代码示例。如果您正苦于以下问题:TypeScript caseOp函数的具体用法?TypeScript caseOp怎么用?TypeScript caseOp使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了caseOp函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: parseClass
/** Parse a [[Class]]. */
export default function parseClass(tokens: Tokens): Class {
const [before, opBlock] = beforeAndOpBlock(tokens)
const {opFields, opSuperClass, traits} = parseClassHeader(before)
type Tuple = [Op<string>, Op<ClassTraitDo>,
Array<MethodImplLike>, Op<Constructor>, Array<MethodImplLike>]
const [opComment, opDo, statics, opConstructor, methods] = caseOp<Lines, Tuple>(
opBlock,
_ => {
const [opComment, rest] = tryTakeComment(_)
if (rest.isEmpty())
return [opComment, null, [], null, []]
const [opDo, rest2] = opTakeDo(rest)
if (rest2.isEmpty())
return [opComment, opDo, [], null, []]
const [statics, rest3] = takeStatics(rest2)
if (rest3.isEmpty())
return [opComment, opDo, statics, null, []]
const [opConstructor, rest4] = opTakeConstructor(rest3)
return [opComment, opDo, statics, opConstructor, parseMethodImpls(rest4)]
},
() => [null, null, [], null, []])
return new Class(
tokens.loc,
opFields, opSuperClass, traits, opComment, opDo, statics, opConstructor, methods)
}
示例2: verifyModuleLines
function verifyModuleLines(lines: Array<LineContent>, loc: Loc): void {
results.moduleKind = caseOp(
opBlockBuildKind(lines, loc),
buildKind => {
if (buildKind === Blocks.Obj) {
for (const line of lines)
if (line instanceof ObjEntry)
results.objEntryExports.add(line)
verifyLines(lines)
return Modules.Exports
} else {
verifyBuiltLines(lines, loc)
return buildKind === Blocks.Bag ? Modules.Bag : Modules.Map
}
},
() => {
if (isEmpty(lines))
return Modules.Do
else {
const l = last(lines)
const lastSK = getLineSK(l)
if (lastSK === SK.Do) {
verifyLines(lines)
return Modules.Do
} else {
const newLocals = verifyLines(rtail(lines))
plusLocals(newLocals, () => ensureValAndVerify(l))
return Modules.Val
}
}
})
}
示例3: ArrayExpression
new ArrayExpression(value.args.map((arg: LocalDeclare) => {
const name = new LiteralString(arg.name)
return caseOp<Val, Expression>(
arg.opType,
_ => new ArrayExpression([name, transpileVal(_)]),
() => name)
})) :
示例4: transpileFunNoLoc
export function transpileFunNoLoc(_: Fun): Expression {
if (_ instanceof FunBlock)
return transpileFunBlockNoLoc(_)
else if (_ instanceof FunGetter)
// _ => _.foo
return focusFun(transpileMember(idFocus, _.name))
else if (_ instanceof FunMember) {
const {opObject, name} = _
const nameAst = transpileMemberName(name)
return caseOp(
opObject,
_ => msCall('methodBound', transpileVal(_), nameAst),
() => msCall('methodUnbound', nameAst))
} else if (_ instanceof FunOperator)
return transpileFunOperatorNoLoc(_)
else if (_ instanceof FunSimple)
return focusFun(transpileVal(_.value))
else if (_ instanceof FunUnary)
return transpileFunUnaryNoLoc(_)
else
throw new Error(_.constructor.name)
}
示例5: transpileSwitchVDNoLoc
function transpileSwitchVDNoLoc({switched, parts, opElse}: Switch, isDo: boolean): Statement {
const partAsts = flatMap(parts, _ => transpileSwitchPart(_, isDo))
partAsts.push(caseOp(
opElse,
_ => loc(_, new SwitchCase(null, transpileBlock(_).body)),
() => switchCaseNoMatch))
return new SwitchStatement(transpileVal(switched), partAsts)
}
示例6: parseObjSimple
export default function parseObjSimple(tokens: Tokens): Val {
const pairs = caseOp(
tokens.opSplitMany(_ => isKeyword(Kw.ObjEntry, _)),
_ => complexPairs(tokens.loc, _),
// Parse 'pairs' like in `{a b}` (equivalent to `{a. a b. b}`),
// where every pair is a single identifier.
() => tokens.map(simplePair))
return new ObjSimple(tokens.loc, pairs)
}
示例7: parseIteratee
function parseIteratee(tokens: Tokens): Iteratee {
const [element, bag]: any = caseOp<{before: Tokens, after: Tokens}, [LocalDeclare, Val]>(
tokens.opSplitOnce(_ => isKeyword(Kw.Of, _)),
({before, after}) => {
check(before.size() === 1, before.loc, _ => _.todoForPattern)
return [parseLocalDeclaresJustNames(before)[0], parseExpr(after)]
},
() => [LocalDeclare.focus(tokens.loc), parseExpr(tokens)])
return new Iteratee(tokens.loc, element, bag)
}
示例8: transpileTraitNoLoc
export function transpileTraitNoLoc(_: Trait): Expression {
const {superTraits, opDo, statics, methods} = _
const name = new LiteralString(verifyResults.name(_))
const supers = new ArrayExpression(superTraits.map(transpileVal))
const trait = msCall('trait', name, supers, methodsObject(statics), methodsObject(methods))
return caseOp(
opDo,
_ => transpileBlockVal(_.block, {lead: plainLet(idFocus, trait), follow: returnFocus}),
() => trait)
}
示例9: verifyLoop
export default function verifyLoop(_: For | ForBag, sk: SK): void {
const {opIteratee, block} = _
function verifyBlock(): void {
withLoop({loop: _, sk}, () => verifyBlockDo(block))
}
caseOp(
opIteratee,
_ => withVerifyIteratee(_, verifyBlock),
verifyBlock)
}
示例10: accessBuiltin
accessBuiltin(name: string, path: string): void {
caseOp(
this.builtinPathToNames.get(path),
_ => {
_.add(name)
},
() => {
this.builtinPathToNames.set(path, new Set([name]))
})
}