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.5 to 1.0.6

3

es/JsNodeToCardNode.d.ts

@@ -7,3 +7,4 @@ import { Expression } from '@babel/types';

declare class JsNodeToCardNode {
translate(source: Expression): ICardNode;
translate(source: Expression | null): ICardNode;
private translateTemplateLiteral;
private translateUnaryExpression;

@@ -10,0 +11,0 @@ private translateBinaryExpression;

@@ -7,3 +7,4 @@ import { Expression } from '@babel/types';

declare class JsNodeToCardNode {
translate(source: Expression): ICardNode;
translate(source: Expression | null): ICardNode;
private translateTemplateLiteral;
private translateUnaryExpression;

@@ -10,0 +11,0 @@ private translateBinaryExpression;

'use strict';
var types = require('@babel/types');
var JsExpressionParser = require('./JsExpressionParser.js');
var generator = require('@babel/generator');

@@ -10,2 +12,5 @@ /**

translate(source) {
if (source === null) {
return '';
}
const { type } = source;

@@ -34,2 +39,4 @@ switch (type) {

return this.translateArrayExpression(source);
case 'TemplateLiteral':
return this.translateTemplateLiteral(source);
default:

@@ -39,2 +46,25 @@ throw new Error(`Unsupported expression type: ${type}`);

}
translateTemplateLiteral(source) {
const { quasis, expressions } = source;
let nodeList = [];
for (let i = 0; i < quasis.length; i++) {
nodeList.push(quasis[i]);
if (i < expressions.length) {
nodeList.push(expressions[i]);
}
}
nodeList = nodeList.filter((item) => item.type !== 'TemplateElement' || Boolean(item.value.raw));
const expression = nodeList
.map((item) => {
if (item.type === 'TemplateElement') {
return `"${item.value.raw}"`;
}
else {
return `(${generator.default(item).code})`;
}
})
.join('+');
const jsNode = new JsExpressionParser().parser(expression);
return this.translate(jsNode);
}
translateUnaryExpression(source) {

@@ -41,0 +71,0 @@ const { operator, argument } = source;

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

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

"dependencies": {
"@babel/generator": "^7.25.6",
"@babel/parser": "^7.25.6",

@@ -56,0 +57,0 @@ "@babel/types": "^7.25.6"

@@ -70,1 +70,2 @@ # 快应用卡片表达式解析

| 调用表达式<br/> CallExpression | `fun(arg1, args2, ...)` | `["()", "fun" arg1, arg2, ...]` | `fun(a, 123)` --> `["()", "fun", ["$", "a"], 123]` |
| 模板字符串 | `str-${js}` | 相当于**加法**二元表达式 `"str" + js` | |

Sorry, the diff of this file is not supported yet

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