Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/compiler"
---

Syntax highlighting does not correctly recognize parameter name with hyphen
4 changes: 4 additions & 0 deletions packages/compiler/src/core/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,10 @@ function createParser(code: string | SourceFile, options: ParseOptions = {}): Pa
if (token() === Token.Identifier) {
sv = tokenValue();
nextToken();
} else if (token() === Token.StringLiteral && messageId !== "tag") {
// Allow string literals as identifiers (similar to model properties)
sv = tokenValue();
nextToken();
} else {
sv = "";
warning({ code: "doc-invalid-identifier", messageId });
Expand Down
31 changes: 28 additions & 3 deletions packages/compiler/src/core/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,34 @@ export function createScanner(
return next(Token.Star);

case CharCode.Backtick:
return lookAhead(1) === CharCode.Backtick && lookAhead(2) === CharCode.Backtick
? next(Token.DocCodeFenceDelimiter, 3)
: scanDocCodeSpan();
// Check if it is a code fence (three backticks)
if (lookAhead(1) === CharCode.Backtick && lookAhead(2) === CharCode.Backtick) {
return next(Token.DocCodeFenceDelimiter, 3);
}

// Check if possible backtick identifier
// Need to look ahead to determine if this is a single backtick or a backtick identifier
let nextPos = position + 1;
let hasContent = false;
while (nextPos < endPosition) {
const nextCh = input.charCodeAt(nextPos);
if (nextCh === CharCode.Backtick) {
// Find the closing backtick, which is a backtick identifier
if (hasContent) {
return scanBacktickedIdentifier();
}
break;
} else if (nextCh === CharCode.LineFeed || nextCh === CharCode.CarriageReturn) {
// Newline encountered, this is not a backtick identifier
break;
} else if (nextCh !== CharCode.Space && nextCh !== CharCode.Tab) {
hasContent = true;
}
nextPos++;
}

// Handled as code span by default
return scanDocCodeSpan();

case CharCode.LessThan:
case CharCode.GreaterThan:
Expand Down
Loading