# HTML/JS 孤儿括号诊断与修复

## 特征

Node.js `--check` 报 `SyntaxError: Unexpected token '}'` 或 `'}'`，常见于 HTML 工作台页面。

## 根因

`});}` 模式同时关闭了**回调函数 AND 外层函数**，但后面还有孤儿行。

典型错误代码：
```js
// renderPriceOverview() 中
    HermesTable.render({...});
  });}     // ← 关闭了 loadPriceData 回调 AND renderPriceOverview 函数
  });      // ← 孤儿！已被上面的 } 关闭
}          // ← 孤儿！
function nextFunc(){...
```

第二个典型：
```js
// renderProductCompare() 中  
    HermesTable.render({...});
  });}     // ← 关闭了 loadPriceData AND renderProductCompare
    var prod=...;  // ← 这段代码本应在函数内，但函数已被关闭
    ...
  });      // ← 孤儿
}
function nextFunc(){...
```

## 修复方法

### Pattern A: `});}` 后面没有代码了
如果 `});}` 之后直接是 `function nextFunc`，删除后面孤儿的 `});` 和 `}` 行。

### Pattern B: `});}` 后面还有代码要执行
如果 `});}` 后面还有函数体代码，把 `});}` 改为 `});`，保留后续代码和正常的闭合。

## 诊断命令

```bash
python3 << 'PYEOF'
import re
with open(path) as f:
    m = re.search(r'<script>(.*?)</script>', f.read(), re.DOTALL)
lines = m.group(1).split('\n')
depth = 0
for i, line in enumerate(lines):
    for ch in line:
        if ch == '{': depth += 1
        elif ch == '}': depth -= 1
    if depth < 0:
        print(f"NEG at JS line {i+1}: {line.rstrip()[:100]}")
        break
PYEOF
```

## 预防

- 不要使用 `});}` 合并闭合，用独立的 `});` + `}` 两行
- 函数体代码写在 `loadData(function() { ... })` 回调内
- 修改后立即 `node --check` 验证
