本文整理汇总了TypeScript中op/Op.opMap函数的典型用法代码示例。如果您正苦于以下问题:TypeScript opMap函数的具体用法?TypeScript opMap怎么用?TypeScript opMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了opMap函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: withFunKind
return withFunKind(kind, () => {
// TODO:ES6 use `...`f
const nArgs = new LiteralNumber(args.length)
const opDeclareRest = opMap(opRestArg, rest =>
makeDeclare(rest, new CallExpression(arraySliceCall, [idArguments, nArgs])))
const argChecks = opIf(compileOptions.checks, () =>
flatMapOps(args, opTypeCheckForLocalDeclare))
const opDeclareThisAst = opIf(opDeclareThis !== null && !dontDeclareThis, () =>
declareLexicalThis)
const lead = cat(opDeclareRest, opDeclareThisAst, argChecks, leadStatements)
const body = () => transpileBlock(block, {lead, opReturnType})
const argAsts = args.map(transpileLocalDeclare)
const id = opMap(verifyResults.opName(_), identifier)
switch (kind) {
case Funs.Async: {
const plainBody = transpileBlock(block, {opReturnType})
const genFunc = new FunctionExpression(null, [], plainBody, {generator: true})
const ret = new ReturnStatement(msCall('async', genFunc))
return new FunctionExpression(id, argAsts, new BlockStatement(cat(lead, ret)))
}
case Funs.Generator:
return new FunctionExpression(id, argAsts, body(), {generator: true})
case Funs.Plain:
// TODO:ES6 Should be able to use rest args in arrow function
return id === null && opDeclareThis === null && opDeclareRest === null ?
new ArrowFunctionExpression(argAsts, body()) :
new FunctionExpression(id, argAsts, body())
default:
throw new Error(String(kind))
}
})
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:35,代码来源:transpileFun.ts
示例2: opIf
return opIf(!localDeclare.isLazy, () =>
opMap(localDeclare.opType, type =>
new ExpressionStatement(msCall(
'checkInstance',
transpileVal(type),
accessLocalDeclare(localDeclare),
new LiteralString(localDeclare.name)))))
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:7,代码来源:transpileLocals.ts
示例3: transpileYieldLikeNoLoc
export function transpileYieldLikeNoLoc(_: YieldLike): Expression {
if (_ instanceof Yield)
return new YieldExpression(opMap(_.opValue, transpileVal))
else if (_ instanceof YieldTo)
return new YieldDelegateExpression(transpileVal(_.value))
else
throw new Error(_.constructor.name)
}
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:8,代码来源:transpileYieldLike.ts
示例4: parseClassHeader
function parseClassHeader(tokens: Tokens)
: {opFields: Op<Array<Field>>, opSuperClass: Op<Val>, traits: Array<Val>} {
const [fieldsTokens, [extendsTokens, traitTokens]] =
tokens.getKeywordSections(Kw.Extends, Kw.Trait)
return {
opFields: opIf(!fieldsTokens.isEmpty(), () => fieldsTokens.map(_ => {
const {name, opType, kind} = parseLocalParts(_)
check(kind === LocalDeclares.Eager, _.loc, _ => _.todoLazyField)
return new Field(_.loc, name, opType)
})),
opSuperClass: opMap(extendsTokens, parseExpr),
traits: caseOp(traitTokens, parseExprParts, () => [])
}
}
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:14,代码来源:parseClass.ts
示例5: opKeywordFromName
export function opKeywordFromName(loc: Loc, name: string): Op<Keyword> {
// I tried a switch statement, but using a map of closures was actually faster.
return opMap(nameToKeywordCreator.get(name), _ => _(loc))
}
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:4,代码来源:Keyword.ts
示例6: parseCase
export default function parseCase(tokens: Tokens): Case {
const [before, block] = beforeAndBlock(tokens)
const opCased = opMap(opParseExpr(before), _ => AssignSingle.focus(_.loc, _))
const {parts, opElse} = parseCaseParts(block)
return new Case(tokens.loc, opCased, parts, opElse)
}
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:6,代码来源:parseCase.ts
注:本文中的op/Op.opMap函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论