Skip to content

Commit

Permalink
Refactor search param handling to work with old Node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
backflip committed Oct 10, 2023
1 parent d3275e3 commit 2a996f6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib/transpile-decl.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function transpileDecl(result, promises, decl, opts, cache) { //

// <url> param()s
const params = {
...Object.fromEntries(url.searchParams),
...paramsFromSearchParams(url.searchParams),
...paramsFromNodes(
node.nodes.slice(2, -1)
)
Expand Down Expand Up @@ -143,6 +143,20 @@ function paramsFromNodes(nodes) {
return params;
}

// params from URL search params
function paramsFromSearchParams(searchParams) {
// valid params as an object
const params = {};

// for each search param
searchParams.forEach((value, key) => {
params[key] = value;
});

// return valid params as an object
return params;
}

// whether the node is a filled param()
function isFilledParam(node) {
return node.type === 'func' && node.value === 'param' && node.nodes.length === 4 && node.nodes[1].type === 'word';
Expand Down

0 comments on commit 2a996f6

Please sign in to comment.