Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): st-mixin feature overall #2398

Merged
merged 25 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd51163
refactor: initial feature setup
idoros Mar 21, 2022
5283709
refactor: moved `MixinValue` type to feature
idoros Mar 21, 2022
8fcb5d9
refactor: extract processor into feature
idoros Mar 21, 2022
9b0c4a1
refactor: move `st-import` feature constants to feature
idoros Mar 22, 2022
7ecc0f8
chore: correct `tsVarOverride` to `stVarOverride`
idoros Mar 22, 2022
ccac48a
refactor: move append mixins in feature
idoros Mar 28, 2022
7ec74b1
Merge branch 'master' of github.com:wix/stylable into ido/mixin-featu…
idoros Apr 4, 2022
2311fa5
test: refactor mixins tests
idoros Apr 4, 2022
7f56ddf
fix: crash of imported alias mixin with pseudo class or element
idoros Apr 5, 2022
8ef70f7
fix: mixin imported with alias
idoros Apr 10, 2022
bd68107
fix: support mixin withing nested selector
idoros Apr 10, 2022
b192762
test: add more tests to selector mixin
idoros Apr 10, 2022
9d8f66e
fix: report warning on zero arguments mixin call
idoros Apr 10, 2022
ce6cf00
fix: filter invalid rule/atrule mix into keyframe
idoros Apr 11, 2022
311d93f
fix: catch missing `-st-mixin` decl
idoros Apr 11, 2022
562f275
refactor: deprecate `meta.mixins` like other fields
idoros Apr 11, 2022
517258a
fix: mixin insertion when `-st-mixin` and `-st-partial-mixin` together
idoros Apr 17, 2022
f19fce4
test: moved `SRule` process tests in feature spec
idoros Apr 17, 2022
b98b516
refactor: remove mixin params re-parse
idoros Apr 17, 2022
cfddb65
refactor: minimize internal mixin API signatures
idoros Apr 18, 2022
5e3054a
refactor: organize `st-mixin` feature code
idoros Apr 18, 2022
54d8bde
Merge branch 'master' of github.com:wix/stylable into ido/mixin-featu…
idoros Apr 18, 2022
8d72611
chore: typo and comment
idoros Apr 18, 2022
45cce74
test: add checks for JS mixin delcs
idoros Apr 24, 2022
152b0dc
chore: fix review renames / removes
idoros Apr 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/deprecated/postcss-ast-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface SRule extends Rule {
selectorAst: SelectorAstNode;
isSimpleSelector: boolean;
selectorType: 'class' | 'element' | 'complex';
/**@deprecated*/
mixins?: RefedMixin[];
stScopeSelector?: string;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/features/feature.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StylableMeta } from '../stylable-meta';
import type { ScopeContext, StylableExports } from '../stylable-transformer';
import type { ScopeContext, StylableExports, StylableTransformer } from '../stylable-transformer';
import type { StylableResolver, MetaResolvedSymbols } from '../stylable-resolver';
import type { StylableEvaluator, EvalValueData } from '../functions';
import type * as postcss from 'postcss';
Expand Down Expand Up @@ -69,7 +69,13 @@ export interface FeatureHooks<T extends NodeTypes = NodeTypes> {
data: EvalValueData;
}) => void;
transformJSExports: (options: { exports: StylableExports; resolved: T['RESOLVED'] }) => void;
transformLastPass: (options: { context: FeatureTransformContext }) => void;
transformLastPass: (options: {
context: FeatureTransformContext;
ast: postcss.Root;
transformer: StylableTransformer;
cssVarsMapping: Record<string, string>;
path: string[];
}) => void;
}
const defaultHooks: FeatureHooks<NodeTypes> = {
metaInit() {
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export * as STGlobal from './st-global';
export * as STVar from './st-var';
export type { VarSymbol } from './st-var';

export * as STMixin from './st-mixin';
export type { RefedMixin, MixinValue } from './st-mixin';

export * as CSSClass from './css-class';
export type { ClassSymbol } from './css-class';

Expand All @@ -23,4 +26,4 @@ export type { CSSVarSymbol } from './css-custom-property';
export * as CSSKeyframes from './css-keyframes';
export type { KeyframesSymbol } from './css-keyframes';

export type { RefedMixin, StylableDirectives } from './types';
export type { StylableDirectives } from './types';
14 changes: 10 additions & 4 deletions packages/core/src/features/st-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ignoreDeprecationWarn } from '../helpers/deprecation';
import { parseStImport, parsePseudoImport, parseImportMessages } from '../helpers/import';
import { isCSSVarProp } from '../helpers/css-custom-property';
import type { StylableMeta } from '../stylable-meta';
import { rootValueMapping, valueMapping } from '../stylable-value-parsers';
import path from 'path';
import type { ImmutablePseudoClass, PseudoClass } from '@tokey/css-selector-parser';
import type * as postcss from 'postcss';
Expand All @@ -30,6 +29,13 @@ export interface Imported {
context: string;
}

export const PseudoImport = `:import`;
export const PseudoImportDecl = {
DEFAULT: `-st-default` as const,
NAMED: `-st-named` as const,
FROM: `-st-from` as const,
};

/**
* ImportTypeHook is used as a way to cast imported symbols before resolving their actual type.
* currently used only for `keyframes` as they are completely on a separate namespace from other symbols.
Expand Down Expand Up @@ -113,7 +119,7 @@ export const hooks = createFeature<{
if (rule.selector !== `:import`) {
context.diagnostics.warn(
rule,
diagnostics.FORBIDDEN_DEF_IN_COMPLEX_SELECTOR(rootValueMapping.import)
diagnostics.FORBIDDEN_DEF_IN_COMPLEX_SELECTOR(PseudoImport)
barak007 marked this conversation as resolved.
Show resolved Hide resolved
);
return;
}
Expand Down Expand Up @@ -201,7 +207,7 @@ function validateImports(context: FeatureTransformContext) {
const fromDecl =
importObj.rule.nodes &&
importObj.rule.nodes.find(
(decl) => decl.type === 'decl' && decl.prop === valueMapping.from
(decl) => decl.type === 'decl' && decl.prop === PseudoImportDecl.FROM
barak007 marked this conversation as resolved.
Show resolved Hide resolved
);

context.diagnostics.warn(
Expand All @@ -218,7 +224,7 @@ function validateImports(context: FeatureTransformContext) {
const namedDecl =
importObj.rule.nodes &&
importObj.rule.nodes.find(
(decl) => decl.type === 'decl' && decl.prop === valueMapping.named
(decl) => decl.type === 'decl' && decl.prop === PseudoImportDecl.NAMED
);

context.diagnostics.warn(
Expand Down
Loading