New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aiot-toolkit/card-expression

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aiot-toolkit/card-expression - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

21

es/JsNodeToCardNode.js

@@ -0,1 +1,3 @@

import { stringLiteral } from '@babel/types';
/**

@@ -46,8 +48,15 @@ * js 结点转换为 card结点

translateMemberExpression(source) {
const { object, property } = source;
return [
'.',
this.translate(object),
this.translate(property),
];
const { object, property, computed } = source;
const translateProperty = () => {
if (property.type === 'Identifier') {
if (computed) {
return property;
}
else {
return stringLiteral(property.name);
}
}
return property;
};
return ['.', this.translate(object), this.translate(translateProperty())];
}

@@ -54,0 +63,0 @@ translateLogicalExpression(source) {

'use strict';
var types = require('@babel/types');
/**

@@ -48,8 +50,15 @@ * js 结点转换为 card结点

translateMemberExpression(source) {
const { object, property } = source;
return [
'.',
this.translate(object),
this.translate(property),
];
const { object, property, computed } = source;
const translateProperty = () => {
if (property.type === 'Identifier') {
if (computed) {
return property;
}
else {
return types.stringLiteral(property.name);
}
}
return property;
};
return ['.', this.translate(object), this.translate(translateProperty())];
}

@@ -56,0 +65,0 @@ translateLogicalExpression(source) {

{
"name": "@aiot-toolkit/card-expression",
"description": "快应用卡片表达式解析库",
"version": "1.0.2",
"version": "1.0.3",
"main": "lib/index.js",

@@ -26,3 +26,3 @@ "module": "es/index.js",

"clean": "rimraf lib && rimraf es",
"publish": "npm run build && npm publish"
"npm:publish": "npm run build && npm publish"
},

@@ -29,0 +29,0 @@ "devDependencies": {

@@ -9,8 +9,8 @@ # 快应用卡片表达式解析

| 表达式 | 转换后 |
| ---------------- | --------------------------------------------------------- |
| `a+123` | `['+', ['$', 'a'], 123]` |
| `!a` | `['!', ['$', 'a']]` |
| `a[1].x.y` | `['.',['.', ['.', ['$', 'a'], 1], ['$''x']], ['$', 'y']]` |
| `fun(a, b, 124)` | `[['()', ['$', 'fun'], ['$', 'a'], ['$', 'b'], 124]` |
| 表达式 | 转换后 |
| ---------------- | ----------------------------------------------------------- |
| `a+123` | `["+", ["$", "a"], 123]` |
| `!a` | `["!", ["$", "a"]]` |
| `a[1].x.y` | `[".",[".", [".", ["$", "a"], 1], ["$", "x"]], ["$", "y"]]` |
| `fun(a, b, 124)` | `["()", ["$", "fun"], ["$", "a"], ["$", "b"], 124]` |

@@ -28,1 +28,18 @@ ## 快速上手

```
## 支持表达式
快应用卡片支持的表达式如下。需要注意的是,各表达式之间**可递归使用**,例如
`data[a+b]` `data.x + (a?1:2)`
| 表达式 | 源码 | 产物 | 示例 |
| ------------------------------------- | -------------------------------------------- | ------------------------------------- | -------------------------------------------------- |
| 字面量 <br/> literal | `value` | `value` | `123` --> `123` |
| 标识符<br/> Identifier | `value` | `["$", "value"]` | `a`-->`["$", "a"]` |
| 数组表达式<br/> ArrayExpression | `[value1, value2, value3]` | `["~", "value1", "value2", "value3"]` | `[a, 1, 2]`-->`["~", ["$", "a"], 1, 2]` |
| 一元表达式<br/> UnaryExpression | `operator value` | `["operator", value]` | `!a`-->`["!", ["$", "a"]]` |
| 二元表达式<br/> BinaryExpression | `value1 operator value1` | `["operator", value1, value2]` | `a+1` --> `["+", ["$", "a"], 1]` |
| 属性表达式<br/> MemberExpression | 1. `value1[value2]` <br/> 2. `value1.value2` | `[".", value1, value2]` | `a[1]` --> `[".", ["$", "a"], 1]` |
| 逻辑表达<br/> LogicalExpression | `value1 operator value1` | `["operator", value1, value2]` | `a \|\| 1` --> `["\|\|", ["$", "a"], 1]` |
| 条件表达式<br/> ConditionalExpression | `condition? value1 : value2` | `[":?", "$condition" value1, value2]` | `a?x:1` --> `[":?", ["$", "a"], ["$", "x"], 1]` |
| 调用表达式<br/> CallExpression | `fun(arg1, args2, ...)` | `["()", "fun" arg1, arg2, ...]` | `fun(a, 123)` --> `["()", "fun", ["$", "a"], 123]` |
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc