diff --git a/packages/tailwindcss-language-service/src/util/doc.ts b/packages/tailwindcss-language-service/src/util/doc.ts index 7c291ff933bdaf3eed03de42a1c2ef8d6c85c214..810f79dd537907593beff2046a23834e2d54e042 100644 --- a/packages/tailwindcss-language-service/src/util/doc.ts +++ b/packages/tailwindcss-language-service/src/util/doc.ts @@ -1,5 +1,4 @@ import type { TextDocument, Range } from 'vscode-languageserver' -import moo from 'moo' export function getTextWithoutComments( doc: TextDocument, @@ -15,8 +14,8 @@ ): string { let text = typeof docOrText === 'string' ? docOrText : docOrText.getText(range) if (type === 'js' || type === 'jsx') { -import type { TextDocument, Range } from 'vscode-languageserver' export function getTextWithoutComments( + type: 'html' | 'js' | 'jsx' | 'css', } if (type === 'css') { @@ -29,35 +28,3 @@ function replace(match: string): string { return match.replace(/./gs, (char) => (char === '\n' ? '\n' : ' ')) } - -let jsLexer: moo.Lexer - -function getJsWithoutComments(text: string): string { - if (!jsLexer) { - jsLexer = moo.states({ - main: { - commentLine: /\/\/.*?$/, - commentBlock: { match: /\/\*[^]*?\*\//, lineBreaks: true }, - stringDouble: /"(?:[^"\\]|\\.)*"/, - stringSingle: /'(?:[^'\\]|\\.)*'/, - stringBacktick: /`(?:[^`\\]|\\.)*`/, - other: { match: /[^]/, lineBreaks: true }, - }, - }) - } - - let str = '' - jsLexer.reset(text) - - for (let token of jsLexer) { - if (token.type === 'commentLine') { - str += ' '.repeat(token.value.length) - } else if (token.type === 'commentBlock') { - str += token.value.replace(/./g, ' ') - } else { - str += token.value - } - } - - return str -}