Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
if (word.charAt(0) !== word.charAt(0).toLowerCase()) {
export function generateInfra(
config: InfraConfig,
diagnostics: Diagnostics = new Diagnostics()
): {
resolver: StylableResolver;
requireModule: RequireType;
fileProcessor: FileProcessor;
} {
const { fs, requireModule } = createMinimalFS(config);
const fileProcessor = cachedProcessFile(
(from, content) => {
const meta = process(postcss.parse(content, { from }), diagnostics);
meta.namespace = config.files[from].namespace || meta.namespace;
return meta;
},
fs,
x => x
);
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
});
}
return (meta: StylableMeta) => {
return new StylableTransformer({
fileProcessor,
requireModule,
diagnostics: new Diagnostics(),
keepValues: false
}).transform(meta).meta;
};
}
export function expectWarningsFromTransform(
config: Config,
expectedWarnings: Diagnostic[]
): StylableResults {
config.trimWS = false;
const locations: any = {};
for (const path in config.files) {
const source = findTestLocations(deindent(config.files[path].content).trim());
config.files[path].content = source.css;
locations[path] = source;
}
const diagnostics = new Diagnostics();
const result = generateFromMock(config, diagnostics);
const warningMessages = diagnostics.reports.map(d => d.message);
if (expectedWarnings.length === 0 && diagnostics.reports.length !== 0) {
expect(
expectedWarnings.length,
`expected no diagnostics but received ${JSON.stringify(warningMessages, null, 2)}`
).to.equal(diagnostics.reports.length);
}
diagnostics.reports.forEach((report, i) => {
const expectedWarning = expectedWarnings[i];
if (!expectedWarning) {
return;
}
const path = expectedWarning.file;
export function generateFromMock(
config: Config,
diagnostics: Diagnostics = new Diagnostics()
): StylableResults {
if (!isAbsolute(config.entry || '')) {
throw new Error('entry must be absolute path: ' + config.entry);
}
const entry = config.entry;
const t = createTransformer(config, diagnostics);
const result = t.transform(t.fileProcessor.process(entry || ''));
return result;
}
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 =
parentAst &&