• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript Op.opIf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中op/Op.opIf函数的典型用法代码示例。如果您正苦于以下问题:TypeScript opIf函数的具体用法?TypeScript opIf怎么用?TypeScript opIf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了opIf函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: transpileSwitchPart

function transpileSwitchPart(_: SwitchPart, isDo: boolean):  Array<SwitchCase> {
	const {values, result} = _

	const follow = opIf(isDo, () => new BreakStatement)
	/*
	We could just pass block.body for the switch lines, but instead
	enclose the body of the switch case in curly braces to ensure a new scope.
	That way this code works:
		switch (0) {
			case 0: {
				const a = 0
				return a
			}
			default: {
				// Without curly braces this would conflict with the other `a`.
				const a = 1
				a
			}
		}
	*/
	const block = transpileBlock(result, {follow})
	// If switch has multiple values, build up a statement like: `case 1: case 2: { doBlock() }`
	const cases: Array<SwitchCase> = []
	for (let i = 0; i < values.length - 1; i = i + 1)
		// These cases fallthrough to the one at the end.
		cases.push(loc(_, new SwitchCase(transpileVal(values[i]), [])))
	cases.push(loc(_, new SwitchCase(transpileVal(values[values.length - 1]), [block])))
	return cases
}
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:29,代码来源:transpileSwitch.ts


示例3: opTypeCheckForLocalDeclare

export function opTypeCheckForLocalDeclare(localDeclare: LocalDeclare): Op<Statement> {
	// TODO: Way to typecheck lazies
	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,代码行数:10,代码来源:transpileLocals.ts


示例4: parseSpacedFold

function parseSpacedFold(start: Val, rest: Tokens): Val {
	let acc = start
	for (let i = rest.start; i < rest.end; i = i + 1) {
		function restVal(): Val {
			return parseSpaced(rest.chopStart(i + 1))
		}

		const token = rest.tokens[i]
		const loc = token.loc
		if (token instanceof KeywordPlain)
			switch (token.kind) {
				case Kw.Ampersand:
					if (i === rest.end - 1)
						throw unexpected(token)
					i = i + 1
					acc = new FunMember(token.loc, acc, parseMemberName(rest.tokens[i]))
					break
				case Kw.Dot: {
					// If this were the last one,
					// it would not be a Kw.Dot but a Kw.ObjEntry
					assert(i < rest.end - 1)
					i = i + 1
					acc = new Member(token.loc, acc, parseMemberName(rest.tokens[i]))
					break
				}
				case Kw.Dot2:
					check(i < rest.end - 1, token.loc, _ => _.infiniteRange)
					return new Range(token.loc, acc, restVal(), false)
				case Kw.Dot3:
					return new Range(token.loc, acc, opIf(i < rest.end - 1, restVal), true)
				case Kw.Focus:
					acc = new Call(token.loc, acc, [LocalAccess.focus(loc)])
					break
				case Kw.Colon:
					return new InstanceOf(token.loc, acc, restVal())
				default:
					throw unexpected(token)
			}
		else if (token instanceof GroupBracket)
			acc = new Sub(loc, acc, parseExprParts(Tokens.of(token)))
		else if (token instanceof GroupParenthesis) {
			checkEmpty(Tokens.of(token), _ => _.parensOutsideCall)
			acc = new Call(loc, acc, [])
		} else if (token instanceof GroupQuote)
			acc = new QuoteTagged(loc, acc, parseQuote(Slice.of(token)))
		else
			throw unexpected(token)
	}
	return acc
}
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:50,代码来源:parseSpaced.ts


示例5: 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


示例6: constructor

	constructor(
		loc: Loc,
		public args: Array<LocalDeclare>,
		public opRestArg: Op<LocalDeclare>,
		public block: Block,
		opts: FunBlockOptions = {}) {
		super(loc)
		const {kind, isThisFun, isDo, opReturnType} = applyDefaults(opts, {
			kind: Funs.Plain,
			isThisFun: false,
			isDo: false,
			opReturnType: null
		})
		this.kind = kind
		this.opDeclareThis = opIf(isThisFun, () => LocalDeclare.this(this.loc))
		this.isDo = isDo
		this.opReturnType = opReturnType
	}
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:18,代码来源:Fun.ts


示例7: parseLocalPartsFromSpaced

function parseLocalPartsFromSpaced(tokens: Tokens, orMember: boolean = false)
	: {name: string, opType: Op<Val>, kind: LocalDeclares, isMember: boolean} {
	const [rest, kind, isMember] =
		isKeyword(Kw.Lazy, tokens.head()) ?
			[tokens.tail(), LocalDeclares.Lazy, false] :
			orMember && isKeyword(Kw.Dot, tokens.head()) ?
			[tokens.tail(), LocalDeclares.Eager, true] :
			[tokens, LocalDeclares.Eager, false]
	const name = parseLocalName(rest.head())
	const rest2 = rest.tail()
	const opType = opIf(!rest2.isEmpty(), () => {
		const colon = rest2.head()
		checkKeyword(Kw.Colon, colon)
		const tokensType = rest2.tail()
		checkNonEmpty(tokensType, _ => _.expectedAfterColon)
		return parseSpaced(tokensType)
	})
	return {name, opType, kind, isMember}
}
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:19,代码来源:parseLocalDeclares.ts


示例8: opParseIteratee

function opParseIteratee(tokens: Tokens): Op<Iteratee> {
	return opIf(!tokens.isEmpty(), () => parseIteratee(tokens))
}
开发者ID:mason-lang,项目名称:mason-lang.github.io,代码行数:3,代码来源:parseFor.ts



注:本文中的op/Op.opIf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript Op.opMap函数代码示例发布时间:2022-05-25
下一篇:
TypeScript Op.opEach函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap