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: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ function visitPropertyDeclaration(node: ts.PropertyDeclaration): VisitResult {
visitModifiers(node.modifiers, /* addSemi */ node.name.kind === SK.ComputedPropertyName);
}

// Visit the name before blanking anything after it, a computed key can contain type syntax:
// `[k as T]: U`. BlankString expects ranges in source order.
visitor(node.name);

let addSemi = !node.initializer && isContextualModifierName(node.name);
const postfixToken = node.exclamationToken || node.questionToken;
if (postfixToken) {
Expand All @@ -340,8 +344,6 @@ function visitPropertyDeclaration(node: ts.PropertyDeclaration): VisitResult {
blankRange(node.type.getFullStart() - 1, node.type.end, addSemi);
}

visitor(node.name);

if (node.initializer) {
visitor(node.initializer);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/fixture/cases/b.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ let g: Box<any>,
// @ts-expect-error: computed property names must have simple type
[("A" + "B") as "AB"] = 1;
// as "AB"

// type syntax in the key and after it
[("C" + "D") as "CD"]: number = 1;
// as "CD" : number
static [("E" + "F") as "EF"]?: number;
// as "EF" ?: number
[foo<"GH">("GH")]!: string;
// <"GH"> !: string
}
};

Expand Down
8 changes: 8 additions & 0 deletions tests/fixture/output/b.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading