本文整理匯總了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
}