Skip to content

Commit

Permalink
Revert "fix(client): fix detection of Angular context after string in…
Browse files Browse the repository at this point in the history
…terpolation (#1922)" (#2023)

This reverts commit bd6282e.

fixes angular/angular#55223
  • Loading branch information
atscott committed Apr 9, 2024
1 parent 410e31f commit 51d907e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
18 changes: 3 additions & 15 deletions client/src/embedded_support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export function isInsideStringLiteral(
* `@Component` or `{styleUrls: [someFunction('stringL¦iteral')]}`, the @angular/language-service
* will always give us the correct answer. This helper gives us a quick win for optimizing the
* number of requests we send to the server.
*
* TODO(atscott): tagged templates don't work: #1872 /
* https://github.com/Microsoft/TypeScript/issues/20055
*/
function isPropertyAssignmentToStringOrStringInArray(
documentText: string, offset: number, propertyAssignmentNames: string[]): boolean {
Expand All @@ -78,23 +81,8 @@ 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: 1 addition & 16 deletions client/src/tests/embedded_support_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ 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 @@ -127,4 +112,4 @@ function extractCursorInfo(textWithCursor: string): {cursor: number, text: strin
cursor,
text: textWithCursor.substr(0, cursor) + textWithCursor.substr(cursor + 1),
};
}
}

0 comments on commit 51d907e

Please sign in to comment.