Skip to content

Allow specifying replacements as a callback #70

Open

Description

@joepie91

Currently, replaceSymbols only accepts a mapping of values. This is problematic because the same value may need to be represented differently in different contexts (reference, and there's no way to do that right now.

An API that would solve this, would be something like:

icssUtils.replaceSymbols(css, (symbol, context) => {
	let mappedSymbol = someMapping[symbol];

	if (context === "decl") {
		return mappedSymbol;
	} else {
		return mappedSymbol.replace(/ /g, ".");
	}
});

Activity

  1. alexander-akait commented on Jul 24, 2020

    @alexander-akait
    Member

    Not sure it is real fix bug, when we replace we should known what it was composing from selector

  2. joepie91 commented on Jul 24, 2020

    @joepie91
    Author

    What usecase do you have in mind where that is necessary?

    At least for the composed-class-name issue that shouldn't be necessary, as the correct formatting is dependent entirely on where the identifier appears (class names cannot appear in rule declarations, and vice versa).

  3. alexander-akait commented on Jul 24, 2020

    @alexander-akait
    Member

    Not really, when we receive something (It can bee selector/value/media query) from another file, we do not know whether it is, so we should keep context where we get value before, we should change :import('file.css') { test: test from selector } (just idea) it will not fundamentally solve the problem, but rather a hack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions