@stylable/core
Advanced tools
Comparing version 4.6.0 to 4.7.0
@@ -13,3 +13,3 @@ "use strict"; | ||
const module_resolver_1 = require("./module-resolver"); | ||
function createInfrastructure(projectRoot, fileSystem, onProcess, resolveOptions = {}, resolveNamespace, timedCacheOptions, resolveModule = module_resolver_1.createDefaultResolver(fileSystem, resolveOptions), cssParser = parser_1.cssParse, createDiagnostics) { | ||
function createInfrastructure(projectRoot, fileSystem, onProcess, resolveOptions = {}, resolveNamespace, timedCacheOptions, resolveModule = (0, module_resolver_1.createDefaultResolver)(fileSystem, resolveOptions), cssParser = parser_1.cssParse, createDiagnostics) { | ||
let resolvePath = (context = projectRoot, moduleId) => { | ||
@@ -19,3 +19,3 @@ return path_1.default.isAbsolute(moduleId) ? moduleId : resolveModule(context, moduleId); | ||
if (timedCacheOptions) { | ||
const cacheManager = timed_cache_1.timedCache(resolvePath, { | ||
const cacheManager = (0, timed_cache_1.timedCache)(resolvePath, { | ||
createKey: (args) => args.join(';'), | ||
@@ -26,5 +26,5 @@ ...timedCacheOptions, | ||
} | ||
const fileProcessor = cached_process_file_1.cachedProcessFile((from, content) => { | ||
const fileProcessor = (0, cached_process_file_1.cachedProcessFile)((from, content) => { | ||
const resolvedFrom = resolvePath(projectRoot, from); | ||
return stylable_processor_1.process(cssParser(content, { from: resolvedFrom }), createDiagnostics === null || createDiagnostics === void 0 ? void 0 : createDiagnostics(resolvedFrom), resolveNamespace); | ||
return (0, stylable_processor_1.process)(cssParser(content, { from: resolvedFrom }), createDiagnostics === null || createDiagnostics === void 0 ? void 0 : createDiagnostics(resolvedFrom), resolveNamespace); | ||
}, { | ||
@@ -31,0 +31,0 @@ readFileSync(resolvedPath) { |
@@ -22,2 +22,5 @@ import type { StylableMeta } from './stylable-meta'; | ||
export declare const stTypes: CustomTypes; | ||
export declare const deprecatedStFunctions: Record<string, { | ||
alternativeName: string; | ||
}>; | ||
export declare const CustomValueStrategy: { | ||
@@ -24,0 +27,0 @@ args: (fnNode: ParsedValue, customTypes: CustomTypes) => (string | Box<string, any>)[]; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isCustomValue = exports.getBoxValue = exports.createCustomValue = exports.resolveCustomValues = exports.CustomValueStrategy = exports.stTypes = exports.unbox = exports.box = void 0; | ||
exports.isCustomValue = exports.getBoxValue = exports.createCustomValue = exports.resolveCustomValues = exports.CustomValueStrategy = exports.deprecatedStFunctions = exports.stTypes = exports.unbox = exports.box = void 0; | ||
const lodash_clonedeepwith_1 = __importDefault(require("lodash.clonedeepwith")); | ||
@@ -24,8 +24,8 @@ const postcss_value_parser_1 = __importDefault(require("postcss-value-parser")); | ||
else if (typeof boxed === 'object' && boxed.type && hasOwnProperty.call(boxed, 'value')) { | ||
return lodash_clonedeepwith_1.default(boxed.value, unbox); | ||
return (0, lodash_clonedeepwith_1.default)(boxed.value, unbox); | ||
} | ||
} | ||
exports.unbox = unbox; | ||
exports.stTypes = { | ||
stArray: createCustomValue({ | ||
function createStArrayCustomFunction() { | ||
return createCustomValue({ | ||
processArgs: (node, customTypes) => { | ||
@@ -38,4 +38,6 @@ return exports.CustomValueStrategy.args(node, customTypes); | ||
getValue: (value, index) => value[parseInt(index, 10)], | ||
}).register('stArray'), | ||
stMap: createCustomValue({ | ||
}); | ||
} | ||
function createStMapCustomFunction() { | ||
return createCustomValue({ | ||
processArgs: (node, customTypes) => { | ||
@@ -48,10 +50,26 @@ return exports.CustomValueStrategy.named(node, customTypes); | ||
getValue: (value, index) => value[index], | ||
}).register('stMap'), | ||
}); | ||
} | ||
exports.stTypes = { | ||
/** @deprecated - use `st-array` */ | ||
stArray: createStArrayCustomFunction().register('stArray'), | ||
/** @deprecated - use `st-map` */ | ||
stMap: createStMapCustomFunction().register('stMap'), | ||
'st-array': createStArrayCustomFunction().register('st-array'), | ||
'st-map': createStMapCustomFunction().register('st-map'), | ||
}; | ||
exports.deprecatedStFunctions = { | ||
stArray: { | ||
alternativeName: 'st-array', | ||
}, | ||
stMap: { | ||
alternativeName: 'st-map', | ||
}, | ||
}; | ||
exports.CustomValueStrategy = { | ||
args: (fnNode, customTypes) => { | ||
const pathArgs = stylable_value_parsers_1.getFormatterArgs(fnNode); | ||
const pathArgs = (0, stylable_value_parsers_1.getFormatterArgs)(fnNode); | ||
const outputArray = []; | ||
for (const arg of pathArgs) { | ||
const parsedArg = postcss_value_parser_1.default(arg).nodes[0]; | ||
const parsedArg = (0, postcss_value_parser_1.default)(arg).nodes[0]; | ||
const ct = parsedArg.type === 'function' && parsedArg.value; | ||
@@ -67,3 +85,3 @@ const resolvedValue = typeof ct === 'string' && customTypes[ct] | ||
const outputMap = {}; | ||
const s = stylable_value_parsers_1.getNamedArgs(fnNode); | ||
const s = (0, stylable_value_parsers_1.getNamedArgs)(fnNode); | ||
for (const [prop, space, ...valueNodes] of s) { | ||
@@ -87,3 +105,3 @@ if (space.type !== 'space') { | ||
else { | ||
resolvedValue = stylable_value_parsers_1.getStringValue(valueNode); | ||
resolvedValue = (0, stylable_value_parsers_1.getStringValue)(valueNode); | ||
} | ||
@@ -93,3 +111,3 @@ } | ||
else { | ||
resolvedValue = stylable_value_parsers_1.getStringValue(valueNodes); | ||
resolvedValue = (0, stylable_value_parsers_1.getStringValue)(valueNodes); | ||
} | ||
@@ -145,3 +163,3 @@ if (resolvedValue) { | ||
// TODO: add diagnostics | ||
return stylable_value_parsers_1.getStringValue([fallbackNode]); | ||
return (0, stylable_value_parsers_1.getStringValue)([fallbackNode]); | ||
} | ||
@@ -148,0 +166,0 @@ } |
import type * as postcss from 'postcss'; | ||
export declare type DiagnosticType = 'error' | 'warning'; | ||
export declare type DiagnosticType = 'error' | 'warning' | 'info'; | ||
export interface DiagnosticOptions { | ||
@@ -18,3 +18,4 @@ word?: string; | ||
warn(node: postcss.Node, message: string, options?: DiagnosticOptions): void; | ||
info(node: postcss.Node, message: string, options?: DiagnosticOptions): void; | ||
} | ||
//# sourceMappingURL=diagnostics.d.ts.map |
@@ -17,4 +17,7 @@ "use strict"; | ||
} | ||
info(node, message, options) { | ||
this.add('info', node, message, options); | ||
} | ||
} | ||
exports.Diagnostics = Diagnostics; | ||
//# sourceMappingURL=diagnostics.js.map |
@@ -23,5 +23,5 @@ import type * as postcss from 'postcss'; | ||
outputValue: string; | ||
typeError: Error; | ||
typeError?: Error; | ||
}; | ||
export declare function evalDeclarationValue(resolver: StylableResolver, value: string, meta: StylableMeta, node?: postcss.Node, variableOverride?: Record<string, string> | null, valueHook?: replaceValueHook, diagnostics?: Diagnostics, passedThrough?: string[], cssVarsMapping?: Record<string, string>, args?: string[]): string; | ||
//# sourceMappingURL=functions.d.ts.map |
@@ -38,5 +38,6 @@ "use strict"; | ||
diagnostics = node ? diagnostics : undefined; | ||
const customValues = custom_values_1.resolveCustomValues(meta, resolver); | ||
const parsedValue = postcss_value_parser_1.default(value); | ||
const customValues = (0, custom_values_1.resolveCustomValues)(meta, resolver); | ||
const parsedValue = (0, postcss_value_parser_1.default)(value); | ||
parsedValue.walk((parsedNode) => { | ||
var _a; | ||
const { type, value } = parsedNode; | ||
@@ -62,3 +63,3 @@ switch (type) { | ||
if (varSymbol && varSymbol._kind === 'var') { | ||
const resolved = processDeclarationValue(resolver, utils_1.stripQuotation(varSymbol.text), meta, varSymbol.node, variableOverride, valueHook, diagnostics, passedThrough.concat(createUniqID(meta.source, varName)), cssVarsMapping, getArgs); | ||
const resolved = processDeclarationValue(resolver, (0, utils_1.stripQuotation)(varSymbol.text), meta, varSymbol.node, variableOverride, valueHook, diagnostics, passedThrough.concat(createUniqID(meta.source, varName)), cssVarsMapping, getArgs); | ||
const { outputValue, topLevelType, typeError } = resolved; | ||
@@ -84,3 +85,3 @@ if (diagnostics && node) { | ||
if (resolvedVarSymbol._kind === 'var') { | ||
const resolvedValue = evalDeclarationValue(resolver, utils_1.stripQuotation(resolvedVarSymbol.text), resolvedVar.meta, resolvedVarSymbol.node, variableOverride, valueHook, diagnostics, passedThrough.concat(createUniqID(meta.source, varName)), cssVarsMapping, getArgs); | ||
const resolvedValue = evalDeclarationValue(resolver, (0, utils_1.stripQuotation)(resolvedVarSymbol.text), resolvedVar.meta, resolvedVarSymbol.node, variableOverride, valueHook, diagnostics, passedThrough.concat(createUniqID(meta.source, varName)), cssVarsMapping, getArgs); | ||
parsedNode.resolvedValue = valueHook | ||
@@ -142,4 +143,4 @@ ? valueHook(resolvedValue, varName, false, passedThrough) | ||
url.value.startsWith('~')) { | ||
const sourceDir = path_1.dirname(meta.source); | ||
url.value = stylable_assets_1.assureRelativeUrlPrefix(path_1.relative(sourceDir, resolver.resolvePath(url.value.slice(1), sourceDir)).replace(/\\/gm, '/')); | ||
const sourceDir = (0, path_1.dirname)(meta.source); | ||
url.value = (0, stylable_assets_1.assureRelativeUrlPrefix)((0, path_1.relative)(sourceDir, resolver.resolvePath(url.value.slice(1), sourceDir)).replace(/\\/gm, '/')); | ||
} | ||
@@ -154,3 +155,3 @@ } | ||
if (formatter && formatter._kind === 'js') { | ||
const formatterArgs = stylable_value_parsers_1.getFormatterArgs(parsedNode); | ||
const formatterArgs = (0, stylable_value_parsers_1.getFormatterArgs)(parsedNode); | ||
try { | ||
@@ -165,3 +166,3 @@ parsedNode.resolvedValue = formatter.symbol.apply(null, formatterArgs); | ||
if (diagnostics && node) { | ||
diagnostics.warn(node, exports.functionWarnings.FAIL_TO_EXECUTE_FORMATTER(parsedNode.resolvedValue, error.message), { word: node.value }); | ||
diagnostics.warn(node, exports.functionWarnings.FAIL_TO_EXECUTE_FORMATTER(parsedNode.resolvedValue, (_a = error) === null || _a === void 0 ? void 0 : _a.message), { word: node.value }); | ||
} | ||
@@ -172,3 +173,3 @@ } | ||
const varWithPrefix = parsedNode.nodes[0].value; | ||
if (stylable_utils_1.isCSSVarProp(varWithPrefix)) { | ||
if ((0, stylable_utils_1.isCSSVarProp)(varWithPrefix)) { | ||
if (cssVarsMapping && cssVarsMapping[varWithPrefix]) { | ||
@@ -183,3 +184,3 @@ parsedNode.nodes[0].value = cssVarsMapping[varWithPrefix]; | ||
} | ||
else if (native_reserved_lists_1.isCssNativeFunction(value)) { | ||
else if ((0, native_reserved_lists_1.isCssNativeFunction)(value)) { | ||
parsedNode.resolvedValue = stringifyFunction(value, parsedNode); | ||
@@ -203,3 +204,3 @@ } | ||
let topLevelType = null; | ||
let typeError = null; | ||
let typeError = undefined; | ||
for (const n of parsedValue.nodes) { | ||
@@ -219,7 +220,7 @@ if (n.type === 'function') { | ||
else { | ||
outputValue += stylable_value_parsers_1.getStringValue([n]); | ||
outputValue += (0, stylable_value_parsers_1.getStringValue)([n]); | ||
} | ||
} | ||
else { | ||
outputValue += stylable_value_parsers_1.getStringValue([n]); | ||
outputValue += (0, stylable_value_parsers_1.getStringValue)([n]); | ||
} | ||
@@ -248,3 +249,3 @@ } | ||
function stringifyFunction(name, parsedNode, perserveQuotes = false) { | ||
return `${name}(${stylable_value_parsers_1.getFormatterArgs(parsedNode, false, undefined, perserveQuotes).join(', ')})`; | ||
return `${name}(${(0, stylable_value_parsers_1.getFormatterArgs)(parsedNode, false, undefined, perserveQuotes).join(', ')})`; | ||
} | ||
@@ -251,0 +252,0 @@ function createUniqID(source, varName) { |
@@ -1,28 +0,48 @@ | ||
export * from './parser'; | ||
export * from './cached-process-file'; | ||
export * from './stylable-processor'; | ||
export * from './stylable-transformer'; | ||
export * from './stylable-utils'; | ||
export * from './stylable-resolver'; | ||
export * from './diagnostics'; | ||
export * from './memory-minimal-fs'; | ||
export * from './stylable-value-parsers'; | ||
export * from './create-infra-structure'; | ||
export * from './stylable'; | ||
export * from './types'; | ||
export * from './stylable-mixins'; | ||
export * from './stylable-assets'; | ||
export * from './functions'; | ||
export * from './custom-values'; | ||
export * from './state-validators'; | ||
export * from './selector-utils'; | ||
export * from './native-reserved-lists'; | ||
export * from './resolve-namespace-factories'; | ||
export * from './module-resolver'; | ||
export * from './report-diagnostic'; | ||
export * from './visit-meta-css-dependencies'; | ||
export * from './murmurhash'; | ||
export * from './timed-cache'; | ||
import * as pseudoStates from './pseudo-states'; | ||
export { pseudoStates }; | ||
export { CssParser, cssObjectToAst, cssParse, safeParse } from './parser'; | ||
export { CacheItem, FileProcessor, MinimalFS, cachedProcessFile, processFn, } from './cached-process-file'; | ||
export { CSSVarSymbol, ClassSymbol, DeclStylableProps, ElementSymbol, ImportSymbol, Imported, KeyframesSymbol, RESERVED_ROOT_NAME, RefedMixin, SDecl, SRule, SimpleSelector, StylableDirectives, StylableMeta, StylableProcessor, StylableSymbol, VarSymbol, createEmptyMeta, process, processNamespace, processorWarnings, validateScopingSelector, parsePseudoImport, } from './stylable-processor'; | ||
export { AdditionalSelector, KeyFrameWithNode, ResolvedElement, ScopedSelectorResults, StylableExports, StylableResults, StylableTransformer, TransformHooks, TransformerOptions, postProcessor, replaceValueHook, transformerWarnings, } from './stylable-transformer'; | ||
export { CUSTOM_SELECTOR_RE, createSubsetAst, expandCustomSelectors, findDeclaration, findRule, generateScopedCSSVar, getAlias, getDeclStylable, getSourcePath, isCSSVarProp, isValidClassName, isValidDeclaration, mergeRules, removeUnusedRules, scopeCSSVar, scopeSelector, transformMatchesOnRule, processDeclarationFunctions, } from './stylable-utils'; | ||
export { CSSResolve, CachedModule, JSResolve, JsModule, StylableResolver, StylableResolverCache, isInPath, resolverWarnings, } from './stylable-resolver'; | ||
export { Diagnostic, DiagnosticOptions, DiagnosticType, Diagnostics } from './diagnostics'; | ||
export { File, MinimalFSSetup, createMinimalFS } from './memory-minimal-fs'; | ||
export { ArgValue, ExtendsValue, MappedStates, MixinValue, ReportWarning, SBTypesParsers, STYLABLE_NAMED_MATCHER, STYLABLE_VALUE_MATCHER, TypedClass, animationPropRegExp, getFormatterArgs, getNamedArgs, getStringValue, globalValueRegExp, groupValues, listOptions, mixinDeclRegExp, paramMapping, rootValueMapping, stKeys, stValues, stValuesMap, strategies, validateAllowedNodesUntil, valueMapping, valueParserWarnings, } from './stylable-value-parsers'; | ||
export { StylableInfrastructure, createInfrastructure } from './create-infra-structure'; | ||
export { CreateProcessorOptions, Stylable, StylableConfig } from './stylable'; | ||
export { CSSObject, IStylableClassNameOptimizer, IStylableNamespaceOptimizer, IStylableOptimizer, ModuleResolver, OptimizeConfig, ParsedValue, PartialObject, StateArguments, StateParsedValue, StateTypeValidator, } from './types'; | ||
export { appendMixin, appendMixins, mixinWarnings } from './stylable-mixins'; | ||
export { OnUrlCallback, UrlNode, assureRelativeUrlPrefix, collectAssets, fixRelativeUrls, isAsset, isExternal, isUrl, makeAbsolute, } from './stylable-assets'; | ||
export { ResolvedFormatter, ValueFormatter, evalDeclarationValue, functionWarnings, processDeclarationValue, resolveArgumentsValue, } from './functions'; | ||
export { Box, BoxedValueArray, BoxedValueMap, CustomValueExtension, CustomValueStrategy, JSValueExtension, box, createCustomValue, getBoxValue, isCustomValue, resolveCustomValues, stTypes, unbox, } from './custom-values'; | ||
export { StateParamType, StateResult, SubValidator, systemValidators } from './state-validators'; | ||
export { PseudoSelectorAstNode, SelectorAstNode, SelectorChunk, SelectorChunk2, Visitor, createChecker, createSimpleSelectorChecker, createWarningRule, filterChunkNodesByType, fixChunkOrdering, getOriginDefinition, isChildOfAtRule, isCompRoot, isGlobal, isImport, isNested, isNodeMatch, isRootValid, isSimpleSelector, matchAtKeyframes, matchAtMedia, matchSelectorTarget, mergeChunks, parseSelector, separateChunks, separateChunks2, stringifySelector, traverseNode, } from './selector-utils'; | ||
export { isCssNativeFunction, nativeFunctions, nativeFunctionsDic, nativePseudoClasses, nativePseudoElements, reservedKeyFrames, } from './native-reserved-lists'; | ||
export { noCollisionNamespace, packageNamespaceFactory } from './resolve-namespace-factories'; | ||
export { createDefaultResolver } from './module-resolver'; | ||
export { DiagnosticsMode, EmitDiagnosticsContext, emitDiagnostics } from './report-diagnostic'; | ||
export { visitMetaCSSDependenciesBFS } from './visit-meta-css-dependencies'; | ||
export { murmurhash3_32_gc } from './murmurhash'; | ||
export { TimedCacheOptions, timedCache } from './timed-cache'; | ||
import { createBooleanStateClassName, createStateWithParamClassName, processPseudoStates, resolveStateParam, setStateToNode, validateStateArgument, validateStateDefinition } from './pseudo-states'; | ||
export declare const pseudoStates: { | ||
booleanStateDelimiter: string; | ||
createBooleanStateClassName: typeof createBooleanStateClassName; | ||
createStateWithParamClassName: typeof createStateWithParamClassName; | ||
processPseudoStates: typeof processPseudoStates; | ||
resolveStateParam: typeof resolveStateParam; | ||
setStateToNode: typeof setStateToNode; | ||
stateErrors: { | ||
UNKNOWN_STATE_USAGE: (name: string) => string; | ||
UNKNOWN_STATE_TYPE: (name: string, type: string) => string; | ||
TOO_MANY_STATE_TYPES: (name: string, types: string[]) => string; | ||
NO_STATE_ARGUMENT_GIVEN: (name: string, type: string) => string; | ||
NO_STATE_TYPE_GIVEN: (name: string) => string; | ||
TOO_MANY_ARGS_IN_VALIDATOR: (name: string, validator: string, args: string[]) => string; | ||
STATE_STARTS_WITH_HYPHEN: (name: string) => string; | ||
}; | ||
stateMiddleDelimiter: string; | ||
stateWithParamDelimiter: string; | ||
validateStateArgument: typeof validateStateArgument; | ||
validateStateDefinition: typeof validateStateDefinition; | ||
}; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.paramMapping = exports.mixinDeclRegExp = exports.listOptions = exports.groupValues = exports.globalValueRegExp = exports.getStringValue = exports.getNamedArgs = exports.getFormatterArgs = exports.animationPropRegExp = exports.STYLABLE_VALUE_MATCHER = exports.STYLABLE_NAMED_MATCHER = exports.SBTypesParsers = exports.createMinimalFS = exports.Diagnostics = exports.resolverWarnings = exports.isInPath = exports.StylableResolver = exports.processDeclarationFunctions = exports.transformMatchesOnRule = exports.scopeSelector = exports.scopeCSSVar = exports.removeUnusedRules = exports.mergeRules = exports.isValidDeclaration = exports.isValidClassName = exports.isCSSVarProp = exports.getSourcePath = exports.getDeclStylable = exports.getAlias = exports.generateScopedCSSVar = exports.findRule = exports.findDeclaration = exports.expandCustomSelectors = exports.createSubsetAst = exports.CUSTOM_SELECTOR_RE = exports.transformerWarnings = exports.StylableTransformer = exports.parsePseudoImport = exports.validateScopingSelector = exports.processorWarnings = exports.processNamespace = exports.process = exports.createEmptyMeta = exports.StylableProcessor = exports.StylableMeta = exports.RESERVED_ROOT_NAME = exports.cachedProcessFile = exports.safeParse = exports.cssParse = exports.cssObjectToAst = void 0; | ||
exports.mergeChunks = exports.matchSelectorTarget = exports.matchAtMedia = exports.matchAtKeyframes = exports.isSimpleSelector = exports.isRootValid = exports.isNodeMatch = exports.isNested = exports.isImport = exports.isGlobal = exports.isCompRoot = exports.isChildOfAtRule = exports.getOriginDefinition = exports.fixChunkOrdering = exports.filterChunkNodesByType = exports.createWarningRule = exports.createSimpleSelectorChecker = exports.createChecker = exports.systemValidators = exports.unbox = exports.stTypes = exports.resolveCustomValues = exports.isCustomValue = exports.getBoxValue = exports.createCustomValue = exports.box = exports.CustomValueStrategy = exports.resolveArgumentsValue = exports.processDeclarationValue = exports.functionWarnings = exports.evalDeclarationValue = exports.makeAbsolute = exports.isUrl = exports.isExternal = exports.isAsset = exports.fixRelativeUrls = exports.collectAssets = exports.assureRelativeUrlPrefix = exports.mixinWarnings = exports.appendMixins = exports.appendMixin = exports.Stylable = exports.createInfrastructure = exports.valueParserWarnings = exports.valueMapping = exports.validateAllowedNodesUntil = exports.strategies = exports.stValuesMap = exports.stValues = exports.rootValueMapping = void 0; | ||
exports.pseudoStates = exports.timedCache = exports.murmurhash3_32_gc = exports.visitMetaCSSDependenciesBFS = exports.emitDiagnostics = exports.createDefaultResolver = exports.packageNamespaceFactory = exports.noCollisionNamespace = exports.reservedKeyFrames = exports.nativePseudoElements = exports.nativePseudoClasses = exports.nativeFunctionsDic = exports.isCssNativeFunction = exports.traverseNode = exports.stringifySelector = exports.separateChunks2 = exports.separateChunks = exports.parseSelector = void 0; | ||
var parser_1 = require("./parser"); | ||
Object.defineProperty(exports, "cssObjectToAst", { enumerable: true, get: function () { return parser_1.cssObjectToAst; } }); | ||
Object.defineProperty(exports, "cssParse", { enumerable: true, get: function () { return parser_1.cssParse; } }); | ||
Object.defineProperty(exports, "safeParse", { enumerable: true, get: function () { return parser_1.safeParse; } }); | ||
var cached_process_file_1 = require("./cached-process-file"); | ||
Object.defineProperty(exports, "cachedProcessFile", { enumerable: true, get: function () { return cached_process_file_1.cachedProcessFile; } }); | ||
var stylable_processor_1 = require("./stylable-processor"); | ||
Object.defineProperty(exports, "RESERVED_ROOT_NAME", { enumerable: true, get: function () { return stylable_processor_1.RESERVED_ROOT_NAME; } }); | ||
Object.defineProperty(exports, "StylableMeta", { enumerable: true, get: function () { return stylable_processor_1.StylableMeta; } }); | ||
Object.defineProperty(exports, "StylableProcessor", { enumerable: true, get: function () { return stylable_processor_1.StylableProcessor; } }); | ||
Object.defineProperty(exports, "createEmptyMeta", { enumerable: true, get: function () { return stylable_processor_1.createEmptyMeta; } }); | ||
Object.defineProperty(exports, "process", { enumerable: true, get: function () { return stylable_processor_1.process; } }); | ||
Object.defineProperty(exports, "processNamespace", { enumerable: true, get: function () { return stylable_processor_1.processNamespace; } }); | ||
Object.defineProperty(exports, "processorWarnings", { enumerable: true, get: function () { return stylable_processor_1.processorWarnings; } }); | ||
Object.defineProperty(exports, "validateScopingSelector", { enumerable: true, get: function () { return stylable_processor_1.validateScopingSelector; } }); | ||
Object.defineProperty(exports, "parsePseudoImport", { enumerable: true, get: function () { return stylable_processor_1.parsePseudoImport; } }); | ||
var stylable_transformer_1 = require("./stylable-transformer"); | ||
Object.defineProperty(exports, "StylableTransformer", { enumerable: true, get: function () { return stylable_transformer_1.StylableTransformer; } }); | ||
Object.defineProperty(exports, "transformerWarnings", { enumerable: true, get: function () { return stylable_transformer_1.transformerWarnings; } }); | ||
var stylable_utils_1 = require("./stylable-utils"); | ||
Object.defineProperty(exports, "CUSTOM_SELECTOR_RE", { enumerable: true, get: function () { return stylable_utils_1.CUSTOM_SELECTOR_RE; } }); | ||
Object.defineProperty(exports, "createSubsetAst", { enumerable: true, get: function () { return stylable_utils_1.createSubsetAst; } }); | ||
Object.defineProperty(exports, "expandCustomSelectors", { enumerable: true, get: function () { return stylable_utils_1.expandCustomSelectors; } }); | ||
Object.defineProperty(exports, "findDeclaration", { enumerable: true, get: function () { return stylable_utils_1.findDeclaration; } }); | ||
Object.defineProperty(exports, "findRule", { enumerable: true, get: function () { return stylable_utils_1.findRule; } }); | ||
Object.defineProperty(exports, "generateScopedCSSVar", { enumerable: true, get: function () { return stylable_utils_1.generateScopedCSSVar; } }); | ||
Object.defineProperty(exports, "getAlias", { enumerable: true, get: function () { return stylable_utils_1.getAlias; } }); | ||
Object.defineProperty(exports, "getDeclStylable", { enumerable: true, get: function () { return stylable_utils_1.getDeclStylable; } }); | ||
Object.defineProperty(exports, "getSourcePath", { enumerable: true, get: function () { return stylable_utils_1.getSourcePath; } }); | ||
Object.defineProperty(exports, "isCSSVarProp", { enumerable: true, get: function () { return stylable_utils_1.isCSSVarProp; } }); | ||
Object.defineProperty(exports, "isValidClassName", { enumerable: true, get: function () { return stylable_utils_1.isValidClassName; } }); | ||
Object.defineProperty(exports, "isValidDeclaration", { enumerable: true, get: function () { return stylable_utils_1.isValidDeclaration; } }); | ||
Object.defineProperty(exports, "mergeRules", { enumerable: true, get: function () { return stylable_utils_1.mergeRules; } }); | ||
Object.defineProperty(exports, "removeUnusedRules", { enumerable: true, get: function () { return stylable_utils_1.removeUnusedRules; } }); | ||
Object.defineProperty(exports, "scopeCSSVar", { enumerable: true, get: function () { return stylable_utils_1.scopeCSSVar; } }); | ||
Object.defineProperty(exports, "scopeSelector", { enumerable: true, get: function () { return stylable_utils_1.scopeSelector; } }); | ||
Object.defineProperty(exports, "transformMatchesOnRule", { enumerable: true, get: function () { return stylable_utils_1.transformMatchesOnRule; } }); | ||
Object.defineProperty(exports, "processDeclarationFunctions", { enumerable: true, get: function () { return stylable_utils_1.processDeclarationFunctions; } }); | ||
var stylable_resolver_1 = require("./stylable-resolver"); | ||
Object.defineProperty(exports, "StylableResolver", { enumerable: true, get: function () { return stylable_resolver_1.StylableResolver; } }); | ||
Object.defineProperty(exports, "isInPath", { enumerable: true, get: function () { return stylable_resolver_1.isInPath; } }); | ||
Object.defineProperty(exports, "resolverWarnings", { enumerable: true, get: function () { return stylable_resolver_1.resolverWarnings; } }); | ||
var diagnostics_1 = require("./diagnostics"); | ||
Object.defineProperty(exports, "Diagnostics", { enumerable: true, get: function () { return diagnostics_1.Diagnostics; } }); | ||
var memory_minimal_fs_1 = require("./memory-minimal-fs"); | ||
Object.defineProperty(exports, "createMinimalFS", { enumerable: true, get: function () { return memory_minimal_fs_1.createMinimalFS; } }); | ||
var stylable_value_parsers_1 = require("./stylable-value-parsers"); | ||
Object.defineProperty(exports, "SBTypesParsers", { enumerable: true, get: function () { return stylable_value_parsers_1.SBTypesParsers; } }); | ||
Object.defineProperty(exports, "STYLABLE_NAMED_MATCHER", { enumerable: true, get: function () { return stylable_value_parsers_1.STYLABLE_NAMED_MATCHER; } }); | ||
Object.defineProperty(exports, "STYLABLE_VALUE_MATCHER", { enumerable: true, get: function () { return stylable_value_parsers_1.STYLABLE_VALUE_MATCHER; } }); | ||
Object.defineProperty(exports, "animationPropRegExp", { enumerable: true, get: function () { return stylable_value_parsers_1.animationPropRegExp; } }); | ||
Object.defineProperty(exports, "getFormatterArgs", { enumerable: true, get: function () { return stylable_value_parsers_1.getFormatterArgs; } }); | ||
Object.defineProperty(exports, "getNamedArgs", { enumerable: true, get: function () { return stylable_value_parsers_1.getNamedArgs; } }); | ||
Object.defineProperty(exports, "getStringValue", { enumerable: true, get: function () { return stylable_value_parsers_1.getStringValue; } }); | ||
Object.defineProperty(exports, "globalValueRegExp", { enumerable: true, get: function () { return stylable_value_parsers_1.globalValueRegExp; } }); | ||
Object.defineProperty(exports, "groupValues", { enumerable: true, get: function () { return stylable_value_parsers_1.groupValues; } }); | ||
Object.defineProperty(exports, "listOptions", { enumerable: true, get: function () { return stylable_value_parsers_1.listOptions; } }); | ||
Object.defineProperty(exports, "mixinDeclRegExp", { enumerable: true, get: function () { return stylable_value_parsers_1.mixinDeclRegExp; } }); | ||
Object.defineProperty(exports, "paramMapping", { enumerable: true, get: function () { return stylable_value_parsers_1.paramMapping; } }); | ||
Object.defineProperty(exports, "rootValueMapping", { enumerable: true, get: function () { return stylable_value_parsers_1.rootValueMapping; } }); | ||
Object.defineProperty(exports, "stValues", { enumerable: true, get: function () { return stylable_value_parsers_1.stValues; } }); | ||
Object.defineProperty(exports, "stValuesMap", { enumerable: true, get: function () { return stylable_value_parsers_1.stValuesMap; } }); | ||
Object.defineProperty(exports, "strategies", { enumerable: true, get: function () { return stylable_value_parsers_1.strategies; } }); | ||
Object.defineProperty(exports, "validateAllowedNodesUntil", { enumerable: true, get: function () { return stylable_value_parsers_1.validateAllowedNodesUntil; } }); | ||
Object.defineProperty(exports, "valueMapping", { enumerable: true, get: function () { return stylable_value_parsers_1.valueMapping; } }); | ||
Object.defineProperty(exports, "valueParserWarnings", { enumerable: true, get: function () { return stylable_value_parsers_1.valueParserWarnings; } }); | ||
var create_infra_structure_1 = require("./create-infra-structure"); | ||
Object.defineProperty(exports, "createInfrastructure", { enumerable: true, get: function () { return create_infra_structure_1.createInfrastructure; } }); | ||
var stylable_1 = require("./stylable"); | ||
Object.defineProperty(exports, "Stylable", { enumerable: true, get: function () { return stylable_1.Stylable; } }); | ||
var stylable_mixins_1 = require("./stylable-mixins"); | ||
Object.defineProperty(exports, "appendMixin", { enumerable: true, get: function () { return stylable_mixins_1.appendMixin; } }); | ||
Object.defineProperty(exports, "appendMixins", { enumerable: true, get: function () { return stylable_mixins_1.appendMixins; } }); | ||
Object.defineProperty(exports, "mixinWarnings", { enumerable: true, get: function () { return stylable_mixins_1.mixinWarnings; } }); | ||
var stylable_assets_1 = require("./stylable-assets"); | ||
Object.defineProperty(exports, "assureRelativeUrlPrefix", { enumerable: true, get: function () { return stylable_assets_1.assureRelativeUrlPrefix; } }); | ||
Object.defineProperty(exports, "collectAssets", { enumerable: true, get: function () { return stylable_assets_1.collectAssets; } }); | ||
Object.defineProperty(exports, "fixRelativeUrls", { enumerable: true, get: function () { return stylable_assets_1.fixRelativeUrls; } }); | ||
Object.defineProperty(exports, "isAsset", { enumerable: true, get: function () { return stylable_assets_1.isAsset; } }); | ||
Object.defineProperty(exports, "isExternal", { enumerable: true, get: function () { return stylable_assets_1.isExternal; } }); | ||
Object.defineProperty(exports, "isUrl", { enumerable: true, get: function () { return stylable_assets_1.isUrl; } }); | ||
Object.defineProperty(exports, "makeAbsolute", { enumerable: true, get: function () { return stylable_assets_1.makeAbsolute; } }); | ||
var functions_1 = require("./functions"); | ||
Object.defineProperty(exports, "evalDeclarationValue", { enumerable: true, get: function () { return functions_1.evalDeclarationValue; } }); | ||
Object.defineProperty(exports, "functionWarnings", { enumerable: true, get: function () { return functions_1.functionWarnings; } }); | ||
Object.defineProperty(exports, "processDeclarationValue", { enumerable: true, get: function () { return functions_1.processDeclarationValue; } }); | ||
Object.defineProperty(exports, "resolveArgumentsValue", { enumerable: true, get: function () { return functions_1.resolveArgumentsValue; } }); | ||
var custom_values_1 = require("./custom-values"); | ||
Object.defineProperty(exports, "CustomValueStrategy", { enumerable: true, get: function () { return custom_values_1.CustomValueStrategy; } }); | ||
Object.defineProperty(exports, "box", { enumerable: true, get: function () { return custom_values_1.box; } }); | ||
Object.defineProperty(exports, "createCustomValue", { enumerable: true, get: function () { return custom_values_1.createCustomValue; } }); | ||
Object.defineProperty(exports, "getBoxValue", { enumerable: true, get: function () { return custom_values_1.getBoxValue; } }); | ||
Object.defineProperty(exports, "isCustomValue", { enumerable: true, get: function () { return custom_values_1.isCustomValue; } }); | ||
Object.defineProperty(exports, "resolveCustomValues", { enumerable: true, get: function () { return custom_values_1.resolveCustomValues; } }); | ||
Object.defineProperty(exports, "stTypes", { enumerable: true, get: function () { return custom_values_1.stTypes; } }); | ||
Object.defineProperty(exports, "unbox", { enumerable: true, get: function () { return custom_values_1.unbox; } }); | ||
var state_validators_1 = require("./state-validators"); | ||
Object.defineProperty(exports, "systemValidators", { enumerable: true, get: function () { return state_validators_1.systemValidators; } }); | ||
var selector_utils_1 = require("./selector-utils"); | ||
Object.defineProperty(exports, "createChecker", { enumerable: true, get: function () { return selector_utils_1.createChecker; } }); | ||
Object.defineProperty(exports, "createSimpleSelectorChecker", { enumerable: true, get: function () { return selector_utils_1.createSimpleSelectorChecker; } }); | ||
Object.defineProperty(exports, "createWarningRule", { enumerable: true, get: function () { return selector_utils_1.createWarningRule; } }); | ||
Object.defineProperty(exports, "filterChunkNodesByType", { enumerable: true, get: function () { return selector_utils_1.filterChunkNodesByType; } }); | ||
Object.defineProperty(exports, "fixChunkOrdering", { enumerable: true, get: function () { return selector_utils_1.fixChunkOrdering; } }); | ||
Object.defineProperty(exports, "getOriginDefinition", { enumerable: true, get: function () { return selector_utils_1.getOriginDefinition; } }); | ||
Object.defineProperty(exports, "isChildOfAtRule", { enumerable: true, get: function () { return selector_utils_1.isChildOfAtRule; } }); | ||
Object.defineProperty(exports, "isCompRoot", { enumerable: true, get: function () { return selector_utils_1.isCompRoot; } }); | ||
Object.defineProperty(exports, "isGlobal", { enumerable: true, get: function () { return selector_utils_1.isGlobal; } }); | ||
Object.defineProperty(exports, "isImport", { enumerable: true, get: function () { return selector_utils_1.isImport; } }); | ||
Object.defineProperty(exports, "isNested", { enumerable: true, get: function () { return selector_utils_1.isNested; } }); | ||
Object.defineProperty(exports, "isNodeMatch", { enumerable: true, get: function () { return selector_utils_1.isNodeMatch; } }); | ||
Object.defineProperty(exports, "isRootValid", { enumerable: true, get: function () { return selector_utils_1.isRootValid; } }); | ||
Object.defineProperty(exports, "isSimpleSelector", { enumerable: true, get: function () { return selector_utils_1.isSimpleSelector; } }); | ||
Object.defineProperty(exports, "matchAtKeyframes", { enumerable: true, get: function () { return selector_utils_1.matchAtKeyframes; } }); | ||
Object.defineProperty(exports, "matchAtMedia", { enumerable: true, get: function () { return selector_utils_1.matchAtMedia; } }); | ||
Object.defineProperty(exports, "matchSelectorTarget", { enumerable: true, get: function () { return selector_utils_1.matchSelectorTarget; } }); | ||
Object.defineProperty(exports, "mergeChunks", { enumerable: true, get: function () { return selector_utils_1.mergeChunks; } }); | ||
Object.defineProperty(exports, "parseSelector", { enumerable: true, get: function () { return selector_utils_1.parseSelector; } }); | ||
Object.defineProperty(exports, "separateChunks", { enumerable: true, get: function () { return selector_utils_1.separateChunks; } }); | ||
Object.defineProperty(exports, "separateChunks2", { enumerable: true, get: function () { return selector_utils_1.separateChunks2; } }); | ||
Object.defineProperty(exports, "stringifySelector", { enumerable: true, get: function () { return selector_utils_1.stringifySelector; } }); | ||
Object.defineProperty(exports, "traverseNode", { enumerable: true, get: function () { return selector_utils_1.traverseNode; } }); | ||
var native_reserved_lists_1 = require("./native-reserved-lists"); | ||
Object.defineProperty(exports, "isCssNativeFunction", { enumerable: true, get: function () { return native_reserved_lists_1.isCssNativeFunction; } }); | ||
Object.defineProperty(exports, "nativeFunctionsDic", { enumerable: true, get: function () { return native_reserved_lists_1.nativeFunctionsDic; } }); | ||
Object.defineProperty(exports, "nativePseudoClasses", { enumerable: true, get: function () { return native_reserved_lists_1.nativePseudoClasses; } }); | ||
Object.defineProperty(exports, "nativePseudoElements", { enumerable: true, get: function () { return native_reserved_lists_1.nativePseudoElements; } }); | ||
Object.defineProperty(exports, "reservedKeyFrames", { enumerable: true, get: function () { return native_reserved_lists_1.reservedKeyFrames; } }); | ||
var resolve_namespace_factories_1 = require("./resolve-namespace-factories"); | ||
Object.defineProperty(exports, "noCollisionNamespace", { enumerable: true, get: function () { return resolve_namespace_factories_1.noCollisionNamespace; } }); | ||
Object.defineProperty(exports, "packageNamespaceFactory", { enumerable: true, get: function () { return resolve_namespace_factories_1.packageNamespaceFactory; } }); | ||
var module_resolver_1 = require("./module-resolver"); | ||
Object.defineProperty(exports, "createDefaultResolver", { enumerable: true, get: function () { return module_resolver_1.createDefaultResolver; } }); | ||
var report_diagnostic_1 = require("./report-diagnostic"); | ||
Object.defineProperty(exports, "emitDiagnostics", { enumerable: true, get: function () { return report_diagnostic_1.emitDiagnostics; } }); | ||
var visit_meta_css_dependencies_1 = require("./visit-meta-css-dependencies"); | ||
Object.defineProperty(exports, "visitMetaCSSDependenciesBFS", { enumerable: true, get: function () { return visit_meta_css_dependencies_1.visitMetaCSSDependenciesBFS; } }); | ||
var murmurhash_1 = require("./murmurhash"); | ||
Object.defineProperty(exports, "murmurhash3_32_gc", { enumerable: true, get: function () { return murmurhash_1.murmurhash3_32_gc; } }); | ||
var timed_cache_1 = require("./timed-cache"); | ||
Object.defineProperty(exports, "timedCache", { enumerable: true, get: function () { return timed_cache_1.timedCache; } }); | ||
const pseudo_states_1 = require("./pseudo-states"); | ||
exports.pseudoStates = { | ||
booleanStateDelimiter: pseudo_states_1.booleanStateDelimiter, | ||
createBooleanStateClassName: pseudo_states_1.createBooleanStateClassName, | ||
createStateWithParamClassName: pseudo_states_1.createStateWithParamClassName, | ||
processPseudoStates: pseudo_states_1.processPseudoStates, | ||
resolveStateParam: pseudo_states_1.resolveStateParam, | ||
setStateToNode: pseudo_states_1.setStateToNode, | ||
stateErrors: pseudo_states_1.stateErrors, | ||
stateMiddleDelimiter: pseudo_states_1.stateMiddleDelimiter, | ||
stateWithParamDelimiter: pseudo_states_1.stateWithParamDelimiter, | ||
validateStateArgument: pseudo_states_1.validateStateArgument, | ||
validateStateDefinition: pseudo_states_1.validateStateDefinition, | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pseudoStates = void 0; | ||
__exportStar(require("./parser"), exports); | ||
__exportStar(require("./cached-process-file"), exports); | ||
__exportStar(require("./stylable-processor"), exports); | ||
__exportStar(require("./stylable-transformer"), exports); | ||
__exportStar(require("./stylable-utils"), exports); | ||
__exportStar(require("./stylable-resolver"), exports); | ||
__exportStar(require("./diagnostics"), exports); | ||
__exportStar(require("./memory-minimal-fs"), exports); | ||
__exportStar(require("./stylable-value-parsers"), exports); | ||
__exportStar(require("./create-infra-structure"), exports); | ||
__exportStar(require("./stylable"), exports); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./stylable-mixins"), exports); | ||
__exportStar(require("./stylable-assets"), exports); | ||
__exportStar(require("./functions"), exports); | ||
__exportStar(require("./custom-values"), exports); | ||
__exportStar(require("./state-validators"), exports); | ||
__exportStar(require("./selector-utils"), exports); | ||
__exportStar(require("./native-reserved-lists"), exports); | ||
__exportStar(require("./resolve-namespace-factories"), exports); | ||
__exportStar(require("./module-resolver"), exports); | ||
__exportStar(require("./report-diagnostic"), exports); | ||
__exportStar(require("./visit-meta-css-dependencies"), exports); | ||
__exportStar(require("./murmurhash"), exports); | ||
__exportStar(require("./timed-cache"), exports); | ||
const pseudoStates = __importStar(require("./pseudo-states")); | ||
exports.pseudoStates = pseudoStates; | ||
//# sourceMappingURL=index.js.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
for (const filePath of filePaths.keys()) { | ||
for (const directoryPath of getParentPaths(path_1.dirname(filePath))) { | ||
for (const directoryPath of getParentPaths((0, path_1.dirname)(filePath))) { | ||
directoryPaths.add(directoryPath); | ||
@@ -28,3 +28,3 @@ } | ||
if (trimWS) { | ||
return deindent_1.default(files[path].content).trim(); | ||
return (0, deindent_1.default)(files[path].content).trim(); | ||
} | ||
@@ -88,3 +88,3 @@ return files[path].content; | ||
lastPath = currentPath; | ||
currentPath = path_1.dirname(currentPath); | ||
currentPath = (0, path_1.dirname)(currentPath); | ||
} | ||
@@ -91,0 +91,0 @@ return parentPaths; |
@@ -31,3 +31,3 @@ "use strict"; | ||
const postcss_safe_parser_1 = __importDefault(require("postcss-safe-parser")); | ||
const processor = postcss_1.default([postcss_nested_1.default()]); | ||
const processor = (0, postcss_1.default)([(0, postcss_nested_1.default)()]); | ||
function cssObjectToAst(cssObject, sourceFile = '') { | ||
@@ -38,5 +38,5 @@ return processor.process(cssObject, { from: sourceFile, parser: postcss_js_1.default }); | ||
function safeParse(css, options = { from: 'style.css' }) { | ||
return postcss_safe_parser_1.default(css, options); | ||
return (0, postcss_safe_parser_1.default)(css, options); | ||
} | ||
exports.safeParse = safeParse; | ||
//# sourceMappingURL=parser.js.map |
@@ -28,4 +28,4 @@ "use strict"; | ||
const mappedStates = {}; | ||
const ast = postcss_value_parser_1.default(value); | ||
const statesSplitByComma = stylable_value_parsers_1.groupValues(ast.nodes); | ||
const ast = (0, postcss_value_parser_1.default)(value); | ||
const statesSplitByComma = (0, stylable_value_parsers_1.groupValues)(ast.nodes); | ||
statesSplitByComma.forEach((workingState) => { | ||
@@ -60,3 +60,3 @@ const [stateDefinition, ...stateDefault] = workingState; | ||
if (stateDefinition.nodes.length > 1) { | ||
diagnostics.warn(decl, exports.stateErrors.TOO_MANY_STATE_TYPES(stateDefinition.value, stylable_value_parsers_1.listOptions(stateDefinition)), { word: decl.value }); | ||
diagnostics.warn(decl, exports.stateErrors.TOO_MANY_STATE_TYPES(stateDefinition.value, (0, stylable_value_parsers_1.listOptions)(stateDefinition)), { word: decl.value }); | ||
} | ||
@@ -92,7 +92,7 @@ const paramType = stateDefinition.nodes[0]; | ||
function resolveArguments(paramType, stateType, name, diagnostics, decl) { | ||
const separatedByComma = stylable_value_parsers_1.groupValues(paramType.nodes); | ||
const separatedByComma = (0, stylable_value_parsers_1.groupValues)(paramType.nodes); | ||
separatedByComma.forEach((group) => { | ||
const validator = group[0]; | ||
if (validator.type === 'function') { | ||
const args = stylable_value_parsers_1.listOptions(validator); | ||
const args = (0, stylable_value_parsers_1.listOptions)(validator); | ||
if (args.length > 1) { | ||
@@ -220,3 +220,3 @@ diagnostics.warn(decl, exports.stateErrors.TOO_MANY_ARGS_IN_VALIDATOR(name, validator.value, args), { word: decl.value }); | ||
} | ||
const strippedParam = utils_1.stripQuotation(actualParam); | ||
const strippedParam = (0, utils_1.stripQuotation)(actualParam); | ||
node.type = 'class'; | ||
@@ -228,3 +228,3 @@ node.name = createStateWithParamClassName(name, namespace, strippedParam); | ||
const param = nodeContent || defaultStringValue; | ||
return functions_1.evalDeclarationValue(resolver, param, meta, rule, undefined, undefined, diagnostics); | ||
return (0, functions_1.evalDeclarationValue)(resolver, param, meta, rule, undefined, undefined, diagnostics); | ||
} | ||
@@ -231,0 +231,0 @@ function createBooleanStateClassName(stateName, namespace) { |
@@ -32,3 +32,3 @@ "use strict"; | ||
const body = part.slice(position); | ||
const matches = balanced_match_1.default('(', ')', body); | ||
const matches = (0, balanced_match_1.default)('(', ')', body); | ||
const bodySelectors = matches && matches.body | ||
@@ -35,0 +35,0 @@ ? postcss_1.list |
@@ -9,2 +9,6 @@ "use strict"; | ||
const error = new Error(message); | ||
if (type === 'info') { | ||
ctx.emitWarning(error); | ||
return; | ||
} | ||
if (diagnosticsMode === 'auto') { | ||
@@ -27,6 +31,9 @@ if (type === 'warning') { | ||
var _a, _b; | ||
(_a = meta.diagnostics) === null || _a === void 0 ? void 0 : _a.reports.forEach((diagnostic) => reportDiagnostic(ctx, diagnosticsMode, diagnostic)); | ||
(_b = meta.transformDiagnostics) === null || _b === void 0 ? void 0 : _b.reports.forEach((diagnostic) => reportDiagnostic(ctx, diagnosticsMode, diagnostic)); | ||
(_a = meta.diagnostics) === null || _a === void 0 ? void 0 : _a.reports.forEach(handleReport); | ||
(_b = meta.transformDiagnostics) === null || _b === void 0 ? void 0 : _b.reports.forEach(handleReport); | ||
function handleReport(diagnostic) { | ||
reportDiagnostic(ctx, diagnosticsMode, diagnostic); | ||
} | ||
} | ||
exports.emitDiagnostics = emitDiagnostics; | ||
//# sourceMappingURL=report-diagnostic.js.map |
@@ -15,3 +15,3 @@ "use strict"; | ||
namespace + | ||
murmurhash_1.murmurhash3_32_gc(hashSalt + config.name + '@' + normalizeVersion(config.version) + '/' + fromRoot)); | ||
(0, murmurhash_1.murmurhash3_32_gc)(hashSalt + config.name + '@' + normalizeVersion(config.version) + '/' + fromRoot)); | ||
}; | ||
@@ -18,0 +18,0 @@ } |
@@ -126,3 +126,3 @@ "use strict"; | ||
function isSimpleSelector(selectorAst) { | ||
const isSimpleSelectorASTNode = exports.createSimpleSelectorChecker(); | ||
const isSimpleSelectorASTNode = (0, exports.createSimpleSelectorChecker)(); | ||
const isSimple = traverseNode(selectorAst, (node) => isSimpleSelectorASTNode(node) !== false /*stop on complex selector */); | ||
@@ -129,0 +129,0 @@ return isSimple; |
@@ -18,5 +18,4 @@ import type * as postcss from 'postcss'; | ||
export declare function makeAbsolute(resourcePath: string, rootContext: string, moduleContext: string): string; | ||
export declare function processDeclarationUrls(decl: postcss.Declaration, onUrl: OnUrlCallback, transform: boolean): void; | ||
export declare function fixRelativeUrls(ast: postcss.Root, originPath: string, targetPath: string): void; | ||
export declare function assureRelativeUrlPrefix(url: string): string; | ||
//# sourceMappingURL=stylable-assets.d.ts.map |
@@ -6,10 +6,14 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assureRelativeUrlPrefix = exports.fixRelativeUrls = exports.processDeclarationUrls = exports.makeAbsolute = exports.isAsset = exports.isUrl = exports.isExternal = exports.collectAssets = void 0; | ||
exports.assureRelativeUrlPrefix = exports.fixRelativeUrls = exports.makeAbsolute = exports.isAsset = exports.isUrl = exports.isExternal = exports.collectAssets = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
const css_selector_tokenizer_1 = __importDefault(require("css-selector-tokenizer")); | ||
const { parseValues, stringifyValues } = css_selector_tokenizer_1.default; | ||
const stylable_utils_1 = require("./stylable-utils"); | ||
function collectAssets(ast) { | ||
const assetDependencies = []; | ||
const onUrl = (node) => assetDependencies.push(node.url); | ||
ast.walkDecls((decl) => processDeclarationUrls(decl, onUrl, false)); | ||
ast.walkDecls((decl) => { | ||
(0, stylable_utils_1.processDeclarationFunctions)(decl, (node) => { | ||
if (node.type === 'url') { | ||
assetDependencies.push(node.url); | ||
} | ||
}, false); | ||
}); | ||
return assetDependencies; | ||
@@ -58,37 +62,17 @@ } | ||
exports.makeAbsolute = makeAbsolute; | ||
function processDeclarationUrls(decl, onUrl, transform) { | ||
const ast = parseValues(decl.value); | ||
ast.nodes.forEach((node) => { | ||
node.nodes.forEach((node) => findUrls(node, onUrl)); | ||
function fixRelativeUrls(ast, originPath, targetPath) { | ||
ast.walkDecls((decl) => { | ||
(0, stylable_utils_1.processDeclarationFunctions)(decl, (node) => { | ||
if (node.type === 'url') { | ||
if (!node.url || !isAsset(node.url) || !node.url.startsWith('.')) { | ||
return; | ||
} | ||
const url = path_1.default | ||
.join(path_1.default.relative(path_1.default.dirname(targetPath), path_1.default.dirname(originPath)), node.url) | ||
.replace(/\\/gm, '/'); | ||
node.url = assureRelativeUrlPrefix(url); | ||
} | ||
}, true); | ||
}); | ||
if (transform) { | ||
decl.value = stringifyValues(ast); | ||
} | ||
} | ||
exports.processDeclarationUrls = processDeclarationUrls; | ||
function findUrls(node, onUrl) { | ||
switch (node.type) { | ||
case 'value': | ||
node.nodes.forEach((child) => findUrls(child, onUrl)); | ||
break; | ||
case 'nested-item': | ||
node.nodes.forEach((child) => findUrls(child, onUrl)); | ||
break; | ||
case 'url': | ||
onUrl(node); | ||
break; | ||
} | ||
} | ||
function fixRelativeUrls(ast, originPath, targetPath) { | ||
const onUrl = (node) => { | ||
if (!node.url || !isAsset(node.url) || !node.url.startsWith('.')) { | ||
return; | ||
} | ||
const url = path_1.default | ||
.join(path_1.default.relative(path_1.default.dirname(targetPath), path_1.default.dirname(originPath)), node.url) | ||
.replace(/\\/gm, '/'); | ||
node.url = assureRelativeUrlPrefix(url); | ||
}; | ||
ast.walkDecls((decl) => processDeclarationUrls(decl, onUrl, true)); | ||
} | ||
exports.fixRelativeUrls = fixRelativeUrls; | ||
@@ -95,0 +79,0 @@ function assureRelativeUrlPrefix(url) { |
@@ -84,3 +84,3 @@ import type * as postcss from 'postcss'; | ||
name: string; | ||
global?: boolean; | ||
global: boolean; | ||
} | ||
@@ -87,0 +87,0 @@ export declare type StylableSymbol = ImportSymbol | VarSymbol | ClassSymbol | ElementSymbol | CSSVarSymbol | KeyframesSymbol; |
@@ -18,3 +18,3 @@ "use strict"; | ||
this.rawAst = ast.clone(); | ||
this.source = stylable_utils_1.getSourcePath(ast, diagnostics); | ||
this.source = (0, stylable_utils_1.getSourcePath)(ast, diagnostics); | ||
this.root = exports.RESERVED_ROOT_NAME; | ||
@@ -21,0 +21,0 @@ this.namespace = ''; |
@@ -63,6 +63,6 @@ "use strict"; | ||
if (local && (local._kind === 'class' || local._kind === 'element')) { | ||
handleLocalClassMixin(mix, transformer, meta, variableOverride, cssVarsMapping, path, rule); | ||
handleLocalClassMixin(reParseMixinNamedArgs(mix, rule, transformer.diagnostics), transformer, meta, variableOverride, cssVarsMapping, path, rule); | ||
} | ||
else { | ||
const resolvedMixin = transformer.resolver.resolve(mix.ref); | ||
const resolvedMixin = transformer.resolver.deepResolve(mix.ref); | ||
if (resolvedMixin) { | ||
@@ -72,6 +72,6 @@ if (resolvedMixin._kind === 'js') { | ||
try { | ||
handleJSMixin(transformer, mix, resolvedMixin.symbol, meta, rule, variableOverride); | ||
handleJSMixin(transformer, reParseMixinArgs(mix, rule, transformer.diagnostics), resolvedMixin.symbol, meta, rule, variableOverride); | ||
} | ||
catch (e) { | ||
transformer.diagnostics.error(rule, exports.mixinWarnings.FAILED_TO_APPLY_MIXIN(e), { word: mix.mixin.type }); | ||
transformer.diagnostics.error(rule, exports.mixinWarnings.FAILED_TO_APPLY_MIXIN(String(e)), { word: mix.mixin.type }); | ||
return; | ||
@@ -87,7 +87,7 @@ } | ||
else { | ||
handleImportedCSSMixin(transformer, mix, rule, meta, path, variableOverride, cssVarsMapping); | ||
handleImportedCSSMixin(transformer, reParseMixinNamedArgs(mix, rule, transformer.diagnostics), rule, meta, path, variableOverride, cssVarsMapping); | ||
} | ||
} | ||
else { | ||
// TODO: error cannot resolve mixin | ||
// TODO: error cannot resolve mixin - this should be a diagnostic covered by unknown symbol | ||
} | ||
@@ -115,5 +115,5 @@ } | ||
const res = mixinFunction(mix.mixin.options.map((v) => v.value)); | ||
const mixinRoot = parser_1.cssObjectToAst(res).root; | ||
const mixinRoot = (0, parser_1.cssObjectToAst)(res).root; | ||
mixinRoot.walkDecls((decl) => { | ||
if (!stylable_utils_1.isValidDeclaration(decl)) { | ||
if (!(0, stylable_utils_1.isValidDeclaration)(decl)) { | ||
decl.value = String(decl); | ||
@@ -124,8 +124,8 @@ } | ||
const mixinPath = mix.ref.import.from; | ||
stylable_assets_1.fixRelativeUrls(mixinRoot, transformer.fileProcessor.resolvePath(mixinPath, path_1.dirname(meta.source)), meta.source); | ||
stylable_utils_1.mergeRules(mixinRoot, rule); | ||
(0, stylable_assets_1.fixRelativeUrls)(mixinRoot, transformer.fileProcessor.resolvePath(mixinPath, (0, path_1.dirname)(meta.source)), meta.source); | ||
(0, stylable_utils_1.mergeRules)(mixinRoot, rule); | ||
} | ||
function createMixinRootFromCSSResolve(transformer, mix, meta, resolvedClass, path, decl, variableOverride, cssVarsMapping) { | ||
const isRootMixin = resolvedClass.symbol.name === resolvedClass.meta.root; | ||
const mixinRoot = stylable_utils_1.createSubsetAst(resolvedClass.meta.ast, (resolvedClass.symbol._kind === 'class' ? '.' : '') + resolvedClass.symbol.name, undefined, isRootMixin); | ||
const mixinRoot = (0, stylable_utils_1.createSubsetAst)(resolvedClass.meta.ast, (resolvedClass.symbol._kind === 'class' ? '.' : '') + resolvedClass.symbol.name, undefined, isRootMixin); | ||
const namedArgs = mix.mixin.options; | ||
@@ -135,3 +135,3 @@ if (mix.mixin.partial) { | ||
} | ||
const resolvedArgs = functions_1.resolveArgumentsValue(namedArgs, transformer, meta, transformer.diagnostics, decl, variableOverride, path, cssVarsMapping); | ||
const resolvedArgs = (0, functions_1.resolveArgumentsValue)(namedArgs, transformer, meta, transformer.diagnostics, decl, variableOverride, path, cssVarsMapping); | ||
const mixinMeta = isRootMixin | ||
@@ -142,3 +142,3 @@ ? resolvedClass.meta | ||
transformer.transformAst(mixinRoot, mixinMeta, undefined, resolvedArgs, path.concat(symbolName + ' from ' + meta.source), true); | ||
stylable_assets_1.fixRelativeUrls(mixinRoot, mixinMeta.source, meta.source); | ||
(0, stylable_assets_1.fixRelativeUrls)(mixinRoot, mixinMeta.source, meta.source); | ||
return mixinRoot; | ||
@@ -167,3 +167,3 @@ } | ||
if (roots.length === 1) { | ||
stylable_utils_1.mergeRules(roots[0], rule); | ||
(0, stylable_utils_1.mergeRules)(roots[0], rule); | ||
} | ||
@@ -173,3 +173,3 @@ else if (roots.length > 1) { | ||
roots.forEach((root) => mixinRoot.prepend(...root.nodes)); | ||
stylable_utils_1.mergeRules(mixinRoot, rule); | ||
(0, stylable_utils_1.mergeRules)(mixinRoot, rule); | ||
} | ||
@@ -192,4 +192,4 @@ else { | ||
const mixinDecl = getMixinDeclaration(rule) || postcss.decl(); | ||
const resolvedArgs = functions_1.resolveArgumentsValue(namedArgs, transformer, meta, transformer.diagnostics, mixinDecl, variableOverride, path, cssVarsMapping); | ||
const mixinRoot = stylable_utils_1.createSubsetAst(meta.ast, '.' + mix.ref.name, undefined, isRootMixin); | ||
const resolvedArgs = (0, functions_1.resolveArgumentsValue)(namedArgs, transformer, meta, transformer.diagnostics, mixinDecl, variableOverride, path, cssVarsMapping); | ||
const mixinRoot = (0, stylable_utils_1.createSubsetAst)(meta.ast, '.' + mix.ref.name, undefined, isRootMixin); | ||
if (isPartial) { | ||
@@ -199,3 +199,3 @@ filterPartialMixinDecl(meta, mixinRoot, overrideKeys); | ||
transformer.transformAst(mixinRoot, isRootMixin ? meta : createInheritedMeta({ meta, symbol: mix.ref, _kind: 'css' }), undefined, resolvedArgs, path.concat(mix.mixin.type + ' from ' + meta.source), true); | ||
stylable_utils_1.mergeRules(mixinRoot, rule); | ||
(0, stylable_utils_1.mergeRules)(mixinRoot, rule); | ||
} | ||
@@ -256,2 +256,35 @@ function createInheritedMeta(resolvedClass) { | ||
} | ||
/** this is a workaround for parsing the mixin args too early */ | ||
function reParseMixinNamedArgs(mix, rule, diagnostics) { | ||
var _a; | ||
const options = ((_a = mix.mixin.valueNode) === null || _a === void 0 ? void 0 : _a.type) === 'function' | ||
? stylable_value_parsers_1.strategies.named(mix.mixin.valueNode, (message, options) => { | ||
diagnostics.warn(mix.mixin.originDecl || rule, message, options); | ||
}) | ||
: mix.mixin.options || {}; | ||
return { | ||
...mix, | ||
mixin: { | ||
...mix.mixin, | ||
options, | ||
}, | ||
}; | ||
} | ||
function reParseMixinArgs(mix, rule, diagnostics) { | ||
var _a; | ||
const options = ((_a = mix.mixin.valueNode) === null || _a === void 0 ? void 0 : _a.type) === 'function' | ||
? stylable_value_parsers_1.strategies.args(mix.mixin.valueNode, (message, options) => { | ||
diagnostics.warn(mix.mixin.originDecl || rule, message, options); | ||
}) | ||
: Array.isArray(mix.mixin.options) | ||
? mix.mixin.options | ||
: []; | ||
return { | ||
...mix, | ||
mixin: { | ||
...mix.mixin, | ||
options, | ||
}, | ||
}; | ||
} | ||
//# sourceMappingURL=stylable-mixins.js.map |
@@ -46,2 +46,4 @@ import * as postcss from 'postcss'; | ||
INVALID_NESTING(child: string, parent: string): string; | ||
DEPRECATED_ST_GLOBAL_CUSTOM_PROPERTY(): string; | ||
DEPRECATED_ST_FUNCTION_NAME: (name: string, alternativeName: string) => string; | ||
}; | ||
@@ -59,2 +61,3 @@ export declare class StylableProcessor { | ||
private collectUrls; | ||
private handleStFunctions; | ||
private handleNamespaceReference; | ||
@@ -71,3 +74,3 @@ protected handleRule(rule: SRule, inStScope?: boolean): void; | ||
protected addCSSVarDefinition(node: postcss.Declaration | postcss.AtRule): void; | ||
protected addCSSVar(varName: string, node: postcss.Declaration | postcss.AtRule): void; | ||
protected addCSSVar(varName: string, node: postcss.Declaration | postcss.AtRule, global: boolean): void; | ||
protected handleDirectives(rule: SRule, decl: postcss.Declaration): void; | ||
@@ -77,6 +80,6 @@ protected setClassGlobalMapping(decl: postcss.Declaration, rule: postcss.Rule): void; | ||
protected handleStImport(atRule: postcss.AtRule): Imported; | ||
protected handleImport(rule: postcss.Rule): Imported; | ||
private handleScope; | ||
private checkForInvalidAsUsage; | ||
} | ||
export declare function parsePseudoImport(rule: postcss.Rule, context: string, diagnostics: Diagnostics): Imported; | ||
export declare function validateScopingSelector(atRule: postcss.AtRule, { selector: scopingSelector }: SRule, diagnostics: Diagnostics): void; | ||
@@ -83,0 +86,0 @@ export declare function createEmptyMeta(root: postcss.Root, diagnostics: Diagnostics): StylableMeta; |
@@ -28,3 +28,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.process = exports.processNamespace = exports.createEmptyMeta = exports.validateScopingSelector = exports.StylableProcessor = exports.processorWarnings = void 0; | ||
exports.process = exports.processNamespace = exports.createEmptyMeta = exports.validateScopingSelector = exports.parsePseudoImport = exports.StylableProcessor = exports.processorWarnings = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
@@ -34,2 +34,3 @@ const postcss = __importStar(require("postcss")); | ||
const toky_1 = require("toky"); | ||
const custom_values_1 = require("./custom-values"); | ||
const diagnostics_1 = require("./diagnostics"); | ||
@@ -39,3 +40,2 @@ const murmurhash_1 = require("./murmurhash"); | ||
const selector_utils_1 = require("./selector-utils"); | ||
const stylable_assets_1 = require("./stylable-assets"); | ||
const stylable_meta_1 = require("./stylable-meta"); | ||
@@ -45,2 +45,3 @@ const stylable_utils_1 = require("./stylable-utils"); | ||
const utils_1 = require("./utils"); | ||
const validate_at_property_1 = require("./validate-at-property"); | ||
__exportStar(require("./stylable-meta"), exports); /* TEMP EXPORT */ | ||
@@ -169,2 +170,8 @@ const parseNamed = stylable_value_parsers_1.SBTypesParsers[stylable_value_parsers_1.valueMapping.named]; | ||
}, | ||
DEPRECATED_ST_GLOBAL_CUSTOM_PROPERTY() { | ||
return `"st-global-custom-property" is deprecated and will be removed in the next version. Use "@property" with ${stylable_value_parsers_1.paramMapping.global}`; | ||
}, | ||
DEPRECATED_ST_FUNCTION_NAME: (name, alternativeName) => { | ||
return `"${name}" is deprecated, use "${alternativeName}"`; | ||
}, | ||
}; | ||
@@ -183,3 +190,3 @@ class StylableProcessor { | ||
if (node.type === 'rule' && node.selector === stylable_value_parsers_1.rootValueMapping.import) { | ||
const imported = this.handleImport(node); | ||
const imported = parsePseudoImport(node, this.dirContext, this.diagnostics); | ||
this.meta.imports.push(imported); | ||
@@ -190,5 +197,5 @@ this.addImportSymbols(imported); | ||
root.walkRules((rule) => { | ||
if (!selector_utils_1.isChildOfAtRule(rule, 'keyframes')) { | ||
if (!(0, selector_utils_1.isChildOfAtRule)(rule, 'keyframes')) { | ||
this.handleCustomSelectors(rule); | ||
this.handleRule(rule, selector_utils_1.isChildOfAtRule(rule, stylable_value_parsers_1.rootValueMapping.stScope)); | ||
this.handleRule(rule, (0, selector_utils_1.isChildOfAtRule)(rule, stylable_value_parsers_1.rootValueMapping.stScope)); | ||
} | ||
@@ -204,3 +211,3 @@ const parent = rule.parent; | ||
} | ||
else if (stylable_utils_1.isCSSVarProp(decl.prop)) { | ||
else if ((0, stylable_utils_1.isCSSVarProp)(decl.prop)) { | ||
this.addCSSVarDefinition(decl); | ||
@@ -228,3 +235,3 @@ } | ||
handleCustomSelectors(rule) { | ||
stylable_utils_1.expandCustomSelectors(rule, this.meta.customSelectors, this.meta.diagnostics); | ||
(0, stylable_utils_1.expandCustomSelectors)(rule, this.meta.customSelectors, this.meta.diagnostics); | ||
} | ||
@@ -254,3 +261,3 @@ handleAtRules(root) { | ||
case 'keyframes': | ||
if (!selector_utils_1.isChildOfAtRule(atRule, stylable_value_parsers_1.rootValueMapping.stScope)) { | ||
if (!(0, selector_utils_1.isChildOfAtRule)(atRule, stylable_value_parsers_1.rootValueMapping.stScope)) { | ||
this.meta.keyframes.push(atRule); | ||
@@ -260,3 +267,3 @@ let { params: name } = atRule; | ||
let global; | ||
const globalName = utils_1.globalValue(name); | ||
const globalName = (0, utils_1.globalValue)(name); | ||
if (globalName !== undefined) { | ||
@@ -307,3 +314,3 @@ name = globalName; | ||
break; | ||
case 'st-import': | ||
case 'st-import': { | ||
if (((_a = atRule.parent) === null || _a === void 0 ? void 0 : _a.type) !== 'root') { | ||
@@ -319,7 +326,10 @@ this.diagnostics.warn(atRule, exports.processorWarnings.NO_ST_IMPORT_IN_NESTED_SCOPE()); | ||
break; | ||
case 'property': | ||
this.checkRedeclareSymbol(atRule.params, atRule); | ||
} | ||
case 'property': { | ||
this.addCSSVarDefinition(atRule); | ||
(0, validate_at_property_1.validateAtProperty)(atRule, this.diagnostics); | ||
break; | ||
} | ||
case 'st-global-custom-property': { | ||
this.diagnostics.info(atRule, exports.processorWarnings.DEPRECATED_ST_GLOBAL_CUSTOM_PROPERTY()); | ||
const cssVarsByComma = atRule.params.split(','); | ||
@@ -331,3 +341,5 @@ const cssVarsBySpacing = atRule.params | ||
if (cssVarsBySpacing.length > cssVarsByComma.length) { | ||
this.diagnostics.warn(atRule, exports.processorWarnings.GLOBAL_CSS_VAR_MISSING_COMMA(atRule.params), { word: atRule.params }); | ||
this.diagnostics.warn(atRule, exports.processorWarnings.GLOBAL_CSS_VAR_MISSING_COMMA(atRule.params), { | ||
word: atRule.params, | ||
}); | ||
break; | ||
@@ -337,11 +349,10 @@ } | ||
const cssVar = entry.trim(); | ||
if (stylable_utils_1.isCSSVarProp(cssVar)) { | ||
if (!this.meta.cssVars[cssVar]) { | ||
this.meta.cssVars[cssVar] = { | ||
_kind: 'cssVar', | ||
name: cssVar, | ||
global: true, | ||
}; | ||
this.meta.mappedSymbols[cssVar] = this.meta.cssVars[cssVar]; | ||
} | ||
if ((0, stylable_utils_1.isCSSVarProp)(cssVar)) { | ||
const property = { | ||
_kind: 'cssVar', | ||
name: cssVar, | ||
global: true, | ||
}; | ||
this.meta.cssVars[cssVar] = property; | ||
this.meta.mappedSymbols[cssVar] = property; | ||
} | ||
@@ -358,8 +369,22 @@ else { | ||
toRemove.forEach((node) => node.remove()); | ||
namespace = namespace || utils_1.filename2varname(path_1.default.basename(this.meta.source)) || 's'; | ||
namespace = namespace || (0, utils_1.filename2varname)(path_1.default.basename(this.meta.source)) || 's'; | ||
this.meta.namespace = this.handleNamespaceReference(namespace); | ||
} | ||
collectUrls(decl) { | ||
stylable_assets_1.processDeclarationUrls(decl, (node) => this.meta.urls.push(node.url), false); | ||
(0, stylable_utils_1.processDeclarationFunctions)(decl, (node) => { | ||
if (node.type === 'url') { | ||
this.meta.urls.push(node.url); | ||
} | ||
}, false); | ||
} | ||
handleStFunctions(decl) { | ||
(0, stylable_utils_1.processDeclarationFunctions)(decl, (node) => { | ||
if (node.type === 'nested-item' && custom_values_1.deprecatedStFunctions[node.name]) { | ||
const { alternativeName } = custom_values_1.deprecatedStFunctions[node.name]; | ||
this.diagnostics.info(decl, exports.processorWarnings.DEPRECATED_ST_FUNCTION_NAME(node.name, alternativeName), { | ||
word: node.name, | ||
}); | ||
} | ||
}, false); | ||
} | ||
handleNamespaceReference(namespace) { | ||
@@ -374,3 +399,3 @@ let pathToSource; | ||
else { | ||
pathToSource = utils_1.stripQuotation(node.text.slice(i + 1)); | ||
pathToSource = (0, utils_1.stripQuotation)(node.text.slice(i + 1)); | ||
} | ||
@@ -385,7 +410,7 @@ break; | ||
handleRule(rule, inStScope = false) { | ||
rule.selectorAst = selector_utils_1.parseSelector(rule.selector); | ||
const checker = selector_utils_1.createSimpleSelectorChecker(); | ||
rule.selectorAst = (0, selector_utils_1.parseSelector)(rule.selector); | ||
const checker = (0, selector_utils_1.createSimpleSelectorChecker)(); | ||
let locallyScoped = false; | ||
selector_utils_1.traverseNode(rule.selectorAst, (node, index, nodes, parents) => { | ||
if (node.type === 'selector' && !selector_utils_1.isNested(parents)) { | ||
(0, selector_utils_1.traverseNode)(rule.selectorAst, (node, index, nodes, parents) => { | ||
if (node.type === 'selector' && !(0, selector_utils_1.isNested)(parents)) { | ||
locallyScoped = false; | ||
@@ -400,3 +425,3 @@ } | ||
if (rule.selector === stylable_value_parsers_1.rootValueMapping.import) { | ||
if (selector_utils_1.isChildOfAtRule(rule, stylable_value_parsers_1.rootValueMapping.stScope)) { | ||
if ((0, selector_utils_1.isChildOfAtRule)(rule, stylable_value_parsers_1.rootValueMapping.stScope)) { | ||
this.diagnostics.warn(rule, exports.processorWarnings.NO_IMPORT_IN_ST_SCOPE()); | ||
@@ -415,3 +440,3 @@ rule.remove(); | ||
if (rule.selector === stylable_value_parsers_1.rootValueMapping.vars) { | ||
if (selector_utils_1.isChildOfAtRule(rule, stylable_value_parsers_1.rootValueMapping.stScope)) { | ||
if ((0, selector_utils_1.isChildOfAtRule)(rule, stylable_value_parsers_1.rootValueMapping.stScope)) { | ||
this.diagnostics.warn(rule, exports.processorWarnings.NO_VARS_DEF_IN_ST_SCOPE()); | ||
@@ -472,3 +497,3 @@ rule.remove(); | ||
} | ||
if (!selector_utils_1.isRootValid(rule.selectorAst, 'root')) { | ||
if (!(0, selector_utils_1.isRootValid)(rule.selectorAst, 'root')) { | ||
this.diagnostics.warn(rule, exports.processorWarnings.ROOT_AFTER_SPACING()); | ||
@@ -515,3 +540,3 @@ } | ||
addElementSymbolOnce(name, rule) { | ||
if (selector_utils_1.isCompRoot(name) && !this.meta.elements[name]) { | ||
if ((0, selector_utils_1.isCompRoot)(name) && !this.meta.elements[name]) { | ||
let alias = this.meta.mappedSymbols[name]; | ||
@@ -594,2 +619,3 @@ if (alias && alias._kind !== 'import') { | ||
this.collectUrls(decl); | ||
this.handleStFunctions(decl); | ||
this.checkRedeclareSymbol(decl.prop, decl); | ||
@@ -618,7 +644,7 @@ let type = null; | ||
handleCSSVarUse(decl) { | ||
const parsed = postcss_value_parser_1.default(decl.value); | ||
const parsed = (0, postcss_value_parser_1.default)(decl.value); | ||
parsed.walk((node) => { | ||
if (node.type === 'function' && node.value === 'var' && node.nodes) { | ||
const varName = node.nodes[0]; | ||
if (!stylable_value_parsers_1.validateAllowedNodesUntil(node, 1)) { | ||
if (!(0, stylable_value_parsers_1.validateAllowedNodesUntil)(node, 1)) { | ||
const args = postcss_value_parser_1.default.stringify(node.nodes); | ||
@@ -629,3 +655,3 @@ this.diagnostics.warn(decl, exports.processorWarnings.ILLEGAL_CSS_VAR_ARGS(args), { | ||
} | ||
this.addCSSVar(postcss_value_parser_1.default.stringify(varName).trim(), decl); | ||
this.addCSSVar(postcss_value_parser_1.default.stringify(varName).trim(), decl, false); | ||
} | ||
@@ -635,7 +661,16 @@ }); | ||
addCSSVarDefinition(node) { | ||
const varName = node.type === 'atrule' ? node.params : node.prop; | ||
this.addCSSVar(varName.trim(), node); | ||
let varName = node.type === 'atrule' ? node.params.trim() : node.prop.trim(); | ||
let isGlobal = false; | ||
const globalVarName = (0, utils_1.globalValue)(varName); | ||
if (globalVarName !== undefined) { | ||
varName = globalVarName.trim(); | ||
isGlobal = true; | ||
} | ||
if (node.type === 'atrule') { | ||
this.checkRedeclareSymbol(varName, node); | ||
} | ||
this.addCSSVar(varName, node, isGlobal); | ||
} | ||
addCSSVar(varName, node) { | ||
if (stylable_utils_1.isCSSVarProp(varName)) { | ||
addCSSVar(varName, node, global) { | ||
if ((0, stylable_utils_1.isCSSVarProp)(varName)) { | ||
if (!this.meta.cssVars[varName]) { | ||
@@ -645,2 +680,3 @@ const cssVarSymbol = { | ||
name: varName, | ||
global, | ||
}; | ||
@@ -683,3 +719,3 @@ this.meta.cssVars[varName] = cssVarSymbol; | ||
decl.value === this.meta.root) { | ||
this.extendTypedRule(decl, rule.selector, stylable_value_parsers_1.valueMapping.extends, stylable_utils_1.getAlias(extendsRefSymbol) || extendsRefSymbol); | ||
this.extendTypedRule(decl, rule.selector, stylable_value_parsers_1.valueMapping.extends, (0, stylable_utils_1.getAlias)(extendsRefSymbol) || extendsRefSymbol); | ||
} | ||
@@ -696,11 +732,12 @@ else { | ||
const mixins = []; | ||
/** | ||
* This functionality is broken we don't know what strategy to choose here. | ||
* Should be fixed when we refactor to the new flow | ||
*/ | ||
stylable_value_parsers_1.SBTypesParsers[decl.prop](decl, (type) => { | ||
const mixinRefSymbol = this.meta.mappedSymbols[type]; | ||
if (mixinRefSymbol && | ||
mixinRefSymbol._kind === 'import' && | ||
!mixinRefSymbol.import.from.match(/.css$/)) { | ||
return 'args'; | ||
} | ||
return 'named'; | ||
}, this.diagnostics).forEach((mixin) => { | ||
const symbol = this.meta.mappedSymbols[type]; | ||
return (symbol === null || symbol === void 0 ? void 0 : symbol._kind) === 'import' && !symbol.import.from.match(/.css$/) | ||
? 'args' | ||
: 'named'; | ||
}, this.diagnostics, false).forEach((mixin) => { | ||
const mixinRefSymbol = this.meta.mappedSymbols[mixin.type]; | ||
@@ -790,3 +827,3 @@ if (mixinRefSymbol && | ||
}; | ||
const imports = toky_1.tokenizeImports(`import ${atRule.params}`, '[', ']', true)[0]; | ||
const imports = (0, toky_1.tokenizeImports)(`import ${atRule.params}`, '[', ']', true)[0]; | ||
if (imports && imports.star) { | ||
@@ -819,50 +856,2 @@ this.diagnostics.error(atRule, exports.processorWarnings.ST_IMPORT_STAR()); | ||
} | ||
handleImport(rule) { | ||
let fromExists = false; | ||
const importObj = { | ||
defaultExport: '', | ||
from: '', | ||
request: '', | ||
named: {}, | ||
keyframes: {}, | ||
rule, | ||
context: this.dirContext, | ||
}; | ||
rule.walkDecls((decl) => { | ||
switch (decl.prop) { | ||
case stylable_value_parsers_1.valueMapping.from: { | ||
const importPath = utils_1.stripQuotation(decl.value); | ||
if (!importPath.trim()) { | ||
this.diagnostics.error(decl, exports.processorWarnings.EMPTY_IMPORT_FROM()); | ||
} | ||
if (fromExists) { | ||
this.diagnostics.warn(rule, exports.processorWarnings.MULTIPLE_FROM_IN_IMPORT()); | ||
} | ||
setImportObjectFrom(importPath, this.dirContext, importObj); | ||
fromExists = true; | ||
break; | ||
} | ||
case stylable_value_parsers_1.valueMapping.default: | ||
importObj.defaultExport = decl.value; | ||
if (!selector_utils_1.isCompRoot(importObj.defaultExport) && importObj.from.match(/\.css$/)) { | ||
this.diagnostics.warn(decl, exports.processorWarnings.DEFAULT_IMPORT_IS_LOWER_CASE(), { word: importObj.defaultExport }); | ||
} | ||
break; | ||
case stylable_value_parsers_1.valueMapping.named: | ||
{ | ||
const { keyframesMap, namedMap } = parseNamed(decl.value, decl, this.diagnostics); | ||
importObj.named = namedMap; | ||
importObj.keyframes = keyframesMap; | ||
} | ||
break; | ||
default: | ||
this.diagnostics.warn(decl, exports.processorWarnings.ILLEGAL_PROP_IN_IMPORT(decl.prop), { word: decl.prop }); | ||
break; | ||
} | ||
}); | ||
if (!importObj.from) { | ||
this.diagnostics.error(rule, exports.processorWarnings.FROM_PROP_MISSING_IN_IMPORT()); | ||
} | ||
return importObj; | ||
} | ||
handleScope(atRule) { | ||
@@ -875,3 +864,3 @@ const scopingRule = postcss.rule({ selector: atRule.params }); | ||
const scopedRule = rule.clone({ | ||
selector: stylable_utils_1.scopeSelector(scopingRule.selector, rule.selector, false).selector, | ||
selector: (0, stylable_utils_1.scopeSelector)(scopingRule.selector, rule.selector, false).selector, | ||
}); | ||
@@ -886,3 +875,3 @@ scopedRule.stScopeSelector = atRule.params; | ||
for (const [local, imported] of Object.entries(importDef.named)) { | ||
if (stylable_utils_1.isCSSVarProp(imported) && !stylable_utils_1.isCSSVarProp(local)) { | ||
if ((0, stylable_utils_1.isCSSVarProp)(imported) && !(0, stylable_utils_1.isCSSVarProp)(local)) { | ||
this.diagnostics.warn(importDef.rule, exports.processorWarnings.INVALID_CUSTOM_PROPERTY_AS_VALUE(imported, local)); | ||
@@ -907,2 +896,55 @@ } | ||
} | ||
function parsePseudoImport(rule, context, diagnostics) { | ||
let fromExists = false; | ||
const importObj = { | ||
defaultExport: '', | ||
from: '', | ||
request: '', | ||
named: {}, | ||
keyframes: {}, | ||
rule, | ||
context, | ||
}; | ||
rule.walkDecls((decl) => { | ||
switch (decl.prop) { | ||
case stylable_value_parsers_1.valueMapping.from: { | ||
const importPath = (0, utils_1.stripQuotation)(decl.value); | ||
if (!importPath.trim()) { | ||
diagnostics.error(decl, exports.processorWarnings.EMPTY_IMPORT_FROM()); | ||
} | ||
if (fromExists) { | ||
diagnostics.warn(rule, exports.processorWarnings.MULTIPLE_FROM_IN_IMPORT()); | ||
} | ||
setImportObjectFrom(importPath, context, importObj); | ||
fromExists = true; | ||
break; | ||
} | ||
case stylable_value_parsers_1.valueMapping.default: | ||
importObj.defaultExport = decl.value; | ||
if (!(0, selector_utils_1.isCompRoot)(importObj.defaultExport) && importObj.from.match(/\.css$/)) { | ||
diagnostics.warn(decl, exports.processorWarnings.DEFAULT_IMPORT_IS_LOWER_CASE(), { | ||
word: importObj.defaultExport, | ||
}); | ||
} | ||
break; | ||
case stylable_value_parsers_1.valueMapping.named: | ||
{ | ||
const { keyframesMap, namedMap } = parseNamed(decl.value, decl, diagnostics); | ||
importObj.named = namedMap; | ||
importObj.keyframes = keyframesMap; | ||
} | ||
break; | ||
default: | ||
diagnostics.warn(decl, exports.processorWarnings.ILLEGAL_PROP_IN_IMPORT(decl.prop), { | ||
word: decl.prop, | ||
}); | ||
break; | ||
} | ||
}); | ||
if (!importObj.from) { | ||
diagnostics.error(rule, exports.processorWarnings.FROM_PROP_MISSING_IN_IMPORT()); | ||
} | ||
return importObj; | ||
} | ||
exports.parsePseudoImport = parsePseudoImport; | ||
function validateScopingSelector(atRule, { selector: scopingSelector }, diagnostics) { | ||
@@ -915,3 +957,3 @@ if (!scopingSelector) { | ||
function createEmptyMeta(root, diagnostics) { | ||
utils_1.deprecated('createEmptyMeta is deprecated and will be removed in the next version. Use "new StylableMeta()"'); | ||
(0, utils_1.deprecated)('createEmptyMeta is deprecated and will be removed in the next version. Use "new StylableMeta()"'); | ||
return new stylable_meta_1.StylableMeta(root, diagnostics); | ||
@@ -921,3 +963,3 @@ } | ||
function processNamespace(namespace, source) { | ||
return namespace + murmurhash_1.murmurhash3_32_gc(source); // .toString(36); | ||
return namespace + (0, murmurhash_1.murmurhash3_32_gc)(source); // .toString(36); | ||
} | ||
@@ -924,0 +966,0 @@ exports.processNamespace = processNamespace; |
@@ -91,3 +91,3 @@ "use strict"; | ||
ast.walkRules((rule) => { | ||
if (selector_utils_1.isChildOfAtRule(rule, 'keyframes')) { | ||
if ((0, selector_utils_1.isChildOfAtRule)(rule, 'keyframes')) { | ||
return; | ||
@@ -98,14 +98,19 @@ } | ||
ast.walkAtRules((atRule) => { | ||
var _a; | ||
var _a, _b; | ||
const { name } = atRule; | ||
if (name === 'media') { | ||
atRule.params = functions_1.evalDeclarationValue(this.resolver, atRule.params, meta, atRule, variableOverride, this.replaceValueHook, this.diagnostics, path.slice(), undefined, undefined); | ||
atRule.params = (0, functions_1.evalDeclarationValue)(this.resolver, atRule.params, meta, atRule, variableOverride, this.replaceValueHook, this.diagnostics, path.slice(), undefined, undefined); | ||
} | ||
else if (name === 'property') { | ||
atRule.params = (_a = cssVarsMapping[atRule.params]) !== null && _a !== void 0 ? _a : atRule.params; | ||
if ((_a = atRule.nodes) === null || _a === void 0 ? void 0 : _a.length) { | ||
atRule.params = (_b = cssVarsMapping[atRule.params]) !== null && _b !== void 0 ? _b : atRule.params; | ||
} | ||
else { | ||
atRule.remove(); | ||
} | ||
} | ||
}); | ||
ast.walkDecls((decl) => { | ||
stylable_utils_1.getDeclStylable(decl).sourceValue = decl.value; | ||
if (stylable_utils_1.isCSSVarProp(decl.prop)) { | ||
(0, stylable_utils_1.getDeclStylable)(decl).sourceValue = decl.value; | ||
if ((0, stylable_utils_1.isCSSVarProp)(decl.prop)) { | ||
decl.prop = this.getScopedCSSVar(decl, meta, cssVarsMapping); | ||
@@ -118,6 +123,6 @@ } | ||
case stylable_value_parsers_1.valueMapping.states: | ||
pseudo_states_1.validateStateDefinition(decl, meta, this.resolver, this.diagnostics); | ||
(0, pseudo_states_1.validateStateDefinition)(decl, meta, this.resolver, this.diagnostics); | ||
break; | ||
default: | ||
decl.value = functions_1.evalDeclarationValue(this.resolver, decl.value, meta, decl, variableOverride, this.replaceValueHook, this.diagnostics, path.slice(), cssVarsMapping, undefined); | ||
decl.value = (0, functions_1.evalDeclarationValue)(this.resolver, decl.value, meta, decl, variableOverride, this.replaceValueHook, this.diagnostics, path.slice(), cssVarsMapping, undefined); | ||
} | ||
@@ -128,3 +133,3 @@ }); | ||
} | ||
ast.walkRules((rule) => stylable_mixins_1.appendMixins(this, rule, meta, variableOverride || {}, cssVarsMapping, path)); | ||
ast.walkRules((rule) => (0, stylable_mixins_1.appendMixins)(this, rule, meta, variableOverride || {}, cssVarsMapping, path)); | ||
if (metaExports) { | ||
@@ -139,4 +144,4 @@ Object.assign(metaExports.classes, this.exportClasses(meta)); | ||
for (const varSymbol of meta.vars) { | ||
const { outputValue, topLevelType } = functions_1.processDeclarationValue(this.resolver, varSymbol.text, meta, varSymbol.node, variableOverride); | ||
stVarsExport[varSymbol.name] = topLevelType ? custom_values_1.unbox(topLevelType) : outputValue; | ||
const { outputValue, topLevelType } = (0, functions_1.processDeclarationValue)(this.resolver, varSymbol.text, meta, varSymbol.node, variableOverride); | ||
stVarsExport[varSymbol.name] = topLevelType ? (0, custom_values_1.unbox)(topLevelType) : outputValue; | ||
} | ||
@@ -155,3 +160,3 @@ } | ||
const name = atRule.params; | ||
const globalName = utils_1.globalValue(name); | ||
const globalName = (0, utils_1.globalValue)(name); | ||
if (globalName === undefined) { | ||
@@ -174,3 +179,3 @@ atRule.params = this.scope(name, meta.namespace); | ||
ast.walkDecls(stylable_value_parsers_1.animationPropRegExp, (decl) => { | ||
const parsed = postcss_value_parser_1.default(decl.value); | ||
const parsed = (0, postcss_value_parser_1.default)(decl.value); | ||
parsed.nodes.forEach((node) => { | ||
@@ -191,3 +196,3 @@ const scoped = keyframesExports[node.value]; | ||
for (const symbolName of Object.keys(imported.named)) { | ||
if (stylable_utils_1.isCSSVarProp(symbolName)) { | ||
if ((0, stylable_utils_1.isCSSVarProp)(symbolName)) { | ||
const importedVar = this.resolver.deepResolve(meta.mappedSymbols[symbolName]); | ||
@@ -200,3 +205,3 @@ if (importedVar && | ||
? importedVar.symbol.name | ||
: stylable_utils_1.generateScopedCSSVar(importedVar.meta.namespace, importedVar.symbol.name.slice(2)); | ||
: (0, stylable_utils_1.generateScopedCSSVar)(importedVar.meta.namespace, importedVar.symbol.name.slice(2)); | ||
} | ||
@@ -212,3 +217,3 @@ } | ||
? localVarName | ||
: stylable_utils_1.generateScopedCSSVar(meta.namespace, localVarName.slice(2)); | ||
: (0, stylable_utils_1.generateScopedCSSVar)(meta.namespace, localVarName.slice(2)); | ||
} | ||
@@ -230,3 +235,3 @@ } | ||
for (const ast of selectorAst) { | ||
selector_utils_1.traverseNode(ast, (inner) => { | ||
(0, selector_utils_1.traverseNode)(ast, (inner) => { | ||
if (inner.type === 'class') { | ||
@@ -240,4 +245,4 @@ meta.globals[inner.name] = true; | ||
ast.walkRules((r) => { | ||
const selectorAst = selector_utils_1.parseSelector(r.selector); | ||
selector_utils_1.traverseNode(selectorAst, (node) => { | ||
const selectorAst = (0, selector_utils_1.parseSelector)(r.selector); | ||
(0, selector_utils_1.traverseNode)(selectorAst, (node) => { | ||
if (node.type === 'nested-pseudo-class' && node.name === 'global') { | ||
@@ -251,3 +256,3 @@ this.addGlobalsToMeta([node], meta); | ||
// this.addGlobalsToMeta([selectorAst], meta); | ||
r.selector = selector_utils_1.stringifySelector(selectorAst); | ||
r.selector = (0, selector_utils_1.stringifySelector)(selectorAst); | ||
}); | ||
@@ -290,7 +295,7 @@ } | ||
scopeSelector(originMeta, selector, rule) { | ||
const context = new ScopeContext(originMeta, selector_utils_1.parseSelector(selector), rule || postcss.rule({ selector })); | ||
const context = new ScopeContext(originMeta, (0, selector_utils_1.parseSelector)(selector), rule || postcss.rule({ selector })); | ||
const targetSelectorAst = this.scopeSelectorAst(context); | ||
return { | ||
targetSelectorAst, | ||
selector: selector_utils_1.stringifySelector(targetSelectorAst), | ||
selector: (0, selector_utils_1.stringifySelector)(targetSelectorAst), | ||
elements: context.elements, | ||
@@ -302,3 +307,3 @@ }; | ||
// split selectors to chunks: .a.b .c:hover, a .c:hover -> [[[.a.b], [.c:hover]], [[.a], [.c:hover]]] | ||
const selectorListChunks = selector_utils_1.separateChunks2(selectorAst); | ||
const selectorListChunks = (0, selector_utils_1.separateChunks2)(selectorAst); | ||
// resolve meta classes and elements | ||
@@ -335,3 +340,3 @@ context.metaParts = this.resolveMetaParts(originMeta); | ||
} | ||
const outputAst = selector_utils_1.mergeChunks(selectorListChunks); | ||
const outputAst = (0, selector_utils_1.mergeChunks)(selectorListChunks); | ||
context.additionalSelectors.forEach((addSelector) => outputAst.nodes.push(addSelector())); | ||
@@ -349,3 +354,3 @@ return outputAst; | ||
context.setCurrentAnchor({ name, type: 'class', resolved }); | ||
const { symbol, meta } = selector_utils_1.getOriginDefinition(resolved); | ||
const { symbol, meta } = (0, selector_utils_1.getOriginDefinition)(resolved); | ||
this.scopeClassNode(symbol, meta, node, originMeta); | ||
@@ -361,3 +366,3 @@ } | ||
if (resolved && resolved.length > 1) { | ||
const { symbol, meta } = selector_utils_1.getOriginDefinition(resolved); | ||
const { symbol, meta } = (0, selector_utils_1.getOriginDefinition)(resolved); | ||
this.scopeClassNode(symbol, meta, node, originMeta); | ||
@@ -392,3 +397,3 @@ } | ||
}); | ||
const resolvedPart = selector_utils_1.getOriginDefinition(resolved); | ||
const resolvedPart = (0, selector_utils_1.getOriginDefinition)(resolved); | ||
node.before = resolvedPart.symbol[stylable_value_parsers_1.valueMapping.root] ? '' : ' '; | ||
@@ -406,3 +411,3 @@ this.scopeClassNode(resolvedPart.symbol, resolvedPart.meta, node, originMeta); | ||
if (!native_reserved_lists_1.nativePseudoElements.includes(name) && | ||
!is_vendor_prefixed_1.default(name) && | ||
!(0, is_vendor_prefixed_1.default)(name) && | ||
!this.isDuplicateStScopeDiagnostic(context)) { | ||
@@ -421,3 +426,3 @@ this.diagnostics.warn(context.rule, exports.transformerWarnings.UNKNOWN_PSEUDO_ELEMENT(name), { | ||
found = true; | ||
pseudo_states_1.setStateToNode(states, meta, name, node, meta.namespace, this.resolver, this.diagnostics, context.rule); | ||
(0, pseudo_states_1.setStateToNode)(states, meta, name, node, meta.namespace, this.resolver, this.diagnostics, context.rule); | ||
break; | ||
@@ -428,3 +433,3 @@ } | ||
!native_reserved_lists_1.nativePseudoClasses.includes(name) && | ||
!is_vendor_prefixed_1.default(name) && | ||
!(0, is_vendor_prefixed_1.default)(name) && | ||
!this.isDuplicateStScopeDiagnostic(context)) { | ||
@@ -469,3 +474,3 @@ this.diagnostics.warn(context.rule, pseudo_states_1.stateErrors.UNKNOWN_STATE_USAGE(name), { | ||
if (transformedScope && context.chunks && context.chunk) { | ||
const currentChunkSelector = selector_utils_1.stringifySelector({ | ||
const currentChunkSelector = (0, selector_utils_1.stringifySelector)({ | ||
type: 'selector', | ||
@@ -480,3 +485,3 @@ nodes: context.chunk.nodes, | ||
for (const chunk of stScopeSelectorChunks) { | ||
const scopeChunkSelector = selector_utils_1.stringifySelector({ | ||
const scopeChunkSelector = (0, selector_utils_1.stringifySelector)({ | ||
type: 'selector', | ||
@@ -497,6 +502,6 @@ nodes: chunk.nodes, | ||
handleCustomSelector(customSelector, meta, context, name, node) { | ||
const selectorListChunks = selector_utils_1.separateChunks2(selector_utils_1.parseSelector(customSelector)); | ||
const selectorListChunks = (0, selector_utils_1.separateChunks2)((0, selector_utils_1.parseSelector)(customSelector)); | ||
const hasSingleSelector = selectorListChunks.length === 1; | ||
removeFirstRootInEachSelectorChunk(selectorListChunks, meta); | ||
const internalContext = new ScopeContext(meta, selector_utils_1.mergeChunks(selectorListChunks), context.rule); | ||
const internalContext = new ScopeContext(meta, (0, selector_utils_1.mergeChunks)(selectorListChunks), context.rule); | ||
const customAstSelectors = this.scopeSelectorAst(internalContext).nodes; | ||
@@ -545,3 +550,3 @@ customAstSelectors.forEach(trimLeftSelectorAst); | ||
resolvedClasses[className] = this.resolver.resolveExtends(meta, className, false, undefined, (res, extend) => { | ||
const decl = stylable_utils_1.findRule(meta.ast, '.' + className); | ||
const decl = (0, stylable_utils_1.findRule)(meta.ast, '.' + className); | ||
if (decl) { | ||
@@ -586,3 +591,3 @@ if (res && res._kind === 'js') { | ||
const b = resolved[resolved.length - 1]; | ||
rule.after(selector_utils_1.createWarningRule(b.symbol.name, this.scope(b.symbol.name, b.meta.namespace), path_1.basename(b.meta.source), a.symbol.name, this.scope(a.symbol.name, a.meta.namespace), path_1.basename(a.meta.source), true)); | ||
rule.after((0, selector_utils_1.createWarningRule)(b.symbol.name, this.scope(b.symbol.name, b.meta.namespace), (0, path_1.basename)(b.meta.source), a.symbol.name, this.scope(a.symbol.name, a.meta.namespace), (0, path_1.basename)(a.meta.source), true)); | ||
}); | ||
@@ -604,4 +609,4 @@ } | ||
const rule = postcss.rule({ selector: scope.params }); | ||
const context = new ScopeContext(meta, selector_utils_1.parseSelector(rule.selector), rule); | ||
transformedScopes[rule.selector] = selector_utils_1.separateChunks2(transformer.scopeSelectorAst(context)); | ||
const context = new ScopeContext(meta, (0, selector_utils_1.parseSelector)(rule.selector), rule); | ||
transformedScopes[rule.selector] = (0, selector_utils_1.separateChunks2)(transformer.scopeSelectorAst(context)); | ||
const ruleReports = transformer.diagnostics.reports.splice(len); | ||
@@ -650,3 +655,3 @@ ruleReports.forEach(({ message, type, options: { word } = {} }) => { | ||
return () => { | ||
const clone = lodash_clonedeep_1.default(selectorNode); | ||
const clone = (0, lodash_clonedeep_1.default)(selectorNode); | ||
clone.nodes[nodeIndex].nodes = customElementChunk.nodes; | ||
@@ -653,0 +658,0 @@ return clone; |
@@ -7,2 +7,3 @@ import * as postcss from 'postcss'; | ||
import type { StylableResolver } from './stylable-resolver'; | ||
import { AnyValueNode } from 'css-selector-tokenizer'; | ||
export declare const CUSTOM_SELECTOR_RE: RegExp; | ||
@@ -28,2 +29,3 @@ export declare function isValidDeclaration(decl: postcss.Declaration): boolean; | ||
export declare function isValidClassName(className: string): boolean; | ||
export declare function processDeclarationFunctions(decl: postcss.Declaration, onFunction: (node: AnyValueNode) => void, transform?: boolean): void; | ||
//# sourceMappingURL=stylable-utils.d.ts.map |
@@ -25,3 +25,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isValidClassName = exports.scopeCSSVar = exports.isCSSVarProp = exports.generateScopedCSSVar = exports.getAlias = exports.getSourcePath = exports.getDeclStylable = exports.findRule = exports.findDeclaration = exports.removeUnusedRules = exports.createSubsetAst = exports.mergeRules = exports.scopeSelector = exports.transformMatchesOnRule = exports.expandCustomSelectors = exports.isValidDeclaration = exports.CUSTOM_SELECTOR_RE = void 0; | ||
exports.processDeclarationFunctions = exports.isValidClassName = exports.scopeCSSVar = exports.isCSSVarProp = exports.generateScopedCSSVar = exports.getAlias = exports.getSourcePath = exports.getDeclStylable = exports.findRule = exports.findDeclaration = exports.removeUnusedRules = exports.createSubsetAst = exports.mergeRules = exports.scopeSelector = exports.transformMatchesOnRule = exports.expandCustomSelectors = exports.isValidDeclaration = exports.CUSTOM_SELECTOR_RE = void 0; | ||
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
@@ -33,2 +33,3 @@ const path_1 = require("path"); | ||
const stylable_value_parsers_1 = require("./stylable-value-parsers"); | ||
const css_selector_tokenizer_1 = require("css-selector-tokenizer"); | ||
exports.CUSTOM_SELECTOR_RE = /:--[\w-]+/g; | ||
@@ -57,12 +58,12 @@ function isValidDeclaration(decl) { | ||
function transformMatchesOnRule(rule, lineBreak) { | ||
return replace_rule_selector_1.replaceRuleSelector(rule, { lineBreak }); | ||
return (0, replace_rule_selector_1.replaceRuleSelector)(rule, { lineBreak }); | ||
} | ||
exports.transformMatchesOnRule = transformMatchesOnRule; | ||
function scopeSelector(scopeSelectorRule, targetSelectorRule, rootScopeLevel = false) { | ||
const scopingSelectorAst = selector_utils_1.parseSelector(scopeSelectorRule); | ||
const targetSelectorAst = selector_utils_1.parseSelector(targetSelectorRule); | ||
const scopingSelectorAst = (0, selector_utils_1.parseSelector)(scopeSelectorRule); | ||
const targetSelectorAst = (0, selector_utils_1.parseSelector)(targetSelectorRule); | ||
const nodes = []; | ||
targetSelectorAst.nodes.forEach((targetSelector) => { | ||
scopingSelectorAst.nodes.forEach((scopingSelector) => { | ||
const outputSelector = lodash_clonedeep_1.default(targetSelector); | ||
const outputSelector = (0, lodash_clonedeep_1.default)(targetSelector); | ||
outputSelector.before = scopingSelector.before || outputSelector.before; | ||
@@ -88,3 +89,3 @@ const first = outputSelector.nodes[0]; | ||
!globalSelector) { | ||
outputSelector.nodes.unshift(...lodash_clonedeep_1.default(scopingSelector.nodes), { | ||
outputSelector.nodes.unshift(...(0, lodash_clonedeep_1.default)(scopingSelector.nodes), { | ||
type: 'spacing', | ||
@@ -94,5 +95,5 @@ value: ' ', | ||
} | ||
selector_utils_1.traverseNode(outputSelector, (node, i, nodes) => { | ||
(0, selector_utils_1.traverseNode)(outputSelector, (node, i, nodes) => { | ||
if (node.type === 'invalid' && node.value === '&') { | ||
nodes.splice(i, 1, ...lodash_clonedeep_1.default(scopingSelector.nodes)); | ||
nodes.splice(i, 1, ...(0, lodash_clonedeep_1.default)(scopingSelector.nodes)); | ||
} | ||
@@ -105,3 +106,3 @@ }); | ||
return { | ||
selector: selector_utils_1.stringifySelector(scopingSelectorAst), | ||
selector: (0, selector_utils_1.stringifySelector)(scopingSelectorAst), | ||
selectorAst: scopingSelectorAst, | ||
@@ -114,3 +115,3 @@ }; | ||
mixinAst.walkRules((mixinRule) => { | ||
if (selector_utils_1.isChildOfAtRule(mixinRule, 'keyframes')) { | ||
if ((0, selector_utils_1.isChildOfAtRule)(mixinRule, 'keyframes')) { | ||
return; | ||
@@ -166,3 +167,3 @@ } | ||
// keyframes on class mixin? | ||
const prefixType = selector_utils_1.parseSelector(selectorPrefix).nodes[0].nodes[0]; | ||
const prefixType = (0, selector_utils_1.parseSelector)(selectorPrefix).nodes[0].nodes[0]; | ||
const containsPrefix = containsMatchInFirstChunk.bind(null, prefixType); | ||
@@ -174,3 +175,3 @@ const mixinRoot = mixinTarget ? mixinTarget : postcss.root(); | ||
? scopeSelector(selectorPrefix, node.selector, true).selectorAst | ||
: selector_utils_1.parseSelector(node.selector); | ||
: (0, selector_utils_1.parseSelector)(node.selector); | ||
const matchesSelectors = isRoot | ||
@@ -180,7 +181,7 @@ ? ast.nodes | ||
if (matchesSelectors.length) { | ||
const selector = selector_utils_1.stringifySelector({ | ||
const selector = (0, selector_utils_1.stringifySelector)({ | ||
...ast, | ||
nodes: matchesSelectors.map((selectorNode) => { | ||
if (!isRoot) { | ||
selector_utils_1.fixChunkOrdering(selectorNode, prefixType); | ||
(0, selector_utils_1.fixChunkOrdering)(selectorNode, prefixType); | ||
} | ||
@@ -223,3 +224,3 @@ return destructiveReplaceNode(selectorNode, prefixType, { | ||
let shouldOutput = true; | ||
selector_utils_1.traverseNode(rule.selectorAst, (node) => { | ||
(0, selector_utils_1.traverseNode)(rule.selectorAst, (node) => { | ||
// TODO: remove. | ||
@@ -277,4 +278,4 @@ if (symbols.includes(node.name)) { | ||
function destructiveReplaceNode(ast, matchNode, replacementNode) { | ||
selector_utils_1.traverseNode(ast, (node) => { | ||
if (selector_utils_1.isNodeMatch(node, matchNode)) { | ||
(0, selector_utils_1.traverseNode)(ast, (node) => { | ||
if ((0, selector_utils_1.isNodeMatch)(node, matchNode)) { | ||
node.type = 'selector'; | ||
@@ -288,3 +289,3 @@ node.nodes = [replacementNode]; | ||
let isMatch = false; | ||
selector_utils_1.traverseNode(selectorNode, (node) => { | ||
(0, selector_utils_1.traverseNode)(selectorNode, (node) => { | ||
if (node.type === 'operator' || node.type === 'spacing') { | ||
@@ -296,3 +297,3 @@ return false; | ||
} | ||
else if (selector_utils_1.isNodeMatch(node, prefixType)) { | ||
else if ((0, selector_utils_1.isNodeMatch)(node, prefixType)) { | ||
isMatch = true; | ||
@@ -310,3 +311,3 @@ return false; | ||
} | ||
else if (!path_1.isAbsolute(source)) { | ||
else if (!(0, path_1.isAbsolute)(source)) { | ||
throw new Error('source filename is not absolute path: "' + source + '"'); | ||
@@ -358,2 +359,25 @@ } | ||
exports.isValidClassName = isValidClassName; | ||
function processDeclarationFunctions(decl, onFunction, transform = false) { | ||
const ast = (0, css_selector_tokenizer_1.parseValues)(decl.value); | ||
ast.nodes.forEach((node) => findFunction(node, onFunction)); | ||
if (transform) { | ||
decl.value = (0, css_selector_tokenizer_1.stringifyValues)(ast); | ||
} | ||
} | ||
exports.processDeclarationFunctions = processDeclarationFunctions; | ||
function findFunction(node, onFunctionNode) { | ||
switch (node.type) { | ||
case 'value': | ||
case 'values': | ||
node.nodes.forEach((child) => findFunction(child, onFunctionNode)); | ||
break; | ||
case 'url': | ||
onFunctionNode(node); | ||
break; | ||
case 'nested-item': | ||
onFunctionNode(node); | ||
node.nodes.forEach((child) => findFunction(child, onFunctionNode)); | ||
break; | ||
} | ||
} | ||
//# sourceMappingURL=stylable-utils.js.map |
import type * as postcss from 'postcss'; | ||
import postcssValueParser from 'postcss-value-parser'; | ||
import postcssValueParser, { FunctionNode, WordNode, Node as ValueNode } from 'postcss-value-parser'; | ||
import type { Diagnostics } from './diagnostics'; | ||
@@ -25,2 +25,4 @@ import type { ParsedValue, StateParsedValue } from './types'; | ||
partial?: boolean; | ||
valueNode?: FunctionNode | WordNode; | ||
originDecl?: postcss.Declaration; | ||
} | ||
@@ -78,3 +80,3 @@ export interface ArgValue { | ||
}; | ||
'-st-mixin'(mixinNode: postcss.Declaration, strategy: (type: string) => 'named' | 'args', diagnostics?: Diagnostics | undefined): MixinValue[]; | ||
'-st-mixin'(mixinNode: postcss.Declaration, strategy: (type: string) => 'named' | 'args', diagnostics?: Diagnostics | undefined, emitStrategyDiagnostics?: boolean): MixinValue[]; | ||
'-st-partial-mixin'(mixinNode: postcss.Declaration, strategy: (type: string) => 'named' | 'args', diagnostics?: Diagnostics | undefined): MixinValue[]; | ||
@@ -85,3 +87,3 @@ }; | ||
export declare function getStringValue(nodes: ParsedValue | ParsedValue[]): string; | ||
export declare function groupValues(nodes: any[], divType?: string): any[]; | ||
export declare function groupValues(nodes: ValueNode[], divType?: string): postcssValueParser.Node[][]; | ||
export declare const strategies: { | ||
@@ -88,0 +90,0 @@ named: (node: any, reportWarning?: ReportWarning | undefined) => Record<string, string>; |
@@ -60,3 +60,3 @@ "use strict"; | ||
// Experimental | ||
const selector = selector_utils_1.parseSelector(decl.value.replace(/^['"]/, '').replace(/['"]$/, '')); | ||
const selector = (0, selector_utils_1.parseSelector)(decl.value.replace(/^['"]/, '').replace(/['"]$/, '')); | ||
return selector.nodes[0].nodes; | ||
@@ -68,6 +68,6 @@ }, | ||
} | ||
return pseudo_states_1.processPseudoStates(value, decl, diagnostics); | ||
return (0, pseudo_states_1.processPseudoStates)(value, decl, diagnostics); | ||
}, | ||
'-st-extends'(value) { | ||
const ast = postcss_value_parser_1.default(value); | ||
const ast = (0, postcss_value_parser_1.default)(value); | ||
const types = []; | ||
@@ -100,20 +100,21 @@ ast.walk((node) => { | ||
if (value) { | ||
handleNamedTokens(postcss_value_parser_1.default(value), { namedMap, keyframesMap }, 'namedMap', node, diagnostics); | ||
handleNamedTokens((0, postcss_value_parser_1.default)(value), { namedMap, keyframesMap }, 'namedMap', node, diagnostics); | ||
} | ||
return { namedMap, keyframesMap }; | ||
}, | ||
'-st-mixin'(mixinNode, strategy, diagnostics) { | ||
const ast = postcss_value_parser_1.default(mixinNode.value); | ||
'-st-mixin'(mixinNode, strategy, diagnostics, emitStrategyDiagnostics = true) { | ||
const ast = (0, postcss_value_parser_1.default)(mixinNode.value); | ||
const mixins = []; | ||
function reportWarning(message, options) { | ||
if (diagnostics) { | ||
diagnostics.warn(mixinNode, message, options); | ||
if (emitStrategyDiagnostics) { | ||
diagnostics === null || diagnostics === void 0 ? void 0 : diagnostics.warn(mixinNode, message, options); | ||
} | ||
} | ||
ast.nodes.forEach((node) => { | ||
const strat = strategy(node.value); | ||
if (node.type === 'function') { | ||
mixins.push({ | ||
type: node.value, | ||
options: exports.strategies[strat](node, reportWarning), | ||
options: exports.strategies[strategy(node.value)](node, reportWarning), | ||
valueNode: node, | ||
originDecl: mixinNode, | ||
}); | ||
@@ -124,7 +125,9 @@ } | ||
type: node.value, | ||
options: strat === 'named' ? {} : [], | ||
options: strategy(node.value) === 'named' ? {} : [], | ||
valueNode: node, | ||
originDecl: mixinNode, | ||
}); | ||
} | ||
else if (node.type === 'string' && diagnostics) { | ||
diagnostics.error(mixinNode, exports.valueParserWarnings.VALUE_CANNOT_BE_STRING(), { | ||
else if (node.type === 'string') { | ||
diagnostics === null || diagnostics === void 0 ? void 0 : diagnostics.error(mixinNode, exports.valueParserWarnings.VALUE_CANNOT_BE_STRING(), { | ||
word: mixinNode.value, | ||
@@ -131,0 +134,0 @@ }); |
@@ -27,6 +27,6 @@ "use strict"; | ||
this.resolverCache = resolverCache; | ||
const { fileProcessor, resolvePath } = create_infra_structure_1.createInfrastructure(projectRoot, fileSystem, onProcess, resolveOptions, this.resolveNamespace, timedCacheOptions, resolveModule, cssParser); | ||
const { fileProcessor, resolvePath } = (0, create_infra_structure_1.createInfrastructure)(projectRoot, fileSystem, onProcess, resolveOptions, this.resolveNamespace, timedCacheOptions, resolveModule, cssParser); | ||
this.resolvePath = resolvePath; | ||
this.fileProcessor = fileProcessor; | ||
this.resolver = new stylable_resolver_1.StylableResolver(this.fileProcessor, this.requireModule); | ||
this.resolver = this.createResolver(); | ||
} | ||
@@ -43,2 +43,3 @@ static create(config) { | ||
this.resolverCache = new Map(); | ||
this.resolver = this.createResolver(); | ||
} | ||
@@ -45,0 +46,0 @@ createResolver({ requireModule, resolverCache, } = {}) { |
{ | ||
"name": "@stylable/core", | ||
"version": "4.6.0", | ||
"version": "4.7.0", | ||
"description": "CSS for Components", | ||
@@ -14,7 +14,7 @@ "main": "dist/index.js", | ||
"deindent": "^0.1.0", | ||
"enhanced-resolve": "^5.8.2", | ||
"enhanced-resolve": "^5.8.3", | ||
"is-vendor-prefixed": "^4.0.0", | ||
"lodash.clonedeep": "^4.5.0", | ||
"lodash.clonedeepwith": "^4.5.0", | ||
"postcss": "^8.3.6", | ||
"postcss": "^8.3.8", | ||
"postcss-js": "^3.0.3", | ||
@@ -21,0 +21,0 @@ "postcss-nested": "^5.0.6", |
@@ -56,4 +56,4 @@ import cloneDeepWith from 'lodash.clonedeepwith'; | ||
export const stTypes: CustomTypes = { | ||
stArray: createCustomValue<BoxedValueArray, BoxedValueArray>({ | ||
function createStArrayCustomFunction() { | ||
return createCustomValue<BoxedValueArray, BoxedValueArray>({ | ||
processArgs: (node, customTypes) => { | ||
@@ -66,4 +66,7 @@ return CustomValueStrategy.args(node, customTypes); | ||
getValue: (value, index) => value[parseInt(index, 10)], | ||
}).register('stArray'), | ||
stMap: createCustomValue<BoxedValueMap, BoxedValueMap>({ | ||
}); | ||
} | ||
function createStMapCustomFunction() { | ||
return createCustomValue<BoxedValueMap, BoxedValueMap>({ | ||
processArgs: (node, customTypes) => { | ||
@@ -76,3 +79,21 @@ return CustomValueStrategy.named(node, customTypes); | ||
getValue: (value, index) => value[index], | ||
}).register('stMap'), | ||
}); | ||
} | ||
export const stTypes: CustomTypes = { | ||
/** @deprecated - use `st-array` */ | ||
stArray: createStArrayCustomFunction().register('stArray'), | ||
/** @deprecated - use `st-map` */ | ||
stMap: createStMapCustomFunction().register('stMap'), | ||
'st-array': createStArrayCustomFunction().register('st-array'), | ||
'st-map': createStMapCustomFunction().register('st-map'), | ||
} as const; | ||
export const deprecatedStFunctions: Record<string, { alternativeName: string }> = { | ||
stArray: { | ||
alternativeName: 'st-array', | ||
}, | ||
stMap: { | ||
alternativeName: 'st-map', | ||
}, | ||
}; | ||
@@ -79,0 +100,0 @@ |
import type * as postcss from 'postcss'; | ||
export type DiagnosticType = 'error' | 'warning'; | ||
export type DiagnosticType = 'error' | 'warning' | 'info'; | ||
@@ -32,2 +32,5 @@ export interface DiagnosticOptions { | ||
} | ||
public info(node: postcss.Node, message: string, options?: DiagnosticOptions) { | ||
this.add('info', node, message, options); | ||
} | ||
} |
@@ -84,3 +84,3 @@ import { dirname, relative } from 'path'; | ||
args: string[] = [] | ||
): { topLevelType: any; outputValue: string; typeError: Error } { | ||
): { topLevelType: any; outputValue: string; typeError?: Error } { | ||
diagnostics = node ? diagnostics : undefined; | ||
@@ -294,3 +294,3 @@ const customValues = resolveCustomValues(meta, resolver); | ||
parsedNode.resolvedValue, | ||
error.message | ||
(error as Error)?.message | ||
), | ||
@@ -331,3 +331,3 @@ { word: (node as postcss.Declaration).value } | ||
let topLevelType = null; | ||
let typeError = null; | ||
let typeError: Error | undefined = undefined; | ||
for (const n of parsedValue.nodes) { | ||
@@ -342,3 +342,3 @@ if (n.type === 'function') { | ||
} catch (e) { | ||
typeError = e; | ||
typeError = e as Error; | ||
// catch broken variable resolutions | ||
@@ -345,0 +345,0 @@ } |
256
src/index.ts
@@ -1,28 +0,228 @@ | ||
export * from './parser'; | ||
export * from './cached-process-file'; | ||
export * from './stylable-processor'; | ||
export * from './stylable-transformer'; | ||
export * from './stylable-utils'; | ||
export * from './stylable-resolver'; | ||
export * from './diagnostics'; | ||
export * from './memory-minimal-fs'; | ||
export * from './stylable-value-parsers'; | ||
export * from './create-infra-structure'; | ||
export * from './stylable'; | ||
export * from './types'; | ||
export * from './stylable-mixins'; | ||
export * from './stylable-assets'; | ||
export * from './functions'; | ||
export * from './custom-values'; | ||
export * from './state-validators'; | ||
export * from './selector-utils'; | ||
export * from './native-reserved-lists'; | ||
export * from './resolve-namespace-factories'; | ||
export * from './module-resolver'; | ||
export * from './report-diagnostic'; | ||
export * from './visit-meta-css-dependencies'; | ||
export * from './murmurhash'; | ||
export * from './timed-cache'; | ||
import * as pseudoStates from './pseudo-states'; | ||
export { pseudoStates }; | ||
export { CssParser, cssObjectToAst, cssParse, safeParse } from './parser'; | ||
export { | ||
CacheItem, | ||
FileProcessor, | ||
MinimalFS, | ||
cachedProcessFile, | ||
processFn, | ||
} from './cached-process-file'; | ||
export { | ||
CSSVarSymbol, | ||
ClassSymbol, | ||
DeclStylableProps, | ||
ElementSymbol, | ||
ImportSymbol, | ||
Imported, | ||
KeyframesSymbol, | ||
RESERVED_ROOT_NAME, | ||
RefedMixin, | ||
SDecl, | ||
SRule, | ||
SimpleSelector, | ||
StylableDirectives, | ||
StylableMeta, | ||
StylableProcessor, | ||
StylableSymbol, | ||
VarSymbol, | ||
createEmptyMeta, | ||
process, | ||
processNamespace, | ||
processorWarnings, | ||
validateScopingSelector, | ||
parsePseudoImport, | ||
} from './stylable-processor'; | ||
export { | ||
AdditionalSelector, | ||
KeyFrameWithNode, | ||
ResolvedElement, | ||
ScopedSelectorResults, | ||
StylableExports, | ||
StylableResults, | ||
StylableTransformer, | ||
TransformHooks, | ||
TransformerOptions, | ||
postProcessor, | ||
replaceValueHook, | ||
transformerWarnings, | ||
} from './stylable-transformer'; | ||
export { | ||
CUSTOM_SELECTOR_RE, | ||
createSubsetAst, | ||
expandCustomSelectors, | ||
findDeclaration, | ||
findRule, | ||
generateScopedCSSVar, | ||
getAlias, | ||
getDeclStylable, | ||
getSourcePath, | ||
isCSSVarProp, | ||
isValidClassName, | ||
isValidDeclaration, | ||
mergeRules, | ||
removeUnusedRules, | ||
scopeCSSVar, | ||
scopeSelector, | ||
transformMatchesOnRule, | ||
processDeclarationFunctions, | ||
} from './stylable-utils'; | ||
export { | ||
CSSResolve, | ||
CachedModule, | ||
JSResolve, | ||
JsModule, | ||
StylableResolver, | ||
StylableResolverCache, | ||
isInPath, | ||
resolverWarnings, | ||
} from './stylable-resolver'; | ||
export { Diagnostic, DiagnosticOptions, DiagnosticType, Diagnostics } from './diagnostics'; | ||
export { File, MinimalFSSetup, createMinimalFS } from './memory-minimal-fs'; | ||
export { | ||
ArgValue, | ||
ExtendsValue, | ||
MappedStates, | ||
MixinValue, | ||
ReportWarning, | ||
SBTypesParsers, | ||
STYLABLE_NAMED_MATCHER, | ||
STYLABLE_VALUE_MATCHER, | ||
TypedClass, | ||
animationPropRegExp, | ||
getFormatterArgs, | ||
getNamedArgs, | ||
getStringValue, | ||
globalValueRegExp, | ||
groupValues, | ||
listOptions, | ||
mixinDeclRegExp, | ||
paramMapping, | ||
rootValueMapping, | ||
stKeys, | ||
stValues, | ||
stValuesMap, | ||
strategies, | ||
validateAllowedNodesUntil, | ||
valueMapping, | ||
valueParserWarnings, | ||
} from './stylable-value-parsers'; | ||
export { StylableInfrastructure, createInfrastructure } from './create-infra-structure'; | ||
export { CreateProcessorOptions, Stylable, StylableConfig } from './stylable'; | ||
export { | ||
CSSObject, | ||
IStylableClassNameOptimizer, | ||
IStylableNamespaceOptimizer, | ||
IStylableOptimizer, | ||
ModuleResolver, | ||
OptimizeConfig, | ||
ParsedValue, | ||
PartialObject, | ||
StateArguments, | ||
StateParsedValue, | ||
StateTypeValidator, | ||
} from './types'; | ||
export { appendMixin, appendMixins, mixinWarnings } from './stylable-mixins'; | ||
export { | ||
OnUrlCallback, | ||
UrlNode, | ||
assureRelativeUrlPrefix, | ||
collectAssets, | ||
fixRelativeUrls, | ||
isAsset, | ||
isExternal, | ||
isUrl, | ||
makeAbsolute, | ||
} from './stylable-assets'; | ||
export { | ||
ResolvedFormatter, | ||
ValueFormatter, | ||
evalDeclarationValue, | ||
functionWarnings, | ||
processDeclarationValue, | ||
resolveArgumentsValue, | ||
} from './functions'; | ||
export { | ||
Box, | ||
BoxedValueArray, | ||
BoxedValueMap, | ||
CustomValueExtension, | ||
CustomValueStrategy, | ||
JSValueExtension, | ||
box, | ||
createCustomValue, | ||
getBoxValue, | ||
isCustomValue, | ||
resolveCustomValues, | ||
stTypes, | ||
unbox, | ||
} from './custom-values'; | ||
export { StateParamType, StateResult, SubValidator, systemValidators } from './state-validators'; | ||
export { | ||
PseudoSelectorAstNode, | ||
SelectorAstNode, | ||
SelectorChunk, | ||
SelectorChunk2, | ||
Visitor, | ||
createChecker, | ||
createSimpleSelectorChecker, | ||
createWarningRule, | ||
filterChunkNodesByType, | ||
fixChunkOrdering, | ||
getOriginDefinition, | ||
isChildOfAtRule, | ||
isCompRoot, | ||
isGlobal, | ||
isImport, | ||
isNested, | ||
isNodeMatch, | ||
isRootValid, | ||
isSimpleSelector, | ||
matchAtKeyframes, | ||
matchAtMedia, | ||
matchSelectorTarget, | ||
mergeChunks, | ||
parseSelector, | ||
separateChunks, | ||
separateChunks2, | ||
stringifySelector, | ||
traverseNode, | ||
} from './selector-utils'; | ||
export { | ||
isCssNativeFunction, | ||
nativeFunctions, | ||
nativeFunctionsDic, | ||
nativePseudoClasses, | ||
nativePseudoElements, | ||
reservedKeyFrames, | ||
} from './native-reserved-lists'; | ||
export { noCollisionNamespace, packageNamespaceFactory } from './resolve-namespace-factories'; | ||
export { createDefaultResolver } from './module-resolver'; | ||
export { DiagnosticsMode, EmitDiagnosticsContext, emitDiagnostics } from './report-diagnostic'; | ||
export { visitMetaCSSDependenciesBFS } from './visit-meta-css-dependencies'; | ||
export { murmurhash3_32_gc } from './murmurhash'; | ||
export { TimedCacheOptions, timedCache } from './timed-cache'; | ||
import { | ||
booleanStateDelimiter, | ||
createBooleanStateClassName, | ||
createStateWithParamClassName, | ||
processPseudoStates, | ||
resolveStateParam, | ||
setStateToNode, | ||
stateErrors, | ||
stateMiddleDelimiter, | ||
stateWithParamDelimiter, | ||
validateStateArgument, | ||
validateStateDefinition, | ||
} from './pseudo-states'; | ||
export const pseudoStates = { | ||
booleanStateDelimiter, | ||
createBooleanStateClassName, | ||
createStateWithParamClassName, | ||
processPseudoStates, | ||
resolveStateParam, | ||
setStateToNode, | ||
stateErrors, | ||
stateMiddleDelimiter, | ||
stateWithParamDelimiter, | ||
validateStateArgument, | ||
validateStateDefinition, | ||
}; |
@@ -0,1 +1,2 @@ | ||
import type { Diagnostic, DiagnosticType } from './diagnostics'; | ||
import type { StylableMeta } from './stylable-processor'; | ||
@@ -15,5 +16,12 @@ | ||
diagnosticsMode: DiagnosticsMode, | ||
{ message, type }: { message: string; type: 'warning' | 'error' } | ||
{ message, type }: { message: string; type: DiagnosticType } | ||
) { | ||
const error = new Error(message); | ||
if (type === 'info') { | ||
ctx.emitWarning(error); | ||
return; | ||
} | ||
if (diagnosticsMode === 'auto') { | ||
@@ -36,8 +44,8 @@ if (type === 'warning') { | ||
) { | ||
meta.diagnostics?.reports.forEach((diagnostic) => | ||
reportDiagnostic(ctx, diagnosticsMode, diagnostic) | ||
); | ||
meta.transformDiagnostics?.reports.forEach((diagnostic) => | ||
reportDiagnostic(ctx, diagnosticsMode, diagnostic) | ||
); | ||
meta.diagnostics?.reports.forEach(handleReport); | ||
meta.transformDiagnostics?.reports.forEach(handleReport); | ||
function handleReport(diagnostic: Diagnostic) { | ||
reportDiagnostic(ctx, diagnosticsMode, diagnostic); | ||
} | ||
} |
import path from 'path'; | ||
import type * as postcss from 'postcss'; | ||
import cssSelectorTokenizer from 'css-selector-tokenizer'; | ||
import { processDeclarationFunctions } from './stylable-utils'; | ||
const { parseValues, stringifyValues } = cssSelectorTokenizer; | ||
export interface UrlNode { | ||
@@ -22,4 +20,13 @@ type: 'url'; | ||
const assetDependencies: string[] = []; | ||
const onUrl: OnUrlCallback = (node) => assetDependencies.push(node.url); | ||
ast.walkDecls((decl) => processDeclarationUrls(decl, onUrl, false)); | ||
ast.walkDecls((decl) => { | ||
processDeclarationFunctions( | ||
decl, | ||
(node) => { | ||
if (node.type === 'url') { | ||
assetDependencies.push(node.url); | ||
} | ||
}, | ||
false | ||
); | ||
}); | ||
return assetDependencies; | ||
@@ -64,45 +71,27 @@ } | ||
export function processDeclarationUrls( | ||
decl: postcss.Declaration, | ||
onUrl: OnUrlCallback, | ||
transform: boolean | ||
) { | ||
const ast = parseValues(decl.value); | ||
ast.nodes.forEach((node) => { | ||
node.nodes.forEach((node) => findUrls(node, onUrl)); | ||
export function fixRelativeUrls(ast: postcss.Root, originPath: string, targetPath: string) { | ||
ast.walkDecls((decl) => { | ||
processDeclarationFunctions( | ||
decl, | ||
(node) => { | ||
if (node.type === 'url') { | ||
if (!node.url || !isAsset(node.url) || !node.url.startsWith('.')) { | ||
return; | ||
} | ||
const url = path | ||
.join( | ||
path.relative(path.dirname(targetPath), path.dirname(originPath)), | ||
node.url | ||
) | ||
.replace(/\\/gm, '/'); | ||
node.url = assureRelativeUrlPrefix(url); | ||
} | ||
}, | ||
true | ||
); | ||
}); | ||
if (transform) { | ||
decl.value = stringifyValues(ast); | ||
} | ||
} | ||
function findUrls(node: cssSelectorTokenizer.AnyValueNode, onUrl: OnUrlCallback) { | ||
switch (node.type) { | ||
case 'value': | ||
node.nodes.forEach((child) => findUrls(child, onUrl)); | ||
break; | ||
case 'nested-item': | ||
node.nodes.forEach((child) => findUrls(child, onUrl)); | ||
break; | ||
case 'url': | ||
onUrl(node); | ||
break; | ||
} | ||
} | ||
export function fixRelativeUrls(ast: postcss.Root, originPath: string, targetPath: string) { | ||
const onUrl = (node: UrlNode) => { | ||
if (!node.url || !isAsset(node.url) || !node.url.startsWith('.')) { | ||
return; | ||
} | ||
const url = path | ||
.join(path.relative(path.dirname(targetPath), path.dirname(originPath)), node.url) | ||
.replace(/\\/gm, '/'); | ||
node.url = assureRelativeUrlPrefix(url); | ||
}; | ||
ast.walkDecls((decl) => processDeclarationUrls(decl, onUrl, true)); | ||
} | ||
export function assureRelativeUrlPrefix(url: string) { | ||
return !url.startsWith('./') && !url.startsWith('../') ? './' + url : url; | ||
} |
@@ -123,3 +123,3 @@ import type * as postcss from 'postcss'; | ||
name: string; | ||
global?: boolean; | ||
global: boolean; | ||
} | ||
@@ -126,0 +126,0 @@ |
import { dirname } from 'path'; | ||
import * as postcss from 'postcss'; | ||
import type { Diagnostics } from './diagnostics'; | ||
@@ -12,3 +13,3 @@ import { resolveArgumentsValue } from './functions'; | ||
import { createSubsetAst, isValidDeclaration, mergeRules } from './stylable-utils'; | ||
import { valueMapping, mixinDeclRegExp } from './stylable-value-parsers'; | ||
import { valueMapping, mixinDeclRegExp, strategies } from './stylable-value-parsers'; | ||
@@ -65,5 +66,13 @@ export const mixinWarnings = { | ||
if (local && (local._kind === 'class' || local._kind === 'element')) { | ||
handleLocalClassMixin(mix, transformer, meta, variableOverride, cssVarsMapping, path, rule); | ||
handleLocalClassMixin( | ||
reParseMixinNamedArgs(mix, rule, transformer.diagnostics), | ||
transformer, | ||
meta, | ||
variableOverride, | ||
cssVarsMapping, | ||
path, | ||
rule | ||
); | ||
} else { | ||
const resolvedMixin = transformer.resolver.resolve(mix.ref); | ||
const resolvedMixin = transformer.resolver.deepResolve(mix.ref); | ||
if (resolvedMixin) { | ||
@@ -75,3 +84,3 @@ if (resolvedMixin._kind === 'js') { | ||
transformer, | ||
mix, | ||
reParseMixinArgs(mix, rule, transformer.diagnostics), | ||
resolvedMixin.symbol, | ||
@@ -85,3 +94,3 @@ meta, | ||
rule, | ||
mixinWarnings.FAILED_TO_APPLY_MIXIN(e), | ||
mixinWarnings.FAILED_TO_APPLY_MIXIN(String(e)), | ||
{ word: mix.mixin.type } | ||
@@ -99,3 +108,3 @@ ); | ||
transformer, | ||
mix, | ||
reParseMixinNamedArgs(mix, rule, transformer.diagnostics), | ||
rule, | ||
@@ -109,3 +118,3 @@ meta, | ||
} else { | ||
// TODO: error cannot resolve mixin | ||
// TODO: error cannot resolve mixin - this should be a diagnostic covered by unknown symbol | ||
} | ||
@@ -396,1 +405,46 @@ } | ||
} | ||
/** this is a workaround for parsing the mixin args too early */ | ||
function reParseMixinNamedArgs( | ||
mix: RefedMixin, | ||
rule: postcss.Rule, | ||
diagnostics: Diagnostics | ||
): RefedMixin { | ||
const options = | ||
mix.mixin.valueNode?.type === 'function' | ||
? strategies.named(mix.mixin.valueNode, (message, options) => { | ||
diagnostics.warn(mix.mixin.originDecl || rule, message, options); | ||
}) | ||
: (mix.mixin.options as Record<string, string>) || {}; | ||
return { | ||
...mix, | ||
mixin: { | ||
...mix.mixin, | ||
options, | ||
}, | ||
}; | ||
} | ||
function reParseMixinArgs( | ||
mix: RefedMixin, | ||
rule: postcss.Rule, | ||
diagnostics: Diagnostics | ||
): RefedMixin { | ||
const options = | ||
mix.mixin.valueNode?.type === 'function' | ||
? strategies.args(mix.mixin.valueNode, (message, options) => { | ||
diagnostics.warn(mix.mixin.originDecl || rule, message, options); | ||
}) | ||
: Array.isArray(mix.mixin.options) | ||
? (mix.mixin.options as { value: string }[]) | ||
: []; | ||
return { | ||
...mix, | ||
mixin: { | ||
...mix.mixin, | ||
options, | ||
}, | ||
}; | ||
} |
@@ -5,2 +5,3 @@ import path from 'path'; | ||
import { tokenizeImports } from 'toky'; | ||
import { deprecatedStFunctions } from './custom-values'; | ||
import { Diagnostics } from './diagnostics'; | ||
@@ -19,3 +20,2 @@ import { murmurhash3_32_gc } from './murmurhash'; | ||
} from './selector-utils'; | ||
import { processDeclarationUrls } from './stylable-assets'; | ||
import { | ||
@@ -37,2 +37,3 @@ ClassSymbol, | ||
isCSSVarProp, | ||
processDeclarationFunctions, | ||
scopeSelector, | ||
@@ -49,2 +50,3 @@ } from './stylable-utils'; | ||
import { deprecated, filename2varname, globalValue, stripQuotation } from './utils'; | ||
import { validateAtProperty } from './validate-at-property'; | ||
export * from './stylable-meta'; /* TEMP EXPORT */ | ||
@@ -175,2 +177,8 @@ | ||
}, | ||
DEPRECATED_ST_GLOBAL_CUSTOM_PROPERTY() { | ||
return `"st-global-custom-property" is deprecated and will be removed in the next version. Use "@property" with ${paramMapping.global}`; | ||
}, | ||
DEPRECATED_ST_FUNCTION_NAME: (name: string, alternativeName: string) => { | ||
return `"${name}" is deprecated, use "${alternativeName}"`; | ||
}, | ||
}; | ||
@@ -181,2 +189,3 @@ | ||
protected dirContext!: string; | ||
constructor( | ||
@@ -197,3 +206,3 @@ protected diagnostics = new Diagnostics(), | ||
if (node.type === 'rule' && node.selector === rootValueMapping.import) { | ||
const imported = this.handleImport(node); | ||
const imported = parsePseudoImport(node, this.dirContext, this.diagnostics); | ||
this.meta.imports.push(imported); | ||
@@ -260,2 +269,3 @@ this.addImportSymbols(imported); | ||
const toRemove: postcss.Node[] = []; | ||
root.walkAtRules((atRule) => { | ||
@@ -341,3 +351,3 @@ switch (atRule.name) { | ||
break; | ||
case 'st-import': | ||
case 'st-import': { | ||
if (atRule.parent?.type !== 'root') { | ||
@@ -354,9 +364,15 @@ this.diagnostics.warn( | ||
} | ||
break; | ||
case 'property': | ||
this.checkRedeclareSymbol(atRule.params, atRule); | ||
} | ||
case 'property': { | ||
this.addCSSVarDefinition(atRule); | ||
validateAtProperty(atRule, this.diagnostics); | ||
break; | ||
} | ||
case 'st-global-custom-property': { | ||
this.diagnostics.info( | ||
atRule, | ||
processorWarnings.DEPRECATED_ST_GLOBAL_CUSTOM_PROPERTY() | ||
); | ||
const cssVarsByComma = atRule.params.split(','); | ||
@@ -372,3 +388,5 @@ const cssVarsBySpacing = atRule.params | ||
processorWarnings.GLOBAL_CSS_VAR_MISSING_COMMA(atRule.params), | ||
{ word: atRule.params } | ||
{ | ||
word: atRule.params, | ||
} | ||
); | ||
@@ -382,10 +400,10 @@ break; | ||
if (isCSSVarProp(cssVar)) { | ||
if (!this.meta.cssVars[cssVar]) { | ||
this.meta.cssVars[cssVar] = { | ||
_kind: 'cssVar', | ||
name: cssVar, | ||
global: true, | ||
}; | ||
this.meta.mappedSymbols[cssVar] = this.meta.cssVars[cssVar]; | ||
} | ||
const property: CSSVarSymbol = { | ||
_kind: 'cssVar', | ||
name: cssVar, | ||
global: true, | ||
}; | ||
this.meta.cssVars[cssVar] = property; | ||
this.meta.mappedSymbols[cssVar] = property; | ||
} else { | ||
@@ -399,2 +417,3 @@ this.diagnostics.warn( | ||
} | ||
toRemove.push(atRule); | ||
@@ -410,4 +429,32 @@ break; | ||
private collectUrls(decl: postcss.Declaration) { | ||
processDeclarationUrls(decl, (node) => this.meta.urls.push(node.url), false); | ||
processDeclarationFunctions( | ||
decl, | ||
(node) => { | ||
if (node.type === 'url') { | ||
this.meta.urls.push(node.url); | ||
} | ||
}, | ||
false | ||
); | ||
} | ||
private handleStFunctions(decl: postcss.Declaration) { | ||
processDeclarationFunctions( | ||
decl, | ||
(node) => { | ||
if (node.type === 'nested-item' && deprecatedStFunctions[node.name]) { | ||
const { alternativeName } = deprecatedStFunctions[node.name]; | ||
this.diagnostics.info( | ||
decl, | ||
processorWarnings.DEPRECATED_ST_FUNCTION_NAME(node.name, alternativeName), | ||
{ | ||
word: node.name, | ||
} | ||
); | ||
} | ||
}, | ||
false | ||
); | ||
} | ||
private handleNamespaceReference(namespace: string): string { | ||
@@ -662,2 +709,3 @@ let pathToSource: string | undefined; | ||
this.collectUrls(decl); | ||
this.handleStFunctions(decl); | ||
this.checkRedeclareSymbol(decl.prop, decl); | ||
@@ -700,3 +748,3 @@ let type = null; | ||
this.addCSSVar(postcssValueParser.stringify(varName).trim(), decl); | ||
this.addCSSVar(postcssValueParser.stringify(varName).trim(), decl, false); | ||
} | ||
@@ -707,7 +755,24 @@ }); | ||
protected addCSSVarDefinition(node: postcss.Declaration | postcss.AtRule) { | ||
const varName = node.type === 'atrule' ? node.params : node.prop; | ||
this.addCSSVar(varName.trim(), node); | ||
let varName = node.type === 'atrule' ? node.params.trim() : node.prop.trim(); | ||
let isGlobal = false; | ||
const globalVarName = globalValue(varName); | ||
if (globalVarName !== undefined) { | ||
varName = globalVarName.trim(); | ||
isGlobal = true; | ||
} | ||
if (node.type === 'atrule') { | ||
this.checkRedeclareSymbol(varName, node); | ||
} | ||
this.addCSSVar(varName, node, isGlobal); | ||
} | ||
protected addCSSVar(varName: string, node: postcss.Declaration | postcss.AtRule) { | ||
protected addCSSVar( | ||
varName: string, | ||
node: postcss.Declaration | postcss.AtRule, | ||
global: boolean | ||
) { | ||
if (isCSSVarProp(varName)) { | ||
@@ -718,2 +783,3 @@ if (!this.meta.cssVars[varName]) { | ||
name: varName, | ||
global, | ||
}; | ||
@@ -779,16 +845,16 @@ this.meta.cssVars[varName] = cssVarSymbol; | ||
const mixins: RefedMixin[] = []; | ||
/** | ||
* This functionality is broken we don't know what strategy to choose here. | ||
* Should be fixed when we refactor to the new flow | ||
*/ | ||
SBTypesParsers[decl.prop]( | ||
decl, | ||
(type) => { | ||
const mixinRefSymbol = this.meta.mappedSymbols[type]; | ||
if ( | ||
mixinRefSymbol && | ||
mixinRefSymbol._kind === 'import' && | ||
!mixinRefSymbol.import.from.match(/.css$/) | ||
) { | ||
return 'args'; | ||
} | ||
return 'named'; | ||
const symbol = this.meta.mappedSymbols[type]; | ||
return symbol?._kind === 'import' && !symbol.import.from.match(/.css$/) | ||
? 'args' | ||
: 'named'; | ||
}, | ||
this.diagnostics | ||
this.diagnostics, | ||
false | ||
).forEach((mixin) => { | ||
@@ -923,68 +989,2 @@ const mixinRefSymbol = this.meta.mappedSymbols[mixin.type]; | ||
protected handleImport(rule: postcss.Rule) { | ||
let fromExists = false; | ||
const importObj: Imported = { | ||
defaultExport: '', | ||
from: '', | ||
request: '', | ||
named: {}, | ||
keyframes: {}, | ||
rule, | ||
context: this.dirContext, | ||
}; | ||
rule.walkDecls((decl) => { | ||
switch (decl.prop) { | ||
case valueMapping.from: { | ||
const importPath = stripQuotation(decl.value); | ||
if (!importPath.trim()) { | ||
this.diagnostics.error(decl, processorWarnings.EMPTY_IMPORT_FROM()); | ||
} | ||
if (fromExists) { | ||
this.diagnostics.warn(rule, processorWarnings.MULTIPLE_FROM_IN_IMPORT()); | ||
} | ||
setImportObjectFrom(importPath, this.dirContext, importObj); | ||
fromExists = true; | ||
break; | ||
} | ||
case valueMapping.default: | ||
importObj.defaultExport = decl.value; | ||
if (!isCompRoot(importObj.defaultExport) && importObj.from.match(/\.css$/)) { | ||
this.diagnostics.warn( | ||
decl, | ||
processorWarnings.DEFAULT_IMPORT_IS_LOWER_CASE(), | ||
{ word: importObj.defaultExport } | ||
); | ||
} | ||
break; | ||
case valueMapping.named: | ||
{ | ||
const { keyframesMap, namedMap } = parseNamed( | ||
decl.value, | ||
decl, | ||
this.diagnostics | ||
); | ||
importObj.named = namedMap; | ||
importObj.keyframes = keyframesMap; | ||
} | ||
break; | ||
default: | ||
this.diagnostics.warn( | ||
decl, | ||
processorWarnings.ILLEGAL_PROP_IN_IMPORT(decl.prop), | ||
{ word: decl.prop } | ||
); | ||
break; | ||
} | ||
}); | ||
if (!importObj.from) { | ||
this.diagnostics.error(rule, processorWarnings.FROM_PROP_MISSING_IN_IMPORT()); | ||
} | ||
return importObj; | ||
} | ||
private handleScope(atRule: postcss.AtRule) { | ||
@@ -1032,2 +1032,60 @@ const scopingRule = postcss.rule({ selector: atRule.params }) as SRule; | ||
export function parsePseudoImport(rule: postcss.Rule, context: string, diagnostics: Diagnostics) { | ||
let fromExists = false; | ||
const importObj: Imported = { | ||
defaultExport: '', | ||
from: '', | ||
request: '', | ||
named: {}, | ||
keyframes: {}, | ||
rule, | ||
context, | ||
}; | ||
rule.walkDecls((decl) => { | ||
switch (decl.prop) { | ||
case valueMapping.from: { | ||
const importPath = stripQuotation(decl.value); | ||
if (!importPath.trim()) { | ||
diagnostics.error(decl, processorWarnings.EMPTY_IMPORT_FROM()); | ||
} | ||
if (fromExists) { | ||
diagnostics.warn(rule, processorWarnings.MULTIPLE_FROM_IN_IMPORT()); | ||
} | ||
setImportObjectFrom(importPath, context, importObj); | ||
fromExists = true; | ||
break; | ||
} | ||
case valueMapping.default: | ||
importObj.defaultExport = decl.value; | ||
if (!isCompRoot(importObj.defaultExport) && importObj.from.match(/\.css$/)) { | ||
diagnostics.warn(decl, processorWarnings.DEFAULT_IMPORT_IS_LOWER_CASE(), { | ||
word: importObj.defaultExport, | ||
}); | ||
} | ||
break; | ||
case valueMapping.named: | ||
{ | ||
const { keyframesMap, namedMap } = parseNamed(decl.value, decl, diagnostics); | ||
importObj.named = namedMap; | ||
importObj.keyframes = keyframesMap; | ||
} | ||
break; | ||
default: | ||
diagnostics.warn(decl, processorWarnings.ILLEGAL_PROP_IN_IMPORT(decl.prop), { | ||
word: decl.prop, | ||
}); | ||
break; | ||
} | ||
}); | ||
if (!importObj.from) { | ||
diagnostics.error(rule, processorWarnings.FROM_PROP_MISSING_IN_IMPORT()); | ||
} | ||
return importObj; | ||
} | ||
export function validateScopingSelector( | ||
@@ -1034,0 +1092,0 @@ atRule: postcss.AtRule, |
@@ -202,3 +202,7 @@ import isVendorPrefixed from 'is-vendor-prefixed'; | ||
} else if (name === 'property') { | ||
atRule.params = cssVarsMapping[atRule.params] ?? atRule.params; | ||
if (atRule.nodes?.length) { | ||
atRule.params = cssVarsMapping[atRule.params] ?? atRule.params; | ||
} else { | ||
atRule.remove(); | ||
} | ||
} | ||
@@ -205,0 +209,0 @@ }); |
@@ -27,2 +27,3 @@ import cloneDeep from 'lodash.clonedeep'; | ||
import type { StylableResolver } from './stylable-resolver'; | ||
import { AnyValueNode, parseValues, stringifyValues } from 'css-selector-tokenizer'; | ||
@@ -393,1 +394,31 @@ export const CUSTOM_SELECTOR_RE = /:--[\w-]+/g; | ||
} | ||
export function processDeclarationFunctions( | ||
decl: postcss.Declaration, | ||
onFunction: (node: AnyValueNode) => void, | ||
transform = false | ||
) { | ||
const ast = parseValues(decl.value); | ||
ast.nodes.forEach((node) => findFunction(node, onFunction)); | ||
if (transform) { | ||
decl.value = stringifyValues(ast); | ||
} | ||
} | ||
function findFunction(node: AnyValueNode, onFunctionNode: (node: AnyValueNode) => void) { | ||
switch (node.type) { | ||
case 'value': | ||
case 'values': | ||
node.nodes.forEach((child) => findFunction(child, onFunctionNode)); | ||
break; | ||
case 'url': | ||
onFunctionNode(node); | ||
break; | ||
case 'nested-item': | ||
onFunctionNode(node); | ||
node.nodes.forEach((child) => findFunction(child, onFunctionNode)); | ||
break; | ||
} | ||
} |
@@ -5,2 +5,4 @@ import type * as postcss from 'postcss'; | ||
FunctionNode, | ||
WordNode, | ||
Node as ValueNode, | ||
} from 'postcss-value-parser'; | ||
@@ -42,2 +44,4 @@ import type { Diagnostics } from './diagnostics'; | ||
partial?: boolean; | ||
valueNode?: FunctionNode | WordNode; | ||
originDecl?: postcss.Declaration; | ||
} | ||
@@ -164,3 +168,4 @@ | ||
strategy: (type: string) => 'named' | 'args', | ||
diagnostics?: Diagnostics | ||
diagnostics?: Diagnostics, | ||
emitStrategyDiagnostics = true | ||
) { | ||
@@ -171,13 +176,14 @@ const ast = postcssValueParser(mixinNode.value); | ||
function reportWarning(message: string, options?: { word: string }) { | ||
if (diagnostics) { | ||
diagnostics.warn(mixinNode, message, options); | ||
if (emitStrategyDiagnostics) { | ||
diagnostics?.warn(mixinNode, message, options); | ||
} | ||
} | ||
ast.nodes.forEach((node: any) => { | ||
const strat = strategy(node.value); | ||
ast.nodes.forEach((node) => { | ||
if (node.type === 'function') { | ||
mixins.push({ | ||
type: node.value, | ||
options: strategies[strat](node, reportWarning), | ||
options: strategies[strategy(node.value)](node, reportWarning), | ||
valueNode: node, | ||
originDecl: mixinNode, | ||
}); | ||
@@ -187,6 +193,8 @@ } else if (node.type === 'word') { | ||
type: node.value, | ||
options: strat === 'named' ? {} : [], | ||
options: strategy(node.value) === 'named' ? {} : [], | ||
valueNode: node, | ||
originDecl: mixinNode, | ||
}); | ||
} else if (node.type === 'string' && diagnostics) { | ||
diagnostics.error(mixinNode, valueParserWarnings.VALUE_CANNOT_BE_STRING(), { | ||
} else if (node.type === 'string') { | ||
diagnostics?.error(mixinNode, valueParserWarnings.VALUE_CANNOT_BE_STRING(), { | ||
word: mixinNode.value, | ||
@@ -340,5 +348,5 @@ }); | ||
export function groupValues(nodes: any[], divType = 'div') { | ||
const grouped: any[] = []; | ||
let current: any[] = []; | ||
export function groupValues(nodes: ValueNode[], divType = 'div') { | ||
const grouped: ValueNode[][] = []; | ||
let current: ValueNode[] = []; | ||
@@ -345,0 +353,0 @@ nodes.forEach((n: any) => { |
@@ -98,6 +98,7 @@ import type { FileProcessor, MinimalFS } from './cached-process-file'; | ||
this.fileProcessor = fileProcessor; | ||
this.resolver = new StylableResolver(this.fileProcessor, this.requireModule); | ||
this.resolver = this.createResolver(); | ||
} | ||
public initCache() { | ||
this.resolverCache = new Map(); | ||
this.resolver = this.createResolver(); | ||
} | ||
@@ -104,0 +105,0 @@ public createResolver({ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
761239
158
12895
Updatedenhanced-resolve@^5.8.3
Updatedpostcss@^8.3.8