本文整理汇总了TypeScript中babel-types.isNullLiteral函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isNullLiteral函数的具体用法?TypeScript isNullLiteral怎么用?TypeScript isNullLiteral使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isNullLiteral函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: isEmptyDeclarator
export function isEmptyDeclarator (node: t.Node) {
if (
t.isVariableDeclarator(node) &&
(node.init === null ||
t.isNullLiteral(node.init))
) {
return true
}
return false
}
开发者ID:topud,项目名称:taro,代码行数:10,代码来源:utils.ts
示例2:
// Remove null args at the end of method or constructor calls.
// This may conflict in some situations when comparing null to undefined, see #231,
// but if disabled can cause problems with some APIs that use options to represent optional
// arguments like CanvasRenderingContext2D.fill: ?fillRule: string -> unit (fails if passed null).
function removeNullTailArgs<T>(path: traverse.NodePath<types.NewExpression | types.CallExpression>) {
if (Array.isArray(path.node.arguments)) {
for (var i = path.node.arguments.length - 1; i >= 0; i--) {
if (types.isNullLiteral(path.node.arguments[i]))
path.node.arguments.splice(i, 1);
else
break;
}
}
}
开发者ID:fdcastel,项目名称:Fable,代码行数:14,代码来源:babelPlugins.ts
示例3: getArgumentName
export function getArgumentName (arg) {
if (t.isThisExpression(arg)) {
return 'this'
} else if (t.isNullLiteral(arg)) {
return 'null'
} else if (t.isStringLiteral(arg) || t.isNumericLiteral(arg)) {
return arg.value
} else if (t.isIdentifier(arg)) {
return arg.name
} else {
return generate(arg).code
}
throw new Error(`bind 不支持传入该参数: ${arg}`)
}
开发者ID:topud,项目名称:taro,代码行数:14,代码来源:utils.ts
示例4: toConstant
//.........这里部分代码省略.........
) {
return options.constants[expression.name];
}
}
if (b.isLogicalExpression(expression)) {
const left = toConstant(expression.left);
const right = toConstant(expression.right);
if (constant && expression.operator === '&&') {
return left && right;
}
if (constant && expression.operator === '||') {
return left || right;
}
}
if (b.isMemberExpression(expression)) {
const object = toConstant(expression.object);
if (!object || !constant) {
constant = false;
return;
}
const member = expression.computed
? toConstant(expression.property)
: b.isIdentifier(expression.property)
? expression.property.name
: undefined;
if (member === undefined && !expression.computed) {
constant = false;
}
if (!constant) return;
if ({}.hasOwnProperty.call(object, '' + member) && member[0] !== '_') {
return object[member];
}
}
if (b.isNullLiteral(expression)) {
return null;
}
if (b.isNumericLiteral(expression)) {
return expression.value;
}
if (b.isObjectExpression(expression)) {
const result: any = {};
for (let i = 0; constant && i < expression.properties.length; i++) {
const property = expression.properties[i];
if (b.isObjectProperty(property)) {
if (property.shorthand) {
constant = false;
return;
}
const key = property.computed
? toConstant(property.key)
: b.isIdentifier(property.key)
? property.key.name
: b.isStringLiteral(property.key)
? property.key.value
: undefined;
if (!key || key[0] === '_') {
constant = false;
}
if (!constant) return;
const value = toConstant(property.value);
if (!constant) return;
result[key] = value;
} else if (b.isObjectMethod(property)) {
constant = false;
} else if (b.isSpreadProperty(property)) {
const argument = toConstant(property.argument);
开发者ID:Ashwinie,项目名称:inceptionEngine,代码行数:67,代码来源:index.ts
示例5: parseLoopBody
export function parseLoopBody (
body: NodePath<t.BlockStatement>,
jsxDeclarations: Set<NodePath<t.Node>>,
// @TODO
// 把 templates 换成 Map 可以支持 shalow variables declared
// 现在先用 ESLint 的 no-shalow 顶着
templates: Map<string, t.JSXElement>,
loopScopes: Set<string>,
finalReturnElement: t.JSXElement,
returnedPaths: NodePath<t.Node>[]
) {
const bodyScope = body.scope
body.traverse({
JSXElement (jsxElementPath) {
const parentNode = jsxElementPath.parent
const parentPath = jsxElementPath.parentPath
const isFinalReturn = jsxElementPath.getFunctionParent().isClassMethod()
const isJSXChildren = t.isJSXElement(parentNode)
if (!isJSXChildren) {
let statementParent = jsxElementPath.getStatementParent()
if (
!(
statementParent.isVariableDeclaration() ||
statementParent.isExpressionStatement()
)
) {
statementParent = statementParent.findParent(
s => s.isVariableDeclaration() || s.isExpressionStatement()
) as NodePath<t.Statement>
}
jsxDeclarations.add(statementParent)
if (t.isVariableDeclarator(parentNode)) {
if (statementParent) {
const name = findIdentifierFromStatement(statementParent.node as t.VariableDeclaration)
// setTemplate(name, path, templates)
name && templates.set(name, jsxElementPath.node)
}
} else if (t.isLogicalExpression(parentNode)) {
const { left, operator } = parentNode
if (operator === '&&') {
if (t.isExpression(left)) {
newJSXIfAttr(jsxElementPath.node, left)
parentPath.replaceWith(jsxElementPath.node)
if (statementParent) {
const name = findIdentifierFromStatement(statementParent.node as t.VariableDeclaration)
setTemplate(name, jsxElementPath, templates)
// name && templates.set(name, path.node)
}
}
}
} else if (t.isConditionalExpression(parentNode)) {
const { test, consequent, alternate } = parentNode
const block = buildBlockElement()
if (t.isJSXElement(consequent) && t.isLiteral(alternate)) {
const { value, confident } = parentPath.get('alternate').evaluate()
if (confident && !value) {
newJSXIfAttr(block, test)
block.children = [ jsxElementPath.node ]
// newJSXIfAttr(jsxElementPath.node, test)
parentPath.replaceWith(block)
if (statementParent) {
const name = findIdentifierFromStatement(
statementParent.node as t.VariableDeclaration
)
setTemplate(name, jsxElementPath, templates)
// name && templates.set(name, path.node)
}
}
} else if (t.isLiteral(consequent) && t.isJSXElement(consequent)) {
if (t.isNullLiteral(consequent)) {
newJSXIfAttr(block, reverseBoolean(test))
// newJSXIfAttr(jsxElementPath.node, reverseBoolean(test))
parentPath.replaceWith(block)
if (statementParent) {
const name = findIdentifierFromStatement(
statementParent.node as t.VariableDeclaration
)
setTemplate(name, jsxElementPath, templates)
// name && templates.set(name, path.node)
}
}
} else if (t.isJSXElement(consequent) && t.isJSXElement(alternate)) {
const block2 = buildBlockElement()
block.children = [consequent]
newJSXIfAttr(block, test)
setJSXAttr(block2, Adapter.else)
block2.children = [alternate]
const parentBlock = buildBlockElement()
parentBlock.children = [block, block2]
parentPath.replaceWith(parentBlock)
if (statementParent) {
const name = findIdentifierFromStatement(
statementParent.node as t.VariableDeclaration
)
setTemplate(name, jsxElementPath, templates)
}
} else {
// console.log('todo')
}
} else if (t.isReturnStatement(parentNode)) {
//.........这里部分代码省略.........
开发者ID:AlloyTeam,项目名称:Nuclear,代码行数:101,代码来源:loop-component.ts
示例6: function
ExpressionStatement: function(path: traverse.NodePath<types.ExpressionStatement>) {
if (types.isNullLiteral(path.node.expression))
path.remove();
}
开发者ID:7sharp9,项目名称:Fable,代码行数:4,代码来源:babelPlugins.ts
注:本文中的babel-types.isNullLiteral函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论