Type after `as` or `satisfies` at end of line is tokenized as an expression
まだ誰も着手していません。
評価
- 難易度
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/TypeScript-TmLanguage のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
microsoft/TypeScript-TmLanguage#1071 ·
-
tristeオープン
難易度 5/5 1週間以上 初心者へのやさしさ 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
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
inu-appcenter/memorIN-frontend#106 ·
メンテナーはふだん 1 日以内に返信
-
kind/bug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 7 日以内に返信
-
[Bug] @deck.gl/arcgis dist import resolves to unpublished @deck.gl/core source path (9.3.11, 9.4.0)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
CSCfi/sd-search-ui#145 ·
メンテナーはふだん 1 日以内に返信
-
Add: Cbeebies pl SDオープンcheck:passed streams:add
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信