js-to-json-logic
Advanced tools
Comparing version 0.0.3 to 0.0.4
const { parse } = require('@babel/parser') | ||
const { default: traverse } = require('@babel/traverse') | ||
@@ -42,2 +41,16 @@ const processOp = (operator) => { | ||
switch (node.type) { | ||
case 'File': { | ||
return processNode(node.program) | ||
} | ||
case 'Program': { | ||
if (node.directives.length > 0) { | ||
return node.directives.length > 1 | ||
? processError(node, 'Only one expression statement allowed.') | ||
: processNode(node.directives[0]) | ||
} | ||
return node.body.length > 1 | ||
? processError(node, 'Block statements can only have one expression statement.') | ||
: processNode(node.body[0]) | ||
} | ||
case 'TemplateLiteral': { | ||
@@ -246,29 +259,3 @@ const nodes = [] | ||
try { | ||
let result | ||
traverse( | ||
parse( | ||
code, | ||
{ | ||
strictMode: true | ||
} | ||
), | ||
{ | ||
Program (path) { | ||
if (path.node.directives.length > 0) { | ||
result = path.node.directives.length > 1 | ||
? processError(path.node, 'Only one expression statement allowed.') | ||
: processNode(path.node.directives[0]) | ||
return | ||
} | ||
result = path.node.body.length > 1 | ||
? processError(path.node, 'Block statements can only have one expression statement.') | ||
: processNode(path.node.body[0]) | ||
} | ||
} | ||
) | ||
return result | ||
return processNode(parse(code, { strictMode: true })) | ||
} catch (e) { | ||
@@ -275,0 +262,0 @@ return processError({ |
{ | ||
"name": "js-to-json-logic", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Generate JSON Logic objects using JavaScript syntax.", | ||
@@ -18,5 +18,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@babel/parser": "^7.7.7", | ||
"@babel/traverse": "^7.7.4", | ||
"json-logic-js": "^1.2.2" | ||
"@babel/parser": "^7.7.7" | ||
}, | ||
@@ -23,0 +21,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
24230
540
- Removed@babel/traverse@^7.7.4
- Removedjson-logic-js@^1.2.2
- Removed@babel/code-frame@7.26.2(transitive)
- Removed@babel/generator@7.26.3(transitive)
- Removed@babel/template@7.25.9(transitive)
- Removed@babel/traverse@7.26.4(transitive)
- Removed@jridgewell/gen-mapping@0.3.8(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/set-array@1.2.1(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@jridgewell/trace-mapping@0.3.25(transitive)
- Removeddebug@4.4.0(transitive)
- Removedglobals@11.12.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjsesc@3.1.0(transitive)
- Removedjson-logic-js@1.2.3(transitive)
- Removedms@2.1.3(transitive)
- Removedpicocolors@1.1.1(transitive)