Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/runtime/src/internal/compute/evaluate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jest.mock("../devtools.js");

i18n.init({
fallbackLng: "en",
supportedLngs: ["en", "zh"],
});
i18n.addResourceBundle("en", getI18nNamespace("app", "hello"), {
HELLO: "Hello",
Expand Down Expand Up @@ -255,6 +256,8 @@ const consoleError = jest.spyOn(console, "error");

describe("evaluate", () => {
beforeEach(() => {
i18n.changeLanguage("zh");

(_internalApiGetRuntimeContext as jest.Mock).mockReset();
});

Expand Down Expand Up @@ -291,7 +294,7 @@ describe("evaluate", () => {
["<% I18N('HELLO') %>", "Hello"],
["<% I18N('COUNT_ITEMS', { count: 5 }) %>", "Total 5 items"],
["<% I18N('NOT_EXISTED') %>", "NOT_EXISTED"],
["<% __WIDGET_I18N__('my-widget')('WORLD') %>", "World"],
["<% __WIDGET_I18N__('my-widget')('WORLD') %>", "世界"],
["<% I18N_TEXT({ en: 'hello', zh: '你好' }) %>", "你好"],
["<% CTX.myFreeContext %>", "good"],
["<% CTX.notExisted %>", undefined],
Expand All @@ -318,6 +321,7 @@ describe("evaluate", () => {
["<% SIZE %>", 2],
["<% STATE.myState %>", "better"],
["<% FORM_STATE.myFormItem %>", "input"],
["<% LANGUAGE %>", "zh"],
])("evaluate(%j) should return %j", (raw, result) => {
expect(evaluate(raw, runtimeContext)).toEqual(result);
});
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime/src/internal/compute/getGeneralGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ function getIndividualGlobal(
);
case "I18N_TEXT":
return collectCoverage ? fakeI18nText : i18nText;
case "LANGUAGE": {
return collectCoverage ? "zh" : i18n.language || "zh";
}
Comment on lines +84 to +86
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

同步公开契约:为新全局 LANGUAGE 补齐类型/文档/清单

新增全局需同步到:API 文档、d.ts/类型提示、表达式/DSL 提示、dll manifest/白名单、CHANGELOG。请确认并补齐。


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) 搜索是否已有白名单/类型里显式列出全局名
rg -nP -C2 '\b(BASE_URL|I18N_TEXT|I18N|THEME|PERMISSIONS|console|location|LANGUAGE)\b' -S

# 2) 检查 d.ts 是否已包含 LANGUAGE
fd -t f -e d.ts | xargs rg -n 'LANGUAGE' -n || true

# 3) 文档与变更记录
rg -n 'LANGUAGE' docs CHANGELOG.md -S || true

# 4) 可能的 dll manifest/白名单文件
fd -i -t f 'manifest' | xargs rg -n 'LANGUAGE' -n || true

# 5) 用例覆盖
rg -n 'LANGUAGE' -g '!**/node_modules/**' -S

Length of output: 267155


补齐公开契约:为新全局 LANGUAGE 补齐类型/文档/清单

检查结果:LANGUAGE 已在 runtime 中新增并被单测使用,但未在类型/白名单/文档/CHANGELOG 中登记。
需要补齐的项(最小可交付):

  • 类型 / 白名单:将 LANGUAGE 加入 packages/types/src/manifest.ts(或仓库中负责表达式全局的类型/manifest)并新增/更新相关 .d.ts,保证 IDE 类型提示。
  • 表达式 / DSL 提示:更新表达式提示/文档生成逻辑(doc-helpers 或 docs 源)以暴露 LANGUAGE 给编辑器/DSL 用户。
  • dll manifest / 白名单:在 bricks/manifest 或项目的白名单文件中加入 LANGUAGE(以便打包/运行时允许)。
  • CHANGELOG:在 packages/runtime/CHANGELOG.md(或受影响包的 CHANGELOG)记录新增全局及兼容说明。

参考位置(便于快速修改):

  • 使用处:packages/runtime/src/internal/compute/getGeneralGlobals.ts — case "LANGUAGE"(行 84–86)
  • 单测:packages/runtime/src/internal/compute/evaluate.spec.ts — 测试 "<% LANGUAGE %>"(行 ~324)
    我可协助生成所需的 d.ts/manifest/文档补丁或 PR。

case "PERMISSIONS":
return getReadOnlyProxy({
check: collectCoverage
Expand Down
Loading