How to use the @stylable/core.safeParse 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 / core-test-kit / src / diagnostics.ts View on Github external
export function expectWarnings(css: string, warnings: Diagnostic[]) {
    const source = findTestLocations(css);
    const root = safeParse(source.css);
    const res = process(root);

    res.diagnostics.reports.forEach((report, i) => {
        const expectedWarning = warnings[i];
        if (expectedWarning.skip) {
            return;
        }

        expect(report.message).to.equal(expectedWarning.message);
        expect(report.node.source!.start, 'start').to.eql(source.start);
        if (source.word !== null) {
            expect(report.options.word).to.equal(source.word);
        }

        if (expectedWarning.severity) {
            expect(
github wix / stylable / packages / language-service / src / lib / provider.ts View on Github external
export function createMeta(src: string, path: string) {
    let meta: StylableMeta;
    const fakes: postcss.Rule[] = [];
    try {
        const ast: postcss.Root = safeParse(src, { from: URI.file(path).fsPath });
        if (ast.nodes) {
            for (const node of ast.nodes) {
                if (node.type === 'decl') {
                    const r = postcss.rule({ selector: node.prop + ':' + node.value });
                    r.source = node.source;
                    node.replaceWith(r);
                    fakes.push(r);
                }
            }
        }
        if (ast.raws.after && ast.raws.after.trim()) {
            const r = postcss.rule({ selector: ast.raws.after.trim() });
            ast.append(r);
            fakes.push(r);
        }
github wix / stylable / packages / schema-extract / src / main.ts View on Github external
export function extractSchema(
    css: string,
    filePath: string,
    root: string,
    path: MinimalPath,
    resolveNamespace?: (namespace: string, source: string) => string
) {
    const processor = new StylableProcessor(undefined, resolveNamespace);
    const meta = processor.process(safeParse(css, { from: filePath }));
    return generateSchema(meta, filePath, root, path);
}