本文整理汇总了TypeScript中op/Op.nonNull函数的典型用法代码示例。如果您正苦于以下问题:TypeScript nonNull函数的具体用法?TypeScript nonNull怎么用?TypeScript nonNull使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nonNull函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: renderModuleDeclaration
export function renderModuleDeclaration(_: ModuleDeclaration): void {
setAst(_)
if (_ instanceof ImportDeclaration)
renderImportDeclarationNoLoc(_)
else if (_ instanceof ExportNamedDeclaration) {
const {declaration, specifiers, source} = _
o('export ')
if (nonNull(declaration))
renderDeclaration(declaration)
else {
o('{')
interleave(specifiers, renderExportSpecifier, ',')
o('}')
if (nonNull(source)) {
o(' from ')
renderLiteralString(source)
}
}
} else if (_ instanceof ExportDefaultDeclaration) {
o('export default ')
renderDeclarationOrExpression(_.declaration)
} else if (_ instanceof ExportAllDeclaration) {
o('export * from ')
renderLiteralString(_.source)
} else
throw badType(_)
}
示例2: renderContinueStatementNoLoc
export function renderContinueStatementNoLoc({label}: ContinueStatement): void {
o('continue')
if (nonNull(label)) {
o(' ')
renderIdentifier(label)
}
}
示例3: renderBreakStatementNoLoc
export function renderBreakStatementNoLoc({label}: BreakStatement): void {
o('break')
if (nonNull(label)) {
o(' ')
renderIdentifier(label)
}
}
示例4: parseName
/** Parse a [[Name]] or a [[Keyword]] usable as one. */
export default function parseName(token: Token): string {
const name = tryParseName(token)
if (nonNull(name))
return name
else
throw unexpected(token)
}
示例5: maybeWrapInCheckInstance
export function maybeWrapInCheckInstance(
ast: Expression,
opType: Op<Val>,
name: string)
: Expression {
return compileOptions.checks && nonNull(opType) ?
msCall('checkInstance', transpileVal(opType), ast, new LiteralString(name)) :
ast
}
示例6: renderVariableDeclarator
export function renderVariableDeclarator(_: VariableDeclarator): void {
setAst(_)
const {id, init} = _
renderPattern(id)
if (nonNull(init)) {
o('=')
renderExpression(init)
}
}
示例7: renderLoopNoLoc
export function renderLoopNoLoc(_: Loop): void {
if (_ instanceof WhileStatement) {
const {test, body} = _
o('while(')
renderExpression(test)
o(')')
renderStatement(body)
} else if (_ instanceof DoWhileStatement) {
const {body, test} = _
o('do ')
renderStatement(body)
if (!(body instanceof BlockStatement))
o(';')
o(' while(')
renderExpression(test)
o(')')
} else if (_ instanceof ForStatement) {
const {init, test, update, body} = _
o('for(')
if (nonNull(init))
renderVariableDeclarationOrExpression(init)
o(';')
if (nonNull(test))
renderExpression(test)
o(';')
if (nonNull(update))
renderExpression(update)
o(')')
renderStatement(body)
} else if (_ instanceof ForInOfStatement) {
o('for(')
renderVariableDeclarationOrIdentifier(_.left)
o(_ instanceof ForOfStatement ? ' of ' : ' in ')
renderExpression(_.right)
o(')')
renderStatement(_.body)
} else
throw badType(_)
}
示例8: parseMemberName
/** Parse a plain member (`a.b`) or computed member (`a."b"`). */
export default function parseMemberName(token: Token): MemberName {
const name = tryParseName(token)
if (nonNull(name)) // .foo
return name
else if (token instanceof GroupQuote) // ."foo"
return parseQuote(Slice.of(token))
else if (token instanceof GroupParenthesis) // .(foo)
return parseExpr(Tokens.of(token))
else
throw unexpected(token)
}
示例9: renderFunctionNoLoc
export function renderFunctionNoLoc(_: FunctionDeclaration | FunctionExpression): void {
const {id, params, body, async, generator} = _
if (async)
o('async ')
o('function')
if (generator)
o('*')
if (nonNull(id)) {
o(' ')
renderIdentifier(id)
}
paren(params, renderPattern)
renderBlockStatement(body)
}
示例10: mapStr
function mapStr(str: string): void {
if (curAst !== lastMappedAst) {
const {loc} = curAst
if (nonNull(loc)) {
sourceMap.addMapping({
source: inFilePath,
original: loc.start,
generated: new Pos(outLine, outColumn)
})
lastMappedAst = curAst
}
}
outColumn = outColumn + str.length
}