fix: use coerceToString
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import type { NixValue, NixAttrs, NixString } from "../types";
|
import type { NixValue, NixAttrs, NixString } from "../types";
|
||||||
import { isStringWithContext } from "../types";
|
import { isStringWithContext } from "../types";
|
||||||
import { forceNixString, forceAttrs, forceBool, forceList, forceString } from "../type-assert";
|
import { forceNixString, forceAttrs, forceList, forceString } from "../type-assert";
|
||||||
import { force } from "../thunk";
|
import { force } from "../thunk";
|
||||||
import {
|
import {
|
||||||
type NixStringContext,
|
type NixStringContext,
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export interface CoerceResult {
|
|||||||
*/
|
*/
|
||||||
export const coerceToString = (
|
export const coerceToString = (
|
||||||
value: NixValue,
|
value: NixValue,
|
||||||
mode: StringCoercionMode = StringCoercionMode.ToString,
|
mode: StringCoercionMode,
|
||||||
copyToStore: boolean = false,
|
copyToStore: boolean = false,
|
||||||
outContext?: NixStringContext,
|
outContext?: NixStringContext,
|
||||||
): string => {
|
): string => {
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
import type { NixValue, NixAttrs } from "../types";
|
import type { NixValue, NixAttrs } from "../types";
|
||||||
import { forceString, forceList, forceNixString } from "../type-assert";
|
import { forceString, forceList } from "../type-assert";
|
||||||
import { force } from "../thunk";
|
import { force } from "../thunk";
|
||||||
import { type DerivationData, type OutputInfo, generateAterm } from "../derivation-helpers";
|
import { type DerivationData, type OutputInfo, generateAterm } from "../derivation-helpers";
|
||||||
import { coerceToString, StringCoercionMode } from "./conversion";
|
import { coerceToString, StringCoercionMode } from "./conversion";
|
||||||
import {
|
import { type NixStringContext, extractInputDrvsAndSrcs, isStringWithContext } from "../string-context";
|
||||||
type NixStringContext,
|
|
||||||
extractInputDrvsAndSrcs,
|
|
||||||
isStringWithContext,
|
|
||||||
HAS_CONTEXT,
|
|
||||||
} from "../string-context";
|
|
||||||
import { nixValueToJson } from "../conversion";
|
import { nixValueToJson } from "../conversion";
|
||||||
|
|
||||||
const forceAttrs = (value: NixValue): NixAttrs => {
|
const forceAttrs = (value: NixValue): NixAttrs => {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import { CatchableError, HAS_CONTEXT, type NixValue } from "../types";
|
import { CatchableError, HAS_CONTEXT, type NixValue } from "../types";
|
||||||
import { force } from "../thunk";
|
import { force } from "../thunk";
|
||||||
import { forceString } from "../type-assert";
|
import { coerceToString, StringCoercionMode } from "./conversion";
|
||||||
|
|
||||||
export const seq =
|
export const seq =
|
||||||
(e1: NixValue) =>
|
(e1: NixValue) =>
|
||||||
@@ -34,7 +34,7 @@ export const abort = (s: NixValue): never => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const throwFunc = (s: NixValue): never => {
|
export const throwFunc = (s: NixValue): never => {
|
||||||
throw new CatchableError(forceString(s));
|
throw new CatchableError(coerceToString(s, StringCoercionMode.Base));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const trace = (e1: NixValue, e2: NixValue): NixValue => {
|
export const trace = (e1: NixValue, e2: NixValue): NixValue => {
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
import { forceAttrs, forceBool, forceString } from "../type-assert";
|
import { forceAttrs, forceBool, forceString } from "../type-assert";
|
||||||
import type { NixValue, NixAttrs } from "../types";
|
import type { NixValue, NixAttrs } from "../types";
|
||||||
import { force } from "../thunk";
|
import { force } from "../thunk";
|
||||||
|
import { coerceToString, StringCoercionMode } from "./conversion";
|
||||||
|
|
||||||
// Declare Deno.core.ops global (provided by deno_core runtime)
|
// Declare Deno.core.ops global (provided by deno_core runtime)
|
||||||
|
|
||||||
export const importFunc = (path: NixValue): NixValue => {
|
export const importFunc = (path: NixValue): NixValue => {
|
||||||
// For MVP: only support string paths
|
// TODO: context?
|
||||||
// TODO: After implementing path type, also accept path values
|
const pathStr = coerceToString(path, StringCoercionMode.Base);
|
||||||
const pathStr = forceString(path);
|
|
||||||
|
|
||||||
// Call Rust op - returns JS code string
|
// Call Rust op - returns JS code string
|
||||||
const code = Deno.core.ops.op_import(pathStr);
|
const code = Deno.core.ops.op_import(pathStr);
|
||||||
|
|||||||
@@ -98,12 +98,7 @@ function nextComponent(s: string, startIdx: number): ComponentResult {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, consume the longest sequence of non-digit, non-separator characters
|
// Otherwise, consume the longest sequence of non-digit, non-separator characters
|
||||||
while (
|
while (p < s.length && !(s[p] >= "0" && s[p] <= "9") && s[p] !== "." && s[p] !== "-") {
|
||||||
p < s.length &&
|
|
||||||
!(s[p] >= "0" && s[p] <= "9") &&
|
|
||||||
s[p] !== "." &&
|
|
||||||
s[p] !== "-"
|
|
||||||
) {
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import type { NixInt, NixValue } from "../types";
|
import type { NixInt, NixValue } from "../types";
|
||||||
import { forceString, forceList, forceInt } from "../type-assert";
|
import { forceString, forceList, forceInt } from "../type-assert";
|
||||||
|
import { coerceToString, StringCoercionMode } from "./conversion";
|
||||||
|
|
||||||
export const stringLength = (e: NixValue): NixInt => BigInt(forceString(e).length);
|
export const stringLength = (e: NixValue): NixInt => BigInt(forceString(e).length);
|
||||||
|
|
||||||
@@ -20,7 +21,10 @@ export const substring =
|
|||||||
export const concatStringsSep =
|
export const concatStringsSep =
|
||||||
(sep: NixValue) =>
|
(sep: NixValue) =>
|
||||||
(list: NixValue): string =>
|
(list: NixValue): string =>
|
||||||
forceList(list).join(forceString(sep));
|
// FIXME: context?
|
||||||
|
forceList(list)
|
||||||
|
.map((elem) => coerceToString(elem, StringCoercionMode.Interpolation))
|
||||||
|
.join(forceString(sep));
|
||||||
|
|
||||||
export const baseNameOf = (x: NixValue): string => {
|
export const baseNameOf = (x: NixValue): string => {
|
||||||
const str = forceString(x);
|
const str = forceString(x);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const nixValueToJson = (
|
|||||||
if (seen.has(v)) {
|
if (seen.has(v)) {
|
||||||
throw new Error("derivation: circular reference detected in __structuredAttrs");
|
throw new Error("derivation: circular reference detected in __structuredAttrs");
|
||||||
}
|
}
|
||||||
|
// FIXME: tryAttrsToString
|
||||||
seen.add(v);
|
seen.add(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user