How to use typescript-styled-plugin - 2 common examples

To help you get started, we’ve selected a few typescript-styled-plugin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / typescript-lit-html-plugin / src / index.ts View on Github external
public create(info: ts.server.PluginCreateInfo): ts.LanguageService {
        if ((info.languageService as any)[litHtmlPluginMarker]) {
            // Already decorated
            return info.languageService;
        }

        const logger = new LanguageServiceLogger(info);
        this._config.update(info.config);

        logger.log('config: ' + JSON.stringify(this._config));

        const styledLanguageService = new StyledTemplateLanguageService(
            this._typescript, {} as any,
            new CssDocumentProvider(this.htmlLanguageService),
            logger);

        const htmlTemplateLanguageService = new HtmlTemplateLanguageService(
            this._typescript,
            this._config,
            this._virtualDocumentProvider,
            this.htmlLanguageService,
            styledLanguageService,
            logger);

        const languageService = decorateWithTemplateLanguageService(
            this._typescript,
            info.languageService,
            info.project,
github microsoft / typescript-lit-html-plugin / src / substitutions.ts View on Github external
export function getSubstitutions(
    typescript: typeof ts,
    languageService: LanguageService,
    documentProvider: VirtualDocumentProvider,
    templateString: string,
    spans: ReadonlyArray<{ start: number, end: number }>
): string {
    const virtualDoc = documentProvider.createVirtualDocument(new NoopTemplateContext(typescript, templateString));

    const regions = getDocumentRegions(languageService, virtualDoc);
    const cssSpans = spans
        .map(span => ({ language: regions.getLanguageAtPosition(virtualDoc.positionAt(span.start)), span }))
        .filter(x => x.language === 'css')
        .map(x => x.span);

    const settings = getTemplateSettings({} as any);
    return settings.getSubstitutions!(templateString, cssSpans);
}

typescript-styled-plugin

TypeScript language service plugin that adds IntelliSense for styled components

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis