Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): fix detection of Angular context after string interpolation #1922

Merged
merged 1 commit into from
Sep 22, 2023
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
15 changes: 15 additions & 0 deletions client/src/embedded_support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,23 @@ function isPropertyAssignmentToStringOrStringInArray(
let lastTokenText: string|undefined;
let unclosedBraces = 0;
let unclosedBrackets = 0;
let unclosedTaggedTemplates = 0;
let propertyAssignmentContext = false;

function isTemplateStartOfTaggedTemplate() {
return token === ts.SyntaxKind.NoSubstitutionTemplateLiteral ||
token === ts.SyntaxKind.TemplateHead;
}

while (token !== ts.SyntaxKind.EndOfFileToken && scanner.getStartPos() < offset) {
if (isTemplateStartOfTaggedTemplate()) {
unclosedTaggedTemplates++;
}
if (token === ts.SyntaxKind.CloseBraceToken && unclosedTaggedTemplates > 0) {
// https://github.com/Microsoft/TypeScript/issues/20055
token = scanner.reScanTemplateToken(/*isTaggedTemplate*/ true);
unclosedTaggedTemplates--;
}
if (lastToken === ts.SyntaxKind.Identifier && lastTokenText !== undefined &&
propertyAssignmentNames.includes(lastTokenText) && token === ts.SyntaxKind.ColonToken) {
propertyAssignmentContext = true;
Expand Down
17 changes: 16 additions & 1 deletion client/src/tests/embedded_support_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ describe('embedded language support', () => {
it('at end of template', () => {
test(`template: '<div></div>¦'`, isInsideInlineTemplateRegion, true);
});

it('works for inline templates after a template string', () => {
test(
'const x = `${""}`;\n' +
'template: `hello ¦world`',
isInsideInlineTemplateRegion, true);
});

it('works for inline templates after a tagged template string inside tagged template string',
() => {
test(
'const x = `${`${""}`}`;\n' +
'template: `hello ¦world`',
isInsideInlineTemplateRegion, true);
});
});

describe('isInsideAngularContext', () => {
Expand Down Expand Up @@ -112,4 +127,4 @@ function extractCursorInfo(textWithCursor: string): {cursor: number, text: strin
cursor,
text: textWithCursor.substr(0, cursor) + textWithCursor.substr(cursor + 1),
};
}
}
Loading