How to use the @stylable/core.StylableTransformer function in @stylable/core

To help you get started, we’ve selected a few @stylable/core 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 wix / stylable / packages / language-service / src / lib / provider.ts View on Github external
// we're looking at a var usage
        if (!meta.mappedSymbols[word]) {
            return { word, meta: null };
        } else if (meta.mappedSymbols[word]._kind === 'var') {
            // deepResolve doesn't do local symbols
            return { word, meta };
        }
        const resolvedVar = stylable.resolver.deepResolve(meta.mappedSymbols[word]);
        if (resolvedVar) {
            return { word, meta: resolvedVar.meta };
        } else {
            return { word, meta: null };
        }
    }

    const transformer = new StylableTransformer({
        diagnostics: new Diagnostics(),
        fileProcessor: stylable.fileProcessor,
        requireModule: () => {
            throw new Error('Not implemented, why are we here');
        }
    });

    const expandedLine: string = expandCustomSelectors(
        postcss.rule({ selector: lineChunkAtCursor }),
        meta.customSelectors
    )
        .split(' ')
        .pop()!; // TODO: replace with selector parser
    const resolvedElements = transformer.resolveSelectorElements(meta, expandedLine);

    let reso: CSSResolve | undefined;
github wix / stylable / packages / core-test-kit / src / generate-test-util.ts View on Github external
export function createTransformer(
    config: Config,
    diagnostics: Diagnostics = new Diagnostics(),
    replaceValueHook?: replaceValueHook,
    postProcessor?: postProcessor
): StylableTransformer {
    const { requireModule, fileProcessor } = generateInfra(config, diagnostics);

    return new StylableTransformer({
        fileProcessor,
        requireModule,
        diagnostics,
        keepValues: false,
        replaceValueHook,
        postProcessor,
        mode: config.mode
    });
}
github wix / stylable / packages / core-test-kit / src / generate-test-util.ts View on Github external
return (meta: StylableMeta) => {
        return new StylableTransformer({
            fileProcessor,
            requireModule,
            diagnostics: new Diagnostics(),
            keepValues: false
        }).transform(meta).meta;
    };
}
github wix / stylable / packages / language-service / src / lib / provider.ts View on Github external
private createProviderOptions(
        src: string,
        position: ProviderPosition,
        meta: StylableMeta,
        fakeRules: postcss.Rule[],
        fullLineText: string,
        cursorPosInLine: number,
        fs: IFileSystem
    ): ProviderOptions {
        const transformer = new StylableTransformer({
            diagnostics: new Diagnostics(),
            fileProcessor: this.stylable.fileProcessor,
            requireModule: () => {
                throw new Error('Not implemented, why are we here');
            }
        });

        const path = pathFromPosition(meta.rawAst, {
            line: position.line + 1,
            character: position.character
        });
        const astAtCursor: postcss.NodeBase = path[path.length - 1];
        const parentAst: postcss.NodeBase | undefined = (astAtCursor as postcss.Declaration).parent
            ? (astAtCursor as postcss.Declaration).parent
            : undefined;
        const parentSelector: SRule | null =
github wix / stylable / packages / language-service / src / lib / provider.ts View on Github external
length += node.name.length + 1;
                    if (
                        node.type === 'pseudo-class' &&
                        posChar > length + 1 &&
                        posChar <= length + 2 + node.content.length
                    ) {
                        word = node.name;
                    }
                }
            });
        }

        let stateDef = null as StateParsedValue | string | null;

        if (word) {
            const transformer = new StylableTransformer({
                diagnostics: new Diagnostics(),
                fileProcessor: this.stylable.fileProcessor,
                requireModule: () => {
                    throw new Error('Not implemented, why are we here');
                }
            });
            const resolvedElements = transformer.resolveSelectorElements(meta, line);
            resolvedElements[0][0].resolved.forEach(el => {
                const symbolStates = (el.symbol as ClassSymbol)[valueMapping.states];
                if (symbolStates && typeof symbolStates[word] === 'object') {
                    stateDef = symbolStates[word];
                }
            });
            if (stateDef && typeof stateDef === 'object') {
                const parameters = resolveStateParams(stateDef);