diff --git a/extensions/html-language-features/server/src/modes/embeddedSupport.ts b/extensions/html-language-features/server/src/modes/embeddedSupport.ts index c3398f8f80f..26ef68439da 100644 --- a/extensions/html-language-features/server/src/modes/embeddedSupport.ts +++ b/extensions/html-language-features/server/src/modes/embeddedSupport.ts @@ -168,7 +168,7 @@ function getEmbeddedDocument(document: TextDocument, contents: EmbeddedRegion[], for (const c of contents) { if (c.languageId === languageId && (!ignoreAttributeValues || !c.attributeValue)) { result = substituteWithWhitespace(result, currentPos, c.start, oldContent, lastSuffix, getPrefix(c)); - result += oldContent.substring(c.start, c.end); + result += updateContent(c, oldContent.substring(c.start, c.end)); currentPos = c.end; lastSuffix = getSuffix(c); } @@ -194,6 +194,12 @@ function getSuffix(c: EmbeddedRegion) { } return ''; } +function updateContent(c: EmbeddedRegion, content: string): string { + if (!c.attributeValue && c.languageId === 'javascript') { + return content.replace(``, ` */`); + } + return content; +} function substituteWithWhitespace(result: string, start: number, end: number, oldContent: string, before: string, after: string) { result += before; diff --git a/extensions/html-language-features/server/src/test/embedded.test.ts b/extensions/html-language-features/server/src/test/embedded.test.ts index 722578cb07c..87698f39718 100644 --- a/extensions/html-language-features/server/src/test/embedded.test.ts +++ b/extensions/html-language-features/server/src/test/embedded.test.ts @@ -119,7 +119,10 @@ suite('HTML Embedded Support', () => { test('Script content', function (): any { assertEmbeddedLanguageContent('', 'javascript', ' var i = 0; '); assertEmbeddedLanguageContent('', 'javascript', ' var i = 0; '); + assertEmbeddedLanguageContent('', 'javascript', ' /* this comment should not give error */ '); + assertEmbeddedLanguageContent('', 'javascript', ' /* this comment should not give error */ console.log("logging"); '); + assertEmbeddedLanguageContent('', 'javascript', ' var data=100; /* this comment should not give error */ '); assertEmbeddedLanguageContent('
', 'javascript', ' foo(); bar(); '); assertEmbeddedLanguageContent('', 'javascript', ' return; '); assertEmbeddedLanguageContent('