@getlang/get
Advanced tools
Comparing version 0.0.35 to 0.0.36
@@ -8,2 +8,8 @@ import { mapValues } from 'lodash-es'; | ||
import { invariant, NullSelectionError, QuerySyntaxError, ValueReferenceError, ImportError, NullInputError, NullSelection, } from '@getlang/utils'; | ||
function assert(value) { | ||
if (value instanceof NullSelection) { | ||
throw new NullSelectionError(value.selector); | ||
} | ||
return value; | ||
} | ||
function toValue(value, typeInfo) { | ||
@@ -72,13 +78,9 @@ switch (typeInfo.type) { | ||
if (node.context) { | ||
context = { | ||
value: await visit(node.context), | ||
typeInfo: node.context.typeInfo, | ||
}; | ||
let value = await visit(node.context); | ||
const optional = node.typeInfo.type === Type.Maybe; | ||
value = optional ? value : assert(value); | ||
if (value instanceof NullSelection) | ||
return value; | ||
context = { value, typeInfo: node.context.typeInfo }; | ||
} | ||
if (context?.value instanceof NullSelection) { | ||
if (node.typeInfo.type === Type.Maybe) { | ||
return context.value; | ||
} | ||
throw new NullSelectionError(context.value.selector); | ||
} | ||
return unwrap(context, cb); | ||
@@ -119,13 +121,5 @@ } | ||
const { slice } = node; | ||
const fauxSelector = `slice@${slice.line}:${slice.col}`; | ||
const value = await hooks.slice(slice.value, context ? toValue(context.value, context.typeInfo) : {}, context?.value ?? {}); | ||
if (value !== undefined) { | ||
return value; | ||
} | ||
else if (node.typeInfo.type === Type.Maybe) { | ||
return new NullSelection(fauxSelector); | ||
} | ||
else { | ||
throw new NullSelectionError(fauxSelector); | ||
} | ||
const optional = node.typeInfo.type === Type.Maybe; | ||
return optional ? value : assert(value); | ||
}); | ||
@@ -158,8 +152,5 @@ }, | ||
} | ||
const result = select(context.typeInfo); | ||
if (result instanceof NullSelection && | ||
node.typeInfo.type !== Type.Maybe) { | ||
throw new NullSelectionError(selector); | ||
} | ||
return result; | ||
const value = select(context.typeInfo); | ||
const optional = node.typeInfo.type === Type.Maybe; | ||
return optional ? value : assert(value); | ||
}); | ||
@@ -260,6 +251,3 @@ }, | ||
ExtractStmt(node) { | ||
if (node.value instanceof NullSelection) { | ||
throw new NullSelectionError(node.value.selector); | ||
} | ||
scope.extracted = node.value; | ||
scope.extracted = assert(node.value); | ||
}, | ||
@@ -266,0 +254,0 @@ Program: { |
@@ -28,2 +28,9 @@ import { mapValues } from 'lodash-es' | ||
function assert(value: any) { | ||
if (value instanceof NullSelection) { | ||
throw new NullSelectionError(value.selector) | ||
} | ||
return value | ||
} | ||
function toValue(value: any, typeInfo: TypeInfo): any { | ||
@@ -113,15 +120,8 @@ switch (typeInfo.type) { | ||
if (node.context) { | ||
context = { | ||
value: await visit(node.context), | ||
typeInfo: node.context.typeInfo, | ||
} | ||
let value = await visit(node.context) | ||
const optional = node.typeInfo.type === Type.Maybe | ||
value = optional ? value : assert(value) | ||
if (value instanceof NullSelection) return value | ||
context = { value, typeInfo: node.context.typeInfo } | ||
} | ||
if (context?.value instanceof NullSelection) { | ||
if (node.typeInfo.type === Type.Maybe) { | ||
return context.value | ||
} | ||
throw new NullSelectionError(context.value.selector) | ||
} | ||
return unwrap(context, cb) | ||
@@ -168,3 +168,2 @@ } | ||
const { slice } = node | ||
const fauxSelector = `slice@${slice.line}:${slice.col}` | ||
const value = await hooks.slice( | ||
@@ -175,9 +174,4 @@ slice.value, | ||
) | ||
if (value !== undefined) { | ||
return value | ||
} else if (node.typeInfo.type === Type.Maybe) { | ||
return new NullSelection(fauxSelector) | ||
} else { | ||
throw new NullSelectionError(fauxSelector) | ||
} | ||
const optional = node.typeInfo.type === Type.Maybe | ||
return optional ? value : assert(value) | ||
}) | ||
@@ -213,10 +207,5 @@ }, | ||
const result = select(context!.typeInfo) | ||
if ( | ||
result instanceof NullSelection && | ||
node.typeInfo.type !== Type.Maybe | ||
) { | ||
throw new NullSelectionError(selector) | ||
} | ||
return result | ||
const value = select(context!.typeInfo) | ||
const optional = node.typeInfo.type === Type.Maybe | ||
return optional ? value : assert(value) | ||
}) | ||
@@ -342,6 +331,3 @@ }, | ||
ExtractStmt(node) { | ||
if (node.value instanceof NullSelection) { | ||
throw new NullSelectionError(node.value.selector) | ||
} | ||
scope.extracted = node.value | ||
scope.extracted = assert(node.value) | ||
}, | ||
@@ -348,0 +334,0 @@ |
{ | ||
"name": "@getlang/get", | ||
"version": "0.0.35", | ||
"version": "0.0.36", | ||
"license": "Apache-2.0", | ||
@@ -20,3 +20,3 @@ "type": "module", | ||
"dependencies": { | ||
"@getlang/lib": "^0.0.16", | ||
"@getlang/lib": "^0.0.17", | ||
"@getlang/utils": "^0.0.15", | ||
@@ -23,0 +23,0 @@ "@getlang/parser": "^0.0.25", |
Sorry, the diff of this file is not supported yet
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
34700
659
+ Added@getlang/lib@0.0.17(transitive)
- Removed@getlang/lib@0.0.16(transitive)
Updated@getlang/lib@^0.0.17