Type after `as` or `satisfies` at end of line is tokenized as an expression
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 68/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- typescript
- Domínio
- tooling
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- TypeScript
- Estrelas
- 471
- Forks
- 150
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de microsoft/TypeScript-TmLanguage
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
microsoft/TypeScript-TmLanguage#1071 ·
-
tristeAberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 5/100
microsoft/TypeScript-TmLanguage#1078 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
microsoft/TypeScript-TmLanguage#1076 · 6 comentários ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 55/100
microsoft/TypeScript-TmLanguage#1074 · 2 comentários ·
-
typescript-basics: fix highlighting for triple-slash reference directives with preserve="true"Aberta
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 58/100
microsoft/TypeScript-TmLanguage#1066 · 1 comentário ·
Todas as issues de microsoft/TypeScript-TmLanguage
Issues semelhantes
-
refactor
Dificuldade 2/5 Meio dia Facilidade para iniciantes 84/100
Mantenedores costumam responder em até 5 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
OHDSI/Data2Evidence#3450 ·
Mantenedores costumam responder em até 2 dias
-
e2e-failure ready-to-code
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 90/100
redhat-developer/rhdh-plugin-export-overlays#4011 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
automation missing-model model-sync provider:ofox
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
anomalyco/models.dev#8421 ·
Mantenedores costumam responder em até 1 dia
-
SlackAdapter and TelegramAdapter are not assignable to Adapter under exactOptionalPropertyTypesAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia