瀏覽代碼

fix: `$last` path return `undefined` in javascript block

Ahmad Kholid 3 年之前
父節點
當前提交
5fbed3d1c0
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      src/content/blocks-handler/handler-javascript-code.js

+ 4 - 0
src/content/blocks-handler/handler-javascript-code.js

@@ -20,6 +20,10 @@ function findData(obj, path) {
   const paths = path.split('.');
   const isWhitespace = paths.length === 1 && !/\\S/.test(paths[0]);
 
+  if (path.startsWith('$last') && Array.isArray(obj)) {
+    paths[0] = obj.length - 1;
+  }
+
   if (paths.length === 0 || isWhitespace) return obj;
   else if (paths.length === 1) return obj[paths[0]];