From 3e7c0a0bc9ac2dbb531484444b918ae8805b6da5 Mon Sep 17 00:00:00 2001 From: Markus Felten Date: Fri, 5 Apr 2019 19:46:44 +0200 Subject: [PATCH] fix: declare args of firts() as nullable --- src/functions.mjs | 2 +- tests/basics-test.mjs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/functions.mjs b/src/functions.mjs index 16aacaf5..c4ce1e40 100644 --- a/src/functions.mjs +++ b/src/functions.mjs @@ -151,7 +151,7 @@ export const functions = { }, first: { - arguments: ["object|number"], + arguments: ["object|number|undefined"], returns: "object?", apply: (context, args) => { args = args.filter(e => e !== undefined && e.value !== undefined); diff --git a/tests/basics-test.mjs b/tests/basics-test.mjs index d80da9bc..0b89c0ad 100644 --- a/tests/basics-test.mjs +++ b/tests/basics-test.mjs @@ -104,6 +104,7 @@ test("length (string)", async t => t.is(await expand("${length('abc')}"), 3)); test("length (array)", async t => t.is(await expand("${length([1,2,3])}"), 3)); test("first", async t => t.is(await expand("${first(1,2,3)}"), 1)); +test.only("first missing", async t => t.is(await expand("${first(env.MISSING,'b')}"), 'b')); test("split", async t => t.deepEqual(await expand("${split('1,2,3,4',',')}"), ["1", "2", "3", "4"]));