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

refactor(core): integrate new CSS selector parser (from Tokey) #1884

Merged
merged 46 commits into from
Oct 21, 2021

Conversation

idoros
Copy link
Collaborator

@idoros idoros commented Jun 29, 2021

This PR replaces the usage of css-selector-tokenizer with @tokey/css-selector-parser and on the way deprecates all the utils that were used to handle the old AST.

While trying to keep as much backwards/forwards compatibility working, some changes are breaking:

  • internal AST state that is unintentionally exposed to public API
  • change to escaping api that align selector escaping with state definition and js class referencing.

tasks

  • deprecate previous api (keep backwards compatibility with deprecation flags and warnings)
    • selector-util to deprecate folder and route usage
    • deprecate stylable-utils that worked with the old selector AST
    • deprecate postcss ast SRule/SDecl extensions (set deprecation fields and offer alternative where we know they are required)
      • SRule.selectorAst - deprecated with (internally cached selector parser. publicly selector needs to be transformed manually)
      • SRule.isSimpleSelector - deprecated (internal util with no public alternativ)
      • SRule.selectorType - deprecated (internal util with no public alternativ)
      • SRule.mixins - deprecated (still used internally with no public alternative)
      • SRule.stScopeSelector - deprecated on SRule with alternative backwards/forwards compatible getRuleScopeSelector(rule)
      • SDecl.stylable- deprecated
    • deprecate stylableMeta.mixins
    • elements / resolveSelectorElements
    • no internal deprecation usage
  • new selector utils that support the new parser
    • parse/stringify
    • getStylableData/setStylableData to cache selector ast on postcss.Rule/Decl
    • cachedParseSelector
    • isSimpleSelector
    • walk selector
  • validations for tokey extended functional selectors

next phases

  • pass cachedParseSelector through stylable configuration

- add `@tokey/css-selector-parser` dependency to core
- only internal processor process effected
- keep backwards compatibility with SRule
- future intentions comments and removed export in selector-utils
- move to types / utils into deprecation folder
- mark fields and related utils as deprecated with intention to remove
- add alternative getStylableAstData/setStylableAstData
- no breaking change - keep lib exports
- there are probably breaking changes:
- some exports are not exported anymore
- ast return type from scopeSelector / resolveSelectorElements
- transformer uses the new ast insterad of an & element
- new scopeNestedSelector to replace previous scopeSelector
- deprecated stylable-utils/scopeSelector
- fix infinite loop issues when scoping selecotr contained an &
- move to deprecated folder
- mark as deprecated on index export
- kept tests until removed (moved to proper folder)
- move current exported api to deprecation folder
- mark as deprecated on index exports
@idoros idoros added core Processing and transforming logic tech debt Updates, upgrades, stale code and work-arounds labels Jun 29, 2021
@idoros idoros requested review from barak007 and tomrav June 29, 2021 08:43
- utils that used deprected stylable/selector utils
- change all stylable utils to use non deprecated helpers
- moved old tests to deprecated folder
- new utils that work with new ast to replace deprecated utils
- copied tests for new utils
- changed scopeNestedSelector to return both ast & selector (immutable)
- new util to parse and cache selectors (return readonly by default)
- new util to figure out isSimpleSelector
- remove setting of selectorAst/isSimpleSelector/selectorType on astData
- remove all usages of selectorAst/isSimpleSelector/selectorType
- change utils to specify they accept readonly if they don't mutate
- add reverse map for scoped class names on meta
- change parsing to tokey css selector parser
@tomrav tomrav changed the title tokey css selector parser New CSS Selector Parser (from Tokey) Jul 13, 2021
@tomrav tomrav changed the title New CSS Selector Parser (from Tokey) refactor(core): integrate new CSS selector parser (from Tokey) Jul 13, 2021
- add errors for selectors stylable doesn't support
- exception for pseudo classes value() reference
- export getRuleScopeSelector(rule) as a backwards/forwards alternative
- use getRuleScopeSelector internally
- add deprecated warn on stylableMeta.mixins
- add deprecation warn on SRule.mixins
- still use SRule.mixins internally for now
- removed unused stylable AST data
- rename ignoreWarn to ignoreDeprecationWarn
- add to deprecated types and functions
@idoros idoros requested a review from barak007 July 19, 2021 16:02
- no selector transformation on the parameter itself
- stop collecting reserved pseudo classes as -st-states
- new warning when collecting reserved classes as states
@idoros idoros mentioned this pull request Aug 15, 2021
33 tasks
- replace 2 versions of selector walk with a single one from tokey
- use immutable type versions from tokey
- remove DeepReadOnlyAll type
- no change is done directly on it during transform
- moved from toky to @Tokey
- removed unused dependency in @stylable/rollup-plugin
@tzachbon tzachbon linked an issue Aug 17, 2021 that may be closed by this pull request
@idoros idoros mentioned this pull request Aug 24, 2021
4 tasks
@idoros idoros merged commit d8bfacb into master Oct 21, 2021
@idoros idoros deleted the ido/tokey-css-selector-parser branch October 21, 2021 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Processing and transforming logic tech debt Updates, upgrades, stale code and work-arounds
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Naming a state global does not show diagnostic
3 participants