Type after `as` or `satisfies` at end of line is tokenized as an expression
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 68/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
- 領域
- tooling
研究方向
Start with TypeScript.YAML-tmLanguage around lines 1755-1761 and line 62, then run repro.mjs with the listed vscode-textmate and vscode-oniguruma versions. Compare scopes for the inline and multiline as and satisfies examples; done means the next-line type receives the same type scopes without breaking the semicolonless single-line case.
由索引模型根據 Issue 內容生成。
描述
When a line ends with as or satisfies, the type on the next line gets expression scopes instead of type scopes.
JavaScript and TypeScript Nightly version: not tested in the extension. Reproduced with TypeScript.tmLanguage at eeeb0dc4daa8793b8227bb3b34ddfc267c85fd81 (current master), vscode-textmate 9.3.2, vscode-oniguruma 2.0.1, Node 26.7.0, macOS arm64.
Code
const a = b as A | undefined
const a = b as
A | undefined
const a = b satisfies
A | undefined
Prettier 3.9.8 emits this layout when an as expression exceeds the print width, e.g.:
const inlineSourceMap = convertSourceMap.fromSource(content)?.toObject() as
SourceMap | undefined
Actual
| Token | Same line | Next line |
|---|---|---|
A |
entity.name.type.ts |
variable.other.constant.ts |
| |
keyword.operator.type.ts |
keyword.operator.bitwise.ts |
undefined |
support.type.builtin.ts |
constant.language.undefined.ts |
A type on the line after satisfies gets the same scopes as a type on the line after as.
Expected
The same scopes on both layouts, because TypeScript parses both as a type assertion with the type A | undefined.
Repro script
npm install [email protected] [email protected]
curl -sLO https://raw.githubusercontent.com/microsoft/TypeScript-TmLanguage/eeeb0dc4daa8793b8227bb3b34ddfc267c85fd81/TypeScript.tmLanguage
node repro.mjs
// repro.mjs
import { readFileSync } from "node:fs";
import { createRequire } from "node:module";
import vsctm from "vscode-textmate";
import oniguruma from "vscode-oniguruma";
const require = createRequire(import.meta.url);
await oniguruma.loadWASM(
readFileSync(require.resolve("vscode-oniguruma/release/onig.wasm")).buffer,
);
const registry = new vsctm.Registry({
onigLib: Promise.resolve({
createOnigScanner: (patterns) => new oniguruma.OnigScanner(patterns),
createOnigString: (s) => new oniguruma.OnigString(s),
}),
loadGrammar: async () =>
vsctm.parseRawGrammar(
readFileSync("TypeScript.tmLanguage", "utf8"),
"TypeScript.tmLanguage",
),
});
const grammar = await registry.loadGrammar("source.ts");
const tokenize = (code) => {
let state = vsctm.INITIAL;
for (const line of code.split("\n")) {
const { tokens, ruleStack } = grammar.tokenizeLine(line, state);
state = ruleStack;
for (const { startIndex, endIndex, scopes } of tokens) {
const text = line.slice(startIndex, endIndex);
if (text.trim())
console.log(JSON.stringify(text).padEnd(10), scopes.at(-1));
}
}
console.log();
};
tokenize("const a = b as A | undefined");
tokenize("const a = b as\n A | undefined");
tokenize("const a = b satisfies\n A | undefined");
Possible cause (unverified)
The as/satisfies rule's end includes $ through lookAheadEndOfType, so the type ends at the line break right after the keyword:
https://github.com/microsoft/TypeScript-TmLanguage/blob/eeeb0dc4daa8793b8227bb3b34ddfc267c85fd81/TypeScript.YAML-tmLanguage#L1755-L1761
https://github.com/microsoft/TypeScript-TmLanguage/blob/eeeb0dc4daa8793b8227bb3b34ddfc267c85fd81/TypeScript.YAML-tmLanguage#L62
The $ is presumably what ends the type at the end of a line without a semicolon (x as T followed by a new statement), so dropping it could break that case.
- 主要語言
- TypeScript
- 星號
- 471
- 分支
- 150
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoft/TypeScript-TmLanguage 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
microsoft/TypeScript-TmLanguage#1071 ·
-
triste未關閉
難度 5/5 一週以上 新手友好度 5/100
microsoft/TypeScript-TmLanguage#1078 ·
-
難度 3/5 1-2 天 新手友好度 68/100
microsoft/TypeScript-TmLanguage#1076 · 6 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 55/100
microsoft/TypeScript-TmLanguage#1074 · 2 則留言 ·
-
難度 1/5 1-3 小時 新手友好度 58/100
microsoft/TypeScript-TmLanguage#1066 · 1 則留言 ·
查看 microsoft/TypeScript-TmLanguage 的全部 Issue
相似的 Issue
-
module-request
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 90/100
appandflow/stim#1604 · 1 則留言 ·
維護者通常 1 天內回覆
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難度 1/5 1 小時以內 新手友好度 92/100
lingdojo/kana-dojo#31060 · 1 則留言 · 5 個 reaction ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 90/100
paperclipai/paperclip#14173 ·
維護者通常 1 天內回覆
-
needs-triage
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆